Repository navigation
fix(zig): bound the single-quote pattern in _build_brace_safe_stream - #1676
Merged
Merged
Conversation
zig's char literals ('a', '\n', '\u{1F600}') are just as short-lived as
rust's, but _build_brace_safe_stream's single-quote pattern was still
unbounded for zig. Zig also has multi-line `\\`-prefixed string literals
that are never shielded at all here (a separate, pre-existing gap) -- so a
real contraction/possessive apostrophe inside one of those strings' prose
content (confirmed on language-crucible's zig/main.zig:128, "Compare Zig's
CPU feature detection") reached the unbounded pattern as an unpaired `'`,
which greedily searched forward for the NEXT unrelated `'` (found ~44 lines
later, in "won't") and blanked everything in between -- including the `{`
of a real function's own opening brace.
That single swallowed `{` desyncs the brace-depth counter for the rest of
the scan: whichever function's body search was already in flight when the
desync hit never finds its real closing brace and instead swallows every
subsequent line until some later, unrelated `}` happens to rebalance the
count. Confirmed on this exact corpus: main.zig's `wasi_cwd` (line 60)
swallowed lines 60-7104 (nearly the whole 7529-line file) as its own
"body", hiding every function after it -- including the 3 named in the
original #1419 fix's primary repro (`ZigClang_main` and friends), which is
why that fix (extern/export calling-convention + quoted-identifier support)
left this file's found-function count completely unchanged at 18.
Bounded the pattern to 10 chars for zig, mirroring rust's existing bound
exactly (same idiom, same function). main.zig alone: 18 -> 68 functions
found. Full zig corpus: found_functions 2700 -> 2750, args_exact_match
2700 -> 2750, zero new extra_functions.
Fixes #1426
Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
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 #1426. Follow-up to #1419, whose calling-convention/quoted-identifier
fix left this issue's primary repro file (
main.zig, 7529 lines) completelyunchanged at 18 found functions -- a separate, pre-existing mechanism.
_build_brace_safe_stream's single-quote pattern was unbounded for zig(only rust had the bounded
{0,10}form). Zig's char literals ('a','\n','\u{1F600}') are just as short-lived as rust's, but zig also hasmulti-line
\\-prefixed string literals that are never shielded at allhere (a separate, pre-existing gap) -- so a real contraction/possessive
apostrophe inside one of those strings' prose content (confirmed on
main.zig:128,"Compare Zig's CPU feature detection") reached theunbounded pattern as an unpaired
', which greedily searched forward forthe NEXT unrelated
'(found ~44 lines later, in"won't") and blankedeverything in between -- including the
{of a real function's own openingbrace (
pub fn log(...) {at line 142).That single swallowed
{desyncs the brace-depth counter for the rest ofthe scan: whichever function's body search was already in flight when the
desync hit never finds its real closing brace and instead swallows every
subsequent line until some later, unrelated
}happens to rebalance thecount. Confirmed on this exact corpus:
main.zig'swasi_cwd(line 60)swallowed lines 60-7104 (nearly the whole file) as its own "body", hiding
every function after it -- including
ZigClang_mainand friends, #1419'sown primary repro, which is exactly why that fix left this file's count
unchanged.
Fix
Bounded the pattern to 10 chars for zig, mirroring rust's existing bound
exactly (same idiom, same function, same fix shape).
Verification
crucible_check.py --mode bothblessed via--update --yes(expectedcascading drift -- main.zig's function count nearly quadrupling shifts a lot
of downstream stats, which is real signal, not noise).
audit_check.py --ciclean.
Type of change
detector.py)Differential Scan target
Zig parser corpus (zig compiler source) -- the same file the issue's
measurements came from.
Co-Authored-By: Claude Sonnet 5 [email protected]