Skip to content

Commit 2897ff4

Browse files
add test for dead code eliminator
1 parent 8a6fc16 commit 2897ff4

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from vyper.compiler.phases import CompilerData
2+
3+
4+
def test_dead_code_eliminator():
5+
code = """
6+
s: uint256
7+
8+
@internal
9+
def foo():
10+
self.s = 1
11+
12+
@internal
13+
def qux():
14+
self.s = 2
15+
16+
@external
17+
def bar():
18+
self.foo()
19+
20+
@external
21+
def __init__():
22+
self.qux()
23+
"""
24+
25+
c = CompilerData(code, no_optimize=True)
26+
initcode_asm = [i for i in c.assembly if not isinstance(i, list)]
27+
runtime_asm = c.assembly_runtime
28+
29+
foo_label = "_sym_internal_foo___"
30+
qux_label = "_sym_internal_qux___"
31+
32+
# all the labels should be in all the unoptimized asms
33+
for s in (foo_label, qux_label):
34+
assert s in initcode_asm
35+
assert s in runtime_asm
36+
37+
c = CompilerData(code, no_optimize=False)
38+
initcode_asm = [i for i in c.assembly if not isinstance(i, list)]
39+
runtime_asm = c.assembly_runtime
40+
41+
# qux should not be in runtime code
42+
for instr in runtime_asm:
43+
if isinstance(instr, str):
44+
assert not instr.startswith(qux_label), instr
45+
46+
# foo should not be in initcode asm
47+
for instr in initcode_asm:
48+
if isinstance(instr, str):
49+
assert not instr.startswith(foo_label), instr

0 commit comments

Comments
 (0)