diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-03-18 13:02:01 +0100 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-03-19 20:12:37 +0100 |
| commit | 129f39cb89c02d4199fd641036f21ff7d1707238 (patch) | |
| tree | 94faae390030f72f11021ea74327abf312c71b1b | |
| parent | bd8b62826267e9c2ce0669383ed0875b2a85cb9a (diff) | |
| download | rust-129f39cb89c02d4199fd641036f21ff7d1707238.tar.gz rust-129f39cb89c02d4199fd641036f21ff7d1707238.zip | |
Use `nodes_newly_allocated_in_current_session` to lookup forbidden reads
| -rw-r--r-- | compiler/rustc_query_system/src/dep_graph/graph.rs | 23 |
1 files changed, 18 insertions, 5 deletions
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<D: Deps> DepGraphData<D> { &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<D: Deps> { /// /// 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<Lock<FxHashSet<DepNode>>>, + nodes_newly_allocated_in_current_session: Option<Lock<FxHashMap<DepNode, DepNodeIndex>>>, /// 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<D: Deps> CurrentDepGraph<D> { #[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<D: Deps> CurrentDepGraph<D> { 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<D: Deps> CurrentDepGraph<D> { !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<D: Deps>(data: &DepGraphData<D>, 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), |
