fix: disambiguate colliding WIT import names#1562
Open
jsturtevant wants to merge 2 commits into
Open
Conversation
Contributor
Author
|
This will be ontop of #1331 |
736b4f5 to
6ff506c
Compare
7b9e0ba to
9d108b5
Compare
9d108b5 to
2ff2286
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates Hyperlight’s component bindgen to avoid Rust trait member name collisions when multiple WIT imports share the same short interface name by generating namespace-qualified (and version-qualified) member names, and expands the bindgen-test-cases WIT fixture to cover these collision scenarios.
Changes:
- Introduces collision detection for imported instance names and emits disambiguated associated type + getter names via
import_member_names. - Threads collision info through codegen state so related emit paths (including resource/typevar references) can use the disambiguated member names.
- Extends the
bindgen-test-casesWIT fixture with multiple colliding imports (including versioned imports and hyphenated namespace edge cases).
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/tests/rust_guests/witguest/bindgen-test-cases/world.wit | Adds imports that intentionally collide to exercise disambiguation logic. |
| src/tests/rust_guests/witguest/bindgen-test-cases/deps/a-pkg/types.wit | Adds a:pkg/types dependency interface for collision fixture. |
| src/tests/rust_guests/witguest/bindgen-test-cases/deps/b-pkg/types.wit | Adds b:pkg/types dependency interface for collision fixture. |
| src/tests/rust_guests/witguest/bindgen-test-cases/deps/c-pkg-v1/types.wit | Adds c:pkg@1.0.0 dependency interface for version collision fixture. |
| src/tests/rust_guests/witguest/bindgen-test-cases/deps/c-pkg-v2/types.wit | Adds c:pkg@2.0.0 dependency interface for version collision fixture. |
| src/tests/rust_guests/witguest/bindgen-test-cases/deps/a-bc/types.wit | Adds a:b-c/types dependency interface for hyphenated namespace fixture. |
| src/tests/rust_guests/witguest/bindgen-test-cases/deps/ab-c/types.wit | Adds a-b:c/types dependency interface for hyphenated namespace fixture. |
| src/hyperlight_component_util/src/emit.rs | Adds collision detection + naming helpers, stores collision set in State, and adds unit tests around name parsing/disambiguation. |
| src/hyperlight_component_util/src/rtypes.rs | Switches instance-member emission to use disambiguated names and threads collision set into resource/typevar emission paths. |
| src/hyperlight_component_util/src/host.rs | Uses disambiguated member names when generating host-side import handling. |
| src/hyperlight_component_util/src/guest.rs | Uses disambiguated member names when generating guest-side import handling. |
4d3a303 to
5af128b
Compare
Apply collision-aware import member naming across host, guest, resource, and type-variable codegen. Keep bare imports stable, qualify namespaced collisions, preserve version suffixes, and avoid applying import collision disambiguation to exports. Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
Extend the bindgen-test-cases fixture with colliding package, versioned, hyphenated, and bare import cases, plus export-name coverage. Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
04d9e15 to
af38639
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes: #1328
When two WIT packages export an interface with the same short name, the generated Rust trait has duplicate members and fails to compile. For example:
After this fix, the full namespace is prepended per component to produce unique names:
Two imports from the same package at different versions — the version is appended:
Also fixes a secondary collision where namespace components themselves contain hyphens (e.g.
a:b-c/typesvsa-b:c/types). Flat-joining with-collapsed both toABCTypes; per-component first-letter capitalisation now givesABcTypesvsAbCTypes.