[Python-checkins] bpo-46009: Remove GEN_START (GH-30367)

brandtbucher webhook-mailer at python.org
Tue Jan 4 14:38:37 EST 2022


https://github.com/python/cpython/commit/31e43cbe5f01cdd5b5ab330ec3040920e8b61a91
commit: 31e43cbe5f01cdd5b5ab330ec3040920e8b61a91
branch: main
author: Brandt Bucher <brandt at python.org>
committer: brandtbucher <brandtbucher at gmail.com>
date: 2022-01-04T11:38:32-08:00
summary:

bpo-46009: Remove GEN_START (GH-30367)

files:
A Misc/NEWS.d/next/Core and Builtins/2022-01-03-11-36-34.bpo-46009.QZGrov.rst
M Doc/library/dis.rst
M Doc/whatsnew/3.11.rst
M Include/opcode.h
M Lib/importlib/_bootstrap_external.py
M Lib/opcode.py
M Objects/frameobject.c
M Python/ceval.c
M Python/compile.c
M Python/opcode_targets.h

diff --git a/Doc/library/dis.rst b/Doc/library/dis.rst
index 87ec584789d31..8490a09669656 100644
--- a/Doc/library/dis.rst
+++ b/Doc/library/dis.rst
@@ -1175,14 +1175,6 @@ All of the following opcodes use their arguments.
       Previously, this instruction also pushed a boolean value indicating
       success (``True``) or failure (``False``).
 
-.. opcode:: GEN_START (kind)
-
-    Pops TOS. The ``kind`` operand corresponds to the type of generator or
-    coroutine. The legal kinds are 0 for generator, 1 for coroutine,
-    and 2 for async generator.
-
-   .. versionadded:: 3.10
-
 
 .. opcode:: ROT_N (count)
 
diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst
index be6cb158a8049..6794e828a7252 100644
--- a/Doc/whatsnew/3.11.rst
+++ b/Doc/whatsnew/3.11.rst
@@ -388,7 +388,7 @@ CPython bytecode changes
   This decouples the argument shifting for methods from the handling of
   keyword arguments and allows better specialization of calls.
 
