Skip to content

globals has no stated contract: 2 open cells are one-owner/ambiguity misfires, and the crucible shows the rule counting local declarations, function prototypes and hyphenated identifiers #2858

Description

@squid-protocol

Roadmap Phase 3 (docs/contract_roadmap.md, epic #2812), next by the mechanical audit after the func_start/class_start pair (#2856): the globals row is draft and carries 2 of the report's 27 open-defect cells (csharp 3 vs median 2, shell 3 vs 2; 5% of its 44 comparable cells).

_c("globals", "architecture", "declaration", "Accessing global state, environment variables, or system registries", planted=True)

Consumers: encapsulation_ratio (signal_processor.py — 1 - globals / (core_var_decl + globals)), the secrets-risk careless amplifier, the statistical_auditor extraction-density group.

The two open cells (verdicts against corpus main)

  • csharp main.cs = 1 — Environment.Exit(payload) (the planted high_risk call) matches the globals rule's bare \bEnvironment\. prefix. Ledger csharp-environment-exit-is-global-and-danger (keyword-overlap). Process control through the ambient class is not an access to the environment: the two members that end the process are high_risk's (one owner, the io C2 shape).
  • shell a.sh = 3 — trap : TERM (the planted safety handler) matches the globals rule's bare word list \b(PATH|HOME|…|TERM|…)\b. Ledger shell-trap-signal-env-collision. A bare well-known name is a signal name, a prose word or a log string; the environment-variable form is $NAME / ${NAME / an assignment NAME=. The crucible reads 174 hits on 256 files, and the bare forms are trap … INT TERM, # HOME verification, "etcd must be in your PATH".

What rule_probe.py globals all measured on the crucible with no red cell

  • c 2771 hits / 32 files — the rule is ^[ \t]*(?:static|extern)?<type> <name> = at any indentation: PyThreadState *tstate = _PyThreadState_GET(); is a function-local declaration. A local is never a global.
  • cpp 485, objective-c 16 — bare static / extern count static void _bind_methods(); and extern char *WWW_nameOfFile(…): a storage-class keyword on a procedure declares linkage, not state.
  • fortran — EXTERNAL (9 of 16 hits, LOGICAL, EXTERNAL :: wrf_dm_on_monitor) declares an external procedure; the corpus plant EXTERNAL HELPER was authored to it.
  • cobol 185 / 570 — COMMON matches inside COMMON-RETURN, CA-POLICY-COMMON, COMMON-8-BIN (the fix(standards): guard debt patterns against hyphenated identifiers (closes #2537) #2622 hyphen shape; test's C3).
  • livecode 385 / 98 — it (the handler-local result variable) is 60+ of the sample; the platform is the genuine ambient read.
  • perl 2694 / 21 — \$\$ matches the deref $$options{$param} / $$self{OPTIONS} (the pid variable is $$ followed by nothing); \$_ matches $_[2], the argument array.
  • rust 2 / 46 — both hits are the lifetime &'static mut A, not a static mut item; and the honest forms static X: T = … / const X: T = … at column 0 count nowhere.
  • swift 33 / 6 — bare default in \b(shared|standard|default|…)\b also matches a switch case's default:; the crucible's hits are the .default singleton accessor. The corpus plant is the bare identifier let region = shared.
  • lua 407 / 113 — arg matches local arg = {...} (a local shadowing the global).
  • kotlin — bare object also matches an anonymous object expression (val x = object : Runnable); a global is the named object declaration.
  • typescript 113 / 27 — every global. hit is assemblyscript's local let global = <Global>element; self. is const self = this as often as a worker global (the ambiguity anchor, test's C3).
  • agc_assembly 150 / 10 — BIT14/BIT10 are references to fixed constants (CAF BIT14), not shared erasable.
  • assembly 70 / 234 — the rule counts the section switch .data/.bss (a region header, the shape cobol globals counts WORKING-STORAGE SECTION: a region header stacked on top of the item-level GLOBAL/EXTERNAL clauses, unconditional on every COBOL program #2805 dropped from cobol's WORKING-STORAGE), not the labeled storage it contains (buf: resd 4, msg: .asciz, .comm sym,4 — 307 on the same files).
  • python — counts locals() (a reflective handle on the local namespace) and does not count the global x statement, the language's own declaration form; its embedded twin counts both.
  • haskell — the unsafePerformIO-IORef idiom counts; the ambient reads (getEnv, lookupEnv, getArgs) count nowhere.
  • go — var x T at column 0 without an initializer (var mu sync.Mutex) and top-level const count nowhere; var ( / const ( groups are indented and invisible (a scope question, deferred).

What the contract must state

  1. One hit is a declaration of a binding at program scope — file, module, class-static or process-wide — or a read or write of the process's ambient environment through its named handle, in a form an ordinary identifier cannot match.
  2. Scope, not mutability (C1): a program-scope constant counts (java public static final X =, kotlin const val, dart static const, zig const, rust static/const items); constness is immutability_locks' axis (immutability_locks has no contract: rust's let is invisible while swift's let scores 11 — and it is subtracted from the corpus's worst gated metric #2772). A function-local binding never counts, whatever its keyword.
  3. Declaration or ambient handle, not a reference (C2): an ordinary read of a global by name is invisible; a reference to a named constant (CAF BIT14) is a reference. The ambient handles are the language's named process-state objects (os.environ, process.env, $PATH, System.getenv, sy-subrc, msg.sender, %ENV, sqlite_master).
  4. The ambiguity anchor (C3): an everyday word fires only in its global form.
  5. Linkage and region headers are not state (C4): a storage-class keyword on a procedure, fortran EXTERNAL, extern "C", a .data section switch.
  6. One owner (C5): process control through the ambient class is high_risk's; locals() is nobody's global. Deliberate duals kept: kotlin object (class_start, func_start & class_start have no stated contract: 5 open cells are all collective-entry cross-product mis-marks, not rule defects #2856), fortran COMMON (safety_bypasses), jcl SET (state_mutation, state_mutation has no stated contract: three incompatible definitions across 46 languages, and it governs the corpus's two worst metrics #2765), dockerfile ENV.
  7. Stated absence (C6): html, markdown (ledgered n/a).

Done in the #2765/#2841/#2852/#2856 shape

docs/globals_rule_contract.md, the sheet row → stated, one cross-language test_globals_contract_<N>.py, engine PR labelled rosetta:rebless-owed, corpus PR with the re-plants (swift's bare identifiers, fortran's EXTERNAL, assembly's section headers) and both cells' ledger entries resolved. Expected: globals open defects 2 → 0, every corpus language reading 2.

Metadata

Metadata

Assignees

No one assigned

    Labels

    core-enginemetrics

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions