Recursively compute the dependency chain depth for a variable.
(
var: &str,
deps: &HashMap<String, HashSet<String>>,
cache: &mut HashMap<String, u32>,
visiting: &mut HashSet<String>,
)
| 5834 | |
| 5835 | /// Recursively compute the dependency chain depth for a variable. |
| 5836 | fn chain_depth( |
| 5837 | var: &str, |
| 5838 | deps: &HashMap<String, HashSet<String>>, |
| 5839 | cache: &mut HashMap<String, u32>, |
| 5840 | visiting: &mut HashSet<String>, |
| 5841 | ) -> u32 { |
| 5842 | if let Some(&cached) = cache.get(var) { |
| 5843 | return cached; |
| 5844 | } |
| 5845 | if !visiting.insert(var.to_string()) { |
| 5846 | // Cycle detected — break it. |
| 5847 | return 1; |
| 5848 | } |
| 5849 | let depth = if let Some(rhs_vars) = deps.get(var) { |
| 5850 | let mut max_child: u32 = 0; |
| 5851 | for dep in rhs_vars { |
| 5852 | max_child = max_child.max(chain_depth(dep, deps, cache, visiting)); |
| 5853 | } |
| 5854 | max_child + 1 |
| 5855 | } else { |
| 5856 | 1 |
| 5857 | }; |
| 5858 | visiting.remove(var); |
| 5859 | cache.insert(var.to_string(), depth); |
| 5860 | depth |
| 5861 | } |
| 5862 | |
| 5863 | /// Collect assignment dependencies from a statement (cheap AST walk). |
| 5864 | fn collect_assignment_deps(stmt: &Statement<'_>, deps: &mut HashMap<String, HashSet<String>>) { |
no test coverage detected