Skip to content

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

Merged
merged 8 commits into from
Nov 3, 2022

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Nov 2, 2022

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 the StopIteration into a RuntimeError.

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: #99005

@@ -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]
Copy link
Member Author

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)
{
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

@iritkatriel iritkatriel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants