diff options
| author | Camille Gillot <gillot.camille@gmail.com> | 2021-06-01 09:05:22 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-06-01 09:05:22 +0200 |
| commit | 0f0f3138cb80137b9277b29118c05dbff9a8915e (patch) | |
| tree | 4809ba7275fdf021453562db97dc0f0e9a5fd598 /compiler/rustc_data_structures/src | |
| parent | c9c1f8be3fda5b58520c579451d3f5e20736ec90 (diff) | |
Revert "Reduce the amount of untracked state in TyCtxt"
Diffstat (limited to 'compiler/rustc_data_structures/src')
| -rw-r--r-- | compiler/rustc_data_structures/src/stable_hasher.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/stable_hasher.rs b/compiler/rustc_data_structures/src/stable_hasher.rs index 18b352cf3b0..ff28784a1dc 100644 --- a/compiler/rustc_data_structures/src/stable_hasher.rs +++ b/compiler/rustc_data_structures/src/stable_hasher.rs @@ -550,3 +550,35 @@ pub fn hash_stable_hashmap<HCX, K, V, R, SK, F>( entries.sort_unstable_by(|&(ref sk1, _), &(ref sk2, _)| sk1.cmp(sk2)); entries.hash_stable(hcx, hasher); } + +/// A vector container that makes sure that its items are hashed in a stable +/// order. +#[derive(Debug)] +pub struct StableVec<T>(Vec<T>); + +impl<T> StableVec<T> { + pub fn new(v: Vec<T>) -> Self { + StableVec(v) + } +} + +impl<T> ::std::ops::Deref for StableVec<T> { + type Target = Vec<T>; + + fn deref(&self) -> &Vec<T> { + &self.0 + } +} + +impl<T, HCX> HashStable<HCX> for StableVec<T> +where + T: HashStable<HCX> + ToStableHashKey<HCX>, +{ + fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) { + let StableVec(ref v) = *self; + + let mut sorted: Vec<_> = v.iter().map(|x| x.to_stable_hash_key(hcx)).collect(); + sorted.sort_unstable(); + sorted.hash_stable(hcx, hasher); + } +} |
