Add SymbolExportInfo
This is currently a wrapper to `SymbolExportLevel` but it allows later addition of extra information.
This commit is contained in:
parent
419e3ba97b
commit
49cc6d1f84
12 changed files with 75 additions and 38 deletions
|
@ -1526,8 +1526,8 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
|
|||
let mut symbols = Vec::new();
|
||||
|
||||
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
|
||||
for &(symbol, level) in tcx.exported_symbols(LOCAL_CRATE).iter() {
|
||||
if level.is_below_threshold(export_threshold) {
|
||||
for &(symbol, info) in tcx.exported_symbols(LOCAL_CRATE).iter() {
|
||||
if info.level.is_below_threshold(export_threshold) {
|
||||
symbols.push(symbol_export::symbol_name_for_instance_in_crate(
|
||||
tcx,
|
||||
symbol,
|
||||
|
@ -1544,8 +1544,8 @@ pub(crate) fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<St
|
|||
// For each dependency that we are linking to statically ...
|
||||
if *dep_format == Linkage::Static {
|
||||
// ... we add its symbol list to our export list.
|
||||
for &(symbol, level) in tcx.exported_symbols(cnum).iter() {
|
||||
if !level.is_below_threshold(export_threshold) {
|
||||
for &(symbol, info) in tcx.exported_symbols(cnum).iter() {
|
||||
if !info.level.is_below_threshold(export_threshold) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_hir::Node;
|
|||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
|
||||
use rustc_middle::middle::exported_symbols::{
|
||||
metadata_symbol_name, ExportedSymbol, SymbolExportLevel,
|
||||
metadata_symbol_name, ExportedSymbol, SymbolExportInfo, SymbolExportLevel,
|
||||
};
|
||||
use rustc_middle::ty::query::{ExternProviders, Providers};
|
||||
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef};
|
||||
|
@ -42,7 +42,7 @@ pub fn crates_export_threshold(crate_types: &[CrateType]) -> SymbolExportLevel {
|
|||
}
|
||||
}
|
||||
|
||||
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<SymbolExportLevel> {
|
||||
fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<SymbolExportInfo> {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
if !tcx.sess.opts.output_types.should_codegen() {
|
||||
|
@ -129,12 +129,17 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
|||
tcx.symbol_name(Instance::mono(tcx, def_id.to_def_id())),
|
||||
export_level
|
||||
);
|
||||
(def_id.to_def_id(), export_level)
|
||||
(def_id.to_def_id(), SymbolExportInfo {
|
||||
level: export_level,
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
if let Some(id) = tcx.proc_macro_decls_static(()) {
|
||||
reachable_non_generics.insert(id.to_def_id(), SymbolExportLevel::C);
|
||||
reachable_non_generics.insert(
|
||||
id.to_def_id(),
|
||||
SymbolExportInfo { level: SymbolExportLevel::C },
|
||||
);
|
||||
}
|
||||
|
||||
reachable_non_generics
|
||||
|
@ -143,8 +148,8 @@ fn reachable_non_generics_provider(tcx: TyCtxt<'_>, cnum: CrateNum) -> DefIdMap<
|
|||
fn is_reachable_non_generic_provider_local(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
|
||||
let export_threshold = threshold(tcx);
|
||||
|
||||
if let Some(&level) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
|
||||
level.is_below_threshold(export_threshold)
|
||||
if let Some(&info) = tcx.reachable_non_generics(def_id.krate).get(&def_id) {
|
||||
info.level.is_below_threshold(export_threshold)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -157,7 +162,7 @@ fn is_reachable_non_generic_provider_extern(tcx: TyCtxt<'_>, def_id: DefId) -> b
|
|||
fn exported_symbols_provider_local<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
cnum: CrateNum,
|
||||
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportLevel)] {
|
||||
) -> &'tcx [(ExportedSymbol<'tcx>, SymbolExportInfo)] {
|
||||
assert_eq!(cnum, LOCAL_CRATE);
|
||||
|
||||
if !tcx.sess.opts.output_types.should_codegen() {
|
||||
|
@ -167,13 +172,16 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
let mut symbols: Vec<_> = tcx
|
||||
.reachable_non_generics(LOCAL_CRATE)
|
||||
.iter()
|
||||
.map(|(&def_id, &level)| (ExportedSymbol::NonGeneric(def_id), level))
|
||||
.map(|(&def_id, &info)| (ExportedSymbol::NonGeneric(def_id), info))
|
||||
.collect();
|
||||
|
||||
if tcx.entry_fn(()).is_some() {
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, "main"));
|
||||
|
||||
symbols.push((exported_symbol, SymbolExportLevel::C));
|
||||
symbols.push((
|
||||
exported_symbol,
|
||||
SymbolExportInfo { level: SymbolExportLevel::C },
|
||||
));
|
||||
}
|
||||
|
||||
if tcx.allocator_kind(()).is_some() {
|
||||
|
@ -181,7 +189,10 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
let symbol_name = format!("__rust_{}", method.name);
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
|
||||
|
||||
symbols.push((exported_symbol, SymbolExportLevel::Rust));
|
||||
symbols.push((
|
||||
exported_symbol,
|
||||
SymbolExportInfo { level: SymbolExportLevel::Rust },
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +205,10 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
|
||||
symbols.extend(PROFILER_WEAK_SYMBOLS.iter().map(|sym| {
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
|
||||
(exported_symbol, SymbolExportLevel::C)
|
||||
(
|
||||
exported_symbol,
|
||||
SymbolExportInfo { level: SymbolExportLevel::C },
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -204,7 +218,10 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
|
||||
symbols.extend(MSAN_WEAK_SYMBOLS.iter().map(|sym| {
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
|
||||
(exported_symbol, SymbolExportLevel::C)
|
||||
(
|
||||
exported_symbol,
|
||||
SymbolExportInfo { level: SymbolExportLevel::C },
|
||||
)
|
||||
}));
|
||||
}
|
||||
|
||||
|
@ -212,7 +229,10 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
let symbol_name = metadata_symbol_name(tcx);
|
||||
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name));
|
||||
|
||||
symbols.push((exported_symbol, SymbolExportLevel::Rust));
|
||||
symbols.push((
|
||||
exported_symbol,
|
||||
SymbolExportInfo { level: SymbolExportLevel::Rust },
|
||||
));
|
||||
}
|
||||
|
||||
if tcx.sess.opts.share_generics() && tcx.local_crate_exports_generics() {
|
||||
|
@ -245,7 +265,12 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => {
|
||||
if substs.non_erasable_generics().next().is_some() {
|
||||
let symbol = ExportedSymbol::Generic(def.did, substs);
|
||||
symbols.push((symbol, SymbolExportLevel::Rust));
|
||||
symbols.push((
|
||||
symbol,
|
||||
SymbolExportInfo {
|
||||
level: SymbolExportLevel::Rust,
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
MonoItem::Fn(Instance { def: InstanceDef::DropGlue(_, Some(ty)), substs }) => {
|
||||
|
@ -254,7 +279,12 @@ fn exported_symbols_provider_local<'tcx>(
|
|||
substs.non_erasable_generics().next(),
|
||||
Some(GenericArgKind::Type(ty))
|
||||
);
|
||||
symbols.push((ExportedSymbol::DropGlue(ty), SymbolExportLevel::Rust));
|
||||
symbols.push((
|
||||
ExportedSymbol::DropGlue(ty),
|
||||
SymbolExportInfo {
|
||||
level: SymbolExportLevel::Rust,
|
||||
},
|
||||
));
|
||||
}
|
||||
_ => {
|
||||
// Any other symbols don't qualify for sharing
|
||||
|
|
|
@ -23,7 +23,7 @@ use rustc_incremental::{
|
|||
};
|
||||
use rustc_metadata::EncodedMetadata;
|
||||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportLevel;
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportInfo;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::cgu_reuse_tracker::CguReuseTracker;
|
||||
use rustc_session::config::{self, CrateType, Lto, OutputFilenames, OutputType};
|
||||
|
@ -304,7 +304,7 @@ pub type TargetMachineFactoryFn<B> = Arc<
|
|||
+ Sync,
|
||||
>;
|
||||
|
||||
pub type ExportedSymbols = FxHashMap<CrateNum, Arc<Vec<(String, SymbolExportLevel)>>>;
|
||||
pub type ExportedSymbols = FxHashMap<CrateNum, Arc<Vec<(String, SymbolExportInfo)>>>;
|
||||
|
||||
/// Additional resources used by optimize_and_codegen (not module specific)
|
||||
#[derive(Clone)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue