-
-
Notifications
You must be signed in to change notification settings - Fork 804
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: add support for modules with variables #3707
Closed
charles-cooper
wants to merge
31
commits into
vyperlang:master
from
charles-cooper:feat/module_variables
Closed
Changes from 16 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
a59d575
wip - module variables
charles-cooper e353a15
add size_in_bytes to module
charles-cooper 33dffaf
wip - storage allocator
charles-cooper 654256b
remove ImportedVariable thing
charles-cooper bcc03d6
wip - add get_element_ptr for module, fix some logic in Expr.parse_At…
charles-cooper e9b867a
call set_data_positions recursively
charles-cooper 037d5a6
add a sanity check
charles-cooper 3512e3f
rename some size calculators and add immutable_bytes_required to Vype…
charles-cooper 86c299a
add a comment
charles-cooper 9e689b9
add Context.self_ptr helper
charles-cooper 8becda2
add a note
charles-cooper a0d0bd1
Merge branch 'master' into feat/module_variables
charles-cooper 9ac072b
improve Context.self_ptr
charles-cooper 4e102bf
add function variable read/writes analysis
charles-cooper 9f100d9
calculate pointer things
charles-cooper 2d05699
quash mypy
charles-cooper 1585bdc
wip - handle immutables
charles-cooper bf6e99c
feat: replace `enum` with `flag` keyword (#3697)
AlbertoCentonze 1824321
refactor: make `assert_tx_failed` a contextmanager (#3706)
DanielSchiavini 7489e34
feat: allow `range(x, y, bound=N)` (#3679)
DanielSchiavini 1040f3e
feat: improve panics in IR generation (#3708)
charles-cooper 977851a
add special visibility for the __init__ function
charles-cooper 8af611b
remove unused MemoryOffset, CalldataOffset classes
charles-cooper c241e91
wip - allow init functions to be called from init func
charles-cooper 3de7bb2
rename DataLocations.CODE to IMMUTABLES
charles-cooper ee91a52
refactor set_data_positions and rework VarInfo positions API
charles-cooper 5e08300
thread new offset through codegen
charles-cooper 1e393fa
mark storage layout override tests as xfail
charles-cooper 6cf9ff0
Merge branch 'master' into feat/module_variables
charles-cooper 7a82180
Merge branch 'master' into feat/module_variables
charles-cooper eff76e0
Merge branch 'master' into feat/module_variables
charles-cooper 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
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 | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,6 +7,7 @@ | |||||||||||||||||||||||||||
from vyper.evm.address_space import CALLDATA, DATA, IMMUTABLES, MEMORY, STORAGE, TRANSIENT | ||||||||||||||||||||||||||||
from vyper.evm.opcodes import version_check | ||||||||||||||||||||||||||||
from vyper.exceptions import CompilerPanic, StructureException, TypeCheckFailure, TypeMismatch | ||||||||||||||||||||||||||||
from vyper.semantics.data_locations import DataLocation | ||||||||||||||||||||||||||||
from vyper.semantics.types import ( | ||||||||||||||||||||||||||||
AddressT, | ||||||||||||||||||||||||||||
BoolT, | ||||||||||||||||||||||||||||
|
@@ -17,6 +18,7 @@ | |||||||||||||||||||||||||||
HashMapT, | ||||||||||||||||||||||||||||
IntegerT, | ||||||||||||||||||||||||||||
InterfaceT, | ||||||||||||||||||||||||||||
ModuleT, | ||||||||||||||||||||||||||||
StructT, | ||||||||||||||||||||||||||||
TupleT, | ||||||||||||||||||||||||||||
_BytestringT, | ||||||||||||||||||||||||||||
|
@@ -64,6 +66,17 @@ def is_array_like(typ): | |||||||||||||||||||||||||||
return ret | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def data_location_to_addr_space(s: DataLocation): | ||||||||||||||||||||||||||||
if s == DataLocation.STORAGE: | ||||||||||||||||||||||||||||
return STORAGE | ||||||||||||||||||||||||||||
if s == DataLocation.MEMORY: | ||||||||||||||||||||||||||||
return MEMORY | ||||||||||||||||||||||||||||
if s == DataLocation.CODE: | ||||||||||||||||||||||||||||
return IMMUTABLES | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
raise CompilerPanic("unreachable") # pragma: nocover | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
def get_type_for_exact_size(n_bytes): | ||||||||||||||||||||||||||||
"""Create a type which will take up exactly n_bytes. Used for allocating internal buffers. | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
@@ -442,6 +455,39 @@ def _getelemptr_abi_helper(parent, member_t, ofst, clamp=True): | |||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# get a variable out of a module | ||||||||||||||||||||||||||||
def _get_element_ptr_module(parent, key): | ||||||||||||||||||||||||||||
# note that this implementation is substantially similar to | ||||||||||||||||||||||||||||
# the StructT pathway through get_element_ptr_tuplelike and | ||||||||||||||||||||||||||||
# has potential to be refactored. | ||||||||||||||||||||||||||||
module_t = parent.typ | ||||||||||||||||||||||||||||
assert isinstance(module_t, ModuleT) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
assert isinstance(key, str) | ||||||||||||||||||||||||||||
typ = module_t.variables[key].typ | ||||||||||||||||||||||||||||
attrs = list(module_t.variables.keys()) | ||||||||||||||||||||||||||||
index = attrs.index(key) | ||||||||||||||||||||||||||||
annotation = key | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
ofst = 0 # offset from parent start | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
assert parent.location == STORAGE, parent.location | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
for i in range(index): | ||||||||||||||||||||||||||||
ofst += module_t.variables[attrs[i]].typ.storage_slots_required | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# calculated the same way both ways | ||||||||||||||||||||||||||||
assert ofst == module_t.variables[key].position.position | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
return IRnode.from_list( | ||||||||||||||||||||||||||||
add_ofst(parent, ofst), | ||||||||||||||||||||||||||||
typ=typ, | ||||||||||||||||||||||||||||
location=parent.location, | ||||||||||||||||||||||||||||
encoding=parent.encoding, | ||||||||||||||||||||||||||||
annotation=annotation, | ||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
# TODO simplify this code, especially the ABI decoding | ||||||||||||||||||||||||||||
def _get_element_ptr_tuplelike(parent, key): | ||||||||||||||||||||||||||||
typ = parent.typ | ||||||||||||||||||||||||||||
|
@@ -485,7 +531,7 @@ def _get_element_ptr_tuplelike(parent, key): | |||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if parent.location.word_addressable: | ||||||||||||||||||||||||||||
for i in range(index): | ||||||||||||||||||||||||||||
ofst += typ.member_types[attrs[i]].storage_size_in_words | ||||||||||||||||||||||||||||
ofst += typ.member_types[attrs[i]].storage_slots_required | ||||||||||||||||||||||||||||
elif parent.location.byte_addressable: | ||||||||||||||||||||||||||||
for i in range(index): | ||||||||||||||||||||||||||||
ofst += typ.member_types[attrs[i]].memory_bytes_required | ||||||||||||||||||||||||||||
|
@@ -552,7 +598,7 @@ def _get_element_ptr_array(parent, key, array_bounds_check): | |||||||||||||||||||||||||||
return _getelemptr_abi_helper(parent, subtype, ofst) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
if parent.location.word_addressable: | ||||||||||||||||||||||||||||
element_size = subtype.storage_size_in_words | ||||||||||||||||||||||||||||
element_size = subtype.storage_slots_required | ||||||||||||||||||||||||||||
elif parent.location.byte_addressable: | ||||||||||||||||||||||||||||
element_size = subtype.memory_bytes_required | ||||||||||||||||||||||||||||
else: | ||||||||||||||||||||||||||||
|
@@ -590,6 +636,9 @@ def get_element_ptr(parent, key, array_bounds_check=True): | |||||||||||||||||||||||||||
if is_tuple_like(typ): | ||||||||||||||||||||||||||||
ret = _get_element_ptr_tuplelike(parent, key) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
elif isinstance(typ, ModuleT): | ||||||||||||||||||||||||||||
ret = _get_element_ptr_module(parent, key) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
elif isinstance(typ, HashMapT): | ||||||||||||||||||||||||||||
ret = _get_element_ptr_mapping(parent, key) | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
|
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.
Check notice
Code scanning / CodeQL
Explicit returns mixed with implicit (fall through) returns Note