diff --git a/src/librustc/hir/map/definitions.rs b/src/librustc/hir/map/definitions.rs index ad3e6eb80e9..e3425d7fa61 100644 --- a/src/librustc/hir/map/definitions.rs +++ b/src/librustc/hir/map/definitions.rs @@ -13,6 +13,7 @@ use hir::map::def_collector::DefCollector; use rustc_data_structures::fnv::FnvHashMap; use std::fmt::Write; +use std::hash::{Hash, Hasher, SipHasher}; use syntax::{ast, visit}; use syntax::parse::token::InternedString; use ty::TyCtxt; @@ -133,6 +134,18 @@ pub fn to_string(&self, tcx: TyCtxt) -> String { s } + + pub fn deterministic_hash(&self, tcx: TyCtxt) -> u64 { + let mut state = SipHasher::new(); + self.deterministic_hash_to(tcx, &mut state); + state.finish() + } + + pub fn deterministic_hash_to(&self, tcx: TyCtxt, state: &mut H) { + tcx.crate_name(self.krate).hash(state); + tcx.crate_disambiguator(self.krate).hash(state); + self.data.hash(state); + } } /// Root of an inlined item. We track the `DefPath` of the item within diff --git a/src/librustc_incremental/calculate_svh.rs b/src/librustc_incremental/calculate_svh.rs index 6ab429ffe00..4b2d42ca889 100644 --- a/src/librustc_incremental/calculate_svh.rs +++ b/src/librustc_incremental/calculate_svh.rs @@ -144,7 +144,7 @@ pub fn new(st: &'a mut SipHasher, } fn hash_def_path(&mut self, path: &DefPath) { - path.to_string(self.tcx).hash(self.st); + path.deterministic_hash_to(self.tcx, self.st); } }