@@ -76,6 +76,9 @@ use std::ops::Deref;
76
76
use std:: path:: PathBuf ;
77
77
use std:: sync:: Arc ;
78
78
79
+ use rustc_data_structures:: fingerprint:: Fingerprint ;
80
+ use rustc_query_system:: ich:: StableHashingContext ;
81
+
79
82
#[ derive( Default ) ]
80
83
pub struct QuerySystem < ' tcx > {
81
84
pub arenas : QueryArenas < ' tcx > ,
@@ -477,21 +480,33 @@ macro_rules! define_feedable {
477
480
$( impl <' tcx, K : IntoQueryParam <$( $K) * > + Copy > TyCtxtFeed <' tcx, K > {
478
481
$( #[ $attr] ) *
479
482
#[ inline( always) ]
480
- pub fn $name( self , value: query_provided:: $name<' tcx>) -> $V {
483
+ pub fn $name( self , value: query_provided:: $name<' tcx>) {
481
484
let key = self . key( ) . into_query_param( ) ;
482
485
483
486
let tcx = self . tcx;
484
487
let erased = query_provided_to_value:: $name( tcx, value) ;
485
488
let value = restore:: <$V>( erased) ;
486
489
let cache = & tcx. query_system. caches. $name;
487
490
491
+ let hasher: Option <fn ( & mut StableHashingContext <' _>, & _) -> _> = hash_result!( [ $( $modifiers) * ] ) ;
488
492
match try_get_cached( tcx, cache, & key) {
489
493
Some ( old) => {
490
494
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
+ }
495
510
}
496
511
None => {
497
512
let dep_node = dep_graph:: DepNode :: construct( tcx, dep_graph:: DepKind :: $name, & key) ;
@@ -503,7 +518,6 @@ macro_rules! define_feedable {
503
518
hash_result!( [ $( $modifiers) * ] ) ,
504
519
) ;
505
520
cache. complete( key, erased, dep_node_index) ;
506
- value
507
521
}
508
522
}
509
523
}
0 commit comments