Fix tests.

Avoid invoking queries inside `check_paths`, since we are holding a lock
to the reconstructed graph.
This commit is contained in:
Camille GILLOT 2021-03-06 13:55:20 +01:00
parent 39b306a53d
commit cfe786e5e0
11 changed files with 30 additions and 14 deletions

View File

@ -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,20 +17,27 @@ pub fn new(prev_node_count: usize) -> 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());
let target = self.dep_index_to_index[target];
// Skip missing edges.
if let Some(target) = target {
self.graph.add_edge(source, target, ());
}
}
}
pub fn nodes(&self) -> Vec<&DepNode<K>> {
self.graph.all_nodes().iter().map(|n| &n.data).collect()

View File

@ -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 {

View File

@ -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)

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]

View File

@ -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)]