Skip to main content

Module model

Module model 

Source
Expand description

The binding model: a normalized, fully-lowered view of an Api that every language backend consumes.

Before this module existed, each of the eleven generators re-walked the IR, re-derived the C ABI calling convention, and re-invented every emitted C symbol name. They drifted: iterators were lowered as lists in some targets, listeners were emitted only by the C header, and a custom c_prefix reached only the C and C++ outputs while the other nine hard-coded weaveffi_.

BindingModel::build walks the IR exactly once and produces a flat list of ModuleBindings in which:

  • every emitted C symbol name is precomputed once (so all backends agree by construction, and a non-default prefix is honored everywhere); and
  • every function/struct/callback is paired with its lowered AbiFn signature (built from crate::abi), so no backend re-derives parameter arity, ordering, or out_*/out_err placement.

A backend reads the idiomatic shape from the retained TypeRefs (param.ty, field.ty, …) and the native shape from the AbiFns, then writes only the marshalling that bridges the two in its own idioms. The hard, drift-prone facts live here; only language syntax lives in the backends.

Structs§

AbiFn
A single lowered C symbol: its name, ordered ABI parameter slots, and C return type. This is what a backend declares to its FFI layer and calls.
AsyncBinding
The lowered surface of an async function.
BindingModel
The whole API, normalized and lowered for code generation.
BuilderBinding
The fluent builder lowered for a struct that opted in with builder: true.
CallbackBinding
A callback function-pointer typedef declared at module scope.
EnumBinding
An enum, fully lowered.
EnumVariantBinding
A single enum variant with its precomputed C constant name.
ErrorBinding
The error domain in effect for a module: its own errors: block, or the nearest ancestor’s when the module declares none.
ErrorCodeBinding
One error code of a module’s error domain, with its C constant name.
FieldBinding
A struct field, retained with its getter symbol and lowered return.
FnBinding
A function, fully lowered.
InterfaceBinding
An interface (opaque object type), fully lowered.
IteratorBinding
The lowered surface of an iter<T>-returning function.
ListenerBinding
A listener: a register/unregister pair bound to a callback.
ModuleBinding
One module, flattened with its underscore-joined symbol path.
ParamBinding
One IR parameter, retained with its lowered ABI slots.
RichEnumBinding
The opaque-object surface of a rich (algebraic) enum: how its tag is read, how each variant is constructed and projected, and how the object is freed.
RichVariantBinding
One variant of a rich enum: its constructor and the getters for its associated data.
StructBinding
A struct, fully lowered.

Enums§

CallShape
How a function crosses the boundary. Exactly one shape applies to any given function: synchronous, asynchronous (callback-completed), or iterator-returning.

Functions§

iterator_item_ctype
The element C type of an iterator’s out_item slot (the pointee of T* out_item). Exposed for backends that materialize iterator results.