@@ -24,6 +24,8 @@ use std::hash::{Hash, Hasher};
2424use std:: mem;
2525use std:: num:: NonZeroU32 ;
2626use std:: ptr;
27+ #[ cfg( debug_assertions) ]
28+ use std:: sync:: atomic:: { AtomicUsize , Ordering } ;
2729
2830pub ( crate ) struct QueryStateShard < ' tcx , D : QueryAccessors < ' tcx > + ?Sized > {
2931 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> {
5153 pub ( super ) cache : D :: Cache ,
5254 pub ( super ) shards : Sharded < QueryStateShard < ' tcx , D > > ,
5355 #[ cfg( debug_assertions) ]
54- pub ( super ) cache_hits : usize ,
56+ pub ( super ) cache_hits : AtomicUsize ,
5557}
5658
5759impl < ' tcx , Q : QueryAccessors < ' tcx > > QueryState < ' tcx , Q > {
@@ -100,7 +102,7 @@ impl<'tcx, M: QueryAccessors<'tcx>> Default for QueryState<'tcx, M> {
100102 cache : M :: Cache :: default ( ) ,
101103 shards : Default :: default ( ) ,
102104 #[ cfg( debug_assertions) ]
103- cache_hits : 0 ,
105+ cache_hits : AtomicUsize :: new ( 0 ) ,
104106 }
105107 }
106108}
@@ -439,6 +441,10 @@ impl<'tcx> TyCtxt<'tcx> {
439441 if unlikely ! ( self . prof. enabled( ) ) {
440442 self . prof . query_cache_hit ( index. into ( ) ) ;
441443 }
444+ #[ cfg( debug_assertions) ]
445+ {
446+ state. cache_hits . fetch_add ( 1 , Ordering :: Relaxed ) ;
447+ }
442448 on_hit ( value, index)
443449 } ,
444450 on_miss,
0 commit comments