Skip to content

zig args: whitespace-split fallback + wrapper-detection both broke on bare-body args capture (75.8% -> 100%) #1645

Closed

Description

@squid-protocol

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:

  1. 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).
  2. Multi-param lists where a param's TYPE itself contains literal parens
    (ctx: @This(), function-pointer params fn (?*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).
  3. 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 a switch (operation) { .a, .b => X, ... } parameter-type
    expression's internal commas leak out as false top-level separators
    (tigerbeetle/state_machine.zig::transient_error measured 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_groups rules-dict flag (zig's args group
    index 1) so detector.py routes zig through this new path instead of the
    whitespace-split/wrapper-detection heuristics.
  • The => depth-counter fix is scoped to treat_as_body=True only (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

  1. added
    bug
    testing
    core-engine
    threat: false-negative
    on Aug 15, 2026
  2. added a commit that references this issue on Aug 15, 2026
    fac5029
  3. added this to the v2.4.8 milestone on Aug 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginetestingthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions