Skip to content

perl func_start: qr{...}/m{...}-style brace-delimited regex literals desync _slice_by_braces, dropping every function after the first one #1437

Closed

Description

@squid-protocol

Summary

tests/tools/tree_sitter_accuracy_audit.py --lang perl measures func_start recall at only 70.6%
(710/1005 real functions found). Root cause confirmed via direct pipeline tracing: this is NOT a
func_start regex gap -- the regex correctly matches every one of 23 real sub Name {}
definitions in the repro file below, at their correct positions -- it's a brace-counting desync in
_slice_by_braces (Mode B) caused by Perl's custom-delimiter quote-like operators (qr{...},
likely also m{...}, s{...}{...}, tr{...}{...}) not being shielded before brace-depth
counting runs.

Repro

language-crucible/data/perl/bugzilla/CGI.pm: func_start.finditer() correctly finds all 23
real sub definitions in this file, in order, at the correct line numbers. But a full
galaxyscope scan of just this file finds only 8 of them: the first 5 (lines 24-242) and the
last 3 (lines 700-720) -- everything in between (lines 264-678, 15 functions) is silently
dropped.

The drop-off begins immediately after check_etag (found, ends line 260) and before
multipart_start (the first one dropped, starts line 264). Between close_standby_message
(also dropped) and _prevent_unsafe_response (also dropped), at line 317:

sub _prevent_unsafe_response {
  my ($self, $headers) = @_;
  my $safe_content_type_re = qr{
        ^ (*COMMIT) # COMMIT makes the regex faster
        ...

qr{...} is Perl's brace-delimited regex-literal quote-like operator -- its content between the
braces is arbitrary regex syntax (which can itself contain {/} from quantifiers like {2,4},
nested groups, or just literal braces if the regex targets brace characters), not real code-block
structure. grep -n "qr{" confirms this file uses the construct twice (lines 317, 337) and
gitgalaxy/core/prism.py/gitgalaxy/standards/language_standards.py's perl entry has no special
handling for qr/m/s/tr custom-delimiter forms at all -- only the ordinary /.../ regex
and '...'/"..." string forms appear to be shielded. A naive brace-counter treating qr{'s
opening brace as a real block-open (and whatever {/} characters happen to appear inside the
regex body as real nested block boundaries) desyncs the running depth count for the rest of the
file -- explaining both why everything after this point is dropped (their real start positions
now look like they're "inside" an unclosed block) and why STORE/FETCH/DELELTE near the end of the
file happen to resync (the accumulated depth count coincidentally returns to 0 by chance before
reaching them).

Suggested fix shape

Perl's quote-like operators (q, qq, qr, m, s, tr/y) all support arbitrary matched
delimiter pairs ({}, (), [], <>, or any non-alphanumeric character used as both open and
close for a symmetric delimiter). At minimum, the brace-delimited forms (qr{...}, m{...},
s{...}{...}, tr{...}{...}) need to be recognized and shielded (their entire span replaced with
a neutral placeholder, same idiom as string/comment shielding elsewhere in prism.py) BEFORE any
brace-depth counting runs for perl, so their internal {/} characters never reach
_slice_by_braces. Verify against tests/extraction/languages/test_perl.py and re-run
python tests/tools/tree_sitter_accuracy_audit.py --lang perl --regenerate to confirm
found_functions (currently 710) rises meaningfully toward real_functions (1005) without
extra_functions (currently near 0) climbing.

Scope note

This only affects func_start/args/class_start name-extraction accuracy (the extraction-
gauntlet pillar from epic #813), not GitGalaxy's risk-scoring rules, which are unaffected.

Activity

  1. added
    bug
    testing
    core-engine
    threat: false-negative
    priority: high
    on Aug 13, 2026
  2. 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-enginepriority: hightestingthreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions