interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / docs / CAPABILITIES.md

369 lines · 28121 bytes Raw Blame History Source

Bridge v0 capability contract

Input is the pinned seed's Omega program/function language, further bounded below. The shell entry point snapshots the source, asks the pinned Omega compiler to check the entire unit, then sends the same bytes to the Omega target compiler. Both targets consume the same typed nodes. The private build/bridge executable is an internal emitter, not a standalone validation API. Use tools/bridge.

FeatureC outputPython output
bool; unsigned/signed 8, 16, 32, 64-bit scalarssupportedsupported using canonical 64-bit bits
explicit checked numeric conversionssupportedsupported
unsigned arithmeticwraps at declared widthsame
signed add/sub/mul/neg/shl overflowtrap 1same
div/remtruncation toward zero, zero divisor trap 2; min/-1 division trap 1; remainder zerosame
shiftsarithmetic signed right shift; invalid amount trap 7same
eager left-to-right operands/call argumentssequenced GNU statement expressionsPython argument order
if/else, bounded while, forsupportedsupported
forward/mutual calls and recursion in programssupported within resource budgetsame
new arrays, global pools, view/edit parameters, get/put/lenchecked; actual element widths; readonly views are const void *bytearray for uchar (immutable bytes also accepted for a readonly uchar view), list for other widths
read/write/exit in programsPOSIX, negative errno returned in long bitsos read/write, same errno mapping
callable function units without maingenerated checked C ABI wrappersgenerated checked module functions
text constants (text NAME "..."), baseline tools/bridge onlyexact decoded bytes as static const uint8_t plus a separate length; get/len/write and readonly view argumentsimmutable bytes; same
inline text literals in expressionsrefused by the seed, error 16same
floating point, heap, free, own, reflection, concurrency, GPU, external callsrefused by seed or bridgesame
arbitrary C/Python inputno frontendno frontend

Capacity limits: input including the target selector is below 1,048,576 bytes, output at most 4,194,304 bytes, 32 functions, four parameters per function (arrays expand to address/length), eight globals (texts and global arrays share this table), 32,768 decoded text bytes per unit, 32 live locals, 32 block levels including the function, 1,024 expression nodes per statement, eight-character names. Global arrays have at most 524,288 elements. Local arrays total at most 32,768 bytes per function. Capacity exhaustion is a compile refusal (14, 23 or 24), never a partial generated file. The seed has further checked register and grammar limits.

Text (docs/TEXT-CONVERSION.md): the bridge decodes exactly the seed's four escapes (\n, \t, \\, \") and keeps every other byte inside the quotes, including raw NUL, CR, tab and bytes 128-255; empty text has length zero and no terminator. Output contains only decimal byte initializers, never source bytes. Writes, reads and edit arguments into a text are refused by the seed (error 20) and again by the bridge. Note bodies are skipped untokenized outside cabi library modes, so note bytes the seed ignores no longer cause a bridge error 16. The seeded frontends (tools/bridge-seeded) still refuse text.

Resource boundary: generated execution has a 128-active-call limit, reported as trap 6. Native Omega instead checks its eight-MiB machine stack. Their exhaustion thresholds differ. Only executions within the bridge budget are claimed equivalent; t_stack verifies the eventual trap code only. C hosts must provide an eight-MiB stack. Resource consumption, allocation failure and OS signal/restart behavior are not cross-runtime equivalence claims. Python uses its host heap for fixed-size arrays and interpreter state; the Omega source language has no heap operations. This is not a no-allocation Python runtime.

For loops evaluate a compound count once; a variable count is read each iteration. Variable-count for loops and while loops have a default one-million-iteration guard. Explicit while bounds retain the seed's allowed range. Arrays are never returned, transferred or stored as references. View writes, shape mismatches and overlapping array arguments inside Omega are refused by the shared frontend. Runtime bounds are always enabled.

