-
-
Notifications
You must be signed in to change notification settings - Fork 793
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
fix: call internal functions from constructor #2496
fix: call internal functions from constructor #2496
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2496 +/- ##
===========================================
- Coverage 87.37% 71.00% -16.38%
===========================================
Files 94 94
Lines 10054 10115 +61
Branches 2490 2443 -47
===========================================
- Hits 8785 7182 -1603
- Misses 802 2260 +1458
- Partials 467 673 +206
Continue to review full report at Codecov.
|
2980cf1
to
ca57d81
Compare
f043608
to
0cf738b
Compare
0cf738b
to
fa85fbf
Compare
this commit allows the user to call internal functions from the `__init__` function. it does this by tracing all the internal functions called from every function's execution (during the annotation phase), and then generating code for the functions called from the init function for during deploy code generation this also has a performance benefit (compiler time) because we can get rid of the two-pass method for tracing frame size. also, this opens the door to topsort of internal functions, if desired (so that the user does not have to order them manually).
dcdb2a6
to
f85b6de
Compare
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.
Needs tests and documentation internally talking about the flow that is taken
ah i ended up doing some refactoring and forgot to turn this back into a draft |
btw it now depends on a change to |
the old way depended on traversing the IR and looking for nodes with specific fields. this uses the function signatures produced during codegen which are more well structured.
This pull request introduces 3 alerts when merging a22be84 into 31e2b4e - view on LGTM.com new alerts:
|
This pull request introduces 1 alert when merging f75404f into 31e2b4e - view on LGTM.com new alerts:
|
to demonstrate and test topsort working
@internal | ||
def _stockAvailable() -> uint256: | ||
return self.holdings[self.company] | ||
|
||
# Find out how much stock any address (that's owned by someone) has. | ||
@view | ||
@internal | ||
def _getHolding(_stockholder: address) -> uint256: | ||
return self.holdings[_stockholder] |
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.
These two methods aren't really that useful
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.
true, i think they are good there just to demonstrate that internal functions can be defined after they are called
else: | ||
# frame size for internal function does not need to be adjusted | ||
# since it is already accounted for by the caller | ||
o.total_gas = o.gas | ||
# note: internal functions do not need to adjust gas estimate since | ||
# it is already accounted for by the caller. | ||
pass |
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.
remove else
case
this commit allows the user to call internal functions from the `__init__` function. it does this by generating a call graph during the annotation phase and then generating code for the functions called from the init function for during deploy code generation this also has a performance benefit (compiler time) because we can get rid of the two-pass method for tracing frame size. now that we have a call graph, this commit also introduces a topsort of functions based on the call dependency tree. this ensures we can compile functions that call functions that occur after them in the source code. lastly, this commit also refactors vyper/codegen/module.py so that the payable logic is cleaner, it uses properties instead of calculations more, and cleans up properties on IRnode, FunctionSignature and Context.
What I did
allow calling internal functions from constructor. fixes #1631 and #2318
How I did it
Commit message
How to verify it
Description for the changelog
Cute Animal Picture