code wiki / _hdl_build / nx_engineer_wire.nx
nx_engineer_wire.nx source
↩ module page · 41 lines · 2298 B
1// nx_engineer_wire.nx -- the ENGINEER's WIRING capability (operator: "if we need wiring we need the
2// engineer to have a wiring capability"). Wiring = swap component X for component Y at a call site, then
3// CERTIFY the wired system before accepting it. A swap is admissible only if it is NON-REGRESSING (every
4// case the old component handled, the new one still handles -- rule 19 contract stability) and ideally
5// IMPROVING (fixes at least one case the old got wrong). A swap that breaks anything is REJECTED, never
6// wired. The Engineer runs both components over a labelled case set and returns the verdict; the Council
7// only admits a safe wiring. RACI: Engineer certifies, Council admits, Builder/Researcher supplied the
8// new component. license_tier: ORIGINAL
9
10import "nx_syscalls.nx"
11
12const EW_REGRESS: i64 = 0 // the new component broke a case the old one handled -> REJECT
13const EW_NEUTRAL: i64 = 1 // non-regressing but no improvement -> optional
14const EW_OK: i64 = 2 // non-regressing AND fixes >=1 case -> WIRE IT
15
16// the new component must cover every call site the old one served (completeness of the swap).
17func ew_coverage_ok(old_served: i64, new_served: i64) -> i64 { if new_served >= old_served { return 1 } return 0 }
18
19// cases the old component got RIGHT but the new one gets WRONG -- the regressions a wiring must not add.
20func ew_regressions(n: i64, old_correct: *i64, new_correct: *i64) -> i64 {
21 var c: i64 = 0; var i: i64 = 0
22 while i < n { if old_correct[i] == 1 { if new_correct[i] == 0 { c = c + 1 } } i = i + 1 }
23 return c
24}
25
26// cases the new component FIXES (old wrong, new right) -- the reason to wire it.
27func ew_improvements(n: i64, old_correct: *i64, new_correct: *i64) -> i64 {
28 var c: i64 = 0; var i: i64 = 0
29 while i < n { if old_correct[i] == 0 { if new_correct[i] == 1 { c = c + 1 } } i = i + 1 }
30 return c
31}
32
33// the wiring verdict: any regression dominates (reject); else improvement -> OK; else neutral.
34func ew_verdict(regressions: i64, improvements: i64) -> i64 {
35 if regressions > 0 { return EW_REGRESS }
36 if improvements > 0 { return EW_OK }
37 return EW_NEUTRAL
38}
39
40// is it safe to wire? never wire a regression.
41func ew_safe_to_wire(verdict: i64) -> i64 { if verdict == EW_REGRESS { return 0 } return 1 }