@@ -15,6 +15,7 @@ use rustc_data_structures::fx::FxHashMap;
1515use rustc_data_structures:: profiling:: TimingGuard ;
1616#[ cfg( parallel_compiler) ]
1717use rustc_data_structures:: sharded:: Sharded ;
18+ use rustc_data_structures:: stack:: ensure_sufficient_stack;
1819use rustc_data_structures:: sync:: Lock ;
1920use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed , FatalError } ;
2021use rustc_session:: Session ;
@@ -188,12 +189,12 @@ where
188189 #[ cfg( not( parallel_compiler) ) ]
189190 let mut state_lock = state. active . lock ( ) ;
190191 let lock = & mut * state_lock;
192+ let current_job_id = qcx. current_query_job ( ) ;
191193
192194 match lock. entry ( key) {
193195 Entry :: Vacant ( entry) => {
194196 let id = qcx. next_job_id ( ) ;
195- let job = qcx. current_query_job ( ) ;
196- let job = QueryJob :: new ( id, span, job) ;
197+ let job = QueryJob :: new ( id, span, current_job_id) ;
197198
198199 let key = * entry. key ( ) ;
199200 entry. insert ( QueryResult :: Started ( job) ) ;
@@ -212,7 +213,7 @@ where
212213 // so we just return the error.
213214 return TryGetJob :: Cycle ( id. find_cycle_in_stack (
214215 qcx. try_collect_active_jobs ( ) . unwrap ( ) ,
215- & qcx . current_query_job ( ) ,
216+ & current_job_id ,
216217 span,
217218 ) ) ;
218219 }
@@ -230,7 +231,7 @@ where
230231
231232 // With parallel queries we might just have to wait on some other
232233 // thread.
233- let result = latch. wait_on ( qcx . current_query_job ( ) , span) ;
234+ let result = latch. wait_on ( current_job_id , span) ;
234235
235236 match result {
236237 Ok ( ( ) ) => TryGetJob :: JobCompleted ( query_blocked_prof_timer) ,
@@ -346,10 +347,9 @@ where
346347 }
347348}
348349
350+ #[ inline( never) ]
349351fn try_execute_query < Q , Qcx > (
350352 qcx : Qcx ,
351- state : & QueryState < Q :: Key , Qcx :: DepKind > ,
352- cache : & Q :: Cache ,
353353 span : Span ,
354354 key : Q :: Key ,
355355 dep_node : Option < DepNode < Qcx :: DepKind > > ,
@@ -358,9 +358,11 @@ where
358358 Q : QueryConfig < Qcx > ,
359359 Qcx : QueryContext ,
360360{
361+ let state = Q :: query_state ( qcx) ;
361362 match JobOwner :: < ' _ , Q :: Key , Qcx :: DepKind > :: try_start ( & qcx, state, span, key) {
362363 TryGetJob :: NotYetStarted ( job) => {
363364 let ( result, dep_node_index) = execute_job :: < Q , Qcx > ( qcx, key, dep_node, job. id ) ;
365+ let cache = Q :: query_cache ( qcx) ;
364366 if Q :: FEEDABLE {
365367 // We should not compute queries that also got a value via feeding.
366368 // This can't happen, as query feeding adds the very dependencies to the fed query
@@ -381,7 +383,7 @@ where
381383 }
382384 #[ cfg( parallel_compiler) ]
383385 TryGetJob :: JobCompleted ( query_blocked_prof_timer) => {
384- let Some ( ( v, index) ) = cache . lookup ( & key) else {
386+ let Some ( ( v, index) ) = Q :: query_cache ( qcx ) . lookup ( & key) else {
385387 panic ! ( "value must be in cache after waiting" )
386388 } ;
387389
@@ -393,6 +395,7 @@ where
393395 }
394396}
395397
398+ #[ inline( always) ]
396399fn execute_job < Q , Qcx > (
397400 qcx : Qcx ,
398401 key : Q :: Key ,
@@ -478,6 +481,7 @@ where
478481 ( result, dep_node_index)
479482}
480483
484+ #[ inline( always) ]
481485fn try_load_from_disk_and_cache_in_memory < Q , Qcx > (
482486 qcx : Qcx ,
483487 key : & Q :: Key ,
@@ -568,6 +572,7 @@ where
568572 Some ( ( result, dep_node_index) )
569573}
570574
575+ #[ inline]
571576#[ instrument( skip( tcx, result, hash_result) , level = "debug" ) ]
572577pub ( crate ) fn incremental_verify_ich < Tcx , V : Debug > (
573578 tcx : Tcx ,
@@ -722,6 +727,7 @@ pub enum QueryMode {
722727 Ensure ,
723728}
724729
730+ #[ inline( always) ]
725731pub fn get_query < Q , Qcx , D > ( qcx : Qcx , span : Span , key : Q :: Key , mode : QueryMode ) -> Option < Q :: Value >
726732where
727733 D : DepKind ,
@@ -739,14 +745,8 @@ where
739745 None
740746 } ;
741747
742- let ( result, dep_node_index) = try_execute_query :: < Q , Qcx > (
743- qcx,
744- Q :: query_state ( qcx) ,
745- Q :: query_cache ( qcx) ,
746- span,
747- key,
748- dep_node,
749- ) ;
748+ let ( result, dep_node_index) =
749+ ensure_sufficient_stack ( || try_execute_query :: < Q , Qcx > ( qcx, span, key, dep_node) ) ;
750750 if let Some ( dep_node_index) = dep_node_index {
751751 qcx. dep_context ( ) . dep_graph ( ) . read_index ( dep_node_index)
752752 }
@@ -762,14 +762,12 @@ where
762762{
763763 // We may be concurrently trying both execute and force a query.
764764 // Ensure that only one of them runs the query.
765- let cache = Q :: query_cache ( qcx) ;
766- if let Some ( ( _, index) ) = cache. lookup ( & key) {
765+ if let Some ( ( _, index) ) = Q :: query_cache ( qcx) . lookup ( & key) {
767766 qcx. dep_context ( ) . profiler ( ) . query_cache_hit ( index. into ( ) ) ;
768767 return ;
769768 }
770769
771- let state = Q :: query_state ( qcx) ;
772770 debug_assert ! ( !Q :: ANON ) ;
773771
774- try_execute_query :: < Q , _ > ( qcx, state , cache , DUMMY_SP , key, Some ( dep_node) ) ;
772+ ensure_sufficient_stack ( || try_execute_query :: < Q , _ > ( qcx, DUMMY_SP , key, Some ( dep_node) ) ) ;
775773}
0 commit comments