Skip to content

Commit

Permalink
GH-125837: Split LOAD_CONST into three. (GH-125972)
Browse files Browse the repository at this point in the history
* Add LOAD_CONST_IMMORTAL opcode

* Add LOAD_SMALL_INT opcode

* Remove RETURN_CONST opcode
  • Loading branch information
markshannon authored Oct 29, 2024
1 parent 67f5c5b commit faa3272
Show file tree
Hide file tree
Showing 33 changed files with 706 additions and 538 deletions.
23 changes: 16 additions & 7 deletions Doc/library/dis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -862,13 +862,6 @@ iterations of the loop.
Returns with ``STACK[-1]`` to the caller of the function.


.. opcode:: RETURN_CONST (consti)

Returns with ``co_consts[consti]`` to the caller of the function.

.. versionadded:: 3.12


.. opcode:: YIELD_VALUE

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


.. opcode:: LOAD_SMALL_INT (i)

Pushes the integer ``i`` onto the stack.
``i`` must be in ``range(256)``

.. versionadded:: 3.14


.. opcode:: LOAD_CONST_IMMORTAL (consti)

Pushes ``co_consts[consti]`` onto the stack.
Can be used when the constant value is known to be immortal.

.. versionadded:: 3.14


.. opcode:: LOAD_NAME (namei)

Pushes the value associated with ``co_names[namei]`` onto the stack.
Expand Down
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1123,7 +1123,7 @@ CPython bytecode changes
* Add the :opcode:`LOAD_SUPER_ATTR` instruction. (Contributed by Carl Meyer and
Vladimir Matveev in :gh:`103497`.)

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

Demos and Tools
===============
Expand Down
3 changes: 2 additions & 1 deletion Include/internal/pycore_magic_number.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ Known values:
Python 3.14a1 3606 (Specialize CALL_KW)
Python 3.14a1 3607 (Add pseudo instructions JUMP_IF_TRUE/FALSE)
Python 3.14a1 3608 (Add support for slices)
Python 3.14a2 3609 (Add LOAD_SMALL_INT and LOAD_CONST_IMMORTAL instructions, remove RETURN_CONST)
Python 3.15 will start with 3650
Expand All @@ -273,7 +274,7 @@ PC/launcher.c must also be updated.
*/

#define PYC_MAGIC_NUMBER 3608
#define PYC_MAGIC_NUMBER 3609
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
(little-endian) and then appending b'\r\n'. */
#define PYC_MAGIC_NUMBER_TOKEN \
Expand Down
33 changes: 17 additions & 16 deletions Include/internal/pycore_opcode_metadata.h

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

1 change: 0 additions & 1 deletion Include/internal/pycore_opcode_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ extern "C" {

#define IS_SCOPE_EXIT_OPCODE(opcode) \
((opcode) == RETURN_VALUE || \
(opcode) == RETURN_CONST || \
(opcode) == RAISE_VARARGS || \
(opcode) == RERAISE)

Expand Down
Loading

0 comments on commit faa3272

Please sign in to comment.