interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / docs / osc / ZIG-LESSONS-COMPTIME-INCREMENTAL.md

217 lines · 29145 bytes Raw Blame History Source

Zig lessons: bounded compile-time evaluation and incremental compilation

Decisions in short

  1. Compile-time evaluation: build a small first step (named integer constants that can stand where the parser today demands a literal) on top of the folding the checker already has. Do not build a compile-time function interpreter now. If one is ever built, it must meet the contract in "Decision for comptime", including an explicit step budget with its own refusal kind and no way to see the machine.
  2. Incremental compilation: do not build it now. The OSC compiler finishes a program in milliseconds. The build and test time is spent in sanitizer test binaries, which an incremental compiler would not touch. Define the cache key and the measurement that would justify a cache later, and build nothing until that measurement says so.

Context

Zig's compiler evaluates ordinary code at compile time under a budget, and its 0.17.0 release (2026-10-01) makes incremental rebuilds usable for most x86_64-linux projects. The review asked whether Omega should copy either idea. The right first question for each is what Omega already has and what it costs today. This record answers from the repository and from measurements, not from Zig's reputation.

What exists today

Constant folding in the checker

Where a literal is still required

The parser asks for an OT_INT token, with no names and no expressions, at: array length (osc_parse.c:118, range check 120-126, array length over 64 is CAPACITY), while ... bound N (908, range 1..1000000 at 910-915, limit defined at line 11), for i in A .. B (931-941), arena bound K (874-876), pool slot count (844) and pool generation base (860). Array lengths become numbers inside OscType while parsing (osc_parse.c:112-126), before the checker runs. const is a reserved word in the lexer (osc_lex.c:26), so no constant item syntax exists.

The language already terminates

There is no recursion and no forward reference (docs/osc/OSC-1-DESIGN.md:25, 111), and every loop has a literal trip bound of at most 1,000,000 (osc_parse.c:11, 910, 934). So every OSC program terminates. Termination is not the same as cheap: two nested maximal loops are 10^12 iterations.

The interpreter

Identities

The stores

Measured times

Measured 2026-10-13 on the DGX Spark, gcc -O2, build/compiler/oscc built with make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 oscc. Rows marked "given" come from the orchestrator and were not repeated by this record.

whatresult
largest test program tests/compiler/progs/oom.osc (3194 bytes)under 0.01 s, 8.2 MB peak RSS (given); re-measured with /usr/bin/time: 0.00 s wall, 8156 to 8216 KB over 3 runs; about 2 ms per run in a 10-run shell loop including process start
all 47 programs in tests/compiler/progs (40,529 bytes, 1,406 lines)0.089 s total (given); shell loop 112 to 121 ms over 4 runs, which includes starting 47 processes
synthetic near-ceiling unit: 16 functions x 200 statements (48,918 bytes, generated with a shell loop, not a real program)13 to 14 ms per run, 9.9 MB peak RSS; 32 functions x 200 statements is refused at the 32768-token cap (CAPACITY, osc_lex.h:14)
make test-compiler-quick, binaries already built28 s twice; 46 s when the seven test binaries had to be built first
the same quick steps timed one by one a few minutes later (other jobs on the machine, load average 1.8)ASan backend 19.0 s, ASan legacy writer 12.9 s, ASan compiler fuzz 7.2 s: 39.1 s of 40.7 s, about 96 percent. Every plain-build step is under 0.7 s (model 0.15 s, backend 0.24 s, compiler fuzz 0.14 s, legacy writer 0.04 s, determinism 0.36 s, caller self-test 0.62 s)
plain full-count legsmodel sweep at its default 10^6 sequences 1.4 s (test_osc_model default, tests/compiler/test_osc_model.c:8); legacy writer full differential 2.4 s; compiler tests at default counts 0.95 s
make test-compiler-full as a wholeNOT TIMED here. docs/osc/OSC-3-DESIGN.md:33-35 records 1m32 to 2m23 single core for the suite before the quick/full split

The quick figures vary by a third between runs because the machine is shared. The conclusions below do not depend on that spread.

Zig facts used (fetched 2026-10-13)

Decision for comptime

What I build first (named constants only)

Add integer constant items that are evaluated with the existing fold semantics and can appear wherever the parser today requires a literal: array length, loop bound, for range ends, arena bound, pool slot count, contract clauses and ordinary expressions.

What I do not build now (a compile-time function interpreter)

