@@ -76,6 +76,9 @@ use std::ops::Deref;
7676use std:: path:: PathBuf ;
7777use std:: sync:: Arc ;
7878
79+ use rustc_data_structures:: fingerprint:: Fingerprint ;
80+ use rustc_query_system:: ich:: StableHashingContext ;
81+
7982#[ derive( Default ) ]
8083pub struct QuerySystem < ' tcx > {
8184 pub arenas : QueryArenas < ' tcx > ,
@@ -477,21 +480,33 @@ macro_rules! define_feedable {
477480 $( impl <' tcx, K : IntoQueryParam <$( $K) * > + Copy > TyCtxtFeed <' tcx, K > {
478481 $( #[ $attr] ) *
479482 #[ inline( always) ]
480- pub fn $name( self , value: query_provided:: $name<' tcx>) -> $V {
483+ pub fn $name( self , value: query_provided:: $name<' tcx>) {
481484 let key = self . key( ) . into_query_param( ) ;
482485
483486 let tcx = self . tcx;
484487 let erased = query_provided_to_value:: $name( tcx, value) ;
485488 let value = restore:: <$V>( erased) ;
486489 let cache = & tcx. query_system. caches. $name;
487490
491+ let hasher: Option <fn ( & mut StableHashingContext <' _>, & _) -> _> = hash_result!( [ $( $modifiers) * ] ) ;
488492 match try_get_cached( tcx, cache, & key) {
489493 Some ( old) => {
490494 let old = restore:: <$V>( old) ;
491- bug!(
492- "Trying to feed an already recorded value for query {} key={key:?}:\n old value: {old:?}\n new value: {value:?}" ,
493- stringify!( $name) ,
494- )
495+ if let Some ( hasher) = hasher {
496+ let ( value_hash, old_hash) : ( Fingerprint , Fingerprint ) = tcx. with_stable_hashing_context( |mut hcx|
497+ ( hasher( & mut hcx, & value) , hasher( & mut hcx, & old) )
498+ ) ;
499+ assert_eq!(
500+ old_hash, value_hash,
501+ "Trying to feed an already recorded value for query {} key={key:?}:\n old value: {old:?}\n new value: {value:?}" ,
502+ stringify!( $name) ,
503+ )
504+ } else {
505+ bug!(
506+ "Trying to feed an already recorded value for query {} key={key:?}:\n old value: {old:?}\n new value: {value:?}" ,
507+ stringify!( $name) ,
508+ )
509+ }
495510 }
496511 None => {
497512 let dep_node = dep_graph:: DepNode :: construct( tcx, dep_graph:: DepKind :: $name, & key) ;
@@ -503,7 +518,6 @@ macro_rules! define_feedable {
503518 hash_result!( [ $( $modifiers) * ] ) ,
504519 ) ;
505520 cache. complete( key, erased, dep_node_index) ;
506- value
507521 }
508522 }
509523 }
0 commit comments