44
55use crate :: dep_graph:: { DepKind , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
66use crate :: ty:: query:: caches:: QueryCache ;
7- use crate :: ty:: query:: config:: { QueryAccessors , QueryConfig , QueryDescription } ;
7+ use crate :: ty:: query:: config:: { QueryAccessors , QueryDescription } ;
88use crate :: ty:: query:: job:: { QueryInfo , QueryJob , QueryJobId , QueryJobInfo , QueryShardJobId } ;
99use crate :: ty:: query:: Query ;
1010use crate :: ty:: tls;
@@ -49,22 +49,20 @@ impl<'tcx, K, C: Default> Default for QueryStateShard<'tcx, K, C> {
4949 }
5050}
5151
52- pub ( crate ) type QueryState < ' tcx , Q > = QueryStateImpl <
53- ' tcx ,
54- <Q as QueryConfig < ' tcx > >:: Key ,
55- <Q as QueryConfig < ' tcx > >:: Value ,
56- <Q as QueryAccessors < ' tcx > >:: Cache ,
57- > ;
52+ pub ( crate ) type QueryState < ' tcx , Q > = QueryStateImpl < ' tcx , <Q as QueryAccessors < ' tcx > >:: Cache > ;
5853
59- pub ( crate ) struct QueryStateImpl < ' tcx , K , V , C : QueryCache < K , V > > {
54+ pub ( crate ) struct QueryStateImpl < ' tcx , C : QueryCache > {
6055 pub ( super ) cache : C ,
61- pub ( super ) shards : Sharded < QueryStateShard < ' tcx , K , C :: Sharded > > ,
56+ pub ( super ) shards : Sharded < QueryStateShard < ' tcx , C :: Key , C :: Sharded > > ,
6257 #[ cfg( debug_assertions) ]
6358 pub ( super ) cache_hits : AtomicUsize ,
6459}
6560
66- impl < ' tcx , K , V , C : QueryCache < K , V > > QueryStateImpl < ' tcx , K , V , C > {
67- pub ( super ) fn get_lookup < K2 : Hash > ( & ' tcx self , key : & K2 ) -> QueryLookup < ' tcx , K , C :: Sharded > {
61+ impl < ' tcx , C : QueryCache > QueryStateImpl < ' tcx , C > {
62+ pub ( super ) fn get_lookup < K2 : Hash > (
63+ & ' tcx self ,
64+ key : & K2 ,
65+ ) -> QueryLookup < ' tcx , C :: Key , C :: Sharded > {
6866 // We compute the key's hash once and then use it for both the
6967 // shard lookup and the hashmap lookup. This relies on the fact
7068 // that both of them use `FxHasher`.
@@ -88,10 +86,12 @@ pub(super) enum QueryResult<'tcx> {
8886 Poisoned ,
8987}
9088
91- impl < ' tcx , K , V , C : QueryCache < K , V > > QueryStateImpl < ' tcx , K , V , C > {
89+ impl < ' tcx , C : QueryCache > QueryStateImpl < ' tcx , C > {
9290 pub fn iter_results < R > (
9391 & self ,
94- f : impl for < ' a > FnOnce ( Box < dyn Iterator < Item = ( & ' a K , & ' a V , DepNodeIndex ) > + ' a > ) -> R ,
92+ f : impl for < ' a > FnOnce (
93+ Box < dyn Iterator < Item = ( & ' a C :: Key , & ' a C :: Value , DepNodeIndex ) > + ' a > ,
94+ ) -> R ,
9595 ) -> R {
9696 self . cache . iter ( & self . shards , |shard| & mut shard. cache , f)
9797 }
@@ -104,11 +104,11 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
104104 pub ( super ) fn try_collect_active_jobs (
105105 & self ,
106106 kind : DepKind ,
107- make_query : impl Fn ( K ) -> Query < ' tcx > + Copy ,
107+ make_query : impl Fn ( C :: Key ) -> Query < ' tcx > + Copy ,
108108 jobs : & mut FxHashMap < QueryJobId , QueryJobInfo < ' tcx > > ,
109109 ) -> Option < ( ) >
110110 where
111- K : Clone ,
111+ C :: Key : Clone ,
112112 {
113113 // We use try_lock_shards here since we are called from the
114114 // deadlock handler, and this shouldn't be locked.
@@ -131,8 +131,8 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
131131 }
132132}
133133
134- impl < ' tcx , K , V , C : QueryCache < K , V > > Default for QueryStateImpl < ' tcx , K , V , C > {
135- fn default ( ) -> QueryStateImpl < ' tcx , K , V , C > {
134+ impl < ' tcx , C : QueryCache > Default for QueryStateImpl < ' tcx , C > {
135+ fn default ( ) -> QueryStateImpl < ' tcx , C > {
136136 QueryStateImpl {
137137 cache : C :: default ( ) ,
138138 shards : Default :: default ( ) ,
@@ -151,27 +151,22 @@ pub(crate) struct QueryLookup<'tcx, K, C> {
151151
152152/// A type representing the responsibility to execute the job in the `job` field.
153153/// This will poison the relevant query if dropped.
154- pub ( super ) type JobOwner < ' tcx , Q > = JobOwnerImpl <
155- ' tcx ,
156- <Q as QueryConfig < ' tcx > >:: Key ,
157- <Q as QueryConfig < ' tcx > >:: Value ,
158- <Q as QueryAccessors < ' tcx > >:: Cache ,
159- > ;
160-
161- pub ( super ) struct JobOwnerImpl < ' tcx , K , V , C : QueryCache < K , V > >
154+ pub ( super ) struct JobOwner < ' tcx , C >
162155where
163- K : Eq + Hash + Clone + Debug ,
164- V : Clone ,
156+ C : QueryCache ,
157+ C :: Key : Eq + Hash + Clone + Debug ,
158+ C :: Value : Clone ,
165159{
166- state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
167- key : K ,
160+ state : & ' tcx QueryStateImpl < ' tcx , C > ,
161+ key : C :: Key ,
168162 id : QueryJobId ,
169163}
170164
171- impl < ' tcx , K , V , C : QueryCache < K , V > > JobOwnerImpl < ' tcx , K , V , C >
165+ impl < ' tcx , C : QueryCache > JobOwner < ' tcx , C >
172166where
173- K : Eq + Hash + Clone + Debug ,
174- V : Clone ,
167+ C : QueryCache ,
168+ C :: Key : Eq + Hash + Clone + Debug ,
169+ C :: Value : Clone ,
175170{
176171 /// Either gets a `JobOwner` corresponding the query, allowing us to
177172 /// start executing the query, or returns with the result of the query.
@@ -185,13 +180,11 @@ where
185180 pub ( super ) fn try_start < Q > (
186181 tcx : TyCtxt < ' tcx > ,
187182 span : Span ,
188- key : & K ,
189- mut lookup : QueryLookup < ' tcx , K , C :: Sharded > ,
190- ) -> TryGetJob < ' tcx , Q >
183+ key : & C :: Key ,
184+ mut lookup : QueryLookup < ' tcx , C :: Key , C :: Sharded > ,
185+ ) -> TryGetJob < ' tcx , C >
191186 where
192- K : Eq + Hash + Clone + Debug ,
193- V : Clone ,
194- Q : QueryDescription < ' tcx , Key = K , Value = V , Cache = C > + ' tcx ,
187+ Q : QueryDescription < ' tcx , Key = C :: Key , Value = C :: Value , Cache = C > ,
195188 {
196189 let lock = & mut * lookup. lock ;
197190
@@ -231,7 +224,7 @@ where
231224 entry. insert ( QueryResult :: Started ( job) ) ;
232225
233226 let owner =
234- JobOwnerImpl { state : Q :: query_state ( tcx) , id : global_id, key : ( * key) . clone ( ) } ;
227+ JobOwner { state : Q :: query_state ( tcx) , id : global_id, key : ( * key) . clone ( ) } ;
235228 return TryGetJob :: NotYetStarted ( owner) ;
236229 }
237230 } ;
@@ -272,7 +265,7 @@ where
272265 /// Completes the query by updating the query cache with the `result`,
273266 /// signals the waiter and forgets the JobOwner, so it won't poison the query
274267 #[ inline( always) ]
275- pub ( super ) fn complete ( self , tcx : TyCtxt < ' tcx > , result : & V , dep_node_index : DepNodeIndex ) {
268+ pub ( super ) fn complete ( self , tcx : TyCtxt < ' tcx > , result : & C :: Value , dep_node_index : DepNodeIndex ) {
276269 // We can move out of `self` here because we `mem::forget` it below
277270 let key = unsafe { ptr:: read ( & self . key ) } ;
278271 let state = self . state ;
@@ -305,10 +298,10 @@ where
305298 ( result, diagnostics. into_inner ( ) )
306299}
307300
308- impl < ' tcx , K , V , C : QueryCache < K , V > > Drop for JobOwnerImpl < ' tcx , K , V , C >
301+ impl < ' tcx , C : QueryCache > Drop for JobOwner < ' tcx , C >
309302where
310- K : Eq + Hash + Clone + Debug ,
311- V : Clone ,
303+ C :: Key : Eq + Hash + Clone + Debug ,
304+ C :: Value : Clone ,
312305{
313306 #[ inline( never) ]
314307 #[ cold]
@@ -339,18 +332,22 @@ pub struct CycleError<'tcx> {
339332}
340333
341334/// The result of `try_start`.
342- pub ( super ) enum TryGetJob < ' tcx , D : QueryDescription < ' tcx > > {
335+ pub ( super ) enum TryGetJob < ' tcx , C : QueryCache >
336+ where
337+ C :: Key : Eq + Hash + Clone + Debug ,
338+ C :: Value : Clone ,
339+ {
343340 /// The query is not yet started. Contains a guard to the cache eventually used to start it.
344- NotYetStarted ( JobOwner < ' tcx , D > ) ,
341+ NotYetStarted ( JobOwner < ' tcx , C > ) ,
345342
346343 /// The query was already completed.
347344 /// Returns the result of the query and its dep-node index
348345 /// if it succeeded or a cycle error if it failed.
349346 #[ cfg( parallel_compiler) ]
350- JobCompleted ( ( D :: Value , DepNodeIndex ) ) ,
347+ JobCompleted ( ( C :: Value , DepNodeIndex ) ) ,
351348
352349 /// Trying to execute the query resulted in a cycle.
353- Cycle ( D :: Value ) ,
350+ Cycle ( C :: Value ) ,
354351}
355352
356353impl < ' tcx > TyCtxt < ' tcx > {
@@ -479,22 +476,22 @@ impl<'tcx> TyCtxt<'tcx> {
479476 /// which will be used if the query is not in the cache and we need
480477 /// to compute it.
481478 #[ inline( always) ]
482- fn try_get_cached < K , V , C , R , OnHit , OnMiss > (
479+ fn try_get_cached < C , R , OnHit , OnMiss > (
483480 self ,
484- state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
485- key : K ,
481+ state : & ' tcx QueryStateImpl < ' tcx , C > ,
482+ key : C :: Key ,
486483 // `on_hit` can be called while holding a lock to the query cache
487484 on_hit : OnHit ,
488485 on_miss : OnMiss ,
489486 ) -> R
490487 where
491- C : QueryCache < K , V > ,
492- OnHit : FnOnce ( & V , DepNodeIndex ) -> R ,
493- OnMiss : FnOnce ( K , QueryLookup < ' tcx , K , C :: Sharded > ) -> R ,
488+ C : QueryCache ,
489+ OnHit : FnOnce ( & C :: Value , DepNodeIndex ) -> R ,
490+ OnMiss : FnOnce ( C :: Key , QueryLookup < ' tcx , C :: Key , C :: Sharded > ) -> R ,
494491 {
495492 state. cache . lookup (
496493 state,
497- QueryStateShard :: < K , C :: Sharded > :: get_cache,
494+ QueryStateShard :: < C :: Key , C :: Sharded > :: get_cache,
498495 key,
499496 |value, index| {
500497 if unlikely ! ( self . prof. enabled( ) ) {
@@ -534,9 +531,9 @@ impl<'tcx> TyCtxt<'tcx> {
534531 self ,
535532 span : Span ,
536533 key : Q :: Key ,
537- lookup : QueryLookup < ' tcx , Q :: Key , <Q :: Cache as QueryCache < Q :: Key , Q :: Value > >:: Sharded > ,
534+ lookup : QueryLookup < ' tcx , Q :: Key , <Q :: Cache as QueryCache >:: Sharded > ,
538535 ) -> Q :: Value {
539- let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
536+ let job = match JobOwner :: try_start :: < Q > ( self , span, & key, lookup) {
540537 TryGetJob :: NotYetStarted ( job) => job,
541538 TryGetJob :: Cycle ( result) => return result,
542539 #[ cfg( parallel_compiler) ]
@@ -697,7 +694,7 @@ impl<'tcx> TyCtxt<'tcx> {
697694 fn force_query_with_job < Q : QueryDescription < ' tcx > + ' tcx > (
698695 self ,
699696 key : Q :: Key ,
700- job : JobOwner < ' tcx , Q > ,
697+ job : JobOwner < ' tcx , Q :: Cache > ,
701698 dep_node : DepNode ,
702699 ) -> ( Q :: Value , DepNodeIndex ) {
703700 // If the following assertion triggers, it can have two reasons:
@@ -796,7 +793,7 @@ impl<'tcx> TyCtxt<'tcx> {
796793 // Cache hit, do nothing
797794 } ,
798795 |key, lookup| {
799- let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
796+ let job = match JobOwner :: try_start :: < Q > ( self , span, & key, lookup) {
800797 TryGetJob :: NotYetStarted ( job) => job,
801798 TryGetJob :: Cycle ( _) => return ,
802799 #[ cfg( parallel_compiler) ]
0 commit comments