Commit 8567aff
L1: harmonic_anomaly + import-inlining + cascade-cleanup so score JITs
Six interlocking changes that close the L1 gap from Path B:
"the harmonic libraries don't JIT because they use dicts and strings."
1. harmonic_anomaly rewritten to use array-of-int representations
instead of dict-of-string-keys. Detector is now an array indexed
by constants (DET_N_DIMS=0, DET_STRATEGIES=1, ...). Strategies
are int codes (0=log, 1=modulo, 2=discrete) — public API still
accepts strings. Per-dim freq tables are parallel arrays of
(key, count). Hot path (score) is dict-free, string-free.
2. Interpreter::inline_imports public API. Walks Statement::Import
recursively, parses the imported file, applies alias prefix to
fn defs, returns the flattened AST. Uses the same rewrite_module
_calls helper as the runtime import path so intra-module calls
stay correctly aliased.
3. CLI's maybe_register_jit calls inline_imports BEFORE
compile_program. Without this, the bytecode compiler sees
Statement::Import as a no-op and the JIT only sees the top-level
user fns (Path B's "1/4 fns JIT'd" finding).
4. omnimcode-codegen jit_module: dependency-cleanup fixpoint pass.
Previously, when a fn body failed to lower mid-emission, we left
a "broken stub returns 0" body in place. That caused silent
wrong-results in callers. Now: failed fns are deleted entirely;
any fn that called a deleted fn cascades to also-deleted; iterate
to fixpoint. Honest: only ship fns whose full dep graph compiled.
5. Two new substrate intrinsics callable from JIT'd code:
- omc_log_phi_pi_fibonacci(arg_bits) -> i64 (float-bit-pattern)
- omc_fold(value) -> i64
Both pre-declared in JitContext::new with global mappings.
Op::Fold1 now lowers via omc_fold; Op::Call("log_phi_pi_fibonacci")
intercepted as intrinsic. Without these, _bucket_log couldn't JIT
and the cleanup pass would cascade-delete the entire harmonic
library.
6. Compiler infer_type tagged log_phi_pi_fibonacci as float-returning
so `logv * 50.0` emits Op::MulFloat. Bumped harmonic_anomaly's
bucket fn to use 50.0 (not 50) so the multiplication is provably
float-typed.
What works after this:
- ha.score JITs; small test ha.score(det, [1, 2]) returns 0.268
(correct, matches tree-walk)
- Tests 1-5 of harmonic_libs (4 anomaly + 1 clustering) pass under
OMC_HBIT_JIT=1
- 15/53 user fns JIT in the NSL-KDD program (vs 1/4 before)
What does NOT yet work (added as L1.5 follow-up task):
- JIT execution of the full NSL-KDD program is FLAKY (1/5 runs
succeed; 4/5 segfault before producing output). The runs that
succeed produce the correct anomaly numbers. The flakiness is
almost certainly an MCJIT memory-protection or cross-fn-call
lifetime issue, not an algorithmic correctness bug. Investigate
in its own session.
- Tests 6+ in harmonic_libs (clustering + recommend) segfault under
JIT — those libs still use dict-based representations.
Workspace: 41 codegen tests pass, 149 core unit tests pass. The
harmonic_lib test suite passes 18/18 in tree-walk; tests 1-5 pass
under JIT before the clustering segfault.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 0fe4f76 commit 8567aff
6 files changed
Lines changed: 487 additions & 77 deletions
File tree
- examples/lib
- omnimcode-cli/src
- omnimcode-codegen/src
- omnimcode-core/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
30 | 50 | | |
31 | 51 | | |
32 | 52 | | |
33 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
34 | 66 | | |
35 | 67 | | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
43 | 75 | | |
44 | | - | |
| 76 | + | |
45 | 77 | | |
46 | 78 | | |
47 | 79 | | |
48 | 80 | | |
49 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
50 | 87 | | |
51 | 88 | | |
52 | 89 | | |
53 | 90 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
57 | 96 | | |
58 | 97 | | |
59 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
60 | 119 | | |
61 | 120 | | |
62 | 121 | | |
63 | | - | |
64 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
65 | 126 | | |
| 127 | + | |
66 | 128 | | |
67 | 129 | | |
68 | | - | |
69 | | - | |
| 130 | + | |
| 131 | + | |
70 | 132 | | |
71 | 133 | | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
78 | 149 | | |
79 | 150 | | |
80 | 151 | | |
81 | 152 | | |
82 | 153 | | |
83 | 154 | | |
84 | | - | |
85 | | - | |
86 | | - | |
| 155 | + | |
| 156 | + | |
87 | 157 | | |
88 | 158 | | |
89 | 159 | | |
90 | 160 | | |
91 | | - | |
| 161 | + | |
| 162 | + | |
92 | 163 | | |
93 | | - | |
94 | | - | |
95 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
96 | 168 | | |
97 | 169 | | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | 170 | | |
104 | 171 | | |
105 | 172 | | |
106 | 173 | | |
107 | 174 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
113 | 186 | | |
114 | 187 | | |
115 | 188 | | |
116 | 189 | | |
117 | | - | |
118 | | - | |
| 190 | + | |
119 | 191 | | |
120 | 192 | | |
121 | 193 | | |
122 | 194 | | |
123 | 195 | | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
124 | 201 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
130 | 207 | | |
131 | 208 | | |
132 | 209 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
138 | 219 | | |
139 | | - | |
140 | | - | |
| 220 | + | |
| 221 | + | |
141 | 222 | | |
142 | 223 | | |
143 | 224 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
120 | 120 | | |
121 | 121 | | |
122 | 122 | | |
123 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
124 | 141 | | |
125 | 142 | | |
126 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
393 | 393 | | |
394 | 394 | | |
395 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
396 | 426 | | |
397 | 427 | | |
398 | 428 | | |
| |||
593 | 623 | | |
594 | 624 | | |
595 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
596 | 660 | | |
597 | 661 | | |
598 | 662 | | |
| |||
0 commit comments