@@ -2509,8 +2509,43 @@ def test_fold_constant_big_set_for_iter(self):
25092509 ("LOAD_CONST" , 0 , 14 ),
25102510 ("RETURN_VALUE" , None , 15 ),
25112511 ]
2512- self .cfg_optimization_test (before , after , consts = [None ],
2513- expected_consts = [None , frozenset ({1 , 2 , 3 })])
2512+ self .cfg_optimization_test (before , after , consts = ["test" ],
2513+ expected_consts = ["test" , frozenset ({1 , 2 , 3 })])
2514+
2515+ def test_fold_constant_list_to_tuple_for_iter (self ):
2516+ INTRINSIC_LIST_TO_TUPLE = 6
2517+ before = [
2518+ ("BUILD_LIST" , 0 , 1 ),
2519+ ("LOAD_SMALL_INT" , 1 , 2 ), ("LIST_APPEND" , 1 , 3 ),
2520+ ("LOAD_SMALL_INT" , 2 , 4 ), ("LIST_APPEND" , 1 , 5 ),
2521+ ("LOAD_SMALL_INT" , 3 , 6 ), ("LIST_APPEND" , 1 , 7 ),
2522+ ("CALL_INTRINSIC_1" , INTRINSIC_LIST_TO_TUPLE , 8 ),
2523+ ("GET_ITER" , 0 , 9 ),
2524+ top := self .Label (),
2525+ ("FOR_ITER" , end := self .Label (), 10 ),
2526+ ("STORE_FAST" , 0 , 11 ),
2527+ ("JUMP" , top , 12 ),
2528+ end ,
2529+ ("END_FOR" , None , 13 ),
2530+ ("POP_ITER" , None , 14 ),
2531+ ("LOAD_CONST" , 0 , 15 ),
2532+ ("RETURN_VALUE" , None , 16 ),
2533+ ]
2534+ after = [
2535+ ("LOAD_CONST" , 1 , 8 ),
2536+ ("GET_ITER" , 0 , 9 ),
2537+ top := self .Label (),
2538+ ("FOR_ITER" , end := self .Label (), 10 ),
2539+ ("STORE_FAST" , 0 , 11 ),
2540+ ("JUMP" , top , 12 ),
2541+ end ,
2542+ ("END_FOR" , None , 13 ),
2543+ ("POP_ITER" , None , 14 ),
2544+ ("LOAD_CONST" , 0 , 15 ),
2545+ ("RETURN_VALUE" , None , 16 ),
2546+ ]
2547+ self .cfg_optimization_test (before , after , consts = ["test" ],
2548+ expected_consts = ["test" , (1 , 2 , 3 )])
25142549
25152550 def test_fold_constant_big_list_contains_op (self ):
25162551 # x in [c1, c2, ..., cN] (N > 30) should fold to LOAD_CONST tuple
@@ -2569,7 +2604,7 @@ def test_no_fold_big_list_for_iter_with_non_const(self):
25692604 ("LOAD_CONST" , 0 , 14 ),
25702605 ("RETURN_VALUE" , None , 15 ),
25712606 ]
2572- self .cfg_optimization_test (same , same , consts = [None ])
2607+ self .cfg_optimization_test (same , same , consts = ["test" ])
25732608
25742609
25752610class OptimizeLoadFastTestCase (DirectCfgOptimizerTests ):
0 commit comments