@@ -2435,9 +2435,9 @@ def test_list_to_tuple_get_iter(self):
24352435 ]
24362436 expected_insts = [
24372437 ("BUILD_LIST" , 0 , 1 ),
2438- ("LOAD_FAST " , 0 , 2 ),
2438+ ("LOAD_FAST_BORROW " , 0 , 2 ),
24392439 ("LIST_EXTEND" , 1 , 3 ),
2440- ("LOAD_FAST " , 1 , 4 ),
2440+ ("LOAD_FAST_BORROW " , 1 , 4 ),
24412441 ("LIST_EXTEND" , 1 , 5 ),
24422442 ("NOP" , None , 6 ), # ("CALL_INTRINSIC_1", INTRINSIC_LIST_TO_TUPLE, 6),
24432443 ("GET_ITER" , None , 7 ),
@@ -2463,15 +2463,24 @@ def test_list_to_tuple_get_iter_is_safe(self):
24632463 self .assertEqual (items , [])
24642464
24652465
2466- @unittest .skipIf (_testinternalcapi is None , "requires _testinternalcapi" )
2467- class OptimizeLoadFastTestCase (CompilationStepTestCase ):
2468- def check (self , insts , expected_insts ):
2469- self .check_instructions (insts )
2470- self .check_instructions (expected_insts )
2471- seq = self .seq_from_insts (insts )
2472- opt_insts = _testinternalcapi .optimize_load_fast (seq )
2473- expected_insts = self .seq_from_insts (expected_insts ).get_instructions ()
2474- self .assertInstructionsMatch (opt_insts , expected_insts )
2466+ class OptimizeLoadFastTestCase (DirectCfgOptimizerTests ):
2467+ def make_bb (self , insts ):
2468+ last_loc = insts [- 1 ][2 ]
2469+ maxconst = 0
2470+ for op , arg , _ in insts :
2471+ if op == "LOAD_CONST" :
2472+ maxconst = max (maxconst , arg )
2473+ consts = [None for _ in range (maxconst + 1 )]
2474+ return insts + [
2475+ ("LOAD_CONST" , 0 , last_loc + 1 ),
2476+ ("RETURN_VALUE" , None , last_loc + 2 ),
2477+ ], consts
2478+
2479+ def check (self , insts , expected_insts , consts = None ):
2480+ insts_bb , insts_consts = self .make_bb (insts )
2481+ expected_insts_bb , exp_consts = self .make_bb (expected_insts )
2482+ self .cfg_optimization_test (insts_bb , expected_insts_bb ,
2483+ consts = insts_consts , expected_consts = exp_consts )
24752484
24762485 def test_optimized (self ):
24772486 insts = [
@@ -2518,7 +2527,12 @@ def test_unoptimized_if_unconsumed(self):
25182527 ("COPY" , 1 , 2 ),
25192528 ("POP_TOP" , None , 3 ),
25202529 ]
2521- self .check (insts , insts )
2530+ expected = [
2531+ ("LOAD_FAST" , 0 , 1 ),
2532+ ("NOP" , None , 2 ),
2533+ ("NOP" , None , 3 ),
2534+ ]
2535+ self .check (insts , expected )
25222536
25232537 def test_unoptimized_if_support_killed (self ):
25242538 insts = [
0 commit comments