Full-program results are compared byte-for-byte on stdout/stderr and process status. Trap exits are 100 + code; explicit exit and main return use the low eight bits. I/O tests use ordinary pipes/files with no asynchronous signals. Neither backend optimizes away checks.

Other conversion targets need a real emitter, capability checks, reference executor, differential corpus and an attachment gate; no language other than C and Python has a converter. Calling a compiled Omega function in place from C, C++, Python, Rust, Zig or Go is the native call adapter (docs/NATIVE-ABI.md): tools/native builds the library and writes each language's declarations from the Omega signatures. That is a call into Omega's machine code, a separate claim from conversion. JavaScript, Java, C#, Fortran and other languages have no implemented or tested adapter here.

The seed's optional grouped-expression syntax and explicit view A argument prefix are not lowered by this bridge; use ordinary prefix expressions and view-typed parameters. Source constructs beyond the table may be accepted by the seed and then refused by the target compiler. Error 24 includes an unsupported-capability diagnostic; errors 13/14/23 identify name, table/output or storage limits. No target output is published on these failures.

Additive seeded frontend

tools/bridge-seeded c|python|h SOURCE.om is an explicit frontend mode for omega-mv e5b32567, requiring OMEGA_SEEDED_OMC with sha256 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f. The source snapshot is checked by that exact compiler before conversion. A different compiler fingerprint refuses with status 65 and no target output. This mode keeps tools/bridge's baseline seed 191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9 and the required tools/test.sh suite, but the shared src/toc.om emitter changes baseline tools/bridge c|python output text: exported scalar parameters of narrowing functions become volatile, the o_get/o_io/o_buf helpers take const void *, and unused loop counters are no longer emitted. The behavior suites (tools/test.sh, seeded, seeded-float, freestanding) are unchanged and pass; byte-identical output to the previous tools/bridge is not claimed.

The additive mode accepts at most 1024 numeric constants (integer, f32 or f64; error 14 beyond), 512 functions, six parameters per function, function names up to the frontend's 63-byte limit (other names retain its limits), fixed view/edit shapes up to 16,777,216 elements, explicit view/edit call prefixes and bounded-loop break. Seeded C also supports continue within a checked enclosing loop. Default variable-loop and while guards match omc's 1,000,000-pass trap 4. Source and emission storage are bounded at 1 MiB and 4 MiB; seeded local array storage is bounded at 16 MiB, while the baseline local-storage refusal remains 32 KiB. Checked arithmetic, bounds, alias refusals, call budget and no-heap restrictions remain enforced. Text constants (refused, error 24) and external calls remain unsupported in this mode. These are implementation bounds, not performance measurements.

Seeded C permits binary32 (f32) and binary64 (f64) scalars, including typed public parameters/results: float constants (const K f64 0.1; a suffixed literal is error 16 and an integer literal error 16, as in omc), typed or suffixed float literals in expressions, add/sub/mul/div, neg, fabs, fsqrt, ordered comparisons and eq/ne, int<->float and f32<->f64 conversions (an integer literal under a float conversion is typed long, as in omc), and same-width bitcasts between f32 and uint and between f64 and ulong/long. Operations go through o_fp/o_fcv with explicit ARM (AArch64) NaN propagation and FCVTZS/FCVTZU saturation, so results match the seeded omc's AArch64 bits. Decimal conversion reuses the pinned Omega e5b32567 implementation, including its limits: at most 2^63-1 significant digits (error 8) and overflow to infinity refused (error 8). That conversion is not always correctly rounded (aien-dev/omega-mv#1024); the converter reproduces omc's bits, and tests/seeded_float.py pins the two known misrounded literals. Storage is canonical IEEE-754 bits. Fast-math and incompatible binary32/binary64 implementations are refused at C compilation. The fsqrt compatibility lowering uses the host's AArch64 FSQRT or x86-64 SSE scalar square-root instruction and normalizes NaN propagation to AArch64; it adds no libm dependency. Other host architectures are refused at C compilation. Where omc refuses a float program the converter reports omc's error code. Accepted but unlowered features (f64 arrays, float shift counts, untyped float literals as a left operand, int/long-with-f32 bitcasts) are refused with error 24, as are all Python and baseline float inputs. No approximate integer substitute is emitted.

