Skip to content

tree-sitter ground truth: perl bodyless forward declarations counted as real functions GitGalaxy correctly ignores #1608

Closed

Description

@squid-protocol

Summary

Found while investigating perl's func_recall accuracy gap (937/1063 = 88.1% baseline): old Perl style uses bodyless forward declarations pre-declaring a sub's prototype before its real definition appears later in the file (e.g. line 75: sub AbsPath($); with no body, then line 4505: sub AbsPath($) { ... } with a real body). Tree-sitter's perl grammar uses the same subroutine_declaration_statement node type for BOTH the bodyless declaration AND the real definition. The ground-truth measurement tool counts BOTH occurrences as separate real functions.

GitGalaxy correctly finds and scores only the real, body-bearing definition (there is no executable logic in a bodyless declaration for branch/io/etc. to fire inside) -- the line-4505 occurrence IS present and correctly paired in GitGalaxy's function_data output. But the bodyless declaration shows up as a permanently unpairable "missing" entry in the --lang perl --verbose audit output's missing-functions sample, dragging down the measured func_recall_pct even though GitGalaxy isn't actually missing anything real.

Confirmed via language-crucible/data/perl/exiftool/exiftool and exiftool/ExifTool.pm: dozens of names appear TWICE in the ground truth's real_functions walk -- once as a bodyless declaration near the top of the file, once as the real definition much later with an actual body.

Root cause

File: tests/tools/tree_sitter_accuracy_audit.py, the measure() function's real-function-walking logic for perl (perl's func_node_types entry in NODE_MAPS includes subroutine_declaration_statement, which tree-sitter-perl uses for both cases).

When iterating tree-sitter nodes to build the real_functions ground truth, no check is made for whether the node has an actual body field child. A subroutine_declaration_statement node without a body is a forward declaration, not a real executable function.

Fix strategy

Mirror how _count_perl_real_args (added by #1519's fix, PR #1520) already checks node.child_by_field_name("body") and treats a missing body as 0 args: add a similar check in the real-function walk. When a subroutine_declaration_statement or method_declaration_statement node has no body field child, skip counting it as a real function entirely rather than adding it to real_funcs.

This is the same architectural solution already resolved for objective-c in #1336 ("objc C-style prototype bodyless fix"): the correct fix direction was to make the ground-truth audit tool EXCLUDE bodyless declarations from its real_functions count (rather than try to make GitGalaxy's engine somehow detect/report a phantom function for a declaration with no code).

References

#1336 (objc bodyless-declarations fix, same principle applied there), #1519 (perl args fix that already handles missing-body detection), #1520 (PR for #1519), #1227 (parent tree-sitter-accuracy epic), #1261 (related args-counting accuracy work).

Activity

  1. added
    bug
    testing
    core-engine
    on Aug 14, 2026
  2. squid-protocol commented on Aug 14, 2026

    @squid-protocol
    OwnerAuthor

    Fixed and verified in #1610 (merged, all CI green): tree_sitter_accuracy_audit.py's perl real-function walk now skips subroutine_declaration_statement/method_declaration_statement nodes with no body field child, matching the #1336 objective-c precedent. Confirmed via the same audit tool: real_functions dropped from the inflated 1063 to the correct 941, and func_recall rose from 88.1% to 99.68% (938/941) once combined with #1606/#1607's engine-side fixes. Note: this fix also unmasked a separate, narrow engine bug filed as #1609 (not fixed here).

  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-enginetesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions