Skip to content

Commit f227187

Browse files
committed
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**).
1 parent c22fdf9 commit f227187

File tree

7 files changed

+21
-30
lines changed

7 files changed

+21
-30
lines changed

src/librustc/session/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ pub use self::code_stats::{SizeKind, TypeSizeInfo, VariantInfo};
1313

1414
use dep_graph::DepGraph;
1515
use hir::def_id::{CrateNum, DefIndex};
16-
use hir::svh::Svh;
1716
use lint;
1817
use middle::cstore::CrateStore;
1918
use middle::dependency_format;
@@ -402,15 +401,14 @@ impl Session {
402401

403402
/// Returns the symbol name for the registrar function,
404403
/// given the crate Svh and the function DefIndex.
405-
pub fn generate_plugin_registrar_symbol(&self, svh: &Svh, index: DefIndex)
404+
pub fn generate_plugin_registrar_symbol(&self, disambiguator: Symbol, index: DefIndex)
406405
-> String {
407-
format!("__rustc_plugin_registrar__{}_{}", svh, index.as_usize())
406+
format!("__rustc_plugin_registrar__{}_{}", disambiguator, index.as_usize())
408407
}
409408

410-
pub fn generate_derive_registrar_symbol(&self,
411-
svh: &Svh,
412-
index: DefIndex) -> String {
413-
format!("__rustc_derive_registrar__{}_{}", svh, index.as_usize())
409+
pub fn generate_derive_registrar_symbol(&self, disambiguator: Symbol, index: DefIndex)
410+
-> String {
411+
format!("__rustc_derive_registrar__{}_{}", disambiguator, index.as_usize())
414412
}
415413

416414
pub fn sysroot<'a>(&'a self) -> &'a Path {

src/librustc_metadata/creader.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ impl<'a> CrateLoader<'a> {
600600
Err(err) => self.sess.span_fatal(span, &err),
601601
};
602602

603-
let sym = self.sess.generate_derive_registrar_symbol(&root.hash,
603+
let sym = self.sess.generate_derive_registrar_symbol(root.disambiguator,
604604
root.macro_derive_registrar.unwrap());
605605
let registrar = unsafe {
606606
let sym = match lib.symbol(&sym) {
@@ -654,7 +654,7 @@ impl<'a> CrateLoader<'a> {
654654
/// Look for a plugin registrar. Returns library path, crate
655655
/// SVH and DefIndex of the registrar function.
656656
pub fn find_plugin_registrar(&mut self, span: Span, name: &str)
657-
-> Option<(PathBuf, Svh, DefIndex)> {
657+
-> Option<(PathBuf, Symbol, DefIndex)> {
658658
let ekrate = self.read_extension_crate(span, &ExternCrateInfo {
659659
name: Symbol::intern(name),
660660
ident: Symbol::intern(name),
@@ -675,7 +675,7 @@ impl<'a> CrateLoader<'a> {
675675
let root = ekrate.metadata.get_root();
676676
match (ekrate.dylib.as_ref(), root.plugin_registrar_fn) {
677677
(Some(dylib), Some(reg)) => {
678-
Some((dylib.to_path_buf(), root.hash, reg))
678+
Some((dylib.to_path_buf(), root.disambiguator, reg))
679679
}
680680
(None, Some(_)) => {
681681
span_err!(self.sess, span, E0457,

src/librustc_plugin/load.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ impl<'a> PluginLoader<'a> {
100100
fn load_plugin(&mut self, span: Span, name: &str, args: Vec<ast::NestedMetaItem>) {
101101
let registrar = self.reader.find_plugin_registrar(span, name);
102102

103-
if let Some((lib, svh, index)) = registrar {
104-
let symbol = self.sess.generate_plugin_registrar_symbol(&svh, index);
103+
if let Some((lib, disambiguator, index)) = registrar {
104+
let symbol = self.sess.generate_plugin_registrar_symbol(disambiguator, index);
105105
let fun = self.dylink_registrar(span, lib, symbol);
106106
self.plugins.push(PluginRegistrar {
107107
fun: fun,

src/librustc_trans/back/symbol_export.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ impl ExportedSymbols {
6464
}
6565

6666
if let Some(id) = scx.sess().derive_registrar_fn.get() {
67-
let svh = &scx.link_meta().crate_hash;
6867
let def_id = scx.tcx().hir.local_def_id(id);
6968
let idx = def_id.index;
70-
let registrar = scx.sess().generate_derive_registrar_symbol(svh, idx);
69+
let disambiguator = scx.sess().local_crate_disambiguator();
70+
let registrar = scx.sess().generate_derive_registrar_symbol(disambiguator, idx);
7171
local_crate.push((registrar, SymbolExportLevel::C));
7272
}
7373

src/librustc_trans/back/symbol_names.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,14 @@ pub fn symbol_name<'a, 'tcx>(instance: Instance<'tcx>,
179179

180180
if let Some(id) = node_id {
181181
if scx.sess().plugin_registrar_fn.get() == Some(id) {
182-
let svh = &scx.link_meta().crate_hash;
183182
let idx = def_id.index;
184-
return scx.sess().generate_plugin_registrar_symbol(svh, idx);
183+
let disambiguator = scx.sess().local_crate_disambiguator();
184+
return scx.sess().generate_plugin_registrar_symbol(disambiguator, idx);
185185
}
186186
if scx.sess().derive_registrar_fn.get() == Some(id) {
187-
let svh = &scx.link_meta().crate_hash;
188187
let idx = def_id.index;
189-
return scx.sess().generate_derive_registrar_symbol(svh, idx);
188+
let disambiguator = scx.sess().local_crate_disambiguator();
189+
return scx.sess().generate_derive_registrar_symbol(disambiguator, idx);
190190
}
191191
}
192192

src/librustc_trans/base.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ use middle::lang_items::StartFnLangItem;
3939
use middle::cstore::EncodedMetadata;
4040
use rustc::ty::{self, Ty, TyCtxt};
4141
use rustc::dep_graph::{AssertDepGraphSafe, DepNode};
42+
use rustc::middle::cstore::LinkMeta;
4243
use rustc::hir::map as hir_map;
4344
use rustc::util::common::time;
4445
use session::config::{self, NoDebugInfo};
@@ -725,6 +726,7 @@ fn contains_null(s: &str) -> bool {
725726
}
726727

727728
fn write_metadata(cx: &SharedCrateContext,
729+
link_meta: &LinkMeta,
728730
exported_symbols: &NodeSet)
729731
-> (ContextRef, ModuleRef, EncodedMetadata) {
730732
use flate;
@@ -762,7 +764,7 @@ fn write_metadata(cx: &SharedCrateContext,
762764

763765
let cstore = &cx.tcx().sess.cstore;
764766
let metadata = cstore.encode_metadata(cx.tcx(),
765-
cx.link_meta(),
767+
&link_meta,
766768
exported_symbols);
767769
if kind == MetadataKind::Uncompressed {
768770
return (metadata_llcx, metadata_llmod, metadata);
@@ -1071,13 +1073,12 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10711073
let link_meta = link::build_link_meta(incremental_hashes_map);
10721074

10731075
let shared_ccx = SharedCrateContext::new(tcx,
1074-
link_meta.clone(),
10751076
exported_symbols,
10761077
check_overflow);
10771078
// Translate the metadata.
10781079
let (metadata_llcx, metadata_llmod, metadata) =
10791080
time(tcx.sess.time_passes(), "write metadata", || {
1080-
write_metadata(&shared_ccx, shared_ccx.exported_symbols())
1081+
write_metadata(&shared_ccx, &link_meta, shared_ccx.exported_symbols())
10811082
});
10821083

10831084
let metadata_module = ModuleTranslation {

src/librustc_trans/context.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use llvm;
1212
use llvm::{ContextRef, ModuleRef, ValueRef};
1313
use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap, DepTrackingMapConfig};
14-
use middle::cstore::LinkMeta;
1514
use rustc::hir;
1615
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
1716
use rustc::traits;
@@ -65,7 +64,6 @@ pub struct Stats {
6564
/// (aside from metadata-related ones).
6665
pub struct SharedCrateContext<'a, 'tcx: 'a> {
6766
exported_symbols: NodeSet,
68-
link_meta: LinkMeta,
6967
tcx: TyCtxt<'a, 'tcx, 'tcx>,
7068
empty_param_env: ty::ParameterEnvironment<'tcx>,
7169
stats: Stats,
@@ -316,7 +314,6 @@ pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (Cont
316314

317315
impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
318316
pub fn new(tcx: TyCtxt<'b, 'tcx, 'tcx>,
319-
link_meta: LinkMeta,
320317
exported_symbols: NodeSet,
321318
check_overflow: bool)
322319
-> SharedCrateContext<'b, 'tcx> {
@@ -367,7 +364,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
367364

368365
SharedCrateContext {
369366
exported_symbols: exported_symbols,
370-
link_meta: link_meta,
371367
empty_param_env: tcx.empty_parameter_environment(),
372368
tcx: tcx,
373369
stats: Stats {
@@ -409,10 +405,6 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
409405
&self.project_cache
410406
}
411407

412-
pub fn link_meta<'a>(&'a self) -> &'a LinkMeta {
413-
&self.link_meta
414-
}
415-
416408
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {
417409
self.tcx
418410
}
@@ -440,7 +432,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
440432
pub fn metadata_symbol_name(&self) -> String {
441433
format!("rust_metadata_{}_{}",
442434
self.tcx().crate_name(LOCAL_CRATE),
443-
self.link_meta().crate_hash)
435+
self.tcx().crate_disambiguator(LOCAL_CRATE))
444436
}
445437
}
446438

0 commit comments

Comments
 (0)