Seeded C views/edit arrays additionally admit ushort, uint and f32. Local and global f32 arrays use fixed-width uint32_t raw IEEE bits; unsigned arrays use uint16_t and uint32_t. Loads/stores use alias-safe fixed-width builtin copies on the required little-endian host, retaining NaN payloads and signed zero without per-element byte loops. Unsigned operators still wrap at the declared width. Public arrays remain borrowed void */const void * plus an exact element count. Alignment, wrap, result overlap and mutable-view alias checks use the declared element size (2, 4 or 8 bytes), not the old uchar/ulong-only assumption. Public scalar f32/f64 parameters and result pointers are C float/double; integer scalars retain canonical uint64_t bits. Only success writes the result. Global arrays are standalone-program features: the pinned compiler refuses its global pool in function mode with error 9, before the converter emits anything. tests/seeded_views.py executes the pinned omc and emitted C on exhaustive u16 values, edge cases and 2^20 deterministic random u32/f32 patterns (host and qemu-x86_64), and checks out-of-range refusals, runtime boundary errors and per-feature killed mutants. The same test checks GCC -O2 AArch64 assembly for one scalar 16/32/64-bit load/store at constant-width calls and kills a restored-byte-loop mutant. The checked borrowed-view profile of bridge-freest shares this typed C lowering and ABI, but uses an import-free explicit status context instead of hosted traps.

Function units export only their final function, using omega_NAME. h validates every function body through the same emitter before emitting the C declaration from checked signature metadata. Exported scalar value parameters are volatile inside the checked setjmp wrapper; the public ABI is unchanged. The result pointer comes first; integer scalars use canonical uint64_t bits; arrays use address and element-count pairs. Counts must equal the declared fixed shape. ABI statuses are 0 for completion, 1 through 14 for Omega traps, 32 for invalid host arguments or overlapping arrays, and 33 for reentry. Views are not written by Omega and use const-qualified C pointers. Generated C contains the implementation and checked runtime, not a call into AArch64 machine code, and can be compiled on Linux x86-64 with GNU C. Native call adapters remain a separate AArch64 path. Literal-count loops do not emit an unused runtime guard counter. Seeded C marks source scalar declarations as possibly unused, preserving evaluation of their initializers, including calls with side effects. This is declaration metadata, not a repository warning-flag change. The seeded strict-host test compiles with -Wall -Wextra -Werror and includes an annotation-removal mutant.

Qualification is separate from implementation. Run the unchanged baseline tools/test.sh first, then python3 tests/seeded.py with both pinned compilers configured. The latter compares native Omega, generated C and Python, executes generated x86-64 machine code through qemu-x86_64, checks the header ABI, and includes wrong-seed and arithmetic-emitter negative controls. No device qualification is implied.

python3 tests/seeded_float.py compares the seeded executable and generated C byte-for-byte (host and x86-64 under qemu) over zero, subnormal, normal, overflow, infinity and NaN inputs for f32 and f64, 132 constants against an exact round-to-nearest-even oracle (one-ulp mutant detected), and converter refusal codes cross-checked against omc. It includes baseline/Python, f64-array, numeric-cast, unsupported-op, header-validation and fast-math refusal controls. These are host/emulator results only.

Explicit runtime-extent hosted views

tools/bridge-seeded --runtime-views c|h unit.om keeps the e5b32567 source validator and explicitly changes only the hosted view boundary policy. Numeric view/edit lengths are capacities: callers pass 0 <= n <= CAP, and len, get, put and helper-call counts use the actual n. The default profile still requires exact declared counts; it is not a runtime-view alias.

