Skip to content

fix(zig): recognize extern/export calling-convention strings and @"..." quoted identifiers in func_start - #1433

Merged
squid-protocol merged 7 commits into
mainfrom
fix/zig-1419-extern-callconv-quoted-ident
Aug 13, 2026
Merged

squid-protocol merged 7 commits into
mainfrom
fix/zig-1419-extern-callconv-quoted-ident

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Aug 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

Fixes #1419. Two additive func_start recall gaps for zig, both zero-risk (precision already
100%, no new false positives to preserve).

Root cause (broader than the issue's suggested regex-only fix)

The regex itself already had partial support (extern already accepted an optional
calling-convention string, and the name-capture group already had a @"..." alternative), but:

  1. export (unlike extern) didn't accept the calling-convention string form -- narrow regex
    gap, fixed alongside tightening both extern/export's string handling to support backslash
    escaping (\"(?:[^"\\]|\\.)*\" instead of the old unescaped [^"]+).
  2. The real blocker for @"..."-quoted identifiers was upstream of the regex entirely:
    detector.py's shared string-shield step was blanking @"resume"-style text out as an
    ordinary string literal before func_start ever got to see it, and the shared
    _extract_name() post-processor's word-tokenization character class didn't allow @/"
    either -- so even a successful regex match would have its captured name mangled on the way out.

Fix

  • func_start regex: export now accepts the same optional calling-convention string as
    extern; both use proper backslash-escaping for the string body.
  • detector.py, zig-gated (lang_id == "zig"): the string-shield's fast_shield() now passes
    @"..." text through unblanked; the shield's own string-matching alternation uses a
    zig-specific backslash-escape pattern instead of reusing C#'s ""-doubling verbatim-string
    rule (different escaping conventions, same @"..." prefix is coincidental); the bare-;
    bodyless-declaration handling (previously rust-only, from rust func_start misses bodyless multi-line trait method signatures (deserialize_* family) #1319) now also covers zig, needed so
    extern "c" fn foo(...) c_int; isn't dropped for lacking a {} body.
  • detector.py, content-gated on the @" prefix marker (not lang_id -- this function has no
    language parameter at all, called from 3 sites as a stateless string-normalizer):
    _extract_name() early-returns raw for any match starting with @". This alone is sufficient
    and correctly scoped for zig's case.

