Skip to content

Commit 3c6f620

Browse files
incr.comp.: Add -Zincremental-verify-ich, which allows to perform a consistency check for stored query result fingerprints.
1 parent 81fd279 commit 3c6f620

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
10171017
"print high-level information about incremental reuse (or the lack thereof)"),
10181018
incremental_dump_hash: bool = (false, parse_bool, [UNTRACKED],
10191019
"dump hash information in textual format to stdout"),
1020+
incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
1021+
"verify incr. comp. hashes of green query instances"),
10201022
dump_dep_graph: bool = (false, parse_bool, [UNTRACKED],
10211023
"dump the dependency graph to $RUST_DEP_GRAPH (default: /tmp/dep_graph.gv)"),
10221024
query_dep_graph: bool = (false, parse_bool, [UNTRACKED],

src/librustc/ty/maps/plumbing.rs

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ macro_rules! define_maps {
327327
return Self::load_from_disk_and_cache_in_memory(tcx,
328328
key,
329329
span,
330-
dep_node_index)
330+
dep_node_index,
331+
&dep_node)
331332
}
332333
}
333334

@@ -372,7 +373,8 @@ macro_rules! define_maps {
372373
fn load_from_disk_and_cache_in_memory(tcx: TyCtxt<'a, $tcx, 'lcx>,
373374
key: $K,
374375
span: Span,
375-
dep_node_index: DepNodeIndex)
376+
dep_node_index: DepNodeIndex,
377+
dep_node: &DepNode)
376378
-> Result<$V, CycleError<'a, $tcx>>
377379
{
378380
debug_assert!(tcx.dep_graph.is_green(dep_node_index));
@@ -390,6 +392,32 @@ macro_rules! define_maps {
390392
})
391393
})?;
392394

395+
// If -Zincremental-verify-ich is specified, re-hash results from
396+
// the cache and make sure that they have the expected fingerprint.
397+
if tcx.sess.opts.debugging_opts.incremental_verify_ich {
398+
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
399+
use ich::Fingerprint;
400+
401+
assert!(Some(tcx.dep_graph.fingerprint_of(dep_node)) ==
402+
tcx.dep_graph.prev_fingerprint_of(dep_node),
403+
"Fingerprint for green query instance not loaded \
404+
from cache: {:?}", dep_node);
405+
406+
debug!("BEGIN verify_ich({:?})", dep_node);
407+
let mut hcx = tcx.create_stable_hashing_context();
408+
let mut hasher = StableHasher::new();
409+
410+
result.hash_stable(&mut hcx, &mut hasher);
411+
412+
let new_hash: Fingerprint = hasher.finish();
413+
debug!("END verify_ich({:?})", dep_node);
414+
415+
let old_hash = tcx.dep_graph.fingerprint_of(dep_node);
416+
417+
assert!(new_hash == old_hash, "Found unstable fingerprints \
418+
for {:?}", dep_node);
419+
}
420+
393421
if tcx.sess.opts.debugging_opts.query_dep_graph {
394422
tcx.dep_graph.mark_loaded_from_cache(dep_node_index, true);
395423
}

0 commit comments

Comments
 (0)