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 / spec / universal / translation-s2-v1.md

169 lines · 11926 bytes Raw Blame History Rendered
1# Translation profile S2 v1: signed i64, comparisons, select (#624, PROPOSED)
2
3Status: PROPOSED 2026-10-26 by the #624 integration coordinator. Not frozen; no tool implements it.
4Additive: `translation-v1.md`, `translation-compose-v1.md`, `translation-compose-v2.md`,
5`source-aware-v1.md` and `source-aware-v2.md` are unchanged and every S1 unit, identity and status stays
6byte-identical. Freezing this file needs one review pass from the #621 codec owner (envelope rows of
7section 2) and the C and Rust lane owners (section 4); the freeze replaces this status line and nothing
8else.
9
10Purpose: the smallest widening that real C -> Rust ports need first (aien-dev/babel). It stays pure and
11bounded: no loops, recursion, memory, calls or effects, so every S2 unit is a straight-line DAG with
12selection, and evaluation always terminates (the PostScript -> PDF lesson). Order of work: C import and
13Rust export first, then the other ten directions; S2 is QUALIFIED only when all 12 directions and 30
14compositions pass independent validation, and S3 (arrays/slices) does not start before that.
15
16## 1. Semantic profile S2
17
18One pure function of 0..6 inputs, each `u64` or `i64`, returning `u64`, `i64` or `bool`. Values:
19
20| type | values |
21|---|---|
22| u64 (type 1, as S1) | integers 0..2^64-1 |
23| i64 (type 5, new) | integers -2^63..2^63-1, two's complement bit pattern in a constant's u64 immediate |
24| bool (type 6, new) | false, true; not an integer (no arithmetic on it, no implicit conversion) |
25
26Operations (S1's 1..4 and 9 unchanged; new ones listed):
27
28| op | meaning | operand types -> result |
29|---|---|---|
30| 1 | constant | u64 / i64 / bool (immediate 0 or 1 for bool) |
31| 2/3/4 | add/sub/mul | (u64,u64)->u64 attr 1; (i64,i64)->i64 attr 5 or 6 |
32| 10..15 | eq, ne, lt, le, gt, ge | (T,T)->bool, T is u64 or i64; i64 compares signed, u64 unsigned |
33| 16 | select c ? a : b | A = bool c; B = a; immediate = earlier SSA index of b (op 8 precedent); a, b same type |
34| 17 | not | bool -> bool |
35| 9 | input | u64 or i64 |
36
37Arithmetic attributes for i64 (new):
38
39- 5 = wrapping: the result is the exact result reduced to -2^63..2^63-1 modulo 2^64. Total.
40- 6 = overflow-is-error: defined only when the exact result is in range; obligation 32
41 (no-signed-overflow) is attached. Outside the range the source language's behavior is an error (C/C++
42 undefined behavior; Zig checked illegal behavior). Rust's plain operators carry the error contract only
43 when overflow checks are on: rustc 1.98.1 panics with `-C overflow-checks=on` (the debug default, and
44 settable in release) and, with overflow checks off (the release default), returns the result reduced
45 modulo 2^64; the Rust Reference permits either panic or wrap when checks are off, so the wrap is the
46 measured behavior of the pinned rustc, not a language guarantee. The exported Rust source is the same in
47 every setting; the setting is part of the realization and section 6 qualifies all three (D, R, RC). A
48 Rust crate that needs the error contract in a release build must set `overflow-checks = true` in the
49 profile of the ROOT package or workspace manifest: Cargo ignores `[profile]` settings in dependencies.
50 Any total realization that equals the exact result whenever it is in range is a REFINEMENT of attr 6 and
51 is labelled PROVEN_REFINEMENT only with a proof, BOUNDED_VALIDATION otherwise. Release wrapping is such a
52 REFINEMENT of C17 signed overflow (undefined behavior); it is never reported as equal to the C error, and
53 debug panic results are never promoted to a release guarantee.
54
55No signed/unsigned mixing, casts, division, remainder, shifts, bitwise operators, short-circuit `&&`/`||`
56(they are selects and come with S2.1), loops, early returns or statements other than the single return
57expression.
58
59## 2. Envelope rows (source-aware v3, #621 codec owner)
60
61One new OMSA semantic header version value, 3, for S2 profiles only; v1/v2 units are unchanged. New
62registry rows: type 5 i64, type 6 bool; attributes 5 and 6; obligation bit 32; ops 10..17 as above with
63effects 0, alias 0; op 16 B/immediate rule as in section 1. Profiles (one per language):
64
65| profile | name | language |
66|---|---|---|
67| 10 | c17-int64-select-v1 | 1 |
68| 11 | rust-i64-select-v1 | 2 |
69| 12 | python-i64-select-v1 | 3 |
70| 13 | cpp17-int64-select-v1 | 5 |
71| 14 | zig-i64-select-v1 | 6 |
72| 15 | go-i64-select-v1 | 7 |
73
74`retarget` and the N(U) neutral form extend as in compose-v2 section 2: N(U) is the profile 10 unit.
75
76## 3. Source forms each importer must establish (before emitting a record)
77
78| language | i64 attr 5 (wrapping) | i64 attr 6 (overflow-is-error) | compare / select |
79|---|---|---|---|
80| C17 | `(int64_t)((uint64_t)a + (uint64_t)b)` exact shape (GCC 13 pinned: conversion is modulo 2^64, implementation-defined in C17) | `a + b` on two `int64_t` | `a < b` etc. only as the condition of `?:`; `c ? x : y` |
81| Rust | `a.wrapping_add(b)` | `a + b` on `i64`; the error outcome requires overflow-checks on (section 1) | `if c { x } else { y }`; comparison operators |
82| Python | `((a + b + 2**63) & (2**64-1)) - 2**63` exact shape | `_ck(a + b)` with the profile's range-check helper | `x if c else y` |
83| C++17 | as C with `std::int64_t` and `static_cast` | as C | as C |
84| Zig | `a +% b` on `i64` | `a + b` on `i64` | `if (c) x else y` |
85| Go | `a + b` on `int64` (always wrapping, language spec) | never produced | Go has no `?:`; a single `if c { return x }; return y` form |
86
87## 4. Exporters
88
89Each exporter emits plain source in the form above for every attribute it can express. For attr 6 the
90exporters emit the language's own overflow-is-error form where one exists (C/C++ plain `+`, Rust plain
91`+`, Zig plain `+`, Python `_ck`). Go export of attr 6 emits plain `+` (wrapping), recorded as a
92REFINEMENT, never as equality. Round trip: import(export(U)) must have U's semantic identity except
93where this table maps two attributes to one source form (Go attr 6 -> attr 5 on re-import), which is
94recorded per fixture, not hidden.
95
96## 5. Lowering and realization
97
98`lower` emits `long` (i64) values in restricted Omegese. The original text of this section said that
99the pinned omc realizes 64-bit `long` add, sub and mul as wrapping (seed/omc/omc.om at f8588e10,
100`bo_fix`: type 9 takes no overflow check). That statement is superseded: amendment A1 (section 7)
101measures that omc 734f0a39 traps on a signed `long` overflow (trap 1), and the overflow log of
102omega-bridge#49 (`evidence/deepinfer-flops-pairs/overflow-measurement.log`) shows the same for
103omc 2c824805. The original conclusion that a realization of attr 6 is a REFINEMENT is superseded too:
104under A1 `lower-s2` realizes attr 6 exactly. Signed compares use `lt`/`le`/`gt`/`ge` on `long`.
105Bindings: omega-bridge tools/native must carry `int64_t` and a `bool`-as-`uint64_t` 0/1 result; that is
106a bridge change (ABI v1 has `uint64_t` only), owned by the bridge lane.
107
108## 6. Required tests per direction (the S1 set, widened)
109
110Positive; boundary (i64 -2^63, -1, 0, 1, 2^63-1 per input, all compare outcomes, both select arms);
111overflow (attr 5 wraps; attr 6 at exactly the boundary and one past it, where the C oracle is built with
112`-fsanitize=signed-integer-overflow -fno-sanitize-recover` and must report the error); malformed;
113unsupported feature (each excluded construct in section 1 refuses with its exit code); mutation (attr 5
114<-> 6, signed <-> unsigned compare, select arm swap, operand swap of non-commutative ops, constant sign
115flip). Oracles: REFERENCE on Python bigints; DIFFERENTIAL against gcc 13.3.0, rustc 1.98.1, CPython
1163.12.3, g++ 13.3.0, Zig 0.17.0, Go 1.27.3.
117
118Rust build-setting matrix (rustc 1.98.1). Every exported Rust unit and every C -> Omega -> Rust
119composition is compiled and run in three settings, each with its flags spelled out:
120
121| setting | rustc flags | attr 6 one past the boundary | in range, attr 5, compare/select |
122|---|---|---|---|
123| D | `-C opt-level=0 -C debug-assertions=on -C overflow-checks=on` | panic, caught = error (equals the C UBSan error) | equal to the reference / C oracle |
124| R | `-C opt-level=3 -C debug-assertions=off -C overflow-checks=off` | the two's-complement wrapped value, asserted exactly (bigint reference reduced modulo 2^64); classified REFINEMENT, never ERROR | equal |
125| RC | `-C opt-level=3 -C overflow-checks=on` | panic, caught = error | equal |
126
127Units with no attr 6 operation must give identical rows in D, R and RC. Two negative controls run in every
128self-test and must be observed failing: an expectation that R reports the attr 6 error, and the `add` unit
129with attr 6 exported as `wrapping_add` checked against the D and RC error expectation.
130
131## 7. Amendments (universal/624-s2-impl, BabelS2, 2026-10-26)
132
133Marked amendments made while implementing this profile. Each is the smallest choice consistent with the
134text above; the self-test `tests/universal/translation/s2_selftest.py` (`mk/s2.mk test-translation-s2`)
135exercises every one.
136
137- **A1 (corrects section 5).** The pinned omc 734f0a39 does NOT wrap `long` add/sub/mul: a signed
138 overflow at run time exits with trap status 1 (observed on the native caller). `lower-s2` therefore
139 computes every attr 5 and attr 6 operation with wrapping `ulong` arithmetic on the two's-complement bits,
140 and keeps a poison bit per value: an attr 6 op ORs its own overflow predicate into poison, a select ORs
141 its condition's poison with the chosen arm's poison, and a poisoned root executes `trap 1`. attr 6 is
142 thus realized exactly (trap iff the C/Rust oracle reports overflow on the demanded path), not refined.
143- **A2.** Select is demand-driven, as C `?:` and Rust `if`: overflow in the arm not taken is not an
144 error. The reference evaluator, the importer, the exporter and the lowering all follow this.
145- **A3 (records attributes and obligations).** i64 and bool constants attr 0, u64 constants attr 1;
146 compare, select and not attr 0 with obligations 0; inputs attr 0 with obligations 1; attr 5 ops
147 obligations 1; attr 6 ops obligations 33.
148- **A4 (C importer grammar, section 3).** Parameters and result are `int64_t` only (`uint64_t`, `int`
149 and other types refuse 66). Literals are `0LL` or `[1-9][0-9]*LL` up to 2^63-1 (larger refuses 67).
150 Unary minus, `!`, casts, a comparison outside a `?:` condition, chained comparisons and `<<`/`>>`
151 refuse 68; a lone `=` refuses 69.
152- **A5.** An imported result that would otherwise be a bare input is normalized by the pair const 0
153 (type 5, attr 0) followed by add (type 5, attr 5, obligations 1); exporters strip the pair.
154- **A6 (corrects section 5, bindings).** No bridge change: ABI v1 passes an i64 argument and result as its
155 `uint64_t` two's-complement bits, and a bool root is returned as `uint64_t` 0/1. The C caller converts.
156- **A7.** Oracle versions as run: rustc 1.98.1 (48a229cea 2026-09-01); gcc 13.3.0
157 (Ubuntu 13.3.0-6ubuntu2~24.04.1).
158- **A8 (function names, requested by consumer aien-dev/babel).** The function name is not part of the
159 semantic unit (identity is unchanged by it); it appears only in the provenance source text.
160 - `c-i64-import`: the function may have any C identifier of at most 63 bytes that is not a C keyword
161 (C17 and C23, plus `int64_t`, `uint64_t`, `main`), not a C17 7.1.3 reserved identifier (`__x`, `_X`),
162 not a `*_t` typedef name and not an all-upper-case `*_MAX`/`*_MIN`/`*_WIDTH`/`*_C` `<stdint.h>` macro
163 name; otherwise 71. Parameter names keep the section 3 rule.
164 - `rust-i64-export [NAME]`: optional NAME, default `calc`; a C identifier of at most 63 bytes that is
165 not a Rust keyword (strict, reserved or 2024 edition `gen`) nor `_`; otherwise 64. The dispatcher
166 frames it exactly as `c-export` does (one length byte, the name, then the envelope).
167 - `lower-s2 [NAME]`: optional NAME with the S1 `lower` rule (not an Omegese reserved word); otherwise
168 64. The bridge symbol becomes `omega_<NAME>`.
169 S1 tools are unchanged.