code wiki / _hdl_build / nx_oo_extract.nx
nx_oo_extract.nx
buildroot/runtime/_hdl_build/nx_oo_extract.nx
about
nx_oo_extract.nx -- BYTE-PROVEN OO DUP-FUNCTION EXTRACTOR (the real "object-oriented without losing
functionality" operation, unblocked by the 2026-07-21 byte-equiv proof). Moves functions that are
DUPLICATED byte-identically across N consumers into a shared base lib, repoints each consumer to
import it, and COMMITS only if EVERY consumer's rebuild is BYTE-IDENTICAL to before (else REVERTS all).
never-brick + rule-13 (originals backed up). Every refusal carries verdict+reason+fix (operator law).
argv: <funcname[,funcname...]> <baselib-srcpath> <buildonly-elf> <consumer-srcpath1> [consumer-srcpath2 ...]
[--proof=bytes|behave] [--workload=<path>]
exit: 0 EXTRACTED | 1 REFUSED(reverted) | 2 usage/precondition | 3 io/build error(reverted)
v2 (2026-08-18, the /compare generator dedup): TWO capabilities the single-function v1 could not do.
(1) N FUNCTIONS IN ONE PASS. A comma-separated funcname list moves the whole shared set at once with ONE
import line and ONE proof cycle. v1 needed N runs and each run left the consumer importing a lib that
the NEXT run would rewrite -- and a base lib holding one function is not a base class, it is a shard.
(2) BEHAVIOURAL PROOF. `--proof=behave` proves the extraction by the consumer's OUTPUT, not its image:
each consumer is run BEFORE and AFTER over every argv line in --workload that names it, and the
captured stdout must be byte-identical. Needed because an added `import` line legitimately reorders
the compiled image (functions are laid out in source order), so `--proof=bytes` REFUSES a correct
extraction; the byte proof stays the default because it is the stronger claim when it holds.
Workload format: one line per run, `<consumer-target> <argv1> <argv2> ...`; a consumer with no
workload line has NO proof and the run REFUSES (a proof over an empty set is not a proof).
A function is extracted only if its body is byte-identical across EVERY consumer; a divergent body is
REFUSED by name -- resolve by rename or by making them equal first, never by picking one.
license_tier: ORIGINAL No hw writes (Rule 26).
dependencies 4 imports · 0 importers
imports: nx_seat_drive_lib.nxnx_seg_store.nxnx_deploy_lib.nxnx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 29 | const OE_CAP: i64 = 2097152 |
| 30 | const OE_MAXC: i64 = 128 |
| 31 | const OE_MAXF: i64 = 64 // functions per extraction (argv[1] list); a REFUSED-by-count if exceeded |
| 32 | const OE_NAME: i64 = 128 // one function-name slot |
| 33 | const OE_MAXW: i64 = 256 // workload lines |
| 34 | const OE_WARGV: i64 = 32 // argv tokens per workload line |
| 35 | const OE_ABSPATH: i64 = 1024 // an absolute path buffer: start-cwd + /buildroot/_build/<target>.sov.elf |
functions
| 37 | func oe_read(path: *u8, buf: *u8, cap: i64) -> i64 |
| 46 | func oe_isid(c: i64) -> i64 called by 1: oe_body_uses_consumer_const |
| 53 | func oe_eq(a: *u8, an: i64, b: *u8, bn: i64) -> i64 { if an != bn { return 0 } var i: i64 = 0; while i < an { if a[i] != b[i] { return 0 } i = i + 1 } return 1 } |
| 54 | func oe_streq(a: *u8, b: *u8) -> i64 { var i: i64 = 0; while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } if b[i] != (0 as u8) { return 0 } return 1 } |
| 55 | func oe_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 } |
| 57 | func oe_find_func(buf: *u8, n: i64, fname: *u8, out: *i64) -> i64 called by 1: oe_find_func_trim |
| 107 | func oe_trim_body_end(buf: *u8, out: *i64) -> i64 called by 1: oe_find_func_trim |
| 134 | func oe_find_func_trim(buf: *u8, n: i64, fname: *u8, out: *i64) -> i64 |
| 140 | func oe_build_snap(buildelf: *u8, target: *u8, snappath: *u8, buf: *u8) -> i64 |
| 166 | func oe_base(path: *u8, out: *u8) -> i64 |
| 177 | func oe_target(path: *u8, out: *u8) -> i64 |
| 188 | func oe_body_uses_consumer_const(body: *u8, bn: i64, src: *u8, sn: i64, fname: *u8, cp: *u8) -> i64 |
| 231 | func oe_import_insert_at(src: *u8, sn: i64) -> i64 |
| 253 | func oe_split_names(s: *u8, names: *u8) -> i64 called by 1: main |
| 274 | func oe_run_in(elf_abs: *u8, av: *i64, na: i64, outfile: *u8, cwd: *u8) -> i64 |
| 293 | func oe_behave(target: *u8, wl: *u8, wn: i64, outprefix: *u8, tokbuf: *u8) -> i64 |
| 354 | func oe_mask_volatile(b: *u8, n: i64, tok: *u8) -> i64 called by 1: oe_behave_cmp |
| 373 | func oe_behave_cmp(target: *u8, wl: *u8, wn: i64, prefa: *u8, prefb: *u8, ba: *u8, bb: *u8) -> i64 |
| 421 | func main(argc: i64, argv: *i64) -> i64 |