about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2021-03-06 13:55:20 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2021-03-30 18:10:06 +0200
commitcfe786e5e00316fb70b48fc6e324b72acf069df4 (patch)
tree74464ecfb4e789981ad77b8cf37291242f584138
parent39b306a53db513c754d5e8d60fc2691829209131 (diff)
downloadrust-cfe786e5e00316fb70b48fc6e324b72acf069df4.tar.gz
rust-cfe786e5e00316fb70b48fc6e324b72acf069df4.zip
Fix tests.
Avoid invoking queries inside `check_paths`, since we are holding a lock
to the reconstructed graph.
-rw-r--r--compiler/rustc_query_system/src/dep_graph/query.rs17
-rw-r--r--compiler/rustc_query_system/src/dep_graph/serialized.rs9
-rw-r--r--src/test/ui/async-await/issues/issue-64964.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-assoc-type-codegen.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-caller-callee.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-struct-signature.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-trait-impl-two-traits-same-method.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-trait-impl.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-type-alias.rs2
-rw-r--r--src/test/ui/dep-graph/dep-graph-variance-alias.rs2
11 files changed, 30 insertions, 14 deletions
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<K> {
     pub graph: Graph<DepNode<K>, ()>,
     pub indices: FxHashMap<DepNode<K>, NodeIndex>,
+    pub dep_index_to_index: IndexVec<DepNodeIndex, Option<NodeIndex>>,
 }
 
 impl<K: DepKind> DepGraphQuery<K> {
@@ -15,18 +17,25 @@ impl<K: DepKind> DepGraphQuery<K> {
 
         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<K>, 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<K: DepKind>(
 ) -> 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 {
diff --git a/src/test/ui/async-await/issues/issue-64964.rs b/src/test/ui/async-await/issues/issue-64964.rs
index 11f6cb6af9c..5313d1715c4 100644
--- a/src/test/ui/async-await/issues/issue-64964.rs
+++ b/src/test/ui/async-await/issues/issue-64964.rs
@@ -1,5 +1,5 @@
 // check-pass
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/issue-64964
 // edition:2018
 
 // Regression test for ICE related to `await`ing in a method + incr. comp. (#64964)
diff --git a/src/test/ui/dep-graph/dep-graph-assoc-type-codegen.rs b/src/test/ui/dep-graph/dep-graph-assoc-type-codegen.rs
index 0d11d933af0..a0ee3ad31e6 100644
--- a/src/test/ui/dep-graph/dep-graph-assoc-type-codegen.rs
+++ b/src/test/ui/dep-graph/dep-graph-assoc-type-codegen.rs
@@ -1,7 +1,7 @@
 // Test that when a trait impl changes, fns whose body uses that trait
 // must also be recompiled.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-assoc-type-codegen
 
 #![feature(rustc_attrs)]
 #![allow(warnings)]
diff --git a/src/test/ui/dep-graph/dep-graph-caller-callee.rs b/src/test/ui/dep-graph/dep-graph-caller-callee.rs
index b12c635d2e7..c95ea53650b 100644
--- a/src/test/ui/dep-graph/dep-graph-caller-callee.rs
+++ b/src/test/ui/dep-graph/dep-graph-caller-callee.rs
@@ -1,7 +1,7 @@
 // Test that immediate callers have to change when callee changes, but
 // not callers' callers.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-caller-callee
 
 #![feature(rustc_attrs)]
 #![allow(dead_code)]
diff --git a/src/test/ui/dep-graph/dep-graph-struct-signature.rs b/src/test/ui/dep-graph/dep-graph-struct-signature.rs
index 7ef6fac48c3..50a670b8772 100644
--- a/src/test/ui/dep-graph/dep-graph-struct-signature.rs
+++ b/src/test/ui/dep-graph/dep-graph-struct-signature.rs
@@ -1,7 +1,7 @@
 // Test cases where a changing struct appears in the signature of fns
 // and methods.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-struct-signature
 
 #![feature(rustc_attrs)]
 #![allow(dead_code)]
diff --git a/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits-same-method.rs b/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits-same-method.rs
index 1b3bf5a3933..c0a6617316b 100644
--- a/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits-same-method.rs
+++ b/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits-same-method.rs
@@ -1,7 +1,7 @@
 // Test that adding an impl to a trait `Foo` DOES affect functions
 // that only use `Bar` if they have methods in common.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-trait-impl-two-traits-same-method
 
 #![feature(rustc_attrs)]
 #![allow(dead_code)]
diff --git a/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs b/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs
index ebfe8ccc3df..56e9762ddb2 100644
--- a/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs
+++ b/src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs
@@ -1,7 +1,7 @@
 // Test that adding an impl to a trait `Foo` does not affect functions
 // that only use `Bar`, so long as they do not have methods in common.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-trait-impl-two-traits
 
 #![feature(rustc_attrs)]
 #![allow(warnings)]
diff --git a/src/test/ui/dep-graph/dep-graph-trait-impl.rs b/src/test/ui/dep-graph/dep-graph-trait-impl.rs
index 9dd201e2a1f..3bbe3e745ca 100644
--- a/src/test/ui/dep-graph/dep-graph-trait-impl.rs
+++ b/src/test/ui/dep-graph/dep-graph-trait-impl.rs
@@ -1,7 +1,7 @@
 // Test that when a trait impl changes, fns whose body uses that trait
 // must also be recompiled.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-trait-impl
 
 #![feature(rustc_attrs)]
 #![allow(warnings)]
diff --git a/src/test/ui/dep-graph/dep-graph-type-alias.rs b/src/test/ui/dep-graph/dep-graph-type-alias.rs
index c9151ce79c5..5c5e24693a4 100644
--- a/src/test/ui/dep-graph/dep-graph-type-alias.rs
+++ b/src/test/ui/dep-graph/dep-graph-type-alias.rs
@@ -1,6 +1,6 @@
 // Test that changing what a `type` points to does not go unnoticed.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-type-alias
 
 #![feature(rustc_attrs)]
 #![allow(dead_code)]
diff --git a/src/test/ui/dep-graph/dep-graph-variance-alias.rs b/src/test/ui/dep-graph/dep-graph-variance-alias.rs
index 927ea559778..6cc1f44104a 100644
--- a/src/test/ui/dep-graph/dep-graph-variance-alias.rs
+++ b/src/test/ui/dep-graph/dep-graph-variance-alias.rs
@@ -1,7 +1,7 @@
 // Test that changing what a `type` points to does not go unnoticed
 // by the variance analysis.
 
-// compile-flags: -Z query-dep-graph
+// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-variance-alias
 
 #![feature(rustc_attrs)]
 #![allow(dead_code)]