-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong context for closure in finally with await in try. #26948
Comments
Might be related: |
It seems to happen after doSync gets optimized. I used the following command using Zach's repro and optimization-filter:
|
Two observations:
|
The most recent comment by hixie in the source bug says this is likely not related. |
I think that the culprit is this cl: https://codereview.chromium.org/1569523002 It introduced a reparsing of finally clauses to fix a bug with try-catch inside of try-finally. I think that the proper fix here is to revisit the cl above and avoid reparsing finally clauses. What do you think? |
Reparsing finally clauses is definitely the issue here. The CL you reference did not introduce the reparsing. That was introcuded even before the begin of history in this repo. Your observation about creating multiple instances of the same variable is true. In non-async code it's harmless, because each copy of the finally block code accesses only its own copy of the variable. In async code, each instance of the variable gets saved to a different context slot. (That by itself should not be a problem either.) However, we also get multiple instances of the anonymous closure. Why? Because the compiler only registers the closure function once the backend compiles the closure node. So, each time the finally block gets reparsed, a new anonymous closure function is created because no function for that token position has been registered yet. I'm not sure yet whether that is a correctness problem. I have observed though that in the sample code above, the VM compiles two different anonymous functions for the literal in the finally clause, and they do not agree in which context slot the 'next' variable is stored. I agree that the right fix is to avoid reparsing the code in the finally block. Maybe the AST for the finally code can be shared, or it has to be cloned in a different way. |
Because this issue is already in earlier stable releases, and does not have an immediate fix, I am not considering it a blocker for 1.18, and removing the milestone. Let me know if you disagree, or have a fix that should be put in a patch release. |
I agree with this approach. Once we have a fix, we can consider if that meets the bar for a merge to stable patch release. |
Add regression test. R=fschneider@google.com, hausner@google.com Review URL: https://codereview.chromium.org/2188863002 .
The program below should print 5.0 forever. However, after
doSync
is optimized, the closure passed todoPrint
apparently has the wrong context, and extracts a bogus value fornext
.Invoke with, e.g.:
The bug can be worked around by pulling out the
finally
block ofdoSync
into its own function, wrapped in atry
so that we don't try to inline it.The text was updated successfully, but these errors were encountered: