GH-103488: Use return-offset, not yield-offset.#103502
Merged
markshannon merged 4 commits intopython:mainfrom Apr 13, 2023
Merged
GH-103488: Use return-offset, not yield-offset.#103502markshannon merged 4 commits intopython:mainfrom
markshannon merged 4 commits intopython:mainfrom
Conversation
…orrect when sending to a generator or coroutine.
iritkatriel
reviewed
Apr 13, 2023
| STACK_SHRINK(shrink_stack); | ||
| new_frame->localsplus[0] = owner; | ||
| JUMPBY(INLINE_CACHE_ENTRIES_LOAD_ATTR); | ||
| frame->return_offset = 0; |
Member
There was a problem hiding this comment.
What are the rules about when this needs to be 0ed and when it doesn't?
Member
Author
There was a problem hiding this comment.
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.
Member
Author
There was a problem hiding this comment.
I've added a comment in pycore_frame.h
Member
|
Also, this PR fixes #101914, output from pylint using example: @mdboom can you confirm that? =) |
iritkatriel
approved these changes
Apr 13, 2023
carljm
added a commit
to carljm/cpython
that referenced
this pull request
Apr 13, 2023
* 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)
Contributor
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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 +1and yielding toprev_instr - yield_offset + 1we now return toprev_instr + return_offset + 1and yield toprev_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.