FFI and C ABI specification
Decision summary
Section titled “Decision summary”- External calls use C ABI.
- FFI boundary types are restricted to primitives and explicit layout structs.
Ownership split
Section titled “Ownership split”- Language-level extern syntax and type diagnostics are defined in
docs/spec/ffi-and-extern.md. - This document defines runtime-side ABI mapping and call-boundary behavior.
Allowed FFI types (v0.1)
Section titled “Allowed FFI types (v0.1)”i64,f64,bool(asi8),ptr,unit.stringpassed as{ptr, len}.arraypassed as{ptr, len, cap}.
Ownership rules
Section titled “Ownership rules”- External functions do not take ownership of GC-managed pointers unless documented.
- Passing GC-managed pointers requires them to be pinned or protected during the call.
ABI mapping
Section titled “ABI mapping”- Use Cranelift default calling convention for target ISA.
- All FFI function signatures declared via
cranelift_module::Module::declare_function.
Runtime boundary rules
Section titled “Runtime boundary rules”- JIT and AOT must bind extern calls through the same ABI-compatible signature surface.
- FFI behavior must not bypass runtime ownership for syscall/platform policy.
- FFI adaptation logic belongs in runtime and standard library layers, not semantic analysis.
- FFI is optional in v0.1; standard library can wrap FFI when needed.
Non-goals
Section titled “Non-goals”- Defining language-level
Externattribute syntax. - Defining backend packaging/link orchestration policy.