Skip to content

Commit cfe786e

Browse files
committed
Fix tests.
Avoid invoking queries inside `check_paths`, since we are holding a lock to the reconstructed graph.
1 parent 39b306a commit cfe786e

11 files changed

+30
-14
lines changed

compiler/rustc_query_system/src/dep_graph/query.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::graph::implementation::{Direction, Graph, NodeIndex, INCOMING};
3+
use rustc_index::vec::IndexVec;
34

45
use super::{DepKind, DepNode, DepNodeIndex};
56

67
pub struct DepGraphQuery<K> {
78
pub graph: Graph<DepNode<K>, ()>,
89
pub indices: FxHashMap<DepNode<K>, NodeIndex>,
10+
pub dep_index_to_index: IndexVec<DepNodeIndex, Option<NodeIndex>>,
911
}
1012

1113
impl<K: DepKind> DepGraphQuery<K> {
@@ -15,18 +17,25 @@ impl<K: DepKind> DepGraphQuery<K> {
1517

1618
let graph = Graph::with_capacity(node_count, edge_count);
1719
let indices = FxHashMap::default();
20+
let dep_index_to_index = IndexVec::new();
1821

19-
DepGraphQuery { graph, indices }
22+
DepGraphQuery { graph, indices, dep_index_to_index }
2023
}
2124

2225
pub fn push(&mut self, index: DepNodeIndex, node: DepNode<K>, edges: &[DepNodeIndex]) {
2326
let source = self.graph.add_node(node);
24-
debug_assert_eq!(index.index(), source.0);
27+
if index.index() >= self.dep_index_to_index.len() {
28+
self.dep_index_to_index.resize(index.index() + 1, None);
29+
}
30+
self.dep_index_to_index[index] = Some(source);
2531
self.indices.insert(node, source);
2632

2733
for &target in edges.iter() {
28-
let target = NodeIndex(target.index());
29-
self.graph.add_edge(source, target, ());
34+
let target = self.dep_index_to_index[target];
35+
// Skip missing edges.
36+
if let Some(target) = target {
37+
self.graph.add_edge(source, target, ());
38+
}
3039
}
3140
}
3241

compiler/rustc_query_system/src/dep_graph/serialized.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@ fn encode_node<K: DepKind>(
144144
) -> FileEncodeResult {
145145
#[cfg(debug_assertions)]
146146
if let Some(record_graph) = &_record_graph {
147-
record_graph.lock().push(_index, node.node, &node.edges);
147+
if let Some(record_graph) = &mut if cfg!(parallel_compiler) {
148+
Some(record_graph.lock())
149+
} else {
150+
// Do not ICE when a query is called from within `with_query`.
151+
record_graph.try_lock()
152+
} {
153+
record_graph.push(_index, node.node, &node.edges);
154+
}
148155
}
149156

150157
if let Some(record_stats) = &record_stats {

src/test/ui/async-await/issues/issue-64964.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// check-pass
2-
// compile-flags: -Z query-dep-graph
2+
// compile-flags: -Z query-dep-graph -C incremental=tmp/issue-64964
33
// edition:2018
44

55
// Regression test for ICE related to `await`ing in a method + incr. comp. (#64964)

src/test/ui/dep-graph/dep-graph-assoc-type-codegen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that when a trait impl changes, fns whose body uses that trait
22
// must also be recompiled.
33

4-
// compile-flags: -Z query-dep-graph
4+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-assoc-type-codegen
55

66
#![feature(rustc_attrs)]
77
#![allow(warnings)]

src/test/ui/dep-graph/dep-graph-caller-callee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that immediate callers have to change when callee changes, but
22
// not callers' callers.
33

4-
// compile-flags: -Z query-dep-graph
4+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-caller-callee
55

66
#![feature(rustc_attrs)]
77
#![allow(dead_code)]

src/test/ui/dep-graph/dep-graph-struct-signature.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test cases where a changing struct appears in the signature of fns
22
// and methods.
33

4-
// compile-flags: -Z query-dep-graph
4+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-struct-signature
55

66
#![feature(rustc_attrs)]
77
#![allow(dead_code)]

src/test/ui/dep-graph/dep-graph-trait-impl-two-traits-same-method.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that adding an impl to a trait `Foo` DOES affect functions
22
// that only use `Bar` if they have methods in common.
33

4-
// compile-flags: -Z query-dep-graph
4+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-trait-impl-two-traits-same-method
55

66
#![feature(rustc_attrs)]
77
#![allow(dead_code)]

src/test/ui/dep-graph/dep-graph-trait-impl-two-traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that adding an impl to a trait `Foo` does not affect functions
22
// that only use `Bar`, so long as they do not have methods in common.
33

4-
// compile-flags: -Z query-dep-graph
4+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-trait-impl-two-traits
55

66
#![feature(rustc_attrs)]
77
#![allow(warnings)]

src/test/ui/dep-graph/dep-graph-trait-impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Test that when a trait impl changes, fns whose body uses that trait
22
// must also be recompiled.
33

4-
// compile-flags: -Z query-dep-graph
4+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-trait-impl
55

66
#![feature(rustc_attrs)]
77
#![allow(warnings)]

src/test/ui/dep-graph/dep-graph-type-alias.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test that changing what a `type` points to does not go unnoticed.
22

3-
// compile-flags: -Z query-dep-graph
3+
// compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-type-alias
44

55
#![feature(rustc_attrs)]
66
#![allow(dead_code)]

0 commit comments

Comments
 (0)