From ce21f2052713fac5a4085cd63cb1f1e5f6d337be Mon Sep 17 00:00:00 2001 From: dalance Date: Tue, 12 Nov 2024 15:43:21 +0900 Subject: [PATCH] Remove unused dependencies from filelist --- crates/analyzer/src/type_dag.rs | 42 +++++++++++++++------------------ crates/tests/src/lib.rs | 2 -- crates/veryl/src/cmd_build.rs | 6 +---- 3 files changed, 20 insertions(+), 30 deletions(-) diff --git a/crates/analyzer/src/type_dag.rs b/crates/analyzer/src/type_dag.rs index cd733e6e..234301d2 100644 --- a/crates/analyzer/src/type_dag.rs +++ b/crates/analyzer/src/type_dag.rs @@ -2,8 +2,7 @@ use crate::symbol::{Symbol, SymbolId}; use crate::symbol_path::SymbolPathNamespace; use crate::symbol_table; use bimap::BiMap; -use daggy::petgraph::unionfind::UnionFind; -use daggy::petgraph::visit::{EdgeRef, NodeIndexable}; +use daggy::petgraph::visit::Dfs; use daggy::{petgraph::algo, Dag, Walker}; use std::{cell::RefCell, collections::HashMap, collections::HashSet}; use veryl_parser::veryl_token::Token; @@ -143,31 +142,28 @@ impl TypeDag { } fn connected_components(&self) -> Vec> { - let graph = self.dag.graph(); - let mut vertex_sets = UnionFind::new(graph.node_bound()); - for edge in graph.edge_references() { - let (a, b) = (edge.source(), edge.target()); + let mut ret = Vec::new(); + let mut graph = self.dag.graph().clone(); - // Ignore Index0 because it is root node - if a.index() != 0 { - vertex_sets.union(graph.to_index(a), graph.to_index(b)); - } - } - let labels = vertex_sets.into_labeling(); + // Reverse edge to traverse nodes which are called from parent node + graph.reverse(); - let mut ret = HashMap::new(); - for node in graph.node_indices() { - let label = labels[graph.to_index(node)]; - let index = node.index() as u32; - - if self.paths.contains_key(&index) { - let sym = self.get_symbol(index); - ret.entry(label) - .and_modify(|x: &mut Vec<_>| x.push(sym.clone())) - .or_insert(vec![sym]); + for node in self.symbols.keys() { + let mut connected = Vec::new(); + let mut dfs = Dfs::new(&graph, (*node).into()); + while let Some(x) = dfs.next(&graph) { + let index = x.index() as u32; + if self.paths.contains_key(&index) { + let symbol = self.get_symbol(index); + connected.push(symbol); + } + } + if !connected.is_empty() { + ret.push(connected); } } - ret.into_values().collect() + + ret } fn dump(&self) -> String { diff --git a/crates/tests/src/lib.rs b/crates/tests/src/lib.rs index fccd487e..05484c08 100644 --- a/crates/tests/src/lib.rs +++ b/crates/tests/src/lib.rs @@ -326,8 +326,6 @@ mod filelist { "module_a.veryl", "module_b.veryl", "module_c.veryl", - "fifo_controller.veryl", - "fifo.veryl", "ram.veryl", ]; check_list(&paths, all); diff --git a/crates/veryl/src/cmd_build.rs b/crates/veryl/src/cmd_build.rs index 80de1672..2441804e 100644 --- a/crates/veryl/src/cmd_build.rs +++ b/crates/veryl/src/cmd_build.rs @@ -217,11 +217,7 @@ impl CmdBuild { let mut candidate_symbols: Vec<_> = type_dag::connected_components() .into_iter() - .filter(|symbols| { - symbols - .iter() - .any(|symbol| symbol.namespace.included(&prj_namespace)) - }) + .filter(|symbols| symbols[0].namespace.included(&prj_namespace)) .flatten() .collect(); if include_tests {