Skip to content

Commit 1798f22

Browse files
committed
erase coroutine shim dereftemps
1 parent e4787c8 commit 1798f22

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

compiler/rustc_mir_transform/src/coroutine.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,27 +1622,27 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform {
16221622
let mut drop_shim =
16231623
create_coroutine_drop_shim_async(tcx, &transform, body, drop_clean, can_unwind);
16241624
// Run derefer to fix Derefs that are not in the first place
1625-
deref_finder(tcx, &mut drop_shim);
1625+
deref_finder(tcx, &mut drop_shim, false);
16261626
body.coroutine.as_mut().unwrap().coroutine_drop_async = Some(drop_shim);
16271627
} else {
16281628
// If coroutine has no async drops, generating sync drop shim
16291629
let mut drop_shim =
16301630
create_coroutine_drop_shim(tcx, &transform, coroutine_ty, body, drop_clean);
16311631
// Run derefer to fix Derefs that are not in the first place
1632-
deref_finder(tcx, &mut drop_shim);
1632+
deref_finder(tcx, &mut drop_shim, false);
16331633
body.coroutine.as_mut().unwrap().coroutine_drop = Some(drop_shim);
16341634

16351635
// For coroutine with sync drop, generating async proxy for `future_drop_poll` call
16361636
let mut proxy_shim = create_coroutine_drop_shim_proxy_async(tcx, body);
1637-
deref_finder(tcx, &mut proxy_shim);
1637+
deref_finder(tcx, &mut proxy_shim, false);
16381638
body.coroutine.as_mut().unwrap().coroutine_drop_proxy_async = Some(proxy_shim);
16391639
}
16401640

16411641
// Create the Coroutine::resume / Future::poll function
16421642
create_coroutine_resume_function(tcx, transform, body, can_return, can_unwind);
16431643

16441644
// Run derefer to fix Derefs that are not in the first place
1645-
deref_finder(tcx, body);
1645+
deref_finder(tcx, body, false);
16461646
}
16471647

16481648
fn is_required(&self) -> bool {

compiler/rustc_mir_transform/src/deref_separator.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct DerefChecker<'a, 'tcx> {
1111
tcx: TyCtxt<'tcx>,
1212
patcher: MirPatch<'tcx>,
1313
local_decls: &'a LocalDecls<'tcx>,
14+
add_deref_metadata: bool,
1415
}
1516

1617
impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
@@ -39,7 +40,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
3940
let temp = self.patcher.new_local_with_info(
4041
ty,
4142
self.local_decls[p_ref.local].source_info.span,
42-
LocalInfo::DerefTemp,
43+
if self.add_deref_metadata {
44+
LocalInfo::DerefTemp
45+
} else {
46+
LocalInfo::Boring
47+
},
4348
);
4449

4550
// We are adding current p_ref's projections to our
@@ -50,7 +55,11 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
5055
self.patcher.add_assign(
5156
loc,
5257
Place::from(temp),
53-
Rvalue::CopyForDeref(deref_place),
58+
if self.add_deref_metadata {
59+
Rvalue::CopyForDeref(deref_place)
60+
} else {
61+
Rvalue::Use(Operand::Copy(deref_place))
62+
},
5463
);
5564
place_local = temp;
5665
last_len = p_ref.projection.len();
@@ -67,9 +76,14 @@ impl<'a, 'tcx> MutVisitor<'tcx> for DerefChecker<'a, 'tcx> {
6776
}
6877
}
6978

70-
pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
79+
pub(super) fn deref_finder<'tcx>(
80+
tcx: TyCtxt<'tcx>,
81+
body: &mut Body<'tcx>,
82+
add_deref_metadata: bool,
83+
) {
7184
let patch = MirPatch::new(body);
72-
let mut checker = DerefChecker { tcx, patcher: patch, local_decls: &body.local_decls };
85+
let mut checker =
86+
DerefChecker { tcx, patcher: patch, local_decls: &body.local_decls, add_deref_metadata };
7387

7488
for (bb, data) in body.basic_blocks.as_mut_preserves_cfg().iter_enumerated_mut() {
7589
checker.visit_basic_block_data(bb, data);
@@ -80,7 +94,7 @@ pub(super) fn deref_finder<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
8094

8195
impl<'tcx> crate::MirPass<'tcx> for Derefer {
8296
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
83-
deref_finder(tcx, body);
97+
deref_finder(tcx, body, true);
8498
}
8599

86100
fn is_required(&self) -> bool {

compiler/rustc_mir_transform/src/elaborate_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'tcx> crate::MirPass<'tcx> for ElaborateDrops {
8787
.elaborate()
8888
};
8989
elaborate_patch.apply(body);
90-
deref_finder(tcx, body);
90+
deref_finder(tcx, body, true);
9191
}
9292

9393
fn is_required(&self) -> bool {

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> crate::MirPass<'tcx> for Inline {
6464
if inline::<NormalInliner<'tcx>>(tcx, body) {
6565
debug!("running simplify cfg on {:?}", body.source);
6666
simplify_cfg(tcx, body);
67-
deref_finder(tcx, body);
67+
deref_finder(tcx, body, false);
6868
}
6969
}
7070

@@ -100,7 +100,7 @@ impl<'tcx> crate::MirPass<'tcx> for ForceInline {
100100
if inline::<ForceInliner<'tcx>>(tcx, body) {
101101
debug!("running simplify cfg on {:?}", body.source);
102102
simplify_cfg(tcx, body);
103-
deref_finder(tcx, body);
103+
deref_finder(tcx, body, false);
104104
}
105105
}
106106
}

compiler/rustc_mir_transform/src/shim.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ use rustc_span::source_map::{Spanned, dummy_spanned};
1717
use rustc_span::{DUMMY_SP, Span};
1818
use tracing::{debug, instrument};
1919

20+
use crate::deref_separator::deref_finder;
2021
use crate::elaborate_drop::{DropElaborator, DropFlagMode, DropStyle, Unwind, elaborate_drop};
2122
use crate::patch::MirPatch;
2223
use crate::{
23-
abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, deref_separator, inline,
24-
instsimplify, mentioned_items, pass_manager as pm, remove_noop_landing_pads,
25-
run_optimization_passes, simplify,
24+
abort_unwinding_calls, add_call_guards, add_moves_for_packed_drops, inline, instsimplify,
25+
mentioned_items, pass_manager as pm, remove_noop_landing_pads, run_optimization_passes,
26+
simplify,
2627
};
2728

2829
mod async_destructor_ctor;
@@ -222,6 +223,8 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body<
222223
};
223224
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
224225

226+
deref_finder(tcx, &mut result, false);
227+
225228
// We don't validate MIR here because the shims may generate code that's
226229
// only valid in a `PostAnalysis` param-env. However, since we do initial
227230
// 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<
232235
&[
233236
&mentioned_items::MentionedItems,
234237
&add_moves_for_packed_drops::AddMovesForPackedDrops,
235-
&deref_separator::Derefer,
236238
&remove_noop_landing_pads::RemoveNoopLandingPads,
237239
&simplify::SimplifyCfg::MakeShim,
238240
&instsimplify::InstSimplify::BeforeInline,

0 commit comments

Comments
 (0)