Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract "world elaboration" to a separate function #1800

Merged

Conversation

alexcrichton
Copy link
Member

This commit extracts the process of elaborating a worlds imports/exports
to a dedicated function. This function ensures the transitive closure of
all imports/exports are listed in the world in proper topograhical
order. This additionally validates that the world has a coherent
definition given WIT today, notably that imports don't accidentally try
to use exported types.

This functionality was all present previously during the process of
taking a WIT document and creating Resolve. This moves the logic
around and refactors it slightly given its new surroundings. This
reorders a few imports/exports in worlds from what was previously
present but the underlying meaning of worlds should be the same.

The goal of this commit is to enable Resolve-mutating transformations
to not need to preserve all these invariants each time a world is
modified. Instead a world can be modified and then this function can be
called to "clean up" the world afterwards.

This commit extracts the process of elaborating a worlds imports/exports
to a dedicated function. This function ensures the transitive closure of
all imports/exports are listed in the world in proper topograhical
order. This additionally validates that the world has a coherent
definition given WIT today, notably that imports don't accidentally try
to use exported types.

This functionality was all present previously during the process of
taking a WIT document and creating `Resolve`. This moves the logic
around and refactors it slightly given its new surroundings. This
reorders a few imports/exports in worlds from what was previously
present but the underlying meaning of worlds should be the same.

The goal of this commit is to enable `Resolve`-mutating transformations
to not need to preserve all these invariants each time a world is
modified. Instead a world can be modified and then this function can be
called to "clean up" the world afterwards.
This commit updates the `importize` operation to be a much simpler "just
move the exports to the imports" operation where care is only taken to
preserve imported types and to additionally error on overlap of imported
types and exported functions/interfaces. The previous `elaborate_world`
method helps make this method much simpler than before.
@alexcrichton
Copy link
Member Author

The impact of this new function shows up a bit in the second commit here where importize is simplified with this operation, but my main motivation is tackling #1774 as my work-in-progress to implement that is getting pretty unwieldy trying to maintain these invariants.

alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Sep 18, 2024
This commit is the first half and the meat of the implementation
of bytecodealliance#1774 where, by default, WIT processing tools will now merge world
imports when possible based on semver versions. The precise shape of how
this is done has gone through a few iterations and this is the end
result I've ended up settling on. This should handle all the various
cases we're interested in and continue to produce valid worlds within a
`Resolve` (with the help of `elaborate_world` added in bytecodealliance#1800). CLI
tooling has been updated with flags to configure this behavior but the
behavior is now enabled by default.
@alexcrichton alexcrichton added this pull request to the merge queue Sep 18, 2024
Merged via the queue into bytecodealliance:main with commit e5132af Sep 18, 2024
30 checks passed
@alexcrichton alexcrichton deleted the function-to-elaborate-a-world branch September 18, 2024 21:36
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Sep 23, 2024
This commit is the first half and the meat of the implementation
of bytecodealliance#1774 where, by default, WIT processing tools will now merge world
imports when possible based on semver versions. The precise shape of how
this is done has gone through a few iterations and this is the end
result I've ended up settling on. This should handle all the various
cases we're interested in and continue to produce valid worlds within a
`Resolve` (with the help of `elaborate_world` added in bytecodealliance#1800). CLI
tooling has been updated with flags to configure this behavior but the
behavior is now enabled by default.
alexcrichton added a commit to alexcrichton/wasm-tools that referenced this pull request Sep 23, 2024
This commit is the first half and the meat of the implementation
of bytecodealliance#1774 where, by default, WIT processing tools will now merge world
imports when possible based on semver versions. The precise shape of how
this is done has gone through a few iterations and this is the end
result I've ended up settling on. This should handle all the various
cases we're interested in and continue to produce valid worlds within a
`Resolve` (with the help of `elaborate_world` added in bytecodealliance#1800). CLI
tooling has been updated with flags to configure this behavior but the
behavior is now enabled by default.
github-merge-queue bot pushed a commit that referenced this pull request Sep 24, 2024
* Implement merging semver-compatible interfaces in imports

This commit is the first half and the meat of the implementation
of #1774 where, by default, WIT processing tools will now merge world
imports when possible based on semver versions. The precise shape of how
this is done has gone through a few iterations and this is the end
result I've ended up settling on. This should handle all the various
cases we're interested in and continue to produce valid worlds within a
`Resolve` (with the help of `elaborate_world` added in #1800). CLI
tooling has been updated with flags to configure this behavior but the
behavior is now enabled by default.

* Add broken test case for wit-component

* Match wasm/component import names based on versions

This commit implements the final bit of #1774 where the `wit-component`
crate will now match imports based on semver version in addition to the
previous exact-name matching that was performed previously.

* Don't panic on duplicate shims in wit-component

This is now possible with import version matching so refactor the
internal data structures to better support insertion of possibly
duplicate shims. Most of wit-component was already ready for this
refactoring, it was just the initial generation of shims that needed to
be reorganized slightly.

* wip

* Elaborate all worlds after semver merging

Any interface could be modified, so elaborate all of them to fixup anything
that needs new imports.

* Only merge once at the end, not continuously

This commit updates how the semver-merging bits of `Resolve` work by
moving it towards the end of the encoding process rather than
once-per-world-merged. That helps both deduplicate work and fix some
asserts I'm seeing that are tripping if a `Resolve` is import-merged and
then merged again elsewhere.

This additionally simplifies some APIs because the boolean of what to do
isn't threaded to quite so many locations.

* Fix test

* Update interface deps of exports too

Dependencies might depend on replaced interfaces so the dependency edges
there need to be updated in the same manner as imports.

* Fix fuzzer build

Also ensure to at least try to test the new merging function.
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