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-2-DESIGN.md

545 lines · 31146 bytes Raw Blame History Source

OSC-2: the second compiler slice (design, normative)

OSC-2 slice; not a general Omega compiler; no self-hosting.

Status note 2026-10-01: OSC-2 items 1 to 4 are merged (omega#148 0abdb08 contracts, #149 845dce4 structs, #150 c773622 arenas, #151 7e713e3 writer range checks). Status is IMPLEMENTED / NOT QUALIFIED (host receipts only). Shortfalls against the ADR and audit III.7 are listed in the addendum of docs/osc/OSC-1-SELF-HOST-STATEMENT.md.

OSC-2 extends the OSC-1 slice (docs/osc/OSC-1-DESIGN.md) item by item. Everything OSC-1 states stays in force unless a section below changes it. Each item ships with its own golden programs, named negatives, fuzz coverage and a receipt (make osc2-receipt ITEM=<name>, schema omega.osc2.compiler.receipt.v1, written to evidence/OSC-2/receipts/osc2-<item>-<sha256>.json).

1. Contracts

1.1 Subset statement

OSC-1 parsed requires / ensures and recorded them as text only. OSC-2 item 1 makes them enforced contracts:

Functions without clauses compile to byte-identical IR and machine code compared with OSC-1 (checked for every program in tests/compiler/progs/ that existed before OSC-2).

1.2 Grammar change

fn_decl   = "fn" ident "(" [ params ] ")" [ "->" type ]
            [ "requires" expr ] [ "ensures" expr ] block ;

clause = { token } from OSC-1 section 2 is replaced by expr. The clause must be followed by ensures (after requires) or by the function's {. An empty clause is a SYNTAX error. The source text is still recorded in OscFunc.requires_text / ensures_text (it is part of the canonical IR encoding, unchanged from OSC-1), rebuilt from the clause tokens with the OSC-1 spacing rule. Longer than 255 bytes is CAPACITY.

1.3 Names a clause may use

clausemay use
requiresparameters; element reads p[i] through any array parameter (own, &, &mut)
ensuresparameters; result (the return value) in a non-void function; element reads only through shared & parameters

1.4 Static enforcement (constant folding only)

The checker evaluates clauses with the same arithmetic as the interpreter (wrap for unsigned, checked for signed). A sub-expression that would trap, an element read and a call are "unknown". && and || are decided left to right, so false && x is false and true || x is true. Three refusals, all CONTRACT_VIOLATION with origin_line = the line of the clause and other = the clause text:

transitionlineobjectwhen
requires is constant false / ensures is constant falseclausefunctionthe clause folds to false on its own
requires false at callcallcalleethe arguments of a call fold to constants that make the callee's requires fold to false
ensures false at returnreturnfunctiona return with a constant value makes ensures fold to false

1.5 Run-time checks

Trap codes 9 and 10 are appended to the OSC-1 list; existing codes are never renumbered. OSC_TRAP_MAX = 10. The back end emits a trap stub only for codes a unit uses, so units without contracts produce the same bytes as OSC-1.

1.6 Elision

1.7 Evidence

2. Structs

2.1 Subset statement

OSC-2 item 2 adds fixed-layout structs to the OSC-1 subset. A struct is a named group of fields that lives in one pool allocation and is handled exactly like an owned array: it is created by its owner, moved, borrowed with & / &mut, and released at scope end. A struct is never a value: there is no struct copy, compare, or return. OSC-2 slice; not a general Omega compiler; no self-hosting.

2.2 Grammar

unit     := (struct | fn)*
struct   := "struct" NAME "{" field ("," field)* "}"
field    := NAME ":" ftype
ftype    := scalar | "[" scalar ";" INT "]"            scalar = integer type or bool
type     := ... | "own" NAME | "&" NAME | "&mut" NAME  (NAME = a declared struct)
let      := ... | "let" NAME ":" "own" NAME "=" NAME "{" init ("," init)* "}" ";"
init     := NAME ":" expr                              (scalar field)
          | NAME ":" "[" expr ";" INT "]"              (array field, INT = its length)
expr     := ... | NAME "." NAME | NAME "." NAME "[" expr "]"
stmt     := ... | NAME "." NAME "=" expr ";" | NAME "." NAME "[" expr "]" "=" expr ";"

2.3 Layout (fixed, part of the IR digest)

2.4 Semantics

2.5 Diagnostics

New kinds (appended; existing kinds unchanged):

KindTransitionCause
UNKNOWN_FIELDaccess unknown field / initialise unknown fields.z or S { z: .. } with no field z
DUPLICATE_FIELDfield initialised twice / field declared twicea field given twice in a literal or declaration
MISSING_FIELDfield not initialiseda literal omits a field
UNDEFINED_TYPEundefined struct typea type name that is not a declared struct
RECURSIVE_STRUCTstruct field of its own typea field whose type names the struct itself

Existing kinds used by structs:

2.6 Limits

2.7 Evidence

3. Arenas

3.1 Subset statement

OSC-2 item 3 wires the OSC-0B region rules (model events REGION_OPEN, ALLOC with a region, REGION_DESTROY) into the compiler. An arena is a bounded block of cells. Objects allocated in it are never released one by one: the whole arena is destroyed when its block ends. OSC-2 slice; not a general Omega compiler; no self-hosting.

3.2 Grammar

stmt     := ... | "arena" NAME "bound" INT block        (INT = K, 1..64 cells)
let      := ... | "let" NAME ":" "own" "[" scalar ";" INT "]" "in" NAME "=" "alloc" "(" expr ")" ";"
              | "let" NAME ":" "own" NAME "in" NAME "=" NAME "{" init ("," init)* "}" ";"

3.3 Semantics

3.4 Diagnostics

New kinds (appended; existing kinds unchanged):

KindTransitionCause
ARENA_ESCAPEouter borrow assigned a borrow of an arena object / borrow of an arena object returned / borrow live at arena enda borrow of an arena object outlives the arena
ARENA_MOVEmove out of arena / move into own parameter / move into arenaany move of an arena object (slice restriction)
ARENA_CAPACITYarena bound outside 1..64 / arena capacity exceededK not in 1..64; definite allocations over K

borrow live at arena end is a defence in depth: with lexical borrows the two other ARENA_ESCAPE checks catch every escape first, so no test reaches it.

Existing kinds used by arenas:

New trap: TRAP ARENA_FULL = 11 (OSC_TRAP_ARENA_FULL, now OSC_TRAP_MAX).

3.5 Limits

3.6 Evidence

4. Legacy AArch64 writer

4.1 Statement

src/aarch64_encoder.c is the instruction writer used by the existing Omega code (omega_program_realize, the matvec emitters, omega_self_host, omega_exec, the polyglot encoder, rx_omega, the M5/M6/M9/M14 gates). Up to OSC-1 it trimmed fields silently (rm & 0x1f, imm19 & 0x7FFFF, (uoff >> scale) & 0xFFF, simm9 & 0x1FF, (shift / 16) & 3, ...), which OSC-0 III.6 says must be hardened (OSC-1-DESIGN.md section 9 left it untouched). OSC-2 item 4 takes option A (fix, not retire):

Option B (keep trimming for a caller that relies on it) was not needed: an audit of all 280 call sites found no caller that passes an out-of-range field. Every constant is in range; computed values are either range-checked by the caller first (src/polyglot/omx_encoder.c, its resolve() branch fix-ups), already cast to the parameter type by the caller (omega_self_host.c instruction counts), or registers X0..X17/XZR. The M6/M9/M14 gates and the host suites in 4.5 run through the strict writer and pass unchanged.

4.2 Ranges (normative)

EmitterFieldAccepted
allrd rn rm rt0..31 (31 is XZR or SP, as the instruction defines)
all with sfsfC bool (0 or 1 by type)
movz movkimm160..65535 (uint16_t)
movz movkshift0, 16, 32, 48 when sf = 1; 0, 16 when sf = 0
bimm26 (words)-2^25 .. 2^25 - 1
b_condcond0..15
b_cond cbz cbnzimm19 (words)-2^18 .. 2^18 - 1
adrimm21 (bytes)-2^20 .. 2^20 - 1
ldr_uoff str_uoffuoff (bytes)multiple of 8 (sf = 1) or 4 (sf = 0), uoff / size <= 4095
ldrb_uoff strb_uoffuoff (bytes)0..4095
ldr_post str_post ldr_x_post str_x_postsimm9-256..255
subs_immimm120..4095

ret has no fields. The "buffer full" result (-1, nothing written) is unchanged.

4.3 Refusal path

A refused call writes nothing and does not advance *pos. It prints exactly one line on stderr,

A64_LEGACY_FIELD_OUT_OF_RANGE <emitter> <field>=<value>

(<emitter> is the C function name, e.g. aarch64_emit_cbz; <field> is the parameter name; <value> is the received value in signed decimal), and then calls abort() (SIGABRT). Abort is deliberate and deterministic: several existing callers ignore the emitter's int result (for example the matvec emitters), and this item may not change callers, so a soft error would silently drop an instruction and produce wrong code. A refusal is a bug in the caller.

4.4 No new callers

tests/compiler/legacy_a64_allowlist.txt lists the 17 C files that include aarch64_encoder.h or name an aarch64_emit_* function (14 callers, the writer itself and its header, this item's test, and seed/check/a64check.c, a reference check that uses the writer only as an oracle for the seed's hand-written words and makes no program with it). tests/compiler/legacy_a64_callers.sh scans every tracked and untracked (not ignored) *.c / *.h file and requires the set to equal the list:

--selftest first proves both refusals fire on a synthetic tree (a new includer, a new direct caller, a stale line). It runs in make test-compiler. The CI compiler job guard now also triggers on src/aarch64_* changes.

4.5 Evidence

4.6 Not covered