Skip to content

Commit ee7a9a8

Browse files
committed
Expand hash check.
1 parent 5471381 commit ee7a9a8

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -513,15 +513,18 @@ impl<K: DepKind> DepGraph<K> {
513513
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Fingerprint,
514514
) -> DepNodeIndex {
515515
if let Some(data) = self.data.as_ref() {
516+
// The caller query has more dependencies than the node we are creating. We may
517+
// encounter a case where this created node is marked as green, but the caller query is
518+
// subsequently marked as red or recomputed. In this case, we will end up feeding a
519+
// value to an existing node.
520+
//
521+
// For sanity, we still check that the loaded stable hash and the new one match.
516522
if let Some(dep_node_index) = self.dep_node_index_of_opt(&node) {
523+
let _current_fingerprint =
524+
crate::query::incremental_verify_ich(cx, result, &node, Some(hash_result));
525+
517526
#[cfg(debug_assertions)]
518-
{
519-
let hashing_timer = cx.profiler().incr_result_hashing();
520-
let current_fingerprint =
521-
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result));
522-
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
523-
data.current.record_edge(dep_node_index, node, current_fingerprint);
524-
}
527+
data.current.record_edge(dep_node_index, node, _current_fingerprint);
525528

526529
return dep_node_index;
527530
}

compiler/rustc_query_system/src/query/plumbing.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! manage the caches, and so forth.
44
55
use crate::dep_graph::{DepContext, DepNode, DepNodeIndex, DepNodeParams};
6+
use crate::ich::StableHashingContext;
67
use crate::query::caches::QueryCache;
78
use crate::query::config::QueryVTable;
89
use crate::query::job::{report_cycle, QueryInfo, QueryJob, QueryJobId, QueryJobInfo};
@@ -525,7 +526,7 @@ where
525526
if std::intrinsics::unlikely(
526527
try_verify || qcx.dep_context().sess().opts.unstable_opts.incremental_verify_ich,
527528
) {
528-
incremental_verify_ich(*qcx.dep_context(), &result, dep_node, query);
529+
incremental_verify_ich(*qcx.dep_context(), &result, dep_node, query.hash_result);
529530
}
530531

531532
return Some((result, dep_node_index));
@@ -558,39 +559,42 @@ where
558559
//
559560
// See issue #82920 for an example of a miscompilation that would get turned into
560561
// an ICE by this check
561-
incremental_verify_ich(*qcx.dep_context(), &result, dep_node, query);
562+
incremental_verify_ich(*qcx.dep_context(), &result, dep_node, query.hash_result);
562563

563564
Some((result, dep_node_index))
564565
}
565566

566-
#[instrument(skip(qcx, result, query), level = "debug")]
567-
fn incremental_verify_ich<Qcx, K, V: Debug>(
568-
qcx: Qcx::DepContext,
567+
#[instrument(skip(tcx, result, hash_result), level = "debug")]
568+
pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
569+
tcx: Tcx,
569570
result: &V,
570-
dep_node: &DepNode<Qcx::DepKind>,
571-
query: &QueryVTable<Qcx, K, V>,
572-
) where
573-
Qcx: QueryContext,
571+
dep_node: &DepNode<Tcx::DepKind>,
572+
hash_result: Option<fn(&mut StableHashingContext<'_>, &V) -> Fingerprint>,
573+
) -> Fingerprint
574+
where
575+
Tcx: DepContext,
574576
{
575577
assert!(
576-
qcx.dep_graph().is_green(dep_node),
578+
tcx.dep_graph().is_green(dep_node),
577579
"fingerprint for green query instance not loaded from cache: {:?}",
578580
dep_node,
579581
);
580582

581-
let new_hash = query.hash_result.map_or(Fingerprint::ZERO, |f| {
582-
qcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result))
583+
let new_hash = hash_result.map_or(Fingerprint::ZERO, |f| {
584+
tcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, result))
583585
});
584586

585-
let old_hash = qcx.dep_graph().prev_fingerprint_of(dep_node);
587+
let old_hash = tcx.dep_graph().prev_fingerprint_of(dep_node);
586588

587589
if Some(new_hash) != old_hash {
588590
incremental_verify_ich_failed(
589-
qcx.sess(),
591+
tcx.sess(),
590592
DebugArg::from(&dep_node),
591593
DebugArg::from(&result),
592594
);
593595
}
596+
597+
new_hash
594598
}
595599

596600
// This DebugArg business is largely a mirror of std::fmt::ArgumentV1, which is

0 commit comments

Comments
 (0)