|
4 | 4 | use crate::middle::region;
|
5 | 5 | use crate::mir;
|
6 | 6 | use crate::ty;
|
| 7 | +use crate::ty::fast_reject; |
7 | 8 | use rustc_crate::ich::StableHashingContext;
|
8 | 9 | use rustc_data_structures::fingerprint::Fingerprint;
|
9 | 10 | use rustc_data_structures::fx::FxHashMap;
|
10 | 11 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
|
| 12 | +use rustc_span::def_id::DefId; |
| 13 | +use smallvec::SmallVec; |
11 | 14 | use std::cell::RefCell;
|
12 | 15 | use std::mem;
|
13 | 16 |
|
| 17 | +pub fn hash_stable_trait_impls<'a>( |
| 18 | + hcx: &mut StableHashingContext<'a>, |
| 19 | + hasher: &mut StableHasher, |
| 20 | + blanket_impls: &[DefId], |
| 21 | + non_blanket_impls: &FxHashMap<fast_reject::SimplifiedType, Vec<DefId>>, |
| 22 | +) { |
| 23 | + { |
| 24 | + let mut blanket_impls: SmallVec<[_; 8]> = |
| 25 | + blanket_impls.iter().map(|&def_id| hcx.def_path_hash(def_id)).collect(); |
| 26 | + |
| 27 | + if blanket_impls.len() > 1 { |
| 28 | + blanket_impls.sort_unstable(); |
| 29 | + } |
| 30 | + |
| 31 | + blanket_impls.hash_stable(hcx, hasher); |
| 32 | + } |
| 33 | + |
| 34 | + { |
| 35 | + let mut keys: SmallVec<[_; 8]> = |
| 36 | + non_blanket_impls.keys().map(|k| (k, k.map_def(|d| hcx.def_path_hash(d)))).collect(); |
| 37 | + keys.sort_unstable_by(|&(_, ref k1), &(_, ref k2)| k1.cmp(k2)); |
| 38 | + keys.len().hash_stable(hcx, hasher); |
| 39 | + for (key, ref stable_key) in keys { |
| 40 | + stable_key.hash_stable(hcx, hasher); |
| 41 | + let mut impls: SmallVec<[_; 8]> = |
| 42 | + non_blanket_impls[key].iter().map(|&impl_id| hcx.def_path_hash(impl_id)).collect(); |
| 43 | + |
| 44 | + if impls.len() > 1 { |
| 45 | + impls.sort_unstable(); |
| 46 | + } |
| 47 | + |
| 48 | + impls.hash_stable(hcx, hasher); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
| 52 | + |
14 | 53 | impl<'a, 'tcx, T> HashStable<StableHashingContext<'a>> for &'tcx ty::List<T>
|
15 | 54 | where
|
16 | 55 | T: HashStable<StableHashingContext<'a>>,
|
|
0 commit comments