about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo>2020-01-22 12:17:21 +0100
committerMichael Woerister <michaelwoerister@posteo>2020-01-23 16:56:59 +0100
commit197cc1e43afba388a0266a08d2b946a187b766bb (patch)
tree74a4b064655c776105752655c23056ab580683e8 /src/librustc_codegen_ssa
parent2ceb92bc53a849e36341c3fd619cb49470e224e2 (diff)
Add projection query for upstream drop-glue instances.
This reduces the amount of invalidated data when new types are
add to upstream crates.
Diffstat (limited to 'src/librustc_codegen_ssa')
-rw-r--r--src/librustc_codegen_ssa/back/symbol_export.rs63
1 files changed, 48 insertions, 15 deletions
diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs
index 7e888a271e3..a6cd0c09684 100644
--- a/src/librustc_codegen_ssa/back/symbol_export.rs
+++ b/src/librustc_codegen_ssa/back/symbol_export.rs
@@ -255,14 +255,13 @@ fn exported_symbols_provider_local(
                         symbols.push((symbol, SymbolExportLevel::Rust));
                     }
                 }
-                MonoItem::Fn(Instance { def: InstanceDef::DropGlue(def_id, Some(ty)), substs }) => {
+                MonoItem::Fn(Instance { def: InstanceDef::DropGlue(_, Some(ty)), substs }) => {
                     // A little sanity-check
                     debug_assert_eq!(
                         substs.non_erasable_generics().next(),
                         Some(GenericArgKind::Type(ty))
                     );
-                    let symbol = ExportedSymbol::Generic(def_id, substs);
-                    symbols.push((symbol, SymbolExportLevel::Rust));
+                    symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportLevel::Rust));
                 }
                 _ => {
                     // Any other symbols don't qualify for sharing
@@ -298,24 +297,41 @@ fn upstream_monomorphizations_provider(
         cnum_stable_ids
     };
 
+    let drop_in_place_fn_def_id = tcx.lang_items().drop_in_place_fn();
+
     for &cnum in cnums.iter() {
         for (exported_symbol, _) in tcx.exported_symbols(cnum).iter() {
-            if let &ExportedSymbol::Generic(def_id, substs) = exported_symbol {
-                let substs_map = instances.entry(def_id).or_default();
-
-                match substs_map.entry(substs) {
-                    Occupied(mut e) => {
-                        // If there are multiple monomorphizations available,
-                        // we select one deterministically.
-                        let other_cnum = *e.get();
-                        if cnum_stable_ids[other_cnum] > cnum_stable_ids[cnum] {
-                            e.insert(cnum);
-                        }
+            let (def_id, substs) = match *exported_symbol {
+                ExportedSymbol::Generic(def_id, substs) => (def_id, substs),
+                ExportedSymbol::DropGlue(ty) => {
+                    if let Some(drop_in_place_fn_def_id) = drop_in_place_fn_def_id {
+                        (drop_in_place_fn_def_id, tcx.intern_substs(&[ty.into()]))
+                    } else {
+                        // `drop_in_place` in place does not exist, don't try
+                        // to use it.
+                        continue;
                     }
-                    Vacant(e) => {
+                }
+                ExportedSymbol::NonGeneric(..) | ExportedSymbol::NoDefId(..) => {
+                    // These are no monomorphizations
+                    continue;
+                }
+            };
+
+            let substs_map = instances.entry(def_id).or_default();
+
+            match substs_map.entry(substs) {
+                Occupied(mut e) => {
+                    // If there are multiple monomorphizations available,
+                    // we select one deterministically.
+                    let other_cnum = *e.get();
+                    if cnum_stable_ids[other_cnum] > cnum_stable_ids[cnum] {
                         e.insert(cnum);
                     }
                 }
+                Vacant(e) => {
+                    e.insert(cnum);
+                }
             }
         }
     }
@@ -331,6 +347,17 @@ fn upstream_monomorphizations_for_provider(
     tcx.upstream_monomorphizations(LOCAL_CRATE).get(&def_id)
 }
 
+fn upstream_drop_glue_for_provider<'tcx>(
+    tcx: TyCtxt<'tcx>,
+    substs: SubstsRef<'tcx>,
+) -> Option<CrateNum> {
+    if let Some(def_id) = tcx.lang_items().drop_in_place_fn() {
+        tcx.upstream_monomorphizations_for(def_id).and_then(|monos| monos.get(&substs).cloned())
+    } else {
+        None
+    }
+}
+
 fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
     if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
         !tcx.reachable_set(LOCAL_CRATE).contains(&hir_id)
@@ -345,6 +372,7 @@ pub fn provide(providers: &mut Providers<'_>) {
     providers.exported_symbols = exported_symbols_provider_local;
     providers.upstream_monomorphizations = upstream_monomorphizations_provider;
     providers.is_unreachable_local_definition = is_unreachable_local_definition_provider;
+    providers.upstream_drop_glue_for = upstream_drop_glue_for_provider;
 }
 
 pub fn provide_extern(providers: &mut Providers<'_>) {
@@ -405,6 +433,11 @@ pub fn symbol_name_for_instance_in_crate<'tcx>(
             Instance::new(def_id, substs),
             instantiating_crate,
         ),
+        ExportedSymbol::DropGlue(ty) => symbol_names::symbol_name_for_instance_in_crate(
+            tcx,
+            Instance::resolve_drop_in_place(tcx, ty),
+            instantiating_crate,
+        ),
         ExportedSymbol::NoDefId(symbol_name) => symbol_name.to_string(),
     }
 }