@@ -263,7 +263,7 @@ basicblock_insert_instruction(basicblock *block, int pos, cfg_instr *instr) {
263
263
}
264
264
265
265
/* For debugging purposes only */
266
- #if 0
266
+ #if 1
267
267
static void
268
268
dump_instr (cfg_instr * i )
269
269
{
@@ -1395,7 +1395,6 @@ nop_out(basicblock *bb, int start, int count)
1395
1395
INSTR_SET_OP0 (& bb -> b_instr [start ], NOP );
1396
1396
count -- ;
1397
1397
}
1398
- assert (start >= -1 );
1399
1398
}
1400
1399
1401
1400
/* 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
1416
1415
PyObject * newconst ;
1417
1416
RETURN_IF_ERROR (get_constant_sequence (bb , n - 1 , seq_size , consts , & newconst ));
1418
1417
if (newconst == NULL ) {
1418
+ /* not a const sequence */
1419
1419
return SUCCESS ;
1420
1420
}
1421
- assert (PyTuple_GET_SIZE (newconst ) == seq_size );
1421
+ assert (PyTuple_CheckExact ( newconst ) && PyTuple_GET_SIZE (newconst ) == seq_size );
1422
1422
int index = add_const (newconst , consts , const_cache );
1423
1423
RETURN_IF_ERROR (index );
1424
- INSTR_SET_OP1 (& bb -> b_instr [n ], LOAD_CONST , index );
1425
1424
nop_out (bb , n - 1 , seq_size );
1425
+ INSTR_SET_OP1 (& bb -> b_instr [n ], LOAD_CONST , index );
1426
1426
return SUCCESS ;
1427
1427
}
1428
1428
@@ -1445,9 +1445,10 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
1445
1445
PyObject * newconst ;
1446
1446
RETURN_IF_ERROR (get_constant_sequence (bb , n - 1 , seq_size , consts , & newconst ));
1447
1447
if (newconst == NULL ) {
1448
+ /* not a const sequence */
1448
1449
return SUCCESS ;
1449
1450
}
1450
- assert (PyTuple_GET_SIZE (newconst ) == seq_size );
1451
+ assert (PyTuple_CheckExact ( newconst ) && PyTuple_GET_SIZE (newconst ) == seq_size );
1451
1452
int build = instr -> i_opcode ;
1452
1453
int extend = build == BUILD_LIST ? LIST_EXTEND : SET_UPDATE ;
1453
1454
if (build == BUILD_SET ) {
@@ -1460,10 +1461,11 @@ optimize_if_const_list_or_set(basicblock *bb, int n, PyObject *consts, PyObject
1460
1461
}
1461
1462
int index = add_const (newconst , consts , const_cache );
1462
1463
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 );
1465
1466
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 );
1467
1469
return SUCCESS ;
1468
1470
}
1469
1471
0 commit comments