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

add n_slots to storage variables #3788

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 19 additions & 19 deletions tests/unit/cli/storage_layout/test_storage_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ def public_foo3():

assert out["layout"]["storage_layout"] == {
"$.nonreentrant_key": {"slot": 0, "type": "nonreentrant lock"},
"foo": {"slot": 1, "type": "HashMap[address, uint256]"},
"arr": {"slot": 2, "type": "DynArray[uint256, 3]"},
"baz": {"slot": 6, "type": "Bytes[65]"},
"bar": {"slot": 10, "type": "uint256"},
"foo": {"slot": 1, "type": "HashMap[address, uint256]", "n_slots": 1},
"arr": {"slot": 2, "type": "DynArray[uint256, 3]", "n_slots": 4},
"baz": {"slot": 6, "type": "Bytes[65]", "n_slots": 4},
"bar": {"slot": 10, "type": "uint256", "n_slots": 1},
}


Expand All @@ -68,7 +68,7 @@ def __init__():
},
"storage_layout": {
"$.nonreentrant_key": {"slot": 0, "type": "nonreentrant lock"},
"name": {"slot": 1, "type": "String[32]"},
"name": {"slot": 1, "type": "String[32]", "n_slots": 2},
},
}

Expand Down Expand Up @@ -115,9 +115,9 @@ def __init__():
},
"storage_layout": {
"$.nonreentrant_key": {"slot": 0, "type": "nonreentrant lock"},
"counter": {"slot": 1, "type": "uint256"},
"counter2": {"slot": 2, "type": "uint256"},
"a_library": {"supply": {"slot": 3, "type": "uint256"}},
"counter": {"slot": 1, "type": "uint256", "n_slots": 1},
"counter2": {"slot": 2, "type": "uint256", "n_slots": 1},
"a_library": {"supply": {"slot": 3, "type": "uint256", "n_slots": 1}},
},
}

Expand Down Expand Up @@ -164,9 +164,9 @@ def __init__():
},
"storage_layout": {
"$.nonreentrant_key": {"slot": 0, "type": "nonreentrant lock"},
"counter": {"slot": 1, "type": "uint256"},
"a_library": {"supply": {"slot": 2, "type": "uint256"}},
"counter2": {"slot": 3, "type": "uint256"},
"counter": {"slot": 1, "type": "uint256", "n_slots": 1},
"a_library": {"supply": {"slot": 2, "type": "uint256", "n_slots": 1}},
"counter2": {"slot": 3, "type": "uint256", "n_slots": 1},
},
}

Expand Down Expand Up @@ -247,10 +247,10 @@ def bar():
},
"storage_layout": {
"$.nonreentrant_key": {"slot": 0, "type": "nonreentrant lock"},
"counter": {"slot": 1, "type": "uint256"},
"lib2": {"storage_variable": {"slot": 2, "type": "uint256"}},
"counter2": {"slot": 3, "type": "uint256"},
"a_library": {"supply": {"slot": 4, "type": "uint256"}},
"counter": {"slot": 1, "type": "uint256", "n_slots": 1},
"lib2": {"storage_variable": {"slot": 2, "type": "uint256", "n_slots": 1}},
"counter2": {"slot": 3, "type": "uint256", "n_slots": 1},
"a_library": {"supply": {"slot": 4, "type": "uint256", "n_slots": 1}},
},
}

Expand Down Expand Up @@ -326,12 +326,12 @@ def foo() -> uint256:
},
"storage_layout": {
"$.nonreentrant_key": {"slot": 0, "type": "nonreentrant lock"},
"counter": {"slot": 1, "type": "uint256"},
"counter": {"slot": 1, "type": "uint256", "n_slots": 1},
"lib2": {
"lib1": {"supply": {"slot": 2, "type": "uint256"}},
"storage_variable": {"slot": 3, "type": "uint256"},
"lib1": {"supply": {"slot": 2, "type": "uint256", "n_slots": 1}},
"storage_variable": {"slot": 3, "type": "uint256", "n_slots": 1},
},
"counter2": {"slot": 4, "type": "uint256"},
"counter2": {"slot": 4, "type": "uint256", "n_slots": 1},
},
}

Expand Down
2 changes: 1 addition & 1 deletion vyper/semantics/analysis/data_positions.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _allocate_layout_r(
if location == DataLocation.CODE:
item = {"type": str(type_), "length": size, "offset": offset}
elif location in (DataLocation.STORAGE, DataLocation.TRANSIENT):
item = {"type": str(type_), "slot": offset}
item = {"type": str(type_), "n_slots": size, "slot": offset}
else: # pragma: nocover
raise CompilerPanic("unreachable")
ret[layout_key][node.target.id] = item
Expand Down
Loading