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

205 lines · 16188 bytes Raw Blame History Rendered
1# Go 1.27 uint64 profile v1 (#741, G3)
2
3Status: experimental, author-tested (TESTED), not QUALIFIED. Profile `go-u64-pure-v1` (source-aware v2:
4OMSA semantic header version 2, language 7 Go 1.27, profile 9, runtime 0, ABI 1, op dialect 7, arithmetic
5obligations 1; `source-aware-v2.md` section 2, `translation-compose-v2.md` section 1). Additive to
6`translation-v1.md`, `translation-compose-v1.md` and `translation-compose-v2.md`; S1 semantics (integers
7modulo 2^64, ops 1/2/3/4/9) are unchanged. Go is used only as a test oracle; both adapters are
8handwritten seeded Omega.
9
10## 1. Accepted source
11
12The whole input is one Go source file of package `main` holding exactly one function declaration:
13
14```
15file := "package" "main" ";" "func" NAME "(" [params] ")" "uint64" "{" "return" expr [";"] "}" [";"] EOF
16params := group ("," group)*
17group := PNAME ("," PNAME)* "uint64"
18expr := term (("+" | "-") term)* (S1 ops 2, 3; left associative)
19term := primary ("*" primary)* (S1 op 4; left associative)
20primary := PNAME | LITERAL | "(" expr ")"
21LITERAL := "0" | [1-9][0-9]* (value at most 2^64-1)
22```
23
24- Tokens are separated by spaces, tabs, CR, LF and comments. `;` is the explicit semicolon or one
25 inserted by Go's rule: a newline (LF) or the end of input after an identifier other than `package` and
26 `func`, a literal, `)`, `]` or `}` is a `;` token. So `return a\n+ b` ends the return statement after
27 `a` (then `+ b` refuses 69), `func calc(a uint64\n)` and `(a\n+ b)` refuse 65, while a newline after a
28 binary operator (`a +\n b`) or after `{`, `(` and `,` is plain whitespace. CR alone never inserts.
29- Package clause exactly `package main`. The file is a translation unit that a caller links with its
30 own `func main` (the oracle does exactly that); no other package name, no `import`, no other
31 declaration. The function name is `calc` or `omega_` followed by at least one identifier byte.
32- Parameters: 0..6, named, distinct, type exactly `uint64`, grouped (`a, b uint64`) or not; the slot is
33 the position in declaration order, unused parameters are kept. Names: at most 32 ASCII bytes, first
34 byte `a`..`z`, then `[A-Za-z0-9_]`; not a Go keyword, not a predeclared identifier (types `any bool byte
35 comparable complex64 complex128 error float32 float64 int int8 int16 int32 int64 rune string uint uint8
36 uint16 uint32 uint64 uintptr`, constants `true false iota nil`, functions `append cap clear close complex
37 copy delete imag len make max min new panic print println real recover`), not `main` or `init`. Since
38 the file declares nothing else, `uint64` always denotes the predeclared type.
39- Result: exactly one unnamed `uint64` (not parenthesised). Body: exactly one `return` of one expression;
40 an explicit `;` may follow it, nothing else.
41- Literals: decimal only, `0` or `[1-9][0-9]*`. Refused spellings (68): legacy octal `010` (octal 8 in
42 Go), `0o`/`0x`/`0b` prefixes, `_` separators, float (`2.0`, `1e3`, `.5`) and imaginary (`1i`) constants,
43 rune literals. Go converts `1e3` and `'a'` exactly to `uint64`, but they are second spellings of a
44 number; the profile keeps one spelling per value as the C and Rust profiles do.
45- Comments: line comments `//` and general comments `/* */` (which do not nest) are retained as source
46 bytes; a general comment containing a newline acts as a newline for semicolon insertion, as in Go.
47 Compiler directives are not ordinary comments and refuse 72: the byte after `//` must be a space, tab,
48 CR, LF or the end of input (this excludes `//go:...`, `//go:build`, `//line`, `//export`, `//extern`),
49 a line comment whose text starts with `+build` after spaces/tabs refuses (legacy build constraint), and
50 the byte after `/*` must be a space, tab, CR, LF or `*` (this excludes `/*line`). Comment text may be any
51 valid UTF-8; code outside comments is ASCII.
52- The whole input is strict UTF-8 (no overlong form, surrogate or code point above U+10FFFF), contains
53 no NUL and has no byte-order mark. At most 4096 bytes.
54
55### 1.1 Untyped constants (the Go-specific rule)
56
57`+ - *` on two `uint64` operands are modulo 2^64 by the Go specification. A Go expression whose operands
58are all constants is an untyped constant expression: it is evaluated exactly (arbitrary precision; the gc
59type checker rejects results wider than 512 bits) and only its final value is converted to `uint64` where
60it meets a `uint64` operand or the result; a value outside 0..2^64-1 is a compile error. So `0 - a` and
61`18446744073709551615 + a` wrap at run time, while `a + (0 - 1)` and `return 18446744073709551615 + 1`
62do not compile, and `(0 - 1) + 1` compiles to 0 through a negative intermediate.
63
64Rule of this profile: every constant-only node of the expression tree (a literal, or an operation whose
65two operands are both constant-only) must evaluate exactly within 0..2^64-1; otherwise the importer
66refuses 68. The importer checks every such node as it builds it (unsigned overflow detection on add,
67sub and mul).
68
69Why the accepted programs mean the S1 tree: reduction modulo 2^64 is a ring homomorphism, so a
70constant-only node's exact value is congruent to its modulo-2^64 tree value; when the exact value lies in
710..2^64-1 the two are equal. Every maximal constant expression is such a node, so its exact value equals
72the tree value, fits `uint64` and converts without error; every other operation has a `uint64` operand
73and is Go's modulo-2^64 arithmetic. Intermediate constants are within 0..2^64-1 too, far below the 512-bit
74limit. Hence every accepted source compiles and computes the S1 tree. The rule is narrower than Go: it
75refuses constant expressions with an out-of-range intermediate whose final value fits (`(0 - 1) + 1`,
76`18446744073709551615 * 2 - 18446744073709551615 + a`), which Go accepts. Such a source has no
77in-range S1 tree, and refusing it keeps the profile free of exact arithmetic beyond 64 bits.
78
79The self-test checks this rule against `go build` (section 6): the refusal fixtures record Go's verdict
80(`go_build`), and seeded random trees mixing constants (0, 1, 2, 3, 2^32-1, 2^32, 2^63-1, 2^63, 2^64-2,
812^64-1) and variables check that the importer accepts exactly the trees satisfying the rule, that every
82accepted tree compiles and returns the modulo-2^64 value, and that Go's own verdict on every refused tree
83equals the modelled Go rule above (maximal constant expressions in range, intermediates within 512 bits).
84
85## 2. Refusals (no stdout, named stderr `GO_IMPORT_*`)
86
87| status | name | cases |
88|---|---|---|
89| 65 | SYNTAX | NUL; unterminated general comment; missing return value or statement; trailing comma; a `;` inserted where the grammar has none (newline before `)`, inside parentheses, after `return`); package clause not terminated; missing operator or `)`; parameter group without a type |
90| 66 | UNSUPPORTED_TYPE | parameter or result type other than `uint64` (`int`, `uint`, `uintptr`, `uint32`, `byte`, `*uint64`, `[]uint64`, ...); a predeclared type name in the body (conversions `uint64(x)`) |
91| 67 | LIMIT | over 4096 bytes; over 6 parameters; over 64 upper operations (inputs and the synthetic pair included); parenthesis depth over 16; literal above 2^64-1 |
92| 68 | UNSUPPORTED_ARITHMETIC | `/ % & \| ^ &^ << >>`, comparisons, unary `+ - ^ ! & *`, `++`; literal spelling outside section 1; a constant-only node outside 0..2^64-1 (section 1.1) |
93| 69 | UNSUPPORTED_CONSTRUCT | `import`, `var`, `const`, `type`, a second declaration, a declaration before the package clause, statements other than the one `return` (`:=`, `var`, `if`, `go`, `defer`, a second statement after an inserted `;`, empty statements), type parameters, method receivers, named, parenthesised or multiple results, `return a, b`, variadic parameters, calls, selectors, strings, predeclared constants and functions in the body (`iota`, `max`), assignment, non-ASCII outside comments |
94| 70 | UNKNOWN_IDENTIFIER | an identifier that is not a parameter, keyword or predeclared name (`c`, the function itself) |
95| 71 | UNSUPPORTED_SIGNATURE | package name other than `main`; function name rules (`Calc`, `main`, `foo`); parameter name rules (`_`, `A`, a keyword or predeclared name, over 32 bytes); duplicate parameter; missing result type |
96| 72 | UNSUPPORTED_SOURCE_FORM | invalid UTF-8; byte-order mark; compiler directives and build constraints in comments |
97| 77 | IO | read or write failure |
98
99Public dispatch (`tools/adapters/go-import`) adds 64 BAD_COMMAND (any argument) and 78 for a missing or
100stale build (source or artifact hash differs from `build/L741/build.json`). Many refusals are Go compile
101errors anyway; others (`1e3`, `010`, `x := a`, directives, ...) are valid Go outside this narrow profile.
102The fixture field `go_build` records which (section 6).
103
104## 3. Imported unit
105
106A source-aware v2 OMSB envelope of the Go member: OMSB version 1, OMSA semantic header version 2,
107language 7, profile 9, dialect version 1, runtime 0, ABI 1, the #625 contract digest; every operation
108dialect 7, version 1, type 1, effects 0, alias 0. Input op 9 per parameter in declaration order (slot =
109position, kept when unused; attribute 0, obligations 1); constant op 1 (attribute 1, obligations 0); ops
1102/3/4 (attribute 1 modulo 2^64, obligations 1). Operations are emitted in source order with operands
111before their user, exactly as the C importer orders the equivalent C expression, so the same expression
112imported from C and from Go has the same canonical form N (`translation-compose-v2.md` section 2).
113
114Normalization pair: **yes**. Like the C and Rust importers, the Go importer always appends `const 0` and
115`add(root, that const)` (both with the empty span [0,0]) per `translation-v1.md` section 4, so the root is
116the last result even for a bare earlier parameter, and `N(import_Go(s_G)) = N(import_C(s_C))` holds for
117every F1 expression.
118
119Sidecar OMSP v1, encoding 1 (strict UTF-8), exact source bytes. Spans: an input covers its parameter
120name, a constant its literal token, an arithmetic op its operator byte (`+`, `-`, `*`); spans are ASCII
121tokens and therefore on code point boundaries.
122
123## 4. Export
124
125`tools/adapters/go-export` (Omega source `src/adapters/go-u64-export.om`, prepended with the unchanged
126vendor SHA256 and the #621 v2 codec `src/source-aware/core-v2.om`) reads one OMSB envelope on stdin,
127validates it with the v2 `decode` (sidecar framing, hashes, spans and UTF-8 included) and accepts every
128unit of the extended S1 family: C (OMSA version 1, language/profile 1/1, arithmetic obligations 1), Rust
129(1, 2/2, 1), Python (1, 3/4, 5), C++ (2, 5/7, 1), Zig (2, 6/8, 1) and Go (2, 7/9, 1), runtime 0, ABI 1,
130ops 1/2/3/4/9 with the S1 fields, input slots a permutation of 0..n-1. Output is generated from the
131operation records only; the sidecar is never read for output, so a semantic-only envelope and every
132member retargeting R(U, M) export the same bytes.
133
134```
135package main
136
137func calc(i0 uint64, i1 uint64, ...) uint64 { ("func calc() uint64 {" for 0 inputs)
138 return <expr>
139}
140```
141
142with one LF after every line (a tab before `return`). `<expr>`: input slot s is `i<s>`; a constant is its
143decimal value; ops 2/3/4 are `+`, `-`, `*`. Parentheses are minimal for the exact SSA tree under Go
144precedence (operand 6, `*` 5, `+ -` 4, left associative): a left operand is parenthesised iff its
145precedence is lower than its parent's, a right operand iff lower or equal (so `a+(b+c)` and `a-(b-c)`
146keep their tree and a left chain has none). Spacing follows go/printer: an operator gets a blank on each
147side iff its precedence is below the cutoff of its binary expression (cutoff 5 at depth 1 when the
148unparenthesised binary region mixes precedences 4 and 5, 6 at depth 1 otherwise, 4 at deeper levels; a
149left operand of the same precedence keeps the depth, every other operand gets depth + 1, a parenthesised
150operand is printed one level shallower). The output is therefore gofmt-clean: `gofmt` reproduces it
151byte for byte (checked on every export in the self-test). Shared SSA results are expanded as trees. The
152root is the pre-normalization root of a NORMALIZED unit, otherwise the last result (`translation-v1.md`
153section 4); a second, source-written `+ 0` is never stripped.
154
155The output must re-import under section 1: at most 4096 bytes, parenthesis depth at most 16, at most 64
156operations after re-import (inputs + expanded tree + 2), and every constant-only node of the emitted
157tree within 0..2^64-1 exactly (section 1.1; a C unit of `(0ULL - 1ULL) + a` wraps in C and would be a Go
158compile error). Otherwise it refuses 67 with no stdout. Other refusals: 65 malformed envelope (any v2
159decode failure other than 68, including unknown versions, or more than 8192 bytes); 68 PROFILE_MISMATCH
160(decode status 68, or a valid unit outside the family: profiles 3/5/6, division op 5 in any profile,
161other fields, slot gaps); 77 IO; public dispatch 64 (any argument) and 78 (stale or missing build). The
162function name is always `calc`.
163
164## 5. Toolchain and commands
165
166Both adapters are compiled by the bridge-seed compiler `191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9`
167(bridge commit `0fc7d8662cb799e7c206b17c18ea4c3ec2b8fea9`), built from source by `tools/source-aware/build`,
168the compiler of the reviewed C importer and of the #621 v1 and v2 codecs. `tools/adapters/build-go-u64.py`
169writes `build/L741/{go-import,go-export,build.json}` with the compiler, input and binary hashes; the
170public commands check them before dispatch.
171
172```sh
173export OMEGA_BRIDGE_REPO=/path/to/omega-bridge # holds 0fc7d866 (seed compiler, SA_SEED_REPO) and 012860db (binding)
174export OMEGA_NATIVE_OMC=/path/to/omc # sha256 734f0a39
175export GO=/path/to/go GOFMT=/path/to/gofmt # Go 1.27.3, or go/gofmt on PATH; missing = exit 3 NOT_RUN
176make -f mk/go-u64.mk test-go-u64
177tools/adapters/go-import < calc.go > calc.upper
178tools/adapters/go-export < calc.upper > exported.go
179```
180
181Oracle: Go 1.27.3 linux/arm64 (`$GO`/`$GOFMT` or PATH; version and sha256 recorded in
182the self-test result), `go build -trimpath` in a fresh temporary module (`go 1.27`) with
183`GOTOOLCHAIN=local GOFLAGS=-mod=mod GOPROXY=off GOWORK=off CGO_ENABLED=0`; the unit file is compiled
184unmodified beside a harness file of package `main` that reads decimal vectors and prints `calc(...)`.
185`gofmt` from the same toolchain checks the export form.
186
187## 6. Evidence and limits
188
189`tests/universal/translation/go_selftest.py` (fixtures `fixtures-f2-go.json`: all 35 F1 positives in this
190profile, `not_in_profile` empty, 12 Go-specific extra positives, and Go refusal fixtures with the
191`go build` verdict of each refused file) checks per positive: import; an independent decoder (header,
192fields, sidecar binding, spans); the #621 v2 codec `sa identity|decode|replay` (`build/L832`) and the v1
193codec's refusal (66) of the v2 unit; N equality with the C import of the F1 source; export of the unit and
194of R(U, M) semantic-only for all six members (identical bytes, gofmt-clean); re-import identity; Go on the
195original and the exported program and `cc` on the F1 C, compared with a bigint evaluation of the records
196on the boundary vectors of `translation-v1.md` section 3 (all pairs for two inputs) and seeded random
197vectors. Also: the untyped-constant rule (section 1.1) against `go build`, import and export boundary
198controls, the exporter refusals, public-command closure, the composition C -> Go on every F1 positive and
199the four accepted C import boundary controls, and Go -> C on every F2-go positive through R(U, C) and the
200#622 C exporter. R is computed in test code; when the tree holds the #624 `tools/adapters/retarget` (the
201default of `--retarget`) its output is used for every R(U, M) and must equal the test-code R byte for byte.
202The native realization `lower(N(U_A))` (G1 lowering, omc `734f0a39`, bridge binding) runs on both
203compositions and is required. `test-go-u64` builds every in-tree prerequisite (both codecs, C importer, C
204exporter, lowering, retarget when present); all tool defaults are in-tree or from the environment. A piece
205whose tool is absent is reported NOT_RUN. Finite DIFFERENTIAL evidence, not PROOF.