Skip to content

Commit 375e143

Browse files
committed
address review
1 parent a990491 commit 375e143

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
@@ -263,7 +263,7 @@ basicblock_insert_instruction(basicblock *block, int pos, cfg_instr *instr) {
263263
}
264264

265265
/* For debugging purposes only */
266-
#if 0
266+
#if 1
267267
static void
268268
dump_instr(cfg_instr *i)
269269
{
@@ -1395,7 +1395,6 @@ nop_out(basicblock *bb, int start, int count)
13951395
INSTR_SET_OP0(&bb->b_instr[start], NOP);
13961396
count--;
13971397
}
1398-
assert(start >= -1);
13991398
}
14001399

14011400
/* Replace LOAD_CONST c1, LOAD_CONST c2 ... LOAD_CONST cn, BUILD_TUPLE n
@@ -1416,13 +1415,14 @@ fold_tuple_of_constants(basicblock *bb, int n, PyObject *consts, PyObject *const
14161415
PyObject *newconst;
14171416
RETURN_IF_ERROR(get_constant_sequence(bb, n-1, seq_size, consts, &newconst));
14181417
if (newconst == NULL) {
1418+
/* not a const sequence */
14191419
return SUCCESS;
14201420
}
1421-
assert(PyTuple_GET_SIZE(newconst) == seq_size);
1421+
assert(PyTuple_CheckExact(newconst) && PyTuple_GET_SIZE(newconst) == seq_size);
14221422
int index = add_const(newconst, consts, const_cache);
14231423
RETURN_IF_ERROR(index);
1424-
INSTR_SET_OP1(&bb->b_instr[n], LOAD_CONST, index);
14251424
nop_out(bb, n-1, seq_size);
1425+
INSTR_SET_OP1(&bb->b_instr[n], LOAD_CONST, index);
14261426
return SUCCESS;
14271427
}
14281428

@@ -1445,9 +1445,10 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
14451445
PyObject *newconst;
14461446
RETURN_IF_ERROR(get_constant_sequence(bb, n-1, seq_size, consts, &newconst));
14471447
if (newconst == NULL) {
1448+
/* not a const sequence */
14481449
return SUCCESS;
14491450
}
1450-
assert(PyTuple_GET_SIZE(newconst) == seq_size);
1451+
assert(PyTuple_CheckExact(newconst) && PyTuple_GET_SIZE(newconst) == seq_size);
14511452
int build = instr->i_opcode;
14521453
int extend = build == BUILD_LIST ? LIST_EXTEND : SET_UPDATE;
14531454
if (build == BUILD_SET) {
@@ -1460,10 +1461,11 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
14601461
}
14611462
int index = add_const(newconst, consts, const_cache);
14621463
RETURN_IF_ERROR(index);
1463-
INSTR_SET_OP1(&bb->b_instr[n], extend, 1);
1464-
INSTR_SET_OP1(&bb->b_instr[n-1], LOAD_CONST, index);
1464+
nop_out(bb, n-1, seq_size);
1465+
assert(n >= 2);
14651466
INSTR_SET_OP1(&bb->b_instr[n-2], build, 0);
1466-
nop_out(bb, n-3, seq_size-2);
1467+
INSTR_SET_OP1(&bb->b_instr[n-1], LOAD_CONST, index);
1468+
INSTR_SET_OP1(&bb->b_instr[n], extend, 1);
14671469
return SUCCESS;
14681470
}
14691471

0 commit comments

Comments
 (0)