-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Reconsider the design of StorageMap
and StorageVec
to avoid the use of __get_storage_key
(while staying backward compatible)
#3202
Comments
StorageMap
and StorageVec
to avoid the use of __get_storage_key
StorageMap
and StorageVec
to avoid the use of __get_storage_key
(while staying backward compatible)
@mitchmindtree touched on this subject a bit here #2585 |
I like this -- the only handwavy part we need to sort out is the "extract the storage key from the reference". I suppose that'd be through |
I think the reference itself will contain the key(s) needed depending on how we spec it out. Basically, the key is now an argument so that if insert is not inlined, we don't have any issues. |
…` 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 <[email protected]>
When storage references get implemented, we should move away from using
__get_storage_key
. This was a hacky way to getStorageMap
working but now that we're about to have storage references, I think we can do better.Currently, the method insert looks like:
and is called using
storage.map.insert(key, value)
, which is equivalent to~StorageMap::insert(storage.map, key, value)
.When we have storage references, we can imagine something like:
and the syntax for calling
insert
would remain the same:storage.map.insert(key, value)
and would be equivalent to~StorageMap::insert(storage.map.ref(), key, value)
.Of course, a lot of details and the syntax have to be worked out, but I think this is a much more robust way of implementing
StorageMap
that does not actually break existing code. This also enables passing storage maps around to functions and also writing:One more motivation for the above is that I actually have doubts about the intrinsic
__get_storage_key
if the method using it (likeinsert()
orget()
) is not inlined 🤔Note
Equivalent Rust code for a simple struct would look like
The text was updated successfully, but these errors were encountered: