diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-09-26 18:54:39 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-09-28 11:47:36 -0400 |
| commit | 14a5aefb01bb4f18749ab56cd9fd37bf93c86a37 (patch) | |
| tree | 01239699d8cb998460c98b985f52df26a9768398 /src/librustc_data_structures | |
| parent | f60e58e57580d47e82a374bad73214b6bfec085a (diff) | |
| download | rust-14a5aefb01bb4f18749ab56cd9fd37bf93c86a37.tar.gz rust-14a5aefb01bb4f18749ab56cd9fd37bf93c86a37.zip | |
Switch over all StableHash impls to new format
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/fingerprint.rs | 2 | ||||
| -rw-r--r-- | src/librustc_data_structures/stable_hasher.rs | 140 | ||||
| -rw-r--r-- | src/librustc_data_structures/svh.rs | 6 | ||||
| -rw-r--r-- | src/librustc_data_structures/thin_vec.rs | 6 | ||||
| -rw-r--r-- | src/librustc_data_structures/transitive_relation.rs | 14 |
5 files changed, 46 insertions, 122 deletions
diff --git a/src/librustc_data_structures/fingerprint.rs b/src/librustc_data_structures/fingerprint.rs index c8012bb9424..b43df6045d6 100644 --- a/src/librustc_data_structures/fingerprint.rs +++ b/src/librustc_data_structures/fingerprint.rs @@ -76,7 +76,7 @@ impl ::std::fmt::Display for Fingerprint { impl stable_hasher::StableHasherResult for Fingerprint { #[inline] - fn finish(hasher: stable_hasher::StableHasher<Self>) -> Self { + fn finish(hasher: stable_hasher::StableHasher) -> Self { let (_0, _1) = hasher.finalize(); Fingerprint(_0, _1) } diff --git a/src/librustc_data_structures/stable_hasher.rs b/src/librustc_data_structures/stable_hasher.rs index 7c54a092af0..53dff794ff0 100644 --- a/src/librustc_data_structures/stable_hasher.rs +++ b/src/librustc_data_structures/stable_hasher.rs @@ -1,5 +1,4 @@ use std::hash::{Hash, Hasher, BuildHasher}; -use std::marker::PhantomData; use std::mem; use smallvec::SmallVec; use crate::sip128::SipHasher128; @@ -24,7 +23,7 @@ impl ::std::fmt::Debug for StableHasher { } pub trait StableHasherResult: Sized { - fn finish(hasher: StableHasher<Self>) -> Self; + fn finish(hasher: StableHasher) -> Self; } impl StableHasher { @@ -40,14 +39,14 @@ impl StableHasher { } impl StableHasherResult for u128 { - fn finish(hasher: StableHasher<Self>) -> Self { + fn finish(hasher: StableHasher) -> Self { let (_0, _1) = hasher.finalize(); u128::from(_0) | (u128::from(_1) << 64) } } impl StableHasherResult for u64 { - fn finish(hasher: StableHasher<Self>) -> Self { + fn finish(hasher: StableHasher) -> Self { hasher.finalize().0 } } @@ -181,10 +180,10 @@ macro_rules! impl_stable_hash_via_hash { ($t:ty) => ( impl<CTX> $crate::stable_hasher::HashStable<CTX> for $t { #[inline] - fn hash_stable<W: $crate::stable_hasher::StableHasherResult>( + fn hash_stable( &self, _: &mut CTX, - hasher: &mut $crate::stable_hasher::StableHasher<W> + hasher: &mut $crate::stable_hasher::StableHasher ) { ::std::hash::Hash::hash(self, hasher); } @@ -211,17 +210,13 @@ impl_stable_hash_via_hash!(char); impl_stable_hash_via_hash!(()); impl<CTX> HashStable<CTX> for ::std::num::NonZeroU32 { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.get().hash_stable(ctx, hasher) } } impl<CTX> HashStable<CTX> for f32 { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let val: u32 = unsafe { ::std::mem::transmute(*self) }; @@ -230,9 +225,7 @@ impl<CTX> HashStable<CTX> for f32 { } impl<CTX> HashStable<CTX> for f64 { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let val: u64 = unsafe { ::std::mem::transmute(*self) }; @@ -241,26 +234,20 @@ impl<CTX> HashStable<CTX> for f64 { } impl<CTX> HashStable<CTX> for ::std::cmp::Ordering { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (*self as i8).hash_stable(ctx, hasher); } } impl<T1: HashStable<CTX>, CTX> HashStable<CTX> for (T1,) { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0,) = *self; _0.hash_stable(ctx, hasher); } } impl<T1: HashStable<CTX>, T2: HashStable<CTX>, CTX> HashStable<CTX> for (T1, T2) { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0, ref _1) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -272,9 +259,7 @@ impl<T1, T2, T3, CTX> HashStable<CTX> for (T1, T2, T3) T2: HashStable<CTX>, T3: HashStable<CTX>, { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -288,9 +273,7 @@ impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4) T3: HashStable<CTX>, T4: HashStable<CTX>, { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { let (ref _0, ref _1, ref _2, ref _3) = *self; _0.hash_stable(ctx, hasher); _1.hash_stable(ctx, hasher); @@ -300,9 +283,7 @@ impl<T1, T2, T3, T4, CTX> HashStable<CTX> for (T1, T2, T3, T4) } impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] { - default fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + default fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for item in self { item.hash_stable(ctx, hasher); @@ -312,9 +293,7 @@ impl<T: HashStable<CTX>, CTX> HashStable<CTX> for [T] { impl<T: HashStable<CTX>, CTX> HashStable<CTX> for Vec<T> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (&self[..]).hash_stable(ctx, hasher); } } @@ -325,9 +304,7 @@ impl<K, V, R, CTX> HashStable<CTX> for indexmap::IndexMap<K, V, R> R: BuildHasher, { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for kv in self { kv.hash_stable(ctx, hasher); @@ -340,9 +317,7 @@ impl<K, R, CTX> HashStable<CTX> for indexmap::IndexSet<K, R> R: BuildHasher, { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for key in self { key.hash_stable(ctx, hasher); @@ -352,45 +327,35 @@ impl<K, R, CTX> HashStable<CTX> for indexmap::IndexSet<K, R> impl<A, CTX> HashStable<CTX> for SmallVec<[A; 1]> where A: HashStable<CTX> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (&self[..]).hash_stable(ctx, hasher); } } impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for Box<T> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for ::std::rc::Rc<T> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl<T: ?Sized + HashStable<CTX>, CTX> HashStable<CTX> for ::std::sync::Arc<T> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl<CTX> HashStable<CTX> for str { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - _: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { self.len().hash(hasher); self.as_bytes().hash(hasher); } @@ -399,9 +364,7 @@ impl<CTX> HashStable<CTX> for str { impl<CTX> HashStable<CTX> for String { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (&self[..]).hash_stable(hcx, hasher); } } @@ -416,9 +379,7 @@ impl<HCX> ToStableHashKey<HCX> for String { impl<CTX> HashStable<CTX> for bool { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (if *self { 1u8 } else { 0u8 }).hash_stable(ctx, hasher); } } @@ -428,9 +389,7 @@ impl<T, CTX> HashStable<CTX> for Option<T> where T: HashStable<CTX> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { if let Some(ref value) = *self { 1u8.hash_stable(ctx, hasher); value.hash_stable(ctx, hasher); @@ -445,9 +404,7 @@ impl<T1, T2, CTX> HashStable<CTX> for Result<T1, T2> T2: HashStable<CTX>, { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { mem::discriminant(self).hash_stable(ctx, hasher); match *self { Ok(ref x) => x.hash_stable(ctx, hasher), @@ -460,18 +417,14 @@ impl<'a, T, CTX> HashStable<CTX> for &'a T where T: HashStable<CTX> + ?Sized { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(ctx, hasher); } } impl<T, CTX> HashStable<CTX> for ::std::mem::Discriminant<T> { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - _: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) { ::std::hash::Hash::hash(self, hasher); } } @@ -479,9 +432,7 @@ impl<T, CTX> HashStable<CTX> for ::std::mem::Discriminant<T> { impl<I: indexed_vec::Idx, T, CTX> HashStable<CTX> for indexed_vec::IndexVec<I, T> where T: HashStable<CTX>, { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.len().hash_stable(ctx, hasher); for v in &self.raw { v.hash_stable(ctx, hasher); @@ -492,9 +443,7 @@ impl<I: indexed_vec::Idx, T, CTX> HashStable<CTX> for indexed_vec::IndexVec<I, T impl<I: indexed_vec::Idx, CTX> HashStable<CTX> for bit_set::BitSet<I> { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.words().hash_stable(ctx, hasher); } } @@ -502,9 +451,7 @@ impl<I: indexed_vec::Idx, CTX> HashStable<CTX> for bit_set::BitSet<I> impl<R: indexed_vec::Idx, C: indexed_vec::Idx, CTX> HashStable<CTX> for bit_set::BitMatrix<R, C> { - fn hash_stable<W: StableHasherResult>(&self, - ctx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) { self.words().hash_stable(ctx, hasher); } } @@ -518,9 +465,7 @@ impl<K, V, R, HCX> HashStable<HCX> for ::std::collections::HashMap<K, V, R> R: BuildHasher, { #[inline] - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut HCX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { hash_stable_hashmap(hcx, hasher, self, ToStableHashKey::to_stable_hash_key); } } @@ -529,9 +474,7 @@ impl<K, R, HCX> HashStable<HCX> for ::std::collections::HashSet<K, R> where K: ToStableHashKey<HCX> + Eq + Hash, R: BuildHasher, { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut HCX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let mut keys: Vec<_> = self.iter() .map(|k| k.to_stable_hash_key(hcx)) .collect(); @@ -544,9 +487,7 @@ impl<K, V, HCX> HashStable<HCX> for ::std::collections::BTreeMap<K, V> where K: ToStableHashKey<HCX>, V: HashStable<HCX>, { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut HCX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let mut entries: Vec<_> = self.iter() .map(|(k, v)| (k.to_stable_hash_key(hcx), v)) .collect(); @@ -558,9 +499,7 @@ impl<K, V, HCX> HashStable<HCX> for ::std::collections::BTreeMap<K, V> impl<K, HCX> HashStable<HCX> for ::std::collections::BTreeSet<K> where K: ToStableHashKey<HCX>, { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut HCX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let mut keys: Vec<_> = self.iter() .map(|k| k.to_stable_hash_key(hcx)) .collect(); @@ -569,9 +508,9 @@ impl<K, HCX> HashStable<HCX> for ::std::collections::BTreeSet<K> } } -pub fn hash_stable_hashmap<HCX, K, V, R, SK, F, W>( +pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>( hcx: &mut HCX, - hasher: &mut StableHasher<W>, + hasher: &mut StableHasher, map: &::std::collections::HashMap<K, V, R>, to_stable_hash_key: F) where K: Eq + Hash, @@ -579,7 +518,6 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F, W>( R: BuildHasher, SK: HashStable<HCX> + Ord + Clone, F: Fn(&K, &HCX) -> SK, - W: StableHasherResult, { let mut entries: Vec<_> = map.iter() .map(|(k, v)| (to_stable_hash_key(k, hcx), v)) @@ -610,9 +548,7 @@ impl<T> ::std::ops::Deref for StableVec<T> { impl<T, HCX> HashStable<HCX> for StableVec<T> where T: HashStable<HCX> + ToStableHashKey<HCX> { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut HCX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { let StableVec(ref v) = *self; let mut sorted: Vec<_> = v.iter() diff --git a/src/librustc_data_structures/svh.rs b/src/librustc_data_structures/svh.rs index 3123c182b0f..64042264d79 100644 --- a/src/librustc_data_structures/svh.rs +++ b/src/librustc_data_structures/svh.rs @@ -61,11 +61,7 @@ impl Decodable for Svh { impl<T> stable_hasher::HashStable<T> for Svh { #[inline] - fn hash_stable<W: stable_hasher::StableHasherResult>( - &self, - ctx: &mut T, - hasher: &mut stable_hasher::StableHasher<W> - ) { + fn hash_stable(&self, ctx: &mut T, hasher: &mut stable_hasher::StableHasher) { let Svh { hash } = *self; diff --git a/src/librustc_data_structures/thin_vec.rs b/src/librustc_data_structures/thin_vec.rs index 6692903cd4f..93a8b7f525f 100644 --- a/src/librustc_data_structures/thin_vec.rs +++ b/src/librustc_data_structures/thin_vec.rs @@ -1,4 +1,4 @@ -use crate::stable_hasher::{StableHasher, StableHasherResult, HashStable}; +use crate::stable_hasher::{StableHasher, HashStable}; /// A vector type optimized for cases where this size is usually 0 (cf. `SmallVector`). /// The `Option<Box<..>>` wrapping allows us to represent a zero sized vector with `None`, @@ -60,9 +60,7 @@ impl<T> Extend<T> for ThinVec<T> { } impl<T: HashStable<CTX>, CTX> HashStable<CTX> for ThinVec<T> { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { (**self).hash_stable(hcx, hasher) } } diff --git a/src/librustc_data_structures/transitive_relation.rs b/src/librustc_data_structures/transitive_relation.rs index ffc964ddb5a..9c5447f3f5a 100644 --- a/src/librustc_data_structures/transitive_relation.rs +++ b/src/librustc_data_structures/transitive_relation.rs @@ -1,6 +1,6 @@ use crate::bit_set::BitMatrix; use crate::fx::FxHashMap; -use crate::stable_hasher::{HashStable, StableHasher, StableHasherResult}; +use crate::stable_hasher::{HashStable, StableHasher}; use crate::sync::Lock; use rustc_serialize::{Encodable, Encoder, Decodable, Decoder}; use std::fmt::Debug; @@ -442,9 +442,7 @@ impl<T> Decodable for TransitiveRelation<T> impl<CTX, T> HashStable<CTX> for TransitiveRelation<T> where T: HashStable<CTX> + Eq + Debug + Clone + Hash { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { // 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 { @@ -462,9 +460,7 @@ impl<CTX, T> HashStable<CTX> for TransitiveRelation<T> } impl<CTX> HashStable<CTX> for Edge { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { let Edge { ref source, ref target, @@ -476,9 +472,7 @@ impl<CTX> HashStable<CTX> for Edge { } impl<CTX> HashStable<CTX> for Index { - fn hash_stable<W: StableHasherResult>(&self, - hcx: &mut CTX, - hasher: &mut StableHasher<W>) { + fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { let Index(idx) = *self; idx.hash_stable(hcx, hasher); } |
