bpo-46009: Remove GEN_START (GH-30367)

This commit is contained in:
Brandt Bucher 2022-01-04 11:38:32 -08:00 committed by GitHub
parent f404e26d74
commit 31e43cbe5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 20 additions and 47 deletions

View File

@ -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)

View File

@ -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

7
Include/opcode.h generated
View File

@ -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] = {

View File

@ -377,6 +377,7 @@ _code_type = type(_write_atomic.__code__)
# 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 @@ _code_type = type(_write_atomic.__code__)
# 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__'

View File

@ -151,7 +151,6 @@ haslocal.append(126)
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

View File

@ -0,0 +1 @@
Remove the ``GEN_START`` opcode.

View File

@ -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]));

View File

@ -2709,14 +2709,6 @@ check_eval_breaker:
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;

View File

@ -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;
}
}

View File

@ -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,