1
1
use crate :: dep_graph:: DepNodeIndex ;
2
2
use crate :: query:: plumbing:: { QueryLookup , QueryState } ;
3
- use crate :: query:: QueryContext ;
4
3
5
4
use rustc_arena:: TypedArena ;
6
5
use rustc_data_structures:: fx:: FxHashMap ;
7
6
use rustc_data_structures:: sharded:: Sharded ;
8
7
use rustc_data_structures:: sync:: WorkerLocal ;
9
8
use std:: default:: Default ;
9
+ use std:: fmt:: Debug ;
10
10
use std:: hash:: Hash ;
11
11
use std:: marker:: PhantomData ;
12
12
@@ -24,24 +24,24 @@ pub trait QueryStorage: Default {
24
24
}
25
25
26
26
pub trait QueryCache : QueryStorage {
27
- type Key : Hash ;
27
+ type Key : Hash + Eq + Clone + Debug ;
28
28
type Sharded : Default ;
29
29
30
30
/// Checks if the query is already computed and in the cache.
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 < CTX : QueryContext , R , OnHit , OnMiss > (
34
+ fn lookup < D , Q , R , OnHit , OnMiss > (
35
35
& self ,
36
- state : & QueryState < CTX , Self > ,
36
+ state : & QueryState < D , Q , Self > ,
37
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
40
on_miss : OnMiss ,
41
41
) -> R
42
42
where
43
43
OnHit : FnOnce ( & Self :: Stored , DepNodeIndex ) -> R ,
44
- OnMiss : FnOnce ( Self :: Key , QueryLookup < ' _ , CTX , Self :: Key , Self :: Sharded > ) -> R ;
44
+ OnMiss : FnOnce ( Self :: Key , QueryLookup < ' _ , D , Q , Self :: Key , Self :: Sharded > ) -> R ;
45
45
46
46
fn complete (
47
47
& self ,
@@ -86,21 +86,25 @@ impl<K: Eq + Hash, V: Clone> QueryStorage for DefaultCache<K, V> {
86
86
}
87
87
}
88
88
89
- impl < K : Eq + Hash , V : Clone > QueryCache for DefaultCache < K , V > {
89
+ impl < K , V > QueryCache for DefaultCache < K , V >
90
+ where
91
+ K : Eq + Hash + Clone + Debug ,
92
+ V : Clone ,
93
+ {
90
94
type Key = K ;
91
95
type Sharded = FxHashMap < K , ( V , DepNodeIndex ) > ;
92
96
93
97
#[ inline( always) ]
94
- fn lookup < CTX : QueryContext , R , OnHit , OnMiss > (
98
+ fn lookup < D , Q , R , OnHit , OnMiss > (
95
99
& self ,
96
- state : & QueryState < CTX , Self > ,
100
+ state : & QueryState < D , Q , Self > ,
97
101
key : K ,
98
102
on_hit : OnHit ,
99
103
on_miss : OnMiss ,
100
104
) -> R
101
105
where
102
106
OnHit : FnOnce ( & V , DepNodeIndex ) -> R ,
103
- OnMiss : FnOnce ( K , QueryLookup < ' _ , CTX , K , Self :: Sharded > ) -> R ,
107
+ OnMiss : FnOnce ( K , QueryLookup < ' _ , D , Q , K , Self :: Sharded > ) -> R ,
104
108
{
105
109
let mut lookup = state. get_lookup ( & key) ;
106
110
let lock = & mut * lookup. lock ;
@@ -164,21 +168,24 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
164
168
}
165
169
}
166
170
167
- impl < ' tcx , K : Eq + Hash , V : ' tcx > QueryCache for ArenaCache < ' tcx , K , V > {
171
+ impl < ' tcx , K , V : ' tcx > QueryCache for ArenaCache < ' tcx , K , V >
172
+ where
173
+ K : Eq + Hash + Clone + Debug ,
174
+ {
168
175
type Key = K ;
169
176
type Sharded = FxHashMap < K , & ' tcx ( V , DepNodeIndex ) > ;
170
177
171
178
#[ inline( always) ]
172
- fn lookup < CTX : QueryContext , R , OnHit , OnMiss > (
179
+ fn lookup < D , Q , R , OnHit , OnMiss > (
173
180
& self ,
174
- state : & QueryState < CTX , Self > ,
181
+ state : & QueryState < D , Q , Self > ,
175
182
key : K ,
176
183
on_hit : OnHit ,
177
184
on_miss : OnMiss ,
178
185
) -> R
179
186
where
180
187
OnHit : FnOnce ( & & ' tcx V , DepNodeIndex ) -> R ,
181
- OnMiss : FnOnce ( K , QueryLookup < ' _ , CTX , K , Self :: Sharded > ) -> R ,
188
+ OnMiss : FnOnce ( K , QueryLookup < ' _ , D , Q , K , Self :: Sharded > ) -> R ,
182
189
{
183
190
let mut lookup = state. get_lookup ( & key) ;
184
191
let lock = & mut * lookup. lock ;
0 commit comments