Skip to content

Commit 14fba3c

Browse files
committed
W44: scripts/check_do_not_use_callers.sh — gate against DO-NOT-USE callers
Mechanizes the audit class librarian 19:13:55Z called out as a recurring gap: header WARNING comments alone are insufficient to prevent direct production-path callers of factories that bypass C++ Edge::set_to() or similar invariants. The pattern surfaced twice: 1. 06e2ecb/7d0aff1e42 (pure-C terminator factories) → DominatorAnalysis null in_edge SEGFAULT at analysis.cpp:524 → fix 61c319c used C++ bridge variant. 2. 678e990 (W22 cluster) → 3 production-path cond_branch callers in builder_emit_c.c bypassed Edge::set_to → CFG corruption cascading to v27-not-live + gen_chain + match-runtime + await crashes. Header warnings at Python/jit/hir/hir_instr_c.h:1170-1172 + 1184-1185 ('DO NOT USE for production') existed in both incidents and were not enforced. Script adapts the scripts/caller_grep.sh template (push 92, D-1776930053) to: 1. Enumerate functions/factories preceded by 'DO NOT USE' in Python/jit/hir/*.h headers. 2. For each marked symbol, grep production search paths (Python/jit, Python/cinderx/Jit, Modules, Programs) for callers of <symbol>(. 3. Filter out legitimate non-production callers via ALLOW_LIST_REGEX (read-path tests, layout verification, *_verify*.cpp). 4. Report violations + exit 1 in --strict mode for gate use. Verified at HEAD 678e990: $ scripts/check_do_not_use_callers.sh Found 2 DO-NOT-USE-marked factory(s): Python/jit/hir/hir_instr_c.h:1169 symbol=hir_c_create_branch Python/jit/hir/hir_instr_c.h:1183 symbol=hir_c_create_cond_branch [OK] hir_c_create_branch — no production callers [OK] hir_c_create_cond_branch — no production callers GATE PASS: 2 marker(s) audited, zero production callers found. Synthetic violation test confirms --strict exits 1 + reports caller file:line locations. Ready for integration into gate_phoenix.sh as a standard pre-push gate item. Per W44 (D-1776973262, supervisor 19:37:05Z + librarian 19:36:45Z + shepard 19:39:23Z). Symmetric to scripts/numstat_bundle.sh + scripts/caller_grep.sh discipline-mechanization pattern.
1 parent 678e990 commit 14fba3c

1 file changed

Lines changed: 171 additions & 0 deletions

File tree

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/bin/bash
2+
# check_do_not_use_callers.sh — gate against production-path callers of
3+
# header-marked DO-NOT-USE factories.
4+
#
5+
# Catches the class:
6+
# /* WARNING: DO NOT USE for production — bypass issue. */
7+
# static inline void *hir_c_create_branch(...) { ... }
8+
# being called from production code (e.g., builder_emit_c.c) instead
9+
# of the C++-bridged hir_c_create_branch_cpp variant.
10+
#
11+
# Filed per W44 (D-1776973262, supervisor 19:37:05Z + librarian
12+
# 19:36:45Z): the Edge::set_to bypass class is now 2 incidents
13+
# (06e2ecb652→61c319ca49 + 678e9905a8 W22 cluster); header warning
14+
# alone is insufficient — gate closes the loop.
15+
#
16+
# Symmetric to scripts/caller_grep.sh + scripts/numstat_bundle.sh
17+
# (mechanizes a class supervisor previously caught only via post-hoc
18+
# librarian audit).
19+
#
20+
# Usage:
21+
# scripts/check_do_not_use_callers.sh # default scope
22+
# scripts/check_do_not_use_callers.sh --files # show file:line per match
23+
# scripts/check_do_not_use_callers.sh --strict # exit 1 on any match
24+
#
25+
# Behavior:
26+
# - Scans Python/jit/hir/*.h for "DO NOT USE" warnings preceding
27+
# static inline factory definitions.
28+
# - For each marked symbol, greps Python/ Modules/ Programs/ for
29+
# callers (excluding the defining header itself + verify/test
30+
# files where read-path testing is documented as legitimate).
31+
# - Reports any callers found as VIOLATIONS.
32+
#
33+
# Exit codes:
34+
# 0 — no production callers found (gate clean)
35+
# 1 — at least 1 production caller found (--strict) OR script error
36+
37+
set -euo pipefail
38+
39+
cd "$(dirname "$0")/.."
40+
REPO_ROOT="$(pwd)"
41+
42+
STRICT=0
43+
SHOW_FILES=0
44+
for arg in "$@"; do
45+
case "$arg" in
46+
--strict) STRICT=1 ;;
47+
--files) SHOW_FILES=1 ;;
48+
*) echo "ERROR: unknown arg '$arg'" >&2
49+
echo "Usage: $0 [--strict] [--files]" >&2
50+
exit 1 ;;
51+
esac
52+
done
53+
54+
# Headers to scan for DO-NOT-USE markers.
55+
HEADER_GLOB="Python/jit/hir/*.h"
56+
57+
# Production search paths (excludes verify .cpp files where legitimate
58+
# read-path testing happens, and the defining headers themselves).
59+
SEARCH_PATHS="Python/jit Python/cinderx/Jit Modules Programs"
60+
61+
# Files where DO-NOT-USE callers are LEGITIMATE (read-path tests, layout
62+
# verification, etc.). Add new entries with a brief justification.
63+
ALLOW_LIST_REGEX='/(hir_instr_c_verify\.cpp|test_.*\.c|.*_test\.c|.*_verify.*)$'
64+
65+
echo "=== check_do_not_use_callers.sh — W44 gate ==="
66+
echo "HEAD: $(git rev-parse HEAD)"
67+
echo "Header scope: $HEADER_GLOB"
68+
echo "Production search: $SEARCH_PATHS"
69+
echo "Allow-list (legitimate non-prod callers): $ALLOW_LIST_REGEX"
70+
echo ""
71+
72+
# Step 1: enumerate DO-NOT-USE markers in headers + extract symbol names.
73+
# Strategy: find lines matching "DO NOT USE", then look ahead in the
74+
# same file for the next `static inline ... <name>(...)` definition.
75+
echo "=== Step 1: enumerate DO-NOT-USE-marked factories ==="
76+
MARKERS_TMP=$(mktemp)
77+
trap "rm -f $MARKERS_TMP" EXIT
78+
79+
for header in $HEADER_GLOB; do
80+
[ -f "$header" ] || continue
81+
# awk: when we see "DO NOT USE", remember and look for next factory
82+
# def. Match `static inline <ret> <name>(` patterns.
83+
awk -v hdr="$header" '
84+
/DO NOT USE/ { warned=1; warn_line=NR; next }
85+
warned && /^static inline / {
86+
# Extract symbol name: tokens are "static" "inline" "<ret>"
87+
# ... "<name>(...)"; the name precedes "(".
88+
line=$0
89+
# Find "(" position.
90+
paren=index(line, "(")
91+
if (paren > 0) {
92+
pre = substr(line, 1, paren - 1)
93+
# Take last whitespace-separated token as name.
94+
n = split(pre, parts, /[ \t*]+/)
95+
name = parts[n]
96+
# Strip leading "*" if present (pointer-return type).
97+
sub(/^\*+/, "", name)
98+
if (name != "") {
99+
print hdr ":" warn_line "\t" name
100+
}
101+
}
102+
warned=0
103+
}
104+
warned && /^\}/ { warned=0 }
105+
' "$header" >> "$MARKERS_TMP"
106+
done
107+
108+
N_MARKERS=$(wc -l < "$MARKERS_TMP")
109+
echo "Found $N_MARKERS DO-NOT-USE-marked factory(s):"
110+
if [ "$N_MARKERS" -eq 0 ]; then
111+
echo " (none)"
112+
echo ""
113+
echo "=== Verdict ==="
114+
echo "GATE PASS: no DO-NOT-USE markers found to enforce against."
115+
exit 0
116+
fi
117+
cat "$MARKERS_TMP" | awk -F'\t' '{print " " $1 " symbol=" $2}'
118+
echo ""
119+
120+
# Step 2: for each marked symbol, grep production paths for callers.
121+
echo "=== Step 2: search production callers of each marked symbol ==="
122+
echo ""
123+
124+
TOTAL_VIOLATIONS=0
125+
TOTAL_SYMBOLS_WITH_VIOLATIONS=0
126+
127+
while IFS=$'\t' read -r marker_loc symbol; do
128+
# Caller pattern: "<symbol>(" anywhere — excludes "<symbol>_cpp("
129+
# via word boundary check.
130+
PATTERN="\\b${symbol}\\("
131+
set +e
132+
CALLERS=$(grep -rnE \
133+
--include='*.c' --include='*.cpp' \
134+
"$PATTERN" $SEARCH_PATHS 2>/dev/null || true)
135+
set -e
136+
137+
# Filter out allow-listed files (verify, tests).
138+
CALLERS_FILTERED=$(printf '%s\n' "$CALLERS" | grep -vE "$ALLOW_LIST_REGEX" || true)
139+
140+
if [ -z "$CALLERS_FILTERED" ]; then
141+
echo " [OK] $symbol — no production callers"
142+
continue
143+
fi
144+
145+
N=$(printf '%s\n' "$CALLERS_FILTERED" | wc -l)
146+
TOTAL_VIOLATIONS=$((TOTAL_VIOLATIONS + N))
147+
TOTAL_SYMBOLS_WITH_VIOLATIONS=$((TOTAL_SYMBOLS_WITH_VIOLATIONS + 1))
148+
149+
echo " [VIOLATION] $symbol$N production caller(s):"
150+
if [ "$SHOW_FILES" -eq 1 ]; then
151+
printf '%s\n' "$CALLERS_FILTERED" | sed 's/^/ /'
152+
else
153+
printf '%s\n' "$CALLERS_FILTERED" | cut -d: -f1 | sort -u | sed 's/^/ /'
154+
fi
155+
done < "$MARKERS_TMP"
156+
157+
echo ""
158+
echo "=== Verdict ==="
159+
if [ "$TOTAL_VIOLATIONS" -eq 0 ]; then
160+
echo "GATE PASS: $N_MARKERS marker(s) audited, zero production callers found."
161+
exit 0
162+
else
163+
echo "GATE FAIL: $TOTAL_VIOLATIONS production caller(s) of $TOTAL_SYMBOLS_WITH_VIOLATIONS DO-NOT-USE symbol(s)."
164+
echo ""
165+
echo "Each violation must be fixed by switching the caller to the"
166+
echo "_cpp-suffixed bridge variant (or other documented replacement)."
167+
echo "If a caller is legitimate non-production (read-path test,"
168+
echo "layout verification), add the file to ALLOW_LIST_REGEX above."
169+
[ "$STRICT" -eq 1 ] && exit 1
170+
exit 0
171+
fi

0 commit comments

Comments
 (0)