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-103488: Use return-offset, not yield-offset. by markshannon · Pull Request #103502 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented Apr 13, 2023 •
edited by bedevere-bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

This ensures that the callers instruction pointer is correct when sending to a generator or coroutine.

This is necessary for exception handling, and nice for debuggers and profilers.

Instead of returning to prev_instr +1 and yielding to prev_instr - yield_offset + 1 we now return to prev_instr + return_offset + 1 and yield to prev_instr +1.
These are equivalent unless there is an exception, or when introspecting the stack.

Since call/returns are more common than send/yields this will be a tiny bit slower than main, but reverting to the 3.11 approach would a lot slower.
Compared to the 3.11, this makes call/returns a few percent slower and send/yields an order of magnitude faster.

  • Issue: Python 3.12.0a7 can fail to catch exceptions when an iterator is involved #103488

Sorry, something went wrong.

Uh oh!

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

sunmy2019 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
markshannon added 4 commits April 12, 2023 19:23
@markshannon
Use return-offset, not yield-offset, so that instruction pointer is c…
dc9fee6
…orrect when sending to a generator or coroutine.
@markshannon
Set return_offset on call, instead of resetting it on return.
c86c721
@markshannon
Add news
b4afef3
@markshannon
Add explanatory comment for return_offset.
18fad80
@markshannon
markshannon marked this pull request as ready for review April 13, 2023 10:33
@bedevere-bot bedevere-bot mentioned this pull request Apr 13, 2023
Python 3.12.0a7 can fail to catch exceptions when an iterator is involved #103488
Closed
@bedevere-bot bedevere-bot added the awaiting core review label Apr 13, 2023
iritkatriel
iritkatriel reviewed Apr 13, 2023
View reviewed changes
Comment thread Python/bytecodes.c
STACK_SHRINK(shrink_stack);
new_frame->localsplus[0] = owner;
JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR);
frame->return_offset = 0;

@iritkatriel iritkatriel Apr 13, 2023

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.

What are the rules about when this needs to be 0ed and when it doesn't?

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon Apr 13, 2023

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.

return_offset is only meaningful to the callee, so it needs to be set in any CALL (to a Python function) or SEND (to a coroutine or generator).
If there is no callee, then it is meaningless.

Sorry, something went wrong.

Uh oh!

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

All reactions

@markshannon markshannon Apr 13, 2023

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've added a comment in pycore_frame.h

Sorry, something went wrong.

Uh oh!

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

All reactions
@Eclips4

Eclips4 commented Apr 13, 2023

Copy link
Copy Markdown
Member

Also, this PR fixes #101914, output from pylint using example:

(venv) eclips4@HOME-PC:~/ide/cpython$ pylint test.py
************* Module test
test.py:1:0: C0114: Missing module docstring (missing-module-docstring)
test.py:1:4: E0602: Undefined variable 'b' (undefined-variable)
test.py:2:0: E0602: Undefined variable 'func' (undefined-variable)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

@mdboom can you confirm that? =)

All reactions

Sorry, something went wrong.

Uh oh!

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

iritkatriel
iritkatriel approved these changes Apr 13, 2023
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting core review labels Apr 13, 2023
@markshannon
markshannon merged commit efb8a25 into python:main Apr 13, 2023
@bedevere-bot bedevere-bot removed the awaiting merge label Apr 13, 2023
carljm added a commit to carljm/cpython that referenced this pull request Apr 13, 2023
@carljm
Merge branch 'main' into superopt
9384106
* main:
  pythongh-103479: [Enum] require __new__ to be considered a data type (pythonGH-103495)
  pythongh-103365: [Enum] STRICT boundary corrections (pythonGH-103494)
  pythonGH-103488: Use return-offset, not yield-offset. (pythonGH-103502)
  pythongh-103088: Fix test_venv error message to avoid bytes/str warning (pythonGH-103500)
  pythonGH-103082: Turn on branch events for FOR_ITER instructions. (python#103507)
  pythongh-102978: Fix mock.patch function signatures for class and staticmethod decorators (python#103228)
  pythongh-103462: Ensure SelectorSocketTransport.writelines registers a writer when data is still pending (python#103463)
  pythongh-95299: Rework test_cppext.py to not invoke setup.py directly (python#103316)
@mdboom mdboom mentioned this pull request Apr 20, 2023
pylint is broken with CPython main #101914
Closed
@mdboom

mdboom commented Apr 20, 2023

Copy link
Copy Markdown
Contributor

@mdboom can you confirm that? =)

Yes, confirmed. I closed #101914 as a result.

All reactions

Sorry, something went wrong.

Uh oh!

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

@jacobtylerwalls jacobtylerwalls mentioned this pull request May 18, 2023
crash caused by unimplemented code feature pylint-dev/pylint#8695
Closed
@markshannon
markshannon deleted the fix-103488 branch September 26, 2023 12:55
@cdce8p cdce8p mentioned this pull request Feb 20, 2024
Python 3.12 - ValueError: generator already executing pylint-dev/pylint#9138
Closed
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.

5 participants

@markshannon @Eclips4 @mdboom @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.