The runtime profile also lowers the pinned compiler's bare om2 header and unsized view T * / edit T * parameters, without the numeric capacity ceiling. Only this narrow OM2 subset is added: layouts, part, exports, contracts and om2 diag/om2 fmt are not lowered. Unsupported constructs refuse without output. Six source parameters remain the maximum. The seed counts each numeric view as one machine slot and each unsized view as two; at most six native slots are available. Thus five bounded views are supported, but five unsized views are not. Numeric declarations still obey the seed's fixed-capacity limit.

Kinds are uchar, ushort (halfword), uint, ulong and f32. Every nonempty view must be nonnull, naturally aligned and have a nonwrapping byte range. Empty views may have null or misaligned addresses and have no overlap range. Writable/view and writable/writable overlaps refuse; readonly aliases and adjacent disjoint actual ranges are accepted. Result storage remains nonnull, aligned and disjoint. Admission errors return 32; access outside the live count is trap 3. Writes completed before a trap are not rolled back. Generated headers and C identify the runtime profile. Count arguments in the checked wrapper are volatile for setjmp correctness, without changing the C calling ABI. Compile floating operations with -ffp-contract=off. The existing iteration/call guards are unchanged: accepting a large extent does not promise traversal beyond those guards.

tests/seeded_runtime_views.py compares the generated C against independent checked reference semantics on the host and under x86 QEMU, across empty, one-element, capacity and maximum-address envelopes. It kills removed read/ write bounds, declared-range overlap, null-check, byte-size overflow and byte-loop code-generation mutants. It also covers fixed-profile exact counts, helper count forwarding, readonly aliases and five-bounded-view signatures. See the appended hosted runtime-view ABI in docs/NATIVE-ABI.md.

Explicit draft-1049 float profile (not a default pin refresh)

OMEGA_SEEDED_NEXT_OMC=/path/to/candidate tools/bridge-seeded --float-next c|h unit.om selects omega-mv draft #1049 at 7e93ca8e29b3fe81314a88c9f1cb70666fca27f5, candidate compiler sha256 d89bdc08ca21ea9726f1117adc791f683287d3698ea112a9db5519df2e79aeec. Source sha256 is 0a0f4bbc361e555de223d93e774ed5c8d96da401ab574983897ecc82539e0549. It adds fma a b c with equal explicit f32/f64 operands and one hardware FMADD rounding, plus #1024's exact decimal-to-binary rounding. The compatibility emitter preserves left-to-right operand evaluation and copies the candidate compiler's bounded integer limb conversion into its separately selected literal path. The new FMA profile is AArch64-only, as is this compiler keyword; other C architectures refuse at compilation rather than silently emitting mul+add. The default e5 profile retains its exact historical literal bits and rejects the candidate compiler digest. No baseline/native compiler pin is replaced. tests/seeded_next.py compares edge triples and 2^20 random triples per float width against the candidate machine code, kills FMA and literal mutants, and checks all 512 literal/oracle rows copied from that exact compiler revision (including both filed #1024 counterexamples). The fixture's Wolfram provenance and compiler-side fixpoint, seed/host gate and exact-oracle mutants are recorded in omega-mv #1049. Neither PR is merged or deployed.

