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 / cpp-u64-v1.md

194 lines · 15164 bytes Raw Blame History Source

C++17 std::uint64_t pure profile v1 (#739, G3)

Status: experimental, author-tested (TESTED), not QUALIFIED. Profile cpp17-uint64-pure-v1 (source-aware v2 source-aware-v2.md: OMSA semantic header version 2, language 5 C++17, profile 7, runtime 0, ABI 1, op dialect 5, arithmetic obligations 1). Additive to translation-v1.md, translation-compose-v1.md and translation-compose-v2.md; S1 semantics (integers modulo 2^64, ops 1/2/3/4/9) are unchanged. C++ compilers are used only as test oracles; both adapters are handwritten seeded Omega.

1. Accepted source

The input starts with the exact bytes #include <cstdint>\n and is then exactly one function definition:

source  := "#include <cstdint>\n" ws TYPE ws NAME ws "(" ws [param (ws "," ws param)*] ws ")" ws
           "{" ws "return" ws expr ws ";" ws "}" ws EOF
param   := TYPE ws NAME
expr    := term (ws ("+" | "-") ws term)*            (left associative)
term    := primary (ws "*" ws primary)*              (left associative, binds tighter than + -)
primary := NAME | LITERAL | "(" ws expr ws ")"
LITERAL := TYPE ws "{" ws DEC "ULL" ws "}"           (S1 op 1)
TYPE    := "std::uint64_t"                           (one lexeme: no whitespace or comment inside)
DEC     := "0" | [1-9][0-9]*                         (value at most 2^64-1)
ws      := (SP | TAB | LF | CR | "//" comment-to-LF | "/*" comment "*/")*

Type rules (what the importer establishes before emitting ops 2/3/4)

translation-compose-v2.md section 4 requires both operands of every + - * to be exactly std::uint64_t, with no integral promotion and no mixed types. In this grammar every operand is a parameter, a LITERAL or a parenthesised expr, and each of those is a prvalue or lvalue of exactly std::uint64_t, so every operator has two std::uint64_t operands and a std::uint64_t result ([expr.arith.conv]: same type, no conversion). With the environment assumption below (int at most 64 bits), the integral promotions of [conv.prom] never apply to std::uint64_t, and unsigned arithmetic is modulo 2^64 ([basic.fundamental]).

Why the other constructs are excluded

Environment assumptions (as in the C profile): std::uint64_t exists (it is optional in the standard), unsigned long long is exactly 64 bits, int is at most 64 bits, and no user-defined or predefined macro changes an accepted identifier. Qualification uses the recorded Linux AArch64 g++ environment.

2. Refusals (no stdout, named stderr CPP_IMPORT_*)

statusnamecases
65SYNTAXNUL; unterminated block comment; missing ;, ) or operand; trailing comma; default argument
66UNSUPPORTED_TYPEreturn or parameter type other than std::uint64_t (section 1)
67LIMITover 4096 bytes; over 6 parameters; over 64 upper operations; parenthesis depth over 16; literal above 2^64-1
68UNSUPPORTED_ARITHMETICoperators and literal spellings outside section 1 (including bare ULL and plain int literals)
69UNSUPPORTED_CONSTRUCTspecifiers, 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
70UNKNOWN_IDENTIFIERan identifier that is not a parameter (c, std::max, unqualified uint64_t{...} in an expression)
71UNSUPPORTED_SIGNATUREfunction or parameter name rules; duplicate parameter
72UNSUPPORTED_PREPROCESSORfirst line not exactly #include <cstdint>\n (BOM, CRLF, <stdint.h>, missing); #/%:; backslash; trigraphs
77IOread or write failure

Public dispatch (tools/adapters/cpp-import) adds 64 BAD_COMMAND (any argument) and 78 for a missing or stale build (source or artifact hash differs from build/L739/build.json).

3. Imported unit

A source-aware v2 OMSB envelope of the C++ member: OMSA version 2, language 5, profile 7, dialect version 1, runtime 0, ABI 1, the #625 contract digest; every operation dialect 5, version 1, type 1, effects 0, alias 0. Input op 9 per parameter in declaration order (slot = position, kept when unused; attribute 0, obligations 1); constant op 1 (attribute 1, obligations 0); ops 2/3/4 (attribute 1 modulo 2^64, obligations 1). Operations are emitted in source order with operands before their user, exactly as the C importer orders the equivalent C expression, so N(import_C++(s')) = N(import_C(s)) for every F1 expression (self-tested).

Normalization pair: yes. Like the C importer, the C++ importer always appends const 0 and add(root, that const) (both with the empty span [0,0]) per translation-v1.md section 4, for the same reasons as the Rust profile: a body that is a bare earlier parameter has no other representation whose root is the last result, and strip then treats C, Rust and C++ units alike.

Sidecar OMSP v1, encoding 0 (raw bytes, as the C importer), exact source bytes. Spans: an input covers its parameter name; a constant covers the whole literal std::uint64_t{5ULL} (from std to }); an arithmetic op covers its operator byte.

4. Export

tools/adapters/cpp-export (Omega source src/adapters/cpp-u64-export.om, prepended with the unchanged vendor SHA256 and the #621 v2 codec src/source-aware/core-v2.om) reads one OMSB envelope on stdin, validates it with the v2 decode (sidecar framing, hashes and spans included) and accepts every member of the extended family (translation-compose-v2.md section 1): C 1/1, Rust 2/2, Python 3/4 (arithmetic obligations 5) under OMSA 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, 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 operation records only; the sidecar is never read for output, so a semantic-only envelope and every retargeting R(U, M) export the same bytes.

#include <cstdint>
std::uint64_t calc(std::uint64_t i0, std::uint64_t i1, ...) { return <expr>; }      ("calc()" for 0 inputs)

followed by one LF. <expr>: input slot s is i<s>; a constant is std::uint64_t{<decimal>ULL}; a binary op is <A> + <B>, <A> - <B> or <A> * <B> with single spaces, parenthesised exactly as the C exporter (translation-v1.md section 6: leaf 3, * 2, +/- 1; a left operand gets parentheses iff its precedence is lower than the parent's, a right operand iff lower than or equal), because C++ gives + - * the same precedence and left associativity as C and the braced literal is a postfix-expression (a leaf). Shared SSA results are expanded as trees. The root is the pre-normalization root of a NORMALIZED unit, otherwise the last result (translation-v1.md section 4); a second, source-written + std::uint64_t{0ULL} is never stripped.

The output must re-import under section 1: at most 4096 bytes, parenthesis depth at most 16, at most 64 operations after re-import (inputs + expanded tree + 2). Otherwise it refuses 67 with no stdout. Other refusals: 65 malformed envelope (any v2 decode failure other than 68, including unknown versions 66 and obligation mismatches 72, or more than 8192 bytes); 68 PROFILE_MISMATCH (decode status 68, or a valid unit outside the family: profiles 3/5/6, division op 5 in any profile, other ops or fields, slot gaps); 77 IO; public dispatch 64 (any argument) and 78 (stale or missing build). The function name is always calc.

5. Toolchain and commands

Both adapters are compiled by the bridge-seed compiler 191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 (bridge commit 0fc7d8662cb799e7c206b17c18ea4c3ec2b8fea9), built from source by tools/source-aware/build, the compiler of the C importer, the #621 codecs and the Rust/Python adapters. tools/adapters/build-cpp-u64.py writes build/L739/{cpp-import,cpp-export,build.json} with the compiler, input and binary hashes; the public commands check them before dispatch. The exporter needs src/source-aware/core-v2.om (#621 v2 codec lane).

export SA_SEED_REPO=/path/to/omega-bridge        # contains 0fc7d866 (and 012860db)
export OMEGA_BRIDGE_REPO=$SA_SEED_REPO OMEGA_NATIVE_OMC=/path/to/omc   # omc sha256 734f0a39
make -f mk/cpp-u64.mk test-cpp-u64               # CXX/CC default to g++/cc on PATH
tools/adapters/cpp-import < calc.cpp > calc.upper
tools/adapters/cpp-export < calc.upper > exported.cpp

Oracles (declared and pinned here, translation-compose-v2 section 4): g++ 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04.1, /usr/bin/g++) with `-std=c++17 -O2 -Wall -Wextra -Werror -Wconversion -Wsign-conversion -pedantic-errors -Wno-unused-parameter(unused named inputs are valid and deliberately kept);ccwith-std=c17 -O2 -Wall -Wextra -Werror -Wno-unused-parameterfor C sources; the native realization uses the pinned omc734f0a39` and omega-bridge native.om at 012860db exactly as lower_selftest.py.

6. Evidence and limits

tests/universal/translation/cpp_selftest.py (fixtures fixtures-f2-cpp.json: all 35 F1 positives in this profile, not_in_profile empty, plus C++ refusal fixtures) checks per fixture: import; an independent decoder (v2 header, fields, sidecar binding, spans); v2 codec sa identity|decode|replay|legality from build/L832 (NOT_RUN when that build is absent); N equality with the C import of the F1 source; export of the unit and of R(U, M) semantic-only for all six members (identical bytes); same-language re-import with identical semantic bytes; g++ on the original and the exported C++ and cc on the F1 C, compared with a bigint evaluation of the records on the boundary vectors of translation-v1.md section 3 (all pairs for two inputs) and seeded random vectors. Also: oracle controls (a ULL literal is not std::uint64_t, the braced form and the operators are; an out-of-range braced literal does not compile), import boundary controls, exporter refusals and accepted exporter boundaries, public-command closure, and the compositions C -> C++ (F1 positives and the four accepted C import boundary controls) and C++ -> C (F2 positives and the accepted C++ boundary controls). C++ -> C uses export_C(R(U, C)) with the unchanged v1-core G1 C exporter (translation-compose-v2 section 3). R is the #624 tools/adapters/retarget when the checkout has it (mk/cpp-u64.mk builds it; --retarget or CPP_SELFTEST_RETARGET names another one), and every tool output must then equal the test-code R byte for byte; without it the test-code R alone is used. The self-test has no default outside the checkout: a missing 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 DIFFERENTIAL agreement of the original program, the reference, the generated program and the native realization lower(N(U_A)). Finite DIFFERENTIAL evidence, not PROOF.