Skip to content

Implement dynamic storage based StorageVec#7614

Draft
ironcev wants to merge 1 commit intomasterfrom
ironcev/dynamic-storage-storage-vec
Draft

Implement dynamic storage based StorageVec#7614
ironcev wants to merge 1 commit intomasterfrom
ironcev/dynamic-storage-storage-vec

Conversation

@ironcev
Copy link
Copy Markdown
Member

@ironcev ironcev commented Apr 30, 2026

Description

This PR is an additional step in implementing #7560. It implements StorageVec<V> for dynamic storage.

Additionally the PR:

  • adds comprehensive test coverage for StorageVec in the form of in-language tests. Existing SDK harness tests are deleted in favor of new in-language tests. This is aligned with the agreed strategy to migrate SDK harness tests to in-language tests.
  • closes StorageVec::insert() does not work with nested storage types #6040 by properly documenting the semantics of zero-sized types in relation to storage. Every StorageVec<V> methods that does not work with zero-sized types, which are assumed to be nested storage types, is now documented for limitations.

When running in-language tests using forc test on the whole workspace two blocking issues occur:

Workarounds for those issues are commented in code and linked to the issues.

Additional in-language tests for other storage types will be added in a separate PR.

Breaking Changes

Existing StorageVec<V> methods in the quads-based implementation that cannot be used with nested storage types, e.g., swap now consistently reverts if V is a nested storage type.

Previously, those methods:

  • sometimes always reverted,
  • sometimes reverted in specific paths,
  • sometimes executed with undefined behavior.

Consistently reverting can be a breaking change if some existing code called these methods and they were not reverting. Note that such calls represent invalid usage of the storage API (although it was up to now not clearly documented as such) and reverting will actually point to bugs in existing callers code.

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 30, 2026
@ironcev ironcev deployed to fuel-sway-bot April 30, 2026 10:37 — with GitHub Actions Active
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 30, 2026

PR Summary

High Risk
Touches core stdlib storage semantics and introduces a new dynamic-storage StorageVec implementation with behavior changes for nested/zero-sized types, which can affect contract storage correctness and compatibility. Also changes how CI executes in-language tests, which could mask or surface failures differently if the runner logic is wrong.

Overview
Implements StorageVec<V> for experimental_dynamic_storage, storing non-zero-sized vectors as a single dynamic slot and treating zero-sized V as nested storage types with length tracked separately; adds a dedicated StorageVecError/OutOfBounds error model and updates many methods to consistently reject unsupported nested-type operations (or document/encode the special-case behaviors like pop/resize).

Extends the raw slice API with raw_slice::into_parts() to support the new storage implementation, and makes small doc/wording fixes across storage APIs.

Replaces workspace-level in-language test execution with a per-project runner (run_in_language_tests.sh) and updates CI and just performance commands accordingly; the in-language tests workspace Forc.toml is disabled as a workaround. Adds/renames a large suite of in-language contract tests for StorageVec behavior (and updates related snapshots), plus a few storage-instruction/intrinsics test adjustments (including new zero-length update coverage).

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

@ironcev ironcev added the lib: std Standard library label Apr 30, 2026
@ironcev
Copy link
Copy Markdown
Member Author

ironcev commented Apr 30, 2026

👍

@ironcev ironcev added the breaking May cause existing user code to break. Requires a minor or major release. label Apr 30, 2026
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 00ff960. Configure here.

while i < NUM_OF_ELEMENTS {
expected_after_insertions.push(expected_values.get(i).unwrap());
i += 1;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test verification uses wrong split point for expected sequence

Low Severity

The expected sequence construction in assert_insert_impl uses middle_index (which is an index into the vector after front insertion) as a split point into expected_values. After the front insert, original elements are shifted right by one, so vec[6] holds ev[5]. The loop while i < middle_index pushes ev[0] through ev[5], then inserted_middle, then ev[6] onward. But the actual vector has inserted_middle at position 6 and ev[5] at position 7. The test passes only because inserted_middle = expected_values.get(NUM_OF_ELEMENTS / 2) = ev[5], which is identical to the displaced element. The correct split should be middle_index - 1 elements from expected_values before inserted_middle.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 00ff960. Configure here.

@ironcev ironcev changed the title Implement dynamic storage StorageVec Implement dynamic storage based StorageVec Apr 30, 2026
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. lib: std Standard library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StorageVec::insert() does not work with nested storage types

1 participant