-
-
Notifications
You must be signed in to change notification settings - Fork 32k
GH-90997: Wrap yield from
/await
in a virtual try
/except StopIteration
#96010
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
c05c2af
Use a virtual try/except to handle close()/throw()
brandtbucher 819e0df
Catch up with main
brandtbucher d557e41
Don't load StopIteration as a constant
brandtbucher d5e033a
Clean up control flow a bit
brandtbucher b4f26d8
Catch up with main
brandtbucher 0cb78f2
blurb add
brandtbucher 4b0e60f
Improve docs for SEND
brandtbucher a0953b1
Cleanup
brandtbucher afdf25e
fixup
brandtbucher 5348cbe
Fix wording
brandtbucher f4cc398
Pack everything into END_THROW
brandtbucher f085a2e
Catch up with main
brandtbucher 296bc08
Feedback from code review
brandtbucher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Cleanup
- Loading branch information
commit a0953b13257de36d47ff41af6f8ef5171e63ab25
There are no files selected for viewing
8000
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1946,35 +1946,36 @@ compiler_call_exit_with_nones(struct compiler *c) { | |
static int | ||
compiler_add_yield_from(struct compiler *c, int await) | ||
{ | ||
NEW_JUMP_TARGET_LABEL(c, start); | ||
NEW_JUMP_TARGET_LABEL(c, resume); | ||
NEW_JUMP_TARGET_LABEL(c, error); | ||
NEW_JUMP_TARGET_LABEL(c, stopiter); | ||
NEW_JUMP_TARGET_LABEL(c, send); | ||
NEW_JUMP_TARGET_LABEL(c, fail); | ||
NEW_JUMP_TARGET_LABEL(c, stop); | ||
NEW_JUMP_TARGET_LABEL(c, exit); | ||
USE_LABEL(c, start); | ||
|
||
USE_LABEL(c, send); | ||
ADDOP_JUMP(c, SEND, exit); | ||
USE_LABEL(c, resume); | ||
// Set up a virtual try/except to handle StopIteration raised during a | ||
// close() or throw(): | ||
ADDOP_JUMP(c, SETUP_FINALLY, error); | ||
RETURN_IF_FALSE(compiler_push_fblock(c, TRY_EXCEPT, resume, NO_LABEL, NULL)); | ||
// The only way YIELD_VALUE can raise is if close() or throw() raises: | ||
// Set up a virtual try/except to handle when StopIteration is raised during | ||
// a close or throw call. The only way YIELD_VALUE raises if they do! | ||
ADDOP_JUMP(c, SETUP_FINALLY, fail); | ||
RETURN_IF_FALSE(compiler_push_fblock(c, TRY_EXCEPT, send, NO_LABEL, NULL)); | ||
ADDOP_I(c, YIELD_VALUE, 0); | ||
compiler_pop_fblock(c, TRY_EXCEPT, resume); | ||
compiler_pop_fblock(c, TRY_EXCEPT, send); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nor pop it here |
||
ADDOP_NOLINE(c, POP_BLOCK); | ||
ADDOP_I(c, RESUME, await ? 3 : 2); | ||
ADDOP_JUMP(c, JUMP_NO_INTERRUPT, start); | ||
USE_LABEL(c, error); | ||
ADDOP_JUMP(c, JUMP_NO_INTERRUPT, send); | ||
|
||
USE_LABEL(c, fail); | ||
ADDOP_I(c, LOAD_EXCEPTION_TYPE, 1); // StopIteration | ||
ADDOP(c, CHECK_EXC_MATCH); | ||
ADDOP_JUMP(c, POP_JUMP_IF_TRUE, stopiter); | ||
ADDOP_JUMP(c, POP_JUMP_IF_TRUE, stop); | ||
ADDOP_I(c, RERAISE, 0); | ||
USE_LABEL(c, stopiter); | ||
// StopIteration was raised. Push the return value and continue execution: | ||
|
||
USE_LABEL(c, stop); | ||
// StopIteration was raised. Push the value and break out of the loop: | ||
ADDOP_NAME(c, LOAD_ATTR, &_Py_ID(value), names); | ||
ADDOP_I(c, SWAP, 3); | ||
ADDOP(c, POP_TOP); | ||
ADDOP(c, POP_TOP); | ||
ADDOP(c, POP_TOP); // The thing we're yielding from. | ||
ADDOP(c, POP_TOP); // The last sent value | ||
|
||
USE_LABEL(c, exit); | ||
return 1; | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be no call to
compiler_unwind_fblock
before this block is popped, so we don't need to push a block here.