Skip to content

Commit 47927cf

Browse files
committed
Don't mark LOAD_SMALL_INT as having a constant, as it doesn't load from code.co_consts
1 parent 3a50437 commit 47927cf

File tree

9 files changed

+63
-71
lines changed

9 files changed

+63
-71
lines changed

Include/internal/pycore_opcode_metadata.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.

Include/internal/pycore_uop_metadata.h

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

Lib/dis.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def _get_const_value(op, arg, co_consts):
673673
Otherwise (if it is a LOAD_CONST and co_consts is not
674674
provided) returns the dis.UNKNOWN sentinel.
675675
"""
676-
assert op in hasconst
676+
assert op in hasconst or op == LOAD_SMALL_INT
677677

678678
if op == LOAD_SMALL_INT:
679679
return arg
@@ -993,7 +993,8 @@ def _find_imports(co):
993993
if op == IMPORT_NAME and i >= 2:
994994
from_op = opargs[i-1]
995995
level_op = opargs[i-2]
996-
if (from_op[0] in hasconst and level_op[0] in hasconst):
996+
if (from_op[0] in hasconst and
997+
(level_op[0] in hasconst or level_op[0] == LOAD_SMALL_INT)):
997998
level = _get_const_value(level_op[0], level_op[1], consts)
998999
fromlist = _get_const_value(from_op[0], from_op[1], consts)
9991000
yield (names[oparg], level, fromlist)

Lib/test/test_ast/test_ast.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2311,7 +2311,6 @@ def get_load_const(self, tree):
23112311
def test_load_const(self):
23122312
consts = [None,
23132313
True, False,
2314-
124,
23152314
2.0,
23162315
3j,
23172316
"unicode",

Lib/test/test_dis.py

Lines changed: 44 additions & 44 deletions
Large diffs are not rendered by default.

Python/bytecodes.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,6 @@ dummy_func(
270270
}
271271

272272
replicate(4) inst(LOAD_SMALL_INT, (-- value)) {
273-
/* Tell code generator that this is a const load */
274-
(void)FRAME_CO_CONSTS;
275273
assert(oparg < _PY_NSMALLPOSINTS);
276274
PyObject *obj = (PyObject *)&_PyLong_SMALL_INTS[_PY_NSMALLNEGINTS + oparg];
277275
value = PyStackRef_FromPyObjectImmortal(obj);

Python/executor_cases.c.h

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

Python/flowgraph.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,11 +1264,17 @@ jump_thread(basicblock *bb, cfg_instr *inst, cfg_instr *target, int opcode)
12641264
return false;
12651265
}
12661266

1267+
static int
1268+
loads_const(int opcode)
1269+
{
1270+
return OPCODE_HAS_CONST(opcode) || opcode == LOAD_SMALL_INT;
1271+
}
1272+
12671273
static PyObject*
12681274
get_const_value(int opcode, int oparg, PyObject *co_consts)
12691275
{
12701276
PyObject *constant = NULL;
1271-
assert(OPCODE_HAS_CONST(opcode));
1277+
assert(loads_const(opcode));
12721278
if (opcode == LOAD_CONST) {
12731279
constant = PyList_GET_ITEM(co_consts, oparg);
12741280
}
@@ -1332,7 +1338,7 @@ fold_tuple_on_constants(PyObject *const_cache,
13321338
assert(inst[n].i_oparg == n);
13331339

13341340
for (int i = 0; i < n; i++) {
1335-
if (!OPCODE_HAS_CONST(inst[i].i_opcode)) {
1341+
if (!loads_const(inst[i].i_opcode)) {
13361342
return SUCCESS;
13371343
}
13381344
}
@@ -2102,7 +2108,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
21022108
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
21032109
for (int i = 0; i < b->b_iused; i++) {
21042110
int opcode = b->b_instr[i].i_opcode;
2105-
if (OPCODE_HAS_CONST(opcode) && opcode != LOAD_SMALL_INT) {
2111+
if (OPCODE_HAS_CONST(opcode)) {
21062112
int index = b->b_instr[i].i_oparg;
21072113
index_map[index] = index;
21082114
}
@@ -2156,7 +2162,7 @@ remove_unused_consts(basicblock *entryblock, PyObject *consts)
21562162
for (basicblock *b = entryblock; b != NULL; b = b->b_next) {
21572163
for (int i = 0; i < b->b_iused; i++) {
21582164
int opcode = b->b_instr[i].i_opcode;
2159-
if (OPCODE_HAS_CONST(opcode) && opcode != LOAD_SMALL_INT) {
2165+
if (OPCODE_HAS_CONST(opcode)) {
21602166
int index = b->b_instr[i].i_oparg;
21612167
assert(reverse_index_map[index] >= 0);
21622168
assert(reverse_index_map[index] < n_used_consts);

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)