Research / Compiler, backends and verification

P46 · full · draft

A Compiler in Its Own Language as a Byte-Exact Differential Oracle

partial full Compiler, backends and verification

State of the work. A native source-to-source chain exists on main and is byte-exact on enumerated corpora (401 of 403 documents by the residual ledger); the self-host type checker is not the reference checker, there is no bootstrap fixed point, and the defect census and mutation analysis are still needed.

This is a draft, not peer reviewed. Repository references link to revl at commit 45bec431f.

Pitch

Writing the compiler a second time in the language it compiles, holding all six emitters to the reference's bytes and the front end to its accept/reject and canonical-shape results, turned the second implementation into a bug finder on its own side (the reference side yielded one reported smell and two replicated latent divergences), and produced a native chain that compiles revl source to target source with no reference in it, byte-exact on 401 of 403 corpus documents.

Abstract

A self-hosted compiler is usually sold as a bootstrap milestone. We use one differently: as a differential oracle. revl is a language for agent compositions with a Python reference compiler. We wrote a second implementation in revl itself: lexer, parser, expression checker, a lowering pass that doubles as an admission gate, a type layer, and emitters for six targets (Python, TypeScript, Go, Java, Rust, WebAssembly text). The six emitters are each held to the reference's bytes; the front end is held to the reference's accept/reject and canonical shape. A driver composes the stages into one co-compiled artifact that goes from source text to target source with the reference absent from the chain, which separates the emitters (byte-exact on the reference's IR for every document of every tier's corpus, 403 documents by corpus lists) from the native IR producer (the only remaining gap: two documents, one ts and one rust, per a pinned ledger). A paired measurement, emitter fed the reference IR versus the whole native chain, locates every divergence in one half; an earlier snapshot shows 255 of 255 versus 216 of 255 before the producer was widened. We report defects the oracle found (a missing keyword and a template encoding ambiguity found by fuzzing, both on the self-host side). We also report a secret-redaction port missing from the self-host emitters that every green oracle missed, because no corpus document used it, and that a source-level blind-spot check found. And the limits: the oracle only covers what its corpus exercises, the self-host gate does not implement several guarantees, and the self-hosted compiler is itself compiled by the reference, so there is no bootstrap fixed point.

Problem and claim

A compiler with one implementation has no oracle other than its own tests. Differential testing across independent implementations is cheap when they exist, but building a second compiler is expensive and rarely done. The self-hosting literature treats the second compiler as a bootstrap goal and measures speed or independence from a host language.

The claim of this paper is narrower and checkable. Treat the self-hosted compiler as the second implementation and hold the emitters to byte equality with the reference on all six emitted tiers, and the front end to the reference's accept/reject and canonical shape. Then (1) disagreements are defects in one side, with evidence from this project; (2) a paired measurement (emitter on reference IR, versus the fully native chain) tells which half is wrong, which a single end-to-end number cannot; (3) the end-to-end chain exists with no reference in it for the covered surface.

The paper does not claim that the self-hosted compiler is a complete compiler (docs/selfhost-findings.md:1-19 says the purpose was the oracle, "not self-hosting"), that it is the checker the language relies on (README.md:268-281 names the implementation as the live checker), or that agreement implies correctness: "a differential oracle only covers what its corpus exercises" (docs/selfhost-findings.md:81-84).

