-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Experimental: StorageKey
feature
#4297
Conversation
c89c376
to
032acc8
Compare
ce83390
to
895e01c
Compare
895e01c
to
100653a
Compare
Ah conflicts.. let me fix. |
100653a
to
0fa7196
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.
looks great! I just left a couple comments/questions.
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.
Looking good to me! Left some minor suggestions, but will leave it up to you if you think they're worth addressing.
StorageHandle
featureStorageKey
feature
52cf865
to
d435833
Compare
…` RFC (#4464) ## Description Implement FuelLabs/sway-rfcs#23 Closes #3419 (technically via the RFC) Closes #3202 Closes #3043 Closes #2639 Closes #2465 Closes #4304 This is a big one but mostly removes stuff. It's hard to review but the summary of changes below should be sufficient. Most of the changes here are things that I just had to do to make CI pass. - Removed the `--experimental-storage` flag and made its [behavior](#4297) the default. Also removed everything that was required for the previous storage APIs in favour of the new ones. - Break down the `std::storage` into multiple submodules: - `storage_key` implements the API for `std::core::StorageKey` - `storage_api` implements the free functions `read` (previously `get`), `write` (previously `store`), and `clear`. - 4 more modules for the dynamic storage types which now use the new `StorageKey` API. - `#[storage(write)]` now allows reading from storage as well. This is needed because the way we pack structs in storage now requires that we sometimes read from storage first if we were to write a portion of a slot. - Removed the "storage only types" checks and the corresponding tests. - Removed the `__get_storage_key` intrinsic and the `get_storage_key` IR instruction and all corresponding tests. Also removed the `state_index` metadata as it is no longer required. - Added tests and example to showcase nested storage maps and nested storage vectors. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers. Co-authored-by: Joshua Batty <joshpbatty@gmail.com>
Description
This PR introduces
StorageHandle
to thecore
as an experimental feature.StorageHandle
is a descriptor of a location in storage containing two fields:s
.s
or in its subsequent slots. This offset is new and is not described in the RFC. I will rectify that shortly.The standard library introduces helper methods
read
,try_read
, andwrite
toStorageHandle
that allow reading from and writing to the location pointed to by the handle.try_read
returns anOption
wrapping the data whileread
automatically internally unwraps the data and could panic.The summary of this change is as follows:
core::experimental::storage::StorageHandle
std::experimental::storage::*
that should eventually replacestd::storage::*
. This new library mirrors the old one to the extent possible and introduces the helper methods forStorageHandle
. Other data structures such asStorageVec
andStorageBytes
will be introduced in a separate PR.--experimental-storage
toforc
that enables all the required code in the compiler to supportStorageHandle
as described in the IntroducingStorageKey
sway-rfcs#23.StorageHandle
and monomorphizes it as needed.StorageHandle
and storage reassignment are no longer relevant.StorageHandle
. The key and the offset are statically determined based on the index of the storage variable in thestorage
block and the field accessed, if applicable.StorageMap
and other dynamic storage data structures, we now writeimpl StorageHandle<StorageMap<K, V>>
instead ofimpl StorageMap<K, V>
directly. Also, note that theget
method now returns aStorageHandle
instead of the actual data. To get the actual data,read()
ortry_read()
should be called on the resulting handle. This is needed for multiple reasons including proper support for nested dynamic storage types. Rust also does the same, in a way (whereget
actually returns&
which happens to coerce to the real data in certain places).I still need to figure out how to do nested dynamic storage types with this approach. The stuff I have in
map_in_map_access
intest_projects/experimental_storage/src/main.sw
is just an attempt but not ergonomic at all of course.Checklist
Breaking*
orNew Feature
labels where relevant.