Skip to content

fix(haskell): detect equation-form func_start without a :: signature -- closes #1442 - #1499

Merged
squid-protocol merged 1 commit into
mainfrom
fix/haskell-1442-equation-funcs
Aug 13, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
fix/haskell-1442-equation-funcs

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Closes #1442. Follow-up to #1435/#1443 (merged) -- that PR's own honest
correction predicted this: after fixing the < 2 line-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 required
an explicit :: type signature to match a function at all, but two
extremely common real-world Haskell patterns never have one:

  1. Typeclass instance method equations -- the signature lives on the
    class declaration and is never restated per-instance (e.g. toJSON PlainMath = String "plain", one of 6 equations pandoc's ToJSON HTMLMathMethod instance uses with no :: anywhere).
  2. where-clause local helpers -- Haskell allows, and real code
    routinely omits, a signature on these (e.g. pandoc's applyFilter/
    withMessages, local helpers of applyFilters).

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_start alternative (gitgalaxy/standards/language_standards.py,
"haskell" entry) that anchors on the equation shape directly instead of a ::
signature:

  • Indented only ([ \t]+, excludes column 0 -- unsigned top-level equations are a
    separate, still-open problem, not one of the two confirmed patterns here).
  • Lowercase-led identifier -- real Haskell function/variable names can never start
    uppercase, which cleanly rejects constructor-headed patterns like Just v = ....
  • A reserved-word exclusion so where/do/case/etc. can't be mistaken for the name.
  • A lookahead requiring at least one real pattern token before an unambiguous =
    (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 = expr value 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 the
    signature-anchored alternative.

A function's 2nd+ pattern-matched clause independently satisfies this same
alternative too (all 6 toJSON equations, not just the first). Rather than
emit one node per clause, _slice_by_indentation (gitgalaxy/core/detector.py)
now tracks the most recently accepted haskell block's (name, indent, end) and
skips 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):

found_functions (of 94) extra_functions args_exact_match
Before 53 (56.4%) 28 5
After 81 (86.2%) 29 31

+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 start
with a real function call (extensionEnabled) that's textually indistinguishable
from 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.json updated to reflect this
(measured --regenerate was correctly refused given the 1-count extra_functions
regression; wrote it by hand after independently confirming the tradeoff via
before/after diffing, see test plan).

Golden masters

Both tests/golden_master_audit.json and tests/golden_master_zero_dep_audit.json
re-blessed via update_golden_master.py. Verified the entire 281-line diff is
attributable to this change (ran crucible_check.py against the pre-change tree
first -- clean pass, confirming zero pre-existing flakiness). Two categories:

  1. Haskell files' own function/risk numbers changing, as intended.
  2. Small topological-coordinate ripple across other languages' files
    (cobol/xml/lua/typescript/solidity/etc.) -- expected: spatial_mapper.py's
    PageRank/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's Duplicate Logic signal jumped 4 -> 13
and Tech Debt Exposure ~6% -> ~25%. Root cause: detector.py's duplicate-logic
heuristic 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, unrelated where scopes 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_slice end-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.
  • Full 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-language
    regressions from this haskell-only change.
  • crucible_check.py --mode both -- both golden masters re-blessed, re-verified
    clean (✅ 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 debt
    in test_haskell.py while touching it -- confirmed via git stash that this
    predates this PR).
  • Standalone ReDoS timing check on the new alternative against adversarial
    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

#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
squid-protocol force-pushed the fix/haskell-1442-equation-funcs branch from 2c98adb to 1976c3e Compare August 13, 2026 22:08
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit 68a24d6 into main Aug 13, 2026
30 checks passed
@squid-protocol
squid-protocol deleted the fix/haskell-1442-equation-funcs branch August 13, 2026 22:13
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.

haskell func_start: typeclass instance methods and where-clause locals without an explicit '::' signature are structurally invisible

1 participant