interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / docs / osc / OSC-3-DESIGN.md

318 lines · 18741 bytes Raw Blame History Rendered
1# OSC-3 design: the third Omega Systems Core compiler slice
2
3OSC-3 slice; not a general Omega compiler; no self-hosting.
4
5OSC-3 builds on OSC-2 (docs/osc/OSC-2-DESIGN.md; omega #148..#151) under
6ADR OMEGA-SYSTEMS-CORE-0000. Each item is its own pull request, merged before
7the next, with a content-addressed receipt in `evidence/OSC-3/receipts/`
8written by `make osc3-receipt ITEM=<item> PHYSICS_DIR=<pinned physics>`.
9
10Every OSC-3 receipt records: `make test-compiler-full` PASS (plain and
11ASan/UBSan), contract/struct/arena fuzz with 0 mismatches, runtime model replay
12with 0 rejected runs, the full legacy writer differential, golden and negative
13counts, the golden corpus digests compared program by program with the OSC-2
14encoder receipt (identical unless the item says why), cross-process
15determinism, and the M6/M9/M14 gate logs compared by sha256 with the OSC-2
16encoder receipt. Item-specific evidence lines start with `osc3 <item>:`.
17
18## Item 0: owed external review of OSC-2
19
20OSC-2 (#148..#151) was reviewed only by the Gemini fallback because Codex was
21at its usage limit. The owed Codex review ran on 2026-10-01: first attempt
2211:30Z refused (usage limit, reset 12:03Z); second attempt 12:04Z,
23`codex exec -s read-only -c model="gpt-6-astra"` over
24`git diff 0abdb08^..7e713e3 -- src/compiler src/language tests/compiler mk/compiler.mk src/aarch64_encoder.c`,
25asked for correctness bugs only (miscompilation, interpreter/native
26disagreement, missed contract traps, unsound ownership/borrow/arena checks,
27compiler memory safety, layout, encoder ranges) with concrete failing inputs.
28Result: **NO FINDINGS**. No item 0 fix PR was needed; the result is recorded
29here and in the item 1 pull request.
30
31## Item 1: quick and full compiler suites
32
33`make test-compiler` had grown to 1m32..2m23 single core, mostly the legacy
34writer's exhaustive differential and the full fuzz counts, against a 3-minute
35budget. It is split:
36
37- `make test-compiler-full`: everything, at the full counts. This is the old
38 `test-compiler` (kept as an alias with the same meaning). Receipts use it.
39 CI runs it when `src/compiler/` or `src/aarch64_*` changes.
40- `make test-compiler-quick`: the same binaries, every golden and negative
41 program, determinism, the legacy caller allowlist; smaller sweeps (model
42 10^5 sequences, compiler fuzz 120 per entry, plain and under ASan/UBSan (smaller counts miss coverage checks),
43 legacy writer differential in its sampled mode). Target under 60 s single
44 core. CI runs it on every change to the compiler paths. It is a smoke run
45 and is never receipt evidence.
46
47The quick wall time is measured inside every OSC-3 receipt
48(`test_compiler_quick.wall_seconds`, binaries already built).
49
50CI: the `compiler` job in `.github/workflows/host-suites.yml` runs quick on
51every pull request touching the compiler paths and full when `src/compiler/`
52or `src/aarch64_*` changes. Since omega #154 (Lane 34) the workflow also runs
53on every push to main, and the compiler job then runs quick and full, so main
54has its own post-merge result (the 2026-10-01 audit found the compiler suites
55never ran after merge). An earlier draft of this item added a separate
56`compiler-main.yml` for this; it was dropped as redundant after #154.
57
58## Item 2: versioned handles
59
60The OSC-0B model (`src/compiler/model/osc_model.h`) gives slots u64
61generations with `SLOT_ALLOC` / `SLOT_FREE` / `HANDLE_USE` events: a use or
62free with the wrong generation is `STALE_GENERATION`, and a slot freed at
63`gen_max` is retired, never wrapped (`GENERATION_WRAP`). Item 2 compiles that
64discipline.
65
66### Subset
67
68- A pool is a fixed-capacity block of K slots (1..16) of one scalar type,
69 local to one function. It is declared as a block statement and closed at
70 the end of that block (also on a `return` from inside it), like an arena.
71- A handle is a (slot, u64 generation) pair of one pool. Handles are
72 copyable values and never owners: copying a handle does not move
73 anything, a handle going out of scope frees nothing, and closing the pool
74 ends every slot whatever handles exist.
75- Pools and handles do not cross function boundaries (parameters, returns),
76 are not struct fields or array elements, and are never values in
77 arithmetic, comparisons or `return`.
78- The subset has no durable encoder: no handle (and no borrow) can be
79 written to durable state. The model's `LIVE_HANDLE_DURABLE` refusal is
80 therefore unreachable from compiled code; a durable writer for handles
81 must name that refusal before it exists.
82
83### Grammar
84
85```
86stmt += 'pool' NAME ':' '[' scalar ';' INT ']' ( 'gen' INT )? block
87 | 'let' 'mut'? NAME ':' 'handle' NAME '=' hexpr ';'
88 | NAME '.' 'free' '(' NAME ')' ';'
89 | NAME '[' NAME ']' '=' expr ';' (pool write)
90 | NAME '=' hexpr ';' (handle rebind, NAME mut)
91hexpr := NAME '.' 'alloc' '(' expr ')' | NAME (a handle of the same pool)
92expr += NAME '[' NAME ']' (pool read)
93```
94
95`gen INT` declares the generation base (default 0): every slot starts at
96that generation. It exists so tests can reach exhaustion with a few
97allocations; the base is part of the unit's canonical encoding.
98
99### Semantics
100
101- `p.alloc(e)` takes the lowest free slot, stores `e`, and yields
102 (slot, current generation of that slot).
103- `p.free(h)` checks h, then advances the slot's generation; at
104 2^64 - 1 the slot is retired instead and is never allocated again.
105- `p[h]` and `p[h] = e` check h: the slot must be live and its generation
106 must equal h's.
107- Run-time traps (identical in the interpreter and native AArch64, which
108 share the runtime through fixed function-pointer offsets 48..96):
109 `STALE` (wrong generation or slot not live, on use or free),
110 `RETIRED` (alloc with no free slot while some slot is retired) and
111 `POOL_FULL` (alloc with every slot live).
112- Every pool operation is logged (`POOL_OPEN`, `SLOT_ALLOC`, `SLOT_FREE`,
113 `HANDLE_USE` with rights 1 = read / 2 = write, `POOL_CLOSE`) with its
114 generation folded into the event hash. The test harness replays each
115 native run's log through `osc_model` (one model per pool, base = declared
116 base, max = 2^64 - 1) and requires rejected = 0; for a trapping run the
117 prefix replays clean and the trap itself is confirmed by the model
118 (`STALE` as `STALE_GENERATION`, `RETIRED` as `GENERATION_WRAP` on every
119 slot, `POOL_FULL` as `PROTOCOL` on every slot).
120
121### Static refusals (named)
122
123The checker tracks a provenance per allocation; copies share it. A
124provenance is freed when every path freed it (branch merge intersects).
125
126| Diagnostic | Transition | When |
127|---|---|---|
128| `STALE_HANDLE` | read / write after free | use of a handle whose slot was freed on every path |
129| `STALE_HANDLE` | ... via a copy | the same through a copy made before the free |
130| `STALE_HANDLE` | free after free | double free (also via a copy) |
131| `GENERATION_EXHAUSTED` | retired slot reused | definite allocations exceed K x (2^64 - base) |
132| `POOL_CAPACITY` | pool full | definite live allocations exceed K |
133| `POOL_CAPACITY` | pool size outside 1..16 | K outside 1..16 |
134| `WRONG_POOL` | handle of another pool | handle of pool p used with pool q, or `q.alloc` bound as a handle of p |
135| `TYPE_MISMATCH` | handle / pool used as a value; pool index not a handle | type confusion |
136| `UNSUPPORTED` | handle crosses a function boundary | pool or handle parameter or return type |
137| `IMMUTABLE_ASSIGN` | | rebinding a handle declared without `mut` |
138
139"Definite" means at the pool's own loop and branch depth. Allocations inside
140loops or branches are not counted; once a free happens behind a branch or
141loop, the live count is no longer tracked statically (the generation count
142still is). What the checker cannot decide is checked at run time (the traps
143above).
144
145### Limits
146
147- 16 slots per pool, 8 pools open at once per run, scalar elements only.
148- No handle parameters or returns, no handles in structs or arrays, no
149 durable encoding (see Subset).
150- The model replay has 64 handle ids; the harness re-windows the model
151 (fresh model seeded with the live slots and their generations) past that.
152- Serial counters (audit finding): the runtime's object/region serial
153 (`next_serial`) and the pool instance serial (`pool_serial`) stay `uint32_t`
154 (they are hashed into the event log as 4 bytes, so widening them would
155 change every logged run digest). Instead they never wrap: an allocation,
156 arena open, arena allocation or pool open with its counter at `UINT32_MAX`
157 traps `RUNTIME` before any state changes, identically in the interpreter and
158 native code (both call the same runtime). The handle fuzz leg checks all
159 four sites directly. Handle generations themselves are `u64` and retire at
160 2^64 - 1 (above).
161
162### Evidence
163
164Measured on the Spark, single core, `nice` (full counts = `make
165test-compiler-full`, identical plain and under ASan/UBSan):
166
167```
168osc3 handles: units=125 compiled=102 static_refused=23 runs=4896 ok=2705 stale_traps=1616 pool_full=530 retired=45 overflow=0 mismatches=0
169osc3 handles: model replay pool_events=48807 stale_confirmed=1616 wrap_confirmed=45 full_confirmed=530 windows=0 (handle fuzz runs only)
170osc3 handles: serial counters at UINT32_MAX trap RUNTIME, never wrap: 4 of 4
171runtime model replay: ... rejected=0
172```
173
174- Every run is executed by the interpreter and natively; outcomes (return
175 value or trap, runtime state, event log with generations) are identical.
176- Every native run's event log replays through `osc_model`; every STALE,
177 RETIRED and POOL_FULL trap is confirmed by the model on the replayed
178 prefix (counts equal the trap counts above). The `cycle` golden (100
179 allocations from one slot) exercises the model re-window.
180- Static refusals in the fuzz are only `STALE_HANDLE` (any other refusal
181 fails the leg).
182- Goldens: `handles_basic`, `handles_stale`, `handles_exhaust` (13
183 `expect-run` lines). Negatives: 15 `h_*` programs, one per refusal above.
184- OSC-1/OSC-2 golden programs compile byte-identically (IR and code digests
185 checked by the item 2 receipt against the OSC-2 baseline).
186- The exact receipt is under `evidence/OSC-3/receipts/osc3-handles-*.json`.
187
188## Item 3: drop flags (conditional moves)
189
190OSC-1 and OSC-2 refused any move of an owner inside an `if`
191(`CONDITIONAL_MOVE`, OSC-1-DESIGN "no drop flags"). Item 3 accepts it: an
192owner that is moved on some paths and not on others gets a hidden drop flag,
193and its scope-end release runs only when the flag says live. This supersedes
194the OSC-1 rule; `CONDITIONAL_MOVE` keeps its number but is no longer emitted.
195
196### Subset
197
198- Owners are unique array owners (`own [T; N]`) and unique struct owners
199 (`own S`), declared by `let` (alloc, struct literal or let-move) or as an
200 `own` parameter. Arena owners (`in r`) are unchanged: they cannot be moved
201 (`ARENA_MOVE`), so they never need a flag. Handles (item 2) own nothing
202 and are out of scope.
203- A move is a let-move (`let b: own T = a;`) or passing the owner as an
204 `own` argument. Either may now sit inside one branch of `if` / `else` /
205 `else if`, at any nesting depth.
206- After an `if`, each owner declared before it is in one of three states:
207 live (moved on no path that falls through), moved (moved on every path
208 that falls through) or maybe-moved (moved on some). A branch that ends in
209 `return` does not count: its state never reaches the join.
210- Only maybe-moved owners get a flag. Programs without a conditional move
211 compile to byte-identical IR and code (no `OSC3_CODE_CHANGE_OK`).
212
213### Grammar
214
215No new syntax. The grammar of OSC-2 is unchanged; programs that OSC-2
216refused with `CONDITIONAL_MOVE` are now accepted when the rules below hold.
217
218### Semantics
219
220- Merge rule at the end of an `if` (both arms falling through): equal
221 states stay; any difference (live vs moved, live vs maybe, moved vs maybe)
222 becomes maybe-moved. If one arm returns, the other arm's state is taken.
223- Flag: one `bool` virtual register per flagged declaration, allocated by
224 the lowerer when the checker marks the declaration (`OscNode.dflag`). It
225 is set to 1 (`CONST 1`) right after the declaration (for an `own`
226 parameter: first thing in the entry block), and set to 0 (`CONST 0`) at
227 every move of that owner (before the `CALL` for an own argument, before
228 the new binding for a let-move), on every path.
229- Release: every scope-end release of a flagged owner (block end and every
230 `return` it is live or maybe-moved at) becomes
231 `CBR flag -> release, join; release: RELEASE owner; BR join`. Owners that
232 are definitely moved are not released (as in OSC-2); live owners without
233 a flag are released unconditionally (as in OSC-2). Release order stays
234 reverse declaration order; a skipped release simply drops out.
235- Loop-local owners: an owner declared inside a loop body may be moved on
236 one path of that body; its declaration sets the flag again each
237 iteration, so each iteration's object is released at most once.
238- Frame layout: the flag is an ordinary vreg, so it has the ordinary stack
239 slot of the native frame, `[sp, #8*(v+1)]` (`osc_cg.c slot()`), holding
240 0 or 1 in a 64-bit cell; non-parameter slots are zeroed by the prologue
241 and the declaration's `CONST 1` sets it. No new IR op, no interpreter or
242 backend change: `CONST`, `CBR`, `BR` and `RELEASE` already exist, so both
243 engines run the same IR and agree by construction.
244- Static model trace: around the `if` the checker emits `SAVE`/`RESTORE`
245 as before. A definitely moved owner gets its `MOVE obj -> 0` re-emitted
246 after the `if` (unchanged). A maybe-moved owner emits nothing after the
247 `if`: on the straight-line trace it stays live and its guarded scope-end
248 `RELEASE` replays as a plain release (the trace follows the path on which
249 the flag is set). Each run's runtime log replays exactly (a release that
250 did not run is simply absent).
251- Soundness argument: the flag equals "this owner's object has not been
252 moved" on every executed path, because it is set at the (re)declaration
253 and cleared at each move, and every release of a flagged owner tests it.
254 So no path releases twice (no `RUNTIME` double-release trap) and no path
255 leaks (live count 0 after a normal return); both are checked on every
256 fuzz run in both engines.
257
258### Static refusals (named)
259
260| Diagnostic | Transition | When |
261|---|---|---|
262| `USE_AFTER_MOVE` | use after maybe-move | read, write, field access or call use of a maybe-moved owner ("used after it may have been moved at line N (moved on some path of an 'if')") |
263| `USE_AFTER_MOVE` | use after maybe-move | borrow (`&` / `&mut`) of a maybe-moved owner |
264| `USE_AFTER_MOVE` | use after maybe-move | moving a maybe-moved owner again (double move across branches / two ifs) |
265| `USE_AFTER_MOVE` | use after move (move inside loop) | an owner declared outside a loop moved inside it, also inside an `if` in the loop (unchanged from OSC-1) |
266| `IMMUTABLE_ASSIGN` | assign to immutable binding | re-assigning an owner, maybe-moved or not ("owners are never reassigned"); item 3 does not add a set-live rule |
267
268For the model the maybe-move refusals are use-after-move: the checker emits
269an accepted `MOVE obj -> 0` (the path that moved it) right before the refused
270event, so the negative harness replays them as `use-after-move`.
271
272### Limits
273
274- Flags exist only for owners moved inside `if` arms; moves of an outer
275 owner inside a loop stay refused (no re-initialisation rule).
276- No reassignment of owners (refused), so a flag only goes live -> moved
277 within one declaration's lifetime.
278- One flag per declaration (up to the checker's symbol limit); flags are not
279 packed into bits.
280- The static trace checks the path on which each maybe-moved owner is still
281 live; the moved path is checked by every executed run's runtime replay
282 (fuzz and goldens), not statically.
283
284### Evidence
285
286EVIDENCE_PLACEHOLDER
287
288## Generation width: remaining 32-bit sites and fix plan
289
290ADR OMEGA-SYSTEMS-CORE-0000 decision 1 fixes capability and object generations
291at u64 end to end, a slot retired at the maximum, never wrapped. The 2026-10-01
292audit (track 2, s.F.3) found these sites still 32-bit; checked against main
29307004a8. A u64 generation stored into any of them is silently truncated, and a
294truncated generation can make a stale handle look live again.
295
296| Site (main 07004a8) | Today | Owner | Fix plan |
297|---|---|---|---|
298| `src/runtime/rx_world.h:177` `RxObjRef{uint32_t id; uint32_t generation}` | u32 | runtime lane (src/runtime) | widen `generation` to u64; retire the object id at UINT64_MAX; versioned like omega#71 |
299| `src/runtime/rx_world.h:305` object `generation` | u32 | runtime lane | same change, same PR as :177 |
300| `src/runtime/rx_world.h:328` `RxSub{reaction; generation; mask}` | u32 | runtime lane | widen with :177 (subscriptions compare against object generations) |
301| `src/runtime/rx_world.h:599` `seat_generation` | u32 | runtime lane | widen; retire the seat at max |
302| `src/runtime/rx_graph.c:517, :529` crumb/graph hash writes object generations with `put32` | u32 on the wire | runtime lane | `put64` together with a crumb/graph record version bump (old records refused, not reinterpreted), in the identity-break sequence (item 5) |
303| `src/runtime/rx_jspace.c:1406, :1413, :1414` J-Space body writes branch/slot generations with `put32` | u32 on the wire | runtime lane | `put64` with a J-Space record version bump, same rule |
304| `src/omega_accelerator.h:67, :87` `uint32_t capability_generation` | u32 | accelerator owner (not OSC) | widen to u64, retire at max; ADR decision 1 names this file |
305| `src/compiler/osc_rt.h` `slot_serial[]`, `next_serial`, `pool_serial` | u32, never wraps (item 2) | OSC (this lane) | done in item 2: handle generations are u64 with retire-at-max; the serials stay u32 (hashed into the event log as 4 bytes) and an allocation, arena open, arena allocation or pool open with its counter at UINT32_MAX traps RUNTIME before any state changes (item 2, Limits) |
306| Aienux ADR 0013 (`index u32; generation u32`, retire at u32::MAX) | u32 | aienos lane | request only, see item 5 (`docs/osc/OSC-3-ADR0013-REQUEST.md`); not edited from this repository |
307
308Only the `osc_rt` row is inside this lane's files. The others are listed so the
309owning lanes can schedule them; each is a versioned change with old records
310refused, never reinterpreted. Only the `osc_rt` row is applied by OSC-3 (item 2).
311
312## Slice order after item 4
313
314Per the audit (III.7 and the 2026-10-01 review), the first real migration is
315crumbline (`src/crumbline/`) once effects and capabilities exist:
316item 4 (effects/capabilities), then item 5 (identity break + ADR 0013
317request), then item 6 (crumbline as the first production C module under
318contracts; proposal in docs/osc first).