@@ -263,7 +263,18 @@ where
263
263
return TryGetJob :: Cycle ( value) ;
264
264
}
265
265
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
+ } )
267
278
. unwrap_or_else ( |_| panic ! ( "value must be in cache after waiting" ) ) ;
268
279
269
280
if let Some ( prof_timer) = _query_blocked_prof_timer. take ( ) {
@@ -374,7 +385,7 @@ where
374
385
/// It returns the shard index and a lock guard to the shard,
375
386
/// which will be used if the query is not in the cache and we need
376
387
/// to compute it.
377
- fn try_get_cached < ' a , CTX , C , R , OnHit > (
388
+ pub fn try_get_cached < ' a , CTX , C , R , OnHit > (
378
389
tcx : CTX ,
379
390
cache : & ' a QueryCacheStore < C > ,
380
391
key : & C :: Key ,
@@ -384,7 +395,7 @@ fn try_get_cached<'a, CTX, C, R, OnHit>(
384
395
where
385
396
C : QueryCache ,
386
397
CTX : QueryContext ,
387
- OnHit : FnOnce ( & C :: Stored , DepNodeIndex ) -> R ,
398
+ OnHit : FnOnce ( & C :: Stored ) -> R ,
388
399
{
389
400
cache. cache . lookup ( cache, & key, |value, index| {
390
401
if unlikely ! ( tcx. profiler( ) . enabled( ) ) {
@@ -394,7 +405,8 @@ where
394
405
{
395
406
cache. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
396
407
}
397
- on_hit ( value, index)
408
+ tcx. dep_graph ( ) . read_index ( index) ;
409
+ on_hit ( value)
398
410
} )
399
411
}
400
412
@@ -632,21 +644,15 @@ fn get_query_impl<CTX, C>(
632
644
cache : & QueryCacheStore < C > ,
633
645
span : Span ,
634
646
key : C :: Key ,
647
+ lookup : QueryLookup ,
635
648
query : & QueryVtable < CTX , C :: Key , C :: Value > ,
636
649
) -> C :: Stored
637
650
where
638
651
CTX : QueryContext ,
639
652
C : QueryCache ,
640
653
C :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
641
654
{
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)
650
656
}
651
657
652
658
/// Ensure that either this query has all green inputs or been executed.
@@ -705,9 +711,14 @@ fn force_query_impl<CTX, C>(
705
711
{
706
712
// We may be concurrently trying both execute and force a query.
707
713
// 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
+ }
711
722
} ) ;
712
723
713
724
let lookup = match cached {
@@ -731,7 +742,13 @@ pub enum QueryMode {
731
742
Ensure ,
732
743
}
733
744
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 >
735
752
where
736
753
Q : QueryDescription < CTX > ,
737
754
Q :: Key : crate :: dep_graph:: DepNodeParams < CTX > ,
@@ -745,7 +762,8 @@ where
745
762
}
746
763
747
764
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) ;
749
767
Some ( value)
750
768
}
751
769
0 commit comments