Skip to main content

Module marshal

Module marshal 

Source
Expand description

Strict-typed marshal layer for native module function dispatch.

Replaces the deleted Fn(&[ValueWord], &ModuleContext) -> Result<ValueWord> body shape (the dynamic-FFI escape hatch). Native function bodies now take typed Rust arguments that implement FromSlot; the function’s Rust signature is the typed signature, and the marshal layer cannot be registered against mismatching kinds because the Rust trait system rejects the [register_typed_fn_N] generic constraints.

Mirrors the structural-enforcement track from Phase 2a: forbidden mismatches are unrepresentable, not just unreachable. See docs/defections.md 2026-05-06 (Phase 2b unified marshal + wire/snapshot).

§What’s here

  • FromSlot / ToSlot: read/write a typed value from/to an 8-byte u64 slot. Each impl pins a single NativeKind via the associated constant.
  • MarshalError: typed error returned by the marshal boundary.
  • register_typed_fn_0register_typed_fn_3: per-arity registration helpers. Each wraps a body whose Rust parameter types carry the typed argument contract (each Pi: FromSlot).

§What’s not here yet

  • Higher-arity helpers (4+) — added on demand when stdlib migrations need them.
  • ToSlot for container TypedReturn variants (Ok/Err/Some/ ObjectPairs/etc.) — these need monomorphized heap representations and land alongside the per-stdlib-module migrations in Phase 2c.

Enums§

MarshalError
Typed error returned at the marshal boundary.

Traits§

FromSlot
Read a typed value from an 8-byte raw-bits slot.
ToSlot
Write a typed value into an 8-byte raw-bits slot.

Functions§

register_typed_async_fn_1
Register a 1-arg async native function. Body returns a Future; the dispatcher blocks on it at the call boundary.
register_typed_async_fn_2
Register a 2-arg async native function.
register_typed_async_fn_3
Register a 3-arg async native function.
register_typed_async_fn_1_full
Register a 1-arg async native function with full param spec.
register_typed_async_fn_2_full
Register a 2-arg async native function with full param spec.
register_typed_async_fn_3_full
Register a 3-arg async native function with full param spec.
register_typed_async_function
Register an async native function whose body inspects a variadic KindedSlot vector.
register_typed_fn_0
Register a 0-arg native function whose body takes only the ModuleContext and returns a TypedReturn.
register_typed_fn_1
Register a 1-arg native function. The body’s P0 parameter type declares the typed contract via FromSlot::NATIVE_KIND — there is no separate kind annotation to keep in sync.
register_typed_fn_2
Register a 2-arg native function.
register_typed_fn_3
Register a 3-arg native function.
register_typed_fn_4
Register a 4-arg native function with positional (name, type) param spec.
register_typed_fn_5
Register a 5-arg native function with positional (name, type) param spec.
register_typed_fn_6
Register a 6-arg native function with positional (name, type) param spec.
register_typed_fn_1_full
Register a 1-arg native function with full param spec (per-arg required + default_snippet).
register_typed_fn_2_full
Register a 2-arg native function with full param spec.
register_typed_fn_3_full
Register a 3-arg native function with full param spec.
register_typed_fn_4_full
Register a 4-arg native function with full param spec.
register_typed_fn_5_full
Register a 5-arg native function with full param spec.
register_typed_fn_6_full
Register a 6-arg native function with full param spec.
register_typed_function
Register a native function whose body inspects a variadic KindedSlot slice.

Type Aliases§

VariadicTypedAsyncBody
Body signature for a register_typed_async_function caller.
VariadicTypedBody
Body signature for a register_typed_function caller.