0%

s05 — Driver Integration: oric Two-Hat Dispatch

Goal

oric carries a complete native_backend feature seam: cargo wiring, the shared compiled-backend dispatch, direct target selection including WASM, and native artifact handling — LLVM behavior byte-identical when the feature is off or unselected.

Implementation Sketch

Implements plans/backend-boundary; it does not mirror LLVM orchestration:

  • Workspace: register ori_backend, the backend-neutral ori_target crate, and the pure ori_codegen interface crate; oric/Cargo.toml gains the narrow optional ori_backend edge while shared realization/layout/interface crates remain independent of concrete backends.
  • Implement ori_codegen::CodegenBackend for ori_backend: immutable ExecutableProgram + explicit TargetSpec + matching CompiledLayoutPlan in; backend-private BIR/MIR stays inside compile; finalize returns the common typed relocatable-object or complete-WASM artifact, or a typed error. Do not add compile_to_native_* twins, a native_codegen_pipeline, or native-only artifact handling in oric; realization and compiled-layout planning run once before exhaustive dispatch.
  • CodegenBackendChoice { Llvm, Native } owns ori build selection. ExecutionBackend { Vm, Compiled(CodegenBackendChoice) } owns ori run/ori test; the user-facing --backend=native value maps to the compiled arm without duplicating orchestration. ORI_BACKEND follows the same typed precedence path.
  • TargetSpec is parsed/canonicalized outside concrete backends. A WASM target with CodegenBackendChoice::Native produces a complete WebAssembly module; an explicit runner/host adapter executes it when requested. No evaluator/VM routing exists for WASM.
  • RuntimeConfig::detect() reuse verified for native AOT linking (same libori_rt.a, same five-candidate search); the shared linker consumes the artifact’s typed link manifest without matching on concrete backend identity.
  • ori_compiler facade purity preserved: zero ori_backend dependency.

Test Strategy

  • Matrix: {feature on, feature off} x {—backend native, llvm, vm, unset} x {build, run, test} x {host, wasm target} — dispatch lands in the right typed arm with the right diagnostic every cell; build --backend=vm is rejected by construction.
  • Semantic pin: default build with feature ON but flag unset produces byte-identical LLVM behavior (two-hat invariant); negative pin: —backend=native without feature -> the new E-code, never a panic.
  • Evaluator/VM/LLVM parity remains green; native/WASM cells join the differential gate as they become runnable.

Work Items

  • ori_backend crate registered (workspace members + oric native_backend feature + explicit version); cargo build matrix green both feature states.
  • ori_backend implementation of ori_codegen::CodegenBackend over the one shared realization, explicit target, and compiled-layout path; private BIR/MIR plus typed native-object/complete-WASM finalization; architecture pins forbid native orchestration or post-codegen artifact forks.
  • Typed codegen/execution dispatch, target selection, --backend + ORI_BACKEND precedence, direct compiled WASM routing, and backend-unavailable E-code with spec-style diagnostic.
  • Dispatch test matrix (feature x flag x command) + two-hat semantic pin + negative pin; ori_compiler purity assertion (no ori_backend in its dep tree).