@@ -20,6 +20,7 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
20
20
use rustc_span:: source_map:: DUMMY_SP ;
21
21
use rustc_span:: Span ;
22
22
use std:: collections:: hash_map:: Entry ;
23
+ use std:: fmt:: Debug ;
23
24
use std:: hash:: { Hash , Hasher } ;
24
25
use std:: mem;
25
26
use std:: num:: NonZeroU32 ;
@@ -132,13 +133,28 @@ pub(crate) struct QueryLookupImpl<'tcx, QSS> {
132
133
133
134
/// A type representing the responsibility to execute the job in the `job` field.
134
135
/// This will poison the relevant query if dropped.
135
- pub ( super ) struct JobOwner < ' tcx , Q : QueryDescription < ' tcx > > {
136
- tcx : TyCtxt < ' tcx > ,
137
- key : Q :: Key ,
136
+ pub ( super ) type JobOwner < ' tcx , Q > = JobOwnerImpl <
137
+ ' tcx ,
138
+ <Q as QueryConfig < ' tcx > >:: Key ,
139
+ <Q as QueryConfig < ' tcx > >:: Value ,
140
+ <Q as QueryAccessors < ' tcx > >:: Cache ,
141
+ > ;
142
+
143
+ pub ( super ) struct JobOwnerImpl < ' tcx , K , V , C : QueryCache < K , V > >
144
+ where
145
+ K : Eq + Hash + Clone + Debug ,
146
+ V : Clone ,
147
+ {
148
+ state : & ' tcx QueryStateImpl < ' tcx , K , V , C > ,
149
+ key : K ,
138
150
id : QueryJobId ,
139
151
}
140
152
141
- impl < ' tcx , Q : QueryDescription < ' tcx > + ' tcx > JobOwner < ' tcx , Q > {
153
+ impl < ' tcx , K , V , C : QueryCache < K , V > > JobOwnerImpl < ' tcx , K , V , C >
154
+ where
155
+ K : Eq + Hash + Clone + Debug ,
156
+ V : Clone ,
157
+ {
142
158
/// Either gets a `JobOwner` corresponding the query, allowing us to
143
159
/// start executing the query, or returns with the result of the query.
144
160
/// This function assumes that `try_get_cached` is already called and returned `lookup`.
@@ -148,12 +164,17 @@ impl<'tcx, Q: QueryDescription<'tcx> + 'tcx> JobOwner<'tcx, Q> {
148
164
/// This function is inlined because that results in a noticeable speed-up
149
165
/// for some compile-time benchmarks.
150
166
#[ inline( always) ]
151
- pub ( super ) fn try_start (
167
+ pub ( super ) fn try_start < Q > (
152
168
tcx : TyCtxt < ' tcx > ,
153
169
span : Span ,
154
- key : & Q :: Key ,
170
+ key : & K ,
155
171
mut lookup : QueryLookup < ' tcx , Q > ,
156
- ) -> TryGetJob < ' tcx , Q > {
172
+ ) -> TryGetJob < ' tcx , Q >
173
+ where
174
+ K : Eq + Hash + Clone + Debug ,
175
+ V : Clone ,
176
+ Q : QueryDescription < ' tcx , Key = K , Value = V , Cache = C > + ' tcx ,
177
+ {
157
178
let lock = & mut * lookup. lock ;
158
179
159
180
let ( latch, mut _query_blocked_prof_timer) = match lock. active . entry ( ( * key) . clone ( ) ) {
@@ -191,7 +212,8 @@ impl<'tcx, Q: QueryDescription<'tcx> + 'tcx> JobOwner<'tcx, Q> {
191
212
192
213
entry. insert ( QueryResult :: Started ( job) ) ;
193
214
194
- let owner = JobOwner { tcx, id : global_id, key : ( * key) . clone ( ) } ;
215
+ let owner =
216
+ JobOwnerImpl { state : Q :: query_state ( tcx) , id : global_id, key : ( * key) . clone ( ) } ;
195
217
return TryGetJob :: NotYetStarted ( owner) ;
196
218
}
197
219
} ;
@@ -231,16 +253,15 @@ impl<'tcx, Q: QueryDescription<'tcx> + 'tcx> JobOwner<'tcx, Q> {
231
253
/// Completes the query by updating the query cache with the `result`,
232
254
/// signals the waiter and forgets the JobOwner, so it won't poison the query
233
255
#[ inline( always) ]
234
- pub ( super ) fn complete ( self , result : & Q :: Value , dep_node_index : DepNodeIndex ) {
256
+ pub ( super ) fn complete ( self , tcx : TyCtxt < ' tcx > , result : & V , dep_node_index : DepNodeIndex ) {
235
257
// We can move out of `self` here because we `mem::forget` it below
236
258
let key = unsafe { ptr:: read ( & self . key ) } ;
237
- let tcx = self . tcx ;
259
+ let state = self . state ;
238
260
239
261
// Forget ourself so our destructor won't poison the query
240
262
mem:: forget ( self ) ;
241
263
242
264
let job = {
243
- let state = Q :: query_state ( tcx) ;
244
265
let result = result. clone ( ) ;
245
266
let mut lock = state. shards . get_shard_by_value ( & key) . lock ( ) ;
246
267
let job = match lock. active . remove ( & key) . unwrap ( ) {
@@ -265,12 +286,16 @@ where
265
286
( result, diagnostics. into_inner ( ) )
266
287
}
267
288
268
- impl < ' tcx , Q : QueryDescription < ' tcx > > Drop for JobOwner < ' tcx , Q > {
289
+ impl < ' tcx , K , V , C : QueryCache < K , V > > Drop for JobOwnerImpl < ' tcx , K , V , C >
290
+ where
291
+ K : Eq + Hash + Clone + Debug ,
292
+ V : Clone ,
293
+ {
269
294
#[ inline( never) ]
270
295
#[ cold]
271
296
fn drop ( & mut self ) {
272
297
// Poison the query so jobs waiting on it panic.
273
- let state = Q :: query_state ( self . tcx ) ;
298
+ let state = self . state ;
274
299
let shard = state. shards . get_shard_by_value ( & self . key ) ;
275
300
let job = {
276
301
let mut shard = shard. lock ( ) ;
@@ -492,7 +517,7 @@ impl<'tcx> TyCtxt<'tcx> {
492
517
key : Q :: Key ,
493
518
lookup : QueryLookup < ' tcx , Q > ,
494
519
) -> Q :: Value {
495
- let job = match JobOwner :: try_start ( self , span, & key, lookup) {
520
+ let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
496
521
TryGetJob :: NotYetStarted ( job) => job,
497
522
TryGetJob :: Cycle ( result) => return result,
498
523
#[ cfg( parallel_compiler) ]
@@ -528,7 +553,7 @@ impl<'tcx> TyCtxt<'tcx> {
528
553
. store_diagnostics_for_anon_node ( dep_node_index, diagnostics) ;
529
554
}
530
555
531
- job. complete ( & result, dep_node_index) ;
556
+ job. complete ( self , & result, dep_node_index) ;
532
557
533
558
return result;
534
559
}
@@ -554,7 +579,7 @@ impl<'tcx> TyCtxt<'tcx> {
554
579
} )
555
580
} ) ;
556
581
if let Some ( ( result, dep_node_index) ) = loaded {
557
- job. complete ( & result, dep_node_index) ;
582
+ job. complete ( self , & result, dep_node_index) ;
558
583
return result;
559
584
}
560
585
}
@@ -696,7 +721,7 @@ impl<'tcx> TyCtxt<'tcx> {
696
721
}
697
722
}
698
723
699
- job. complete ( & result, dep_node_index) ;
724
+ job. complete ( self , & result, dep_node_index) ;
700
725
701
726
( result, dep_node_index)
702
727
}
@@ -751,7 +776,7 @@ impl<'tcx> TyCtxt<'tcx> {
751
776
// Cache hit, do nothing
752
777
} ,
753
778
|key, lookup| {
754
- let job = match JobOwner :: try_start ( self , span, & key, lookup) {
779
+ let job = match JobOwnerImpl :: try_start :: < Q > ( self , span, & key, lookup) {
755
780
TryGetJob :: NotYetStarted ( job) => job,
756
781
TryGetJob :: Cycle ( _) => return ,
757
782
#[ cfg( parallel_compiler) ]
0 commit comments