Skip to content

Add support for implements clause#1551

Draft
ricochet wants to merge 1 commit intobytecodealliance:mainfrom
ricochet:implements
Draft

Add support for implements clause#1551
ricochet wants to merge 1 commit intobytecodealliance:mainfrom
ricochet:implements

Conversation

@ricochet
Copy link
Contributor

@ricochet ricochet commented Mar 1, 2026

DO NOT MERGE until wasm-tools release with
bytecodealliance/wasm-tools#2453

The component model implements clause allows a world to import
or export the same interface multiple times under
different plain names.

This threads the new implements:Option<InterfaceId> field from
wit-parser through the WorldGenerator trait
and all backends (Rust, C, C++, C#, Go, MoonBit, Markdown).

A shared wasm_import_module_name helper
produces the [implements=<I>]label binary encoding.

Key per-backend concerns handled:

  • Type dedup: types are generated once per InterfaceId,
    not per label
  • Wasm names: all wasm-level import/export names use the
    implements encoding when applicable
  • Distinct bindings: each label gets its own
    module/namespace with independent function bindings

The component model `implements` clause allows a world to import
or export the same interface multiple times under
different plain names.

This threads the new `implements:Option<InterfaceId>` field from
wit-parser through the `WorldGenerator` trait
and all backends (Rust, C, C++, C#, Go, MoonBit, Markdown).

A shared `wasm_import_module_name` helper
produces the `[implements=<I>]label` binary encoding.

Key per-backend concerns handled:
- Type dedup: types are generated once per InterfaceId,
   not per label
- Wasm names: all wasm-level import/export names use the
  implements encoding when applicable
- Distinct bindings: each label gets its own
   module/namespace with independent function bindings
@alexcrichton
Copy link
Member

The guest side of things I think is going to be tricky in its own right compared to the host side of things. Notably if an interface is imported twice this'll need to generate two different types for all types contained within the interface. Without that it's not a reflection of the original WIT itself, so this means that (at least from my understanding at a skim) the duplicate-related handling will need to be removed.

To handle this though what I'd recommend is updating the Resolve::generate_nominal_type_ids method. That would transform imports of the same interface multiple times into imports of distinct interfaces which will make it much easier to support this in bindings generators (different InterfaceIds and TypeIds for different interfaces/types). The logic of generate_nominal_type_ids will be a bit tricky, but I think that's the best foundational primitive to use here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants