@@ -24,6 +24,8 @@ use std::hash::{Hash, Hasher};
24
24
use std:: mem;
25
25
use std:: num:: NonZeroU32 ;
26
26
use std:: ptr;
27
+ #[ cfg( debug_assertions) ]
28
+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
27
29
28
30
pub ( crate ) struct QueryStateShard < ' tcx , D : QueryAccessors < ' tcx > + ?Sized > {
29
31
pub ( super ) cache : <<D as QueryAccessors < ' tcx > >:: Cache as QueryCache < D :: Key , D :: Value > >:: Sharded ,
@@ -51,7 +53,7 @@ pub(crate) struct QueryState<'tcx, D: QueryAccessors<'tcx> + ?Sized> {
51
53
pub ( super ) cache : D :: Cache ,
52
54
pub ( super ) shards : Sharded < QueryStateShard < ' tcx , D > > ,
53
55
#[ cfg( debug_assertions) ]
54
- pub ( super ) cache_hits : usize ,
56
+ pub ( super ) cache_hits : AtomicUsize ,
55
57
}
56
58
57
59
impl < ' tcx , Q : QueryAccessors < ' tcx > > QueryState < ' tcx , Q > {
@@ -100,7 +102,7 @@ impl<'tcx, M: QueryAccessors<'tcx>> Default for QueryState<'tcx, M> {
100
102
cache : M :: Cache :: default ( ) ,
101
103
shards : Default :: default ( ) ,
102
104
#[ cfg( debug_assertions) ]
103
- cache_hits : 0 ,
105
+ cache_hits : AtomicUsize :: new ( 0 ) ,
104
106
}
105
107
}
106
108
}
@@ -439,6 +441,10 @@ impl<'tcx> TyCtxt<'tcx> {
439
441
if unlikely ! ( self . prof. enabled( ) ) {
440
442
self . prof . query_cache_hit ( index. into ( ) ) ;
441
443
}
444
+ #[ cfg( debug_assertions) ]
445
+ {
446
+ state. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
447
+ }
442
448
on_hit ( value, index)
443
449
} ,
444
450
on_miss,
0 commit comments