From cfe786e5e00316fb70b48fc6e324b72acf069df4 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Sat, 6 Mar 2021 13:55:20 +0100 Subject: Fix tests. Avoid invoking queries inside `check_paths`, since we are holding a lock to the reconstructed graph. --- compiler/rustc_query_system/src/dep_graph/query.rs | 17 +++++++++++++---- compiler/rustc_query_system/src/dep_graph/serialized.rs | 9 ++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) (limited to 'compiler/rustc_query_system/src') diff --git a/compiler/rustc_query_system/src/dep_graph/query.rs b/compiler/rustc_query_system/src/dep_graph/query.rs index 9c85cdd59d9..0fe3748e386 100644 --- a/compiler/rustc_query_system/src/dep_graph/query.rs +++ b/compiler/rustc_query_system/src/dep_graph/query.rs @@ -1,11 +1,13 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::graph::implementation::{Direction, Graph, NodeIndex, INCOMING}; +use rustc_index::vec::IndexVec; use super::{DepKind, DepNode, DepNodeIndex}; pub struct DepGraphQuery { pub graph: Graph, ()>, pub indices: FxHashMap, NodeIndex>, + pub dep_index_to_index: IndexVec>, } impl DepGraphQuery { @@ -15,18 +17,25 @@ impl DepGraphQuery { let graph = Graph::with_capacity(node_count, edge_count); let indices = FxHashMap::default(); + let dep_index_to_index = IndexVec::new(); - DepGraphQuery { graph, indices } + DepGraphQuery { graph, indices, dep_index_to_index } } pub fn push(&mut self, index: DepNodeIndex, node: DepNode, edges: &[DepNodeIndex]) { let source = self.graph.add_node(node); - debug_assert_eq!(index.index(), source.0); + if index.index() >= self.dep_index_to_index.len() { + self.dep_index_to_index.resize(index.index() + 1, None); + } + self.dep_index_to_index[index] = Some(source); self.indices.insert(node, source); for &target in edges.iter() { - let target = NodeIndex(target.index()); - self.graph.add_edge(source, target, ()); + let target = self.dep_index_to_index[target]; + // Skip missing edges. + if let Some(target) = target { + self.graph.add_edge(source, target, ()); + } } } diff --git a/compiler/rustc_query_system/src/dep_graph/serialized.rs b/compiler/rustc_query_system/src/dep_graph/serialized.rs index 3067da9436d..6a3cc215a0b 100644 --- a/compiler/rustc_query_system/src/dep_graph/serialized.rs +++ b/compiler/rustc_query_system/src/dep_graph/serialized.rs @@ -144,7 +144,14 @@ fn encode_node( ) -> FileEncodeResult { #[cfg(debug_assertions)] if let Some(record_graph) = &_record_graph { - record_graph.lock().push(_index, node.node, &node.edges); + if let Some(record_graph) = &mut if cfg!(parallel_compiler) { + Some(record_graph.lock()) + } else { + // Do not ICE when a query is called from within `with_query`. + record_graph.try_lock() + } { + record_graph.push(_index, node.node, &node.edges); + } } if let Some(record_stats) = &record_stats { -- cgit 1.4.1-3-g733a5