Skip to content

Commit 545ec63

Browse files
committed
Add a flag to check depnodes for collisions.
1 parent db353ca commit 545ec63

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

compiler/rustc_incremental/src/persist/save.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ pub(crate) fn build_dep_graph(
173173
sess.opts.dep_tracking_hash(false).encode(&mut encoder);
174174

175175
Some(DepGraph::new(
176-
&sess.prof,
176+
sess,
177177
prev_graph,
178178
prev_work_products,
179179
encoder,

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@ use std::sync::atomic::Ordering;
88

99
use rustc_data_structures::fingerprint::Fingerprint;
1010
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
11-
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
11+
use rustc_data_structures::profiling::QueryInvocationId;
1212
use rustc_data_structures::sharded::{self, Sharded};
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
1414
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc};
1515
use rustc_data_structures::unord::UnordMap;
1616
use rustc_index::IndexVec;
1717
use rustc_macros::{Decodable, Encodable};
1818
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
19+
use rustc_session::Session;
1920
use tracing::{debug, instrument};
2021
#[cfg(debug_assertions)]
2122
use {super::debug::EdgeFilter, std::env};
@@ -119,7 +120,7 @@ where
119120

120121
impl<D: Deps> DepGraph<D> {
121122
pub fn new(
122-
profiler: &SelfProfilerRef,
123+
session: &Session,
123124
prev_graph: Arc<SerializedDepGraph>,
124125
prev_work_products: WorkProductMap,
125126
encoder: FileEncoder,
@@ -129,7 +130,7 @@ impl<D: Deps> DepGraph<D> {
129130
let prev_graph_node_count = prev_graph.node_count();
130131

131132
let current = CurrentDepGraph::new(
132-
profiler,
133+
session,
133134
prev_graph_node_count,
134135
encoder,
135136
record_graph,
@@ -1047,6 +1048,11 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10471048
#[cfg(debug_assertions)]
10481049
forbidden_edge: Option<EdgeFilter>,
10491050

1051+
/// Used to verify the absence of hash collisions among DepNodes.
1052+
/// This field is only `Some` if the `-Z incremental_verify_depnodes` option is present.
1053+
#[cfg(debug_assertions)]
1054+
seen_dep_nodes: Option<Lock<FxHashSet<DepNode>>>,
1055+
10501056
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
10511057
/// their edges. This has the beneficial side-effect that multiple anonymous
10521058
/// nodes can be coalesced into one without changing the semantics of the
@@ -1068,7 +1074,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10681074

10691075
impl<D: Deps> CurrentDepGraph<D> {
10701076
fn new(
1071-
profiler: &SelfProfilerRef,
1077+
session: &Session,
10721078
prev_graph_node_count: usize,
10731079
encoder: FileEncoder,
10741080
record_graph: bool,
@@ -1100,7 +1106,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11001106
prev_graph_node_count,
11011107
record_graph,
11021108
record_stats,
1103-
profiler,
1109+
&session.prof,
11041110
previous,
11051111
),
11061112
anon_node_to_index: Sharded::new(|| {
@@ -1115,6 +1121,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11151121
forbidden_edge,
11161122
#[cfg(debug_assertions)]
11171123
fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)),
1124+
#[cfg(debug_assertions)]
1125+
seen_dep_nodes: session.opts.unstable_opts.incremental_verify_depnodes.then(|| {
1126+
Lock::new(FxHashSet::with_capacity_and_hasher(
1127+
new_node_count_estimate,
1128+
Default::default(),
1129+
))
1130+
}),
11181131
total_read_count: AtomicU64::new(0),
11191132
total_duplicate_read_count: AtomicU64::new(0),
11201133
}
@@ -1143,6 +1156,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11431156
#[cfg(debug_assertions)]
11441157
self.record_edge(dep_node_index, key, current_fingerprint);
11451158

1159+
#[cfg(debug_assertions)]
1160+
if let Some(ref seen_dep_nodes) = self.seen_dep_nodes {
1161+
if !seen_dep_nodes.lock().insert(key) {
1162+
panic!("Found duplicate dep-node {key:?}");
1163+
}
1164+
}
1165+
11461166
dep_node_index
11471167
}
11481168

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,8 @@ options! {
18201820
incremental_info: bool = (false, parse_bool, [UNTRACKED],
18211821
"print high-level information about incremental reuse (or the lack thereof) \
18221822
(default: no)"),
1823+
incremental_verify_depnodes: bool = (false, parse_bool, [UNTRACKED],
1824+
"verify incr. comp. dep-nodes for hash collisions (default: no)"),
18231825
incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
18241826
"verify extended properties for incr. comp. (default: no):
18251827
- hashes of green query instances

0 commit comments

Comments
 (0)