C ABI library mode (cabi-1, omega-bridge#83)

OMEGA_SEEDED_OMC=/path/to/e5b32567/omc tools/bridge-seeded lib-c|lib-h|lib-map unit.om lowers one seeded Omega unit into a C shared library: lib-c emits the library C (the unit's functions, the runtime and one exported wrapper per declared symbol), lib-h the public header and lib-map the GNU ld version script (declared exports global, everything else local). Library modes use the frozen e5 profile only; --float-next and --runtime-views with a library mode exit 24. The pinned seed compiler checks the whole unit first, as in the other modes.

The C surface is declared in note cabi ... lines, so the unit stays plain seeded Omega. Directives (fixture: tests/cabi/fixture.om; production user: CUDApp native/nvml/api.om):

Each export calls FN fr edit ulong N ... with a frame: slot 0 the status, slot 1 the commit mask, one slot per argument (pointer arguments carry their non-null flag; length/count outputs add a slot). The wrapper takes the lock, runs the Omega function, and publishes nothing unless the call returned without a trap, the status is a declared value, the commit mask names only declared outputs and every committed output is in bounds: a record array must fit the caller's count, a string output must fit the caller's length and end in its NUL, a data copy must lie inside its state. Any violation returns the declared trap status (NVML_ERROR_UNKNOWN, 999, in the fixture) with no output written. A cstr result always points into its stable storage or at the fallback text.

Refusals, all with nothing on stdout: 40 malformed lock kind, 41 duplicate export symbol, 42 unknown lock/state/function/alias target, 43 wrong nullability, 44 bad record offset or size, 45 bind to state of the wrong extent or a record array without a count, 46 raw pointer result or argument, 47 out span without length, 48 non-stable or out-of-storage string, 49 import stub with a body, 50 main in a library unit, 51 Omega global, 52 provenance mismatch.

Provenance: every artifact's first line names the SHA-256 of src/toc.om and of the source. tools/bridge-seeded appends both digests as a trailer and opens src/toc.om on descriptor 3; build/bridge recomputes both with its own SHA-256 (in Omega) and refuses any mismatch, a missing trailer or a withheld descriptor 3 with error 52.

Gate (seeded Omega; cc, nm, readelf, sha256sum and tests/cabi/caller.c are test-only ORACLE tools and never shipped), from the checkout root after tools/build.sh:

cat tests/cabi/proc.om tests/cabi/gate.om | "$OMEGA_SEEDED_OMC" > build/cabi-gate
chmod +x build/cabi-gate
OMEGA_SEEDED_OMC=/path/to/omc build/cabi-gate

It checks deterministic generation and golden bytes, exactly 8 exports and the soname, a 57-check caller (null and out-parameters, handles, forged handles, stable strings, 8 threads x 2000 calls with no lost update), cc refusing an import declaration that disagrees with the external header, 18 refusal cases (errors 40-50), eight direct build/bridge provenance cases, and four mutants the caller must catch (null-out commit, publication, lock removal and a ulong import span moved from element 3 to element 2). It prints OMEGA-BRIDGE CABI GATE PASS, exits 77 when unconfigured and 1 on any failure. Evidence: evidence/cabi-1/.

Portable import-free scalar and checked borrowed-view profiles

tools/bridge-freest c|h SOURCE.om selects one of two fail-closed import-free profiles before body conversion. Borrowed-view signatures select the checked profile in src/toc.om; units without borrowed signatures select the original scalar parser/emitter in src/freest.om. A view-bearing unit never retries the scalar profile after a refusal. This does not replace the hosted tools/bridge-seeded c|python|h roots or change their ABI. The shell entrypoint only snapshots, checks compiler fingerprints, validates with the seeded frontend, compiles the Omega converter and publishes its output after success. It implements no source parser.

Use the same OMEGA_SEED baseline fingerprint and OMEGA_SEEDED_OMC frontend fingerprint documented above. The wrapper validates and converts the identical snapshot. No native x86 Omega compiler is required: portable C is compiled by the consumer's C compiler. Both c and h traverse the complete source before publishing bytes, including every unused helper. Headers cannot bypass profile refusal. The input bounds and scalar type/name limits remain those of the seeded frontend and converter tables.

The original scalar subset remains integer-only, stateless and nontrapping: scalar signatures, literal constants, scalar locals, if/else, ret, and acyclic function calls. Unsigned non-bool addition, subtraction, multiplication and negation wrap at the declared width. Integer comparisons and bitwise operations are supported, as are identity and same-signedness widening conversions (including bool to a wider unsigned type). Signed arithmetic, division, remainder, every shift, narrowing and signedness-changing conversions are refused conservatively, even when a particular constant or path could be safe. Loops, arrays, mutable globals, text, I/O, host words, main, recursion, floats, explicit traps, contracts and OM-2 are outside this profile. Refusal applies to the complete unit, not merely the exported root or reachable helpers. No function-name whitelist is used. Spell scalar types as bool, uchar, ushort, uint, ulong, byte, short, int or long; short type aliases are outside this profile.

The final function is exported as uint32_t omega_NAME(uint64_t *result, ...). The result pointer is first. Arguments and results use canonical uint64_t integer bits, including sign extension for signed values. Status 0 stores the result; status 32 refuses null, misaligned or wrapping result addresses and noncanonical scalar arguments before any store. As with other native pointer ABIs, callers remain responsible for supplying valid writable storage; the profile does not probe mapped-memory permissions. There are no runtime traps, reentry state, TLS, setjmp/longjmp, libc calls or host imports in generated code. The output includes only the standard integer type header and pure local helpers; it is not a call into AArch64 machine code.

The checked borrowed-view subset accepts the hosted view element kinds (uchar, ushort, uint, ulong, f32). Units without an om2 header retain the default hosted exact-count contract: a declared extent of 32 requires a caller count of 32, not 31. A seed-validated om2 header explicitly selects the runtime-view contract, where numeric extents are capacities and * is unsized. This selection applies to both C and header output and needs no command-line flag. The subset includes local arrays, checked arithmetic/conversions, floats, bounded loops and internal calls accepted by the seeded C converter. It retains the hosted result-first ABI, scalar canonical bits/float types, capacity/count, NULL/zero, alignment, address-overflow and alias checks. It does not add globals, text, host words, I/O, main, part, ownership/out arrays or unsupported converter capabilities. The whole unit is checked in both c and h modes. Each exported call uses a stack-local status/depth context threaded through private functions: bounds and arithmetic refusals return the same statuses 1–7; foreign-argument refusal is 32. Result storage changes only on success; earlier buffer writes remain visible after refusal. Internal calls and primitive checks unwind before later expressions or writes. There is no TLS, global reentry state, libc/POSIX call, abort, printf, setjmp/longjmp or int128 helper. The allowed undefined-symbol set is empty. Generated C is byte-stable and targets GNU C11 on the same little-endian AArch64/x86 floating environment as the hosted seeded converter; the caller enables FP and supplies valid storage. Host/compiler/header dependencies are unchanged verification/conversion tools, not runtime imports into the generated object.

tests/freest_views.py copies the CUDApp attention-set/fill, fixed launch-record and runtime-copy source shapes. It compares hosted and freestanding output on deterministic randomized and boundary inputs, checks partial-write/refusal behavior, exact-count and capacity/unsized views, pointer/result aliases and unchanged storage on admission refusal. It compiles O0/O2 objects with an empty nm -u set and no TLS, and kills seven mutations in the new Omega emitter path, including removal of the fixed-extent check. It also checks a seeded-valid unsupported part unit refuses without output. Run on the host after tools/build.sh with OMEGA_SEED and OMEGA_SEEDED_OMC configured; ctypes is test infrastructure, not an emitted-code dependency.

For independent integration, dispatch a future bridge-seeded freest|freest-h mode directly to tools/bridge-freest c|h before its hosted-mode case. Keep the hosted roots unchanged. tests/freest.py exercises both hosted and freest revision/epoch roots, the result-first ABI and exhausted-generation boundaries, arbitrary helpers, structural refusal controls and a wrong-result control. It inspects O0/O2 freestanding objects and a -r -nostdlib link with nm -u (requiring an empty set, not an import allowlist) and readelf (no TLS sections). Run it after tools/build.sh with both pinned compilers configured. Set FREEST_CUDAPP_ROOT to use a consumer checkout's actual revision/epoch sources instead of the checked-in source-shape fixtures. For x86-64 execution from an AArch64 host, set CC=x86_64-linux-gnu-gcc and FREEST_RUNNER='qemu-x86_64 -L /usr/x86_64-linux-gnu'. The default hosted optimization is O2; HOSTED_OPT selects an explicit comparison build and is printed in the result. These are targeted host checks, not device qualification.