Skip to content

Commit

Permalink
Test: Added test for container specialisation (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
JuliaPoo authored Apr 14, 2023
1 parent fd338df commit d1f3a74
Showing 1 changed file with 61 additions and 8 deletions.
69 changes: 61 additions & 8 deletions tier2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def writeinst(opc:str, arg:int=0):
return bytes(inst)


###################
# Type prop tests #
###################
################################################
# Type prop tests: TYPE_SET and TYPE_OVERWRITE #
################################################

def test_typeprop1(a):
# Dummy code won't be ran
Expand Down Expand Up @@ -83,6 +83,10 @@ def test_typeprop1(a):
for x,y in zip(insts, expected):
assert x.opname == y

################################################
# Type prop tests: TYPE_SWAP #
################################################

bytecode = b"".join([
# Tests TYPE_SWAP
writeinst("RESUME", 0),
Expand Down Expand Up @@ -151,9 +155,10 @@ def test_typeprop2(a,b):


#######################################
# Type guard #
# Tests for: Type guard #
# + Float unboxing #
# + Jump rewriting test #
# + Tier2 guard stability #
#######################################

def test_guard_elimination(a,b):
Expand Down Expand Up @@ -264,10 +269,9 @@ def test_guard_elimination(a,b):
assert x.opname == y.opname


######################
# Backward jump test #
# + loop peeling #
######################
##############################
# Test: Backward jump offset #
##############################

def test_backwards_jump(a):
for i in range(64):
Expand All @@ -289,6 +293,10 @@ def test_backwards_jump(a):
assert insts[instidx + 1].opname == "BB_TEST_ITER_RANGE" # The loop predicate


######################
# Test: Loop peeling #
######################

def test_loop_peeling(a):
for i in range(64):
a = float(i) + a
Expand Down Expand Up @@ -320,3 +328,48 @@ def test_loop_peeling(a):
assert any(1 for _ in
filter(lambda i: i.opname == 'BINARY_OP_ADD_FLOAT_UNBOXED', insts[instidx:endidx]))


##################################
# Test: Container specialisation #
##################################

def test_container(l):
l[2] = l[0] + l[1]


trigger_tier2(test_container, ([1,2,3,4],))
insts = dis.get_instructions(test_container, tier2=True)
expected = [
"RESUME_QUICK",
"LOAD_FAST",
"LOAD_CONST",

"CHECK_LIST",
"NOP",
"BB_BRANCH_IF_FLAG_UNSET", # Fallthrough!

# Type prop from const array: No type guard needed
"BINARY_SUBSCR_LIST_INT_REST",
"LOAD_FAST",
"LOAD_CONST",
# CHECK_LIST should eliminate the type guard here
"BINARY_SUBSCR_LIST_INT_REST",

# We haven't implemented type prop into container types
# so these checks should get generated
"BINARY_CHECK_FLOAT",
"NOP",
"BB_BRANCH_IF_FLAG_SET",
"BINARY_CHECK_INT",
"NOP",
"BB_BRANCH_IF_FLAG_UNSET",
"BINARY_OP_ADD_INT_REST",

"LOAD_FAST",
"LOAD_CONST",
# CHECK_LIST should eliminate the type guard here
"STORE_SUBSCR_LIST_INT_REST",
"RETURN_CONST",
]
for x,y in zip(insts, expected):
assert x.opname == y

0 comments on commit d1f3a74

Please sign in to comment.