@@ -25,9 +25,9 @@ def writeinst(opc:str, arg:int=0):
2525 return bytes (inst )
2626
2727
28- ###################
29- # Type prop tests #
30- ###################
28+ ################################################
29+ # Type prop tests: TYPE_SET and TYPE_OVERWRITE #
30+ ################################################
3131
3232def test_typeprop1 (a ):
3333 # Dummy code won't be ran
@@ -83,6 +83,10 @@ def test_typeprop1(a):
8383for x ,y in zip (insts , expected ):
8484 assert x .opname == y
8585
86+ ################################################
87+ # Type prop tests: TYPE_SWAP #
88+ ################################################
89+
8690bytecode = b"" .join ([
8791 # Tests TYPE_SWAP
8892 writeinst ("RESUME" , 0 ),
@@ -151,9 +155,10 @@ def test_typeprop2(a,b):
151155
152156
153157#######################################
154- # Type guard #
158+ # Tests for: Type guard #
155159# + Float unboxing #
156160# + Jump rewriting test #
161+ # + Tier2 guard stability #
157162#######################################
158163
159164def test_guard_elimination (a ,b ):
@@ -264,10 +269,9 @@ def test_guard_elimination(a,b):
264269 assert x .opname == y .opname
265270
266271
267- ######################
268- # Backward jump test #
269- # + loop peeling #
270- ######################
272+ ##############################
273+ # Test: Backward jump offset #
274+ ##############################
271275
272276def test_backwards_jump (a ):
273277 for i in range (64 ):
@@ -289,6 +293,10 @@ def test_backwards_jump(a):
289293assert insts [instidx + 1 ].opname == "BB_TEST_ITER_RANGE" # The loop predicate
290294
291295
296+ ######################
297+ # Test: Loop peeling #
298+ ######################
299+
292300def test_loop_peeling (a ):
293301 for i in range (64 ):
294302 a = float (i ) + a
@@ -320,3 +328,48 @@ def test_loop_peeling(a):
320328assert any (1 for _ in
321329 filter (lambda i : i .opname == 'BINARY_OP_ADD_FLOAT_UNBOXED' , insts [instidx :endidx ]))
322330
331+
332+ ##################################
333+ # Test: Container specialisation #
334+ ##################################
335+
336+ def test_container (l ):
337+ l [2 ] = l [0 ] + l [1 ]
338+
339+
340+ trigger_tier2 (test_container , ([1 ,2 ,3 ,4 ],))
341+ insts = dis .get_instructions (test_container , tier2 = True )
342+ expected = [
343+ "RESUME_QUICK" ,
344+ "LOAD_FAST" ,
345+ "LOAD_CONST" ,
346+
347+ "CHECK_LIST" ,
348+ "NOP" ,
349+ "BB_BRANCH_IF_FLAG_UNSET" , # Fallthrough!
350+
351+ # Type prop from const array: No type guard needed
352+ "BINARY_SUBSCR_LIST_INT_REST" ,
353+ "LOAD_FAST" ,
354+ "LOAD_CONST" ,
355+ # CHECK_LIST should eliminate the type guard here
356+ "BINARY_SUBSCR_LIST_INT_REST" ,
357+
358+ # We haven't implemented type prop into container types
359+ # so these checks should get generated
360+ "BINARY_CHECK_FLOAT" ,
361+ "NOP" ,
362+ "BB_BRANCH_IF_FLAG_SET" ,
363+ "BINARY_CHECK_INT" ,
364+ "NOP" ,
365+ "BB_BRANCH_IF_FLAG_UNSET" ,
366+ "BINARY_OP_ADD_INT_REST" ,
367+
368+ "LOAD_FAST" ,
369+ "LOAD_CONST" ,
370+ # CHECK_LIST should eliminate the type guard here
371+ "STORE_SUBSCR_LIST_INT_REST" ,
372+ "RETURN_CONST" ,
373+ ]
374+ for x ,y in zip (insts , expected ):
375+ assert x .opname == y
0 commit comments