Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 06acd8c

Browse files
committedAug 30, 2024
Subpart9 for async drop (major3) - elaborate_drops changes
1 parent b755978 commit 06acd8c

File tree

6 files changed

+450
-72
lines changed

6 files changed

+450
-72
lines changed
 

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4099,6 +4099,7 @@ dependencies = [
40994099
name = "rustc_mir_dataflow"
41004100
version = "0.0.0"
41014101
dependencies = [
4102+
"itertools",
41024103
"polonius-engine",
41034104
"regex",
41044105
"rustc_ast",

‎compiler/rustc_mir_dataflow/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
itertools = "0.12"
89
polonius-engine = "0.13.0"
910
regex = "1"
1011
rustc_ast = { path = "../rustc_ast" }

‎compiler/rustc_mir_dataflow/src/elaborate_drops.rs‎

Lines changed: 414 additions & 68 deletions
Large diffs are not rendered by default.

‎compiler/rustc_mir_transform/src/coroutine.rs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1174,7 +1174,13 @@ fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
11741174
let def_id = body.source.def_id();
11751175
let param_env = tcx.param_env(def_id);
11761176

1177-
let mut elaborator = DropShimElaborator { body, patch: MirPatch::new(body), tcx, param_env };
1177+
let mut elaborator = DropShimElaborator {
1178+
body,
1179+
patch: MirPatch::new(body),
1180+
tcx,
1181+
param_env,
1182+
produce_async_drops: false,
1183+
};
11781184

11791185
for (block, block_data) in body.basic_blocks.iter_enumerated() {
11801186
let (target, unwind, source_info) = match block_data.terminator() {
@@ -1213,6 +1219,7 @@ fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
12131219
*target,
12141220
unwind,
12151221
block,
1222+
None,
12161223
);
12171224
}
12181225
elaborator.patch.apply(body);

‎compiler/rustc_mir_transform/src/elaborate_drops.rs‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,14 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, '_, '_, 'tcx> {
165165
self.ctxt.param_env()
166166
}
167167

168+
fn allow_async_drops(&self) -> bool {
169+
true
170+
}
171+
172+
fn terminator_loc(&self, bb: BasicBlock) -> Location {
173+
self.ctxt.patch.terminator_loc(self.ctxt.body, bb)
174+
}
175+
168176
#[instrument(level = "debug", skip(self), ret)]
169177
fn drop_style(&self, path: Self::Path, mode: DropFlagMode) -> DropStyle {
170178
let ((maybe_live, maybe_dead), multipart) = match mode {
@@ -333,7 +341,7 @@ impl<'b, 'mir, 'tcx> ElaborateDropsCtxt<'b, 'mir, 'tcx> {
333341
// This function should mirror what `collect_drop_flags` does.
334342
for (bb, data) in self.body.basic_blocks.iter_enumerated() {
335343
let terminator = data.terminator();
336-
let TerminatorKind::Drop { place, target, unwind, replace, drop: _, async_fut: _ } =
344+
let TerminatorKind::Drop { place, target, unwind, replace, drop, async_fut: _ } =
337345
terminator.kind
338346
else {
339347
continue;
@@ -379,6 +387,7 @@ impl<'b, 'mir, 'tcx> ElaborateDropsCtxt<'b, 'mir, 'tcx> {
379387
target,
380388
unwind,
381389
bb,
390+
drop,
382391
)
383392
}
384393
LookupResult::Parent(None) => {}

‎compiler/rustc_mir_transform/src/shim.rs‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,13 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
281281
if ty.is_some() {
282282
let patch = {
283283
let param_env = tcx.param_env_reveal_all_normalized(def_id);
284-
let mut elaborator =
285-
DropShimElaborator { body: &body, patch: MirPatch::new(&body), tcx, param_env };
284+
let mut elaborator = DropShimElaborator {
285+
body: &body,
286+
patch: MirPatch::new(&body),
287+
tcx,
288+
param_env,
289+
produce_async_drops: false,
290+
};
286291
let dropee = tcx.mk_place_deref(dropee_ptr);
287292
let resume_block = elaborator.patch.resume_block();
288293
elaborate_drops::elaborate_drop(
@@ -293,6 +298,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
293298
return_block,
294299
elaborate_drops::Unwind::To(resume_block),
295300
START_BLOCK,
301+
None,
296302
);
297303
elaborator.patch
298304
};
@@ -341,6 +347,7 @@ pub struct DropShimElaborator<'a, 'tcx> {
341347
pub patch: MirPatch<'tcx>,
342348
pub tcx: TyCtxt<'tcx>,
343349
pub param_env: ty::ParamEnv<'tcx>,
350+
pub produce_async_drops: bool,
344351
}
345352

346353
impl fmt::Debug for DropShimElaborator<'_, '_> {
@@ -365,6 +372,13 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> {
365372
self.param_env
366373
}
367374

375+
fn terminator_loc(&self, bb: BasicBlock) -> Location {
376+
self.patch.terminator_loc(self.body, bb)
377+
}
378+
fn allow_async_drops(&self) -> bool {
379+
self.produce_async_drops
380+
}
381+
368382
fn drop_style(&self, _path: Self::Path, mode: DropFlagMode) -> DropStyle {
369383
match mode {
370384
DropFlagMode::Shallow => {

0 commit comments

Comments
 (0)
Please sign in to comment.