Skip to content

Commit e5ee011

Browse files
Rename exported_symbol_ids query to something more explicit and document what it is doing.
1 parent 1733a61 commit e5ee011

File tree

16 files changed

+62
-47
lines changed

16 files changed

+62
-47
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ define_dep_nodes!( <'tcx>
556556
[] RvaluePromotableMap(DefId),
557557
[] ImplParent(DefId),
558558
[] TraitOfItem(DefId),
559-
[] IsExportedSymbol(DefId),
559+
[] IsReachableNonGeneric(DefId),
560560
[] IsMirAvailable(DefId),
561561
[] ItemAttrs(DefId),
562562
[] FnArgNames(DefId),
@@ -574,7 +574,7 @@ define_dep_nodes!( <'tcx>
574574
[] GetPanicStrategy(CrateNum),
575575
[] IsNoBuiltins(CrateNum),
576576
[] ImplDefaultness(DefId),
577-
[] ExportedSymbolIds(CrateNum),
577+
[] ReachableNonGenerics(CrateNum),
578578
[] NativeLibraries(CrateNum),
579579
[] PluginRegistrarFn(CrateNum),
580580
[] DeriveRegistrarFn(CrateNum),

src/librustc/ty/maps/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ impl<'tcx> QueryDescription<'tcx> for queries::item_attrs<'tcx> {
212212
}
213213
}
214214

215-
impl<'tcx> QueryDescription<'tcx> for queries::is_exported_symbol<'tcx> {
215+
impl<'tcx> QueryDescription<'tcx> for queries::is_reachable_non_generic<'tcx> {
216216
fn describe(_: TyCtxt, _: DefId) -> String {
217-
bug!("is_exported_symbol")
217+
bug!("is_reachable_non_generic")
218218
}
219219
}
220220

@@ -383,7 +383,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::is_sanitizer_runtime<'tcx> {
383383
}
384384
}
385385

386-
impl<'tcx> QueryDescription<'tcx> for queries::exported_symbol_ids<'tcx> {
386+
impl<'tcx> QueryDescription<'tcx> for queries::reachable_non_generics<'tcx> {
387387
fn describe(_tcx: TyCtxt, _: CrateNum) -> String {
388388
format!("looking up the exported symbols of a crate")
389389
}

