jrandolf opened PR #14867 from jrandolf:bindgen-labelled-imports to bytecodealliance:main:
This fixes several
bindgen!bugs with labelled (implements) imports and exports, one commit each:
- Plain and labelled import of one interface. A world like
import store; import a: store;generated the bindings module forstoretwice and failed with E0428. The same happened when the plain import came in throughuseorinclude(e.g.include wasi:cli/imports@0.3.0; import a: wasi:cli/environment@0.3.0;), in either order, and withwithremappings. Labelled imports now reuse the plain import's bindings, and the world'sadd_to_linkerbinds the interface under its own name and under each label.named_importskeys. A key naming an interface that exists but isn't imported by the world panicked the macro withno entry found for key; it's now an error. Keys are also matched the same way aswith, so an unversioned key applies to every imported version of the interface instead of just the first one found.@unstableon labelled imports. Every label of an interface got the feature gate of the first label, since the gate was looked up by interface id. It's now looked up by label.- Conflicting export names. Labels can clash with the modules and accessors generated for interface exports (e.g.
export foo: greeter; export greeter;in packagefoo:foo) or with the world's own methods. That used to generate code that failed to compile with confusing errors. It's now reported as an error naming both exports.There's no harness for proc-macro errors, so the error cases are unit tests in
crates/wit-bindgen/tests/errors.rsthat callOpts::generatedirectly. Most of the diff is new snapshots.Closes #14855
Closes #14856
jrandolf has marked PR #14867 as ready for review.
jrandolf removed the review request for wasmtime-core-reviewers from PR #14867.
jrandolf requested alexcrichton for a review on PR #14867.
jrandolf requested wasmtime-core-reviewers for a review on PR #14867.
github-actions[bot] added the label wasmtime:api on PR #14867.
:memo: alexcrichton submitted PR review.
:speech_balloon: alexcrichton created PR review comment:
Why is
clone_ofhandled here? I would naively expect that to not be necessary, but I could very well be missing something
:speech_balloon: alexcrichton created PR review comment:
This seems a bit odd here -- shouldn't this loop
breakof some kind once anamed_importskey is found? Otherwise multiple keys could be considered used despite only actually using one of them.
:speech_balloon: alexcrichton created PR review comment:
Personally I think it's ok to skip these tests for now. I think having things manually tested is generally fine for errors
:speech_balloon: alexcrichton created PR review comment:
I'm a bit hesitant about how ad-hoc this feels (and detection of duplicate exports). I think it's reasonable to detect this for an improved error, but I think it'd be best to integrate this in such a way where it's not just sprinkled in a few places which is quite easy to forget in the future.
Alternatively though this is a sign that we should generate bindings differently -- if an arbitrary
*.witfile can't be reflected into the bindings here that in-and-of-itself arguably a bug where the bindings should be adjusted.Would you be ok splitting this out to a separate PR or perhaps an issue to further discuss?
:speech_balloon: alexcrichton created PR review comment:
Does the handling of this map still need to be present in
import? For one-off maps like this I prefer to have the handling in as little places as possible as otherwise it can get pretty tough to see how this is changing over time.
:memo: jrandolf submitted PR review.
:speech_balloon: jrandolf created PR review comment:
Done
:memo: jrandolf submitted PR review.
:speech_balloon: jrandolf created PR review comment:
Done
:memo: jrandolf submitted PR review.
:speech_balloon: jrandolf created PR review comment:
Agreed, I've taken that commit out of this PR. I'll follow up separately, probably by looking at whether the bindings can be generated so these don't clash in the first place.
jrandolf edited PR #14867:
This fixes several
bindgen!bugs with labelled (implements) imports, one commit each:
- Plain and labelled import of one interface. A world like
import store; import a: store;generated the bindings module forstoretwice and failed with E0428. The same happened when the plain import came in throughuseorinclude(e.g.include wasi:cli/imports@0.3.0; import a: wasi:cli/environment@0.3.0;), in either order, and withwithremappings. Labelled imports now reuse the plain import's bindings, and the world'sadd_to_linkerbinds the interface under its own name and under each label.named_importskeys. A key naming an interface that exists but isn't imported by the world panicked the macro withno entry found for key; it's now an error. Keys are also matched the same way aswith, so an unversioned key applies to every imported version of the interface instead of just the first one found.@unstableon labelled imports. Every label of an interface got the feature gate of the first label, since the gate was looked up by interface id. It's now looked up by label.Most of the diff is new snapshots.
#14856 also covers labels clashing with the names generated for other exports. That's not fixed here; I'll follow up on it separately.
Closes #14855
jrandolf updated PR #14867.
jrandolf updated PR #14867.
:memo: jrandolf submitted PR review.
:speech_balloon: jrandolf created PR review comment:
wit-parser gives each labelled import its own copy of the interface (
clone_ofpoints at the original), while named-import bindings are generated once per interface, so the copies are skipped. I've added a comment saying so.
:memo: jrandolf submitted PR review.
:speech_balloon: jrandolf created PR review comment:
Done, the map is now only filled in up front and
importjust reads it.
:memo: jrandolf submitted PR review.
:speech_balloon: jrandolf created PR review comment:
Follow-up is #14891: the generated names are now chosen so they can't clash, instead of erroring.
jrandolf requested alexcrichton for a review on PR #14867.
jrandolf updated PR #14867.
:thumbs_up: alexcrichton submitted PR review.
alexcrichton added PR #14867 Fix bindgen! with labelled imports and exports to the merge queue.
:check: alexcrichton merged PR #14867.
alexcrichton removed PR #14867 Fix bindgen! with labelled imports and exports from the merge queue.
Last updated: Oct 31 2026 at 23:03 UTC