1
Fork 0

exp-stuff-dirty

This commit is contained in:
ouz-a 2022-04-28 01:03:07 +03:00
parent 0e7915d11f
commit f1c5f34f76
34 changed files with 65 additions and 141 deletions

View file

@ -57,6 +57,17 @@ fn may_be_reference(ty: Ty<'_>) -> bool {
}
}
/// Determines whether or not this LocalDecl is temp, if not it needs retagging.
fn is_not_temp<'tcx>(local_decl: &LocalDecl<'tcx>) -> bool {
if local_decl.local_info.is_some() {
match local_decl.local_info.as_ref().unwrap().as_ref() {
LocalInfo::Temp => return false,
_ => (),
};
}
return true;
}
impl<'tcx> MirPass<'tcx> for AddRetag {
fn is_enabled(&self, sess: &rustc_session::Session) -> bool {
sess.opts.debugging_opts.mir_emit_retag
@ -71,7 +82,9 @@ impl<'tcx> MirPass<'tcx> for AddRetag {
let needs_retag = |place: &Place<'tcx>| {
// FIXME: Instead of giving up for unstable places, we should introduce
// a temporary and retag on that.
is_stable(place.as_ref()) && may_be_reference(place.ty(&*local_decls, tcx).ty)
is_stable(place.as_ref())
&& may_be_reference(place.ty(&*local_decls, tcx).ty)
&& is_not_temp(&local_decls[place.local])
};
let place_base_raw = |place: &Place<'tcx>| {
// If this is a `Deref`, get the type of what we are deref'ing.

View file

@ -34,7 +34,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
if p_elem == ProjectionElem::Deref && !p_ref.projection.is_empty() {
let ty = p_ref.ty(&self.local_decls, self.tcx).ty;
let temp =
self.patcher.new_temp(ty, self.local_decls[p_ref.local].source_info.span);
self.patcher.new_local_temp(ty, self.local_decls[p_ref.local].source_info.span);
self.patcher.add_statement(loc, StatementKind::StorageLive(temp));
@ -42,12 +42,12 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
// temp value, excluding projections we already covered.
let deref_place = Place::from(place_local)
.project_deeper(&p_ref.projection[last_len..], self.tcx);
self.patcher.add_assign(
loc,
Place::from(temp),
Rvalue::Use(Operand::Move(deref_place)),
);
place_local = temp;
last_len = p_ref.projection.len();
@ -58,7 +58,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefChecker<'tcx> {
*place = temp_place;
}
// We are destroying last temp since it's no longer used.
// We are destroying the previous temp since it's no longer used.
if let Some(prev_temp) = prev_temp {
self.patcher.add_statement(loc, StatementKind::StorageDead(prev_temp));
}

View file

@ -426,13 +426,13 @@ fn run_post_borrowck_cleanup_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tc
&add_moves_for_packed_drops::AddMovesForPackedDrops,
// `AddRetag` needs to run after `ElaborateDrops`. Otherwise it should run fairly late,
// but before optimizations begin.
&deref_separator::Derefer,
&add_retag::AddRetag,
&lower_intrinsics::LowerIntrinsics,
&simplify::SimplifyCfg::new("elaborate-drops"),
// `Deaggregator` is conceptually part of MIR building, some backends rely on it happening
// and it can help optimizations.
&deaggregator::Deaggregator,
&deref_separator::Derefer,
&Lint(const_prop_lint::ConstProp),
];