Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/spec/omegese-om2.md # 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 Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / spec / omegese-om2.md` 256 lines · 19121 bytes Raw Blame History Rendered 1 # Omegese profile OM-2: contract for the compact checked SHA slice (#599, #625, #748) 2 3 Status: FROZEN 2026-10-25 by the #599 language-evolution coordinator (ledger L835) after two 4 independent reviews of the first draft (Codex Sol and Claude Opus, both HOLD; every finding is 5 resolved below). It governs #655, #745, #746, #665 and #747, and is additive to 6 `docs/one_layer/OMEGESE.md`, which stays normative for everything not stated here. A change after 7 freeze needs `omegese-om3.md`. 8 9 ## 0. Profiles, opt-in and compatibility 10 11 - **OM-1** is the language of the pinned seed-born omc, sha256 12 ``734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61`` (main ``acb3f15c``). 13 - **OM-2 is opt-in per unit.** A unit is OM-2 iff its first line that is not a `note` is exactly `om2`. 14 OM-1 refuses that line (fixture under `734f0a39`). The words of sections 2-7 are reserved and 15 recognised only in OM-2 units. An OM-1 unit keeps every name it has today, including the existing 16 user functions `rotr` (`om/blake3/blake3.om:68`) and the names `fresh` and `at`. 17 - **C1 (meaning).** Every OM-1 unit keeps its verdict, error code and line, stdout, exit status, trap 18 code and trap order. 19 - **C2 (bytes).** Every OM-1 unit in the frozen manifest `seed/qualification/om2/manifest-c2.txt` (the 20 #748 lane enumerates it from `seed/rung4/tests`, the seed gate corpora, `om/**/*.om`, the om-units, 21 the gate669 corpus, refusals included) compiles to byte-identical output, or to the identical error, 22 under `734f0a39` and the OM-2 compiler. This is checked per manifest entry and is not claimed beyond 23 it. omc.om itself is excluded; it must still pass the full birth (`seed/omega-from-seed.sh`: om4(omc.om) 24 == omc(omc.om) == omc(omc(omc.om))). 25 A declared delta, `seed/qualification/om2/manifest-c2-*.txt`, replaces named rows whose result a later 26 reviewed change altered and states why; the frozen rows are still replayed against their pinned 27 compiler; a row a delta names is judged by the delta. One delta is a language decision rather 28 than a code change: `manifest-c2-longnames.txt` (Drake, 2026-11-08), where names of 9 to 63 bytes 29 became valid (OMEGESE.md 9.2) and 28 gate-made inputs that relied on error 13 for them changed result. 30 - **C3 (om4 subset).** Because of the om4 == omc birth rule, the compiler's own source stays inside 31 om4's language. omc therefore cannot read its own argv, so all modes are selected in-band (sections 32 1 and 2). The compiler's identity is supplied by the harness, never self-reported. 33 - **C4 (opt-in optimization).** Code-changing transformations (section 4) apply only where an OM-2 34 unit requests them. A missing proof never becomes permission to optimize: the compiler emits the 35 checked code or refuses with a named obligation. 36 37 ## 1. Diagnostics (#655) 38 39 - The human line stays exactly `omc: line N: error E` on stderr, and stdout carries only the artifact. 40 Nothing goes to stdout on refusal. Compilation stops at the first error, as today. 41 - **In-band mode:** in an OM-2 unit, the line `om2 diag` (instead of `om2`) makes omc write one machine 42 record after the human line: 43 `omc-diag 1 code=E sev=S line=N col=C span=A-B expect=K found=H obligation=O profile=OM-2` 44 - `A-B`: a half-open byte span into the exact input bytes. 45 - `H`: at most 32 bytes, hex-encoded. 46 - `K`: one of `value type name word number end newline`. 47 - `O`: one of `- init ctor layout bounds growth regs`. 48 - `S` is `incomplete` only when the failure is at end of input and some continuation of the input 49 could be accepted. Two cases are `unknown`: a reference to a function or struct that is not yet 50 declared, and an incomplete argument list of a call to a function whose signature has not been 51 read. These depend on later text (#655 milestone B). Every other failure is `error`. 52 - Source identity: the harness pairs each diagnostic with sha256(input) and the compiler pin. A 53 diagnostic from a different input digest is stale and must be discarded by consumers. 54 - Suggested repairs are never emitted. 55 56 ## 2. Literals, expression boundaries and the formatter (#745) 57 58 - **Hex literal (OM-2 units):** `0x` followed by 1..16 digits `0-9a-f`. Its value is the unsigned 59 integer, and it takes the type the place needs under exactly the decimal range rule (error 8 60 outside). `0xffffffff` for `int` is error 8; there is no two's-complement reinterpretation. 61 - Error 6: a `-` before a hex literal; `0x` with no digits; more than 16 digits; an uppercase digit 62 or `0X`; `_`; any other character. Uppercase is refused so that each value has one spelling. 63 - `0x2a` and `42` compile identically (fixture). 64 - **Expression boundaries (both profiles, unchanged):** every word has a fixed arity and expressions 65 are prefix. The OM-1 codes for a statement with tokens left after its expression, and for a line that 66 ends before an operand is complete, are pinned by fixtures. Grouping `(`…`)` (§9.10) is unchanged: 67 a group adds no code and never changes which operands a word takes. OM-2 adds no grouping syntax. 68 - **Canonical formatter (in-band):** input whose first line is `om2 fmt` is not compiled. omc writes 69 the canonical text of the rest on stdout. The rules: 70 - single spaces between tokens; leading indentation preserved as given; no trailing spaces; LF line 71 ends (CR refused, error 6); exactly one final LF; 72 - every `note` line, and every `text` literal's bytes, preserved exactly; 73 - nothing else is rewritten. 74 - **Properties:** fmt is idempotent, and compile(fmt(x)) is byte-identical to compile(x) for every 75 accepted x. Malformed input is refused with its compile error code and nothing on stdout. 76 - The source digest of fmt(x) differs from that of x in general: identity is always of exact bytes, 77 and the line mapping is identity because fmt never adds or removes lines (fixture). 78 79 ## 3. Rotate (#665) 80 81 - In an OM-2 unit, `rotr x n` and `rotl x n` for unsigned `x` of type uchar, ushort, uint or ulong, 82 with `n` of the same type. The result has `x`'s type, and its value is the rotation of the w-bit 83 pattern (w = 8, 16, 32, 64). Signed `x` is error 7. 84 - `n` must be in 0..w-1; n = 0 is the identity. n >= w traps 7 at run time, the same as OM-1 shifts, 85 including a constant n (OM-1 also compiles a constant out-of-range shift to the runtime trap, 86 `omc.om:2394`). 87 - **Lowering:** uint/ulong with constant n in range gives one `ROR` (immediate). Other n gives the 88 range check then `RORV`. uchar/ushort may use shifts; the result is exact. 89 90 ## 4. Unrolling, inlining, folding and checks (#665) 91 92 - **`for i T K unroll`** (K a number 1..64, in an OM-2 unit) emits the body K times, with `i` bound to 93 the constants 0..K-1. 94 - A write to `i` in the body is error 7. 95 - `break`/`continue` in an unrolled body is error 9. 96 - Removing `unroll` must leave observable behaviour unchanged. A gate compiles both forms of every 97 unrolled fixture and compares their runs. 98 - **`fn NAME ... to T inline`** (OM-2) marks a function for inlining. Rules: 99 - The function must not be recursive and must contain no `new` (error 9). 100 - Arguments are evaluated left to right before the body, exactly as for a call. 101 - Traps, their order and their codes are unchanged, and removing `inline` must leave behaviour 102 unchanged (same gate). 103 - Calls to functions without `inline` stay calls. 104 - **Parameter slots (function mode):** an unsized view or edit takes two of the six parameter slots, 105 pointer first and then length; a sized array, layout or `out` takes one slot (its pointer); a scalar 106 takes one. More than six slots is error 9. The bridge passes the slots in this order. 107 - **Folding:** only inside unrolled or inlined bodies, an operation whose operands are all constants is 108 computed at compile time with exactly OM-1 arithmetic. An operation that would trap is not folded and 109 stays the runtime trap, so a guarded `if ne i 0` / `div 100 i` compiles and behaves as before. 110 - **Check elimination:** an index into a SIZED array that is a constant after unrolling or folding is 111 checked at compile time (error 21 outside) and gets no runtime check. Every other index keeps its 112 runtime check. That includes every index into an unsized view (section 6) and every conversion range 113 check. No other check is eliminated in OM-2. 114 - **Resource bounds:** an unrolled body is at most 64 copies, and inlining at most 4 levels deep. 115 Anything beyond that is error 14 with `obligation=growth`. The 16-register limit stays error 12 116 (`obligation=regs`): there is no spilling. Each bound limits compiler work and memory linearly in the 117 output. The per-function stack of an inlined body counts toward the caller's frame under the OM-1 118 4 MiB local-array rule. A function's emitted words have no bound of their own since 2026-11-11 (the 119 65536-word bound, which refused a unit such as 6553 view calls in one body, was a table size, not a 120 rule; OMEGESE 9.6): the output is part of omc's arena, and trap branches stay in reach through 121 islands of trap stubs inside a long function. 122 - **Source mapping:** every emitted instruction keeps its source line. With `om2 diag`, a runtime trap 123 site table is written after the artifact on stderr as `omc-site 1 line=N iter=k` records (k for 124 unrolled copies, `-` otherwise). This does not change stdout. 125 126 ## 5. Initialization and representation invariants (#746) 127 128 - **Fresh scratch:** `NAME edit T N fresh` (OM-2; N ≤ 64) tells the compiler the incoming contents are 129 unspecified. 130 - The compiler keeps one may-be-unwritten bit per element, and intersects the written sets at every 131 control-flow join. A rolled loop contributes nothing, because no induction is attempted. 132 - A `get NAME i` with a constant i (after unrolling and inlining) whose bit is not definitely written 133 is error 27 (`obligation=init`). A `get` with a non-constant index is error 27 unless all N bits are 134 definitely written. 135 - Passing NAME to a non-inline call, to `read`/`write`, or to `part` is error 27. 136 - Storage being initialized is distinct from the logical range the caller uses: `fresh` promises 137 nothing about what is left behind. 138 - Analysis storage is one 64-bit set per open block, bounded by the 512-block limit. 139 - **Abstract types:** `abstract NAME T` (OM-2; NAME ≤ 8 characters; T uint or ulong) declares a type 140 representation-equal to T but distinct from it. 141 - **Construction:** `seal NAME v` is allowed only in the function named `NAME` followed by `mk` (for 142 example `dup32mk`), which must return NAME. A `seal` anywhere else is error 28 143 (`obligation=ctor`). 144 - **Use:** `open v` gives the T value. A T value or a bare number where NAME is required is error 7. 145 - **No external values:** NAME may not be a parameter or return type of the unit's entry function, and 146 there are no arrays of NAME. External bytes therefore never become NAME without passing through the 147 constructor. 148 - **Preserving operations**, from a fixed table: `rotr NAME n` and `rotl NAME n` (64-bit rotation of a 149 dup value is the dup of the 32-bit rotation by n mod 32), and `and`/`or`/`xor` of two NAME values. 150 Each returns NAME, and is allowed only when the `abstract` line lists it (`abstract dup32 ulong ops 151 rotr xor`). Every other operation needs `open` first. 152 - **Invariant:** `holds NAME dup32` attaches the one built-in predicate of OM-2, `dup32`: 153 high32(v) == low32(v). The constructor body must be exactly 154 `ret seal NAME or shl ulong x 32 ulong x` with `x` a uint parameter. uint values are held 155 zero-extended in registers (`omc.om` conversion rule), which is the premise of the #748 arithmetic. 156 With that exact body the check is erased, rule `dup32`. Any other constructor body keeps a runtime 157 check (trap 10 on false). Any other predicate is error 28. `om2 diag` reports every kept and every 158 erased check as `omc-check 1 kept|erased line=N rule=dup32|-`. 159 - Trap 10 is also available to user code, so the trap site, not the code alone, identifies a 160 violation. 161 - **External layout:** `layout NAME SIZE` followed by one line per field 162 `field F T [COUNT] at OFF little|big`, then `end`, before the first `fn` (OM-2; NAME and F ≤ 8 163 characters; SIZE 1..4096; COUNT 1..4096). 164 - A parameter `c edit NAME` or `c view NAME` takes a `uchar` array of exactly SIZE bytes (ABI: 165 `(uint8_t *ptr)` with SIZE fixed, alignment 1). 166 - `get c F [i]` and `put c F [i] v` access the field at its declared width and endianness, with the 167 index checked like an array's. 168 - Overlapping fields, a field past SIZE, and a COUNT or OFF out of range are error 29 169 (`obligation=layout`). 170 - Structs (§9.7: 8-byte cells) are unchanged and never assumed C-compatible. 171 - SHA's context: `layout shactx 104`, `field state uint 8 at 0 little`, `field count ulong 1 at 32 172 little`, `field buf uchar 64 at 40 little`, `end`. This must equal `src/sha256.h` on LP64 AArch64 173 Linux; an `offsetof` oracle checks it outside the delivered closure. 174 175 ## 6. Variable-length views and native ABI v2 (#747) 176 177 - **Unsized views (OM-2):** `NAME view T *` and `NAME edit T *` are parameters with run-time length 178 `len NAME` (ulong). Every element index is checked at run time (trap 3); none is eliminated. 179 `read`/`write`/`pread`/`pwrite` keep their slice checks. A local `new` stays sized. 180 - **Subview:** `part A o k` is the view of the k elements of A starting at o. 181 - It is formed only after the checks `o <= len A` and `k <= len A - o`, in that order; otherwise it 182 traps 3. The wrapped `o + k <= len A` is never used (#748 golden: len = 2^64-1, o = 2^64-2, k = 4). 183 - `o` is evaluated before `k`. A `part` is allowed only as a call argument. 184 - A part of a view is a view, and a part of an edit is an edit or, with `view` in front, a view. 185 - For the distinct-names rule (error 19), a part counts as its base array, so two parts of one array 186 in one call are error 19 whatever their ranges. No range-disjointness reasoning is attempted. 187 - A part lives only for the call it is passed to. 188 - **ABI v2** (omega-bridge `docs/NATIVE-ABI.md`, sole writer L837). These rules add to every v1 rule 189 and check, including the v1 address-wrap and result-overlap checks: 190 - **Symbol versioning:** a unit with any unsized view or layout parameter is bound as 191 `omega2_`. No `omega_` is emitted for it, so a v1 caller fails at link time, which is the 192 explicit refusal. Every language binding uses the versioned symbol. 193 - An unsized view argument is `(const T *ptr, uint64_t len)`, or `(T *ptr, uint64_t len)` for edit, 194 with `len` counted in elements. 195 - **Before any Omega code runs**, the bridge returns status 32 (refuse) if: 196 - `len > 0` and `ptr == NULL`; 197 - `ptr` is not aligned to sizeof(T); 198 - `len * sizeof(T)` overflows 64 bits; 199 - `ptr + len*sizeof(T)` wraps; 200 - an `edit` range overlaps any other array argument's range or the result buffer. Ranges are 201 half-open, and an empty range overlaps nothing. 202 - `len == 0` with any pointer (NULL included) is an empty view. 203 - Status 33 keeps its v1 meaning (reentry). 204 - **Outputs:** a parameter declared `NAME out T N` (OM-2, sized) is written to a binding-owned buffer 205 and copied to the caller's pointer only after status 0, with memmove semantics. It may therefore 206 overlap inputs, as `sha256_hash(buf, n, buf)` does today, and nothing is written to it on a trap. 207 - **Unsupported (caller precondition, not detected):** the bridge does not check that the memory 208 exists for `len` elements, that it is writable, or that it stays alive during the call. Forged 209 lengths and read-only memory passed as edit are UNSUPPORTED and outside the guarantee. 210 - **Stack:** function-mode stack exhaustion is not converted to a status. It faults as in v1 211 (NATIVE-ABI.md), and this is UNSUPPORTED. 212 - **Multi-entry units:** a unit may export several entries with `export fn NAME ...` (OM-2); each gets 213 its own versioned symbol. A non-exported function stays private. Without any `export`, the v1 rule 214 (the last `fn` is the entry) holds. 215 - **Module boundary:** separately compiled units are linked only through their exported symbols, and 216 each binding embeds its unit's source sha256, the omc pin and the profile (`OM-1` or `OM-2`). 217 `om/units.sh --check` refuses a stale unit, compiler or profile. A test links two units into one 218 binary and calls them interleaved. 219 220 ## 7. SHA consumer semantics (#747/#748) 221 222 - The API `sha256_init/update/final/hash` of `src/sha256.h` is preserved, including updates of length 0 223 or at least 2^32, any split points, and `sha256_hash` with digest overlapping data. The four 224 functions become `export` entries of the SHA unit. If the C names cannot be emitted directly by the 225 bridge, a generated declaration header (bridge output, not handwritten C) provides them. No 226 handwritten C logic remains. 227 - **Post-final:** after `final`, the context's contents are unspecified, and memory safety is the only 228 guarantee. An `update` or `final` without `init` gives an unspecified digest. A receipt shows that 229 init → update → final after a final equals the same sequence on a fresh context. No whole-context 230 byte equality with the replaced implementation is claimed. 231 - `hash` of n bytes equals init → update(n) → final (receipt). 232 233 ## 8. Effects, traps and leakage 234 235 - **Effects:** the SHA unit makes no system calls, and writes only to its `edit`/`out` arguments. 236 - **Traps:** codes 1..14 as in OM-1, with 10 also used by kept invariant checks. New compile errors: 237 27 init, 28 ctor, 29 layout. Error 24 keeps its OM-1 meaning (branch displacement). 238 - **Leakage model:** the observer sees the executed instruction-address sequence and the data-address 239 sequence on the host CPU, not values. 240 - **Required property, trace equivalence:** for two messages with equal lengths, op codes and call 241 sequence, the SHA unit's executed instruction-address and data-address traces are identical. 242 - **Evidence:** (a) a static scan of the emitted code listing every conditional branch and every 243 indexed address, each classified as length-dependent or data-dependent; a data-dependent branch 244 must be a never-taken check (for example the uint conversion range check after `and x 0xffffffff`), 245 and is listed; (b) a dynamic comparison of traces for seeded message pairs, where tooling permits; 246 otherwise NOT_RUN. 247 - Never-taken data-dependent branches are a speculative-execution channel. Speculative constant-time 248 is UNSUPPORTED, as are claims about instruction latency or caches. No constant-time claim is made 249 beyond trace equivalence on the tested host. 250 251 ## 9. Evidence classes 252 253 Every acceptance result is labelled SOURCE (text or static check), HOST (GB10 host CPU, AArch64 254 Linux), EMULATED (qemu or a simulator), or PHYSICAL-GPU (none in this slice). RULE means a stated 255 static rule plus its fixtures; it is not a mechanized proof. Differential tests are finite. NOT_RUN is 256 never PASS. Authors do not certify their own lane: the #748 lane (L836) qualifies independently.