Skip to content

Commit

Permalink
gh-111354: simplify detection of RESUME after YIELD_VALUE at except-d…
Browse files Browse the repository at this point in the history
…epth 1 (#111459)
  • Loading branch information
iritkatriel committed Nov 2, 2023
1 parent 970e719 commit 52cc4af
Show file tree
Hide file tree
Showing 18 changed files with 362 additions and 339 deletions.
13 changes: 11 additions & 2 deletions Doc/library/dis.rst
Expand Up @@ -823,6 +823,8 @@ iterations of the loop.
.. versionchanged:: 3.12
oparg set to be the exception block depth, for efficient closing of generators.

.. versionchanged:: 3.13
this opcode no longer has an oparg

.. opcode:: SETUP_ANNOTATIONS

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


.. opcode:: RESUME (where)
.. opcode:: RESUME (context)

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

The ``where`` operand marks where the ``RESUME`` occurs:
The ``context`` oparand consists of two parts. The lowest two bits
indicate where the ``RESUME`` occurs:

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

The next bit is ``1`` if the RESUME is at except-depth ``1``, and ``0``
otherwise.

.. versionadded:: 3.11

.. versionchanged:: 3.13
The oparg value changed to include information about except-depth


.. opcode:: RETURN_GENERATOR

Expand Down
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.13.rst
Expand Up @@ -945,6 +945,14 @@ Others

* None yet

CPython bytecode changes
========================

* ``YIELD_VALUE`` no longer has an oparg. The oparg of ``RESUME`` was
changed to add a bit indicating whether the except-depth is 1, which
is needed to optimize closing of generators.
(Contributed by Irit Katriel in :gh:`111354`.)

Porting to Python 3.13
======================

Expand Down
6 changes: 3 additions & 3 deletions Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Include/internal/pycore_opcode_utils.h
Expand Up @@ -64,6 +64,8 @@ extern "C" {
#define RESUME_AFTER_YIELD_FROM 2
#define RESUME_AFTER_AWAIT 3

#define RESUME_OPARG_LOCATION_MASK 0x3
#define RESUME_OPARG_DEPTH1_MASK 0x4

#ifdef __cplusplus
}
Expand Down
150 changes: 75 additions & 75 deletions Include/opcode_ids.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52cc4af

Please sign in to comment.