Fix effect analysis in presence of tail calls within try blocks#6463
Fix effect analysis in presence of tail calls within try blocks#6463vouillon wants to merge 2 commits intoWebAssembly:mainfrom
Conversation
This is obviously correct: this accounts for the fact that tail calls can throw through exception handlers. It is probably not worthwhile to make a more precise analysis: - The change only affects code with a tail call within a try block, which should be rare - Tail calls already have a branchesOut effect, which greatly limits possible optimizations
|
Another option we discussed before was something like this:
That seems like it would be as precise as we can get it, but as you said, it might not be worth the overhead. Maybe it's worth mentioning as a possible future TODO though. I'm curious what other people think here. |
|
I prefer the approach @kripken sketched because any local optimizations around the return call should be able to rely on the fact that it will not throw, at least not in a way that is observable by surrounding code. |
|
To get a sense of how many optimizations we are missing, I have run First with this PR, and a second time after modifying the code to (wrongly) assume that tail calls never throw: if (parent.features.hasExceptionHandling() &&
- (parent.tryDepth == 0 || curr->isReturn)) {
+ (parent.tryDepth == 0 && !curr->isReturn)) {
parent.throws_ = true;
}The output code was exactly the same in both cases. |
Thinking a bit more about it, this is not that surprising. The only optimizations for which this makes a difference are the ones that eliminates a Since my code does not contain any tail-call inside a |
|
Superseded by #6470 |
This is obviously correct: this accounts for the fact that tail calls can throw through exception handlers.
It is probably not worthwhile to make a more precise analysis: