Use () in reachable_set.

This commit is contained in:
Camille GILLOT 2021-05-11 11:35:50 +02:00
parent 85a14d70bb
commit 3a729915da
4 changed files with 16 additions and 20 deletions

View File

@ -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) {

View File

@ -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()),
}
}

View File

@ -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`

View File

@ -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 =