Repository navigation
Description
Summary
zig's args_exact_match was the single worst-performing language/metric pair
in docs/self_scan/tree_sitter_accuracy_history.csv at 75.78% (2046/2700),
far below every other baselined language (next-worst was java at 86.98%).
Root cause
Unlike most languages' args regex, zig's capture group is the bare inner
parameter-list text only -- it never shares group(0) with a fn name(...)
prefix the way python's does, so it never satisfies the existing #1199
self-contained-"(...)" detection in detector.py::_calculate_block_metrics.
That routed every zig signature into one of two heuristics, both wrong for
this capture shape:
- Comma-free single param (
self: Default) fell into the naive
whitespace-split fallback, which miscounted the internal space in the type
annotation as a second argument (self:,Default-> 2). Majority of the
mismatches (real=1 got=2/3). - Multi-param lists where a param's TYPE itself contains literal parens
(ctx: @This(), function-pointer paramsfn (?*anyopaque) void, both
idiomatic Zig) broke_count_top_level_args's own wrapper-detection: it
assumes the first(it finds via.find("(")is the signature's outer
wrapper (true for python's"def foo(x, y)"-shaped capture) and re-slices
to just that inner span, silently truncating or zeroing the real body
(measured got=0/1 against real up to 12). - A third, narrower bug:
_count_top_level_args's depth counter treats a
bare>as a generic-closing bracket, but zig's=>switch/match-arm
arrow is a two-char token whose>isn't a bracket -- decrementing depth
on it let aswitch (operation) { .a, .b => X, ... }parameter-type
expression's internal commas leak out as false top-level separators
(tigerbeetle/state_machine.zig::transient_errormeasured got=10 against
real=4).
Fix
- Added
_count_top_level_args(args_str, treat_as_body=True): skips the
wrapper-detection re-slice entirely, depth-counting top-level commas over
the whole captured string as-is. - Added an opt-in
_args_bare_body_groupsrules-dict flag (zig's args group
index 1) sodetector.pyroutes zig through this new path instead of the
whitespace-split/wrapper-detection heuristics. - The
=>depth-counter fix is scoped totreat_as_body=Trueonly (i.e.
zig's own call path) rather than applied unconditionally, to avoid
rippling into other languages' baselines in what should be a zig-scoped
change -- see follow-up issue for the analogous pre-existing bug in other
languages' wrapper-detected path.
Result
args_exact_match 2046/2700 (75.78%) -> 2700/2700 (100%). Baseline
regenerated in tests/tree_sitter_accuracy_baseline_zig.json. Golden master
fixtures re-blessed (tests/golden_master_audit.json,
tests/golden_master_zero_dep_audit.json) since real-world zig function
Input Parameters counts changed. Full test suite (6922 tests) and
crucible_check.py (both full-precision and zero-dependency venvs) pass
clean.
Activity
fix(core): zig args accuracy 75.8% -> 100% (bare-body param-list capt…