remove LinkMeta
from SharedCrateContext
A number of things were using `crate_hash` that really ought to be using `crate_disambiguator` (e.g., to create the plugin symbol names). They have been updated. It is important to remove `LinkMeta` from `SharedCrateContext` since it contains a hash of the entire crate, and hence it will change whenever **anything** changes (which would then require rebuilding **everything**).
This commit is contained in:
parent
c22fdf9a3a
commit
f227187cb8
@ -13,7 +13,6 @@ pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
|
||||
|
||||
use dep_graph::DepGraph;
|
||||
use hir::def_id::{CrateNum, DefIndex};
|
||||
use hir::svh::Svh;
|
||||
use lint;
|
||||
use middle::cstore::CrateStore;
|
||||
use middle::dependency_format;
|
||||
@ -402,15 +401,14 @@ impl Session {
|
||||
|
||||
/// Returns the symbol name for the registrar function,
|
||||
/// given the crate Svh and the function DefIndex.
|
||||
pub fn generate_plugin_registrar_symbol(&self, svh: &Svh, index: DefIndex)
|
||||
pub fn generate_plugin_registrar_symbol(&self, disambiguator: Symbol, index: DefIndex)
|
||||
-> String {
|
||||
format!("__rustc_plugin_registrar__{}_{}", svh, index.as_usize())
|
||||
format!("__rustc_plugin_registrar__{}_{}", disambiguator, index.as_usize())
|
||||
}
|
||||
|
||||
pub fn generate_derive_registrar_symbol(&self,
|
||||
svh: &Svh,
|
||||
index: DefIndex) -> String {
|
||||
format!("__rustc_derive_registrar__{}_{}", svh, index.as_usize())
|
||||
pub fn generate_derive_registrar_symbol(&self, disambiguator: Symbol, index: DefIndex)
|
||||
-> String {
|
||||
format!("__rustc_derive_registrar__{}_{}", disambiguator, index.as_usize())
|
||||
}
|
||||
|
||||
pub fn sysroot<'a>(&'a self) -> &'a Path {
|
||||
|
@ -600,7 +600,7 @@ impl<'a> CrateLoader<'a> {
|
||||
Err(err) => self.sess.span_fatal(span, &err),
|
||||
};
|
||||
|
||||
let sym = self.sess.generate_derive_registrar_symbol(&root.hash,
|
||||
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
|
||||
root.macro_derive_registrar.unwrap());
|
||||
let registrar = unsafe {
|
||||
let sym = match lib.symbol(&sym) {
|
||||
@ -654,7 +654,7 @@ impl<'a> CrateLoader<'a> {
|
||||
/// Look for a plugin registrar. Returns library path, crate
|
||||
/// SVH and DefIndex of the registrar function.
|
||||
pub fn find_plugin_registrar(&mut self, span: Span, name: &str)
|
||||
-> Option<(PathBuf, Svh, DefIndex)> {
|
||||
-> Option<(PathBuf, Symbol, DefIndex)> {
|
||||
let ekrate = self.read_extension_crate(span, &ExternCrateInfo {
|
||||
name: Symbol::intern(name),
|
||||
ident: Symbol::intern(name),
|
||||
@ -675,7 +675,7 @@ impl<'a> CrateLoader<'a> {
|
||||
let root = ekrate.metadata.get_root();
|
||||
match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
|
||||
(Some(dylib), Some(reg)) => {
|
||||
Some((dylib.to_path_buf(), root.hash, reg))
|
||||
Some((dylib.to_path_buf(), root.disambiguator, reg))
|
||||
}
|
||||
(None, Some(_)) => {
|
||||
span_err!(self.sess, span, E0457,
|
||||
|
@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
|
||||
fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
|
||||
let registrar = self.reader.find_plugin_registrar(span, name);
|
||||
|
||||
if let Some((lib, svh, index)) = registrar {
|
||||
let symbol = self.sess.generate_plugin_registrar_symbol(&svh, index);
|
||||
if let Some((lib, disambiguator, index)) = registrar {
|
||||
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
|
||||
let fun = self.dylink_registrar(span, lib, symbol);
|
||||
self.plugins.push(PluginRegistrar {
|
||||
fun: fun,
|
||||
|
@ -64,10 +64,10 @@ impl ExportedSymbols {
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
|
@ -179,14 +179,14 @@ pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>,
|
||||
|
||||
if let Some(id) = node_id {
|
||||
if scx.sess().plugin_registrar_fn.get() == Some(id) {
|
||||
let svh = &scx.link_meta().crate_hash;
|
||||
let idx = def_id.index;
|
||||
return scx.sess().generate_plugin_registrar_symbol(svh, idx);
|
||||
let disambiguator = scx.sess().local_crate_disambiguator();
|
||||
return scx.sess().generate_plugin_registrar_symbol(disambiguator, idx);
|
||||
}
|
||||
if scx.sess().derive_registrar_fn.get() == Some(id) {
|
||||
let svh = &scx.link_meta().crate_hash;
|
||||
let idx = def_id.index;
|
||||
return scx.sess().generate_derive_registrar_symbol(svh, idx);
|
||||
let disambiguator = scx.sess().local_crate_disambiguator();
|
||||
return scx.sess().generate_derive_registrar_symbol(disambiguator, idx);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,7 @@ use middle::lang_items::StartFnLangItem;
|
||||
use middle::cstore::EncodedMetadata;
|
||||
use rustc::ty::{self, Ty, TyCtxt};
|
||||
use rustc::dep_graph::{AssertDepGraphSafe, DepNode};
|
||||
use rustc::middle::cstore::LinkMeta;
|
||||
use rustc::hir::map as hir_map;
|
||||
use rustc::util::common::time;
|
||||
use session::config::{self, NoDebugInfo};
|
||||
@ -725,6 +726,7 @@ fn contains_null(s: &str) -> bool {
|
||||
}
|
||||
|
||||
fn write_metadata(cx: &SharedCrateContext,
|
||||
link_meta: &LinkMeta,
|
||||
exported_symbols: &NodeSet)
|
||||
-> (ContextRef, ModuleRef, EncodedMetadata) {
|
||||
use flate;
|
||||
@ -762,7 +764,7 @@ fn write_metadata(cx: &SharedCrateContext,
|
||||
|
||||
let cstore = &cx.tcx().sess.cstore;
|
||||
let metadata = cstore.encode_metadata(cx.tcx(),
|
||||
cx.link_meta(),
|
||||
&link_meta,
|
||||
exported_symbols);
|
||||
if kind == MetadataKind::Uncompressed {
|
||||
return (metadata_llcx, metadata_llmod, metadata);
|
||||
@ -1071,13 +1073,12 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
let link_meta = link::build_link_meta(incremental_hashes_map);
|
||||
|
||||
let shared_ccx = SharedCrateContext::new(tcx,
|
||||
link_meta.clone(),
|
||||
exported_symbols,
|
||||
check_overflow);
|
||||
// Translate the metadata.
|
||||
let (metadata_llcx, metadata_llmod, metadata) =
|
||||
time(tcx.sess.time_passes(), "write metadata", || {
|
||||
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
|
||||
write_metadata(&shared_ccx, &link_meta, shared_ccx.exported_symbols())
|
||||
});
|
||||
|
||||
let metadata_module = ModuleTranslation {
|
||||
|
@ -11,7 +11,6 @@
|
||||
use llvm;
|
||||
use llvm::{ContextRef, ModuleRef, ValueRef};
|
||||
use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap, DepTrackingMapConfig};
|
||||
use middle::cstore::LinkMeta;
|
||||
use rustc::hir;
|
||||
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
|
||||
use rustc::traits;
|
||||
@ -65,7 +64,6 @@ pub struct Stats {
|
||||
/// (aside from metadata-related ones).
|
||||
pub struct SharedCrateContext<'a, 'tcx: 'a> {
|
||||
exported_symbols: NodeSet,
|
||||
link_meta: LinkMeta,
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
empty_param_env: ty::ParameterEnvironment<'tcx>,
|
||||
stats: Stats,
|
||||
@ -316,7 +314,6 @@ pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (Cont
|
||||
|
||||
impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
|
||||
link_meta: LinkMeta,
|
||||
exported_symbols: NodeSet,
|
||||
check_overflow: bool)
|
||||
-> SharedCrateContext<'b, 'tcx> {
|
||||
@ -367,7 +364,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
|
||||
SharedCrateContext {
|
||||
exported_symbols: exported_symbols,
|
||||
link_meta: link_meta,
|
||||
empty_param_env: tcx.empty_parameter_environment(),
|
||||
tcx: tcx,
|
||||
stats: Stats {
|
||||
@ -409,10 +405,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
&self.project_cache
|
||||
}
|
||||
|
||||
pub fn link_meta<'a>(&'a self) -> &'a LinkMeta {
|
||||
&self.link_meta
|
||||
}
|
||||
|
||||
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
@ -440,7 +432,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
|
||||
pub fn metadata_symbol_name(&self) -> String {
|
||||
format!("rust_metadata_{}_{}",
|
||||
self.tcx().crate_name(LOCAL_CRATE),
|
||||
self.link_meta().crate_hash)
|
||||
self.tcx().crate_disambiguator(LOCAL_CRATE))
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user