Skip to content

Commit b6e8635

Browse files
ICH: Make StableHashingContext work with any TyCtxt, not just the global one.
1 parent 9006db1 commit b6e8635

File tree

12 files changed

+239
-208
lines changed

12 files changed

+239
-208
lines changed

src/librustc/ich/caching_codemap_view.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub struct CachingCodemapView<'tcx> {
2929
time_stamp: usize,
3030
}
3131

32-
impl<'tcx> CachingCodemapView<'tcx> {
33-
pub fn new<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> CachingCodemapView<'tcx> {
32+
impl<'gcx> CachingCodemapView<'gcx> {
33+
pub fn new<'a, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>) -> CachingCodemapView<'gcx> {
3434
let codemap = tcx.sess.codemap();
3535
let files = codemap.files();
3636
let first_file = files[0].clone();

src/librustc/ich/hcx.rs

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ use rustc_data_structures::accumulate_vec::AccumulateVec;
3333
/// enough information to transform DefIds and HirIds into stable DefPaths (i.e.
3434
/// a reference to the TyCtxt) and it holds a few caches for speeding up various
3535
/// things (e.g. each DefId/DefPath is only hashed once).
36-
pub struct StableHashingContext<'a, 'tcx: 'a> {
37-
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
38-
codemap: CachingCodemapView<'tcx>,
36+
pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
37+
tcx: ty::TyCtxt<'a, 'gcx, 'tcx>,
38+
codemap: CachingCodemapView<'gcx>,
3939
hash_spans: bool,
4040
hash_bodies: bool,
4141
overflow_checks_enabled: bool,
@@ -51,9 +51,9 @@ pub enum NodeIdHashingMode {
5151
HashTraitsInScope,
5252
}
5353

54-
impl<'a, 'tcx: 'a> StableHashingContext<'a, 'tcx> {
54+
impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
5555

56-
pub fn new(tcx: ty::TyCtxt<'a, 'tcx, 'tcx>) -> Self {
56+
pub fn new(tcx: ty::TyCtxt<'a, 'gcx, 'tcx>) -> Self {
5757
let hash_spans_initial = tcx.sess.opts.debuginfo != NoDebugInfo;
5858
let check_overflow_initial = tcx.sess.overflow_checks();
5959

@@ -111,7 +111,7 @@ impl<'a, 'tcx: 'a> StableHashingContext<'a, 'tcx> {
111111
}
112112

113113
#[inline]
114-
pub fn tcx(&self) -> ty::TyCtxt<'a, 'tcx, 'tcx> {
114+
pub fn tcx(&self) -> ty::TyCtxt<'a, 'gcx, 'tcx> {
115115
self.tcx
116116
}
117117

@@ -131,7 +131,7 @@ impl<'a, 'tcx: 'a> StableHashingContext<'a, 'tcx> {
131131
}
132132

133133
#[inline]
134-
pub fn codemap(&mut self) -> &mut CachingCodemapView<'tcx> {
134+
pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> {
135135
&mut self.codemap
136136
}
137137

@@ -195,9 +195,9 @@ impl<'a, 'tcx: 'a> StableHashingContext<'a, 'tcx> {
195195
}
196196

197197

198-
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ast::NodeId {
198+
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::NodeId {
199199
fn hash_stable<W: StableHasherResult>(&self,
200-
hcx: &mut StableHashingContext<'a, 'tcx>,
200+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
201201
hasher: &mut StableHasher<W>) {
202202
match hcx.node_id_hashing_mode {
203203
NodeIdHashingMode::Ignore => {
@@ -230,7 +230,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for ast::NodeId {
230230
}
231231
}
232232

233-
impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for Span {
233+
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Span {
234234

235235
// Hash a span in a stable way. We can't directly hash the span's BytePos
236236
// fields (that would be similar to hashing pointers, since those are just
@@ -242,7 +242,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for Span {
242242
// Also, hashing filenames is expensive so we avoid doing it twice when the
243243
// span starts and ends in the same file, which is almost always the case.
244244
fn hash_stable<W: StableHasherResult>(&self,
245-
hcx: &mut StableHashingContext<'a, 'tcx>,
245+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
246246
hasher: &mut StableHasher<W>) {
247247
use syntax_pos::Pos;
248248

@@ -305,15 +305,16 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a, 'tcx>> for Span {
305305
}
306306
}
307307

308-
pub fn hash_stable_hashmap<'a, 'tcx, K, V, R, SK, F, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
309-
hasher: &mut StableHasher<W>,
310-
map: &HashMap<K, V, R>,
311-
extract_stable_key: F)
308+
pub fn hash_stable_hashmap<'a, 'gcx, 'tcx, K, V, R, SK, F, W>(
309+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
310+
hasher: &mut StableHasher<W>,
311+
map: &HashMap<K, V, R>,
312+
extract_stable_key: F)
312313
where K: Eq + std_hash::Hash,
313-
V: HashStable<StableHashingContext<'a, 'tcx>>,
314+
V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
314315
R: std_hash::BuildHasher,
315-
SK: HashStable<StableHashingContext<'a, 'tcx>> + Ord + Clone,
316-
F: Fn(&mut StableHashingContext<'a, 'tcx>, &K) -> SK,
316+
SK: HashStable<StableHashingContext<'a, 'gcx, 'tcx>> + Ord + Clone,
317+
F: Fn(&mut StableHashingContext<'a, 'gcx, 'tcx>, &K) -> SK,
317318
W: StableHasherResult,
318319
{
319320
let mut keys: Vec<_> = map.keys()
@@ -327,14 +328,15 @@ pub fn hash_stable_hashmap<'a, 'tcx, K, V, R, SK, F, W>(hcx: &mut StableHashingC
327328
}
328329
}
329330

330-
pub fn hash_stable_hashset<'a, 'tcx, K, R, SK, F, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
331-
hasher: &mut StableHasher<W>,
332-
set: &HashSet<K, R>,
333-
extract_stable_key: F)
331+
pub fn hash_stable_hashset<'a, 'tcx, 'gcx, K, R, SK, F, W>(
332+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
333+
hasher: &mut StableHasher<W>,
334+
set: &HashSet<K, R>,
335+
extract_stable_key: F)
334336
where K: Eq + std_hash::Hash,
335337
R: std_hash::BuildHasher,
336-
SK: HashStable<StableHashingContext<'a, 'tcx>> + Ord + Clone,
337-
F: Fn(&mut StableHashingContext<'a, 'tcx>, &K) -> SK,
338+
SK: HashStable<StableHashingContext<'a, 'gcx, 'tcx>> + Ord + Clone,
339+
F: Fn(&mut StableHashingContext<'a, 'gcx, 'tcx>, &K) -> SK,
338340
W: StableHasherResult,
339341
{
340342
let mut keys: Vec<_> = set.iter()
@@ -344,10 +346,11 @@ pub fn hash_stable_hashset<'a, 'tcx, K, R, SK, F, W>(hcx: &mut StableHashingCont
344346
keys.hash_stable(hcx, hasher);
345347
}
346348

347-
pub fn hash_stable_nodemap<'a, 'tcx, V, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
348-
hasher: &mut StableHasher<W>,
349-
map: &NodeMap<V>)
350-
where V: HashStable<StableHashingContext<'a, 'tcx>>,
349+
pub fn hash_stable_nodemap<'a, 'tcx, 'gcx, V, W>(
350+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
351+
hasher: &mut StableHasher<W>,
352+
map: &NodeMap<V>)
353+
where V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
351354
W: StableHasherResult,
352355
{
353356
hash_stable_hashmap(hcx, hasher, map, |hcx, node_id| {
@@ -356,14 +359,15 @@ pub fn hash_stable_nodemap<'a, 'tcx, V, W>(hcx: &mut StableHashingContext<'a, 't
356359
}
357360

358361

359-
pub fn hash_stable_btreemap<'a, 'tcx, K, V, SK, F, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
360-
hasher: &mut StableHasher<W>,
361-
map: &BTreeMap<K, V>,
362-
extract_stable_key: F)
362+
pub fn hash_stable_btreemap<'a, 'tcx, 'gcx, K, V, SK, F, W>(
363+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
364+
hasher: &mut StableHasher<W>,
365+
map: &BTreeMap<K, V>,
366+
extract_stable_key: F)
363367
where K: Eq + Ord,
364-
V: HashStable<StableHashingContext<'a, 'tcx>>,
365-
SK: HashStable<StableHashingContext<'a, 'tcx>> + Ord + Clone,
366-
F: Fn(&mut StableHashingContext<'a, 'tcx>, &K) -> SK,
368+
V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
369+
SK: HashStable<StableHashingContext<'a, 'gcx, 'tcx>> + Ord + Clone,
370+
F: Fn(&mut StableHashingContext<'a, 'gcx, 'tcx>, &K) -> SK,
367371
W: StableHasherResult,
368372
{
369373
let mut keys: Vec<_> = map.keys()

0 commit comments

Comments
 (0)