Commit ae98ee1
Phase H.4:
examples/self_healing_h4.omc — the user can now DECLARE self-healing
intent in source code, not just rely on the compiler to detect it.
H.1-H.3 all worked on STATIC bugs. H.2's divide-by-singularity check
only fires when the divisor is a LITERAL the compiler can inspect at
compile time. Variables don't trigger it — and the variable case
is where the bug actually ships in real code.
H.4 surfaces a new keyword `safe` that opts an expression into
runtime self-healing semantics. The parser recognises `safe EXPR`
and wraps it as ["SAFE_EXPR", inner]. The encoder rewrites
SAFE_EXPR containing a BIN / to a CALL_BUILTIN safe_divide,
UNCONDITIONALLY — regardless of whether the divisor is a literal or
a variable.
Demo 3 is the headline. Same function in Demo 2 (no `safe`) and
Demo 3 (`safe`):
fn compute(count, mod) {
return safe count / mod; <-- new in Demo 3
}
print(compute(144, 0)); <-- compute on the singular case
Without `safe`: would crash on mod=0. With `safe`: returns 144
(safe_divide → fold_escape(0)=1 → 144/1 = 144). One-keyword
annotation flips a runtime crash into a finite answer on attractor.
No `if mod == 0` boilerplate.
The static healer (H.2) and the user-declared `safe` (H.4) are
COMPLEMENTARY, not redundant. Same primitive (safe_divide); different
trigger conditions.
Demo 4 stitches all three Phase H stages together: token-level
recovery (missing SEMI), AST-level healing (compue → compute typo,
7 → 8 harmonic), and user-declared safe semantics on a dynamic
divisor. Output: 8 (Fibonacci attractor).
The bigger context: for LLM-generated code, failures cluster around
typos, off-by-one constants, and unguarded edge cases — exactly the
three classes Phase H handles. Self-healing as a property of the
target language reduces the defensive-coding burden on the generator.
What's not yet done:
- `safe` only meaningfully rewrites BIN /. Other expressions
wrapped in `safe` are no-ops, reserving the slot for future
runtime guards.
- Indentation-aware brace placement (H.3.1).
- The "stuck" and "exhausted" iteration outcomes remain
unexercised; designing a meaningful demo is future work.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>safe keyword — runtime self-healing as user syntax1 parent 4c2256b commit ae98ee1
2 files changed
Lines changed: 2288 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
7 | 70 | | |
8 | 71 | | |
9 | 72 | | |
| |||
0 commit comments