code wiki / _hdl_build / nx_gate_vocab_census.nx
nx_gate_vocab_census.nx source
↩ module page · 216 lines · 10611 B
1// nx_gate_vocab_census.nx -- HOW MANY GATES CAN THE D001 ORACLE ACTUALLY ACCEPT? (2026-07-31, ws=gate-dry-d001)
2//
3// WHY THIS EXISTS: nx_gate_migrate is now live and sound (selftest 12/12 with real neg-controls), but its
4// clause (c) -- the PASS/FAIL vector -- is implemented as gm_count(out,"PASS") before vs after, a LITERAL
5// SUBSTRING COUNT. Migrating a gate onto nx_gate_verdict makes gv_check emit " <name>: PASS" per check.
6// So a gate that today reports its checks in ANY OTHER vocabulary has PASS=0 before and PASS=N after, and
7// the oracle refuses a migration that is semantically sound and strictly an improvement.
8// That means the migratable population is NOT the 2601 non-inheriting gates -- it is only the subset that
9// ALREADY speaks PASS. NOBODY HAS THAT NUMBER, and every plan for D001 has been sized without it.
10//
11// THE THREE DECISION-RELEVANT BUCKETS (single responsibility -- it classifies, it does not migrate):
12// INHERITS -- source imports nx_gate_verdict. Already done; no work owed.
13// EMITS-PASS -- does not inherit, but the source already contains the PASS literal, so gv_check's rows
14// can match the existing count. MIGRATABLE TODAY under the oracle as it stands.
15// NO-PASS -- does not inherit and never says PASS (the ' OK' family, and the composer-generated gates
16// that emit no check rows at all). BLOCKED BY THE VOCABULARY TRAP until clause (c) compares
17// the semantic vector instead of the literal token.
18// Plus the ANCHOR axis, a different rung: does the source emit a "verdict=" anchor at all? A gate without
19// one is machine-read as NOT-GREEN by gg_line_green -- a passing gate scored as failing.
20//
21// ENVELOPE, declared in-band and never silent: this is a SOURCE-LITERAL PROXY, not a runtime observation.
22// It reads what the source CONTAINS; it does not run the gate and observe what it PRINTS. A gate could
23// carry the PASS literal in a comment, or build the word at runtime, and this would mis-file it. The proxy
24// is deliberate -- running 2800 gates costs machine-hours, this costs seconds -- but the number it produces
25// is a PLANNING estimate, and any gate it calls migratable must still be PROVEN one at a time by
26// nx_gate_migrate verify. Do not bank this as a migration result. FLAT scan of runtime +
27// runtime/_hdl_build under the discovered buildroot, shadow trees excluded.
28// license_tier: ORIGINAL No hw writes (Rule 26).
29import "nx_syscalls.nx"
30import "nx_gate_verdict.nx"
31
32const VC_DIRBUF: i64 = 262144
33const VC_PATH: i64 = 512
34const VC_SRC: i64 = 262144
35const VC_RECLEN_OFF: i64 = 16
36const VC_NAME_OFF: i64 = 19
37
38const VC_C_TOTAL: i64 = 0
39const VC_C_INHERITS: i64 = 1
40const VC_C_EMITS_PASS: i64 = 2
41const VC_C_NO_PASS: i64 = 3
42const VC_C_HAS_ANCHOR: i64 = 4
43const VC_C_NO_ANCHOR: i64 = 5
44const VC_C_UNREADABLE: i64 = 6
45const VC_CN: i64 = 7
46
47// DELIBERATELY SELF-CONTAINED: this organ does NOT borrow gv_cat from nx_gate_verdict, because that lib
48// has DIVERGED between trees -- the NAS copy exports gv_cat/gv_catn/gv_bite/gv_journal and the local
49// buildroot copy exports only the original six (gv_puts/gv_num/gv_ctr/gv_head/gv_check/gv_verdict).
50// A census whose own portability depends on which revision of the base class happens to be in the tree
51// cannot be run on both trees to COMPARE them, which is most of the point. Own the four lines instead.
52func vc_cat(dst: *u8, o: i64, s: *u8) -> i64 {
53 var i: i64 = 0
54 var p: i64 = o
55 while s[i] != (0 as u8) { dst[p] = s[i]; p = p + 1; i = i + 1 }
56 dst[p] = 0 as u8
57 return p
58}
59
60func vc_exists(path: *u8) -> i64 {
61 let fd: i64 = sys_openat_rd(path)
62 if fd < 0 { return 0 }
63 sys_close(fd)
64 return 1
65}
66
67func vc_enter_buildroot() -> i64 {
68 if vc_exists("runtime/nx_gate_verdict.nx" as *u8) == 1 { gv_puts("VOCAB root=cwd\n" as *u8); return 1 }
69 if sys_chdir("buildroot" as *u8) == 0 {
70 if vc_exists("runtime/nx_gate_verdict.nx" as *u8) == 1 { gv_puts("VOCAB root=buildroot\n" as *u8); return 1 }
71 }
72 gv_puts("VOCAB-FAIL no-corpus-root -- a census that cannot find its corpus must REFUSE, never report zero.\n" as *u8)
73 return 0
74}
75
76// read a whole file into buf; returns bytes read, or -1 when it cannot be opened at all.
77// -1 is DISTINCT from 0: an unreadable file must never be classified as an empty one.
78func vc_slurp(path: *u8, buf: *u8, cap: i64) -> i64 {
79 let fd: i64 = sys_openat_rd(path)
80 if fd < 0 { return 0 - 1 }
81 var total: i64 = 0
82 var run: i64 = 1
83 while run == 1 {
84 if total >= cap { run = 0 } else {
85 let r: i64 = sys_read(fd, ((buf as i64) + total) as *u8, cap - total)
86 if r <= 0 { run = 0 } else { total = total + r }
87 }
88 }
89 sys_close(fd)
90 return total
91}
92
93func vc_contains(buf: *u8, n: i64, needle: *u8) -> i64 {
94 var nl: i64 = 0
95 while needle[nl] != (0 as u8) { nl = nl + 1 }
96 if nl == 0 { return 1 }
97 if n < nl { return 0 }
98 var i: i64 = 0
99 while i <= n - nl {
100 var m: i64 = 1
101 var c: i64 = 0
102 while c < nl { if buf[i + c] != needle[c] { m = 0; c = nl } else { c = c + 1 } }
103 if m == 1 { return 1 }
104 i = i + 1
105 }
106 return 0
107}
108
109func vc_is_gate_src(nm: *u8, n: i64) -> i64 {
110 if n < 8 { return 0 }
111 let t: *u8 = "_gate.nx" as *u8
112 var k: i64 = 0
113 while k < 8 {
114 if nm[n - 8 + k] != t[k] { return 0 }
115 k = k + 1
116 }
117 return 1
118}
119
120func vc_scan(dir: *u8, ctr: *i64) -> i64 {
121 let fd: i64 = sys_openat_rd(dir)
122 if fd < 0 { return 0 - 1 }
123 let dbuf: *u8 = sys_mmap(VC_DIRBUF)
124 let path: *u8 = sys_mmap(VC_PATH)
125 let src: *u8 = sys_mmap(VC_SRC)
126 var n: i64 = sys_getdents64(fd, dbuf, VC_DIRBUF)
127 while n > 0 {
128 var p: i64 = 0
129 while p < n {
130 let reclen: i64 = (dbuf[p + VC_RECLEN_OFF] as i64) + ((dbuf[p + VC_RECLEN_OFF + 1] as i64) * 256)
131 if reclen <= 0 { p = n }
132 else {
133 let nm: *u8 = ((dbuf as i64) + p + VC_NAME_OFF) as *u8
134 var ln: i64 = 0
135 while nm[ln] != (0 as u8) { ln = ln + 1 }
136 if vc_is_gate_src(nm, ln) == 1 {
137 ctr[VC_C_TOTAL] = ctr[VC_C_TOTAL] + 1
138 var o: i64 = vc_cat(path, 0, dir)
139 path[o] = 47 as u8
140 o = o + 1
141 var w: i64 = 0
142 while w < ln { path[o + w] = nm[w]; w = w + 1 }
143 path[o + ln] = 0 as u8
144 let sn: i64 = vc_slurp(path, src, VC_SRC)
145 if sn < 0 { ctr[VC_C_UNREADABLE] = ctr[VC_C_UNREADABLE] + 1 }
146 else {
147 if vc_contains(src, sn, "nx_gate_verdict" as *u8) == 1 { ctr[VC_C_INHERITS] = ctr[VC_C_INHERITS] + 1 }
148 else {
149 if vc_contains(src, sn, "PASS" as *u8) == 1 { ctr[VC_C_EMITS_PASS] = ctr[VC_C_EMITS_PASS] + 1 }
150 else { ctr[VC_C_NO_PASS] = ctr[VC_C_NO_PASS] + 1 }
151 }
152 if vc_contains(src, sn, "verdict=" as *u8) == 1 { ctr[VC_C_HAS_ANCHOR] = ctr[VC_C_HAS_ANCHOR] + 1 }
153 else { ctr[VC_C_NO_ANCHOR] = ctr[VC_C_NO_ANCHOR] + 1 }
154 }
155 }
156 p = p + reclen
157 }
158 }
159 n = sys_getdents64(fd, dbuf, VC_DIRBUF)
160 }
161 sys_close(fd)
162 return 0
163}
164
165func main(argc: i64, argv: *i64) -> i64 {
166 gv_puts("=== nx_gate_vocab_census -- how many gates can the D001 oracle actually ACCEPT? ===\n" as *u8)
167 if vc_enter_buildroot() == 0 { return 4 }
168
169 let ctr: *i64 = sys_mmap(VC_CN * 8) as *i64
170 var i: i64 = 0
171 while i < VC_CN { ctr[i] = 0; i = i + 1 }
172
173 let r1: i64 = vc_scan("runtime" as *u8, ctr)
174 let r2: i64 = vc_scan("runtime/_hdl_build" as *u8, ctr)
175 if r1 < 0 { gv_puts("VOCAB-FAIL cannot open runtime -- REFUSING rather than reporting a partial corpus.\n" as *u8); return 4 }
176 if r2 < 0 { gv_puts("VOCAB-FAIL cannot open runtime/_hdl_build -- REFUSING rather than reporting a partial corpus.\n" as *u8); return 4 }
177
178 gv_puts("\nNX-GATEVOCAB gate_sources=" as *u8)
179 gv_num(ctr[VC_C_TOTAL])
180 gv_puts(" INHERITS=" as *u8)
181 gv_num(ctr[VC_C_INHERITS])
182 gv_puts(" MIGRATABLE-TODAY=" as *u8)
183 gv_num(ctr[VC_C_EMITS_PASS])
184 // RENAMED 2026-08-01 (debt 1785564910): this bucket is NO LONGER BLOCKED. nx_gate_migrate gained a
185 // third clause-(c) state, GM_ENRICHED: when the BEFORE side enumerated ZERO checks and the AFTER side
186 // enumerates N ALL PASSING, that is ACCEPTED as an enrichment rather than refused as a divergence --
187 // because nx_gate_verdict REFUSES to emit GREEN with ctr[1]==0, so a zero-check original cannot be
188 // expressed on the base class any other way. Proven: selftest 15/15 (T13 accept, T14 FAIL-introducing
189 // refused, T15 reverse refused) and TWO real migrations COMMITTED (deployclass_gate, roleaccess_gate).
190 // Leaving the old label would under-size the campaign by ~997 gates -- the same stale-instrument class
191 // this organ was built to expose.
192 gv_puts(" ENRICHMENT-REACHABLE=" as *u8)
193 gv_num(ctr[VC_C_NO_PASS])
194 gv_puts(" unreadable=" as *u8)
195 gv_num(ctr[VC_C_UNREADABLE])
196 gv_puts("\nNX-GATEANCHOR has_verdict_anchor=" as *u8)
197 gv_num(ctr[VC_C_HAS_ANCHOR])
198 gv_puts(" NO_ANCHOR=" as *u8)
199 gv_num(ctr[VC_C_NO_ANCHOR])
200 var adopt: i64 = 0
201 if ctr[VC_C_TOTAL] > 0 { adopt = ctr[VC_C_INHERITS] * 1000 / ctr[VC_C_TOTAL] }
202 gv_puts("\nadoption_permil=" as *u8)
203 gv_num(adopt)
204 var reach: i64 = 0
205 // reachable now INCLUDES the former NO-PASS bucket: the enrichment clause accepts it. Still a
206 // PLANNING estimate -- every gate must still be proven one at a time by nx_gate_migrate verify.
207 if ctr[VC_C_TOTAL] > 0 { reach = (ctr[VC_C_INHERITS] + ctr[VC_C_EMITS_PASS] + ctr[VC_C_NO_PASS]) * 1000 / ctr[VC_C_TOTAL] }
208 gv_puts(" reachable_permil=" as *u8)
209 gv_num(reach)
210 gv_puts(" (adoption = already inheriting; reachable = adoption + what the oracle could accept TODAY)\n" as *u8)
211 gv_puts("envelope: SOURCE-LITERAL PROXY, not a runtime observation -- it reads what the source CONTAINS,\n" as *u8)
212 gv_puts(" it does NOT run the gate and watch what it PRINTS. A PASS literal in a comment mis-files a gate.\n" as *u8)
213 gv_puts(" This is a PLANNING estimate: every gate it calls migratable must still be proven one at a time\n" as *u8)
214 gv_puts(" by nx_gate_migrate verify. Do NOT bank it as a migration result. FLAT scan, shadow trees excluded.\n" as *u8)
215 return 0
216}