Skip to content

Commit 1bd74a3

Browse files
committed
Add a flag to check depnodes for collisions.
1 parent a3d06f8 commit 1bd74a3

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::Arc;
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,
@@ -1057,6 +1058,11 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10571058
#[cfg(debug_assertions)]
10581059
forbidden_edge: Option<EdgeFilter>,
10591060

1061+
/// Used to verify the absence of hash collisions among DepNodes.
1062+
/// This field is only `Some` if the `-Z incremental_verify_depnodes` option is present.
1063+
#[cfg(debug_assertions)]
1064+
seen_dep_nodes: Option<Lock<FxHashSet<DepNode>>>,
1065+
10601066
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
10611067
/// their edges. This has the beneficial side-effect that multiple anonymous
10621068
/// nodes can be coalesced into one without changing the semantics of the
@@ -1078,7 +1084,7 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10781084

10791085
impl<D: Deps> CurrentDepGraph<D> {
10801086
fn new(
1081-
profiler: &SelfProfilerRef,
1087+
session: &Session,
10821088
prev_graph_node_count: usize,
10831089
encoder: FileEncoder,
10841090
record_graph: bool,
@@ -1110,7 +1116,7 @@ impl<D: Deps> CurrentDepGraph<D> {
11101116
prev_graph_node_count,
11111117
record_graph,
11121118
record_stats,
1113-
profiler,
1119+
&session.prof,
11141120
previous,
11151121
),
11161122
anon_node_to_index: Sharded::new(|| {
@@ -1125,6 +1131,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11251131
forbidden_edge,
11261132
#[cfg(debug_assertions)]
11271133
fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)),
1134+
#[cfg(debug_assertions)]
1135+
seen_dep_nodes: session.opts.unstable_opts.incremental_verify_depnodes.then(|| {
1136+
Lock::new(FxHashSet::with_capacity_and_hasher(
1137+
new_node_count_estimate,
1138+
Default::default(),
1139+
))
1140+
}),
11281141
total_read_count: AtomicU64::new(0),
11291142
total_duplicate_read_count: AtomicU64::new(0),
11301143
}
@@ -1153,6 +1166,13 @@ impl<D: Deps> CurrentDepGraph<D> {
11531166
#[cfg(debug_assertions)]
11541167
self.record_edge(dep_node_index, key, current_fingerprint);
11551168

1169+
#[cfg(debug_assertions)]
1170+
if let Some(ref seen_dep_nodes) = self.seen_dep_nodes {
1171+
if !seen_dep_nodes.lock().insert(key) {
1172+
panic!("Found duplicate dep-node {key:?}");
1173+
}
1174+
}
1175+
11561176
dep_node_index
11571177
}
11581178

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,8 @@ options! {
17591759
incremental_info: bool = (false, parse_bool, [UNTRACKED],
17601760
"print high-level information about incremental reuse (or the lack thereof) \
17611761
(default: no)"),
1762+
incremental_verify_depnodes: bool = (false, parse_bool, [UNTRACKED],
1763+
"verify incr. comp. dep-nodes for hash collisions (default: no)"),
17621764
incremental_verify_ich: bool = (false, parse_bool, [UNTRACKED],
17631765
"verify extended properties for incr. comp. (default: no):
17641766
- hashes of green query instances

0 commit comments

Comments
 (0)