@@ -188,40 +188,6 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
188188
189189 job. signal_complete ( ) ;
190190 }
191-
192- /// Executes a job by changing the ImplicitCtxt to point to the
193- /// new query job while it executes. It returns the diagnostics
194- /// captured during execution and the actual result.
195- #[ inline( always) ]
196- pub ( super ) fn start < ' lcx , F , R > (
197- & self ,
198- tcx : TyCtxt < ' _ , ' tcx , ' lcx > ,
199- diagnostics : Option < & Lock < ThinVec < Diagnostic > > > ,
200- compute : F )
201- -> R
202- where
203- F : for < ' b > FnOnce ( TyCtxt < ' b , ' tcx , ' lcx > ) -> R
204- {
205- // The TyCtxt stored in TLS has the same global interner lifetime
206- // as `tcx`, so we use `with_related_context` to relate the 'gcx lifetimes
207- // when accessing the ImplicitCtxt
208- tls:: with_related_context ( tcx, move |current_icx| {
209- // Update the ImplicitCtxt to point to our new query job
210- let new_icx = tls:: ImplicitCtxt {
211- tcx : tcx. global_tcx ( ) ,
212- query : Some ( self . job . clone ( ) ) ,
213- diagnostics,
214- layout_depth : current_icx. layout_depth ,
215- task_deps : current_icx. task_deps ,
216- } ;
217-
218- // Use the ImplicitCtxt while we execute the query
219- tls:: enter_context ( & new_icx, |_| {
220- compute ( tcx)
221- } )
222- } )
223- }
224-
225191}
226192
227193#[ inline( always) ]
@@ -265,6 +231,39 @@ pub(super) enum TryGetJob<'a, 'tcx: 'a, D: QueryDescription<'tcx> + 'a> {
265231}
266232
267233impl < ' a , ' gcx , ' tcx > TyCtxt < ' a , ' gcx , ' tcx > {
234+ /// Executes a job by changing the ImplicitCtxt to point to the
235+ /// new query job while it executes. It returns the diagnostics
236+ /// captured during execution and the actual result.
237+ #[ inline( always) ]
238+ pub ( super ) fn start_query < F , R > (
239+ self ,
240+ job : Lrc < QueryJob < ' gcx > > ,
241+ diagnostics : Option < & Lock < ThinVec < Diagnostic > > > ,
242+ compute : F )
243+ -> R
244+ where
245+ F : for <' b , ' lcx > FnOnce ( TyCtxt < ' b , ' gcx , ' lcx > ) -> R
246+ {
247+ // The TyCtxt stored in TLS has the same global interner lifetime
248+ // as `self`, so we use `with_related_context` to relate the 'gcx lifetimes
249+ // when accessing the ImplicitCtxt
250+ tls:: with_related_context ( self , move |current_icx| {
251+ // Update the ImplicitCtxt to point to our new query job
252+ let new_icx = tls:: ImplicitCtxt {
253+ tcx : self . global_tcx ( ) ,
254+ query : Some ( job) ,
255+ diagnostics,
256+ layout_depth : current_icx. layout_depth ,
257+ task_deps : current_icx. task_deps ,
258+ } ;
259+
260+ // Use the ImplicitCtxt while we execute the query
261+ tls:: enter_context ( & new_icx, |_| {
262+ compute ( self . global_tcx ( ) )
263+ } )
264+ } )
265+ }
266+
268267 #[ inline( never) ]
269268 #[ cold]
270269 pub ( super ) fn report_cycle (
@@ -378,7 +377,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
378377 self . sess . profiler ( |p| p. start_query ( Q :: NAME , Q :: CATEGORY ) ) ;
379378
380379 let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
381- job. start ( self , diagnostics, |tcx| {
380+ self . start_query ( job. job . clone ( ) , diagnostics, |tcx| {
382381 tcx. dep_graph . with_anon_task ( dep_node. kind , || {
383382 Q :: compute ( tcx. global_tcx ( ) , key)
384383 } )
@@ -401,16 +400,23 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
401400 }
402401
403402 if !dep_node. kind . is_input ( ) {
404- if let Some ( ( prev_dep_node_index,
405- dep_node_index) ) = self . dep_graph . try_mark_green_and_read ( self ,
406- & dep_node) {
407- return Ok ( self . load_from_disk_and_cache_in_memory :: < Q > (
408- key,
409- job,
410- prev_dep_node_index,
411- dep_node_index,
412- & dep_node
413- ) )
403+ // The diagnostics for this query will be
404+ // promoted to the current session during
405+ // try_mark_green(), so we can ignore them here.
406+ let loaded = self . start_query ( job. job . clone ( ) , None , |tcx| {
407+ let marked = tcx. dep_graph . try_mark_green_and_read ( tcx, & dep_node) ;
408+ marked. map ( |( prev_dep_node_index, dep_node_index) | {
409+ ( tcx. load_from_disk_and_cache_in_memory :: < Q > (
410+ key. clone ( ) ,
411+ prev_dep_node_index,
412+ dep_node_index,
413+ & dep_node
414+ ) , dep_node_index)
415+ } )
416+ } ) ;
417+ if let Some ( ( result, dep_node_index) ) = loaded {
418+ job. complete ( & result, dep_node_index) ;
419+ return Ok ( result) ;
414420 }
415421 }
416422
@@ -422,7 +428,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
422428 fn load_from_disk_and_cache_in_memory < Q : QueryDescription < ' gcx > > (
423429 self ,
424430 key : Q :: Key ,
425- job : JobOwner < ' a , ' gcx , Q > ,
426431 prev_dep_node_index : SerializedDepNodeIndex ,
427432 dep_node_index : DepNodeIndex ,
428433 dep_node : & DepNode
@@ -461,15 +466,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
461466
462467 self . sess . profiler ( |p| p. start_query ( Q :: NAME , Q :: CATEGORY ) ) ;
463468
464- // The diagnostics for this query have already been
465- // promoted to the current session during
466- // try_mark_green(), so we can ignore them here.
467- let result = job. start ( self , None , |tcx| {
468- // The dep-graph for this computation is already in
469- // place
470- tcx. dep_graph . with_ignore ( || {
471- Q :: compute ( tcx, key)
472- } )
469+ // The dep-graph for this computation is already in
470+ // place
471+ let result = self . dep_graph . with_ignore ( || {
472+ Q :: compute ( self , key)
473473 } ) ;
474474
475475 self . sess . profiler ( |p| p. end_query ( Q :: NAME , Q :: CATEGORY ) ) ;
@@ -486,8 +486,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
486486 self . dep_graph . mark_loaded_from_cache ( dep_node_index, true ) ;
487487 }
488488
489- job. complete ( & result, dep_node_index) ;
490-
491489 result
492490 }
493491
@@ -540,7 +538,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
540538 self . sess . profiler ( |p| p. start_query ( Q :: NAME , Q :: CATEGORY ) ) ;
541539
542540 let ( ( result, dep_node_index) , diagnostics) = with_diagnostics ( |diagnostics| {
543- job. start ( self , diagnostics, |tcx| {
541+ self . start_query ( job. job . clone ( ) , diagnostics, |tcx| {
544542 if dep_node. kind . is_eval_always ( ) {
545543 tcx. dep_graph . with_eval_always_task ( dep_node,
546544 tcx,
0 commit comments