Skip to content

Commit e6c9a53

Browse files
incr.comp.: Compute hashes of all query results.
1 parent 3cf28f3 commit e6c9a53

File tree

17 files changed

+828
-84
lines changed

17 files changed

+828
-84
lines changed

src/librustc/ich/hcx.rs

+75-7
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ use hir::def_id::DefId;
1313
use hir::map::DefPathHash;
1414
use ich::{self, CachingCodemapView};
1515
use session::config::DebugInfoLevel::NoDebugInfo;
16-
use ty::TyCtxt;
17-
use util::nodemap::{NodeMap, ItemLocalMap};
16+
use ty::{self, TyCtxt, fast_reject};
17+
use util::nodemap::{NodeMap, NodeSet, ItemLocalMap};
1818

19+
use std::cmp::Ord;
1920
use std::hash as std_hash;
2021
use std::collections::{HashMap, HashSet, BTreeMap};
2122

@@ -47,6 +48,7 @@ pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
4748
#[derive(PartialEq, Eq, Clone, Copy)]
4849
pub enum NodeIdHashingMode {
4950
Ignore,
51+
CheckedIgnore,
5052
HashDefPath,
5153
HashTraitsInScope,
5254
}
@@ -148,7 +150,7 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
148150
self.overflow_checks_enabled = true;
149151
}
150152
let prev_hash_node_ids = self.node_id_hashing_mode;
151-
self.node_id_hashing_mode = NodeIdHashingMode::Ignore;
153+
self.node_id_hashing_mode = NodeIdHashingMode::CheckedIgnore;
152154

153155
f(self);
154156

@@ -202,6 +204,9 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::N
202204
let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
203205
match hcx.node_id_hashing_mode {
204206
NodeIdHashingMode::Ignore => {
207+
// Don't do anything.
208+
}
209+
NodeIdHashingMode::CheckedIgnore => {
205210
// Most NodeIds in the HIR can be ignored, but if there is a
206211
// corresponding entry in the `trait_map` we need to hash that.
207212
// Make sure we don't ignore too much by checking that there is
@@ -321,7 +326,7 @@ pub fn hash_stable_hashmap<'a, 'gcx, 'tcx, K, V, R, SK, F, W>(
321326
let mut keys: Vec<_> = map.keys()
322327
.map(|k| (extract_stable_key(hcx, k), k))
323328
.collect();
324-
keys.sort_unstable_by_key(|&(ref stable_key, _)| stable_key.clone());
329+
keys.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2));
325330
keys.len().hash_stable(hcx, hasher);
326331
for (stable_key, key) in keys {
327332
stable_key.hash_stable(hcx, hasher);
@@ -354,8 +359,25 @@ pub fn hash_stable_nodemap<'a, 'tcx, 'gcx, V, W>(
354359
where V: HashStable<StableHashingContext<'a, 'gcx, 'tcx>>,
355360
W: StableHasherResult,
356361
{
357-
hash_stable_hashmap(hcx, hasher, map, |hcx, node_id| {
358-
hcx.tcx.hir.definitions().node_to_hir_id(*node_id).local_id
362+
let definitions = hcx.tcx.hir.definitions();
363+
hash_stable_hashmap(hcx, hasher, map, |_, node_id| {
364+
let hir_id = definitions.node_to_hir_id(*node_id);
365+
let owner_def_path_hash = definitions.def_path_hash(hir_id.owner);
366+
(owner_def_path_hash, hir_id.local_id)
367+
});
368+
}
369+
370+
pub fn hash_stable_nodeset<'a, 'tcx, 'gcx, W>(
371+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
372+
hasher: &mut StableHasher<W>,
373+
map: &NodeSet)
374+
where W: StableHasherResult,
375+
{
376+
let definitions = hcx.tcx.hir.definitions();
377+
hash_stable_hashset(hcx, hasher, map, |_, node_id| {
378+
let hir_id = definitions.node_to_hir_id(*node_id);
379+
let owner_def_path_hash = definitions.def_path_hash(hir_id.owner);
380+
(owner_def_path_hash, hir_id.local_id)
359381
});
360382
}
361383

@@ -386,10 +408,56 @@ pub fn hash_stable_btreemap<'a, 'tcx, 'gcx, K, V, SK, F, W>(
386408
let mut keys: Vec<_> = map.keys()
387409
.map(|k| (extract_stable_key(hcx, k), k))
388410
.collect();
389-
keys.sort_unstable_by_key(|&(ref stable_key, _)| stable_key.clone());
411+
keys.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2));
390412
keys.len().hash_stable(hcx, hasher);
391413
for (stable_key, key) in keys {
392414
stable_key.hash_stable(hcx, hasher);
393415
map[key].hash_stable(hcx, hasher);
394416
}
395417
}
418+
419+
pub fn hash_stable_trait_impls<'a, 'tcx, 'gcx, W, R>(
420+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
421+
hasher: &mut StableHasher<W>,
422+
blanket_impls: &Vec<DefId>,
423+
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
424+
where W: StableHasherResult,
425+
R: std_hash::BuildHasher,
426+
{
427+
{
428+
let mut blanket_impls: AccumulateVec<[_; 8]> = blanket_impls
429+
.iter()
430+
.map(|&def_id| hcx.def_path_hash(def_id))
431+
.collect();
432+
433+
if blanket_impls.len() > 1 {
434+
blanket_impls.sort_unstable();
435+
}
436+
437+
blanket_impls.hash_stable(hcx, hasher);
438+
}
439+
440+
{
441+
let tcx = hcx.tcx();
442+
let mut keys: AccumulateVec<[_; 8]> =
443+
non_blanket_impls.keys()
444+
.map(|k| (k, k.map_def(|d| tcx.def_path_hash(d))))
445+
.collect();
446+
keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2));
447+
keys.len().hash_stable(hcx, hasher);
448+
for (key, ref stable_key) in keys {
449+
stable_key.hash_stable(hcx, hasher);
450+
let mut impls : AccumulateVec<[_; 8]> = non_blanket_impls[key]
451+
.iter()
452+
.map(|&impl_id| hcx.def_path_hash(impl_id))
453+
.collect();
454+
455+
if impls.len() > 1 {
456+
impls.sort_unstable();
457+
}
458+
459+
impls.hash_stable(hcx, hasher);
460+
}
461+
}
462+
}
463+

src/librustc/ich/impls_cstore.rs

+7
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ impl_stable_hash_for!(enum middle::cstore::LinkagePreference {
3838
RequireDynamic,
3939
RequireStatic
4040
});
41+
42+
impl_stable_hash_for!(struct middle::cstore::ExternCrate {
43+
def_id,
44+
span,
45+
direct,
46+
path_len
47+
});

src/librustc/ich/impls_hir.rs

+40-14
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@
1313
1414
use hir;
1515
use hir::def_id::{DefId, CrateNum, CRATE_DEF_INDEX};
16-
use ich::{StableHashingContext, NodeIdHashingMode};
17-
use std::mem;
18-
19-
use syntax::ast;
20-
16+
use ich::{self, StableHashingContext, NodeIdHashingMode};
2117
use rustc_data_structures::stable_hasher::{HashStable, StableHasher,
2218
StableHasherResult};
19+
use std::mem;
20+
use syntax::ast;
21+
use util::nodemap::DefIdSet;
2322

2423
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for DefId {
2524
#[inline]
@@ -30,6 +29,16 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for DefId
3029
}
3130
}
3231

32+
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for DefIdSet
33+
{
34+
fn hash_stable<W: StableHasherResult>(&self,
35+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
36+
hasher: &mut StableHasher<W>) {
37+
ich::hash_stable_hashset(hcx, hasher, self, |hcx, def_id| {
38+
hcx.def_path_hash(*def_id)
39+
});
40+
}
41+
}
3342

3443
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::HirId {
3544
#[inline]
@@ -235,7 +244,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::T
235244
hir::TyTypeof(..) |
236245
hir::TyErr |
237246
hir::TyInfer => {
238-
NodeIdHashingMode::Ignore
247+
NodeIdHashingMode::CheckedIgnore
239248
}
240249
hir::TyPath(..) => {
241250
NodeIdHashingMode::HashTraitsInScope
@@ -403,7 +412,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::P
403412
hir::PatKind::Lit(..) |
404413
hir::PatKind::Range(..) |
405414
hir::PatKind::Slice(..) => {
406-
NodeIdHashingMode::Ignore
415+
NodeIdHashingMode::CheckedIgnore
407416
}
408417
hir::PatKind::Path(..) |
409418
hir::PatKind::Struct(..) |
@@ -574,21 +583,21 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::E
574583
hir::ExprRepeat(..) |
575584
hir::ExprTup(..) => {
576585
// For these we only hash the span when debuginfo is on.
577-
(false, NodeIdHashingMode::Ignore)
586+
(false, NodeIdHashingMode::CheckedIgnore)
578587
}
579588
// For the following, spans might be significant because of
580589
// panic messages indicating the source location.
581590
hir::ExprBinary(op, ..) => {
582-
(hcx.binop_can_panic_at_runtime(op.node), NodeIdHashingMode::Ignore)
591+
(hcx.binop_can_panic_at_runtime(op.node), NodeIdHashingMode::CheckedIgnore)
583592
}
584593
hir::ExprUnary(op, _) => {
585-
(hcx.unop_can_panic_at_runtime(op), NodeIdHashingMode::Ignore)
594+
(hcx.unop_can_panic_at_runtime(op), NodeIdHashingMode::CheckedIgnore)
586595
}
587596
hir::ExprAssignOp(op, ..) => {
588-
(hcx.binop_can_panic_at_runtime(op.node), NodeIdHashingMode::Ignore)
597+
(hcx.binop_can_panic_at_runtime(op.node), NodeIdHashingMode::CheckedIgnore)
589598
}
590599
hir::ExprIndex(..) => {
591-
(true, NodeIdHashingMode::Ignore)
600+
(true, NodeIdHashingMode::CheckedIgnore)
592601
}
593602
// For these we don't care about the span, but want to hash the
594603
// trait in scope
@@ -899,7 +908,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::I
899908
hir::ItemStatic(..) |
900909
hir::ItemConst(..) |
901910
hir::ItemFn(..) => {
902-
(NodeIdHashingMode::Ignore, hcx.hash_spans())
911+
(NodeIdHashingMode::CheckedIgnore, hcx.hash_spans())
903912
}
904913
hir::ItemUse(..) => {
905914
(NodeIdHashingMode::HashTraitsInScope, false)
@@ -916,7 +925,7 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for hir::I
916925
hir::ItemEnum(..) |
917926
hir::ItemStruct(..) |
918927
hir::ItemUnion(..) => {
919-
(NodeIdHashingMode::Ignore, false)
928+
(NodeIdHashingMode::CheckedIgnore, false)
920929
}
921930
};
922931

@@ -1160,3 +1169,20 @@ for ::middle::lang_items::LangItem {
11601169
::std::hash::Hash::hash(self, hasher);
11611170
}
11621171
}
1172+
1173+
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>>
1174+
for hir::TraitCandidate {
1175+
fn hash_stable<W: StableHasherResult>(&self,
1176+
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
1177+
hasher: &mut StableHasher<W>) {
1178+
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
1179+
let hir::TraitCandidate {
1180+
def_id,
1181+
import_id,
1182+
} = *self;
1183+
1184+
def_id.hash_stable(hcx, hasher);
1185+
import_id.hash_stable(hcx, hasher);
1186+
});
1187+
}
1188+
}

0 commit comments

Comments
 (0)