diff options
| author | zetanumbers <dariasukhonina@gmail.com> | 2024-02-13 12:31:41 +0300 |
|---|---|---|
| committer | Daria Sukhonina <dariasukhonina@gmail.com> | 2024-04-16 20:45:07 +0300 |
| commit | 24a24ec6ba24bfe5e0980d22f585c98a608ec701 (patch) | |
| tree | 0f0eeced9b28d8c0cef3325886775aa27607dd67 /compiler/rustc_ty_utils | |
| parent | 1dea922ea6e74f99a0e97de5cdb8174e4dea0444 (diff) | |
| download | rust-24a24ec6ba24bfe5e0980d22f585c98a608ec701.tar.gz rust-24a24ec6ba24bfe5e0980d22f585c98a608ec701.zip | |
Add simple async drop glue generation
Explainer: https://zetanumbers.github.io/book/async-drop-design.html https://github.com/rust-lang/rust/pull/121801
Diffstat (limited to 'compiler/rustc_ty_utils')
| -rw-r--r-- | compiler/rustc_ty_utils/src/common_traits.rs | 21 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 41 |
2 files changed, 61 insertions, 1 deletions
diff --git a/compiler/rustc_ty_utils/src/common_traits.rs b/compiler/rustc_ty_utils/src/common_traits.rs index 51b908881eb..cb95239e991 100644 --- a/compiler/rustc_ty_utils/src/common_traits.rs +++ b/compiler/rustc_ty_utils/src/common_traits.rs @@ -22,6 +22,17 @@ fn is_unpin_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) is_item_raw(tcx, query, LangItem::Unpin) } +fn has_surface_async_drop_raw<'tcx>( + tcx: TyCtxt<'tcx>, + query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, +) -> bool { + is_item_raw(tcx, query, LangItem::AsyncDrop) +} + +fn has_surface_drop_raw<'tcx>(tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool { + is_item_raw(tcx, query, LangItem::Drop) +} + fn is_item_raw<'tcx>( tcx: TyCtxt<'tcx>, query: ty::ParamEnvAnd<'tcx, Ty<'tcx>>, @@ -34,5 +45,13 @@ fn is_item_raw<'tcx>( } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { is_copy_raw, is_sized_raw, is_freeze_raw, is_unpin_raw, ..*providers }; + *providers = Providers { + is_copy_raw, + is_sized_raw, + is_freeze_raw, + is_unpin_raw, + has_surface_async_drop_raw, + has_surface_drop_raw, + ..*providers + }; } diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index a8f9afb87dd..3a18f4d0939 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -54,6 +54,47 @@ fn resolve_instance<'tcx>( debug!(" => trivial drop glue"); ty::InstanceDef::DropGlue(def_id, None) } + } else if Some(def_id) == tcx.lang_items().async_drop_in_place_fn() { + let ty = args.type_at(0); + + match *ty.kind() { + ty::Array(..) + | ty::Slice(_) + | ty::Tuple(_) + | ty::Bool + | ty::Char + | ty::Int(_) + | ty::Uint(_) + | ty::Float(_) + | ty::Str + | ty::RawPtr(_, _) + | ty::Ref(..) + | ty::FnDef(..) + | ty::FnPtr(..) + | ty::Infer(ty::IntVar(_) | ty::FloatVar(_)) + | ty::Adt(..) + | ty::Closure(..) + | ty::CoroutineClosure(..) + | ty::CoroutineWitness(..) + | ty::Pat(..) + | ty::Never + | ty::Coroutine(..) => {} + + ty::Param(_) + | ty::Error(_) + | ty::Dynamic(..) + | ty::Alias(..) + | ty::Infer(ty::TyVar(_)) + | ty::Bound(..) + | ty::Foreign(_) + | ty::Placeholder(_) + | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => { + return Ok(None); + } + } + + debug!(" => async drop glue ctor"); + ty::InstanceDef::AsyncDropGlueCtorShim(def_id, ty) } else { debug!(" => free item"); // FIXME(effects): we may want to erase the effect param if that is present on this item. |