Correction, found by CI, not by pre-push verification: the implementation's first pass also
widened _extract_name()'s word-tokenization character class to allow bare @/" generally, on
the reasoning that no other language's captured name could legitimately start with @". That
reasoning covered the early-return correctly but missed that the character class itself applies
unconditionally to every language's tokenization, not just the @"-prefixed case -- CSS's own
@media/@import at-rules also contain a bare @, and the widened class kept it glued to the
following word instead of splitting on it as a non-word separator, so @media stopped being
reported as media. CI's tree-sitter-accuracy-audit --all (which diffs every baselined
language, not just zig) caught this as a real regression on the css baseline after this PR's
first push -- the repo-wide test suite and targeted csharp/cpp/rust/scala spot-checks I ran
locally didn't exercise CSS at all, so they passed clean while the bug was live. Fixed by
reverting the character-class widening (unnecessary -- the early-return already fully covers
zig's case before execution ever reaches that line) in a follow-up commit on this same branch.
Confirmed both --lang css --ci and --lang zig --ci clean afterward, plus --all --ci across
all 31 baselined languages.

Root-caused by Claude, implemented by Gemini (agy/Antigravity CLI) in an isolated worktree,
independently re-verified end-to-end by Claude before push (full-suite regression run, diff
review, live before/after numbers) -- see repo's established Claude/Gemini pairing workflow.

Results

tests/tools/tree_sitter_accuracy_audit.py --lang zig:

metric before after
found_functions 1828 2424
extra_functions 0 0
func recall 73.9% 98.0%
func precision 100% 100%

Known remaining gap (follow-up filed separately, not this PR)

#1426: the issue's own flagship named repro (zig/main.zig's ZigClang_main and 2 others) is
still not found -- confirmed via git stash A/B test that this file finds exactly 18 functions
both before and after this fix, completely unaffected by it, even though the fixed regex matches
the relevant line correctly in an isolated minimal repro. A separate, pre-existing, not-yet-
understood mechanism specific to this file -- needs its own root-cause pass.

Test plan

  • tests/extraction/languages/test_zig.py / test_zig_strict.py -- 111 passed, 2 xfailed (3
    new valid cases: extern "stdcall" fn, export "c" fn, pub fn @"resume"() void {})
  • Full repo test suite (pytest tests/) -- 6851 passed, 2 skipped, 11 xfailed, 3 xpassed (the
    3 xpasses are pre-existing JCL known-limitations, unrelated to this change)
  • tree_sitter_accuracy_audit.py --lang zig --regenerate + --summary-table
  • crucible_check.py --mode both -- both golden masters blessed (expected drift from +596
    found functions), re-verified clean after
  • audit_check.py --ci --regenerate -- ruff/mypy/dead-key/ast-accuracy all clean (one real
    ruff format fix applied -- a stray blank line left by the implementation pass -- plus 4
    pure line-shift baseline entries auto-regenerated)

🤖 Generated with Claude Code + Gemini (Antigravity CLI)

squid-protocol and others added 6 commits August 13, 2026 09:29
…." quoted identifiers in func_start (#1419)

Two additive recall gaps, both zero-risk (100% precision held, no new false
positives):

1. extern/export followed by a calling-convention string literal
   (`extern "c" fn foo(...) c_int;`) is now recognized in both the func_start
   regex's prefix alternation and the shared bare-`;`-terminated bodyless-
   declaration handling in detector.py (previously rust-only, from #1319 --
   now `lang_id in ("rust", "zig")`).

2. Zig's `@"..."`-quoted identifier syntax (used for reserved-word names and
   FFI symbol names) is now recognized end-to-end. The func_start regex
   already had a `@"..."` alternative in its name-capture group, but
   detector.py's shared string-shield step was blanking that text out as if
   it were an ordinary string literal before func_start ever saw it, and the
   shared `_extract_name()` post-processor's word-tokenization character
   class didn't allow `@`/`"` either -- both are now zig-gated exceptions
   (the `_extract_name()` early-return and the widened findall character
   class are not lang-gated, since no other language's captured match text
   can legitimately start with `@"`, confirmed via full-suite regression run).

found_functions 1828->2424 (recall 73.9%->98.0%), extra_functions held at 0.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Gemini 3.1 Pro <[email protected]>
…ary table + golden masters + ruff baseline

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…allconv-quoted-ident

# Conflicts:
#	tests/golden_master_audit.json
#	tests/golden_master_zero_dep_audit.json
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

… regressed css @media

CI's tree-sitter-accuracy-audit --all caught a real cross-language
regression: widening _extract_name()'s word-tokenization character class to
include bare '@' (added to support zig's @"..." quoted identifiers) also
changed css's own at-rule name extraction, since '@media'/'@import' etc. now
kept the '@' as part of the token instead of splitting on it as a
non-word-char separator -- css func_start started reporting "@media" instead
of "media", failing its committed baseline.

The widening was actually unnecessary: the early-return added right above it
(`if match_strip.startswith('@"'): return match_strip`) already fully
handles zig's own @"..." case before execution ever reaches this
tokenization step. Reverting the character class to its original
[a-zA-Z0-9_./%$():~-] fixes css with zero effect on zig's own numbers
(confirmed via --lang zig --ci and the full repo test suite, both still
clean) -- the early-return alone is the correct, sufficient, and properly-
scoped fix for the @"..." case.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit 3602305 into main Aug 13, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/zig-1419-extern-callconv-quoted-ident branch August 13, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

zig func_start misses extern/export calling-convention prefix and @"..."-quoted identifier names

1 participant