@@ -533,7 +533,13 @@ where
533533 None
534534 } ;
535535
536- let result = if let Some ( result) = result {
536+ if let Some ( result) = result {
537+ // If `-Zincremental-verify-ich` is specified, re-hash results from
538+ // the cache and make sure that they have the expected fingerprint.
539+ if unlikely ! ( tcx. dep_context( ) . sess( ) . opts. debugging_opts. incremental_verify_ich) {
540+ incremental_verify_ich ( * tcx. dep_context ( ) , & result, dep_node, dep_node_index, query) ;
541+ }
542+
537543 result
538544 } else {
539545 // We could not load a result from the on-disk cache, so
@@ -545,20 +551,21 @@ where
545551
546552 prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
547553
548- result
549- } ;
550-
551- // If `-Zincremental-verify-ich` is specified, re-hash results from
552- // the cache and make sure that they have the expected fingerprint.
553- if unlikely ! ( tcx. dep_context( ) . sess( ) . opts. debugging_opts. incremental_verify_ich) {
554+ // Verify that re-running the query produced a result with the expected hash
555+ // This catches bugs in query implementations, turning them into ICEs.
556+ // For example, a query might sort its result by `DefId` - since `DefId`s are
557+ // not stable across compilation sessions, the result could get up getting sorted
558+ // in a different order when the query is re-run, even though all of the inputs
559+ // (e.g. `DefPathHash` values) were green.
560+ //
561+ // See issue #82920 for an example of a miscompilation that would get turned into
562+ // an ICE by this check
554563 incremental_verify_ich ( * tcx. dep_context ( ) , & result, dep_node, dep_node_index, query) ;
555- }
556564
557- result
565+ result
566+ }
558567}
559568
560- #[ inline( never) ]
561- #[ cold]
562569fn incremental_verify_ich < CTX , K , V : Debug > (
563570 tcx : CTX :: DepContext ,
564571 result : & V ,
0 commit comments