@@ -20,6 +20,7 @@ use rustc_data_structures::sync::Lock;
2020use rustc_errors:: { DiagnosticBuilder , ErrorGuaranteed , FatalError } ;
2121use rustc_session:: Session ;
2222use rustc_span:: { Span , DUMMY_SP } ;
23+ use std:: borrow:: Borrow ;
2324use std:: cell:: Cell ;
2425use std:: collections:: hash_map:: Entry ;
2526use std:: fmt:: Debug ;
@@ -370,11 +371,26 @@ where
370371 C : QueryCache ,
371372 C :: Key : Clone + DepNodeParams < Qcx :: DepContext > ,
372373 C :: Value : Value < Qcx :: DepContext > ,
374+ C :: Stored : Debug + std:: borrow:: Borrow < C :: Value > ,
373375 Qcx : QueryContext ,
374376{
375377 match JobOwner :: < ' _ , C :: Key > :: try_start ( & qcx, state, span, key. clone ( ) ) {
376378 TryGetJob :: NotYetStarted ( job) => {
377- let ( result, dep_node_index) = execute_job ( qcx, key, dep_node, query, job. id ) ;
379+ let ( result, dep_node_index) = execute_job ( qcx, key. clone ( ) , dep_node, query, job. id ) ;
380+ if query. feedable {
381+ // We may have put a value inside the cache from inside the execution.
382+ // Verify that it has the same hash as what we have now, to ensure consistency.
383+ let _ = cache. lookup ( & key, |cached_result, _| {
384+ let hasher = query. hash_result . expect ( "feedable forbids no_hash" ) ;
385+ let old_hash = qcx. dep_context ( ) . with_stable_hashing_context ( |mut hcx| hasher ( & mut hcx, cached_result. borrow ( ) ) ) ;
386+ let new_hash = qcx. dep_context ( ) . with_stable_hashing_context ( |mut hcx| hasher ( & mut hcx, & result) ) ;
387+ debug_assert_eq ! (
388+ old_hash, new_hash,
389+ "Computed query value for {:?}({:?}) is inconsistent with fed value,\n computed={:#?}\n fed={:#?}" ,
390+ query. dep_kind, key, result, cached_result,
391+ ) ;
392+ } ) ;
393+ }
378394 let result = job. complete ( cache, result, dep_node_index) ;
379395 ( result, Some ( dep_node_index) )
380396 }
0 commit comments