@@ -255,14 +255,13 @@ fn exported_symbols_provider_local(
255
255
symbols. push ( ( symbol, SymbolExportLevel :: Rust ) ) ;
256
256
}
257
257
}
258
- MonoItem :: Fn ( Instance { def : InstanceDef :: DropGlue ( def_id , Some ( ty) ) , substs } ) => {
258
+ MonoItem :: Fn ( Instance { def : InstanceDef :: DropGlue ( _ , Some ( ty) ) , substs } ) => {
259
259
// A little sanity-check
260
260
debug_assert_eq ! (
261
261
substs. non_erasable_generics( ) . next( ) ,
262
262
Some ( GenericArgKind :: Type ( ty) )
263
263
) ;
264
- let symbol = ExportedSymbol :: Generic ( def_id, substs) ;
265
- symbols. push ( ( symbol, SymbolExportLevel :: Rust ) ) ;
264
+ symbols. push ( ( ExportedSymbol :: DropGlue ( ty) , SymbolExportLevel :: Rust ) ) ;
266
265
}
267
266
_ => {
268
267
// Any other symbols don't qualify for sharing
@@ -298,24 +297,41 @@ fn upstream_monomorphizations_provider(
298
297
cnum_stable_ids
299
298
} ;
300
299
300
+ let drop_in_place_fn_def_id = tcx. lang_items ( ) . drop_in_place_fn ( ) ;
301
+
301
302
for & cnum in cnums. iter ( ) {
302
303
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 ;
314
313
}
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] {
316
329
e. insert ( cnum) ;
317
330
}
318
331
}
332
+ Vacant ( e) => {
333
+ e. insert ( cnum) ;
334
+ }
319
335
}
320
336
}
321
337
}
@@ -331,6 +347,17 @@ fn upstream_monomorphizations_for_provider(
331
347
tcx. upstream_monomorphizations ( LOCAL_CRATE ) . get ( & def_id)
332
348
}
333
349
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
+
334
361
fn is_unreachable_local_definition_provider ( tcx : TyCtxt < ' _ > , def_id : DefId ) -> bool {
335
362
if let Some ( hir_id) = tcx. hir ( ) . as_local_hir_id ( def_id) {
336
363
!tcx. reachable_set ( LOCAL_CRATE ) . contains ( & hir_id)
@@ -345,6 +372,7 @@ pub fn provide(providers: &mut Providers<'_>) {
345
372
providers. exported_symbols = exported_symbols_provider_local;
346
373
providers. upstream_monomorphizations = upstream_monomorphizations_provider;
347
374
providers. is_unreachable_local_definition = is_unreachable_local_definition_provider;
375
+ providers. upstream_drop_glue_for = upstream_drop_glue_for_provider;
348
376
}
349
377
350
378
pub fn provide_extern ( providers : & mut Providers < ' _ > ) {
@@ -405,6 +433,11 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
405
433
Instance :: new ( def_id, substs) ,
406
434
instantiating_crate,
407
435
) ,
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
+ ) ,
408
441
ExportedSymbol :: NoDefId ( symbol_name) => symbol_name. to_string ( ) ,
409
442
}
410
443
}
0 commit comments