Remove DropAndReplace terminator

PR 107844 made DropAndReplace unused, let's remove it completely
from the codebase.
This commit is contained in:
Giacomo Pasini 2023-03-05 21:02:14 +01:00
parent 14c54b637b
commit c5d4e4d907
No known key found for this signature in database
GPG key ID: A03851B78A6C9A46
48 changed files with 33 additions and 341 deletions

View file

@ -1,5 +1,5 @@
use rustc_index::bit_set::ChunkedBitSet;
use rustc_middle::mir::{Body, Field, Rvalue, Statement, StatementKind, TerminatorKind};
use rustc_middle::mir::{Body, Field, TerminatorKind};
use rustc_middle::ty::subst::SubstsRef;
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, VariantDef};
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
@ -8,7 +8,7 @@ use rustc_mir_dataflow::{self, move_path_children_matching, Analysis, MoveDataPa
use crate::MirPass;
/// Removes `Drop` and `DropAndReplace` terminators whose target is known to be uninitialized at
/// Removes `Drop` terminators whose target is known to be uninitialized at
/// that point.
///
/// This is redundant with drop elaboration, but we need to do it prior to const-checking, and
@ -37,8 +37,7 @@ impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
let mut to_remove = vec![];
for (bb, block) in body.basic_blocks.iter_enumerated() {
let terminator = block.terminator();
let (TerminatorKind::Drop { place, .. } | TerminatorKind::DropAndReplace { place, .. })
= &terminator.kind
let TerminatorKind::Drop { place, .. } = &terminator.kind
else { continue };
maybe_inits.seek_before_primary_effect(body.terminator_loc(bb));
@ -64,24 +63,12 @@ impl<'tcx> MirPass<'tcx> for RemoveUninitDrops {
for bb in to_remove {
let block = &mut body.basic_blocks_mut()[bb];
let (TerminatorKind::Drop { target, .. } | TerminatorKind::DropAndReplace { target, .. })
let TerminatorKind::Drop { target, .. }
= &block.terminator().kind
else { unreachable!() };
// Replace block terminator with `Goto`.
let target = *target;
let old_terminator_kind = std::mem::replace(
&mut block.terminator_mut().kind,
TerminatorKind::Goto { target },
);
// If this is a `DropAndReplace`, we need to emulate the assignment to the return place.
if let TerminatorKind::DropAndReplace { place, value, .. } = old_terminator_kind {
block.statements.push(Statement {
source_info: block.terminator().source_info,
kind: StatementKind::Assign(Box::new((place, Rvalue::Use(value)))),
});
}
block.terminator_mut().kind = TerminatorKind::Goto { target: *target };
}
}
}