Skip to main content

Module closures

Module closures 

Source
Expand description

Per-program closure type collection + emission.

A $closure_<sig> rec-group type is needed wherever a function-typed value occupies a slot — which is wider than the set of closures the module builds, since the closure may be built by a caller in another package. The module’s own closure literals and adapters cover what it constructs; three collectors cover the shapes it only names:

  • CodegenAnalysis’s type funnel — every type the module mentions, after substitution: expression types, slot annotations, cast targets, plus the sigs the shape-dispatch paths build for themselves — a method call’s, from its own arity, and a property access’s () -> R / (W) -> void accessor branch, which is emitted whether or not an accessor is declared.
  • class_member_sigs — local class members, whose ABI is fixed by the declaration whether or not the module mentions them.
  • collect_from_dependencies — the imported surface of other packages.

Local interface and type declarations need no collector of their own: an object shape’s payload is a uniform (ref null $Object) array and casts test function fields signature-blind, so a member’s type never becomes a Wasm type on its own. The one thing a member does fix is the sig its dispatch goes through, and the funnel takes that from the call site — where the generics are already substituted, which the declaration’s spelling isn’t.

Missing a sig is an internal compiler failure, so these over-collect freely: emit_arity_closures dedups, and an unused shape costs one func type plus one struct type.

Structs§

ClosureMeta
ClosureMethods
ClosureSig

Functions§

allocate_methods
class_member_sigs
Closure signatures for each local class’s members — its own, and the ones it inherits from a dependency class. An instance flowing through an interface-typed receiver carries every method in its chain as a $closure_<sig> value in the object-fields payload.
classify
collect_from_dependencies
Consumer modules must re-declare these as a local closure rec group so import signatures and cast sites using (ref $closure_<sig>) resolve under WasmGC structural canonicalization.
declared_funcs
ref.func in a const-expr requires declarative element coverage; these are the target indices.
emit_arity_closures
Structural canonicalization unifies prelude and consumer copies at instantiation time.
emit_env_types
Must run after box_types::emit so env-field lookups for boxed captures resolve.
emit_func_and_struct_types
emit_method_bodies
emit_method_function_entries
Must be called after existing function-section entries so pre-allocated indices match.
emit_vtable_global