@@ -7,6 +7,7 @@ use crate::rustc_middle::ty::TyEncoder;
7
7
use crate :: QueryConfigRestored ;
8
8
use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
9
9
use rustc_data_structures:: sync:: Lock ;
10
+ use rustc_data_structures:: unord:: UnordMap ;
10
11
use rustc_errors:: DiagInner ;
11
12
12
13
use rustc_index:: Idx ;
@@ -189,6 +190,16 @@ pub(super) fn encode_all_query_results<'tcx>(
189
190
}
190
191
}
191
192
193
+ pub fn query_key_hash_verify_all < ' tcx > ( tcx : TyCtxt < ' tcx > ) {
194
+ if tcx. sess ( ) . opts . unstable_opts . incremental_verify_ich || cfg ! ( debug_assertions) {
195
+ tcx. sess . time ( "query_key_hash_verify_all" , || {
196
+ for verify in super :: QUERY_KEY_HASH_VERIFY . iter ( ) {
197
+ verify ( tcx) ;
198
+ }
199
+ } )
200
+ }
201
+ }
202
+
192
203
macro_rules! handle_cycle_error {
193
204
( [ ] ) => { {
194
205
rustc_query_system:: HandleCycleError :: Error
@@ -370,6 +381,34 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
370
381
} ) ;
371
382
}
372
383
384
+ pub ( crate ) fn query_key_hash_verify < ' tcx > (
385
+ query : impl QueryConfig < QueryCtxt < ' tcx > > ,
386
+ qcx : QueryCtxt < ' tcx > ,
387
+ ) {
388
+ let _timer =
389
+ qcx. profiler ( ) . generic_activity_with_arg ( "query_key_hash_verify_for" , query. name ( ) ) ;
390
+
391
+ let mut map = UnordMap :: default ( ) ;
392
+
393
+ let cache = query. query_cache ( qcx) ;
394
+ cache. iter ( & mut |key, _, _| {
395
+ let node = DepNode :: construct ( qcx. tcx , query. dep_kind ( ) , key) ;
396
+ if let Some ( other_key) = map. insert ( node, * key) {
397
+ bug ! (
398
+ "query key:\n \
399
+ `{:?}`\n \
400
+ and key:\n \
401
+ `{:?}`\n \
402
+ mapped to the same dep node:\n \
403
+ {:?}",
404
+ key,
405
+ other_key,
406
+ node
407
+ ) ;
408
+ }
409
+ } ) ;
410
+ }
411
+
373
412
fn try_load_from_on_disk_cache < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode )
374
413
where
375
414
Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -691,6 +730,13 @@ macro_rules! define_queries {
691
730
)
692
731
}
693
732
} }
733
+
734
+ pub fn query_key_hash_verify<' tcx>( tcx: TyCtxt <' tcx>) {
735
+ $crate:: plumbing:: query_key_hash_verify(
736
+ query_impl:: $name:: QueryType :: config( tcx) ,
737
+ QueryCtxt :: new( tcx) ,
738
+ )
739
+ }
694
740
} ) * }
695
741
696
742
pub ( crate ) fn engine( incremental: bool ) -> QueryEngine {
@@ -730,6 +776,10 @@ macro_rules! define_queries {
730
776
>
731
777
] = & [ $( expand_if_cached!( [ $( $modifiers) * ] , query_impl:: $name:: encode_query_results) ) ,* ] ;
732
778
779
+ const QUERY_KEY_HASH_VERIFY : & [
780
+ for <' tcx> fn ( TyCtxt <' tcx>)
781
+ ] = & [ $( query_impl:: $name:: query_key_hash_verify) ,* ] ;
782
+
733
783
#[ allow( nonstandard_style) ]
734
784
mod query_callbacks {
735
785
use super :: * ;
0 commit comments