Skip to content

args counts an arrow-less :: signature in haskell: a top-level value (region :: IORef Int) is not a callable #2785

Closed as not planned

Description

@squid-protocol

Found by the 46-language audit in docs/args_rule_contract.md, written for #2773. Much narrower
than the other findings in that pass -- 2 hits on the control shell, not a systemic call-site leak.

The contract

args matches the parameters a callable declares.

Measured

keyword-rosetta/data/haskell, args against func_start:

file func_start args the extra hits
a.hs 3 5 region :: IORef Int, home :: IORef Int
b/c/main 10 10 exact
total 15 15 -- (func_start counts the same two, so the ratio hides it)

The planted figure is 13 (one parameter per probe, SPEC.md); haskell reads 15.

region :: IORef Int          -- a top-level VALUE. Zero parameters.
region = unsafePerformIO (newIORef 0)

region is a globals probe -- a top-level mutable IORef, planted for the globals signal. It is
not a callable at all, and the :: arm of args scores it anyway.

The cause

"args": re.compile(
    r"::(?:[ \t\n]|--[^\n]*\n|\{-…-\})*((?:[a-zA-Z0-9_\'.,()\[\]]|=>|->|⊸)…)"   # arm 1
    r"|\\(…)->"
    r"|@[A-Z][a-zA-Z0-9_\']*"
    r"|^[ \t]*…([a-zA-Z_][a-zA-Z0-9_']*)[ \t]+(…LHS pattern list…)[ \t]*(?:=(?!=)…)"
),
"_args_arrow_count_groups": {1},

Arm 1 matches any :: type signature. _args_arrow_count_groups then counts top-level ->
occurrences in the captured type to get the arity -- which is correct, and for IORef Int correctly
yields zero parameters. But the match itself still lands in struct_args, which is a count of
matches, not of parameters. So a module of pure top-level constants records a parameter surface it
does not have.

Note this is the narrow, contract-level version of the same thing func_start does here: a ::
signature for a value is also counted as a function start. Whether that is a second defect or the
deliberate "a CAF is a nullary function" reading is worth settling in the same pass -- the two
should agree.

Suggested shape

Require arm 1's captured type to contain a top-level -> (or ⊸) before it counts. A signature
with no arrow declares no parameters, so the match earns nothing downstream anyway, and dropping it
makes struct_args agree with the arity _args_arrow_count_groups already computes.

language-crucible/data/haskell: 169 args against 250 func_start (a/f 0.68); the change is
small there and worth measuring before/after.

Corpus pairing

keyword-rosetta/data/haskell needs no authoring change -- the fix should land it on 13 exactly.

Part of #2669 (rosetta[haskell] tracking issue).

Activity

  1. added
    bug
    metrics
    core-engine
    on Sep 6, 2026
  2. squid-protocol commented on Sep 6, 2026

    @squid-protocol
    OwnerAuthor

    Closing as already settled, and settled correctly — I filed this without checking keyword-rosetta's deviation_ledger.json, which is exactly the audit trail that exists to stop a question being re-litigated.

    The behaviour is covered by haskell-caf-bindings-count-as-functions (disposition engine-semantic, validated 2026-09-04):

    Top-level value bindings (CAFs like region = unsafePerformIO ...) count func_start/args like any function binding — morphologically correct for haskell, where top-level values ARE nullary functions. a.hs records 5 (3 probes + 2 planted globals). Type-signature + binding pairs count once, not twice (verified).

    That reading is better than mine. In Haskell a top-level value genuinely is a nullary function — region :: IORef Int binds a CAF, not a variable in the C sense — and the engine is consistent about it: func_start and args both count it, and _args_arrow_count_groups correctly derives arity 0 from the arrow-less type. My proposal (require a top-level -> before the :: arm counts) would have made args and func_start disagree with each other on the same binding, which is worse than the thing I was trying to fix.

    The one observation worth keeping is cross-language and not a haskell bug: struct_args counts matches, so a zero-parameter callable contributes 1 in haskell but 0 in objective-c (- (void)dealloc matches nothing). That inconsistency is real but it is a property of the file-level metric's definition, not of this rule — noting it here rather than reopening under it.

    docs/args_rule_contract.md lists haskell as a contract violation on the strength of this issue; I'll correct that entry in a follow-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginemetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions