Sitelet https://github.com/starkware-libs/cairo/pull/10153
Skip to content

feat(lowering): support tuple element access via t.0 syntax - #10153

Merged
TomerStarkware merged 1 commit into
mainfrom
tomer/tuple-index-lowering
Jun 24, 2026
Merged

TomerStarkware merged 1 commit into
mainfrom
tomer/tuple-index-lowering

Conversation

@TomerStarkware

Copy link
Copy Markdown
Collaborator

Implements the lowering half of t.0 tuple-index member access, stacked on top of #10111 (the semantic half).

What

Generalizes the member-access lowering machinery from struct-only to any aggregate (struct or tuple):

  • Replace the concrete_struct_id-keyed Scattered with a TypeId-keyed one, keyed by MemberAccessKind instead of MemberId.
  • Add helpers in refs.rs that handle both structs and tuples uniformly:
    • aggregate_ty — the type an access reads a member of.
    • aggregate_members — ordered (MemberAccessKind, member_ty) pairs of an aggregate.
    • member_access_components — snapshot-wrapped member types + selected index.
  • Handle MemberAccessKind::Index in member-access lowering, ref-binding, and struct deconstruct/reconstruct (previously unreachable!/Unsupported).

Tests

  • Lowering test_data/tuple cases.
  • Corelib tuple_test.cairo: index read, nested access, assignment, nested assignment, ref arguments, and access through snapshots.

Note

Stacked on #10111 — review/merge that first. The base will need to be retargeted to main once #10111 lands.

🤖 Generated with Claude Code

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

@TomerStarkware
TomerStarkware requested a review from orizi June 23, 2026 08:58
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-semantic branch from 9d86e35 to b57a97e Compare June 23, 2026 11:41
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-lowering branch from 18033fe to 5d78973 Compare June 23, 2026 11:45

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 2 files and all commit messages, and made 1 comment.
Reviewable status: 2 of 6 files reviewed, 1 unresolved discussion (waiting on TomerStarkware).


crates/cairo-lang-lowering/src/test_data/tuple line 131 at r1 (raw file):

//! > ==========================================================================

//! > Test tuple index access - ref argument.

have a similar one - testing:

fn foo(ref t: (felt252, u8)) {
    t.1 = 3;
}

Code quote:

//! > Test tuple index access - ref argument.

@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-semantic branch from b57a97e to 18e7f93 Compare June 23, 2026 14:33
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-lowering branch from 5d78973 to 1bfc617 Compare June 23, 2026 14:39

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@TomerStarkware made 1 comment.
Reviewable status: 2 of 6 files reviewed, 1 unresolved discussion (waiting on orizi).


crates/cairo-lang-lowering/src/test_data/tuple line 131 at r1 (raw file):

Previously, orizi wrote…

have a similar one - testing:

fn foo(ref t: (felt252, u8)) {
    t.1 = 3;
}

Done.

@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-semantic branch from 18e7f93 to 68342c1 Compare June 23, 2026 14:41
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-lowering branch from 1bfc617 to 628cab4 Compare June 23, 2026 14:41

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@orizi reviewed 4 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-semantic branch from 68342c1 to 43cf84b Compare June 24, 2026 08:04
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-lowering branch from 628cab4 to fd1b04c Compare June 24, 2026 10:03

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 18 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-semantic branch from 43cf84b to 9cb2c32 Compare June 24, 2026 10:38
Base automatically changed from tomer/tuple-index-semantic to main June 24, 2026 11:01
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-lowering branch 2 times, most recently from 0770cbe to 4306e5f Compare June 24, 2026 11:44

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 17 files and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Adds positional tuple element access by index using dot notation (e.g. `t.0`,
`t.1`), resolved in the semantic model. Member access is generalized via a new
`MemberAccessKind` enum (`Struct{..}` | `Index{..}`) threaded through
`ExprMemberAccess`, `ExprVarMemberPath` and `usage::MemberPath`, so a member is
identified either by a struct member id or by a numeric tuple index.

The index must be a plain non-negative decimal literal (no base prefix or type
suffix); out-of-bounds and non-tuple accesses are reported. Lowering of tuple
index access is not yet implemented and currently reports an "Unsupported"
error; it will be added in a follow-up.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@TomerStarkware
TomerStarkware force-pushed the tomer/tuple-index-lowering branch from 4306e5f to 1a45667 Compare June 24, 2026 12:04

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@orizi reviewed 1 file and all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

@TomerStarkware
TomerStarkware added this pull request to the merge queue Jun 24, 2026
Merged via the queue into main with commit 434b8b2 Jun 24, 2026
53 checks passed
@TomerStarkware
TomerStarkware deleted the tomer/tuple-index-lowering branch June 24, 2026 13:59
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.

3 participants