@@ -7,6 +7,7 @@ use crate::rustc_middle::ty::TyEncoder;
77use crate :: QueryConfigRestored ;
88use rustc_data_structures:: stable_hasher:: { Hash64 , HashStable , StableHasher } ;
99use rustc_data_structures:: sync:: Lock ;
10+ use rustc_data_structures:: unord:: UnordMap ;
1011use rustc_errors:: DiagInner ;
1112
1213use rustc_index:: Idx ;
@@ -189,6 +190,16 @@ pub(super) fn encode_all_query_results<'tcx>(
189190 }
190191}
191192
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+
192203macro_rules! handle_cycle_error {
193204 ( [ ] ) => { {
194205 rustc_query_system:: HandleCycleError :: Error
@@ -370,6 +381,34 @@ pub(crate) fn encode_query_results<'a, 'tcx, Q>(
370381 } ) ;
371382}
372383
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+
373412fn try_load_from_on_disk_cache < ' tcx , Q > ( query : Q , tcx : TyCtxt < ' tcx > , dep_node : DepNode )
374413where
375414 Q : QueryConfig < QueryCtxt < ' tcx > > ,
@@ -691,6 +730,13 @@ macro_rules! define_queries {
691730 )
692731 }
693732 } }
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+ }
694740 } ) * }
695741
696742 pub ( crate ) fn engine( incremental: bool ) -> QueryEngine {
@@ -730,6 +776,10 @@ macro_rules! define_queries {
730776 >
731777 ] = & [ $( expand_if_cached!( [ $( $modifiers) * ] , query_impl:: $name:: encode_query_results) ) ,* ] ;
732778
779+ const QUERY_KEY_HASH_VERIFY : & [
780+ for <' tcx> fn ( TyCtxt <' tcx>)
781+ ] = & [ $( query_impl:: $name:: query_key_hash_verify) ,* ] ;
782+
733783 #[ allow( nonstandard_style) ]
734784 mod query_callbacks {
735785 use super :: * ;
0 commit comments