Skip to content

Commit 15de220

Browse files
committed
scripts: count_emit_methods.sh — reproducible Tier 5/6 baseline
Per pythia python#79 python#3 [chat L2032] + supervisor [chat L2034] assignment: the brace-counted scan methodology that produced 100/123 = 81.3% Tier 5 close ratio existed only in chat history (D-1776880902). Anyone re-grepping in two weeks reproduces the same /144-class lapse. This script anchors the methodology in repo: - Brace-balanced extraction of HIRBuilder::emit* method definitions (multi-line signatures + any return type + balanced { } body) - Categorization: stub (≤8 body lines + has hir_builder_emit_*_c call) / partial (>8 body lines + has C call) / pure C++ (no C call) - Output: counts + exhaustive pure-C++ + partial method lists Reference values verified at HEAD a642405 (post-Tier-5-close, push 62): TOTAL: 123 STUBS: 93 PARTIAL: 7 PURE C++: 23 RATIO: 100/123 = 81.3% Closes pythia python#79 python#3 'methodology not committed to repo' substance. Anyone running scripts/count_emit_methods.sh reproduces the canonical baseline without needing chat-search or external memory. Origin lessons embedded in script header: - /144 propagated 2026-04-21 (commit 7783df7) → 2026-04-22 Tier 5 close - Real denominator at HEAD a642405 was 123 (pythia python#78 python#1 catch) - Methodology lives in repo, not chat Authorization chain: - pythia python#79 python#3 surfaced gap: chat L2032 - supervisor python#3 assignment: chat L2034
1 parent 149b7e2 commit 15de220

1 file changed

Lines changed: 103 additions & 0 deletions

File tree

scripts/count_emit_methods.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
# count_emit_methods.sh — reproducible Tier 5/6 progress baseline.
3+
#
4+
# Scans Python/jit/hir/builder.cpp for HIRBuilder::emit* method definitions and
5+
# categorizes them by C-conversion status (stub / partial / pure C++).
6+
#
7+
# Usage:
8+
# scripts/count_emit_methods.sh [BUILDER_CPP_PATH]
9+
# (default path: Python/jit/hir/builder.cpp relative to repo root)
10+
#
11+
# Output: counts + the exhaustive pure-C++ method list.
12+
#
13+
# Origin: replaces the unverified /144 chat-propagated baseline that propagated
14+
# from 2026-04-21 (commit 7783df7182) through 2026-04-22 Tier 5 close. Real
15+
# denominator at HEAD a642405a5c was 123, not 144 (pythia #78 #1 catch).
16+
#
17+
# Methodology:
18+
# denominator = count of HIRBuilder::emit* method bodies in builder.cpp
19+
# (multi-line signatures, any return type, brace-balanced body)
20+
# stub = body has <=8 non-comment lines AND contains hir_builder_emit_*_c
21+
# partial = body has >8 non-comment lines AND contains hir_builder_emit_*_c
22+
# pure C++ = body does NOT contain hir_builder_emit_*_c
23+
#
24+
# Reference values: at HEAD a642405a5c (post-Tier-5-close, push 62):
25+
# total: 123
26+
# stub: 93
27+
# partial: 7
28+
# pure C++: 23
29+
# ratio: (stub + partial) / total = 100/123 = 81.3%
30+
31+
set -euo pipefail
32+
33+
BUILDER_CPP="${1:-Python/jit/hir/builder.cpp}"
34+
35+
if [[ ! -f "$BUILDER_CPP" ]]; then
36+
echo "ERROR: $BUILDER_CPP not found" >&2
37+
exit 1
38+
fi
39+
40+
python3 - "$BUILDER_CPP" <<'PYEOF'
41+
import re
42+
import sys
43+
44+
src = open(sys.argv[1]).read()
45+
46+
# Brace-balanced extraction: <return type> HIRBuilder::emitXxx( ... ) { ... }
47+
methods = []
48+
i = 0
49+
while i < len(src):
50+
m = re.search(r'^(\w[\w\s:&*<>]*?)\s+HIRBuilder::(emit\w+)\s*\(', src[i:], re.MULTILINE)
51+
if not m:
52+
break
53+
name = m.group(2)
54+
ret_type = m.group(1).strip()
55+
start = i + m.start()
56+
paren_close = src.find(')', start)
57+
brace = src.find('{', paren_close)
58+
if brace == -1:
59+
break
60+
depth = 1
61+
j = brace + 1
62+
while j < len(src) and depth > 0:
63+
if src[j] == '{':
64+
depth += 1
65+
elif src[j] == '}':
66+
depth -= 1
67+
j += 1
68+
body = src[brace + 1:j - 1]
69+
methods.append((name, ret_type, body))
70+
i = j
71+
72+
stubs, partial, pure_cpp = [], [], []
73+
for name, ret_type, body in methods:
74+
body_lines = [l.strip() for l in body.strip().split('\n')
75+
if l.strip() and not l.strip().startswith('//')]
76+
has_c_call = 'hir_builder_emit_' in body
77+
if not has_c_call:
78+
pure_cpp.append((name, ret_type))
79+
elif len(body_lines) <= 8:
80+
stubs.append((name, ret_type))
81+
else:
82+
partial.append((name, ret_type))
83+
84+
total = len(methods)
85+
converted = len(stubs) + len(partial)
86+
ratio = (converted / total * 100) if total else 0.0
87+
88+
print(f"=== HIRBuilder::emit* C-conversion baseline ({sys.argv[1]}) ===")
89+
print(f"TOTAL: {total}")
90+
print(f" STUBS (delegate to C, body <=8 lines): {len(stubs)}")
91+
print(f" PARTIAL (some C, some C++): {len(partial)}")
92+
print(f" PURE C++ (no C call): {len(pure_cpp)}")
93+
print(f"CONVERTED (stubs + partial): {converted}")
94+
print(f"RATIO: {converted}/{total} = {ratio:.1f}%")
95+
print()
96+
print("=== Pure C++ method list ===")
97+
for name, ret_type in sorted(pure_cpp):
98+
print(f" {ret_type} {name}")
99+
print()
100+
print("=== Partial method list ===")
101+
for name, ret_type in sorted(partial):
102+
print(f" {ret_type} {name}")
103+
PYEOF

0 commit comments

Comments
 (0)