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 / cpp-u64-v1.md
| 1 | # C++17 std::uint64_t pure profile v1 (#739, G3) |
| 2 | |
| 3 | Status: experimental, author-tested (TESTED), not QUALIFIED. Profile `cpp17-uint64-pure-v1` (source-aware v2 |
| 4 | `source-aware-v2.md`: OMSA semantic header version 2, language 5 C++17, profile 7, runtime 0, ABI 1, op dialect |
| 5 | 5, arithmetic obligations 1). Additive to `translation-v1.md`, `translation-compose-v1.md` and |
| 6 | `translation-compose-v2.md`; S1 semantics (integers modulo 2^64, ops 1/2/3/4/9) are unchanged. C++ compilers |
| 7 | are used only as test oracles; both adapters are handwritten seeded Omega. |
| 8 | |
| 9 | ## 1. Accepted source |
| 10 | |
| 11 | The input starts with the exact bytes `#include <cstdint>\n` and is then exactly one function definition: |
| 12 | |
| 13 | ``` |
| 14 | source := "#include <cstdint>\n" ws TYPE ws NAME ws "(" ws [param (ws "," ws param)*] ws ")" ws |
| 15 | "{" ws "return" ws expr ws ";" ws "}" ws EOF |
| 16 | param := TYPE ws NAME |
| 17 | expr := term (ws ("+" | "-") ws term)* (left associative) |
| 18 | term := primary (ws "*" ws primary)* (left associative, binds tighter than + -) |
| 19 | primary := NAME | LITERAL | "(" ws expr ws ")" |
| 20 | LITERAL := TYPE ws "{" ws DEC "ULL" ws "}" (S1 op 1) |
| 21 | TYPE := "std::uint64_t" (one lexeme: no whitespace or comment inside) |
| 22 | DEC := "0" | [1-9][0-9]* (value at most 2^64-1) |
| 23 | ws := (SP | TAB | LF | CR | "//" comment-to-LF | "/*" comment "*/")* |
| 24 | ``` |
| 25 | |
| 26 | - 0..6 parameters, all `std::uint64_t`, named and distinct; zero parameters are written `()`. `+`, `-`, `*` |
| 27 | are S1 ops 2, 3, 4. Parentheses group only and produce no operation. |
| 28 | - `NAME` (function and parameters): at most 32 ASCII bytes, first byte `a`..`z`, then `[A-Za-z0-9_]`; no |
| 29 | `__` anywhere (reserved, [lex.name]); not beginning with `int` or `uint` (the `<cstdint>` names); not a C++17 |
| 30 | or C++20 keyword, alternative token, or identifier with special meaning (`final`, `override`, `import`, |
| 31 | `module`); not `main`, `std`, `linux` or `unix`. The function name is `calc` or `omega_` followed by at least |
| 32 | one identifier byte. Other names refuse; nothing is renamed. |
| 33 | - Comments are retained as source bytes and may contain any byte except NUL (no UTF-8 check, as in the C |
| 34 | profile); code outside comments is ASCII. |
| 35 | - At most 4096 bytes, at most 64 upper operations (inputs and the synthetic pair included), parenthesis depth |
| 36 | at most 16 (literal braces are not counted). |
| 37 | |
| 38 | ### Type rules (what the importer establishes before emitting ops 2/3/4) |
| 39 | |
| 40 | `translation-compose-v2.md` section 4 requires both operands of every `+ - *` to be exactly `std::uint64_t`, |
| 41 | with no integral promotion and no mixed types. In this grammar every operand is a parameter, a `LITERAL` or a |
| 42 | parenthesised `expr`, and each of those is a prvalue or lvalue of exactly `std::uint64_t`, so every operator |
| 43 | has two `std::uint64_t` operands and a `std::uint64_t` result ([expr.arith.conv]: same type, no conversion). |
| 44 | With the environment assumption below (`int` at most 64 bits), the integral promotions of [conv.prom] never |
| 45 | apply to `std::uint64_t`, and unsigned arithmetic is modulo 2^64 ([basic.fundamental]). |
| 46 | |
| 47 | - Literal spelling. `123ULL` alone has type `unsigned long long`. On the qualified target (Linux AArch64, |
| 48 | LP64) `std::uint64_t` is `unsigned long`, a distinct type, so `a + 1ULL` is a mixed-type expression whose |
| 49 | result type is `unsigned long long`; it refuses 68. The only constant spelling is |
| 50 | `std::uint64_t{<DEC>ULL}`: a braced explicit type conversion ([expr.type.conv]) whose result is exactly |
| 51 | `std::uint64_t`. List-initialization forbids narrowing ([dcl.init.list]), so a value that does not fit is |
| 52 | ill-formed instead of being converted (the self-test has an oracle control). The `ULL` suffix inside the |
| 53 | braces is required because an unsuffixed decimal at or above 2^63 has no standard type ([lex.icon]); one |
| 54 | uniform spelling covers all 2^64 values. `ull`, `UL`, `U`, unsuffixed, hexadecimal, octal, binary, leading |
| 55 | zero, digit separators `'` and user-defined literals refuse 68. `std::uint64_t{}`, `std::uint64_t{a}`, |
| 56 | `std::uint64_t{1ULL+2ULL}` and `std::uint64_t(...)` refuse 69 (only a single decimal literal may be braced). |
| 57 | - A plain `1` is `int`; `1 - a` and `a - 1` mix `int` and `std::uint64_t` (usual arithmetic conversions); |
| 58 | they refuse 68 rather than being typed implicitly. |
| 59 | - `uint64_t` unqualified refuses 66: `<cstdint>` declares `std::uint64_t`; whether it also declares |
| 60 | `::uint64_t` is unspecified ([headers]). `<stdint.h>` is a deprecated header ([depr.c.headers]) and is not |
| 61 | accepted (72). Other types (`int`, `auto`, `unsigned long long`, `std::int64_t`, `std::uint32_t`, |
| 62 | `std::size_t`, `::uint64_t`, `std :: uint64_t` with inner whitespace, `(void)`) refuse 66. |
| 63 | |
| 64 | ### Why the other constructs are excluded |
| 65 | |
| 66 | - `constexpr`, `consteval`, `inline`, `static`, `extern`, `extern "C"`, `noexcept`, `[[...]]` attributes and |
| 67 | trailing `const`: they change linkage, the ODR status, the function type or the diagnostics of the |
| 68 | declaration, not its value; each would be a second spelling of the same S1 function, and an exporter would |
| 69 | have to decide which to emit. They refuse 69. |
| 70 | - Templates, namespaces, `using`, `auto`, references, pointers, casts (`static_cast` etc. and functional |
| 71 | casts), lambdas, user-defined literals, operator overloading, statements other than the single `return`, |
| 72 | control flow, a second declaration (also a stray `;`): outside S1 or a second spelling; 69 (types 66). |
| 73 | - Division `/` (division by zero is undefined behaviour; op 5 is outside the family), `%`, shifts, bitwise |
| 74 | and logical operators, comparisons, `?:`, unary `+ - ~ !`, assignment, `++`/`--` and the alternative tokens |
| 75 | (`and`, `or`, `not`, `xor`, `bitand`, `bitor`, `compl`, `*_eq`): 68. |
| 76 | - Preprocessing beyond the first line: any `#` or `%:` outside comments refuses 72. Every backslash byte and |
| 77 | every C trigraph spelling (`??` followed by one of `= / ' ( ) ! < > -`) refuses 72 anywhere, including inside |
| 78 | comments, exactly as in the C profile: C++17 removed trigraphs, but `-trigraphs` and pre-C++17 modes still |
| 79 | replace them, and a `??/` or `\` at the end of a `//` comment splices the next line into the comment. |
| 80 | - `linux` and `unix` are predefined object-like macros in GCC's GNU modes (`-std=gnu++17`, g++'s default) and |
| 81 | not in `-std=c++17`; reserving them keeps every accepted source meaningful under both. |
| 82 | |
| 83 | Environment assumptions (as in the C profile): `std::uint64_t` exists (it is optional in the standard), |
| 84 | `unsigned long long` is exactly 64 bits, `int` is at most 64 bits, and no user-defined or predefined macro |
| 85 | changes an accepted identifier. Qualification uses the recorded Linux AArch64 g++ environment. |
| 86 | |
| 87 | ## 2. Refusals (no stdout, named stderr `CPP_IMPORT_*`) |
| 88 | |
| 89 | | status | name | cases | |
| 90 | |---|---|---| |
| 91 | | 65 | SYNTAX | NUL; unterminated block comment; missing `;`, `)` or operand; trailing comma; default argument | |
| 92 | | 66 | UNSUPPORTED_TYPE | return or parameter type other than `std::uint64_t` (section 1) | |
| 93 | | 67 | LIMIT | over 4096 bytes; over 6 parameters; over 64 upper operations; parenthesis depth over 16; literal above 2^64-1 | |
| 94 | | 68 | UNSUPPORTED_ARITHMETIC | operators and literal spellings outside section 1 (including bare `ULL` and plain `int` literals) | |
| 95 | | 69 | UNSUPPORTED_CONSTRUCT | specifiers, attributes, templates, namespaces, `using`, references, pointers, casts, braced non-literals, lambdas, statements, a second declaration, keywords such as `this`/`sizeof`/`true` in expressions, unnamed parameters, non-ASCII outside comments | |
| 96 | | 70 | UNKNOWN_IDENTIFIER | an identifier that is not a parameter (`c`, `std::max`, unqualified `uint64_t{...}` in an expression) | |
| 97 | | 71 | UNSUPPORTED_SIGNATURE | function or parameter name rules; duplicate parameter | |
| 98 | | 72 | UNSUPPORTED_PREPROCESSOR | first line not exactly `#include <cstdint>\n` (BOM, CRLF, `<stdint.h>`, missing); `#`/`%:`; backslash; trigraphs | |
| 99 | | 77 | IO | read or write failure | |
| 100 | |
| 101 | Public dispatch (`tools/adapters/cpp-import`) adds 64 BAD_COMMAND (any argument) and 78 for a missing or stale |
| 102 | build (source or artifact hash differs from `build/L739/build.json`). |
| 103 | |
| 104 | ## 3. Imported unit |
| 105 | |
| 106 | A source-aware v2 OMSB envelope of the C++ member: OMSA version 2, language 5, profile 7, dialect version 1, |
| 107 | runtime 0, ABI 1, the #625 contract digest; every operation dialect 5, version 1, type 1, effects 0, alias 0. |
| 108 | Input op 9 per parameter in declaration order (slot = position, kept when unused; attribute 0, obligations |
| 109 | 1); constant op 1 (attribute 1, obligations 0); ops 2/3/4 (attribute 1 modulo 2^64, obligations 1). |
| 110 | Operations are emitted in source order with operands before their user, exactly as the C importer orders the |
| 111 | equivalent C expression, so `N(import_C++(s')) = N(import_C(s))` for every F1 expression (self-tested). |
| 112 | |
| 113 | Normalization pair: **yes**. Like the C importer, the C++ importer always appends `const 0` and |
| 114 | `add(root, that const)` (both with the empty span [0,0]) per `translation-v1.md` section 4, for the same |
| 115 | reasons as the Rust profile: a body that is a bare earlier parameter has no other representation whose root is |
| 116 | the last result, and `strip` then treats C, Rust and C++ units alike. |
| 117 | |
| 118 | Sidecar OMSP v1, encoding 0 (raw bytes, as the C importer), exact source bytes. Spans: an input covers its |
| 119 | parameter name; a constant covers the whole literal `std::uint64_t{5ULL}` (from `std` to `}`); an arithmetic |
| 120 | op covers its operator byte. |
| 121 | |
| 122 | ## 4. Export |
| 123 | |
| 124 | `tools/adapters/cpp-export` (Omega source `src/adapters/cpp-u64-export.om`, prepended with the unchanged vendor |
| 125 | SHA256 and the #621 v2 codec `src/source-aware/core-v2.om`) reads one OMSB envelope on stdin, validates it with |
| 126 | the v2 `decode` (sidecar framing, hashes and spans included) and accepts every member of the extended family |
| 127 | (`translation-compose-v2.md` section 1): C 1/1, Rust 2/2, Python 3/4 (arithmetic obligations 5) under OMSA |
| 128 | version 1 and C++ 5/7, Zig 6/8, Go 7/9 under version 2 (the codec ties the version to the profile); runtime 0, |
| 129 | ABI 1, ops 1/2/3/4/9 with the S1 fields, input slots a permutation of 0..n-1. Output is generated from the |
| 130 | operation records only; the sidecar is never read for output, so a semantic-only envelope and every |
| 131 | retargeting R(U, M) export the same bytes. |
| 132 | |
| 133 | ``` |
| 134 | #include <cstdint> |
| 135 | std::uint64_t calc(std::uint64_t i0, std::uint64_t i1, ...) { return <expr>; } ("calc()" for 0 inputs) |
| 136 | ``` |
| 137 | |
| 138 | followed by one LF. `<expr>`: input slot s is `i<s>`; a constant is `std::uint64_t{<decimal>ULL}`; a binary |
| 139 | op is `<A> + <B>`, `<A> - <B>` or `<A> * <B>` with single spaces, parenthesised exactly as the C exporter |
| 140 | (`translation-v1.md` section 6: leaf 3, `*` 2, `+`/`-` 1; a left operand gets parentheses iff its precedence |
| 141 | is lower than the parent's, a right operand iff lower than or equal), because C++ gives `+ - *` the same |
| 142 | precedence and left associativity as C and the braced literal is a postfix-expression (a leaf). Shared SSA |
| 143 | results are expanded as trees. The root is the pre-normalization root of a NORMALIZED unit, otherwise the last |
| 144 | result (`translation-v1.md` section 4); a second, source-written `+ std::uint64_t{0ULL}` is never stripped. |
| 145 | |
| 146 | The output must re-import under section 1: at most 4096 bytes, parenthesis depth at most 16, at most 64 |
| 147 | operations after re-import (inputs + expanded tree + 2). Otherwise it refuses 67 with no stdout. Other |
| 148 | refusals: 65 malformed envelope (any v2 decode failure other than 68, including unknown versions 66 and |
| 149 | obligation mismatches 72, or more than 8192 bytes); 68 PROFILE_MISMATCH (decode status 68, or a valid unit |
| 150 | outside the family: profiles 3/5/6, division op 5 in any profile, other ops or fields, slot gaps); 77 IO; |
| 151 | public dispatch 64 (any argument) and 78 (stale or missing build). The function name is always `calc`. |
| 152 | |
| 153 | ## 5. Toolchain and commands |
| 154 | |
| 155 | Both adapters are compiled by the bridge-seed compiler `191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9` |
| 156 | (bridge commit `0fc7d8662cb799e7c206b17c18ea4c3ec2b8fea9`), built from source by `tools/source-aware/build`, |
| 157 | the compiler of the C importer, the #621 codecs and the Rust/Python adapters. `tools/adapters/build-cpp-u64.py` |
| 158 | writes `build/L739/{cpp-import,cpp-export,build.json}` with the compiler, input and binary hashes; the public |
| 159 | commands check them before dispatch. The exporter needs `src/source-aware/core-v2.om` (#621 v2 codec lane). |
| 160 | |
| 161 | ```sh |
| 162 | export SA_SEED_REPO=/path/to/omega-bridge # contains 0fc7d866 (and 012860db) |
| 163 | export OMEGA_BRIDGE_REPO=$SA_SEED_REPO OMEGA_NATIVE_OMC=/path/to/omc # omc sha256 734f0a39 |
| 164 | make -f mk/cpp-u64.mk test-cpp-u64 # CXX/CC default to g++/cc on PATH |
| 165 | tools/adapters/cpp-import < calc.cpp > calc.upper |
| 166 | tools/adapters/cpp-export < calc.upper > exported.cpp |
| 167 | ``` |
| 168 | |
| 169 | Oracles (declared and pinned here, translation-compose-v2 section 4): g++ 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1, |
| 170 | `/usr/bin/g++`) with `-std=c++17 -O2 -Wall -Wextra -Werror -Wconversion -Wsign-conversion -pedantic-errors |
| 171 | -Wno-unused-parameter` (unused named inputs are valid and deliberately kept); `cc` with `-std=c17 -O2 -Wall |
| 172 | -Wextra -Werror -Wno-unused-parameter` for C sources; the native realization uses the pinned omc `734f0a39` |
| 173 | and omega-bridge `native.om` at `012860db` exactly as `lower_selftest.py`. |
| 174 | |
| 175 | ## 6. Evidence and limits |
| 176 | |
| 177 | `tests/universal/translation/cpp_selftest.py` (fixtures `fixtures-f2-cpp.json`: all 35 F1 positives in this |
| 178 | profile, `not_in_profile` empty, plus C++ refusal fixtures) checks per fixture: import; an independent decoder |
| 179 | (v2 header, fields, sidecar binding, spans); v2 codec `sa identity|decode|replay|legality` from `build/L832` |
| 180 | (NOT_RUN when that build is absent); N equality with the C import of the F1 source; export of the unit and of |
| 181 | R(U, M) semantic-only for all six members (identical bytes); same-language re-import with identical semantic |
| 182 | bytes; g++ on the original and the exported C++ and `cc` on the F1 C, compared with a bigint evaluation of the |
| 183 | records on the boundary vectors of `translation-v1.md` section 3 (all pairs for two inputs) and seeded random |
| 184 | vectors. Also: oracle controls (a `ULL` literal is not `std::uint64_t`, the braced form and the operators are; |
| 185 | an out-of-range braced literal does not compile), import boundary controls, exporter refusals and accepted |
| 186 | exporter boundaries, public-command closure, and the compositions C -> C++ (F1 positives and the four accepted |
| 187 | C import boundary controls) and C++ -> C (F2 positives and the accepted C++ boundary controls). C++ -> C uses |
| 188 | `export_C(R(U, C))` with the unchanged v1-core G1 C exporter (translation-compose-v2 section 3). R is the #624 |
| 189 | `tools/adapters/retarget` when the checkout has it (`mk/cpp-u64.mk` builds it; `--retarget` or |
| 190 | `CPP_SELFTEST_RETARGET` names another one), and every tool output must then equal the test-code R byte for |
| 191 | byte; without it the test-code R alone is used. The self-test has no default outside the checkout: a missing |
| 192 | g++/cc, `OMEGA_NATIVE_OMC` or `OMEGA_BRIDGE_REPO` is NOT_RUN (exit 3), a pin mismatch is FAIL. Both compositions check identity under N and the |
| 193 | DIFFERENTIAL agreement of the original program, the reference, the generated program and the native |
| 194 | realization `lower(N(U_A))`. Finite DIFFERENTIAL evidence, not PROOF. |