Skip to content

Add aligned_and_dynamic_storage feature and imm6 arg to srw opcode#7565

Draft
ironcev wants to merge 6 commits intomasterfrom
ironcev/dynamic-storage-srw
Draft

Add aligned_and_dynamic_storage feature and imm6 arg to srw opcode#7565
ironcev wants to merge 6 commits intomasterfrom
ironcev/dynamic-storage-srw

Conversation

@ironcev
Copy link
Member

@ironcev ironcev commented Feb 25, 2026

Description

This PR is the first step in implementing dynamic storage support on compiler and std side, as described in the Aligned and dynamic storage RFC.

The PR:

  • adds the aligned_and_dynamic_storage experimental feature.
  • extends the srw opcode with an immediate offset.
  • extends the __state_read_word intrinsic with the offset.
  • extends the state_load_word IR operation with the offset.

Additionally, the PR:

Defining opcodes via the define_op_codes macros does not allow for customisations based on feature flags. Also, opcodes are modeled as enums in code generation. Changing the whole mechanics of opcode definition just to support two different srw opcodes does not pay off, especially because we do not expect srw to be used in real-life code. Thus, supporting only srw res is_set slot imm6 will be a breaking change not hidden behind a feature flag.

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 Feb 25, 2026
@cursor
Copy link

cursor bot commented Feb 25, 2026

PR Summary

High Risk
High risk because it changes core compiler/IR semantics for storage reads and makes srw’s asm syntax a breaking change, which can affect bytecode generation and existing contracts/tests. It also patches several Fuel dependencies to git branches/commits, increasing integration and build variability.

Overview
Adds a new experimental flag, aligned_and_dynamic_storage, and expands storage-word reads to support word offsets.

This changes the srw opcode to require an imm6 offset and threads that through parsing/printing, asm lowering, and bytecode emission, and extends the IR state_load_word operation (and __state_load_word intrinsic) to carry the offset, with verification that the offset fits in 6 bits.

Improves diagnostics by introducing CompileError::IntrinsicArgNotConstant and using it to enforce compile-time-constant immediates for __gtf’s tx_field_id and __state_load_word’s offset, updates docs/tests accordingly, and expands CI to run std/e2e suites with the new experimental feature enabled.

Written by Cursor Bugbot for commit d87fc83. This will update automatically on new commits. 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: parser Everything to do with the parser compiler: codegen Everything to do with IR->ASM, register allocation, etc. compiler: ui Mostly compiler messages breaking May cause existing user code to break. Requires a minor or major release. labels Feb 25, 2026
@ironcev
Copy link
Member Author

ironcev commented Feb 25, 2026

👍

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 25, 2026

Merging this PR will degrade performance by 18.43%

❌ 2 regressed benchmarks
✅ 23 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
code_lens 4.8 µs 5.9 µs -18.43%
tokens_for_program 533.3 µs 595.6 µs -10.47%

Comparing ironcev/dynamic-storage-srw (d87fc83) with master (56a6518)

Open in CodSpeed

@ironcev ironcev temporarily deployed to fuel-sway-bot March 6, 2026 05:37 — with GitHub Actions Inactive
Copy link

@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.

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Git branch patches in Cargo.toml must not be merged
    • Removed the accidental [patch.crates-io] git-branch overrides from Cargo.toml so dependencies resolve from published crates.io versions again.

Create PR

Or push these changes by commenting:

@cursor push 4fbc4cdd14
Preview (4fbc4cdd14)
diff --git a/Cargo.toml b/Cargo.toml
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -242,19 +242,4 @@
 vte = "0.13"
 walkdir = "2.3"
 whoami = "1.5"
-wiremock = "0.6"
-
-[patch.crates-io]
-fuel-core-client = { git = "https://github.com/FuelLabs/fuel-core", branch = "dento/dynamic-storage" }
-fuel-core-storage = { git = "https://github.com/FuelLabs/fuel-core", branch = "dento/dynamic-storage" }
-fuel-core-types = { git = "https://github.com/FuelLabs/fuel-core", branch = "dento/dynamic-storage" }
-
-fuel-asm = { git = "https://github.com/FuelLabs/fuel-vm" }
-fuel-crypto = { git = "https://github.com/FuelLabs/fuel-vm" }
-fuel-types = { git = "https://github.com/FuelLabs/fuel-vm" }
-fuel-tx = { git = "https://github.com/FuelLabs/fuel-vm" }
-fuel-vm = { git = "https://github.com/FuelLabs/fuel-vm" }
-
-fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "ironcev/clonable-isuseraccountvariables" }
-fuels-core = { git = "https://github.com/FuelLabs/fuels-rs", branch = "ironcev/clonable-isuseraccountvariables" }
-fuels-accounts = { git = "https://github.com/FuelLabs/fuels-rs", branch = "ironcev/clonable-isuseraccountvariables" }
\ No newline at end of file
+wiremock = "0.6"
\ No newline at end of file
This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.


fuels = { git = "https://github.com/FuelLabs/fuels-rs", branch = "ironcev/clonable-isuseraccountvariables" }
fuels-core = { git = "https://github.com/FuelLabs/fuels-rs", branch = "ironcev/clonable-isuseraccountvariables" }
fuels-accounts = { git = "https://github.com/FuelLabs/fuels-rs", branch = "ironcev/clonable-isuseraccountvariables" } No newline at end of file
Copy link

Choose a reason for hiding this comment

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

Git branch patches in Cargo.toml must not be merged

High Severity

The [patch.crates-io] section pins dependencies to unreleased git branches (fuel-core on dento/dynamic-storage, fuels-rs on ironcev/clonable-isuseraccountvariables, fuel-vm on main). If merged, the main branch would depend on development branches in external repos that could be force-pushed, deleted, or contain unstable code, breaking reproducible builds and potentially introducing regressions.

Fix in Cursor Fix in Web

@ironcev ironcev temporarily deployed to fuel-sway-bot March 8, 2026 08:05 — with GitHub Actions Inactive
@ironcev ironcev temporarily deployed to fuel-sway-bot March 9, 2026 08:03 — with GitHub Actions Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking May cause existing user code to break. Requires a minor or major release. 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: parser Everything to do with the parser compiler: ui Mostly compiler messages 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.

Confusing error message when using non-const tx_field_id in __gtf

1 participant