Fold Definitions into the untracked data

This commit is contained in:
Oli Scherer 2022-12-08 08:52:07 +00:00
parent 1c1d3570ee
commit 75ff5c7dd3
10 changed files with 49 additions and 70 deletions

View File

@ -805,7 +805,6 @@ pub fn create_global_ctxt<'tcx>(
}); });
let ty::ResolverOutputs { let ty::ResolverOutputs {
definitions,
global_ctxt: untracked_resolutions, global_ctxt: untracked_resolutions,
ast_lowering: untracked_resolver_for_lowering, ast_lowering: untracked_resolver_for_lowering,
untracked, untracked,
@ -818,7 +817,6 @@ pub fn create_global_ctxt<'tcx>(
lint_store, lint_store,
arena, arena,
hir_arena, hir_arena,
definitions,
untracked_resolutions, untracked_resolutions,
untracked, untracked,
krate, krate,

View File

@ -13,7 +13,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
use rustc_ast::{self as ast, *}; use rustc_ast::{self as ast, *};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::svh::Svh; use rustc_data_structures::svh::Svh;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::{Lrc, ReadGuard};
use rustc_expand::base::SyntaxExtension; use rustc_expand::base::SyntaxExtension;
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
use rustc_hir::definitions::Definitions; use rustc_hir::definitions::Definitions;
@ -69,7 +69,7 @@ pub struct CrateLoader<'a> {
// Immutable configuration. // Immutable configuration.
sess: &'a Session, sess: &'a Session,
metadata_loader: &'a MetadataLoaderDyn, metadata_loader: &'a MetadataLoaderDyn,
definitions: &'a Definitions, definitions: ReadGuard<'a, Definitions>,
local_crate_name: Symbol, local_crate_name: Symbol,
// Mutable output. // Mutable output.
cstore: &'a mut CStore, cstore: &'a mut CStore,
@ -267,7 +267,7 @@ impl<'a> CrateLoader<'a> {
metadata_loader: &'a MetadataLoaderDyn, metadata_loader: &'a MetadataLoaderDyn,
local_crate_name: Symbol, local_crate_name: Symbol,
cstore: &'a mut CStore, cstore: &'a mut CStore,
definitions: &'a Definitions, definitions: ReadGuard<'a, Definitions>,
used_extern_options: &'a mut FxHashSet<Symbol>, used_extern_options: &'a mut FxHashSet<Symbol>,
) -> Self { ) -> Self {
CrateLoader { CrateLoader {

View File

@ -35,7 +35,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap}; use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_data_structures::steal::Steal; use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{self, Lock, Lrc, ReadGuard, RwLock, WorkerLocal}; use rustc_data_structures::sync::{self, Lock, Lrc, ReadGuard, WorkerLocal};
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_data_structures::vec_map::VecMap; use rustc_data_structures::vec_map::VecMap;
use rustc_errors::{ use rustc_errors::{
@ -182,18 +182,12 @@ impl<'tcx> CtxtInterners<'tcx> {
/// Interns a type. /// Interns a type.
#[allow(rustc::usage_of_ty_tykind)] #[allow(rustc::usage_of_ty_tykind)]
#[inline(never)] #[inline(never)]
fn intern_ty( fn intern_ty(&self, kind: TyKind<'tcx>, sess: &Session, untracked: &Untracked) -> Ty<'tcx> {
&self,
kind: TyKind<'tcx>,
sess: &Session,
definitions: &rustc_hir::definitions::Definitions,
untracked: &Untracked,
) -> Ty<'tcx> {
Ty(Interned::new_unchecked( Ty(Interned::new_unchecked(
self.type_ self.type_
.intern(kind, |kind| { .intern(kind, |kind| {
let flags = super::flags::FlagComputation::for_kind(&kind); let flags = super::flags::FlagComputation::for_kind(&kind);
let stable_hash = self.stable_hash(&flags, sess, definitions, untracked, &kind); let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
InternedInSet(self.arena.alloc(WithCachedTypeInfo { InternedInSet(self.arena.alloc(WithCachedTypeInfo {
internee: kind, internee: kind,
@ -210,7 +204,6 @@ impl<'tcx> CtxtInterners<'tcx> {
&self, &self,
flags: &ty::flags::FlagComputation, flags: &ty::flags::FlagComputation,
sess: &'a Session, sess: &'a Session,
definitions: &'a rustc_hir::definitions::Definitions,
untracked: &'a Untracked, untracked: &'a Untracked,
val: &T, val: &T,
) -> Fingerprint { ) -> Fingerprint {
@ -220,7 +213,7 @@ impl<'tcx> CtxtInterners<'tcx> {
Fingerprint::ZERO Fingerprint::ZERO
} else { } else {
let mut hasher = StableHasher::new(); let mut hasher = StableHasher::new();
let mut hcx = StableHashingContext::new(sess, definitions, untracked); let mut hcx = StableHashingContext::new(sess, untracked);
val.hash_stable(&mut hcx, &mut hasher); val.hash_stable(&mut hcx, &mut hasher);
hasher.finish() hasher.finish()
} }
@ -231,7 +224,6 @@ impl<'tcx> CtxtInterners<'tcx> {
&self, &self,
kind: Binder<'tcx, PredicateKind<'tcx>>, kind: Binder<'tcx, PredicateKind<'tcx>>,
sess: &Session, sess: &Session,
definitions: &rustc_hir::definitions::Definitions,
untracked: &Untracked, untracked: &Untracked,
) -> Predicate<'tcx> { ) -> Predicate<'tcx> {
Predicate(Interned::new_unchecked( Predicate(Interned::new_unchecked(
@ -239,7 +231,7 @@ impl<'tcx> CtxtInterners<'tcx> {
.intern(kind, |kind| { .intern(kind, |kind| {
let flags = super::flags::FlagComputation::for_predicate(kind); let flags = super::flags::FlagComputation::for_predicate(kind);
let stable_hash = self.stable_hash(&flags, sess, definitions, untracked, &kind); let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
InternedInSet(self.arena.alloc(WithCachedTypeInfo { InternedInSet(self.arena.alloc(WithCachedTypeInfo {
internee: kind, internee: kind,
@ -957,10 +949,9 @@ impl<'tcx> CommonTypes<'tcx> {
fn new( fn new(
interners: &CtxtInterners<'tcx>, interners: &CtxtInterners<'tcx>,
sess: &Session, sess: &Session,
definitions: &rustc_hir::definitions::Definitions,
untracked: &Untracked, untracked: &Untracked,
) -> CommonTypes<'tcx> { ) -> CommonTypes<'tcx> {
let mk = |ty| interners.intern_ty(ty, sess, definitions, untracked); let mk = |ty| interners.intern_ty(ty, sess, untracked);
CommonTypes { CommonTypes {
unit: mk(Tuple(List::empty())), unit: mk(Tuple(List::empty())),
@ -1106,8 +1097,6 @@ pub struct GlobalCtxt<'tcx> {
/// Common consts, pre-interned for your convenience. /// Common consts, pre-interned for your convenience.
pub consts: CommonConsts<'tcx>, pub consts: CommonConsts<'tcx>,
definitions: RwLock<Definitions>,
untracked: Untracked, untracked: Untracked,
/// Output of the resolver. /// Output of the resolver.
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt, pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
@ -1273,7 +1262,6 @@ impl<'tcx> TyCtxt<'tcx> {
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>, lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
arena: &'tcx WorkerLocal<Arena<'tcx>>, arena: &'tcx WorkerLocal<Arena<'tcx>>,
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>, hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
definitions: Definitions,
untracked_resolutions: ty::ResolverGlobalCtxt, untracked_resolutions: ty::ResolverGlobalCtxt,
untracked: Untracked, untracked: Untracked,
krate: Lrc<ast::Crate>, krate: Lrc<ast::Crate>,
@ -1288,7 +1276,7 @@ impl<'tcx> TyCtxt<'tcx> {
s.emit_fatal(err); s.emit_fatal(err);
}); });
let interners = CtxtInterners::new(arena); let interners = CtxtInterners::new(arena);
let common_types = CommonTypes::new(&interners, s, &definitions, &untracked); let common_types = CommonTypes::new(&interners, s, &untracked);
let common_lifetimes = CommonLifetimes::new(&interners); let common_lifetimes = CommonLifetimes::new(&interners);
let common_consts = CommonConsts::new(&interners, &common_types); let common_consts = CommonConsts::new(&interners, &common_types);
@ -1299,7 +1287,6 @@ impl<'tcx> TyCtxt<'tcx> {
hir_arena, hir_arena,
interners, interners,
dep_graph, dep_graph,
definitions: RwLock::new(definitions),
prof: s.prof.clone(), prof: s.prof.clone(),
types: common_types, types: common_types,
lifetimes: common_lifetimes, lifetimes: common_lifetimes,
@ -1477,7 +1464,7 @@ impl<'tcx> TyCtxt<'tcx> {
// If this is a DefPathHash from the local crate, we can look up the // If this is a DefPathHash from the local crate, we can look up the
// DefId in the tcx's `Definitions`. // DefId in the tcx's `Definitions`.
if stable_crate_id == self.sess.local_stable_crate_id() { if stable_crate_id == self.sess.local_stable_crate_id() {
self.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id() self.untracked.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
} else { } else {
// If this is a DefPathHash from an upstream crate, let the CrateStore map // If this is a DefPathHash from an upstream crate, let the CrateStore map
// it to a DefId. // it to a DefId.
@ -1537,7 +1524,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
// This is fine because: // This is fine because:
// - those queries are `eval_always` so we won't miss their result changing; // - those queries are `eval_always` so we won't miss their result changing;
// - this write will have happened before these queries are called. // - this write will have happened before these queries are called.
let key = self.definitions.write().create_def(parent, data); let key = self.untracked.definitions.write().create_def(parent, data);
let feed = TyCtxtFeed { tcx: self.tcx, key }; let feed = TyCtxtFeed { tcx: self.tcx, key };
feed.def_span(self.span); feed.def_span(self.span);
@ -1551,7 +1538,7 @@ impl<'tcx> TyCtxt<'tcx> {
// definitions change. // definitions change.
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE); self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
let definitions = &self.definitions; let definitions = &self.untracked.definitions;
std::iter::from_generator(|| { std::iter::from_generator(|| {
let mut i = 0; let mut i = 0;
@ -1575,7 +1562,7 @@ impl<'tcx> TyCtxt<'tcx> {
// Leak a read lock once we start iterating on definitions, to prevent adding new ones // Leak a read lock once we start iterating on definitions, to prevent adding new ones
// while iterating. If some query needs to add definitions, it should be `ensure`d above. // while iterating. If some query needs to add definitions, it should be `ensure`d above.
let definitions = self.definitions.leak(); let definitions = self.untracked.definitions.leak();
definitions.def_path_table() definitions.def_path_table()
} }
@ -1587,7 +1574,7 @@ impl<'tcx> TyCtxt<'tcx> {
self.ensure().hir_crate(()); self.ensure().hir_crate(());
// Leak a read lock once we start iterating on definitions, to prevent adding new ones // Leak a read lock once we start iterating on definitions, to prevent adding new ones
// while iterating. If some query needs to add definitions, it should be `ensure`d above. // while iterating. If some query needs to add definitions, it should be `ensure`d above.
let definitions = self.definitions.leak(); let definitions = self.untracked.definitions.leak();
definitions.def_path_hash_to_def_index_map() definitions.def_path_hash_to_def_index_map()
} }
@ -1601,7 +1588,7 @@ impl<'tcx> TyCtxt<'tcx> {
/// system if the result is otherwise tracked through queries /// system if the result is otherwise tracked through queries
#[inline] #[inline]
pub fn definitions_untracked(self) -> ReadGuard<'tcx, Definitions> { pub fn definitions_untracked(self) -> ReadGuard<'tcx, Definitions> {
self.definitions.read() self.untracked.definitions.read()
} }
/// Note that this is *untracked* and should only be used within the query /// Note that this is *untracked* and should only be used within the query
@ -1616,9 +1603,7 @@ impl<'tcx> TyCtxt<'tcx> {
self, self,
f: impl FnOnce(StableHashingContext<'_>) -> R, f: impl FnOnce(StableHashingContext<'_>) -> R,
) -> R { ) -> R {
let definitions = self.definitions_untracked(); f(StableHashingContext::new(self.sess, &self.untracked))
let hcx = StableHashingContext::new(self.sess, &*definitions, &self.untracked);
f(hcx)
} }
pub fn serialize_query_result_cache(self, encoder: FileEncoder) -> FileEncodeResult { pub fn serialize_query_result_cache(self, encoder: FileEncoder) -> FileEncodeResult {
@ -2412,7 +2397,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.interners.intern_ty( self.interners.intern_ty(
st, st,
self.sess, self.sess,
&self.definitions.read(),
// This is only used to create a stable hashing context. // This is only used to create a stable hashing context.
&self.untracked, &self.untracked,
) )
@ -2423,7 +2407,6 @@ impl<'tcx> TyCtxt<'tcx> {
self.interners.intern_predicate( self.interners.intern_predicate(
binder, binder,
self.sess, self.sess,
&self.definitions.read(),
// This is only used to create a stable hashing context. // This is only used to create a stable hashing context.
&self.untracked, &self.untracked,
) )

View File

@ -40,7 +40,6 @@ use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, LifetimeRes, Res}; use rustc_hir::def::{CtorKind, CtorOf, DefKind, LifetimeRes, Res};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
use rustc_hir::definitions::Definitions;
use rustc_hir::Node; use rustc_hir::Node;
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_macros::HashStable; use rustc_macros::HashStable;
@ -150,7 +149,6 @@ mod sty;
pub type RegisteredTools = FxHashSet<Ident>; pub type RegisteredTools = FxHashSet<Ident>;
pub struct ResolverOutputs { pub struct ResolverOutputs {
pub definitions: Definitions,
pub global_ctxt: ResolverGlobalCtxt, pub global_ctxt: ResolverGlobalCtxt,
pub ast_lowering: ResolverAstLowering, pub ast_lowering: ResolverAstLowering,
pub untracked: Untracked, pub untracked: Untracked,

View File

@ -6,7 +6,7 @@ use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHa
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::definitions::{DefPathHash, Definitions}; use rustc_hir::definitions::DefPathHash;
use rustc_session::cstore::Untracked; use rustc_session::cstore::Untracked;
use rustc_session::Session; use rustc_session::Session;
use rustc_span::source_map::SourceMap; use rustc_span::source_map::SourceMap;
@ -19,7 +19,6 @@ use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData, DUMM
/// things (e.g., each `DefId`/`DefPath` is only hashed once). /// things (e.g., each `DefId`/`DefPath` is only hashed once).
#[derive(Clone)] #[derive(Clone)]
pub struct StableHashingContext<'a> { pub struct StableHashingContext<'a> {
definitions: &'a Definitions,
untracked: &'a Untracked, untracked: &'a Untracked,
// The value of `-Z incremental-ignore-spans`. // The value of `-Z incremental-ignore-spans`.
// This field should only be used by `unstable_opts_incremental_ignore_span` // This field should only be used by `unstable_opts_incremental_ignore_span`
@ -47,12 +46,11 @@ pub(super) enum BodyResolver<'tcx> {
impl<'a> StableHashingContext<'a> { impl<'a> StableHashingContext<'a> {
#[inline] #[inline]
pub fn new(sess: &'a Session, definitions: &'a Definitions, untracked: &'a Untracked) -> Self { pub fn new(sess: &'a Session, untracked: &'a Untracked) -> Self {
let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans; let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans;
StableHashingContext { StableHashingContext {
body_resolver: BodyResolver::Forbidden, body_resolver: BodyResolver::Forbidden,
definitions,
untracked, untracked,
incremental_ignore_spans: sess.opts.unstable_opts.incremental_ignore_spans, incremental_ignore_spans: sess.opts.unstable_opts.incremental_ignore_spans,
caching_source_map: None, caching_source_map: None,
@ -98,7 +96,7 @@ impl<'a> StableHashingContext<'a> {
#[inline] #[inline]
pub fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash { pub fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
self.definitions.def_path_hash(def_id) self.untracked.definitions.read().def_path_hash(def_id)
} }
#[inline] #[inline]

View File

@ -836,7 +836,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
} else if orig_name == Some(kw::SelfLower) { } else if orig_name == Some(kw::SelfLower) {
Some(self.r.graph_root) Some(self.r.graph_root)
} else { } else {
self.r.crate_loader().process_extern_crate(item, local_def_id).map(|crate_id| { let crate_id = self.r.crate_loader().process_extern_crate(item, local_def_id);
crate_id.map(|crate_id| {
self.r.extern_crate_map.insert(local_def_id, crate_id); self.r.extern_crate_map.insert(local_def_id, crate_id);
self.r.expect_module(crate_id.as_def_id()) self.r.expect_module(crate_id.as_def_id())
}) })

View File

@ -1298,7 +1298,8 @@ impl<'a> Resolver<'a> {
// otherwise cause duplicate suggestions. // otherwise cause duplicate suggestions.
continue; continue;
} }
if let Some(crate_id) = self.crate_loader().maybe_process_path_extern(ident.name) { let crate_id = self.crate_loader().maybe_process_path_extern(ident.name);
if let Some(crate_id) = crate_id {
let crate_root = self.expect_module(crate_id.as_def_id()); let crate_root = self.expect_module(crate_id.as_def_id());
suggestions.extend(self.lookup_import_candidates_from_module( suggestions.extend(self.lookup_import_candidates_from_module(
lookup_ident, lookup_ident,

View File

@ -107,10 +107,7 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
r.effective_visibilities.update_eff_vis( r.effective_visibilities.update_eff_vis(
r.local_def_id(node_id), r.local_def_id(node_id),
eff_vis, eff_vis,
ResolverTree( ResolverTree(&r.untracked),
&r.definitions,
&r.untracked.cstore.as_any().downcast_ref().unwrap(),
),
) )
} }
} }

View File

@ -29,7 +29,7 @@ use rustc_ast::{self as ast, NodeId, CRATE_NODE_ID};
use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path}; use rustc_ast::{AngleBracketedArg, Crate, Expr, ExprKind, GenericArg, GenericArgs, LitKind, Path};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::{Lrc, RwLock};
use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed}; use rustc_errors::{Applicability, DiagnosticBuilder, ErrorGuaranteed};
use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind}; use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind};
use rustc_hir::def::Namespace::*; use rustc_hir::def::Namespace::*;
@ -866,7 +866,6 @@ struct MacroData {
pub struct Resolver<'a> { pub struct Resolver<'a> {
session: &'a Session, session: &'a Session,
definitions: Definitions,
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`. /// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
expn_that_defined: FxHashMap<LocalDefId, ExpnId>, expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
@ -1113,15 +1112,15 @@ impl<'a> AsMut<Resolver<'a>> for Resolver<'a> {
/// A minimal subset of resolver that can implemenent `DefIdTree`, sometimes /// A minimal subset of resolver that can implemenent `DefIdTree`, sometimes
/// required to satisfy borrow checker by avoiding borrowing the whole resolver. /// required to satisfy borrow checker by avoiding borrowing the whole resolver.
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
struct ResolverTree<'a>(&'a Definitions, &'a CStore); struct ResolverTree<'a>(&'a Untracked);
impl DefIdTree for ResolverTree<'_> { impl DefIdTree for ResolverTree<'_> {
#[inline] #[inline]
fn opt_parent(self, id: DefId) -> Option<DefId> { fn opt_parent(self, id: DefId) -> Option<DefId> {
let ResolverTree(definitions, cstore) = self; let ResolverTree(Untracked { definitions, cstore, .. }) = self;
match id.as_local() { match id.as_local() {
Some(id) => definitions.def_key(id).parent, Some(id) => definitions.read().def_key(id).parent,
None => cstore.def_key(id).parent, None => cstore.as_any().downcast_ref::<CStore>().unwrap().def_key(id).parent,
} }
.map(|index| DefId { index, ..id }) .map(|index| DefId { index, ..id })
} }
@ -1130,7 +1129,7 @@ impl DefIdTree for ResolverTree<'_> {
impl<'a, 'b> DefIdTree for &'a Resolver<'b> { impl<'a, 'b> DefIdTree for &'a Resolver<'b> {
#[inline] #[inline]
fn opt_parent(self, id: DefId) -> Option<DefId> { fn opt_parent(self, id: DefId) -> Option<DefId> {
ResolverTree(&self.definitions, self.cstore()).opt_parent(id) ResolverTree(&self.untracked).opt_parent(id)
} }
} }
@ -1157,10 +1156,10 @@ impl Resolver<'_> {
"adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}", "adding a def'n for node-id {:?} and data {:?} but a previous def'n exists: {:?}",
node_id, node_id,
data, data,
self.definitions.def_key(self.node_id_to_def_id[&node_id]), self.untracked.definitions.read().def_key(self.node_id_to_def_id[&node_id]),
); );
let def_id = self.definitions.create_def(parent, data); let def_id = self.untracked.definitions.write().create_def(parent, data);
// Create the definition. // Create the definition.
if expn_id != ExpnId::root() { if expn_id != ExpnId::root() {
@ -1259,7 +1258,6 @@ impl<'a> Resolver<'a> {
let mut resolver = Resolver { let mut resolver = Resolver {
session, session,
definitions,
expn_that_defined: Default::default(), expn_that_defined: Default::default(),
// The outermost module has def ID 0; this is not reflected in the // The outermost module has def ID 0; this is not reflected in the
@ -1314,7 +1312,11 @@ impl<'a> Resolver<'a> {
metadata_loader, metadata_loader,
local_crate_name: crate_name, local_crate_name: crate_name,
used_extern_options: Default::default(), used_extern_options: Default::default(),
untracked: Untracked { cstore: Box::new(CStore::new(session)), source_span }, untracked: Untracked {
cstore: Box::new(CStore::new(session)),
source_span,
definitions: RwLock::new(definitions),
},
macro_names: FxHashSet::default(), macro_names: FxHashSet::default(),
builtin_macros: Default::default(), builtin_macros: Default::default(),
builtin_macro_kinds: Default::default(), builtin_macro_kinds: Default::default(),
@ -1405,7 +1407,6 @@ impl<'a> Resolver<'a> {
pub fn into_outputs(self) -> ResolverOutputs { pub fn into_outputs(self) -> ResolverOutputs {
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect(); let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
let definitions = self.definitions;
let expn_that_defined = self.expn_that_defined; let expn_that_defined = self.expn_that_defined;
let visibilities = self.visibilities; let visibilities = self.visibilities;
let has_pub_restricted = self.has_pub_restricted; let has_pub_restricted = self.has_pub_restricted;
@ -1453,14 +1454,15 @@ impl<'a> Resolver<'a> {
builtin_macro_kinds: self.builtin_macro_kinds, builtin_macro_kinds: self.builtin_macro_kinds,
lifetime_elision_allowed: self.lifetime_elision_allowed, lifetime_elision_allowed: self.lifetime_elision_allowed,
}; };
ResolverOutputs { definitions, global_ctxt, ast_lowering, untracked } ResolverOutputs { global_ctxt, ast_lowering, untracked }
} }
pub fn clone_outputs(&self) -> ResolverOutputs { pub fn clone_outputs(&self) -> ResolverOutputs {
let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect(); let proc_macros = self.proc_macros.iter().map(|id| self.local_def_id(*id)).collect();
let definitions = self.definitions.clone(); let definitions = self.untracked.definitions.clone();
let cstore = Box::new(self.cstore().clone()); let cstore = Box::new(self.cstore().clone());
let untracked = Untracked { cstore, source_span: self.untracked.source_span.clone() }; let untracked =
Untracked { cstore, source_span: self.untracked.source_span.clone(), definitions };
let global_ctxt = ResolverGlobalCtxt { let global_ctxt = ResolverGlobalCtxt {
expn_that_defined: self.expn_that_defined.clone(), expn_that_defined: self.expn_that_defined.clone(),
visibilities: self.visibilities.clone(), visibilities: self.visibilities.clone(),
@ -1496,11 +1498,11 @@ impl<'a> Resolver<'a> {
builtin_macro_kinds: self.builtin_macro_kinds.clone(), builtin_macro_kinds: self.builtin_macro_kinds.clone(),
lifetime_elision_allowed: self.lifetime_elision_allowed.clone(), lifetime_elision_allowed: self.lifetime_elision_allowed.clone(),
}; };
ResolverOutputs { definitions, global_ctxt, ast_lowering, untracked } ResolverOutputs { global_ctxt, ast_lowering, untracked }
} }
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> { fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
StableHashingContext::new(self.session, &self.definitions, &self.untracked) StableHashingContext::new(self.session, &self.untracked)
} }
pub fn crate_loader(&mut self) -> CrateLoader<'_> { pub fn crate_loader(&mut self) -> CrateLoader<'_> {
@ -1509,7 +1511,7 @@ impl<'a> Resolver<'a> {
&*self.metadata_loader, &*self.metadata_loader,
self.local_crate_name, self.local_crate_name,
&mut *self.untracked.cstore.untracked_as_any().downcast_mut().unwrap(), &mut *self.untracked.cstore.untracked_as_any().downcast_mut().unwrap(),
&self.definitions, self.untracked.definitions.read(),
&mut self.used_extern_options, &mut self.used_extern_options,
) )
} }
@ -1958,7 +1960,7 @@ impl<'a> Resolver<'a> {
#[inline] #[inline]
pub fn opt_name(&self, def_id: DefId) -> Option<Symbol> { pub fn opt_name(&self, def_id: DefId) -> Option<Symbol> {
let def_key = match def_id.as_local() { let def_key = match def_id.as_local() {
Some(def_id) => self.definitions.def_key(def_id), Some(def_id) => self.untracked.definitions.read().def_key(def_id),
None => self.cstore().def_key(def_id), None => self.cstore().def_key(def_id),
}; };
def_key.get_opt_name() def_key.get_opt_name()

View File

@ -6,9 +6,9 @@ use crate::search_paths::PathKind;
use crate::utils::NativeLibKind; use crate::utils::NativeLibKind;
use crate::Session; use crate::Session;
use rustc_ast as ast; use rustc_ast as ast;
use rustc_data_structures::sync::{self, MetadataRef}; use rustc_data_structures::sync::{self, MetadataRef, RwLock};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, StableCrateId, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, Definitions};
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_span::hygiene::{ExpnHash, ExpnId}; use rustc_span::hygiene::{ExpnHash, ExpnId};
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
@ -257,4 +257,5 @@ pub struct Untracked {
pub cstore: Box<CrateStoreDyn>, pub cstore: Box<CrateStoreDyn>,
/// Reference span for definitions. /// Reference span for definitions.
pub source_span: IndexVec<LocalDefId, Span>, pub source_span: IndexVec<LocalDefId, Span>,
pub definitions: RwLock<Definitions>,
} }