about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2021-05-11 11:35:50 +0200
committerCamille GILLOT <gillot.camille@gmail.com>2021-05-12 13:58:42 +0200
commit3a729915da0e0658843b8c07a2156a8ca027ca77 (patch)
treedd37bb655d52ca20f91afa6c6141bd4d5f29f438
parent85a14d70bb2f094f67642ed22f5ffab4a4b9b719 (diff)
downloadrust-3a729915da0e0658843b8c07a2156a8ca027ca77.tar.gz
rust-3a729915da0e0658843b8c07a2156a8ca027ca77.zip
Use () in reachable_set.
-rw-r--r--compiler/rustc_codegen_ssa/src/back/symbol_export.rs12
-rw-r--r--compiler/rustc_middle/src/query/mod.rs6
-rw-r--r--compiler/rustc_mir/src/monomorphize/partitioning/default.rs12
-rw-r--r--compiler/rustc_passes/src/reachable.rs6
4 files changed, 16 insertions, 20 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
index 2bff2fcba43..ba85c70c4a5 100644
--- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
+++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
@@ -4,7 +4,7 @@ use rustc_ast::expand::allocator::ALLOCATOR_METHODS;
 use rustc_data_structures::fingerprint::Fingerprint;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_hir as hir;
-use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE};
+use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
 use rustc_hir::Node;
 use rustc_index::vec::IndexVec;
 use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
@@ -60,7 +60,7 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
         tcx.is_panic_runtime(LOCAL_CRATE) || tcx.is_compiler_builtins(LOCAL_CRATE);
 
     let mut reachable_non_generics: DefIdMap<_> = tcx
-        .reachable_set(LOCAL_CRATE)
+        .reachable_set(())
         .iter()
         .filter_map(|&def_id| {
             // We want to ignore some FFI functions that are not exposed from
@@ -355,12 +355,8 @@ fn upstream_drop_glue_for_provider<'tcx>(
     }
 }
 
-fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
-    if let Some(def_id) = def_id.as_local() {
-        !tcx.reachable_set(LOCAL_CRATE).contains(&def_id)
-    } else {
-        bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
-    }
+fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
+    !tcx.reachable_set(()).contains(&def_id)
 }
 
 pub fn provide(providers: &mut Providers) {
diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs
index 3fbb543536c..6788be90116 100644
--- a/compiler/rustc_middle/src/query/mod.rs
+++ b/compiler/rustc_middle/src/query/mod.rs
@@ -855,7 +855,7 @@ rustc_queries! {
         desc { "checking for private elements in public interfaces" }
     }
 
-    query reachable_set(_: CrateNum) -> FxHashSet<LocalDefId> {
+    query reachable_set(_: ()) -> FxHashSet<LocalDefId> {
         storage(ArenaCacheSelector<'tcx>)
         desc { "reachability" }
     }
@@ -1141,10 +1141,10 @@ rustc_queries! {
     query is_reachable_non_generic(def_id: DefId) -> bool {
         desc { |tcx| "checking whether `{}` is an exported symbol", tcx.def_path_str(def_id) }
     }
-    query is_unreachable_local_definition(def_id: DefId) -> bool {
+    query is_unreachable_local_definition(def_id: LocalDefId) -> bool {
         desc { |tcx|
             "checking whether `{}` is reachable from outside the crate",
-            tcx.def_path_str(def_id),
+            tcx.def_path_str(def_id.to_def_id()),
         }
     }
 
diff --git a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs
index edd46310f20..541c825416c 100644
--- a/compiler/rustc_mir/src/monomorphize/partitioning/default.rs
+++ b/compiler/rustc_mir/src/monomorphize/partitioning/default.rs
@@ -451,7 +451,9 @@ fn mono_item_visibility(
     let is_generic = instance.substs.non_erasable_generics().next().is_some();
 
     // Upstream `DefId` instances get different handling than local ones.
-    if !def_id.is_local() {
+    let def_id = if let Some(def_id) = def_id.as_local() {
+        def_id
+    } else {
         return if export_generics && is_generic {
             // If it is a upstream monomorphization and we export generics, we must make
             // it available to downstream crates.
@@ -460,7 +462,7 @@ fn mono_item_visibility(
         } else {
             Visibility::Hidden
         };
-    }
+    };
 
     if is_generic {
         if export_generics {
@@ -470,7 +472,7 @@ fn mono_item_visibility(
             } else {
                 // This instance might be useful in a downstream crate.
                 *can_be_internalized = false;
-                default_visibility(tcx, def_id, true)
+                default_visibility(tcx, def_id.to_def_id(), true)
             }
         } else {
             // We are not exporting generics or the definition is not reachable
@@ -481,10 +483,10 @@ fn mono_item_visibility(
         // If this isn't a generic function then we mark this a `Default` if
         // this is a reachable item, meaning that it's a symbol other crates may
         // access when they link to us.
-        if tcx.is_reachable_non_generic(def_id) {
+        if tcx.is_reachable_non_generic(def_id.to_def_id()) {
             *can_be_internalized = false;
             debug_assert!(!is_generic);
-            return default_visibility(tcx, def_id, false);
+            return default_visibility(tcx, def_id.to_def_id(), false);
         }
 
         // If this isn't reachable then we're gonna tag this with `Hidden`
diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs
index 20aaaea5b98..7ceeb4b97db 100644
--- a/compiler/rustc_passes/src/reachable.rs
+++ b/compiler/rustc_passes/src/reachable.rs
@@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
 use rustc_hir as hir;
 use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::LOCAL_CRATE;
-use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
+use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
 use rustc_hir::itemlikevisit::ItemLikeVisitor;
 use rustc_hir::Node;
@@ -386,9 +386,7 @@ impl<'a, 'tcx> ItemLikeVisitor<'tcx> for CollectPrivateImplItemsVisitor<'a, 'tcx
     }
 }
 
-fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, crate_num: CrateNum) -> FxHashSet<LocalDefId> {
-    debug_assert!(crate_num == LOCAL_CRATE);
-
+fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> {
     let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
 
     let any_library =