Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reimplement AST folding #3669

Merged
merged 189 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from 178 commits
Commits
Show all changes
189 commits
Select commit Hold shift + click to select a range
50dc8fa
wip
tserg Nov 8, 2023
78d954c
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Nov 9, 2023
fafb447
use folded kwargs for fn defaults
tserg Nov 9, 2023
0f6b929
separate expansion steps
tserg Nov 9, 2023
6069f3b
add comment
tserg Nov 9, 2023
1c4bf3d
move remove unused statements after folding
tserg Nov 10, 2023
0aa3b69
fix get_index_value
tserg Nov 10, 2023
f2afc0d
wip
tserg Nov 10, 2023
7f75749
fix lint
tserg Nov 10, 2023
415e123
add compile time and runtime constants attributes
tserg Nov 12, 2023
1557927
fix list tests
tserg Nov 13, 2023
0bebd49
fix tuple exprinfo ctor; fix lint
tserg Nov 13, 2023
0f0ecd1
set folded_value metadata in constant node ctor
tserg Nov 13, 2023
e9be281
fix for loop bound
tserg Nov 13, 2023
94f4f88
wip
tserg Nov 13, 2023
3340cd1
fix folding tests
tserg Nov 13, 2023
763ab84
fix darray from annotation
tserg Nov 13, 2023
56b4149
fix raw call kwargs
tserg Nov 13, 2023
7c4fe7b
fix constant expression visit
tserg Nov 13, 2023
e549ce2
fix unary op
tserg Nov 13, 2023
7409e11
fix exception
tserg Nov 13, 2023
a89b14b
revert folding tests
tserg Nov 13, 2023
6d0f714
remove literal bounds validation
tserg Nov 13, 2023
7b38284
validate folded value with typ
tserg Nov 13, 2023
78de745
revert literal validation in folding
tserg Nov 13, 2023
519ec25
fix some tests
tserg Nov 13, 2023
04ccfa6
fix kwarg handler
tserg Nov 13, 2023
c10095b
fix for semantics
tserg Nov 13, 2023
e14da49
fix iteration tests
tserg Nov 13, 2023
9b94fdd
fix lint
tserg Nov 13, 2023
e74d701
update tests
tserg Nov 14, 2023
bbf0510
fix minmax
tserg Nov 14, 2023
6be94e3
fix lint
tserg Nov 14, 2023
0b0c947
fix infer_arg_types sig
tserg Nov 14, 2023
5fa44d7
fix prefold annotation
tserg Nov 14, 2023
0252268
make prefold a wrapper over evaluate
tserg Nov 14, 2023
e46f528
fix abs test
tserg Nov 14, 2023
f96d25f
fix lint
tserg Nov 14, 2023
d961beb
fix typo
tserg Nov 14, 2023
3c37c52
fix interface tests
tserg Nov 14, 2023
23fe402
fix some builtins wip
tserg Nov 14, 2023
dd8cb8f
fix tests
tserg Nov 14, 2023
93c2e31
fix interface repr
tserg Nov 14, 2023
02af165
add annotated ast output
tserg Nov 14, 2023
3b59708
fix compiler phases
tserg Nov 14, 2023
0bfaf2f
add prefold to builtin fn sig
tserg Nov 14, 2023
78bad6c
clean up prefold
tserg Nov 14, 2023
524fb8f
fix lint
tserg Nov 14, 2023
92a33cf
fix mypy lint
tserg Nov 14, 2023
28e202f
fix ast dict test
tserg Nov 14, 2023
07f2026
fix mypy
tserg Nov 14, 2023
092f71b
add tests
tserg Nov 15, 2023
cd5f6cc
fix builtins wip
tserg Nov 15, 2023
b0b39e4
add raw ast output
tserg Nov 15, 2023
55a125e
remove dead code
tserg Nov 15, 2023
c480521
add type propagation for subscript folding
tserg Nov 15, 2023
6de0e81
rename to always_folded_before_codegen
tserg Nov 15, 2023
6a0ca23
introduce constancy
tserg Nov 15, 2023
d13eabb
fix lint
tserg Nov 15, 2023
16b069c
rename to VariableConstancy
tserg Nov 15, 2023
2705f10
fix lint
tserg Nov 15, 2023
5a51de3
use IntEnum
tserg Nov 15, 2023
3078bcc
fix more builtins
tserg Nov 15, 2023
1683fb8
add test
tserg Nov 15, 2023
28b02e7
rename unannotated ast output option
tserg Nov 15, 2023
7b46c4e
fix method id typo
tserg Nov 15, 2023
fc565d6
fix help test
tserg Nov 15, 2023
7a13db2
refactor user defined const folding
tserg Nov 16, 2023
8785e02
add darray test
tserg Nov 16, 2023
926fef6
combine check_kwargable and check_constant
tserg Nov 16, 2023
19b0102
remove folded_before_codegen attribute
tserg Nov 16, 2023
596958a
fix lint
tserg Nov 16, 2023
19f5c7f
fix methodid
tserg Nov 16, 2023
c7585c6
clean up NameConstant
tserg Nov 16, 2023
12ac785
rewrite shift check
tserg Nov 16, 2023
37681b7
clean up builtins
tserg Nov 17, 2023
d82dbc0
add builtins tests
tserg Nov 17, 2023
eda9ba8
fix call args constancy
tserg Nov 17, 2023
2520b90
fix abs test
tserg Nov 17, 2023
3d7d317
improve error msg for as_wei_value
tserg Nov 17, 2023
c77244c
fix folded builtins for constants
tserg Nov 17, 2023
f39effa
fix constant var decl expr visit
tserg Nov 17, 2023
e55eba6
fix lint
tserg Nov 17, 2023
5816107
add unaryop and compare to constancy check
tserg Nov 18, 2023
5620301
add for bound tests
tserg Nov 18, 2023
6a5e00d
clean up index value getter
tserg Nov 18, 2023
6505a94
fix lint
tserg Nov 18, 2023
6af3191
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Dec 21, 2023
0f2302b
fix lint
tserg Dec 21, 2023
4256dca
fix tests; relax type propagation in folding builtins
tserg Dec 21, 2023
ce3f61f
rename evaluate to fold
tserg Dec 21, 2023
83a8b66
add immutable enum to modifiability
tserg Dec 22, 2023
59d2a04
add _is_prefoldable attribute to nodes
tserg Dec 22, 2023
be4be41
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Dec 24, 2023
7898efe
remove prefold; add get_folded_value and get_folded_value_maybe
tserg Dec 24, 2023
3b6a566
uncatch vy exc in prefold
tserg Dec 24, 2023
51d9344
fix unary fold node type
tserg Dec 24, 2023
64214ec
fix bool test
tserg Dec 24, 2023
1d3de4b
rename get_folded_value to get_folded_value_throwing
tserg Dec 24, 2023
1d8b5be
use maybe for side efx in prefold
tserg Dec 24, 2023
6e3ad8e
replace get with maybe variant
tserg Dec 24, 2023
5bde191
use get_folded_value_throwing for prefold
tserg Dec 24, 2023
4f4576c
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Dec 25, 2023
6daf69f
remove is_immutable; rename constancy to modifiability
tserg Dec 25, 2023
ade20fd
use throwing instead of maybe when folding
tserg Dec 26, 2023
b0a295d
fix as wei value test
tserg Dec 26, 2023
6838aa2
fix lint
tserg Dec 26, 2023
bce87d1
use throwing in prefold
tserg Dec 26, 2023
e4fb5d8
remove folding
tserg Dec 26, 2023
7134cc2
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Dec 26, 2023
1f9be95
fix minmax folded node
tserg Dec 27, 2023
81d1bfb
improve tests
tserg Dec 27, 2023
3736bf5
use pytest.raises instead of assert_compile_failed
tserg Dec 27, 2023
dd2522d
Merge branch 'refactor/folding_alt2' into refactor/no_folding
tserg Dec 27, 2023
e1e5576
fix kwarg handling
tserg Dec 27, 2023
3a642fb
fix kwargs and constant structs
tserg Dec 27, 2023
27441ec
fix list codegen
tserg Dec 27, 2023
394c9fb
uncatch vyper exception when prefolding call nodes
tserg Dec 27, 2023
17f01fa
handle const, list and tuples
tserg Dec 28, 2023
4df618f
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Dec 28, 2023
93a9b42
fix tuple
tserg Dec 28, 2023
14d1e09
read folded value from metadata
tserg Dec 28, 2023
85de1de
Merge branch 'master' of https://github.com/vyperlang/vyper into refa…
tserg Dec 28, 2023
59f7d36
try reverting const amendment
tserg Dec 28, 2023
1f57495
revert; assert struct
tserg Dec 28, 2023
13b341b
clean up expr codegen ctor
tserg Dec 28, 2023
1709d3a
relax module node for exception str
tserg Dec 28, 2023
fe925d6
fix lint
tserg Dec 28, 2023
8ddd2ca
Merge branch 'refactor/no_folding' into refactor/folding_alt2
tserg Dec 28, 2023
5cffa31
remove folded ast output
tserg Dec 28, 2023
aff2fc1
remove folding
tserg Dec 28, 2023
a37fc0e
update READMEs
tserg Dec 28, 2023
bb066c8
remove outdated comment
tserg Dec 28, 2023
20c773d
fix tests
tserg Dec 28, 2023
9ae1344
fix outdated comments
tserg Dec 28, 2023
d6f79e8
replace _kwargable with modifiability for builtins
tserg Dec 28, 2023
3cf993b
remove maybe variant; add is_literal_value and has_folded_value prope…
tserg Dec 29, 2023
9dbc5db
refactor is_literal_value
tserg Dec 29, 2023
4130dbb
minor touch up
tserg Dec 29, 2023
b3d9f20
remove _is_prefoldable
tserg Dec 29, 2023
6d2addc
minor clean up
tserg Dec 29, 2023
6eca837
fix range
tserg Dec 29, 2023
5432063
clean up has_folded_value branches
tserg Dec 29, 2023
87e6469
add expected_return_typ named kwarg
tserg Dec 29, 2023
9beacb2
fix mypy
tserg Dec 29, 2023
31791b2
fix range test
tserg Dec 29, 2023
37e9a28
try simplifying const structs codegen
tserg Dec 29, 2023
1375c03
move validate_literal_nodes into parse_with_settings
charles-cooper Dec 30, 2023
00dadf7
update some comments
charles-cooper Dec 30, 2023
5012cb6
set parent on folded nodes
charles-cooper Dec 30, 2023
2adda25
fix lint
charles-cooper Dec 30, 2023
ead4f3d
remove dead function: Module.replace_in_tree
charles-cooper Dec 30, 2023
ecabcc5
improve a comment
charles-cooper Dec 30, 2023
730fbc6
refactor pre_typecheck
charles-cooper Dec 30, 2023
0e225d5
fix modification of list while iterating over it
charles-cooper Dec 30, 2023
c947593
update calls to `fold()` in tests
charles-cooper Dec 30, 2023
8f29c77
bugfix
charles-cooper Dec 30, 2023
4095ced
remove an isinstance check
charles-cooper Dec 30, 2023
be04b01
fix mypy
charles-cooper Dec 30, 2023
211a233
fix some exception handling
charles-cooper Dec 30, 2023
f862b2b
fix some more bugs
charles-cooper Dec 30, 2023
9a318d5
rollback change moving validate_literal_nodes
charles-cooper Dec 30, 2023
c2ec198
fix lint
charles-cooper Dec 30, 2023
cc15bf3
clarify a comment
charles-cooper Dec 30, 2023
ce8a192
improve vy_ast.Hex API
charles-cooper Dec 30, 2023
1ea47ad
rewrite some error messages
charles-cooper Dec 30, 2023
c87b156
remove "type-checking" _try_folds
charles-cooper Dec 30, 2023
6437230
fix a bug
charles-cooper Dec 30, 2023
5648335
rewrite a ternary op
charles-cooper Dec 30, 2023
94a562e
simplify the modifiability hierarchy
charles-cooper Dec 31, 2023
853f046
fix lint
charles-cooper Dec 31, 2023
d04fb7c
fix transient variables
charles-cooper Dec 31, 2023
c93ece1
some comments
charles-cooper Dec 31, 2023
2f00b29
add another note
charles-cooper Dec 31, 2023
58f25b6
add back in deepcopy of vyper_module
charles-cooper Dec 31, 2023
580bd89
change unannotated_ast/ast to ast/annotated_ast, respectively
charles-cooper Dec 31, 2023
3fb3bc0
fix lint
charles-cooper Dec 31, 2023
8ac8fe6
fix lint, some tests
charles-cooper Dec 31, 2023
4937876
simplify infer_kwarg_types for method_id
charles-cooper Dec 31, 2023
41e0fa3
use pytest.raises instead of assert_compile_failed for a new test
charles-cooper Dec 31, 2023
2303b37
clarify a branch condition
charles-cooper Dec 31, 2023
a31611e
remove a redundant __init__ implementation
charles-cooper Dec 31, 2023
18a1453
lint, fix an error message
charles-cooper Dec 31, 2023
d826be8
improve an error message
charles-cooper Dec 31, 2023
c4757dd
fix: block None nodes at ast level
charles-cooper Dec 31, 2023
f7edbbd
fix lint
charles-cooper Dec 31, 2023
4296250
fix an error message
charles-cooper Dec 31, 2023
1ada8f1
fix some comments, remove a dead function
charles-cooper Dec 31, 2023
c19f04e
fix comment
charles-cooper Dec 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions tests/functional/builtins/codegen/test_keccak256.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from vyper.utils import hex_to_int


