-
-
Notifications
You must be signed in to change notification settings - Fork 823
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
feat[venom]: inline pass and call conv #4468
Draft
harkal
wants to merge
91
commits into
vyperlang:master
Choose a base branch
from
harkal:feat/inline_pass
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
91 commits
Select commit
Hold shift + click to select a range
8238831
init
harkal c54273c
add fcg
harkal 5565d4c
func inliner
harkal 5f01394
params
harkal 6b88eed
helpers
harkal 2b19059
global opti
harkal 7d144de
work
harkal fe9f39a
refactor
harkal 051225a
float
harkal 1997b25
codename `asylum`
harkal 027a2eb
more conservative
harkal d79c6d9
disable load elimination
harkal ca1ba5f
export func for repl
harkal 7508436
first function is entry
harkal 1257fd4
debuging aids
harkal d4893bd
work
harkal a1f76b6
fix grammar
harkal b4b4ae6
test
harkal a4d4ea9
lint
harkal 7c79be7
mem2var debug
charles-cooper 29ece7c
update varname in mem2var
charles-cooper 542c115
invalidate dfg
harkal a376e88
polish store elimination
charles-cooper 33fd262
test update
harkal 30e0c79
remove superflus passes
harkal c6c3c8a
testing
harkal 020b9b2
Merge branch 'master' into feat/inline_pass
harkal 2ef4df6
helper
harkal 7341c04
handle reverts
harkal 757563d
add tests
harkal bf0ebb3
cleanup
harkal 289d683
bounds
harkal 674fb50
refactors
harkal 057246c
Merge branch 'master' into feat/inline_pass
harkal 05adb1a
refactor, lint, cleanup
harkal 4a2041f
debug
harkal 4878398
work
harkal 385e59f
recursive inline out
harkal af699c6
add has block method
harkal 33d8ffd
make "consts".. "private"
harkal dab4060
temp
harkal 476b9de
inliner
harkal 6fd42ef
fix var equivalance
harkal 4e602b9
lint
harkal 5d0ac96
comment wip stuff
harkal 828e623
make cost a function
harkal 2d5d872
Merge branch 'master' into feat/inline_pass
harkal ad2e8b7
dfg equiv
harkal 6bf03ec
drop var equivalence
harkal 6ca95a6
lint
harkal 82a5ebc
Merge branch 'master' into feat/inline_pass
harkal bb31c40
passthroug
harkal 9d17a79
assert
harkal aba2afc
params
harkal 2e6c79b
temp
harkal 7380f52
Merge branch 'master' into feat/inline_pass
harkal 29c1302
fix edge case in mem2var
harkal cac9d4c
post merge
harkal f04400c
temp
harkal 7fe033d
tmep
harkal 733e3b2
fix
harkal e54bd0f
comment out
harkal 3cdbb48
dfg linting
harkal 70ff390
lint
harkal eaef2a4
sccp fixes
harkal abd12cd
add back
harkal d98dbcd
enable more
harkal 317cfb5
fix
harkal 0234851
new failing test
harkal bd82d5c
venom -> evm changed
harkal abba8ca
internal update test case
harkal 3552bae
get param by name
harkal b61009b
store
harkal 7d44552
fix
harkal 75d1a44
start
harkal 9f3eac0
Revert "start"
harkal 0b50b4b
new cc on all prims
harkal 3093987
bugfix
harkal 4e19321
fixes and cleanup
harkal fb21434
param support in inliner
harkal b1df259
failing test
harkal 642dcb2
no return handling
harkal cf743a9
Merge branch 'master' into feat/inline_pass
harkal 83134fa
lint
harkal 678c80c
wrong paste
harkal 6d43af9
wip
harkal 6adc1c1
wip
harkal 7d6a204
Revert "wip"
harkal a5e4ed8
Revert "wip"
harkal 1941ced
Merge remote-tracking branch 'origin-vyper/master' into feat/inline_pass
harkal 77cf70a
fix
harkal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
def test_simple_call(get_contract): | ||
code = """ | ||
@internal | ||
def name(_name: uint256) -> uint256: | ||
return _name + 1 | ||
|
||
|
||
@external | ||
def foo(x: uint256) -> uint256: | ||
u: uint256 = 1 + x | ||
ret: uint256 = self.name(u + 10) | ||
return ret | ||
""" | ||
|
||
c = get_contract(code) | ||
assert c.foo(1) == 13 | ||
|
||
|
||
def test_simple_call_multiple_args_in_call(get_contract): | ||
code = """ | ||
@internal | ||
def bar(_name: uint256, _name2: uint256) -> uint256: | ||
return _name + 10 | ||
|
||
@external | ||
def foo(x: uint256) -> uint256: | ||
ret: uint256 = self.bar(20, 10) | ||
return ret | ||
""" | ||
|
||
c = get_contract(code) | ||
assert c.foo(1) == 30 | ||
|
||
|
||
def test_simple_call_multiple_args(get_contract): | ||
code = """ | ||
@internal | ||
def bar(_name: uint256, _name2: uint256) -> (uint256, uint256): | ||
return _name + 1, _name + 2 | ||
|
||
@external | ||
def foo(x: uint256) -> (uint256, uint256): | ||
ret: (uint256, uint256) = self.bar(20, 10) | ||
return ret | ||
""" | ||
|
||
c = get_contract(code) | ||
assert c.foo(1) == (21, 22) | ||
|
||
|
||
def test_call_in_call(get_contract): | ||
code = """ | ||
@internal | ||
def _foo(a: uint256) -> uint256: | ||
return a | ||
|
||
@external | ||
def foo() -> uint256: | ||
a: uint256 = 1 | ||
return self._foo(a) | ||
""" | ||
|
||
c = get_contract(code) | ||
|
||
assert c.foo() == 1 | ||
|
||
|
||
def test_2d_array_input_1(get_contract): | ||
code = """ | ||
@internal | ||
def test_input(arr: DynArray[DynArray[int128, 2], 1]) -> DynArray[DynArray[int128, 2], 1]: | ||
return arr | ||
|
||
@external | ||
def test_values(arr: DynArray[DynArray[int128, 2], 1]) -> DynArray[DynArray[int128, 2], 1]: | ||
return self.test_input(arr) | ||
""" | ||
|
||
c = get_contract(code) | ||
assert c.test_values([[1, 2]]) == ([[1, 2]]) | ||
|
||
|
||
def test_call_with_unused_params(get_contract): | ||
code = """ | ||
@internal | ||
def _foo3(a: uint256, b: uint256) -> uint256: | ||
return 42 | ||
|
||
@external | ||
def foo() -> uint256: | ||
return self._foo3(9, 11) | ||
""" | ||
|
||
c = get_contract(code) | ||
|
||
assert c.foo() == 42 | ||
|
||
|
||
def test_internal_assign(get_contract): | ||
code = """ | ||
@internal | ||
def foo(x: uint256) -> uint256: | ||
x = 10 | ||
return x | ||
|
||
@external | ||
def bar(x: uint256) -> uint256: | ||
return self.foo(x) | ||
""" | ||
c = get_contract(code) | ||
|
||
assert c.bar(70) == 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import pytest | ||
|
||
from tests.evm_backends.base_env import ExecutionReverted | ||
|
||
|
||
def test_call_in_call(get_contract): | ||
code = """ | ||
@internal | ||
def _foo(a: uint256,) -> uint256: | ||
return 1 + a | ||
|
||
@internal | ||
def _foo2() -> uint256: | ||
return 4 | ||
|
||
@external | ||
def foo() -> uint256: | ||
return self._foo(self._foo2()) | ||
""" | ||
|
||
c = get_contract(code) | ||
assert c.foo() == 5 | ||
|
||
|
||
def test_call_in_call_with_raise(get_contract): | ||
code = """ | ||
@internal | ||
def sum(a: uint256) -> uint256: | ||
if a > 1: | ||
return a + 1 | ||
raise | ||
|
||
@internal | ||
def middle(a: uint256) -> uint256: | ||
return self.sum(a) | ||
|
||
@external | ||
def test(a: uint256) -> uint256: | ||
return self.middle(a) | ||
""" | ||
|
||
c = get_contract(code) | ||
|
||
assert c.test(2) == 3 | ||
|
||
with pytest.raises(ExecutionReverted): | ||
c.test(0) | ||
|
||
|
||
def test_inliner_with_unused_param(get_contract): | ||
code = """ | ||
data: public(uint256) | ||
|
||
@internal | ||
def _foo(start: uint256, length: uint256): | ||
self.data = start | ||
|
||
@external | ||
def foo(x: uint256, y: uint256): | ||
self._foo(x, y) | ||
""" | ||
|
||
c = get_contract(code) | ||
c.foo(1, 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import itertools | ||
|
||
from tests.venom_utils import parse_from_basic_block | ||
from vyper.venom.analysis import DFGAnalysis, IRAnalysesCache | ||
from vyper.venom.basicblock import IRVariable | ||
from vyper.venom.context import IRContext | ||
|
||
|
||
def _entry_fn(ctx: "IRContext"): | ||
# TODO: make this part of IRContext | ||
return next(iter(ctx.functions.values())) | ||
|
||
|
||
def test_variable_equivalence_dfg_order(): | ||
a_code = """ | ||
main: | ||
%1 = 1 | ||
%2 = %1 | ||
%3 = %2 | ||
""" | ||
# technically invalid code, but variable equivalence should handle | ||
# it either way | ||
b_code = """ | ||
main: | ||
%3 = %2 | ||
%2 = %1 | ||
%1 = 1 | ||
""" | ||
fn1 = _entry_fn(parse_from_basic_block(a_code)) | ||
fn2 = _entry_fn(parse_from_basic_block(b_code)) | ||
|
||
dfg1 = IRAnalysesCache(fn1).request_analysis(DFGAnalysis) | ||
dfg2 = IRAnalysesCache(fn2).request_analysis(DFGAnalysis) | ||
|
||
vars_ = map(IRVariable, ("%1", "%2", "%3")) | ||
for var1, var2 in itertools.combinations(vars_, 2): | ||
assert dfg1.are_equivalent(var1, var2) | ||
assert dfg2.are_equivalent(var1, var2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#4411