feat!: improve storage slot allocation #10320
Open
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.
Closes #5736
Closes #8659
We currently allocate storage slots for state variables by assuming they are generic over a type
T
which implements theSerialize<N>
trait, and then provideN
slots. This is incorrect for some state variables (notablySharedMutable
).This changes that scheme for one in which state variables implement the
Storage<N>
trait with whatever value they choose, and thatN
is the one that gets selected for their allocation. All state variables currently use theN
from the serialization of their inner type (until we do #5492), so in practice nothing changes so far (but we become ready to perform that work).I also added a simple test for the storage allocation scheme, which should be very helpful in the future as we make this more complex down the line. I also cleaned up some small warnings I found along the way, and removed the weird exception for #8659, which apparently was unnecessary - it may just be a renmant from some older version of the codebase.
edit: I tried to make the test a bit more thorough using dynamic lengths and got some unexpected errors, I'm looking into those.