-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Run RemoveZsts pass at mir-opt-level=1 #83417
Conversation
@@ -8,9 +8,6 @@ pub struct RemoveZsts; | |||
|
|||
impl<'tcx> MirPass<'tcx> for RemoveZsts { | |||
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { | |||
if tcx.sess.mir_opt_level() < 3 { |
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 this be kept and use < 1
instead? I noticed that some const errors have changed, so I'm wondering if it's being triggered on mir-opt-level=0
.
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 doesn't run at mir-opt-level=0.
See
rust/compiler/rustc_mir/src/transform/mod.rs
Line 498 in 79e5814
&remove_zsts::RemoveZsts, |
rust/compiler/rustc_mir/src/transform/mod.rs
Line 558 in 79e5814
if mir_opt_level > 0 { optimizations } else { no_optimizations }, |
The error changes because it removes an assignment, so we hit a different error path due to a different use of the constant. The specific error messages changed in this PR are fine (see #83177 (comment)).
But this area seems undertested, I think I've found some cases where it's wrong. I'll open another PR to add tests, that we should merge before this one.
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 error changes because it removes an assignment, so we hit a different error path due to a different use of the constant. The specific error messages changed in this PR are fine (see #83177 (comment)).
I see, does the mir-opt-level apply to const-eval as well?
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 so, because I believe the same MIR is used for const eval and codegen.
But I don't think that's relevant here--the error that changes is in main
, not in const eval'd code.
There is a separate const eval error due to the panic (reported as a future compat warning):
rust/src/test/ui/consts/const-eval/panic-never-type.rs
Lines 8 to 10 in 79e5814
const VOID: ! = panic!(); | |
//~^ WARN any use of this value will cause an error | |
//~| WARN this was previously accepted by the compiler but is being phased out |
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.
Since #78407, CTFE uses unoptimized MIR to avoid situations where an undefined behaviour is hidden because of MIR optimizations.
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.
But I don't think that's relevant here--the error that changes is in
main
, not in const eval'd code.
Ah, I didn't notice that. Thanks for clearing up my confusion :)
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 reason for the change in diagnostics is that const propagation now doesn't see the constant anymore, but codegen will still evaluate it because it was used in the initial MIR body (see the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/transform/required_consts/index.html field)
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.
Another way to resolve that these tests get changed would be to eagerly evaluate all required_consts
in const propagation
To stop depending on optimizations reporting these entirely, we could also evaluate the constant in
if let ConstKind::Unevaluated(_) = ct.val { |
required_consts
if the evaluation did not succeed
This comment has been minimized.
This comment has been minimized.
Note that in the future you can just edit your message to replace |
I don't understand the reason for this PR. If we are breaking those tests, they are already in our test suite, so what is that PR adding? I think we should avoid changing ui tests in this PR by doing what I mentioned in #83417 (comment) (that you can do in a separate PR though if you want :) ) |
The existing tests aren't the same as #83423. For the existing tests, RemoveZsts just changes the error message. But for the tests in #83423, RemoveZsts removes the error entirely, allowing erroneous code to compile. (I thought that was strange so I did some more testing...this seems to only happen with |
Right, these are only evaluated once we go into codegen, and for generic constants, this will always be true, we need to monomorphize in order to evaluate them. For the already monomorphic constants we can optimize a little by doing the second part in #83417 (comment) (meaning: only put constants into If we can keep errors in check builds instead of full builds, we should do so, even if it is imperfect. |
☔ The latest upstream changes (presumably #85704) made this pull request unmergeable. Please resolve the merge conflicts. |
Effectively reverts commit 6960bc9.
429a536
to
585e4ae
Compare
Rebased. I made @rustbot label: -S-waiting-on-author +S-waiting-on-review |
Let's merge as is then. Pointing to the use site of a broken constant isn't really necessary, and for associated constants of generics we still behave as previously, so that is good. @bors r+ |
📌 Commit 585e4ae has been approved by |
⌛ Testing commit 585e4ae with merge 5b243cdd288c0c43b89060c71cfc549ee02c04fb... |
💔 Test failed - checks-actions |
A job failed! Check out the build log: (web) (plain) Click to see the possible cause of the failure (guessed by this bot)
|
@bors retry |
Maybe this should be rollup=never? (because perf implications) |
⌛ Testing commit 585e4ae with merge 92d26e1859495c185896762086e495f4061de4fd... |
The job Click to see the possible cause of the failure (guessed by this bot)
|
💔 Test failed - checks-actions |
^ looks like more network issues:
|
@bors retry |
☀️ Test successful - checks-actions |
Revert "Auto merge of rust-lang#83417 - erikdesjardins:enableremovezsts, r=oli-obk" This reverts commit 8007b50, reversing changes made to e55c13e. Fixes rust-lang#88043 r? `@oli-obk`
…removezsts, r=oli-obk"" This reverts commit 8e11199.
Reenable RemoveZsts Now that the underlying issue has been fixed by rust-lang#88124, we can reland rust-lang#83417. r? `@oli-obk`
per #83177 (comment)
This pass removes assignments to ZST places.
Perf (from #83177 (comment)): https://perf.rust-lang.org/compare.html?start=41b315a470d583f6446599984ff9ad3bd61012b2&end=bd5d1b96f0c64c9938feea831789e1b5bb2cd4a2
r? @oli-obk