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:
Tomasz Miąsko
2020-10-17 00:00:00 +00:00
parent e1e48ae29b
commit 52d3782685
8 changed files with 20 additions and 27 deletions

View File

@@ -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,
};