nx_srcdiff.nx
buildroot/runtime/nx_srcdiff.nx
about
nx_srcdiff.nx -- IS A DIRECTION MERGE SAFE, OR DOES THIS NEED A UNION? The per-file decision organ.
WHY IT EXISTS. The estate's banked law is that A DIVERGENCE'S DIRECTION IS A PER-FILE MEASUREMENT,
NEVER A PER-TREE POLICY -- and the 2026-08-03 lane proved it the hard way: BOTH of that session's
directional hypotheses INVERTED once someone actually body-diffed the files ("NAS strict superset"
hid the laptop's richer state; "local larger => NAS revert" was a missing leak fix).
So every convergence needs one question answered first: does adopting one side LOSE anything?
That question was being answered ad-hoc, by hand, outside the estate -- four separate times in the
2026-08-06 session alone, in a laptop shell no other seat can run. An analysis that gates a
DESTRUCTIVE act and lives only in one operator's scrollback is not a capability the fleet has.
WHAT IT REPORTS, and the verdict IS the decision:
IDENTICAL -- same line multiset (!!ORDER may still differ; byte identity is nx_filehash's job)
A-SUPERSET -- B's lines all appear in A. Adopting A loses NOTHING: a DIRECTION merge is safe.
B-SUPERSET -- the mirror.
BIDIRECTIONAL -- both sides hold lines the other lacks. A direction merge DESTROYS WORK; UNION.
This is exactly the shape that decided the real cases: nx_syscalls.nx came back A-SUPERSET (the
only delta was 5 sys_munmap doc lines) so a direction was correct; the 4 same-size gate/quality
files came back A-SUPERSET too, with every "laptop-only" line being the SUPERSEDED original of a
line the other side replaced -- which a surplus report shows and a size screen cannot.
!!A LINE MULTISET IS NOT BYTE IDENTITY. Reordering, and CR-only differences, do not show up as
surplus. CR counts are reported per side BECAUSE they are the classic invisible delta (a 2026-08-03
convergence found 742 stray CRs that git's autocrlf hid while a byte gate counted every one).
Use nx_filehash/nx_treehash for identity; use THIS to decide which way to merge.
DIALECT: plain-if, <=6 params, consts above use. Tables are mmap'd through static POINTERS --
a BSS static ARRAY silently crashes the module at startup (banked gotcha).
license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 32 | const SD_SLOTS: i64 = 131072 // power of two; a 1000-line file loads at <1% -- headroom is cheap |
| 33 | const SD_MASK: i64 = 131071 |
| 34 | const SD_OUTBUF: i64 = 4194304 |
| 35 | const SD_NUMBUF: i64 = 64 |
| 36 | const SD_FNV_OFF: i64 = 1469598103934665603 |
| 37 | const SD_FNV_PRIME: i64 = 1099511628211 |
| 38 | const SD_SAMPLE_CAP: i64 = 25 // stdout sample; the FULL surplus list always goes to [outfile] |
| 39 | const SD_SURCAP: i64 = 4096 // surplus lines retained per side for the pairing measurement |
| 40 | const SD_PAIR_PERMIL: i64 = 700 // token-containment bar for a one-to-one modification pair |
| 41 | const SD_LF: i64 = 10 |
| 42 | const SD_CR: i64 = 13 |
functions
| 56 | func sd_puts(s: *u8) -> i64 |
| 62 | func sd_putn(v: i64) -> i64 |
| 73 | func sd_streq(a: *u8, b: *u8) -> i64 |
| 84 | func sd_hash(s: *u8) -> i64 |
| 96 | func sd_add(keys: *i64, counts: *i64, line: *u8) -> i64 |
| 111 | func sd_get(keys: *i64, counts: *i64, line: *u8) -> i64 |
| 121 | func sd_emit(tag: *u8, n: i64, line: *u8) -> i64 called by 1: main |
| 145 | func sd_sample(tag: *u8, n: i64, line: *u8) -> i64 |
| 158 | func sd_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 177 | func sd_is_sp(c: i64) -> i64 called by 1: sd_contain |
| 184 | func sd_has_sub(hay: *u8, b: *u8, bs: i64, bl: i64) -> i64 |
| 199 | func sd_contain(a: *u8, b: *u8) -> i64 |
| 233 | func sd_load(buf: *u8, n: i64, keys: *i64, counts: *i64, cslot: i64, lslot: i64) -> i64 |
| 270 | func main(argc: i64, argv: *i64) -> i64 |