1
Fork 0

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::fx::FxHashMap;
use rustc_data_structures::graph::implementation::{Direction, Graph, NodeIndex, INCOMING}; use rustc_data_structures::graph::implementation::{Direction, Graph, NodeIndex, INCOMING};
use rustc_index::vec::IndexVec;
use super::{DepKind, DepNode, DepNodeIndex}; use super::{DepKind, DepNode, DepNodeIndex};
pub struct DepGraphQuery<K> { pub struct DepGraphQuery<K> {
pub graph: Graph<DepNode<K>, ()>, pub graph: Graph<DepNode<K>, ()>,
pub indices: FxHashMap<DepNode<K>, NodeIndex>, pub indices: FxHashMap<DepNode<K>, NodeIndex>,
pub dep_index_to_index: IndexVec<DepNodeIndex, Option<NodeIndex>>,
} }
impl<K: DepKind> DepGraphQuery<K> { impl<K: DepKind> DepGraphQuery<K> {
@ -15,20 +17,27 @@ impl<K: DepKind> DepGraphQuery<K> {
let graph = Graph::with_capacity(node_count, edge_count); let graph = Graph::with_capacity(node_count, edge_count);
let indices = FxHashMap::default(); 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]) { pub fn push(&mut self, index: DepNodeIndex, node: DepNode<K>, edges: &[DepNodeIndex]) {
let source = self.graph.add_node(node); 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); self.indices.insert(node, source);
for &target in edges.iter() { 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, ()); self.graph.add_edge(source, target, ());
} }
} }
}
pub fn nodes(&self) -> Vec<&DepNode<K>> { pub fn nodes(&self) -> Vec<&DepNode<K>> {
self.graph.all_nodes().iter().map(|n| &n.data).collect() self.graph.all_nodes().iter().map(|n| &n.data).collect()

View file

@ -144,7 +144,14 @@ fn encode_node<K: DepKind>(
) -> FileEncodeResult { ) -> FileEncodeResult {
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
if let Some(record_graph) = &_record_graph { 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 { if let Some(record_stats) = &record_stats {

View file

@ -1,5 +1,5 @@
// check-pass // check-pass
// compile-flags: -Z query-dep-graph // compile-flags: -Z query-dep-graph -C incremental=tmp/issue-64964
// edition:2018 // edition:2018
// Regression test for ICE related to `await`ing in a method + incr. comp. (#64964) // 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 // Test that when a trait impl changes, fns whose body uses that trait
// must also be recompiled. // 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)] #![feature(rustc_attrs)]
#![allow(warnings)] #![allow(warnings)]

View file

@ -1,7 +1,7 @@
// Test that immediate callers have to change when callee changes, but // Test that immediate callers have to change when callee changes, but
// not callers' callers. // 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)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]

View file

@ -1,7 +1,7 @@
// Test cases where a changing struct appears in the signature of fns // Test cases where a changing struct appears in the signature of fns
// and methods. // and methods.
// compile-flags: -Z query-dep-graph // compile-flags: -Z query-dep-graph -C incremental=tmp/dep-graph-struct-signature
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]

View file

@ -1,7 +1,7 @@
// Test that adding an impl to a trait `Foo` DOES affect functions // Test that adding an impl to a trait `Foo` DOES affect functions
// that only use `Bar` if they have methods in common. // 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)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]

View file

@ -1,7 +1,7 @@
// Test that adding an impl to a trait `Foo` does not affect functions // 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. // 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)] #![feature(rustc_attrs)]
#![allow(warnings)] #![allow(warnings)]

View file

@ -1,7 +1,7 @@
// Test that when a trait impl changes, fns whose body uses that trait // Test that when a trait impl changes, fns whose body uses that trait
// must also be recompiled. // 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)] #![feature(rustc_attrs)]
#![allow(warnings)] #![allow(warnings)]

View file

@ -1,6 +1,6 @@
// Test that changing what a `type` points to does not go unnoticed. // 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)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]

View file

@ -1,7 +1,7 @@
// Test that changing what a `type` points to does not go unnoticed // Test that changing what a `type` points to does not go unnoticed
// by the variance analysis. // 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)] #![feature(rustc_attrs)]
#![allow(dead_code)] #![allow(dead_code)]