feat(semantic): support tuple element access via t.0 syntax - #10111
Conversation
orizi
left a comment
There was a problem hiding this comment.
@orizi made 1 comment.
Reviewable status: 0 of 17 files reviewed, 1 unresolved discussion (waiting on TomerStarkware).
crates/cairo-lang-semantic/src/expr/compute.rs line 3776 at r1 (raw file):
/// Computes the semantic model of a tuple-index access expression (e.g. "expr.0"). fn tuple_index_access_expr<'db>(
why can't this be fully part of the member access expr handling?
0aa64af to
af4bfbb
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware made 1 comment.
Reviewable status: 0 of 18 files reviewed, 1 unresolved discussion (waiting on orizi).
crates/cairo-lang-semantic/src/expr/compute.rs line 3776 at r1 (raw file):
Previously, orizi wrote…
why can't this be fully part of the member access expr handling?
Done.
af4bfbb to
9d86e35
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 14 files and all commit messages, made 1 comment, and resolved 1 discussion.
Reviewable status: 14 of 18 files reviewed, 1 unresolved discussion (waiting on TomerStarkware).
crates/cairo-lang-semantic/src/expr/compute.rs line 4191 at r3 (raw file):
TypeLongId::Tuple(tys) => tuple_index_members(ctx.db, &tys, *explored_derefs), _ => continue, };
make the helpers return iterators - and avoid the extra map allocations.
Code quote:
let (_, long_ty) = finalized_snapshot_peeled_ty(ctx, deref_info.target_ty, stable_ptr)?;
let new_members = match long_ty {
TypeLongId::Concrete(ConcreteTypeId::Struct(concrete_struct_id)) => {
let members = ctx.db.concrete_struct_members(concrete_struct_id)?;
struct_enriched_members(concrete_struct_id, members, *explored_derefs)
}
TypeLongId::Tuple(tys) => tuple_index_members(ctx.db, &tys, *explored_derefs),
_ => continue,
};9d86e35 to
b57a97e
Compare
Implements the lowering half of `t.0` tuple-index member access, building on the semantic support (#10111). Generalizes the member-access machinery from struct-only to any aggregate (struct or tuple): - Replace `concrete_struct_id`-keyed scattering with a `TypeId`-keyed `Scattered`, keyed by `MemberAccessKind` instead of `MemberId`. - Add `aggregate_ty`, `aggregate_members`, and `member_access_components` helpers in `refs.rs` that handle both structs and tuples uniformly. - Handle `MemberAccessKind::Index` in member-access lowering, ref-binding, and struct deconstruct/reconstruct. Adds lowering test_data and corelib tests covering tuple index read, nested access, assignment, `ref` arguments, and access through snapshots.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 3 files and all commit messages, made 2 comments, and resolved 1 discussion.
Reviewable status: 16 of 18 files reviewed, 2 unresolved discussions (waiting on TomerStarkware).
crates/cairo-lang-semantic/src/expr/compute.rs line 4195 at r4 (raw file):
// Insert member if there is not already a member with the same name. enriched.entry(name).or_insert(value); }
rather not use the Either
Suggestion:
match &long_ty {
TypeLongId::Concrete(ConcreteTypeId::Struct(concrete_struct_id)) => {
let members = ctx.db.concrete_struct_members(*concrete_struct_id)?;
for (name, value) in struct_enriched_members(
*concrete_struct_id,
members,
*explored_derefs,
)) {
enriched.entry(name).or_insert(value);
}
}
TypeLongId::Tuple(tys) => {
for (name, value) in tuple_index_members(ctx.db, tys, *explored_derefs) {
enriched.entry(name).or_insert(value);
}
}
_ => continue,
};crates/cairo-lang-semantic/src/resolve/mod.rs line 165 at r4 (raw file):
/// How the member is accessed: a struct member id or a tuple index. pub kind: MemberAccessKind<'db>, /// The (unsnapshotted) type of the member.
unsnapshotted?
Code quote:
/// The (unsnapshotted) type of the member.b57a97e to
18e7f93
Compare
Implements the lowering half of `t.0` tuple-index member access, building on the semantic support (#10111). Generalizes the member-access machinery from struct-only to any aggregate (struct or tuple): - Replace `concrete_struct_id`-keyed scattering with a `TypeId`-keyed `Scattered`, keyed by `MemberAccessKind` instead of `MemberId`. - Add `aggregate_ty`, `aggregate_members`, and `member_access_components` helpers in `refs.rs` that handle both structs and tuples uniformly. - Handle `MemberAccessKind::Index` in member-access lowering, ref-binding, and struct deconstruct/reconstruct. Adds lowering test_data and corelib tests covering tuple index read, nested access, assignment, `ref` arguments, and access through snapshots.
18e7f93 to
68342c1
Compare
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware made 3 comments.
Reviewable status: 15 of 18 files reviewed, 2 unresolved discussions (waiting on orizi).
crates/cairo-lang-semantic/src/expr/compute.rs line 4191 at r3 (raw file):
Previously, orizi wrote…
make the helpers return iterators - and avoid the extra map allocations.
Done.
crates/cairo-lang-semantic/src/expr/compute.rs line 4195 at r4 (raw file):
Previously, orizi wrote…
rather not use the Either
Done.
crates/cairo-lang-semantic/src/resolve/mod.rs line 165 at r4 (raw file):
Previously, orizi wrote…
unsnapshotted?
removed
Implements the lowering half of `t.0` tuple-index member access, building on the semantic support (#10111). Generalizes the member-access machinery from struct-only to any aggregate (struct or tuple): - Replace `concrete_struct_id`-keyed scattering with a `TypeId`-keyed `Scattered`, keyed by `MemberAccessKind` instead of `MemberId`. - Add `aggregate_ty`, `aggregate_members`, and `member_access_components` helpers in `refs.rs` that handle both structs and tuples uniformly. - Handle `MemberAccessKind::Index` in member-access lowering, ref-binding, and struct deconstruct/reconstruct. Adds lowering test_data and corelib tests covering tuple index read, nested access, assignment, `ref` arguments, and access through snapshots.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 3 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).
68342c1 to
43cf84b
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 8 files and all commit messages.
Reviewable status: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>
43cf84b to
9cb2c32
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 2 files and all commit messages.
Reviewable status: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 newMemberAccessKindenum (Struct{..}|Index{..}) threaded throughExprMemberAccess,ExprVarMemberPathandusage::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.