s06 — BIR + Realized-ArcFunction Translation
Goal
ori_backend exists as a crate with the BIR core implemented per the s03 design — SoA storage, block params, reserved fact-slot side tables, structural verifier — and a translation from realized ArcFunction covering the trivial subset, with the RC-op-preservation invariant machine-checked.
Implementation Sketch
- Crate skeleton per the ori_llvm single-crate precedent:
compiler_repo/compiler/ori_backend/src/withbir/(IR types, builder, verifier),lower/(ArcFunction->BIR),isel/,regalloc/,emit/,obj/module stubs;#![deny(unsafe_code)]except where encoders later require it; deps: ori_ir, ori_types, ori_arc, ori_repr, ori_registry, ori_stack — NEVER ori_llvm, NEVER ori_canon. - BIR core per s03 doc: per-function SoA (
tags: Vec<BirTag>,data: Vec<BirData>,extra: Vec<u32>), blocks with params, terminators,Idxtype refs, span side table, fact side tables RESERVED (empty until s18: effects/return-provenance/reuse-events/uniqueness keyed by instruction index), free-slot recycling (Go freeValues pattern). - Translation (trivial subset first):
Let{Literal},Let{Var},Let{PrimOp},Apply(direct),Return,Jump,Branch— 1:1 lowering preserving block structure, spans, and EVERY RC op verbatim (none in the trivial subset yet; the invariant infrastructure still lands now). - BIR verifier: use-before-def, block connectivity, type-ref resolvability, and the RC-preservation check — count + multiset of (RcInc/RcDec/IsShared/Reuse/CollectionReuse/Burden*) ops per function MUST be identical pre/post translation (AIMS invariant 5: translation never adds/removes/moves RC ops). Burden* ops: lower like Rc* per the coexistence contract or reject with explicit diagnostic when ORI_DISABLE_BURDEN_OPS semantics demand (decision recorded at s03).
ensure_sufficient_stack(ori_stack) on recursive walks per compiler-ops discipline; 500-line file limit; tests in sibling tests.rs files.
Test Strategy
- Matrix: trivial-subset ArcInstr x {literal types int/float/bool/str-ref} x {straight-line, branch, jump-with-args} — translation correct per cell (golden BIR snapshots via ori_test_harness directives).
- Semantic pin: RC-preservation verifier FAILS on a deliberately mutated translation (negative pin proves the checker has teeth).
- Property test: translate-then-verify over generated trivial ArcFunctions (block/param shapes randomized).
Work Items
- ori_backend crate skeleton (module tree, deps, lint config) building green in the workspace.
- BIR core types: SoA storage + blocks/params/terminators + span table + reserved fact-slot side tables + slot recycling.
- Realized-ArcFunction->BIR translation for the trivial subset with span provenance.
- BIR structural verifier incl. the RC-op-preservation multiset check; negative pin proving it rejects a mutated translation.
- Golden-snapshot + property tests over the trivial-subset matrix (ori_test_harness, ORI_BLESS workflow).