diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index c7749adb114..11c06455141 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -677,7 +677,7 @@ impl DepGraphData { &self.current.nodes_newly_allocated_in_current_session { outline(|| { - let seen = nodes_newly_allocated_in_current_session.lock().contains(dep_node); + let seen = nodes_newly_allocated_in_current_session.lock().contains_key(dep_node); assert!(!seen, "{}", msg()); }); } @@ -1141,7 +1141,7 @@ pub(super) struct CurrentDepGraph { /// /// 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. - nodes_newly_allocated_in_current_session: Option>>, + nodes_newly_allocated_in_current_session: Option>>, /// Anonymous `DepNode`s are nodes whose IDs we compute from the list of /// their edges. This has the beneficial side-effect that multiple anonymous @@ -1216,7 +1216,7 @@ impl CurrentDepGraph { #[cfg(debug_assertions)] fingerprints: Lock::new(IndexVec::from_elem_n(None, new_node_count_estimate)), nodes_newly_allocated_in_current_session: new_node_dbg.then(|| { - Lock::new(FxHashSet::with_capacity_and_hasher( + Lock::new(FxHashMap::with_capacity_and_hasher( new_node_count_estimate, Default::default(), )) @@ -1253,7 +1253,11 @@ impl CurrentDepGraph { self.nodes_newly_allocated_in_current_session { outline(|| { - if !nodes_newly_allocated_in_current_session.lock().insert(key) { + if nodes_newly_allocated_in_current_session + .lock() + .insert(key, dep_node_index) + .is_some() + { panic!("Found duplicate dep-node {key:?}"); } }); @@ -1355,7 +1359,7 @@ impl CurrentDepGraph { !self .nodes_newly_allocated_in_current_session .as_ref() - .map_or(false, |set| set.lock().contains(node)), + .map_or(false, |set| set.lock().contains_key(node)), "node from previous graph present in new node collection" ); } @@ -1477,6 +1481,15 @@ fn panic_on_forbidden_read(data: &DepGraphData, dep_node_index: DepN } } + if dep_node.is_none() + && let Some(nodes) = &data.current.nodes_newly_allocated_in_current_session + { + // Try to find it among the nodes allocated so far in this session + if let Some((node, _)) = nodes.lock().iter().find(|&(_, index)| *index == dep_node_index) { + dep_node = Some(*node); + } + } + let dep_node = dep_node.map_or_else( || format!("with index {:?}", dep_node_index), |dep_node| format!("`{:?}`", dep_node),