rustc_query_system/dep_graph/
debug.rsuse std::error::Error;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::sync::Lock;
use super::{DepNode, DepNodeIndex};
#[derive(Debug)]
pub struct DepNodeFilter {
text: String,
}
impl DepNodeFilter {
pub fn new(text: &str) -> Self {
DepNodeFilter { text: text.trim().to_string() }
}
pub fn accepts_all(&self) -> bool {
self.text.is_empty()
}
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))
}
}
pub struct EdgeFilter {
pub source: DepNodeFilter,
pub target: DepNodeFilter,
pub index_to_node: Lock<FxHashMap<DepNodeIndex, DepNode>>,
}
impl EdgeFilter {
pub fn new(test: &str) -> Result<EdgeFilter, Box<dyn Error>> {
if let [source, target] = *test.split("->").collect::<Vec<_>>() {
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)
}
}