Skip to content

Commit f229fe6

Browse files
committed
Replace ConstProp by DataflowConstProp.
1 parent ffc48e3 commit f229fe6

File tree

165 files changed

+264
-2598
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

165 files changed

+264
-2598
lines changed

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 13 additions & 553 deletions
Large diffs are not rendered by default.

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ use crate::MirPass;
2424
const BLOCK_LIMIT: usize = 100;
2525
const PLACE_LIMIT: usize = 100;
2626

27-
pub struct DataflowConstProp;
27+
pub struct ConstProp;
2828

29-
impl<'tcx> MirPass<'tcx> for DataflowConstProp {
29+
impl<'tcx> MirPass<'tcx> for ConstProp {
3030
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
31-
sess.mir_opt_level() >= 3
31+
sess.mir_opt_level() >= 2
3232
}
3333

3434
#[instrument(skip_all level = "debug")]

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,7 @@ fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
549549
// destroy the SSA property. It should still happen before const-propagation, so the
550550
// latter pass will leverage the created opportunities.
551551
&separate_const_switch::SeparateConstSwitch,
552-
&const_prop::ConstProp,
553-
&dataflow_const_prop::DataflowConstProp,
552+
&dataflow_const_prop::ConstProp,
554553
//
555554
// Const-prop runs unconditionally, but doesn't mutate the MIR at mir-opt-level=0.
556555
&const_debuginfo::ConstDebugInfo,

tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

tests/mir-opt/const_prop/array_index.main.ConstProp.32bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-abort.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

tests/mir-opt/const_prop/array_index.main.ConstProp.64bit.panic-unwind.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
bb1: {
3030
- _1 = _2[_3];
31-
+ _1 = const 2_u32;
31+
+ _1 = _2[2 of 3];
3232
StorageDead(_3);
3333
StorageDead(_2);
3434
_0 = const ();

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-abort.diff

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable];
4243
}
4344

4445
bb1: {

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.32bit.panic-unwind.diff

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind continue];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind continue];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind continue];
4243
}
4344

4445
bb1: {

tests/mir-opt/const_prop/bad_op_unsafe_oob_for_slices.main.ConstProp.64bit.panic-abort.diff

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@
3434
StorageLive(_5);
3535
StorageLive(_6);
3636
_6 = const 3_usize;
37-
_7 = Len((*_1));
37+
- _7 = Len((*_1));
3838
- _8 = Lt(_6, _7);
3939
- assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, _6) -> [success: bb1, unwind unreachable];
40-
+ _8 = Lt(const 3_usize, _7);
41-
+ assert(move _8, "index out of bounds: the length is {} but the index is {}", move _7, const 3_usize) -> [success: bb1, unwind unreachable];
40+
+ _7 = const 3_usize;
41+
+ _8 = const false;
42+
+ assert(const false, "index out of bounds: the length is {} but the index is {}", const 3_usize, const 3_usize) -> [success: bb1, unwind unreachable];
4243
}
4344

4445
bb1: {

0 commit comments

Comments
 (0)