Skip to content

Commit 33c9290

Browse files
committed
Simplify debugging options.
1 parent 5c8fdfe commit 33c9290

File tree

1 file changed

+41
-39
lines changed
  • compiler/rustc_query_system/src/dep_graph

1 file changed

+41
-39
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,27 @@ use rustc_data_structures::fingerprint::Fingerprint;
22
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
33
use rustc_data_structures::profiling::QueryInvocationId;
44
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
5-
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, RwLock};
5+
use rustc_data_structures::sync::{AtomicU32, Lock, Lrc, RwLock};
66
use rustc_data_structures::unlikely;
77
use rustc_errors::Diagnostic;
88
use rustc_index::vec::IndexVec;
99
use rustc_serialize::{Encodable, Encoder};
1010

1111
use smallvec::{smallvec, SmallVec};
12-
use std::env;
1312
use std::hash::Hash;
1413
use std::marker::PhantomData;
1514
use std::sync::atomic::Ordering::Relaxed;
1615

17-
use super::debug::EdgeFilter;
1816
use super::query::DepGraphQuery;
1917
use super::serialized::{
2018
CurrentDepGraph, DepNodeColor, DepNodeIndex, SerializedDepGraph, SerializedDepNodeIndex,
2119
};
2220
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
2321
use crate::query::QueryContext;
2422

