|
1 | 1 | use crate::dep_graph::DepNodeIndex;
|
2 |
| -use crate::query::plumbing::{QueryLookup, QueryState}; |
| 2 | +use crate::query::plumbing::{QueryCacheStore, QueryLookup}; |
3 | 3 |
|
4 | 4 | use rustc_arena::TypedArena;
|
5 | 5 | use rustc_data_structures::fx::FxHashMap;
|
@@ -31,17 +31,15 @@ pub trait QueryCache: QueryStorage {
|
31 | 31 | /// It returns the shard index and a lock guard to the shard,
|
32 | 32 | /// which will be used if the query is not in the cache and we need
|
33 | 33 | /// to compute it.
|
34 |
| - fn lookup<D, Q, R, OnHit, OnMiss>( |
| 34 | + fn lookup<'s, R, OnHit>( |
35 | 35 | &self,
|
36 |
| - state: &QueryState<D, Q, Self>, |
37 |
| - key: Self::Key, |
| 36 | + state: &'s QueryCacheStore<Self>, |
| 37 | + key: &Self::Key, |
38 | 38 | // `on_hit` can be called while holding a lock to the query state shard.
|
39 | 39 | on_hit: OnHit,
|
40 |
| - on_miss: OnMiss, |
41 |
| - ) -> R |
| 40 | + ) -> Result<R, QueryLookup> |
42 | 41 | where
|
43 |
| - OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R, |
44 |
| - OnMiss: FnOnce(Self::Key, QueryLookup<'_, D, Q, Self::Key, Self::Sharded>) -> R; |
| 42 | + OnHit: FnOnce(&Self::Stored, DepNodeIndex) -> R; |
45 | 43 |
|
46 | 44 | fn complete(
|
47 | 45 | &self,
|
@@ -95,23 +93,24 @@ where
|
95 | 93 | type Sharded = FxHashMap<K, (V, DepNodeIndex)>;
|
96 | 94 |
|
97 | 95 | #[inline(always)]
|
98 |
| - fn lookup<D, Q, R, OnHit, OnMiss>( |
| 96 | + fn lookup<'s, R, OnHit>( |
99 | 97 | &self,
|
100 |
| - state: &QueryState<D, Q, Self>, |
101 |
| - key: K, |
| 98 | + state: &'s QueryCacheStore<Self>, |
| 99 | + key: &K, |
102 | 100 | on_hit: OnHit,
|
103 |
| - on_miss: OnMiss, |
104 |
| - ) -> R |
| 101 | + ) -> Result<R, QueryLookup> |
105 | 102 | where
|
106 | 103 | OnHit: FnOnce(&V, DepNodeIndex) -> R,
|
107 |
| - OnMiss: FnOnce(K, QueryLookup<'_, D, Q, K, Self::Sharded>) -> R, |
108 | 104 | {
|
109 |
| - let mut lookup = state.get_lookup(&key); |
110 |
| - let lock = &mut *lookup.lock; |
| 105 | + let (lookup, lock) = state.get_lookup(key); |
| 106 | + let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key); |
111 | 107 |
|
112 |
| - let result = lock.cache.raw_entry().from_key_hashed_nocheck(lookup.key_hash, &key); |
113 |
| - |
114 |
| - if let Some((_, value)) = result { on_hit(&value.0, value.1) } else { on_miss(key, lookup) } |
| 108 | + if let Some((_, value)) = result { |
| 109 | + let hit_result = on_hit(&value.0, value.1); |
| 110 | + Ok(hit_result) |
| 111 | + } else { |
| 112 | + Err(lookup) |
| 113 | + } |
115 | 114 | }
|
116 | 115 |
|
117 | 116 | #[inline]
|
@@ -177,26 +176,23 @@ where
|
177 | 176 | type Sharded = FxHashMap<K, &'tcx (V, DepNodeIndex)>;
|
178 | 177 |
|
179 | 178 | #[inline(always)]
|
180 |
| - fn lookup<D, Q, R, OnHit, OnMiss>( |
| 179 | + fn lookup<'s, R, OnHit>( |
181 | 180 | &self,
|
182 |
| - state: &QueryState<D, Q, Self>, |
183 |
| - key: K, |
| 181 | + state: &'s QueryCacheStore<Self>, |
| 182 | + key: &K, |
184 | 183 | on_hit: OnHit,
|
185 |
| - on_miss: OnMiss, |
186 |
| - ) -> R |
| 184 | + ) -> Result<R, QueryLookup> |
187 | 185 | where
|
188 | 186 | OnHit: FnOnce(&&'tcx V, DepNodeIndex) -> R,
|
189 |
| - OnMiss: FnOnce(K, QueryLookup<'_, D, Q, K, Self::Sharded>) -> R, |
190 | 187 | {
|
191 |
| - let mut lookup = state.get_lookup(&key); |
192 |
| - let lock = &mut *lookup.lock; |
193 |
| - |
194 |
| - let result = lock.cache.raw_entry().from_key_hashed_nocheck(lookup.key_hash, &key); |
| 188 | + let (lookup, lock) = state.get_lookup(key); |
| 189 | + let result = lock.raw_entry().from_key_hashed_nocheck(lookup.key_hash, key); |
195 | 190 |
|
196 | 191 | if let Some((_, value)) = result {
|
197 |
| - on_hit(&&value.0, value.1) |
| 192 | + let hit_result = on_hit(&&value.0, value.1); |
| 193 | + Ok(hit_result) |
198 | 194 | } else {
|
199 |
| - on_miss(key, lookup) |
| 195 | + Err(lookup) |
200 | 196 | }
|
201 | 197 | }
|
202 | 198 |
|
|
0 commit comments