def test_hash_code(get_contract_with_gas_estimation, keccak):
hash_code = """
@external
Expand Down Expand Up @@ -80,3 +83,31 @@ def try32(inp: bytes32) -> bool:
assert c.tryy(b"\x35" * 33) is True

print("Passed KECCAK256 hash test")


def test_hash_constant_bytes32(get_contract_with_gas_estimation, keccak):
hex_val = "0x1234567890123456789012345678901234567890123456789012345678901234"
code = f"""
FOO: constant(bytes32) = {hex_val}
BAR: constant(bytes32) = keccak256(FOO)
@external
def foo() -> bytes32:
x: bytes32 = BAR
return x
"""
c = get_contract_with_gas_estimation(code)
assert "0x" + c.foo().hex() == keccak(hex_to_int(hex_val).to_bytes(32, "big")).hex()


def test_hash_constant_string(get_contract_with_gas_estimation, keccak):
str_val = "0x1234567890123456789012345678901234567890123456789012345678901234"
code = f"""
FOO: constant(String[66]) = "{str_val}"
BAR: constant(bytes32) = keccak256(FOO)
@external
def foo() -> bytes32:
x: bytes32 = BAR
return x
"""
c = get_contract_with_gas_estimation(code)
assert "0x" + c.foo().hex() == keccak(str_val.encode()).hex()
30 changes: 30 additions & 0 deletions tests/functional/builtins/codegen/test_sha256.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from vyper.utils import hex_to_int

pytestmark = pytest.mark.usefixtures("memory_mocker")


Expand Down Expand Up @@ -77,3 +79,31 @@ def bar() -> bytes32:
c.set(test_val, transact={})
assert c.a() == test_val
assert c.bar() == hashlib.sha256(test_val).digest()


def test_sha256_constant_bytes32(get_contract_with_gas_estimation):
hex_val = "0x1234567890123456789012345678901234567890123456789012345678901234"
code = f"""
FOO: constant(bytes32) = {hex_val}
BAR: constant(bytes32) = sha256(FOO)
@external
def foo() -> bytes32:
x: bytes32 = BAR
return x
"""
c = get_contract_with_gas_estimation(code)
assert c.foo() == hashlib.sha256(hex_to_int(hex_val).to_bytes(32, "big")).digest()


def test_sha256_constant_string(get_contract_with_gas_estimation):
str_val = "0x1234567890123456789012345678901234567890123456789012345678901234"
code = f"""
FOO: constant(String[66]) = "{str_val}"
BAR: constant(bytes32) = sha256(FOO)
@external
def foo() -> bytes32:
x: bytes32 = BAR
return x
"""
c = get_contract_with_gas_estimation(code)
assert c.foo() == hashlib.sha256(str_val.encode()).digest()
7 changes: 1 addition & 6 deletions tests/functional/builtins/codegen/test_unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,11 @@ def bar() -> decimal:

def test_negation_int128(get_contract):
code = """
a: constant(int128) = -2**127

