code wiki / _hdl_build / nx_eco_graph_arch.nx
nx_eco_graph_arch.nx source
↩ module page · 234 lines · 9574 B
1// nx_eco_graph_arch.nx -- SOVEREIGN ARCHITECTURE REVIEW of the ecosystem's dependency design, computed
2// from the eco_graph store with the field's own instruments (operator 2026-07-16: "is syscalls supposed
3// to have this design? give the ecosystem design a SOTA review"):
4// 1. SCCs (iterative Kosaraju) -> cycles = Acyclic-Dependencies-Principle violations, NAMED; the
5// largest SCC = the "core" in MacCormack's core-periphery method
6// 2. PROPAGATION COST -> avg % of the codebase a change can reach (MacCormack et al.,
7// "Exploring the Structure of Complex Software Designs" -- Linux/
8// Mozilla were measured with exactly this)
9// 3. Fan-in concentration -> the god-node question: direct-import share of the top hubs
10// (libc-pattern universal base vs unhealthy coupling)
11// 4. Depth histogram -> generations from roots: deep layered composition vs base-hugging flat
12// Usage: nx_eco_graph_arch <store-prefix> license_tier: ORIGINAL expect_exit:0
13import "nx_syscalls.nx"
14import "nx_eco_graph.nx"
15const K_MAGIC_10000: i64 = 10000
16
17func aw(s: *u8) -> i64 { var n:i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
18func an(v: i64) -> i64 { let b:*u8=sys_mmap(24); var m:i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var j:i64=0; while j<k{b[j]=t[k-1-j];j=j+1} sys_write(1,b,k); return 0 }
19func aname(g: *EcoGraph, idx: i64) -> i64 {
20 let off: i64 = g.node_off[idx]
21 var n: i64 = 0
22 while g.arena[off+n] != (0 as u8) { n = n + 1 }
23 sys_write(1, ((g.arena as i64)+off) as *u8, n)
24 return 0
25}
26
27func main(argc: i64, argv: *i64) -> i64 {
28 if argc < 2 { aw("usage: nx_eco_graph_arch <store-prefix>\n" as *u8); return 2 }
29 let g: *EcoGraph = eg_load(argv[1] as *u8)
30 if (g as i64) == 0 { aw("ERROR store not found\n" as *u8); return 3 }
31 let n: i64 = g.node_count
32 let E: i64 = g.out_head[n]
33 aw("=== NX-ECO-ARCH: sovereign architecture review of the dependency design ===\n" as *u8)
34 aw("nodes=" as *u8); an(n); aw(" edges=" as *u8); an(E); aw("\n\n" as *u8)
35
36 // ---------- 1. SCCs: iterative Kosaraju ----------
37 let color: *u8 = sys_mmap(n + 2)
38 let order: *i64 = sys_mmap((n+2)*8) as *i64
39 let stv: *i64 = sys_mmap((n+2)*8) as *i64
40 let stp: *i64 = sys_mmap((n+2)*8) as *i64
41 var i: i64 = 0
42 while i < n { color[i] = 0 as u8; i = i + 1 }
43 var ordn: i64 = 0
44 var s: i64 = 0
45 while s < n {
46 if color[s] == (0 as u8) {
47 var sp: i64 = 0
48 stv[0] = s
49 stp[0] = g.out_head[s]
50 color[s] = 1 as u8
51 while sp >= 0 {
52 let v: i64 = stv[sp]
53 if stp[sp] < g.out_head[v+1] {
54 let w: i64 = g.out_list[stp[sp]]
55 stp[sp] = stp[sp] + 1
56 if color[w] == (0 as u8) {
57 color[w] = 1 as u8
58 sp = sp + 1
59 stv[sp] = w
60 stp[sp] = g.out_head[w]
61 }
62 } else {
63 order[ordn] = v
64 ordn = ordn + 1
65 sp = sp - 1
66 }
67 }
68 }
69 s = s + 1
70 }
71 // pass 2 on transpose (in-edges), reverse finish order
72 let comp: *i64 = sys_mmap((n+2)*8) as *i64
73 i = 0
74 while i < n { comp[i] = 0 - 1; i = i + 1 }
75 var nc: i64 = 0
76 var oi: i64 = ordn - 1
77 while oi >= 0 {
78 let s2: i64 = order[oi]
79 if comp[s2] < 0 {
80 var sp2: i64 = 0
81 stv[0] = s2
82 comp[s2] = nc
83 while sp2 >= 0 {
84 let v2: i64 = stv[sp2]
85 sp2 = sp2 - 1
86 var p: i64 = g.in_head[v2]
87 while p < g.in_head[v2+1] {
88 let w2: i64 = g.in_list[p]
89 if comp[w2] < 0 {
90 comp[w2] = nc
91 sp2 = sp2 + 1
92 stv[sp2] = w2
93 }
94 p = p + 1
95 }
96 }
97 nc = nc + 1
98 }
99 oi = oi - 1
100 }
101 // component sizes
102 let csz: *i64 = sys_mmap((n+2)*8) as *i64
103 i = 0; while i < nc { csz[i] = 0; i = i + 1 }
104 i = 0; while i < n { csz[comp[i]] = csz[comp[i]] + 1; i = i + 1 }
105 var ncyc: i64 = 0
106 var incyc: i64 = 0
107 var big: i64 = 0
108 i = 0
109 while i < nc {
110 if csz[i] > 1 { ncyc = ncyc + 1; incyc = incyc + incyc*0 + csz[i] }
111 if csz[i] > csz[big] { big = i }
112 i = i + 1
113 }
114 aw("[1] CYCLES (Acyclic-Dependencies-Principle):\n" as *u8)
115 aw(" nontrivial SCCs=" as *u8); an(ncyc); aw(" organs-inside-cycles=" as *u8); an(incyc)
116 aw(" largest-SCC(core)=" as *u8); an(csz[big]); aw("\n" as *u8)
117 // print members of up to 5 nontrivial SCCs (cap 20 names each)
118 var printed: i64 = 0
119 var ci: i64 = 0
120 while ci < nc {
121 if csz[ci] > 1 { if printed < 5 {
122 aw(" CYCLE size=" as *u8); an(csz[ci]); aw(":" as *u8)
123 var m: i64 = 0
124 i = 0
125 while i < n {
126 if comp[i] == ci { if m < 20 { aw(" " as *u8); aname(g, i) } m = m + 1 }
127 i = i + 1
128 }
129 if m > 20 { aw(" ...+" as *u8); an(m-20) }
130 aw("\n" as *u8)
131 printed = printed + 1
132 } }
133 ci = ci + 1
134 }
135 aw("\n" as *u8)
136
137 // ---------- 2. PROPAGATION COST (MacCormack): avg transitive reach of a change ----------
138 // For each v: how many organs TRANSITIVELY depend on v (BFS over in-edges). Stamp array, no memset.
139 let stamp: *i64 = sys_mmap((n+2)*8) as *i64
140 i = 0; while i < n { stamp[i] = 0 - 1; i = i + 1 }
141 var total: i64 = 0
142 var mxreach: i64 = 0
143 var mxv: i64 = 0
144 s = 0
145 while s < n {
146 var reach: i64 = 0
147 var sp3: i64 = 0
148 stv[0] = s
149 stamp[s] = s
150 while sp3 >= 0 {
151 let v3: i64 = stv[sp3]
152 sp3 = sp3 - 1
153 var p3: i64 = g.in_head[v3]
154 while p3 < g.in_head[v3+1] {
155 let w3: i64 = g.in_list[p3]
156 if stamp[w3] != s {
157 stamp[w3] = s
158 reach = reach + 1
159 sp3 = sp3 + 1
160 stv[sp3] = w3
161 }
162 p3 = p3 + 1
163 }
164 }
165 total = total + reach
166 if reach > mxreach { mxreach = reach; mxv = s }
167 s = s + 1
168 }
169 // PC as basis points (x/10000) to keep integer precision: total / (n*n)
170 let pc_bp: i64 = total * K_MAGIC_10000 / (n * n)
171 aw("[2] PROPAGATION COST (MacCormack core-periphery instrument):\n" as *u8)
172 aw(" avg transitive dependents per organ=" as *u8); an(total / n)
173 aw(" propagation-cost=" as *u8); an(pc_bp / 100); aw("." as *u8); an(pc_bp % 100); aw("% (published Linux ~5-18%, Mozilla pre-redesign ~17%)\n" as *u8)
174 aw(" max blast-radius organ=" as *u8); aname(g, mxv); aw(" reaches " as *u8); an(mxreach); aw(" (" as *u8); an(mxreach * 100 / n); aw("% of ecosystem)\n\n" as *u8)
175
176 // ---------- 3. FAN-IN CONCENTRATION (the god-node question) ----------
177 aw("[3] FAN-IN CONCENTRATION (direct imports; libc-pattern vs coupling):\n" as *u8)
178 let bi: *i64 = sys_mmap(14*8) as *i64
179 let bc: *i64 = sys_mmap(14*8) as *i64
180 var bn: i64 = 0
181 i = 0
182 while i < n {
183 let fin: i64 = g.in_head[i+1] - g.in_head[i]
184 if bn < 12 { bi[bn] = i; bc[bn] = fin; bn = bn + 1 } else {
185 var mn: i64 = 0
186 var k: i64 = 1
187 while k < bn { if bc[k] < bc[mn] { mn = k } k = k + 1 }
188 if fin > bc[mn] { bi[mn] = i; bc[mn] = fin }
189 }
190 i = i + 1
191 }
192 var em: i64 = 0
193 while em < bn {
194 var bb: i64 = 0
195 var k2: i64 = 1
196 while k2 < bn { if bc[k2] > bc[bb] { bb = k2 } k2 = k2 + 1 }
197 if bc[bb] >= 0 {
198 aw(" " as *u8); aname(g, bi[bb]); aw(" direct-importers=" as *u8); an(bc[bb]); aw(" (" as *u8); an(bc[bb] * 100 / n); aw("% of all organs)\n" as *u8)
199 bc[bb] = 0 - 1
200 }
201 em = em + 1
202 }
203 aw("\n" as *u8)
204
205 // ---------- 4. DEPTH: BFS generations from roots ----------
206 let gen: *i64 = sys_mmap((n+2)*8) as *i64
207 i = 0; while i < n { gen[i] = 0 - 1; i = i + 1 }
208 var wt: i64 = 0
209 i = 0
210 while i < n { if g.out_head[i] == g.out_head[i+1] { gen[i] = 0; order[wt] = i; wt = wt + 1 } i = i + 1 }
211 var wh: i64 = 0
212 while wh < wt {
213 let v4: i64 = order[wh]
214 var p4: i64 = g.in_head[v4]
215 while p4 < g.in_head[v4+1] {
216 let u: i64 = g.in_list[p4]
217 if gen[u] < 0 { gen[u] = gen[v4] + 1; order[wt] = u; wt = wt + 1 }
218 p4 = p4 + 1
219 }
220 wh = wh + 1
221 }
222 var mxg: i64 = 0
223 i = 0; while i < n { if gen[i] > mxg { mxg = gen[i] } i = i + 1 }
224 aw("[4] DEPTH (shortest import-hops from roots; deep layering vs base-hugging):\n" as *u8)
225 var l: i64 = 0
226 while l <= mxg {
227 var cnt: i64 = 0
228 i = 0; while i < n { if gen[i] == l { cnt = cnt + 1 } i = i + 1 }
229 aw(" gen " as *u8); an(l); aw(": " as *u8); an(cnt); aw(" organs (" as *u8); an(cnt * 100 / n); aw("%)\n" as *u8)
230 l = l + 1
231 }
232 aw("\nNX-ECO-ARCH done -- feed cycles to the janitor, numbers to /compare/ecosysdesign.\n" as *u8)
233 return 0
234}