Repository navigation
Description
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. Ledgercsharp-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. Ledgershell-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 assignmentNAME=. The crucible reads 174 hits on 256 files, and the bare forms aretrap … 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/externcountstatic void _bind_methods();andextern 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 plantEXTERNAL HELPERwas authored to it. - cobol 185 / 570 —
COMMONmatches insideCOMMON-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 platformis 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 astatic mutitem; and the honest formsstatic X: T = …/const X: T = …at column 0 count nowhere. - swift 33 / 6 — bare
defaultin\b(shared|standard|default|…)\balso matches aswitchcase'sdefault:; the crucible's hits are the.defaultsingleton accessor. The corpus plant is the bare identifierlet region = shared. - lua 407 / 113 —
argmatcheslocal arg = {...}(a local shadowing the global). - kotlin — bare
objectalso 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 locallet global = <Global>element;self.isconst self = thisas often as a worker global (the ambiguity anchor, test's C3). - agc_assembly 150 / 10 —
BIT14/BIT10are 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 theglobal xstatement, 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 Tat column 0 without an initializer (var mu sync.Mutex) and top-levelconstcount nowhere;var (/const (groups are indented and invisible (a scope question, deferred).
What the contract must state
- 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.
- Scope, not mutability (C1): a program-scope constant counts (java
public static final X =, kotlinconst val, dartstatic const, zigconst, ruststatic/constitems); constness isimmutability_locks' axis (immutability_locks has no contract: rust'sletis invisible while swift'sletscores 11 — and it is subtracted from the corpus's worst gated metric #2772). A function-local binding never counts, whatever its keyword. - 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). - The ambiguity anchor (C3): an everyday word fires only in its global form.
- Linkage and region headers are not state (C4): a storage-class keyword on a procedure, fortran
EXTERNAL,extern "C", a.datasection switch. - One owner (C5): process control through the ambient class is high_risk's;
locals()is nobody's global. Deliberate duals kept: kotlinobject(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), fortranCOMMON(safety_bypasses), jclSET(state_mutation, state_mutation has no stated contract: three incompatible definitions across 46 languages, and it governs the corpus's two worst metrics #2765), dockerfileENV. - 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.
Activity
test(python): locals() is nobody's global, the global statement is (#…
feat(standards): globals counts program-lifetime bindings and ambient…
c api: a file-scope variable is globals' hit, not public surface (#2907…
fix(rules): widen globals residue forms + swift branch .default — closes