@external
def foo() -> int128:
return -2**127
a: constant(int128) = min_value(int128)

@external
def bar() -> int128:
return -(a+1)
"""
c = get_contract(code)
assert c.foo() == -(2**127)
assert c.bar() == 2**127 - 1
10 changes: 5 additions & 5 deletions tests/functional/builtins/folding/test_abs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from vyper import ast as vy_ast
from vyper.builtins import functions as vy_fn
from vyper.exceptions import OverflowException
from vyper.exceptions import InvalidType


@pytest.mark.fuzzing
Expand All @@ -21,7 +21,7 @@ def foo(a: int256) -> int256:

vyper_ast = vy_ast.parse_to_ast(f"abs({a})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE["abs"].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE["abs"]._try_fold(old_node)

assert contract.foo(a) == new_node.value == abs(a)

Expand All @@ -35,7 +35,7 @@ def test_abs_upper_bound_folding(get_contract, a):
def foo(a: int256) -> int256:
return abs({a})
"""
with pytest.raises(OverflowException):
with pytest.raises(InvalidType):
get_contract(source)


Expand All @@ -55,7 +55,7 @@ def test_abs_lower_bound_folded(get_contract, tx_failed):
source = """
@external
def foo() -> int256:
return abs(-2**255)
return abs(min_value(int256))
"""
with pytest.raises(OverflowException):
with pytest.raises(InvalidType):
get_contract(source)
2 changes: 1 addition & 1 deletion tests/functional/builtins/folding/test_addmod_mulmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def foo(a: uint256, b: uint256, c: uint256) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({a}, {b}, {c})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert contract.foo(a, b, c) == new_node.value
11 changes: 7 additions & 4 deletions tests/functional/builtins/folding/test_bitwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
st_sint256 = st.integers(min_value=-(2**255), max_value=2**255 - 1)


