Skip to content

Commit b8a420a

Browse files
gHashTaggHashTag
andauthored
build: add make warnings-baseline advisory dead-code meter (#1119)
Adds scripts/warnings-baseline.sh (counts non-test build warnings via JSON diagnostics, compares to baseline 683, lists top files) and a make warnings-baseline target. Advisory only; never edits code, never gates CI. Gives the #969 audit a repeatable progress meter. Closes #1116 Co-authored-by: gHashTag <admin@t27.ai>
1 parent 12dc993 commit b8a420a

3 files changed

Lines changed: 155 additions & 1 deletion

File tree

Makefile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
# Anchor: phi^2 + phi^-2 = 3
99

10-
.PHONY: help seal-check install-hooks
10+
.PHONY: help seal-check install-hooks warnings-baseline
1111

1212
# Default target: list what is available.
1313
help:
@@ -16,6 +16,8 @@ help:
1616
@echo " vs sha256(bootstrap/src/compiler.rs) (advisory)."
1717
@echo " make install-hooks Install the local git hooks (incl. the advisory"
1818
@echo " pre-push seal-staleness warning)."
19+
@echo " make warnings-baseline Count non-test build warnings vs the recorded"
20+
@echo " baseline and list the top files (advisory; #969)."
1921

2022
# Advisory: report NMSE seal freshness. Exit 0 fresh / 2 stale / 3 unsealed.
2123
# Never reseals; refreezing stays an explicit reviewed step.
@@ -25,3 +27,8 @@ seal-check:
2527
# Install the local git hooks (advisory pre-push includes the seal check).
2628
install-hooks:
2729
@scripts/install-git-hooks.sh
30+
31+
# Advisory: count non-test build warnings vs the recorded baseline and list the
32+
# top offending files, to track #969 dead-code progress. Never edits code.
33+
warnings-baseline:
34+
@scripts/warnings-baseline.sh

docs/NOW.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Last updated: 2026-06-14
44

5+
## warnings-baseline-meter -- advisory non-test build-warning meter for the #969 audit (Closes #1116)
6+
7+
- **WHERE**: new `scripts/warnings-baseline.sh` and the top-level `Makefile` (new `warnings-baseline` target).
8+
- **WHAT**: the #969 dead-code audit removes/annotates build warnings one conservative slice at a time (#1105, #1111, ...), but there was no memorable, repeatable way to see the current count or pick the next slice. `scripts/warnings-baseline.sh` builds the binary crate with `--message-format=json`, counts the non-test compiler warnings, compares the count to a recorded baseline, and prints the top offending source files; `--quiet` prints a one-line verdict. A `make warnings-baseline` target wraps it (continuing the thin #1109 Makefile). It is advisory only -- never edits code, never reseals, NOT wired into CI (required checks stay check-now-freshness / validate / check / check-linked-issue); informational exit codes (0 <= baseline, 1 > baseline, 2 build failed) are never used to fail a required check.
9+
- **Why** the audit needs a progress meter so each conservative slice is easy to pick and regressions are visible. Baseline correctness: the structured primary-span count on master is 683 (measured from the JSON diagnostics) -- earlier NOW.md entries quoted ~685/726 from the cargo summary line, which rounds differently, so the script documents that the JSON primary-span count is the canonical meter and pins BASELINE=683; it suggests updating BASELINE when a reviewed slice legitimately lowers it. Verified: `make warnings-baseline` reports 683 == baseline 683, verdict OK, exit 0, with the top files (compiler.rs 248, host/errors.rs 28, ...). L6 gf16 SSOT untouched; catalog stays 83; no gen/ edits; ASCII-only added lines; no quality claim added. Closes #1116.
10+
- **Anchor**: phi^2 + phi^-2 = 3
11+
12+
513
## fix-stray-ident-leak -- close the stray-identifier parser leak (#1110 known-gap -> fix) (Closes #1115)
614

715
- **WHERE**: `bootstrap/src/compiler.rs` (`parse_body_stmt` bare-expression branch; the #1110 characterization test renamed `characterizes_stray_ident_leak_known_gap` -> `rejects_stray_ident` and switched to `assert_dropped`).

scripts/warnings-baseline.sh

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
#!/usr/bin/env bash
2+
#
3+
# warnings-baseline.sh -- advisory non-test build-warning reporter for t27.
4+
#
5+
# The #969 dead-code audit removes or annotates build warnings one conservative
6+
# slice at a time (see docs/NOW.md). This script gives that effort a memorable,
7+
# read-only progress meter: it builds the binary crate with JSON diagnostics,
8+
# counts the non-test compiler warnings, compares the count to a recorded
9+
# baseline, and prints the top offending source files so the next slice is easy
10+
# to pick.
11+
#
12+
# It is ADVISORY ONLY: it never edits code, never reseals anything, and is NOT
13+
# wired into CI (the required checks stay check-now-freshness / validate /
14+
# check / check-linked-issue). The baseline is a soft reference, not a gate.
15+
#
16+
# Exit codes (informational, never used to fail a required check):
17+
# 0 = warning count <= baseline (no regression)
18+
# 1 = warning count > baseline (more warnings than the recorded baseline)
19+
# 2 = build failed (could not produce diagnostics)
20+
#
21+
# Usage:
22+
# scripts/warnings-baseline.sh # full report + top modules
23+
# scripts/warnings-baseline.sh --quiet # one-line verdict only
24+
#
25+
# Anchor: phi^2 + phi^-2 = 3
26+
27+
set -uo pipefail
28+
29+
# Recorded baseline of non-test build warnings on master. Update this number
30+
# (in the same PR) whenever a reviewed slice legitimately lowers it, so the
31+
# meter keeps tracking real progress. Measured precisely from the structured
32+
# JSON diagnostics on master after the host/mod.rs facade slice (#1111): 683.
33+
# (Earlier NOW.md entries quoted ~685/726 from the cargo summary line, which
34+
# rounds differently; this script's primary-span count is the canonical meter.)
35+
BASELINE=683
36+
37+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
38+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
39+
cd "$REPO_ROOT"
40+
41+
QUIET=0
42+
if [ "${1:-}" = "--quiet" ]; then QUIET=1; fi
43+
log() { if [ "$QUIET" -eq 0 ]; then echo "$@"; fi; }
44+
45+
# Prefer an explicit cargo if present; fall back to PATH.
46+
CARGO_BIN="cargo"
47+
if [ -x "$HOME/.cargo/bin/cargo" ]; then CARGO_BIN="$HOME/.cargo/bin/cargo"; fi
48+
49+
# Capture JSON diagnostics. We do not redirect into the build target dir; the
50+
# caller's CARGO_TARGET_DIR (if any) is respected. stderr carries progress.
51+
JSON_OUT="$(mktemp)"
52+
trap 'rm -f "$JSON_OUT"' EXIT
53+
54+
if ! "$CARGO_BIN" build --bin t27c --message-format=json >"$JSON_OUT" 2>/dev/null; then
55+
log "warnings-baseline: BUILD FAILED -- cannot count warnings."
56+
exit 2
57+
fi
58+
59+
# Count non-test warnings and tally the top files using the structured output.
60+
# A small python helper keeps the JSON parsing robust and dependency-free.
61+
REPORT="$(python3 - "$JSON_OUT" <<'PY'
62+
import json, sys, collections
63+
path = sys.argv[1]
64+
counts = collections.Counter()
65+
total = 0
66+
with open(path, "r", encoding="utf-8", errors="replace") as fh:
67+
for line in fh:
68+
line = line.strip()
69+
if not line:
70+
continue
71+
try:
72+
m = json.loads(line)
73+
except Exception:
74+
continue
75+
if m.get("reason") != "compiler-message":
76+
continue
77+
msg = m.get("message", {})
78+
if msg.get("level") != "warning":
79+
continue
80+
text = msg.get("message", "")
81+
# Skip the cargo summary line ("`t27c` generated N warnings").
82+
if text.startswith("`t27c`"):
83+
continue
84+
total += 1
85+
f = None
86+
for s in msg.get("spans", []):
87+
if s.get("is_primary"):
88+
f = s.get("file_name")
89+
break
90+
if f is None:
91+
spans = msg.get("spans", [])
92+
if spans:
93+
f = spans[0].get("file_name")
94+
counts[f or "<unknown>"] += 1
95+
print(total)
96+
for f, n in counts.most_common(10):
97+
print(f"{n}\t{f}")
98+
PY
99+
)"
100+
101+
TOTAL="$(printf '%s\n' "$REPORT" | head -n 1)"
102+
TOPS="$(printf '%s\n' "$REPORT" | tail -n +2)"
103+
104+
if ! printf '%s' "$TOTAL" | grep -qE '^[0-9]+$'; then
105+
log "warnings-baseline: could not parse warning count."
106+
exit 2
107+
fi
108+
109+
if [ "$TOTAL" -gt "$BASELINE" ]; then
110+
VERDICT="REGRESSED ($TOTAL > baseline $BASELINE)"
111+
CODE=1
112+
else
113+
VERDICT="OK ($TOTAL <= baseline $BASELINE)"
114+
CODE=0
115+
fi
116+
117+
if [ "$QUIET" -eq 1 ]; then
118+
echo "warnings-baseline: $VERDICT"
119+
exit "$CODE"
120+
fi
121+
122+
echo "================================================================"
123+
echo " t27 non-test build warnings (advisory; #969 dead-code progress)"
124+
echo "================================================================"
125+
echo " count : $TOTAL"
126+
echo " baseline : $BASELINE"
127+
echo " verdict : $VERDICT"
128+
echo "----------------------------------------------------------------"
129+
echo " top files by warning count:"
130+
printf '%s\n' "$TOPS" | while IFS=$'\t' read -r n f; do
131+
[ -n "$n" ] && printf ' %5s %s\n' "$n" "$f"
132+
done
133+
echo "----------------------------------------------------------------"
134+
if [ "$CODE" -eq 0 ] && [ "$TOTAL" -lt "$BASELINE" ]; then
135+
echo " note: count is BELOW baseline -- if a reviewed slice lowered it,"
136+
echo " update BASELINE in this script (currently $BASELINE) in the same PR."
137+
fi
138+
echo " advisory only: never edits code, never gates CI."
139+
exit "$CODE"

0 commit comments

Comments
 (0)