Hand-written Cranelift calls bypass the shared ABI catalog and desynchronize JIT, AOT, and runtime extern "C-unwind" implementations.
Design model
Platform spec article
Design model
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”Document the dual registry that connects Beskid lowered code to the host runtime: symbolic names for the linker (RUNTIME_EXPORT_SYMBOLS) and machine signatures for Cranelift (BUILTIN_SPECS).
Primary actors
Section titled “Primary actors”| Actor | Artifact |
|---|---|
beskid_abi::builtins | BuiltinFnSpec { symbol, params, returns } entries |
beskid_abi::symbols | SYM_* constants + RUNTIME_EXPORT_SYMBOLS list |
beskid_codegen | declare_builtin_imports builds Cranelift FuncIds from specs |
beskid_runtime::builtins | #[unsafe(no_mangle)] pub extern "C-unwind" implementations |
Builtin families
Section titled “Builtin families”| Family | Examples | Consumer |
|---|---|---|
| Allocation / values | alloc, str_new, str_concat, array_new | All backends |
| GC | gc_write_barrier, gc_collect, gc_root_handle | Lowering + host snapshots |
| Fibers | fiber_spawn, fiber_yield, fiber_join_value | corelib_concurrency |
| Channels / hubs | channel_send, hub_wait_receive_value | Concurrency package |
| Sync | mutex_lock, wait_group_wait | Runtime scheduler |
| Interop | interop_dispatch_unit, interop_dispatch_ptr | Tagged interop lowering |
| IO / faults | syscall_write, panic, panic_str | Corelib + traps |
| Diagnostics | test_bytes_ptr (test-only) | Compiler tests |
Return kinds include AbiReturnKind::Never for diverging panic calls so Cranelift marks unreachable correctly.
Data layout contracts
Section titled “Data layout contracts”BeskidStr:{ ptr, len }UTF-8 bytes (immutable; length in bytes).BeskidArray:{ ptr, len, cap }; element storage optional behind runtimearrays_backingfeature (Runtime feature flags).
Registry diagram
Section titled “Registry diagram”flowchart LR specs[BUILTIN_SPECS signatures] names[RUNTIME_EXPORT_SYMBOLS] clif[Cranelift imports] nm[no_mangle exports] specs --> clif names --> nm clif -->|same symbol string| nm
Related topics
Section titled “Related topics”- ABI versioning — when to bump version after symbol changes
- Flow and algorithm