Skip to main content

Module contract

Module contract 

Source
Expand description

Contract tables: a per-declaration fingerprint of each top-level module’s ABI.

A producer exports, for every top-level module m, const {prefix}_contract_entry* {prefix}_{m}_contract(size_t* out_len): a static table with one ContractEntry per declaration in m and its submodules, sorted ascending by id. Every generated consumer checks, when it loads the library, that each entry it was generated with is present in the producer’s table with an equal hash. Extra producer entries are fine, so adding a declaration never breaks a deployed binding, while removing or changing one is reported by its dotted path.

entries is the one function that computes a table. The #[weaveffi::module] macro, the CLI, and the C header generator all call it on the validated Model, so the two sides agree by construction.

  • The id is fnv1a64 of the declaration’s dotted path (kv.Store.put, kv.KvError, kv.stats.Summary).
  • The hash is fnv1a64 of a canonical signature string computed from the resolved model, never from source spelling: type aliases are already substituted, [u8] is already bytes, and every type is its resolved IDL spelling (see Ty’s Display). Docs, deprecation text, and error messages are excluded, and so is the order of sibling declarations, because each entry is independent.

The canonical strings are:

DeclarationSignature
function or interface member{kind} {name}({param}: {type}, ...) -> {type or void}, then throws, async, cancellable when set; kind is function, constructor, method, or static
recordrecord {name} {{field}: {type}, ...}
enumenum {name} {{Variant} = {value}, ...}, a rich variant followed by {{field}: {type}, ...}
callback interfacecallback {name} {{method}({param}: {type}, ...) -> {type or void}; ...}, a method followed by throws when set
error domainerrors {name} {{Code} = {value}, ...}, a code with fields followed by {{field}: {type}, ...}
interfaceinterface {name} (its members have their own entries)

Structs§

ContractEntry
One declaration’s entry in a module’s contract table.

Functions§

entries
The contract table of the top-level module root (which must be one of model’s roots): one entry per declaration in root and its submodules, sorted ascending by id.
fnv1a64
The 64-bit FNV-1a hash of data: tiny, dependency-free, and stable across platforms and Rust versions.