use super::*;
use dep_graph::{DepGraph, DepKind, DepNodeIndex};
-use ich::Fingerprint;
use hir::intravisit::{Visitor, NestedVisitorMap};
+use session::CrateDisambiguator;
use std::iter::repeat;
use syntax::ast::{NodeId, CRATE_NODE_ID};
use syntax_pos::Span;
}
pub(super) fn finalize_and_compute_crate_hash(self,
- crate_disambiguator: &Fingerprint)
+ crate_disambiguator: CrateDisambiguator)
-> Vec<MapEntry<'hir>> {
let mut node_hashes: Vec<_> = self
.hir_body_nodes
self.dep_graph.with_task(DepNode::new_no_params(DepKind::Krate),
&self.hcx,
- (node_hashes, crate_disambiguator),
+ (node_hashes, crate_disambiguator.to_fingerprint()),
identity_fn);
self.map
}
use hir::map::definitions::*;
use hir::def_id::{CRATE_DEF_INDEX, DefIndex, DefIndexAddressSpace};
+use session::CrateDisambiguator;
use syntax::ast::*;
use syntax::ext::hygiene::Mark;
}
}
- pub fn collect_root(&mut self, crate_name: &str, crate_disambiguator: &str) {
+ pub fn collect_root(&mut self,
+ crate_name: &str,
+ crate_disambiguator: CrateDisambiguator) {
let root = self.definitions.create_root_def(crate_name,
crate_disambiguator);
assert_eq!(root, CRATE_DEF_INDEX);
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::stable_hasher::StableHasher;
use serialize::{Encodable, Decodable, Encoder, Decoder};
+use session::CrateDisambiguator;
use std::fmt::Write;
use std::hash::Hash;
use syntax::ast;
DefPathHash(hasher.finish())
}
- fn root_parent_stable_hash(crate_name: &str, crate_disambiguator: &str) -> DefPathHash {
+ fn root_parent_stable_hash(crate_name: &str,
+ crate_disambiguator: CrateDisambiguator)
+ -> DefPathHash {
let mut hasher = StableHasher::new();
// Disambiguate this from a regular DefPath hash,
// see compute_stable_hash() above.
/// Add a definition with a parent definition.
pub fn create_root_def(&mut self,
crate_name: &str,
- crate_disambiguator: &str)
+ crate_disambiguator: CrateDisambiguator)
-> DefIndex {
let key = DefKey {
parent: None,
intravisit::walk_crate(&mut collector, &forest.krate);
let crate_disambiguator = sess.local_crate_disambiguator();
- collector.finalize_and_compute_crate_hash(&crate_disambiguator)
+ collector.finalize_and_compute_crate_hash(crate_disambiguator)
};
if log_enabled!(::log::LogLevel::Debug) {
use hir::svh::Svh;
use ich;
use ty::{self, TyCtxt};
-use session::Session;
+use session::{Session, CrateDisambiguator};
use session::search_paths::PathKind;
use util::nodemap::NodeSet;
fn export_macros_untracked(&self, cnum: CrateNum);
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind;
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol;
- fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> ich::Fingerprint;
+ fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
fn struct_field_names_untracked(&self, def: DefId) -> Vec<ast::Name>;
fn item_children_untracked(&self, did: DefId, sess: &Session) -> Vec<def::Export>;
fn dep_kind_untracked(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
fn export_macros_untracked(&self, cnum: CrateNum) { bug!("export_macros") }
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
- fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> ich::Fingerprint {
+ fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator {
bug!("crate_disambiguator")
}
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
pub plugin_attributes: RefCell<Vec<(String, AttributeType)>>,
pub crate_types: RefCell<Vec<config::CrateType>>,
pub dependency_formats: RefCell<dependency_format::Dependencies>,
- /// The crate_disambiguator is constructed out of all the `-C metadata`
+ /// The crate_disambiguator is constructed out of all the `-C metadata`
/// arguments passed to the compiler. Its value together with the crate-name
/// forms a unique global identifier for the crate. It is used to allow
/// multiple crates with the same name to coexist. See the
/// trans::back::symbol_names module for more information.
- pub crate_disambiguator: RefCell<Option<Fingerprint>>,
+ pub crate_disambiguator: RefCell<Option<CrateDisambiguator>>,
pub features: RefCell<feature_gate::Features>,
/// The maximum recursion limit for potentially infinitely recursive
}
impl Session {
- pub fn local_crate_disambiguator(&self) -> Fingerprint {
+ pub fn local_crate_disambiguator(&self) -> CrateDisambiguator {
match *self.crate_disambiguator.borrow() {
- Some(sym) => sym,
+ Some(value) => value,
None => bug!("accessing disambiguator before initialization"),
}
}
/// Returns the symbol name for the registrar function,
/// given the crate Svh and the function DefIndex.
- pub fn generate_plugin_registrar_symbol(&self, disambiguator: Fingerprint,
+ pub fn generate_plugin_registrar_symbol(&self, disambiguator: CrateDisambiguator,
index: DefIndex)
-> String {
- format!("__rustc_plugin_registrar__{}_{}", disambiguator.to_hex(),
+ format!("__rustc_plugin_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
index.as_usize())
}
- pub fn generate_derive_registrar_symbol(&self, disambiguator: Fingerprint, index: DefIndex)
+ pub fn generate_derive_registrar_symbol(&self, disambiguator: CrateDisambiguator,
+ index: DefIndex)
-> String {
- format!("__rustc_derive_registrar__{}_{}", disambiguator.to_hex(),
+ format!("__rustc_derive_registrar__{}_{}", disambiguator.to_fingerprint().to_hex(),
index.as_usize())
}
sess
}
+/// Hash value constructed out of all the `-C metadata` arguments passed to the
+/// compiler. Together with the crate-name forms a unique global identifier for
+/// the crate.
+#[derive(Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Clone, Copy, RustcEncodable, RustcDecodable)]
+pub struct CrateDisambiguator(Fingerprint);
+
+impl CrateDisambiguator {
+ pub fn to_fingerprint(self) -> Fingerprint {
+ self.0
+ }
+}
+
+impl From<Fingerprint> for CrateDisambiguator {
+ fn from(fingerprint: Fingerprint) -> CrateDisambiguator {
+ CrateDisambiguator(fingerprint)
+ }
+}
+
+impl_stable_hash_for!(tuple_struct CrateDisambiguator { fingerprint });
+
/// Holds data on the current incremental compilation session, if there is one.
#[derive(Debug)]
pub enum IncrCompSession {
crate_name,
// Don't print the whole crate disambiguator. That's just
// annoying in debug output.
- &(crate_disambiguator.to_hex())[..4],
+ &(crate_disambiguator.to_fingerprint().to_hex())[..4],
self.def_path(def_id).to_string_no_crate())
}
use dep_graph::{DepConstructor, DepNode};
use errors::DiagnosticBuilder;
-use ich::Fingerprint;
use hir::def_id::{CrateNum, DefId, DefIndex};
use hir::def::{Def, Export};
use hir::{self, TraitCandidate, ItemLocalId};
use middle::exported_symbols::SymbolExportLevel;
use middle::trans::{CodegenUnit, Stats};
use mir;
-use session::CompileResult;
+use session::{CompileResult, CrateDisambiguator};
use session::config::OutputFilenames;
use traits::Vtable;
use traits::specialization_graph;
[] fn native_libraries: NativeLibraries(CrateNum) -> Rc<Vec<NativeLibrary>>,
[] fn plugin_registrar_fn: PluginRegistrarFn(CrateNum) -> Option<DefId>,
[] fn derive_registrar_fn: DeriveRegistrarFn(CrateNum) -> Option<DefId>,
- [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> Fingerprint,
+ [] fn crate_disambiguator: CrateDisambiguator(CrateNum) -> CrateDisambiguator,
[] fn crate_hash: CrateHash(CrateNum) -> Svh,
[] fn original_crate_name: OriginalCrateName(CrateNum) -> Symbol,
use hir::def::{Def, CtorKind, ExportMap};
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use hir::map::DefPathData;
-use ich::{Fingerprint, StableHashingContext};
+use ich::StableHashingContext;
use middle::const_val::ConstVal;
use middle::lang_items::{FnTraitLangItem, FnMutTraitLangItem, FnOnceTraitLangItem};
use middle::privacy::AccessLevels;
use middle::resolve_lifetime::ObjectLifetimeDefault;
use mir::Mir;
use mir::GeneratorLayout;
+use session::CrateDisambiguator;
use traits;
use ty;
use ty::subst::{Subst, Substs};
}
fn crate_disambiguator<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
- crate_num: CrateNum) -> Fingerprint {
+ crate_num: CrateNum) -> CrateDisambiguator {
assert_eq!(crate_num, LOCAL_CRATE);
tcx.sess.local_crate_disambiguator()
}
use rustc::ich::Fingerprint;
use rustc_data_structures::stable_hasher::StableHasher;
use rustc_mir as mir;
-use rustc::session::{Session, CompileResult};
+use rustc::session::{Session, CompileResult, CrateDisambiguator};
use rustc::session::CompileIncomplete;
use rustc::session::config::{self, Input, OutputFilenames, OutputType};
use rustc::session::search_paths::PathKind;
rustc_incremental::prepare_session_directory(
sess,
&crate_name,
- &disambiguator,
+ disambiguator,
);
let dep_graph = if sess.opts.build_dep_graph() {
.collect()
}
-pub fn compute_crate_disambiguator(session: &Session) -> Fingerprint {
+pub fn compute_crate_disambiguator(session: &Session) -> CrateDisambiguator {
use std::hash::Hasher;
// The crate_disambiguator is a 128 bit hash. The disambiguator is fed
let is_exe = session.crate_types.borrow().contains(&config::CrateTypeExecutable);
hasher.write(if is_exe { b"exe" } else { b"lib" });
- hasher.finish()
+ CrateDisambiguator::from(hasher.finish())
}
//! unsupported file system and emit a warning in that case. This is not yet
//! implemented.
-use rustc::ich::Fingerprint;
use rustc::hir::svh::Svh;
-use rustc::session::Session;
+use rustc::session::{Session, CrateDisambiguator};
use rustc::util::fs as fs_util;
use rustc_data_structures::{flock, base_n};
use rustc_data_structures::fx::{FxHashSet, FxHashMap};
/// The garbage collection will take care of it.
pub fn prepare_session_directory(sess: &Session,
crate_name: &str,
- crate_disambiguator: &Fingerprint) {
+ crate_disambiguator: CrateDisambiguator) {
if sess.opts.incremental.is_none() {
return
}
fn crate_path(sess: &Session,
crate_name: &str,
- crate_disambiguator: &Fingerprint)
+ crate_disambiguator: CrateDisambiguator)
-> PathBuf {
let incr_dir = sess.opts.incremental.as_ref().unwrap().clone();
- let crate_disambiguator = crate_disambiguator.to_smaller_hash();
- let crate_name = format!("{}-{}",
- crate_name,
- base_n::encode(crate_disambiguator, INT_ENCODE_BASE));
+ // The full crate disambiguator is really long. 64 bits of it should be
+ // sufficient.
+ let crate_disambiguator = crate_disambiguator.to_fingerprint().to_smaller_hash();
+ let crate_disambiguator = base_n::encode(crate_disambiguator, INT_ENCODE_BASE);
+
+ let crate_name = format!("{}-{}", crate_name, crate_disambiguator);
incr_dir.join(crate_name)
}
use native_libs::relevant_lib;
use schema::CrateRoot;
-use rustc::ich::Fingerprint;
use rustc::hir::def_id::{CrateNum, DefIndex, CRATE_DEF_INDEX};
use rustc::hir::svh::Svh;
use rustc::middle::allocator::AllocatorKind;
use rustc::middle::cstore::DepKind;
-use rustc::session::Session;
+use rustc::session::{Session, CrateDisambiguator};
use rustc::session::config::{Sanitizer, self};
use rustc_back::PanicStrategy;
use rustc::session::search_paths::PathKind;
pub fn find_plugin_registrar(&mut self,
span: Span,
name: &str)
- -> Option<(PathBuf, Fingerprint, DefIndex)> {
+ -> Option<(PathBuf, CrateDisambiguator, DefIndex)> {
let ekrate = self.read_extension_crate(span, &ExternCrateInfo {
name: Symbol::intern(name),
ident: Symbol::intern(name),
use schema;
-use rustc::ich::Fingerprint;
use rustc::hir::def_id::{CRATE_DEF_INDEX, CrateNum, DefIndex};
use rustc::hir::map::definitions::DefPathTable;
use rustc::hir::svh::Svh;
use rustc::middle::cstore::{DepKind, ExternCrate, MetadataLoader};
+use rustc::session::CrateDisambiguator;
use rustc_back::PanicStrategy;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc::util::nodemap::{FxHashMap, FxHashSet, NodeMap};
pub fn hash(&self) -> Svh {
self.root.hash
}
- pub fn disambiguator(&self) -> Fingerprint {
+ pub fn disambiguator(&self) -> CrateDisambiguator {
self.root.disambiguator
}
LoadedMacro, EncodedMetadata,
EncodedMetadataHashes, NativeLibraryKind};
use rustc::middle::stability::DeprecationEntry;
-use rustc::ich::Fingerprint;
use rustc::hir::def;
-use rustc::session::Session;
+use rustc::session::{CrateDisambiguator, Session};
use rustc::ty::{self, TyCtxt};
use rustc::ty::maps::Providers;
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, CRATE_DEF_INDEX};
self.get_crate_data(cnum).name
}
- fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> Fingerprint
+ fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator
{
self.get_crate_data(cnum).disambiguator()
}
use rustc::hir;
use rustc::hir::def::{self, CtorKind};
use rustc::hir::def_id::{DefIndex, DefId, CrateNum};
-use rustc::ich::{Fingerprint, StableHashingContext};
+use rustc::ich::StableHashingContext;
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary};
use rustc::middle::lang_items;
use rustc::mir;
+use rustc::session::CrateDisambiguator;
use rustc::ty::{self, Ty, ReprOptions};
use rustc_back::PanicStrategy;
pub name: Symbol,
pub triple: String,
pub hash: hir::svh::Svh,
- pub disambiguator: Fingerprint,
+ pub disambiguator: CrateDisambiguator,
pub panic_strategy: PanicStrategy,
pub has_global_allocator: bool,
pub has_default_lib_allocator: bool,
let mut definitions = Definitions::new();
DefCollector::new(&mut definitions, Mark::root())
- .collect_root(crate_name, &session.local_crate_disambiguator().to_hex());
+ .collect_root(crate_name, session.local_crate_disambiguator());
let mut invocations = FxHashMap();
invocations.insert(Mark::root(),
pub fn metadata_symbol_name(tcx: TyCtxt) -> String {
format!("rust_metadata_{}_{}",
tcx.crate_name(LOCAL_CRATE),
- tcx.crate_disambiguator(LOCAL_CRATE).to_hex())
+ tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex())
}
fn crate_export_threshold(crate_type: config::CrateType) -> SymbolExportLevel {
// 1. http://llvm.org/bugs/show_bug.cgi?id=11479
let llmod_id = format!("{}-{}.rs",
cgu.name(),
- tcx.crate_disambiguator(LOCAL_CRATE));
+ tcx.crate_disambiguator(LOCAL_CRATE)
+ .to_fingerprint().to_hex());
// Instantiate translation items without filling out definitions yet...
let scx = SharedCrateContext::new(tcx);
// END RUST SOURCE
// START rustc.node12.EraseRegions.after.mir
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:5) => validate_1[e36f]::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:5) => validate_1[e36f]::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:5) => validate_1[317d]::{{impl}}[0]::foo[0] }, BrAnon(0)) Test, _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:5) => validate_1[317d]::{{impl}}[0]::foo[0] }, BrAnon(1)) mut i32]);
// ...
// return;
// }
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(50)], _2: &ReErased mut i32) -> i32 {
// ...
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:11) => validate_1[e36f]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:11) => validate_1[e36f]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:11) => validate_1[317d]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(50)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:11) => validate_1[317d]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
// StorageLive(_3);
// _3 = _2;
// StorageLive(_4);
// fn write_42::{{closure}}(_1: &ReErased [closure@NodeId(22)], _2: *mut i32) -> () {
// ...
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_4[e36f]::write_42[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(22)], _2: *mut i32]);
-// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_4[e36f]::write_42[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(22)], _2: *mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_4[317d]::write_42[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(22)], _2: *mut i32]);
+// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_4[317d]::write_42[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(22)], _2: *mut i32]);
// StorageLive(_3);
// _3 = _2;
// (*_3) = const 23i32;
// fn test(_1: &ReErased mut i32) -> () {
// ...
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_4[e36f]::test[0] }, BrAnon(0)) mut i32]);
-// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_4[e36f]::test[0] }, BrAnon(0)) mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_4[317d]::test[0] }, BrAnon(0)) mut i32]);
+// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_4[317d]::test[0] }, BrAnon(0)) mut i32]);
// ...
// _3 = const write_42(_4) -> bb1;
// }
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(60)], _2: &ReErased mut i32) -> bool {
// ...
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[e36f]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[e36f]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
-// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[e36f]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[e36f]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[317d]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[317d]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
+// Validate(Release, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[317d]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(60)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:10) => validate_4[317d]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
// StorageLive(_3);
// ...
// _0 = const write_42(_4) -> bb1;
// fn test(_1: &ReErased mut i32) -> () {
// ...
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_5[e36f]::test[0] }, BrAnon(0)) mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(0:4) => validate_5[317d]::test[0] }, BrAnon(0)) mut i32]);
// ...
// Validate(Release, [_3: bool, _4: *mut i32]);
// _3 = const write_42(_4) -> bb1;
// fn main::{{closure}}(_1: &ReErased [closure@NodeId(46)], _2: &ReErased mut i32) -> bool {
// ...
// bb0: {
-// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[e36f]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[e36f]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
+// Validate(Acquire, [_1: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[317d]::main[0]::{{closure}}[0] }, BrEnv) [closure@NodeId(46)], _2: &ReFree(DefId { krate: CrateNum(0), index: DefIndex(1:9) => validate_5[317d]::main[0]::{{closure}}[0] }, BrAnon(1)) mut i32]);
// StorageLive(_3);
// _3 = _2;
// StorageLive(_4);