Skip to content

Add a suspends effect - #9070

Open
tlively wants to merge 4 commits into
mainfrom
suspends-effect
Open

Add a suspends effect#9070
tlively wants to merge 4 commits into
mainfrom
suspends-effect

Conversation

@tlively

@tlively tlively commented Sep 2, 2026

Copy link
Copy Markdown
Member

This will be necessary for a future optimization that turns resumes of continuations that never suspend into calls. Update the effect analysis of suspends to set the new effect and clobber global state because the suspend handler might do anything before returning. Test that the effects are analyzed as intended and that they work with global effect analysis.

This will be necessary for a future optimization that turns resumes of continuations that never suspend into calls. Update the effect analysis of suspends to set the new effect and clobber global state because the suspend handler might do anything before returning. Test that the effects are analyzed as intended and that they work with global effect analysis.
@tlively
tlively requested a review from a team as a code owner September 2, 2026 19:00
@tlively
tlively requested review from aheejin and kripken and removed request for a team and kripken September 2, 2026 19:00
Comment thread src/ir/effects.h Outdated
return calls || readsSharedMutableArray || writesSharedArray;
}
bool throws() const { return throws_ || !delegateTargets.empty(); }
bool suspends() const { return suspends_; }

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.

No need for this helper, can just call the property this name (i.e. remove the _ there).

We only add functions when it does more than a simple property read (see e.g. hasReturnCallThrow which has no function).

Comment thread src/ir/effects.h Outdated
return localsWritten.size() > 0 || danglingPop || writesGlobalState() ||
throws() || transfersControlFlow() || hasSynchronization() ||
mayNotReturn;
mayNotReturn || suspends();

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.

This is already covered by transfersControlFlow.

Comment thread src/ir/effects.h Outdated
// Suspending transfers control to an enclosing handler and executes
// arbitrary other code before we may resume here.
parent.suspends_ = true;
parent.clobbersGlobalState();

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.

Why is this better than the old .calls = true?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When GlobalEffects sees a calls effect on something that is not actually a call, it clears the global effects entirely, meaning that users must conservatively assume all effects: https://github.com/WebAssembly/binaryen/blob/main/src/passes/GlobalEffects.cpp#L135-L175

However, I guess that's not meaningfully different from setting calls = true. I'll revert this part.

@tlively
tlively requested a review from kripken September 3, 2026 01:47
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