-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add speculative const-checking and remove qualify_min_const_fn.rs
#77128
Add speculative const-checking and remove qualify_min_const_fn.rs
#77128
Conversation
Most of the extra logic was unused in the post-drop-elaboration checker.
I haven't run the clippy tests locally (I'm not sure how), so this probably won't pass CI. I'm working on it. Also, you might have noticed that I use early returns instead of |
Also removes some checks that were overzealous.
a141a97
to
70e70de
Compare
{ | ||
return; | ||
} | ||
}, | ||
FnKind::Closure(..) => return, | ||
} | ||
|
||
let mir = cx.tcx.optimized_mir(def_id); | ||
let mir = cx.tcx.mir_const(WithOptConstParam::unknown(def_id)).borrow(); |
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.
whoa, how does this work? Couldn't it already have been stolen?
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.
Clippy tests don't run on PR CI, and I still can't run them locally due to some error about "two copies of the regex
crate".
I don't know if clippy has a mechanism for ordering lints. It's not correct to const-check optimized MIR, since optimizations (especially drop elaboration) could have removed invalid operations. This was true for qualify_min_const_fn
as well. Can someone from @rust-lang/clippy weigh in here?
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, ./x.py clean
seemed to work. Besides being incorrect, running const-checking on optimized MIR causes a bunch of assertions to fire, since we don't reason about promoteds inside const-checking. I guess we'll have to disable the lint until someone tells us how to order the execution of clippy lints.
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.
clippy could override the query that steals mir_const
and just not steal it. Right now we're doing a hacky thing (
rust/src/tools/clippy/src/driver.rs
Line 86 in 87d262a
// FIXME: #4825; This is required, because Clippy lints that are based on MIR have to be |
cc @rust-lang/clippy are you ok with turning off the "this could be const fn" lint until we figure out how to get it to use exactly the same analysis as the one used by rustc?
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 passes clippy tests locally now that I've commented out a single assertion. It was just the one ICE in every test. I think we could live with it (that assertion was more of a sanity check), but it doesn't feel great.
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.
Clippy is tested by running ./x.py test src/tools/clippy
If it works like Miri, test --stage 0
should also work (and be much faster as rustc is built only once).
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 tried started with stage 0
but got the bug about two rlibs for regex
. Can anyone reproduce? Doing a stage 1 build just to run clippy tests is pretty painful, especially since they don't run on CI.
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 regex thing is a longstanding problem with compiletest-rs that we've not really been able to fix. I don't know if https://crates.io/crates/trybuild fares better, maybe we should try it 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.
Miri also uses compiletest and its stage 0 tests work fine...
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.
in miri we don't use any crates in our unit tests I think
I really hate having to do this, since I don't think unstable compiler APIs should have to work around misuse by external crates. However, this is the only way this change will pass CI without a ton of modifications to clippy and/or involvement of the clippy team.
3d76006
to
5b51326
Compare
Cc @rust-lang/wg-const-eval |
Okay, so I'm gonna close this for now. I'll let someone from clippy move
@flip1995 This statement is misleading, and the misunderstanding underlying it will likely cause issues in the future, definitely with this lint and maybe with others. At |
Should we have an issue to track this pending cleanup? |
Added a note to #76618 (comment) and rewrote rust-lang/rust-clippy#6080. |
cc #76618
This removes
qualify_min_const_fn.rs
entirely. It remained after #76850 because it was still used for a clippy lint. To continue to support clippy, I added a speculative mode to the const-checker, which is exposed via thenon_const_fn_could_be_made_stable_const_fn
method.r? @oli-obk