src/librustc/ty/maps/mod.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,6 @@ define_maps! { <'tcx>
238238
[] fn fn_arg_names: FnArgNames(DefId) -> Vec<ast::Name>,
239239
[] fn impl_parent: ImplParent(DefId) -> Option<DefId>,
240240
[] fn trait_of_item: TraitOfItem(DefId) -> Option<DefId>,
241-
[] fn is_exported_symbol: IsExportedSymbol(DefId) -> bool,
242241
[] fn item_body_nested_bodies: ItemBodyNestedBodies(DefId) -> ExternBodyNestedBodies,
243242
[] fn const_is_rvalue_promotable_to_static: ConstIsRvaluePromotableToStatic(DefId) -> bool,
244243
[] fn rvalue_promotable_map: RvaluePromotableMap(DefId) -> Lrc<ItemLocalSet>,
@@ -290,7 +289,23 @@ define_maps! { <'tcx>
290289
[] fn lint_levels: lint_levels_node(CrateNum) -> Lrc<lint::LintLevelMap>,
291290

292291
[] fn impl_defaultness: ImplDefaultness(DefId) -> hir::Defaultness,
293-
[] fn exported_symbol_ids: ExportedSymbolIds(CrateNum) -> Lrc<DefIdSet>,
292+
293+
// The DefIds of all non-generic functions and statics in the given crate
294+
// that can be reached from outside the crate.
295+
//
296+
// We expect this items to be available for being linked to.
297+
//
298+
// This query can also be called for LOCAL_CRATE. In this case it will
299+
// compute which items will be reachable to other crates, taking into account
300+
// the kind of crate that is currently compiled. Crates with only a
301+
// C interface have fewer reachable things.
302+
//
303+
// Does not include external symbols that don't have a corresponding DefId,
304+
// like the compiler-generated `main` function and so on.
305+
[] fn reachable_non_generics: ReachableNonGenerics(CrateNum) -> Lrc<DefIdSet>,
306+
[] fn is_reachable_non_generic: IsReachableNonGeneric(DefId) -> bool,
307+
308+
294309
[] fn native_libraries: NativeLibraries(CrateNum) -> Lrc<Vec<NativeLibrary>>,
295310
[] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
296311
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,

src/librustc/ty/maps/plumbing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
851851
DepKind::RvaluePromotableMap => { force!(rvalue_promotable_map, def_id!()); }
852852
DepKind::ImplParent => { force!(impl_parent, def_id!()); }
853853
DepKind::TraitOfItem => { force!(trait_of_item, def_id!()); }
854-
DepKind::IsExportedSymbol => { force!(is_exported_symbol, def_id!()); }
854+
DepKind::IsReachableNonGeneric => { force!(is_reachable_non_generic, def_id!()); }
855855
DepKind::IsMirAvailable => { force!(is_mir_available, def_id!()); }
856856
DepKind::ItemAttrs => { force!(item_attrs, def_id!()); }
857857
DepKind::FnArgNames => { force!(fn_arg_names, def_id!()); }
@@ -868,7 +868,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
868868
DepKind::GetPanicStrategy => { force!(panic_strategy, krate!()); }
869869
DepKind::IsNoBuiltins => { force!(is_no_builtins, krate!()); }
870870
DepKind::ImplDefaultness => { force!(impl_defaultness, def_id!()); }
871-
DepKind::ExportedSymbolIds => { force!(exported_symbol_ids, krate!()); }
871+
DepKind::ReachableNonGenerics => { force!(reachable_non_generics, krate!()); }
872872
DepKind::NativeLibraries => { force!(native_libraries, krate!()); }
873873
DepKind::PluginRegistrarFn => { force!(plugin_registrar_fn, krate!()); }
874874
DepKind::DeriveRegistrarFn => { force!(derive_registrar_fn, krate!()); }

src/librustc_metadata/creader.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,6 @@ impl<'a> CrateLoader<'a> {
225225
crate_root.def_path_table.decode((&metadata, self.sess))
226226
});
227227

228-
let exported_symbols = crate_root.exported_symbols
229-
.decode((&metadata, self.sess))
230-
.collect();
231228
let trait_impls = crate_root
232229
.impls
233230
.decode((&metadata, self.sess))
@@ -238,7 +235,6 @@ impl<'a> CrateLoader<'a> {
238235
name,
239236
extern_crate: Cell::new(None),
240237
def_path_table: Lrc::new(def_path_table),
241-
exported_symbols,
242238
trait_impls,
243239
proc_macros: crate_root.macro_derive_registrar.map(|_| {
244240
self.load_derive_macros(&crate_root, dylib.clone().map(|p| p.0), span)

src/librustc_metadata/cstore.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ pub struct CrateMetadata {
7878
/// compilation support.
7979
pub def_path_table: Lrc<DefPathTable>,
8080

81-
pub exported_symbols: FxHashSet<DefIndex>,
82-
8381
pub trait_impls: FxHashMap<(u32, DefIndex), schema::LazySeq<DefIndex>>,
8482

8583
pub dep_kind: Cell<DepKind>,

src/librustc_metadata/cstore_impl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
160160
fn_arg_names => { cdata.get_fn_arg_names(def_id.index) }
161161
impl_parent => { cdata.get_parent_impl(def_id.index) }
162162
trait_of_item => { cdata.get_trait_of_item(def_id.index) }
163-
is_exported_symbol => {
164-
cdata.exported_symbols.contains(&def_id.index)
165-
}
166163
item_body_nested_bodies => { cdata.item_body_nested_bodies(def_id.index) }
167164
const_is_rvalue_promotable_to_static => {
168165
cdata.const_is_rvalue_promotable_to_static(def_id.index)
@@ -179,7 +176,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
179176
extern_crate => { Lrc::new(cdata.extern_crate.get()) }
180177
is_no_builtins => { cdata.is_no_builtins(tcx.sess) }
181178
impl_defaultness => { cdata.get_impl_defaultness(def_id.index) }
182-
exported_symbol_ids => { Lrc::new(cdata.get_exported_symbols()) }
179+
reachable_non_generics => { Lrc::new(cdata.reachable_non_generics()) }
183180
native_libraries => { Lrc::new(cdata.get_native_libraries(tcx.sess)) }
184181
plugin_registrar_fn => {
185182
cdata.root.plugin_registrar_fn.map(|index| {

src/librustc_metadata/decoder.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,10 +1006,11 @@ impl<'a, 'tcx> CrateMetadata {
10061006
arg_names.decode(self).collect()
10071007
}
10081008

1009-
pub fn get_exported_symbols(&self) -> DefIdSet {
1010-
self.exported_symbols
1011-
.iter()
1012-
.map(|&index| self.local_def_id(index))
1009+
pub fn reachable_non_generics(&self) -> DefIdSet {
1010+
self.root
1011+
.reachable_non_generics
1012+
.decode(self)
1013+
.map(|index| self.local_def_id(index))
10131014
.collect()
10141015
}
10151016

src/librustc_metadata/encoder.rs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ pub struct EncodeContext<'a, 'tcx: 'a> {
5353
opaque: opaque::Encoder<'a>,
5454
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
5555
link_meta: &'a LinkMeta,
56-
exported_symbols: &'a NodeSet,
56+
reachable_non_generics: &'a NodeSet,
5757

5858
lazy_state: LazyState,
5959
type_shorthands: FxHashMap<Ty<'tcx>, usize>,
@@ -395,10 +395,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
395395

396396
// Encode exported symbols info.
397397
i = self.position();
398-
let exported_symbols = self.tracked(
399-
IsolatedEncoder::encode_exported_symbols,
400-
self.exported_symbols);
401-
let exported_symbols_bytes = self.position() - i;
398+
let reachable_non_generics = self.tracked(
399+
IsolatedEncoder::encode_reachable_non_generics,
400+
self.reachable_non_generics);
401+
let reachable_non_generics_bytes = self.position() - i;
402402

403403
// Encode and index the items.
404404
i = self.position();
@@ -442,7 +442,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
442442
codemap,
443443
def_path_table,
444444
impls,
445-
exported_symbols,
445+
reachable_non_generics,
446446
index,
447447
});
448448

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

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

16651668
pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
16661669
link_meta: &LinkMeta,
1667-
exported_symbols: &NodeSet)
1670+
reachable_non_generics: &NodeSet)
16681671
-> EncodedMetadata
16691672
{
16701673
let mut cursor = Cursor::new(vec![]);
@@ -1678,7 +1681,7 @@ pub fn encode_metadata<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
16781681
opaque: opaque::Encoder::new(&mut cursor),
16791682
tcx,
16801683
link_meta,
1681-
exported_symbols,
1684+
reachable_non_generics,
16821685
lazy_state: LazyState::NoNode,
16831686
type_shorthands: Default::default(),
16841687
predicate_shorthands: Default::default(),

src/librustc_metadata/schema.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ pub struct CrateRoot {
202202
pub codemap: LazySeq<syntax_pos::FileMap>,
203203
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
204204
pub impls: LazySeq<TraitImpls>,
205-
pub exported_symbols: LazySeq<DefIndex>,
205+
pub reachable_non_generics: LazySeq<DefIndex>,
206206
pub index: LazySeq<index::Index>,
207207
}
208208

src/librustc_mir/monomorphize/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance:
736736
}
737737
Some(_) => true,
738738
None => {
739-
if tcx.is_exported_symbol(def_id) ||
739+
if tcx.is_reachable_non_generic(def_id) ||
740740
tcx.is_foreign_item(def_id)
741741
{
742742
// We can link to the item in question, no instance needed
@@ -984,7 +984,7 @@ impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
984984
}
985985
MonoItemCollectionMode::Lazy => {
986986
self.entry_fn == Some(def_id) ||
987-
self.tcx.is_exported_symbol(def_id) ||
987+
self.tcx.is_reachable_non_generic(def_id) ||
988988
attr::contains_name(&self.tcx.get_attrs(def_id),
989989
"rustc_std_internal_symbol")
990990
}

src/librustc_mir/monomorphize/partitioning.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
363363
can_be_internalized = false;
364364
Visibility::Hidden
365365
} else if def_id.is_local() {
366-
if tcx.is_exported_symbol(def_id) {
366+
if tcx.is_reachable_non_generic(def_id) {
367367
can_be_internalized = false;
368368
default_visibility(def_id)
369369
} else {
@@ -385,7 +385,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
385385
(Linkage::External, visibility)
386386
}
387387
MonoItem::Static(def_id) => {
388-
let visibility = if tcx.is_exported_symbol(def_id) {
388+
let visibility = if tcx.is_reachable_non_generic(def_id) {
389389
can_be_internalized = false;
390390
default_visibility(def_id)
391391
} else {
@@ -395,7 +395,7 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
395395
}
396396
MonoItem::GlobalAsm(node_id) => {
397397
let def_id = tcx.hir.local_def_id(node_id);
398-
let visibility = if tcx.is_exported_symbol(def_id) {
398+
let visibility = if tcx.is_reachable_non_generic(def_id) {
399399
can_be_internalized = false;
400400
default_visibility(def_id)
401401
} else {

src/librustc_trans/back/symbol_export.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn crates_export_threshold(crate_types: &[config::CrateType])
6161
}
6262

6363
pub fn provide(providers: &mut Providers) {
64-
providers.exported_symbol_ids = |tcx, cnum| {
64+
providers.reachable_non_generics = |tcx, cnum| {
6565
let export_threshold = threshold(tcx);
6666
Lrc::new(tcx.exported_symbols(cnum)
6767
.iter()
@@ -77,8 +77,8 @@ pub fn provide(providers: &mut Providers) {
7777
.collect())
7878
};
7979

80-
providers.is_exported_symbol = |tcx, id| {
81-
tcx.exported_symbol_ids(id.krate).contains(&id)
80+
providers.is_reachable_non_generic = |tcx, id| {
81+
tcx.reachable_non_generics(id.krate).contains(&id)
8282
};
8383

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

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

191191
Arc::new(crate_exports)
192192
};
193+
194+
providers.is_reachable_non_generic = |tcx, id| {
195+
tcx.reachable_non_generics(id.krate).contains(&id)
196+
};
197+
193198
providers.symbol_export_level = export_level;
194199
}
195200

src/librustc_trans/callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ pub fn get_fn<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>,
151151

152152
if cx.tcx.is_translated_item(instance_def_id) {
153153
if instance_def_id.is_local() {
154-
if !cx.tcx.is_exported_symbol(instance_def_id) {
154+
if !cx.tcx.is_reachable_non_generic(instance_def_id) {
155155
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
156156
}
157157
} else {

src/librustc_trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ pub fn get_static(cx: &CodegenCx, def_id: DefId) -> ValueRef {
134134

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

137-
if !cx.tcx.is_exported_symbol(def_id) {
137+
if !cx.tcx.is_reachable_non_generic(def_id) {
138138
unsafe {
139139
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
140140
}

src/librustc_trans/debuginfo/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn is_node_local_to_unit(cx: &CodegenCx, def_id: DefId) -> bool
3232
// visible). It might better to use the `exported_items` set from
3333
// `driver::CrateAnalysis` in the future, but (atm) this set is not
3434
// available in the translation pass.
35-
!cx.tcx.is_exported_symbol(def_id)
35+
!cx.tcx.is_reachable_non_generic(def_id)
3636
}
3737

3838
#[allow(non_snake_case)]

0 commit comments

Comments
 (0)