Skip to content

Commit

Permalink
Rename exported_symbol_ids query to something more explicit and docum…
Browse files Browse the repository at this point in the history
…ent what it is doing.
  • Loading branch information
michaelwoerister committed Mar 6, 2018
1 parent 1733a61 commit e5ee011
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 47 deletions.
4 changes: 2 additions & 2 deletions src/librustc/dep_graph/dep_node.rs
Expand Up @@ -556,7 +556,7 @@ define_dep_nodes!( <'tcx>
[] RvaluePromotableMap(DefId),
[] ImplParent(DefId),
[] TraitOfItem(DefId),
[] IsExportedSymbol(DefId),
[] IsReachableNonGeneric(DefId),
[] IsMirAvailable(DefId),
[] ItemAttrs(DefId),
[] FnArgNames(DefId),
Expand All @@ -574,7 +574,7 @@ define_dep_nodes!( <'tcx>
[] GetPanicStrategy(CrateNum),
[] IsNoBuiltins(CrateNum),
[] ImplDefaultness(DefId),
[] ExportedSymbolIds(CrateNum),
[] ReachableNonGenerics(CrateNum),
[] NativeLibraries(CrateNum),
[] PluginRegistrarFn(CrateNum),
[] DeriveRegistrarFn(CrateNum),
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/ty/maps/config.rs
Expand Up @@ -212,9 +212,9 @@ impl<'tcx> QueryDescription<'tcx> for queries::item_attrs<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::is_exported_symbol<'tcx> {
impl<'tcx> QueryDescription<'tcx> for queries::is_reachable_non_generic<'tcx> {
fn describe(_: TyCtxt, _: DefId) -> String {
bug!("is_exported_symbol")
bug!("is_reachable_non_generic")
}
}

Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::is_sanitizer_runtime<'tcx> {
}
}

