code wiki / (root) / nx_argcall_repro.nx

nx_argcall_repro.nx source

↩ module page · 66 lines · 2530 B

1// nx_argcall_repro.nx -- MINIMAL fast repro of the chat-template crash: a 10-arg function 2// (same arg SHAPE as tk_bpe_encode: buf, 4 array-subscript i64s, a string-literal *u8, an ilen, 3// 2 scratch *i64, an out *i64) called TWICE in one function. No model load -> iterate in seconds. 4// If the 2nd call crashes/miscompiles, the bug is call-site codegen for repeated 10-arg calls 5// (eat-the-debt: root-fix nx_cc). If both calls print correct sums, the bug is in tk_bpe_encode's 6// body under 2nd-call conditions instead. 7// license_tier: ORIGINAL expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_lib_std.nx" 10const K_MAGIC_16384: i64 = 16384 11const K_MAGIC_4096: i64 = 4096 12 13func rp_enc(buf: *u8, a: i64, b: i64, c: i64, d: i64, input: *u8, ilen: i64, p: *i64, q: *i64, ids: *i64) -> i64 { 14 var i: i64 = 0 15 while i < ilen { 16 let ch: i64 = input[i] as i64 17 p[i] = ch 18 q[i] = ch + a 19 ids[i] = ch + a + b + c + d 20 i = i + 1 21 } 22 return ilen 23} 24 25func main(argc: i64, argv: *i64) -> i64 { 26 let mt: *i64 = sys_mmap(64) as *i64 27 mt[0] = 1 28 mt[1] = 2 29 mt[2] = 3 30 mt[3] = 4 31 let buf: *u8 = sys_mmap(64) as *u8 32 let p: *i64 = sys_mmap(K_MAGIC_16384) as *i64 33 let q: *i64 = sys_mmap(K_MAGIC_16384) as *i64 34 let ids: *i64 = sys_mmap(K_MAGIC_16384) as *i64 35 // build an 805-byte content buffer (like the real crib+task) 36 let content: *u8 = sys_mmap(K_MAGIC_4096) as *u8 37 var k: i64 = 0 38 while k < 805 { content[k] = (65 + (k % 26)) as u8; k = k + 1 } 39 content[805] = 0 as u8 40 // 1st call: short literal input (like "user\n", 5 bytes) -- mirrors nsv_chatml_ids 41 std_puts("R1 before-call-1\n" as *u8) 42 let n1: i64 = rp_enc(buf, mt[0], mt[1], mt[2], mt[3], "user\n" as *u8, 5, p, q, ids) 43 std_puts("R2 after-call-1 n1=" as *u8) 44 std_pdec(n1) 45 std_puts(" ids0=" as *u8) 46 std_pdec(ids[0]) 47 std_puts("\n" as *u8) 48 // 2nd call: 805-byte content (the exact shape that crashed in nsv_chatml_ids) 49 std_puts("R3 before-call-2\n" as *u8) 50 let n2: i64 = rp_enc(buf, mt[0], mt[1], mt[2], mt[3], content, 805, p, q, ids) 51 std_puts("R4 after-call-2 n2=" as *u8) 52 std_pdec(n2) 53 std_puts(" ids804=" as *u8) 54 std_pdec(ids[804]) 55 std_puts("\n" as *u8) 56 if n1 == 5 { 57 if n2 == 805 { 58 std_putln("ARGCALL-REPRO PASS (no crash, both calls correct)" as *u8) 59 sys_exit(0) 60 return 0 61 } 62 } 63 std_putln("ARGCALL-REPRO FAIL (wrong counts)" as *u8) 64 sys_exit(1) 65 return 1 66}