0%

s05 — Driver Integration: oric Two-Hat Dispatch

Goal

oric carries a complete native_backend feature seam: cargo wiring, --backend flag, compile_to_native_* entry chain, and a native codegen pipeline shell — LLVM behavior byte-identical when the feature is off or unselected.

Implementation Sketch

Follows the ori_llvm integration pattern verified at plan time:

  • Workspace: ori_backend crate registered in compiler_repo/Cargo.toml members; oric/Cargo.toml gains native_backend = ["dep:ori_backend", "dep:ori_arc", "dep:ori_repr"] (ori_arc/ori_repr shared with the llvm feature); explicit version string per the ori_llvm precedent.
  • oric/src/lib.rs: #[cfg(feature = "native_backend")] module declarations mirroring the llvm-gated set (lib.rs:64-79 precedent); NO new compile_error gate (optional backend; degraded paths suffice).
  • Entry chain: compile_to_native_with_imported_monos / compile_to_native_with_imports in commands/compile_common.rs mirroring lines 134/194; commands/native_codegen_pipeline/mod.rs shell that REUSES run_borrow_inference + compute_aims_contracts + compute_module_repr_plan (all backend-agnostic — they produce ArcFunction/contracts/ReprPlan, not LLVM artifacts) and hands realized ArcFunction + ReprPlan to ori_backend.
  • build_file dispatch at commands/build/mod.rs:87-106: --backend=native branches before the single/multi split; dual stub per the cfg(not) precedent at mod.rs:108-124 with a new E-code for backend-unavailable.
  • BuildOptions: backend: BackendChoice field (always-compiled enum like Backend; mirrors NarrowingPolicy placement precedent at build_options/mod.rs:71); env override ORI_BACKEND=native applied after CLI merge per the ORI_NO_REPR_OPT pattern (build_options/mod.rs:402-405).
  • RuntimeConfig::detect() reuse verified for native AOT linking (same libori_rt.a, same five-candidate search).
  • ori_compiler facade purity preserved: ZERO ori_backend dependency (WASM playground stays interpreter-only).

Test Strategy

  • Matrix: {feature on, feature off} x {—backend native, llvm, unset} x {build, run, test} — dispatch lands in the right arm with the right diagnostic every cell.
  • 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.
  • Dual-execution parity untouched: full ./test-all.sh green.

Work Items

  • ori_backend crate registered (workspace members + oric native_backend feature + explicit version); cargo build matrix green both feature states.
  • compile_to_native_* entry chain + native_codegen_pipeline shell reusing run_borrow_inference/compute_aims_contracts/compute_module_repr_plan.
  • build_file + run/test dispatch on BuildOptions.backend + —backend flag + ORI_BACKEND env (CLI-wins precedence) + 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).