Skip to content

Commit 1c1d357

Browse files
committed
Move the untracked cstore and source_span into a struct
1 parent 2cd36f2 commit 1c1d357

File tree

16 files changed

+78
-91
lines changed

16 files changed

+78
-91
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4342,6 +4342,7 @@ dependencies = [
43424342
"rustc_feature",
43434343
"rustc_fs_util",
43444344
"rustc_hir",
4345+
"rustc_index",
43454346
"rustc_lint_defs",
43464347
"rustc_macros",
43474348
"rustc_serialize",

compiler/rustc_interface/src/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ pub fn create_global_ctxt<'tcx>(
808808
definitions,
809809
global_ctxt: untracked_resolutions,
810810
ast_lowering: untracked_resolver_for_lowering,
811+
untracked,
811812
} = resolver_outputs;
812813

813814
let gcx = sess.time("setup_global_ctxt", || {
@@ -819,6 +820,7 @@ pub fn create_global_ctxt<'tcx>(
819820
hir_arena,
820821
definitions,
821822
untracked_resolutions,
823+
untracked,
822824
krate,
823825
dep_graph,
824826
queries.on_disk_cache.as_ref().map(OnDiskCache::as_dyn),

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+3
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,9 @@ impl CrateStore for CStore {
629629
fn as_any(&self) -> &dyn Any {
630630
self
631631
}
632+
fn untracked_as_any(&mut self) -> &mut dyn Any {
633+
self
634+
}
632635

633636
fn crate_name(&self, cnum: CrateNum) -> Symbol {
634637
self.get_crate_data(cnum).root.name

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_index::vec::Idx;
1414
use rustc_middle::hir::nested_filter;
1515
use rustc_span::def_id::StableCrateId;
1616
use rustc_span::symbol::{kw, sym, Ident, Symbol};
17-
use rustc_span::{Span, DUMMY_SP};
17+
use rustc_span::Span;
1818
use rustc_target::spec::abi::Abi;
1919

2020
#[inline]
@@ -1162,7 +1162,7 @@ pub(super) fn crate_hash(tcx: TyCtxt<'_>, crate_num: CrateNum) -> Svh {
11621162
.filter_map(|(def_id, info)| {
11631163
let _ = info.as_owner()?;
11641164
let def_path_hash = definitions.def_path_hash(def_id);
1165-
let span = resolutions.source_span.get(def_id).unwrap_or(&DUMMY_SP);
1165+
let span = tcx.source_span(def_id);
11661166
debug_assert_eq!(span.parent(), None);
11671167
Some((def_path_hash, span))
11681168
})

compiler/rustc_middle/src/hir/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,6 @@ pub fn provide(providers: &mut Providers) {
141141
providers.hir_attrs = |tcx, id| {
142142
tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
143143
};
144-
providers.source_span =
145-
|tcx, def_id| tcx.resolutions(()).source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
146144
providers.def_span = |tcx, def_id| {
147145
let def_id = def_id.expect_local();
148146
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);

compiler/rustc_middle/src/query/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ rustc_queries! {
4343
/// This span is meant for dep-tracking rather than diagnostics. It should not be used outside
4444
/// of rustc_middle::hir::source_map.
4545
query source_span(key: LocalDefId) -> Span {
46+
// Accesses untracked data
47+
eval_always
4648
desc { "getting the source span" }
4749
}
4850

compiler/rustc_middle/src/ty/context.rs

+27-42
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ use rustc_query_system::dep_graph::DepNodeIndex;
5959
use rustc_query_system::ich::StableHashingContext;
6060
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
6161
use rustc_session::config::{CrateType, OutputFilenames};
62-
use rustc_session::cstore::CrateStoreDyn;
62+
use rustc_session::cstore::{CrateStoreDyn, Untracked};
6363
use rustc_session::lint::Lint;
6464
use rustc_session::Limit;
6565
use rustc_session::Session;
@@ -187,15 +187,13 @@ impl<'tcx> CtxtInterners<'tcx> {
187187
kind: TyKind<'tcx>,
188188
sess: &Session,
189189
definitions: &rustc_hir::definitions::Definitions,
190-
cstore: &CrateStoreDyn,
191-
source_span: &IndexVec<LocalDefId, Span>,
190+
untracked: &Untracked,
192191
) -> Ty<'tcx> {
193192
Ty(Interned::new_unchecked(
194193
self.type_
195194
.intern(kind, |kind| {
196195
let flags = super::flags::FlagComputation::for_kind(&kind);
197-
let stable_hash =
198-
self.stable_hash(&flags, sess, definitions, cstore, source_span, &kind);
196+
let stable_hash = self.stable_hash(&flags, sess, definitions, untracked, &kind);
199197

200198
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
201199
internee: kind,
@@ -213,8 +211,7 @@ impl<'tcx> CtxtInterners<'tcx> {
213211
flags: &ty::flags::FlagComputation,
214212
sess: &'a Session,
215213
definitions: &'a rustc_hir::definitions::Definitions,
216-
cstore: &'a CrateStoreDyn,
217-
source_span: &'a IndexVec<LocalDefId, Span>,
214+
untracked: &'a Untracked,
218215
val: &T,
219216
) -> Fingerprint {
220217
// It's impossible to hash inference variables (and will ICE), so we don't need to try to cache them.
@@ -223,7 +220,7 @@ impl<'tcx> CtxtInterners<'tcx> {
223220
Fingerprint::ZERO
224221
} else {
225222
let mut hasher = StableHasher::new();
226-
let mut hcx = StableHashingContext::new(sess, definitions, cstore, source_span);
223+
let mut hcx = StableHashingContext::new(sess, definitions, untracked);
227224
val.hash_stable(&mut hcx, &mut hasher);
228225
hasher.finish()
229226
}
@@ -235,16 +232,14 @@ impl<'tcx> CtxtInterners<'tcx> {
235232
kind: Binder<'tcx, PredicateKind<'tcx>>,
236233
sess: &Session,
237234
definitions: &rustc_hir::definitions::Definitions,
238-
cstore: &CrateStoreDyn,
239-
source_span: &IndexVec<LocalDefId, Span>,
235+
untracked: &Untracked,
240236
) -> Predicate<'tcx> {
241237
Predicate(Interned::new_unchecked(
242238
self.predicate
243239
.intern(kind, |kind| {
244240
let flags = super::flags::FlagComputation::for_predicate(kind);
245241

246-
let stable_hash =
247-
self.stable_hash(&flags, sess, definitions, cstore, source_span, &kind);
242+
let stable_hash = self.stable_hash(&flags, sess, definitions, untracked, &kind);
248243

249244
InternedInSet(self.arena.alloc(WithCachedTypeInfo {
250245
internee: kind,
@@ -963,10 +958,9 @@ impl<'tcx> CommonTypes<'tcx> {
963958
interners: &CtxtInterners<'tcx>,
964959
sess: &Session,
965960
definitions: &rustc_hir::definitions::Definitions,
966-
cstore: &CrateStoreDyn,
967-
source_span: &IndexVec<LocalDefId, Span>,
961+
untracked: &Untracked,
968962
) -> CommonTypes<'tcx> {
969-
let mk = |ty| interners.intern_ty(ty, sess, definitions, cstore, source_span);
963+
let mk = |ty| interners.intern_ty(ty, sess, definitions, untracked);
970964

971965
CommonTypes {
972966
unit: mk(Tuple(List::empty())),
@@ -1114,6 +1108,7 @@ pub struct GlobalCtxt<'tcx> {
11141108

11151109
definitions: RwLock<Definitions>,
11161110

1111+
untracked: Untracked,
11171112
/// Output of the resolver.
11181113
pub(crate) untracked_resolutions: ty::ResolverGlobalCtxt,
11191114
/// The entire crate as AST. This field serves as the input for the hir_crate query,
@@ -1280,6 +1275,7 @@ impl<'tcx> TyCtxt<'tcx> {
12801275
hir_arena: &'tcx WorkerLocal<hir::Arena<'tcx>>,
12811276
definitions: Definitions,
12821277
untracked_resolutions: ty::ResolverGlobalCtxt,
1278+
untracked: Untracked,
12831279
krate: Lrc<ast::Crate>,
12841280
dep_graph: DepGraph,
12851281
on_disk_cache: Option<&'tcx dyn OnDiskCache<'tcx>>,
@@ -1292,14 +1288,7 @@ impl<'tcx> TyCtxt<'tcx> {
12921288
s.emit_fatal(err);
12931289
});
12941290
let interners = CtxtInterners::new(arena);
1295-
let common_types = CommonTypes::new(
1296-
&interners,
1297-
s,
1298-
&definitions,
1299-
&*untracked_resolutions.cstore,
1300-
// This is only used to create a stable hashing context.
1301-
&untracked_resolutions.source_span,
1302-
);
1291+
let common_types = CommonTypes::new(&interners, s, &definitions, &untracked);
13031292
let common_lifetimes = CommonLifetimes::new(&interners);
13041293
let common_consts = CommonConsts::new(&interners, &common_types);
13051294

@@ -1315,6 +1304,7 @@ impl<'tcx> TyCtxt<'tcx> {
13151304
types: common_types,
13161305
lifetimes: common_lifetimes,
13171306
consts: common_consts,
1307+
untracked,
13181308
untracked_resolutions,
13191309
untracked_crate: Steal::new(krate),
13201310
on_disk_cache,
@@ -1428,7 +1418,7 @@ impl<'tcx> TyCtxt<'tcx> {
14281418
if let Some(id) = id.as_local() {
14291419
self.definitions_untracked().def_key(id)
14301420
} else {
1431-
self.untracked_resolutions.cstore.def_key(id)
1421+
self.untracked.cstore.def_key(id)
14321422
}
14331423
}
14341424

@@ -1442,7 +1432,7 @@ impl<'tcx> TyCtxt<'tcx> {
14421432
if let Some(id) = id.as_local() {
14431433
self.definitions_untracked().def_path(id)
14441434
} else {
1445-
self.untracked_resolutions.cstore.def_path(id)
1435+
self.untracked.cstore.def_path(id)
14461436
}
14471437
}
14481438

@@ -1452,7 +1442,7 @@ impl<'tcx> TyCtxt<'tcx> {
14521442
if let Some(def_id) = def_id.as_local() {
14531443
self.definitions_untracked().def_path_hash(def_id)
14541444
} else {
1455-
self.untracked_resolutions.cstore.def_path_hash(def_id)
1445+
self.untracked.cstore.def_path_hash(def_id)
14561446
}
14571447
}
14581448

@@ -1461,7 +1451,7 @@ impl<'tcx> TyCtxt<'tcx> {
14611451
if crate_num == LOCAL_CRATE {
14621452
self.sess.local_stable_crate_id()
14631453
} else {
1464-
self.untracked_resolutions.cstore.stable_crate_id(crate_num)
1454+
self.untracked.cstore.stable_crate_id(crate_num)
14651455
}
14661456
}
14671457

@@ -1472,7 +1462,7 @@ impl<'tcx> TyCtxt<'tcx> {
14721462
if stable_crate_id == self.sess.local_stable_crate_id() {
14731463
LOCAL_CRATE
14741464
} else {
1475-
self.untracked_resolutions.cstore.stable_crate_id_to_crate_num(stable_crate_id)
1465+
self.untracked.cstore.stable_crate_id_to_crate_num(stable_crate_id)
14761466
}
14771467
}
14781468

@@ -1491,7 +1481,7 @@ impl<'tcx> TyCtxt<'tcx> {
14911481
} else {
14921482
// If this is a DefPathHash from an upstream crate, let the CrateStore map
14931483
// it to a DefId.
1494-
let cstore = &*self.untracked_resolutions.cstore;
1484+
let cstore = &*self.untracked.cstore;
14951485
let cnum = cstore.stable_crate_id_to_crate_num(stable_crate_id);
14961486
cstore.def_path_hash_to_def_id(cnum, hash)
14971487
}
@@ -1505,7 +1495,7 @@ impl<'tcx> TyCtxt<'tcx> {
15051495
let (crate_name, stable_crate_id) = if def_id.is_local() {
15061496
(self.crate_name, self.sess.local_stable_crate_id())
15071497
} else {
1508-
let cstore = &*self.untracked_resolutions.cstore;
1498+
let cstore = &*self.untracked.cstore;
15091499
(cstore.crate_name(def_id.krate), cstore.stable_crate_id(def_id.krate))
15101500
};
15111501

@@ -1604,7 +1594,7 @@ impl<'tcx> TyCtxt<'tcx> {
16041594
/// Note that this is *untracked* and should only be used within the query
16051595
/// system if the result is otherwise tracked through queries
16061596
pub fn cstore_untracked(self) -> &'tcx CrateStoreDyn {
1607-
&*self.untracked_resolutions.cstore
1597+
&*self.untracked.cstore
16081598
}
16091599

16101600
/// Note that this is *untracked* and should only be used within the query
@@ -1618,7 +1608,7 @@ impl<'tcx> TyCtxt<'tcx> {
16181608
/// system if the result is otherwise tracked through queries
16191609
#[inline]
16201610
pub fn source_span_untracked(self, def_id: LocalDefId) -> Span {
1621-
self.untracked_resolutions.source_span.get(def_id).copied().unwrap_or(DUMMY_SP)
1611+
self.untracked.source_span.get(def_id).copied().unwrap_or(DUMMY_SP)
16221612
}
16231613

16241614
#[inline(always)]
@@ -1627,12 +1617,7 @@ impl<'tcx> TyCtxt<'tcx> {
16271617
f: impl FnOnce(StableHashingContext<'_>) -> R,
16281618
) -> R {
16291619
let definitions = self.definitions_untracked();
1630-
let hcx = StableHashingContext::new(
1631-
self.sess,
1632-
&*definitions,
1633-
&*self.untracked_resolutions.cstore,
1634-
&self.untracked_resolutions.source_span,
1635-
);
1620+
let hcx = StableHashingContext::new(self.sess, &*definitions, &self.untracked);
16361621
f(hcx)
16371622
}
16381623

@@ -2428,9 +2413,8 @@ impl<'tcx> TyCtxt<'tcx> {
24282413
st,
24292414
self.sess,
24302415
&self.definitions.read(),
2431-
&*self.untracked_resolutions.cstore,
24322416
// This is only used to create a stable hashing context.
2433-
&self.untracked_resolutions.source_span,
2417+
&self.untracked,
24342418
)
24352419
}
24362420

@@ -2440,9 +2424,8 @@ impl<'tcx> TyCtxt<'tcx> {
24402424
binder,
24412425
self.sess,
24422426
&self.definitions.read(),
2443-
&*self.untracked_resolutions.cstore,
24442427
// This is only used to create a stable hashing context.
2445-
&self.untracked_resolutions.source_span,
2428+
&self.untracked,
24462429
)
24472430
}
24482431

@@ -3124,4 +3107,6 @@ pub fn provide(providers: &mut ty::query::Providers) {
31243107
// We want to check if the panic handler was defined in this crate
31253108
tcx.lang_items().panic_impl().map_or(false, |did| did.is_local())
31263109
};
3110+
providers.source_span =
3111+
|tcx, def_id| tcx.untracked.source_span.get(def_id).copied().unwrap_or(DUMMY_SP);
31273112
}

compiler/rustc_middle/src/ty/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_index::vec::IndexVec;
4646
use rustc_macros::HashStable;
4747
use rustc_query_system::ich::StableHashingContext;
4848
use rustc_serialize::{Decodable, Encodable};
49-
use rustc_session::cstore::CrateStoreDyn;
49+
use rustc_session::cstore::Untracked;
5050
use rustc_span::hygiene::MacroKind;
5151
use rustc_span::symbol::{kw, sym, Ident, Symbol};
5252
use rustc_span::{ExpnId, Span};
@@ -153,18 +153,16 @@ pub struct ResolverOutputs {
153153
pub definitions: Definitions,
154154
pub global_ctxt: ResolverGlobalCtxt,
155155
pub ast_lowering: ResolverAstLowering,
156+
pub untracked: Untracked,
156157
}
157158

158159
#[derive(Debug)]
159160
pub struct ResolverGlobalCtxt {
160-
pub cstore: Box<CrateStoreDyn>,
161161
pub visibilities: FxHashMap<LocalDefId, Visibility>,
162162
/// This field is used to decide whether we should make `PRIVATE_IN_PUBLIC` a hard error.
163163
pub has_pub_restricted: bool,
164164
/// Item with a given `LocalDefId` was defined during macro expansion with ID `ExpnId`.
165165
pub expn_that_defined: FxHashMap<LocalDefId, ExpnId>,
166-
/// Reference span for definitions.
167-
pub source_span: IndexVec<LocalDefId, Span>,
168166
pub effective_visibilities: EffectiveVisibilities,
169167
pub extern_crate_map: FxHashMap<LocalDefId, CrateNum>,
170168
pub maybe_unused_trait_imports: FxIndexSet<LocalDefId>,

0 commit comments

Comments
 (0)