8000 address review · python/cpython@96ff172 · GitHub
[go: up one dir, main page]

Skip to content
/ cpython Public

Commit 96ff172

Browse files
committed
address review
1 parent d3768ac commit 96ff172

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Python/flowgraph.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ basicblock_insert_instruction(basicblock *block, int pos, cfg_instr *instr) {
264264
}
265265

266266
/* For debugging purposes only */
267-
#if 0
267+
#if 1
268268
static void
269269
dump_instr(cfg_instr *i)
270270
{
@@ -1396,7 +1396,6 @@ nop_out(basicblock *bb, int start, int count)
13961396
INSTR_SET_OP0(&bb->b_instr[start], NOP);
13971397
count--;
13981398
}
1399-
assert(start >= -1);
14001399
}
14011400

14021401
/* Replace LOAD_CONST c1, LOAD_CONST c2 ... LOAD_CONST cn, BUILD_TUPLE n
@@ -1417,13 +1416,14 @@ fold_tuple_of_constants(basicblock *bb, int n, PyObject *consts, PyObject *const
14171416
PyObject *newconst;
14181417
RETURN_IF_ERROR(get_constant_sequence(bb, n-1, seq_size, consts, &newconst));
14191418
if (newconst == NULL) {
1419+
/* not a const sequence */
14201420
return SUCCESS;
14211421
}
1422-
assert(PyTuple_GET_SIZE(newconst) == seq_size);
1422+
assert(PyTuple_CheckExact(newconst) && PyTuple_GET_SIZE(newconst) == seq_size);
14231423
int index = add_const(newconst, consts, const_cache);
14241424
RETURN_IF_ERROR(index);
1425-
INSTR_SET_OP1(&bb->b_instr[n], LOAD_CONST, index);
14261425
nop_out(bb, n-1, seq_size);
1426+
INSTR_SET_OP1(&bb->b_instr[n], LOAD_CONST, index);
14271427
return SUCCESS;
14281428
}
14291429

@@ -1446,9 +1446,10 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
14461446
PyObject *newconst;
14471447
RETURN_IF_ERROR(get_constant_sequence(bb, n-1, seq_size, consts, &newconst));
14481448
if (newconst == NULL) {
1449+
/* not a const sequence */
14491450
return SUCCESS;
14501451
}
1451-
assert(PyTuple_GET_SIZE(newconst) == seq_size);
1452+
assert(PyTuple_CheckExact(newconst) && PyTuple_GET_SIZE(newconst) == seq_size);
14521453
int build = instr->i_opcode;
14531454
int extend = build == BUILD_LIST ? LIST_EXTEND : SET_UPDATE;
14541455
if (build == BUILD_SET) {
@@ -1461,10 +1462,11 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
14611462
}
14621463
int index = add_const(newconst, consts, const_cache);
14631464
RETURN_IF_ERROR(index);
1464-
INSTR_SET_OP1(&bb->b_instr[n], extend, 1);
1465-
INSTR_SET_OP1(&bb->b_instr[n-1], LOAD_CONST, index);
1465+
nop_out(bb, n-1, seq_size);
1466+
assert(n >= 2);
14661467
INSTR_SET_OP1(&bb->b_instr[n-2], build, 0);
1467-
nop_out(bb, n-3, seq_size-2);
1468+
INSTR_SET_OP1(&bb->b_instr[n-1], LOAD_CONST, index);
1469+
INSTR_SET_OP1(&bb->b_instr[n], extend, 1);
14681470
return SUCCESS;
14691471
}
14701472

0 commit comments

Comments
 (0)
0