-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Infallible promotion #3027
Infallible promotion #3027
Conversation
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.
Overall good read and strategy, but especially >>
and <<
and bit-operators (^,&,|,!
) are missing. They could require some more reasoning.
text/0000-infallible-promotion.md
Outdated
If too much code is broken, various ways to weaken this proposal (at the expense of more technical debt, sometimes across several parts of the compiler) are [described blow][rationale-and-alternatives]. | ||
|
||
The long-term plan is that such code can switch to [inline `const` expressions](2920-inline-const.md) instead. | ||
However, inline `const` expressions are still in the process of being implemented, and for now are specified to not support code that depends on generic parameters in the context, which is a loss of expressivity when compared with implicit promotion. |
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.
Does this mean, that this RFC is planned to be blocked on inline const 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.
The pacing of the individual breaking changes will be up for the lang team to decide. Having a migration path may or may not make a difference when incurring a breaking change.
They are trivial, I just added them. What kinds of problems did you foresee here? |
I was assuming overflow just means overflow and not underflow, but this RFC specifies the meaning. Thus should be fine. |
Yeah, "overflow" includes all kinds of values that cannot be represented, no matter "in which direction they overflow". |
How about changing constants so that if they have a #[panic] attribute they can have a "panic" value that results in a panic upon const use? (and no compiler error) Then promotion would generate consts with the #[panic] attribute and everything should work fine without needing the complicated, inflexible and limited list of special cases in this RFC. |
That would need a lot of complicated machinery all over the compiler. Note that we need a "complicated, inflexible and limited list of special cases" anyway for promotion, e.g. to exclude interior mutability or types that drop. All this RFC is doing is restricting that list just a bit more to avoid having to deal with consts that can fail to evaluate without making compilation fail. In other words, this RFC is a lot simpler than what you proposed. The patch to implement this RFC will be less than 20 lines, followed by a cleanup PR that can remove way more code (and way more subtle code) than what the RFC implementation added. Also note that panics are not the only way consts can fail to evaluate. They can also cause Undefined Behavior or perform an operation that us not support by CTFE. |
Thanks for the write-up, Ralf! I knew some of the various pieces here, but between this and its earlier MCP version still learned a bunch -- the details of how the checked operators are promoted was an interesting nuance, for example, and not something I'd seen documented elsewhere. It was great having it all in order to bring everything together. Since it LGTM (and we asked you to write it), |
Team member @scottmcm has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
A recent comment by @oli-obk reminded me of the subtle interaction of promotion and const-validity checks. I added some text explaining that to the RFC; please let me know if that makes sense. |
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. The RFC will be merged soon. |
I created a tracking issue at rust-lang/rust#80619. |
@nikomatsakis @rust-lang/lang who's in charge of merging accepted RFCs? :) |
I tried 😄 EDIT: un-cc @Mark-Simulacrum |
Huzzah! The @rust-lang/lang team has decided to accept this RFC. To track further discussion, subscribe to the tracking issue here: |
This comment has been minimized.
This comment has been minimized.
…-obk avoid promoting division, modulo and indexing operations that could fail For division, `x / y` will still be promoted if `y` is a non-zero integer literal; however, `1/(1+1)` will not be promoted any more. While at it, also see if we can reject promoting floating-point arithmetic (which are [complicated](rust-lang/unsafe-code-guidelines#237) so maybe we should not promote them). This will need a crater run to see if there's code out there that relies on these things being promoted. If we can land this, promoteds in `fn`/`const fn` cannot fail to evaluate any more, which should let us do some simplifications in codegen/Miri! Cc rust-lang/rfcs#3027 Fixes rust-lang#61821 r? `@oli-obk`
make const_err a future incompat lint This is the first step for rust-lang#71800: make const_err a future-incompat lint. I also rewrote the const_err lint description as the old one seemed wrong. This has the unfortunate side-effect of making const-eval error even more verbose by making the const_err message longer without fixing the redundancy caused by additionally emitting an error on each use site of the constant. We cannot fix that redundancy until const_err is a *hard* error (at that point the error-on-use-site can be turned into a `delay_span_bug!` for uses of monomorphic consts, and into a nicely rendered error for [lazily / post-monomorhization evaluated] associated consts). ~~The one annoying effect of this PR is that `let _x = &(1/(1-1));` now also shows the future-incompat warning, even though of course we will *not* make this a hard error. We'll instead (hopefully) stop promoting it -- see rust-lang/rfcs#3027. The only way I see to avoid the future-incompat warning is to use a different lint for "failure to evaluate promoted".~~ Cc `@rust-lang/wg-const-eval`
This is the RFC-follow-up to rust-lang/lang-team#58.
Rendered