Running real functions at compile time through osc_interp_run is deferred, for three reasons found in the code:

  1. Ordering. Array lengths are fixed by the parser (osc_parse.c:112-126) and the interpreter runs on lowered IR, which exists only after the whole unit is checked (osc_front.c:57-58). A function result could therefore feed values, not array lengths, loop bounds or arena and pool sizes, unless the pipeline is restructured.
  2. Payoff. The IR has no optimisation pass that would use a computed value (OSC-1-DESIGN.md:38). I found no program in the corpus that needs one; UNVERIFIED, because I did not read all 47 programs for this.
  3. Risk. A second evaluator beside fold and ceval (osc_check.c:623, 756) is one more place for arithmetic to disagree. The interpreter is the arithmetic oracle (osc_interp.h:1-7), but it is not wired into the checker.

Contract if a function interpreter is ever added

The machine-specialisation invariant

A compile-time value must never carry information about the machine into the program's meaning.

Candidate uses

#usewhat proves it
1Named loop bound: const N: u32 = 8; then for i in 0 .. N or while c bound NA1 (same digests as the literal spelling), A2 (limit still enforced)
2Derived array length: [u32; LANES * 4]A3 (same digests; 64 + 1 refused CAPACITY like literal 65)
3Arena and pool sizing from one named constantA4 (ARENA_CAPACITY at 65 as in neg/ar_capacity_bound_65.osc; POOL_CAPACITY over 16)
4Contract limits: requires n <= MAX_NA5 (clause elided exactly as with a literal; a constant-false clause is CONTRACT_VIOLATION)
5Table value computed by a loop in a compile-time function (only if the function interpreter is built)B1 to B4: equals the run-time interpreter result, runs out of fuel in a defined way

Decision for incremental compilation

Do not build an incremental or cached compile path for the OSC compiler now.

The key, if a cache is ever built

key = SHA-256( "omega.cache.v1" 0x00
               || kind          (realization | verification-receipt)
               || semantic_id   (32 bytes)
               || machine_id    (32 bytes)
               || compiler_id   (32 bytes)
               || options_id    (32 bytes) )

Rules that keep a cache from weakening trust

The measurement that would justify building it

Add a shadow log first, with no cache behind it. For each candidate step (realization synthesis, verification, receipt production) write one line: key as defined above, kind, wall seconds. Collect it over a representative period of CI and development runs. Build the cache only if, from that log:

  1. the share of wall time spent on steps whose key was already seen is above a threshold, and
  2. the absolute saving is above a second threshold that clearly exceeds the cost of hashing inputs and reading an entry.

The thresholds are a policy call for Drake. Suggested starting values to argue with: 20 percent of step time and 60 seconds per day. Until that log exists the answer to "should I cache" is no.

What I will not do

Acceptance tests

Tier A (named constants). New programs follow the existing layout: positive programs in tests/compiler/progs/, refusals in tests/compiler/neg/ with the // expect: KIND object=NAME line=N header (test_osc_compiler.c:16, 686).

Tier B (only if a function interpreter is built).

Cache (only if the shadow log justifies it).

Open questions

  1. One evaluator or two. fold is a static function tied to the checker context (osc_check.c:623), but array lengths and loop bounds are read by the parser (osc_parse.c:118, 844, 876, 908, 931). Either move folding to a shared file that both use, or let the parser keep a small constant table and rely on test A7 to keep the two in step. This needs a decision from whoever owns the OSC front end.
  2. Surface syntax: reuse const (reserved, osc_lex.c:26) or a new word.
  3. Whether Tier B is wanted at all. It needs a named program that gains from it (candidate use 5), and a pipeline change so results can feed more than values.
  4. The default fuel number. 1,000,000 is a placeholder until B5 is measured.
  5. The mapping from an OscUnit digest to an Omega semantic ID. No code defines it today.
  6. A finding outside this record's scope, since confirmed and fixed: omega_realize_compute_triple_id used to write the code bytes only if they fit in its 4096-byte buffer after a 78-byte header, and otherwise returned an id that omitted them without any error, so for a realization over about 4018 bytes the triple id did not commit to the code. Issue #429, fixed in PR #430: the code bytes are now streamed into the hash in full and a length past capacity is refused; gate OMEGA_REALIZATION_ID_COVERS_ALL_CODE_PASS guards it.
  7. What compiler_id should be (binary digest, source-tree digest, or crumb digest), and who sets the cache thresholds.