11use crate :: dep_graph:: DepNodeIndex ;
22use crate :: query:: plumbing:: { QueryLookup , QueryState } ;
3- use crate :: query:: QueryContext ;
43
54use rustc_arena:: TypedArena ;
65use rustc_data_structures:: fx:: FxHashMap ;
76use rustc_data_structures:: sharded:: Sharded ;
87use rustc_data_structures:: sync:: WorkerLocal ;
98use std:: default:: Default ;
9+ use std:: fmt:: Debug ;
1010use std:: hash:: Hash ;
1111use std:: marker:: PhantomData ;
1212
@@ -24,24 +24,24 @@ pub trait QueryStorage: Default {
2424}
2525
2626pub trait QueryCache : QueryStorage {
27- type Key : Hash ;
27+ type Key : Hash + Eq + Clone + Debug ;
2828 type Sharded : Default ;
2929
3030 /// Checks if the query is already computed and in the cache.
3131 /// It returns the shard index and a lock guard to the shard,
3232 /// which will be used if the query is not in the cache and we need
3333 /// to compute it.
34- fn lookup < CTX : QueryContext , R , OnHit , OnMiss > (
34+ fn lookup < D , Q , R , OnHit , OnMiss > (
3535 & self ,
36- state : & QueryState < CTX , Self > ,
36+ state : & QueryState < D , Q , Self > ,
3737 key : Self :: Key ,
3838 // `on_hit` can be called while holding a lock to the query state shard.
3939 on_hit : OnHit ,
4040 on_miss : OnMiss ,
4141 ) -> R
4242 where
4343 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 ;
4545
4646 fn complete (
4747 & self ,
@@ -86,21 +86,25 @@ impl<K: Eq + Hash, V: Clone> QueryStorage for DefaultCache<K, V> {
8686 }
8787}
8888
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+ {
9094 type Key = K ;
9195 type Sharded = FxHashMap < K , ( V , DepNodeIndex ) > ;
9296
9397 #[ inline( always) ]
94- fn lookup < CTX : QueryContext , R , OnHit , OnMiss > (
98+ fn lookup < D , Q , R , OnHit , OnMiss > (
9599 & self ,
96- state : & QueryState < CTX , Self > ,
100+ state : & QueryState < D , Q , Self > ,
97101 key : K ,
98102 on_hit : OnHit ,
99103 on_miss : OnMiss ,
100104 ) -> R
101105 where
102106 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 ,
104108 {
105109 let mut lookup = state. get_lookup ( & key) ;
106110 let lock = & mut * lookup. lock ;
@@ -164,21 +168,24 @@ impl<'tcx, K: Eq + Hash, V: 'tcx> QueryStorage for ArenaCache<'tcx, K, V> {
164168 }
165169}
166170
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+ {
168175 type Key = K ;
169176 type Sharded = FxHashMap < K , & ' tcx ( V , DepNodeIndex ) > ;
170177
171178 #[ inline( always) ]
172- fn lookup < CTX : QueryContext , R , OnHit , OnMiss > (
179+ fn lookup < D , Q , R , OnHit , OnMiss > (
173180 & self ,
174- state : & QueryState < CTX , Self > ,
181+ state : & QueryState < D , Q , Self > ,
175182 key : K ,
176183 on_hit : OnHit ,
177184 on_miss : OnMiss ,
178185 ) -> R
179186 where
180187 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 ,
182189 {
183190 let mut lookup = state. get_lookup ( & key) ;
184191 let lock = & mut * lookup. lock ;
0 commit comments