use hir;
use hir::def_id::DefId;
-use ich::{self, CachingCodemapView, DefPathHashes};
+use ich::{self, CachingCodemapView};
use session::config::DebugInfoLevel::NoDebugInfo;
use ty;
+use util::nodemap::NodeMap;
use std::hash as std_hash;
+use std::collections::{HashMap, HashSet, BTreeMap};
use syntax::ast;
use syntax::attr;
/// things (e.g. each DefId/DefPath is only hashed once).
pub struct StableHashingContext<'a, 'tcx: 'a> {
tcx: ty::TyCtxt<'a, 'tcx, 'tcx>,
- def_path_hashes: DefPathHashes<'a, 'tcx>,
codemap: CachingCodemapView<'tcx>,
hash_spans: bool,
hash_bodies: bool,
StableHashingContext {
tcx: tcx,
- def_path_hashes: DefPathHashes::new(tcx),
codemap: CachingCodemapView::new(tcx),
hash_spans: hash_spans_initial,
hash_bodies: true,
}
#[inline]
- pub fn def_path_hash(&mut self, def_id: DefId) -> u64 {
- self.def_path_hashes.hash(def_id)
+ pub fn def_path_hash(&mut self, def_id: DefId) -> ich::Fingerprint {
+ self.tcx.def_path_hash(def_id)
}
#[inline]
}
}
}
+
+pub fn hash_stable_hashmap<'a, 'tcx, K, V, R, SK, F, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
+ hasher: &mut StableHasher<W>,
+ map: &HashMap<K, V, R>,
+ extract_stable_key: F)
+ where K: Eq + std_hash::Hash,
+ V: HashStable<StableHashingContext<'a, 'tcx>>,
+ R: std_hash::BuildHasher,
+ SK: HashStable<StableHashingContext<'a, 'tcx>> + Ord + Clone,
+ F: Fn(&mut StableHashingContext<'a, 'tcx>, &K) -> SK,
+ W: StableHasherResult,
+{
+ let mut keys: Vec<_> = map.keys()
+ .map(|k| (extract_stable_key(hcx, k), k))
+ .collect();
+ keys.sort_unstable_by_key(|&(ref stable_key, _)| stable_key.clone());
+ keys.len().hash_stable(hcx, hasher);
+ for (stable_key, key) in keys {
+ stable_key.hash_stable(hcx, hasher);
+ map[key].hash_stable(hcx, hasher);
+ }
+}
+
+pub fn hash_stable_hashset<'a, 'tcx, K, R, SK, F, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
+ hasher: &mut StableHasher<W>,
+ set: &HashSet<K, R>,
+ extract_stable_key: F)
+ where K: Eq + std_hash::Hash,
+ R: std_hash::BuildHasher,
+ SK: HashStable<StableHashingContext<'a, 'tcx>> + Ord + Clone,
+ F: Fn(&mut StableHashingContext<'a, 'tcx>, &K) -> SK,
+ W: StableHasherResult,
+{
+ let mut keys: Vec<_> = set.iter()
+ .map(|k| extract_stable_key(hcx, k))
+ .collect();
+ keys.sort_unstable();
+ keys.hash_stable(hcx, hasher);
+}
+
+pub fn hash_stable_nodemap<'a, 'tcx, V, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
+ hasher: &mut StableHasher<W>,
+ map: &NodeMap<V>)
+ where V: HashStable<StableHashingContext<'a, 'tcx>>,
+ W: StableHasherResult,
+{
+ hash_stable_hashmap(hcx, hasher, map, |hcx, node_id| {
+ hcx.tcx.hir.definitions().node_to_hir_id(*node_id).local_id
+ });
+}
+
+
+pub fn hash_stable_btreemap<'a, 'tcx, K, V, SK, F, W>(hcx: &mut StableHashingContext<'a, 'tcx>,
+ hasher: &mut StableHasher<W>,
+ map: &BTreeMap<K, V>,
+ extract_stable_key: F)
+ where K: Eq + Ord,
+ V: HashStable<StableHashingContext<'a, 'tcx>>,
+ SK: HashStable<StableHashingContext<'a, 'tcx>> + Ord + Clone,
+ F: Fn(&mut StableHashingContext<'a, 'tcx>, &K) -> SK,
+ W: StableHasherResult,
+{
+ let mut keys: Vec<_> = map.keys()
+ .map(|k| (extract_stable_key(hcx, k), k))
+ .collect();
+ keys.sort_unstable_by_key(|&(ref stable_key, _)| stable_key.clone());
+ keys.len().hash_stable(hcx, hasher);
+ for (stable_key, key) in keys {
+ stable_key.hash_stable(hcx, hasher);
+ map[key].hash_stable(hcx, hasher);
+ }
+}