Skip to content

Typed references (memory<T>, storage<T>, calldata<T>) #426

Backlog

Description

@micahscopes

Problem

The PR #424 type draft (e326f17) has alias, array, mapping, struct, function, and variant, but no kind for a typed reference to a value in a specific EVM data location (such as memory<string>, storage<uint256>, or calldata<bytes>).

In languages where references are first-class types (such as Core Solidity's memory<T>, storage<T>, and calldata<T>, or Solidity storage/memory reference parameters), a reference can appear inside function signatures, struct fields, or generic type arguments, not only as a top-level variable's pointer location. Today a compiler has to emit memory<string> as a one-field struct holding a raw word, which drops both the target type (string) and the location (memory) everywhere except the free-text label.

Sketch: type/complex/reference

Add "reference" to type/complex:

{
  "kind": "reference",
  "label": "memory<string>",
  "location": "memory",
  "contains": {
    "type": { "id": "t5" }
  }
}

Fields:

  • kind (required): "reference".
  • contains (required): { "type": ... }, the target type T.
  • location (optional): "storage", "memory", "calldata", "transient", "code", or "returndata" (omitted if the language does not fix the location in the type).
  • label, class, definition: same as other complex types.

This stays on the type side: it says what the value refers to. Where the reference word itself lives (for example on the stack) and how to follow it stay in pointers and the upcoming realization schema.

Questions

  1. Should location use the pointer location enum (storage, memory, calldata, transient, code, returndata) or be an open string?
  2. Should reference live in the type schema now, or wait for the realization schema?

Prototype

An end-to-end prototype (schema overlay + compiler output + JSON Schema validation) is available on micahscopes/solcore-rs@ethdebug-proposals-5.1-5.2 (overlay files in docs/ethdebug-proposals).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions