Skip to content

Fix haskell clause-splitting in tri-comparison's tree-sitter walk - #1865

Merged
squid-protocol merged 4 commits into
mainfrom
tri-comparison-clause-fix
Aug 19, 2026
Merged

squid-protocol merged 4 commits into
mainfrom
tri-comparison-clause-fix

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

  • tests/tools/tri_comparison_gatherer.py::_walk_tree_sitter counted every matching tree-sitter node with no consolidation, so a Haskell function written as multiple pattern-match clauses (idiomatic style) counted as multiple distinct occurrences of one name -- e.g. toJSON written as 5 clauses in one Options.hs instance block read as 5 separate functions, where GitGalaxy and ctags each correctly report 1.
  • This is the same bug tree_sitter_accuracy_audit.py's measure() already fixed once (tree_sitter_accuracy_audit: haskell ground truth counts each pattern-match clause as a separate real function, deflating measured func_start recall from ~94% to 50.5% #1614-1616); this newer module wrote its own simpler walk instead of reusing that closure and silently reintroduced it. Ported the same fix: consecutive func-type sibling nodes sharing a name (interleaved comment nodes don't break the run) collapse into the first occurrence only.
  • Regenerated docs/self_scan/tri_comparison_ledger.json and docs/self_scan/tri_comparison_chart.svg across all 45 languages (tree-sitter-language-pack + a locally-built universal-ctags) so the committed artifacts reflect the fix.

Verification

  • Haskell's raw tree-sitter function count: 275 → 146 (GitGalaxy's own count is 148, now nearly matching instead of off by 129).
  • The ledger's haskell/function/existence/agree[tree_sitter]_vs[ctags,gitgalaxy] shape (91 occurrences) no longer reproduces; 3 haskell shapes total went stale, all clause-splitting artifacts, none deleted (kept per the ledger's own "never delete, mark still_reproduces: false" lifecycle).
  • Confirmed no other language's ledger entries changed as a side effect of this run.
  • ruff_audit.py --ci and mypy_audit.py --ci: no new findings beyond baseline.

Test plan

  • Re-ran tri_comparison_chart.py --languages haskell --write before/after the fix, confirmed the toJSON example collapses from 5 clause-nodes to 1 per real instance via direct source inspection (Options.hs lines 171-174 and 190-192, two separate instance ToJSON blocks).
  • Full tri_comparison_chart.py --all --write run across all 45 languages, diffed the ledger to confirm only haskell (and one unrelated pre-existing perl entry) changed.
  • ruff_audit.py --ci / mypy_audit.py --ci clean against baseline.

🤖 Generated with Claude Code

_walk_tree_sitter listed every matching tree-sitter node with no
consolidation, so a Haskell function written as multiple pattern-match
clauses (idiomatic style -- toJSON instance methods, guard-clause
helpers, etc.) counted as multiple distinct occurrences of one name.
Confirmed via the ledger's own toJSON example: 5 clause-nodes at
consecutive lines in one Options.hs instance block, where GitGalaxy and
ctags each correctly report 1.

This is the same bug tree_sitter_accuracy_audit.py's measure() already
fixed once (#1614-1616) -- this module wrote its own simpler walk
instead of reusing that closure and silently reintroduced it. Ported
the same fix: consecutive func-type sibling nodes sharing a name
(interleaved `comment` nodes don't break the run) collapse into the
first occurrence only.

Verified: haskell's raw tree-sitter function count drops from 275 to
146 (GitGalaxy's own count is 148), and the ledger's
tree_sitter-only-vs-[ctags,gitgalaxy] shape (91 occurrences) no longer
reproduces. Regenerated the full ledger and chart across all 45
languages with tree-sitter-language-pack + a locally-built
universal-ctags -- no other language's entries were affected.

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

squid-protocol and others added 3 commits August 19, 2026 11:02
Resolved without needing a fresh investigation -- two from source already
read earlier in this same effort, one from a doc comment already sitting
in ctags_reader.py:

- agree[gitgalaxy]_vs[ctags,tree_sitter] (2): mixed verdict, read
  individually. getExtensions is a real instance method both other tools
  structurally can't see; extensionEnabled is a genuine GitGalaxy false
  positive (misreads a guard-clause call as a definition).
- args agree[none]_vs[gitgalaxy,tree_sitter] (9): one systematic cause,
  point-free/eta-reduced equations -- GitGalaxy counts true signature
  arity, tree-sitter counts only the aligned clause's explicit patterns.
  Same shape as Claim 1, not an engine defect.
- class agree[gitgalaxy,tree_sitter]_vs[ctags] (16): not a real
  discrepancy at all -- ctags_reader.py already documents
  CTAGS_CLASS_KINDS["haskell"] = set() on purpose, no class-shaped ctags
  kind exists for this language.

The remaining 2 unvalidated haskell shapes (ctags-alone existence,
ctags-misses-real existence) are still open -- under investigation.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
agree[ctags]_vs[gitgalaxy,tree_sitter] (103 occurrences): dispatched
agent investigation, all 10 sampled cases are ctags-side artifacts, no
GitGalaxy/tree-sitter defect. Three causes: multi-clause double-tagging
(ctags tags every pattern-match equation as a separate occurrence, GG/TS
correctly anchor to the first clause only), keyword-as-identifier
misparsing (class/where/pattern), and a value-vs-function kind collapse
ctags' Haskell parser can't express (GitGalaxy and tree-sitter's own
audit tooling both independently make the same correct distinction, per
#1312/#1566). Full evidence in the ledger verdict.

5 of 8 haskell shapes now validated. 1 remaining under investigation.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
agree[gitgalaxy,tree_sitter]_vs[ctags] (69 occurrences): dispatched agent
investigation confirms all 10 sampled misses -- and by cross-check
against further non-sampled instances, plausibly all 69 -- are
locally-scoped definitions (instance methods, where-clause helpers,
let-bound names in do blocks), never top-level. ctags' Haskell parser
has no layout-rule/scope awareness and only tags column-1 equations; it
correctly handles multi-clause definitions when they're top-level
(expandFilterPath/writeFnBinary/writerFn all tag fine), so this is a
pure scope gap distinct from the clause-splitting bug fixed earlier.
GitGalaxy and tree-sitter both correct; nothing to fix in this repo.

Added a doc addendum to ctags_reader.py alongside its existing Haskell
notes so this is documented at the source, not just in the ledger.

All 8 haskell ledger shapes are now resolved: 5 validated (real
findings, all confirming GitGalaxy/tree-sitter correctness against
ctags-side limitations, plus one genuine GitGalaxy false-positive and
one documented point-free-arity distinction), 3 stale/no-longer-
reproducing (artifacts of the clause-splitting bug fixed earlier in
this PR, kept as history per the ledger's own lifecycle). Regenerated
chart.svg reflects the cleared asterisks.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@squid-protocol
squid-protocol merged commit 2066869 into main Aug 19, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the tri-comparison-clause-fix branch August 19, 2026 17:50
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.

1 participant