@@ -255,14 +255,13 @@ fn exported_symbols_provider_local(
255255 symbols. push ( ( symbol, SymbolExportLevel :: Rust ) ) ;
256256 }
257257 }
258- MonoItem :: Fn ( Instance { def : InstanceDef :: DropGlue ( def_id , Some ( ty) ) , substs } ) => {
258+ MonoItem :: Fn ( Instance { def : InstanceDef :: DropGlue ( _ , Some ( ty) ) , substs } ) => {
259259 // A little sanity-check
260260 debug_assert_eq ! (
261261 substs. non_erasable_generics( ) . next( ) ,
262262 Some ( GenericArgKind :: Type ( ty) )
263263 ) ;
264- let symbol = ExportedSymbol :: Generic ( def_id, substs) ;
265- symbols. push ( ( symbol, SymbolExportLevel :: Rust ) ) ;
264+ symbols. push ( ( ExportedSymbol :: DropGlue ( ty) , SymbolExportLevel :: Rust ) ) ;
266265 }
267266 _ => {
268267 // Any other symbols don't qualify for sharing
@@ -298,24 +297,41 @@ fn upstream_monomorphizations_provider(
298297 cnum_stable_ids
299298 } ;
300299
300+ let drop_in_place_fn_def_id = tcx. lang_items ( ) . drop_in_place_fn ( ) ;
301+
301302 for & cnum in cnums. iter ( ) {
302303 for ( exported_symbol, _) in tcx. exported_symbols ( cnum) . iter ( ) {
303- if let & ExportedSymbol :: Generic ( def_id, substs) = exported_symbol {
304- let substs_map = instances. entry ( def_id) . or_default ( ) ;
305-
306- match substs_map. entry ( substs) {
307- Occupied ( mut e) => {
308- // If there are multiple monomorphizations available,
309- // we select one deterministically.
310- let other_cnum = * e. get ( ) ;
311- if cnum_stable_ids[ other_cnum] > cnum_stable_ids[ cnum] {
312- e. insert ( cnum) ;
313- }
304+ let ( def_id, substs) = match * exported_symbol {
305+ ExportedSymbol :: Generic ( def_id, substs) => ( def_id, substs) ,
306+ ExportedSymbol :: DropGlue ( ty) => {
307+ if let Some ( drop_in_place_fn_def_id) = drop_in_place_fn_def_id {
308+ ( drop_in_place_fn_def_id, tcx. intern_substs ( & [ ty. into ( ) ] ) )
309+ } else {
310+ // `drop_in_place` in place does not exist, don't try
311+ // to use it.
312+ continue ;
314313 }
315- Vacant ( e) => {
314+ }
315+ ExportedSymbol :: NonGeneric ( ..) | ExportedSymbol :: NoDefId ( ..) => {
316+ // These are no monomorphizations
317+ continue ;
318+ }
319+ } ;
320+
321+ let substs_map = instances. entry ( def_id) . or_default ( ) ;
322+
323+ match substs_map. entry ( substs) {
324+ Occupied ( mut e) => {
325+ // If there are multiple monomorphizations available,
326+ // we select one deterministically.
327+ let other_cnum = * e. get ( ) ;
328+ if cnum_stable_ids[ other_cnum] > cnum_stable_ids[ cnum] {
316329 e. insert ( cnum) ;
317330 }
318331 }
332+ Vacant ( e) => {
333+ e. insert ( cnum) ;
334+ }
319335 }
320336 }
321337 }
@@ -331,6 +347,17 @@ fn upstream_monomorphizations_for_provider(
331347 tcx. upstream_monomorphizations ( LOCAL_CRATE ) . get ( & def_id)
332348}
333349
350+ fn upstream_drop_glue_for_provider < ' tcx > (
351+ tcx : TyCtxt < ' tcx > ,
352+ substs : SubstsRef < ' tcx > ,
353+ ) -> Option < CrateNum > {
354+ if let Some ( def_id) = tcx. lang_items ( ) . drop_in_place_fn ( ) {
355+ tcx. upstream_monomorphizations_for ( def_id) . and_then ( |monos| monos. get ( & substs) . cloned ( ) )
356+ } else {
357+ None
358+ }
359+ }
360+
334361fn is_unreachable_local_definition_provider ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
335362 if let Some ( hir_id) = tcx. hir ( ) . as_local_hir_id ( def_id) {
336363 !tcx. reachable_set ( LOCAL_CRATE ) . contains ( & hir_id)
@@ -345,6 +372,7 @@ pub fn provide(providers: &mut Providers<'_>) {
345372 providers. exported_symbols = exported_symbols_provider_local;
346373 providers. upstream_monomorphizations = upstream_monomorphizations_provider;
347374 providers. is_unreachable_local_definition = is_unreachable_local_definition_provider;
375+ providers. upstream_drop_glue_for = upstream_drop_glue_for_provider;
348376}
349377
350378pub fn provide_extern ( providers : & mut Providers < ' _ > ) {
@@ -405,6 +433,11 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
405433 Instance :: new ( def_id, substs) ,
406434 instantiating_crate,
407435 ) ,
436+ ExportedSymbol :: DropGlue ( ty) => symbol_names:: symbol_name_for_instance_in_crate (
437+ tcx,
438+ Instance :: resolve_drop_in_place ( tcx, ty) ,
439+ instantiating_crate,
440+ ) ,
408441 ExportedSymbol :: NoDefId ( symbol_name) => symbol_name. to_string ( ) ,
409442 }
410443}
0 commit comments