Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d49aba5

Browse files
authored
gh-111354: Simplify _PyGen_yf by moving some of its work to the compiler and frame state (#111648)
1 parent 7810b69 commit d49aba5

16 files changed

+342
-338
lines changed

Doc/library/dis.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,8 @@ iterations of the loop.
824824
oparg set to be the exception block depth, for efficient closing of generators.
825825

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

829830
.. opcode:: SETUP_ANNOTATIONS
830831

Doc/whatsnew/3.13.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,8 @@ Others
948948
CPython bytecode changes
949949
========================
950950

951-
* ``YIELD_VALUE`` no longer has an oparg. The oparg of ``RESUME`` was
951+
* The oparg of ``YIELD_VALUE`` is now ``1`` if the yield is part of a
952+
yield-from or await, and ``0`` otherwise. The oparg of ``RESUME`` was
952953
changed to add a bit indicating whether the except-depth is 1, which
953954
is needed to optimize closing of generators.
954955
(Contributed by Irit Katriel in :gh:`111354`.)

Include/internal/pycore_frame.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,16 @@ extern PyFrameObject* _PyFrame_New_NoTrack(PyCodeObject *code);
3636
/* other API */
3737

3838
typedef enum _framestate {
39-
FRAME_CREATED = -2,
40-
FRAME_SUSPENDED = -1,
39+
FRAME_CREATED = -3,
40+
FRAME_SUSPENDED = -2,
41+
FRAME_SUSPENDED_YIELD_FROM = -1,
4142
FRAME_EXECUTING = 0,
4243
FRAME_COMPLETED = 1,
4344
FRAME_CLEARED = 4
4445
} PyFrameState;
4546

47+
#define FRAME_STATE_SUSPENDED(S) ((S) == FRAME_SUSPENDED || (S) == FRAME_SUSPENDED_YIELD_FROM)
48+
4649
enum _frameowner {
4750
FRAME_OWNED_BY_THREAD = 0,
4851
FRAME_OWNED_BY_GENERATOR = 1,

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/opcode_ids.h

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

Lib/_opcode_metadata.py

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

0 commit comments

Comments
 (0)