Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tuples and tuple indexing #3646

Merged
merged 7 commits into from
Jan 31, 2024

Conversation

zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Jan 24, 2024

Add support for extracting elements of a tuple by their numerical index.

Also formally add the well-established basic syntactic and semantic rules for
tuples, for which we have had leads issues but no proposal, into the design.

@zygoloid zygoloid added proposal A proposal proposal draft Proposal in draft, not ready for review labels Jan 24, 2024
@zygoloid zygoloid force-pushed the proposal-tuple-indexing branch from aa58ded to 6665d4c Compare January 24, 2024 21:30
@zygoloid zygoloid marked this pull request as ready for review January 25, 2024 00:09
@zygoloid zygoloid changed the title Tuple indexing Tuples and tuple indexing Jan 25, 2024
@github-actions github-actions bot requested a review from KateGregory January 25, 2024 00:09
@github-actions github-actions bot added proposal rfc Proposal with request-for-comment sent out and removed proposal draft Proposal in draft, not ready for review labels Jan 25, 2024
@zygoloid zygoloid requested review from chandlerc and josh11b January 25, 2024 00:09
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Super excited to see this in a concrete proposal!

Some quick initial thoughts inline.

docs/design/expressions/member_access.md Outdated Show resolved Hide resolved
proposals/p3646.md Outdated Show resolved Hide resolved
proposals/p3646.md Outdated Show resolved Hide resolved
proposals/p3646.md Outdated Show resolved Hide resolved
@jonmeow
Copy link
Contributor

jonmeow commented Jan 25, 2024

To be sure:

let A: i32 = 1;
let Foo: auto = (41, 42);
// Invalid:
var b: i32 = Foo.A;
// Valid:
var c: i32 = Foo.(A);

Note, I'm not sure how I feel about this; the (1,).0 syntax will probably take some getting used to, it looks a lot like other syntaxes [and I'm super-familiar with Python syntax]. Just want to be sure my interpretation is correct.

@zygoloid
Copy link
Contributor Author

To be sure:

let A: i32 = 1;
let Foo: auto = (41, 42);
// Invalid:
var b: i32 = Foo.A;
// Valid:
var c: i32 = Foo.(A);

You would need template A:! i32 = 1;, because we need a template constant as the index, but otherwise yes.

@zygoloid zygoloid requested a review from chandlerc January 27, 2024 02:02
docs/design/lexical_conventions/README.md Outdated Show resolved Hide resolved
proposals/p3646.md Outdated Show resolved Hide resolved
Clarify disambiguation rule.
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Approving for leads based on our discussion and merging!

@chandlerc chandlerc added this pull request to the merge queue Jan 31, 2024
Merged via the queue into carbon-language:trunk with commit a1655b6 Jan 31, 2024
7 checks passed
- _expression_ `.` _integer-literal_
- _expression_ `->` _integer-literal_

The _expression_ is required to be of tuple type.
Copy link
Contributor

Choose a reason for hiding this comment

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

Presumably this only applies to the . form, and the expression in the -> form is required to be of type pointer to tuple?

There's a similar problem on line 878.

zygoloid added a commit that referenced this pull request Feb 1, 2024
Improve design changes from #3646 to integrate better into the overall description of member access design.
github-merge-queue bot pushed a commit that referenced this pull request Feb 3, 2024
…3679)

Improve the exposition of the design changes from #3646 to integrate
better into the overall description of member access design.

This fixes the incorrect description of the rules for `->` by instead
relying on the general rule that `->` is rewritten to use `*` and `.`
before any other processing is done, and generally makes
*integer-literal* names be less of a special case.
@zygoloid zygoloid deleted the proposal-tuple-indexing branch February 6, 2024 01:11
brymer-meneses added a commit to brymer-meneses/carbon-lang that referenced this pull request Aug 3, 2024
this changes the tuple index from `tuple[0]` to `tuple.0` in accordance
with the accepted propsal carbon-language#3646
brymer-meneses added a commit to brymer-meneses/carbon-lang that referenced this pull request Aug 15, 2024
this changes the tuple index from `tuple[0]` to `tuple.0` in accordance
with the accepted propsal carbon-language#3646
github-merge-queue bot pushed a commit that referenced this pull request Aug 15, 2024
This changes the tuple index from tuple[0] to tuple.0 in accordance with
the accepted propsal
#3646

I messed up syncing to trunk on my original PR
#4186, that's why I'm
starting on a blank state. Please let me know if I missed incorporating
a change from my prior PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal rfc Proposal with request-for-comment sent out proposal A proposal
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants