diff options
Diffstat (limited to 'compiler/rustc_query_system/src/query/caches.rs')
-rw-r--r-- | compiler/rustc_query_system/src/query/caches.rs | 35 |
1 files changed, 11 insertions, 24 deletions
diff --git a/compiler/rustc_query_system/src/query/caches.rs b/compiler/rustc_query_system/src/query/caches.rs index 4b3cd16c2..29f6a07e8 100644 --- a/compiler/rustc_query_system/src/query/caches.rs +++ b/compiler/rustc_query_system/src/query/caches.rs @@ -16,17 +16,11 @@ pub trait CacheSelector<'tcx, V> { V: Copy; } -pub trait QueryStorage { - type Value: Copy; -} - -pub trait QueryCache: QueryStorage + Sized { +pub trait QueryCache: Sized { type Key: Hash + Eq + Copy + Debug; + type Value: Copy; /// Checks if the query is already computed and in the cache. - /// It returns the shard index and a lock guard to the shard, - /// which will be used if the query is not in the cache and we need - /// to compute it. fn lookup(&self, key: &Self::Key) -> Option<(Self::Value, DepNodeIndex)>; fn complete(&self, key: Self::Key, value: Self::Value, index: DepNodeIndex); @@ -55,16 +49,13 @@ impl<K, V> Default for DefaultCache<K, V> { } } -impl<K: Eq + Hash, V: Copy + Debug> QueryStorage for DefaultCache<K, V> { - type Value = V; -} - impl<K, V> QueryCache for DefaultCache<K, V> where K: Eq + Hash + Copy + Debug, - V: Copy + Debug, + V: Copy, { type Key = K; + type Value = V; #[inline(always)] fn lookup(&self, key: &K) -> Option<(V, DepNodeIndex)> { @@ -127,15 +118,12 @@ impl<V> Default for SingleCache<V> { } } -impl<V: Copy + Debug> QueryStorage for SingleCache<V> { - type Value = V; -} - impl<V> QueryCache for SingleCache<V> where - V: Copy + Debug, + V: Copy, { type Key = (); + type Value = V; #[inline(always)] fn lookup(&self, _key: &()) -> Option<(V, DepNodeIndex)> { @@ -148,7 +136,9 @@ where } fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) { - self.cache.lock().as_ref().map(|value| f(&(), &value.0, value.1)); + if let Some(value) = self.cache.lock().as_ref() { + f(&(), &value.0, value.1) + } } } @@ -173,16 +163,13 @@ impl<K: Idx, V> Default for VecCache<K, V> { } } -impl<K: Eq + Idx, V: Copy + Debug> QueryStorage for VecCache<K, V> { - type Value = V; -} - impl<K, V> QueryCache for VecCache<K, V> where K: Eq + Idx + Copy + Debug, - V: Copy + Debug, + V: Copy, { type Key = K; + type Value = V; #[inline(always)] fn lookup(&self, key: &K) -> Option<(V, DepNodeIndex)> { |