Skip to content

Commit 21ec51d

Browse files
committed
Separate Definitions and CrateStore from ResolverOutputs.
1 parent 76d4862 commit 21ec51d

File tree

8 files changed

+71
-74
lines changed

8 files changed

+71
-74
lines changed

compiler/rustc_interface/src/passes.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_data_structures::temp_dir::MaybeTempDir;
1313
use rustc_errors::{Applicability, ErrorGuaranteed, MultiSpan, PResult};
1414
use rustc_expand::base::{ExtCtxt, LintStoreExpand, ResolverExpand};
1515
use rustc_hir::def_id::{StableCrateId, LOCAL_CRATE};
16+
use rustc_hir::definitions::Definitions;
1617
use rustc_hir::Crate;
1718
use rustc_lint::{EarlyCheckNode, LintStore};
1819
use rustc_metadata::creader::CStore;
@@ -29,7 +30,7 @@ use rustc_query_impl::{OnDiskCache, Queries as TcxQueries};
2930
use rustc_resolve::{Resolver, ResolverArenas};
3031
use rustc_serialize::json;
3132
use rustc_session::config::{CrateType, Input, OutputFilenames, OutputType};
32-
use rustc_session::cstore::{MetadataLoader, MetadataLoaderDyn};
33+
use rustc_session::cstore::{CrateStoreDyn, MetadataLoader, MetadataLoaderDyn};
3334
use rustc_session::output::{filename_for_input, filename_for_metadata};
3435
use rustc_session::search_paths::PathKind;
3536
use rustc_session::{Limit, Session};
@@ -141,7 +142,9 @@ mod boxed_resolver {
141142
f((&mut *resolver).as_mut().unwrap())
142143
}
143144

