Auto merge of #86143 - bjorn3:revert_revert_merge_crate_disambiguator, r=michaelwoerister

Reland "Merge CrateDisambiguator into StableCrateId"

Reverts https://github.com/rust-lang/rust/pull/85891 as this revert of #85804 made perf even worse.

r? `@Mark-Simulacrum`
This commit is contained in:
bors 2021-07-06 11:31:59 +00:00
commit d04ec47358
67 changed files with 227 additions and 298 deletions

View file

@ -15,6 +15,7 @@ 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};
@ -990,25 +991,24 @@ 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_crate_disambiguator().to_fingerprint().hash_stable(&mut hcx, &mut stable_hasher);
tcx.sess.local_stable_crate_id().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<(Symbol, Fingerprint, Svh)> {
fn upstream_crates(cstore: &dyn CrateStore) -> Vec<(StableCrateId, Svh)> {
let mut upstream_crates: Vec<_> = cstore
.crates_untracked()
.iter()
.map(|&cnum| {
let name = cstore.crate_name_untracked(cnum);
let disambiguator = cstore.crate_disambiguator_untracked(cnum).to_fingerprint();
let stable_crate_id = cstore.stable_crate_id_untracked(cnum);
let hash = cstore.crate_hash_untracked(cnum);
(name, disambiguator, hash)
(stable_crate_id, hash)
})
.collect();
upstream_crates.sort_unstable_by_key(|&(name, dis, _)| (name.as_str(), dis));
upstream_crates.sort_unstable_by_key(|&(stable_crate_id, _)| stable_crate_id);
upstream_crates
}

View file

@ -13,7 +13,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::CrateDisambiguator;
use rustc_session::StableCrateId;
use rustc_span::symbol::Symbol;
use rustc_span::Span;
use rustc_target::spec::Target;
@ -185,7 +185,7 @@ pub trait CrateStore {
// "queries" used in resolve that aren't tracked for incremental compilation
fn crate_name_untracked(&self, cnum: CrateNum) -> Symbol;
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
fn stable_crate_id_untracked(&self, cnum: CrateNum) -> StableCrateId;
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
// This is basically a 1-based range of ints, which is a little

View file

@ -48,8 +48,8 @@ impl<'tcx> ExportedSymbol<'tcx> {
pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String {
format!(
"rust_metadata_{}_{}",
"rust_metadata_{}_{:08x}",
tcx.crate_name(LOCAL_CRATE),
tcx.crate_disambiguator(LOCAL_CRATE).to_fingerprint().to_hex()
tcx.sess.local_stable_crate_id().to_u64(),
)
}

View file

@ -490,15 +490,23 @@ 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_crate_disambiguator = format!("{}", tcx.crate_disambiguator(LOCAL_CRATE));
format!("-in-{}.{}", tcx.crate_name(LOCAL_CRATE), &local_crate_disambiguator[0..8])
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() as u32,
)
} else {
String::new()
};
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)
let stable_crate_id = tcx.sess.local_stable_crate_id();
format!(
"{}.{:08x}{}",
tcx.crate_name(cnum),
stable_crate_id.to_u64() as u32,
local_crate_id,
)
});
write!(cgu_name, "{}", crate_prefix).unwrap();

View file

@ -1233,10 +1233,6 @@ 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 {

View file

@ -1299,30 +1299,34 @@ impl<'tcx> TyCtxt<'tcx> {
}
#[inline]
pub fn stable_crate_id(self, cnum: CrateNum) -> StableCrateId {
self.def_path_hash(cnum.as_def_id()).stable_crate_id()
pub fn stable_crate_id(self, crate_num: CrateNum) -> StableCrateId {
if crate_num == LOCAL_CRATE {
self.sess.local_stable_crate_id()
} else {
self.cstore.stable_crate_id_untracked(crate_num)
}
}
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 disambiguator since this code is called from debug!()
// crate name and stable crate id since this code is called from debug!()
// statements within the query system and we'd run into endless
// recursion otherwise.
let (crate_name, crate_disambiguator) = if def_id.is_local() {
(self.crate_name, self.sess.local_crate_disambiguator())
let (crate_name, stable_crate_id) = if def_id.is_local() {
(self.crate_name, self.sess.local_stable_crate_id())
} else {
(
self.cstore.crate_name_untracked(def_id.krate),
self.cstore.crate_disambiguator_untracked(def_id.krate),
self.def_path_hash(def_id.krate.as_def_id()).stable_crate_id(),
)
};
format!(
"{}[{}]{}",
crate_name,
// Don't print the whole crate disambiguator. That's just
// Don't print the whole stable crate id. That's just
// annoying in debug output.
&(crate_disambiguator.to_fingerprint().to_hex())[..4],
&(format!("{:08x}", stable_crate_id.to_u64()))[..4],
self.def_path(def_id).to_string_no_crate_verbose()
)
}

View file

@ -48,7 +48,6 @@ 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_session::Limits;
use rustc_target::spec::PanicStrategy;