use context::SharedCrateContext;
use monomorphize::Instance;
use symbol_map::SymbolMap;
+use back::symbol_names::symbol_name;
use util::nodemap::FxHashMap;
use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE};
use rustc::session::config;
+use rustc::ty::TyCtxt;
use syntax::attr;
use trans_item::TransItem;
scx.tcx().hir.local_def_id(node_id)
})
.map(|def_id| {
- let name = symbol_for_def_id(scx, def_id, symbol_map);
+ let name = symbol_for_def_id(scx.tcx(), def_id, symbol_map);
let export_level = export_level(scx, def_id);
debug!("EXPORTED SYMBOL (local): {} ({:?})", name, export_level);
(name, export_level)
}
if let Some(id) = scx.sess().derive_registrar_fn.get() {
- let svh = &scx.link_meta().crate_hash;
let def_id = scx.tcx().hir.local_def_id(id);
let idx = def_id.index;
- let registrar = scx.sess().generate_derive_registrar_symbol(svh, idx);
+ let disambiguator = scx.sess().local_crate_disambiguator();
+ let registrar = scx.sess().generate_derive_registrar_symbol(disambiguator, idx);
local_crate.push((registrar, SymbolExportLevel::C));
}
if scx.sess().crate_types.borrow().contains(&config::CrateTypeDylib) {
- local_crate.push((scx.metadata_symbol_name(),
+ local_crate.push((metadata_symbol_name(scx.tcx()),
SymbolExportLevel::Rust));
}
.exported_symbols(cnum)
.iter()
.map(|&def_id| {
- let name = Instance::mono(scx, def_id).symbol_name(scx);
+ let name = symbol_name(Instance::mono(scx.tcx(), def_id), scx.tcx());
let export_level = if special_runtime_crate {
// We can probably do better here by just ensuring that
// it has hidden visibility rather than public
cnum: CrateNum)
-> &[(String, SymbolExportLevel)] {
match self.exports.get(&cnum) {
- Some(exports) => &exports[..],
+ Some(exports) => exports,
None => &[]
}
}
{
for &(ref name, export_level) in self.exported_symbols(cnum) {
if is_below_threshold(export_level, export_threshold) {
- f(&name[..], export_level)
+ f(&name, export_level)
}
}
}
}
+pub fn metadata_symbol_name(tcx: TyCtxt) -> String {
+ format!("rust_metadata_{}_{}",
+ tcx.crate_name(LOCAL_CRATE),
+ tcx.crate_disambiguator(LOCAL_CRATE))
+}
+
pub fn crate_export_threshold(crate_type: config::CrateType)
-> SymbolExportLevel {
match crate_type {
}
}
-fn symbol_for_def_id<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
+fn symbol_for_def_id<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
symbol_map: &SymbolMap<'tcx>)
-> String {
// Just try to look things up in the symbol map. If nothing's there, we
// recompute.
- if let Some(node_id) = scx.tcx().hir.as_local_node_id(def_id) {
+ if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
if let Some(sym) = symbol_map.get(TransItem::Static(node_id)) {
return sym.to_owned();
}
}
- let instance = Instance::mono(scx, def_id);
+ let instance = Instance::mono(tcx, def_id);
symbol_map.get(TransItem::Fn(instance))
.map(str::to_owned)
- .unwrap_or_else(|| instance.symbol_name(scx))
+ .unwrap_or_else(|| symbol_name(instance, tcx))
}