Skip to content

Implement dynamic storage for storage declaration and std#7598

Open
ironcev wants to merge 4 commits intomasterfrom
ironcev/dynamic-storage-std-and-storage-declaration
Open

Implement dynamic storage for storage declaration and std#7598
ironcev wants to merge 4 commits intomasterfrom
ironcev/dynamic-storage-std-and-storage-declaration

Conversation

@ironcev
Copy link
Copy Markdown
Member

@ironcev ironcev commented Apr 20, 2026

Description

This PR is a part of #7560 implementation and implements:

  • storage fields access compilation for dynamic storage.
  • dynamic storage for all the types and functions in the std::storage module, except the StorageVec.

In the storage_api, support for dynamic storage is added as the extension to the existing API based on quads. The reason is that we will need to support quad-based storage for backwards compatibility, for contracts that cannot migrate all the data, but still want to use, in parallel, the benefits of dynamic storage.

The existing API is marked as deprecated in favor of the new API in which the function suffix, either quads or slot(s), clearly indicates what kind of storage access the function performs.

Additionally, the existing clear API that returned boolean information about slot occupancy is split into two distinctive APIs: clear that only clears and doesn't return occupancy information, and clear_existed that returns boolean information about slot occupancy.

Introducing two variants for clearing is done for performance reasons. Returning the occupancy information in dynamic storage case requires more gas, and in many of the cases that information is not needed. Having two distinctive function allows developers to opt-in for the cost.

Additionally, the PR:

Planned next steps are:

  • Adding additional comprehensive test coverage. Some of the existing tests are adapted to test the new API and dynamic storage in this PR. Considering the impact of the change, unlike for other experimental feature, we want dynamic storage test to be included in all the tests that are currently testing storage.
  • Further optimizing writing to storage by supporting __state_store_slot in the StorageKey. __state_store_slot intrinsic is used in storage types, e.g. when storing slices or inserting into a StorageMap, but currently not in the StorageKey in general. There, __state_update_slot is always used. Supporting __state_store_slot in the StorageKey requires introduction of an additional abstraction that will allow us to express that a StorageKey points to a value that is guaranteed to be the only value in the slot.
  • Enabling SDK tests for StorageVecs that are temporarily disabled. This will be done when dynamic storage version of StorageVec is implemented.
  • Emitting <project>-storage_slots.json for dynamic storage and properly consuming them in the SDK. Until then, some of the tests are disabled and marked as TODO: (INIT-STORAGE).

Checklist

  • I have linked to any relevant issues.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have updated the documentation where relevant (API docs, the reference, and the Sway book).
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added (or requested a maintainer to add) the necessary Breaking* or New Feature labels where relevant.
  • I have done my best to ensure that my PR adheres to the Fuel Labs Code Review Standards.
  • I have requested a review from the relevant team or maintainers.

@ironcev ironcev self-assigned this Apr 20, 2026
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 20, 2026

PR Summary

High Risk
Touches core storage key generation, IR emission, and standard-library storage primitives, which can affect on-chain data layout/compatibility and correctness across many programs.

Overview
Implements experimental dynamic storage end-to-end: IR generation now builds StorageKey values differently when context.experimental.dynamic_storage is enabled (byte offsets + dynamic slots) and the typed storage access model is updated to carry a full storage_field_path for key derivation.

Extends std::storage with explicit APIs for quad-slot vs dynamic-slot operations (*_quads, *_slot(s), plus update_slot/append_slot) while deprecating the legacy read/write/clear/read_slice/write_slice APIs; updates StorageKey, StorageMap, StorageString, and StorageBytes to use the new primitives (with cfg-split behavior) and clarifies zero-sized “storage type” semantics.

Fixes purity analysis to treat StateUpdateSlot/supd/supi as write-only (not read+write), and updates/expands tests for the new storage intrinsics and CEI/purity expectations.

Reviewed by Cursor Bugbot for commit 271d72c. Bugbot is set up for automated code reviews on this repo. Configure here.

@ironcev ironcev added compiler General compiler. Should eventually become more specific as the issue is triaged compiler: ir IRgen and sway-ir including optimization passes compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: codegen Everything to do with IR->ASM, register allocation, etc. labels Apr 20, 2026
@ironcev
Copy link
Copy Markdown
Member Author

ironcev commented Apr 20, 2026

👍

Comment thread sway-lib-std/src/storage/storable_slice.sw
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 20, 2026

Merging this PR will not alter performance

✅ 25 untouched benchmarks


Comparing ironcev/dynamic-storage-std-and-storage-declaration (271d72c) with master (e12e611)

Open in CodSpeed

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 15d3ff5. Configure here.

Comment thread sway-lib-std/src/storage/storage_api.sw
@ironcev ironcev marked this pull request as ready for review April 21, 2026 08:48
@ironcev ironcev requested review from a team as code owners April 21, 2026 08:48
@ironcev ironcev requested review from Dentosal and bitzoic April 21, 2026 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

compiler: codegen Everything to do with IR->ASM, register allocation, etc. compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen compiler: ir IRgen and sway-ir including optimization passes compiler General compiler. Should eventually become more specific as the issue is triaged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix issues found during testing of the Iterator implementation for StorageVec

1 participant