Skip to content

globals rule audit: 11 more languages share zig/dart's ^[ \t]* any-indentation anchor (#2651 follow-up) #2660

Closed

Description

@squid-protocol

Follow-up from #2651 (zig+dart fixed there). During that fix I audited every language's globals rule for the same ^[ \t]* (any-indentation) anchor shape that let function-local var/const declarations count as globals. 11 more languages share the pattern:

assembly, cpp, css, dockerfile, go, haskell, kotlin, livecode, lua, perl, scheme

Not all of these are necessarily bugs — some may have offsetting context (a keyword requiring package/file scope elsewhere in the alternation) or may simply have no realistic function-local collision in their morphology (css has no function scope at all, for instance). Each needs the same per-language check #2651 did: does an indented same-named construct exist in real code, and does it false-positive as a global?

Fix shape per language (where confirmed real): same anchor change as #2651, ^[ \t]* → ^(?![ \t]), with tests proving indented declarations don't count and top-level ones still do.

Found via keyword-rosetta classification / #2651's audit step.

Activity

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

    @squid-protocol
    OwnerAuthor

    Batch B.2 of #2669 — the per-language check this issue asks for, run on all 11.

    Result: 1 of the 11 is a real bug with the #2651 fix shape. Applying the anchor change to the other 10 would break four languages and silently do nothing in four more.

    Method, per language: (a) confirm the ^[ \t]* anchor is actually present in the rule; (b) hand-built scratch scan with a top-level construct that must keep counting and an indented same-named one; (c) run the current rule and the ^(?![ \t]) variant over the real-world language-crucible corpus and read what the change would actually delete. (c) is what decided most of these — the scratch scan alone would have got four of them wrong.

    globals is at the planted 2 for all 11 in the rosetta corpus, so no rosetta cell can validate any of this; the crucible numbers below are the only evidence available, and they double as a preview of the golden-master diff.

    Verdict table

    language crucible globals now → anchored verdict
    go 43 → 36 (−16.3%) ✅ REAL — ship the #2651 anchor change
    kotlin 5 → 5 ⚠️ real FP, wrong fix shape
    scheme 124 → 25 (−79.8%) ⚠️ real FP, wrong fix shape
    assembly 73 → 47 (−35.6%) ❌ not real — fix harmful
    css 30 → 25 (−16.7%) ❌ not real — fix harmful
    lua 417 → 373 (−10.6%) ❌ not real — fix harmful
    perl 3149 → 3149 (±0) ❌ not real — indented our is a global; 0 incidence
    cpp 489 → 489 (±0) ❌ not real — anchor is inert
    dockerfile 10 → 10 (±0) ❌ not real — 0 incidence in 71 real Dockerfiles
    haskell 0 → 0 (±0) ❌ not real — rule never fires on real Haskell
    livecode — ❌ not in the family at all (see below)

    ✅ go — real, ship it

    ^[ \t]*var\s+[a-zA-Z_]\w*\s*(?:[a-zA-Z_]\w*\s*)?=. gofmt indents function bodies with tabs, so every function-local var x = … counts as a global. All 7 deletions on the crucible corpus were checked by hand and every one is function-local:

    go/kubernetes/kubelet.go:91      	var certificateRenewFailure = compbasemetrics.NewCounter(   <- inside a func, after an if/err block
    go/kubernetes/csi_plugin.go:325  	var migratedPlugins = map[string](func() bool){             <- inside a func
    go/core/syscall_linux.go:693     	var len _Socklen = SizeofSockaddrAny                        <- inside func Accept4
    go/kubernetes/scheduler.go:610   		var found = false
    go/core/proc.go:5415             	var status uint32 = _Grunnable
    

    100% false-positive removal, no true positive lost. The grouped-var regression you would expect does not exist, because the inner lines of a var ( … ) block carry no var keyword and never matched this rule in the first place:

    var (            -> now: ['var single =', 'var local =']
    	registry = …    fixed: ['var single =']
    	limit    = 10
    )
    

    ⚠️ kotlin and scheme — real false positive, but ^(?![ \t]) is the wrong fix

    Both have a genuine FP and a genuine indented true positive, and the column-0 anchor cannot tell them apart — it deletes both.

    kotlin. One scratch file, three matches, and the fix keeps the wrong one:

    class Foo {
        companion object {
            const val LIMIT = 5     <- THE idiomatic Kotlin global constant. Fix DELETES it.
        }
        fun f() {
            val TIMEOUT = 3000      <- genuine FP. Fix correctly deletes it.
        }
    }

    now=3 ['companion object', 'const val LIMIT =', 'val TIMEOUT ='] → fixed=1 ['companion object']. Net effect on real code: trades a rare FP (uppercase function-local val) for losing the single most common way Kotlin declares a global. A workable shape is to require const for the indented form and keep ^(?![ \t]) only for the bare val — needs its own issue and its own tests.

    scheme. Indentation does not track scope in Scheme; the wrapping form does. Internal defines are a real FP:

    (define (f x)
      (define y 5)   <- local binding, currently counts as a global
      y)

    But the dominant real-world idiom wraps a whole file in (let () …) or (library …), which indents every module-level define. In the crucible corpus:

    file col-0 (define indented (define
    cpnanopass.ss (Chez, whole file inside (let () …) at line 16) 0 682
    io.ss 0 285
    syntax.ss 318 341
    schemify.rkt 9 119

    Anchoring to column 0 takes two entire real files from 285 and 682 candidate globals to zero. −79.8% corpus-wide is not FP removal, it is the rule going blind on the commonest Scheme file layout.

    ❌ Fix actively harmful — indentation is not scope

    • assembly (−35.6%). Deletes 10 .data, 7 .rodata, 5 .bss, 2 SECTION .data, 2 SECTION .bss. GAS/NASM convention indents directives and only labels sit at column 0, so every one of those is a real global data section. This rule matches section directives, not variable declarations — it never had the zig + dart: globals rule anchors ^[ \t]* so function-local var/const count as globals (+150% on the rosetta corpus) #2651 defect.
    • css (−16.7%). Deletes :root, body and * nested inside @media blocks. Those are real global selectors. As this issue itself guessed, css has no function scope — but the conclusion is stronger than "no collision": the anchor is load-bearing against nesting and must stay.
    • lua (−10.6%). Deletes X =, A =, PANDOC_STATE = and friends. In Lua any unqualified assignment without local is a global at any indentation — an indented COUNTER = 0 inside a function is exactly the bug the rule exists to find. The fix would make the rule miss real globals.
    • perl (±0). Indented our $x inside a sub still declares a package variable, i.e. a global — true positive. Incidence in the crucible is 0 anyway (grep -cE '^[ \t]+our[ \t]+[$@%]' = 0 across 29 files).

    ❌ Not real — anchor inert or no incidence

    • cpp (±0 over 489 matches in 47 files). The rule's first alternative \b(extern|static(?!\s*assert)|thread_local|inline\s+constexpr)\b is unanchored and catches the same lines, so the anchored second alternative can never change a count. Provably inert. (Separately: cpp does count a function-local static int n = 0; as a global — but via alternative 1, so globals rule audit: 11 more languages share zig/dart's ^[ \t]* any-indentation anchor (#2651 follow-up) #2660's fix cannot touch it, and static storage duration is arguably a defensible read. Not this issue.)
    • dockerfile (±0). grep -cE '^[ \t]+ENV[ \t]' = 0 across 71 real Dockerfiles — nobody indents ENV. And where it does occur it is a real global env var, since Dockerfile has no scoping. No FP to fix.
    • haskell (0 → 0). The rule requires an IORef|TVar|MVar type signature within 200 chars of unsafePerformIO; it fires zero times across 12 real Haskell files. A where-bound instance is constructible (scratch scan confirms it matches and the anchor would suppress it) but the idiom is essentially always top-level with {-# NOINLINE #-}. The anchor change is provably safe here — Haskell's layout rule puts top-level bindings at column 0 — but it has no measurable effect. Not worth the diff.

    ❌ livecode — not in the family

    Its globals rule is \b(global\s+|the\s+global|the\s+environment|the\s+platform|it)\b|\$ENV\b, compiled re.I|re.U — no ^[ \t]* anchor and not even re.M. It cannot have this defect. The audit list should read 10 languages, not 11.

    Recommendation

  3. squid-protocol commented on Sep 2, 2026

    @squid-protocol
    OwnerAuthor

    Follow-up to the B.2 report above: the two "real FP, wrong fix shape" languages are now filed separately, so this issue can be narrowed to go alone.

    assembly / css / lua / perl / cpp / dockerfile / haskell remain audited, fix rejected on evidence, and livecode is not in the family (no anchor). That leaves go as this issue's whole remaining scope.

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

    core-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions