-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
GH-96793: Implement PEP 479 in bytecode. #99006
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
Conversation
@@ -346,7 +346,7 @@ def make_tracer(): | |||
return Tracer() | |||
|
|||
def compare_events(self, line_offset, events, expected_events): | |||
events = [(l - line_offset, e) for (l, e) in events] | |||
events = [(l - line_offset if l is not None else None, e) for (l, e) in events] |
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.
I introduced for debugging this PR. It is no longer strictly necessary, but it gives nicer output when tests fail.
|
||
static int | ||
wrap_in_stopiteration_handler(struct compiler *c) | ||
{ |
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.
I wonder if this is not wrapping too much, like the instructions that deal with the function's arguments and annotations?
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.
Annotations are executed in the enclosing scope, as are defaults. So there is no problem there.
MAKE_CELL
and RETURN_GENERATOR
instructions are inserted in the back-end so happen after this.
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.
LGTM
In order to specialize iteration over generators and send to coroutines we need to remove the pre- and post checks from the C wrappers.
The pre-checks are largely eliminated by the the compiler and specialization.
The post-checks need to be handled in bytecode.
To do that, we wrap the generator body in a
try: ... except StopIteration: ...
which converts theStopIteration
into aRuntimeError
.I initially did this entirely in bytecode, but it adds a lot of bulk to the bytecode.
The new
STOPITERATION_ERROR
instruction should only be temporary: #99005for gen():
, and awaiting coroutines,await coro()
#96793