@@ -16,13 +16,13 @@ use std::marker::PhantomData;
1616pub trait CacheSelector < ' tcx , V > {
1717 type Cache
1818 where
19- V : Clone ;
19+ V : Copy ;
2020 type ArenaCache ;
2121}
2222
2323pub trait QueryStorage {
2424 type Value : Debug ;
25- type Stored : Clone ;
25+ type Stored : Copy ;
2626
2727 /// Store a value without putting it in the cache.
2828 /// This is meant to be used with cycle errors.
@@ -36,14 +36,7 @@ pub trait QueryCache: QueryStorage + Sized {
3636 /// It returns the shard index and a lock guard to the shard,
3737 /// which will be used if the query is not in the cache and we need
3838 /// to compute it.
39- fn lookup < R , OnHit > (
40- & self ,
41- key : & Self :: Key ,
42- // `on_hit` can be called while holding a lock to the query state shard.
43- on_hit : OnHit ,
44- ) -> Result < R , ( ) >
45- where
46- OnHit : FnOnce ( & Self :: Stored , DepNodeIndex ) -> R ;
39+ fn lookup ( & self , key : & Self :: Key ) -> Option < ( Self :: Stored , DepNodeIndex ) > ;
4740
4841 fn complete ( & self , key : Self :: Key , value : Self :: Value , index : DepNodeIndex ) -> Self :: Stored ;
4942
@@ -55,7 +48,7 @@ pub struct DefaultCacheSelector<K>(PhantomData<K>);
5548impl < ' tcx , K : Eq + Hash , V : ' tcx > CacheSelector < ' tcx , V > for DefaultCacheSelector < K > {
5649 type Cache = DefaultCache < K , V >
5750 where
58- V : Clone ;
51+ V : Copy ;
5952 type ArenaCache = ArenaCache < ' tcx , K , V > ;
6053}
6154
@@ -72,7 +65,7 @@ impl<K, V> Default for DefaultCache<K, V> {
7265 }
7366}
7467
75- impl < K : Eq + Hash , V : Clone + Debug > QueryStorage for DefaultCache < K , V > {
68+ impl < K : Eq + Hash , V : Copy + Debug > QueryStorage for DefaultCache < K , V > {
7669 type Value = V ;
7770 type Stored = V ;
7871
@@ -86,28 +79,20 @@ impl<K: Eq + Hash, V: Clone + Debug> QueryStorage for DefaultCache<K, V> {
8679impl < K , V > QueryCache for DefaultCache < K , V >
8780where
8881 K : Eq + Hash + Clone + Debug ,
89- V : Clone + Debug ,
82+ V : Copy + Debug ,
9083{
9184 type Key = K ;
9285
9386 #[ inline( always) ]
94- fn lookup < R , OnHit > ( & self , key : & K , on_hit : OnHit ) -> Result < R , ( ) >
95- where
96- OnHit : FnOnce ( & V , DepNodeIndex ) -> R ,
97- {
87+ fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
9888 let key_hash = sharded:: make_hash ( key) ;
9989 #[ cfg( parallel_compiler) ]
10090 let lock = self . cache . get_shard_by_hash ( key_hash) . lock ( ) ;
10191 #[ cfg( not( parallel_compiler) ) ]
10292 let lock = self . cache . lock ( ) ;
10393 let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
10494
105- if let Some ( ( _, value) ) = result {
106- let hit_result = on_hit ( & value. 0 , value. 1 ) ;
107- Ok ( hit_result)
108- } else {
109- Err ( ( ) )
110- }
95+ if let Some ( ( _, value) ) = result { Some ( * value) } else { None }
11196 }
11297
11398 #[ inline]
@@ -176,23 +161,15 @@ where
176161 type Key = K ;
177162
178163 #[ inline( always) ]
179- fn lookup < R , OnHit > ( & self , key : & K , on_hit : OnHit ) -> Result < R , ( ) >
180- where
181- OnHit : FnOnce ( & & ' tcx V , DepNodeIndex ) -> R ,
182- {
164+ fn lookup ( & self , key : & K ) -> Option < ( & ' tcx V , DepNodeIndex ) > {
183165 let key_hash = sharded:: make_hash ( key) ;
184166 #[ cfg( parallel_compiler) ]
185167 let lock = self . cache . get_shard_by_hash ( key_hash) . lock ( ) ;
186168 #[ cfg( not( parallel_compiler) ) ]
187169 let lock = self . cache . lock ( ) ;
188170 let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
189171
190- if let Some ( ( _, value) ) = result {
191- let hit_result = on_hit ( & & value. 0 , value. 1 ) ;
192- Ok ( hit_result)
193- } else {
194- Err ( ( ) )
195- }
172+ if let Some ( ( _, value) ) = result { Some ( ( & value. 0 , value. 1 ) ) } else { None }
196173 }
197174
198175 #[ inline]
@@ -234,7 +211,7 @@ pub struct VecCacheSelector<K>(PhantomData<K>);
234211impl < ' tcx , K : Idx , V : ' tcx > CacheSelector < ' tcx , V > for VecCacheSelector < K > {
235212 type Cache = VecCache < K , V >
236213 where
237- V : Clone ;
214+ V : Copy ;
238215 type ArenaCache = VecArenaCache < ' tcx , K , V > ;
239216}
240217
@@ -251,7 +228,7 @@ impl<K: Idx, V> Default for VecCache<K, V> {
251228 }
252229}
253230
254- impl < K : Eq + Idx , V : Clone + Debug > QueryStorage for VecCache < K , V > {
231+ impl < K : Eq + Idx , V : Copy + Debug > QueryStorage for VecCache < K , V > {
255232 type Value = V ;
256233 type Stored = V ;
257234
@@ -265,25 +242,17 @@ impl<K: Eq + Idx, V: Clone + Debug> QueryStorage for VecCache<K, V> {
265242impl < K , V > QueryCache for VecCache < K , V >
266243where
267244 K : Eq + Idx + Clone + Debug ,
268- V : Clone + Debug ,
245+ V : Copy + Debug ,
269246{
270247 type Key = K ;
271248
272249 #[ inline( always) ]
273- fn lookup < R , OnHit > ( & self , key : & K , on_hit : OnHit ) -> Result < R , ( ) >
274- where
275- OnHit : FnOnce ( & V , DepNodeIndex ) -> R ,
276- {
250+ fn lookup ( & self , key : & K ) -> Option < ( V , DepNodeIndex ) > {
277251 #[ cfg( parallel_compiler) ]
278252 let lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
279253 #[ cfg( not( parallel_compiler) ) ]
280254 let lock = self . cache . lock ( ) ;
281- if let Some ( Some ( value) ) = lock. get ( * key) {
282- let hit_result = on_hit ( & value. 0 , value. 1 ) ;
283- Ok ( hit_result)
284- } else {
285- Err ( ( ) )
286- }
255+ if let Some ( Some ( value) ) = lock. get ( * key) { Some ( * value) } else { None }
287256 }
288257
289258 #[ inline]
@@ -357,20 +326,12 @@ where
357326 type Key = K ;
358327
359328 #[ inline( always) ]
360- fn lookup < R , OnHit > ( & self , key : & K , on_hit : OnHit ) -> Result < R , ( ) >
361- where
362- OnHit : FnOnce ( & & ' tcx V , DepNodeIndex ) -> R ,
363- {
329+ fn lookup ( & self , key : & K ) -> Option < ( & ' tcx V , DepNodeIndex ) > {
364330 #[ cfg( parallel_compiler) ]
365331 let lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
366332 #[ cfg( not( parallel_compiler) ) ]
367333 let lock = self . cache . lock ( ) ;
368- if let Some ( Some ( value) ) = lock. get ( * key) {
369- let hit_result = on_hit ( & & value. 0 , value. 1 ) ;
370- Ok ( hit_result)
371- } else {
372- Err ( ( ) )
373- }
334+ if let Some ( Some ( value) ) = lock. get ( * key) { Some ( ( & value. 0 , value. 1 ) ) } else { None }
374335 }
375336
376337 #[ inline]
0 commit comments