Skip to content

Commit e7e1dc1

Browse files
committed
Auto merge of #83007 - Aaron1011:incr-verify-default, r=Mark-Simulacrum
Turn `-Z incremental-verify-ich` on by default Issue #82920 showed that the kind of bugs caught by this flag have soundness implications.
2 parents 56f74c5 + 7d7c81a commit e7e1dc1

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

compiler/rustc_query_system/src/query/plumbing.rs

+18-11
Original file line numberDiff line numberDiff line change
@@ -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]
562569
fn incremental_verify_ich<CTX, K, V: Debug>(
563570
tcx: CTX::DepContext,
564571
result: &V,

0 commit comments

Comments
 (0)