[wasm-reduce] Remove functions with delta debugging#8690
Open
tlively wants to merge 1 commit into
Open
Conversation
Also take care not to remove functions that are referenced from module-level code, since in general those references cannot be replaced with anything else. When we remove functions, use ChildLocalizer to keep any children with side effects, since they might be important for reproducing the issue. Also try to replace calls to removed functions with constants if possible to avoid inserting unnecessary traps. Unlike the old implementation, this reduction scheme avoids wasted work by ensuring that the reduced module is still valid.
kripken
reviewed
May 12, 2026
| // working set size. We don't want to waste time on very fine-grained | ||
| // partitions when we could switch to a different reduction strategy | ||
| // instead. | ||
| if (size_t sqrtRemaining = std::sqrt(dd.working.size()); |
Member
There was a problem hiding this comment.
The old code uses the factor to guide this work. Should we keep doing that?
In particular, every attempt here calls loadWorking, which is slow on a huge file. Other reduction methods might be faster, and worth doing before we get to a fine grain here.
| module->functions = std::move(newFuncs); | ||
| module->updateFunctionsMap(); | ||
|
|
||
| std::vector<Name> exportsToRemove; |
Member
There was a problem hiding this comment.
Suggested change
| std::vector<Name> exportsToRemove; | |
| // When we remove a function, we remove its exports. | |
| std::vector<Name> exportsToRemove; |
| return std::make_unique<FunctionReplacer>(); | ||
| }; | ||
| void visitCall(Call* curr) { | ||
| if (getModule()->getFunctionOrNull(curr->target)) { |
Member
There was a problem hiding this comment.
Suggested change
| if (getModule()->getFunctionOrNull(curr->target)) { | |
| // Replace calls to functions we are removing. | |
| if (getModule()->getFunctionOrNull(curr->target)) { |
| auto* block = | ||
| ChildLocalizer(curr, getFunction(), *getModule(), getPassOptions()) | ||
| .getChildrenReplacement(); | ||
| auto* replacement = builder.replaceWithIdenticalType(curr); |
Member
There was a problem hiding this comment.
What happens for uninhabitable types here?
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.
Also take care not to remove functions that are referenced from module-level code, since in general those references cannot be replaced with anything else. When we remove functions, use ChildLocalizer to keep any children with side effects, since they might be important for reproducing the issue. Also try to replace calls to removed functions with constants if possible to avoid inserting unnecessary traps. Unlike the old implementation, this reduction scheme avoids wasted work by ensuring that the reduced module is still valid.