code wiki / (root) / nx_retire_onto_lib.nx

nx_retire_onto_lib.nx

buildroot/runtime/nx_retire_onto_lib.nx

40066 B787 linesdepth 5pulls 7 transitivereach 2 importersview sourcekind librarytopic retire
docsdependenciesstructsconstsfunctions

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

nx_syscalls.nx nx_store_seed_lib.nx nx_gatekit_lib.nx nx_retire_onto_lib.nx nx_retire_onto.nx nx_retire_onto_gate.nx

imports: nx_syscalls.nxnx_store_seed_lib.nxnx_gatekit_lib.nx

imported by: nx_retire_onto.nxnx_retire_onto_gate.nx

structs

none

consts

45const RO_PROBE_DENSE: i64 = 1048576
48const RO_PROBE_MS: i64 = 60000
49const RO_BUILD_MS: i64 = 300000
50const RO_PROBE_OUTCAP: i64 = 65536
51const RO_PROBE_SRC_CAP: i64 = 4096
53const RO_PROBE_PATH_CAP: i64 = 4096
54const RO_PROVE_PASS: i64 = 1
55const RO_PROVE_DIFFER: i64 = 0
56const RO_PROVE_UNBUILDABLE: i64 = 0 - 1
57const RO_PROVE_UNSUPPORTED: i64 = 0 - 2
58const RO_PROVE_NOROOT: i64 = 0 - 3
61const RO_PROVE_ADMISSION: i64 = 0 - 4
63const RO_SYS_OPENAT: i64 = 257
69const RO_SYS_GETPID: i64 = 172
70const RO_AT_FDCWD: i64 = 0 - 100
71const RO_O_WRONLY_CREAT_TRUNC: i64 = 0x241
72const RO_MODE_644: i64 = 420
73const RO_NL: i64 = 10
74const RO_CR: i64 = 13
75const RO_TAB: i64 = 9
76const RO_SP: i64 = 32
77const RO_LPAREN: i64 = 40
78const RO_RPAREN: i64 = 41
79const RO_LBRACE: i64 = 123
80const RO_RBRACE: i64 = 125
81const RO_COMMA: i64 = 44
82const RO_COLON: i64 = 58
83const RO_QUOTE: i64 = 34
84const RO_BSLASH: i64 = 92
85const RO_SLASH: i64 = 47
86const RO_MAX_PARAMS: i64 = 16
87const RO_P_STRIDE: i64 = 4
89const RO_PAT_CAP: i64 = 512
90const RO_PATH_CAP: i64 = 1024
93const RO_OUT_SLACK: i64 = 2 * RO_PAT_CAP
98const RO_RETIRABLE: i64 = 0
99const RO_ALREADY: i64 = 1
100const RO_REFUSED: i64 = 2
101const RO_APPLIED: i64 = 3
102const RO_PROVEN: i64 = 4
103const RO_REFUSED_DIFFER: i64 = 5
104const RO_REFUSED_UNBUILDABLE: i64 = 6
105const RO_REFUSED_UNSUPPORTED: i64 = 7
106const RO_DEFERRED_ADMISSION: i64 = 8
107const RO_CODES: i64 = 9
109const RO_MODE_DRY: i64 = 0
110const RO_MODE_PROVE: i64 = 1
111const RO_MODE_APPLY: i64 = 2
114const RO_L_FSTART: i64 = 0
115const RO_L_PSTART: i64 = 1
116const RO_L_PEND: i64 = 2
117const RO_L_BOPEN: i64 = 3
118const RO_L_BCLOSE: i64 = 4
119const RO_L_RSTART: i64 = 5
120const RO_L_REND: i64 = 6
121const RO_L_N: i64 = 8
124const RO_T_CAND: i64 = 9
125const RO_T_N: i64 = 11
569const RO_LADDER2_N: i64 = 49

functions

