Skip to content

Commit 98e855f

Browse files
gh-119180: Add LOAD_COMMON_CONSTANT opcode (#119321)
The PEP 649 implementation will require a way to load NotImplementedError from the bytecode. @markshannon suggested implementing this by converting LOAD_ASSERTION_ERROR into a more general mechanism for loading constants. This PR adds this new opcode. I will work on the rest of the implementation of the PEP separately. Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
1 parent 506b1a3 commit 98e855f

22 files changed

+337
-288
lines changed

Diff for: Doc/library/dis.rst

+5-4
Original file line numberDiff line numberDiff line change
@@ -929,12 +929,13 @@ iterations of the loop.
929929
Exception representation on the stack now consist of one, not three, items.
930930

931931

932-
.. opcode:: LOAD_ASSERTION_ERROR
932+
.. opcode:: LOAD_COMMON_CONSTANT
933933

934-
Pushes :exc:`AssertionError` onto the stack. Used by the :keyword:`assert`
935-
statement.
934+
Pushes a common constant onto the stack. The interpreter contains a hardcoded
935+
list of constants supported by this instruction. Used by the :keyword:`assert`
936+
statement to load :exc:`AssertionError`.
936937

937-
.. versionadded:: 3.9
938+
.. versionadded:: 3.14
938939

939940

940941
.. opcode:: LOAD_BUILD_CLASS

Diff for: Include/internal/pycore_opcode_metadata.h

+8-8
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

+5
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ extern "C" {
5858
#define MAKE_FUNCTION_ANNOTATIONS 0x04
5959
#define MAKE_FUNCTION_CLOSURE 0x08
6060

61+
/* Values used as the oparg for LOAD_COMMON_CONSTANT */
62+
#define CONSTANT_ASSERTIONERROR 0
63+
#define CONSTANT_NOTIMPLEMENTEDERROR 1
64+
#define NUM_COMMON_CONSTANTS 2
65+
6166
/* Values used in the oparg for RESUME */
6267
#define RESUME_AT_FUNC_START 0
6368
#define RESUME_AFTER_YIELD 1

Diff for: Include/internal/pycore_uop_ids.h

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

Diff for: Include/internal/pycore_uop_metadata.h

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

Diff for: Include/opcode_ids.h

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

0 commit comments

Comments
 (0)