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 validated ExecutableProgram + explicit TargetSpec + matching CompiledLayoutPlan covering the trivial subset, with logical-event preservation, compiled-action satisfaction, and no-layout-rederivation 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/(ExecutableProgram->BIR),isel/,regalloc/,emit/,obj/module stubs;#![deny(unsafe_code)]except where encoders later require it; deps: ori_codegen, ori_ir, ori_types, ori_arc, ori_repr, ori_target, ori_registry, ori_stack — NEVER ori_llvm, ori_vm, or 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 preserves block structure, spans, and every frozen AIMS event’s stable identity, multiplicity, order, transfer edge, and cleanup obligation. Each event maps through the matchingCompiledLayoutPlanto the target-selected physical action; transitionalRc*instruction names are migration inputs, not the architectural contract. Type layouts and call ABIs are stable IDs intoCompiledLayoutPlan, not freshly classified BIR data. - Enum construction, match, projection, derive, and drop extensions retain semantic variant/field IDs plus a stable
CompiledEnumLayoutreference. No BIR node stores a copied tag index, payload index, or locally selected encoding. - BIR verifier: use-before-def, block connectivity, type/layout/ABI-ref resolvability, logical-event coverage, compiled-plan satisfaction, and a negative check that no BIR-local field offset/enum/call-ABI or ownership-policy decision exists. Every frozen event must appear exactly once with the same stable identity, multiplicity, order, transfer edge, and cleanup obligation, and its action reference must resolve to the matching
CompiledLayoutPlan. An identical physical-action multiset is required only for an identity adapter; another target may use a different physical sequence when the plan-satisfaction proof validates equivalent realization. TransitionalRc*/Burden*forms remain accepted migration carriers, never AIMS ground truth. 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 pins: the verifier FAILS when a deliberately mutated translation drops, duplicates, reorders, or remaps a logical event, or references an action outside the matching compiled plan (negative pins prove both checks have 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.
-
ExecutableProgram + explicit TargetSpec + matching CompiledLayoutPlan-> BIR translation for the trivial subset with span provenance, target/layout fingerprint validation, and stable layout/ABI references. - BIR structural verifier incl. exact logical-event coverage and compiled-plan-satisfaction checks; negative pins proving it rejects missing, duplicate, reordered, or invalidly mapped events.
- Golden-snapshot + property tests over the trivial-subset matrix (ori_test_harness, ORI_BLESS workflow).