@@ -16,13 +16,13 @@ use std::marker::PhantomData;
16
16
pub trait CacheSelector < ' tcx , V > {
17
17
type Cache
18
18
where
19
- V : Clone ;
19
+ V : Copy ;
20
20
type ArenaCache ;
21
21
}
22
22
23
23
pub trait QueryStorage {
24
24
type Value : Debug ;
25
- type Stored : Clone ;
25
+ type Stored : Copy ;
26
26
27
27
/// Store a value without putting it in the cache.
28
28
/// This is meant to be used with cycle errors.
@@ -36,14 +36,7 @@ pub trait QueryCache: QueryStorage + Sized {
36
36
/// It returns the shard index and a lock guard to the shard,
37
37
/// which will be used if the query is not in the cache and we need
38
38
/// 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 ) > ;
47
40
48
41
fn complete ( & self , key : Self :: Key , value : Self :: Value , index : DepNodeIndex ) -> Self :: Stored ;
49
42
@@ -55,7 +48,7 @@ pub struct DefaultCacheSelector<K>(PhantomData<K>);
55
48
impl < ' tcx , K : Eq + Hash , V : ' tcx > CacheSelector < ' tcx , V > for DefaultCacheSelector < K > {
56
49
type Cache = DefaultCache < K , V >
57
50
where
58
- V : Clone ;
51
+ V : Copy ;
59
52
type ArenaCache = ArenaCache < ' tcx , K , V > ;
60
53
}
61
54
@@ -72,7 +65,7 @@ impl<K, V> Default for DefaultCache<K, V> {
72
65
}
73
66
}
74
67
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 > {
76
69
type Value = V ;
77
70
type Stored = V ;
78
71
@@ -86,28 +79,20 @@ impl<K: Eq + Hash, V: Clone + Debug> QueryStorage for DefaultCache<K, V> {
86
79
impl < K , V > QueryCache for DefaultCache < K , V >
87
80
where
88
81
K : Eq + Hash + Clone + Debug ,
89
- V : Clone + Debug ,
82
+ V : Copy + Debug ,
90
83
{
91
84
type Key = K ;
92
85
93
86
#[ 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 ) > {
98
88
let key_hash = sharded:: make_hash ( key) ;
99
89
#[ cfg( parallel_compiler) ]
100
90
let lock = self . cache . get_shard_by_hash ( key_hash) . lock ( ) ;
101
91
#[ cfg( not( parallel_compiler) ) ]
102
92
let lock = self . cache . lock ( ) ;
103
93
let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
104
94
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 }
111
96
}
112
97
113
98
#[ inline]
@@ -176,23 +161,15 @@ where
176
161
type Key = K ;
177
162
178
163
#[ 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 ) > {
183
165
let key_hash = sharded:: make_hash ( key) ;
184
166
#[ cfg( parallel_compiler) ]
185
167
let lock = self . cache . get_shard_by_hash ( key_hash) . lock ( ) ;
186
168
#[ cfg( not( parallel_compiler) ) ]
187
169
let lock = self . cache . lock ( ) ;
188
170
let result = lock. raw_entry ( ) . from_key_hashed_nocheck ( key_hash, key) ;
189
171
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 }
196
173
}
197
174
198
175
#[ inline]
@@ -234,7 +211,7 @@ pub struct VecCacheSelector<K>(PhantomData<K>);
234
211
impl < ' tcx , K : Idx , V : ' tcx > CacheSelector < ' tcx , V > for VecCacheSelector < K > {
235
212
type Cache = VecCache < K , V >
236
213
where
237
- V : Clone ;
214
+ V : Copy ;
238
215
type ArenaCache = VecArenaCache < ' tcx , K , V > ;
239
216
}
240
217
@@ -251,7 +228,7 @@ impl<K: Idx, V> Default for VecCache<K, V> {
251
228
}
252
229
}
253
230
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 > {
255
232
type Value = V ;
256
233
type Stored = V ;
257
234
@@ -265,25 +242,17 @@ impl<K: Eq + Idx, V: Clone + Debug> QueryStorage for VecCache<K, V> {
265
242
impl < K , V > QueryCache for VecCache < K , V >
266
243
where
267
244
K : Eq + Idx + Clone + Debug ,
268
- V : Clone + Debug ,
245
+ V : Copy + Debug ,
269
246
{
270
247
type Key = K ;
271
248
272
249
#[ 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 ) > {
277
251
#[ cfg( parallel_compiler) ]
278
252
let lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
279
253
#[ cfg( not( parallel_compiler) ) ]
280
254
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 }
287
256
}
288
257
289
258
#[ inline]
@@ -357,20 +326,12 @@ where
357
326
type Key = K ;
358
327
359
328
#[ 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 ) > {
364
330
#[ cfg( parallel_compiler) ]
365
331
let lock = self . cache . get_shard_by_hash ( key. index ( ) as u64 ) . lock ( ) ;
366
332
#[ cfg( not( parallel_compiler) ) ]
367
333
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 }
374
335
}
375
336
376
337
#[ inline]
0 commit comments