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

Assignment statements #2511

Merged
merged 23 commits into from
Jan 28, 2023

Conversation

zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Jan 4, 2023

Assignment is permitted only as a complete statement, not as a subexpression.
Assignment and compound assignment syntax follow C++ in all other respects.
Pre-increment is provided. Post-increment is not. Uses of all of these operators
are translated into calls to interface members.

@zygoloid zygoloid added proposal A proposal proposal draft Proposal in draft, not ready for review labels Jan 4, 2023
@zygoloid zygoloid force-pushed the proposal-assignment-statement branch from 497c90c to c1be5e4 Compare January 4, 2023 22:43
@zygoloid zygoloid marked this pull request as ready for review January 6, 2023 00:15
@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 6, 2023
docs/design/assignment.md Outdated Show resolved Hide resolved
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.

Some quick initial thoughts...

@@ -1223,25 +1222,6 @@ fn Foo() {
> - Proposal
> [#162: Basic Syntax](https://github.com/carbon-language/carbon-lang/pull/162)

### Assignment statements
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason to not keep at least a brief overview here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a very brief overview on line 253-260. I didn't feel like this section pulled its weight compared to that very brief overview and the detailed description in the separate page.

Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, I still would find it helpful, although its not a big deal. Maybe @josh11b has a thought one way or the other?

Assuming we don't keep it, I think then the section above or up one level should be adjusted to at least have a list of the different kinds of statements and links to their dedicated page. Otherwise, folks dropping in this section from a link to that section can't really navigate to all the relevant parts of the design.

Copy link
Contributor

Choose a reason for hiding this comment

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

@josh11b to maybe provide guidance on the right amount of content and structure here.

FWIW, the only thing I'm really looking for here is some reasonably discoverable link to the dedicated document. Totally happy with however much or little detail accompanies it here and whatever structure works best to incorporate it. =]

Copy link
Contributor

Choose a reason for hiding this comment

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

I do think there should be something inside the previous section about assignment statements if this section is going to be removed, like around the sentence starting with "Expressions."

Copy link
Contributor Author

@zygoloid zygoloid Jan 19, 2023

Choose a reason for hiding this comment

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

Thanks, that makes sense to me. Done.

docs/design/assignment.md Show resolved Hide resolved
docs/design/assignment.md Outdated Show resolved Hide resolved
proposals/p2511.md Outdated Show resolved Hide resolved
proposals/p2511.md Show resolved Hide resolved

## Alternatives considered

### Allow assignment as a subexpression
Copy link
Contributor

Choose a reason for hiding this comment

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

I will note particular concerns with this for increment and decrement. e.g., absl's flat_hash_map erase relies on postincrement as a subexpression. This could make particular challenges for migrating code, as either adding additional locals (since map.erase(it); ++it; is potentially different) or creating new APIs becomes a prerequisite for migration, likely reducing automated migration.

But it's not clear to me that you're looking for this kind of concern at this time, so I'll mostly suggest that if you're still considering this, "alternatives considered" indicates that it has been ruled out; "open questions" might be more appropriate? I think the difference here is whether the plan is "look more" versus "wait and see if there are too many complaints"; if it's the latter, I would agree with "alternatives considered", but would also want more consideration for how we migrate existing C++ code on the assumption that this isn't reconsidered.

Copy link
Contributor

@jonmeow jonmeow Jan 6, 2023

Choose a reason for hiding this comment

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

Thought: for migration, maybe we just transform C++ it++ into something like [&]() -> auto { var x: auto = it; ++it; return x; }() (something like that can become a general solution for subexpressions, although maybe not ideal for readers)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've added some brief discussion here giving the rationale for rejecting this alternative, which was previously missing, and also describing possibilities for getting the same effect (eg, for migration) and some potential limitations when doing so.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about having a distinct alternative for increment and decrement? It can I think be much more brief, but I feel like there are some unique aspects to those, both in terms of the impact and potentially more limited pitfalls. And so it might be clearer to treat those separately.

Minor point either way though -- there is a fundamental tradeoff here in that this will create some unknown amount of migration friction, and it'll be experience with tooling and actual migrations that teach us whether we end up want to revisit parts of this or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be explicit, I'm fine with the resolution here, although apprehensive about migration costs.

docs/design/assignment.md Show resolved Hide resolved
docs/design/assignment.md Outdated Show resolved Hide resolved
Comment on lines 157 to 158
In leads issue [#451](https://github.com/carbon-language/carbon-lang/issues/451)
it was decided that we would initially not support chained assignment.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should the rationale be provided here so that leads issues aren't a canonical reference for decisions?

Perhaps more importantly, what was the rationale? What trade-offs did the leads consider? On a skim, I see a decision, but without further context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added some words, but honestly I'm not sure we had much rationale here other than that we didn't see sufficient motivation to add this feature compared to the cost.

Copy link
Contributor

Choose a reason for hiding this comment

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

A lack of justification is still important to document. :)

proposals/p2511.md Outdated Show resolved Hide resolved
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.

Just noting a few things here orthogonal to the naming discussion...

@@ -1223,25 +1222,6 @@ fn Foo() {
> - Proposal
> [#162: Basic Syntax](https://github.com/carbon-language/carbon-lang/pull/162)

### Assignment statements
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, I still would find it helpful, although its not a big deal. Maybe @josh11b has a thought one way or the other?

Assuming we don't keep it, I think then the section above or up one level should be adjusted to at least have a list of the different kinds of statements and links to their dedicated page. Otherwise, folks dropping in this section from a link to that section can't really navigate to all the relevant parts of the design.

proposals/p2511.md Outdated Show resolved Hide resolved

## Alternatives considered

### Allow assignment as a subexpression
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about having a distinct alternative for increment and decrement? It can I think be much more brief, but I feel like there are some unique aspects to those, both in terms of the impact and potentially more limited pitfalls. And so it might be clearer to treat those separately.

Minor point either way though -- there is a fundamental tradeoff here in that this will create some unknown amount of migration friction, and it'll be experience with tooling and actual migrations that teach us whether we end up want to revisit parts of this or not.

Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

LGTM overall.

proposals/p2511.md Outdated Show resolved Hide resolved

## Alternatives considered

### Allow assignment as a subexpression
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be explicit, I'm fine with the resolution here, although apprehensive about migration costs.

Comment on lines 157 to 158
In leads issue [#451](https://github.com/carbon-language/carbon-lang/issues/451)
it was decided that we would initially not support chained assignment.
Copy link
Contributor

Choose a reason for hiding this comment

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

A lack of justification is still important to document. :)

zygoloid and others added 4 commits January 17, 2023 14:13
Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
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.

Definitely converging. Mostly suggesting some added information to cover a bit of discussion that we had around extensibility of increment and decrement to try and more fully document the principles that underpin the design and the rationale for those.

I also think we need at least some fixes to the top level overview.

@@ -1223,25 +1222,6 @@ fn Foo() {
> - Proposal
> [#162: Basic Syntax](https://github.com/carbon-language/carbon-lang/pull/162)

### Assignment statements
Copy link
Contributor

Choose a reason for hiding this comment

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

@josh11b to maybe provide guidance on the right amount of content and structure here.

FWIW, the only thing I'm really looking for here is some reasonably discoverable link to the dedicated document. Totally happy with however much or little detail accompanies it here and whatever structure works best to incorporate it. =]

docs/design/assignment.md Show resolved Hide resolved
proposals/p2511.md Show resolved Hide resolved
statements to the list of things that can appear in a block.
Add alternative considered for providing increment automatically
whenever we can add 1.
jonmeow pushed a commit that referenced this pull request Jan 21, 2023
Add support for user-defined assignment, as well as compound assignment and increment, following the design direction in pending proposal #2511.

Some of this isn't fully testable yet: because explorer doesn't properly support `impl` specialization, the blanket `impl`s in the prelude prevent types from customizing assignment.
@chandlerc chandlerc self-requested a review January 27, 2023 01:12
@zygoloid zygoloid requested a review from jonmeow January 27, 2023 01:19
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.

LGTM! I spotted a tiny wording nit just as I was skimming it, but seems trivial to fix forward if the suggestion isn't quite right. =D

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.

(sorry for not including this tweak...)

docs/design/assignment.md Outdated Show resolved Hide resolved
docs/design/assignment.md Outdated Show resolved Hide resolved
@zygoloid zygoloid merged commit a89aba2 into carbon-language:trunk Jan 28, 2023
josh11b added a commit to josh11b/carbon-lang that referenced this pull request Jun 2, 2023
zygoloid pushed a commit that referenced this pull request Jun 2, 2023
With this change `docs/design/lexical_conventions/symbolic_tokens.md` should now include all operators and symbols from accepted proposals.
@zygoloid zygoloid deleted the proposal-assignment-statement branch October 4, 2023 23:27
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.

None yet

6 participants