@@ -263,7 +263,18 @@ where
263263 return TryGetJob :: Cycle ( value) ;
264264 }
265265
266- let cached = try_get_cached ( tcx, cache, key, |value, index| ( value. clone ( ) , index) )
266+ let cached = cache
267+ . cache
268+ . lookup ( cache, & key, |value, index| {
269+ if unlikely ! ( tcx. profiler( ) . enabled( ) ) {
270+ tcx. profiler ( ) . query_cache_hit ( index. into ( ) ) ;
271+ }
272+ #[ cfg( debug_assertions) ]
273+ {
274+ cache. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
275+ }
276+ ( value. clone ( ) , index)
277+ } )
267278 . unwrap_or_else ( |_| panic ! ( "value must be in cache after waiting" ) ) ;
268279
269280 if let Some ( prof_timer) = _query_blocked_prof_timer. take ( ) {
@@ -374,7 +385,7 @@ where
374385/// It returns the shard index and a lock guard to the shard,
375386/// which will be used if the query is not in the cache and we need
376387/// to compute it.
377- fn try_get_cached < ' a , CTX , C , R , OnHit > (
388+ pub fn try_get_cached < ' a , CTX , C , R , OnHit > (
378389 tcx : CTX ,
379390 cache : & ' a QueryCacheStore < C > ,
380391 key : & C :: Key ,
@@ -384,7 +395,7 @@ fn try_get_cached<'a, CTX, C, R, OnHit>(
384395where
385396 C : QueryCache ,
386397 CTX : QueryContext ,
387- OnHit : FnOnce ( & C :: Stored , DepNodeIndex ) -> R ,
398+ OnHit : FnOnce ( & C :: Stored ) -> R ,
388399{
389400 cache. cache . lookup ( cache, & key, |value, index| {
390401 if unlikely ! ( tcx. profiler( ) . enabled( ) ) {
@@ -394,7 +405,8 @@ where
394405 {
395406 cache. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
396407 }
397- on_hit ( value, index)
408+ tcx. dep_graph ( ) . read_index ( index) ;
409+ on_hit ( value)
398410 } )
399411}
400412
@@ -632,21 +644,15 @@ fn get_query_impl<CTX, C>(
632644 cache : & QueryCacheStore < C > ,
633645 span : Span ,
634646 key : C :: Key ,
647+ lookup : QueryLookup ,
635648 query : & QueryVtable < CTX , C :: Key , C :: Value > ,
636649) -> C :: Stored
637650where
638651 CTX : QueryContext ,
639652 C : QueryCache ,
640653 C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
641654{
642- let cached = try_get_cached ( tcx, cache, & key, |value, index| {
643- tcx. dep_graph ( ) . read_index ( index) ;
644- value. clone ( )
645- } ) ;
646- match cached {
647- Ok ( value) => value,
648- Err ( lookup) => try_execute_query ( tcx, state, cache, span, key, lookup, query) ,
649- }
655+ try_execute_query ( tcx, state, cache, span, key, lookup, query)
650656}
651657
652658/// Ensure that either this query has all green inputs or been executed.
@@ -705,9 +711,14 @@ fn force_query_impl<CTX, C>(
705711{
706712 // We may be concurrently trying both execute and force a query.
707713 // Ensure that only one of them runs the query.
708-
709- let cached = try_get_cached ( tcx, cache, & key, |_, _| {
710- // Cache hit, do nothing
714+ let cached = cache. cache . lookup ( cache, & key, |_, index| {
715+ if unlikely ! ( tcx. profiler( ) . enabled( ) ) {
716+ tcx. profiler ( ) . query_cache_hit ( index. into ( ) ) ;
717+ }
718+ #[ cfg( debug_assertions) ]
719+ {
720+ cache. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
721+ }
711722 } ) ;
712723
713724 let lookup = match cached {
@@ -731,7 +742,13 @@ pub enum QueryMode {
731742 Ensure ,
732743}
733744
734- pub fn get_query < Q , CTX > ( tcx : CTX , span : Span , key : Q :: Key , mode : QueryMode ) -> Option < Q :: Stored >
745+ pub fn get_query < Q , CTX > (
746+ tcx : CTX ,
747+ span : Span ,
748+ key : Q :: Key ,
749+ lookup : QueryLookup ,
750+ mode : QueryMode ,
751+ ) -> Option < Q :: Stored >
735752where
736753 Q : QueryDescription < CTX > ,
737754 Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
@@ -745,7 +762,8 @@ where
745762 }
746763
747764 debug ! ( "ty::query::get_query<{}>(key={:?}, span={:?})" , Q :: NAME , key, span) ;
748- let value = get_query_impl ( tcx, Q :: query_state ( tcx) , Q :: query_cache ( tcx) , span, key, query) ;
765+ let value =
766+ get_query_impl ( tcx, Q :: query_state ( tcx) , Q :: query_cache ( tcx) , span, key, lookup, query) ;
749767 Some ( value)
750768}
751769
0 commit comments