Skip to content

Commit

Permalink
Fix issues uncovered by rebasing:
Browse files Browse the repository at this point in the history
- 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).
  • Loading branch information
michaelwoerister committed Sep 18, 2017
1 parent 3cc3ae2 commit e3f9131
Show file tree
Hide file tree
Showing 22 changed files with 328 additions and 237 deletions.
12 changes: 12 additions & 0 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,18 @@ impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId,) {
}
}

impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefIndex,) {
const CAN_RECONSTRUCT_QUERY_KEY: bool = true;

fn to_fingerprint(&self, tcx: TyCtxt) -> Fingerprint {
tcx.hir.definitions().def_path_hash(self.0).0
}

fn to_debug_str(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> String {
tcx.item_path_str(DefId::local(self.0))
}
}

impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> DepNodeParams<'a, 'gcx, 'tcx> for (DefId, DefId) {
const CAN_RECONSTRUCT_QUERY_KEY: bool = false;

Expand Down
44 changes: 15 additions & 29 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ use syntax::symbol::Symbol;
use syntax_pos::Span;

use rustc_data_structures::stable_hasher::{HashStable, StableHashingContextProvider,
StableHasher, StableHasherResult};
StableHasher, StableHasherResult,
ToStableHashKey};
use rustc_data_structures::accumulate_vec::AccumulateVec;

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

impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
Expand Down Expand Up @@ -150,7 +149,7 @@ impl<'a, 'gcx, 'tcx> StableHashingContext<'a, 'gcx, 'tcx> {
self.overflow_checks_enabled = true;
}
let prev_hash_node_ids = self.node_id_hashing_mode;
self.node_id_hashing_mode = NodeIdHashingMode::CheckedIgnore;
self.node_id_hashing_mode = NodeIdHashingMode::Ignore;

f(self);

Expand Down Expand Up @@ -207,41 +206,28 @@ impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for ast::N
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a, 'gcx, 'tcx>,
hasher: &mut StableHasher<W>) {
let hir_id = hcx.tcx.hir.node_to_hir_id(*self);
match hcx.node_id_hashing_mode {
NodeIdHashingMode::Ignore => {
// Don't do anything.
}
NodeIdHashingMode::CheckedIgnore => {
// Most NodeIds in the HIR can be ignored, but if there is a
// corresponding entry in the `trait_map` we need to hash that.
// Make sure we don't ignore too much by checking that there is
// no entry in a debug_assert!().
debug_assert!(hcx.tcx.in_scope_traits(hir_id).is_none());
}
NodeIdHashingMode::HashDefPath => {
hir_id.hash_stable(hcx, hasher);
}
NodeIdHashingMode::HashTraitsInScope => {
if let Some(traits) = hcx.tcx.in_scope_traits(hir_id) {
// The ordering of the candidates is not fixed. So we hash
// the def-ids and then sort them and hash the collection.
let mut candidates: AccumulateVec<[_; 8]> =
traits.iter()
.map(|&hir::TraitCandidate { def_id, import_id: _ }| {
hcx.def_path_hash(def_id)
})
.collect();
if traits.len() > 1 {
candidates.sort();
}
candidates.hash_stable(hcx, hasher);
}
hcx.tcx.hir.node_to_hir_id(*self).hash_stable(hcx, hasher);
}
}
}
}

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

#[inline]
fn to_stable_hash_key(&self,
hcx: &StableHashingContext<'a, 'gcx, 'tcx>)
-> (DefPathHash, hir::ItemLocalId) {
hcx.tcx.hir.node_to_hir_id(*self).to_stable_hash_key(hcx)
}
}

impl<'a, 'gcx, 'tcx> HashStable<StableHashingContext<'a, 'gcx, 'tcx>> for Span {

// Hash a span in a stable way. We can't directly hash the span's BytePos
Expand Down
6 changes: 6 additions & 0 deletions src/librustc/ich/impls_cstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,9 @@ impl_stable_hash_for!(struct middle::cstore::ExternCrate {
direct,
path_len
});

impl_stable_hash_for!(struct middle::cstore::CrateSource {
dylib,
rlib,
rmeta
});
Loading

0 comments on commit e3f9131

Please sign in to comment.