Make async drop code more consistent with regular drop code
Fixes #126573
This commit is contained in:
parent
f873ae029e
commit
af10880f6b
4 changed files with 67 additions and 14 deletions
|
@ -219,8 +219,9 @@ impl<'tcx> Instance<'tcx> {
|
|||
InstanceKind::Item(def) => tcx
|
||||
.upstream_monomorphizations_for(def)
|
||||
.and_then(|monos| monos.get(&self.args).cloned()),
|
||||
InstanceKind::DropGlue(_, Some(_)) | InstanceKind::AsyncDropGlueCtorShim(_, _) => {
|
||||
tcx.upstream_drop_glue_for(self.args)
|
||||
InstanceKind::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
|
||||
InstanceKind::AsyncDropGlueCtorShim(_, Some(_)) => {
|
||||
tcx.upstream_async_drop_glue_for(self.args)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -256,7 +257,7 @@ impl<'tcx> InstanceKind<'tcx> {
|
|||
match self {
|
||||
ty::InstanceKind::Item(def) => Some(def),
|
||||
ty::InstanceKind::DropGlue(def_id, Some(_))
|
||||
| InstanceKind::AsyncDropGlueCtorShim(def_id, _)
|
||||
| InstanceKind::AsyncDropGlueCtorShim(def_id, Some(_))
|
||||
| InstanceKind::ThreadLocalShim(def_id) => Some(def_id),
|
||||
InstanceKind::VTableShim(..)
|
||||
| InstanceKind::ReifyShim(..)
|
||||
|
@ -267,6 +268,7 @@ impl<'tcx> InstanceKind<'tcx> {
|
|||
| ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
|
||||
| ty::InstanceKind::CoroutineKindShim { .. }
|
||||
| InstanceKind::DropGlue(..)
|
||||
| InstanceKind::AsyncDropGlueCtorShim(..)
|
||||
| InstanceKind::CloneShim(..)
|
||||
| InstanceKind::FnPtrAddrShim(..) => None,
|
||||
}
|
||||
|
@ -332,6 +334,26 @@ impl<'tcx> InstanceKind<'tcx> {
|
|||
.map_or_else(|| adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.did))
|
||||
});
|
||||
}
|
||||
if let ty::InstanceKind::AsyncDropGlueCtorShim(.., Some(ty)) = *self {
|
||||
// Async drop glue generally wants to be instantiated at
|
||||
// every codegen unit, but without an #[inline] hint. We
|
||||
// should make this available to normal end-users.
|
||||
if tcx.sess.opts.incremental.is_none() {
|
||||
return true;
|
||||
}
|
||||
// When compiling with incremental, we can generate a *lot* of
|
||||
// codegen units. Including drop glue into all of them has a
|
||||
// considerable compile time cost.
|
||||
//
|
||||
// We include enums without destructors to allow, say, optimizing
|
||||
// drops of `Option::None` before LTO. We also respect the intent of
|
||||
// `#[inline]` on `Drop::drop` implementations.
|
||||
return ty.ty_adt_def().map_or(true, |adt_def| {
|
||||
adt_def
|
||||
.async_destructor(tcx)
|
||||
.map_or_else(|| adt_def.is_enum(), |dtor| tcx.cross_crate_inlinable(dtor.ctor))
|
||||
});
|
||||
}
|
||||
if let ty::InstanceKind::ThreadLocalShim(..) = *self {
|
||||
return false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue