Skip to content

Commit

Permalink
pythongh-111354: Simplify _PyGen_yf by moving some of its work to the…
Browse files Browse the repository at this point in the history
… compiler and frame state (python#111648)
  • Loading branch information
iritkatriel authored and aisk committed Feb 11, 2024
1 parent 23c76e6 commit a248d0d
Show file tree
Hide file tree
Showing 16 changed files with 342 additions and 338 deletions.
3 changes: 2 additions & 1 deletion Doc/library/dis.rst
Expand Up @@ -824,7 +824,8 @@ iterations of the loop.
oparg set to be the exception block depth, for efficient closing of generators.

.. versionchanged:: 3.13
this opcode no longer has an oparg
oparg is ``1`` if this instruction is part of a yield-from or await, and ``0``
otherwise.

.. opcode:: SETUP_ANNOTATIONS

Expand Down
3 changes: 2 additions & 1 deletion Doc/whatsnew/3.13.rst
Expand Up @@ -948,7 +948,8 @@ Others
CPython bytecode changes
========================

* ``YIELD_VALUE`` no longer has an oparg. The oparg of ``RESUME`` was
* The oparg of ``YIELD_VALUE`` is now ``1`` if the yield is part of a
yield-from or await, and ``0`` otherwise. 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`.)
Expand Down
7 changes: 5 additions & 2 deletions Include/internal/pycore_frame.h
Expand Up @@ -36,13 +36,16 @@ extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code);
/* other API */

typedef enum _framestate {
FRAME_CREATED = -2,
FRAME_SUSPENDED = -1,
FRAME_CREATED = -3,
FRAME_SUSPENDED = -2,
FRAME_SUSPENDED_YIELD_FROM = -1,
FRAME_EXECUTING = 0,
FRAME_COMPLETED = 1,
FRAME_CLEARED = 4
} PyFrameState;

#define FRAME_STATE_SUSPENDED(S) ((S) == FRAME_SUSPENDED || (S) == FRAME_SUSPENDED_YIELD_FROM)

enum _frameowner {
FRAME_OWNED_BY_THREAD = 0,
FRAME_OWNED_BY_GENERATOR = 1,
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.

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.

150 changes: 75 additions & 75 deletions Lib/_opcode_metadata.py

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

0 comments on commit a248d0d

Please sign in to comment.