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
}
@@ -103,11 +103,11 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
103
103
pub ( super ) fn try_collect_active_jobs (
104
104
& self ,
105
105
kind : DepKind ,
106
- make_query : fn ( K ) -> Query < ' tcx > ,
106
+ make_query : fn ( C :: Key ) -> Query < ' tcx > ,
107
107
jobs : & mut FxHashMap < QueryJobId , QueryJobInfo < ' tcx > > ,
108
108
) -> Option < ( ) >
109
109
where
110
- K : Clone ,
110
+ C :: Key : Clone ,
111
111
{
112
112
// We use try_lock_shards here since we are called from the
113
113
// deadlock handler, and this shouldn't be locked.
@@ -130,8 +130,8 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
130
130
}
131
131
}
132
132
133
- impl < ' tcx , K , V , C : QueryCache < K , V > > Default for QueryStateImpl < ' tcx , K , V , C > {
134
- fn default ( ) -> QueryStateImpl < ' tcx , K , V , C > {
133
+ impl < ' tcx , C : QueryCache > Default for QueryStateImpl < ' tcx , C > {
134
+ fn default ( ) -> QueryStateImpl < ' tcx , C > {
135
135
QueryStateImpl {
136
136
cache : C :: default ( ) ,
137
137
shards : Default :: default ( ) ,
@@ -150,27 +150,22 @@ pub(crate) struct QueryLookup<'tcx, K, C> {
150
150
151
151
/// A type representing the responsibility to execute the job in the `job` field.
152
152
/// This will poison the relevant query if dropped.
153
- pub ( super ) type JobOwner < ' tcx , Q > = JobOwnerImpl <
154
- ' tcx ,
155
- <Q as QueryConfig < ' tcx > >:: Key ,
156
- <Q as QueryConfig < ' tcx > >:: Value ,
157
- <Q as QueryAccessors < ' tcx > >:: Cache ,
158
- > ;
159
-
160
- pub ( super ) struct JobOwnerImpl < ' tcx , K , V , C : QueryCache < K , V > >
153
+ pub ( super ) struct JobOwner < ' tcx , C >
161
154
where
162
- K : Eq + Hash + Clone + Debug ,
163
- V : Clone ,
155
+ C : QueryCache ,
156
+ C :: Key : Eq + Hash + Clone + Debug ,
157
+ C :: Value : Clone ,
164
158
{
165
- state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
166
- key : K ,
159
+ state : & ' tcx QueryStateImpl < ' tcx , C > ,
160
+ key : C :: Key ,
167
161
id : QueryJobId ,
168
162
}
169
163
170
- impl < ' tcx , K , V , C : QueryCache < K , V > > JobOwnerImpl < ' tcx , K , V , C >
164
+ impl < ' tcx , C : QueryCache > JobOwner < ' tcx , C >
171
165
where
172
- K : Eq + Hash + Clone + Debug ,
173
- V : Clone ,
166
+ C : QueryCache ,
167
+ C :: Key : Eq + Hash + Clone + Debug ,
168
+ C :: Value : Clone ,
174
169
{
175
170
/// Either gets a `JobOwner` corresponding the query, allowing us to
176
171
/// start executing the query, or returns with the result of the query.
@@ -184,13 +179,11 @@ where
184
179
pub ( super ) fn try_start < Q > (
185
180
tcx : TyCtxt < ' tcx > ,
186
181
span : Span ,
187
- key : & K ,
188
- mut lookup : QueryLookup < ' tcx , K , C :: Sharded > ,
189
- ) -> TryGetJob < ' tcx , Q >
182
+ key : & C :: Key ,
183
+ mut lookup : QueryLookup < ' tcx , C :: Key , C :: Sharded > ,
184
+ ) -> TryGetJob < ' tcx , C >
190
185
where
191
- K : Eq + Hash + Clone + Debug ,
192
- V : Clone ,
193
- Q : QueryDescription < ' tcx , Key = K , Value = V , Cache = C > + ' tcx ,
186
+ Q : QueryDescription < ' tcx , Key = C :: Key , Value = C :: Value , Cache = C > ,
194
187
{
195
188
let lock = & mut * lookup. lock ;
196
189
@@ -230,7 +223,7 @@ where
230
223
entry. insert ( QueryResult :: Started ( job) ) ;
231
224
232
225
let owner =
233
- JobOwnerImpl { state : Q :: query_state ( tcx) , id : global_id, key : ( * key) . clone ( ) } ;
226
+ JobOwner { state : Q :: query_state ( tcx) , id : global_id, key : ( * key) . clone ( ) } ;
234
227
return TryGetJob :: NotYetStarted ( owner) ;
235
228
}
236
229
} ;
@@ -271,7 +264,12 @@ where
271
264
/// Completes the query by updating the query cache with the `result`,
272
265
/// signals the waiter and forgets the JobOwner, so it won't poison the query
273
266
#[ inline( always) ]
274
- pub ( super ) fn complete ( self , tcx : TyCtxt < ' tcx > , result : & V , dep_node_index : DepNodeIndex ) {
267
+ pub ( super ) fn complete (
268
+ self ,
269
+ tcx : TyCtxt < ' tcx > ,
270
+ result : & C :: Value ,
271
+ dep_node_index : DepNodeIndex ,
272
+ ) {
275
273
// We can move out of `self` here because we `mem::forget` it below
276
274
let key = unsafe { ptr:: read ( & self . key ) } ;
277
275
let state = self . state ;
@@ -304,10 +302,10 @@ where
304
302
( result, diagnostics. into_inner ( ) )
305
303
}
306
304
307
- impl < ' tcx , K , V , C : QueryCache < K , V > > Drop for JobOwnerImpl < ' tcx , K , V , C >
305
+ impl < ' tcx , C : QueryCache > Drop for JobOwner < ' tcx , C >
308
306
where
309
- K : Eq + Hash + Clone + Debug ,
310
- V : Clone ,
307
+ C :: Key : Eq + Hash + Clone + Debug ,
308
+ C :: Value : Clone ,
311
309
{
312
310
#[ inline( never) ]
313
311
#[ cold]
@@ -338,18 +336,22 @@ pub struct CycleError<'tcx> {
338
336
}
339
337
340
338
/// The result of `try_start`.
341
- pub ( super ) enum TryGetJob < ' tcx , D : QueryDescription < ' tcx > > {
339
+ pub ( super ) enum TryGetJob < ' tcx , C : QueryCache >
340
+ where
341
+ C :: Key : Eq + Hash + Clone + Debug ,
342
+ C :: Value : Clone ,
343
+ {
342
344
/// The query is not yet started. Contains a guard to the cache eventually used to start it.
343
- NotYetStarted ( JobOwner < ' tcx , D > ) ,
345
+ NotYetStarted ( JobOwner < ' tcx , C > ) ,
344
346
345
347
/// The query was already completed.
346
348
/// Returns the result of the query and its dep-node index
347
349
/// if it succeeded or a cycle error if it failed.
348
350
#[ cfg( parallel_compiler) ]
349
- JobCompleted ( ( D :: Value , DepNodeIndex ) ) ,
351
+ JobCompleted ( ( C :: Value , DepNodeIndex ) ) ,
350
352
351
353
/// Trying to execute the query resulted in a cycle.
352
- Cycle ( D :: Value ) ,
354
+ Cycle ( C :: Value ) ,
353
355
}
354
356
355
357
impl < ' tcx > TyCtxt < ' tcx > {
@@ -478,22 +480,22 @@ impl<'tcx> TyCtxt<'tcx> {
478
480
/// which will be used if the query is not in the cache and we need
479
481
/// to compute it.
480
482
#[ inline( always) ]
481
- fn try_get_cached < K , V , C , R , OnHit , OnMiss > (
483
+ fn try_get_cached < C , R , OnHit , OnMiss > (
482
484
self ,
483
- state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
484
- key : K ,
485
+ state : & ' tcx QueryStateImpl < ' tcx , C > ,
486
+ key : C :: Key ,
485
487
// `on_hit` can be called while holding a lock to the query cache
486
488
on_hit : OnHit ,
487
489
on_miss : OnMiss ,
488
490
) -> R
489
491
where
490
- C : QueryCache < K , V > ,
491
- OnHit : FnOnce ( & V , DepNodeIndex ) -> R ,
492
- OnMiss : FnOnce ( K , QueryLookup < ' tcx , K , C :: Sharded > ) -> R ,
492
+ C : QueryCache ,
493
+ OnHit : FnOnce ( & C :: Value , DepNodeIndex ) -> R ,
494
+ OnMiss : FnOnce ( C :: Key , QueryLookup < ' tcx , C :: Key , C :: Sharded > ) -> R ,
493
495
{
494
496
state. cache . lookup (
495
497
state,
496
- QueryStateShard :: < K , C :: Sharded > :: get_cache,
498
+ QueryStateShard :: < C :: Key , C :: Sharded > :: get_cache,
497
499
key,
498
500
|value, index| {
499
501
if unlikely ! ( self . prof. enabled( ) ) {
@@ -533,9 +535,9 @@ impl<'tcx> TyCtxt<'tcx> {
533
535
self ,
534
536
span : Span ,
535
537
key : Q :: Key ,
536
- lookup : QueryLookup < ' tcx , Q :: Key , <Q :: Cache as QueryCache < Q :: Key , Q :: Value > >:: Sharded > ,
538
+ lookup : QueryLookup < ' tcx , Q :: Key , <Q :: Cache as QueryCache >:: Sharded > ,
537
539
) -> Q :: Value {
538
- let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
540
+ let job = match JobOwner :: try_start :: < Q > ( self , span, & key, lookup) {
539
541
TryGetJob :: NotYetStarted ( job) => job,
540
542
TryGetJob :: Cycle ( result) => return result,
541
543
#[ cfg( parallel_compiler) ]
@@ -696,7 +698,7 @@ impl<'tcx> TyCtxt<'tcx> {
696
698
fn force_query_with_job < Q : QueryDescription < ' tcx > + ' tcx > (
697
699
self ,
698
700
key : Q :: Key ,
699
- job : JobOwner < ' tcx , Q > ,
701
+ job : JobOwner < ' tcx , Q :: Cache > ,
700
702
dep_node : DepNode ,
701
703
) -> ( Q :: Value , DepNodeIndex ) {
702
704
// If the following assertion triggers, it can have two reasons:
@@ -795,7 +797,7 @@ impl<'tcx> TyCtxt<'tcx> {
795
797
// Cache hit, do nothing
796
798
} ,
797
799
|key, lookup| {
798
- let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
800
+ let job = match JobOwner :: try_start :: < Q > ( self , span, & key, lookup) {
799
801
TryGetJob :: NotYetStarted ( job) => job,
800
802
TryGetJob :: Cycle ( _) => return ,
801
803
#[ cfg( parallel_compiler) ]
0 commit comments