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.
This commit is contained in:
parent
e1e48ae29b
commit
52d3782685
|
@ -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,
|
||||
};
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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]);
|
||||
| ^^^^^^^
|
||||
|
|
Loading…
Reference in a new issue