23+
#[cfg(debug_assertions)]
24+
use {super::debug::EdgeFilter, rustc_data_structures::sync::AtomicU64, std::env};
25+
2526
#[derive(Clone)]
2627
pub struct DepGraph<K: DepKind> {
2728
data: Option<Lrc<DepGraphData<K>>>,
@@ -49,11 +50,6 @@ struct DepGraphData<K: DepKind> {
4950
/// nodes and edges as well as all fingerprints of nodes that have them.
5051
previous: RwLock<CurrentDepGraph<K>>,
5152

52-
/// Used to trap when a specific edge is added to the graph.
53-
/// This is used for debug purposes and is only active with `debug_assertions`.
54-
#[allow(dead_code)]
55-
forbidden_edge: Option<EdgeFilter>,
56-
5753
/// Anonymous `DepNode`s are nodes whose IDs we compute from the list of
5854
/// their edges. This has the beneficial side-effect that multiple anonymous
5955
/// nodes can be coalesced into one without changing the semantics of the
@@ -67,11 +63,6 @@ struct DepGraphData<K: DepKind> {
6763
/// the `DepGraph` is created.
6864
anon_id_seed: Fingerprint,
6965

70-
/// These are simple counters that are for profiling and
71-
/// debugging and only active with `debug_assertions`.
72-
total_read_count: AtomicU64,
73-
total_duplicate_read_count: AtomicU64,
74-
7566
/// A set of loaded diagnostics that is in the progress of being emitted.
7667
emitting_diagnostics: Lock<FxHashSet<DepNodeIndex>>,
7768

@@ -82,6 +73,18 @@ struct DepGraphData<K: DepKind> {
8273
previous_work_products: FxHashMap<WorkProductId, WorkProduct>,
8374

8475
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
76+
77+
/// Used to trap when a specific edge is added to the graph.
78+
/// This is used for debug purposes and is only active with `debug_assertions`.
79+
#[cfg(debug_assertions)]
80+
forbidden_edge: Option<EdgeFilter>,
81+
82+
/// These are simple counters that are for profiling and
83+
/// debugging and only active with `debug_assertions`.
84+
#[cfg(debug_assertions)]
85+
total_read_count: AtomicU64,
86+
#[cfg(debug_assertions)]
87+
total_duplicate_read_count: AtomicU64,
8588
}
8689

8790
pub fn hash_result<HashCtxt, R>(hcx: &mut HashCtxt, result: &R) -> Option<Fingerprint>
@@ -106,28 +109,28 @@ impl<K: DepKind> DepGraph<K> {
106109
let mut stable_hasher = StableHasher::new();
107110
nanos.hash(&mut stable_hasher);
108111

109-
let forbidden_edge = if cfg!(debug_assertions) {
110-
match env::var("RUST_FORBID_DEP_GRAPH_EDGE") {
111-
Ok(s) => match EdgeFilter::new(&s) {
112-
Ok(f) => Some(f),
113-
Err(err) => panic!("RUST_FORBID_DEP_GRAPH_EDGE invalid: {}", err),
114-
},
115-
Err(_) => None,
116-
}
117-
} else {
118-
None
112+
#[cfg(debug_assertions)]
113+
let forbidden_edge = match env::var("RUST_FORBID_DEP_GRAPH_EDGE") {
114+
Ok(s) => match EdgeFilter::new(&s) {
115+
Ok(f) => Some(f),
116+
Err(err) => panic!("RUST_FORBID_DEP_GRAPH_EDGE invalid: {}", err),
117+
},
118+
Err(_) => None,
119119
};
120120

121121
DepGraph {
122122
data: Some(Lrc::new(DepGraphData {
123+
previous: RwLock::new(CurrentDepGraph::new(prev_graph)),
124+
emitting_diagnostics: Default::default(),
123125
previous_work_products: prev_work_products,
124126
dep_node_debug: Default::default(),
125127
anon_id_seed: stable_hasher.finish(),
128+
#[cfg(debug_assertions)]
126129
forbidden_edge,
130+
#[cfg(debug_assertions)]
127131
total_read_count: AtomicU64::new(0),
132+
#[cfg(debug_assertions)]
128133
total_duplicate_read_count: AtomicU64::new(0),
129-
emitting_diagnostics: Default::default(),
130-
previous: RwLock::new(CurrentDepGraph::new(prev_graph)),
131134
})),
132135
virtual_dep_node_index: Lrc::new(AtomicU32::new(0)),
133136
}
@@ -305,14 +308,13 @@ impl<K: DepKind> DepGraph<K> {
305308

306309
#[inline]
307310
pub fn read_index(&self, dep_node_index: DepNodeIndex) {
308-
if let Some(ref data) = self.data {
311+
if let Some(ref _data) = self.data {
309312
K::read_deps(|task_deps| {
310313
if let Some(task_deps) = task_deps {
311314
let mut task_deps = task_deps.lock();
312315
let task_deps = &mut *task_deps;
313-
if cfg!(debug_assertions) {
314-
data.total_read_count.fetch_add(1, Relaxed);
315-
}
316+
#[cfg(debug_assertions)]
317+
_data.total_read_count.fetch_add(1, Relaxed);
316318

317319
// As long as we only have a low number of reads we can avoid doing a hash
318320
// insert and potentially allocating/reallocating the hashmap
@@ -330,18 +332,17 @@ impl<K: DepKind> DepGraph<K> {
330332
}
331333

332334
#[cfg(debug_assertions)]
333-
{
334-
if let Some(target) = task_deps.node {
335-
if let Some(ref forbidden_edge) = data.forbidden_edge {
336-
let src = self.dep_node_of(dep_node_index);
337-
if forbidden_edge.test(&src, &target) {
338-
panic!("forbidden edge {:?} -> {:?} created", src, target)
339-
}
335+
if let Some(target) = task_deps.node {
336+
if let Some(ref forbidden_edge) = _data.forbidden_edge {
337+
let src = self.dep_node_of(dep_node_index);
338+
if forbidden_edge.test(&src, &target) {
339+
panic!("forbidden edge {:?} -> {:?} created", src, target)
340340
}
341341
}
342342
}
343-
} else if cfg!(debug_assertions) {
344-
data.total_duplicate_read_count.fetch_add(1, Relaxed);
343+
} else {
344+
#[cfg(debug_assertions)]
345+
_data.total_duplicate_read_count.fetch_add(1, Relaxed);
345346
}
346347
}
347348
})
@@ -750,7 +751,8 @@ impl<K: DepKind> DepGraph<K> {
750751
eprintln!("[incremental] Total Node Count: {}", total_node_count);
751752
eprintln!("[incremental] Total Edge Count: {}", total_edge_count);
752753

753-
if cfg!(debug_assertions) {
754+
#[cfg(debug_assertions)]
755+
{
754756
let total_edge_reads = data.total_read_count.load(Relaxed);
755757
let total_duplicate_edge_reads = data.total_duplicate_read_count.load(Relaxed);
756758

0 commit comments

Comments
 (0)