Contributions

  1. A self-hosted front end and six emitters in selfhost/*.rvl (12 files: lexer, parser, checker, lower, types, compile, emit_{py,ts,go,java,rust,wasm}), about 75.5k lines in total by wc -l (75,495), with the emitters held to the reference's bytes.
  2. A composed driver, compile_to_at(source, tier, path), co-compiled in one artifact: admit, lower to IR, parse JSON, emit. Unsupported cases return named refusals (REFUSED|LINK|...) rather than output that differs from the reference (docs/selfhost-compile.md:25-64).
  3. The paired measurement: each document's emitter output on the reference IR versus through the whole native chain, asserted per document and recomputed every run, with the residual pinned in a ledger (LOWER_GAP_DOCS) (tests/test_selfhost_compile.py:874-920).
  4. A catalogue of defects the oracle found, and a defect class the byte-agreement oracles missed (secret redaction missing at both ends), which a source-level blind-spot check found, and a coverage gate built in response (docs/selfhost-findings.md:81-112, docs/selfhost-findings.md:1466-1530; tests/test_selfhost_coverage.py:1-20).
  5. A measured account of what a byte oracle for WebAssembly text costs: scalar corner first, then string data, list and product-type allocation, tagged cells (docs/selfhost-findings.md:137-165, docs/selfhost-findings.md:701, docs/selfhost-findings.md:1289, docs/selfhost-findings.md:1347).
  6. A published list of what the self-host gate does not decide (G5, G7, G9, A2, A8, A9, G-RETAIN, G-SECRET-FLOW unimplemented; G1, G2, G3, G6 with divergences noted) (docs/conformance.md:223-271).

Evidence on main

Claimpath:line or testStatusNote
Twelve self-host source filesselfhost/*.rvl (lexer 822, parser 1339, checker 4176, lower 36635, types 859, compile 2788, emit_go 5401, emit_java 3993, emit_py 5028, emit_rust 6969, emit_ts 4900, emit_wasm 2585 lines)shippedwc -l
Native chain, no reference in it, byte-exact vs referencedocs/selfhost-compile.md:313-366; tests/test_selfhost_compile.py:281 (test_native_compile_is_byte_identical_with_no_reference)shippedParametrized headline over one function document per tier, not the corpus. Corpus-wide native agreement is the row below (test line 874, part b)
Six emitters co-compile in one artifacttests/test_selfhost_compile.py:1854 (test_six_way_composition_co_compiles)shipped
Emitter byte-exact on reference IR for all corpus documents; residual is in lower.rvltests/test_selfhost_compile.py:874 (test_the_residual_is_located_in_lower_not_in_the_emitter)shippedRecomputed each run
Residual ledger: ts 1 doc, rust 1 doc, others nonetests/test_selfhost_compile.py:492; docs/selfhost-findings.md:1770-1808shippedGenerated blocks in the doc
Corpus sizes py 106, ts 82, go 78, java 61, rust 54, wasm 22tests/test_selfhost_emit_py.py, tests/test_selfhost_emit_ts.py, tests/test_selfhost_emit_go.py, tests/test_selfhost_emit_java.py, tests/test_selfhost_emit_rust.py, tests/test_selfhost_emit_wasm.py (CORPUS lists)shippedCounted by parsing list literals, not by running
Parser and checker differential vs reference incl. fuzztests/test_selfhost_parser.py; tests/test_selfhost_checker.py:1-30; docs/selfhost-findings.md:113-127shippedExpression layer only. Compared as accept/reject and canonical S-expression shape, not bytes; messages are not compared
Conformance column: 59 of 61 constructs byte-identical through the native chain (py tier)docs/conformance.md:100-110, docs/conformance.md:148-162; README.md:283-286shippedOnly emit_py_src is used for this column
Self-host gate is not the reference gatedocs/conformance.md:223-271; README.md:288-293; tools/gate_reference_census.py:1-25shipped (as a documented gap)
Oracle blind-spot gatestests/test_selfhost_coverage.py:1-20; tests/test_selfhost_line_coverage.py:1-25shippedAnalysis belongs in P47
wasm emitter widened past the scalar cornerdocs/selfhost-findings.md:701, docs/selfhost-findings.md:1289, docs/selfhost-findings.md:1347shippedNon-ASCII string literals out (docs/selfhost-findings.md:733)
emit_rust.rvl emitted to rust builds and runs, matching referencedocs/selfhost-compile.md:384-480 (open status at 403-405; later blockers closed at 409+); tests/test_selfhost_emit_rust.py:978 (test_the_rust_emitter_builds_as_rust, skips without cordis-rs)partialcompile.rvl itself cannot be emitted to rust (needs @rs body for py_repr, doc line 476)
Bootstrap fixed point (compiler compiles itself and output compiles itself)nonenot presentFixture compile_rvl loads selfhost/compile.rvl through the reference (tests/test_selfhost_compile.py:122-127)

The wasm emitter has been widened past the scalar corner (docs/selfhost-findings.md:701, docs/selfhost-findings.md:1289, docs/selfhost-findings.md:1347; the scalar-only text is the first slice, docs/selfhost-findings.md:137-165). "Six-tier byte-exact self-compile" needs the qualifier that two documents (one ts, one rust) still fall outside the fully-native chain (tests/test_selfhost_compile.py:492).

Numbers that exist

Paper outline

  1. Introduction: second implementation as oracle, not as milestone.
  2. The reference compiler and the interchange IR: what is compared (bytes at stage boundaries).
  3. The self-host: stages, the language features it needed (recursive ADTs, no Map for the parser, friction table).
  4. The native driver and its refusal discipline (named refusals instead of divergent output).
  5. The paired measurement and the ledger that ratchets it.
  6. What the oracle found; the secret-redaction miss and the coverage gates.
  7. Cost of a byte oracle per target, with WebAssembly as the worst case.
  8. Limits: gate not equal to the reference gate, corpus dependence, no fixed point, no performance.
  9. Related work.

Threats to validity and limits

Fact-check

Claims in this draft were checked against revl main at commit 45bec431f: about 60 checked, 9 corrected.

Cite this draft

@misc{revlp46,
  author       = {Thomas Moussajee},
  title        = {A Compiler in Its Own Language as a Byte-Exact Differential Oracle},
  year         = {2026},
  howpublished = {\url{https://inso1337.github.io/revl/research/P46.html}},
  note         = {Research draft, not peer reviewed. Written against revl commit 45bec431f. Licensed CC BY 4.0.}
}

Text licensed CC BY 4.0, author Thomas Moussajee.

← All research drafts