Skip to content

Commit d5b1fee

Browse files
incr.comp.: Remove tcx from StableHashingContext.
1 parent ba6f93c commit d5b1fee

File tree

28 files changed

+300
-277
lines changed

28 files changed

+300
-277
lines changed

src/librustc/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
603603
}
604604

605605
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
606-
where T: HashStable<StableHashingContext<'a, 'gcx, 'tcx>> + fmt::Debug
606+
where T: HashStable<StableHashingContext<'gcx>> + fmt::Debug
607607
{
608608
default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
609609

610610
default fn to_fingerprint(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Fingerprint {
611-
let mut hcx = StableHashingContext::new(tcx);
611+
let mut hcx = tcx.create_stable_hashing_context();
612612
let mut hasher = StableHasher::new();
613613

614614
self.hash_stable(&mut hcx, &mut hasher);

src/librustc/hir/map/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub struct Map<'hir> {
247247
/// plain old integers.
248248
map: Vec<MapEntry<'hir>>,
249249

250-
definitions: Definitions,
250+
definitions: &'hir Definitions,
251251

252252
/// Bodies inlined from other crates are cached here.
253253
inlined_bodies: RefCell<DefIdMap<&'hir Body>>,
@@ -304,8 +304,8 @@ impl<'hir> Map<'hir> {
304304
}
305305

306306
#[inline]
307-
pub fn definitions(&self) -> &Definitions {
308-
&self.definitions
307+
pub fn definitions(&self) -> &'hir Definitions {
308+
self.definitions
309309
}
310310

311311
pub fn def_key(&self, def_id: DefId) -> DefKey {
@@ -1013,7 +1013,7 @@ impl Named for TraitItem { fn name(&self) -> Name { self.name } }
10131013
impl Named for ImplItem { fn name(&self) -> Name { self.name } }
10141014

10151015
pub fn map_crate<'hir>(forest: &'hir mut Forest,
1016-
definitions: Definitions)
1016+
definitions: &'hir Definitions)
10171017
-> Map<'hir> {
10181018
let map = {
10191019
let mut collector = NodeCollector::root(&forest.krate,

src/librustc/ich/hcx.rs

+51-37
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
use hir;
1212
use hir::def_id::{DefId, DefIndex};
1313
use hir::map::DefPathHash;
14+
use hir::map::definitions::Definitions;
1415
use ich::{self, CachingCodemapView};
16+
use middle::cstore::CrateStore;
1517
use session::config::DebugInfoLevel::NoDebugInfo;
1618
use ty::{self, TyCtxt, fast_reject};
1719
use session::Session;
@@ -41,8 +43,10 @@ thread_local!(static IGNORED_ATTR_NAMES: RefCell<FxHashSet<Symbol>> =
4143
/// enough information to transform DefIds and HirIds into stable DefPaths (i.e.
4244
/// a reference to the TyCtxt) and it holds a few caches for speeding up various
4345
/// things (e.g. each DefId/DefPath is only hashed once).
44-
pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
45-
tcx: TyCtxt<'a, 'gcx, 'tcx>,
46+
pub struct StableHashingContext<'gcx> {
47+
sess: &'gcx Session,
48+
definitions: &'gcx Definitions,
49+
cstore: &'gcx CrateStore,
4650
body_resolver: BodyResolver<'gcx>,
4751
hash_spans: bool,
4852
hash_bodies: bool,
@@ -65,21 +69,27 @@ pub enum NodeIdHashingMode {
6569
/// We could also just store a plain reference to the hir::Crate but we want
6670
/// to avoid that the crate is used to get untracked access to all of the HIR.
6771
#[derive(Clone, Copy)]
68-
struct BodyResolver<'hir>(&'hir hir::Crate);
72+
struct BodyResolver<'gcx>(&'gcx hir::Crate);
6973

70-
impl<'hir> BodyResolver<'hir> {
74+
impl<'gcx> BodyResolver<'gcx> {
7175
// Return a reference to the hir::Body with the given BodyId.
7276
// DOES NOT DO ANY TRACKING, use carefully.
73-
fn body(self, id: hir::BodyId) -> &'hir hir::Body {
77+
fn body(self, id: hir::BodyId) -> &'gcx hir::Body {
7478
self.0.body(id)
7579
}
7680
}
7781

78-
impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
79-
80-
pub fn new(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Self {
81-
let hash_spans_initial = tcx.sess.opts.debuginfo != NoDebugInfo;
82-
let check_overflow_initial = tcx.sess.overflow_checks();
82+
impl<'gcx> StableHashingContext<'gcx> {
83+
// The `krate` here is only used for mapping BodyIds to Bodies.
84+
// Don't use it for anything else or you'll run the risk of
85+
// leaking data out of the tracking system.
86+
pub fn new(sess: &'gcx Session,
87+
krate: &'gcx hir::Crate,
88+
definitions: &'gcx Definitions,
89+
cstore: &'gcx CrateStore)
90+
-> Self {
91+
let hash_spans_initial = sess.opts.debuginfo != NoDebugInfo;
92+
let check_overflow_initial = sess.overflow_checks();
8393

8494
debug_assert!(ich::IGNORED_ATTRIBUTES.len() > 0);
8595
IGNORED_ATTR_NAMES.with(|names| {
@@ -90,13 +100,13 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
90100
}
91101
});
92102

93-
let body_resolver = BodyResolver(tcx.dep_graph.with_ignore(|| tcx.hir.krate()));
94-
95103
StableHashingContext {
96-
tcx,
97-
body_resolver,
104+
sess,
105+
body_resolver: BodyResolver(krate),
106+
definitions,
107+
cstore,
98108
caching_codemap: None,
99-
raw_codemap: tcx.sess.codemap(),
109+
raw_codemap: sess.codemap(),
100110
hash_spans: hash_spans_initial,
101111
hash_bodies: true,
102112
overflow_checks_enabled: check_overflow_initial,
@@ -106,7 +116,7 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
106116

107117
#[inline]
108118
pub fn sess(&self) -> &'gcx Session {
109-
self.tcx.sess
119+
self.sess
110120
}
111121

112122
pub fn force_span_hashing(mut self) -> Self {
@@ -146,12 +156,16 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
146156

147157
#[inline]
148158
pub fn def_path_hash(&self, def_id: DefId) -> DefPathHash {
149-
self.tcx.def_path_hash(def_id)
159+
if def_id.is_local() {
160+
self.definitions.def_path_hash(def_id.index)
161+
} else {
162+
self.cstore.def_path_hash(def_id)
163+
}
150164
}
151165

152166
#[inline]
153167
pub fn local_def_path_hash(&self, def_index: DefIndex) -> DefPathHash {
154-
self.tcx.hir.definitions().def_path_hash(def_index)
168+
self.definitions.def_path_hash(def_index)
155169
}
156170

157171
#[inline]
@@ -239,26 +253,26 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
239253
}
240254

241255
impl<'a, 'gcx, 'lcx> StableHashingContextProvider for ty::TyCtxt<'a, 'gcx, 'lcx> {
242-
type ContextType = StableHashingContext<'a, 'gcx, 'lcx>;
256+
type ContextType = StableHashingContext<'gcx>;
243257
fn create_stable_hashing_context(&self) -> Self::ContextType {
244-
StableHashingContext::new(*self)
258+
(*self).create_stable_hashing_context()
245259
}
246260
}
247261

248-
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::BodyId {
262+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::BodyId {
249263
fn hash_stable<W: StableHasherResult>(&self,
250-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
264+
hcx: &mut StableHashingContext<'gcx>,
251265
hasher: &mut StableHasher<W>) {
252266
if hcx.hash_bodies() {
253267
hcx.body_resolver.body(*self).hash_stable(hcx, hasher);
254268
}
255269
}
256270
}
257271

258-
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::HirId {
272+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
259273
#[inline]
260274
fn hash_stable<W: StableHasherResult>(&self,
261-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
275+
hcx: &mut StableHashingContext<'gcx>,
262276
hasher: &mut StableHasher<W>) {
263277
match hcx.node_id_hashing_mode {
264278
NodeIdHashingMode::Ignore => {
@@ -270,52 +284,52 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::H
270284
local_id,
271285
} = *self;
272286

273-
hcx.tcx.hir.definitions().def_path_hash(owner).hash_stable(hcx, hasher);
287+
hcx.local_def_path_hash(owner).hash_stable(hcx, hasher);
274288
local_id.hash_stable(hcx, hasher);
275289
}
276290
}
277291
}
278292
}
279293

280-
impl<'a, 'gcx, 'tcx> ToStableHashKey<StableHashingContext<'a, 'gcx, 'tcx>> for hir::HirId {
294+
impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for hir::HirId {
281295
type KeyType = (DefPathHash, hir::ItemLocalId);
282296

283297
#[inline]
284298
fn to_stable_hash_key(&self,
285-
hcx: &StableHashingContext<'a, 'gcx, 'tcx>)
299+
hcx: &StableHashingContext<'gcx>)
286300
-> (DefPathHash, hir::ItemLocalId) {
287301
let def_path_hash = hcx.local_def_path_hash(self.owner);
288302
(def_path_hash, self.local_id)
289303
}
290304
}
291305

292-
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::NodeId {
306+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
293307
fn hash_stable<W: StableHasherResult>(&self,
294-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
308+
hcx: &mut StableHashingContext<'gcx>,
295309
hasher: &mut StableHasher<W>) {
296310
match hcx.node_id_hashing_mode {
297311
NodeIdHashingMode::Ignore => {
298312
// Don't do anything.
299313
}
300314
NodeIdHashingMode::HashDefPath => {
301-
hcx.tcx.hir.node_to_hir_id(*self).hash_stable(hcx, hasher);
315+
hcx.definitions.node_to_hir_id(*self).hash_stable(hcx, hasher);
302316
}
303317
}
304318
}
305319
}
306320

307-
impl<'a, 'gcx, 'tcx> ToStableHashKey<StableHashingContext<'a, 'gcx, 'tcx>> for ast::NodeId {
321+
impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for ast::NodeId {
308322
type KeyType = (DefPathHash, hir::ItemLocalId);
309323

310324
#[inline]
311325
fn to_stable_hash_key(&self,
312-
hcx: &StableHashingContext<'a, 'gcx, 'tcx>)
326+
hcx: &StableHashingContext<'gcx>)
313327
-> (DefPathHash, hir::ItemLocalId) {
314-
hcx.tcx.hir.node_to_hir_id(*self).to_stable_hash_key(hcx)
328+
hcx.definitions.node_to_hir_id(*self).to_stable_hash_key(hcx)
315329
}
316330
}
317331

318-
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Span {
332+
impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
319333

320334
// Hash a span in a stable way. We can't directly hash the span's BytePos
321335
// fields (that would be similar to hashing pointers, since those are just
@@ -327,7 +341,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Span {
327341
// Also, hashing filenames is expensive so we avoid doing it twice when the
328342
// span starts and ends in the same file, which is almost always the case.
329343
fn hash_stable<W: StableHasherResult>(&self,
330-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
344+
hcx: &mut StableHashingContext<'gcx>,
331345
hasher: &mut StableHasher<W>) {
332346
use syntax_pos::Pos;
333347

@@ -390,8 +404,8 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Span {
390404
}
391405
}
392406

393-
pub fn hash_stable_trait_impls<'a, 'tcx, 'gcx, W, R>(
394-
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
407+
pub fn hash_stable_trait_impls<'gcx, W, R>(
408+
hcx: &mut StableHashingContext<'gcx>,
395409
hasher: &mut StableHasher<W>,
396410
blanket_impls: &Vec<DefId>,
397411
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)

0 commit comments

Comments
 (0)