From 8ca837c2046d708eec2c34af502a817f038098dc Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 28 Sep 2025 19:59:57 +0100 Subject: [PATCH 1/7] Copyedit 3.14 What's New: CPython bytecode changes --- Doc/library/dis.rst | 21 +++++-------- Doc/whatsnew/3.14.rst | 72 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 79 insertions(+), 14 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index 711ef55def6949..c404215aa7b645 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -1102,11 +1102,6 @@ iterations of the loop. Pushes ``co_consts[consti]`` onto the stack. -.. opcode:: LOAD_CONST_IMMORTAL (consti) - - Works as :opcode:`LOAD_CONST`, but is more efficient for immortal objects. - - .. opcode:: LOAD_SMALL_INT (i) Pushes the integer ``i`` onto the stack. @@ -1968,14 +1963,20 @@ but are replaced by real opcodes or removed before bytecode is generated. Marks the end of the code block associated with the last ``SETUP_FINALLY``, ``SETUP_CLEANUP`` or ``SETUP_WITH``. + +.. opcode:: LOAD_CONST_IMMORTAL (consti) + + Works as :opcode:`LOAD_CONST`, but is more efficient for immortal objects. + + .. opcode:: JUMP -.. opcode:: JUMP_NO_INTERRUPT + JUMP_NO_INTERRUPT Undirected relative jump instructions which are replaced by their directed (forward/backward) counterparts by the assembler. .. opcode:: JUMP_IF_TRUE -.. opcode:: JUMP_IF_FALSE + JUMP_IF_FALSE Conditional jumps which do not impact the stack. Replaced by the sequence ``COPY 1``, ``TO_BOOL``, ``POP_JUMP_IF_TRUE/FALSE``. @@ -1991,12 +1992,6 @@ but are replaced by real opcodes or removed before bytecode is generated. This opcode is now a pseudo-instruction. -.. opcode:: LOAD_METHOD - - Optimized unbound method lookup. Emitted as a ``LOAD_ATTR`` opcode - with a flag set in the arg. - - .. _opcode_collections: Opcode collections diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index caeff3a00aa049..92538bf399aa28 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2800,9 +2800,79 @@ Deprecated CPython bytecode changes ======================== -* Replaced the opcode ``BINARY_SUBSCR`` by :opcode:`BINARY_OP` with oparg ``NB_SUBSCR``. +* Replaced the opcode :opcode:`!BINARY_SUBSCR` by :opcode:`BINARY_OP` + with oparg ``NB_SUBSCR``. (Contributed by Irit Katriel in :gh:`100239`.) +* Add the :opcode:`BUILD_INTERPOLATION` & :opcode:`BUILD_TEMPLATE` + opcodes to construct new :class:`~string.templatelib.Interpolation` + and :class:`~string.templatelib.Template` instances, respectively. + (Contributed by Lysandros Nikolaou and others in :gh:`132661`; + see also :ref:`PEP 750: Template strings `). + +* Remove the :opcode:`!BUILD_CONST_KEY_MAP` opcode. + Use :opcode:`BUILD_MAP` instead. + (Contributed by Mark Shannon in :gh:`122160`.) + +* Replace the :opcode:`!LOAD_ASSERTION_ERROR` opcode with + :opcode:`LOAD_COMMON_CONSTANT` and add support for loading + :exc:`NotImplementedError`. + +* Add the :opcode:`LOAD_FAST_BORROW` & :opcode:`LOAD_FAST_BORROW_LOAD_FAST_BORROW` + opcodes to reduce reference counting overhead when the interpreter can prove + that the reference in the frame outlives the reference loaded onto the stack. + (Contributed by Matt Page in :gh:`130704`.) + +* Add the :opcode:`LOAD_SMALL_INT` opcode, which pushes a small integer + equal to the ``oparg`` to the stack. + The :opcode:`!RETURN_CONST` opcode is removed as it is no longer used. + (Contributed by Mark Shannon in :gh:`125837`.) + +* Add the new :opcode:`LOAD_SPECIAL` instruction. + Generate code for :keyword:`with` and :keyword:`async with` statements + using the new instruction. + Removed the :opcode:`!BEFORE_WITH` and :opcode:`!BEFORE_ASYNC_WITH` instructions. + (Contributed by Mark Shannon in :gh:`120507`.) + +* Add the :opcode:`POP_ITER` opcode to support 'virtual' iterators. + (Contributed by Mark Shannon in :gh:`132554`.) + +Pseudo-instructions +------------------- + +* Add the :opcode:`!ANNOTATIONS_PLACEHOLDER` pseudo instruction + to support partially executed module-level annotations with + :ref:`deferred evaluation of annotations `. + (Contributed by Jelle Zijlstra in :gh:`130907`.) + +* Add the :opcode:`BINARY_OP_EXTEND` pseudo instruction, + which executes a pair of functions (guard and specialization functions) + accessed from the inline cache. + (Contributed by Irit Katriel in :gh:`100239`.) + +* Add three specialisations for :opcode:`CALL_KW`; + :opcode:`!CALL_KW_PY` for calls to Python functions, + :opcode:`!CALL_KW_BOUND_METHOD` for calls to bound methods, and + :opcode:`!CALL_KW_NON_PY` for all other calls. + (Contributed by Mark Shannon in :gh:`118093`.) + +* Add the :opcode:`JUMP_IF_TRUE` and :opcode:`JUMP_IF_FALSE` pseudo instructions, + conditional jumps which do not impact the stack. + Replaced by the sequence ``COPY 1``, ``TO_BOOL``, ``POP_JUMP_IF_TRUE/FALSE``. + (Contributed by Irit Katriel in :gh:`124285`.) + +* Add the :opcode:`LOAD_CONST_MORTAL` pseudo instruction. + (Contributed by Mark Shannon in :gh:`128685`.) + +* Add the :opcode:`LOAD_CONST_IMMORTAL` pseudo instruction, + which does the same as :opcode:`!LOAD_CONST`, but is more efficient + for immortal objects. + (Contributed by Mark Shannon in :gh:`125837`.) + +* Add the :opcode:`NOT_TAKEN` pseudo instruction, used by :mod:`sys.monitoring` + to record branch events (i.e. :monitoring-event:`BRANCH_LEFT`). + (Contributed by Mark Shannon in :gh:`122548`.) + C API changes ============= From 7a1cc7fd011d5bba85c5b06b394390ac7d0b0fce Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:32:44 +0100 Subject: [PATCH 2/7] Delete LOAD_CONST_IMMORTAL (it exists in 3.14 but not 15) --- Doc/library/dis.rst | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index c404215aa7b645..d21198819223ac 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -1964,11 +1964,6 @@ but are replaced by real opcodes or removed before bytecode is generated. ``SETUP_CLEANUP`` or ``SETUP_WITH``. -.. opcode:: LOAD_CONST_IMMORTAL (consti) - - Works as :opcode:`LOAD_CONST`, but is more efficient for immortal objects. - - .. opcode:: JUMP JUMP_NO_INTERRUPT From ab8a8b354a561ad88c60db5a5e09d86f9908b3a3 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:34:05 +0100 Subject: [PATCH 3/7] fixup! Delete LOAD_CONST_IMMORTAL (it exists in 3.14 but not 15) --- Doc/whatsnew/3.14.rst | 2 +- Misc/NEWS.d/3.14.0a2.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 92538bf399aa28..c894038883333b 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2864,7 +2864,7 @@ Pseudo-instructions * Add the :opcode:`LOAD_CONST_MORTAL` pseudo instruction. (Contributed by Mark Shannon in :gh:`128685`.) -* Add the :opcode:`LOAD_CONST_IMMORTAL` pseudo instruction, +* Add the :opcode:`!LOAD_CONST_IMMORTAL` pseudo instruction, which does the same as :opcode:`!LOAD_CONST`, but is more efficient for immortal objects. (Contributed by Mark Shannon in :gh:`125837`.) diff --git a/Misc/NEWS.d/3.14.0a2.rst b/Misc/NEWS.d/3.14.0a2.rst index 7405a1344a9fa6..4a64bcc75206f0 100644 --- a/Misc/NEWS.d/3.14.0a2.rst +++ b/Misc/NEWS.d/3.14.0a2.rst @@ -1400,7 +1400,7 @@ The :class:`memoryview` type now supports subscription, making it a .. nonce: KlCdgD .. section: Core and Builtins -Adds :opcode:`LOAD_SMALL_INT` and :opcode:`LOAD_CONST_IMMORTAL` +Adds :opcode:`LOAD_SMALL_INT` and :opcode:`!LOAD_CONST_IMMORTAL` instructions. ``LOAD_SMALL_INT`` pushes a small integer equal to the ``oparg`` to the stack. ``LOAD_CONST_IMMORTAL`` does the same as ``LOAD_CONST`` but is more efficient for immortal objects. Removes From 4bc622599489479dd489e1af97fb868b87a38696 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:42:31 +0100 Subject: [PATCH 4/7] wordsmithing --- Doc/whatsnew/3.14.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index c894038883333b..ea4d95dcf74352 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2800,8 +2800,8 @@ Deprecated CPython bytecode changes ======================== -* Replaced the opcode :opcode:`!BINARY_SUBSCR` by :opcode:`BINARY_OP` - with oparg ``NB_SUBSCR``. +* Replaced the opcode :opcode:`!BINARY_SUBSCR` by the :opcode:`BINARY_OP` + opcode with the ``NB_SUBSCR`` oparg. (Contributed by Irit Katriel in :gh:`100239`.) * Add the :opcode:`BUILD_INTERPOLATION` & :opcode:`BUILD_TEMPLATE` From 85b20d3e8cede09e18873a16be94613f597e19f8 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+aa-turner@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:49:54 +0100 Subject: [PATCH 5/7] fix refwarn errors --- Doc/library/dis.rst | 2 +- Doc/whatsnew/3.14.rst | 4 ++-- Doc/whatsnew/3.7.rst | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst index d21198819223ac..284eeff5e4dc7e 100644 --- a/Doc/library/dis.rst +++ b/Doc/library/dis.rst @@ -1642,7 +1642,7 @@ iterations of the loop. Pushes a ``NULL`` to the stack. Used in the call sequence to match the ``NULL`` pushed by - :opcode:`LOAD_METHOD` for non-method calls. + :opcode:`!LOAD_METHOD` for non-method calls. .. versionadded:: 3.11 diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index ea4d95dcf74352..2799f56417f8e4 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2845,7 +2845,7 @@ Pseudo-instructions :ref:`deferred evaluation of annotations `. (Contributed by Jelle Zijlstra in :gh:`130907`.) -* Add the :opcode:`BINARY_OP_EXTEND` pseudo instruction, +* Add the :opcode:`!BINARY_OP_EXTEND` pseudo instruction, which executes a pair of functions (guard and specialization functions) accessed from the inline cache. (Contributed by Irit Katriel in :gh:`100239`.) @@ -2861,7 +2861,7 @@ Pseudo-instructions Replaced by the sequence ``COPY 1``, ``TO_BOOL``, ``POP_JUMP_IF_TRUE/FALSE``. (Contributed by Irit Katriel in :gh:`124285`.) -* Add the :opcode:`LOAD_CONST_MORTAL` pseudo instruction. +* Add the :opcode:`!LOAD_CONST_MORTAL` pseudo instruction. (Contributed by Mark Shannon in :gh:`128685`.) * Add the :opcode:`!LOAD_CONST_IMMORTAL` pseudo instruction, diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 6e6934befccb3b..9ac3bf53833f93 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -2483,7 +2483,7 @@ avoiding possible problems use new functions :c:func:`PySlice_Unpack` and CPython bytecode changes ------------------------ -There are two new opcodes: :opcode:`LOAD_METHOD` and :opcode:`!CALL_METHOD`. +There are two new opcodes: :opcode:`!LOAD_METHOD` and :opcode:`!CALL_METHOD`. (Contributed by Yury Selivanov and INADA Naoki in :issue:`26110`.) The :opcode:`!STORE_ANNOTATION` opcode has been removed. From a53114a50ab84fddfb18a2ad0561b722370373ae Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Sun, 28 Sep 2025 20:50:54 +0100 Subject: [PATCH 6/7] Apply suggestions from code review Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index 2799f56417f8e4..e37e23269d44eb 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2804,7 +2804,7 @@ CPython bytecode changes opcode with the ``NB_SUBSCR`` oparg. (Contributed by Irit Katriel in :gh:`100239`.) -* Add the :opcode:`BUILD_INTERPOLATION` & :opcode:`BUILD_TEMPLATE` +* Add the :opcode:`BUILD_INTERPOLATION` and :opcode:`BUILD_TEMPLATE` opcodes to construct new :class:`~string.templatelib.Interpolation` and :class:`~string.templatelib.Template` instances, respectively. (Contributed by Lysandros Nikolaou and others in :gh:`132661`; @@ -2818,12 +2818,12 @@ CPython bytecode changes :opcode:`LOAD_COMMON_CONSTANT` and add support for loading :exc:`NotImplementedError`. -* Add the :opcode:`LOAD_FAST_BORROW` & :opcode:`LOAD_FAST_BORROW_LOAD_FAST_BORROW` +* Add the :opcode:`LOAD_FAST_BORROW` and :opcode:`LOAD_FAST_BORROW_LOAD_FAST_BORROW` opcodes to reduce reference counting overhead when the interpreter can prove that the reference in the frame outlives the reference loaded onto the stack. (Contributed by Matt Page in :gh:`130704`.) -* Add the :opcode:`LOAD_SMALL_INT` opcode, which pushes a small integer +* Add the :opcode:`LOAD_SMALL_INT` opcode, which pushes a small integer equal to the ``oparg`` to the stack. The :opcode:`!RETURN_CONST` opcode is removed as it is no longer used. (Contributed by Mark Shannon in :gh:`125837`.) @@ -2850,7 +2850,7 @@ Pseudo-instructions accessed from the inline cache. (Contributed by Irit Katriel in :gh:`100239`.) -* Add three specialisations for :opcode:`CALL_KW`; +* Add three specializations for :opcode:`CALL_KW`; :opcode:`!CALL_KW_PY` for calls to Python functions, :opcode:`!CALL_KW_BOUND_METHOD` for calls to bound methods, and :opcode:`!CALL_KW_NON_PY` for all other calls. From 46716e9893c146b27a5fc4fd4390fcffe436f7c8 Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Mon, 29 Sep 2025 16:06:01 +0100 Subject: [PATCH 7/7] Update Doc/whatsnew/3.14.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Doc/whatsnew/3.14.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index e37e23269d44eb..b3a3927aa6f6fc 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -2870,7 +2870,7 @@ Pseudo-instructions (Contributed by Mark Shannon in :gh:`125837`.) * Add the :opcode:`NOT_TAKEN` pseudo instruction, used by :mod:`sys.monitoring` - to record branch events (i.e. :monitoring-event:`BRANCH_LEFT`). + to record branch events (such as :monitoring-event:`BRANCH_LEFT`). (Contributed by Mark Shannon in :gh:`122548`.)