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
GitHub aien-dev/omega-mv#771 (code only)
Fetch it
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/9c4c47c9cd320ece.bundle -o 9c4c47c9cd320ece.bundle git fetch 9c4c47c9cd320ece.bundle refs/pull/771/head
Provenance
github-import 1
aien-dev/omega-mv
771
a367b15f432d2095a4911032a44cc586c34439ac
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":771,"url":"https://github.com/aien-dev/omega-mv/pull/771","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:38:32Z","metadata":"unavailable","state_derived":true}
Changes
diff --git a/.crumb b/.crumb index f3e51fe46..44ceaa955 100644 --- a/.crumb +++ b/.crumb @@ -71,8 +71,8 @@ "purpose": "Directory research. Purpose not yet described by a human." }, { - "digest": "f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", - "last_commit": "a8a6a3d3c", + "digest": "b0dbb6b57430fc910c245cac7044f627b5c99a627db610f2bd7fb6f3ea3e7d2c", + "last_commit": "06ecf3a74", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, @@ -84,26 +84,26 @@ }, { "digest": "5395ff8ff9afceebe8e453788f80a3064b831513cc4cb92fd55869115e06b874", - "last_commit": "a8a6a3d3c", + "last_commit": "dcccc0211", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { "digest": "308db0e6cf45c0a48f01f5f5f228450f191389de68006915b9ecf9c65b9a2e29", - "last_commit": "a8a6a3d3c", + "last_commit": "a50c3bd41", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:07bf1706dcffbad66c0353871ff67a6749055da03cee8d8ebdf9a4c91e36bddc", - "compiled_at": "2026-10-30T12:31:50Z", + "children_root": "sha256:79199e5da239896482a9049a014424a7cae34ba6fd445de2bfd4b493cbeb7a5b", + "compiled_at": "2026-10-30T14:45:08Z", "compiler": "crumb-compile/1", - "digest": "sha256:904fca8c0e0cf3e3a5e5adb73393e01c7018b920bb542d289904240f70e400d6", - "evidence_files": 12622, - "evidence_root": "sha256:b1a08e2ce56e6feada0d8a31f06fbd7adee57adc1c1ad8dec220293ee5d439f9", - "files": 17849, - "generated_at_commit": "52a82f392fa513ebbc2d9d719a0f14c385289b06", - "source_tree": "sha256:75458da6553a0ee5ea2af95f46afb658e8a3f6e53cca6e3b4b9874035f78c2ed" + "digest": "sha256:079bd08574a511e28b81bc78f92b2405856be58362fd87119dd528099a95bfb7", + "evidence_files": 12627, + "evidence_root": "sha256:a06d0e5fddb8ad7beffab0da1a2ba9d51eb4ceac2729029fdc83b144eba90559", + "files": 17865, + "generated_at_commit": "06ecf3a74e2eeb75fe5f217b47878e9a5d419f54", + "source_tree": "sha256:edea595d42797eefa1b412b65145074c750c677dd2c9945c3bcfa395d927f68e" }, "owner_lane": "", "provenance": { diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index dda6d20b5..ce3ed869b 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -20,6 +20,7 @@ Every model below did real work. A model is listed only for work it did. The orc | Codex (GPT-6 Astra) | Seeded executable contracts, loop-head invariants, release erasure, purity and runtime refusal controls | | Codex (GPT-6.1 Sol) | Corrected boolean bitwise typing in seeded OSC IR output, with C-referee regression cases | | Codex (GPT-6.1 Sol) | Seeded Omega OSC IR v1 to WebAssembly MVP backend, native differential gate, refusal and mutant controls | +| OpenAI GPT-6 Astra | SC1-Q checked quantities, object-bound slices, exhaustive arithmetic fixtures, compiled negative controls and native evidence (#756/#673) | | Codex | Handwritten bounded PD0 stream primitive and binary consumer in Omega, native tests, and host-reference/source review (native execution NOT_RUN) | | Codex | Current .om front-page status and source-backed C migration inventory | | Codex | BUILD receipt cleanliness enforcement and optional diagnostic pointer regression fixes | diff --git a/om/quantity/README.md b/om/quantity/README.md new file mode 100644 index 000000000..2503542f9 --- /dev/null +++ b/om/quantity/README.md @@ -0,0 +1,104 @@ +# SC1-Q checked quantities + +Implementation plan: (1) freeze API and fixtures, (2) implement checked operations and independent fixtures, (3) compile pinned seed and execute native tests plus named mutants, (4) record immutable evidence. Scope is only `om/quantity/`. + +## Frozen API + +`struct bqty val ulong cap ulong end`; `struct qobj ident ulong ver ulong extent ulong end`; `struct qslic ident ulong ver ulong off ulong count ulong end`. + +The library struct was first frozen as `struct qty`. Since #909/#914 the seeded compiler has a native `qty` type keyword (spec/quantities-and-modular.md section 6, Phase 1), so `struct qty` is refused with error 16. The struct is renamed `bqty` (bounded quantity) with identical fields and semantics; this is the Phase 2 nominal library type, layered on top of the native Phase 1 `qty`, not a replacement for it. The native `qty` traps on overflow; `bqty` carries a nominal cap and returns status codes. Receipts recorded before the rename used the old name and compiler 734f0a39; the post-rename replay is a separate receipt. + +All functions return int: 0 success, 1 invalid operand (`val > cap`), 2 domain mismatch (different caps, negative signed ingress, widening via narrow), 3 overflow/underflow or extent violation, 4 object/version mismatch. Checks precede arithmetic and output stores. Every refusal leaves the complete output unchanged. Output must be a distinct struct from each input (seed alias rule). + +- `qword(out edit bqty, raw ulong, cap ulong)` and `qsigned(out edit bqty, raw long, cap ulong)` validate original ingress, then write value/cap. +- `qadd/qsub/qmul(out edit bqty, a view bqty, b view bqty)`: validate both operands, require equal caps, then checked arithmetic within that cap. Subtraction refuses b>a. Zero multiplication succeeds. +- `qnarrow(out edit bqty, a view bqty, cap ulong)`: validate a, refuse cap>a.cap as domain mismatch, refuse a.val>cap as overflow; no scalar cast before validation. +- `qnext(out edit bqty, a view bqty)`: validate a and refuse a.val==a.cap; increment without wrap. +- `qtyslice(out edit qslic, off view bqty, count view bqty, expect view qobj, current view qobj)`: compare all expected/current identity, version and extent fields, validate operands and require both caps equal current.extent, then check off<=extent and count<=extent-off. Writes binding plus offset/count, never forms an unchecked end address. + +Raw words, struct construction, field writes and extraction are trusted boundaries, not sealing or provenance. In particular qword(add raw_a raw_b) cannot detect a prior wrap. Consumers must recompute from validated original operands at the effect boundary. A `ulong` identity is an owner-assigned nonreused object identifier, not an fd; the owner supplies the trusted current version/extent. Reusing both identity and version cannot be detected here. This library has no authentication, storage, parser, address dereference or service integration. + +Equal caps are not physical units: two counts from different application domains +still have type `bqty`. The consumer owns that domain distinction. To revalidate +a serialized slice, reconstruct distinct checked offset/count values from its +original fields and the trusted current extent, construct the expected object +from its recorded identity/version, then call `qtyslice` against the current +object immediately before the effect. Never treat a raw `qslic` as validated. + +## Frozen expectations before implementation + +Q1: `(18446744073709551608 + 16) mod 2^64 = 8`; checked add returns3 and leaves sentinel output unchanged. Q2: exhaustive widths1..8, all pairs in0..(2^w-1), compare add/sub/mul with independent exact arithmetic oracle within u64. Q3: u64 zero/max, malformed operands, domain mismatch. Q4: max*2 returns3 before multiplication; zero*max succeeds. Q5: signed -1 returns2 unchanged; signed max succeeds under u64 max. Q6: 256 narrowed to255 returns3 unchanged; 255 narrowed to255 succeeds; widening refuses2. Q7: zero and exact extent slices succeed, extent+1 refuses3. Q8: scalar passed to bqty and bqty passed to scalar are compiler error7; ordinary crypto-style unsigned wrap stays accepted. Q9: epoch max refuses3; stale version and reused identity with changed version refuse4; identity or extent mismatch refuses4. Every runtime refusal checks output preservation. + +Mutation controls must compile and reach the named Q1_ADD_GUARD and Q4_MUL_GUARD assertions, with normal exit1. Build failures or signals do not count. + +## Qualification boundary + +This is a bounded library profile. Independent review is complete (see below). It is not language-wide constructor sealing, formal/native translation proof or a qualified consumer migration. The omnet transport/Revision consumer slice exists only as a proposal in aien-dev/omnet#6, with the remaining sites inventoried, not migrated. Those remain open under #756/#673. Native execution, finite exhaustive arithmetic checks, compiler-refusal fixtures and mutation sensitivity are separate evidence categories. No GPU or timing secrecy claim. + +## Native replay + +Run from repository root on Linux AArch64. The only production unit is `quantity.om`; `tests.om` is the executable fixture runner, `demo.om` is the demonstration, and `mutate.om` is a test-only exact source transformer. No generated binary is installed or committed. + +```sh +nice -n 19 sh seed/omega-from-seed.sh +sha256sum seed/out/omc +# Required compiler hash: 62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b +mkdir -p /tmp/security756-replay +cat om/quantity/quantity.om om/quantity/tests.om | nice -n 19 seed/out/omc > /tmp/security756-replay/tests +chmod +x /tmp/security756-replay/tests +nice -n 19 /tmp/security756-replay/tests +cat om/quantity/quantity.om om/quantity/demo.om | nice -n 19 seed/out/omc > /tmp/security756-replay/demo +chmod +x /tmp/security756-replay/demo +nice -n 19 /tmp/security756-replay/demo +nice -n 19 seed/out/omc < om/quantity/fixtures/crypto-wrap.om > /tmp/security756-replay/crypto +chmod +x /tmp/security756-replay/crypto +nice -n 19 /tmp/security756-replay/crypto +cat om/quantity/quantity.om om/quantity/fixtures/mixed-scalar.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-scalar +cat om/quantity/quantity.om om/quantity/fixtures/mixed-quantity.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-quantity +cat om/quantity/quantity.om om/quantity/fixtures/mixed-object.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-object +cat om/quantity/quantity.om om/quantity/fixtures/mixed-slice.om | nice -n 19 seed/out/omc > /tmp/security756-replay/refused-slice +nice -n 19 seed/out/omc < om/quantity/mutate.om > /tmp/security756-replay/mutate +chmod +x /tmp/security756-replay/mutate +nice -n 19 /tmp/security756-replay/mutate a < om/quantity/quantity.om > /tmp/security756-replay/add.om +nice -n 19 /tmp/security756-replay/mutate m < om/quantity/quantity.om > /tmp/security756-replay/mul.om +cat /tmp/security756-replay/add.om om/quantity/tests.om | nice -n 19 seed/out/omc > /tmp/security756-replay/mutant-add +cat /tmp/security756-replay/mul.om om/quantity/tests.om | nice -n 19 seed/out/omc > /tmp/security756-replay/mutant-mul +chmod +x /tmp/security756-replay/mutant-add /tmp/security756-replay/mutant-mul +nice -n 19 /tmp/security756-replay/mutant-add +nice -n 19 /tmp/security756-replay/mutant-mul +``` + +Expected exits: successful compiles, tests, demo and crypto control0; each mixed-type compile7; guard transformer0; each mutant compile0 and execution1, printing its named failed assertion. Never execute output from a refused compile. Check each command's exit individually; an arbitrary nonzero is not success. + +The independent arithmetic oracle uses signed long operations on inputs0..255, whose exact sums/products fit (at most510/65025); it does not duplicate the library's overflow predicate. The runner exhausts87380 pairs across widths1..8 and262140 binary operations, plus all in-domain raw/signed constructors, next operations, all87380 narrowing pairs, and the zero-capacity unary fixture. This is finite differential checking, not a proof over u64. Extrema and object cases are separately named fixtures. Output sentinels check every tested refusal. The demo's side-effect counter is a local witness only, not a real service-effect test. + +Observed evidence is additive under `evidence/`. It retains initial attempts, including the scalar literal syntax diagnostic16 before the fixture was corrected to pass a scalar variable and reach the intended nominal type diagnostic7. The compiled mutation controls both execute to their intended assertion; the transformer also refuses absent/duplicate guards (exit4) and an invalid mode (exit2). + +Independent review found no implementation defect and requested additional u64 +multiply fixtures. The runtime suite now refuses `2^32 * 2^32` and +`(2^32+1)^2`, accepts the exact `(2^32-1)^2 = 18446744065119617025`, +and exercises `0 * u64_max`. The second refusal defeats a multiply-first guard +that only compares the wrapped product against its cap and left operand. +Object-to-quantity and slice-to-quantity fixtures also refuse with compiler7. +These are boundary checks, not exhaustive u64 proof. The finite signed oracle +shares the compiler with the library; it is algorithmically independent, not +an independently compiled translation referee. Original evidence remains immutable; +review additions and final clean replay have separate receipts. The replay after +the `qty` -> `bqty` rename on main's compiler 62775d2a is the additive receipt +`evidence/main-omc-rename-replay.json`: tests, demo and crypto exit0, the four +mixed fixtures compile7, both mutants exit1 at their named guards, an invalid +transformer mode exits2, and the exporter stdout equals the retained corpus byte +for byte. The earlier receipts, recorded with compiler 734f0a39 and the old name, +are unchanged. + +`oracle-export.om` emits actual helper results, with no reference arithmetic in +the program: width1..8, a0..cap, b0..cap, then add/sub/mul, three little-endian +u64 words per result `(status,value,cap)`. The external arbitrary-precision oracle +compares each exact integer result with `[0,cap]`; expected success is +`(0,result,cap)`, refusal `(3,17,19)`. All262140 records matched independently, +including every refusal sentinel. `evidence/review-exhaustion.json` binds the +6291360-byte output and exporter; the raw output is retained compressed beside it. +Replay by concatenating `quantity.om oracle-export.om` into the pinned compiler, +executing the resulting binary, and comparing its stdout SHA-256 and bytes to +the decompressed corpus. This supplements, rather than relabels, the original +same-compiler signed oracle. diff --git a/om/quantity/demo.om b/om/quantity/demo.om new file mode 100644 index 000000000..d2dd8c5c9 --- /dev/null +++ b/om/quantity/demo.om @@ -0,0 +1,94 @@ +note Concatenate quantity.om then demo.om. No parser or service is simulated. +text db "PASS modular baseline8 checked add status3 unchanged output effects0\n" +text dm "PASS multiply status3 narrow status3 negative status2 unchanged output\n" +text da "PASS reused object identity changed version status4 unchanged slice\n" + +fn demoadd to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 18446744073709551608 ulong 18446744073709551615 +b = new bqty ulong 16 ulong 18446744073709551615 +effects = int 0 +rc = qadd out a b +if eq rc int 0 +effects = add effects int 1 +end +if ne effects int 0 +ret bool 0 +end +if ne add get a val get b val ulong 8 +ret bool 0 +end +if ne rc int 3 +ret bool 0 +end +ret and eq get out val ulong 17 eq get out cap ulong 19 +end + +fn demomul to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 18446744073709551615 ulong 18446744073709551615 +b = new bqty ulong 2 ulong 18446744073709551615 +rc = qmul out a b +if ne rc int 3 +ret bool 0 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret bool 0 +end +rc = qnarrow out a ulong 255 +if ne rc int 3 +ret bool 0 +end +if not and eq get out val ulong 17 eq get out cap ulong 19 +ret bool 0 +end +rc = qsigned out long -1 ulong 18446744073709551615 +if ne rc int 2 +ret bool 0 +end +ret and eq get out val ulong 17 eq get out cap ulong 19 +end + +fn demoaba to bool +out = new qslic ulong 91 ulong 92 ulong 93 ulong 94 +off = new bqty ulong 0 ulong 8 +count = new bqty ulong 1 ulong 8 +expect = new qobj ulong 5 ulong 7 ulong 8 +current = new qobj ulong 5 ulong 8 ulong 8 +rc = qtyslice out off count expect current +if ne rc int 4 +ret bool 0 +end +if ne get out ident ulong 91 +ret bool 0 +end +if ne get out ver ulong 92 +ret bool 0 +end +ret and eq get out off ulong 93 eq get out count ulong 94 +end + +fn main to int +if not demoadd +ret int 1 +end +n = write int 1 db ulong 0 len db +if ne n long len db +ret int 2 +end +if not demomul +ret int 3 +end +n = write int 1 dm ulong 0 len dm +if ne n long len dm +ret int 4 +end +if not demoaba +ret int 5 +end +n = write int 1 da ulong 0 len da +if ne n long len da +ret int 6 +end +ret int 0 +end diff --git a/om/quantity/evidence/clean-replay.json b/om/quantity/evidence/clean-replay.json new file mode 100644 index 000000000..af345a518 --- /dev/null +++ b/om/quantity/evidence/clean-replay.json @@ -0,0 +1,147 @@ +{ + "checkout": "f696440aa", + "contract_sha256": "ced61decef1ff4efbf5bc81598db648aa810be434e373e9bc1563dbcb4523496", + "compiler_sha256": "734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61", + "records": [ + { + "name": "tests", + "source_sha256": "7614bfcab3e2821e071b8b03d99ad1009f57dfbe3dc566c2e97fcb212bbda7df", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "cc328b083385ae3e2bc695f2a66d52bb8e0b31101005cc894fb7b4636c5dc6ad", + "exit": 0, + "stdout_sha256": "4813f7f491aca7d4ccf35e8e7c2676211d9c68f30a161f34b545547e899d729b", + "stdout_bytes": 62, + "stderr": "", + "stdout": "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n" + }, + { + "name": "demo", + "source_sha256": "4c236ab4dbb0f5374227e8d950af25ded11ae50b0fba0bc25db91b452e22f08d", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "fde488154d9806c49e57b27b6affbe51f2037d43569b2a87fe64b595a6d02fdb", + "exit": 0, + "stdout_sha256": "662d1da493c9e96cb4d2b3b7778dea1ec80e5953c41d59eeafa88837f0882431", + "stdout_bytes": 208, + "stderr": "", + "stdout": "PASS modular baseline8 checked add status3 unchanged output effects0\nPASS multiply status3 narrow status3 negative status2 unchanged output\nPASS reused object identity changed version status4 unchanged slice\n" + }, + { + "name": "crypto", + "source_sha256": "92c32dd28633f6351dd2f8f053d5cccf29b97deb325da9a3bf19cb35dfe7e5fe", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "6178e84856c15364c07299ee581478b44b2e7fc1f794c36e4c1c52290277a219", + "exit": 0, + "stdout_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 0, + "stderr": "", + "stdout": "" + }, + { + "name": "mutate", + "source_sha256": "c4e7bf75938e6a4ae22c5b405773984465efa646d1a4b08521505b93904471c5", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "8078ac96be29235c0a4ff878575afa38bc9619e8c06434d4878cca728a5f4542" + }, + { + "name": "export", + "source_sha256": "09eb487ce982b60d566576f7c3949ef2632146950597f92da90ef8560ee0e1e9", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "06af414693ec76840f541ee584cd7877f0400af703012d3d7a715ea070abfdc6", + "exit": 0, + "stdout_sha256": "0841c3b0714b36b46e09a83d036243989b0295b5aa3af68650fa24eca9886bd9", + "stdout_bytes": 6291360, + "stderr": "", + "independent_corpus": "all6291360bytes equal" + }, + { + "name": "mixed-scalar", + "source_sha256": "046e8729e6808b5845941cb2591113411ecc54ff54330b3ad20d9ee7268945c9", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mixed-quantity", + "source_sha256": "3f9c4e55552dc320cfa5ed8a8e5581ec5fde0dbe0660b6429c085a82eb0c2bd6", + "compile_exit": 7, + "compile_stderr": "omc: line 149: error 7\n" + }, + { + "name": "mixed-object", + "source_sha256": "e0956012a52edb290381187f7094f5fe05c3aae86900b84b1373c71dcf4435f8", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mixed-slice", + "source_sha256": "6a8c33da0ada678ceccd15d7db803174f0bbbdc61cdf9c22970075d4a75ca9b3", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mutant-a", + "transform_args": [ + "a" + ], + "transform_stdin_sha256": "bb0214be78009c9af59e8fb82f22ed84de4eeba94bdc95a4bffd972d5616da97", + "source_sha256": "823e070d52351c797121931e3d0bfc0f6869f4e5b971bb54f1b2fc0be7513316", + "compile_exit": 0, + "binary_sha256": "51185d80447455201cfbc44afae292df7904818d9d9d753b8edc9281b8728f4a", + "exit": 1, + "stdout": "FAIL Q1_ADD_GUARD\n" + }, + { + "name": "mutant-m", + "transform_args": [ + "m" + ], + "transform_stdin_sha256": "bb0214be78009c9af59e8fb82f22ed84de4eeba94bdc95a4bffd972d5616da97", + "source_sha256": "7c38cf4da8faf15fe3b8b885d07968cf3cb9e672031929cb7d84197660fbb900", + "compile_exit": 0, + "binary_sha256": "c59af673d93018a6f1122d24c3ef90f1d4ee5d86e3da5fa6aab4cf8029aa1776", + "exit": 1, + "stdout": "FAIL Q4_MUL_GUARD\n" + }, + { + "name": "missing", + "args": [ + "a" + ], + "stdin_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdin_fixture": "empty", + "binary_sha256": "8078ac96be29235c0a4ff878575afa38bc9619e8c06434d4878cca728a5f4542", + "exit": 4, + "stdout": "", + "stderr": "" + }, + { + "name": "duplicate", + "args": [ + "a" + ], + "stdin_sha256": "64708d35e3ea1cddf1ace2633ff69b3174cc615dcfb509a12f9fc282e3e091ce", + "stdin_fixture": "quantity.om concatenated twice", + "binary_sha256": "8078ac96be29235c0a4ff878575afa38bc9619e8c06434d4878cca728a5f4542", + "exit": 4, + "stdout": "", + "stderr": "" + }, + { + "name": "bad-arg", + "args": [ + "?" + ], + "stdin_sha256": "bb0214be78009c9af59e8fb82f22ed84de4eeba94bdc95a4bffd972d5616da97", + "stdin_fixture": "quantity.om", + "binary_sha256": "8078ac96be29235c0a4ff878575afa38bc9619e8c06434d4878cca728a5f4542", + "exit": 2, + "stdout": "", + "stderr": "" + } + ], + "limits": "bounded library/external finite arithmetic evidence; no general sealed provenance or native translation proof" +} diff --git a/om/quantity/evidence/exhaustive-outcomes.bin.gz b/om/quantity/evidence/exhaustive-outcomes.bin.gz new file mode 100644 index 000000000..2758fa126 Binary files /dev/null and b/om/quantity/evidence/exhaustive-outcomes.bin.gz differ diff --git a/om/quantity/evidence/main-omc-rename-replay.json b/om/quantity/evidence/main-omc-rename-replay.json new file mode 100644 index 000000000..517c29a67 --- /dev/null +++ b/om/quantity/evidence/main-omc-rename-replay.json @@ -0,0 +1,117 @@ +{ + "checkout": "12e6d8218", + "note": "post-rename replay (struct qty -> bqty) on main compiler; earlier receipts are kept unchanged", + "compiler_sha256": "62775d2a391cfef7cde64e387655caa9809a267093112910ec76bfa568f3712b", + "records": [ + { + "name": "tests", + "source_sha256": "7a4d2fc9b6601ce246bcafdcbb6358dff0d6635078f5635065841a57d12fcb76", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "cc328b083385ae3e2bc695f2a66d52bb8e0b31101005cc894fb7b4636c5dc6ad", + "exit": 0, + "stdout_sha256": "4813f7f491aca7d4ccf35e8e7c2676211d9c68f30a161f34b545547e899d729b", + "stdout_bytes": 62, + "stderr": "", + "stdout": "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n" + }, + { + "name": "demo", + "source_sha256": "84262281675903e412bddbb4850644dbe644aaf588682773b354f71c5d1c279f", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "fde488154d9806c49e57b27b6affbe51f2037d43569b2a87fe64b595a6d02fdb", + "exit": 0, + "stdout_sha256": "662d1da493c9e96cb4d2b3b7778dea1ec80e5953c41d59eeafa88837f0882431", + "stdout_bytes": 208, + "stderr": "", + "stdout": "PASS modular baseline8 checked add status3 unchanged output effects0\nPASS multiply status3 narrow status3 negative status2 unchanged output\nPASS reused object identity changed version status4 unchanged slice\n" + }, + { + "name": "crypto", + "source_sha256": "92c32dd28633f6351dd2f8f053d5cccf29b97deb325da9a3bf19cb35dfe7e5fe", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "6178e84856c15364c07299ee581478b44b2e7fc1f794c36e4c1c52290277a219", + "exit": 0, + "stdout_sha256": "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", + "stdout_bytes": 0, + "stderr": "", + "stdout": "" + }, + { + "name": "export", + "source_sha256": "f7d758098b6874cc72d95dffc448fa5435fcb787300d4a77d615bfc950489bbb", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "06af414693ec76840f541ee584cd7877f0400af703012d3d7a715ea070abfdc6", + "exit": 0, + "stdout_sha256": "0841c3b0714b36b46e09a83d036243989b0295b5aa3af68650fa24eca9886bd9", + "stdout_bytes": 6291360, + "stderr": "", + "independent_corpus": "all6291360bytes equal" + }, + { + "name": "mixed-scalar", + "source_sha256": "1b2d8b526477e45c1e06bb247421e5cfcec1f5689e2aaa2f5dd90beb437d0ffe", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mixed-quantity", + "source_sha256": "4983a6d507cb8d0484cb7443ec8b8ce4e10eae855c97f10cdd9a2da341d07d43", + "compile_exit": 7, + "compile_stderr": "omc: line 149: error 7\n" + }, + { + "name": "mixed-object", + "source_sha256": "792045eeb2e39fa5dcc42c9f0b036318b6f84ae73c028cd6e5e36b07beb70600", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mixed-slice", + "source_sha256": "8fc52c4b3bffadb0621341f8b13ed9cf0573d07dae0031202afdafda79f62c30", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mutate", + "source_sha256": "c4e7bf75938e6a4ae22c5b405773984465efa646d1a4b08521505b93904471c5", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "8078ac96be29235c0a4ff878575afa38bc9619e8c06434d4878cca728a5f4542" + }, + { + "name": "mutant-a", + "source_sha256": "cb98155fc210b875e216e217da1b13b765e1650d149fbb0a1908541d97108555", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "51185d80447455201cfbc44afae292df7904818d9d9d753b8edc9281b8728f4a", + "transform_exit": 0, + "exit": 1, + "stdout_sha256": "04799d328894b1edb9f33866fa6b905ed4f557b594d0637f08f1bd1bf3d82794", + "stdout_bytes": 18, + "stderr": "", + "stdout": "FAIL Q1_ADD_GUARD\n" + }, + { + "name": "mutant-m", + "source_sha256": "a277a422d05467fbf861352f0e617b86ddcfcb79c042904e4fa072a5b04f2a42", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "c59af673d93018a6f1122d24c3ef90f1d4ee5d86e3da5fa6aab4cf8029aa1776", + "transform_exit": 0, + "exit": 1, + "stdout_sha256": "c5dea7a05c40f75d4257311c5fa814b9286bdc4582eb1d70c462b6bd3a0b307c", + "stdout_bytes": 18, + "stderr": "", + "stdout": "FAIL Q4_MUL_GUARD\n" + }, + { + "name": "mutate-invalid-mode", + "exit": 2 + } + ], + "verdict": "PASS" +} diff --git a/om/quantity/evidence/native.db940c56cbc733b477fc5620ac3728e9751a11393e6442c9da997460aa8558ba.json b/om/quantity/evidence/native.db940c56cbc733b477fc5620ac3728e9751a11393e6442c9da997460aa8558ba.json new file mode 100644 index 000000000..3b53a8095 --- /dev/null +++ b/om/quantity/evidence/native.db940c56cbc733b477fc5620ac3728e9751a11393e6442c9da997460aa8558ba.json @@ -0,0 +1,153 @@ +{ + "profile": "SC1-Q", + "source_commit": "ee1b3f8ea1acb45f27fd190049e30ad14e8d3a3b", + "base_commit": "00eb0e7106d2f8fc841e5e16eb624fa1bd029111", + "contract_sha256": "8bc52be7a480e279fb77673648a2f7775ba6d4841a8b1e6c427531b25d4d1860", + "target": "Linux 7.0.0-1019-nvidia aarch64", + "abi": "Linux AArch64 seed ELF", + "compiler_expected_sha256": "734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61", + "source_hashes_raw": "bb0214be78009c9af59e8fb82f22ed84de4eeba94bdc95a4bffd972d5616da97 om/quantity/quantity.om\n33fed09f146cd4eb009bbd6f9134102478fbbfc9c70a41680d29de3649899ff1 om/quantity/tests.om\ndf1723da7d055b2be827374b857bad29cd40413f70c3044b23517253cf73b46a om/quantity/demo.om\nc4e7bf75938e6a4ae22c5b405773984465efa646d1a4b08521505b93904471c5 om/quantity/mutate.om\ncdb679f250c0b3d5b42f681928fcea5dfb8489a6deb9f2ec268a6c71856f7a46 om/quantity/fixtures/mixed-scalar.om\n59a911bb47db77179df5e8fdb58787c1895175227aa2a40e08ac50d2d99567e1 om/quantity/fixtures/mixed-quantity.om\n92c32dd28633f6351dd2f8f053d5cccf29b97deb325da9a3bf19cb35dfe7e5fe om/quantity/fixtures/crypto-wrap.om\nac7c2d1177153075c0e56a733770c18856dff157656e9f59493070989e5c5321 om/quantity/README.md\n2e35db7d6c2066fb4a20d19b8a9579c44caca9c9937b0594a89422010b673637 seed/omc/omc.om\n734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61 seed/out/omc\nbaaf081fe6055a768485c5d25d7435681ce00b04cfa80b26c48169f78944e14d seed/rung0/seed0.hex\n", + "bootstrap_command": "nice -n 19 sh seed/omega-from-seed.sh", + "bootstrap_exit": 0, + "bootstrap_stdout": "PASS seed0 408 bytes, rebuilds itself\nPASS hex1 776 bytes, born from seed0\nPASS asm2 2464 bytes, born from hex1\nPASS om4 om4.bin 14224 bytes\nPASS omc fixpoint 734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61\nPASS fwd exit 0\nPASS fwd runs, exit 7\nPASS mut exit 0\nPASS mut runs, exit 0\nPASS cycle exit 9\nPASS assign exit 7\nRC=0\n", + "invocation": "Each named source is byte concatenation in README order; nice -n 19 seed/out/omc reads it on stdin, captured stdout becomes executable, chmod0755, then nice -n 19 executable. Mutator reads quantity.om on stdin with argument a/m; its stdout replaces only library input. Python subprocess was orchestration only, not shipped first-party implementation or oracle.", + "records": [ + { + "name": "tests", + "source_sha256": "7b4875414ca54b7651b1b106de01e82f0483e254e31b4b6f24a1a9136fd1b917", + "compile_exit": 0, + "compile_stdout_bytes": 12084, + "compile_stderr": "", + "binary_sha256": "80a07497051b0f061575c4cb31198cdc71699b7467e023d38fbaa3e260433d37", + "run_exit": 0, + "stdout": "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n", + "stderr": "" + }, + { + "name": "demo", + "source_sha256": "4c236ab4dbb0f5374227e8d950af25ded11ae50b0fba0bc25db91b452e22f08d", + "compile_exit": 0, + "compile_stdout_bytes": 4200, + "compile_stderr": "", + "binary_sha256": "fde488154d9806c49e57b27b6affbe51f2037d43569b2a87fe64b595a6d02fdb", + "run_exit": 0, + "stdout": "PASS modular baseline8 checked add status3 unchanged output effects0\nPASS multiply status3 narrow status3 negative status2 unchanged output\nPASS reused object identity changed version status4 unchanged slice\n", + "stderr": "" + }, + { + "name": "crypto-wrap", + "source_sha256": "92c32dd28633f6351dd2f8f053d5cccf29b97deb325da9a3bf19cb35dfe7e5fe", + "compile_exit": 0, + "compile_stdout_bytes": 268, + "compile_stderr": "", + "binary_sha256": "6178e84856c15364c07299ee581478b44b2e7fc1f794c36e4c1c52290277a219", + "run_exit": 0, + "stdout": "", + "stderr": "" + }, + { + "name": "mixed-scalar", + "source_sha256": "d376817f9af22df6f16b0f6185227b80fc8b8ea0e800ff7ab21d015be9892b86", + "compile_exit": 16, + "compile_stdout_bytes": 0, + "compile_stderr": "omc: line 147: error 16\n" + }, + { + "name": "mixed-quantity", + "source_sha256": "3f9c4e55552dc320cfa5ed8a8e5581ec5fde0dbe0660b6429c085a82eb0c2bd6", + "compile_exit": 7, + "compile_stdout_bytes": 0, + "compile_stderr": "omc: line 149: error 7\n" + }, + { + "name": "tests-final", + "source_sha256": "c7027a53dcb5a4411e72ccd654c2a0432ff96bbd979fe35311cef66417c38eaa", + "compile_exit": 0, + "compile_stdout_bytes": 14332, + "compile_stderr": "", + "binary_sha256": "1abad58b82b17d8d6be57978cb635572c1ee8f4e6462b4dba068131e4d42375f", + "run_exit": 0, + "stdout": "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n", + "stderr": "" + }, + { + "name": "mixed-scalar-final", + "source_sha256": "046e8729e6808b5845941cb2591113411ecc54ff54330b3ad20d9ee7268945c9", + "compile_exit": 7, + "compile_stdout_bytes": 0, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mutate", + "source_sha256": "c4e7bf75938e6a4ae22c5b405773984465efa646d1a4b08521505b93904471c5", + "compile_exit": 0, + "compile_stdout_bytes": 2100, + "compile_stderr": "", + "binary_sha256": "8078ac96be29235c0a4ff878575afa38bc9619e8c06434d4878cca728a5f4542" + }, + { + "name": "mutation-transform-a", + "run_exit": 0, + "stderr": "", + "output_sha256": "0da2db0c1276eb49e78230726f6e9f40e669ff42468773a8b687c3a3e9e66006" + }, + { + "name": "mutant-a", + "source_sha256": "0a2f91a0ffb25863a744e42683903f3bb00321b950eb455871f1e2e601bd0a96", + "compile_exit": 0, + "compile_stdout_bytes": 14288, + "compile_stderr": "", + "binary_sha256": "1de3a747a8962712300fe3d950b3435450d850b3b746cd8c2bb3112a9ed196a7", + "run_exit": 1, + "stdout": "FAIL Q1_ADD_GUARD\n", + "stderr": "" + }, + { + "name": "mutation-transform-m", + "run_exit": 0, + "stderr": "", + "output_sha256": "51d85e0c982b24916450a75f11dd891a5cca00b466af6e29cd5c62eb089b97d7" + }, + { + "name": "mutant-m", + "source_sha256": "6e0125a241fc3d0aa669642591908e5f6cefdeabcb669fda20245f479b425b2d", + "compile_exit": 0, + "compile_stdout_bytes": 14260, + "compile_stderr": "", + "binary_sha256": "7fe74b127a773148067aed483dc6538429495655dfba093ac77ed0c444719764", + "run_exit": 1, + "stdout": "FAIL Q4_MUL_GUARD\n", + "stderr": "" + }, + { + "name": "mutation-missing", + "run_exit": 4, + "stdout": "", + "stderr": "" + }, + { + "name": "mutation-duplicate", + "run_exit": 4, + "stdout": "", + "stderr": "" + }, + { + "name": "mutation-bad-arg", + "run_exit": 2, + "stdout": "", + "stderr": "" + } + ], + "claims": { + "native_execution": "PASS demo, final runtime suite and modular wrapping control", + "finite_differential": "PASS widths1..8; exact signed wider arithmetic oracle; 87380 pairs and262140 binary checks plus unary/narrow cases", + "nominal_compile_refusal": "PASS both final fixtures error7", + "mutation_sensitivity": "PASS removed add/mul guards compile0 then normal exit1 at named assertion", + "formal_proof": "NOT_RUN", + "native_translation_proof": "NOT_RUN", + "language_wide_sealing": "MISSING_IMPLEMENTATION", + "real_consumer_integration": "BLOCKED_OWNER_HANDOFF", + "independent_review": "NOT_RUN", + "gpu": "NOT_RUN" + } +} diff --git a/om/quantity/evidence/review-exhaustion.json b/om/quantity/evidence/review-exhaustion.json new file mode 100644 index 000000000..51763879b --- /dev/null +++ b/om/quantity/evidence/review-exhaustion.json @@ -0,0 +1,43 @@ +{ + "profile_contract_sha256": "ced61decef1ff4efbf5bc81598db648aa810be434e373e9bc1563dbcb4523496", + "compiler_sha256": "734f0a39319fbfa930bcc62cb30dbf06d47d78e126372b74f5baf478e6126b61", + "export_source_sha256": "09eb487ce982b60d566576f7c3949ef2632146950597f92da90ef8560ee0e1e9", + "export_binary_sha256": "06af414693ec76840f541ee584cd7877f0400af703012d3d7a715ea070abfdc6", + "compile_exit": 0, + "run_exit": 0, + "output_bytes": 6291360, + "output_sha256": "0841c3b0714b36b46e09a83d036243989b0295b5aa3af68650fa24eca9886bd9", + "records_compared": 262140, + "oracle": "external Python arbitrary-precision integers; each actual LEu64(status,val,cap) compared with exact a+b,a-b,a*b, 0<=exact<=cap; refusal(3,17,19)", + "initial_attempts": [ + { + "compile_exit": 9, + "stderr": "omc: line 168: error 9", + "cause": "struct allocation nested inside loops; changed constructor values did not fix it; moved allocations to outermost function block" + } + ], + "review_boundary_records": [ + { + "name": "tests", + "source_sha256": "7614bfcab3e2821e071b8b03d99ad1009f57dfbe3dc566c2e97fcb212bbda7df", + "compile_exit": 0, + "compile_stderr": "", + "binary_sha256": "cc328b083385ae3e2bc695f2a66d52bb8e0b31101005cc894fb7b4636c5dc6ad", + "run_exit": 0, + "stdout": "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n", + "stderr": "" + }, + { + "name": "mixed-object", + "source_sha256": "e0956012a52edb290381187f7094f5fe05c3aae86900b84b1373c71dcf4435f8", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + }, + { + "name": "mixed-slice", + "source_sha256": "6a8c33da0ada678ceccd15d7db803174f0bbbdc61cdf9c22970075d4a75ca9b3", + "compile_exit": 7, + "compile_stderr": "omc: line 148: error 7\n" + } + ] +} diff --git a/om/quantity/fixtures/crypto-wrap.om b/om/quantity/fixtures/crypto-wrap.om new file mode 100644 index 000000000..5b8c7d309 --- /dev/null +++ b/om/quantity/fixtures/crypto-wrap.om @@ -0,0 +1,12 @@ +note Ordinary modular crypto words remain legal. This is arithmetic compatibility not crypto qualification. +fn main to int +word = add ulong 18446744073709551615 ulong 1 +if ne word ulong 0 +ret int 1 +end +word = mul ulong 18446744073709551615 ulong 2 +if ne word ulong 18446744073709551614 +ret int 2 +end +ret int 0 +end diff --git a/om/quantity/fixtures/mixed-object.om b/om/quantity/fixtures/mixed-object.om new file mode 100644 index 000000000..b83307d3a --- /dev/null +++ b/om/quantity/fixtures/mixed-object.om @@ -0,0 +1,7 @@ +note Nominal qobj is not a bounded bqty even when its words fit. +fn main to int +out = new bqty ulong 0 ulong 8 +a = new qobj ulong 1 ulong 0 ulong 8 +b = new bqty ulong 1 ulong 8 +ret qadd out a b +end diff --git a/om/quantity/fixtures/mixed-quantity.om b/om/quantity/fixtures/mixed-quantity.om new file mode 100644 index 000000000..9cab4332a --- /dev/null +++ b/om/quantity/fixtures/mixed-quantity.om @@ -0,0 +1,8 @@ +note Compile after quantity.om; expected compiler error7 at scalar argument. +fn scalar raw ulong to ulong +ret raw +end +fn main to int +a = new bqty ulong 1 ulong 9 +ret int scalar a +end diff --git a/om/quantity/fixtures/mixed-scalar.om b/om/quantity/fixtures/mixed-scalar.om new file mode 100644 index 000000000..2106f296c --- /dev/null +++ b/om/quantity/fixtures/mixed-scalar.om @@ -0,0 +1,7 @@ +note Compile after quantity.om; expected compiler error7 at qadd scalar argument. +fn main to int +out = new bqty ulong 0 ulong 9 +a = new bqty ulong 1 ulong 9 +raw = ulong 1 +ret qadd out a raw +end diff --git a/om/quantity/fixtures/mixed-slice.om b/om/quantity/fixtures/mixed-slice.om new file mode 100644 index 000000000..216a77695 --- /dev/null +++ b/om/quantity/fixtures/mixed-slice.om @@ -0,0 +1,7 @@ +note A previously formed slice is not a quantity operand. +fn main to int +out = new bqty ulong 0 ulong 8 +a = new qslic ulong 1 ulong 0 ulong 0 ulong 1 +b = new bqty ulong 1 ulong 8 +ret qadd out a b +end diff --git a/om/quantity/mutate.om b/om/quantity/mutate.om new file mode 100644 index 000000000..b2aaf333e --- /dev/null +++ b/om/quantity/mutate.om @@ -0,0 +1,95 @@ +note Test-only source transformer. stdin quantity.om, argument a or m; stdout one guard removed. +note Requires exactly one exact guard occurrence, bounded input, complete writes. Never production code. +global src uchar 16384 +text aguard "if gt get b val sub get a cap get a val\nret int 3\nend\n" +text mguard "if ne get a val ulong 0\nif gt get b val div get a cap get a val\nret int 3\nend\nend\n" + +fn match at ulong kind uchar to bool +if eq kind uchar 97 +for i ulong len aguard +if ne get src add at i get aguard i +ret bool 0 +end +end +else +for i ulong len mguard +if ne get src add at i get mguard i +ret bool 0 +end +end +end +ret bool 1 +end + +fn emit at ulong size ulong to bool +pos = ulong 0 +while lt pos size bound 16384 +n = write int 1 src add at pos sub size pos +if le n long 0 +ret bool 0 +end +pos = add pos ulong n +end +ret bool 1 +end + +fn load to long +size = ulong 0 +while lt size len src bound 16384 +n = read int 0 src size sub len src size +if lt n long 0 +ret long -1 +end +if eq n long 0 +ret long size +end +size = add size ulong n +end +ret long -1 +end + +fn main to int +arg = new uchar 1 uchar 0 +if ne argcnt long 2 +ret int 2 +end +n = argread ulong 1 arg ulong 0 ulong 1 +if ne n long 1 +ret int 2 +end +kind = get arg 0 +if and ne kind uchar 97 ne kind uchar 109 +ret int 2 +end +n = load +if lt n long 0 +ret int 3 +end +size = ulong n +width = len aguard +if eq kind uchar 109 +width = len mguard +end +if lt size width +ret int 4 +end +hits = ulong 0 +found = ulong 0 +for i ulong add sub size width ulong 1 +if match i kind +hits = add hits ulong 1 +found = i +end +end +if ne hits ulong 1 +ret int 4 +end +if not emit ulong 0 found +ret int 5 +end +found = add found width +if not emit found sub size found +ret int 5 +end +ret int 0 +end diff --git a/om/quantity/oracle-export.om b/om/quantity/oracle-export.om new file mode 100644 index 000000000..c1e979f80 --- /dev/null +++ b/om/quantity/oracle-export.om @@ -0,0 +1,55 @@ +note Emit actual quantity outcomes for an independently implemented external oracle. +note Order width1..8, a0..cap, b0..cap, add/sub/mul. Record three LEu64: status,val,cap. +note Refusals retain sentinel17/19. No oracle arithmetic is used in this program. +global qxbuf uchar 24 +fn qxemit rc int out view bqty to int +for k ulong 8 +put qxbuf k uchar and shr ulong rc mul k 8 255 +put qxbuf add k 8 uchar and shr get out val mul k 8 255 +put qxbuf add k 16 uchar and shr get out cap mul k 8 255 +end +p = ulong 0 +while lt p 24 +n = write 1 qxbuf p sub 24 p +if le n 0 +ret 2 +end +p = add p ulong n +end +ret 0 +end +fn main to int +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 0 ulong 0 +b = new bqty ulong 0 ulong 0 +for w ulong 8 +cap = sub shl ulong 1 add w 1 1 +for av ulong add cap 1 +for bv ulong add cap 1 +put a val av +put a cap cap +put b val bv +put b cap cap +put out val 17 +put out cap 19 +rc = qadd out a b +if ne qxemit rc out 0 +ret 2 +end +put out val 17 +put out cap 19 +rc = qsub out a b +if ne qxemit rc out 0 +ret 2 +end +put out val 17 +put out cap 19 +rc = qmul out a b +if ne qxemit rc out 0 +ret 2 +end +end +end +end +ret 0 +end diff --git a/om/quantity/quantity.om b/om/quantity/quantity.om new file mode 100644 index 000000000..7f6149563 --- /dev/null +++ b/om/quantity/quantity.om @@ -0,0 +1,142 @@ +note SC1-Q API and status contract frozen in README.md. Raw structs are trusted not sealed. +struct bqty val ulong cap ulong end +struct qobj ident ulong ver ulong extent ulong end +struct qslic ident ulong ver ulong off ulong count ulong end + +fn qword out edit bqty raw ulong cap ulong to int +if gt raw cap +ret int 3 +end +put out val raw +put out cap cap +ret int 0 +end + +fn qsigned out edit bqty raw long cap ulong to int +if lt raw long 0 +ret int 2 +end +ret qword out ulong raw cap +end + +fn qvalid a view bqty to int +if gt get a val get a cap +ret int 1 +end +ret int 0 +end + +fn qpair a view bqty b view bqty to int +if ne qvalid a int 0 +ret int 1 +end +if ne qvalid b int 0 +ret int 1 +end +if ne get a cap get b cap +ret int 2 +end +ret int 0 +end + +fn qadd out edit bqty a view bqty b view bqty to int +rc = qpair a b +if ne rc int 0 +ret rc +end +note Q1_ADD_GUARD mutation removes this check only. +if gt get b val sub get a cap get a val +ret int 3 +end +put out val add get a val get b val +put out cap get a cap +ret int 0 +end + +fn qsub out edit bqty a view bqty b view bqty to int +rc = qpair a b +if ne rc int 0 +ret rc +end +if gt get b val get a val +ret int 3 +end +put out val sub get a val get b val +put out cap get a cap +ret int 0 +end + +fn qmul out edit bqty a view bqty b view bqty to int +rc = qpair a b +if ne rc int 0 +ret rc +end +note Q4_MUL_GUARD mutation removes this check only. +if ne get a val ulong 0 +if gt get b val div get a cap get a val +ret int 3 +end +end +put out val mul get a val get b val +put out cap get a cap +ret int 0 +end + +fn qnarrow out edit bqty a view bqty cap ulong to int +rc = qvalid a +if ne rc int 0 +ret rc +end +if gt cap get a cap +ret int 2 +end +if gt get a val cap +ret int 3 +end +put out val get a val +put out cap cap +ret int 0 +end + +fn qnext out edit bqty a view bqty to int +rc = qvalid a +if ne rc int 0 +ret rc +end +if eq get a val get a cap +ret int 3 +end +put out val add get a val ulong 1 +put out cap get a cap +ret int 0 +end + +fn qtyslice out edit qslic off view bqty count view bqty expect view qobj current view qobj to int +if ne get expect ident get current ident +ret int 4 +end +if ne get expect ver get current ver +ret int 4 +end +if ne get expect extent get current extent +ret int 4 +end +rc = qpair off count +if ne rc int 0 +ret rc +end +if ne get off cap get current extent +ret int 2 +end +if gt get off val get current extent +ret int 3 +end +if gt get count val sub get current extent get off val +ret int 3 +end +put out ident get current ident +put out ver get current ver +put out off get off val +put out count get count val +ret int 0 +end diff --git a/om/quantity/tests.om b/om/quantity/tests.om new file mode 100644 index 000000000..27aca505d --- /dev/null +++ b/om/quantity/tests.om @@ -0,0 +1,358 @@ +note Concatenate quantity.om then tests.om. Wider signed oracle has no quantity guard. +text tadd "FAIL Q1_ADD_GUARD\n" +text tmul "FAIL Q4_MUL_GUARD\n" +text tedge "FAIL Q3_Q5_Q6_Q9_EDGES\n" +text tslc "FAIL Q7_Q9_SLICE\n" +text texh "FAIL Q2_EXACT_ORACLE\n" +text tpass "PASS Q1-Q9 runtime; Q2 widths1..8 pairs87380 operations262140\n" + +fn qsent out edit bqty to void +put out val ulong 17 +put out cap ulong 19 +end + +fn qcheck out view bqty rc int want int value ulong cap ulong to bool +if ne rc want +ret bool 0 +end +if ne get out val value +ret bool 0 +end +ret eq get out cap cap +end + +fn testadd to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 18446744073709551608 ulong 18446744073709551615 +b = new bqty ulong 16 ulong 18446744073709551615 +if ne add get a val get b val ulong 8 +ret bool 0 +end +rc = qadd out a b +ret qcheck out rc int 3 ulong 17 ulong 19 +end + +fn testmul to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 18446744073709551615 ulong 18446744073709551615 +b = new bqty ulong 2 ulong 18446744073709551615 +rc = qmul out a b +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 4294967296 +put b val ulong 4294967296 +rc = qmul out a b +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 4294967297 +put b val ulong 4294967297 +rc = qmul out a b +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 4294967295 +put b val ulong 4294967295 +rc = qmul out a b +if not qcheck out rc int 0 ulong 18446744065119617025 ulong 18446744073709551615 +ret bool 0 +end +qsent out +put a val ulong 0 +put b val ulong 18446744073709551615 +rc = qmul out a b +ret qcheck out rc int 0 ulong 0 ulong 18446744073709551615 +end + +fn edges to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 18446744073709551615 ulong 18446744073709551615 +b = new bqty ulong 0 ulong 18446744073709551615 +rc = qnext out a +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +rc = qsigned out long -1 ulong 18446744073709551615 +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qword out ulong 1 ulong 0 +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +rc = qmul out a b +if not qcheck out rc int 0 ulong 0 ulong 18446744073709551615 +ret bool 0 +end +qsent out +rc = qadd out a b +if not qcheck out rc int 0 ulong 18446744073709551615 ulong 18446744073709551615 +ret bool 0 +end +qsent out +rc = qsub out b a +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +rc = qsigned out long 9223372036854775807 ulong 18446744073709551615 +if not qcheck out rc int 0 ulong 9223372036854775807 ulong 18446744073709551615 +ret bool 0 +end +qsent out +put a val ulong 256 +rc = qnarrow out a ulong 255 +if not qcheck out rc int 3 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 255 +rc = qnarrow out a ulong 255 +if not qcheck out rc int 0 ulong 255 ulong 255 +ret bool 0 +end +qsent out +put a cap ulong 255 +rc = qnarrow out a ulong 256 +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qadd out a b +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qsub out a b +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +rc = qmul out a b +if not qcheck out rc int 2 ulong 17 ulong 19 +ret bool 0 +end +put a val ulong 256 +rc = qadd out a b +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qsub out b a +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qmul out a b +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qnarrow out a ulong 0 +if not qcheck out rc int 1 ulong 17 ulong 19 +ret bool 0 +end +rc = qnext out a +ret qcheck out rc int 1 ulong 17 ulong 19 +end + +fn sexpect out view qslic rc int want int to bool +if ne rc want +ret bool 0 +end +if ne get out ident ulong 91 +ret bool 0 +end +if ne get out ver ulong 92 +ret bool 0 +end +if ne get out off ulong 93 +ret bool 0 +end +ret eq get out count ulong 94 +end + +fn slices to bool +out = new qslic ulong 91 ulong 92 ulong 93 ulong 94 +off = new bqty ulong 6 ulong 8 +count = new bqty ulong 3 ulong 8 +expect = new qobj ulong 5 ulong 7 ulong 8 +current = new qobj ulong 5 ulong 7 ulong 8 +rc = qtyslice out off count expect current +if not sexpect out rc int 3 +ret bool 0 +end +put expect ver ulong 6 +rc = qtyslice out off count expect current +if not sexpect out rc int 4 +ret bool 0 +end +put expect ver ulong 7 +put expect ident ulong 4 +rc = qtyslice out off count expect current +if not sexpect out rc int 4 +ret bool 0 +end +put expect ident ulong 5 +put expect extent ulong 7 +rc = qtyslice out off count expect current +if not sexpect out rc int 4 +ret bool 0 +end +put expect extent ulong 8 +put off cap ulong 9 +rc = qtyslice out off count expect current +if not sexpect out rc int 2 +ret bool 0 +end +put count cap ulong 9 +rc = qtyslice out off count expect current +if not sexpect out rc int 2 +ret bool 0 +end +put off val ulong 10 +rc = qtyslice out off count expect current +if not sexpect out rc int 1 +ret bool 0 +end +put off val ulong 6 +put off cap ulong 8 +put count cap ulong 8 +put count val ulong 2 +rc = qtyslice out off count expect current +if ne rc int 0 +ret bool 0 +end +if ne get out ident ulong 5 +ret bool 0 +end +if ne get out ver ulong 7 +ret bool 0 +end +if ne get out off ulong 6 +ret bool 0 +end +if ne get out count ulong 2 +ret bool 0 +end +put off val ulong 8 +put count val ulong 0 +rc = qtyslice out off count expect current +if ne rc int 0 +ret bool 0 +end +if ne get out off ulong 8 +ret bool 0 +end +if ne get out count ulong 0 +ret bool 0 +end +put off val ulong 0 +put off cap ulong 0 +put count cap ulong 0 +put current extent ulong 0 +put expect extent ulong 0 +rc = qtyslice out off count expect current +ret eq rc int 0 +end + +note Oracle uses signed 64-bit exact arithmetic only on operands0..255. +note Its results are at most65025; it neither uses nor repeats the guarded algorithms. +fn oracle out view bqty rc int exact long cap ulong to bool +if or lt exact long 0 gt exact long cap +ret qcheck out rc int 3 ulong 17 ulong 19 +end +ret qcheck out rc int 0 ulong exact cap +end + +fn pairs cap ulong to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 0 cap +b = new bqty ulong 0 cap +rc = int 0 +for x ulong add cap ulong 1 +put a val x +for y ulong add cap ulong 1 +put b val y +qsent out +rc = qadd out a b +if not oracle out rc add long x long y cap +ret bool 0 +end +qsent out +rc = qsub out a b +if not oracle out rc sub long x long y cap +ret bool 0 +end +qsent out +rc = qmul out a b +if not oracle out rc mul long x long y cap +ret bool 0 +end +end +end +ret bool 1 +end + +fn unary cap ulong to bool +out = new bqty ulong 17 ulong 19 +a = new bqty ulong 0 cap +rc = int 0 +for x ulong add cap ulong 1 +qsent out +rc = qword out x cap +if not qcheck out rc int 0 x cap +ret bool 0 +end +qsent out +rc = qsigned out long x cap +if not qcheck out rc int 0 x cap +ret bool 0 +end +qsent out +put a val x +rc = qnext out a +if not oracle out rc add long x long 1 cap +ret bool 0 +end +for y ulong add cap ulong 1 +qsent out +rc = qnarrow out a y +if not oracle out rc long x y +ret bool 0 +end +end +end +qsent out +rc = qword out add cap ulong 1 cap +ret qcheck out rc int 3 ulong 17 ulong 19 +end + +fn main to int +n = long 0 +if not testadd +n = write int 1 tadd ulong 0 len tadd +ret int sub n sub n long 1 +end +if not testmul +n = write int 1 tmul ulong 0 len tmul +ret int sub n sub n long 1 +end +if not edges +n = write int 1 tedge ulong 0 len tedge +ret int sub n sub n long 1 +end +if not slices +n = write int 1 tslc ulong 0 len tslc +ret int sub n sub n long 1 +end +if not unary ulong 0 +n = write int 1 texh ulong 0 len texh +ret int sub n sub n long 1 +end +for w ulong 8 +if not unary sub shl ulong 1 add w ulong 1 ulong 1 +n = write int 1 texh ulong 0 len texh +ret int sub n sub n long 1 +end +if not pairs sub shl ulong 1 add w ulong 1 ulong 1 +n = write int 1 texh ulong 0 len texh +ret int sub n sub n long 1 +end +end +n = write int 1 tpass ulong 0 len tpass +ret int sub n n +end diff --git a/spec/.crumb b/spec/.crumb index a226ce192..b94c23f39 100644 --- a/spec/.crumb +++ b/spec/.crumb @@ -20,14 +20,14 @@ } ], "children_root": "sha256:6834a3241647d3a098283d4eafedbdb1428dfa4d834f9ed5f22025b6d2303093", - "compiled_at": "2026-10-30T11:28:28Z", + "compiled_at": "2026-10-30T14:45:08Z", "compiler": "crumb-compile/1", - "digest": "sha256:f765ad87fdddd9b47f690b07298c951a0f7e7675dc5de4ffe44e33a0c14b1986", + "digest": "sha256:b0dbb6b57430fc910c245cac7044f627b5c99a627db610f2bd7fb6f3ea3e7d2c", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 63, - "generated_at_commit": "a8a6a3d3c47ce797430f045edc5eae11594ba36d", - "source_tree": "sha256:4cb3bb1977c84caacc34366f814d6fe403a2eda7b89b916948d29541675c59bb" + "generated_at_commit": "06ecf3a74e2eeb75fe5f217b47878e9a5d419f54", + "source_tree": "sha256:b3778f7e7ec8110bd8adb6508ef627a8249586993500a3851b684b39e5bb30ca" }, "owner_lane": "", "provenance": { diff --git a/spec/quantities-and-modular.md b/spec/quantities-and-modular.md index 86f7dd7b7..88479c5ff 100644 --- a/spec/quantities-and-modular.md +++ b/spec/quantities-and-modular.md @@ -112,5 +112,5 @@ Nothing in this specification alters the semantics of existing modular types: ## 6. Implementation Status and Roadmap - **Phase 1 (This Slice, seed/omc)**: Add the `qty` type to the seeded self-hosting compiler `seed/omc/omc.om`, with checked `add`, `sub`, and `mul` trapping on overflow (`trap 1`), explicit conversion via `qty(...)`, compile-time refusal of implicit mixing with `ulong` (error 7), and slice invariants in `part`. -- **Phase 2 (Library & Nominals)**: Formalize `struct qty`, `struct qobj`, and `struct qslic` in the standard library (`om/quantity/`) for nominal sub-range capacities and explicit result codes (0 success, 1 invalid operand, 2 domain mismatch, 3 overflow/underflow, 4 object mismatch). +- **Phase 2 (Library & Nominals)**: Formalize `struct bqty` (named `bqty` because `qty` is the native Phase 1 keyword), `struct qobj`, and `struct qslic` in the standard library (`om/quantity/`) for nominal sub-range capacities and explicit result codes (0 success, 1 invalid operand, 2 domain mismatch, 3 overflow/underflow, 4 object mismatch). - **Phase 3 (Substrate Lowering & IR)**: Lower `qty` through intermediate representations with static range analysis and formal proofs for bounds check elimination.