@@ -20,6 +20,7 @@ use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, H
2020use rustc_span:: source_map:: DUMMY_SP ;
2121use rustc_span:: Span ;
2222use std:: collections:: hash_map:: Entry ;
23+ use std:: fmt:: Debug ;
2324use std:: hash:: { Hash , Hasher } ;
2425use std:: mem;
2526use std:: num:: NonZeroU32 ;
@@ -132,13 +133,28 @@ pub(crate) struct QueryLookupImpl<'tcx, QSS> {
132133
133134/// A type representing the responsibility to execute the job in the `job` field.
134135/// 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 ,
138150 id : QueryJobId ,
139151}
140152
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+ {
142158 /// Either gets a `JobOwner` corresponding the query, allowing us to
143159 /// start executing the query, or returns with the result of the query.
144160 /// 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> {
148164 /// This function is inlined because that results in a noticeable speed-up
149165 /// for some compile-time benchmarks.
150166 #[ inline( always) ]
151- pub ( super ) fn try_start (
167+ pub ( super ) fn try_start < Q > (
152168 tcx : TyCtxt < ' tcx > ,
153169 span : Span ,
154- key : & Q :: Key ,
170+ key : & K ,
155171 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+ {
157178 let lock = & mut * lookup. lock ;
158179
159180 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> {
191212
192213 entry. insert ( QueryResult :: Started ( job) ) ;
193214
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 ( ) } ;
195217 return TryGetJob :: NotYetStarted ( owner) ;
196218 }
197219 } ;
@@ -231,16 +253,15 @@ impl<'tcx, Q: QueryDescription<'tcx> + 'tcx> JobOwner<'tcx, Q> {
231253 /// Completes the query by updating the query cache with the `result`,
232254 /// signals the waiter and forgets the JobOwner, so it won't poison the query
233255 #[ 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 ) {
235257 // We can move out of `self` here because we `mem::forget` it below
236258 let key = unsafe { ptr:: read ( & self . key ) } ;
237- let tcx = self . tcx ;
259+ let state = self . state ;
238260
239261 // Forget ourself so our destructor won't poison the query
240262 mem:: forget ( self ) ;
241263
242264 let job = {
243- let state = Q :: query_state ( tcx) ;
244265 let result = result. clone ( ) ;
245266 let mut lock = state. shards . get_shard_by_value ( & key) . lock ( ) ;
246267 let job = match lock. active . remove ( & key) . unwrap ( ) {
@@ -265,12 +286,16 @@ where
265286 ( result, diagnostics. into_inner ( ) )
266287}
267288
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+ {
269294 #[ inline( never) ]
270295 #[ cold]
271296 fn drop ( & mut self ) {
272297 // Poison the query so jobs waiting on it panic.
273- let state = Q :: query_state ( self . tcx ) ;
298+ let state = self . state ;
274299 let shard = state. shards . get_shard_by_value ( & self . key ) ;
275300 let job = {
276301 let mut shard = shard. lock ( ) ;
@@ -492,7 +517,7 @@ impl<'tcx> TyCtxt<'tcx> {
492517 key : Q :: Key ,
493518 lookup : QueryLookup < ' tcx , Q > ,
494519 ) -> 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) {
496521 TryGetJob :: NotYetStarted ( job) => job,
497522 TryGetJob :: Cycle ( result) => return result,
498523 #[ cfg( parallel_compiler) ]
@@ -528,7 +553,7 @@ impl<'tcx> TyCtxt<'tcx> {
528553 . store_diagnostics_for_anon_node ( dep_node_index, diagnostics) ;
529554 }
530555
531- job. complete ( & result, dep_node_index) ;
556+ job. complete ( self , & result, dep_node_index) ;
532557
533558 return result;
534559 }
@@ -554,7 +579,7 @@ impl<'tcx> TyCtxt<'tcx> {
554579 } )
555580 } ) ;
556581 if let Some ( ( result, dep_node_index) ) = loaded {
557- job. complete ( & result, dep_node_index) ;
582+ job. complete ( self , & result, dep_node_index) ;
558583 return result;
559584 }
560585 }
@@ -696,7 +721,7 @@ impl<'tcx> TyCtxt<'tcx> {
696721 }
697722 }
698723
699- job. complete ( & result, dep_node_index) ;
724+ job. complete ( self , & result, dep_node_index) ;
700725
701726 ( result, dep_node_index)
702727 }
@@ -751,7 +776,7 @@ impl<'tcx> TyCtxt<'tcx> {
751776 // Cache hit, do nothing
752777 } ,
753778 |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) {
755780 TryGetJob :: NotYetStarted ( job) => job,
756781 TryGetJob :: Cycle ( _) => return ,
757782 #[ cfg( parallel_compiler) ]
0 commit comments