diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2016-08-05 20:12:20 -0400 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2016-08-09 08:26:06 -0400 |
| commit | 8150494ac24f430f986cdb093c4018a7c2bff7fd (patch) | |
| tree | 3a502a6a10566cbdd7061080802ba17baaa78abb | |
| parent | d4bd0544ca1bf928f63ef3beb54687d853f24e1f (diff) | |
| download | rust-8150494ac24f430f986cdb093c4018a7c2bff7fd.tar.gz rust-8150494ac24f430f986cdb093c4018a7c2bff7fd.zip | |
add a `deterministic_hash` method to `DefPath`
Produces a deterministic hash, at least for a single platform / compiler-version.
| -rw-r--r-- | src/librustc/hir/map/definitions.rs | 13 | ||||
| -rw-r--r-- | src/librustc_incremental/calculate_svh.rs | 2 |
2 files changed, 14 insertions, 1 deletions
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::def_id::{DefId, DefIndex}; 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 @@ impl DefPath { 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<H: Hasher>(&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 @@ mod svh_visitor { } fn hash_def_path(&mut self, path: &DefPath) { - path.to_string(self.tcx).hash(self.st); + path.deterministic_hash_to(self.tcx, self.st); } } |
