Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit52cc4af

Browse files
authored
gh-111354: simplify detection of RESUME after YIELD_VALUE at except-depth 1 (#111459)
1 parent970e719 commit52cc4af

File tree

18 files changed

+362
-339
lines changed

18 files changed

+362
-339
lines changed

‎Doc/library/dis.rst

Lines changed: 11 additions & 2 deletions
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

Lines changed: 8 additions & 0 deletions
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

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

‎Include/internal/pycore_opcode_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ extern "C" {
6464
#defineRESUME_AFTER_YIELD_FROM 2
6565
#defineRESUME_AFTER_AWAIT 3
6666

67+
#defineRESUME_OPARG_LOCATION_MASK 0x3
68+
#defineRESUME_OPARG_DEPTH1_MASK 0x4
6769

6870
#ifdef__cplusplus
6971
}

‎Include/opcode_ids.h

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp