code wiki / _hdl_build / nx_engineer_build_gate.nx

nx_engineer_build_gate.nx source

↩ module page · 69 lines · 3962 B

1// nx_engineer_build_gate.nx -- the ENGINEER's MANAGED build: the four-pillar miscompile 2// discipline as ONE standing step, owned by the Engineer historically and going forward, so 3// nobody hand-works-around the register-pressure miscompile again. For any source it runs, 4// in <10ms, the whole pipeline and IGNORES NOTHING: 5// PILLAR 1 GUARD eng_compile_diag -- compile; loud-fail on rc!=0 or empty .s 6// PILLAR 2 PROBE eng_asm_scan -- scan the EMITTED machine code for the live-across- 7// call caller-saved clobber (the miscompile, where it lives) 8// PILLAR 3 HEAL doc_asm_fix -- if found, the Doctor spills/reloads it, additively 9// into a NEW .s (the protected source is untouched) 10// PILLAR 4 VERIFY eng_link+eng_run -- link the (healed) asm and run; classify the outcome 11// Verdicts: COMPILE-FAIL / LINK-FAIL / CRASH(signal) / FAIL(exit) / PASS. out[0]=#regs the 12// Doctor healed, out[1]=signal or exit code. RACI: Engineer detects+verifies, Doctor heals, 13// nobody blesses their own fix. license_tier: ORIGINAL 14 15import "nx_engineer_crash.nx" // GUARD + VERIFY (eng_compile_diag, eng_link, eng_run, eng_crashed, eng_signal) 16import "nx_eng_asm_scan.nx" // PROBE (eng_asm_scan) 17import "nx_doctor_asm_fix.nx" // HEAL (doc_asm_fix) 18 19const EBG_PASS: i64 = 0 20const EBG_COMPILE_FAIL: i64 = 1 21const EBG_LINK_FAIL: i64 = 2 22const EBG_CRASH: i64 = 3 23const EBG_FAIL: i64 = 4 24 25// THE root cause, found ignore-nothing: the known-good compiler is NON-DETERMINISTIC -- 26// the SAME source compiled twice produces DIFFERENT assembly, so the register-pressure 27// miscompile appears INTERMITTENTLY (a given compile may or may not clobber a value held 28// across a call). That makes the reliable, SAFE managed heal a RECOMPILE-RETRY: on a run 29// failure, recompile (a fresh allocation usually emits correct code) and re-verify; a real 30// deterministic bug fails every recompile and is reported honestly. (The asm-scan/Doctor 31// heal is kept as a deeper fallback, but its probe has FALSE POSITIVES on real code -- it 32// once crashed a correct u128 test by blanket-spilling 53 "live" regs -- so it runs LAST.) 33// out[2] = recompiles used; out[0] = asm-heal regs; out[1] = signal/exit on honest failure. 34func eng_build_gate(compiler: *u8, src: *u8, sout: *u8, healed: *u8, eout: *u8, capf: *u8, out: *i64) -> i64 { 35 out[0] = 0; out[1] = 0; out[2] = 0 36 var attempt: i64 = 0 37 var rc: i64 = 0 38 while attempt < 4 { 39 if eng_compile_diag(compiler, src, sout, "/tmp/ebg.err" as *u8) < 0 { return EBG_COMPILE_FAIL } // deterministic, retry won't help 40 if eng_link(sout, eout) != 0 { return EBG_LINK_FAIL } 41 rc = eng_run(eout, capf) 42 if eng_crashed(rc) == 0 { if rc == 0 { out[2] = attempt; return EBG_PASS } } // works (maybe after a recompile) 43 attempt = attempt + 1 // intermittent miscompile -> RECOMPILE and retry 44 } 45 out[2] = attempt 46 47 // still failing after recompiles -> deeper fallback: probe + Doctor heal (last resort). 48 let fr: *i64 = sys_mmap(8 * 64) as *i64 49 let fl: *i64 = sys_mmap(8 * 64) as *i64 50 let nf: i64 = eng_asm_scan(sout, fr, fl) 51 if nf > 0 { 52 doc_asm_fix(sout, healed, fr, fl, nf) 53 if eng_link(healed, eout) == 0 { 54 let rc2: i64 = eng_run(eout, capf) 55 if eng_crashed(rc2) == 0 { if rc2 == 0 { out[0] = nf; return EBG_PASS } } 56 } 57 } 58 if eng_crashed(rc) == 1 { out[1] = eng_signal(rc); return EBG_CRASH } 59 if rc != 0 { out[1] = rc; return EBG_FAIL } 60 return EBG_PASS 61} 62 63func ebg_verdict_name(v: i64) -> *u8 { 64 if v == EBG_PASS { return "PASS" as *u8 } 65 if v == EBG_COMPILE_FAIL { return "COMPILE-FAIL" as *u8 } 66 if v == EBG_LINK_FAIL { return "LINK-FAIL" as *u8 } 67 if v == EBG_CRASH { return "CRASH" as *u8 } 68 return "FAIL" as *u8 69}