Repository navigation
fix(zig): recognize extern/export calling-convention strings and @"..." quoted identifiers in func_start - #1433
Merged
Conversation
…." 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]>
…allconv-quoted-ident
…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
…arp #1418 landed first) Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
… 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1419. Two additive
func_startrecall gaps for zig, both zero-risk (precision already100%, no new false positives to preserve).
Root cause (broader than the issue's suggested regex-only fix)
The regex itself already had partial support (
externalready accepted an optionalcalling-convention string, and the name-capture group already had a
@"..."alternative), but:export(unlikeextern) didn't accept the calling-convention string form -- narrow regexgap, fixed alongside tightening both
extern/export's string handling to support backslashescaping (
\"(?:[^"\\]|\\.)*\"instead of the old unescaped[^"]+).@"..."-quoted identifiers was upstream of the regex entirely:detector.py's shared string-shield step was blanking@"resume"-style text out as anordinary string literal before
func_startever 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_startregex:exportnow accepts the same optional calling-convention string asextern; both use proper backslash-escaping for the string body.detector.py, zig-gated (lang_id == "zig"): the string-shield'sfast_shield()now passes@"..."text through unblanked; the shield's own string-matching alternation uses azig-specific backslash-escape pattern instead of reusing C#'s
""-doubling verbatim-stringrule (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 (notlang_id-- this function has nolanguage 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 sufficientand 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, onthe reasoning that no other language's captured name could legitimately start with
@". Thatreasoning 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/@importat-rules also contain a bare@, and the widened class kept it glued to thefollowing word instead of splitting on it as a non-word separator, so
@mediastopped beingreported as
media. CI'stree-sitter-accuracy-audit --all(which diffs every baselinedlanguage, not just zig) caught this as a real regression on the
cssbaseline after this PR'sfirst 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 --ciand--lang zig --ciclean afterward, plus--all --ciacrossall 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:Known remaining gap (follow-up filed separately, not this PR)
#1426: the issue's own flagship named repro (
zig/main.zig'sZigClang_mainand 2 others) isstill not found -- confirmed via
git stashA/B test that this file finds exactly 18 functionsboth 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 (3new valid cases:
extern "stdcall" fn,export "c" fn,pub fn @"resume"() void {})pytest tests/) -- 6851 passed, 2 skipped, 11 xfailed, 3 xpassed (the3 xpasses are pre-existing JCL known-limitations, unrelated to this change)
tree_sitter_accuracy_audit.py --lang zig --regenerate+--summary-tablecrucible_check.py --mode both-- both golden masters blessed (expected drift from +596found functions), re-verified clean after
audit_check.py --ci --regenerate-- ruff/mypy/dead-key/ast-accuracy all clean (one realruff formatfix applied -- a stray blank line left by the implementation pass -- plus 4pure line-shift baseline entries auto-regenerated)
🤖 Generated with Claude Code + Gemini (Antigravity CLI)