Skip to content

Commit 4893684

Browse files
markshannonericsnowcurrently
authored andcommitted
Remove LOAD_CLOSURE instruction.
1 parent d2f617f commit 4893684

File tree

8 files changed

+29
-35
lines changed

8 files changed

+29
-35
lines changed

Include/opcode.h

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

Lib/opcode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ def jabs_op(name, op):
181181
def_op('MAKE_FUNCTION', 132) # Flags
182182
def_op('BUILD_SLICE', 133) # Number of items
183183

184-
def_op('LOAD_CLOSURE', 135)
185-
hasfree.append(135)
186184
def_op('LOAD_DEREF', 136)
187185
hasfree.append(136)
188186
def_op('STORE_DEREF', 137)

Lib/test/test_dis.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def foo(x):
427427
return foo
428428

429429
dis_nested_0 = """\
430-
%3d 0 LOAD_CLOSURE 2 (y)
430+
%3d 0 LOAD_FAST 2 (y)
431431
2 BUILD_TUPLE 1
432432
4 LOAD_CONST 1 (<code object foo at 0x..., file "%s", line %d>)
433433
6 LOAD_CONST 2 ('_h.<locals>.foo')
@@ -444,7 +444,7 @@ def foo(x):
444444

445445
dis_nested_1 = """%s
446446
Disassembly of <code object foo at 0x..., file "%s", line %d>:
447-
%3d 0 LOAD_CLOSURE 1 (x)
447+
%3d 0 LOAD_FAST 1 (x)
448448
2 BUILD_TUPLE 1
449449
4 LOAD_CONST 1 (<code object <listcomp> at 0x..., file "%s", line %d>)
450450
6 LOAD_CONST 2 ('_h.<locals>.foo.<locals>.<listcomp>')
@@ -962,8 +962,8 @@ def jumpy():
962962
Instruction = dis.Instruction
963963
expected_opinfo_outer = [
964964
Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval=(3, 4), argrepr='(3, 4)', offset=0, starts_line=2, is_jump_target=False),
965-
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=3, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
966-
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=4, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
965+
Instruction(opname='LOAD_FAST', opcode=124, arg=3, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
966+
Instruction(opname='LOAD_FAST', opcode=124, arg=4, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
967967
Instruction(opname='BUILD_TUPLE', opcode=102, arg=2, argval=2, argrepr='', offset=6, starts_line=None, is_jump_target=False),
968968
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_f, argrepr=repr(code_object_f), offset=8, starts_line=None, is_jump_target=False),
969969
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f', argrepr="'outer.<locals>.f'", offset=10, starts_line=None, is_jump_target=False),
@@ -985,10 +985,10 @@ def jumpy():
985985

986986
expected_opinfo_f = [
987987
Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=(5, 6), argrepr='(5, 6)', offset=0, starts_line=3, is_jump_target=False),
988-
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=5, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
989-
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=6, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
990-
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=3, argval='c', argrepr='c', offset=6, starts_line=None, is_jump_target=False),
991-
Instruction(opname='LOAD_CLOSURE', opcode=135, arg=4, argval='d', argrepr='d', offset=8, starts_line=None, is_jump_target=False),
988+
Instruction(opname='LOAD_FAST', opcode=124, arg=5, argval='a', argrepr='a', offset=2, starts_line=None, is_jump_target=False),
989+
Instruction(opname='LOAD_FAST', opcode=124, arg=6, argval='b', argrepr='b', offset=4, starts_line=None, is_jump_target=False),
990+
Instruction(opname='LOAD_FAST', opcode=124, arg=3, argval='c', argrepr='c', offset=6, starts_line=None, is_jump_target=False),
991+
Instruction(opname='LOAD_FAST', opcode=124, arg=4, argval='d', argrepr='d', offset=8, starts_line=None, is_jump_target=False),
992992
Instruction(opname='BUILD_TUPLE', opcode=102, arg=4, argval=4, argrepr='', offset=10, starts_line=None, is_jump_target=False),
993993
Instruction(opname='LOAD_CONST', opcode=100, arg=3, argval=code_object_inner, argrepr=repr(code_object_inner), offset=12, starts_line=None, is_jump_target=False),
994994
Instruction(opname='LOAD_CONST', opcode=100, arg=4, argval='outer.<locals>.f.<locals>.inner', argrepr="'outer.<locals>.f.<locals>.inner'", offset=14, starts_line=None, is_jump_target=False),

