Skip to content

Commit faa3272

Browse files
authored
GH-125837: Split LOAD_CONST into three. (GH-125972)
* Add LOAD_CONST_IMMORTAL opcode * Add LOAD_SMALL_INT opcode * Remove RETURN_CONST opcode
1 parent 67f5c5b commit faa3272

33 files changed

+706
-538
lines changed

Diff for: Doc/library/dis.rst

+16-7
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,6 @@ iterations of the loop.
862862
Returns with ``STACK[-1]`` to the caller of the function.
863863

864864

865-
.. opcode:: RETURN_CONST (consti)
866-
867-
Returns with ``co_consts[consti]`` to the caller of the function.
868-
869-
.. versionadded:: 3.12
870-
871-
872865
.. opcode:: YIELD_VALUE
873866

874867
Yields ``STACK.pop()`` from a :term:`generator`.
@@ -1086,6 +1079,22 @@ iterations of the loop.
10861079
Pushes ``co_consts[consti]`` onto the stack.
10871080

10881081

1082+
.. opcode:: LOAD_SMALL_INT (i)
1083+
1084+
Pushes the integer ``i`` onto the stack.
1085+
``i`` must be in ``range(256)``
1086+
1087+
.. versionadded:: 3.14
1088+
1089+
1090+
.. opcode:: LOAD_CONST_IMMORTAL (consti)
1091+
1092+
Pushes ``co_consts[consti]`` onto the stack.
1093+
Can be used when the constant value is known to be immortal.
1094+
1095+
.. versionadded:: 3.14
1096+
1097+
10891098
.. opcode:: LOAD_NAME (namei)
10901099

10911100
Pushes the value associated with ``co_names[namei]`` onto the stack.

Diff for: Doc/whatsnew/3.12.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,7 @@ CPython bytecode changes
11231123
* Add the :opcode:`LOAD_SUPER_ATTR` instruction. (Contributed by Carl Meyer and
11241124
Vladimir Matveev in :gh:`103497`.)
11251125

1126-
* Add the :opcode:`RETURN_CONST` instruction. (Contributed by Wenyang Wang in :gh:`101632`.)
1126+
* Add the ``RETURN_CONST`` instruction. (Contributed by Wenyang Wang in :gh:`101632`.)
11271127

11281128
Demos and Tools
11291129
===============

Diff for: Include/internal/pycore_magic_number.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ Known values:
261261
Python 3.14a1 3606 (Specialize CALL_KW)
262262
Python 3.14a1 3607 (Add pseudo instructions JUMP_IF_TRUE/FALSE)
263263
Python 3.14a1 3608 (Add support for slices)
264+
Python 3.14a2 3609 (Add LOAD_SMALL_INT and LOAD_CONST_IMMORTAL instructions, remove RETURN_CONST)
264265
265266
Python 3.15 will start with 3650
266267
@@ -273,7 +274,7 @@ PC/launcher.c must also be updated.
273274
274275
*/
275276

276-
#define PYC_MAGIC_NUMBER 3608
277+
#define PYC_MAGIC_NUMBER 3609
277278
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
278279
(little-endian) and then appending b'\r\n'. */
279280
#define PYC_MAGIC_NUMBER_TOKEN \

Diff for: Include/internal/pycore_opcode_metadata.h

+17-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Include/internal/pycore_opcode_utils.h

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ extern "C" {
4747

4848
#define IS_SCOPE_EXIT_OPCODE(opcode) \
4949
((opcode) == RETURN_VALUE || \
50-
(opcode) == RETURN_CONST || \
5150
(opcode) == RAISE_VARARGS || \
5251
(opcode) == RERAISE)
5352

0 commit comments

Comments
 (0)