Skip to content

fix: disambiguate colliding WIT import names#1562

Open
jsturtevant wants to merge 2 commits into
mainfrom
jsturtevant/component-util-collisions
Open

fix: disambiguate colliding WIT import names#1562
jsturtevant wants to merge 2 commits into
mainfrom
jsturtevant/component-util-collisions

Conversation

@jsturtevant

@jsturtevant jsturtevant commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

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:

// a:pkg/types and b:pkg/types — both named "types"
world bindgen-test-cases {
    import a:pkg/types;
    import b:pkg/types;
}

After this fix, the full namespace is prepended per component to produce unique names:

impl BindgenTestCasesImports for MyHost {
    type APkgTypes = Self;   // was: type Types (duplicate!)
    fn a_pkg_types(&mut self) -> &mut Self { self }

    type BPkgTypes = Self;   // was: type Types (duplicate!)
    fn b_pkg_types(&mut self) -> &mut Self { self }
}

Two imports from the same package at different versions — the version is appended:

world my-component {
    import a:pkg/types@1.0.0;
    import a:pkg/types@2.0.0;
}
impl MyComponentImports for MyHost {
    type APkgTypesV100 = Self;
    fn a_pkg_types_v1_0_0(&mut self) -> &mut Self { self }

    type APkgTypesV200 = Self;
    fn a_pkg_types_v2_0_0(&mut self) -> &mut Self { self }
}

Also fixes a secondary collision where namespace components themselves contain hyphens (e.g. a:b-c/types vs a-b:c/types). Flat-joining with - collapsed both to ABCTypes; per-component first-letter capitalisation now gives ABcTypes vs AbCTypes.

@jsturtevant jsturtevant added the kind/bugfix For PRs that fix bugs label Jun 18, 2026
@jsturtevant jsturtevant marked this pull request as draft June 18, 2026 23:33
@jsturtevant

Copy link
Copy Markdown
Contributor Author

This will be ontop of #1331

@jsturtevant jsturtevant force-pushed the jsturtevant/component-util-collisions branch 2 times, most recently from 736b4f5 to 6ff506c Compare June 18, 2026 23:51
@jsturtevant jsturtevant changed the base branch from component-util-fixes to main June 19, 2026 15:36
@jsturtevant jsturtevant force-pushed the jsturtevant/component-util-collisions branch 2 times, most recently from 7b9e0ba to 9d108b5 Compare June 19, 2026 21:58
@jsturtevant jsturtevant marked this pull request as ready for review June 19, 2026 22:01
Copilot AI review requested due to automatic review settings June 19, 2026 22:01
@jsturtevant jsturtevant force-pushed the jsturtevant/component-util-collisions branch from 9d108b5 to 2ff2286 Compare June 19, 2026 22:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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-cases WIT 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.

Comment thread src/hyperlight_component_util/src/rtypes.rs Outdated
Comment thread src/hyperlight_component_util/src/emit.rs Outdated
@jsturtevant jsturtevant force-pushed the jsturtevant/component-util-collisions branch 2 times, most recently from 4d3a303 to 5af128b Compare June 19, 2026 22:22
@jsturtevant jsturtevant requested a review from Copilot June 19, 2026 22:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Comment thread src/hyperlight_component_util/src/emit.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.

Comment thread src/hyperlight_component_util/src/emit.rs Outdated
Comment thread src/hyperlight_component_util/src/emit.rs
Comment thread src/hyperlight_component_util/src/emit.rs Outdated
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>
@jsturtevant jsturtevant force-pushed the jsturtevant/component-util-collisions branch from 04d9e15 to af38639 Compare June 20, 2026 00:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bugfix For PRs that fix bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wit: name collision + noff_var_id

2 participants