a73x

95494b6d

tools: deadcode.sh — non-gating pub-decl reference report

a73x   2026-08-14 08:18

Commit message
tools: deadcode.sh — non-gating pub-decl reference report

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

tools/deadcode.sh
Old New
@@ -0,0 +1,27 @@
1 #!/bin/sh
2 # tools/deadcode.sh — NON-GATING dead-code report.
3 #
4 # Lists pub decls whose name appears in no .zig file other than the one
5 # that defines them. Zig has no mature dead-code tool, and lazy compilation
6 # makes the compiler silent about unreferenced container-level decls; this
7 # grep heuristic is a REVIEW PROMPT, not a failure — it always exits 0.
8 #
9 # Known false-positive classes (name-based, not semantic):
10 # - decls referenced only through @field or comptime-built names
11 # - wire-format API kept complete on purpose (protocol.zig codecs)
12 # - entrypoints the build system names (main, std_options, panic)
13 # - a name defined in two files: a reference to either hides both
14 set -u
15 cd "$(dirname "$0")/.."
16 for f in src/*.zig test/*.zig; do
17 grep -oE '^[[:space:]]*pub (inline )?(fn|const|var) [A-Za-z_][A-Za-z0-9_]*' "$f" \
18 | awk '{print $NF}' \
19 | while read -r name; do
20 case "$name" in main|panic|std_options) continue ;; esac
21 if ! grep -rlw --include='*.zig' "$name" src test build.zig \
22 | grep -qv "^$f\$"; then
23 echo "$f: pub $name is referenced nowhere outside its file"
24 fi
25 done
26 done
27 exit 0