diff --git a/compiler/rustc_incremental/src/assert_dep_graph.rs b/compiler/rustc_incremental/src/assert_dep_graph.rs index 93e6c084a1914..95e9901962b2f 100644 --- a/compiler/rustc_incremental/src/assert_dep_graph.rs +++ b/compiler/rustc_incremental/src/assert_dep_graph.rs @@ -34,6 +34,7 @@ //! ``` use std::env; +use std::error::Error; use std::fs::{self, File}; use std::io::Write; @@ -44,7 +45,7 @@ use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LocalDefId}; use rustc_hir::intravisit::{self, Visitor}; use rustc_middle::bug; -use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeFilter, EdgeFilter, RetainedDepGraph}; +use rustc_middle::dep_graph::{DepKind, DepNode, RetainedDepGraph}; use rustc_middle::hir::nested_filter; use rustc_middle::ty::TyCtxt; use rustc_span::{Span, Symbol, sym}; @@ -53,6 +54,60 @@ use {rustc_graphviz as dot, rustc_hir as hir}; use crate::errors; +/// A dep-node filter goes from a user-defined string to a query over +/// nodes. Right now the format is like this: +/// ```ignore (illustrative) +/// x & y & z +/// ``` +/// where the format-string of the dep-node must contain `x`, `y`, and +/// `z`. +#[derive(Debug)] +struct DepNodeFilter { + text: String, +} + +impl DepNodeFilter { + fn new(text: &str) -> Self { + DepNodeFilter { text: text.trim().to_string() } + } + + /// Returns `true` if all nodes always pass the filter. + fn accepts_all(&self) -> bool { + self.text.is_empty() + } + + /// Tests whether `node` meets the filter, returning true if so. + fn test(&self, node: &DepNode) -> bool { + let debug_str = format!("{node:?}"); + self.text.split('&').map(|s| s.trim()).all(|f| debug_str.contains(f)) + } +} + +/// A filter like `F -> G` where `F` and `G` are valid dep-node +/// filters. This can be used to test the source/target independently. +struct EdgeFilter { + source: DepNodeFilter, + target: DepNodeFilter, +} + +impl EdgeFilter { + fn new(test: &str) -> Result> { + if let [source, target] = *test.split("->").collect::>() { + Ok(EdgeFilter { + source: DepNodeFilter::new(source), + target: DepNodeFilter::new(target), + }) + } else { + Err(format!("expected a filter like `a&b -> c&d`, not `{test}`").into()) + } + } + + #[cfg(debug_assertions)] + fn test(&self, source: &DepNode, target: &DepNode) -> bool { + self.source.test(source) && self.target.test(target) + } +} + #[allow(missing_docs)] pub(crate) fn assert_dep_graph(tcx: TyCtxt<'_>) { tcx.dep_graph.with_ignore(|| { diff --git a/compiler/rustc_middle/src/dep_graph/debug.rs b/compiler/rustc_middle/src/dep_graph/debug.rs deleted file mode 100644 index 12ed574271162..0000000000000 --- a/compiler/rustc_middle/src/dep_graph/debug.rs +++ /dev/null @@ -1,64 +0,0 @@ -//! Code for debugging the dep-graph. - -use std::error::Error; - -use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::sync::Lock; - -use super::{DepNode, DepNodeIndex}; - -/// A dep-node filter goes from a user-defined string to a query over -/// nodes. Right now the format is like this: -/// ```ignore (illustrative) -/// x & y & z -/// ``` -/// where the format-string of the dep-node must contain `x`, `y`, and -/// `z`. -#[derive(Debug)] -pub struct DepNodeFilter { - text: String, -} - -impl DepNodeFilter { - pub fn new(text: &str) -> Self { - DepNodeFilter { text: text.trim().to_string() } - } - - /// Returns `true` if all nodes always pass the filter. - pub fn accepts_all(&self) -> bool { - self.text.is_empty() - } - - /// Tests whether `node` meets the filter, returning true if so. - pub fn test(&self, node: &DepNode) -> bool { - let debug_str = format!("{node:?}"); - self.text.split('&').map(|s| s.trim()).all(|f| debug_str.contains(f)) - } -} - -/// A filter like `F -> G` where `F` and `G` are valid dep-node -/// filters. This can be used to test the source/target independently. -pub struct EdgeFilter { - pub source: DepNodeFilter, - pub target: DepNodeFilter, - pub index_to_node: Lock>, -} - -impl EdgeFilter { - pub fn new(test: &str) -> Result> { - if let [source, target] = *test.split("->").collect::>() { - Ok(EdgeFilter { - source: DepNodeFilter::new(source), - target: DepNodeFilter::new(target), - index_to_node: Lock::new(FxHashMap::default()), - }) - } else { - Err(format!("expected a filter like `a&b -> c&d`, not `{test}`").into()) - } - } - - #[cfg(debug_assertions)] - pub fn test(&self, source: &DepNode, target: &DepNode) -> bool { - self.source.test(source) && self.target.test(target) - } -} diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index 1bd9a1692db08..1ba06a9ad1b8e 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -13,11 +13,9 @@ pub use self::graph::{ use self::graph::{MarkFrame, print_markframe_trace}; pub use self::retained::RetainedDepGraph; pub use self::serialized::{SerializedDepGraph, SerializedDepNodeIndex}; -pub use crate::dep_graph::debug::{DepNodeFilter, EdgeFilter}; use crate::ty::print::with_reduced_queries; use crate::ty::{self, TyCtxt}; -mod debug; pub(crate) mod dep_node; mod dep_node_key; mod edges;