1
Fork 0

Add new Deinit statement kind

This commit is contained in:
Jakob Degen 2022-04-05 17:14:59 -04:00
parent d00e77078c
commit 9b6b1a625b
27 changed files with 141 additions and 66 deletions

View file

@ -97,6 +97,7 @@ impl<'tcx> Visitor<'tcx> for UnsafetyChecker<'_, 'tcx> {
StatementKind::Assign(..)
| StatementKind::FakeRead(..)
| StatementKind::SetDiscriminant { .. }
| StatementKind::Deinit(..)
| StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)
| StatementKind::Retag { .. }

View file

@ -827,6 +827,7 @@ pub(super) fn filtered_statement_span(statement: &Statement<'_>) -> Option<Span>
| StatementKind::CopyNonOverlapping(..)
| StatementKind::Assign(_)
| StatementKind::SetDiscriminant { .. }
| StatementKind::Deinit(..)
| StatementKind::Retag(_, _)
| StatementKind::AscribeUserType(_, _) => {
Some(statement.source_info.span)

View file

@ -530,6 +530,7 @@ impl<'a> Conflicts<'a> {
StatementKind::Assign(_) => {}
StatementKind::SetDiscriminant { .. }
| StatementKind::Deinit(..)
| StatementKind::StorageLive(..)
| StatementKind::StorageDead(..)
| StatementKind::Retag(..)

View file

@ -1441,6 +1441,7 @@ impl<'tcx> Visitor<'tcx> for EnsureGeneratorFieldAssignmentsNeverAlias<'_> {
StatementKind::FakeRead(..)
| StatementKind::SetDiscriminant { .. }
| StatementKind::Deinit(..)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::Retag(..)

View file

@ -50,6 +50,7 @@ impl RemoveNoopLandingPads {
StatementKind::Assign { .. }
| StatementKind::SetDiscriminant { .. }
| StatementKind::Deinit(..)
| StatementKind::CopyNonOverlapping(..)
| StatementKind::Retag { .. } => {
return false;

View file

@ -21,7 +21,9 @@ impl<'tcx> MirPass<'tcx> for RemoveZsts {
let (basic_blocks, local_decls) = body.basic_blocks_and_local_decls_mut();
for block in basic_blocks.iter_mut() {
for statement in block.statements.iter_mut() {
if let StatementKind::Assign(box (place, _)) = statement.kind {
if let StatementKind::Assign(box (place, _)) | StatementKind::Deinit(box place) =
statement.kind
{
let place_ty = place.ty(local_decls, tcx).ty;
if !maybe_zst(place_ty) {
continue;

View file

@ -242,6 +242,7 @@ fn is_likely_const<'tcx>(mut tracked_place: Place<'tcx>, block: &BasicBlockData<
// These statements have no influence on the place
// we are interested in
StatementKind::FakeRead(_)
| StatementKind::Deinit(_)
| StatementKind::StorageLive(_)
| StatementKind::Retag(_, _)
| StatementKind::AscribeUserType(_, _)
@ -308,6 +309,7 @@ fn find_determining_place<'tcx>(
// These statements have no influence on the place
// we are interested in
StatementKind::FakeRead(_)
| StatementKind::Deinit(_)
| StatementKind::StorageLive(_)
| StatementKind::StorageDead(_)
| StatementKind::Retag(_, _)

View file

@ -498,7 +498,8 @@ impl<'tcx> Visitor<'tcx> for UsedLocals {
self.visit_rvalue(rvalue, location);
}
StatementKind::SetDiscriminant { ref place, variant_index: _ } => {
StatementKind::SetDiscriminant { ref place, variant_index: _ }
| StatementKind::Deinit(ref place) => {
self.visit_lhs(place, location);
}
}
@ -534,9 +535,8 @@ fn remove_unused_definitions(used_locals: &mut UsedLocals, body: &mut Body<'_>)
}
StatementKind::Assign(box (place, _)) => used_locals.is_used(place.local),
StatementKind::SetDiscriminant { ref place, .. } => {
used_locals.is_used(place.local)
}
StatementKind::SetDiscriminant { ref place, .. }
| StatementKind::Deinit(ref place) => used_locals.is_used(place.local),
_ => true,
};