-* Removed ``COPY_DICT_WITHOUT_KEYS``.
+* Removed ``COPY_DICT_WITHOUT_KEYS`` and ``GEN_START``.
 
 * :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` no longer push an additional
   boolean value indicating whether the match succeeded or failed. Instead, they
diff --git a/Include/opcode.h b/Include/opcode.h
index ef334de601fee..1af54943e1ca5 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -84,7 +84,6 @@ extern "C" {
 #define STORE_FAST                      125
 #define DELETE_FAST                     126
 #define JUMP_IF_NOT_EG_MATCH            127
-#define GEN_START                       129
 #define RAISE_VARARGS                   130
 #define MAKE_FUNCTION                   132
 #define BUILD_SLICE                     133
@@ -164,9 +163,9 @@ extern "C" {
 #define STORE_ATTR_WITH_HINT             81
 #define LOAD_FAST__LOAD_FAST             87
 #define STORE_FAST__LOAD_FAST           128
-#define LOAD_FAST__LOAD_CONST           131
-#define LOAD_CONST__LOAD_FAST           134
-#define STORE_FAST__STORE_FAST          140
+#define LOAD_FAST__LOAD_CONST           129
+#define LOAD_CONST__LOAD_FAST           131
+#define STORE_FAST__STORE_FAST          134
 #define DO_TRACING                      255
 #ifdef NEED_OPCODE_JUMP_TABLES
 static uint32_t _PyOpcode_RelativeJump[8] = {
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index 29324664cea86..872d6d96a74b4 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -377,6 +377,7 @@ def _write_atomic(path, data, mode=0o666):
 #     Python 3.11a4 3469 (bpo-45711: remove type, traceback from exc_info)
 #     Python 3.11a4 3470 (bpo-46221: PREP_RERAISE_STAR no longer pushes lasti)
 #     Python 3.11a4 3471 (bpo-46202: remove pop POP_EXCEPT_AND_RERAISE)
+#     Python 3.11a4 3472 (bpo-46009: replace GEN_START with POP_TOP)
 
 #
 # MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -386,7 +387,7 @@ def _write_atomic(path, data, mode=0o666):
 # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
 # in PC/launcher.c must also be updated.
 
-MAGIC_NUMBER = (3471).to_bytes(2, 'little') + b'\r\n'
+MAGIC_NUMBER = (3472).to_bytes(2, 'little') + b'\r\n'
 _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little')  # For import.c
 
 _PYCACHE = '__pycache__'
diff --git a/Lib/opcode.py b/Lib/opcode.py
index 9bbff182f08fd..f99e20ad0a670 100644
--- a/Lib/opcode.py
+++ b/Lib/opcode.py
@@ -151,7 +151,6 @@ def jabs_op(name, op):
 
 jabs_op('JUMP_IF_NOT_EG_MATCH', 127)
 
-def_op('GEN_START', 129)        # Kind of generator/coroutine
 def_op('RAISE_VARARGS', 130)    # Number of raise arguments (1, 2, or 3)
 
 def_op('MAKE_FUNCTION', 132)    # Flags
diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-01-03-11-36-34.bpo-46009.QZGrov.rst b/Misc/NEWS.d/next/Core and Builtins/2022-01-03-11-36-34.bpo-46009.QZGrov.rst
new file mode 100644
index 0000000000000..1ffcc766725e6
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2022-01-03-11-36-34.bpo-46009.QZGrov.rst	
@@ -0,0 +1 @@
+Remove the ``GEN_START`` opcode.
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 078fcfc6cf607..4dd2183040dac 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -192,6 +192,11 @@ mark_stacks(PyCodeObject *code_obj, int len)
         stacks[i] = UNINITIALIZED;
     }
     stacks[0] = 0;
+    if (code_obj->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR))
+    {
+        // Generators get sent None while starting:
+        stacks[0] = push_value(stacks[0], Object);
+    }
     int todo = 1;
     while (todo) {
         todo = 0;
@@ -291,9 +296,6 @@ mark_stacks(PyCodeObject *code_obj, int len)
                 case RERAISE:
                     /* End of block */
                     break;
-                case GEN_START:
-                    stacks[i+1] = next_stack;
-                    break;
                 default:
                 {
                     int delta = PyCompile_OpcodeStackEffect(opcode, _Py_OPARG(code[i]));
diff --git a/Python/ceval.c b/Python/ceval.c
index 81bea44465dc7..953876f6226b9 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -2709,14 +2709,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
             return retval;
         }
 
-        TARGET(GEN_START) {
-            PyObject *none = POP();
-            assert(none == Py_None);
-            assert(oparg < 3);
-            Py_DECREF(none);
-            DISPATCH();
-        }
-
         TARGET(POP_EXCEPT) {
             _PyErr_StackItem *exc_info = tstate->exc_info;
             PyObject *value = exc_info->exc_value;
diff --git a/Python/compile.c b/Python/compile.c
index 9d3752936266c..3a390751fe2d2 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -1208,8 +1208,6 @@ stack_effect(int opcode, int oparg, int jump)
             return 1;
         case LIST_TO_TUPLE:
             return 0;
-        case GEN_START:
-            return -1;
         case LIST_EXTEND:
         case SET_UPDATE:
         case DICT_MERGE:
@@ -8028,27 +8026,16 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
 
     /* Add the generator prefix instructions. */
     if (flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
-        int kind;
-        if (flags & CO_COROUTINE) {
-            kind = 1;
-        }
-        else if (flags & CO_ASYNC_GENERATOR) {
-            kind = 2;
-        }
-        else {
-            kind = 0;
-        }
-
-        struct instr gen_start = {
-            .i_opcode = GEN_START,
-            .i_oparg = kind,
+        struct instr pop_top = {
+            .i_opcode = POP_TOP,
+            .i_oparg = 0,
             .i_lineno = -1,
             .i_col_offset = -1,
             .i_end_lineno = -1,
             .i_end_col_offset = -1,
             .i_target = NULL,
         };
-        if (insert_instruction(entryblock, 0, &gen_start) < 0) {
+        if (insert_instruction(entryblock, 0, &pop_top) < 0) {
             return -1;
         }
     }
diff --git a/Python/opcode_targets.h b/Python/opcode_targets.h
index a8f1398bfa66d..e9f1a483b970c 100644
--- a/Python/opcode_targets.h
+++ b/Python/opcode_targets.h
@@ -128,18 +128,18 @@ static void *opcode_targets[256] = {
     &&TARGET_DELETE_FAST,
     &&TARGET_JUMP_IF_NOT_EG_MATCH,
     &&TARGET_STORE_FAST__LOAD_FAST,
-    &&TARGET_GEN_START,
-    &&TARGET_RAISE_VARARGS,
     &&TARGET_LOAD_FAST__LOAD_CONST,
+    &&TARGET_RAISE_VARARGS,
+    &&TARGET_LOAD_CONST__LOAD_FAST,
     &&TARGET_MAKE_FUNCTION,
     &&TARGET_BUILD_SLICE,
-    &&TARGET_LOAD_CONST__LOAD_FAST,
+    &&TARGET_STORE_FAST__STORE_FAST,
     &&TARGET_MAKE_CELL,
     &&TARGET_LOAD_CLOSURE,
     &&TARGET_LOAD_DEREF,
     &&TARGET_STORE_DEREF,
     &&TARGET_DELETE_DEREF,
-    &&TARGET_STORE_FAST__STORE_FAST,
+    &&_unknown_opcode,
     &&_unknown_opcode,
     &&TARGET_CALL_FUNCTION_EX,
     &&_unknown_opcode,



More information about the Python-checkins mailing list