Repository navigation
Description
Summary
tests/tools/tree_sitter_accuracy_audit.py's haskell func_node_types ({"function", "bind"}) treats each pattern-matching equation clause of a multi-clause Haskell function as its own separate real_functions occurrence, because that's how tree-sitter-haskell's grammar structures them (one function node per clause, all siblings under the same declarations/local_binds parent). GitGalaxy's _slice_by_indentation (detector.py) deliberately merges all clauses of one function into a single reported FunctionNode (#1442's own comment: "clauses 2..N would otherwise each spawn their own duplicate, overlapping FunctionNode") — which is the semantically correct behavior (one function, however many equations). The audit tool's per-clause ground truth then scores every clause beyond the first as a "missing" real function, via _align_occurrences_by_line's one-to-one line alignment.
Currently-shipped baseline for language-crucible/data/haskell/pandoc (2026-08-14): real_functions=275, found_functions=139 — 50.5% recall. This is almost entirely a measurement artifact, not a real GitGalaxy defect.
Root Cause
Confirmed directly by parsing a minimal multi-clause definition with tree_sitter_language_pack.get_parser("haskell"):
deNote :: Inline -> Inline
deNote (Note _) = Str ""
deNote x = xproduces one signature node plus two separate function nodes (rows 1 and 2 of the equations) — tree-sitter has no single node representing "deNote, the function," only per-clause nodes. measure()'s walk() in tree_sitter_accuracy_audit.py records each as its own (start_line, param_count) tuple under real_funcs["deNote"], so a function with N clauses always contributes N real occurrences, while GitGalaxy (correctly) contributes 1 — _align_occurrences_by_line then reports N−1 as unmatched real occurrences for every single multi-clause function.
Verification
Re-walked the same 7-file corpus with a clause-collapse pass (consecutive same-name function/bind siblings under one parent merged into a single occurrence, keyed by the first clause's line — asking the ground truth the same question GitGalaxy's own detector.py already answers), reusing the existing _align_occurrences_by_line and _get_param_count unchanged, against the exact same (unmodified) GitGalaxy output:
| real_functions | found_functions | recall | |
|---|---|---|---|
| Current (per-clause) | 275 | 139 | 50.5% |
| Clause-collapsed (GG semantics) | 148 | 139 | 93.9% |
Every one of the ~40 names the current measurement lists as "missing" in this corpus (deNote, blockToInlines, isPara, toJSON, tabFilter, compactify, isSingleton, plainToPara, removeNote, splitBy, and more) is a multi-clause pattern-matched definition that GitGalaxy found in full — spot-checked several directly against function_data (e.g. isPara found at its signature line with the full 2-clause block absorbed; blockToInlines's 7-clause block correctly captured as one span).
The residual, genuine gap after collapsing is 9 real misses across 2 files — a much smaller, distinct, already-filed problem (see #1616 and #1615): local where/let-introduced helpers whose defining equation has no = on the naming line itself (guard-only clauses), and single-line where name args = expr openers (same shape #1564 fixed for let, not yet extended to where).
Proposed Fix
In measure()'s walk() (tree_sitter_accuracy_audit.py), for languages where one logical function is represented as multiple sibling clause nodes (currently just haskell), collapse consecutive same-name func_node_types siblings under the same parent into a single real_funcs occurrence before counting — mirroring GitGalaxy's own, already-correct one-function-per-name semantics instead of tree-sitter's raw per-clause node granularity. Gate this behind a lang == "haskell" check (or a new NODE_MAPS flag) so it doesn't change behavior for any other NODE_MAPS language, none of which have this clause-per-node grammar shape.
Note: per CLAUDE.md's standing instruction, this exact mismatch (GitGalaxy's regex-based "one function, one entity" semantics beating tree-sitter's raw per-clause node count for the purpose of counting functions) has been logged as Claim 4 in docs/why_gitgalaxy_beats_ast_here.md.
Related Work
- haskell func_start: typeclass instance methods and where-clause locals without an explicit '::' signature are structurally invisible #1442, haskell func_start: hardcoded '< 2 lines' floor in _slice_by_indentation drops every abstract typeclass method signature #1435, haskell func_start: single-line
let name args = exprlocal bindings are structurally invisible #1564, tcl args regex: default-value braced parameters overcounted (proc foo {{db db}} measures got=2, real=1) #1512, haskell args regex: signature-less equations measure 0, and qualified/dotted types truncate the :: signature capture #1511, tree_sitter_accuracy_audit: haskell's _get_param_count never finds parameters (equation node's pattern list field is 'patterns', not 'parameters') #1505, tree_sitter_accuracy_audit: haskell NODE_MAPS excludes tree-sitter'sbindnode, undercounting point-free functions as false positives #1566, Haskell: detector.py's start_line looks shifted by roughly one prior function when short definitions are stacked #1532, haskell func_start: trailing-apostrophe (prime) function names collapse into their unprimed sibling #1565 (haskell func_start/args hardening, all closed) - rust/swift func_start extra_functions rose after #1302's prism.py fix -- newly exposed, not caused #1311/rust func_start misses bodyless multi-line trait method signatures (deserialize_* family) #1319/tree_sitter_accuracy_audit: _get_param_count node-type whitelist missing real per-language parameter node types (11 languages) #1339 (prior cases where the audit tool's own ground truth, not GitGalaxy's regex, was the root cause)
- [TIER 3] Broaden scala/matlab/haskell func_start regexes -- safe, zero current false positives #1266 (original scala/matlab/haskell func_start broadening epic)
- haskell func_start: single-line
where name args = exprlocal bindings are structurally invisible #1615, haskell func_start: guard-only defining equations (no '=' on the naming line) are structurally invisible #1616 (residual genuine misses isolated by this investigation)
Activity
docs: correct Claim 4 numbers to match the shipped #1614 fix (#1618)
docs: log Claim 4 (haskell multi-clause function counting) in beats-A…
Fix haskell clause-splitting in tri-comparison's tree-sitter walk (#1865
Tri-comparison chart: drop recall/args ratios for unranked found-coun…
Resolve all 6 rust tri-comparison ledger shapes (#1873)