impl<'tcx> QueryDescription<'tcx> for queries::exported_symbol_ids<'tcx> {
impl<'tcx> QueryDescription<'tcx> for queries::reachable_non_generics<'tcx> {
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
format!("looking up the exported symbols of a crate")
}
Expand Down
19 changes: 17 additions & 2 deletions src/librustc/ty/maps/mod.rs
Expand Up @@ -238,7 +238,6 @@ define_maps! { <'tcx>
[] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
[] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
[] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
[] fn is_exported_symbol: IsExportedSymbol(DefId) -> bool,
[] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> ExternBodyNestedBodies,
[] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
[] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
Expand Down Expand Up @@ -290,7 +289,23 @@ define_maps! { <'tcx>
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,

[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
[] fn exported_symbol_ids: ExportedSymbolIds(CrateNum) -> Lrc<DefIdSet>,

// The DefIds of all non-generic functions and statics in the given crate
// that can be reached from outside the crate.
//
// We expect this items to be available for being linked to.
//
// This query can also be called for LOCAL_CRATE. In this case it will
// compute which items will be reachable to other crates, taking into account
// the kind of crate that is currently compiled. Crates with only a
// C interface have fewer reachable things.
//
// Does not include external symbols that don't have a corresponding DefId,
// like the compiler-generated `main` function and so on.
[] fn reachable_non_generics: ReachableNonGenerics(CrateNum) -> Lrc<DefIdSet>,
[] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,


[] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
[] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/maps/plumbing.rs
Expand Up @@ -851,7 +851,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::RvaluePromotableMap => { force!(rvalue_promotable_map, def_id!()); }
DepKind::ImplParent => { force!(impl_parent, def_id!()); }
DepKind::TraitOfItem => { force!(trait_of_item, def_id!()); }
DepKind::IsExportedSymbol => { force!(is_exported_symbol, def_id!()); }
DepKind::IsReachableNonGeneric => { force!(is_reachable_non_generic, def_id!()); }
DepKind::IsMirAvailable => { force!(is_mir_available, def_id!()); }
DepKind::ItemAttrs => { force!(item_attrs, def_id!()); }
DepKind::FnArgNames => { force!(fn_arg_names, def_id!()); }
Expand All @@ -868,7 +868,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
DepKind::GetPanicStrategy => { force!(panic_strategy, krate!()); }
DepKind::IsNoBuiltins => { force!(is_no_builtins, krate!()); }
DepKind::ImplDefaultness => { force!(impl_defaultness, def_id!()); }
DepKind::ExportedSymbolIds => { force!(exported_symbol_ids, krate!()); }
DepKind::ReachableNonGenerics => { force!(reachable_non_generics, krate!()); }
DepKind::NativeLibraries => { force!(native_libraries, krate!()); }
DepKind::PluginRegistrarFn => { force!(plugin_registrar_fn, krate!()); }
DepKind::DeriveRegistrarFn => { force!(derive_registrar_fn, krate!()); }
Expand Down
4 changes: 0 additions & 4 deletions src/librustc_metadata/creader.rs
Expand Up @@ -225,9 +225,6 @@ impl<'a> CrateLoader<'a> {
crate_root.def_path_table.decode((&metadata, self.sess))
});

let exported_symbols = crate_root.exported_symbols
.decode((&metadata, self.sess))
.collect();
let trait_impls = crate_root
.impls
.decode((&metadata, self.sess))
Expand All @@ -238,7 +235,6 @@ impl<'a> CrateLoader<'a> {
name,
extern_crate: Cell::new(None),
def_path_table: Lrc::new(def_path_table),
exported_symbols,
trait_impls,
proc_macros: crate_root.macro_derive_registrar.map(|_| {
self.load_derive_macros(&crate_root, dylib.clone().map(|p| p.0), span)
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_metadata/cstore.rs
Expand Up @@ -78,8 +78,6 @@ pub struct CrateMetadata {
/// compilation support.
pub def_path_table: Lrc<DefPathTable>,

pub exported_symbols: FxHashSet<DefIndex>,

pub trait_impls: FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>,

pub dep_kind: Cell<DepKind>,
Expand Down
5 changes: 1 addition & 4 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -160,9 +160,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
impl_parent => { cdata.get_parent_impl(def_id.index) }
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
is_exported_symbol => {
cdata.exported_symbols.contains(&def_id.index)
}
item_body_nested_bodies => { cdata.item_body_nested_bodies(def_id.index) }
const_is_rvalue_promotable_to_static => {
cdata.const_is_rvalue_promotable_to_static(def_id.index)
Expand All @@ -179,7 +176,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
extern_crate => { Lrc::new(cdata.extern_crate.get()) }
is_no_builtins => { cdata.is_no_builtins(tcx.sess) }
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
exported_symbol_ids => { Lrc::new(cdata.get_exported_symbols()) }
reachable_non_generics => { Lrc::new(cdata.reachable_non_generics()) }
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
plugin_registrar_fn => {
cdata.root.plugin_registrar_fn.map(|index| {
Expand Down
9 changes: 5 additions & 4 deletions src/librustc_metadata/decoder.rs
Expand Up @@ -1006,10 +1006,11 @@ impl<'a, 'tcx> CrateMetadata {
arg_names.decode(self).collect()
}

pub fn get_exported_symbols(&self) -> DefIdSet {
self.exported_symbols
.iter()
.map(|&index| self.local_def_id(index))
pub fn reachable_non_generics(&self) -> DefIdSet {
self.root
.reachable_non_generics
.decode(self)
.map(|index| self.local_def_id(index))
.collect()
}

Expand Down
25 changes: 14 additions & 11 deletions src/librustc_metadata/encoder.rs
Expand Up @@ -53,7 +53,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
opaque: opaque::Encoder<'a>,
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &'a LinkMeta,
exported_symbols: &'a NodeSet,
reachable_non_generics: &'a NodeSet,

lazy_state: LazyState,
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
Expand Down Expand Up @@ -395,10 +395,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

// Encode exported symbols info.
i = self.position();
let exported_symbols = self.tracked(
IsolatedEncoder::encode_exported_symbols,
self.exported_symbols);
let exported_symbols_bytes = self.position() - i;
let reachable_non_generics = self.tracked(
IsolatedEncoder::encode_reachable_non_generics,
self.reachable_non_generics);
let reachable_non_generics_bytes = self.position() - i;

// Encode and index the items.
i = self.position();
Expand Down Expand Up @@ -442,7 +442,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
codemap,
def_path_table,
impls,
exported_symbols,
reachable_non_generics,
index,
});

Expand All @@ -462,7 +462,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
println!(" native bytes: {}", native_lib_bytes);
println!(" codemap bytes: {}", codemap_bytes);
println!(" impl bytes: {}", impl_bytes);
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
println!(" exp. symbols bytes: {}", reachable_non_generics_bytes);
println!(" def-path table bytes: {}", def_path_table_bytes);
println!(" item bytes: {}", item_bytes);
println!(" index bytes: {}", index_bytes);
Expand Down Expand Up @@ -1388,9 +1388,12 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
// middle::reachable module but filters out items that either don't have a
// symbol associated with them (they weren't translated) or if they're an FFI
// definition (as that's not defined in this crate).
fn encode_exported_symbols(&mut self, exported_symbols: &NodeSet) -> LazySeq<DefIndex> {
fn encode_reachable_non_generics(&mut self,
reachable_non_generics: &NodeSet)
-> LazySeq<DefIndex> {
let tcx = self.tcx;
self.lazy_seq(exported_symbols.iter().map(|&id| tcx.hir.local_def_id(id).index))
self.lazy_seq(reachable_non_generics.iter()
.map(|&id| tcx.hir.local_def_id(id).index))
}

fn encode_dylib_dependency_formats(&mut self, _: ()) -> LazySeq<Option<LinkagePreference>> {
Expand Down Expand Up @@ -1664,7 +1667,7 @@ impl<'a, 'tcx, 'v> ItemLikeVisitor<'v> for ImplVisitor<'a, 'tcx> {

pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
link_meta: &LinkMeta,
exported_symbols: &NodeSet)
reachable_non_generics: &NodeSet)
-> EncodedMetadata
{
let mut cursor = Cursor::new(vec![]);
Expand All @@ -1678,7 +1681,7 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
opaque: opaque::Encoder::new(&mut cursor),
tcx,
link_meta,
exported_symbols,
reachable_non_generics,
lazy_state: LazyState::NoNode,
type_shorthands: Default::default(),
predicate_shorthands: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/schema.rs
Expand Up @@ -202,7 +202,7 @@ pub struct CrateRoot {
pub codemap: LazySeq<syntax_pos::FileMap>,
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
pub impls: LazySeq<TraitImpls>,
pub exported_symbols: LazySeq<DefIndex>,
pub reachable_non_generics: LazySeq<DefIndex>,
pub index: LazySeq<index::Index>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/monomorphize/collector.rs
Expand Up @@ -736,7 +736,7 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
}
Some(_) => true,
None => {
if tcx.is_exported_symbol(def_id) ||
if tcx.is_reachable_non_generic(def_id) ||
tcx.is_foreign_item(def_id)
{
// We can link to the item in question, no instance needed
Expand Down Expand Up @@ -984,7 +984,7 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
}
MonoItemCollectionMode::Lazy => {
self.entry_fn == Some(def_id) ||
self.tcx.is_exported_symbol(def_id) ||
self.tcx.is_reachable_non_generic(def_id) ||
attr::contains_name(&self.tcx.get_attrs(def_id),
"rustc_std_internal_symbol")
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/monomorphize/partitioning.rs
Expand Up @@ -363,7 +363,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
can_be_internalized = false;
Visibility::Hidden
} else if def_id.is_local() {
if tcx.is_exported_symbol(def_id) {
if tcx.is_reachable_non_generic(def_id) {
can_be_internalized = false;
default_visibility(def_id)
} else {
Expand All @@ -385,7 +385,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
(Linkage::External, visibility)
}
MonoItem::Static(def_id) => {
let visibility = if tcx.is_exported_symbol(def_id) {
let visibility = if tcx.is_reachable_non_generic(def_id) {
can_be_internalized = false;
default_visibility(def_id)
} else {
Expand All @@ -395,7 +395,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
MonoItem::GlobalAsm(node_id) => {
let def_id = tcx.hir.local_def_id(node_id);
let visibility = if tcx.is_exported_symbol(def_id) {
let visibility = if tcx.is_reachable_non_generic(def_id) {
can_be_internalized = false;
default_visibility(def_id)
} else {
Expand Down
13 changes: 9 additions & 4 deletions src/librustc_trans/back/symbol_export.rs
Expand Up @@ -61,7 +61,7 @@ pub fn crates_export_threshold(crate_types: &[config::CrateType])
}

pub fn provide(providers: &mut Providers) {
providers.exported_symbol_ids = |tcx, cnum| {
providers.reachable_non_generics = |tcx, cnum| {
let export_threshold = threshold(tcx);
Lrc::new(tcx.exported_symbols(cnum)
.iter()
Expand All @@ -77,8 +77,8 @@ pub fn provide(providers: &mut Providers) {
.collect())
};

providers.is_exported_symbol = |tcx, id| {
tcx.exported_symbol_ids(id.krate).contains(&id)
providers.is_reachable_non_generic = |tcx, id| {
tcx.reachable_non_generics(id.krate).contains(&id)
};

providers.exported_symbols = |tcx, cnum| {
Expand Down Expand Up @@ -156,7 +156,7 @@ pub fn provide_extern(providers: &mut Providers) {
tcx.is_panic_runtime(cnum) || tcx.is_compiler_builtins(cnum);

let mut crate_exports: Vec<_> = tcx
.exported_symbol_ids(cnum)
.reachable_non_generics(cnum)
.iter()
.map(|&def_id| {
let name = tcx.symbol_name(Instance::mono(tcx, def_id));
Expand Down Expand Up @@ -190,6 +190,11 @@ pub fn provide_extern(providers: &mut Providers) {

Arc::new(crate_exports)
};

providers.is_reachable_non_generic = |tcx, id| {
tcx.reachable_non_generics(id.krate).contains(&id)
};

providers.symbol_export_level = export_level;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/callee.rs
Expand Up @@ -151,7 +151,7 @@ pub fn get_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,

if cx.tcx.is_translated_item(instance_def_id) {
if instance_def_id.is_local() {
if !cx.tcx.is_exported_symbol(instance_def_id) {
if !cx.tcx.is_reachable_non_generic(instance_def_id) {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/consts.rs
Expand Up @@ -134,7 +134,7 @@ pub fn get_static(cx: &CodegenCx, def_id: DefId) -> ValueRef {

let g = declare::define_global(cx, &sym[..], llty).unwrap();

if !cx.tcx.is_exported_symbol(def_id) {
if !cx.tcx.is_reachable_non_generic(def_id) {
unsafe {
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trans/debuginfo/utils.rs
Expand Up @@ -32,7 +32,7 @@ pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
// visible). It might better to use the `exported_items` set from
// `driver::CrateAnalysis` in the future, but (atm) this set is not
// available in the translation pass.
!cx.tcx.is_exported_symbol(def_id)
!cx.tcx.is_reachable_non_generic(def_id)
}

#[allow(non_snake_case)]
Expand Down

0 comments on commit e5ee011

Please sign in to comment.