Skip to content

fix(csharp,objective-c): fix csharp func_start false positives, objc ground-truth gap - #1328

Merged
squid-protocol merged 1 commit into
mainfrom
fix/1314-objc-csharp-func-precision
Aug 12, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/1314-objc-csharp-func-precision

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Closes #1314. Investigated both languages' reported func_start precision problems and found the root causes differ per language:

objective-c (4.4% → 98.2% measured precision): pure ground-truth bug, no engine change needed.
Objective-C's method_definition/method_declaration tree-sitter nodes have no "name" field in this grammar, so _get_node_name in tree_sitter_accuracy_audit.py silently returned None for every real method, and none of them ever entered real_functions. Every method GitGalaxy correctly detected (traceOn, registerAccess, free, ...) then scored as a false "extra" — a 20:1-looking false-positive ratio that was entirely an artifact of the measurement tool, the same shape as #1313/#1311's precedents. Fixed _get_node_name to read the selector's first identifier child. Confirmed against language-crucible/data/objective-c/worldwideweb: found_functions 5→111, extra_functions 108→2 (the 2 remaining are a legitimate extern C prototype and a tree-sitter parse-error artifact on that file, not GitGalaxy bugs).

csharp (58.2% → 63.4% measured precision): a mix of a ground-truth gap and a real engine bug.

  • Ground truth was missing constructor_declaration from func_node_types (a distinct tree-sitter node type from method_declaration), scoring every real C# constructor as a false extra.

  • The real bug: func_start's permissive "return type" token walk and its final "not a function" shield only excluded modifier/control-flow keywords, not the contextual keywords C# 9+ allows directly before a (:

    • static (a, b) => ... (static lambdas)
    • var (a, b) = Method(...) (tuple deconstruction)
    • catch (Ex e) when (...) (exception filters)
    • x is Foo or Bar (pattern combinators)

    These were captured whole as phantom functions literally named "static"/"var"/"when"/"or". Separately, foreach (var x in expr.Method())-shaped statement headers got silently swallowed token-by-token by the same permissive walk, landing on the loop expression's own receiver+method as a fake function name (e.g. "changes.GetAddedProjects").

    All confirmed against real corpus source (language-crucible/data/csharp/roslyn/{CSharpCompilation,Workspace}.cs) and independently reproduced in xml/powertoys/MainWindow.xaml.cs during golden-master regeneration (removed a phantom hitTestGrid.Children.OfType function there too).

    Most of csharp's remaining extra_functions (322 of 329) trace to tree-sitter's own parse failure on one 14k-line Roslyn source file (LanguageParser.cs, has_error=True from the very first line) — a ground-truth/corpus limitation, not something fixable on the GitGalaxy side.

Changes

  • gitgalaxy/standards/language_standards.py: csharp func_start regex — extended both the per-token exclusion and the final "not a function" shield with the contextual-keyword set above; regenerated the tree-sitter-accuracy summary table in the module docstring.
  • tests/tools/tree_sitter_accuracy_audit.py: objc _get_node_name fix; added constructor_declaration to csharp's NODE_MAPS.
  • tests/extraction/languages/test_csharp.py: 5 new invalid-case tests for the fixed false-positive shapes.
  • tests/tree_sitter_accuracy_baseline_{csharp,objective-c}.json: regenerated via --regenerate.
  • tests/golden_master_audit.json / tests/golden_master_zero_dep_audit.json: regenerated via update_golden_master.py (real func_start output changed across the differential corpus for csharp, as expected for a false-positive fix).

Test plan

  • pytest tests/extraction/languages/test_csharp.py tests/extraction/languages/test_csharp_strict.py tests/extraction/languages/test_objectivec.py tests/extraction/languages/test_objectivec_strict.py — all pass
  • Full suite: pytest tests/ — 6831 passed, 2 skipped, 11 xfailed, 3 xpassed
  • tests/tools/audit_check.py — ruff/mypy/dead-key/ast-accuracy all clean against baselines
  • tests/tools/crucible_check.py — full_precision and zero_dependency both PASS against the regenerated golden masters

…objc ground-truth gap (#1314)

objective-c's measured 4.4% func_start precision was entirely a ground-truth
bug in tree_sitter_accuracy_audit.py: Objective-C's method_definition/
method_declaration nodes have no "name" field in this grammar, so
_get_node_name silently returned None for every real method and none of
them ever entered real_functions -- every method GitGalaxy correctly found
(traceOn, registerAccess, free, ...) then scored as a false "extra".
GitGalaxy's own engine needed no change; fixing name extraction alone moves
measured precision to 98.2% (108 -> 2 extra, both explainable: one is a
legitimate extern C prototype, the other is a tree-sitter parse-error
artifact on that specific file).

csharp had a mix of both problems:
- Ground truth was also missing constructor_declaration from func_node_types
  (csharp constructors are a distinct tree-sitter node type from
  method_declaration), scoring every real constructor as a false extra.
- The engine itself had a real bug: func_start's "return type" token walk
  and its final "not a function" shield only excluded MODIFIER and
  control-flow keywords, not the contextual keywords that can directly
  precede a `(` in non-function C# 9+ constructs. `static (a, b) => ...`
  (static lambdas), `var (a, b) = Method(...)` (tuple deconstruction),
  `catch (Ex e) when (...)` (exception filters), and `x is Foo or Bar`
  (pattern combinators) were captured whole as phantom functions literally
  named "static"/"var"/"when"/"or". Separately, `foreach (var x in
  expr.Method())` and similar statement headers got silently swallowed
  token-by-token by the permissive walk, landing on the loop expression's
  own receiver+method as a fake function name (e.g. "changes.
  GetAddedProjects"). All confirmed against real corpus source
  (language-crucible/data/csharp/roslyn/{CSharpCompilation,Workspace}.cs)
  and reproduced independently in xml/powertoys/MainWindow.xaml.cs during
  golden-master regeneration.

Measured csharp func precision moves 58.2% -> 63.4%; most of the remaining
extra_functions (322/329) trace to tree-sitter's own parse failure on one
14k-line Roslyn source file (has_error=True), a ground-truth/corpus
limitation rather than a GitGalaxy defect.

Regenerated both tree-sitter accuracy baselines and both golden-master
fixtures (func_start output changed for csharp across the differential
corpus, as expected for a false-positive fix).

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

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.

objective-c func_start (4.4% precision) and csharp func_start (58.2% precision) have large, confirmed-real false-positive rates

1 participant