feat(semantic): support tuple member access via v.0 syntax (#7608)#9884
Conversation
Draft
5 tasks
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
5 tasks
5e73005 to
3574eae
Compare
e0ec9a0 to
22810ca
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Replaces the
concrete_struct_id+memberfields onExprMemberAccesswith a unifiedtype_member: TypeMemberfield, and extends member access expressions to support tuple element access via numeric literal syntax (e.g.,t.0,t.1).In
dot_expr, a newast::Expr::Literalbranch parses the numeric index, converts it to a member name string, and routes it through the refactoredmember_access_expr_by_name. Themember_access_exprfunction is split into a name-resolution entry point and a newmember_access_expr_by_namehelper that handles both struct members (TypeMemberKind::StructMember) and tuple elements (TypeMemberKind::TupleElement).The lowering and constant evaluation layers are updated to dispatch on
TypeMemberKind— struct members look up the concrete struct's member list to find the index, while tuple elements use the index directly fromTypeMemberKind::TupleElement.TypeMember,TypeMemberKind, andVisibilityderiveHashto satisfy the new usage in salsa rewrites, andTypeMember/TypeMemberKindare added to theadd_expr_rewrites!macro.Type of change
Please check one:
Why is this change needed?
Tuple element access via dot notation (e.g.,
t.0) was previously unsupported — thedot_exprhandler would fall through to anInvalidMemberExpressionerror for any non-path, non-call RHS. TheExprMemberAccessnode also hard-coded a struct-specific representation (concrete_struct_id+member), making it impossible to represent tuple element access uniformly in the semantic model.What was the behavior or documentation before?
Writing
t.0on a tuple would produce anInvalidMemberExpressiondiagnostic. Struct member access inExprMemberAccesswas represented with aConcreteStructIdandMemberIddirectly on the node.What is the behavior or documentation after?
Tuple element access via numeric literal syntax (e.g.,
t.0,t.1) is now valid and produces aMemberAccessexpression withTypeMemberKind::TupleElement(idx). Struct member access continues to work as before viaTypeMemberKind::StructMember(member_id). Both cases are handled uniformly throughExprMemberAccess.type_member.Related issue or discussion (if any)
Resolves the TODO previously noted as
#7608in the code (// TODO(#7608): handle TypeMemberKind::TupleElement here.).