Skip to content

Commit 31e43cb

Browse files
authored
bpo-46009: Remove GEN_START (GH-30367)
1 parent f404e26 commit 31e43cb

File tree

10 files changed

+20
-47
lines changed

10 files changed

+20
-47
lines changed

‎Doc/library/dis.rst‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,14 +1175,6 @@ All of the following opcodes use their arguments.
11751175
Previously, this instruction also pushed a boolean value indicating
11761176
success (``True``) or failure (``False``).
11771177

1178-
.. opcode:: GEN_START (kind)
1179-
1180-
Pops TOS. The ``kind`` operand corresponds to the type of generator or
1181-
coroutine. The legal kinds are 0 for generator, 1 for coroutine,
1182-
and 2 for async generator.
1183-
1184-
.. versionadded:: 3.10
1185-
11861178

11871179
.. opcode:: ROT_N (count)
11881180

‎Doc/whatsnew/3.11.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ CPython bytecode changes
388388
This decouples the argument shifting for methods from the handling of
389389
keyword arguments and allows better specialization of calls.
390390

391-
* Removed ``COPY_DICT_WITHOUT_KEYS``.
391+
* Removed ``COPY_DICT_WITHOUT_KEYS`` and ``GEN_START``.
392392

393393
* :opcode:`MATCH_CLASS` and :opcode:`MATCH_KEYS` no longer push an additional
394394
boolean value indicating whether the match succeeded or failed. Instead, they

‎Include/opcode.h‎

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Lib/importlib/_bootstrap_external.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@ def _write_atomic(path, data, mode=0o666):
377377
# Python 3.11a4 3469 (bpo-45711: remove type, traceback from exc_info)
378378
# Python 3.11a4 3470 (bpo-46221: PREP_RERAISE_STAR no longer pushes lasti)
379379
# Python 3.11a4 3471 (bpo-46202: remove pop POP_EXCEPT_AND_RERAISE)
380+
# Python 3.11a4 3472 (bpo-46009: replace GEN_START with POP_TOP)
380381

381382
#
382383
# MAGIC must change whenever the bytecode emitted by the compiler may no
@@ -386,7 +387,7 @@ def _write_atomic(path, data, mode=0o666):
386387
# Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array
387388
# in PC/launcher.c must also be updated.
388389

389-
MAGIC_NUMBER = (3471).to_bytes(2, 'little') + b'\r\n'
390+
MAGIC_NUMBER = (3472).to_bytes(2, 'little') + b'\r\n'
390391
_RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c
391392

392393
_PYCACHE = '__pycache__'

‎Lib/opcode.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ def jabs_op(name, op):
151151

152152
jabs_op('JUMP_IF_NOT_EG_MATCH', 127)
153153

154-
def_op('GEN_START', 129) # Kind of generator/coroutine
155154
def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
156155

157156
def_op('MAKE_FUNCTION', 132) # Flags
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove the ``GEN_START`` opcode.

‎Objects/frameobject.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@ mark_stacks(PyCodeObject *code_obj, int len)
192192
stacks[i] = UNINITIALIZED;
193193
}
194194
stacks[0] = 0;
195+
if (code_obj->co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR))
196+
{
197+
// Generators get sent None while starting:
198+
stacks[0] = push_value(stacks[0], Object);
199+
}
195200
int todo = 1;
196201
while (todo) {
197202
todo = 0;
@@ -291,9 +296,6 @@ mark_stacks(PyCodeObject *code_obj, int len)
291296
case RERAISE:
292297
/* End of block */
293298
break;
294-
case GEN_START:
295-
stacks[i+1] = next_stack;
296-
break;
297299
default:
298300
{
299301
int delta = PyCompile_OpcodeStackEffect(opcode, _Py_OPARG(code[i]));

‎Python/ceval.c‎

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,14 +2709,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
27092709
return retval;
27102710
}
27112711

2712-
TARGET(GEN_START) {
2713-
PyObject *none = POP();
2714-
assert(none == Py_None);
2715-
assert(oparg < 3);
2716-
Py_DECREF(none);
2717-
DISPATCH();
2718-
}
2719-
27202712
TARGET(POP_EXCEPT) {
27212713
_PyErr_StackItem *exc_info = tstate->exc_info;
27222714
PyObject *value = exc_info->exc_value;

‎Python/compile.c‎

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,8 +1208,6 @@ stack_effect(int opcode, int oparg, int jump)
12081208
return 1;
12091209
case LIST_TO_TUPLE:
12101210
return 0;
1211-
case GEN_START:
1212-
return -1;
12131211
case LIST_EXTEND:
12141212
case SET_UPDATE:
12151213
case DICT_MERGE:
@@ -8028,27 +8026,16 @@ insert_prefix_instructions(struct compiler *c, basicblock *entryblock,
80288026

80298027
/* Add the generator prefix instructions. */
80308028
if (flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR)) {
8031-
int kind;
8032-
if (flags & CO_COROUTINE) {
8033-
kind = 1;
8034-
}
8035-
else if (flags & CO_ASYNC_GENERATOR) {
8036-
kind = 2;
8037-
}
8038-
else {
8039-
kind = 0;
8040-
}
8041-
8042-
struct instr gen_start = {
8043-
.i_opcode = GEN_START,
8044-
.i_oparg = kind,
8029+
struct instr pop_top = {
8030+
.i_opcode = POP_TOP,
8031+
.i_oparg = 0,
80458032
.i_lineno = -1,
80468033
.i_col_offset = -1,
80478034
.i_end_lineno = -1,
80488035
.i_end_col_offset = -1,
80498036
.i_target = NULL,
80508037
};
8051-
if (insert_instruction(entryblock, 0, &gen_start) < 0) {
8038+
if (insert_instruction(entryblock, 0, &pop_top) < 0) {
80528039
return -1;
80538040
}
80548041
}

‎Python/opcode_targets.h‎

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)