code wiki / _hdl_build / nx_collision_retire_safe.nx
nx_collision_retire_safe.nx source
↩ module page · 67 lines · 4451 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_collision_retire_safe.nx -- the EXECUTOR for the unambiguously-safe collision class. Composes the
4// proposer (nx_collision_plan.crp_plan_one) + the reversible retire (nx_janitor_retire.jan_retire): walks
5// every shadow, and ONLY for the RETIRE_A_SUBSET class (code 2: the runtime copy's func-set is a strict
6// SUBSET of the _hdl_build copy that already runs = pure redundancy) it retires the shadowed runtime copy.
7// Safe by construction, layered:
8// - the runtime copy is UNREACHABLE anyway (runner probes _hdl_build first) -> retiring removes nothing live;
9// - jan_retire REFUSES unless the bytes are byte-verified in the store -> never lose data (#13);
10// - the move is to fenced runtime/_retired/ via renameat, jan_unretire-reversible -> never-brick (#26);
11// - TOOLCHAIN organs (nx_link/nx_asm/nx_cc) are skipped regardless -> never risk the build;
12// - RENAME_DISTINCT / MERGE_UNION are NOT touched here (they need naming/merge judgment) -> no lost capability.
13// - idempotent (#10): a second run finds the file already moved -> jan_retire refuses -> skipped.
14// This DROPS the live collision count; re-run nx_capability_shape_audit + nx_capability_no_regression_check to
15// prove the ceiling ratcheted DOWN with the floor held. expect_exit: 0 license_tier: ORIGINAL
16import "nx_collision_plan.nx"
17import "nx_janitor_dupname.nx"
18import "nx_janitor_retire.nx"
19import "nx_syscalls.nx"
20const RET_MAGIC_1048576: i64 = 1048576
21const RET_MAGIC_131072: i64 = 131072
22const RET_MAGIC_4096: i64 = 4096
23const RET_MAGIC_4194304: i64 = 4194304
24const RET_MAGIC_32768: i64 = 32768
25const RET_MAGIC_1024: i64 = 1024
26
27func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
28" as *u8); return ok }
29func gws(buf: *u8, off: i64) -> i64 { var n: i64=0; while buf[off+n]!=(0 as u8){n=n+1} sys_write(1, (buf as i64 + off) as *u8, n); return 0 }
30
31const RET_STORE: *u8 = "knowledge/store/retired-organs"
32
33func main() -> i64 {
34 gw("=== nx_collision_retire_safe: retire the redundant (RETIRE_A_SUBSET) shadows, reversibly ===\n" as *u8)
35 let ba: *u8=sys_mmap(RET_MAGIC_1048576); let bb: *u8=sys_mmap(RET_MAGIC_1048576)
36 let na: *u8=sys_mmap(RET_MAGIC_131072); let oa: *i64=sys_mmap(8*RET_MAGIC_4096) as *i64
37 let nb: *u8=sys_mmap(RET_MAGIC_131072); let ob: *i64=sys_mmap(8*RET_MAGIC_4096) as *i64
38 let out: *i64=sys_mmap(64) as *i64
39 let fnames: *u8=sys_mmap(RET_MAGIC_4194304); let fnoff: *i64=sys_mmap(8*RET_MAGIC_32768) as *i64; let hc: *i64=sys_mmap(16) as *i64
40 let NF: i64 = jdn_scan(fnames, fnoff, hc)
41
42 var considered: i64=0; var retired: i64=0; var refused: i64=0; var tool_skip: i64=0
43 var i: i64=hc[0]
44 while i<NF {
45 if jdn_is_shadowed(fnames, fnoff, i, hc[0])==1 {
46 let nm: *u8 = (fnames as i64 + fnoff[i]) as *u8
47 let code: i64 = crp_plan_one(nm, ba,bb,na,oa,nb,ob, out)
48 if code==2 {
49 if crp_is_toolchain(nm)==1 {
50 tool_skip=tool_skip+1; gw(" SKIP (toolchain): \x00" as *u8); gws(fnames, fnoff[i]); gw("\n" as *u8)
51 } else {
52 considered=considered+1
53 let src: *u8=sys_mmap(RET_MAGIC_1024); jdn_path("runtime/\x00" as *u8, nm, src)
54 let r: i64 = jan_retire(src, RET_STORE)
55 if r==1 { retired=retired+1; gw(" RETIRED -> runtime/_retired/: \x00" as *u8); gws(fnames, fnoff[i]); gw(" (backed up + reversible)\n" as *u8) }
56 else { refused=refused+1; gw(" REFUSED (not backed up / already retired): \x00" as *u8); gws(fnames, fnoff[i]); gw("\n" as *u8) }
57 }
58 }
59 }
60 i=i+1
61 }
62 gw(" RETIRE_A_SUBSET considered=\x00" as *u8); gn(considered); gw(" retired=\x00" as *u8); gn(retired); gw(" refused=\x00" as *u8); gn(refused); gw(" toolchain-skipped=\x00" as *u8); gn(tool_skip); gw("\n" as *u8)
63 gw(" never-brick(#26)/additive(#13): MOVE to fenced _retired/ (no delete), byte-verified first, jan_unretire-reversible.\n" as *u8)
64 if retired>0 { gw("=== COLLISIONS DROPPED by \x00" as *u8); gn(retired); gw(" -- re-run nx_capability_shape_audit + nx_capability_no_regression_check to prove the ceiling ratchets DOWN.\n" as *u8) }
65 else { gw("=== nothing to retire (already clean or none in the redundant class).\n" as *u8) }
66 sys_exit(0); return 0
67}