Hand-written Cranelift calls bypass the shared ABI catalog and desynchronize JIT, AOT, and runtime extern "C-unwind" implementations.
Flow and algorithm
Platform spec article
Flow and algorithm
Spec standingStandard
-
Codegen must not invent alternate calling conventions for runtime builtins.
Context
Decision
Rule Detail Catalog BUILTIN_SPECSinbeskid_abi::builtinsis the sole source of Cranelift import signatures (ABI-002)Codegen declare_builtin_importsbuildsFuncIds only from specsDiverging builtins AbiReturnKind::Neverforpanicso unreachable blocks are correctParity Symbol strings in specs must match RUNTIME_EXPORT_SYMBOLSentries (ABI-001)Consequences
New builtins require spec,
BUILTIN_SPECS,symbols.rs, andbeskid_runtime::builtinsin one change set.Verification anchors
compiler/crates/beskid_codegen;compiler/crates/beskid_abi/src/builtins.rs. -
no_mangle extern C-unwind symbols implement the stable host surface.
Context
Generated code calls runtime entrypoints across JIT relink and AOT link. Rust panics across the boundary must use the platform unwind ABI expected by Cranelift
callsites.Decision
Rule Detail Export attribute Implementations use #[unsafe(no_mangle)] pub extern "C-unwind"inbeskid_runtime::builtinsRegistry RUNTIME_EXPORT_SYMBOLSlists every export the linker/JIT registersLayout types BeskidStr{ ptr, len }andBeskidArray{ ptr, len, cap }are normative payload headersFamilies Allocation, GC, fibers, channels, interop dispatch, IO, and panicshare one catalogConsequences
Host tooling resolves imports by symbol name +
BUILTIN_SPECSsignature, not Rust mangling.Verification anchors
compiler/crates/beskid_runtime/src/builtins/mod.rs;compiler/crates/beskid_runtime/src/lib.rsre-exports.
- Contracts and edge cases MUST rules for builtin signatures, return kinds, and export name stability.
- Design model BuiltinFnSpec catalog, runtime export symbols, and codegen import boundaries.
- Examples Reading BUILTIN_SPECS, mapping symbols to runtime modules, and typical call patterns.
- FAQ and troubleshooting Builtin symbol drift, signature mismatches, and codegen/runtime debugging.
- Flow and algorithm From lowering call sites through BUILTIN_SPECS to runtime C exports.
- Verification and traceability Crate paths and tests that pin builtin specs to runtime exports.
0 revisions (git unavailable at build; counts may be empty)
No commits recorded for this path.
| Section id | Required | Found |
|---|---|---|
what-this-feature-specifies | yes | yes |
implementation-anchors | yes | yes |
Full tree: run pnpm verify:platform-spec-layout (writes src/generated/platform-spec-layout-report.json).
Purpose
Section titled “Purpose”Trace how a builtin reference in CLIF becomes a live function pointer at run time. Registry diagram: design model.
Lowering to import declaration
Section titled “Lowering to import declaration”- HIR/lowering selects a runtime operation (allocate string,
fiber_yield, etc.). - Codegen emits a
callto the stable symbol string (for examplealloc, not a mangled Rust name). - During JIT
compile,declare_builtin_importswalksBUILTIN_SPECSin declaration order. - For each spec, codegen maps
AbiParamKind::Ptrto the host pointer type andI64toi64, then sets return type fromAbiReturnKind.
Runtime entry
Section titled “Runtime entry”- Generated code calls using the platform default calling convention (SysV on Linux x86_64).
- The runtime builtin enters
enter_runtime_scope/ GC rules as needed (alloc, barriers). - Fiber/channel builtins park or enqueue work via
beskid_runtime::schedulerwithout exposing scheduler internals to CLIF.
String builtin algorithm (str_concat)
Section titled “String builtin algorithm (str_concat)”- Read
BeskidStrheaders for left and right operands. - Allocate a fresh buffer via
allocfor combined byte length. - Copy UTF-8 payload; return new
{ ptr, len }handle. - On allocation failure or null inputs, trap via
panic(no implicitOptionat ABI layer).
GC barrier hook
Section titled “GC barrier hook”- Lowering emits
gc_write_barrier(parent, child)after pointer stores when concurrent GC is active. - Runtime barrier ensures tri-color invariant (see Memory and GC).
- Phase A may simplify barrier work when only one mutator runs; symbol remains reserved.
Related topics
Section titled “Related topics”- Contracts and edge cases
compiler/crates/beskid_abi/src/builtins.rs— full spec table