Repository navigation
fix(haskell): detect equation-form func_start without a :: signature -- closes #1442 - #1499
Merged
Merged
Conversation
#1442) Two extremely common real-world Haskell patterns were structurally invisible to func_start because it required an explicit `::` type signature to anchor on at all: typeclass instance method equations (the signature lives on the class declaration, never restated per-instance) and `where`-clause local helpers (routinely left unsigned in real code). Adds a second func_start alternative that anchors directly on the pattern-matched equation shape (`name pattern... = expr`, indented under an enclosing where/instance block) instead of a signature, with a reserved-word exclusion and an unambiguous-`=` lookaround (rejecting ==/=>/<=/>=// =) to keep it from false-positiving on value bindings, `<-`-bound do-statements, or case alternatives. A function's 2nd+ pattern-matched clause independently satisfies the new alternative too (e.g. all 6 equations of a `toJSON` instance method); _slice_by_indentation now dedups those against the block the first clause already absorbed via the pre-existing same-name-same-indent continuation walk, instead of emitting one node per clause. The `#1312` point-free arrow check is scoped to only the `::`-signature alternative, since it doesn't apply to equation-only matches (which never have an arrow to check). Live-measured on the language-crucible haskell corpus (pandoc, 94 real functions): func recall 53/94 (56.4%) -> 81/94 (86.2%), extra_functions 28 -> 29 (a single new false positive, root-caused to a multi-line boolean guard whose continuation line happens to start with a real function call that itself looks like an equation -- an inherent, documented tradeoff of line-based detection, not a bug in this fix). Both golden masters re-blessed for the resulting corpus-wide drift (mostly PageRank/spatial-coordinate ripple from more haskell functions now being counted network-wide, plus one pre-existing risk-scoring heuristic gap this recall jump exposes -- filed separately as #1498, out of scope here per the issue's own scope note). Verified: tests/extraction/languages/test_haskell{,_strict}.py (new cases for both confirmed patterns + dedup + rejection cases), full extraction + core_engine suites, tree_sitter_accuracy_audit.py --all --ci (31 languages, zero cross-language regressions), crucible_check.py --mode both (clean after re-blessing), audit_check.py --ci (ruff/mypy/dead-key/ast-accuracy clean), and a standalone ReDoS timing check on the new alternative. Co-Authored-By: Claude Sonnet 5 <[email protected]>
squid-protocol
force-pushed
the
fix/haskell-1442-equation-funcs
branch
from
August 13, 2026 22:08
2c98adb to
1976c3e
Compare
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1442. Follow-up to #1435/#1443 (merged) -- that PR's own honest
correction predicted this: after fixing the
< 2line-count floor,haskell func_start recall only moved 52/94 -> 53/94, because the much
larger cause was structural, not the floor.
func_start's regex requiredan explicit
::type signature to match a function at all, but twoextremely common real-world Haskell patterns never have one:
class declaration and is never restated per-instance (e.g.
toJSON PlainMath = String "plain", one of 6 equations pandoc'sToJSON HTMLMathMethodinstance uses with no::anywhere).where-clause local helpers -- Haskell allows, and real coderoutinely omits, a signature on these (e.g. pandoc's
applyFilter/withMessages, local helpers ofapplyFilters).Both are defined purely by a pattern-matched equation (
name pattern... = expr), not a signature -- a materially different shape,exactly as #1442 itself predicted would need "its own design pass".
Fix
Added a second
func_startalternative (gitgalaxy/standards/language_standards.py,"haskell"entry) that anchors on the equation shape directly instead of a::signature:
[ \t]+, excludes column 0 -- unsigned top-level equations are aseparate, still-open problem, not one of the two confirmed patterns here).
uppercase, which cleanly rejects constructor-headed patterns like
Just v = ....where/do/case/etc. can't be mistaken for the name.=(bounded to the current line, so a
<--bound do-statement or a case alternative --neither of which has a bare
=on that line -- fails closed).(?<![!<>/])/(?![=>])guards keep
==,=>,<=,>=,/=from being mistaken for the defining=.Requiring a real pattern token (not just whitespace) before it excludes a bare
name = exprvalue binding, mirroring haskell func_start matches point-free VALUE bindings (no arrow in type) as if they were functions #1312's point-free reasoning for thesignature-anchored alternative.
A function's 2nd+ pattern-matched clause independently satisfies this same
alternative too (all 6
toJSONequations, not just the first). Rather thanemit one node per clause,
_slice_by_indentation(gitgalaxy/core/detector.py)now tracks the most recently accepted haskell block's
(name, indent, end)andskips any later match that's just a clause the first one's existing same-name-
same-indent continuation walk already absorbed. Also scoped #1312's point-free
arrow check to only the
::-signature alternative (match.group(3) is None) --it doesn't apply to equation-only matches, which never have an arrow to check;
applying it there would have rejected nearly every real equation-form match.
Results
Live-measured against the language-crucible haskell corpus (pandoc, 94 real
functions, same corpus #1442/#1435 used):
+28 real functions recovered for a single net-new false positive. Root-caused
that one: a multi-line boolean guard (
| extensionEnabled ... \|\| \n extensionEnabled ... = walk unEmoji) whose continuation line happens to startwith a real function call (
extensionEnabled) that's textually indistinguishablefrom an equation without full guard-aware parsing. This is an inherent, documented
tradeoff of line-based detection -- not a bug in this fix -- and matches the
issue's own acknowledged risk ("a much larger surface of naturally-similar-looking
syntax").
tree_sitter_accuracy_baseline_haskell.jsonupdated to reflect this(measured
--regeneratewas correctly refused given the 1-countextra_functionsregression; wrote it by hand after independently confirming the tradeoff via
before/after diffing, see test plan).
Golden masters
Both
tests/golden_master_audit.jsonandtests/golden_master_zero_dep_audit.jsonre-blessed via
update_golden_master.py. Verified the entire 281-line diff isattributable to this change (ran
crucible_check.pyagainst the pre-change treefirst -- clean pass, confirming zero pre-existing flakiness). Two categories:
(cobol/xml/lua/typescript/solidity/etc.) -- expected:
spatial_mapper.py'sPageRank/embedding runs network-wide across the whole multi-repo corpus, so
any file's function-count change perturbs the shared coordinate space for
every other file too. Same category of expected drift fix(haskell): allow single-line func_start blocks past the '< 2 lines' floor #1443 hit.
One of the haskell-file mismatches is worth calling out explicitly rather than
just re-blessing silently:
Shared.hs'sDuplicate Logicsignal jumped 4 -> 13and
Tech Debt Exposure~6% -> ~25%. Root cause:detector.py's duplicate-logicheuristic flags same-named functions anywhere in a file as "duplicate", with no
lexical-scope awareness -- and Haskell idiomatically reuses generic helper names
(
go, etc.) across many different, unrelatedwherescopes in the same file.This fix makes those local helpers visible for the first time, which exposes a
real but pre-existing, scope-blind heuristic gap -- unrelated to func_start
accuracy and explicitly out of scope per #1442's own scope note ("not GitGalaxy's
risk-scoring rules"). Filed separately as #1498 rather than folded in here.
Test plan
tests/extraction/languages/test_haskell.py-- new func_start valid/invalid/pathological cases for both confirmed patterns, plus integration-level tests
exercising
_function_sliceend-to-end: instance-method-equations-collapse-to-one-node, where-clause-locals-get-their-own-distinct-node, and zero-arg
where-bound value bindings staying rejected. 68 passed (was 65).
tests/extraction/languages/test_haskell_strict.py+test_language_standards_strict.py-- 118 passed, unaffected.
tests/extraction/+tests/core_engine/-- 6625 passed, 2 skipped,11 xfailed, 3 xpassed (all pre-existing, not new).
tree_sitter_accuracy_audit.py --all --ci-- 31 languages, zero cross-languageregressions from this haskell-only change.
crucible_check.py --mode both-- both golden masters re-blessed, re-verifiedclean (
✅ full_precision: PASS,✅ zero_dependency: PASS) after.audit_check.py --ci --regenerate-- ruff/mypy/dead-key/ast-accuracy all clean(2 pure line-shift ruff findings from the new doc-comment pushing existing
lines down, regenerated).
ruff format --check-- clean (also cleaned up pre-existing formatting debtin
test_haskell.pywhile touching it -- confirmed viagit stashthat thispredates this PR).
inputs (50k-char no-equals line, 20k repeated
==, 20k near-miss lines) --all sub-30ms, no catastrophic backtracking.
Root-caused directly by Claude Code (two prior Gemini/agy attempts on this issue
hadn't landed); implemented, verified, and blessed end-to-end in this session.
🤖 Generated with Claude Code