Commit 0cc0f38
Phase H.5: array-bounds healing via fold_escape on the index
examples/self_healing_h5.omc — `safe arr_get(a, idx)` and
`safe arr_set(a, idx, v)` make out-of-bounds accesses total.
Healing formula:
healed_idx = ((fold_escape(idx) % arr_len(a)) + arr_len(a)) % arr_len(a)
fold_escape pulls the index onto the nearest Fibonacci attractor;
modulo by arr_len keeps it in-bounds. Empty arrays return Null
rather than error. Deterministic, in-bounds, and lands the
access on an attractor index wherever the grid permits.
For safe_arr_get([10, 20, 30], idx):
idx=999 → fold to 610 → 610 % 3 = 1 → returns 20
idx=-5 → fold to -5 → ((-5%3)+3)%3 = 1 → returns 20
Two new host primitives (safe_arr_get, safe_arr_set) compose the
existing fold_to_fibonacci_const helper. The encoder extends the
H.4 SAFE_EXPR rewrite to recognize `safe arr_get(...)` and
`safe arr_set(...)` call shapes. p_stmt gains a SAFE branch so
`safe arr_set(buf, i, v);` works as a bare statement.
Five demos, five convergences. Demo 4 is the visual win — a loop
reading 8 indices off a 5-element array via safe arr_get. Every
output value has φ=1.000. Every OOB read landed on a Fibonacci
attractor.
Known limit: safe arr_set via the OMC bytecode VM is a no-op
because CALL_BUILTIN routes through a synthetic-scope shim that
copies array arguments and loses the mutation. Reads compose
cleanly through either interpretation path. H.5.1 would add an
SAFE_ARR_SET_NAMED opcode pair (same pattern as V.7c's
ARR_SET_NAMED) to fix writes. Demo 4 was rewritten to use safe
arr_get only, avoiding this trap.
README and CHANGELOG updated:
- README "What's proven right now" table adds an H.5 row.
- README headline bullet adds array-index OOB to the bug-class
list and points at h5.omc as the current healer demo.
- The phase arc adds H.5.
- CHANGELOG gets a full H.5 entry above H.4.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent ccccf51 commit 0cc0f38
4 files changed
Lines changed: 2428 additions & 1 deletion
| 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 | + | |
7 | 62 | | |
8 | 63 | | |
9 | 64 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
| 44 | + | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
| |||
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
| 100 | + | |
| 101 | + | |
99 | 102 | | |
100 | 103 | | |
101 | 104 | | |
| |||
0 commit comments