# TODO: move this file to tests/unit/ast/nodes/test_fold_bitwise.py


@pytest.mark.fuzzing
@settings(max_examples=50)
@pytest.mark.parametrize("op", ["&", "|", "^"])
Expand All @@ -28,7 +31,7 @@ def foo(a: uint256, b: uint256) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"{a} {op} {b}")
old_node = vyper_ast.body[0].value
new_node = old_node.evaluate()
new_node = old_node.get_folded_value()

assert contract.foo(a, b) == new_node.value

Expand All @@ -49,7 +52,7 @@ def foo(a: uint256, b: uint256) -> uint256:
old_node = vyper_ast.body[0].value

try:
new_node = old_node.evaluate()
new_node = old_node.get_folded_value()
# force bounds check, no-op because validate_numeric_bounds
# already does this, but leave in for hygiene (in case
# more types are added).
Expand Down Expand Up @@ -79,7 +82,7 @@ def foo(a: int256, b: uint256) -> int256:
old_node = vyper_ast.body[0].value

try:
new_node = old_node.evaluate()
new_node = old_node.get_folded_value()
validate_expected_type(new_node, INT256_T) # force bounds check
# compile time behavior does not match runtime behavior.
# compile-time will throw on OOB, runtime will wrap.
Expand All @@ -104,6 +107,6 @@ def foo(a: uint256) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"~{value}")
old_node = vyper_ast.body[0].value
new_node = old_node.evaluate()
new_node = old_node.get_folded_value()

