omega-bridge
Omega-first language interoperability: checked conversion backends and native language bindings
Brought by drakestapleton
GitHub aien-dev/omega-bridge#58 (code only)
Apply it
git checkout -b patch-31c25f89b26cc031 7af4d11c3a9c853abc20a99f97d0a4f01524bb66 curl -fsSL https://interplane.io/drakestapleton/omega-bridge/patches/31c25f89b26cc031.patch | git am
Provenance
github-import 1
aien-dev/omega-bridge
58
f6caea54509649ea7398fb78ead0489c6d3df225
{"kind":"github-import","owner":"aien-dev","repo":"omega-bridge","number":58,"url":"https://github.com/aien-dev/omega-bridge/pull/58","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:40:01Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/README.md b/README.md index 4c667cb..5240540 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,12 @@ Ownership rule ([ARCH-0042](https://github.com/aien-dev/aien-architecture-mv/pul The source-only bootstrap of the pinned Omega compiler currently requires Linux AArch64. Generated C uses GNU C11 and POSIX; generated Python uses Python 3. This branch has local differential tests and caller demos; independent review remains required before release. No universal conversion or performance improvement is claimed. +## How it works / How we built it + +`tools/bridge c|python file.om` checks two hashes: the converter against its source and the seed compiler against pin `191b776e…`. It then takes one snapshot of the input. The pinned Omega seed compiler checks the whole unit, and `build/bridge` (compiled from `src/toc.om`) parses that snapshot into typed expression nodes. Separate writers emit C or Python from those nodes. The generated program prints the same output, exits with the same status and traps with the same code as native Omega. A feature outside the subset is refused with its error code and nothing on stdout. Conversion never installs anything, so rollback means you stop importing the file. + +`src/toc.om` was recovered from uncommitted omega source on base `29b12760`. Run unchanged, its emitter failed 8 of 20 inherited cases: traps turned into exit 0 or a segfault ([evidence/01-recovered-red.log](evidence/01-recovered-red.log)). It was replaced by checked typed nodes. Limits: scalar subset only (no text, floats or heap), and the bootstrap proves a fixpoint, not DDC. The [walkthrough](docs/WALKTHROUGH.md) has the full story, a source map, and an offline recipe with a positive case, a refusal case (exit 24) and a tampered-pin control (exit 65). + Build from exact pinned source: ```sh diff --git a/docs/WALKTHROUGH.md b/docs/WALKTHROUGH.md new file mode 100644 index 0000000..50dc39c --- /dev/null +++ b/docs/WALKTHROUGH.md @@ -0,0 +1,193 @@ +# How Omega Bridge works, and how it was built + +This page is for an engineer who has not seen the project before. It explains the problem, the +mechanism and the design choices, and records one approach that failed. It ends with a recipe you can +run offline from a fresh checkout. Every claim links to the file it comes from. + +Revision described: `main` at `7af4d11c3a9c853abc20a99f97d0a4f01524bb66`. + +## The problem + +Omega programs compile to AArch64 machine code with the seeded Omega compiler, which has no outside +toolchain. That keeps Omega trustworthy, but an existing C or Python application cannot use an Omega +function unless something connects the two. The goal recorded in [DESIGN.md](DESIGN.md#user-goal) is +to let existing languages and tools adopt Omega with as little change as possible, and to say exactly +what is supported instead of claiming that any language translates perfectly. + +## The mechanism + +There are two separate routes. Do not confuse them. + +1. **Conversion** ([src/toc.om](../src/toc.om)). A bounded subset of Omega is turned into GNU C11 or + Python 3 source. The generated program prints the same output, exits with the same status and traps + with the same code as the natively compiled Omega program. +2. **Native call bindings** ([src/native.om](../src/native.om), [NATIVE-ABI.md](NATIVE-ABI.md)). These + leave the program as Omega machine code in a shared library and generate the header or module that + C, C++, Python, Rust, Zig or Go needs to call it. Nothing is translated. + +This walkthrough covers route 1. A conversion request goes through [tools/bridge](../tools/bridge) in +this order: + +1. Check `build/compiler.sha256`, so the converter binary matches its source. A mismatch exits 65. +2. Check that the seed compiler's SHA-256 is + `191b776ef98821597c3e30655da6d680a9b66edbc9ceaca3c39c61ea6df098e9`. A mismatch exits 65. +3. Copy the input once into a private temporary directory. Validation and generation both read that + copy, so a file changed during the request cannot pass one step and fail the other. +4. Compile the copy with the seed compiler as a whole-unit semantic check. If the seed rejects the + program, nothing is emitted. +5. Feed the copy to `build/bridge`, the converter compiled from `src/toc.om`. Its front end (lexer, + name tables, two-pass signature scan; `tok`, `namescan` and `walk_sig` in `src/toc.om`) builds + bounded typed expression nodes (`node`, `expr`, `callnode`). Separate writers then emit C or Python + from those nodes (`eexpr`, `eassign`, `efor`, `generate`). This is code generation from parsed nodes, + not text substitution ([DESIGN.md, "Implemented architecture"](DESIGN.md#implemented-architecture-and-study-reconciliation-l483)). +6. Write the output to stdout only after the whole conversion succeeds. A refused feature exits with the + compiler's error code and leaves stdout empty. + +The generated code keeps Omega's observable rules: fixed-width arithmetic, arrays that carry their +length, checked bounds, and defined traps. Python is made to wrap at fixed widths instead of using its +unbounded integers. The full list of supported features and their limits is in +[CAPABILITIES.md](CAPABILITIES.md). The calling convention for host programs is in [ABI.md](ABI.md): +every exported function returns a status code and writes its result through a pointer. + +## How it was built + +- **Recovered source, not a new compiler.** `src/toc.om` began as uncommitted Omega source, + `seed/toc/toc.om` on omega base `29b12760f4c962606411d6bf25032aedef063301`. Its original digest is + in [RECOVERY.json](RECOVERY.json), and its licence was kept ([PROVENANCE.md](PROVENANCE.md)). The + lexer, tables and signature scan were kept and extended. The typed nodes and target writers replaced + its unchecked emission (commits `614f4ba`, `e24141f` and `7714900`, 2026-10-22). +- **The pinned seed is the checker.** The bridge does not have its own judgement of what is valid + Omega. Every input first passes the pinned seed compiler ([tools/bridge](../tools/bridge)). The + native, C and Python runs therefore share one front end. They are independent executions, not + independent front ends ([PROVENANCE.md](PROVENANCE.md)). +- **Exact source dependency.** [tools/bootstrap.sh](../tools/bootstrap.sh) fetches omega at the pinned + commit, rebuilds the seed chain (seed0, hex1, asm2, om4, omc) from source and compares three omc + stages. No compiler binary is stored in this repository. +- **Opt-in only, rollback by not importing.** Conversion writes to stdout and creates temporary files + under `build/`. It never installs or replaces anything ([DESIGN.md, "Adoption and efficiency"](DESIGN.md#adoption-and-efficiency)). + To roll back, stop linking or importing the generated file. +- **Checks have no off switch.** Library wrappers return errors as values. There is no flag that turns + the bounds or alias checks off ([DESIGN.md](DESIGN.md), decisions 29 and 30). + +## A failed approach: the recovered emitter as found + +The first step was to run the recovered converter unchanged against the inherited test corpus. It +failed 8 of 20 cases ([evidence/01-recovered-red.log](../evidence/01-recovered-red.log)): + +```text +FAIL t_conv ('C mismatch', 105, 0, b'', b'', b'') +FAIL t_exit ('conversion', 16, b'toc: line 2: error 16\n') +FAIL t_ovf ('gcc', ... implicit declaration of function 'o_add_s' ...) +FAIL t_stack ('C mismatch', 106, -11, b'', b'', b'') +cases=20 failures=8 RC=1 +``` + +The emitter copied source text through with too few checks. A conversion trap (exit 105) became a C +program that exited 0, and a stack trap (106) became a segmentation fault (-11). That is why the +emitter was replaced by typed nodes with separate writers instead of being patched case by case. A +second red run, [evidence/22-inherited-text-red.log](../evidence/22-inherited-text-red.log), showed +that the inherited `text.om` program was not covered. It is now refused explicitly (see the recipe +below). + +## Limitations + +- The converters accept a bounded scalar subset. Text constants, floats, heap operations and other + target languages are refused ([CAPABILITIES.md](CAPABILITIES.md)). Converting Python or C *into* + Omega is not implemented. +- `tools/bootstrap.sh` proves a fixpoint, not diverse double compilation. Both routes come from related + seed code ([DESIGN.md](DESIGN.md)). +- The source bootstrap needs Linux AArch64. Generated C needs a GNU C11 compiler and POSIX. Generated + Python needs Python 3. +- No speed-up is claimed. Timings are recorded in `evidence/measurements.json` without a speed claim. + +## Reproduce it + +### Offline part (no GPU, no model, no network after the fetch) + +The host used for the run below: Linux 7.0.0-1019-nvidia aarch64, gcc 13.3.0, Python 3. The bootstrap +needs network access once, to fetch the pinned omega commit. To avoid that, point `OMEGA_SOURCE` at an +existing checkout. + +```sh +git clone https://github.com/aien-dev/omega-bridge && cd omega-bridge +sh tools/bootstrap.sh # ends: bootstrap fixpoint RC=0, seed 191b776e... +sh tools/build.sh # writes build/bridge and build/compiler.sha256 +``` + +The fetch URL in `tools/bootstrap.sh` still uses the old name, `https://github.com/aien-spark/omega.git`. +GitHub redirects it to [aien-dev/omega-mv](https://github.com/aien-dev/omega-mv) (checked +2026-11-04 with `gh api repos/aien-spark/omega`). The pinned commit and its hash checks do not depend on +the name. This page leaves the script unchanged, because AGENTS.md asks for review before any change to +the bootstrap supply chain. + +**Positive case.** Convert `tests/fixtures/fib.om` to both targets and compare against the natively +compiled program: + +```sh +build/bootstrap/omc < tests/fixtures/fib.om > build/fib.native && chmod +x build/fib.native +build/fib.native > build/fib.native.out +tools/bridge c tests/fixtures/fib.om > build/fib.c +gcc -std=gnu11 -O2 build/fib.c -o build/fib && build/fib > build/fib.c.out +tools/bridge python tests/fixtures/fib.om > build/fib.py && python3 build/fib.py > build/fib.py.out +sha256sum build/fib.*.out +``` + +Expected: all three exit 0, print the 26 Fibonacci numbers from 0 to 75025, and have the same hash, +`327ac5f5a3f39c7248466ce0c5863fb988abbed4ab983eb2ac039ad86b06fddd`. + +**The same trap in all three.** `tests/fixtures/t_div0.om` divides by zero. Native, C and Python all +exit 102, as `tests/fixtures/t_div0.want` records. + +**A host caller.** `python3 tests/attachments.py` converts `examples/attachment.om`, builds +`examples/caller.c` with UBSan and runs it and `examples/caller.py`: + +```text +C caller: values, mutation, traps, invalid lengths and recovery OK +Python caller: values, mutation, traps, invalid lengths and recovery OK +attachment cases=2 failures=0 RC=0 +``` + +**Refusal case.** `tests/unsupported/text.om` is valid Omega; the native compiler accepts it. It uses +a text constant, which the converter does not support: + +```sh +tools/bridge c tests/unsupported/text.om > build/text.c; echo rc=$?; wc -c < build/text.c +``` + +Expected: `toc: line 2: error 24`, `unsupported bridge capability`, `rc=24`, and `0` bytes of output. + +**Negative control on the pin.** A seed with one extra byte is refused before conversion: + +```sh +cp build/bootstrap/omc /tmp/omc-tampered && printf '\0' >> /tmp/omc-tampered +OMEGA_SEED=/tmp/omc-tampered tools/bridge c tests/fixtures/fib.om; echo rc=$? # rc=65, no output +``` + +**Full suite.** `sh tools/test.sh` ends with `ALL SUITES RC=0`. The suite's lines include +`cases=113 failures=0 RC=0` (differential), `refusal cases=50 failures=0 RC=0`, +`control cases=7 failures=0 RC=0` and +`robustness cases=225 target_accepts=6 target_refusals=444 failures=0 RC=0`. It took 19 s on the host +above. + +### Optional parts (not needed for the recipe above) + +- Native call bindings need `OMEGA_NATIVE_OMC`, the seeded omega-mv compiler; see + [NATIVE-ABI.md](NATIVE-ABI.md). +- The GPU adapter converts no host program. Device runs go through CUDA++ in an authorised hardware + window; see [GPU-ADAPTER.md](GPU-ADAPTER.md) and [GPU-SUPPORT-MATRIX.md](GPU-SUPPORT-MATRIX.md). + +## Source map + +| What | Where | +|---|---| +| Conversion CLI and pin checks | [tools/bridge](../tools/bridge) | +| Converter (front end, typed nodes, C and Python writers) | [src/toc.om](../src/toc.om) | +| Seed bootstrap from pinned source | [tools/bootstrap.sh](../tools/bootstrap.sh) | +| Native, C and Python differential tests | [tests/differential.py](../tests/differential.py) | +| Refusals | [tests/refusals.py](../tests/refusals.py), [tests/unsupported/](../tests/unsupported/) | +| Host callers | [tests/attachments.py](../tests/attachments.py), [examples/caller.c](../examples/caller.c), [examples/caller.py](../examples/caller.py) | +| Damaged-output controls | [tests/controls.py](../tests/controls.py) | +| Design decisions | [DESIGN.md](DESIGN.md) | +| Supported features and limits | [CAPABILITIES.md](CAPABILITIES.md) | +| Caller ABI | [ABI.md](ABI.md) | +| Provenance | [PROVENANCE.md](PROVENANCE.md), [RECOVERY.json](RECOVERY.json) |