diff options
author | bors <bors@rust-lang.org> | 2023-04-15 07:58:57 +0000 |
---|---|---|
committer | bors <bors@rust-lang.org> | 2023-04-15 07:58:57 +0000 |
commit | 67e273ba0e8d0bacc98905c0e536b249f53fc011 (patch) | |
tree | 1e168ed4f19978bb495076fcca9b66065d18d5ac | |
parent | 825c70658e0190bccd93d477907b06e05ad9ccc3 (diff) | |
parent | 483525eed300f3615f71ee05ddeeb8e0c232aa53 (diff) | |
download | rust-67e273ba0e8d0bacc98905c0e536b249f53fc011.tar.gz |
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.
-rw-r--r-- | compiler/rustc_mir_transform/src/const_prop.rs | 8 | ||||
-rw-r--r-- | compiler/rustc_mir_transform/src/lib.rs | 2 | ||||
-rw-r--r-- | tests/codegen/optimize-attr-1.rs | 3 | ||||
-rw-r--r-- | tests/mir-opt/div_overflow.const_dividend.PreCodegen.after.mir | 17 | ||||
-rw-r--r-- | tests/mir-opt/div_overflow.const_divisor.PreCodegen.after.mir | 11 | ||||
-rw-r--r-- | tests/mir-opt/div_overflow.rs | 19 | ||||
-rw-r--r-- | tests/run-make/const_fn_mir/dump.mir | 8 | ||||
-rw-r--r-- | tests/ui/associated-consts/defaults-not-assumed-fail.stderr | 8 | ||||
-rw-r--r-- | tests/ui/consts/const-err-late.stderr | 6 | ||||
-rw-r--r-- | tests/ui/consts/const-eval/issue-44578.stderr | 8 | ||||
-rw-r--r-- | tests/ui/consts/miri_unleashed/assoc_const.stderr | 6 | ||||
-rw-r--r-- | tests/ui/consts/miri_unleashed/assoc_const_2.stderr | 6 | ||||
-rw-r--r-- | tests/ui/consts/uninhabited-const-issue-61744.stderr | 6 | ||||
-rw-r--r-- | tests/ui/limits/issue-55878.stderr | 8 |
14 files changed, 8 insertions, 108 deletions
diff --git a/compiler/rustc_mir_transform/src/const_prop.rs b/compiler/rustc_mir_transform/src/const_prop.rs index 79a9ac7d20c..c0146e3efb0 100644 --- a/compiler/rustc_mir_transform/src/const_prop.rs +++ b/compiler/rustc_mir_transform/src/const_prop.rs @@ -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>, diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 2e418c1dafc..fc12d423cb0 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -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, // diff --git a/tests/codegen/optimize-attr-1.rs b/tests/codegen/optimize-attr-1.rs index 22abe06e7a9..1d1f0a38657 100644 --- a/tests/codegen/optimize-attr-1.rs +++ b/tests/codegen/optimize-attr-1.rs @@ -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)] diff --git a/tests/mir-opt/div_overflow.const_dividend.PreCodegen.after.mir b/tests/mir-opt/div_overflow.const_dividend.PreCodegen.after.mir deleted file mode 100644 index 1a7fb916e56..00000000000 --- a/tests/mir-opt/div_overflow.const_dividend.PreCodegen.after.mir +++ /dev/null @@ -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 - } -} diff --git a/tests/mir-opt/div_overflow.const_divisor.PreCodegen.after.mir b/tests/mir-opt/div_overflow.const_divisor.PreCodegen.after.mir deleted file mode 100644 index 5526a194be5..00000000000 --- a/tests/mir-opt/div_overflow.const_divisor.PreCodegen.after.mir +++ /dev/null @@ -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 - } -} diff --git a/tests/mir-opt/div_overflow.rs b/tests/mir-opt/div_overflow.rs deleted file mode 100644 index fe34a865b93..00000000000 --- a/tests/mir-opt/div_overflow.rs +++ /dev/null @@ -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); -} diff --git a/tests/run-make/const_fn_mir/dump.mir b/tests/run-make/const_fn_mir/dump.mir index ab4084c952a..9cc70d3b0e6 100644 --- a/tests/run-make/const_fn_mir/dump.mir +++ b/tests/run-make/const_fn_mir/dump.mir @@ -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 } } diff --git a/tests/ui/associated-consts/defaults-not-assumed-fail.stderr b/tests/ui/associated-consts/defaults-not-assumed-fail.stderr index fb7159e40c9..9b761b00691 100644 --- a/tests/ui/associated-consts/defaults-not-assumed-fail.stderr +++ b/tests/ui/associated-consts/defaults-not-assumed-fail.stderr @@ -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`. diff --git a/tests/ui/consts/const-err-late.stderr b/tests/ui/consts/const-err-late.stderr index 192b9ba204b..149d3b5236b 100644 --- a/tests/ui/consts/const-err-late.stderr +++ b/tests/ui/consts/const-err-late.stderr @@ -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`. diff --git a/tests/ui/consts/const-eval/issue-44578.stderr b/tests/ui/consts/const-eval/issue-44578.stderr index 0cbf5448000..f3952809e4b 100644 --- a/tests/ui/consts/const-eval/issue-44578.stderr +++ b/tests/ui/consts/const-eval/issue-44578.stderr @@ -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`. diff --git a/tests/ui/consts/miri_unleashed/assoc_const.stderr b/tests/ui/consts/miri_unleashed/assoc_const.stderr index e1da43c3aea..8e22cb74bf5 100644 --- a/tests/ui/consts/miri_unleashed/assoc_const.stderr +++ b/tests/ui/consts/miri_unleashed/assoc_const.stderr @@ -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 diff --git a/tests/ui/consts/miri_unleashed/assoc_const_2.stderr b/tests/ui/consts/miri_unleashed/assoc_const_2.stderr index fc4b18056da..ae7b03fc9dd 100644 --- a/tests/ui/consts/miri_unleashed/assoc_const_2.stderr +++ b/tests/ui/consts/miri_unleashed/assoc_const_2.stderr @@ -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`. diff --git a/tests/ui/consts/uninhabited-const-issue-61744.stderr b/tests/ui/consts/uninhabited-const-issue-61744.stderr index 3a94e19313f..adefbf336c2 100644 --- a/tests/ui/consts/uninhabited-const-issue-61744.stderr +++ b/tests/ui/consts/uninhabited-const-issue-61744.stderr @@ -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`. diff --git a/tests/ui/limits/issue-55878.stderr b/tests/ui/limits/issue-55878.stderr index 99f1fdf755a..510b36edd8f 100644 --- a/tests/ui/limits/issue-55878.stderr +++ b/tests/ui/limits/issue-55878.stderr @@ -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`. |