Skip to content

add implements support#1756

Queued
ricochet wants to merge 2 commits into
bytecodealliance:mainfrom
ricochet:worktree-implements
Queued

add implements support#1756
ricochet wants to merge 2 commits into
bytecodealliance:mainfrom
ricochet:worktree-implements

Conversation

@ricochet

Copy link
Copy Markdown
Contributor

Adds support for the component model implements proposal (WebAssembly/component-model#613 and WebAssembly/component-model#672):

  • import label: ns:pkg/iface / export label: iface in WIT: named (labeled) imports and exports of interfaces, including importing the same interface under multiple labels. Transpiled bindings import each label under its own specifier, and --map entries for the implemented interface id apply to labeled imports (label-specific mappings win)
  • resource-bearing interfaces imported under multiple labels resolve each label's resource class through that import instance's own resource table rather than the wit type, which is shared by all labels
  • jco types aliases each label to the shared interface module
  • @external-id("...") attributes round-trip through embed/new/print/wit
  • (implements "...") name validation is enabled during transpile via WasmFeatures::CM_IMPLEMENTS

Note: binaries carrying (external-id ...) names can be produced and printed but not yet transpiled. wasmtime-environ 47 embeds wasmparser 0.252, which predates external-id name-option parsing (0.253).

This also updates wasmtime-environ from 46.0.1 to 47.0.2, enabling its anyhow feature for error conversions. Migration notes:

  • the per-instance flags global now holds a single boolean may_leave flag rather than a MAY_ENTER|MAY_LEAVE bitmask, so the generated JS global is initialized to 1
  • wasmtime-environ 47's FACT-generated adapters wrap calls in exception barriers (try_table + catch_all) when the exceptions feature is enabled. The multi-memory augmenter learns to re-encode try_table, but the exceptions feature is masked off the transpile validator for now since the resulting core modules would only run behind --experimental-wasm-exnref in today's JS engines.

I went ahead and bumped js-component-bindgen to 2.1.0 as this is a new feature. Is that the preferred flow here?

vados-cosmonic
vados-cosmonic previously approved these changes Jul 23, 2026

@vados-cosmonic vados-cosmonic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

This is basically ready, nothing but nits here -- thanks for knocking this out @ricochet. Shame we can't fully be sure it will work given the lack of support of try_table/exnref across engines (TIL), but certainly happy to land support for this sooner rather than later.

Comment thread crates/js-component-bindgen/src/core.rs
Comment thread crates/js-component-bindgen/src/lib.rs Outdated
Comment thread crates/js-component-bindgen/src/transpile_bindgen.rs Outdated
Comment thread crates/js-component-bindgen/src/transpile_bindgen.rs Outdated
Comment thread crates/js-component-bindgen/src/transpile_bindgen.rs Outdated
Comment thread crates/js-component-bindgen/src/transpile_bindgen.rs Outdated
Comment thread crates/js-component-bindgen/Cargo.toml Outdated
Comment thread packages/jco-transpile/test/cm/implements.ts
ricochet added 2 commits July 23, 2026 10:49
Updates the wasmtime family (wasmtime, wasmtime-environ) from 46 to
47.0.2 (enabling wasmtime-environ's `anyhow` feature for error
conversions), the wasm-tools family (wasm-encoder, wasm-metadata,
wasmparser, wasmprinter, wat, wast, wit-component, wit-parser) from
0.253 to 0.254, and wit-bindgen(-core) from 0.59 to 0.60.

Migration notes:

- the per-instance flags global now holds a single boolean `may_leave`
  flag rather than a MAY_ENTER|MAY_LEAVE bitmask, so the generated JS
  global is initialized to `1`
- wasmtime-environ 47's FACT-generated adapters wrap calls in exception
  barriers (`try_table` + `catch_all`) when the exceptions feature is
  enabled. The multi-memory augmenter learns to re-encode `try_table`,
  and a new `supports_wasm_exnref` transpile option (default off)
  controls whether the exceptions feature is enabled during validation,
  since the resulting core modules only run behind a flag (e.g.
  --experimental-wasm-exnref) in today's JS engines.
Adds support for the component model `implements` proposal
(WebAssembly/component-model#613 and bytecodealliance#672):

- `import label: ns:pkg/iface` / `export label: iface` in WIT: named
  (labeled) imports and exports of interfaces, including importing the
  same interface under multiple labels. Transpiled bindings import each
  label under its own specifier, and `--map` entries for the
  implemented interface id apply to labeled imports (label-specific
  mappings win)
- resource-bearing interfaces imported under multiple labels resolve
  each label's resource class through that import instance's own
  resource table rather than the wit type, which is shared by all
  labels
- `jco types` aliases each label to the shared interface module
- `@external-id("...")` attributes round-trip through
  embed/new/print/wit
- `(implements "...")` name validation is enabled during transpile via
  `WasmFeatures::CM_IMPLEMENTS`

Adds an `implements-labels` rust test component exercising labeled
imports and exports end to end at runtime.

Note: binaries carrying `(external-id ...)` names can be produced and
printed but not yet transpiled -- wasmtime-environ 47 embeds wasmparser
0.252, which predates external-id name-option parsing (0.253); support
lands with the next wasmtime-environ release.

@vados-cosmonic vados-cosmonic left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀

@vados-cosmonic
vados-cosmonic added this pull request to the merge queue Jul 23, 2026
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