assert contract.foo(value) == new_node.value
2 changes: 1 addition & 1 deletion tests/functional/builtins/folding/test_epsilon.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ def foo() -> {typ_name}:

vyper_ast = vy_ast.parse_to_ast(f"epsilon({typ_name})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE["epsilon"].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE["epsilon"]._try_fold(old_node)

assert contract.foo() == new_node.value
2 changes: 1 addition & 1 deletion tests/functional/builtins/folding/test_floor_ceil.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def foo(a: decimal) -> int256:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({value})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert contract.foo(value) == new_node.value
4 changes: 2 additions & 2 deletions tests/functional/builtins/folding/test_fold_as_wei_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def foo(a: decimal) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"as_wei_value({value:.10f}, '{denom}')")
old_node = vyper_ast.body[0].value
new_node = vy_fn.AsWeiValue().evaluate(old_node)
new_node = vy_fn.AsWeiValue()._try_fold(old_node)

assert contract.foo(value) == new_node.value

Expand All @@ -51,6 +51,6 @@ def foo(a: uint256) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"as_wei_value({value}, '{denom}')")
old_node = vyper_ast.body[0].value
new_node = vy_fn.AsWeiValue().evaluate(old_node)
new_node = vy_fn.AsWeiValue()._try_fold(old_node)

assert contract.foo(value) == new_node.value
6 changes: 3 additions & 3 deletions tests/functional/builtins/folding/test_keccak_sha.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def foo(a: String[100]) -> bytes32:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}('''{value}''')")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert f"0x{contract.foo(value).hex()}" == new_node.value

