code wiki / _hdl_build / nx_build_safe.nx
nx_build_safe.nx source
↩ module page · 44 lines · 2601 B
1// nx_build_safe.nx -- the Engineer's HANG-SAFE build capability (operator: keep building the team to
2// handle this). Even with the G2 compiler FOUND, the codegen HANGS on a huge program (the TLS daemon:
3// the background build produced 0 bytes of asm after minutes). The compiler is also non-deterministic
4// (a retry may pass) and can miscompile. So a robust build must: compile under a TIMEOUT; classify each
5// attempt (OK / HANG / ERROR); RETRY the same compiler (non-determinism); ESCALATE to an alternative
6// compiler after repeated hangs; and -- crucially -- never report a false success (an empty/hung build
7// is HANG, not OK), giving an HONEST EXHAUSTED verdict if nothing produces a runnable artifact.
8// This is what the memory's nx_run_timeout + recompile-retry discipline becomes as a first-class
9// capability. license_tier: ORIGINAL Pairs with nx_build_gate + the Engineer's eng_build_gate.
10
11import "nx_syscalls.nx"
12
13const BS_OK: i64 = 0 // compiled + linked to a non-empty runnable artifact
14const BS_HANG: i64 = 1 // timed out / produced no asm -> codegen hung
15const BS_ERROR: i64 = 2 // compiled but link/asm failed
16const BS_EXHAUSTED: i64 = 3 // retries + escalation exhausted -> honest give-up (NOT a false success)
17
18// classify ONE build attempt. an empty/timed-out build is a HANG, never silently 'ok'.
19func bs_attempt(timed_out: i64, asm_bytes: i64, link_ok: i64) -> i64 {
20 if timed_out == 1 { return BS_HANG }
21 if asm_bytes <= 0 { return BS_HANG }
22 if link_ok != 1 { return BS_ERROR }
23 return BS_OK
24}
25
26// retry the SAME compiler? the non-deterministic compiler may pass on a later attempt.
27func bs_should_retry(verdict: i64, attempts: i64, max_attempts: i64) -> i64 {
28 if verdict == BS_OK { return 0 }
29 if attempts >= max_attempts { return 0 }
30 return 1
31}
32
33// escalate to an ALTERNATIVE compiler after `threshold` hangs on the current one.
34func bs_should_escalate(hangs_on_current: i64, threshold: i64) -> i64 { if hangs_on_current >= threshold { return 1 } return 0 }
35
36// final outcome after the retry/escalate loop -- OK only if some attempt actually produced a runnable artifact.
37func bs_final(any_ok: i64) -> i64 { if any_ok == 1 { return BS_OK } return BS_EXHAUSTED }
38
39// did we honestly avoid a FALSE success? (an exhausted build must report failure, not pretend it built)
40func bs_no_false_success(final_verdict: i64, any_runnable: i64) -> i64 {
41 if final_verdict == BS_OK { if any_runnable == 1 { return 1 } return 0 }
42 if final_verdict == BS_EXHAUSTED { if any_runnable == 0 { return 1 } return 0 }
43 return 1
44}