1
Fork 0

Add simple async drop glue generation

Explainer: https://zetanumbers.github.io/book/async-drop-design.html

https://github.com/rust-lang/rust/pull/121801
This commit is contained in:
zetanumbers 2024-02-13 12:31:41 +03:00 committed by Daria Sukhonina
parent 1dea922ea6
commit 24a24ec6ba
40 changed files with 1921 additions and 20 deletions

View file

@ -168,6 +168,12 @@ pub enum InstanceDef<'tcx> {
///
/// The `DefId` is for `FnPtr::addr`, the `Ty` is the type `T`.
FnPtrAddrShim(DefId, Ty<'tcx>),
/// `core::future::async_drop::async_drop_in_place::<'_, T>`.
///
/// The `DefId` is for `core::future::async_drop::async_drop_in_place`, the `Ty`
/// is the type `T`.
AsyncDropGlueCtorShim(DefId, Ty<'tcx>),
}
impl<'tcx> Instance<'tcx> {
@ -210,7 +216,9 @@ impl<'tcx> Instance<'tcx> {
InstanceDef::Item(def) => tcx
.upstream_monomorphizations_for(def)
.and_then(|monos| monos.get(&self.args).cloned()),
InstanceDef::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.args),
InstanceDef::DropGlue(_, Some(_)) | InstanceDef::AsyncDropGlueCtorShim(_, _) => {
tcx.upstream_drop_glue_for(self.args)
}
_ => None,
}
}
@ -235,7 +243,8 @@ impl<'tcx> InstanceDef<'tcx> {
| ty::InstanceDef::CoroutineKindShim { coroutine_def_id: def_id }
| InstanceDef::DropGlue(def_id, _)
| InstanceDef::CloneShim(def_id, _)
| InstanceDef::FnPtrAddrShim(def_id, _) => def_id,
| InstanceDef::FnPtrAddrShim(def_id, _)
| InstanceDef::AsyncDropGlueCtorShim(def_id, _) => def_id,
}
}
@ -243,9 +252,9 @@ impl<'tcx> InstanceDef<'tcx> {
pub fn def_id_if_not_guaranteed_local_codegen(self) -> Option<DefId> {
match self {
ty::InstanceDef::Item(def) => Some(def),
ty::InstanceDef::DropGlue(def_id, Some(_)) | InstanceDef::ThreadLocalShim(def_id) => {
Some(def_id)
}
ty::InstanceDef::DropGlue(def_id, Some(_))
| InstanceDef::AsyncDropGlueCtorShim(def_id, _)
| InstanceDef::ThreadLocalShim(def_id) => Some(def_id),
InstanceDef::VTableShim(..)
| InstanceDef::ReifyShim(..)
| InstanceDef::FnPtrShim(..)
@ -347,7 +356,8 @@ impl<'tcx> InstanceDef<'tcx> {
| InstanceDef::ThreadLocalShim(..)
| InstanceDef::FnPtrAddrShim(..)
| InstanceDef::FnPtrShim(..)
| InstanceDef::DropGlue(_, Some(_)) => false,
| InstanceDef::DropGlue(_, Some(_))
| InstanceDef::AsyncDropGlueCtorShim(..) => false,
InstanceDef::ClosureOnceShim { .. }
| InstanceDef::ConstructCoroutineInClosureShim { .. }
| InstanceDef::CoroutineKindShim { .. }
@ -396,6 +406,7 @@ fn fmt_instance(
InstanceDef::DropGlue(_, Some(ty)) => write!(f, " - shim(Some({ty}))"),
InstanceDef::CloneShim(_, ty) => write!(f, " - shim({ty})"),
InstanceDef::FnPtrAddrShim(_, ty) => write!(f, " - shim({ty})"),
InstanceDef::AsyncDropGlueCtorShim(_, ty) => write!(f, " - shim({ty})"),
}
}
@ -638,6 +649,12 @@ impl<'tcx> Instance<'tcx> {
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
}
pub fn resolve_async_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> {
let def_id = tcx.require_lang_item(LangItem::AsyncDropInPlace, None);
let args = tcx.mk_args(&[ty.into()]);
Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args)
}
#[instrument(level = "debug", skip(tcx), ret)]
pub fn fn_once_adapter_instance(
tcx: TyCtxt<'tcx>,