-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Assignment statements #2511
Conversation
497c90c
to
c1be5e4
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. =]
There was a problem hiding this comment.
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."
There was a problem hiding this comment.
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.
|
||
## Alternatives considered | ||
|
||
### Allow assignment as a subexpression |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
proposals/p2511.md
Outdated
In leads issue [#451](https://github.com/carbon-language/carbon-lang/issues/451) | ||
it was decided that we would initially not support chained assignment. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. :)
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
|
||
## Alternatives considered | ||
|
||
### Allow assignment as a subexpression |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall.
|
||
## Alternatives considered | ||
|
||
### Allow assignment as a subexpression |
There was a problem hiding this comment.
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.
proposals/p2511.md
Outdated
In leads issue [#451](https://github.com/carbon-language/carbon-lang/issues/451) | ||
it was decided that we would initially not support chained assignment. |
There was a problem hiding this comment.
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. :)
Co-authored-by: Jon Ross-Perkins <jperkins@google.com> Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
There was a problem hiding this 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 |
There was a problem hiding this comment.
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. =]
statements to the list of things that can appear in a block.
Add alternative considered for providing increment automatically whenever we can add 1.
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.
There was a problem hiding this 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
There was a problem hiding this 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...)
With this change `docs/design/lexical_conventions/symbolic_tokens.md` should now include all operators and symbols from accepted proposals.
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.