Skip to content

Refactor how liveness of imports is calculated #2115

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

Merged

Conversation

alexcrichton
Copy link
Member

In wit-component there's a pass when creating a component to prune types/functions/etc from imported interfaces if they're not actually needed by the final component. This logic has not stood well against the test of time and the loop nowadays looks like: for each import if it's found within the imports then mark it live. This logic had some special handling of resource intrinsics but did not take into account any async/stream/future-related intrinsics.

To fix this issue I've replaced the outdated loop with "for all module imports add them, as necessary, to the set of live types". This starts with the source of truth, module imports, and works backwards to WIT types as opposed to the other way around, starting with WIT types and testing to see if it's included in the intrinsics list. That fixes the various cases with async intrinsics and should ensure that all future intrinsics are also accounted for.

Closes bytecodealliance/wasip3-prototyping#82

In `wit-component` there's a pass when creating a component to prune
types/functions/etc from imported interfaces if they're not actually
needed by the final component. This logic has not stood well against the
test of time and the loop nowadays looks like: for each import if it's
found within the imports then mark it live. This logic had some special
handling of resource intrinsics but did not take into account any
async/stream/future-related intrinsics.

To fix this issue I've replaced the outdated loop with "for all module
imports add them, as necessary, to the set of live types". This starts
with the source of truth, module imports, and works backwards to WIT
types as opposed to the other way around, starting with WIT types and
testing to see if it's included in the intrinsics list. That fixes the
various cases with async intrinsics and should ensure that all future
intrinsics are also accounted for.

Closes bytecodealliance/wasip3-prototyping#82
Comment on lines +52 to +64
if u.arbitrary()? {
let mut dst = Module::default();
let mut reencode = RemoveImports {
u,
removed_funcs: 0,
};
if reencode
.parse_core_module(&mut dst, Default::default(), &dummy)
.is_ok()
{
dummy = dst.finish();
}
}
Copy link
Member Author

Choose a reason for hiding this comment

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

I'll note that this update to the fuzzer did not actually turn up this bug after fuzzing for ~1 hour on 30 cores. My best guess is that the shape of this bug is pretty specific so it's relatively rare to come up, but nonetheless I'm hoping that this stresses the optional import logic of wit-component.

@alexcrichton alexcrichton added this pull request to the merge queue Mar 27, 2025
Merged via the queue into bytecodealliance:main with commit 375d1ea Mar 27, 2025
32 checks passed
@alexcrichton alexcrichton deleted the fix-liveness-of-imports branch March 27, 2025 18:24
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.

component validation panic
2 participants