GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-96793: Implement PEP 479 in bytecode. by markshannon · Pull Request #99006 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Nov 2, 2022 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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

  • Issue: Enable specialization of iteration over generators, for gen():, and awaiting coroutines, await coro() #96793

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
markshannon added 6 commits November 1, 2022 16:57
@markshannon
Handle converting StopIteration to RuntimeError in bytecode.
65d303f
@markshannon
Wrap async generators and generator expressions in handler for Stop[A…
9cda4fc
…sync]Iteration.
@markshannon
Add custom instruction for converting StopIteration into RuntimeError.
1947227
@markshannon
Remove LOAD_ERROR instruction.
f86c5e4
@markshannon
Document new instruction
7e74daa
@markshannon
Add news
089ddcb
@markshannon
markshannon requested a review from iritkatriel as a code owner November 2, 2022 14:43
@bedevere-bot bedevere-bot mentioned this pull request Nov 2, 2022
Enable specialization of iteration over generators, for gen():, and awaiting coroutines, await coro() #96793
Closed
4 tasks done
@bedevere-bot bedevere-bot added the awaiting core review label Nov 2, 2022
@markshannon
Fix magic number
13cf7e2
markshannon
markshannon commented Nov 2, 2022
View reviewed changes
Comment thread Lib/test/test_sys_settrace.py

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]

@markshannon markshannon Nov 2, 2022

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
iritkatriel
iritkatriel reviewed Nov 2, 2022
View reviewed changes
Comment thread Python/compile.c

static int
wrap_in_stopiteration_handler(struct compiler *c)
{

@iritkatriel iritkatriel Nov 2, 2022

Copy link
Copy Markdown
Member

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@markshannon markshannon Nov 3, 2022

Copy link
Copy Markdown
Member Author

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@markshannon
Merge branch 'main' into pep-479-bytecode
fbc1f11
iritkatriel
iritkatriel approved these changes Nov 3, 2022
View reviewed changes

@iritkatriel iritkatriel left a comment

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Nov 3, 2022
@markshannon
markshannon merged commit f4adb97 into python:main Nov 3, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Nov 3, 2022
@gvanrossum gvanrossum mentioned this pull request Nov 8, 2022
GH-98831: Simple input-output stack effects #99120
Merged
@brandtbucher brandtbucher mentioned this pull request Jan 18, 2023
Generator finalization is slower in 3.11 vs 3.10 #100762
Closed
@tekknolagi tekknolagi mentioned this pull request Jun 12, 2023
Implement PEP 479 in bytecode tekknolagi/skybison#507
Open
@markshannon
markshannon deleted the pep-479-bytecode branch September 26, 2023 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iritkatriel iritkatriel iritkatriel approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@markshannon @iritkatriel @bedevere-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.