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