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/one-layer-format.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 / one-layer-format.md` 704 lines · 41392 bytes Raw Blame History Rendered 1 # Specification: OSC binary IR, canonical format and strict reader 2 3 ```text 4 Document ID: SPEC-ONE-LAYER-FORMAT 5 Issue: aien-spark/omega#444 (one-layer plan, stage 2 "Open the binary front door"); omega#451 (version 6) 6 Status: IMPLEMENTED for format versions 1..6 (reader + writer); version 6 in section 11 7 Code: src/compiler/osc_ir.h (osc_ir_encode, osc_ir_encode_v6, osc_ir_decode, OscIrRefusal) 8 src/compiler/osc_ir.c (encode_unit, encode_unit_v6, unit_version, decode_unit, decode_v6) 9 Tests: tests/compiler/test_osc_ir_decode.c; make test-osc-ir-decode(-quick) 10 Data layout: src/compiler/osc_ir.h is normative for OscUnit; meaning: docs/osc/OSC-1-DESIGN.md 11 ``` 12 13 ## 1. What this format is 14 15 A compiled OSC unit (`OscUnit`, `src/compiler/osc_ir.h`) has one canonical byte form, written by 16 `osc_ir_encode`. Its SHA-256 is the unit's identity (`osc_ir_digest`; docs/osc/OSC-1-DESIGN.md 17 section 4). Until this change the bytes could only be written; `osc_ir_decode` now reads them back 18 without the text front end, so a machine can hand Omega executable meaning as bytes. 19 20 ## 2. Canonical law 21 22 The canonical set is exactly 23 24 { osc_ir_encode(u) : osc_ir_validate(u) == 0 } ∪ { osc_ir_encode_v6(u) : osc_ir_validate(u) == 0 } 25 26 (the second set is format version 6, section 11; `osc_ir_encode` refuses a unit that only 27 version 6 can carry). `osc_ir_decode(buf, len, out)` returns `OSC_IR_OK` only when `buf[0..len)` is in that set, and then 28 fills `out` with the unit `u` that encodes to it. Every other input is refused with one named class 29 (section 7) and `out` is left all zero. The reader never repairs, skips, pads, truncates or guesses. 30 31 Consequences, each checked by `tests/compiler/test_osc_ir_decode.c`: 32 33 - encode -> decode -> encode is byte-identical for every admitted input; 34 - an admitted input re-encodes to exactly itself (no second spelling of a unit exists); 35 - the decoded unit passes `osc_ir_validate`, so the interpreter and back ends accept it. 36 37 ## 3. Wire layout 38 39 All integers little-endian, no padding, no alignment, no pointers. 40 41 ### 3.1 Header 42 43 | bytes | field | 44 |---|---| 45 | 7 | magic `4F 53 43 31 49 52 00` ("OSC1IR\0") | 46 | 1 | version, 1..5 (section 4) | 47 | versions 2..5 only: 1 | `nstructs` 0..16, then `nstructs` struct records (3.2) | 48 | 2 | `nfuncs` 0..32, then `nfuncs` function records (3.3) | 49 50 Nothing may follow the last function record. 51 52 ### 3.2 Struct record (versions 2..5) 53 54 | bytes | field | 55 |---|---| 56 | 1 + n | name: length n 0..63, then n bytes, no NUL | 57 | 1 | `nfields` 0..16 (validation requires 1..16) | 58 | 2 | `ncells` | 59 | per field: 1 + n | field name (as struct name) | 60 | per field: 1 | scalar tag (3.4) | 61 | per field: 2 | `alen` (0 = scalar field) | 62 | per field: 2 | `off` | 63 64 ### 3.3 Function record 65 66 | bytes | field | 67 |---|---| 68 | 1 + n | name: length n 0..63, then n bytes, no NUL | 69 | 1 | `nparams` | 70 | type | return type (3.4) | 71 | 2 | `nvregs` 0..480, then `nvregs` types (3.4) | 72 | 2 | `nblocks` 0..512, then per block: 4 `first`, 4 `count` | 73 | 4 | `ninsns` 0..4096, then `ninsns` instructions (3.5) | 74 | 2 + n | `requires` text: length n 0..255, then n bytes, no NUL | 75 | 2 + n | `ensures` text: as `requires` | 76 77 ### 3.4 Type 78 79 One byte scalar tag: 0 void, 1 bool, 2 u8, 3 u16, 4 u32, 5 u64, 6 i8, 7 i16, 8 i32, 9 i64, 80 10 ref, 11 bytes, 12 cells. Tags above 12 are refused. For every tag except 10 that byte is the 81 whole type (the decoded `ref`, `elem`, `len`, `sid` are 0). Tag 10 (ref) continues: 82 83 | bytes | field | 84 |---|---| 85 | 1 | ref kind: 0 none, 1 own, 2 shared, 3 mut (above 3 refused) | 86 | 1 | element scalar tag | 87 | 2 | `len` | 88 | 1, only when the element tag is 0 (void) | `sid`: struct reference to `structs[sid-1]` | 89 90 An array reference always has a value element type and `sid` 0; a struct reference always has 91 element void and `sid` >= 1 (`type_is_ref`, `src/compiler/osc_ir.c`). The element byte therefore 92 decides, without ambiguity, whether the `sid` byte is present. 93 94 ### 3.5 Instruction 95 96 One opcode byte, then the opcode's fields in this order. `r` is a 2-byte register, block or callee 97 field: 0x0000..0x7FFF, or 0xFFFF for "none" (-1); 0x8000..0xFFFE are refused (RANGE). 98 99 | op | name | fields after the opcode | 100 |---|---|---| 101 | 1 | CONST | r dst, 8 imm | 102 | 2 | MOV | r dst, r a | 103 | 3 | BIN | 1 sub, r dst, r a, r b | 104 | 4 | UN | 1 sub, r dst, r a | 105 | 5 | CMP | 1 sub, r dst, r a, r b | 106 | 6 | CAST | r dst, r a | 107 | 7 | ALLOC | r dst, r a | 108 | 8 | RELEASE | r a | 109 | 9 | LOAD | r dst, r a, r b | 110 | 10 | STORE | r a, r b, r c | 111 | 11 | CALL | r dst, r callee, 1 nargs (0..6; above 6 refused OVERSIZED), nargs x r arg | 112 | 12 | TRAP | 1 imm (trap code) | 113 | 13 | BR | r blk_t | 114 | 14 | CBR | r a, r blk_t, r blk_f | 115 | 15 | RET | r a | 116 | 16 | FLOAD | r dst, r a, r b, 1 imm (field index) | 117 | 17 | FSTORE | r a, r b, r c, 1 imm (field index) | 118 | 18 | AOPEN | r dst, 1 imm (cells) | 119 | 19 | AALLOC | r dst, r a, r b | 120 | 20 | ADESTROY | r a | 121 | 21 | POPEN | r dst, 1 sub (element tag), 1 nargs (slots), 8 imm (generation) | 122 | 22 | PCLOSE | r a | 123 | 23 | HALLOC | r dst, r a, r b | 124 | 24 | HGEN | r dst, r a, r b | 125 | 25 | HFREE | r a, r b, r c | 126 | 26 | HLOAD | r dst, r a, r b, r c | 127 | 27 | HSTORE | r a, r b, r c, r args[0] | 128 | 28 | SLOAD | r dst, r a, r b | 129 | 29 | SSTORE | r a, r b, r c | 130 131 Opcode 0 and opcodes above 29 are refused (RANGE): their length is unknown. The numbers are pinned 132 by `_Static_assert`s in the test. The meaning of every field and every value range that 133 `osc_ir_validate` enforces (types agree, registers in range, blocks partition the instructions, 134 calls only to earlier functions, trap codes 1..14, and the rest) is in `osc_ir.h` and 135 docs/osc/OSC-1-DESIGN.md. 136 137 ### 3.6 Fields the format does not carry 138 139 `OscInsn.line` (debug information; source layout never reaches identity), and per opcode every 140 field not listed in 3.5. The reader sets them as the front end's emitter does 141 (`emit`, `src/compiler/osc_lower.c`): `line` 0; `dst`, `a`, `b`, `c`, `blk_t`, `blk_f`, `callee` 142 -1; everything else 0; HSTORE `nargs` 1. All array entries past a count are 0. The test compares 143 each decoded unit with the unit the compiler produced on every carried field. 144 145 ## 4. Versions and historical readers 146 147 The version byte is a function of the content (`unit_version`, `src/compiler/osc_ir.c`): 5 if any 148 register is a byte slice (bytes/cells), else 4 if any pool instruction (POPEN..HSTORE) occurs, 149 else 3 if any arena instruction (AOPEN, AALLOC, ADESTROY) occurs, else 2 if the unit has structs, 150 else 1. Versions 2..5 share one layout (struct table present, possibly empty); version 1 has no 151 struct table. Every version 1..5 is read. A version byte that is not the one the content requires 152 is refused (VERSION_MISMATCH), so one unit never has two encodings among versions 1..5. Versions 153 are only ever added; an existing version's bytes are never reinterpreted. 154 155 Version 6 (section 11) is not chosen by content: only `osc_ir_encode_v6` writes it, and its 156 domain tag (11.1) keeps it a separate identity domain. `unit_version` and `OSC_IR_VERSION_MAX` (5) 157 are unchanged, so `osc_ir_encode` writes exactly the bytes it wrote before. 158 159 ## 5. Limits 160 161 Counts are checked before anything under them is read: `nstructs` <= 16, `nfields` <= 16, 162 `nfuncs` <= 32, `nvregs` <= 480, `nblocks` <= 512, `ninsns` <= 4096, CALL `nargs` <= 6, names 163 <= 63 bytes, contract texts <= 255 bytes (the `OSC_MAX_*`, `OSC_NAME_MAX`, `OSC_CLAUSE_MAX` 164 constants of `osc_ir.h`). Input longer than `OSC_IR_ENCODED_MAX` (2,620,251 bytes: every count at 165 its maximum, every instruction at the widest form, CALL with six arguments, 18 bytes) is refused 166 before parsing. 167 168 ## 6. Identity 169 170 `identity = SHA-256(canonical bytes)`. The magic and version byte are inside the hashed bytes, so 171 they act as the domain tag that spec/program-identity.md section 2 requires of an identity law: a 172 reader that sees the bytes knows which layout produced them, and two versions can never share a 173 preimage. Function names and the `requires` / `ensures` texts are inside the hashed bytes, so a 174 change to a requirement changes the identity (tested: 514 one-character changes over the corpus, 175 each a new digest, each round-trips). OSC unit identity is separate from Omega program identity v2 176 (`omega.program.v2`, spec/program-identity.md); this change does not alter either law. Version 6 177 has its own identity law (section 11.7): names excluded, structured contracts included, under the 178 tag `omega.osc.ir.v6`. The law above for versions 1..5 is unchanged. 179 180 ## 7. Refusal classes 181 182 `osc_ir_decode` returns the first defect met while reading front to back; the checks after parsing 183 run in the order listed. `osc_ir_refusal_name` gives the names. Classes -12..-15 exist for 184 version 6 only; section 11.8 gives their meaning, check order and counterexamples. 185 186 | code | class | meaning | counterexample in the test | 187 |---|---|---|---| 188 | -1 | ARG | NULL input or output pointer | `osc_ir_decode(NULL, 8, u)` | 189 | -2 | MAGIC | first 7 bytes are not the magic | "OSC2IR..." | 190 | -3 | UNKNOWN_VERSION | version byte 0 or above 6 | versions 0 and 7 | 191 | -4 | TRUNCATED | input ends inside a field | empty input; last byte missing; magic only | 192 | -5 | OVERSIZED | input over `OSC_IR_ENCODED_MAX`, or a count or length over section 5 | 64-byte name; 481 registers; 256-byte requires text; 2,620,252-byte input | 193 | -6 | TRAILING | bytes after the last function | one extra byte | 194 | -7 | RANGE | unknown opcode, scalar tag or ref kind; a register/block/callee field 0x8000..0xFFFE | opcodes 0 and 30; tag 13; register 0x8000 | 195 | -8 | TEXT | a NUL byte inside a name or contract text (it would read back shorter: ambiguous) | name "f\0g" | 196 | -9 | INVALID | well-formed, but `osc_ir_validate` refuses the unit | u8 constant 256; register out of range | 197 | -10 | VERSION_MISMATCH | version byte differs from the one the content requires (section 4) | version 2 or 5 for a plain unit | 198 | -11 | NONCANONICAL | the unit re-encodes to different bytes | none: unreachable (below) | 199 | -12 | DOMAIN | version 6 without its exact domain tag (11.8) | tag "omega.osc.ir.v7" | 200 | -13 | IDENT | version 6: a numeric identifier or name entry names no object (11.8) | name for function 1 of 1 | 201 | -14 | ORDER | version 6: name table not in canonical order, or an empty entry (11.8) | two names for function 0 | 202 | -15 | CONTRACT | version 6: a malformed requires/ensures object (11.8) | result in a requires clause | 203 204 NONCANONICAL is a backstop. Given the checks above it, every field read back writes back to the 205 same bytes, so no input reaches it; the sweeps assert it is never returned. It is reached only when 206 a check above it is removed: decoder mutants 1, 2, 5 and 8 (section 8), and for version 6 207 mutants 23, 24 and 25 (section 11.9), fall through to it. 208 209 ## 8. Qualification 210 211 `make test-osc-ir-decode` (part of `test-compiler`, the full CI leg) and 212 `make test-osc-ir-decode-quick` (part of `test-compiler-quick`, run on every compiler-path change) 213 build `tests/compiler/test_osc_ir_decode.c` plain and with ASan/UBSan. Measured on the Spark, 214 2026-10-14, full mode: 215 216 - corpus: all 59 units the front end compiles from `tests/compiler/progs`, `tests/compiler/slices`, 217 `src/osh`, `tests/physics0/osc` (32 v1, 7 v2, 6 v3, 3 v4, 11 v5) round-trip byte-exactly and 218 equal the compiled unit on every carried field; 219 - 10,000 distinct valid objects (seeded variants of the corpus: constants, names, contract text, 220 operators, trap codes) round-trip byte-exactly (2,000 under ASan); 221 - 202,675 malformed inputs (every byte of every unit up to 2,000 bytes flipped three ways, every 222 truncation, trailing bytes, seeded multi-byte edits; larger units sampled at an even stride): 223 177,013 refused with a named class and a zeroed unit, 25,662 decoded to a different valid unit 224 that re-encodes to exactly those bytes (for example a changed constant), none admitted otherwise, 225 no crash. The ASan/UBSan build runs the same number of cases (177,177 refused, 25,498 admitted; 226 the random edits differ because it draws fewer valid variants first) with no sanitizer report; 227 - one counterexample per reachable class (section 7), built by an independent writer in the test, 228 whose canonical case is byte-identical to `osc_ir_encode`; 229 - negative controls: 5 planted defects caught by the test's own checks, and 22 decoder mutants 230 (`OSC_IR_DECODE_MUTANT` = 1 no trailing check, 2 no version check, 3 no zeroing on refusal, 231 4 no validation, 5 no NUL check, 6 no register range check, 7 no total size check, 8 truncation 232 read as zeros, 9 no count/length maximum anywhere, 10 unknown opcode admitted, 11..22 one 233 count/length maximum off each: nstructs, nfields, nfuncs, nvregs, nblocks, ninsns, call nargs, 234 function name, requires, ensures, struct name, field name) each make the test fail. 235 236 ## 9. Resolved by version 6 (asked by #444, specified in section 11, omega#451) 237 238 - **Numeric identifiers.** Version 6 identifies functions, structs and fields by index only (calls, 239 struct references and field accesses already did). Names move to an optional side table outside 240 identity (11.5, 11.7). 241 - **Structured requirement objects.** Version 6 carries each `requires` / `ensures` clause as a typed 242 postfix term list (11.4) that a checker reads without parsing source text. The objects are inside 243 identity; the source texts move to the side table. 244 - **Domain tag string.** Version 6 writes the tag `omega.osc.ir.v6` after the version byte (11.1), 245 inside the hashed bytes. Versions 1..5 keep their bytes and identities: the tag exists only in the 246 new version, so no existing OSC unit identity changes. 247 248 ## 10. Seeded memory profile: IR v2 milestone, OSC wire v7 249 250 **Specification only; producer and backend qualification is separate.** The 251 milestone name “IR v2 memory” does not change the meaning of wire version 2, 252 which already carries structs. Wire versions 1..5 and their identity bytes 253 remain unchanged. Wire version 6 is the numeric-identifier/structured-contract 254 format of section 11; this profile neither extends nor replaces it. The memory 255 extension uses version 7. A backend 256 that has not implemented this profile must refuse it, not ignore its regions. 257 258 ### 10.1 Header and regions 259 260 All fields remain unsigned little-endian integers without wire padding: 261 262 ``` 263 magic[7] = "OSC1IR\0" 264 version:u8 = 7 265 nstructs:u8, structs[nstructs] existing section 3.2 encoding 266 nregions:u16, regions[nregions] 267 nfuncs:u16, functions[nfuncs] existing section 3.3 encoding 268 ``` 269 270 The struct table stays before the region table. Supporting this profile does 271 not imply supporting structs: a backend may explicitly refuse a nonempty 272 struct table. A region has the following encoding: 273 274 | Field | Encoding and rule | 275 |---|---| 276 | name | u8 length, then 1..63 non-NUL ASCII bytes | 277 | element | u8 scalar tag: 2..9, 13 f32, or 14 f64 | 278 | storage | u8 class from the table below | 279 | owner | u16 function index, or 65535 for module scope | 280 | count | u32 number of elements | 281 | initial length | u32 byte count | 282 | initial data | exactly initial-length bytes | 283 284 Region IDs are zero-based table indices, not addresses or value registers. 285 Table order is source declaration order; names and order participate in 286 identity. Names are unique within an owner scope and may not shadow a module 287 region in an owning function. The initial profile admits at most 1024 regions. 288 Mutable regions have 1..`16777216` elements; an empty read-only text is allowed. 289 Existing native aggregate capacity limits still apply to source compilation. 290 Backends check each element-count multiplication, alignment and aggregate 291 addition for overflow before allocating or emitting memory. Source global 292 pools retain the native 1 GiB aggregate limit and local arrays the native 293 4 MiB aggregate limit. Backend input/output limits remain independently 294 enforced; an unsupported size is a capacity refusal, never truncation. 295 296 Sections 3 through 7 remain the complete rules for versions 1..5. For 297 version 7, this section extends them: tags 13/14 and opcodes 30..33 are 298 admitted only in v7. In a v1..5 unit those bytes remain RANGE, exactly as 299 before. Version 7 carries the historical tag/opcode set unchanged, but this 300 profile's seeded backends refuse references, slices, allocation, arena, 301 pool and struct operations (opcodes 7, 8, 16..29 and tags 10..12) with 302 UNSUPPORTED_OP or UNSUPPORTED_TAG. A complete v7 input is at most 303 8,388,608 bytes, checked before parsing; a backend may set a smaller 304 documented input capacity and refuse beyond it. 305 306 Reader classes are applied in byte order. An unknown storage class or an 307 element tag outside 2..9/13/14 is INVALID; class 3 is UNSUPPORTED_OP. A 308 name that is empty, over 63 bytes, contains NUL, is non-ASCII or contains 309 a dot is INVALID. Initial data for classes 0/1, a mismatched text length, 310 count 0 for a mutable region, a count over 16,777,216, or more than 1024 311 regions is INVALID. Owner validity and duplicate/shadowing names are 312 checked after the function table is read and are INVALID. Every region or 313 register operand outside its table, including 0x8000..0xFFFF, is INVALID. 314 An f32 constant or initializer with a nonzero upper half is INVALID. 315 316 | Class | Meaning | Owner and initialization | 317 |---|---|---| 318 | 0 | Module-private mutable global | owner 65535; no initial data; zero-filled once per module instance | 319 | 1 | Function-local mutable array | owner is its function; no initial data; fresh logical storage on every invocation | 320 | 2 | Read-only text | owner 65535; element u8; initial length equals count; no implicit NUL | 321 | 3 | Reserved Workgroup | refused until initialization, synchronization and invocation ownership have a specified extension | 322 323 No other class is admitted. Function-local regions are accessible only by 324 their owning function. Calls remain restricted to earlier functions, so 325 there is no recursive or reentrant invocation within a module call. 326 An implementation may reuse physical storage for a function-local region 327 between calls, but valid Omega execution cannot observe a previous 328 invocation's values. Exported linear memory is not a JavaScript isolation 329 or zeroization boundary; a JavaScript holder can inspect physical storage. 330 The source initializer is evaluated once, at the `new` declaration, and fills 331 every element before the array is accessible. Its value is not a module data 332 segment. Input validation must establish that every local-region access is 333 dominated by initialization of that region on the current invocation. 334 335 Memory-backed scalar state uses a one-element region. Ordinary scalar 336 locals remain value registers; this profile does not allocate regions for 337 them or introduce a new source spelling for scalar globals. 338 339 For a future SPIR-V backend, class 1 maps to Function storage and class 2 to 340 read-only constant storage. Class 0 requires an explicitly persistent 341 CrossWorkgroup state ABI, or a named refusal: SPIR-V Private storage is 342 per-work-item and cannot implement persistence between module calls. 343 Class 3 is reserved rather than pretending a CPU global supplies barriers. 344 345 ### 10.2 Instructions and bounds 346 347 Existing opcodes, including reference LOAD/STORE 9/10, retain their meaning. 348 The following instructions are appended; every operand below is u16: 349 350 | Opcode | Name | Operands | 351 |---|---|---| 352 | 30 | RLOAD | destination register, region ID, index register | 353 | 31 | RSTORE | region ID, index register, source register | 354 | 32 | BITCAST | destination register, source register | 355 | 33 | RINIT | region ID, initializer register | 356 357 Every operand must designate an existing region or register of the stated 358 kind. None of these instructions admits a sentinel operand. BITCAST and 359 RINIT source registers are definite-assignment uses; RLOAD and BITCAST 360 destinations are definitions. 361 362 RLOAD's destination and RSTORE's source have exactly the region element type. 363 Indices have an integer tag 2..9, never bool or float. Signed negative indices 364 and indices greater than or equal to count trap with Omega bounds trap 3 365 (native exit 103). Bounds are checked before multiplication, addition, 366 pointer formation or narrowing to a wasm32 address. An invalid operation 367 does not read or write its target element. Earlier side effects remain, 368 including partial writes to module memory before a trap. 369 RSTORE into read-only storage is invalid IR, not a silently ignored store. 370 Index and source registers participate in definite-assignment validation. 371 372 There is no unchecked access mode in this profile. An explicit source bounds 373 test can select a nontrapping path, but it does not disable checks on the 374 access. The backend may eliminate a check only when it proves the same 375 in-bounds condition. Whole-linear-memory wasm bounds checks alone are 376 insufficient: crossing into the next region must still trap. Module, 377 text and per-function local backing ranges are pairwise disjoint. 378 379 Arrays use packed element widths: u8/i8 one byte, u16/i16 two, u32/i32/f32 380 four, u64/i64/f64 eight. Each region starts at an address aligned to its 381 element width; no padding exists between elements. Region base addresses 382 are backend layout, not IR identity. Struct cells retain their separate 383 existing layout. Loads/stores preserve little-endian scalar bits. 384 385 BITCAST admits any source/destination pair within exactly one of these 386 wire-tag sets: {2 u8, 6 i8}, {3 u16, 7 i16}, 387 {4 u32, 8 i32, 13 f32}, {5 u64, 9 i64, 14 f64}. Same-type pairs are allowed. 388 It reinterprets bits without numeric conversion. Bool, void, references, 389 and pairs crossing sets are invalid IR. 390 Only declared-width bits are reinterpreted. The destination value register 391 then uses its canonical representation: narrow signed integers are 392 sign-extended; unsigned integers and f32 are zero-extended. These high 393 register bits are representation, not additional array-element bytes. 394 395 RINIT is valid only for a function-local region owned by the current 396 function; its initializer register has exactly the element type and must 397 be definitely assigned. It fills every element with that scalar's bits, 398 without conversion. An initialization bit for each local region starts 399 false at function entry; RINIT sets it true only after the complete fill. 400 A local region is initialized at a block exactly when every path from the 401 function entry to that block passes RINIT for it. Unreachable blocks are 402 still validated, starting with all local-region bits false. Both 403 RLOAD and RSTORE require the target local region's bit to be true. 404 Thus declaration-time initialization is explicit, and the validator need 405 not prove that an arbitrary loop of stores fills the entire region. 406 Repeating RINIT is well-defined and resets the whole region; it does not 407 allocate a second region or expose previous contents. 408 409 ### 10.3 Floating-point types and canonical version selection 410 411 Wire tags 13 and 14 mean f32 and f64. Tags 10..12 keep their historical 412 reference/bytes/cells meanings. The producer must explicitly map its 413 internal float tags rather than serialize them as wire tags. 414 CONST keeps its eight-byte immediate: f32 occupies the low half with a zero 415 upper half; f64 occupies the complete immediate. 416 Floats may appear as value registers, region elements, constants, call 417 arguments, returns and float-aware BIN/UN/CMP/CAST/BITCAST operands. They 418 are not admitted as reference elements or struct fields in this profile. 419 Float BIN subcodes 5..10 and UN subcodes 2..3 are invalid. 420 421 Existing BIN add/sub/mul/div, UN negation, and CMP eq/ne/lt/le/gt/ge accept 422 matching float operands. Float bitwise operations, shifts and remainder 423 are invalid. NaN comparisons follow IEEE semantics: only ne is true. 424 Arithmetic rounds to nearest, ties to even, retains subnormals, and does 425 not contract separate operators into fused operations. Finite arithmetic, 426 infinities and signed zeros follow IEEE-754 at the declared width. 427 428 CONST, MOV, RLOAD, RSTORE, RINIT and BITCAST preserve all float bits, 429 including signed zero and NaN payloads. Float negation toggles only the 430 sign bit. A NaN produced by arithmetic or a float-width conversion may 431 have any quiet-NaN payload/sign; exact-byte parity does not apply to those 432 new NaN bits. This latitude never permits changing a transported NaN's 433 bits. Tests compare such arithmetic results by NaN classification while 434 separately checking exact payload transport. 435 436 CAST has the following complete rules: 437 438 - Integer-to-integer conversions retain the existing checked conversion 439 contract: an unrepresentable destination value traps 5. 440 - Float-to-integer first truncates toward zero, then saturates to the 441 destination type's own signed or unsigned range, including narrow 442 destinations. Negative-to-unsigned saturates to zero; infinities saturate 443 to the appropriate endpoint; NaN converts to zero. Stored/reloaded and 444 directly returned results have the same canonical integer value. 445 - Integer-to-float interprets the source according to its signedness and 446 rounds to the destination width using nearest, ties to even. 447 - f64-to-f32 rounds nearest, ties to even, preserves signed zero and 448 subnormals, and overflows to signed infinity. f32-to-f64 is exact for 449 finite values and preserves infinity and signed zero. NaNs follow the 450 quiet-NaN latitude above. Same-type float CAST is a bit-preserving MOV. 451 - Bool, void and reference types are excluded from CAST in this profile. 452 453 Ordinary trapping wasm float-to-integer conversion alone is not an 454 equivalent lowering. Native/backend conversion defects are implementation 455 bugs, not alternate definitions of these rules. Floating-point intrinsics 456 need separately specified subcodes and are not silently lowered as calls. 457 458 Select wire v7 if and only if the unit has a region, a float type, or an 459 opcode introduced by this profile. Otherwise retain the existing v1..5 460 selection rule. A gratuitous v7 encoding of an old-only unit is refused. 461 Old readers remain valid for their declared versions and must refuse v7. 462 463 ### 10.4 Backend and qualification obligations 464 465 The wasm backend exports its memory as `memory` and every function by its 466 original unique ASCII name. That name is reserved against a function export 467 collision. Read-only initial bytes become active data segments; the source 468 read-only property is enforced for generated Omega instructions, not a 469 security barrier against a JavaScript holder of exported memory. 470 An immutable i32 global named `region.NAME` exports each module region's 471 unsigned wasm32 byte offset. JavaScript interprets the i32 global value as 472 unsigned before indexing memory. Region bases remain stable for the module 473 instance; local arrays have no exported address. Source names cannot 474 contain the dot separator. Float parameters and results use wasm f32/f64 475 for wire tags 13/14; the existing integer/bool ABI remains unchanged. 476 The memory is exported, has the exact page count needed for every 477 region's backing, rounded up to whole 64 KiB pages, has the same maximum, 478 and is never grown. Its zero-filled class-0 storage persists while the 479 instance lives. Region parity compares module regions only through their 480 `region.NAME` offsets; local backing is not part of a portable comparison. 481 Consumers use a typed view of exported memory and call exported scalar 482 functions once per frame. There are no imports, WASI calls, implicit 483 rendering loop, or allocation through JavaScript. 484 All computed export names must be unique, including `memory`, function 485 names and `region.NAME`; a collision is INVALID rather than an invalid wasm 486 module emitted for a JavaScript engine to diagnose later. 487 488 Wasm traps are `WebAssembly.RuntimeError`; MVP does not preserve numeric 489 Omega trap codes. A producer reports ordinary source errors: 7 type 490 mismatch, 9 unsupported context, 14 table capacity, 20 write to text/view, 491 21 constant index out of bounds and 23 storage capacity. A v7 backend keeps 492 the existing named refusal exits and empty stdout on parse/type/capacity 493 refusal; unknown storage classes are INVALID, unsupported profile features 494 are UNSUPPORTED_OP or UNSUPPORTED_TAG, and unsupported wire versions are 495 VERSION. Refusal is not a successful empty module. 496 497 Required qualification includes native/wasm scalar and memory parity; 498 u8/i32/f32/f64 round trips; text data; local reinitialization on repeated 499 calls; region-boundary, negative and wide-index traps; refusal of read-only 500 stores and foreign local ownership; deterministic module bytes; an RGBX 501 gradient framebuffer checksum comparison; a real pinned renderer primitive 502 with a full-buffer pixel comparison; and a changed-store or missing-check 503 mutant rejected by those checks. Existing v1 parity and refusal suites must 504 remain unchanged and green. Host evidence does not qualify GPU execution. 505 The new wire also needs an independent read-only oracle that decodes its 506 region table, validates ownership/types/initialization, and executes memory 507 instructions. Native/wasm agreement alone is not sufficient if both share a 508 producer bug. Hand-encoded valid and malformed units challenge that oracle 509 and both backends; the original pinned C renderer remains an independent 510 pixel reference rather than a translation of the Omega implementation. 511 Required malformed-wire controls include missing or loop-carried local 512 initialization, foreign-local access, invalid/sentinel operands and export 513 collisions. Repeated-call checks include calls after a trapped invocation. 514 Conversion fixtures cover signed, unsigned and narrow destination 515 boundaries, float widths, infinities, NaNs and signed zeros. 516 517 ## 11. Format version 6 (omega#451) 518 519 Written only by `osc_ir_encode_v6`; identity by `osc_ir_digest_v6`; read by the same 520 `osc_ir_decode`. Every integer is little-endian, as in section 3. Types (3.4) and instructions (3.5) 521 are written exactly as in versions 1..5. 522 523 ### 11.1 Header 524 525 | bytes | field | 526 |---|---| 527 | 7 | magic `4F 53 43 31 49 52 00` ("OSC1IR\0") | 528 | 1 | version 6 | 529 | 16 | domain tag: the 15 bytes `omega.osc.ir.v6` and one NUL (`OSC_IR_V6_TAG`, `OSC_IR_V6_TAG_LEN`) | 530 531 The core (11.2) follows, then the name table (11.5). Nothing may follow the name table. 532 `osc_ir_encoding_version` returns 6 only when all 16 tag bytes are present and exact. 533 534 ### 11.2 Core 535 536 | bytes | field | 537 |---|---| 538 | 1 | `nstructs` 0..16, then per struct: | 539 | 1 | `nfields` 0..16 (validation requires 1..16) | 540 | 2 | `ncells` | 541 | per field: 1 | scalar tag (3.4) | 542 | per field: 2 | `alen` (0 = scalar field) | 543 | per field: 2 | `off` | 544 | 2 | `nfuncs` 0..32, then `nfuncs` function records (11.3) | 545 546 The struct table is always present (possibly empty) and carries no names. 547 548 ### 11.3 Function record 549 550 | bytes | field | 551 |---|---| 552 | 1 | `nparams` | 553 | type | return type (3.4) | 554 | 2 | `nvregs` 0..480, then `nvregs` types (3.4) | 555 | 2 | `nblocks` 0..512, then per block: 4 `first`, 4 `count` | 556 | 4 | `ninsns` 0..4096, then `ninsns` instructions (3.5) | 557 | 1 | `nreq` 0..64, then `nreq` requirement terms (11.4): the `requires` object | 558 | 1 | `nens` 0..64, then `nens` requirement terms (11.4): the `ensures` object | 559 560 Numeric identifiers in the core: a CALL `callee` is a function index below `nfuncs`; a type's `sid` 561 names `structs[sid-1]` and is at most `nstructs`; FLOAD / FSTORE `imm` is a field number of that 562 struct. Function names, struct names, field names and contract texts are not in the core. 563 564 ### 11.4 Requirement terms 565 566 A requirement object (`OscCterm req[]` / `ens[]`, `osc_ir.h`) is a postfix program over a typed 567 value stack. Each term is one kind byte, then the kind's fields: 568 569 | kind | name | fields after the kind | effect and typing | 570 |---|---|---|---| 571 | 1 | PARAM | 1 `arg` | push parameter `arg` (< `nparams`; its type is bool or an integer scalar) | 572 | 2 | RESULT | none | push the return value (ensures only; the return type is bool or an integer scalar) | 573 | 3 | CONST | 1 `sub` (scalar tag 1..9), 8 `imm` | push `imm`, canonical for `sub` as for the CONST instruction | 574 | 4 | BIN | 1 `sub` (OscBinOp 1..10) | pop b, a; push a `sub` b with a's type. SHL / SHR: both integer; AND / OR / XOR: equal types; the rest: equal integer types | 575 | 5 | UN | 1 `sub` (OscUnOp 1..3) | pop a; push `sub` a. LNOT: bool; NEG / BNOT: integer | 576 | 6 | CMP | 1 `sub` (OscCmp 1..6) | pop b, a of equal type; push bool | 577 | 7 | CAST | 1 `sub` (integer tag 2..9) | pop an integer; push it converted to `sub` | 578 579 Kind 0 and kinds above 7 are refused (RANGE): their length is unknown. An object is well formed 580 when it is empty (no clause) or leaves exactly one bool on the stack with no step popping an empty 581 stack, and every term field its kind does not carry is 0 (one object has one form). The operator 582 meanings are those of the IR instruction with the same `sub` (`osc_ir.h`). The `requires` object 583 holds on entry, the `ensures` object on return. This change fixes the carried form, its typing and 584 its place in identity; no consumer evaluates the objects yet (11.9). 585 586 ### 11.5 Name table 587 588 | bytes | field | 589 |---|---| 590 | 2 | `count` 0..368 (`OSC_IR_V6_NAMES_MAX` = 32 x 3 + 16 x (1 + 16)), then `count` entries: | 591 | 1 | kind: 1 function name, 2 struct name, 3 field name, 4 requires text, 5 ensures text (`OSC_IR_NAME_*`) | 592 | 1 | `index`: the function (kinds 1, 4, 5) or the struct (kinds 2, 3) | 593 | 1 | `sub`: the field number for kind 3; 0 for every other kind | 594 | 2 | length n: 1..63 for kinds 1..3, 1..255 for kinds 4 and 5 | 595 | n | the text, no NUL | 596 597 Every entry names an existing object (IDENT). Entries are strictly ascending by 598 (kind, `index`, `sub`), so no object has two entries (ORDER). An absent name has no entry; an entry 599 of length 0 is a second spelling of "absent" and is refused (ORDER). Names are optional: a version 6 600 unit may leave any function, struct or field unnamed. Present struct names stay unique within the 601 unit and present field names unique within their struct (`osc_ir_validate`). The texts of kinds 4 602 and 5 are the source spelling, kept for people; the checked meaning is the object in 11.4. 603 604 ### 11.6 Limits 605 606 Section 5's counts apply to the core. In addition: at most 64 terms per object 607 (`OSC_CONTRACT_MAX`), at most 368 name-table entries. Input longer than `OSC_IR_V6_ENCODED_MAX` 608 (2,662,701 bytes: section 5's widest unit without names, every object at 64 ten-byte CONST terms, 609 and every possible name-table entry at its longest) is refused before parsing. For every version 610 byte other than 6, the section 5 bound (`OSC_IR_ENCODED_MAX`) is still applied, after the version 611 byte is read and before it is judged, so inputs of versions 1..5 are refused exactly as before. 612 613 ### 11.7 Canonical law and identity 614 615 The version 6 canonical set is `{ osc_ir_encode_v6(u) : osc_ir_validate(u) == 0 }`. Every valid 616 unit has a version 6 form. A unit with a structured object or an unnamed struct or field has no 617 version 1..5 form: `osc_ir_encode` and `osc_ir_digest` refuse it (-1), and a version 1..5 input that 618 would decode to one is refused (INVALID). A unit that has both forms has one spelling in each; the 619 version byte and tag tell them apart and both decode to the same unit. 620 621 `osc_ir_digest_v6(u) = SHA-256(header || core)`: the 24 header bytes and the core, everything before 622 the name table's `count`. Consequences, each checked by the test: 623 624 - renaming a function, struct or field, or editing a contract text, never changes the identity 625 (alpha-equivalence, as in program identity v2, spec/program-identity.md), while the bytes change; 626 - a change to a requirement object always changes the identity; 627 - the tag is inside the preimage, so a version 6 identity differs from the version 1..5 identity of 628 the same unit. 629 630 Two units that differ only in names share an identity and differ in bytes. A consumer that must tell 631 them apart hashes the whole encoding. 632 633 ### 11.8 Refusal classes for version 6 634 635 Order of checks: total size (OVERSIZED); magic (MAGIC); version byte; tag (TRUNCATED when fewer than 636 16 bytes remain, else DOMAIN); the core front to back (TRUNCATED, OVERSIZED for counts, RANGE for 637 tags, opcodes, register fields and term kinds); each name-table entry in the order kind (RANGE), 638 target (IDENT), order and `sub` (ORDER), length (OVERSIZED; 0 is ORDER), text (TRUNCATED, TEXT); 639 then TRAILING; core identifiers (IDENT); requirement objects (CONTRACT); `osc_ir_validate` 640 (INVALID); the NONCANONICAL backstop. VERSION_MISMATCH does not apply: the writer, not the content, 641 chooses version 6. 642 643 | code | class | meaning | counterexamples in the test | 644 |---|---|---|---| 645 | -12 | DOMAIN | version byte 6 without the exact 16-byte tag | tag "omega.osc.ir.v7"; tag without its NUL; tag missing | 646 | -13 | IDENT | a core identifier or a name entry names no object: `sid` above `nstructs`, `callee` not below `nfuncs`, an entry for a missing function, struct or field | struct id 2 in a unit without structs; name for function 1 of 1; field name for a missing struct; requires text for function 5 | 647 | -14 | ORDER | name entries not strictly ascending (including two for one object), `sub` nonzero outside kind 3, an entry of length 0 | descending entries; two names for function 0; empty entry; field number on a function name | 648 | -15 | CONTRACT | a requirement object that 11.4 refuses | parameter 0 of a function with none; result in a requires clause; clause ending in a u8; BIN with one operand; clause leaving two values; u8 constant 256; constant of type ref; BIN operator 0 | 649 650 The existing classes also have version 6 counterexamples: TRUNCATED (input ends inside the tag, 651 inside a term, inside the name table), UNKNOWN_VERSION (version 7 followed by the version 6 tag), 652 OVERSIZED (64-byte name, 256-byte requires text, 65 terms, 369 entries), RANGE (name kinds 0 and 6, 653 term kinds 0 and 8), TEXT (NUL inside a name), TRAILING (one byte after the name table), INVALID 654 (u8 constant 256 in the core). NONCANONICAL stays unreachable: the sweeps assert it is never 655 returned for version 6 input either. 656 657 ### 11.9 Qualification and limits of this change 658 659 Measured on the Spark, 2026-10-17, `make test-osc-ir-decode`, full mode (section 8's sweeps of 660 versions 1..5 give the same case, refused and admitted totals as before this change; one of their 661 byte flips now lands on version 6 and is refused DOMAIN): 662 663 - corpus: all 59 units round-trip byte-exactly as version 6 three ways (as compiled; with every name 664 and text removed; with random well-typed requires/ensures objects), and decode to the encoded 665 unit on every carried field including every term; 666 - identity: for all 59 units a rename keeps the identity, the identity equals SHA-256 of the bytes 667 before the name table, a changed requirement object gives a new identity, and the version 6 668 identity differs from the version 1..5 identity; `osc_ir_encode` refuses all 67 units that only 669 version 6 can carry (59 with objects, 8 with unnamed structs); 670 - 2,000 distinct valid version 6 objects (seeded variants with objects and with names removed or 671 kept) round-trip byte-exactly (300 under ASan); 672 - 230,463 malformed version 6 inputs (byte flips, truncations, trailing bytes, seeded multi-byte 673 edits of every corpus unit with objects): 199,894 refused with a named class (among them DOMAIN 674 3,597, IDENT 1,079, ORDER 1,085, CONTRACT 21,153), 30,569 decoded to a different valid unit that 675 re-encodes to exactly those bytes, NONCANONICAL never returned, no crash. The ASan/UBSan build 676 runs 231,397 such cases with no sanitizer report; 677 - 35 counterexamples (11.8) from an independent writer in the test, whose canonical case is 678 byte-identical to `osc_ir_encode_v6`; with section 7's 31 cases, 66 of 66 as expected and 14 of 679 the 15 classes exhibited (all but the NONCANONICAL backstop); 680 - 6 more decoder mutants, each caught: 23 no domain check, 24 no name-table target check, 25 no 681 order or empty-entry check, 26 no requirement-object check, 27 no core identifier check, 28 name 682 table hashed into the identity. Mutants 9 and 11..17 switch off the same count maxima in the 683 version 6 core; the version 6 only maxima (terms per object, name-table entries, name-table text 684 length) have no single-site mutant and are switched off by mutant 9. 685 686 Not in this change: the front end (`osc_lower`) still writes versions 1..5 and fills no requirement 687 objects; translating `requires` / `ensures` source into objects, evaluating them, and teaching the 688 independent checker decoder (`src/checker2`) to read version 6 are follow-up work. 689 690 ### 11.10 Role under the seeded `.om` programme (decided 2026-11-06) 691 692 Version 6 is a bounded compatibility format of the C OSC pipeline (`src/compiler`), not an identity 693 of seeded `.om` programs. Its obligations are exactly these: 694 695 - No existing identity moves. Versions 1..5 are written and hashed byte for byte as before, and no 696 producer (`osc_lower`, the seeded `omc` or any other) switches to version 6 in this change. 697 - A version 6 identity names only a version 6 unit. It is never relabelled as, or compared equal 698 to, a version 1..5 identity, a seeded wire v7 (section 10) or v8 identity, or the hash of any 699 `.om` source or `omc` output. The domain tag (11.1) enforces this separation in the bytes. 700 - Numeric identifiers, structured requirement objects and the domain tag are properties of this 701 wire format only. A seeded `.om` producer that wants them must specify its own mapping and 702 qualification against this section first (omega#625); this section grants none. 703 - checker2 receipts, the #451 acceptance and the omega#623 proof receipts stay open obligations 704 until `src/checker2` reads version 6; until then no receipt may cite a version 6 identity.