@@ -112,11 +112,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
112112 let mut lock = cache. borrow_mut ( ) ;
113113 if let Some ( value) = lock. results . get ( key) {
114114 profq_msg ! ( tcx, ProfileQueriesMsg :: CacheHit ) ;
115- tcx. sess . profiler ( |p| {
116- p. record_query ( Q :: CATEGORY ) ;
117- p. record_query_hit ( Q :: CATEGORY ) ;
118- } ) ;
119-
115+ tcx. sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
120116 let result = Ok ( ( value. value . clone ( ) , value. index ) ) ;
121117 #[ cfg( debug_assertions) ]
122118 {
@@ -195,6 +191,7 @@ impl<'a, 'tcx, Q: QueryDescription<'tcx>> JobOwner<'a, 'tcx, Q> {
195191 /// Executes a job by changing the ImplicitCtxt to point to the
196192 /// new query job while it executes. It returns the diagnostics
197193 /// captured during execution and the actual result.
194+ #[ inline( always) ]
198195 pub ( super ) fn start < ' lcx , F , R > (
199196 & self ,
200197 tcx : TyCtxt < ' _ , ' tcx , ' lcx > ,
@@ -382,13 +379,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
382379 )
383380 ) ;
384381
385- self . sess . profiler ( |p| p. record_query ( Q :: CATEGORY ) ) ;
386-
387382 let job = match JobOwner :: try_get ( self , span, & key) {
388383 TryGetJob :: NotYetStarted ( job) => job,
389384 TryGetJob :: JobCompleted ( result) => {
390385 return result. map ( |( v, index) | {
391- self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
392386 self . dep_graph . read_index ( index) ;
393387 v
394388 } )
@@ -430,9 +424,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
430424
431425 if !dep_node. kind . is_input ( ) {
432426 if let Some ( dep_node_index) = self . try_mark_green_and_read ( & dep_node) {
433- profq_msg ! ( self , ProfileQueriesMsg :: CacheHit ) ;
434- self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
435-
436427 return self . load_from_disk_and_cache_in_memory :: < Q > ( key,
437428 job,
438429 dep_node_index,
@@ -483,11 +474,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
483474 } ;
484475
485476 let result = if let Some ( result) = result {
477+ profq_msg ! ( self , ProfileQueriesMsg :: CacheHit ) ;
478+ self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
479+
486480 result
487481 } else {
488482 // We could not load a result from the on-disk cache, so
489483 // recompute.
490484
485+ self . sess . profiler ( |p| p. start_activity ( Q :: CATEGORY ) ) ;
486+
491487 // The diagnostics for this query have already been
492488 // promoted to the current session during
493489 // try_mark_green(), so we can ignore them here.
@@ -498,6 +494,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
498494 Q :: compute ( tcx, key)
499495 } )
500496 } ) ;
497+
498+ self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
501499 result
502500 } ;
503501
@@ -547,6 +545,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
547545 for {:?}", dep_node) ;
548546 }
549547
548+ #[ inline( always) ]
550549 fn force_query_with_job < Q : QueryDescription < ' gcx > > (
551550 self ,
552551 key : Q :: Key ,
@@ -565,10 +564,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
565564 key, dep_node) ;
566565
567566 profq_msg ! ( self , ProfileQueriesMsg :: ProviderBegin ) ;
568- self . sess . profiler ( |p| {
569- p. start_activity ( Q :: CATEGORY ) ;
570- p. record_query ( Q :: CATEGORY ) ;
571- } ) ;
567+ self . sess . profiler ( |p| p. start_activity ( Q :: CATEGORY ) ) ;
572568
573569 let res = job. start ( self , |tcx| {
574570 if dep_node. kind . is_eval_always ( ) {
@@ -624,14 +620,10 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
624620 // this introduces should be negligible as we'll immediately hit the
625621 // in-memory cache, or another query down the line will.
626622
627- self . sess . profiler ( |p| {
628- p. start_activity ( Q :: CATEGORY ) ;
629- p. record_query ( Q :: CATEGORY ) ;
630- } ) ;
631-
632623 let _ = self . get_query :: < Q > ( DUMMY_SP , key) ;
633-
634- self . sess . profiler ( |p| p. end_activity ( Q :: CATEGORY ) ) ;
624+ } else {
625+ profq_msg ! ( self , ProfileQueriesMsg :: CacheHit ) ;
626+ self . sess . profiler ( |p| p. record_query_hit ( Q :: CATEGORY ) ) ;
635627 }
636628 }
637629
@@ -751,6 +743,17 @@ macro_rules! define_queries_inner {
751743 }
752744 }
753745
746+ pub fn record_computed_queries( & self , sess: & Session ) {
747+ sess. profiler( |p| {
748+ $(
749+ p. record_computed_queries(
750+ <queries:: $name<' _> as QueryConfig <' _>>:: CATEGORY ,
751+ self . $name. lock( ) . results. len( )
752+ ) ;
753+ ) *
754+ } ) ;
755+ }
756+
754757 #[ cfg( parallel_queries) ]
755758 pub fn collect_active_jobs( & self ) -> Vec <Lrc <QueryJob <$tcx>>> {
756759 let mut jobs = Vec :: new( ) ;
0 commit comments