@@ -29,32 +29,23 @@ use std::ptr;
29
29
#[ cfg( debug_assertions) ]
30
30
use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
31
31
32
- pub ( crate ) type QueryStateShard < ' tcx , Q > = QueryStateShardImpl <
33
- ' tcx ,
34
- <Q as QueryConfig < ' tcx > >:: Key ,
35
- <<Q as QueryAccessors < ' tcx > >:: Cache as QueryCache <
36
- <Q as QueryConfig < ' tcx > >:: Key ,
37
- <Q as QueryConfig < ' tcx > >:: Value ,
38
- > >:: Sharded ,
39
- > ;
40
-
41
- pub ( crate ) struct QueryStateShardImpl < ' tcx , K , C > {
32
+ pub ( crate ) struct QueryStateShard < ' tcx , K , C > {
42
33
pub ( super ) cache : C ,
43
34
pub ( super ) active : FxHashMap < K , QueryResult < ' tcx > > ,
44
35
45
36
/// Used to generate unique ids for active jobs.
46
37
pub ( super ) jobs : u32 ,
47
38
}
48
39
49
- impl < ' tcx , K , C > QueryStateShardImpl < ' tcx , K , C > {
40
+ impl < ' tcx , K , C > QueryStateShard < ' tcx , K , C > {
50
41
fn get_cache ( & mut self ) -> & mut C {
51
42
& mut self . cache
52
43
}
53
44
}
54
45
55
- impl < ' tcx , K , C : Default > Default for QueryStateShardImpl < ' tcx , K , C > {
56
- fn default ( ) -> QueryStateShardImpl < ' tcx , K , C > {
57
- QueryStateShardImpl { cache : Default :: default ( ) , active : Default :: default ( ) , jobs : 0 }
46
+ impl < ' tcx , K , C : Default > Default for QueryStateShard < ' tcx , K , C > {
47
+ fn default ( ) -> QueryStateShard < ' tcx , K , C > {
48
+ QueryStateShard { cache : Default :: default ( ) , active : Default :: default ( ) , jobs : 0 }
58
49
}
59
50
}
60
51
@@ -67,16 +58,13 @@ pub(crate) type QueryState<'tcx, Q> = QueryStateImpl<
67
58
68
59
pub ( crate ) struct QueryStateImpl < ' tcx , K , V , C : QueryCache < K , V > > {
69
60
pub ( super ) cache : C ,
70
- pub ( super ) shards : Sharded < QueryStateShardImpl < ' tcx , K , C :: Sharded > > ,
61
+ pub ( super ) shards : Sharded < QueryStateShard < ' tcx , K , C :: Sharded > > ,
71
62
#[ cfg( debug_assertions) ]
72
63
pub ( super ) cache_hits : AtomicUsize ,
73
64
}
74
65
75
66
impl < ' tcx , K , V , C : QueryCache < K , V > > QueryStateImpl < ' tcx , K , V , C > {
76
- pub ( super ) fn get_lookup < K2 : Hash > (
77
- & ' tcx self ,
78
- key : & K2 ,
79
- ) -> QueryLookupImpl < ' tcx , QueryStateShardImpl < ' tcx , K , C :: Sharded > > {
67
+ pub ( super ) fn get_lookup < K2 : Hash > ( & ' tcx self , key : & K2 ) -> QueryLookup < ' tcx , K , C :: Sharded > {
80
68
// We compute the key's hash once and then use it for both the
81
69
// shard lookup and the hashmap lookup. This relies on the fact
82
70
// that both of them use `FxHasher`.
@@ -86,7 +74,7 @@ impl<'tcx, K, V, C: QueryCache<K, V>> QueryStateImpl<'tcx, K, V, C> {
86
74
87
75
let shard = self . shards . get_shard_index_by_hash ( key_hash) ;
88
76
let lock = self . shards . get_shard_by_index ( shard) . lock ( ) ;
89
- QueryLookupImpl { key_hash, shard, lock }
77
+ QueryLookup { key_hash, shard, lock }
90
78
}
91
79
}
92
80
@@ -154,11 +142,10 @@ impl<'tcx, K, V, C: QueryCache<K, V>> Default for QueryStateImpl<'tcx, K, V, C>
154
142
}
155
143
156
144
/// Values used when checking a query cache which can be reused on a cache-miss to execute the query.
157
- pub ( crate ) type QueryLookup < ' tcx , Q > = QueryLookupImpl < ' tcx , QueryStateShard < ' tcx , Q > > ;
158
- pub ( crate ) struct QueryLookupImpl < ' tcx , QSS > {
145
+ pub ( crate ) struct QueryLookup < ' tcx , K , C > {
159
146
pub ( super ) key_hash : u64 ,
160
147
pub ( super ) shard : usize ,
161
- pub ( super ) lock : LockGuard < ' tcx , QSS > ,
148
+ pub ( super ) lock : LockGuard < ' tcx , QueryStateShard < ' tcx , K , C > > ,
162
149
}
163
150
164
151
/// A type representing the responsibility to execute the job in the `job` field.
@@ -198,7 +185,7 @@ where
198
185
tcx : TyCtxt < ' tcx > ,
199
186
span : Span ,
200
187
key : & K ,
201
- mut lookup : QueryLookup < ' tcx , Q > ,
188
+ mut lookup : QueryLookup < ' tcx , K , C :: Sharded > ,
202
189
) -> TryGetJob < ' tcx , Q >
203
190
where
204
191
K : Eq + Hash + Clone + Debug ,
@@ -502,11 +489,11 @@ impl<'tcx> TyCtxt<'tcx> {
502
489
where
503
490
C : QueryCache < K , V > ,
504
491
OnHit : FnOnce ( & V , DepNodeIndex ) -> R ,
505
- OnMiss : FnOnce ( K , QueryLookupImpl < ' tcx , QueryStateShardImpl < ' tcx , K , C :: Sharded > > ) -> R ,
492
+ OnMiss : FnOnce ( K , QueryLookup < ' tcx , K , C :: Sharded > ) -> R ,
506
493
{
507
494
state. cache . lookup (
508
495
state,
509
- QueryStateShardImpl :: < K , C :: Sharded > :: get_cache,
496
+ QueryStateShard :: < K , C :: Sharded > :: get_cache,
510
497
key,
511
498
|value, index| {
512
499
if unlikely ! ( self . prof. enabled( ) ) {
@@ -546,7 +533,7 @@ impl<'tcx> TyCtxt<'tcx> {
546
533
self ,
547
534
span : Span ,
548
535
key : Q :: Key ,
549
- lookup : QueryLookup < ' tcx , Q > ,
536
+ lookup : QueryLookup < ' tcx , Q :: Key , < Q :: Cache as QueryCache < Q :: Key , Q :: Value > > :: Sharded > ,
550
537
) -> Q :: Value {
551
538
let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
552
539
TryGetJob :: NotYetStarted ( job) => job,
0 commit comments