Skip to content

Commit 981d172

Browse files
authored
GH-112354: END_FOR instruction to only pop one value. (GH-114247)
* Compiler emits END_FOR; POP_TOP instead of END_FOR. To support tier 2 side exits in loops.
1 parent 6fadd68 commit 981d172

16 files changed

+238
-184
lines changed

Doc/library/dis.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,8 @@ operations on it as if it was a Python list. The top of the stack corresponds to
546546

547547
.. opcode:: END_FOR
548548

549-
Removes the top two values from the stack.
550-
Equivalent to ``POP_TOP``; ``POP_TOP``.
549+
Removes the top-of-stack item.
550+
Equivalent to ``POP_TOP``.
551551
Used to clean up at the end of loops, hence the name.
552552

553553
.. versionadded:: 3.12

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,11 @@ struct _Py_global_strings {
276276
STRUCT_FOR_ID(after_in_child)
277277
STRUCT_FOR_ID(after_in_parent)
278278
STRUCT_FOR_ID(aggregate_class)
279+
STRUCT_FOR_ID(alias)
279280
STRUCT_FOR_ID(allow_code)
280281
STRUCT_FOR_ID(append)
281282
STRUCT_FOR_ID(argdefs)
283+
STRUCT_FOR_ID(args)
282284
STRUCT_FOR_ID(arguments)
283285
STRUCT_FOR_ID(argv)
284286
STRUCT_FOR_ID(as_integer_ratio)
@@ -402,6 +404,8 @@ struct _Py_global_strings {
402404
STRUCT_FOR_ID(errors)
403405
STRUCT_FOR_ID(event)
404406
STRUCT_FOR_ID(eventmask)
407+
STRUCT_FOR_ID(exc_type)
408+
STRUCT_FOR_ID(exc_value)
405409
STRUCT_FOR_ID(excepthook)
406410
STRUCT_FOR_ID(exception)
407411
STRUCT_FOR_ID(existing_file_name)
@@ -655,6 +659,7 @@ struct _Py_global_strings {
655659
STRUCT_FOR_ID(seek)
656660
STRUCT_FOR_ID(seekable)
657661
STRUCT_FOR_ID(selectors)
662+
STRUCT_FOR_ID(self)
658663
STRUCT_FOR_ID(send)
659664
STRUCT_FOR_ID(sep)
660665
STRUCT_FOR_ID(sequence)
@@ -717,6 +722,7 @@ struct _Py_global_strings {
717722
STRUCT_FOR_ID(timetuple)
718723
STRUCT_FOR_ID(top)
719724
STRUCT_FOR_ID(trace_callback)
725+
STRUCT_FOR_ID(traceback)
720726
STRUCT_FOR_ID(trailers)
721727
STRUCT_FOR_ID(translate)
722728
STRUCT_FOR_ID(true)

Include/internal/pycore_opcode_metadata.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_runtime_init_generated.h

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/importlib/_bootstrap_external.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ def _write_atomic(path, data, mode=0o666):
464464
# Python 3.13a1 3565 (Oparg of YIELD_VALUE indicates whether it is in a yield-from)
465465
# Python 3.13a1 3566 (Emit JUMP_NO_INTERRUPT instead of JUMP for non-loop no-lineno cases)
466466
# Python 3.13a1 3567 (Reimplement line number propagation by the compiler)
467+
# Python 3.13a1 3568 (Change semantics of END_FOR)
467468

468469
# Python 3.14 will start with 3600
469470

@@ -480,7 +481,7 @@ def _write_atomic(path, data, mode=0o666):
480481
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
481482
# in PC/launcher.c must also be updated.
482483

483-
MAGIC_NUMBER = (3567).to_bytes(2, 'little') + b'\r\n'
484+
MAGIC_NUMBER = (3568).to_bytes(2, 'little') + b'\r\n'
484485

485486
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
486487

Lib/test/test_compiler_codegen.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def test_for_loop(self):
4949
('JUMP', loop_lbl),
5050
exit_lbl,
5151
('END_FOR', None),
52+
('POP_TOP', None),
5253
('LOAD_CONST', 0),
5354
('RETURN_VALUE', None),
5455
]

0 commit comments

Comments
 (0)