Skip to content

Commit ff296f4

Browse files
committed
Add cfg(debug_assertions) to CurrentDepGraph debug fields
1 parent 7a202a9 commit ff296f4

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

compiler/rustc_query_system/src/dep_graph/graph.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1111
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
1212
use rustc_data_structures::sharded::{self, Sharded};
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
14-
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc};
14+
#[cfg(debug_assertions)]
15+
use rustc_data_structures::sync::AtomicU64;
16+
use rustc_data_structures::sync::{AtomicU32, Lock, Lrc};
1517
use rustc_data_structures::unord::UnordMap;
1618
use rustc_index::IndexVec;
1719
use rustc_macros::{Decodable, Encodable};
@@ -484,9 +486,8 @@ impl<D: Deps> DepGraph<D> {
484486
};
485487
let task_deps = &mut *task_deps;
486488

487-
if cfg!(debug_assertions) {
488-
data.current.total_read_count.fetch_add(1, Ordering::Relaxed);
489-
}
489+
#[cfg(debug_assertions)]
490+
data.current.total_read_count.fetch_add(1, Ordering::Relaxed);
490491

491492
// As long as we only have a low number of reads we can avoid doing a hash
492493
// insert and potentially allocating/reallocating the hashmap
@@ -514,7 +515,8 @@ impl<D: Deps> DepGraph<D> {
514515
}
515516
}
516517
}
517-
} else if cfg!(debug_assertions) {
518+
} else {
519+
#[cfg(debug_assertions)]
518520
data.current.total_duplicate_read_count.fetch_add(1, Ordering::Relaxed);
519521
}
520522
})
@@ -962,10 +964,13 @@ impl<D: Deps> DepGraph<D> {
962964

963965
pub fn print_incremental_info(&self) {
964966
if let Some(data) = &self.data {
967+
#[cfg(debug_assertions)]
965968
data.current.encoder.print_incremental_info(
966969
data.current.total_read_count.load(Ordering::Relaxed),
967970
data.current.total_duplicate_read_count.load(Ordering::Relaxed),
968-
)
971+
);
972+
#[cfg(not(debug_assertions))]
973+
data.current.encoder.print_incremental_info(0, 0)
969974
}
970975
}
971976

@@ -1082,7 +1087,10 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10821087

10831088
/// These are simple counters that are for profiling and
10841089
/// debugging and only active with `debug_assertions`.
1090+
#[cfg(debug_assertions)]
10851091
total_read_count: AtomicU64,
1092+
1093+
#[cfg(debug_assertions)]
10861094
total_duplicate_read_count: AtomicU64,
10871095
}
10881096

@@ -1135,7 +1143,9 @@ impl<D: Deps> CurrentDepGraph<D> {
11351143
forbidden_edge,
11361144
#[cfg(debug_assertions)]
11371145
fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)),
1146+
#[cfg(debug_assertions)]
11381147
total_read_count: AtomicU64::new(0),
1148+
#[cfg(debug_assertions)]
11391149
total_duplicate_read_count: AtomicU64::new(0),
11401150
}
11411151
}

compiler/rustc_query_system/src/dep_graph/serialized.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ impl NodeInfo {
462462
}
463463

464464
struct Stat {
465-
kind: DepKind,
466465
node_counter: u64,
467466
edge_counter: u64,
468467
}
@@ -524,8 +523,7 @@ impl<D: Deps> EncoderState<D> {
524523

525524
// Outline the stats code as it's typically disabled and cold.
526525
outline(move || {
527-
let stat =
528-
stats.entry(kind).or_insert(Stat { kind, node_counter: 0, edge_counter: 0 });
526+
let stat = stats.entry(kind).or_insert(Stat { node_counter: 0, edge_counter: 0 });
529527
stat.node_counter += 1;
530528
stat.edge_counter += edge_count as u64;
531529
});
@@ -651,8 +649,8 @@ impl<D: Deps> GraphEncoder<D> {
651649
let mut status = self.status.lock();
652650
let status = status.as_mut().unwrap();
653651
if let Some(record_stats) = &status.stats {
654-
let mut stats: Vec<_> = record_stats.values().collect();
655-
stats.sort_by_key(|s| -(s.node_counter as i64));
652+
let mut stats: Vec<_> = record_stats.iter().collect();
653+
stats.sort_by_key(|(_, s)| -(s.node_counter as i64));
656654

657655
const SEPARATOR: &str = "[incremental] --------------------------------\
658656
----------------------------------------------\
@@ -677,14 +675,14 @@ impl<D: Deps> GraphEncoder<D> {
677675
);
678676
eprintln!("{SEPARATOR}");
679677

680-
for stat in stats {
678+
for (kind, stat) in stats {
681679
let node_kind_ratio =
682680
(100.0 * (stat.node_counter as f64)) / (status.total_node_count as f64);
683681
let node_kind_avg_edges = (stat.edge_counter as f64) / (stat.node_counter as f64);
684682

685683
eprintln!(
686684
"[incremental] {:<36}|{:>16.1}% |{:>12} |{:>17.1} |",
687-
format!("{:?}", stat.kind),
685+
format!("{:?}", kind),
688686
node_kind_ratio,
689687
stat.node_counter,
690688
node_kind_avg_edges,

0 commit comments

Comments
 (0)