Python/ceval.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3070,13 +3070,6 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, PyFrameObject *f, int throwflag)
30703070
goto error;
30713071
}
30723072

3073-
case TARGET(LOAD_CLOSURE): {
3074-
PyObject *cell = GETLOCAL(oparg);
3075-
Py_INCREF(cell);
3076-
PUSH(cell);
3077-
DISPATCH();
3078-
}
3079-
30803073
case TARGET(LOAD_CLASSDEREF): {
30813074
PyObject *name, *value, *locals = LOCALS();
30823075
assert(locals);

Python/compile.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
#define SETUP_WITH 253
7777
#define POP_BLOCK 252
7878

79+
/* Artificial instruction, will be converted to LOAD_FAST */
80+
#define LOAD_CLOSURE 251
81+
7982
#define IS_TOP_LEVEL_AWAIT(c) ( \
8083
(c->c_flags->cf_flags & PyCF_ALLOW_TOP_LEVEL_AWAIT) \
8184
&& (c->u->u_ste->ste_type == ModuleBlock))
@@ -1185,8 +1188,6 @@ stack_effect(int opcode, int oparg, int jump)
11851188
return -1;
11861189

11871190
/* Closures */
1188-
case LOAD_CLOSURE:
1189-
return 1;
11901191
case LOAD_DEREF:
11911192
case LOAD_CLASSDEREF:
11921193
return 1;
@@ -7436,17 +7437,19 @@ guarantee_lineno_for_exits(struct assembler *a, int firstlineno) {
74367437
}
74377438

74387439
static void
7439-
offset_derefs(struct assembler *a, int nlocals)
7440+
offset_derefs(basicblock *entryblock, int nlocals)
74407441
{
7441-
for (basicblock *b = a->a_entry; b != NULL; b = b->b_next) {
7442+
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
74427443
for (int i = 0; i < b->b_iused; i++) {
74437444
struct instr *inst = &b->b_instr[i];
74447445
switch(inst->i_opcode) {
7446+
case LOAD_CLOSURE:
7447+
inst->i_opcode = LOAD_FAST;
7448+
/* fall through */
74457449
case LOAD_DEREF:
74467450
case STORE_DEREF:
74477451
case DELETE_DEREF:
74487452
case LOAD_CLASSDEREF:
7449-
case LOAD_CLOSURE:
74507453
inst->i_oparg += nlocals;
74517454
}
74527455
}
@@ -7508,6 +7511,9 @@ assemble(struct compiler *c, int addNone)
75087511
a.a_entry = entryblock;
75097512
a.a_nblocks = nblocks;
75107513

7514+
assert(PyDict_GET_SIZE(c->u->u_varnames) < INT_MAX);
7515+
offset_derefs(entryblock, (int)PyDict_GET_SIZE(c->u->u_varnames));
7516+
75117517
consts = consts_dict_keys_inorder(c->u->u_consts);
75127518
if (consts == NULL) {
75137519
goto error;
@@ -7517,8 +7523,6 @@ assemble(struct compiler *c, int addNone)
75177523
}
75187524
guarantee_lineno_for_exits(&a, c->u->u_firstlineno);
75197525

7520-
offset_derefs(&a, (int)PyDict_GET_SIZE(c->u->u_varnames));
7521-
75227526
int maxdepth = stackdepth(c);
75237527
if (maxdepth < 0) {
75247528
goto error;

Python/importlib.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/importlib_external.h

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

Python/opcode_targets.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)