Skip to main content

compute_dead_code

Function compute_dead_code 

Source
pub fn compute_dead_code<S: BuildHasher>(
    graph: &RepoGraph,
    entry_def_indices: &HashSet<DefIndex, S>,
    include_test_paths: bool,
) -> DeadCodeReport
Expand description

Compute the set of definitions unreachable from any entry point.

Returns dead clusters (connected components in the unreachable subgraph), sorted by size descending.

ยงAlgorithm

  1. Optionally filter test paths from entry_def_indices (when include_test_paths is false). Test-path heuristic: the file path contains test_, _test, tests/, spec/, specs/, or bench.
  2. BFS forward over RepoGraph::def_callees from the entry seeds -> reachable set.
  3. Complement (all_defs - reachable) = dead set.
  4. Connected-components on the dead subgraph via def_callees + def_callers treated as undirected (union-find).
  5. For each cluster: pick the highest-rank def as the cluster root; size = member count; total_lines = sum of (end_line - start_line) per member.
  6. Sort clusters by size descending.