Skip to content

Commit 52cc4af

Browse files
authored
gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 (#111459)
1 parent 970e719 commit 52cc4af

18 files changed

+362
-339
lines changed

Doc/library/dis.rst

+11-2
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,8 @@ iterations of the loop.
823823
.. versionchanged:: 3.12
824824
oparg set to be the exception block depth, for efficient closing of generators.
825825

826+
.. versionchanged:: 3.13
827+
this opcode no longer has an oparg
826828

827829
.. opcode:: SETUP_ANNOTATIONS
828830

@@ -1625,20 +1627,27 @@ iterations of the loop.
16251627
success (``True``) or failure (``False``).
16261628

16271629

1628-
.. opcode:: RESUME (where)
1630+
.. opcode:: RESUME (context)
16291631

16301632
A no-op. Performs internal tracing, debugging and optimization checks.
16311633

1632-
The ``where`` operand marks where the ``RESUME`` occurs:
1634+
The ``context`` oparand consists of two parts. The lowest two bits
1635+
indicate where the ``RESUME`` occurs:
16331636

16341637
* ``0`` The start of a function, which is neither a generator, coroutine
16351638
nor an async generator
16361639
* ``1`` After a ``yield`` expression
16371640
* ``2`` After a ``yield from`` expression
16381641
* ``3`` After an ``await`` expression
16391642

1643+
The next bit is ``1`` if the RESUME is at except-depth ``1``, and ``0``
1644+
otherwise.
1645+
16401646
.. versionadded:: 3.11
16411647

1648+
.. versionchanged:: 3.13
1649+
The oparg value changed to include information about except-depth
1650+
16421651

16431652
.. opcode:: RETURN_GENERATOR
16441653

Doc/whatsnew/3.13.rst

+8
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,14 @@ Others
945945

946946
* None yet
947947

948+
CPython bytecode changes
949+
========================
950+
951+
* ``YIELD_VALUE`` no longer has an oparg. The oparg of ``RESUME`` was
952+
changed to add a bit indicating whether the except-depth is 1, which
953+
is needed to optimize closing of generators.
954+
(Contributed by Irit Katriel in :gh:`111354`.)
955+
948956
Porting to Python 3.13
949957
======================
950958

Include/internal/pycore_opcode_metadata.h

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_opcode_utils.h

+2
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ extern "C" {
6464
#define RESUME_AFTER_YIELD_FROM 2
6565
#define RESUME_AFTER_AWAIT 3
6666

67+
#define RESUME_OPARG_LOCATION_MASK 0x3
68+
#define RESUME_OPARG_DEPTH1_MASK 0x4
6769

6870
#ifdef __cplusplus
6971
}

Include/opcode_ids.h

+75-75
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)