Skip to content

Support struct values in storage maps - #1494

Open
g-r-a-n-t wants to merge 8 commits into
argotorg:masterfrom
g-r-a-n-t:storage-map-struct-values
Open

Support struct values in storage maps#1494
g-r-a-n-t wants to merge 8 commits into
argotorg:masterfrom
g-r-a-n-t:storage-map-struct-values

Conversation

@g-r-a-n-t

@g-r-a-n-t g-r-a-n-t commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Adds typed pointers to StorageMap entries, allowing maps to store and access multi-word values such as structs without requiring those values to implement WordRepr.

Pointer-based access uses the normal storage effect model. Existing get and set APIs remain available for single-word WordRepr values.

API

  • Adds StorageMap::ptr, returning a read-only StoragePtr<V>.
  • Adds StorageMap::mut_ptr, returning a mutable StorageMutPtr<V>.
  • Requires mutable access to the map before creating a mutable entry pointer.
  • Implements the standard effect-handle and effect-reference traits for these pointers.
  • Keeps StorageMap::get and StorageMap::set restricted to V: WordRepr.

Storage layout

The map entry hash is treated as the base storage slot for the value. Aggregate fields are projected relative to that slot using the compiler's storage layout.

This PR also defines consistent packed storage layout for nominal structs:

  • Adjacent scalar fields smaller than one word may share a storage slot.
  • Writes to shared slots use read-modify-write operations so neighboring fields are preserved.
  • Nested structs use their recursively computed packed storage span.
  • Tuples, arrays, and other aggregate transitions remain storage boundaries.
  • Signed and narrow scalar values are stored in their canonical bit representation.

HIR layout reporting and MIR/codegen now use the same shared field-layout planner. The same rules therefore apply to both ordinary contract struct fields and structs reached through storage-map entry pointers. Memory and ABI layouts are unchanged.

Example

struct Position {
  owner: u256,
  collateral: u256,
  debt: u256,
}

struct Store {
   positions: StorageMap<u256, Position>,
}

let position = store.positions.ptr(key: account)
let mut position = store.positions.mut_ptr(key: account)

The read-only pointer can inspect the entry, while the mutable pointer can replace the value or update individual fields through normal storage-provider semantics.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5afc5c8632

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ingots/std/src/evm/storage_map.fe Outdated
@g-r-a-n-t
g-r-a-n-t marked this pull request as draft June 25, 2026 15:40
@g-r-a-n-t
g-r-a-n-t marked this pull request as ready for review July 1, 2026 23:32

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 61e216b0e3

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ingots/std/src/evm/storage_map.fe Outdated
@g-r-a-n-t
g-r-a-n-t force-pushed the storage-map-struct-values branch from 24a36a4 to ed1f67f Compare July 7, 2026 17:28
@g-r-a-n-t
g-r-a-n-t force-pushed the storage-map-struct-values branch from ed1f67f to 7427099 Compare July 15, 2026 21:16
@g-r-a-n-t g-r-a-n-t changed the title stdlib: expose storage map value pointers Support struct values in storage maps Jul 15, 2026
@g-r-a-n-t

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 74270991ee

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/codegen/src/sonatina/lower_runtime.rs
@g-r-a-n-t
g-r-a-n-t force-pushed the storage-map-struct-values branch from 42c8cb2 to 2f448f0 Compare July 27, 2026 15:55
@g-r-a-n-t

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2f448f0eda

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread crates/codegen/src/sonatina/lower_runtime.rs Outdated
@g-r-a-n-t

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 13b15271c2

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread ingots/std/src/evm/storage_map.fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant