Skip to content

Commit e3f9131

Browse files
Fix issues uncovered by rebasing:
- Don't hash traits in scope as part of HIR hashing any more. - Some queries returned DefIndexes from other crates. - Provide a generic way of stably hashing maps (not used everywhere yet).
1 parent 3cc3ae2 commit e3f9131

File tree

22 files changed

+328
-237
lines changed

22 files changed

+328
-237
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,18 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
633633
}
634634
}
635635

636+
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,) {
637+
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;
638+
639+
fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
640+
tcx.hir.definitions().def_path_hash(self.0).0
641+
}
642+
643+
fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
644+
tcx.item_path_str(DefId::local(self.0))
645+
}
646+
}
647+
636648
impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
637649
const CAN_RECONSTRUCT_QUERY_KEY: bool = false;
638650

src/librustc/ich/hcx.rs

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ use syntax::symbol::Symbol;
2727
use syntax_pos::Span;
2828

2929
use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvider,
30-
StableHasher, StableHasherResult};
30+
StableHasher, StableHasherResult,
31+
ToStableHashKey};
3132
use rustc_data_structures::accumulate_vec::AccumulateVec;
3233

3334
/// This is the context state available during incr. comp. hashing. It contains
@@ -48,9 +49,7 @@ pub struct StableHashingContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
4849
#[derive(PartialEq, Eq, Clone, Copy)]
4950
pub enum NodeIdHashingMode {
5051
Ignore,
51-
CheckedIgnore,
5252
HashDefPath,
53-
HashTraitsInScope,
5453
}
5554

5655
impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
@@ -150,7 +149,7 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
150149
self.overflow_checks_enabled = true;
151150
}
152151
let prev_hash_node_ids = self.node_id_hashing_mode;
153-
self.node_id_hashing_mode = NodeIdHashingMode::CheckedIgnore;
152+
self.node_id_hashing_mode = NodeIdHashingMode::Ignore;
154153

155154
f(self);
156155

@@ -207,41 +206,28 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::N
207206
fn hash_stable<W: StableHasherResult>(&self,
208207
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
209208
hasher: &mut StableHasher<W>) {
210-
let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
211209
match hcx.node_id_hashing_mode {
212210
NodeIdHashingMode::Ignore => {
213211
// Don't do anything.
214212
}
215-
NodeIdHashingMode::CheckedIgnore => {
216-
// Most NodeIds in the HIR can be ignored, but if there is a
217-
// corresponding entry in the `trait_map` we need to hash that.
218-
// Make sure we don't ignore too much by checking that there is
219-
// no entry in a debug_assert!().
220-
debug_assert!(hcx.tcx.in_scope_traits(hir_id).is_none());
221-
}
222213
NodeIdHashingMode::HashDefPath => {
223-
hir_id.hash_stable(hcx, hasher);
224-
}
225-
NodeIdHashingMode::HashTraitsInScope => {
226-
if let Some(traits) = hcx.tcx.in_scope_traits(hir_id) {
227-
// The ordering of the candidates is not fixed. So we hash
228-
// the def-ids and then sort them and hash the collection.
229-
let mut candidates: AccumulateVec<[_; 8]> =
230-
traits.iter()
231-
.map(|&hir::TraitCandidate { def_id, import_id: _ }| {
232-
hcx.def_path_hash(def_id)
233-
})
234-
.collect();
235-
if traits.len() > 1 {
236-
candidates.sort();
237-
}
238-
candidates.hash_stable(hcx, hasher);
239-
}
214+
hcx.tcx.hir.node_to_hir_id(*self).hash_stable(hcx, hasher);
240215
}
241216
}
242217
}
243218
}
244219

220+
impl<'a, 'gcx, 'tcx> ToStableHashKey<StableHashingContext<'a, 'gcx, 'tcx>> for ast::NodeId {
221+
type KeyType = (DefPathHash, hir::ItemLocalId);
222+
223+
#[inline]
224+
fn to_stable_hash_key(&self,
225+
hcx: &StableHashingContext<'a, 'gcx, 'tcx>)
226+
-> (DefPathHash, hir::ItemLocalId) {
227+
hcx.tcx.hir.node_to_hir_id(*self).to_stable_hash_key(hcx)
228+
}
229+
}
230+
245231
impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Span {
246232

247233
// Hash a span in a stable way. We can't directly hash the span's BytePos

src/librustc/ich/impls_cstore.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,9 @@ impl_stable_hash_for!(struct middle::cstore::ExternCrate {
4545
direct,
4646
path_len
4747
});
48+
49+
impl_stable_hash_for!(struct middle::cstore::CrateSource {
50+
dylib,
51+
rlib,
52+
rmeta
53+
});

0 commit comments

Comments
 (0)