Expand All @@ -41,7 +41,7 @@ def foo(a: Bytes[100]) -> bytes32:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({value})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert f"0x{contract.foo(value).hex()}" == new_node.value

Expand All @@ -62,6 +62,6 @@ def foo(a: Bytes[100]) -> bytes32:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({value})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert f"0x{contract.foo(value).hex()}" == new_node.value
6 changes: 3 additions & 3 deletions tests/functional/builtins/folding/test_len.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def foo(a: String[1024]) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"len('{value}')")
old_node = vyper_ast.body[0].value
new_node = vy_fn.Len().evaluate(old_node)
new_node = vy_fn.Len()._try_fold(old_node)

assert contract.foo(value) == new_node.value

Expand All @@ -35,7 +35,7 @@ def foo(a: Bytes[1024]) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"len(b'{value}')")
old_node = vyper_ast.body[0].value
new_node = vy_fn.Len().evaluate(old_node)
new_node = vy_fn.Len()._try_fold(old_node)

assert contract.foo(value.encode()) == new_node.value

Expand All @@ -53,6 +53,6 @@ def foo(a: Bytes[1024]) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"len({value})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.Len().evaluate(old_node)
new_node = vy_fn.Len()._try_fold(old_node)

assert contract.foo(value) == new_node.value
6 changes: 3 additions & 3 deletions tests/functional/builtins/folding/test_min_max.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def foo(a: decimal, b: decimal) -> decimal:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({left}, {right})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert contract.foo(left, right) == new_node.value

Expand All @@ -50,7 +50,7 @@ def foo(a: int128, b: int128) -> int128:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({left}, {right})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert contract.foo(left, right) == new_node.value

Expand All @@ -69,6 +69,6 @@ def foo(a: uint256, b: uint256) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"{fn_name}({left}, {right})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.DISPATCH_TABLE[fn_name].evaluate(old_node)
new_node = vy_fn.DISPATCH_TABLE[fn_name]._try_fold(old_node)

assert contract.foo(left, right) == new_node.value
2 changes: 1 addition & 1 deletion tests/functional/builtins/folding/test_powmod.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def foo(a: uint256, b: uint256) -> uint256:

vyper_ast = vy_ast.parse_to_ast(f"pow_mod256({a}, {b})")
old_node = vyper_ast.body[0].value
new_node = vy_fn.PowMod256().evaluate(old_node)
new_node = vy_fn.PowMod256()._try_fold(old_node)

assert contract.foo(a, b) == new_node.value
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,48 @@ def foo(a: address = empty(address)):
def foo(a: int112 = min_value(int112)):
self.A = a
""",
"""
struct X:
x: int128
y: address
BAR: constant(X) = X({x: 1, y: 0x0000000000000000000000000000000000012345})
@external
def out_literals(a: int128 = BAR.x + 1) -> X:
return BAR
""",
"""
struct X:
x: int128
y: address
struct Y:
x: X
y: uint256
BAR: constant(X) = X({x: 1, y: 0x0000000000000000000000000000000000012345})
FOO: constant(Y) = Y({x: BAR, y: 256})
@external
def out_literals(a: int128 = FOO.x.x + 1) -> Y:
return FOO
""",
"""
struct Bar:
a: bool

BAR: constant(Bar) = Bar({a: True})

@external
def foo(x: bool = True and not BAR.a):
pass
""",
"""
struct Bar:
a: uint256

BAR: constant(Bar) = Bar({ a: 123 })

@external
def foo(x: bool = BAR.a + 1 > 456):
pass
""",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def test_int128_too_long(get_contract, tx_failed):
contract_1 = """
@external
def foo() -> int256:
return (2**255)-1
return max_value(int256)
"""

c = get_contract(contract_1)
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/codegen/test_call_graph_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def foo():
t = CompilerData(code)

# check the .called_functions data structure on foo() directly
foo = t.vyper_module_folded.get_children(vy_ast.FunctionDef, filters={"name": "foo"})[0]
foo = t.annotated_vyper_module.get_children(vy_ast.FunctionDef, filters={"name": "foo"})[0]
foo_t = foo._metadata["func_type"]
assert [f.name for f in foo_t.called_functions] == func_names

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/codegen/test_interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ def ok() -> {typ}:

@external
def should_fail() -> int256:
return -2**255 # OOB for all int/uint types with less than 256 bits
return min_value(int256)
"""

code = f"""
Expand Down
Loading
Loading