rustc: Move stable_crate_id
from Session
to GlobalCtxt
Removes a piece of mutable state. Follow up to #114578.
This commit is contained in:
parent
0b89aac08d
commit
907aa440cf
10 changed files with 25 additions and 27 deletions
|
@ -60,7 +60,7 @@ use crate::mir::mono::MonoItem;
|
|||
use crate::ty::TyCtxt;
|
||||
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
|
||||
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::definitions::DefPathHash;
|
||||
use rustc_hir::{HirId, ItemLocalId, OwnerId};
|
||||
use rustc_query_system::dep_graph::FingerprintStyle;
|
||||
|
@ -371,7 +371,7 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for HirId {
|
|||
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
|
||||
if tcx.fingerprint_style(dep_node.kind) == FingerprintStyle::HirId {
|
||||
let (local_hash, local_id) = Fingerprint::from(dep_node.hash).split();
|
||||
let def_path_hash = DefPathHash::new(tcx.sess.local_stable_crate_id(), local_hash);
|
||||
let def_path_hash = DefPathHash::new(tcx.stable_crate_id(LOCAL_CRATE), local_hash);
|
||||
let def_id = tcx
|
||||
.def_path_hash_to_def_id(def_path_hash, &mut || {
|
||||
panic!("Failed to extract HirId: {:?} {}", dep_node.kind, dep_node.hash)
|
||||
|
|
|
@ -1210,7 +1210,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, _: LocalCrate) -> Svh {
|
|||
owner_spans.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.stable_crate_id(LOCAL_CRATE).hash_stable(&mut hcx, &mut stable_hasher);
|
||||
// Hash visibility information since it does not appear in HIR.
|
||||
resolutions.visibilities.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
resolutions.has_pub_restricted.hash_stable(&mut hcx, &mut stable_hasher);
|
||||
|
|
|
@ -72,6 +72,6 @@ pub fn metadata_symbol_name(tcx: TyCtxt<'_>) -> String {
|
|||
format!(
|
||||
"rust_metadata_{}_{:08x}",
|
||||
tcx.crate_name(LOCAL_CRATE),
|
||||
tcx.sess.local_stable_crate_id(),
|
||||
tcx.stable_crate_id(LOCAL_CRATE),
|
||||
)
|
||||
}
|
||||
|
|
|
@ -524,13 +524,13 @@ impl<'tcx> 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();
|
||||
let local_stable_crate_id = tcx.stable_crate_id(LOCAL_CRATE);
|
||||
format!("-in-{}.{:08x}", tcx.crate_name(LOCAL_CRATE), local_stable_crate_id)
|
||||
} else {
|
||||
String::new()
|
||||
};
|
||||
|
||||
let stable_crate_id = tcx.sess.local_stable_crate_id();
|
||||
let stable_crate_id = tcx.stable_crate_id(LOCAL_CRATE);
|
||||
format!("{}.{:08x}{}", tcx.crate_name(cnum), stable_crate_id, local_crate_id)
|
||||
});
|
||||
|
||||
|
|
|
@ -527,6 +527,12 @@ pub struct GlobalCtxt<'tcx> {
|
|||
|
||||
pub sess: &'tcx Session,
|
||||
crate_types: Vec<CrateType>,
|
||||
/// The `stable_crate_id` is constructed out of the crate name and all the
|
||||
/// `-C metadata` arguments passed to the compiler. Its value forms a unique
|
||||
/// global identifier for the crate. It is used to allow multiple crates
|
||||
/// with the same name to coexist. See the
|
||||
/// `rustc_symbol_mangling` crate for more information.
|
||||
stable_crate_id: StableCrateId,
|
||||
|
||||
/// This only ever stores a `LintStore` but we don't want a dependency on that type here.
|
||||
///
|
||||
|
@ -688,6 +694,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
pub fn create_global_ctxt(
|
||||
s: &'tcx Session,
|
||||
crate_types: Vec<CrateType>,
|
||||
stable_crate_id: StableCrateId,
|
||||
lint_store: Lrc<dyn Any + sync::DynSend + sync::DynSync>,
|
||||
arena: &'tcx WorkerLocal<Arena<'tcx>>,
|
||||
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
|
||||
|
@ -707,6 +714,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
GlobalCtxt {
|
||||
sess: s,
|
||||
crate_types,
|
||||
stable_crate_id,
|
||||
lint_store,
|
||||
arena,
|
||||
hir_arena,
|
||||
|
@ -842,7 +850,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
#[inline]
|
||||
pub fn stable_crate_id(self, crate_num: CrateNum) -> StableCrateId {
|
||||
if crate_num == LOCAL_CRATE {
|
||||
self.sess.local_stable_crate_id()
|
||||
self.stable_crate_id
|
||||
} else {
|
||||
self.cstore_untracked().stable_crate_id(crate_num)
|
||||
}
|
||||
|
@ -852,7 +860,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
/// that the crate in question has already been loaded by the CrateStore.
|
||||
#[inline]
|
||||
pub fn stable_crate_id_to_crate_num(self, stable_crate_id: StableCrateId) -> CrateNum {
|
||||
if stable_crate_id == self.sess.local_stable_crate_id() {
|
||||
if stable_crate_id == self.stable_crate_id(LOCAL_CRATE) {
|
||||
LOCAL_CRATE
|
||||
} else {
|
||||
self.cstore_untracked().stable_crate_id_to_crate_num(stable_crate_id)
|
||||
|
@ -869,7 +877,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
// If this is a DefPathHash from the local crate, we can look up the
|
||||
// DefId in the tcx's `Definitions`.
|
||||
if stable_crate_id == self.sess.local_stable_crate_id() {
|
||||
if stable_crate_id == self.stable_crate_id(LOCAL_CRATE) {
|
||||
self.untracked.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
|
||||
} else {
|
||||
// If this is a DefPathHash from an upstream crate, let the CrateStore map
|
||||
|
@ -886,7 +894,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
// 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(LOCAL_CRATE), self.sess.local_stable_crate_id())
|
||||
(self.crate_name(LOCAL_CRATE), self.stable_crate_id(LOCAL_CRATE))
|
||||
} else {
|
||||
let cstore = &*self.cstore_untracked();
|
||||
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue