diff options
Diffstat (limited to 'compiler/rustc_middle/src')
| -rw-r--r-- | compiler/rustc_middle/src/dep_graph/dep_node.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/hir/map/mod.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/middle/cstore.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/middle/exported_symbols.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/mir/mono.rs | 13 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/query/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/context.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/query/mod.rs | 1 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/query/on_disk_cache.rs | 23 |
9 files changed, 40 insertions, 35 deletions
diff --git a/compiler/rustc_middle/src/dep_graph/dep_node.rs b/compiler/rustc_middle/src/dep_graph/dep_node.rs index aa54d1ae7b9..8476929eaec 100644 --- a/compiler/rustc_middle/src/dep_graph/dep_node.rs +++ b/compiler/rustc_middle/src/dep_graph/dep_node.rs @@ -285,7 +285,7 @@ pub type DepNode = rustc_query_system::dep_graph::DepNode<DepKind>; // required that their size stay the same, but we don't want to change // it inadvertently. This assert just ensures we're aware of any change. #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] -static_assert_size!(DepNode, 17); +static_assert_size!(DepNode, 18); #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))] static_assert_size!(DepNode, 24); diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 07b39c97c49..20bbf9097f4 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -15,7 +15,6 @@ use rustc_hir::intravisit::Visitor; use rustc_hir::itemlikevisit::ItemLikeVisitor; use rustc_hir::*; use rustc_index::vec::Idx; -use rustc_span::def_id::StableCrateId; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, Ident, Symbol}; @@ -991,24 +990,25 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh { upstream_crates.hash_stable(&mut hcx, &mut stable_hasher); source_file_names.hash_stable(&mut hcx, &mut stable_hasher); tcx.sess.opts.dep_tracking_hash(true).hash_stable(&mut hcx, &mut stable_hasher); - tcx.sess.local_stable_crate_id().hash_stable(&mut hcx, &mut stable_hasher); + tcx.sess.local_crate_disambiguator().to_fingerprint().hash_stable(&mut hcx, &mut stable_hasher); tcx.untracked_crate.non_exported_macro_attrs.hash_stable(&mut hcx, &mut stable_hasher); let crate_hash: Fingerprint = stable_hasher.finish(); Svh::new(crate_hash.to_smaller_hash()) } -fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(StableCrateId, Svh)> { +fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(Symbol, Fingerprint, Svh)> { let mut upstream_crates: Vec<_> = cstore .crates_untracked() .iter() .map(|&cnum| { - let stable_crate_id = cstore.stable_crate_id_untracked(cnum); + let name = cstore.crate_name_untracked(cnum); + let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint(); let hash = cstore.crate_hash_untracked(cnum); - (stable_crate_id, hash) + (name, disambiguator, hash) }) .collect(); - upstream_crates.sort_unstable_by_key(|&(stable_crate_id, _)| stable_crate_id); + upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis)); upstream_crates } diff --git a/compiler/rustc_middle/src/middle/cstore.rs b/compiler/rustc_middle/src/middle/cstore.rs index df578708931..f09449ab864 100644 --- a/compiler/rustc_middle/src/middle/cstore.rs +++ b/compiler/rustc_middle/src/middle/cstore.rs @@ -14,7 +14,7 @@ use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_macros::HashStable; use rustc_session::search_paths::PathKind; use rustc_session::utils::NativeLibKind; -use rustc_session::StableCrateId; +use rustc_session::CrateDisambiguator; use rustc_span::symbol::Symbol; use rustc_span::Span; use rustc_target::spec::Target; @@ -206,7 +206,7 @@ pub trait CrateStore { // "queries" used in resolve that aren't tracked for incremental compilation fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol; - fn stable_crate_id_untracked(&self, cnum: CrateNum) -> StableCrateId; + fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator; fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh; // This is basically a 1-based range of ints, which is a little diff --git a/compiler/rustc_middle/src/middle/exported_symbols.rs b/compiler/rustc_middle/src/middle/exported_symbols.rs index 5ea78e087f8..288dd039446 100644 --- a/compiler/rustc_middle/src/middle/exported_symbols.rs +++ b/compiler/rustc_middle/src/middle/exported_symbols.rs @@ -48,8 +48,8 @@ impl<'tcx> ExportedSymbol<'tcx> { pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String { format!( - "rust_metadata_{}_{:08x}", + "rust_metadata_{}_{}", tcx.crate_name(LOCAL_CRATE), - tcx.sess.local_stable_crate_id().to_u64(), + tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex() ) } diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index c354cdd985b..74650f50a1c 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -490,18 +490,15 @@ impl CodegenUnitNameBuilder<'tcx> { // local crate's ID. Otherwise there can be collisions between CGUs // instantiating stuff for upstream crates. let local_crate_id = if cnum != LOCAL_CRATE { - let local_stable_crate_id = tcx.sess.local_stable_crate_id(); - format!( - "-in-{}.{:08x}", - tcx.crate_name(LOCAL_CRATE), - local_stable_crate_id.to_u64() - ) + let local_crate_disambiguator = format!("{}", tcx.crate_disambiguator(LOCAL_CRATE)); + format!("-in-{}.{}", tcx.crate_name(LOCAL_CRATE), &local_crate_disambiguator[0..8]) } else { String::new() }; - let stable_crate_id = tcx.sess.local_stable_crate_id(); - format!("{}.{:08x}{}", tcx.crate_name(cnum), stable_crate_id.to_u64(), local_crate_id) + let crate_disambiguator = tcx.crate_disambiguator(cnum).to_string(); + // Using a shortened disambiguator of about 40 bits + format!("{}.{}{}", tcx.crate_name(cnum), &crate_disambiguator[0..8], local_crate_id) }); write!(cgu_name, "{}", crate_prefix).unwrap(); diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index ad624d8d113..0860520ef9d 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1237,6 +1237,10 @@ rustc_queries! { query proc_macro_decls_static(_: ()) -> Option<LocalDefId> { desc { "looking up the derive registrar for a crate" } } + query crate_disambiguator(_: CrateNum) -> CrateDisambiguator { + eval_always + desc { "looking up the disambiguator a crate" } + } // The macro which defines `rustc_metadata::provide_extern` depends on this query's name. // Changing the name should cause a compiler error, but in case that changes, be aware. query crate_hash(_: CrateNum) -> Svh { diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 970e669c16f..047b95f116e 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -1275,24 +1275,24 @@ impl<'tcx> TyCtxt<'tcx> { pub fn def_path_debug_str(self, def_id: DefId) -> String { // We are explicitly not going through queries here in order to get - // crate name and stable crate id since this code is called from debug!() + // crate name and disambiguator since this code is called from debug!() // statements within the query system and we'd run into endless // recursion otherwise. - let (crate_name, stable_crate_id) = if def_id.is_local() { - (self.crate_name, self.sess.local_stable_crate_id()) + let (crate_name, crate_disambiguator) = if def_id.is_local() { + (self.crate_name, self.sess.local_crate_disambiguator()) } else { ( self.cstore.crate_name_untracked(def_id.krate), - self.def_path_hash(def_id.krate.as_def_id()).stable_crate_id(), + self.cstore.crate_disambiguator_untracked(def_id.krate), ) }; format!( "{}[{}]{}", crate_name, - // Don't print the whole stable crate id. That's just + // Don't print the whole crate disambiguator. That's just // annoying in debug output. - &(format!("{:08x}", stable_crate_id.to_u64()))[..4], + &(crate_disambiguator.to_fingerprint().to_hex())[..4], self.def_path(def_id).to_string_no_crate_verbose() ) } diff --git a/compiler/rustc_middle/src/ty/query/mod.rs b/compiler/rustc_middle/src/ty/query/mod.rs index a5b540dcb70..297110ee3ec 100644 --- a/compiler/rustc_middle/src/ty/query/mod.rs +++ b/compiler/rustc_middle/src/ty/query/mod.rs @@ -47,6 +47,7 @@ use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec}; use rustc_serialize::opaque; use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; use rustc_session::utils::NativeLibKind; +use rustc_session::CrateDisambiguator; use rustc_target::spec::PanicStrategy; use rustc_ast as ast; diff --git a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs index e473559812f..ebb52d8863f 100644 --- a/compiler/rustc_middle/src/ty/query/on_disk_cache.rs +++ b/compiler/rustc_middle/src/ty/query/on_disk_cache.rs @@ -18,7 +18,7 @@ use rustc_serialize::{ opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize}, Decodable, Decoder, Encodable, Encoder, }; -use rustc_session::{Session, StableCrateId}; +use rustc_session::{CrateDisambiguator, Session}; use rustc_span::hygiene::{ ExpnDataDecodeMode, ExpnDataEncodeMode, ExpnId, HygieneDecodeContext, HygieneEncodeContext, SyntaxContext, SyntaxContextData, @@ -52,7 +52,7 @@ pub struct OnDiskCache<'sess> { // session. current_diagnostics: Lock<FxHashMap<DepNodeIndex, Vec<Diagnostic>>>, - prev_cnums: Vec<(u32, StableCrateId)>, + prev_cnums: Vec<(u32, String, CrateDisambiguator)>, cnum_map: OnceCell<IndexVec<CrateNum, Option<CrateNum>>>, source_map: &'sess SourceMap, @@ -120,7 +120,7 @@ pub struct OnDiskCache<'sess> { #[derive(Encodable, Decodable)] struct Footer { file_index_to_stable_id: FxHashMap<SourceFileIndex, StableSourceFileId>, - prev_cnums: Vec<(u32, StableCrateId)>, + prev_cnums: Vec<(u32, String, CrateDisambiguator)>, query_result_index: EncodedQueryResultIndex, diagnostics_index: EncodedQueryResultIndex, // The location of all allocations. @@ -349,8 +349,9 @@ impl<'sess> OnDiskCache<'sess> { let prev_cnums: Vec<_> = sorted_cnums .iter() .map(|&cnum| { - let stable_crate_id = tcx.def_path_hash(cnum.as_def_id()).stable_crate_id(); - (cnum.as_u32(), stable_crate_id) + let crate_name = tcx.crate_name(cnum).to_string(); + let crate_disambiguator = tcx.crate_disambiguator(cnum); + (cnum.as_u32(), crate_name, crate_disambiguator) }) .collect(); @@ -574,23 +575,25 @@ impl<'sess> OnDiskCache<'sess> { // maps to None. fn compute_cnum_map( tcx: TyCtxt<'_>, - prev_cnums: &[(u32, StableCrateId)], + prev_cnums: &[(u32, String, CrateDisambiguator)], ) -> IndexVec<CrateNum, Option<CrateNum>> { tcx.dep_graph.with_ignore(|| { let current_cnums = tcx .all_crate_nums(()) .iter() .map(|&cnum| { - let stable_crate_id = tcx.def_path_hash(cnum.as_def_id()).stable_crate_id(); - (stable_crate_id, cnum) + let crate_name = tcx.crate_name(cnum).to_string(); + let crate_disambiguator = tcx.crate_disambiguator(cnum); + ((crate_name, crate_disambiguator), cnum) }) .collect::<FxHashMap<_, _>>(); let map_size = prev_cnums.iter().map(|&(cnum, ..)| cnum).max().unwrap_or(0) + 1; let mut map = IndexVec::from_elem_n(None, map_size as usize); - for &(prev_cnum, stable_crate_id) in prev_cnums { - map[CrateNum::from_u32(prev_cnum)] = current_cnums.get(&stable_crate_id).cloned(); + for &(prev_cnum, ref crate_name, crate_disambiguator) in prev_cnums { + let key = (crate_name.clone(), crate_disambiguator); + map[CrateNum::from_u32(prev_cnum)] = current_cnums.get(&key).cloned(); } map[LOCAL_CRATE] = Some(LOCAL_CRATE); |
