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
omega-mv / spec / universal / source-aware-v1.md
| 1 | # Source-aware upper layer v1 |
| 2 | |
| 3 | Issue #621. Parent contract: omega.universal.semantics.v1 at stacked base |
| 4 | 69790fb4ad1e803ca79245430745b96129d1dcf4. This additive, finite interchange |
| 5 | contract does not change OSC, Omegese, checker2, policy or receipt formats. |
| 6 | Independent review is pending. No general importer, converter or proof claim. |
| 7 | |
| 8 | ## Bounds and identities |
| 9 | |
| 10 | A unit is a straight-line typed expression with 1..64 SSA results. Its last |
| 11 | result is the unit result. At most six distinct input slots, no functions, |
| 12 | branches, recursion, heap, floating point, exceptions implemented as execution, |
| 13 | concurrency, arbitrary dialect extensions or native FFI. Source at most 4096 |
| 14 | bytes. Input at most 8192 bytes. Oversized values refuse before indexing. |
| 15 | |
| 16 | Semantic identity = SHA256(`omega.source.semantic.v1` || canonical semantic |
| 17 | bytes). These bytes include every language/profile/runtime/ABI/dialect/version, |
| 18 | operation/type/attribute/effect/alias/obligation/operand/immediate field and the |
| 19 | 32-byte hash of spec/universal/semantics.md. Formatting, spans, raw source and |
| 20 | target selection are excluded. Provenance identity = SHA256( |
| 21 | `omega.source.provenance.v1` || complete canonical envelope). No target |
| 22 | realization identity is minted here. These are intensional content identifiers, |
| 23 | not proofs of behavioral equivalence, and SHA256 collision resistance is an |
| 24 | assumption. Changing profile definitions requires a new version, not reusing IDs. |
| 25 | |
| 26 | Raw bytes, source encoding and byte spans live only in the sidecar. Verified |
| 27 | association checks both semantic and source SHA256. This detects inconsistent |
| 28 | association, not a malicious importer's false claim that text means an IR. |
| 29 | No parser establishes that claim in this slice. Private source must remain local. |
| 30 | Exact replay exports stored bytes; it never reconstructs source from lower IR. |
| 31 | |
| 32 | ## Canonical wire format |
| 33 | |
| 34 | All integers unsigned little endian, all lengths exact; no padding, varints, |
| 35 | implicit NUL or trailing bytes. Numbers below are offsets from each record. |
| 36 | |
| 37 | Envelope: ASCII OMSB (0..3), version=1 (4), semantic length u32 (5), sidecar |
| 38 | length u32 (9), semantic bytes (13), optional sidecar bytes. Sidecar length zero |
| 39 | means absent, not empty source. Semantic-only units may decode/encode/identify; |
| 40 | replay returns PROVENANCE_MISSING. Input total must equal 13+both lengths. |
| 41 | |
| 42 | Semantic header (44 bytes): ASCII OMSA (0), version=1 (4), language (5), profile |
| 43 | (6), dialect version=1 (7), runtime (8), ABI (9), operation count u16 (10), |
| 44 | SHA256 of exact parent semantics.md bytes (12). Then count 20-byte operations. |
| 45 | |
| 46 | Operation: importer dialect (0), op version=1 (1), opcode (2), result type (3), |
| 47 | arithmetic attribute (4), effects bitset (5), alias set (6), obligations bitset |
| 48 | (7), operand A u16 (8), operand B u16 (10), immediate u64 (12). Result index is |
| 49 | record order. An operand must reference an earlier result of the specified type. |
| 50 | Unused operands MUST be 65535; unused immediate MUST be zero. There are no ignored |
| 51 | fields. Input slot immediates 0..5 must be unique in the unit. |
| 52 | |
| 53 | Sidecar: ASCII OMSP (0), version=1 (4), encoding (5), source length u32 (6), |
| 54 | SHA256 of semantic bytes (10), SHA256 of source bytes (42), count pairs of |
| 55 | (start u32,end u32) (74), then exact source bytes. Spans are half-open byte offsets |
| 56 | 0<=start<=end<=source length; empty/synthetic span is [0,0]. UTF8 spans must be on |
| 57 | codepoint boundaries. Encoding 0 preserves arbitrary bytes including invalid |
| 58 | UTF8; encoding 1 validates strict UTF8 (no overlong, surrogate or >U+10FFFF). |
| 59 | Raw source may contain NUL, high bytes, CRLF and invalid text sequences. |
| 60 | |
| 61 | ## Typed registry |
| 62 | |
| 63 | Languages/dialects: 1=C17, 2=Rust2021, 3=Python3, 4=OSC5. Each operation's dialect |
| 64 | must equal its header language. Types: 1=u64, 2=Python builtin arbitrary-precision |
| 65 | int, 3=Python object (operator overloads preserved), 4=symbolic byte-view binding. |
| 66 | Byte-view is an upper symbolic input; it never becomes an invented OscScalar. |
| 67 | |
| 68 | Profiles: 1=c17-uint64-pure-v1 (language1); 2=rust-u64-wrapping-pure-v1 (language2); |
| 69 | 3=cpython-int-pure-v1 (language3); 4=python-explicit-u64-pure-v1 (language3); |
| 70 | 5=osc-v5-u64-pure-v1 (language4); 6=python-dynamic-retained-v1 (language3). |
| 71 | Profile6 is a retention-only extension: dynamic calls, symbolic byte access, |
| 72 | exceptions and unknown effects remain unresolved. It supplies no executable |
| 73 | Python semantics. Profile1/2/4/5 permit only u64 inputs/constants/arithmetic. |
| 74 | Profile3 permits only builtin-int inputs/constants/arithmetic. Profile6 permits |
| 75 | all registry types but u64 arithmetic remains explicit-mask semantics. |
| 76 | |
| 77 | Runtime: 0=none; 1=CPython3.12 model; 2=CPython3.13 model. ABI: 1=abstract-pure-v1, |
| 78 | 2=cpython-object-v1 (symbolic only, no layout/FFI support). Profiles1/2/4/5 require |
| 79 | runtime0 ABI1; profile3 requires runtime1 or2 ABI1; profile6 requires runtime1 or2 |
| 80 | ABI2. These versioned models do not claim support for arbitrary Python releases. |
| 81 | |
| 82 | Arithmetic attributes: 0=none; 1=modulo2^64; 2=builtin-bigint; 3=dynamic; |
| 83 | 4=byte-access. Effects: read1,write2,allocation4,IO8,exception16,unknown32. |
| 84 | Alias sets: 0=none, 1..8=importer-declared may-alias partition, 255=unknown/top. |
| 85 | Different nonzero partitions are not a proof of disjointness. Obligations: |
| 86 | 1=input-domain, 2=nonzero-divisor, 4=source-explicit-masking, |
| 87 | 8=runtime-model, 16=alias-and-bounds-validation. Obligations are required exactly, |
| 88 | never a caller-controlled 'proved' flag. There is no discharge mechanism here. |
| 89 | |
| 90 | | Op | Meaning | Required shape | |
| 91 | |---|---|---| |
| 92 | | 1 | constant | type1 or2; attr1 or2 respectively; effects/alias/obligations0; unused operands; u64 magnitude (nonnegative bigint subset) | |
| 93 | | 2/3/4/5 | add/sub/mul/div | type1 or2; same typed A/B; immediate0; attr1/2; u64 effects0 alias0, bigint effects20 alias255; obligations below | |
| 94 | | 6 | Python dynamic call | profile6, type3 attr3 effects63 alias255 obligations8; A object, unused B, immediate0 | |
| 95 | | 7 | symbolic byte read | profile6, type1 attr4 effects17 alias1..8 or255 obligations24; A view, B u64, immediate0 | |
| 96 | | 8 | symbolic byte write | profile6, type1 attr4 effects19 alias1..8 or255 obligations24; A view, B u64, immediate=earlier type1 SSA value-to-store; no execution/lowering | |
| 97 | | 9 | external input | attr0 effects0; no operands; immediate unique slot0..5; type4 alias1..8 or255, otherwise alias0; obligations1 | |
| 98 | |
| 99 | Arithmetic obligations: u64 1, plus2 for div, plus4 for profiles4/6; bigint8, |
| 100 | plus2 for div. Bigint division means Python floor division including negative |
| 101 | input/results. No wrapped-u64 substitution. Type2 constants here are restricted |
| 102 | to unsigned64 magnitudes; negative/large constants need a future version. |
| 103 | Op8 returns the written u64 value, with a pending byte-range obligation in addition |
| 104 | to its alias/bounds/runtime obligations. Legality is always UNSUPPORTED to OSC. |
| 105 | |
| 106 | ## Native core API and commands |
| 107 | |
| 108 | Production core src/source-aware/core.om is handwritten seeded Omega. It uses |
| 109 | fixed global input/output buffers and typed operation arrays. `decode n` validates |
| 110 | the complete unit and leaves output length zero on failure; `encode` reconstructs |
| 111 | the canonical bytes from validated fields. `perform mode n` resets output first, |
| 112 | decodes, and prepares all output before any write. Return code zero means success. |
| 113 | This whole-unit interface matches the qualified grammar; no shared-object ABI, |
| 114 | thread safety or reentrant library is claimed. External adapters must serialize |
| 115 | calls. Failed decode may leave private scratch fields; no result may be used. |
| 116 | |
| 117 | `tools/source-aware/sa encode|decode|identity|provenance|replay|legality` reads a |
| 118 | canonical envelope on stdin and writes bytes on stdout. encode/decode produce |
| 119 | identical canonical envelopes. identity/provenance emit 32 raw digest bytes. |
| 120 | legality uses four prefix bytes before the envelope: target(1=upper retention, |
| 121 | 2=OSC), available runtime(0..2), ABI(1..2), allowed effects(0..63). The reply is |
| 122 | one pair (legality,obligations) per operation. Invalid target capabilities refuse. |
| 123 | Statuses: 1=LEGAL (upper retention only); 2=REQUIRES_RUNTIME; |
| 124 | 3=LOWERABLE_WITH_OBLIGATIONS; 4=UNSUPPORTED. Missing runtime on bigint/dynamic |
| 125 | operations returns2; provided runtime never makes them lowerable to OSC. |
| 126 | For target2 only u64 inputs/constants and modulo u64 arithmetic can return3, |
| 127 | with their exact obligations; all others return4. Missing ABI or effect allowance |
| 128 | returns4 first. No status certifies a lowering or grants capability authority. |
| 129 | |
| 130 | Named refusals/status: 64=BAD_COMMAND, 65=MALFORMED, 66=UNKNOWN_VERSION, |
| 131 | 67=LIMIT, 68=PROFILE_MISMATCH, 69=UNKNOWN_OPERATION, 70=TYPE_MISMATCH, |
| 132 | 71=EFFECT_ALIAS_MISMATCH, 72=OBLIGATION_MISMATCH, 73=PROVENANCE_MISSING, |
| 133 | 74=PROVENANCE_MISMATCH, 75=SOURCE_SPAN, 76=SOURCE_ENCODING, 77=IO, |
| 134 | 78=CONTRACT_MISMATCH. Semantic failure produces no stdout; named message on stderr. |
| 135 | The CLI buffers output into an exclusive temporary directory before stdout copy. |
| 136 | Direct native code validates everything before output. OS I/O failure can of |
| 137 | course interrupt a stream; no atomic multi-byte pipe write is claimed. Neither |
| 138 | command manages destination paths: shell redirection truncates before invocation. |
| 139 | Use caller-owned temporary files and rename on success for durable destinations. |
| 140 | |
| 141 | ## Existing lower interfaces and trust boundary |
| 142 | |
| 143 | Omegese's `osc_compile` produces existing OscUnit values. Existing |
| 144 | `osc_ir_encode`, `osc_ir_decode`, `osc_ir_validate` and `c2_check_bytes` remain the |
| 145 | only lower serializers/checkers. Upper bytes are never passed as OSC and never |
| 146 | labelled lower proof. A future importer must fill these typed upper records; |
| 147 | a future lowering must consume legality obligations, produce unchanged OSC, |
| 148 | and submit that OSC through both existing decoder/validator and checker2. |
| 149 | The test-only C adapter exercises exactly these existing APIs, using legacy |
| 150 | host orchestration openly. No production C compiler/runtime is added. |
| 151 | |
| 152 | Issue #623 owns source-to-upper/OSC translation validation and signed receipts. |
| 153 | This layer provides exact semantic/provenance digests to bind there, but cannot |
| 154 | mint an approved receipt or certify source correspondence. Target/transform, |
| 155 | source profile, obligations and validation status must be bound by that future |
| 156 | adapter through reviewed existing receipt versioning. Full local judge and |
| 157 | independent API review remain publication gates. |
| 158 | |
| 159 | ## Qualification plan |
| 160 | |
| 161 | Seeded native compile only, pinned immutable source archive and existing bootstrap |
| 162 | entry; existing native SHA256 core imported without edits and hash-checked. |
| 163 | Independent Node buffers/crypto generate and check 10000 valid and 100000 |
| 164 | structurally malformed requests, with category membership, consumed-input hashes, |
| 165 | per-response actual counts, replay/identity/output assertions and declared seeds. |
| 166 | Test-only framed native entry calls the same core. Public commands and direct |
| 167 | core failure-after-success probes must leave no partial semantic output or stale |
| 168 | PASS receipt. Compiled semantic mutants must compile and run before being counted; |
| 169 | byte corruptions test source/span/profile/version/effect/runtime/length refusals. |
| 170 | Legacy fixture hashes are compared to pinned-base encodings through unchanged |
| 171 | OSC and checker2. Receipts are unsigned development evidence only. |
| 172 | |
| 173 | The build defaults to build/L574. SA_BUILD may select a child of that scratch |
| 174 | area; symlinks, hardlinked files and special files there refuse before writes. |
| 175 | SA_SEED_REPO may point to another local clone containing the exact pinned bridge |
| 176 | commit. Only committed archived sources are consumed. This is an explicit pinned |
| 177 | source dependency, not an embedded or silently downloaded compiler binary. |