erase coroutine shim dereftemps

This commit is contained in:
beepster4096
2025-08-13 16:34:04 -07:00
parent fc959e5464
commit a0e9cb7cb4
5 changed files with 32 additions and 16 deletions
@@ -1625,19 +1625,19 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
let mut drop_shim =
create_coroutine_drop_shim_async(tcx, &transform, body, drop_clean, can_unwind);
// Run derefer to fix Derefs that are not in the first place
deref_finder(tcx, &mut drop_shim);
deref_finder(tcx, &mut drop_shim, false);
body.coroutine.as_mut().unwrap().coroutine_drop_async = Some(drop_shim);
} else {
// If coroutine has no async drops, generating sync drop shim
let mut drop_shim =
create_coroutine_drop_shim(tcx, &transform, coroutine_ty, body, drop_clean);
// Run derefer to fix Derefs that are not in the first place
deref_finder(tcx, &mut drop_shim);
deref_finder(tcx, &mut drop_shim, false);
body.coroutine.as_mut().unwrap().coroutine_drop = Some(drop_shim);
// For coroutine with sync drop, generating async proxy for `future_drop_poll` call
let mut proxy_shim = create_coroutine_drop_shim_proxy_async(tcx, body);
deref_finder(tcx, &mut proxy_shim);
deref_finder(tcx, &mut proxy_shim, false);
body.coroutine.as_mut().unwrap().coroutine_drop_proxy_async = Some(proxy_shim);
}
@@ -1645,7 +1645,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
create_coroutine_resume_function(tcx, transform, body, can_return, can_unwind);
// Run derefer to fix Derefs that are not in the first place
deref_finder(tcx, body);
deref_finder(tcx, body, false);
}
fn is_required(&self) -> bool {
@@ -11,6 +11,7 @@ struct DerefChecker<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
patcher: MirPatch<'tcx>,
local_decls: &'a LocalDecls<'tcx>,
add_deref_metadata: bool,
}
impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
@@ -39,7 +40,11 @@ fn visit_place(&mut self, place: &mut Place<'tcx>, cntxt: PlaceContext, loc: Loc
let temp = self.patcher.new_local_with_info(
ty,
self.local_decls[p_ref.local].source_info.span,
LocalInfo::DerefTemp,
if self.add_deref_metadata {
LocalInfo::DerefTemp
} else {
LocalInfo::Boring
},
);
// We are adding current p_ref's projections to our
@@ -50,7 +55,11 @@ fn visit_place(&mut self, place: &mut Place<'tcx>, cntxt: PlaceContext, loc: Loc
self.patcher.add_assign(
loc,
Place::from(temp),
Rvalue::CopyForDeref(deref_place),
if self.add_deref_metadata {
Rvalue::CopyForDeref(deref_place)
} else {
Rvalue::Use(Operand::Copy(deref_place))
},
);
place_local = temp;
last_len = p_ref.projection.len();
@@ -67,9 +76,14 @@ fn visit_place(&mut self, place: &mut Place<'tcx>, cntxt: PlaceContext, loc: Loc
}
}
pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
pub(super) fn deref_finder<'tcx>(
tcx: TyCtxt<'tcx>,
body: &mut Body<'tcx>,
add_deref_metadata: bool,
) {
let patch = MirPatch::new(body);
let mut checker = DerefChecker { tcx, patcher: patch, local_decls: &body.local_decls };
let mut checker =
DerefChecker { tcx, patcher: patch, local_decls: &body.local_decls, add_deref_metadata };
for (bb, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
checker.visit_basic_block_data(bb, data);
@@ -80,7 +94,7 @@ pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
impl<'tcx> crate::MirPass<'tcx> for Derefer {
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
deref_finder(tcx, body);
deref_finder(tcx, body, true);
}
fn is_required(&self) -> bool {
@@ -87,7 +87,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
.elaborate()
};
elaborate_patch.apply(body);
deref_finder(tcx, body);
deref_finder(tcx, body, true);
}
fn is_required(&self) -> bool {
+2 -2
View File
@@ -64,7 +64,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if inline::<NormalInliner<'tcx>>(tcx, body) {
debug!("running simplify cfg on {:?}", body.source);
simplify_cfg(tcx, body);
deref_finder(tcx, body);
deref_finder(tcx, body, false);
}
}
@@ -100,7 +100,7 @@ fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
if inline::<ForceInliner<'tcx>>(tcx, body) {
debug!("running simplify cfg on {:?}", body.source);
simplify_cfg(tcx, body);
deref_finder(tcx, body);
deref_finder(tcx, body, false);
}
}
}
+6 -4
View File
@@ -17,12 +17,13 @@
use rustc_span::{DUMMY_SP, Span};
use tracing::{debug, instrument};
use crate::deref_separator::deref_finder;
use crate::elaborate_drop::{DropElaborator, DropFlagMode, DropStyle, Unwind, elaborate_drop};
use crate::patch::MirPatch;
use crate::{
abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, deref_separator, inline,
instsimplify, mentioned_items, pass_manager as pm, remove_noop_landing_pads,
run_optimization_passes, simplify,
abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, inline, instsimplify,
mentioned_items, pass_manager as pm, remove_noop_landing_pads, run_optimization_passes,
simplify,
};
mod async_destructor_ctor;
@@ -222,6 +223,8 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
};
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
deref_finder(tcx, &mut result, false);
// We don't validate MIR here because the shims may generate code that's
// only valid in a `PostAnalysis` param-env. However, since we do initial
// validation with the MirBuilt phase, which uses a user-facing param-env.
@@ -232,7 +235,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
&[
&mentioned_items::MentionedItems,
&add_moves_for_packed_drops::AddMovesForPackedDrops,
&deref_separator::Derefer,
&remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::MakeShim,
&instsimplify::InstSimplify::BeforeInline,