-
Notifications
You must be signed in to change notification settings - Fork 172
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
Fix returning from LEAVE to surrounding scope #1785
Merged
patrickbkr
merged 1 commit into
MoarVM:main
from
patrickbkr:leave-return-handler-miss-fix
Jul 6, 2024
Merged
Fix returning from LEAVE to surrounding scope #1785
patrickbkr
merged 1 commit into
MoarVM:main
from
patrickbkr:leave-return-handler-miss-fix
Jul 6, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
patrickbkr
pushed a commit
to patrickbkr/roast
that referenced
this pull request
Jan 27, 2024
Discussed in Raku/problem-solving#417 Depends on these three PRs: - MoarVM/MoarVM#1782 - MoarVM/MoarVM#1785 - MoarVM/MoarVM#1788
I believe this works reliably. So I guess it's ready for review. |
The general question of what Technically this PR is unreladed to that issue. Can this PR thus be merged? Again, who's best to ping? @MasterDuke17 @niner |
patrickbkr
pushed a commit
to patrickbkr/roast
that referenced
this pull request
May 21, 2024
Discussed in Raku/problem-solving#417 Depends on these three PRs: - MoarVM/MoarVM#1782 - MoarVM/MoarVM#1785 - MoarVM/MoarVM#1788
niner
reviewed
May 28, 2024
When a LEAVE phaser is run during an unwind, there is no valid return_address set in the LEAVE phasers outer frame. (It's return_address is actually set to interp_cur_op which is still the one that started the unwind in some unrelated frame.) Thus when a `return` in a LEAVE happens, the handler of the outer frame is missed, because `search_frame_handlers_lex()` validates that the `return_address` lies in the handlers area. Luckily there is a flag set on the LEAVE's outer frame: MVM_FRAME_FLAG_EXIT_HAND_RUN. We can simply check for that flag and ignore the frame handlers area. This is fine to do, because frames that have an exit handler attached can not be inlined. This fixes: sub s() { LEAVE return 5; return 7; } s() which before this fix printed Attempt to return outside of any Routine in sub s at leave-bug.raku line 2 in block at leave-bug.raku line 5 Fixes MoarVM#1784
patrickbkr
force-pushed
the
leave-return-handler-miss-fix
branch
from
May 28, 2024 21:01
03f2ea8
to
2c866ae
Compare
patrickbkr
pushed a commit
to patrickbkr/roast
that referenced
this pull request
May 28, 2024
Discussed in Raku/problem-solving#417 Depends on these three PRs: - MoarVM/MoarVM#1782 - MoarVM/MoarVM#1785 - MoarVM/MoarVM#1788
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When a LEAVE phaser is run during an unwind, there is no valid return_address set in the LEAVE phasers caller frame. (It return_address is actually set to cur_op which is still the one that started the unwind in some unrelated frame.) Thus when a
return
in a LEAVE happens, the handler of the outer frame is missed, becausesearch_frame_handlers_lex()
validates that thereturn_address
lies in the handlers area. Luckily there is a flag set on the LEAVE's outer frame:MVM_FRAME_FLAG_EXIT_HAND_RUN. We can simply check for that flag and ignore the frame handlers area. This is fine to do, because frames that have an exit handler attached can not be inlined. This fixes:
which before this fix printed
Fixes #1784