@@ -533,7 +533,13 @@ where
533
533
None
534
534
} ;
535
535
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
+
537
543
result
538
544
} else {
539
545
// We could not load a result from the on-disk cache, so
@@ -545,20 +551,21 @@ where
545
551
546
552
prof_timer. finish_with_query_invocation_id ( dep_node_index. into ( ) ) ;
547
553
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
554
563
incremental_verify_ich ( * tcx. dep_context ( ) , & result, dep_node, dep_node_index, query) ;
555
- }
556
564
557
- result
565
+ result
566
+ }
558
567
}
559
568
560
- #[ inline( never) ]
561
- #[ cold]
562
569
fn incremental_verify_ich < CTX , K , V : Debug > (
563
570
tcx : CTX :: DepContext ,
564
571
result : & V ,
0 commit comments