Skip to content

Commit 67e273b

Browse files
committed
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.
2 parents 825c706 + 483525e commit 67e273b

14 files changed

+8
-108
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct ConstProp;
5454

5555
impl<'tcx> MirPass<'tcx> for ConstProp {
5656
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
57-
sess.mir_opt_level() >= 1
57+
sess.mir_opt_level() >= 2
5858
}
5959

6060
#[instrument(skip(self, tcx), level = "debug")]
@@ -854,12 +854,6 @@ impl<'tcx> MutVisitor<'tcx> for ConstPropagator<'_, 'tcx> {
854854
}
855855
}
856856

857-
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
858-
trace!("visit_constant: {:?}", constant);
859-
self.super_constant(constant, location);
860-
self.eval_constant(constant);
861-
}
862-
863857
fn visit_assign(
864858
&mut self,
865859
place: &mut Place<'tcx>,

compiler/rustc_mir_transform/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,6 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
566566
&separate_const_switch::SeparateConstSwitch,
567567
&simplify::SimplifyLocals::new("before-const-prop"),
568568
&copy_prop::CopyProp,
569-
//
570-
// FIXME(#70073): This pass is responsible for both optimization as well as some lints.
571569
&const_prop::ConstProp,
572570
&dataflow_const_prop::DataflowConstProp,
573571
//

tests/codegen/optimize-attr-1.rs

-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
// CHECK-LABEL: define{{.*}}i32 @nothing
1010
// CHECK-SAME: [[NOTHING_ATTRS:#[0-9]+]]
11-
// NO-OPT: ret i32 4
1211
// SIZE-OPT: ret i32 4
1312
// SPEEC-OPT: ret i32 4
1413
#[no_mangle]
@@ -18,7 +17,6 @@ pub fn nothing() -> i32 {
1817

1918
// CHECK-LABEL: define{{.*}}i32 @size
2019
// CHECK-SAME: [[SIZE_ATTRS:#[0-9]+]]
21-
// NO-OPT: ret i32 6
2220
// SIZE-OPT: ret i32 6
2321
// SPEED-OPT: ret i32 6
2422
#[optimize(size)]
@@ -31,7 +29,6 @@ pub fn size() -> i32 {
3129
// NO-OPT-SAME: [[NOTHING_ATTRS]]
3230
// SPEED-OPT-SAME: [[NOTHING_ATTRS]]
3331
// SIZE-OPT-SAME: [[SPEED_ATTRS:#[0-9]+]]
34-
// NO-OPT: ret i32 8
3532
// SIZE-OPT: ret i32 8
3633
// SPEED-OPT: ret i32 8
3734
#[optimize(speed)]

tests/mir-opt/div_overflow.const_dividend.PreCodegen.after.mir

-17
This file was deleted.

tests/mir-opt/div_overflow.const_divisor.PreCodegen.after.mir

-11
This file was deleted.

tests/mir-opt/div_overflow.rs

-19
This file was deleted.

tests/run-make/const_fn_mir/dump.mir

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
// and is subject to change without notice. Knock yourself out.
33
fn foo() -> i32 {
44
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22
5+
let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10
56

67
bb0: {
7-
_0 = const 11_i32; // scope 0 at main.rs:5:5: 5:10
8+
_1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10
9+
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
10+
}
11+
12+
bb1: {
13+
_0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10
814
return; // scope 0 at main.rs:6:2: 6:2
915
}
1016
}

tests/ui/associated-consts/defaults-not-assumed-fail.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
2626
|
2727
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
2828

29-
note: erroneous constant used
30-
--> $DIR/defaults-not-assumed-fail.rs:33:5
31-
|
32-
LL | assert_eq!(<() as Tr>::B, 0); // causes the error above
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
34-
|
35-
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
36-
3729
error: aborting due to previous error
3830

3931
For more information about this error, try `rustc --explain E0080`.

tests/ui/consts/const-err-late.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ note: erroneous constant used
2828
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
2929
| ^^^^^^^^^^^^^
3030

31-
note: erroneous constant used
32-
--> $DIR/const-err-late.rs:19:16
33-
|
34-
LL | black_box((S::<i32>::FOO, S::<u32>::FOO));
35-
| ^^^^^^^^^^^^^
36-
3731
error: aborting due to 2 previous errors
3832

3933
For more information about this error, try `rustc --explain E0080`.

tests/ui/consts/const-eval/issue-44578.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
2626
|
2727
= 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)
2828

29-
note: erroneous constant used
30-
--> $DIR/issue-44578.rs:25:20
31-
|
32-
LL | println!("{}", <Bar<u16, u8> as Foo>::AMT);
33-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
34-
|
35-
= 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)
36-
3729
error: aborting due to previous error
3830

3931
For more information about this error, try `rustc --explain E0080`.

tests/ui/consts/miri_unleashed/assoc_const.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,6 @@ note: erroneous constant used
2525
LL | let y = <String as Bar<Vec<u32>, String>>::F;
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2727

28-
note: erroneous constant used
29-
--> $DIR/assoc_const.rs:29:13
30-
|
31-
LL | let y = <String as Bar<Vec<u32>, String>>::F;
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33-
3428
warning: skipping const checks
3529
|
3630
help: skipping check that does not even have a feature gate

tests/ui/consts/miri_unleashed/assoc_const_2.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ note: erroneous constant used
1616
LL | let y = <String as Bar<String>>::F;
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1818

19-
note: erroneous constant used
20-
--> $DIR/assoc_const_2.rs:27:13
21-
|
22-
LL | let y = <String as Bar<String>>::F;
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
24-
2519
error: aborting due to previous error
2620

2721
For more information about this error, try `rustc --explain E0080`.

tests/ui/consts/uninhabited-const-issue-61744.stderr

-6
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,6 @@ note: erroneous constant used
657657
LL | dbg!(i32::CONSTANT);
658658
| ^^^^^^^^^^^^^
659659

660-
note: erroneous constant used
661-
--> $DIR/uninhabited-const-issue-61744.rs:18:10
662-
|
663-
LL | dbg!(i32::CONSTANT);
664-
| ^^^^^^^^^^^^^
665-
666660
error: aborting due to previous error
667661

668662
For more information about this error, try `rustc --explain E0080`.

tests/ui/limits/issue-55878.stderr

-8
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
2525
|
2626
= 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)
2727

28-
note: erroneous constant used
29-
--> $DIR/issue-55878.rs:7:26
30-
|
31-
LL | println!("Size: {}", std::mem::size_of::<[u8; u64::MAX as usize]>());
32-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33-
|
34-
= 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)
35-
3628
error: aborting due to previous error
3729

3830
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)