]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-105481: simplify definition of pseudo ops in Lib/opcode.py (#107561)
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>
Wed, 2 Aug 2023 17:16:57 +0000 (18:16 +0100)
committerGitHub <noreply@github.com>
Wed, 2 Aug 2023 17:16:57 +0000 (18:16 +0100)
Doc/whatsnew/3.13.rst
Include/opcode.h
Lib/opcode.py
Misc/NEWS.d/next/Library/2023-08-01-21-43-58.gh-issue-105481.cl2ajS.rst [new file with mode: 0644]
Tools/build/generate_opcode_h.py

index 22c1e03470f5dc2b868c1f9c60db594cc034b662..63cdee6cf1a4f39dfd6d146cd5f16677196d4dea 100644 (file)
@@ -124,6 +124,11 @@ opcode
   This field was added in 3.12, it was never documented and is not intended for
   external usage. (Contributed by Irit Katriel in :gh:`105481`.)
 
+* Removed ``opcode.is_pseudo``, ``opcode.MIN_PSEUDO_OPCODE`` and
+  ``opcode.MAX_PSEUDO_OPCODE``, which were added in 3.12, were never
+  documented or exposed through ``dis``, and were not intended to be
+  used externally.
+
 pathlib
 -------
 
index eb4bb85e5b667df54bdf9963c3afdb3fdf3dc37e..ede1518b6fd25c9604d292faebc26bbeee73c536 100644 (file)
@@ -146,7 +146,6 @@ extern "C" {
 #define INSTRUMENTED_END_SEND                  252
 #define INSTRUMENTED_INSTRUCTION               253
 #define INSTRUMENTED_LINE                      254
-#define MIN_PSEUDO_OPCODE                      256
 #define SETUP_FINALLY                          256
 #define SETUP_CLEANUP                          257
 #define SETUP_WITH                             258
@@ -159,7 +158,6 @@ extern "C" {
 #define LOAD_ZERO_SUPER_ATTR                   265
 #define STORE_FAST_MAYBE_NULL                  266
 #define LOAD_CLOSURE                           267
-#define MAX_PSEUDO_OPCODE                      267
 #define TO_BOOL_ALWAYS_TRUE                      7
 #define TO_BOOL_BOOL                             8
 #define TO_BOOL_INT                             10
index 51432ab1fab3f15e55b5b04177122afcb3e6b359..5a9f8ddd0738db512ccdf1660e192c5058733007 100644 (file)
@@ -19,23 +19,11 @@ if sys.version_info[:2] >= (3, 13):
 
 cmp_op = ('<', '<=', '==', '!=', '>', '>=')
 
-def is_pseudo(op):
-    return op >= MIN_PSEUDO_OPCODE and op <= MAX_PSEUDO_OPCODE
-
 opmap = {}
 
-# pseudo opcodes (used in the compiler) mapped to the values
-# they can become in the actual code.
-_pseudo_ops = {}
-
 def def_op(name, op):
     opmap[name] = op
 
-def pseudo_op(name, op, real_ops):
-    def_op(name, op)
-    _pseudo_ops[name] = real_ops
-
-
 # Instruction opcodes for compiled code
 # Blank lines correspond to available opcodes
 
@@ -212,29 +200,27 @@ def_op('INSTRUMENTED_LINE', 254)
 # 255 is reserved
 
 
-MIN_PSEUDO_OPCODE = 256
-
-pseudo_op('SETUP_FINALLY', 256, ['NOP'])
-pseudo_op('SETUP_CLEANUP', 257, ['NOP'])
-pseudo_op('SETUP_WITH', 258, ['NOP'])
-pseudo_op('POP_BLOCK', 259, ['NOP'])
+# Pseudo ops are above 255:
 
-pseudo_op('JUMP', 260, ['JUMP_FORWARD', 'JUMP_BACKWARD'])
-pseudo_op('JUMP_NO_INTERRUPT', 261, ['JUMP_FORWARD', 'JUMP_BACKWARD_NO_INTERRUPT'])
+def_op('SETUP_FINALLY', 256)
+def_op('SETUP_CLEANUP', 257)
+def_op('SETUP_WITH', 258)
+def_op('POP_BLOCK', 259)
 
-pseudo_op('LOAD_METHOD', 262, ['LOAD_ATTR'])
-pseudo_op('LOAD_SUPER_METHOD', 263, ['LOAD_SUPER_ATTR'])
-pseudo_op('LOAD_ZERO_SUPER_METHOD', 264, ['LOAD_SUPER_ATTR'])
-pseudo_op('LOAD_ZERO_SUPER_ATTR', 265, ['LOAD_SUPER_ATTR'])
+def_op('JUMP', 260)
+def_op('JUMP_NO_INTERRUPT', 261)
 
-pseudo_op('STORE_FAST_MAYBE_NULL', 266, ['STORE_FAST'])
-pseudo_op('LOAD_CLOSURE', 267, ['LOAD_FAST'])
+def_op('LOAD_METHOD', 262)
+def_op('LOAD_SUPER_METHOD', 263)
+def_op('LOAD_ZERO_SUPER_METHOD', 264)
+def_op('LOAD_ZERO_SUPER_ATTR', 265)
 
-MAX_PSEUDO_OPCODE = MIN_PSEUDO_OPCODE + len(_pseudo_ops) - 1
+def_op('STORE_FAST_MAYBE_NULL', 266)
+def_op('LOAD_CLOSURE', 267)
 
-del def_op, pseudo_op
+del def_op
 
-opname = ['<%r>' % (op,) for op in range(MAX_PSEUDO_OPCODE + 1)]
+opname = ['<%r>' % (op,) for op in range(max(opmap.values()) + 1)]
 for op, i in opmap.items():
     opname[i] = op
 
diff --git a/Misc/NEWS.d/next/Library/2023-08-01-21-43-58.gh-issue-105481.cl2ajS.rst b/Misc/NEWS.d/next/Library/2023-08-01-21-43-58.gh-issue-105481.cl2ajS.rst
new file mode 100644 (file)
index 0000000..d02f909
--- /dev/null
@@ -0,0 +1,2 @@
+Remove ``opcode.is_pseudo``, ``opcode.MIN_PSEUDO_OPCODE`` and ``opcode.MAX_PSEUDO_OPCODE``,
+which were added in 3.12, were never documented and were not intended to be used externally.
index 16b028dc1205ac426f289adfb7d09ff2dea9a521..3a817326c94cbbe97258e8da3ac444a57c17c7cd 100644 (file)
@@ -72,10 +72,7 @@ def main(opcode_py,
     opcode = get_python_module_dict(opcode_py)
     opmap = opcode['opmap']
     opname = opcode['opname']
-    is_pseudo = opcode['is_pseudo']
 
-    MIN_PSEUDO_OPCODE = opcode["MIN_PSEUDO_OPCODE"]
-    MAX_PSEUDO_OPCODE = opcode["MAX_PSEUDO_OPCODE"]
     MIN_INSTRUMENTED_OPCODE = opcode["MIN_INSTRUMENTED_OPCODE"]
 
     NUM_OPCODES = len(opname)
@@ -101,16 +98,11 @@ def main(opcode_py,
         for name in opname:
             if name in opmap:
                 op = opmap[name]
-                if op == MIN_PSEUDO_OPCODE:
-                    fobj.write(DEFINE.format("MIN_PSEUDO_OPCODE", MIN_PSEUDO_OPCODE))
                 if op == MIN_INSTRUMENTED_OPCODE:
                     fobj.write(DEFINE.format("MIN_INSTRUMENTED_OPCODE", MIN_INSTRUMENTED_OPCODE))
 
                 fobj.write(DEFINE.format(name, op))
 
-                if op == MAX_PSEUDO_OPCODE:
-                    fobj.write(DEFINE.format("MAX_PSEUDO_OPCODE", MAX_PSEUDO_OPCODE))
-
 
         for name, op in specialized_opmap.items():
             fobj.write(DEFINE.format(name, op))
@@ -126,7 +118,7 @@ def main(opcode_py,
 
         deoptcodes = {}
         for basic, op in opmap.items():
-            if not is_pseudo(op):
+            if op < 256:
                 deoptcodes[basic] = basic
         for basic, family in _opcode_metadata["_specializations"].items():
             for specialized in family: