nx_retire_onto_lib.nx
buildroot/runtime/nx_retire_onto_lib.nx
about
nx_retire_onto_lib.nx -- RETIRE A PRIVATE FUNCTION ONTO ITS SHARED OWNER, function side (global tooling,
2026-08-24, born on procgen PG2).
WHY THIS EXISTS: the library plane's first census (nx_libindex find isqrt) returned 106 of 5,517 libraries
carrying a private isqrt beside nx_vecmath's gate-proven vm_isqrt, and nx_nxa_fk carrying quaternion
primitives beside vm_q_*. nx_oo_extract moves BYTE-IDENTICAL bodies into one lib; these bodies are not
identical -- each is its own hand-rolled Newton loop -- so the move is "keep the private NAME, replace the
BODY with one call to the owner". That was done by hand for eight files earlier the same day. A hand edit
repeated 106 times is the class of work an organ exists for, and a hand edit is also the class of work
that silently half-lands (the estate's str.replace law).
WHAT IT DOES: rewrites func <private>(<params>) -> <ret> { ... }
to func <private>(<params>) -> <ret> { return <owner>(<param names>) }
and inserts `import "<owner_lib basename>"` after the LAST import line when it is absent (before the first
top-level func/const when the file has no imports). Brace matching SKIPS string literals and line comments,
so a `}` inside a string or a comment cannot end the body early -- the gate plants exactly that.
WHAT IT REFUSES, BY NAME: the function is absent or malformed; the owner lib is unreadable or lacks the
owner function; arity, any parameter TYPE, or the return type differ; the file IS the owner lib. A refusal
writes nothing. Idempotent: a body that already is the one-line delegation reports ALREADY and writes
nothing, so a sweep can be re-run after a partial apply and the partition still sums.
WHAT IT DOES NOT DO: prove behaviour. The proof lane is the consumer's rebuild plus the consumer's own gates
on the roster. An exact floor replacing a capped Newton loop is a NAMED delta, never a silent one, and the
name of it is printed on the APPLIED line.
NO SILENT CAPS: files are read whole through sys_read_file (sized from the file); the only bounded buffers
are a pattern scratch (RO_PAT_CAP, sized for "func <name>(" and `import "<basename>"`) and the parameter
table (RO_MAX_PARAMS -- a function with more parameters than that REFUSES by name rather than truncating).
license_tier: ORIGINAL
dependencies 3 imports · 2 importers
imports: nx_syscalls.nxnx_store_seed_lib.nxnx_gatekit_lib.nx
imported by: nx_retire_onto.nxnx_retire_onto_gate.nx
structs
| none |
consts
| 45 | const RO_PROBE_DENSE: i64 = 1048576 |
| 48 | const RO_PROBE_MS: i64 = 60000 |
| 49 | const RO_BUILD_MS: i64 = 300000 |
| 50 | const RO_PROBE_OUTCAP: i64 = 65536 |
| 51 | const RO_PROBE_SRC_CAP: i64 = 4096 |
| 53 | const RO_PROBE_PATH_CAP: i64 = 4096 |
| 54 | const RO_PROVE_PASS: i64 = 1 |
| 55 | const RO_PROVE_DIFFER: i64 = 0 |
| 56 | const RO_PROVE_UNBUILDABLE: i64 = 0 - 1 |
| 57 | const RO_PROVE_UNSUPPORTED: i64 = 0 - 2 |
| 58 | const RO_PROVE_NOROOT: i64 = 0 - 3 |
| 61 | const RO_PROVE_ADMISSION: i64 = 0 - 4 |
| 63 | const RO_SYS_OPENAT: i64 = 257 |
| 69 | const RO_SYS_GETPID: i64 = 172 |
| 70 | const RO_AT_FDCWD: i64 = 0 - 100 |
| 71 | const RO_O_WRONLY_CREAT_TRUNC: i64 = 0x241 |
| 72 | const RO_MODE_644: i64 = 420 |
| 73 | const RO_NL: i64 = 10 |
| 74 | const RO_CR: i64 = 13 |
| 75 | const RO_TAB: i64 = 9 |
| 76 | const RO_SP: i64 = 32 |
| 77 | const RO_LPAREN: i64 = 40 |
| 78 | const RO_RPAREN: i64 = 41 |
| 79 | const RO_LBRACE: i64 = 123 |
| 80 | const RO_RBRACE: i64 = 125 |
| 81 | const RO_COMMA: i64 = 44 |
| 82 | const RO_COLON: i64 = 58 |
| 83 | const RO_QUOTE: i64 = 34 |
| 84 | const RO_BSLASH: i64 = 92 |
| 85 | const RO_SLASH: i64 = 47 |
| 86 | const RO_MAX_PARAMS: i64 = 16 |
| 87 | const RO_P_STRIDE: i64 = 4 |
| 89 | const RO_PAT_CAP: i64 = 512 |
| 90 | const RO_PATH_CAP: i64 = 1024 |
| 93 | const RO_OUT_SLACK: i64 = 2 * RO_PAT_CAP |
| 98 | const RO_RETIRABLE: i64 = 0 |
| 99 | const RO_ALREADY: i64 = 1 |
| 100 | const RO_REFUSED: i64 = 2 |
| 101 | const RO_APPLIED: i64 = 3 |
| 102 | const RO_PROVEN: i64 = 4 |
| 103 | const RO_REFUSED_DIFFER: i64 = 5 |
| 104 | const RO_REFUSED_UNBUILDABLE: i64 = 6 |
| 105 | const RO_REFUSED_UNSUPPORTED: i64 = 7 |
| 106 | const RO_DEFERRED_ADMISSION: i64 = 8 |
| 107 | const RO_CODES: i64 = 9 |
| 109 | const RO_MODE_DRY: i64 = 0 |
| 110 | const RO_MODE_PROVE: i64 = 1 |
| 111 | const RO_MODE_APPLY: i64 = 2 |
| 114 | const RO_L_FSTART: i64 = 0 |
| 115 | const RO_L_PSTART: i64 = 1 |
| 116 | const RO_L_PEND: i64 = 2 |
| 117 | const RO_L_BOPEN: i64 = 3 |
| 118 | const RO_L_BCLOSE: i64 = 4 |
| 119 | const RO_L_RSTART: i64 = 5 |
| 120 | const RO_L_REND: i64 = 6 |
| 121 | const RO_L_N: i64 = 8 |
| 124 | const RO_T_CAND: i64 = 9 |
| 125 | const RO_T_N: i64 = 11 |
| 569 | const RO_LADDER2_N: i64 = 49 |
functions
| 127 | func ro_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 128 | func ro_w(fd: i64, s: *u8) -> i64 { let n: i64 = ro_slen(s); if n > 0 { sys_write(fd, s, n) } return 0 } |
| 129 | func ro_out(s: *u8) -> i64 { return ro_w(1, s) } |
| 130 | func ro_num(v0: i64) -> i64 |
| 146 | func ro_is_ws(c: i64) -> i64 { if c == RO_SP { return 1 } if c == RO_TAB { return 1 } if c == RO_NL { return 1 } if c == RO_CR { return 1 } return 0 } |
| 147 | func ro_streq(a: *u8, b: *u8) -> i64 |
| 155 | func ro_find(buf: *u8, n: i64, from: i64, pat: *u8) -> i64 |
| 169 | func ro_find_bol(buf: *u8, n: i64, pat: *u8) -> i64 |
| 183 | func ro_count(buf: *u8, n: i64, pat: *u8) -> i64 |
| 194 | func ro_span_eq(a: *u8, ao: i64, al: i64, b: *u8, bo: i64, bl: i64) -> i64 |
| 200 | func ro_ends_with(buf: *u8, s: i64, e: i64, suffix: *u8) -> i64 |
| 205 | func ro_trim_start(buf: *u8, s: i64, e: i64) -> i64 |
| 210 | func ro_trim_end(buf: *u8, s: i64, e: i64) -> i64 |
| 215 | func ro_basename(p: *u8) -> *u8 |
| 223 | func ro_mk_pat(pat: *u8, name: *u8) -> i64 |
| 236 | func ro_mk_import(pat: *u8, lib: *u8) -> i64 |
| 250 | func ro_skip_str(buf: *u8, n: i64, i0: i64) -> i64 called by 1: ro_locate |
| 264 | func ro_skip_comment(buf: *u8, n: i64, i0: i64) -> i64 called by 1: ro_locate |
| 272 | func ro_locate(buf: *u8, n: i64, name: *u8, loc: *i64) -> i64 |
| 330 | func ro_params(buf: *u8, ps: i64, pe: i64, prm: *i64) -> i64 |
| 364 | func ro_emit(out: *u8, o0: i64, s: *u8) -> i64 |
| 372 | func ro_import_slot(buf: *u8, n: i64) -> i64 |
| 398 | func ro_compose(buf: *u8, n: i64, loc: *i64, prm: *i64, np: i64, owner_fn: *u8, libname: *u8, out: *u8, import_added: *i64) -> i64 |
| 435 | func ro_report(path: *u8, fname: *u8, verdict: *u8, code: i64, quiet: i64) -> i64 |
| 445 | func ro_rt_eq(a: *u8, la: *i64, b: *u8, lb: *i64) -> i64 |
| 452 | func ro_probe_name(out: *u8, fname: *u8) -> i64 |
| 464 | func ro_probe_paths(name: *u8, src: *u8, elf: *u8, builder: *u8) -> i64 |
| 494 | func ro_probe_side(elf: *u8, suffix: *u8, out: *u8) -> i64 |
| 505 | func ro_probe_clean(elf: *u8) -> i64 |
| 515 | func ro_probe_src(out: *u8, cand_base: *u8, owner_base: *u8, fname: *u8, owner_fn: *u8) -> i64 |
| 539 | func ro_emit_num(out: *u8, o0: i64, v0: i64) -> i64 |
| 559 | func ro_build_rc_class(out: *u8, n: i64, rc: i64) -> i64 |
| 570 | func ro_probe_src2(out: *u8, cand_base: *u8, owner_base: *u8, fname: *u8, owner_fn: *u8) -> i64 |
| 588 | func ro_prove(path: *u8, fname: *u8, lib: *u8, owner_fn: *u8, np: i64, buf: *u8, prm: *i64, loc: *i64) -> i64 |
| 626 | func ro_one(path: *u8, fname: *u8, lib: *u8, owner_fn: *u8, mode: i64, quiet: i64) -> i64 |
| 701 | func ro_sweep(prefix: *u8, suffix: *u8, lib: *u8, owner_fn: *u8, mode: i64, tally: *i64) -> i64 |