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 / rust-u64-v1.md
| 1 | # Rust 2021 u64 wrapping profile v1 (#626, G2) |
| 2 | |
| 3 | Status: experimental, author-tested (TESTED), not QUALIFIED. Profile `rust-u64-wrapping-pure-v1` |
| 4 | (source-aware v1 language 2 Rust2021, profile 2, runtime 0, ABI 1, op dialect 2). Additive to |
| 5 | `translation-v1.md` and `translation-compose-v1.md`; S1 semantics (integers modulo 2^64, ops 1/2/3/4/9) |
| 6 | are unchanged. Rust is used only as a test oracle; both adapters are handwritten seeded Omega. |
| 7 | |
| 8 | ## 1. Accepted source |
| 9 | |
| 10 | The whole input is exactly one function item: |
| 11 | |
| 12 | ``` |
| 13 | source := ws ["pub" ws] "fn" ws NAME ws "(" ws [param ("," ws param)*] ")" ws "->" ws "u64" ws "{" ws expr ws "}" ws EOF |
| 14 | param := NAME ws ":" ws "u64" ws |
| 15 | expr := primary ("." ws METHOD ws "(" ws expr ws ")" ws)* |
| 16 | primary := PARAM | LITERAL | "(" ws expr ws ")" | "u64" ws "::" ws METHOD ws "(" ws expr ws "," ws expr ws ")" |
| 17 | METHOD := "wrapping_add" | "wrapping_sub" | "wrapping_mul" (S1 ops 2, 3, 4) |
| 18 | LITERAL := ("0" | [1-9][0-9]*) "u64" (value at most 2^64-1) |
| 19 | ``` |
| 20 | |
| 21 | - 0..6 parameters, all `u64`, distinct. The receiver of a method call is the left operand, the argument |
| 22 | the right operand; `u64::wrapping_add(x, y)` (and sub/mul) is the same operation as `x.wrapping_add(y)`. |
| 23 | Parentheses group only; they produce no operation. |
| 24 | - `NAME` (function and parameters): at most 32 ASCII bytes, first byte `a`..`z`, then `[A-Za-z0-9_]`; not a |
| 25 | Rust keyword (strict, reserved and weak: `as break const continue crate else enum extern false fn for if |
| 26 | impl in let loop match mod move mut pub ref return self static struct super trait true type unsafe use |
| 27 | where while async await dyn abstract become box do final macro override priv typeof unsized virtual |
| 28 | yield try union gen safe raw auto default macro_rules`), not `main`, not a primitive type name (`u8 u16 |
| 29 | u32 u64 u128 usize i8 i16 i32 i64 i128 isize f16 f32 f64 f128 bool char str`). The function name is `calc` |
| 30 | or `omega_` followed by at least one identifier byte. Other names refuse; nothing is renamed. |
| 31 | - Literals: decimal only with the exact suffix `u64`, no `_` separators (neither `1_000u64` nor `1_u64`), |
| 32 | no hexadecimal/octal/binary prefixes, no leading zero (`010u64` is decimal 10 in Rust but has a second |
| 33 | spelling, so it refuses, as in the C profile), no other suffix, no unsuffixed literal. |
| 34 | - `::` and `->` are single tokens (no inner whitespace). Trailing commas in the parameter list or in |
| 35 | calls refuse (one spelling). The body is exactly one tail expression: no `return` (anywhere), no |
| 36 | statements, no `let`, no blocks. |
| 37 | - Whitespace is space, tab, LF and CR. Ordinary comments are retained as source bytes: line comments `//` |
| 38 | (but not `///` followed by a byte other than `/`, and not `//!`) and block comments `/* */`, which nest as |
| 39 | in Rust. Doc comments (`///`, `//!`, `/**` not followed by `*` or `/`, `/*!`) are attribute sugar and |
| 40 | refuse. Comment text may be any valid UTF-8; code outside comments is ASCII. |
| 41 | - The whole input is strict UTF-8 (no overlong form, surrogate or code point above U+10FFFF), contains no |
| 42 | NUL and has no byte-order mark. At most 4096 bytes. |
| 43 | |
| 44 | ### Why plain `+ - *` refuse |
| 45 | |
| 46 | Rust's `a + b`, `a - b`, `a * b` on `u64` panic on overflow when `overflow-checks` is on (the default of |
| 47 | debug builds) and wrap when it is off (the default of release builds); the meaning of the source depends |
| 48 | on the build profile, not on the text. S1 is total modulo 2^64, which only the `wrapping_*` methods |
| 49 | express in every build mode. Plain operators therefore refuse 68 instead of being imported as wrapping. |
| 50 | The self-test compiles every original and exported program with `-C overflow-checks=on`, so a plain |
| 51 | operator that slipped through would panic on the boundary vectors. |
| 52 | |
| 53 | ## 2. Refusals (no stdout, named stderr `RUST_IMPORT_*`) |
| 54 | |
| 55 | | status | name | cases | |
| 56 | |---|---|---| |
| 57 | | 65 | SYNTAX | NUL; unterminated (also nested) block comment; missing tail expression; trailing comma; wrong arity; missing separator | |
| 58 | | 66 | UNSUPPORTED_TYPE | parameter or return type other than `u64` (`i64`, `usize`, `Wrapping<u64>`, `&u64`, ...); a primitive path other than `u64` in the body (`i64::wrapping_add`) | |
| 59 | | 67 | LIMIT | over 4096 bytes; over 6 parameters; over 64 upper operations (inputs and the synthetic pair included); parenthesis depth (grouping and call parentheses together) over 16; literal above 2^64-1 | |
| 60 | | 68 | UNSUPPORTED_ARITHMETIC | plain `+ - *`; `/ % << >> & \| ^ ! < >`, unary `-`/`*`, `as`, compound assignment; any method or associated item other than the three (`wrapping_div`, `wrapping_neg`, `checked_*`, `overflowing_*`, `saturating_*`, `pow`, `u64::MAX`); literal spelling outside section 1 | |
| 61 | | 69 | UNSUPPORTED_CONSTRUCT | `unsafe`, `const fn`, `async`, `extern`, `pub(...)`, attributes `#[..]`/`#![..]`, generics, `where`, turbofish, `<T>::` paths, `let`, `return`, statements, nested items, `use`, macros, control flow, blocks, closures, references, patterns, field access, a second item, non-ASCII outside comments | |
| 62 | | 70 | UNKNOWN_IDENTIFIER | an identifier that is not a parameter, keyword or primitive type (`c`, `std::...`) | |
| 63 | | 71 | UNSUPPORTED_SIGNATURE | function name rules; missing `-> u64`; parameter name rules (incl. `mut`, `self`); duplicate parameter | |
| 64 | | 72 | UNSUPPORTED_SOURCE_FORM | invalid UTF-8; byte-order mark; doc comments | |
| 65 | | 77 | IO | read or write failure | |
| 66 | |
| 67 | Public dispatch (`tools/adapters/rust-import`) adds 64 BAD_COMMAND (any argument) and 78 for a missing or |
| 68 | stale build (source or artifact hash differs from `build/L626/build.json`). |
| 69 | |
| 70 | ## 3. Imported unit |
| 71 | |
| 72 | A source-aware v1 OMSB envelope of the Rust member (`translation-compose-v1.md` section 1): header |
| 73 | language 2, profile 2, dialect version 1, runtime 0, ABI 1, the #625 contract digest; every operation |
| 74 | dialect 2, version 1, type 1, effects 0, alias 0. Input op 9 per parameter in declaration order (slot = |
| 75 | position, kept when unused; attribute 0, obligations 1); constant op 1 (attribute 1, obligations 0); ops |
| 76 | 2/3/4 (attribute 1 modulo 2^64, obligations 1). Operations are emitted in source order with operands |
| 77 | before their user, exactly as the C importer orders the equivalent C expression, so the same expression |
| 78 | imported from C and from Rust has the same canonical form N. |
| 79 | |
| 80 | Normalization pair: **yes**. Like the C importer, the Rust importer always appends `const 0` and |
| 81 | `add(root, that const)` (both with the empty span [0,0]) per `translation-v1.md` section 4. Reason: a |
| 82 | body that is a bare parameter other than the last one (`fn calc(a: u64, b: u64) -> u64 { a }`) has no |
| 83 | other representation in which the root is the last result, and with the pair `N(import_Rust(s_R)) = |
| 84 | N(import_C(s_C))` holds for every F1 expression, so `strip` treats C and Rust units the same way. |
| 85 | |
| 86 | Sidecar OMSP v1, encoding 1 (strict UTF-8), exact source bytes. Spans: an input covers its parameter |
| 87 | name, a constant its literal token (`42u64`), an arithmetic op its method name (`wrapping_add`); spans are |
| 88 | ASCII tokens and therefore on code point boundaries. |
| 89 | |
| 90 | ## 4. Export |
| 91 | |
| 92 | `tools/adapters/rust-export` (Omega source `src/adapters/rust-u64-export.om`, prepended with the unchanged |
| 93 | vendor SHA256 and `src/source-aware/core.om`) reads one OMSB envelope on stdin, validates it with the #621 |
| 94 | `decode` (sidecar framing, hashes, spans and UTF-8 included), and accepts every S1-family unit: C |
| 95 | (1/1, arithmetic obligations 1), Rust (2/2, 1) and Python (3/4, 5), runtime 0, ABI 1, ops 1/2/3/4/9 with |
| 96 | the S1 fields, input slots a permutation of 0..n-1. Output is generated from the operation records only; |
| 97 | the sidecar is never read for output, so a semantic-only envelope and every member retargeting R(U, M) |
| 98 | export the same bytes. |
| 99 | |
| 100 | ``` |
| 101 | pub fn calc(i0: u64, i1: u64, ...) -> u64 { <expr> } ("pub fn calc() -> u64 { <expr> }" for 0 inputs) |
| 102 | ``` |
| 103 | |
| 104 | followed by one LF. `<expr>`: input slot s is `i<s>`; a constant is `<decimal>u64`; ops 2/3/4 are |
| 105 | `<A>.wrapping_add(<B>)`, `.wrapping_sub(`, `.wrapping_mul(`. A method call binds tighter than every |
| 106 | other Rust expression form and the receiver of every emitted call is a path, a suffixed literal |
| 107 | (`5u64.wrapping_add(i0)` is valid) or another method call, so no receiver ever needs parentheses and |
| 108 | the exporter emits none. Shared SSA results are expanded as trees. The root is the pre-normalization |
| 109 | root of a NORMALIZED unit, otherwise the last result (`translation-v1.md` section 4); a second, |
| 110 | source-written `.wrapping_add(0u64)` is never stripped. |
| 111 | |
| 112 | The output must re-import under section 1: at most 4096 bytes, call-parenthesis depth at most 16 (depth |
| 113 | of `A.m(B)` = max(depth A, depth B + 1)), at most 64 operations after re-import (inputs + expanded tree + |
| 114 | 2). Otherwise it refuses 67 with no stdout. Other refusals: 65 malformed envelope (any #621 decode |
| 115 | failure other than 68, or more than 8192 bytes); 68 PROFILE_MISMATCH (decode status 68, or a valid v1 |
| 116 | unit outside the family: profiles 3/5/6, other ops, other fields, slot gaps); 77 IO; public dispatch 64 |
| 117 | (any argument) and 78 (stale or missing build). The function name is always `calc`. |
| 118 | |
| 119 | ## 5. Toolchain and commands |
| 120 | |
| 121 | Both adapters are compiled by the bridge-seed compiler `191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9` |
| 122 | (bridge commit `0fc7d8662cb799e7c206b17c18ea4c3ec2b8fea9`), built from source by `tools/source-aware/build`. |
| 123 | It is the compiler of the reviewed C importer, the #621 codec and the G1 C exporter: the vendored SHA256 |
| 124 | and `core.om` compile unchanged under it, and neither adapter needs argv (the native omc `734f0a39` was |
| 125 | not needed). `tools/adapters/build-rust-u64.py` writes `build/L626/{rust-import,rust-export,build.json}` |
| 126 | with the compiler, input and binary hashes; the public commands check them before dispatch. |
| 127 | |
| 128 | ```sh |
| 129 | export SA_SEED_REPO=/path/to/omega-bridge # contains 0fc7d866; mk/rust-u64.mk defaults to ~/workspace/omega-bridge |
| 130 | make -f mk/rust-u64.mk test-rust-u64 |
| 131 | tools/adapters/rust-import < calc.rs > calc.upper |
| 132 | tools/adapters/rust-export < calc.upper > exported.rs |
| 133 | ``` |
| 134 | |
| 135 | ## 6. Evidence and limits |
| 136 | |
| 137 | `tests/universal/translation/rust_selftest.py` (fixtures `fixtures-f2-rust.json`: all 35 F1 positives in |
| 138 | this profile, `not_in_profile` empty, plus Rust refusal fixtures) checks per fixture: import; an |
| 139 | independent decoder (header, fields, sidecar binding, spans); #621 `sa identity|decode|replay` built |
| 140 | in-tree (`mk/source-aware.mk`, overridable with `RUST_SA_ROOT`); N equality with the C import |
| 141 | (`mk/c-u64-import.mk` in-tree build, overridable with `RUST_C_IMPORT`) of the F1 source; export of the unit and of |
| 142 | R(U, C|Rust|Python) semantic-only (identical bytes); re-import identity; `rustc --edition 2021 -O -C |
| 143 | overflow-checks=on` on the original and the exported Rust and `cc` on the F1 C, compared with a bigint |
| 144 | evaluation of the records on the boundary vectors of `translation-v1.md` section 3 (all pairs for two |
| 145 | inputs) and seeded random vectors. Also: import and export boundary controls, the exporter refusals, |
| 146 | public-command closure, and the composition C -> Rust on every F1 positive and the four accepted C |
| 147 | import boundary controls. Rust -> C runs only when a passing G1 C exporter is given (`--c-export`), after |
| 148 | R(U, C), because the G1 exporter accepts C-member units only; otherwise it is reported NOT_RUN. The |
| 149 | native realization through the lowering seam is NOT_RUN here. Finite DIFFERENTIAL evidence, not PROOF. |