Skip to content

Commit 75ff5c7

Browse files
committed
Fold Definitions into the untracked data
1 parent 1c1d357 commit 75ff5c7

File tree

10 files changed

+49
-70
lines changed

10 files changed

+49
-70
lines changed

compiler/rustc_interface/src/passes.rs

-2
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ pub fn create_global_ctxt<'tcx>(
805805
});
806806

807807
let ty::ResolverOutputs {
808-
definitions,
809808
global_ctxt: untracked_resolutions,
810809
ast_lowering: untracked_resolver_for_lowering,
811810
untracked,
@@ -818,7 +817,6 @@ pub fn create_global_ctxt<'tcx>(
818817
lint_store,
819818
arena,
820819
hir_arena,
821-
definitions,
822820
untracked_resolutions,
823821
untracked,
824822
krate,

compiler/rustc_metadata/src/creader.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_ast::expand::allocator::AllocatorKind;
1313
use rustc_ast::{self as ast, *};
1414
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1515
use rustc_data_structures::svh::Svh;
16-
use rustc_data_structures::sync::Lrc;
16+
use rustc_data_structures::sync::{Lrc, ReadGuard};
1717
use rustc_expand::base::SyntaxExtension;
1818
use rustc_hir::def_id::{CrateNum, LocalDefId, StableCrateId, LOCAL_CRATE};
1919
use rustc_hir::definitions::Definitions;
@@ -69,7 +69,7 @@ pub struct CrateLoader<'a> {
6969
// Immutable configuration.
7070
sess: &'a Session,
7171
metadata_loader: &'a MetadataLoaderDyn,
72-
definitions: &'a Definitions,
72+
definitions: ReadGuard<'a, Definitions>,
7373
local_crate_name: Symbol,
7474
// Mutable output.
7575
cstore: &'a mut CStore,
@@ -267,7 +267,7 @@ impl<'a> CrateLoader<'a> {
267267
metadata_loader: &'a MetadataLoaderDyn,
268268
local_crate_name: Symbol,
269269
cstore: &'a mut CStore,
270-
definitions: &'a Definitions,
270+
definitions: ReadGuard<'a, Definitions>,
271271
used_extern_options: &'a mut FxHashSet<Symbol>,
272272
) -> Self {
273273
CrateLoader {

compiler/rustc_middle/src/ty/context.rs

+14-31
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
3535
use rustc_data_structures::sharded::{IntoPointer, ShardedHashMap};
3636
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3737
use rustc_data_structures::steal::Steal;
38-
use rustc_data_structures::sync::{self, Lock, Lrc, ReadGuard, RwLock, WorkerLocal};
38+
use rustc_data_structures::sync::{self, Lock, Lrc, ReadGuard, WorkerLocal};
3939
use rustc_data_structures::unord::UnordSet;
4040
use rustc_data_structures::vec_map::VecMap;
4141
use rustc_errors::{
@@ -182,18 +182,12 @@ impl<'tcx> CtxtInterners<'tcx> {
182182
/// Interns a type.
183183
#[allow(rustc::usage_of_ty_tykind)]
184184
#[inline(never)]
185-
fn intern_ty(
186-
&self,
187-
kind: TyKind<'tcx>,
188-
sess: &Session,
189-
definitions: &rustc_hir::definitions::Definitions,
190-
untracked: &Untracked,
191-
) -> Ty<'tcx> {
185+
fn intern_ty(&self, kind: TyKind<'tcx>, sess: &Session, untracked: &Untracked) -> Ty<'tcx> {
192186
Ty(Interned::new_unchecked(
193187
self.type_
194188
.intern(kind, |kind| {
195189
let flags = super::flags::FlagComputation::for_kind(&kind);
196-
let stable_hash = self.stable_hash(&flags, sess, definitions, untracked, &kind);
190+
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
197191

198192
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
199193
internee: kind,
@@ -210,7 +204,6 @@ impl<'tcx> CtxtInterners<'tcx> {
210204
&self,
211205
flags: &ty::flags::FlagComputation,
212206
sess: &'a Session,
213-
definitions: &'a rustc_hir::definitions::Definitions,
214207
untracked: &'a Untracked,
215208
val: &T,
216209
) -> Fingerprint {
@@ -220,7 +213,7 @@ impl<'tcx> CtxtInterners<'tcx> {
220213
Fingerprint::ZERO
221214
} else {
222215
let mut hasher = StableHasher::new();
223-
let mut hcx = StableHashingContext::new(sess, definitions, untracked);
216+
let mut hcx = StableHashingContext::new(sess, untracked);
224217
val.hash_stable(&mut hcx, &mut hasher);
225218
hasher.finish()
226219
}
@@ -231,15 +224,14 @@ impl<'tcx> CtxtInterners<'tcx> {
231224
&self,
232225
kind: Binder<'tcx, PredicateKind<'tcx>>,
233226
sess: &Session,
234-
definitions: &rustc_hir::definitions::Definitions,
235227
untracked: &Untracked,
236228
) -> Predicate<'tcx> {
237229
Predicate(Interned::new_unchecked(
238230
self.predicate
239231
.intern(kind, |kind| {
240232
let flags = super::flags::FlagComputation::for_predicate(kind);
241233

242-
let stable_hash = self.stable_hash(&flags, sess, definitions, untracked, &kind);
234+
let stable_hash = self.stable_hash(&flags, sess, untracked, &kind);
243235

244236
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
245237
internee: kind,
@@ -957,10 +949,9 @@ impl<'tcx> CommonTypes<'tcx> {
957949
fn new(
958950
interners: &CtxtInterners<'tcx>,
959951
sess: &Session,
960-
definitions: &rustc_hir::definitions::Definitions,
961952
untracked: &Untracked,
962953
) -> CommonTypes<'tcx> {
963-
let mk = |ty| interners.intern_ty(ty, sess, definitions, untracked);
954+
let mk = |ty| interners.intern_ty(ty, sess, untracked);
964955

965956
CommonTypes {
966957
unit: mk(Tuple(List::empty())),
@@ -1106,8 +1097,6 @@ pub struct GlobalCtxt<'tcx> {
11061097
/// Common consts, pre-interned for your convenience.
11071098
pub consts: CommonConsts<'tcx>,
11081099

1109-
definitions: RwLock<Definitions>,
1110-
11111100
untracked: Untracked,
11121101
/// Output of the resolver.
11131102
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
@@ -1273,7 +1262,6 @@ impl<'tcx> TyCtxt<'tcx> {
12731262
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
12741263
arena: &'tcx WorkerLocal<Arena<'tcx>>,
12751264
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
1276-
definitions: Definitions,
12771265
untracked_resolutions: ty::ResolverGlobalCtxt,
12781266
untracked: Untracked,
12791267
krate: Lrc<ast::Crate>,
@@ -1288,7 +1276,7 @@ impl<'tcx> TyCtxt<'tcx> {
12881276
s.emit_fatal(err);
12891277
});
12901278
let interners = CtxtInterners::new(arena);
1291-
let common_types = CommonTypes::new(&interners, s, &definitions, &untracked);
1279+
let common_types = CommonTypes::new(&interners, s, &untracked);
12921280
let common_lifetimes = CommonLifetimes::new(&interners);
12931281
let common_consts = CommonConsts::new(&interners, &common_types);
12941282

@@ -1299,7 +1287,6 @@ impl<'tcx> TyCtxt<'tcx> {
12991287
hir_arena,
13001288
interners,
13011289
dep_graph,
1302-
definitions: RwLock::new(definitions),
13031290
prof: s.prof.clone(),
13041291
types: common_types,
13051292
lifetimes: common_lifetimes,
@@ -1477,7 +1464,7 @@ impl<'tcx> TyCtxt<'tcx> {
14771464
// If this is a DefPathHash from the local crate, we can look up the
14781465
// DefId in the tcx's `Definitions`.
14791466
if stable_crate_id == self.sess.local_stable_crate_id() {
1480-
self.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
1467+
self.untracked.definitions.read().local_def_path_hash_to_def_id(hash, err).to_def_id()
14811468
} else {
14821469
// If this is a DefPathHash from an upstream crate, let the CrateStore map
14831470
// it to a DefId.
@@ -1537,7 +1524,7 @@ impl<'tcx> TyCtxtAt<'tcx> {
15371524
// This is fine because:
15381525
// - those queries are `eval_always` so we won't miss their result changing;
15391526
// - this write will have happened before these queries are called.
1540-
let key = self.definitions.write().create_def(parent, data);
1527+
let key = self.untracked.definitions.write().create_def(parent, data);
15411528

15421529
let feed = TyCtxtFeed { tcx: self.tcx, key };
15431530
feed.def_span(self.span);
@@ -1551,7 +1538,7 @@ impl<'tcx> TyCtxt<'tcx> {
15511538
// definitions change.
15521539
self.dep_graph.read_index(DepNodeIndex::FOREVER_RED_NODE);
15531540

1554-
let definitions = &self.definitions;
1541+
let definitions = &self.untracked.definitions;
15551542
std::iter::from_generator(|| {
15561543
let mut i = 0;
15571544

@@ -1575,7 +1562,7 @@ impl<'tcx> TyCtxt<'tcx> {
15751562

15761563
// Leak a read lock once we start iterating on definitions, to prevent adding new ones
15771564
// while iterating. If some query needs to add definitions, it should be `ensure`d above.
1578-
let definitions = self.definitions.leak();
1565+
let definitions = self.untracked.definitions.leak();
15791566
definitions.def_path_table()
15801567
}
15811568

@@ -1587,7 +1574,7 @@ impl<'tcx> TyCtxt<'tcx> {
15871574
self.ensure().hir_crate(());
15881575
// Leak a read lock once we start iterating on definitions, to prevent adding new ones
15891576
// while iterating. If some query needs to add definitions, it should be `ensure`d above.
1590-
let definitions = self.definitions.leak();
1577+
let definitions = self.untracked.definitions.leak();
15911578
definitions.def_path_hash_to_def_index_map()
15921579
}
15931580

@@ -1601,7 +1588,7 @@ impl<'tcx> TyCtxt<'tcx> {
16011588
/// system if the result is otherwise tracked through queries
16021589
#[inline]
16031590
pub fn definitions_untracked(self) -> ReadGuard<'tcx, Definitions> {
1604-
self.definitions.read()
1591+
self.untracked.definitions.read()
16051592
}
16061593

16071594
/// Note that this is *untracked* and should only be used within the query
@@ -1616,9 +1603,7 @@ impl<'tcx> TyCtxt<'tcx> {
16161603
self,
16171604
f: impl FnOnce(StableHashingContext<'_>) -> R,
16181605
) -> R {
1619-
let definitions = self.definitions_untracked();
1620-
let hcx = StableHashingContext::new(self.sess, &*definitions, &self.untracked);
1621-
f(hcx)
1606+
f(StableHashingContext::new(self.sess, &self.untracked))
16221607
}
16231608

16241609
pub fn serialize_query_result_cache(self, encoder: FileEncoder) -> FileEncodeResult {
@@ -2412,7 +2397,6 @@ impl<'tcx> TyCtxt<'tcx> {
24122397
self.interners.intern_ty(
24132398
st,
24142399
self.sess,
2415-
&self.definitions.read(),
24162400
// This is only used to create a stable hashing context.
24172401
&self.untracked,
24182402
)
@@ -2423,7 +2407,6 @@ impl<'tcx> TyCtxt<'tcx> {
24232407
self.interners.intern_predicate(
24242408
binder,
24252409
self.sess,
2426-
&self.definitions.read(),
24272410
// This is only used to create a stable hashing context.
24282411
&self.untracked,
24292412
)

compiler/rustc_middle/src/ty/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use rustc_data_structures::tagged_ptr::CopyTaggedPtr;
4040
use rustc_hir as hir;
4141
use rustc_hir::def::{CtorKind, CtorOf, DefKind, LifetimeRes, Res};
4242
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
43-
use rustc_hir::definitions::Definitions;
4443
use rustc_hir::Node;
4544
use rustc_index::vec::IndexVec;
4645
use rustc_macros::HashStable;
@@ -150,7 +149,6 @@ mod sty;
150149
pub type RegisteredTools = FxHashSet<Ident>;
151150

152151
pub struct ResolverOutputs {
153-
pub definitions: Definitions,
154152
pub global_ctxt: ResolverGlobalCtxt,
155153
pub ast_lowering: ResolverAstLowering,
156154
pub untracked: Untracked,

compiler/rustc_query_system/src/ich/hcx.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_data_structures::stable_hasher::{HashStable, HashingControls, StableHa
66
use rustc_data_structures::sync::Lrc;
77
use rustc_hir as hir;
88
use rustc_hir::def_id::{DefId, LocalDefId};
9-
use rustc_hir::definitions::{DefPathHash, Definitions};
9+
use rustc_hir::definitions::DefPathHash;
1010
use rustc_session::cstore::Untracked;
1111
use rustc_session::Session;
1212
use rustc_span::source_map::SourceMap;
@@ -19,7 +19,6 @@ use rustc_span::{BytePos, CachingSourceMapView, SourceFile, Span, SpanData, DUMM
1919
/// things (e.g., each `DefId`/`DefPath` is only hashed once).
2020
#[derive(Clone)]
2121
pub struct StableHashingContext<'a> {
22-
definitions: &'a Definitions,
2322
untracked: &'a Untracked,
2423
// The value of `-Z incremental-ignore-spans`.
2524
// This field should only be used by `unstable_opts_incremental_ignore_span`
@@ -47,12 +46,11 @@ pub(super) enum BodyResolver<'tcx> {
4746

4847
impl<'a> StableHashingContext<'a> {
4948
#[inline]
50-
pub fn new(sess: &'a Session, definitions: &'a Definitions, untracked: &'a Untracked) -> Self {
49+
pub fn new(sess: &'a Session, untracked: &'a Untracked) -> Self {
5150
let hash_spans_initial = !sess.opts.unstable_opts.incremental_ignore_spans;
5251

5352
StableHashingContext {
5453
body_resolver: BodyResolver::Forbidden,
55-
definitions,
5654
untracked,
5755
incremental_ignore_spans: sess.opts.unstable_opts.incremental_ignore_spans,
5856
caching_source_map: None,
@@ -98,7 +96,7 @@ impl<'a> StableHashingContext<'a> {
9896

9997
#[inline]
10098
pub fn local_def_path_hash(&self, def_id: LocalDefId) -> DefPathHash {
101-
self.definitions.def_path_hash(def_id)
99+
self.untracked.definitions.read().def_path_hash(def_id)
102100
}
103101

104102
#[inline]

compiler/rustc_resolve/src/build_reduced_graph.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
836836
} else if orig_name == Some(kw::SelfLower) {
837837
Some(self.r.graph_root)
838838
} else {
839-
self.r.crate_loader().process_extern_crate(item, local_def_id).map(|crate_id| {
839+
let crate_id = self.r.crate_loader().process_extern_crate(item, local_def_id);
840+
crate_id.map(|crate_id| {
840841
self.r.extern_crate_map.insert(local_def_id, crate_id);
841842
self.r.expect_module(crate_id.as_def_id())
842843
})

compiler/rustc_resolve/src/diagnostics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1298,7 +1298,8 @@ impl<'a> Resolver<'a> {
12981298
// otherwise cause duplicate suggestions.
12991299
continue;
13001300
}
1301-
if let Some(crate_id) = self.crate_loader().maybe_process_path_extern(ident.name) {
1301+
let crate_id = self.crate_loader().maybe_process_path_extern(ident.name);
1302+
if let Some(crate_id) = crate_id {
13021303
let crate_root = self.expect_module(crate_id.as_def_id());
13031304
suggestions.extend(self.lookup_import_candidates_from_module(
13041305
lookup_ident,

compiler/rustc_resolve/src/effective_visibilities.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,7 @@ impl<'r, 'a> EffectiveVisibilitiesVisitor<'r, 'a> {
107107
r.effective_visibilities.update_eff_vis(
108108
r.local_def_id(node_id),
109109
eff_vis,
110-
ResolverTree(
111-
&r.definitions,
112-
&r.untracked.cstore.as_any().downcast_ref().unwrap(),
113-
),
110+
ResolverTree(&r.untracked),
114111
)
115112
}
116113
}

0 commit comments

Comments
 (0)