Skip to content

Commit cdf91ab

Browse files
committed
Async drop codegen (WIP)
1 parent 5bd5d21 commit cdf91ab

File tree

57 files changed

+1740
-143
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1740
-143
lines changed

compiler/rustc_borrowck/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,14 @@ impl<'cx, 'tcx, R> rustc_mir_dataflow::ResultsVisitor<'cx, 'tcx, R> for MirBorro
675675
TerminatorKind::SwitchInt { discr, targets: _ } => {
676676
self.consume_operand(loc, (discr, span), flow_state);
677677
}
678-
TerminatorKind::Drop { place, target: _, unwind: _, replace } => {
678+
TerminatorKind::Drop {
679+
place,
680+
target: _,
681+
unwind: _,
682+
replace,
683+
drop: _,
684+
async_fut: _,
685+
} => {
679686
debug!(
680687
"visit_terminator_drop \
681688
loc: {:?} term: {:?} place: {:?} span: {:?}",

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,14 @@ impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
9999
TerminatorKind::SwitchInt { discr, targets: _ } => {
100100
self.consume_operand(location, discr);
101101
}
102-
TerminatorKind::Drop { place: drop_place, target: _, unwind: _, replace } => {
102+
TerminatorKind::Drop {
103+
place: drop_place,
104+
target: _,
105+
unwind: _,
106+
replace,
107+
drop: _,
108+
async_fut: _,
109+
} => {
103110
let write_kind =
104111
if *replace { WriteKind::Replace } else { WriteKind::StorageDeadOrDrop };
105112
self.access_place(

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,8 +1684,14 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
16841684
}
16851685
}
16861686
TerminatorKind::Unreachable => {}
1687-
TerminatorKind::Drop { target, unwind, .. }
1688-
| TerminatorKind::Assert { target, unwind, .. } => {
1687+
TerminatorKind::Drop { target, unwind, drop, .. } => {
1688+
self.assert_iscleanup(body, block_data, target, is_cleanup);
1689+
self.assert_iscleanup_unwind(body, block_data, unwind, is_cleanup);
1690+
if let Some(drop) = drop {
1691+
self.assert_iscleanup(body, block_data, drop, is_cleanup);
1692+
}
1693+
}
1694+
TerminatorKind::Assert { target, unwind, .. } => {
16891695
self.assert_iscleanup(body, block_data, target, is_cleanup);
16901696
self.assert_iscleanup_unwind(body, block_data, unwind, is_cleanup);
16911697
}

compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,14 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
481481
| TerminatorKind::CoroutineDrop => {
482482
bug!("shouldn't exist at codegen {:?}", bb_data.terminator());
483483
}
484-
TerminatorKind::Drop { place, target, unwind: _, replace: _ } => {
484+
TerminatorKind::Drop {
485+
place,
486+
target,
487+
unwind: _,
488+
replace: _,
489+
drop: _,
490+
async_fut: _,
491+
} => {
485492
let drop_place = codegen_place(fx, *place);
486493
crate::abi::codegen_drop(fx, source_info, drop_place);
487494

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,9 +1232,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12321232
MergingSucc::False
12331233
}
12341234

1235-
mir::TerminatorKind::Drop { place, target, unwind, replace: _ } => {
1236-
self.codegen_drop_terminator(helper, bx, place, target, unwind, mergeable_succ())
1237-
}
1235+
mir::TerminatorKind::Drop {
1236+
place,
1237+
target,
1238+
unwind,
1239+
replace: _,
1240+
drop: _,
1241+
async_fut: _,
1242+
} => self.codegen_drop_terminator(helper, bx, place, target, unwind, mergeable_succ()),
12381243

12391244
mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, unwind } => self
12401245
.codegen_assert_terminator(

compiler/rustc_const_eval/src/const_eval/machine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
568568
RemainderByZero(op) => RemainderByZero(eval_to_int(op)?),
569569
ResumedAfterReturn(coroutine_kind) => ResumedAfterReturn(*coroutine_kind),
570570
ResumedAfterPanic(coroutine_kind) => ResumedAfterPanic(*coroutine_kind),
571+
ResumedAfterDrop(coroutine_kind) => ResumedAfterDrop(*coroutine_kind),
571572
MisalignedPointerDereference { ref required, ref found } => {
572573
MisalignedPointerDereference {
573574
required: eval_to_int(required)?,

compiler/rustc_const_eval/src/interpret/terminator.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
170170
}
171171
}
172172

173-
Drop { place, target, unwind, replace: _ } => {
173+
Drop { place, target, unwind, replace: _, drop: _, async_fut: _ } => {
174174
let frame = self.frame();
175175
let ty = place.ty(&frame.body.local_decls, *self.tcx).ty;
176176
let ty = self.subst_from_frame_and_normalize_erasing_regions(frame, ty)?;
@@ -542,6 +542,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
542542
| ty::InstanceDef::ReifyShim(..)
543543
| ty::InstanceDef::ClosureOnceShim { .. }
544544
| ty::InstanceDef::FnPtrShim(..)
545+
| ty::InstanceDef::FutureDropPollShim(..)
545546
| ty::InstanceDef::DropGlue(..)
546547
| ty::InstanceDef::CloneShim(..)
547548
| ty::InstanceDef::FnPtrAddrShim(..)

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,12 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
363363
);
364364
}
365365
}
366-
TerminatorKind::Drop { target, unwind, .. } => {
366+
TerminatorKind::Drop { target, unwind, drop, .. } => {
367367
self.check_edge(location, *target, EdgeKind::Normal);
368368
self.check_unwind_edge(location, *unwind);
369+
if let Some(drop) = drop {
370+
self.check_edge(location, *drop, EdgeKind::Normal);
371+
}
369372
}
370373
TerminatorKind::Call { args, destination, target, unwind, .. } => {
371374
if let Some(target) = target {

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ declare_features! (
355355
(unstable, associated_type_defaults, "1.2.0", Some(29661)),
356356
/// Allows `async || body` closures.
357357
(unstable, async_closure, "1.37.0", Some(62290)),
358+
/// Allows implementing `AsyncDrop`.
359+
(incomplete, async_drop, "CURRENT_RUSTC_VERSION", None),
358360
/// Allows `#[track_caller]` on async functions.
359361
(unstable, async_fn_track_caller, "1.73.0", Some(110011)),
360362
/// Allows `for await` loops.

compiler/rustc_hir/src/lang_items.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ language_item_table! {
163163

164164
Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None;
165165
Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None;
166+
AsyncDrop, sym::async_drop, async_drop_trait, Target::Trait, GenericRequirement::None;
167+
AsyncDropInPlace, sym::async_drop_in_place, async_drop_in_place_fn, Target::Fn, GenericRequirement::Exact(1);
168+
FutureDropPoll, sym::future_drop_poll, future_drop_poll_fn, Target::Fn, GenericRequirement::Exact(1);
166169

167170
CoerceUnsized, sym::coerce_unsized, coerce_unsized_trait, Target::Trait, GenericRequirement::Minimum(1);
168171
DispatchFromDyn, sym::dispatch_from_dyn, dispatch_from_dyn_trait, Target::Trait, GenericRequirement::Minimum(1);
@@ -260,6 +263,7 @@ language_item_table! {
260263

261264
ExchangeMalloc, sym::exchange_malloc, exchange_malloc_fn, Target::Fn, GenericRequirement::None;
262265
DropInPlace, sym::drop_in_place, drop_in_place_fn, Target::Fn, GenericRequirement::Minimum(1);
266+
DropInPlaceFuture, sym::drop_in_place_future,drop_in_place_future_fn, Target::Fn, GenericRequirement::Minimum(1);
263267
AllocLayout, sym::alloc_layout, alloc_layout, Target::Struct, GenericRequirement::None;
264268

265269
Start, sym::start, start_fn, Target::Fn, GenericRequirement::Exact(1);

0 commit comments

Comments
 (0)