127func ro_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
128func ro_w(fd: i64, s: *u8) -> i64 { let n: i64 = ro_slen(s); if n > 0 { sys_write(fd, s, n) } return 0 }
called by 1: ro_out calls 2: ro_slensys_write
129func ro_out(s: *u8) -> i64 { return ro_w(1, s) }
130func ro_num(v0: i64) -> i64
146func 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 }
147func ro_streq(a: *u8, b: *u8) -> i64
called by 3: mainro_onero_sweep
155func ro_find(buf: *u8, n: i64, from: i64, pat: *u8) -> i64
169func ro_find_bol(buf: *u8, n: i64, pat: *u8) -> i64
called by 2: ro_locatero_import_slot calls 1: ro_find
183func ro_count(buf: *u8, n: i64, pat: *u8) -> i64
called by 1: vrg_broken_src calls 1: ro_find
194func ro_span_eq(a: *u8, ao: i64, al: i64, b: *u8, bo: i64, bl: i64) -> i64
200func ro_ends_with(buf: *u8, s: i64, e: i64, suffix: *u8) -> i64
called by 1: ro_sweep calls 2: ro_slenro_span_eq
205func ro_trim_start(buf: *u8, s: i64, e: i64) -> i64
called by 2: ro_locatero_params calls 1: ro_is_ws
210func ro_trim_end(buf: *u8, s: i64, e: i64) -> i64
called by 2: ro_locatero_params calls 1: ro_is_ws
215func ro_basename(p: *u8) -> *u8
223func ro_mk_pat(pat: *u8, name: *u8) -> i64
called by 1: ro_locate calls 1: ro_slen
236func ro_mk_import(pat: *u8, lib: *u8) -> i64
called by 1: ro_compose calls 1: ro_slen
250func ro_skip_str(buf: *u8, n: i64, i0: i64) -> i64
called by 1: ro_locate
264func ro_skip_comment(buf: *u8, n: i64, i0: i64) -> i64
called by 1: ro_locate
272func ro_locate(buf: *u8, n: i64, name: *u8, loc: *i64) -> i64
330func ro_params(buf: *u8, ps: i64, pe: i64, prm: *i64) -> i64
called by 1: ro_one calls 2: ro_trim_startro_trim_end
364func ro_emit(out: *u8, o0: i64, s: *u8) -> i64
372func ro_import_slot(buf: *u8, n: i64) -> i64
called by 1: ro_compose calls 2: ro_findro_find_bol
398func ro_compose(buf: *u8, n: i64, loc: *i64, prm: *i64, np: i64, owner_fn: *u8, libname: *u8, out: *u8, import_added: *i64) -> i64
435func ro_report(path: *u8, fname: *u8, verdict: *u8, code: i64, quiet: i64) -> i64
called by 1: ro_one calls 1: ro_out
445func ro_rt_eq(a: *u8, la: *i64, b: *u8, lb: *i64) -> i64
called by 1: ro_one calls 1: ro_span_eq
452func ro_probe_name(out: *u8, fname: *u8) -> i64
called by 1: ro_prove calls 2: ro_emitro_emit_num
464func ro_probe_paths(name: *u8, src: *u8, elf: *u8, builder: *u8) -> i64
494func ro_probe_side(elf: *u8, suffix: *u8, out: *u8) -> i64
called by 1: ro_probe_clean calls 2: ro_slenro_emit
505func ro_probe_clean(elf: *u8) -> i64
515func ro_probe_src(out: *u8, cand_base: *u8, owner_base: *u8, fname: *u8, owner_fn: *u8) -> i64
called by 1: ro_prove calls 2: ro_emitro_emit_num
539func ro_emit_num(out: *u8, o0: i64, v0: i64) -> i64
559func ro_build_rc_class(out: *u8, n: i64, rc: i64) -> i64
570func ro_probe_src2(out: *u8, cand_base: *u8, owner_base: *u8, fname: *u8, owner_fn: *u8) -> i64
588func ro_prove(path: *u8, fname: *u8, lib: *u8, owner_fn: *u8, np: i64, buf: *u8, prm: *i64, loc: *i64) -> i64
626func ro_one(path: *u8, fname: *u8, lib: *u8, owner_fn: *u8, mode: i64, quiet: i64) -> i64
701func ro_sweep(prefix: *u8, suffix: *u8, lib: *u8, owner_fn: *u8, mode: i64, tally: *i64) -> i64