Skip to content

[wasm-reduce] Remove functions with delta debugging#8690

Open
tlively wants to merge 1 commit into
mainfrom
ddb-remove-functions
Open

[wasm-reduce] Remove functions with delta debugging#8690
tlively wants to merge 1 commit into
mainfrom
ddb-remove-functions

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented May 11, 2026

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.

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.
@tlively tlively requested a review from kripken May 11, 2026 23:16
@tlively tlively requested a review from a team as a code owner May 11, 2026 23:16
// 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());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens for uninhabitable types here?

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