Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAllow panicking in constants #2345
Conversation
Centril
added
the
T-lang
label
Feb 22, 2018
This comment has been minimized.
This comment has been minimized.
|
This seems like a good idea to me. Supporting panic from compile-time computation as a compile-time error makes perfect sense, and I'd anticipate many excellent error diagnostics on that basis. I do want to see something along the lines of the last item in the unresolved section. Whether |
This comment has been minimized.
This comment has been minimized.
|
I think that making
|
This comment has been minimized.
This comment has been minimized.
|
While I do support panicking in const fn, I'm uneasy with this potential direction mentioned in the unresolved question:
This sounds like eventually the entire We need the I don't know of a better solution. Maybe we could add a |
This comment has been minimized.
This comment has been minimized.
|
Well.. we could infer constness for private functions, which would make a lot of things easier. We could also consider some future Anyway, this is a very much orthogonal topic and we should probably be disussing it in the internals forum instead of here |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@oli-obk Having all of these @Centril Effect polymorphism, alas, is only a solution to abstracting over things. That is, if you might want to say things like "this |
This comment has been minimized.
This comment has been minimized.
|
@glaebhoerl while all of these RFCs increase the possible code that can be evaluated, this one in particular does not add anything new except nicer errors. The only one that allows real new features is the constant if RFC. Everything else was already possible via const fn. The particular concern about marking everything const fn should be part of the const fn stabilization and has already been heavily discussed in the tracking issue rust-lang/rust#24111 |
This comment has been minimized.
This comment has been minimized.
This wouldn't be too different from |
This comment has been minimized.
This comment has been minimized.
|
Also I think that the big thing to point out, whether or not you agree with If you're in favour of const inference then this RFC should be an obvious yes imho. |
This comment has been minimized.
This comment has been minimized.
daboross
commented
Mar 14, 2018
•
Would this change the following from a runtime to a compile-time error, then? fn main() {
Err::<(), ()>(()).unwrap();
}If so, is that a breaking change - if someone does really want to panic at runtime? I like this change, but this aspect seems concerning. It seems to make adding |
This comment has been minimized.
This comment has been minimized.
|
@daboross I mean, that example is enough to warrant a crater run, but IMHO if a logic error is caught at compile time instead of runtime, that's just helping the programmer out. |
This comment has been minimized.
This comment has been minimized.
No. That just becomes a lint. |
This comment has been minimized.
This comment has been minimized.
daboross
commented
Mar 14, 2018
|
@clarcharr it's helping the programmer for actively developed applications and libraries, but not everything has a maintainer. There are situations even today when small backwards-incompatible coherence changes break existing unmaintained libraries (AndyBarron/app-dirs-rs#28 is my latest example). This would be on a much larger scale, though. If we adopt What if there's some bad @oli-obk Alright, that sounds reasonable to me. Does this mean we make all compile-time panics lints which then forward the panic to runtime? |
This comment has been minimized.
This comment has been minimized.
It is only a compile time error if you call it in a const context. Since you can't call non const fns in const contexts, you can't get a breaking change this way. Const context being array lengths, static initializers or outright constants |
This comment has been minimized.
This comment has been minimized.
daboross
commented
Mar 14, 2018
•
|
@oli-obk ahh, that makes a lot more sense, thanks! I guess I was going on the assumption that the compiler would unroll / execute any |
This comment has been minimized.
This comment has been minimized.
|
You can't execute |
This comment has been minimized.
This comment has been minimized.
This is similar to |
This comment has been minimized.
This comment has been minimized.
Fair enough; Specifying what effects a particular function has could be done more ergonomically with effect aliases (type aliases but for the effect kind), like so: effect foo = const + async + total;
foo fn bar(..) { // modulo syntax bikeshed and making it unambiguous.
} |
Ixrec
referenced this pull request
Apr 28, 2018
Open
Add feature gated and unstable const constructor for nightly? #5
This comment has been minimized.
This comment has been minimized.
|
Summary of comment thread: As far as I can tell, all commenters seem to be in favor of this RFC as written. There was some discussion about whether to expand the scope of the RFC to also change
I do have one relatively small concern with the text itself, but my concern is pretty slight, so I think I will propose merging this via the rfcbot and then mark my concern formally there (in part to ensure that it does not get completely overlooked). |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge |
pnkfelix
closed this
May 14, 2018
pnkfelix
reopened this
May 14, 2018
This comment has been minimized.
This comment has been minimized.
|
(argh hit the wrong button.) |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot fcp merge |
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
May 14, 2018
•
|
Team member @pnkfelix has proposed to merge this. The next step is review by the rest of the tagged teams: Concerns:
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
added
proposed-final-comment-period
disposition-merge
labels
May 14, 2018
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
May 14, 2018
This comment has been minimized.
This comment has been minimized.
|
@pnkfelix I assume the support functions to be made |
This comment has been minimized.
This comment has been minimized.
|
@eddyb Okay, my assumption was wrong in that I thought Plus, I didn't know about the The bits of machinery you list mean that its probably relatively easy to implement something that behaves like the second change I outlined: namely, for all practical purposes, in stable code const-eval will be restricted to invocations of (I still think the RFC could spell this out, but its not as vital since I am probably wrong about the intention, in that the change to the API that const-eval presents is just to add |
This comment has been minimized.
This comment has been minimized.
|
@rfcbot resolved feature-scoped-to-macros-or-to-their-expansion |
rfcbot
added
proposed-final-comment-period
disposition-merge
labels
May 15, 2018
rfcbot
added
final-comment-period
and removed
proposed-final-comment-period
labels
Jun 22, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jun 22, 2018
|
|
This comment has been minimized.
This comment has been minimized.
tkadur
commented
Jun 28, 2018
|
I'm jumping in pretty late here, but I'm not sure how I feel about the compile time versions of As an aside, it would give us the option to allow |
This comment has been minimized.
This comment has been minimized.
|
@tkadur note that if you write I think a goal should be to minimize the difference in experience across |
This comment has been minimized.
This comment has been minimized.
tkadur
commented
Jun 29, 2018
This is a good point - makes sense to me. |
This comment has been minimized.
This comment has been minimized.
|
Note that you'll almost never use |
rfcbot
added
finished-final-comment-period
and removed
final-comment-period
labels
Jul 2, 2018
This comment has been minimized.
This comment has been minimized.
rfcbot
commented
Jul 2, 2018
|
The final comment period, with a disposition to merge, as per the review above, is now complete. |
Centril
referenced this pull request
Jul 2, 2018
Open
Tracking issue for RFC 2345, "Allow panicking in constants" #51999
Centril
merged commit 5a44ed0
into
rust-lang:master
Jul 2, 2018
This comment has been minimized.
This comment has been minimized.
|
Huzzah! This RFC is merged! Tracking issue: rust-lang/rust#51999 |
oli-obk commentedFeb 22, 2018
•
edited by Centril
Rendered
Tracking issue
DON'T PANIC! "in large, friendly letters"
cc @pnkfelix (#1383)