-
Notifications
You must be signed in to change notification settings - Fork 292
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
Announce if
and match
in constants on nightly
#461
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @nikomatsakis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This change will allow a great number of standard library functions to be | ||
made `const`. If you like, you can help with this process! There's a [list of | ||
numeric functions][const-int] that can be constified with little effort. Be | ||
aware that things move slowly in the standard library, and it's always best |
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 think we can be quite liberal with accepting const fn
-ification on nightly -- stabilizing is a different matter tho. I think it's in our interest to use the standard library as a proving ground for the feature. So I think we should be more encouraging than "slowly" suggests wrt. unstable stuff.
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.
Constification PRs have been closed because they don't have a motivating use case. I agree with your position on this, but is there consensus? Regardless, "slowly" is unnecessarily pejorative, and I'll change 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 believe in the case you mention, it's more the case that we know that it is not useful in const contexts yet rather than requiring an elaborate justification. Here I think "proving out the language feature" is a useful justification in-and-of-itself. The libs team will have an opportunity to reject stabilization and revert things (if e.g. it incurred hacks), so I think we should be good. My interest here is to have a light-weight process and avoid bureaucracy.
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.
Okay, I've removed that sentence entirely. Do we want to suggest including a concrete example? For many functions that will be overkill.
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.
Maybe we could give an example of how you constify something by pointing to some merged PR which introduced rustc_const_unstable
?
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.
How about rust-lang/rust#63123?
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.
Yeah that works; rust-lang/rust#61635 is another good example.
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 used rust-lang/rust#61635 as the example and explicitly mention rustc_const_unstable
.
Co-Authored-By: lzutao <taolzu@gmail.com>
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
183f13e
to
cbbfaa6
Compare
`debug_assert_ne`) remain forbidden, since they need to call `Debug::fmt` on | ||
their arguments. | ||
|
||
Also forbidden are looping constructs, `while`, `for`, and `loop`, which will |
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.
Maybe also note that for loops need trait methods, too and that you can emulate loops with recursion as shown above
|
||
## What took you so long? | ||
|
||
[Miri], which rust uses under the hood for compile-time function evaluation, |
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.
This is not quite right. Both const eval and miri use the miri engine. The miri engine is essentially a VM that runs MIR as "bytecode". But it's right in the sense that miri showcases what you can do when you take off the safety padding.
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.
So change "Miri" to "miri engine"? Also, how do we capitalize miri at the start of a sentence?
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.
Uh. I think it.s even supposed to be capitalized in the middle of sentences. I do forget. cc @solson
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've typically used "Miri" when referring to the project and miri
when referring to the binary or crate name, but I probably haven't been consistent myself.
} | ||
``` | ||
|
||
However, it is sometimes okay for a `const` to contain a *type* that allows |
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.
It's also OK for constants to have their base value have interior mutability since each use site creates its own copy of 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.
"a const
to contain a reference to a type that..."?
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.
Yea that's good
inside the `const fn`, we don't detect that all fields of `tuple` have been moved | ||
out of, and thus conservatively assume that the drop impl for `tuple` will run. | ||
While this particular case is trivial, there are other, more complex ones that | ||
would require a more expensive solution. It is an open question how precise we |
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.
Maybe note that the solution would make cases not needing it also more expensive
This also separates the discussion of looping constructs from that of `const` trait methods and the `?` operator.
@oli-obk Pushed a commit addressing each of your concerns. |
Co-Authored-By: lqd <remy.rakic+github@gmail.com>
@nikomatsakis (or anybody else with merge rights) |
This is a rough draft of a post announcing that
if
andmatch
will be available on nightly. Obviously this can't be merged before rust-lang/rust#66507.cc @rust-lang/wg-const-eval