@@ -25,9 +25,9 @@ def writeinst(opc:str, arg:int=0):
25
25
return bytes (inst )
26
26
27
27
28
- ###################
29
- # Type prop tests #
30
- ###################
28
+ ################################################
29
+ # Type prop tests: TYPE_SET and TYPE_OVERWRITE #
30
+ ################################################
31
31
32
32
def test_typeprop1 (a ):
33
33
# Dummy code won't be ran
@@ -83,6 +83,10 @@ def test_typeprop1(a):
83
83
for x ,y in zip (insts , expected ):
84
84
assert x .opname == y
85
85
86
+ ################################################
87
+ # Type prop tests: TYPE_SWAP #
88
+ ################################################
89
+
86
90
bytecode = b"" .join ([
87
91
# Tests TYPE_SWAP
88
92
writeinst ("RESUME" , 0 ),
@@ -151,9 +155,10 @@ def test_typeprop2(a,b):
151
155
152
156
153
157
#######################################
154
- # Type guard #
158
+ # Tests for: Type guard #
155
159
# + Float unboxing #
156
160
# + Jump rewriting test #
161
+ # + Tier2 guard stability #
157
162
#######################################
158
163
159
164
def test_guard_elimination (a ,b ):
@@ -264,10 +269,9 @@ def test_guard_elimination(a,b):
264
269
assert x .opname == y .opname
265
270
266
271
267
- ######################
268
- # Backward jump test #
269
- # + loop peeling #
270
- ######################
272
+ ##############################
273
+ # Test: Backward jump offset #
274
+ ##############################
271
275
272
276
def test_backwards_jump (a ):
273
277
for i in range (64 ):
@@ -289,6 +293,10 @@ def test_backwards_jump(a):
289
293
assert insts [instidx + 1 ].opname == "BB_TEST_ITER_RANGE" # The loop predicate
290
294
291
295
296
+ ######################
297
+ # Test: Loop peeling #
298
+ ######################
299
+
292
300
def test_loop_peeling (a ):
293
301
for i in range (64 ):
294
302
a = float (i ) + a
@@ -320,3 +328,48 @@ def test_loop_peeling(a):
320
328
assert any (1 for _ in
321
329
filter (lambda i : i .opname == 'BINARY_OP_ADD_FLOAT_UNBOXED' , insts [instidx :endidx ]))
322
330
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