@@ -219,8 +219,9 @@ impl<'tcx> Instance<'tcx> {
219219 InstanceDef :: Item ( def) => tcx
220220 . upstream_monomorphizations_for ( def)
221221 . and_then ( |monos| monos. get ( & self . args ) . cloned ( ) ) ,
222- InstanceDef :: DropGlue ( _, Some ( _) ) | InstanceDef :: AsyncDropGlueCtorShim ( _, _) => {
223- tcx. upstream_drop_glue_for ( self . args )
222+ InstanceDef :: DropGlue ( _, Some ( _) ) => tcx. upstream_drop_glue_for ( self . args ) ,
223+ InstanceDef :: AsyncDropGlueCtorShim ( _, Some ( _) ) => {
224+ tcx. upstream_async_drop_glue_for ( self . args )
224225 }
225226 _ => None ,
226227 }
@@ -256,7 +257,7 @@ impl<'tcx> InstanceDef<'tcx> {
256257 match self {
257258 ty:: InstanceDef :: Item ( def) => Some ( def) ,
258259 ty:: InstanceDef :: DropGlue ( def_id, Some ( _) )
259- | InstanceDef :: AsyncDropGlueCtorShim ( def_id, _ )
260+ | InstanceDef :: AsyncDropGlueCtorShim ( def_id, Some ( _ ) )
260261 | InstanceDef :: ThreadLocalShim ( def_id) => Some ( def_id) ,
261262 InstanceDef :: VTableShim ( ..)
262263 | InstanceDef :: ReifyShim ( ..)
@@ -267,6 +268,7 @@ impl<'tcx> InstanceDef<'tcx> {
267268 | ty:: InstanceDef :: ConstructCoroutineInClosureShim { .. }
268269 | ty:: InstanceDef :: CoroutineKindShim { .. }
269270 | InstanceDef :: DropGlue ( ..)
271+ | InstanceDef :: AsyncDropGlueCtorShim ( ..)
270272 | InstanceDef :: CloneShim ( ..)
271273 | InstanceDef :: FnPtrAddrShim ( ..) => None ,
272274 }
@@ -332,6 +334,26 @@ impl<'tcx> InstanceDef<'tcx> {
332334 . map_or_else ( || adt_def. is_enum ( ) , |dtor| tcx. cross_crate_inlinable ( dtor. did ) )
333335 } ) ;
334336 }
337+ if let ty:: InstanceDef :: AsyncDropGlueCtorShim ( .., Some ( ty) ) = * self {
338+ // Async drop glue generally wants to be instantiated at
339+ // every codegen unit, but without an #[inline] hint. We
340+ // should make this available to normal end-users.
341+ if tcx. sess . opts . incremental . is_none ( ) {
342+ return true ;
343+ }
344+ // When compiling with incremental, we can generate a *lot* of
345+ // codegen units. Including drop glue into all of them has a
346+ // considerable compile time cost.
347+ //
348+ // We include enums without destructors to allow, say, optimizing
349+ // drops of `Option::None` before LTO. We also respect the intent of
350+ // `#[inline]` on `Drop::drop` implementations.
351+ return ty. ty_adt_def ( ) . map_or ( true , |adt_def| {
352+ adt_def
353+ . async_destructor ( tcx)
354+ . map_or_else ( || adt_def. is_enum ( ) , |dtor| tcx. cross_crate_inlinable ( dtor. ctor ) )
355+ } ) ;
356+ }
335357 if let ty:: InstanceDef :: ThreadLocalShim ( ..) = * self {
336358 return false ;
337359 }
0 commit comments