diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-10-17 00:00:00 +0000 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2020-10-26 10:41:44 +0100 |
| commit | 52d37826858ee4dad6b66a3060994f41df247770 (patch) | |
| tree | 2d1bc76c92806acd3d79e0bd8e707657d6daf2f1 | |
| parent | e1e48ae29b52d214f93d816e99056aacb102a90a (diff) | |
| download | rust-52d37826858ee4dad6b66a3060994f41df247770.tar.gz rust-52d37826858ee4dad6b66a3060994f41df247770.zip | |
simplify-locals: Remove unused set-discriminant statements
Update affected ui & incremental tests to use a user declared variable bindings instead of temporaries. The former are preserved because of debuginfo, the latter are not.
8 files changed, 20 insertions, 27 deletions
diff --git a/compiler/rustc_mir/src/transform/simplify.rs b/compiler/rustc_mir/src/transform/simplify.rs index f88156588e5..183111877d1 100644 --- a/compiler/rustc_mir/src/transform/simplify.rs +++ b/compiler/rustc_mir/src/transform/simplify.rs @@ -427,7 +427,6 @@ impl Visitor<'_> for UsedLocals { fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { match statement.kind { StatementKind::LlvmInlineAsm(..) - | StatementKind::SetDiscriminant { .. } // FIXME: Try to remove those as well. | StatementKind::Retag(..) | StatementKind::Coverage(..) | StatementKind::FakeRead(..) @@ -467,6 +466,10 @@ impl Visitor<'_> for UsedLocals { } self.visit_rvalue(rvalue, location); } + + StatementKind::SetDiscriminant { ref place, variant_index: _ } => { + self.visit_lhs(place, location); + } } } @@ -481,10 +484,7 @@ impl Visitor<'_> for UsedLocals { } /// Removes unused definitions. Updates the used locals to reflect the changes made. -fn remove_unused_definitions<'a, 'tcx>( - used_locals: &'a mut UsedLocals, - body: &mut Body<'tcx>, -) { +fn remove_unused_definitions<'a, 'tcx>(used_locals: &'a mut UsedLocals, body: &mut Body<'tcx>) { // The use counts are updated as we remove the statements. A local might become unused // during the retain operation, leading to a temporary inconsistency (storage statements or // definitions referencing the local might remain). For correctness it is crucial that this @@ -502,6 +502,10 @@ fn remove_unused_definitions<'a, 'tcx>( used_locals.is_used(*local) } StatementKind::Assign(box (place, _)) => used_locals.is_used(place.local), + + StatementKind::SetDiscriminant { ref place, .. } => { + used_locals.is_used(place.local) + } _ => true, }; diff --git a/src/test/incremental/hashes/enum_constructors.rs b/src/test/incremental/hashes/enum_constructors.rs index 4161c6a6bfc..26ff6b109dc 100644 --- a/src/test/incremental/hashes/enum_constructors.rs +++ b/src/test/incremental/hashes/enum_constructors.rs @@ -7,7 +7,7 @@ // build-pass (FIXME(62277): could be check-pass?) // revisions: cfail1 cfail2 cfail3 -// compile-flags: -Z query-dep-graph -Zincremental-ignore-spans +// compile-flags: -Z query-dep-graph -Zincremental-ignore-spans -Zmir-opt-level=0 #![allow(warnings)] #![feature(rustc_attrs)] diff --git a/src/test/mir-opt/simplify_locals.d1.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.d1.SimplifyLocals.diff index 19811070e2a..76bf175d073 100644 --- a/src/test/mir-opt/simplify_locals.d1.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify_locals.d1.SimplifyLocals.diff @@ -3,14 +3,14 @@ fn d1() -> () { let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:20:9: 20:9 - let mut _1: E; // in scope 0 at $DIR/simplify-locals.rs:22:13: 22:17 +- let mut _1: E; // in scope 0 at $DIR/simplify-locals.rs:22:13: 22:17 scope 1 { } bb0: { - StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:22:13: 22:17 - discriminant(_1) = 0; // scope 0 at $DIR/simplify-locals.rs:22:13: 22:17 - StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:22:17: 22:18 +- StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:22:13: 22:17 +- discriminant(_1) = 0; // scope 0 at $DIR/simplify-locals.rs:22:13: 22:17 +- StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:22:17: 22:18 _0 = const (); // scope 0 at $DIR/simplify-locals.rs:20:9: 23:2 return; // scope 0 at $DIR/simplify-locals.rs:23:2: 23:2 } diff --git a/src/test/mir-opt/simplify_locals.d2.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals.d2.SimplifyLocals.diff index 91621a102e1..c06fa09053c 100644 --- a/src/test/mir-opt/simplify_locals.d2.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify_locals.d2.SimplifyLocals.diff @@ -3,14 +3,13 @@ fn d2() -> () { let mut _0: (); // return place in scope 0 at $DIR/simplify-locals.rs:26:9: 26:9 - let mut _1: E; // in scope 0 at $DIR/simplify-locals.rs:28:22: 28:26 +- let mut _1: E; // in scope 0 at $DIR/simplify-locals.rs:28:22: 28:26 - let mut _2: (i32, E); // in scope 0 at $DIR/simplify-locals.rs:28:5: 28:17 - let mut _3: E; // in scope 0 at $DIR/simplify-locals.rs:28:11: 28:15 -+ let mut _2: E; // in scope 0 at $DIR/simplify-locals.rs:28:11: 28:15 bb0: { - StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:28:22: 28:26 - discriminant(_1) = 1; // scope 0 at $DIR/simplify-locals.rs:28:22: 28:26 +- StorageLive(_1); // scope 0 at $DIR/simplify-locals.rs:28:22: 28:26 +- discriminant(_1) = 1; // scope 0 at $DIR/simplify-locals.rs:28:22: 28:26 - StorageLive(_2); // scope 0 at $DIR/simplify-locals.rs:28:5: 28:17 - StorageLive(_3); // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15 - discriminant(_3) = 0; // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15 @@ -30,10 +29,7 @@ - // mir::Constant - // + span: $DIR/simplify-locals.rs:28:5: 28:26 - // + literal: Const { ty: E, val: Value(Scalar(0x01)) } -+ StorageLive(_2); // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15 -+ discriminant(_2) = 0; // scope 0 at $DIR/simplify-locals.rs:28:11: 28:15 -+ StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:28:15: 28:16 - StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:28:25: 28:26 +- StorageDead(_1); // scope 0 at $DIR/simplify-locals.rs:28:25: 28:26 - StorageDead(_2); // scope 0 at $DIR/simplify-locals.rs:28:26: 28:27 _0 = const (); // scope 0 at $DIR/simplify-locals.rs:26:9: 29:2 return; // scope 0 at $DIR/simplify-locals.rs:29:2: 29:2 diff --git a/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.32bit.mir b/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.32bit.mir index 523ecb5ec1a..dae0cbb65a4 100644 --- a/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.32bit.mir +++ b/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.32bit.mir @@ -3,7 +3,6 @@ fn change_loop_body() -> () { let mut _0: (); // return place in scope 0 at $DIR/while_let_loops.rs:5:27: 5:27 let mut _1: i32; // in scope 0 at $DIR/while_let_loops.rs:6:9: 6:15 - let mut _2: std::option::Option<u32>; // in scope 0 at $DIR/while_let_loops.rs:7:28: 7:32 scope 1 { debug _x => _1; // in scope 1 at $DIR/while_let_loops.rs:6:9: 6:15 } @@ -11,10 +10,7 @@ fn change_loop_body() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/while_let_loops.rs:6:9: 6:15 _1 = const 0_i32; // scope 0 at $DIR/while_let_loops.rs:6:18: 6:19 - StorageLive(_2); // scope 1 at $DIR/while_let_loops.rs:7:28: 7:32 - discriminant(_2) = 0; // scope 1 at $DIR/while_let_loops.rs:7:28: 7:32 _0 = const (); // scope 1 at $DIR/while_let_loops.rs:7:5: 10:6 - StorageDead(_2); // scope 1 at $DIR/while_let_loops.rs:10:5: 10:6 StorageDead(_1); // scope 0 at $DIR/while_let_loops.rs:11:1: 11:2 return; // scope 0 at $DIR/while_let_loops.rs:11:2: 11:2 } diff --git a/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.64bit.mir b/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.64bit.mir index 523ecb5ec1a..dae0cbb65a4 100644 --- a/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.64bit.mir +++ b/src/test/mir-opt/while_let_loops.change_loop_body.PreCodegen.after.64bit.mir @@ -3,7 +3,6 @@ fn change_loop_body() -> () { let mut _0: (); // return place in scope 0 at $DIR/while_let_loops.rs:5:27: 5:27 let mut _1: i32; // in scope 0 at $DIR/while_let_loops.rs:6:9: 6:15 - let mut _2: std::option::Option<u32>; // in scope 0 at $DIR/while_let_loops.rs:7:28: 7:32 scope 1 { debug _x => _1; // in scope 1 at $DIR/while_let_loops.rs:6:9: 6:15 } @@ -11,10 +10,7 @@ fn change_loop_body() -> () { bb0: { StorageLive(_1); // scope 0 at $DIR/while_let_loops.rs:6:9: 6:15 _1 = const 0_i32; // scope 0 at $DIR/while_let_loops.rs:6:18: 6:19 - StorageLive(_2); // scope 1 at $DIR/while_let_loops.rs:7:28: 7:32 - discriminant(_2) = 0; // scope 1 at $DIR/while_let_loops.rs:7:28: 7:32 _0 = const (); // scope 1 at $DIR/while_let_loops.rs:7:5: 10:6 - StorageDead(_2); // scope 1 at $DIR/while_let_loops.rs:10:5: 10:6 StorageDead(_1); // scope 0 at $DIR/while_let_loops.rs:11:1: 11:2 return; // scope 0 at $DIR/while_let_loops.rs:11:2: 11:2 } diff --git a/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs index 49d489d9168..0895f4c18e3 100644 --- a/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs +++ b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.rs @@ -1,5 +1,6 @@ // build-fail // only-x86_64 +// compile-flags: -Zmir-opt-level=0 fn main() { Bug::V([0; !0]); //~ ERROR is too big for the current diff --git a/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr index d31ce9cfe0c..51eac95afb9 100644 --- a/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr +++ b/src/test/ui/lint/issue-69485-var-size-diffs-too-large.stderr @@ -1,5 +1,5 @@ error: the type `[u8; 18446744073709551615]` is too big for the current architecture - --> $DIR/issue-69485-var-size-diffs-too-large.rs:5:12 + --> $DIR/issue-69485-var-size-diffs-too-large.rs:6:12 | LL | Bug::V([0; !0]); | ^^^^^^^ |
