Skip to main content

Module interface_table

Module interface_table 

Source
Expand description

The interface table: which interfaces this contract implements, collected by the linker from its #[contract] impl blocks.

Every #[contract] impl Trait for T (and every bare #[contract] impl T) expands to one 8-byte InterfaceId record via __interface_record!. implements! answers whether a given id is among them. This is what thruput-erc165-if builds supports_interface on: the claim is read off the impls that actually linked, so there is no list to maintain and nothing to get wrong.

§Layout and cost

On the guest the records use the entrypoint table’s shape: #[used] statics in the thruput_rv32_interfaces input section, which the runtime linker script KEEPs and brackets as its own output section. Whether that section reaches the deployed image is the lowerer’s call, made the way it already drops the raw spec section: the reader below touches a one-word anchor in thruput_rv32_interfaces_anchor, an ordinary GC-able section that survives the link only if the table reader behind implements! was instantiated. The lowerer copies the table into VM memory only when the anchor section is present. A contract with no ERC-165 impl therefore ships an image byte-identical to one built without this module; one with an impl pays four bytes of anchor plus 8 per impl block, plus the scan.

§What counts as “this contract”

The unit is the contract image, not the storage struct. A crate with impl X for A and impl Y for B links both into one image whose dispatch table answers to both interfaces at one address, so its table holds both ids and supports_interface says yes to both — which is the truth ERC-165 asks about. On the guest the table is simply the whole image. On the host, where one test process holds many contracts, the records go through a linkme slice keyed by the package that expanded them, name and version both, so implements! from inside a contract crate sees every impl block of that crate — A’s and B’s alike, the same as the guest — while another contract crate’s records, or another version of this one (a migration test may link two), stay apart. That is the scope the entrypoint guards and the mock registry already use for “one contract”.

Functions§

implements_in
True if the contract identified by package/version carries a #[contract] impl of the interface identified by interface_id.