Add a suspends effect - #9070
Conversation
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.
| return calls || readsSharedMutableArray || writesSharedArray; | ||
| } | ||
| bool throws() const { return throws_ || !delegateTargets.empty(); } | ||
| bool suspends() const { return suspends_; } |
There was a problem hiding this comment.
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).
| return localsWritten.size() > 0 || danglingPop || writesGlobalState() || | ||
| throws() || transfersControlFlow() || hasSynchronization() || | ||
| mayNotReturn; | ||
| mayNotReturn || suspends(); |
There was a problem hiding this comment.
This is already covered by transfersControlFlow.
| // Suspending transfers control to an enclosing handler and executes | ||
| // arbitrary other code before we may resume here. | ||
| parent.suspends_ = true; | ||
| parent.clobbersGlobalState(); |
There was a problem hiding this comment.
Why is this better than the old .calls = true?
There was a problem hiding this comment.
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.
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.