summary refs log tree commit diff
path: root/src/librustc_data_structures/transitive_relation.rs
diff options
context:
space:
mode:
authorMichael Woerister <michaelwoerister@posteo.net>2017-04-05 13:00:17 +0200
committerMichael Woerister <michaelwoerister@posteo.net>2017-04-12 11:42:15 +0200
commitbc7af816f3b8712efa4e6643f9cdeb1d5ba5c78a (patch)
tree0bbca767d33bb89337e1d5c58c58c788bebe0b32 /src/librustc_data_structures/transitive_relation.rs
parentc008cd70f5cb20cf22eb2cc9ae12f978296e8a45 (diff)
downloadrust-bc7af816f3b8712efa4e6643f9cdeb1d5ba5c78a.tar.gz
rust-bc7af816f3b8712efa4e6643f9cdeb1d5ba5c78a.zip
ICH: Hash everything that gets encoded into crate metadata.
Diffstat (limited to 'src/librustc_data_structures/transitive_relation.rs')
-rw-r--r--src/librustc_data_structures/transitive_relation.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs
index 2bce7faf08c..2631108aeb5 100644
--- a/src/librustc_data_structures/transitive_relation.rs
+++ b/src/librustc_data_structures/transitive_relation.rs
@@ -9,11 +9,14 @@
 // except according to those terms.
 
 use bitvec::BitMatrix;
+use stable_hasher::{HashStable, StableHasher, StableHasherResult};
 use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
 use std::cell::RefCell;
 use std::fmt::Debug;
 use std::mem;
 
+
+
 #[derive(Clone)]
 pub struct TransitiveRelation<T: Debug + PartialEq> {
     // List of elements. This is used to map from a T to a usize.  We
@@ -334,6 +337,49 @@ impl<T> Decodable for TransitiveRelation<T>
     }
 }
 
+impl<CTX, T> HashStable<CTX> for TransitiveRelation<T>
+    where T: HashStable<CTX> + PartialEq + Debug
+{
+    fn hash_stable<W: StableHasherResult>(&self,
+                                          hcx: &mut CTX,
+                                          hasher: &mut StableHasher<W>) {
+        // We are assuming here that the relation graph has been built in a
+        // deterministic way and we can just hash it the way it is.
+        let TransitiveRelation {
+            ref elements,
+            ref edges,
+            // "closure" is just a copy of the data above
+            closure: _
+        } = *self;
+
+        elements.hash_stable(hcx, hasher);
+        edges.hash_stable(hcx, hasher);
+    }
+}
+
+impl<CTX> HashStable<CTX> for Edge {
+    fn hash_stable<W: StableHasherResult>(&self,
+                                          hcx: &mut CTX,
+                                          hasher: &mut StableHasher<W>) {
+        let Edge {
+            ref source,
+            ref target,
+        } = *self;
+
+        source.hash_stable(hcx, hasher);
+        target.hash_stable(hcx, hasher);
+    }
+}
+
+impl<CTX> HashStable<CTX> for Index {
+    fn hash_stable<W: StableHasherResult>(&self,
+                                          hcx: &mut CTX,
+                                          hasher: &mut StableHasher<W>) {
+        let Index(idx) = *self;
+        idx.hash_stable(hcx, hasher);
+    }
+}
+
 #[test]
 fn test_one_step() {
     let mut relation = TransitiveRelation::new();