Skip to content

gh-109923: set line number on the POP_TOP that follows a RETURN_GENERATOR #109924

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 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions Lib/test/test_dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,8 @@ async def _asyncwith(c):

dis_asyncwith = """\
%4d RETURN_GENERATOR

None POP_TOP

%4d RESUME 0
POP_TOP
RESUME 0

%4d LOAD_FAST 0 (c)
BEFORE_ASYNC_WITH
Expand Down Expand Up @@ -598,7 +596,6 @@ async def _asyncwith(c):
ExceptionTable:
12 rows
""" % (_asyncwith.__code__.co_firstlineno,
_asyncwith.__code__.co_firstlineno,
_asyncwith.__code__.co_firstlineno + 1,
_asyncwith.__code__.co_firstlineno + 2,
_asyncwith.__code__.co_firstlineno + 1,
Expand Down Expand Up @@ -757,10 +754,8 @@ def foo(x):
None COPY_FREE_VARS 1

%4d RETURN_GENERATOR

None POP_TOP

%4d RESUME 0
POP_TOP
RESUME 0
LOAD_FAST 0 (.0)
>> FOR_ITER 10 (to 34)
STORE_FAST 1 (z)
Expand All @@ -782,7 +777,6 @@ def foo(x):
__file__,
_h.__code__.co_firstlineno + 3,
_h.__code__.co_firstlineno + 3,
_h.__code__.co_firstlineno + 3,
)

def load_test(x, y=0):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Set line number on the ``POP_TOP`` that follows a ``RETURN_GENERATOR``.
6 changes: 4 additions & 2 deletions Python/flowgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -2461,17 +2461,19 @@ insert_prefix_instructions(_PyCompile_CodeUnitMetadata *umd, basicblock *entrybl
* of 0. This is because RETURN_GENERATOR pushes an element
* with _PyFrame_StackPush before switching stacks.
*/

location loc = LOCATION(umd->u_firstlineno, umd->u_firstlineno, -1, -1);
cfg_instr make_gen = {
.i_opcode = RETURN_GENERATOR,
.i_oparg = 0,
.i_loc = LOCATION(umd->u_firstlineno, umd->u_firstlineno, -1, -1),
.i_loc = loc,
.i_target = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 0, &make_gen));
cfg_instr pop_top = {
.i_opcode = POP_TOP,
.i_oparg = 0,
.i_loc = NO_LOCATION,
.i_loc = loc,
.i_target = NULL,
};
RETURN_IF_ERROR(basicblock_insert_instruction(entryblock, 1, &pop_top));
Expand Down