0%

s14 — ABI Obligations: FFI, Atomics/TLS, Inline-Asm Policy, WASM Glue

Goal

The remaining target-ABI obligations matrix closes: C FFI calling conventions per ISA (full aggregate/float rules, variadics), Deep-FFI surface (out params, [byte] elision, ownership), atomics policy, inline-asm policy record, and the WASM linear-memory/JS-glue ABI.

Implementation Sketch

  • Full C calling conventions per ISA beyond the s08/s09 subset: aggregate classification (SysV class algorithm, AAPCS64 HFA rules, RV64 2xXLEN rules, s390x by-reference rules, win64 shadow space), float/vector registers, struct-by-value both directions — consumed by extern “c” calls (spec Clause 26) and validated against C test shims compiled with the system cc.
  • C variadics (printf-class, unsafe-gated per spec): per-ISA va-call lowering.
  • Deep FFI: out params, owned/borrowed annotations, #error protocols, #free Drop wiring, [byte] -> (ptr,len) elision — emission parity with the LLVM backend per the platform-ffi proposal surface.
  • Atomics/TLS: atomic RC is the only shipped compiled mechanism, so it conservatively satisfies both neutral ThreadReachability values. RL-19–21 shall freeze thread reachability in AIMS; CompiledLayoutPlan then selects and validates atomic or thread-confined mechanics and the native emitter encodes the plan’s ordering. The transitional RcAtomicity enum is not the calculus authority. TLS remains only where the runtime contract demands it (audit, likely none).
  • Inline-asm policy: DECISION RECORD only (Ori has no inline-asm surface; asm is a reserved future keyword) — the backend reserves an escape-hatch design but ships nothing.
  • WASM ABI: direct compiled-module linear-memory exports (__ori_alloc/__ori_free), JsValue handle slab, JsPromise resolution points, JS glue + TS declarations parity with the existing LLVM WASM path (aot/wasm/ precedent), and WASI posture. The ABI is represented in shared TargetSpec/CompiledLayoutPlan data; ori_backend owns module/glue emission, with no evaluator or VM mode.

Test Strategy

  • Matrix: FFI shape {scalar args, aggregates by-value both ways, floats, mixed, out-params, variadic, [byte] elision} x native ISA, validated by C shim round-trips (compile shim with cc, call across, assert bit-exact); wasm cells via JS host harness.
  • Semantic pin: per-ISA one aggregate-classification pin (a struct that classifies differently across ISAs lands in the documented registers/stack slots — disassembly-pinned).
  • Negative pin: an ABI-mismatch fixture (wrong classification, test-only) fails the round-trip, proving the harness detects miscompilation.

Work Items

  • Full per-ISA C calling-convention implementation (aggregate classification, floats, both directions) + C-shim round-trip harness.
  • Variadic calls + Deep-FFI surface (out params, ownership, error protocols, [byte] elision) at parity with the LLVM backend.
  • Atomics audit + RC atomic-ordering conformance; TLS audit; non-atomic-RC future recorded as fact-gated.
  • Inline-asm policy decision record (reserved escape hatch, nothing shipped).
  • WASM linear-memory/JS-glue/WASI ABI at parity with the existing wasm path; FFI matrix green incl. negative ABI pin.