Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upRFC: Constants in array repeat expressions #2203
Conversation
Centril
added some commits
Oct 20, 2017
This comment has been minimized.
This comment has been minimized.
|
+1 from me. This looks like a small and intuitive change. I really like the application to array initializers. |
This comment has been minimized.
This comment has been minimized.
|
See also #1169. |
This comment has been minimized.
This comment has been minimized.
ExpHP
commented
Nov 7, 2017
•
This comment has been minimized.
This comment has been minimized.
|
@ExpHP Are they mutually exclusive? Can't both be done? |
scottmcm
added
the
T-lang
label
Nov 7, 2017
This comment has been minimized.
This comment has been minimized.
ExpHP
commented
Nov 7, 2017
|
@Centril all I can really say is I hope they are compatible! (I mean, who doesn't want to have their |
This comment has been minimized.
This comment has been minimized.
|
@ExpHP A workable rule for having your
Thus, this RFC should be forward compatible with |
This comment has been minimized.
This comment has been minimized.
ExpHP
commented
Nov 7, 2017
•
|
Hm, I'm not sure that the solution is that simple. That creates a potentially confusing scenario where two different expressions that evaluate to the same value could have different semantics when they appear inside an array repetition, as one could get On the other hand, upon reflection I'm not sure how attached I actually am to |
This comment has been minimized.
This comment has been minimized.
ExpHP
commented
Nov 7, 2017
|
A compelling argument from @Centril on IRC is that |
This comment has been minimized.
This comment has been minimized.
|
(summarizing what we discussed on IRC): As you put it I think If there is confusion as to whether the I also think |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Nov 8, 2017
•
This comment has been minimized.
This comment has been minimized.
|
@burdges You'd have to decide what to do when the iterator has less - panic seems the (only) reasonable option... But sure, it should be doable eventually =) |
This comment has been minimized.
This comment has been minimized.
burdges
commented
Nov 8, 2017
|
Yes, you might want |
This comment has been minimized.
This comment has been minimized.
|
@burdges Right. Do note that the result of such an expression is non-const unlike the result of |
This comment has been minimized.
This comment has been minimized.
|
Note for future self/implementers: moving the That makes |
This comment has been minimized.
This comment has been minimized.
|
@eddyb can you say a bit about how we would implement this? I haven't though deeply here but I am mildly worried that it will be hard for us to test if an expression "is const" -- i.e., do we just have to like run it through miri and see what happens? Put another way: it's one way to have a set of expressions that must be const and then check that they are. It's another to have something that might or might not be const and to impose different requirements depending on the result. Seems like it could interact poorly with type inference etc. Otherwise, I like the idea. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis No, we'd just run a special case for rvalue promotion, just like we do for borrowed temporaries and for SIMD shuffle indices. |
This comment has been minimized.
This comment has been minimized.
OK, so we'd be defining this not really for const expresions per se but for 'promotable expressions', which is (I think) not the same set, right? That is, we do some analysis to decide if something is promotable, and it is presumably a bit conservative, or could at least in theory be. Still, it seems like this case will be mildly harder to handle. For example, we can do rvalue promotion on the MIR level before borrow check runs, and hence borrowed temporaries having a longer lifetime just "falls out", but we can't do the same here -- well, I suppose we could wait to check the requirement that I am basically hoping we can avoid having to know whether something is constant during type check but instead have that be computed from the MIR alone. |
This comment has been minimized.
This comment has been minimized.
That's what I was saying in #2203 (comment) ("necessary to avoid
That last part is what I was saying ("so the current rule could just be "
In the I don't understand the part about "a longer lifetime", but I hope the above explanation suffices. |
Centril
added some commits
Feb 16, 2018
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis: I've updated and aligned the RFC according to @eddyb's ideas.. Hopefully that addresses your concerns =) |
This comment has been minimized.
This comment has been minimized.
|
I think @eddyb and I are aligned here in terms of how we want this to work in the compiler, so if they are satisfied I think I am. And reading over their comments, it makes sense. |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge I propose that we accept this RFC. The RFC expands |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 5, 2018
•
|
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
rfcbot
removed
the
proposed-final-comment-period
label
Mar 8, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 8, 2018
|
|
aturon
assigned
nikomatsakis
Mar 15, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Mar 18, 2018
|
The final comment period is now complete. |
Centril
referenced this pull request
Mar 18, 2018
Open
Tracking issue for RFC 2203, "Constants in array repeat expressions" #49147
Centril
merged commit f8a83dd
into
rust-lang:master
Mar 18, 2018
This comment has been minimized.
This comment has been minimized.
|
Huzzah! The RFC has been accepted. Tracking issue: rust-lang/rust#49147 |
Centril commentedNov 3, 2017
•
edited
Rendered.
Tracking issue
Relaxes the rules for repeat expressions,
[x; N]such thatxmay also beconst, in addition totypeof(x): Copy. The result of[x; N]wherexisconstis itself alsoconst.