4
4
5
5
use crate :: dep_graph:: { DepKind , DepNode , DepNodeIndex , SerializedDepNodeIndex } ;
6
6
use crate :: ty:: query:: caches:: QueryCache ;
7
- use crate :: ty:: query:: config:: { QueryAccessors , QueryConfig , QueryDescription } ;
7
+ use crate :: ty:: query:: config:: { QueryAccessors , QueryDescription } ;
8
8
use crate :: ty:: query:: job:: { QueryInfo , QueryJob , QueryJobId , QueryJobInfo , QueryShardJobId } ;
9
9
use crate :: ty:: query:: Query ;
10
10
use crate :: ty:: tls;
@@ -49,22 +49,20 @@ impl<'tcx, K, C: Default> Default for QueryStateShard<'tcx, K, C> {
49
49
}
50
50
}
51
51
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 > ;
58
53
59
- pub ( crate ) struct QueryStateImpl < ' tcx , K , V , C : QueryCache < K , V > > {
54
+ pub ( crate ) struct QueryStateImpl < ' tcx , C : QueryCache > {
60
55
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 > > ,
62
57
#[ cfg( debug_assertions) ]
63
58
pub ( super ) cache_hits : AtomicUsize ,
64
59
}
65
60
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 > {
68
66
// We compute the key's hash once and then use it for both the
69
67
// shard lookup and the hashmap lookup. This relies on the fact
70
68
// that both of them use `FxHasher`.
@@ -88,10 +86,12 @@ pub(super) enum QueryResult<'tcx> {
88
86
Poisoned ,
89
87
}
90
88
91
- impl < ' tcx , K , V , C : QueryCache < K , V > > QueryStateImpl < ' tcx , K , V , C > {
89
+ impl < ' tcx , C : QueryCache > QueryStateImpl < ' tcx , C > {
92
90
pub fn iter_results < R > (
93
91
& 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 ,
95
95
) -> R {
96
96
self . cache . iter ( & self . shards , |shard| & mut shard. cache , f)
97
97
}
@@ -104,11 +104,11 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
104
104
pub ( super ) fn try_collect_active_jobs (
105
105
& self ,
106
106
kind : DepKind ,
107
- make_query : impl Fn ( K ) -> Query < ' tcx > + Copy ,
107
+ make_query : impl Fn ( C :: Key ) -> Query < ' tcx > + Copy ,
108
108
jobs : & mut FxHashMap < QueryJobId , QueryJobInfo < ' tcx > > ,
109
109
) -> Option < ( ) >
110
110
where
111
- K : Clone ,
111
+ C :: Key : Clone ,
112
112
{
113
113
// We use try_lock_shards here since we are called from the
114
114
// 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> {
131
131
}
132
132
}
133
133
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 > {
136
136
QueryStateImpl {
137
137
cache : C :: default ( ) ,
138
138
shards : Default :: default ( ) ,
@@ -151,27 +151,22 @@ pub(crate) struct QueryLookup<'tcx, K, C> {
151
151
152
152
/// A type representing the responsibility to execute the job in the `job` field.
153
153
/// 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 >
162
155
where
163
- K : Eq + Hash + Clone + Debug ,
164
- V : Clone ,
156
+ C : QueryCache ,
157
+ C :: Key : Eq + Hash + Clone + Debug ,
158
+ C :: Value : Clone ,
165
159
{
166
- state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
167
- key : K ,
160
+ state : & ' tcx QueryStateImpl < ' tcx , C > ,
161
+ key : C :: Key ,
168
162
id : QueryJobId ,
169
163
}
170
164
171
- impl < ' tcx , K , V , C : QueryCache < K , V > > JobOwnerImpl < ' tcx , K , V , C >
165
+ impl < ' tcx , C : QueryCache > JobOwner < ' tcx , C >
172
166
where
173
- K : Eq + Hash + Clone + Debug ,
174
- V : Clone ,
167
+ C : QueryCache ,
168
+ C :: Key : Eq + Hash + Clone + Debug ,
169
+ C :: Value : Clone ,
175
170
{
176
171
/// Either gets a `JobOwner` corresponding the query, allowing us to
177
172
/// start executing the query, or returns with the result of the query.
@@ -185,13 +180,11 @@ where
185
180
pub ( super ) fn try_start < Q > (
186
181
tcx : TyCtxt < ' tcx > ,
187
182
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 >
191
186
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 > ,
195
188
{
196
189
let lock = & mut * lookup. lock ;
197
190
@@ -231,7 +224,7 @@ where
231
224
entry. insert ( QueryResult :: Started ( job) ) ;
232
225
233
226
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 ( ) } ;
235
228
return TryGetJob :: NotYetStarted ( owner) ;
236
229
}
237
230
} ;
@@ -272,7 +265,7 @@ where
272
265
/// Completes the query by updating the query cache with the `result`,
273
266
/// signals the waiter and forgets the JobOwner, so it won't poison the query
274
267
#[ 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 ) {
276
269
// We can move out of `self` here because we `mem::forget` it below
277
270
let key = unsafe { ptr:: read ( & self . key ) } ;
278
271
let state = self . state ;
@@ -305,10 +298,10 @@ where
305
298
( result, diagnostics. into_inner ( ) )
306
299
}
307
300
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 >
309
302
where
310
- K : Eq + Hash + Clone + Debug ,
311
- V : Clone ,
303
+ C :: Key : Eq + Hash + Clone + Debug ,
304
+ C :: Value : Clone ,
312
305
{
313
306
#[ inline( never) ]
314
307
#[ cold]
@@ -339,18 +332,22 @@ pub struct CycleError<'tcx> {
339
332
}
340
333
341
334
/// 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
+ {
343
340
/// 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 > ) ,
345
342
346
343
/// The query was already completed.
347
344
/// Returns the result of the query and its dep-node index
348
345
/// if it succeeded or a cycle error if it failed.
349
346
#[ cfg( parallel_compiler) ]
350
- JobCompleted ( ( D :: Value , DepNodeIndex ) ) ,
347
+ JobCompleted ( ( C :: Value , DepNodeIndex ) ) ,
351
348
352
349
/// Trying to execute the query resulted in a cycle.
353
- Cycle ( D :: Value ) ,
350
+ Cycle ( C :: Value ) ,
354
351
}
355
352
356
353
impl < ' tcx > TyCtxt < ' tcx > {
@@ -479,22 +476,22 @@ impl<'tcx> TyCtxt<'tcx> {
479
476
/// which will be used if the query is not in the cache and we need
480
477
/// to compute it.
481
478
#[ inline( always) ]
482
- fn try_get_cached < K , V , C , R , OnHit , OnMiss > (
479
+ fn try_get_cached < C , R , OnHit , OnMiss > (
483
480
self ,
484
- state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
485
- key : K ,
481
+ state : & ' tcx QueryStateImpl < ' tcx , C > ,
482
+ key : C :: Key ,
486
483
// `on_hit` can be called while holding a lock to the query cache
487
484
on_hit : OnHit ,
488
485
on_miss : OnMiss ,
489
486
) -> R
490
487
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 ,
494
491
{
495
492
state. cache . lookup (
496
493
state,
497
- QueryStateShard :: < K , C :: Sharded > :: get_cache,
494
+ QueryStateShard :: < C :: Key , C :: Sharded > :: get_cache,
498
495
key,
499
496
|value, index| {
500
497
if unlikely ! ( self . prof. enabled( ) ) {
@@ -534,9 +531,9 @@ impl<'tcx> TyCtxt<'tcx> {
534
531
self ,
535
532
span : Span ,
536
533
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 > ,
538
535
) -> 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) {
540
537
TryGetJob :: NotYetStarted ( job) => job,
541
538
TryGetJob :: Cycle ( result) => return result,
542
539
#[ cfg( parallel_compiler) ]
@@ -697,7 +694,7 @@ impl<'tcx> TyCtxt<'tcx> {
697
694
fn force_query_with_job < Q : QueryDescription < ' tcx > + ' tcx > (
698
695
self ,
699
696
key : Q :: Key ,
700
- job : JobOwner < ' tcx , Q > ,
697
+ job : JobOwner < ' tcx , Q :: Cache > ,
701
698
dep_node : DepNode ,
702
699
) -> ( Q :: Value , DepNodeIndex ) {
703
700
// If the following assertion triggers, it can have two reasons:
@@ -796,7 +793,7 @@ impl<'tcx> TyCtxt<'tcx> {
796
793
// Cache hit, do nothing
797
794
} ,
798
795
|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) {
800
797
TryGetJob :: NotYetStarted ( job) => job,
801
798
TryGetJob :: Cycle ( _) => return ,
802
799
#[ cfg( parallel_compiler) ]
0 commit comments