Skip to content

Make WIT merging commutative#2451

Draft
fibonacci1729 wants to merge 1 commit intobytecodealliance:mainfrom
fibonacci1729:wit-commutativity
Draft

Make WIT merging commutative#2451
fibonacci1729 wants to merge 1 commit intobytecodealliance:mainfrom
fibonacci1729:wit-commutativity

Conversation

@fibonacci1729
Copy link
Contributor

@fibonacci1729 fibonacci1729 commented Feb 25, 2026

Closes #1897

This PR makes the following changes made to mod.rs to make WIT merging commutative:

  • MergeMap::build_interface — Previously, every type and function in from's interface was required to exist in into's interface (strict equality). Now, one interface can be a superset of the other. If both sides have exclusive items, it fails (genuinely incompatible). If only from has extras, they're skipped in the mapping phase and handled later during the merge.

  • Resolve::merge interface processing — When a mapped interface has extra types/functions from from, those extras are now added to the into interface (types added to the types map, functions added to the functions map with proper span adjustment and remapping).

  • Adds topologically_sort_interfaces method on Resolve that rebuilds the interfaces arena in topological order after a merge (newly-added interfaces may have been added after existing interfaces that now depend on them).

NOTE: I made use of Copilot (Claude Opus 4.6) in implementing the topological sort bits.

Signed-off-by: Brian Hardock <brian.hardock@fermyon.com>
}

#[test]
fn merging_is_commutative() -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: Would this test be better put into wit-component/tests/merge?

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.

merging wit is not commutative

1 participant