code wiki / _hdl_build / nx_elseif_desync_probe.nx
nx_elseif_desync_probe.nx source
↩ module page · 50 lines · 2012 B
1// nx_elseif_desync_probe.nx -- PROBE for debt seq358 "else-if branch with MULTILINE body desyncs
2// nx_parse: subsequent funcs FUSE into the current one as empty stubs -> binary compiles clean and
3// exits 0 SILENTLY doing nothing". Same live-or-fixed oracle as the landmine probes.
4// CONTRACT: exit 0 => ROOT-FIXED; non-zero OR build-failure (bogus arity error) => STILL LIVE.
5// The discriminator: `second` is DEFINED AFTER a func that ends in an else-if with a multiline body,
6// and `second` takes >=1 arg (the debt says the arity check surfaces the desync only then). If the
7// desync is live, `second` fuses into `first` as statements and is emitted as an empty stub returning
8// 0, so second(5) != 105.
9// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
10import "nx_syscalls.nx"
11import "nx_estr.nx"
12
13// ends in an else-if whose body is genuinely MULTILINE (several statements)
14func first(x: i64) -> i64 {
15 var r: i64 = 0
16 if x == 1 {
17 r = 10
18 } else if x == 2 {
19 r = 20
20 r = r + 1
21 r = r + 0
22 } else {
23 r = 30
24 }
25 return r
26}
27
28// DEFINED IMMEDIATELY AFTER first(): if the parser desynced, this fuses into first as statements and
29// is emitted as an empty stub. Takes 1 arg (the arity-surfacing condition from seq358).
30func second(y: i64) -> i64 {
31 return y + 100
32}
33
34func main() -> i64 {
35 var bad: i64 = 0
36 if first(1) != 10 { bad = bad + 1 }
37 if first(2) != 21 { bad = bad + 1 }
38 if first(3) != 30 { bad = bad + 1 }
39 // THE DISCRIMINATOR: second() must actually run. A fused-away empty stub returns 0.
40 if second(5) != 105 { bad = bad + 1 }
41 if second(0) != 100 { bad = bad + 1 }
42 if bad != 0 {
43 es_puts("SEQ358 STILL-LIVE (else-if multiline desync: second() got " as *u8); es_putn(second(5))
44 es_puts(" want 105)\n" as *u8)
45 sys_exit(1); return 1
46 }
47 es_puts("SEQ358 ROOT-FIXED (else-if multiline body does NOT desync the next function)\n" as *u8)
48 sys_exit(0)
49 return 0
50}