1 //! Code for debugging the dep-graph.
3 use super::{DepKind, DepNode, DepNodeIndex};
4 use rustc_data_structures::fx::FxHashMap;
5 use rustc_data_structures::sync::Lock;
8 /// A dep-node filter goes from a user-defined string to a query over
9 /// nodes. Right now the format is like this:
10 /// ```ignore (illustrative)
13 /// where the format-string of the dep-node must contain `x`, `y`, and
16 pub struct DepNodeFilter {
21 pub fn new(text: &str) -> Self {
22 DepNodeFilter { text: text.trim().to_string() }
25 /// Returns `true` if all nodes always pass the filter.
26 pub fn accepts_all(&self) -> bool {
30 /// Tests whether `node` meets the filter, returning true if so.
31 pub fn test<K: DepKind>(&self, node: &DepNode<K>) -> bool {
32 let debug_str = format!("{:?}", node);
33 self.text.split('&').map(|s| s.trim()).all(|f| debug_str.contains(f))
37 /// A filter like `F -> G` where `F` and `G` are valid dep-node
38 /// filters. This can be used to test the source/target independently.
39 pub struct EdgeFilter<K: DepKind> {
40 pub source: DepNodeFilter,
41 pub target: DepNodeFilter,
42 pub index_to_node: Lock<FxHashMap<DepNodeIndex, DepNode<K>>>,
45 impl<K: DepKind> EdgeFilter<K> {
46 pub fn new(test: &str) -> Result<EdgeFilter<K>, Box<dyn Error>> {
47 let parts: Vec<_> = test.split("->").collect();
49 Err(format!("expected a filter like `a&b -> c&d`, not `{}`", test).into())
52 source: DepNodeFilter::new(parts[0]),
53 target: DepNodeFilter::new(parts[1]),
54 index_to_node: Lock::new(FxHashMap::default()),
59 #[cfg(debug_assertions)]
60 pub fn test(&self, source: &DepNode<K>, target: &DepNode<K>) -> bool {
61 self.source.test(source) && self.target.test(target)