Skip to content

Commit 12a17c2

Browse files
committed
Auto merge of rust-lang#135449 - mzacho:current-dep-graph-cfg-debug-assert, r=<try>
Add cfg(debug_assertions) to CurrentDepGraph debug fields The change cascades down to the use sites of the fields. After the change then `dep_graph::serialized::Stat.kind` is dead code in non-debug builds, and it turns out it can be removed entirely, since its value can be read from a HashMap key at the only use site of the field.
2 parents 7a202a9 + a4ef424 commit 12a17c2

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

compiler/rustc_incremental/src/persist/save.rs

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub(crate) fn save_dep_graph(tcx: TyCtxt<'_>) {
4444
sess.time("assert_dep_graph", || assert_dep_graph(tcx));
4545
sess.time("check_dirty_clean", || dirty_clean::check_dirty_clean_annotations(tcx));
4646

47+
#[cfg(debug_assertions)]
4748
if sess.opts.unstable_opts.incremental_info {
4849
tcx.dep_graph.print_incremental_info()
4950
}

compiler/rustc_query_system/src/dep_graph/graph.rs

+13-5
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
})
@@ -960,6 +962,7 @@ impl<D: Deps> DepGraph<D> {
960962
}
961963
}
962964

965+
#[cfg(debug_assertions)]
963966
pub fn print_incremental_info(&self) {
964967
if let Some(data) = &self.data {
965968
data.current.encoder.print_incremental_info(
@@ -1082,7 +1085,10 @@ pub(super) struct CurrentDepGraph<D: Deps> {
10821085

10831086
/// These are simple counters that are for profiling and
10841087
/// debugging and only active with `debug_assertions`.
1088+
#[cfg(debug_assertions)]
10851089
total_read_count: AtomicU64,
1090+
1091+
#[cfg(debug_assertions)]
10861092
total_duplicate_read_count: AtomicU64,
10871093
}
10881094

@@ -1135,7 +1141,9 @@ impl<D: Deps> CurrentDepGraph<D> {
11351141
forbidden_edge,
11361142
#[cfg(debug_assertions)]
11371143
fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)),
1144+
#[cfg(debug_assertions)]
11381145
total_read_count: AtomicU64::new(0),
1146+
#[cfg(debug_assertions)]
11391147
total_duplicate_read_count: AtomicU64::new(0),
11401148
}
11411149
}

compiler/rustc_query_system/src/dep_graph/serialized.rs

+6-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
});
@@ -643,6 +641,7 @@ impl<D: Deps> GraphEncoder<D> {
643641
}
644642
}
645643

644+
#[cfg(debug_assertions)]
646645
pub(crate) fn print_incremental_info(
647646
&self,
648647
total_read_count: u64,
@@ -651,8 +650,8 @@ impl<D: Deps> GraphEncoder<D> {
651650
let mut status = self.status.lock();
652651
let status = status.as_mut().unwrap();
653652
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));
653+
let mut stats: Vec<_> = record_stats.iter().collect();
654+
stats.sort_by_key(|(_, s)| -(s.node_counter as i64));
656655

657656
const SEPARATOR: &str = "[incremental] --------------------------------\
658657
----------------------------------------------\
@@ -677,14 +676,14 @@ impl<D: Deps> GraphEncoder<D> {
677676
);
678677
eprintln!("{SEPARATOR}");
679678

680-
for stat in stats {
679+
for (kind, stat) in stats {
681680
let node_kind_ratio =
682681
(100.0 * (stat.node_counter as f64)) / (status.total_node_count as f64);
683682
let node_kind_avg_edges = (stat.edge_counter as f64) / (stat.node_counter as f64);
684683

685684
eprintln!(
686685
"[incremental] {:<36}|{:>16.1}% |{:>12} |{:>17.1} |",
687-
format!("{:?}", stat.kind),
686+
format!("{:?}", kind),
688687
node_kind_ratio,
689688
stat.node_counter,
690689
node_kind_avg_edges,

0 commit comments

Comments
 (0)