diff options
Diffstat (limited to 'compiler/rustc_mir_transform/src')
| -rw-r--r-- | compiler/rustc_mir_transform/src/add_retag.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/deref_separator.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_mir_transform/src/lib.rs | 2 |
3 files changed, 18 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/add_retag.rs b/compiler/rustc_mir_transform/src/add_retag.rs index 28a5a22dd9d..ff4cd477326 100644 --- a/compiler/rustc_mir_transform/src/add_retag.rs +++ b/compiler/rustc_mir_transform/src/add_retag.rs @@ -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. diff --git a/compiler/rustc_mir_transform/src/deref_separator.rs b/compiler/rustc_mir_transform/src/deref_separator.rs index 7d81bb74cd6..afaab6e9a35 100644 --- a/compiler/rustc_mir_transform/src/deref_separator.rs +++ b/compiler/rustc_mir_transform/src/deref_separator.rs @@ -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)); } diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index d395ccd3819..40cc6dafe61 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -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), ]; |
