Auto merge of #109900 - cjgillot:disable-const-prop, r=oli-obk
Only enable ConstProp at mir-opt-level >= 2. That pass is not responsible for lints any more, so we can restrict it to optimized builds. This reduces the amount of duplicated const-eval messages.
This commit is contained in:
commit
67e273ba0e
@ -54,7 +54,7 @@ pub struct ConstProp;
|
||||
|
||||
impl<'tcx> MirPass<'tcx> for ConstProp {
|
||||
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
|
||||
sess.mir_opt_level() >= 1
|
||||
sess.mir_opt_level() >= 2
|
||||
}
|
||||
|
||||
#[instrument(skip(self, tcx), level = "debug")]
|
||||
@ -854,12 +854,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
|
||||
trace!("visit_constant: {:?}", constant);
|
||||
self.super_constant(constant, location);
|
||||
self.eval_constant(constant);
|
||||
}
|
||||
|
||||
fn visit_assign(
|
||||
&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
|
@ -566,8 +566,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
|
||||
&separate_const_switch::SeparateConstSwitch,
|
||||
&simplify::SimplifyLocals::new("before-const-prop"),
|
||||
©_prop::CopyProp,
|
||||
//
|
||||
// FIXME(#70073): This pass is responsible for both optimization as well as some lints.
|
||||
&const_prop::ConstProp,
|
||||
&dataflow_const_prop::DataflowConstProp,
|
||||
//
|
||||
|
@ -8,7 +8,6 @@
|
||||
|
||||
// CHECK-LABEL: define{{.*}}i32 @nothing
|
||||
// CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
|
||||
// NO-OPT: ret i32 4
|
||||
// SIZE-OPT: ret i32 4
|
||||
// SPEEC-OPT: ret i32 4
|
||||
#[no_mangle]
|
||||
@ -18,7 +17,6 @@ pub fn nothing() -> i32 {
|
||||
|
||||
// CHECK-LABEL: define{{.*}}i32 @size
|
||||
// CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]]
|
||||
// NO-OPT: ret i32 6
|
||||
// SIZE-OPT: ret i32 6
|
||||
// SPEED-OPT: ret i32 6
|
||||
#[optimize(size)]
|
||||
@ -31,7 +29,6 @@ pub fn size() -> i32 {
|
||||
// NO-OPT-SAME: [[NOTHING_ATTRS]]
|
||||
// SPEED-OPT-SAME: [[NOTHING_ATTRS]]
|
||||
// SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]]
|
||||
// NO-OPT: ret i32 8
|
||||
// SIZE-OPT: ret i32 8
|
||||
// SPEED-OPT: ret i32 8
|
||||
#[optimize(speed)]
|
||||
|
@ -1,17 +0,0 @@
|
||||
// MIR for `const_dividend` after PreCodegen
|
||||
|
||||
fn const_dividend(_1: i32) -> i32 {
|
||||
debug a => _1; // in scope 0 at $DIR/div_overflow.rs:+0:23: +0:24
|
||||
let mut _0: i32; // return place in scope 0 at $DIR/div_overflow.rs:+0:34: +0:37
|
||||
let mut _2: bool; // in scope 0 at $DIR/div_overflow.rs:+1:5: +1:12
|
||||
|
||||
bb0: {
|
||||
_2 = Eq(_1, const 0_i32); // scope 0 at $DIR/div_overflow.rs:+1:5: +1:12
|
||||
assert(!move _2, "attempt to divide `{}` by zero", const 256_i32) -> bb1; // scope 0 at $DIR/div_overflow.rs:+1:5: +1:12
|
||||
}
|
||||
|
||||
bb1: {
|
||||
_0 = Div(const 256_i32, _1); // scope 0 at $DIR/div_overflow.rs:+1:5: +1:12
|
||||
return; // scope 0 at $DIR/div_overflow.rs:+2:2: +2:2
|
||||
}
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
// MIR for `const_divisor` after PreCodegen
|
||||
|
||||
fn const_divisor(_1: i32) -> i32 {
|
||||
debug a => _1; // in scope 0 at $DIR/div_overflow.rs:+0:22: +0:23
|
||||
let mut _0: i32; // return place in scope 0 at $DIR/div_overflow.rs:+0:33: +0:36
|
||||
|
||||
bb0: {
|
||||
_0 = Div(_1, const 256_i32); // scope 0 at $DIR/div_overflow.rs:+1:5: +1:12
|
||||
return; // scope 0 at $DIR/div_overflow.rs:+2:2: +2:2
|
||||
}
|
||||
}
|
@ -1,19 +0,0 @@
|
||||
// ignore-wasm32 compiled with panic=abort by default
|
||||
// compile-flags: -Copt-level=0 -Coverflow-checks=yes
|
||||
|
||||
// Tests that division with a const does not emit a panicking branch for overflow
|
||||
|
||||
// EMIT_MIR div_overflow.const_divisor.PreCodegen.after.mir
|
||||
pub fn const_divisor(a: i32) -> i32 {
|
||||
a / 256
|
||||
}
|
||||
|
||||
// EMIT_MIR div_overflow.const_dividend.PreCodegen.after.mir
|
||||
pub fn const_dividend(a: i32) -> i32 {
|
||||
256 / a
|
||||
}
|
||||
|
||||
fn main() {
|
||||
const_divisor(123);
|
||||
const_dividend(123);
|
||||
}
|
@ -2,9 +2,15 @@
|
||||
// and is subject to change without notice. Knock yourself out.
|
||||
fn foo() -> i32 {
|
||||
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
|
||||
let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10
|
||||
|
||||
bb0: {
|
||||
_0 = const 11_i32; // scope 0 at main.rs:5:5: 5:10
|
||||
_1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10
|
||||
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> bb1; // scope 0 at main.rs:5:5: 5:10
|
||||
}
|
||||
|
||||
bb1: {
|
||||
_0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10
|
||||
return; // scope 0 at main.rs:6:2: 6:2
|
||||
}
|
||||
}
|
||||
|
@ -26,14 +26,6 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
|
||||
|
|
||||
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/defaults-not-assumed-fail.rs:33:5
|
||||
|
|
||||
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -28,12 +28,6 @@ note: erroneous constant used
|
||||
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/const-err-late.rs:19:16
|
||||
|
|
||||
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -26,14 +26,6 @@ LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
||||
|
|
||||
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/issue-44578.rs:25:20
|
||||
|
|
||||
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -25,12 +25,6 @@ note: erroneous constant used
|
||||
LL | let y = <String as Bar<Vec<u32>, String>>::F;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/assoc_const.rs:29:13
|
||||
|
|
||||
LL | let y = <String as Bar<Vec<u32>, String>>::F;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
warning: skipping const checks
|
||||
|
|
||||
help: skipping check that does not even have a feature gate
|
||||
|
@ -16,12 +16,6 @@ note: erroneous constant used
|
||||
LL | let y = <String as Bar<String>>::F;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/assoc_const_2.rs:27:13
|
||||
|
|
||||
LL | let y = <String as Bar<String>>::F;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -657,12 +657,6 @@ note: erroneous constant used
|
||||
LL | dbg!(i32::CONSTANT);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/uninhabited-const-issue-61744.rs:18:10
|
||||
|
|
||||
LL | dbg!(i32::CONSTANT);
|
||||
| ^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
@ -25,14 +25,6 @@ LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
|
||||
|
|
||||
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
note: erroneous constant used
|
||||
--> $DIR/issue-55878.rs:7:26
|
||||
|
|
||||
LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this note originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user