144-
pub fn to_resolver_outputs(resolver: Rc<RefCell<BoxedResolver>>) -> ResolverOutputs {
145+
pub fn to_resolver_outputs(
146+
resolver: Rc<RefCell<BoxedResolver>>,
147+
) -> (Definitions, Box<CrateStoreDyn>, ResolverOutputs) {
145148
match Rc::try_unwrap(resolver) {
146149
Ok(resolver) => {
147150
let mut resolver = resolver.into_inner();
@@ -841,7 +844,7 @@ pub fn create_global_ctxt<'tcx>(
841844
let sess = &compiler.session();
842845
let krate =
843846
resolver.borrow_mut().access(|resolver| lower_to_hir(sess, resolver, krate, hir_arena));
844-
let resolver_outputs = BoxedResolver::to_resolver_outputs(resolver);
847+
let (definitions, cstore, resolver_outputs) = BoxedResolver::to_resolver_outputs(resolver);
845848

846849
let query_result_on_disk_cache = rustc_incremental::load_query_result_cache(sess);
847850

@@ -866,6 +869,8 @@ pub fn create_global_ctxt<'tcx>(
866869
sess,
867870
lint_store,
868871
arena,
872+
definitions,
873+
cstore,
869874
resolver_outputs,
870875
krate,
871876
dep_graph,

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
455455
}
456456

457457
fn encode_def_path_table(&mut self) {
458-
let table = self.tcx.resolutions(()).definitions.def_path_table();
458+
let table = self.tcx.definitions_untracked().def_path_table();
459459
if self.is_proc_macro {
460460
for def_index in std::iter::once(CRATE_DEF_INDEX)
461461
.chain(self.tcx.resolutions(()).proc_macros.iter().map(|p| p.local_def_index))
@@ -476,7 +476,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
476476

477477
fn encode_def_path_hash_map(&mut self) -> Lazy<DefPathHashMapRef<'tcx>> {
478478
self.lazy(DefPathHashMapRef::BorrowedFromTcx(
479-
self.tcx.resolutions(()).definitions.def_path_hash_to_def_index_map(),
479+
self.tcx.definitions_untracked().def_path_hash_to_def_index_map(),
480480
))
481481
}
482482

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'hir> Map<'hir> {
167167

168168
pub fn def_key(self, def_id: LocalDefId) -> DefKey {
169169
// Accessing the DefKey is ok, since it is part of DefPathHash.
170-
self.tcx.untracked_resolutions.definitions.def_key(def_id)
170+
self.tcx.definitions_untracked().def_key(def_id)
171171
}
172172

173173
pub fn def_path_from_hir_id(self, id: HirId) -> Option<DefPath> {
@@ -176,13 +176,13 @@ impl<'hir> Map<'hir> {
176176

177177
pub fn def_path(self, def_id: LocalDefId) -> DefPath {
178178
// Accessing the DefPath is ok, since it is part of DefPathHash.
179-
self.tcx.untracked_resolutions.definitions.def_path(def_id)
179+
self.tcx.definitions_untracked().def_path(def_id)
180180
}
181181

182182
#[inline]
183183
pub fn def_path_hash(self, def_id: LocalDefId) -> DefPathHash {
184184
// Accessing the DefPathHash is ok, it is incr. comp. stable.
185-
self.tcx.untracked_resolutions.definitions.def_path_hash(def_id)
185+
self.tcx.definitions_untracked().def_path_hash(def_id)
186186
}
187187

188188
#[inline]
@@ -219,7 +219,7 @@ impl<'hir> Map<'hir> {
219219
// Create a dependency to the crate to be sure we re-execute this when the amount of
220220
// definitions change.
221221
self.tcx.ensure().hir_crate(());
222-
self.tcx.untracked_resolutions.definitions.iter_local_def_id()
222+
self.tcx.definitions_untracked().iter_local_def_id()
223223
}
224224

225225
pub fn opt_def_kind(self, local_def_id: LocalDefId) -> Option<DefKind> {
@@ -1104,7 +1104,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
11041104
upstream_crates.hash_stable(&mut hcx, &mut stable_hasher);
11051105
source_file_names.hash_stable(&mut hcx, &mut stable_hasher);
11061106
if tcx.sess.opts.debugging_opts.incremental_relative_spans {
1107-
let definitions = &tcx.untracked_resolutions.definitions;
1107+
let definitions = &tcx.definitions_untracked();
11081108
let mut owner_spans: Vec<_> = krate
11091109
.owners
11101110
.iter_enumerated()
@@ -1135,7 +1135,7 @@ fn upstream_crates(tcx: TyCtxt<'_>) -> Vec<(StableCrateId, Svh)> {
11351135
.crates(())
11361136
.iter()
11371137
.map(|&cnum| {
1138-
let stable_crate_id = tcx.resolutions(()).cstore.stable_crate_id(cnum);
1138+
let stable_crate_id = tcx.stable_crate_id(cnum);
11391139
let hash = tcx.crate_hash(cnum);
11401140
(stable_crate_id, hash)
11411141
})

compiler/rustc_middle/src/hir/mod.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod nested_filter;
77
pub mod place;
88

99
use crate::ty::query::Providers;
10-
use crate::ty::{ImplSubject, TyCtxt};
10+
use crate::ty::{DefIdTree, ImplSubject, TyCtxt};
1111
use rustc_data_structures::fingerprint::Fingerprint;
1212
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1313
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -105,22 +105,19 @@ pub fn provide(providers: &mut Providers) {
105105
providers.hir_owner_nodes = |tcx, id| tcx.hir_crate(()).owners[id].map(|i| &i.nodes);
106106
providers.hir_owner_parent = |tcx, id| {
107107
// Accessing the def_key is ok since its value is hashed as part of `id`'s DefPathHash.
108-
let parent = tcx.untracked_resolutions.definitions.def_key(id).parent;
109-
let parent = parent.map_or(CRATE_HIR_ID, |local_def_index| {
110-
let def_id = LocalDefId { local_def_index };
111-
let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
108+
tcx.local_parent(id).map_or(CRATE_HIR_ID, |parent| {
109+
let mut parent_hir_id = tcx.hir().local_def_id_to_hir_id(parent);
112110
if let Some(local_id) =
113111
tcx.hir_crate(()).owners[parent_hir_id.owner].unwrap().parenting.get(&id)
114112
{
115113
parent_hir_id.local_id = *local_id;
116114
}
117115
parent_hir_id
118-
});
119-
parent
116+
})
120117
};
121118
providers.hir_attrs =
122119
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs);
123-
providers.source_span = |tcx, def_id| tcx.resolutions(()).definitions.def_span(def_id);
120+
providers.source_span = |tcx, def_id| tcx.definitions_untracked().def_span(def_id);
124121
providers.def_span = |tcx, def_id| tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
125122
providers.fn_arg_names = |tcx, id| {
126123
let hir = tcx.hir();
@@ -141,7 +138,7 @@ pub fn provide(providers: &mut Providers) {
141138
providers.all_local_trait_impls = |tcx, ()| &tcx.resolutions(()).trait_impls;
142139
providers.expn_that_defined = |tcx, id| {
143140
let id = id.expect_local();
144-
tcx.resolutions(()).definitions.expansion_that_defined(id)
141+
tcx.definitions_untracked().expansion_that_defined(id)
145142
};
146143
providers.in_scope_traits_map =
147144
|tcx, id| tcx.hir_crate(()).owners[id].as_owner().map(|owner_info| &owner_info.trait_map);

compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ rustc_queries! {
3131
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
3232
/// of rustc_middle::hir::source_map.
3333
query source_span(key: LocalDefId) -> Span {
34+
eval_always
3435
desc { "get the source span" }
3536
}
3637

compiler/rustc_middle/src/ty/context.rs

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use rustc_middle::mir::FakeReadCause;
5050
use rustc_query_system::ich::StableHashingContext;
5151
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
5252
use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
53+
use rustc_session::cstore::CrateStoreDyn;
5354
use rustc_session::lint::{Level, Lint};
5455
use rustc_session::Limit;
5556
use rustc_session::Session;
@@ -150,7 +151,8 @@ impl<'tcx> CtxtInterners<'tcx> {
150151
&self,
151152
kind: TyKind<'tcx>,
152153
sess: &Session,
153-
resolutions: &ty::ResolverOutputs,
154+
definitions: &rustc_hir::definitions::Definitions,
155+
cstore: &CrateStoreDyn,
154156
) -> Ty<'tcx> {
155157
Ty(Interned::new_unchecked(
156158
self.type_
@@ -165,11 +167,7 @@ impl<'tcx> CtxtInterners<'tcx> {
165167
Fingerprint::ZERO
166168
} else {
167169
let mut hasher = StableHasher::new();
168-
let mut hcx = StableHashingContext::ignore_spans(
169-
sess,
170-
&resolutions.definitions,
171-
&*resolutions.cstore,
172-
);
170+
let mut hcx = StableHashingContext::ignore_spans(sess, definitions, cstore);
173171
kind.hash_stable(&mut hcx, &mut hasher);
174172
hasher.finish()
175173
};
@@ -900,9 +898,10 @@ impl<'tcx> CommonTypes<'tcx> {
900898
fn new(
901899
interners: &CtxtInterners<'tcx>,
902900
sess: &Session,
903-
resolutions: &ty::ResolverOutputs,
901+
definitions: &rustc_hir::definitions::Definitions,
902+
cstore: &CrateStoreDyn,
904903
) -> CommonTypes<'tcx> {
905-
let mk = |ty| interners.intern_ty(ty, sess, resolutions);
904+
let mk = |ty| interners.intern_ty(ty, sess, definitions, cstore);
906905

907906
CommonTypes {
908907
unit: mk(Tuple(List::empty())),
@@ -1023,6 +1022,9 @@ pub struct GlobalCtxt<'tcx> {
10231022
/// Common consts, pre-interned for your convenience.
10241023
pub consts: CommonConsts<'tcx>,
10251024

1025+
definitions: rustc_hir::definitions::Definitions,
1026+
cstore: Box<CrateStoreDyn>,
1027+
10261028
/// Output of the resolver.
10271029
pub(crate) untracked_resolutions: ty::ResolverOutputs,
10281030

@@ -1163,7 +1165,9 @@ impl<'tcx> TyCtxt<'tcx> {
11631165
s: &'tcx Session,
11641166
lint_store: Lrc<dyn Any + sync::Send + sync::Sync>,
11651167
arena: &'tcx WorkerLocal<Arena<'tcx>>,
1166-
resolutions: ty::ResolverOutputs,
1168+
definitions: rustc_hir::definitions::Definitions,
1169+
cstore: Box<CrateStoreDyn>,
1170+
untracked_resolutions: ty::ResolverOutputs,
11671171
krate: &'tcx hir::Crate<'tcx>,
11681172
dep_graph: DepGraph,
11691173
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
@@ -1176,7 +1180,7 @@ impl<'tcx> TyCtxt<'tcx> {
11761180
s.fatal(&err);
11771181
});
11781182
let interners = CtxtInterners::new(arena);
1179-
let common_types = CommonTypes::new(&interners, s, &resolutions);
1183+
let common_types = CommonTypes::new(&interners, s, &definitions, &*cstore);
11801184
let common_lifetimes = CommonLifetimes::new(&interners);
11811185
let common_consts = CommonConsts::new(&interners, &common_types);
11821186

@@ -1186,7 +1190,9 @@ impl<'tcx> TyCtxt<'tcx> {
11861190
arena,
11871191
interners,
11881192
dep_graph,
1189-
untracked_resolutions: resolutions,
1193+
definitions,
1194+
cstore,
1195+
untracked_resolutions,
11901196
prof: s.prof.clone(),
11911197
types: common_types,
11921198
lifetimes: common_lifetimes,
@@ -1287,9 +1293,9 @@ impl<'tcx> TyCtxt<'tcx> {
12871293
pub fn def_key(self, id: DefId) -> rustc_hir::definitions::DefKey {
12881294
// Accessing the DefKey is ok, since it is part of DefPathHash.
12891295
if let Some(id) = id.as_local() {
1290-
self.untracked_resolutions.definitions.def_key(id)
1296+
self.definitions.def_key(id)
12911297
} else {
1292-
self.untracked_resolutions.cstore.def_key(id)
1298+
self.cstore.def_key(id)
12931299
}
12941300
}
12951301

@@ -1301,19 +1307,19 @@ impl<'tcx> TyCtxt<'tcx> {
13011307
pub fn def_path(self, id: DefId) -> rustc_hir::definitions::DefPath {
13021308
// Accessing the DefPath is ok, since it is part of DefPathHash.
13031309
if let Some(id) = id.as_local() {
1304-
self.untracked_resolutions.definitions.def_path(id)
1310+
self.definitions.def_path(id)
13051311
} else {
1306-
self.untracked_resolutions.cstore.def_path(id)
1312+
self.cstore.def_path(id)
13071313
}
13081314
}
13091315

13101316
#[inline]
13111317
pub fn def_path_hash(self, def_id: DefId) -> rustc_hir::definitions::DefPathHash {
13121318
// Accessing the DefPathHash is ok, it is incr. comp. stable.
13131319
if let Some(def_id) = def_id.as_local() {
1314-
self.untracked_resolutions.definitions.def_path_hash(def_id)
1320+
self.definitions.def_path_hash(def_id)
13151321
} else {
1316-
self.untracked_resolutions.cstore.def_path_hash(def_id)
1322+
self.cstore.def_path_hash(def_id)
13171323
}
13181324
}
13191325

@@ -1322,7 +1328,7 @@ impl<'tcx> TyCtxt<'tcx> {
13221328
if crate_num == LOCAL_CRATE {
13231329
self.sess.local_stable_crate_id()
13241330
} else {
1325-
self.untracked_resolutions.cstore.stable_crate_id(crate_num)
1331+
self.cstore.stable_crate_id(crate_num)
13261332
}
13271333
}
13281334

@@ -1333,7 +1339,7 @@ impl<'tcx> TyCtxt<'tcx> {
13331339
if stable_crate_id == self.sess.local_stable_crate_id() {
13341340
LOCAL_CRATE
13351341
} else {
1336-
self.untracked_resolutions.cstore.stable_crate_id_to_crate_num(stable_crate_id)
1342+
self.cstore.stable_crate_id_to_crate_num(stable_crate_id)
13371343
}
13381344
}
13391345

@@ -1348,16 +1354,12 @@ impl<'tcx> TyCtxt<'tcx> {
13481354
// If this is a DefPathHash from the local crate, we can look up the
13491355
// DefId in the tcx's `Definitions`.
13501356
if stable_crate_id == self.sess.local_stable_crate_id() {
1351-
self.untracked_resolutions
1352-
.definitions
1353-
.local_def_path_hash_to_def_id(hash, err)
1354-
.to_def_id()
1357+
self.definitions.local_def_path_hash_to_def_id(hash, err).to_def_id()
13551358
} else {
13561359
// If this is a DefPathHash from an upstream crate, let the CrateStore map
13571360
// it to a DefId.
1358-
let cstore = &self.untracked_resolutions.cstore;
1359-
let cnum = cstore.stable_crate_id_to_crate_num(stable_crate_id);
1360-
cstore.def_path_hash_to_def_id(cnum, hash)
1361+
let cnum = self.cstore.stable_crate_id_to_crate_num(stable_crate_id);
1362+
self.cstore.def_path_hash_to_def_id(cnum, hash)
13611363
}
13621364
}
13631365

@@ -1369,7 +1371,7 @@ impl<'tcx> TyCtxt<'tcx> {
13691371
let (crate_name, stable_crate_id) = if def_id.is_local() {
13701372
(self.crate_name, self.sess.local_stable_crate_id())
13711373
} else {
1372-
let cstore = &self.untracked_resolutions.cstore;
1374+
let cstore = &self.cstore;
13731375
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
13741376
};
13751377

@@ -1385,30 +1387,24 @@ impl<'tcx> TyCtxt<'tcx> {
13851387

13861388
/// Note that this is *untracked* and should only be used within the query
13871389
/// system if the result is otherwise tracked through queries
1388-
pub fn cstore_untracked(self) -> &'tcx ty::CrateStoreDyn {
1389-
&*self.untracked_resolutions.cstore
1390+
pub fn cstore_untracked(self) -> &'tcx CrateStoreDyn {
1391+
&*self.cstore
13901392
}
13911393

13921394
/// Note that this is *untracked* and should only be used within the query
13931395
/// system if the result is otherwise tracked through queries
13941396
pub fn definitions_untracked(self) -> &'tcx hir::definitions::Definitions {
1395-
&self.untracked_resolutions.definitions
1397+
&self.definitions
13961398
}
13971399

13981400
#[inline(always)]
13991401
pub fn create_stable_hashing_context(self) -> StableHashingContext<'tcx> {
1400-
let resolutions = &self.gcx.untracked_resolutions;
1401-
StableHashingContext::new(self.sess, &resolutions.definitions, &*resolutions.cstore)
1402+
StableHashingContext::new(self.sess, &self.definitions, &*self.cstore)
14021403
}
14031404

14041405
#[inline(always)]
14051406
pub fn create_no_span_stable_hashing_context(self) -> StableHashingContext<'tcx> {
1406-
let resolutions = &self.gcx.untracked_resolutions;
1407-
StableHashingContext::ignore_spans(
1408-
self.sess,
1409-
&resolutions.definitions,
1410-
&*resolutions.cstore,
1411-
)
1407+
StableHashingContext::ignore_spans(self.sess, &self.definitions, &*self.cstore)
14121408
}
14131409

14141410
pub fn serialize_query_result_cache(self, encoder: &mut FileEncoder) -> FileEncodeResult {
@@ -2237,7 +2233,7 @@ impl<'tcx> TyCtxt<'tcx> {
22372233
#[allow(rustc::usage_of_ty_tykind)]
22382234
#[inline]
22392235
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
2240-
self.interners.intern_ty(st, self.sess, &self.gcx.untracked_resolutions)
2236+
self.interners.intern_ty(st, self.sess, &self.definitions, &*self.cstore)
22412237
}
22422238

22432239
#[inline]

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap};
4040
use rustc_hir::Node;
4141
use rustc_macros::HashStable;
4242
use rustc_query_system::ich::StableHashingContext;
43-
use rustc_session::cstore::CrateStoreDyn;
4443
use rustc_span::symbol::{kw, sym, Ident, Symbol};
4544
use rustc_span::Span;
4645
use rustc_target::abi::Align;
@@ -128,8 +127,6 @@ pub type RegisteredTools = FxHashSet<Ident>;
128127

129128
#[derive(Debug)]
130129
pub struct ResolverOutputs {
131-
pub definitions: rustc_hir::definitions::Definitions,
132-
pub cstore: Box<CrateStoreDyn>,
133130
pub visibilities: FxHashMap<LocalDefId, Visibility>,
134131
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
135132
pub has_pub_restricted: bool,

0 commit comments

Comments
 (0)