Skip to content

Add support for implements clause#1551

Draft
ricochet wants to merge 1 commit into
bytecodealliance:mainfrom
ricochet:implements
Draft

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

Conversation

@ricochet

@ricochet ricochet commented Mar 1, 2026

Copy link
Copy Markdown
Contributor

The implements clause lets a world import or export the same interface multiple times under different plain names:

world runner {
  import primary: store;
  import backup:  store;
}

No bindings-generator changes needed. wit-parser surfaces each label as a plain-name interface import/export, generate_nominal_type_ids gives each its own type identity, and the existing plain-name interface code path emits label-named modules and wasm_import_modules.

The test covers Rust, Go, and WAT runners with Rust and Go tests, composed via compose.wac so the two labels resolve to two independent store instances.

Temporary, until releases catch up:

  • wac is pointed at the implements branch; composition support for the clause is not yet in a released wac.
  • CI's wasmtime is pinned to the dev build; the implements has landed on wasmtime main but is not yet released.

@alexcrichton

Copy link
Copy Markdown
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.

multiple times under different plain names:

    world runner {
      import primary: store;
      import backup:  store;
    }

No bindings-generator changes needed. wit-parser surfaces each label as
a plain-name interface import/export, `generate_nominal_type_ids` gives each
its own type identity, and the existing plain-name interface code path emits
label-named modules and `wasm_import_module`s.

The test covers Rust, Go, and WAT runners with Rust and Go tests, composed
via `compose.wac` so the two labels resolve to two independent `store`
instances.

Temporary, until releases catch up:
- `wac` is pointed at the `implements` branch; composition support for the
  clause is not yet in a released wac.
- CI's wasmtime is pinned to the `dev` build; the clause has landed on
  wasmtime `main` but is not yet released.

Signed-off-by: Bailey Hayes <bailey@cosmonic.com>
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