Outline some cold code and turn on hash collision detection with debug_assertions

This commit is contained in:
John Kåre Alsaker 2025-03-18 00:05:45 +01:00
parent 5a21f890e9
commit e70cafec4e

View File

@ -8,6 +8,7 @@ use std::sync::atomic::{AtomicU32, Ordering};
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::outline;
use rustc_data_structures::profiling::QueryInvocationId; use rustc_data_structures::profiling::QueryInvocationId;
use rustc_data_structures::sharded::{self, Sharded}; use rustc_data_structures::sharded::{self, Sharded};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@ -675,8 +676,10 @@ impl<D: Deps> DepGraphData<D> {
} else if let Some(nodes_newly_allocated_in_current_session) = } else if let Some(nodes_newly_allocated_in_current_session) =
&self.current.nodes_newly_allocated_in_current_session &self.current.nodes_newly_allocated_in_current_session
{ {
let seen = nodes_newly_allocated_in_current_session.lock().contains(dep_node); outline(|| {
assert!(!seen, "{}", msg()); let seen = nodes_newly_allocated_in_current_session.lock().contains(dep_node);
assert!(!seen, "{}", msg());
});
} }
} }
@ -1133,7 +1136,8 @@ pub(super) struct CurrentDepGraph<D: Deps> {
forbidden_edge: Option<EdgeFilter>, forbidden_edge: Option<EdgeFilter>,
/// Used to verify the absence of hash collisions among DepNodes. /// Used to verify the absence of hash collisions among DepNodes.
/// This field is only `Some` if the `-Z incremental_verify_ich` option is present. /// This field is only `Some` if the `-Z incremental_verify_ich` option is present
/// or if `debug_assertions` are enabled.
/// ///
/// The map contains all DepNodes that have been allocated in the current session so far and /// The map contains all DepNodes that have been allocated in the current session so far and
/// for which there is no equivalent in the previous session. /// for which there is no equivalent in the previous session.
@ -1186,6 +1190,9 @@ impl<D: Deps> CurrentDepGraph<D> {
let new_node_count_estimate = 102 * prev_graph_node_count / 100 + 200; let new_node_count_estimate = 102 * prev_graph_node_count / 100 + 200;
let new_node_dbg =
session.opts.unstable_opts.incremental_verify_ich || cfg!(debug_assertions);
CurrentDepGraph { CurrentDepGraph {
encoder: GraphEncoder::new( encoder: GraphEncoder::new(
encoder, encoder,
@ -1207,16 +1214,12 @@ impl<D: Deps> CurrentDepGraph<D> {
forbidden_edge, forbidden_edge,
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)), fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)),
nodes_newly_allocated_in_current_session: session nodes_newly_allocated_in_current_session: new_node_dbg.then(|| {
.opts Lock::new(FxHashSet::with_capacity_and_hasher(
.unstable_opts new_node_count_estimate,
.incremental_verify_ich Default::default(),
.then(|| { ))
Lock::new(FxHashSet::with_capacity_and_hasher( }),
new_node_count_estimate,
Default::default(),
))
}),
total_read_count: AtomicU64::new(0), total_read_count: AtomicU64::new(0),
total_duplicate_read_count: AtomicU64::new(0), total_duplicate_read_count: AtomicU64::new(0),
} }
@ -1248,9 +1251,11 @@ impl<D: Deps> CurrentDepGraph<D> {
if let Some(ref nodes_newly_allocated_in_current_session) = if let Some(ref nodes_newly_allocated_in_current_session) =
self.nodes_newly_allocated_in_current_session self.nodes_newly_allocated_in_current_session
{ {
if !nodes_newly_allocated_in_current_session.lock().insert(key) { outline(|| {
panic!("Found duplicate dep-node {key:?}"); if !nodes_newly_allocated_in_current_session.lock().insert(key) {
} panic!("Found duplicate dep-node {key:?}");
}
});
} }
dep_node_index dep_node_index