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 / seed / ng / front / README.md

292 lines · 22874 bytes Raw Blame History Rendered
1# seed/ng/front: the ng-front lane (Hive NG)
2
3`seed/ng/src/front.om` is the ng front end: the lexer, parser and language checks of
4`seed/omc/omc.om` @943d9555 with every machine-code path removed. It is a unit of `seed/ng/ng.units`
5(after `ir.om`, so it is OM-2 code) and runs as two ng modes (`src/main.om`). In both the payload is an
6Omega unit, and ng must refuse exactly what omc refuses, on the same line with the same error code,
7and accept what omc accepts (DECISIONS D5, D6, D9):
8
9- `@ng front-check` checks only and writes nothing.
10- `@ng front-ir` checks the same way (the same refusals, through `fe_check`), then lowers the unit it
11 accepted to ΩIR with the `ir_*` builders of `src/ir.om` and writes the binary unit to stdout
12 (`fe_lout`, the section "@ng front-ir" at the end of front.om).
13
14## How front.om was made (provenance, not a build step)
15
161. `rename.om rename.map < omc.om` renames every function to `fe_NAME` (`main` to `fe_run`) and every
17 global to `f_NAME` (8 bytes at most), the D1b name discipline. The renamed omc rebuilds byte for byte.
182. Hand edits, each with an `omc.om NAME @943d9555 line N` note: no output write; x86/EFI targets and
19 IR v1 units exit 64; `fe_cond` reads and type-checks only; `fe_pushb` without branch places;
20 `fe_s_text` without code; `fe_xefival` is error 25; `fe_alloc` without the 16-register cap;
21 `fe_trapsite` keeps only the om2 diag site record; `fe_finish` without trap stubs; the
22 check-point snapshot without code offsets.
233. `prune.om prune.txt` removes the rest: code buffers and code-offset globals are sinks, word writers
24 and branch patchers go, and then every function, assignment and block left without an effect.
25
26Since the first commit `src/front.om` is edited directly (the OM-2 renames `at`, `big`, `ops` to
27`atp`, `bigf`, `opsb`; `fe_run` split into main.om's input and `fe_check`), so the tools are the
28record of how it was derived, not a way to rebuild it. The gate checks the result.
29Long names (omc `omc/long-names` 2e20b286, omc `564c5835`) were carried over by hand at the same omc sites:
30`fe_tok2` interns a word of 9..63 bytes as the packed word 1 + 256 * index (`f_ln_*`, `f_tw8`), the 14 name
31checks omc raised from 8 to 63 bytes are raised here, and `fe_mput_name`, `fe_findfn`, `fe_newname`,
32`fe_rdval` and `fe_stmt` follow omc. Abstract, layout, layout-field and IR-mode names stay at 8 as in omc.
33
34## What is not reproduced (D6)
35
36omc refusals that come from its AArch64 code generator are not language rules: error 12 (16-register
37expression pool), 14 for trap sites, 24 (branch displacement range). ng accepts such units; they are
38`beyond` rows in `declared.txt` (`NAME beyond K REASON`), and the gate requires omc to exit exactly K
39and ng to exit 0. Whether ng then compiles them correctly needs an independent referee (expected output
40or a C twin): NOT_RUN until ng emits code. The value slots of `fe_alloc` keep omc's pool numbering
41without the cap (slots past 16 share a number); ΩIR values replace them.
42
43Units ng does not take exit 64 and are `scope` rows (`NAME scope K REASON`, omc must exit K): x86/EFI
44targets (D8) and IR v1 units (first line `ir`). Runtime pools are accepted, so their former
45scope rows are removed from `declared.txt`. A bound of ng's own that omc never reaches because
46another omc limit refuses first is an `ngonly` row (`NAME ngonly K REASON`): both must exit K, and
47their stderr lines differ (none today). omc has had no table capacities since 2026-11-11 (OMEGESE 9.6), and
48ng's front has had none since the same day (no-caps arena, `src/ir.om` `ar_*`): its input, names, long names,
49functions, calls, blocks, breaks, continues, inline edges, om2 diag site records, value-depth cells and the
50front-ir lowering's names, block stack, snapshots, local arrays and call arguments are regions of one 128 MiB
51arena that grow on demand. A full arena is error 14 with an ng-use record on stderr. Value nesting is bounded
52by ng's own stack at 32768 levels, as omc's is. Names, long names, functions and lowering names have chained
53hashes. A unit whose first line is `usage` is checked as usual and writes the ng-use record in place of output,
54as omc's `usage` does (`seed/ng/tests/nocaps/gate.om` is the alarm).
55An input ng refuses at a fixed table of its own while omc goes past it would be an `ngcap` row
56(`NAME ngcap K REASON`, REASON naming ng's table): ng must exit K and omc anything else below 100. The gate prints
57`NGCAP ng still refuses C inputs omc accepts` on every run with C > 0, and a row whose input ng accepts fails.
58There are none since the arena: the seven former rows are ordinary rows (`calls_524289`, `size_*`, `c2-00312`,
59`c2-05720` and `c2-00308` exact, `c2-00838` beyond 12). Each K is omc's exit as measured with the pinned omc. om2
60fmt units get all of omc's checks (`fe_fmtprep`) and no formatted text.
61An input of any size the arena holds is read whole (cases `size_*`, newlines only: both compilers' error 16). The
62one input edge that is main.om's: a stdin read error is `ng: refused class 27` (omc: error 1).
63
64`enlarge` (keyword 244, omc pools landing 1) is reserved in every unit. Without a pool to name, its misuses receive omc's same code and line (`cases/pool_enlarge_*.om`); pool `len`, `get`, `put`, `read` and `write` add no words or non-pool forms. With a pool, `NAME = enlarge P n` is accepted and lowered (below).
65
66## Gate
67
68The complete check-parity sweep is mandatory in `tests/gates/run.sh seed`.
69Its input lists are enumerated once in `seed/ng/front/check-lists.txt`.
70The host gate compiles `gate-front.om`, supplies `declared.txt` and
71`mutants.txt`, and gives the runner a fresh scratch directory.
72Targeted invocations remain useful while developing, but do not replace this
73full release check.
74
75The source is `units:seed/ng/ng.units`: the units that list names, concatenated in its order, so a
76stage lane's unit (src/a64.om on the slice branches) comes with the list and no gate command changes
77(`ngbuild build`, below, checks their sha256 pins; this gate does not);
78`in:front-check.in` puts the mode line `@ng front-check` before each case
79on ng's stdin, while omc reads the case alone. A wrong mode line makes every case FAIL.
80
81Cases: `cases-front.txt` (f64 rem/and/or/xor, the gate15 refusal cases error-codes.reg names, omc.om,
82the ng-front tools and each ng unit alone, the input-size edges, 524288, 524289 and 1000000 calls in one function,
83and `diag_big`, an om2
84`diag` unit whose 96955 stderr bytes are compared in full: omc and ng each write stderr to their own
85descriptor and the gate compares the two in 65536-byte chunks), `cases-om2.txt` (every .om under
86seed/omc/om2), `cases-tests.txt` (seed/omc/tests), and the frozen C2 manifest (5876 units). Mutants
87(`mutants/`): m_scope (s_end forgets to restore the name table), m_fltop (f64 accepts rem/and/or/xor),
88m_fmtcr (om2 fmt misses a CR), m_sitebyte (one site-record byte past 65536 corrupted), m_callcap (the
89old 524288-entry call table again: `calls_524289` and `calls_1000000` fail); each must be KILLED.
90Units far past every old table, run to their answers through `@ng a64`, are the no-caps gate's
91(`seed/ng/tests/nocaps/gate.om`; seed/ng/README.md, No-caps gate).
92
93The gate runs on the Spark; there is no GitHub workflow for it. Build ng through its pins and check that
94the gate's checker (`SCRATCH/fecheck`) is byte-for-byte that ng:
95
96 cat seed/ng/sha256.om seed/ng/ngbuild.om | seed/out/omc > ngbuild
97 ngbuild build seed/out/omc seed/ng/ng.units ng
98 cmp ng SCRATCH/fecheck
99
100Host runs are recorded in the lane's READY files.
101
102## @ng front-ir (M1)
103
104The lowering is a second walk over the source after `fe_check` accepted it, reusing the front end's
105tokenizer, number parser and function table. Each Omega function becomes an ΩIR function (handle =
106front index + 1); `fn main to int` is the program entry (kind 2, IR.md D11). Values are SSA: a join
107(if merge, loop head, `for` latch, `break` target) is a block whose parameters are the token and every
108scalar name in scope; branch targets are fresh blocks that take only the token. The checks omc makes at
109run time become ΩIR check ops (IR.md s13): signed add/sub/mul overflow, div/rem by zero and signed
110minimum div -1, shift and rotate amounts, signed shl and neg, `get`/`put` bounds, `read`/`write` slices,
111failing conversions, and `while` fuel (1000000 passes, or its `bound`). Local and global arrays are
112`alloca`/`gaddr` references; texts are class 1 globals.
113
114What it does not lower exits 64 with `ng: front-ir: line N: not lowered` (no output): units without
115`fn main to int` (ΩIR needs a program entry; omc writes no executable for them either), a bool or float
116shift amount, and every construct outside the M1 subset (read from code: the `fe_lno` call sites).
117Every array parameter, sized or unsized, is a `SLICE` of its declared access (0 `view`, 1 `edit`).
118A sized parameter's length is checked by the front end before lowering, so a text can reach a sized
119`view` parameter. `len` of a parameter is the `len` op. An argument is the caller's slice when the
120access matches, else `slice` over the whole array, and `part A o k` is `chk.slice` (trap 3, omc's two
121part checks in one) then `slice`. `unroll` loops lower as plain `for` loops and `inline` functions as
122calls: both are omc code-shape choices with the same results.
123
124Gate (Omega, `gate-front-ir.om`; the scratch directory must not exist):
125
126 cat seed/ng/sha256.om seed/ng/front/gate-front-ir.om | seed/out/omc > gate-front-ir
127 gate-front-ir seed/out/omc "$(cut -d' ' -f1 seed/out/omc.sha256)" \
128 SCRATCH seed/ng/front/cases-front-ir.txt
129
130It builds ng (the units of `seed/ng/ng.units`), ngcheck and ngrun with the pinned omc, then for each `run`
131case compiles the unit with omc and runs it, lowers it with ng, requires ngcheck ACCEPT, runs the ΩIR with
132ngrun and compares exit status and stdout (stderr is free: the kernels time themselves there); for each
133`refuse` case ng's exit and stderr must equal omc's with empty stdout. Cases: the 15 run pairs of
134`seed/ng/tests/ir`, two default-fuel run units of `cases/` (`fuel_while`, `fuel_for`: no bound, trap 4
135after 1000000 passes), two signed `for` latch units of `cases/` (`for_latch_i8`, `for_latch_i64`: the body
136writes the counter's maximum and the latch's add 1 traps 1, as omc's does; fe_lendl adds it under chk.add),
137two slice cases (`runs/p-part.om`, its `part` traps 3, and `runs/p-partok.om`), the
138thirteen ng-bench kernels (the OM-2 crypto units sha, chacha, x25519 last), six mixed-shift and fma run
139units of `cases/` (below), 33 refusal units of `cases/`, the float-to-integer cases below, and the host-word cases (`host` rows, below). ngrun interprets (90-470x native) and has no step cap yet, so twelve kernels run as reduced
140copies (`runs/`, loop counts and sizes only, `runs/PROVENANCE.md` lists each change; approved by the
141queen) and matmul verbatim. The full-size kernels stay verbatim in `kernels/` (`kernels/PROVENANCE.md`).
142No standing gate compares all of them at full size: ng-a64's rgate front phase (ng/slice-m1, list `tfr`)
143runs only the nine integer kernels (arith, branch, leafcall, fib38, fib40, isort, sieve, sort, matmul)
144natively against omc; linear (f64, rgate list `tfz`) is refused by a64, and sha, chacha and x25519 are in
145no rgate list. Full size for those four is one-off ngrun-vs-omc evidence recorded with the hand-off, not a gate.
146Every child the gate starts is killed after 600 s: that case prints `NOT_RUN` and counts in `notrun=`, never
147as ok, FAIL, a kill or a trip. Negative controls: five lowering mutants (the `for` latch adds 2;
148`and`/`or`/`xor` shifted to the next op; a `part`'s offset and count swapped; a mixed-type shift amount
149checked against its own width instead of the value's; fma's second and third operands swapped) must fail a
150run case, two host mutants (a `long` host argument lowered as `int`; `chk.bounds` in place of a host
151slice's `chk.slice`) must fail a host case. Swapped fmin and fmax, qty arithmetic without its checks,
152and every array parameter declared read-only must each fail a run case;
153`@ng front-check` mode must fail the first run case (no ΩIR) and `@ng ir-copy` mode the first refusal case.
154Last line `FRONTIRGATE PASS|FAIL|NOT_RUN cases=N run=R refuse=F host=H classed=Q ... notrun=U`, exit 0, 1 or 4 (NOT_RUN: no failure but U > 0,
155never PASS).
156
157### Float-to-integer conversion
158
159A float source converts with the total IR `conv` (op 36) and no `chk.conv`: like omc's `fp_toint` it
160truncates toward zero, saturates to the destination's range and maps NaN to 0 (`fe_lcf` answers false for a
161float source). Integer-to-integer narrowing keeps its `chk.conv` (trap 5). Before this, front-ir emitted
162`chk.conv` for a float source, so an out-of-range or NaN conversion trapped 5 where omc saturates
163(CompilerBugHunt, ledger L1060; NgFrontFull). Cases at the end of `cases-front-ir.txt`: 160 programs
164`runs/fconv-TYPE-FLOAT-EDGE.om` (f32 and f64 to each of the eight integer types: the destination's minimum
165and maximum and a value past each, NaN, both infinities, both-sign fractions and -0), each writing all
166eight bytes of the converted value so a wrong upper byte is seen, plus `seed/omc/tests/float/convert_sat.om`;
167`runs/fconv-bad-bool.om` (float to bool) must be refused as omc refuses it. The input bounds are derived in
168`float-bounds.txt` (Wolfram). `cases-fconv.txt` puts the same units through gate-front's check parity.
169
170## Mixed-type shifts and fma
171
172omc admits `shl`/`shr` with an integer value and an integer amount of another type (only a shift may mix
173its operand types) and compares the amount's 64-bit register, sign- or zero-extended by its type, unsigned
174with the value's width (`bo_schk`, trap 7): a negative amount traps like a wide one, and none is wrapped.
175`fe_lsham` lowers the amount to `conv` u64, `lt` the width, `chk.true 7` and `conv` to the value's type,
176exact because the amount is then below the width; `fe_lbop`'s checks follow unchanged. `fma a b c` lowers
177to ΩIR `fma` (46, one rounding) on three values of one float type. Run cases `cases/sh_mix*.om` and
178`cases/fma_mix.om`; their exits and stdout bytes, worked out before the run (constants from Wolfram), are in
179`cases/groups4.expect`. omc's refusals `rot_mix` (a rotate keeps one type, 7), `fma_lit` (11) and
180`fma_types` (7) are refuse cases. A bool or float shift amount, which omc also admits, stays not lowered; the scope
181gate keeps it failing closed, and its bool-amount admission mutant must be KILLED:
182
183 gate-front seed/out/omc "$(cut -d' ' -f1 seed/out/omc.sha256)" \
184 units:seed/ng/ng.units+in:seed/ng/front/front-ir.in \
185 seed/ng/front/declared-lower-scope.txt seed/ng/front/mutants-lower-scope.txt SCRATCH \
186 seed/ng/front/cases-lower-scope.txt
187
188## fmin and fmax
189
190`fmin a b` and `fmax a b` lower to ΩIR `min` (24) and `max` (25) on two values of one float type (`fe_lfmm`);
191IR.md s7.3 gives them OMEGESE's FMINNM/FMAXNM meaning: one quiet NaN gives the other operand, a signaling
192NaN gives that NaN quieted, two quiet NaNs give the first, and -0 is below +0. Run case `cases/fmm_mix.om`
193writes the bits of 28 results (f32 and f64: ordered values, signed zeros in both orders, quiet and signaling
194NaNs with a number in both orders, two quiet NaNs); its 168 bytes, worked out before the run, are in
195`cases/groups6.expect`. `lsc_fmin` and `lsc_fmax`, the former lower-scope cases, are run cases now. The
196min/max swap mutant (8) must fail a run case.
197
198## qty
199
200`qty` (omc type 13) lowers as ΩIR u64. Its `add`, `sub` and `mul` carry `chk.add`/`chk.sub`/`chk.mul` code 1,
201which fail on any unsigned wrap (IR.md s7.9), as omc traps 1; `div` and `rem` keep `chk.divz` (trap 2);
202compares are unsigned. `qty V` (`fe_lqty`): a literal is a qty constant, a signed value gets `chk.conv` u64
203(trap 5 when negative), an unsigned one converts; `ulong q` and `qty u` with a ulong keep the u64 value (no op,
204as omc); narrowing a qty to a smaller or signed type gets `chk.conv` (trap 5). A qty is a valid index and a valid
205shift amount (u64, as a ulong amount: `cases/qty_shamt.om`). Cases:
206every unit of `tests/quantity` (38 run, 39 refuse) in `cases-front-ir.txt` and `cases-quantity.txt` for
207gate-front; mutant 9 (the checks dropped) must fail a run case.
208
209## Data edges
210
211Every array parameter, sized or unsized, is an ΩIR SLICE of its declared access (0 view, 1 edit); the caller
212passes the name's slice or a `slice` over the whole array, so a text (access 0) reaches a sized `view`
213parameter (fe_check has already matched a sized parameter's length, error 7, and refused a text to `edit`,
214error 20). OM-2 `fresh` after an edit parameter is a check-pass rule (error 27) and lowers to nothing. An
215empty text gets one zero byte of ΩIR storage and its name is the empty slice after `chk.slice (0, 0)`, so
216`len` is 0 and a `get` traps 3 as omc's. `const NAME bool 0|1` is a bool constant. Cases (programs by
217NgFrontFull): `runs/data-bool.om`, `data-empty.om`, `data-empty-bounds.om` (trap 3), `data-view.om`, and
218omc's refusals `runs/bad-data-*.om` (8, 27, 7, 20), also in `cases-data.txt` for gate-front.
219
220## Host words
221
222Every host word of `seed/ng/hostwords.tsv` (99, the words omc's keyword table admits as host operations at
223the pin) lowers to ΩIR `host` (op 110, IR.md s7.11) with the word's keyword id as imm and ty i64; `cpufence`
224and `cpurelax` are statements with ty 0. read, write, monons and realns keep their earlier paths; `fe_lhost`
225takes the other 93 from the table's argument letters (`fe_lhfmt`, generated from the table): `i` int, `l`
226long, `L` ulong, `u` a uint constant (omc requires a literal), and `r`, `w`, `S` a byte array name followed by
227off and n (ulong), with `chk.slice` on the three where omc checks the slice, before the next argument is read.
228mapaddr and mapget are ulong in omc: their i64 result is `conv`ed with the same bits. The check pass gained
229execenv (233) and prlimit (235), which the pinned omc admits: execenv goes through `fe_hpack` with omc.om
230hpack's second packet (the environment), its two pre-stack trap sites and one record scan per packet;
231prlimit through `fe_hprlim` (int pid, int resource, writable byte slice; no trap site of its own).
232The scheduler words of omc f4fa7951 (Radicle main c106bae0) follow omc.om: `cpuset` 236 and `cpuget` 237
233through `fe_hsched` (int pid, then a byte slice, writable for cpuget; text is error 20), `cpunow` 238
234through `fe_hsched` (no operand; the stack-floor check before its 16-byte slot), and `setprio` 239 (three
235int) and `getprio` 240 (two int) through `fe_hscalar`. All five are program-only (function mode error 9).
236
237Cases: `cases-host.txt` (the 99 programs `runs/host-WORD.om`, seven refusals `runs/bad-host-*.om` and two
238`om2 diag` units `runs/diag-host-*.om`) in gate-front's check parity; in `cases-front-ir.txt` one
239`host NAME SRC C` row per word and the seven refusals as `refuse` rows. A `host` row compiles and runs the
240unit with omc (empty stdin, the repository root as working directory: the programs name only empty or
241`/dev/null` paths and invalid descriptors; none opens a device), lowers it, requires ngcheck ACCEPT and runs
242the ΩIR with `ngrun --scratch SCRATCH/hK` (a new directory each run). C 0: exit and stdout equal the
243binary's. C 115..123: ngrun refuses the word by that class (IR.md s7.11: process, limits, device, network,
244outside scratch, nondeterministic, unsafe filesystem) with exit C and no stdout, so that program's ΩIR is
245checked but not executed: behavior parity for it stays NOT_RUN. The C column follows IR.md's table and
246trap-first rules (empty paths are not one path component: 119; malformed packets and empty stat paths
247trap 3 natively and in ngrun: 0; a negative descriptor gets -9 without a kernel call in both: 0).
248
249## Executable contracts
250
251The check pass still validates every clause. Lowering consumes the validated function and loop
252prefixes. `requires` is a `chk.true` with trap 9 at entry; `ensures` is trap 10 at every normal
253explicit or implicit return. The return expression is evaluated once. Postconditions see the
254current values of names visible at entry, and `result` only while checking a value return.
255
256Loop invariants run at the loop head before its condition, including zero trips and the final
257false condition. Continue returns to that head (through the increment for a `for`); break,
258exit and trap do not add contract checks. Release mode consumes predicates without evaluating
259them. Diagnostic mode preserves the check pass's diagnostic stream. A contract clause outside
260these supported prefix paths still encounters the central not-lowered guard.
261
262The front IR gate imports runtime, refusal and diagnostic fixture sources directly from
263`seed/omc/contracts/contracts.cases`, so there is no separate fixture inventory to maintain.
264Three enforcement mutants remove function checks, postconditions, and loop invariants.
265The native and interpreter differential also covers side effects before a failing check.
266Function-mode units remain outside this program-entry lowering. Constant-true predicates are
267semantically preserved; matching omc's proof-erased output bytes is not claimed.
268
269Implementation: OpenAI Codex, assigned NG completion lane.
270
271## Nominal, struct and layout gate rows
272
273The `nom-*` rows of `cases-front-ir.txt` (31 run, 54 refuse) exercise the nominal, struct and layout lowering of
274`src/front.om`: the 76-case data sweep in its same classes, wrapped copies of the struct units whose `main` does
275not return int (`cases/nom_tN.om`, `sh cases/nom-wrap.sh check` verifies them against `seed/omc/tests/struct`),
276and boundary and evaluation-order controls `cases/nom_*.om` whose exits and stdout are those of the omc binary.
277Mutants 14 to 18 of `gate-front-ir.om` change struct field indexing, the array bound, layout byte order and the
278dup32 retained check; each pattern occurs once in `src/front.om`, so a rewrite of those lines makes the gate
279report the pattern missing, loudly. `COVERAGE.md` lists what was run and the limits.
280
281## Run-time pools
282
283`global NAME T *` uses a class 2 global with a scalar element type. `len`, `get`, `put`,
284`read`, `write` and assignment-form `enlarge` lower to ops 111..116; [IR.md](../IR.md)
285defines their types, tokens, bounds and storage contract. A store evaluates index, then value,
286then resolves and checks the current descriptor. Pool storage never becomes a REF or SLICE.
287
288The canonical pool fixtures and `pool-widths-order.om` exercise source execution against omc;
289`pool-fd-policy.om` retains the interpreter's host restrictions. The old scope rows for
290`pool_runtime.om` and `seed/omc/omc.om` are removed. Existing target and IR v1 exclusions remain.
291The full front check, lowering, IR and native gates are required for release; their receipts carry
292the actual results. Linux AArch64 and the interpreter support pools; Mach-O pool ops remain unsupported.