chore(tools): make unreachable-code analysis runnable from the Taskfile

Add `task deadcode` (whole-program RTA from ./cmd/...) and `task reachaudit`
(the existing classifier on top of it). Neither joins `task check`: both
report a standing backlog, so gating on them fails every run until that
backlog is zero, same as `task vuln`.

`task deadcode` shells to `go run ...@latest` rather than a local binary on
purpose. A deadcode built against an older Go than this module exits non-zero
and prints nothing, which reads as "no dead code" instead of "analysis
failed" -- the locally installed copy was built against 1.26 against a 1.27
module and had been silently reporting an empty tree.

reachaudit had two traps that made it answer confidently from nothing:
its --repo default pointed at a path that does not exist on either machine,
and it reused /tmp/reachaudit-deadcode.txt with no staleness check, so it
would serve a previous tree's analysis indefinitely. Key the cache on HEAD
and refuse it outright when the tree is dirty.

Also lands the design for tools/symbolrefs, the type-resolved reference
index that covers what reachability cannot: RTA treats every address-taken
function as live, so every reflect.ValueOf entry in the *extract tables
launders a dead symbol into a reachable-looking one, and deadcode reports
functions only, leaving dead package vars unrepresentable.
This commit is contained in:
sam committed 2026-09-18 13:15:26 +10:00
1 parent c984cc6cbc
commit 8d0716900d
3 files changed
+159 -3

No files matched your search

+5 -3
View File
@@ -67,8 +67,10 @@ def cmd_closure(repo: Path) -> set[str]:
def deadcode_findings(repo: Path) -> list[str]:
"""Run deadcode, or reuse a cached run. Falls back to an empty list with a
loud warning rather than silently reporting zero findings."""
cache = Path("/tmp/reachaudit-deadcode.txt")
if cache.exists():
head = run(["git", "rev-parse", "HEAD"], repo) or "unknown"
dirty = "-dirty" if run(["git", "status", "--porcelain"], repo) else ""
cache = Path(f"/tmp/reachaudit-deadcode-{head[:12]}{dirty}.txt")
if cache.exists() and not dirty:
return cache.read_text().splitlines()
print("running deadcode (this compiles the module, may take a minute)...", file=sys.stderr)
out = subprocess.run(
@@ -138,7 +140,7 @@ def consumers(repo: Path, pkg: str) -> tuple[int, int]:
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("--repo", default=str(Path.home() / "projects/archie-core"))
ap.add_argument("--repo", default=str(Path(__file__).resolve().parents[2]))
ap.add_argument("--json")
ap.add_argument("--md")
ap.add_argument("--refresh", action="store_true", help="re-run deadcode instead of using the cache")