interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / om / crumb-coverage / crumb-coverage.om

767 lines · 13104 bytes Raw Blame History
1note om/crumb-coverage/crumb-coverage.om: .crumb coverage of a git tree (DRA-95).
2note Usage, from the repository root: git ls-files -z > list; crumb-coverage < list
3note Reads the NUL-separated tracked paths (git index order, checked strictly increasing) and counts:
4note tracked_dirs the root plus every directory that is an ancestor of a tracked path;
5note crumb_dirs tracked paths named .crumb (one per directory);
6note enforced_dirs crumb directories with at least one invariant whose check resolves.
7note Each .crumb is parsed as strict JSON (om/vendor/json.om). Every string of its top-level "invariants"
8note array is one invariant; its check is the text after "Check: ". A check resolves when it is
9note cargo test -p CRATE --test T -- --exact NAME and crates/CRATE/tests/T.rs contains "fn LEAF(", or
10note cargo test -p CRATE --lib -- --exact M::tests::LEAF and crates/CRATE/src/M.rs (lib.rs when no M)
11note contains "fn LEAF(", or
12note [sh|bash] PATH ... and PATH is a repository-relative regular file.
13note LEAF is the last :: segment of NAME; "tests" segments are dropped from M. Unresolved invariants are
14note printed. Exit 0 all resolve, 1 some do not, 2 usage, 3 io, 4 input or crumb JSON refused.
15note Build: { printf 'om2\n'; cat om/vendor/json.om om/crumb-coverage/crumb-coverage.om; } | "$AIEN_OMC" > cc
16
17const ccx ulong 999999999
18
19note gst slots
20const kop ulong 0
21const kn ulong 1
22const kdirs ulong 2
23const kcr ulong 3
24const kenf ulong 4
25const kinv ulong 5
26const kres ulong 6
27const kunr ulong 7
28const kfsz ulong 8
29const kpn ulong 9
30const kndl ulong 10
31const kci ulong 11
32const kcrr ulong 12
33
34global gin uchar 8388608
35global gco ulong 8192
36global gcl ulong 8192
37global gpth uchar 4096
38global gst ulong 16
39global gob uchar 65536
40global gstb uchar 128
41global gdg uchar 24
42global ginv uchar 8192
43global gnd uchar 512
44global gfil uchar 983040
45
46text tusage "usage: git ls-files -z | crumb-coverage (no arguments; run from the repository root)"
47text tio "io"
48text tbig "input-too-large"
49text tpath "bad-path"
50text tunsort "paths-not-in-git-order"
51text tmany "too-many-crumbs"
52text tjson "crumb-json"
53text tinvarr "invariants-not-array-of-strings"
54text tlong "name-too-long"
55text tref "crumb-coverage refused "
56text tcrumb ".crumb"
57text tinv "invariants"
58text tchk "Check: "
59text tcargo "cargo test -p "
60text ttest "--test "
61text tlib "--lib"
62text tex " -- --exact "
63text tcc "::"
64text tsh "sh"
65text tbash "bash"
66text tcrates "crates/"
67text ttests "tests/"
68text ttestw "tests"
69text tsrcd "src/"
70text tlibw "lib"
71text trs ".rs"
72text tfn "fn "
73text thead "crumb-coverage "
74text o1 "tracked_dirs"
75text o2 "crumb_dirs"
76text o3 "enforced_dirs"
77text o4 "invariants"
78text o5 "resolved"
79text o6 "unresolved"
80text tcrl "crumb "
81text tunr "unresolved "
82
83note ======== output ========
84
85fn cc_dec v ulong to ulong
86n = ulong 0
87x = v
88while true bound 25
89put gdg n add 48 uchar rem x 10
90n = add n 1
91x = div x 10
92if eq x 0
93break
94end
95end
96ret n
97end
98
99note cc_oflush: a pass writes at least one byte of at most 65536, so 65536 passes suffice
100fn cc_oflush fd int to void
101o = ulong 0
102m = get gst kop
103while lt o m bound 65536
104w = write fd gob o sub m o
105if le w 0
106exit 3
107end
108o = add o ulong w
109end
110put gst kop 0
111end
112
113fn cc_ob c uchar to void
114p = get gst kop
115if ge p len gob
116cc_oflush 1
117p = ulong 0
118end
119put gob p c
120put gst kop add p 1
121end
122
123fn cc_otx t view uchar * to void
124for i ulong len t
125cc_ob get t i
126end
127end
128
129fn cc_ou v ulong to void
130n = cc_dec v
131for i ulong n
132cc_ob get gdg sub sub n i 1
133end
134end
135
136fn cc_kv t view uchar * v ulong to void
137cc_otx t
138cc_ob 32
139cc_ou v
140end
141
142fn cc_die c ulong t view uchar * to void
143put gst kop 0
144cc_otx tref
145cc_ou c
146cc_ob 32
147cc_otx t
148cc_ob 10
149cc_oflush 2
150exit int c
151end
152
153fn cc_ogin o ulong n ulong to void
154for i ulong n
155cc_ob get gin add o i
156end
157end
158
159fn cc_oinv n ulong to void
160for i ulong n
161cc_ob get ginv i
162end
163end
164
165note ======== input: the NUL-separated path list ========
166
167note cc_input: every pass adds at least one byte to gin (8388608 bytes), and a full gin is refused
168fn cc_input to void
169o = ulong 0
170for it ulong 8388609
171if ge o len gin
172cc_die 4 tbig
173end
174r = read 0 gin o sub len gin o
175if lt r 0
176cc_die 3 tio
177end
178if eq r 0
179break
180end
181o = add o ulong r
182end
183put gst kn o
184end
185
186note cc_nul: the NUL ending the path that starts at s (paths are at most 4096 bytes)
187fn cc_nul s ulong n ulong to ulong
188for k ulong 4097
189p = add s k
190if ge p n
191cc_die 4 tpath
192end
193if eq get gin p 0
194ret p
195end
196end
197cc_die 4 tpath
198ret 0
199end
200
201fn cc_common s ulong l ulong ps ulong pl ulong to ulong
202m = l
203if lt pl m
204m = pl
205end
206for i ulong m
207if ne get gin add s i get gin add ps i
208ret i
209end
210end
211ret m
212end
213
214note cc_order: the path at s must sort strictly after the previous one (git index order, unsigned bytes)
215fn cc_order s ulong l ulong ps ulong pl ulong c ulong to void
216if eq c l
217cc_die 4 tunsort
218end
219if lt c pl
220if lt get gin add s c get gin add ps c
221cc_die 4 tunsort
222end
223end
224end
225
226fn cc_iscrumb s ulong l ulong to void
227t = len tcrumb
228if lt l t
229ret
230end
231b = sub add s l t
232for i ulong t
233if ne get gin add b i get tcrumb i
234ret
235end
236end
237if gt l t
238if ne get gin sub b 1 47
239ret
240end
241end
242k = get gst kcr
243if ge k len gco
244cc_die 4 tmany
245end
246put gco k s
247put gcl k l
248put gst kcr add k 1
249end
250
251note cc_path: a directory ending at a '/' at index i is new unless the previous path shares bytes 0..i;
252note the subtree of a directory is contiguous in sorted order, so each directory is counted once.
253fn cc_path s ulong l ulong ps ulong pl ulong hp bool to void
254if eq l 0
255cc_die 4 tpath
256end
257if eq get gin s 47
258cc_die 4 tpath
259end
260c = ulong 0
261if hp
262c = cc_common s l ps pl
263cc_order s l ps pl c
264end
265for i ulong l
266if ge i c
267if eq get gin add s i 47
268put gst kdirs add get gst kdirs 1
269end
270end
271end
272cc_iscrumb s l
273end
274
275note cc_scan: every path is at least one byte plus its NUL, so at most 4194304 paths
276fn cc_scan to void
277n = get gst kn
278if gt n 0
279put gst kdirs 1
280end
281s = ulong 0
282ps = ulong 0
283pl = ulong 0
284hp = false
285for it ulong 4194305
286if ge s n
287break
288end
289e = cc_nul s n
290l = sub e s
291cc_path s l ps pl hp
292ps = s
293pl = l
294hp = true
295s = add e 1
296end
297end
298
299note ======== files ========
300
301fn cc_le64 o ulong to ulong
302v = ulong 0
303for i ulong 8
304v = or shl v 8 ulong get gstb add o sub 7 i
305end
306ret v
307end
308
309fn cc_close fd long to void
310r = fclose int fd
311if ne r 0
312cc_die 3 tio
313end
314end
315
316note cc_try: open gpth[0 .. kpn) read-only without following a final symlink; a descriptor of a regular file
317note (size in kfsz) or -1 when the path is missing or not a regular file
318fn cc_try to long
319fd = fopen gpth 0 get gst kpn 557056 0
320if lt fd 0
321ret long -1
322end
323r = fstat int fd gstb 0 128
324if ne r 0
325cc_die 3 tio
326end
327md = or ulong get gstb 16 shl ulong get gstb 17 8
328if ne and md 61440 32768
329cc_close fd
330ret long -1
331end
332put gst kfsz cc_le64 48
333ret fd
334end
335
336fn cc_rdfil fd long to ulong
337sz = get gst kfsz
338if gt sz len gfil
339cc_die 3 tbig
340end
341o = ulong 0
342while lt o sz bound 983040
343r = pread int fd gfil o sub sz o long o
344if le r 0
345cc_die 3 tio
346end
347o = add o ulong r
348end
349cc_close fd
350ret sz
351end
352
353fn cc_rdsrc fd long b edit uchar * sz ulong to void
354o = ulong 0
355while lt o sz bound 983040
356r = pread int fd b o sub sz o long o
357if le r 0
358cc_die 3 tio
359end
360o = add o ulong r
361end
362cc_close fd
363end
364
365note ======== gpth and the needle ========
366
367fn cc_preset to void
368put gst kpn 0
369end
370
371fn cc_pb c uchar to void
372p = get gst kpn
373if ge p sub len gpth 1
374cc_die 4 tlong
375end
376put gpth p c
377put gst kpn add p 1
378end
379
380fn cc_pt t view uchar * to void
381for i ulong len t
382cc_pb get t i
383end
384end
385
386fn cc_pi a ulong b ulong to void
387if gt a b
388cc_die 4 tpath
389end
390for i ulong sub b a
391cc_pb get ginv add a i
392end
393end
394
395fn cc_pset s ulong l ulong to void
396cc_preset
397for i ulong l
398cc_pb get gin add s i
399end
400end
401
402fn cc_nb c uchar to void
403p = get gst kndl
404if ge p len gnd
405cc_die 4 tlong
406end
407put gnd p c
408put gst kndl add p 1
409end
410
411note ======== the invariant text in ginv ========
412
413note cc_at: ginv[p ..] starts with t, all within ginv[0 .. n)
414fn cc_at p ulong n ulong t view uchar * to bool
415m = len t
416if gt p n
417ret false
418end
419if gt m sub n p
420ret false
421end
422for i ulong m
423if ne get ginv add p i get t i
424ret false
425end
426end
427ret true
428end
429
430fn cc_find n ulong from ulong t view uchar * to ulong
431m = len t
432if gt m n
433ret ccx
434end
435if gt from sub n m
436ret ccx
437end
438for i ulong add sub sub n m from 1
439if cc_at add from i n t
440ret add from i
441end
442end
443ret ccx
444end
445
446note cc_word: the end of the space-delimited word starting at p
447fn cc_word n ulong p ulong to ulong
448if ge p n
449ret n
450end
451for i ulong sub n p
452if eq get ginv add p i 32
453ret add p i
454end
455end
456ret n
457end
458
459fn cc_weq p ulong w ulong t view uchar * to bool
460if ne sub w p len t
461ret false
462end
463ret cc_at p w t
464end
465
466note cc_leaf: the index after the last "::" in ginv[a .. b), or a
467fn cc_leaf a ulong b ulong to ulong
468r = a
469for i ulong sub b a
470if cc_at add a i b tcc
471r = add add a i 2
472end
473end
474ret r
475end
476
477note cc_mods: append src/M.rs for the module path ginv[a .. ls - 2), "tests" segments dropped; src/lib.rs if none
478fn cc_mods a ulong ls ulong to void
479cc_pt tsrcd
480nseg = ulong 0
481if gt ls a
482e = sub ls 2
483s = a
484while le s e bound 4096
485x = cc_find e s tcc
486if eq x ccx
487x = e
488end
489if not cc_weq s x ttestw
490if gt nseg 0
491cc_pb 47
492end
493cc_pi s x
494nseg = add nseg 1
495end
496s = add x 2
497end
498end
499if eq nseg 0
500cc_pt tlibw
501end
502cc_pt trs
503end
504
505fn cc_fat p ulong m ulong to bool
506for k ulong m
507if ne get gfil add p k get gnd k
508ret false
509end
510end
511ret true
512end
513
514note cc_hasfn: the file at gpth contains the needle gnd[0 .. kndl)
515fn cc_hasfn to bool
516fd = cc_try
517if lt fd 0
518ret false
519end
520sz = cc_rdfil fd
521m = get gst kndl
522if gt m sz
523ret false
524end
525for i ulong add sub sz m 1
526if cc_fat i m
527ret true
528end
529end
530ret false
531end
532
533note cc_name: q is past the target selector; finds " -- --exact NAME", builds the source path for lib tests
534note and the needle "fn LEAF(", then searches the file
535fn cc_name n ulong q ulong lib bool to bool
536x = cc_find n q tex
537if eq x ccx
538ret false
539end
540a = add x len tex
541b = cc_word n a
542if eq b a
543ret false
544end
545ls = cc_leaf a b
546if eq ls b
547ret false
548end
549if lib
550cc_mods a ls
551end
552put gst kndl 0
553for i ulong len tfn
554cc_nb get tfn i
555end
556for i ulong sub b ls
557cc_nb get ginv add ls i
558end
559cc_nb 40
560ret cc_hasfn
561end
562
563fn cc_cargo n ulong p ulong to bool
564w = cc_word n p
565if or eq w p ge w n
566ret false
567end
568cc_preset
569cc_pt tcrates
570cc_pi p w
571cc_pb 47
572q = add w 1
573if cc_at q n ttest
574a = add q len ttest
575b = cc_word n a
576if eq b a
577ret false
578end
579cc_pt ttests
580cc_pi a b
581cc_pt trs
582ret cc_name n b false
583end
584if cc_at q n tlib
585ret cc_name n add q len tlib true
586end
587ret false
588end
589
590fn cc_file n ulong p ulong to bool
591q = p
592w = cc_word n q
593if or cc_weq q w tsh cc_weq q w tbash
594q = add w 1
595w = cc_word n q
596end
597if ge q w
598ret false
599end
600if eq get ginv q 47
601ret false
602end
603cc_preset
604cc_pi q w
605fd = cc_try
606if lt fd 0
607ret false
608end
609cc_close fd
610ret true
611end
612
613fn cc_resolve n ulong to bool
614p = cc_find n 0 tchk
615if eq p ccx
616ret false
617end
618p = add p len tchk
619if cc_at p n tcargo
620ret cc_cargo n add p len tcargo
621end
622ret cc_file n p
623end
624
625note ======== one .crumb ========
626
627fn cc_odir j ulong to void
628l = get gcl j
629if eq l len tcrumb
630cc_ob 46
631ret
632end
633cc_ogin get gco j sub sub l len tcrumb 1
634end
635
636fn cc_unres j ulong n ulong to void
637cc_otx tunr
638cc_odir j
639cc_ob 58
640cc_ob 32
641cc_oinv n
642cc_ob 10
643end
644
645fn cc_list src view uchar 983040 tape view uint 262160 nb edit uchar 8192 v ulong j ulong to void
646if ne js_type tape v jsarr
647cc_die 4 tinvarr
648end
649e = js_first tape v
650while ne e jsnone bound 999999
651if ne js_type tape e jsstr
652cc_die 4 tinvarr
653end
654r = js_sget src js_off tape e nb
655if lt r 0
656cc_die 4 tjson
657end
658n = ulong r
659if gt n len ginv
660cc_die 4 tlong
661end
662for i ulong n
663put ginv i get nb i
664end
665put gst kci add get gst kci 1
666if cc_resolve n
667put gst kcrr add get gst kcrr 1
668else
669cc_unres j n
670end
671e = js_enext tape e
672end
673end
674
675fn cc_line j ulong to void
676i = get gst kci
677r = get gst kcrr
678put gst kinv add get gst kinv i
679put gst kres add get gst kres r
680put gst kunr add get gst kunr sub i r
681if gt r 0
682put gst kenf add get gst kenf 1
683end
684cc_otx tcrl
685cc_odir j
686cc_ob 32
687cc_kv o4 i
688cc_ob 32
689cc_kv o5 r
690cc_ob 10
691end
692
693fn cc_crumb src edit uchar 983040 tape edit uint 262160 nb edit uchar 8192 j ulong to void
694cc_pset get gco j get gcl j
695fd = cc_try
696if lt fd 0
697cc_die 3 tio
698end
699sz = get gst kfsz
700if or eq sz 0 gt sz len src
701cc_close fd
702cc_die 4 tjson
703end
704cc_rdsrc fd src sz
705r = js_init tape sz 64
706if lt r 0
707cc_die 4 tjson
708end
709r = js_parse src tape sz
710if lt r 0
711cc_die 4 tjson
712end
713if ne js_type tape 0 jsobj
714cc_die 4 tjson
715end
716put gst kci 0
717put gst kcrr 0
718k = js_first tape 0
719while ne k jsnone bound 999999
720if js_streq src js_off tape k tinv
721cc_list src tape nb add k 1 j
722end
723k = js_mnext tape k
724end
725cc_line j
726end
727
728note ======== report ========
729
730fn cc_report to void
731cc_otx thead
732cc_kv o1 get gst kdirs
733cc_ob 10
734cc_otx thead
735cc_kv o2 get gst kcr
736cc_ob 10
737cc_otx thead
738cc_kv o3 get gst kenf
739cc_ob 10
740cc_otx thead
741cc_kv o4 get gst kinv
742cc_ob 32
743cc_kv o5 get gst kres
744cc_ob 32
745cc_kv o6 get gst kunr
746cc_ob 10
747cc_oflush 1
748end
749
750fn main to int
751if ne argcnt 1
752cc_die 2 tusage
753end
754cc_input
755cc_scan
756src = new uchar 983040 0
757tape = new uint 262160 0
758nb = new uchar 8192 0
759for j ulong get gst kcr
760cc_crumb src tape nb j
761end
762cc_report
763if gt get gst kunr 0
764ret 1
765end
766ret 0
767end