Rule 3.2
On this page

Rule 3.2

Chapter 3, Textual structure and names Test

A local variable, parameter, module constant or module variable may use any identifier TypeScript permits. Function parameters and body locals occupy a lexical scope inside the module’s: they may shadow a module value, and a closure resolves the nearest declaration. Duplicate declarations in the same scope remain errors. The backend must give a name its target cannot spell a fresh identifier, rewriting its declarations and references consistently. The authored IR, CPU oracle, diagnostics and debugger retain the source name. Every other declaration follows the same rule (Proposal 0070): a binding, an override, a struct, a field, a helper function or an entry point whose name a target cannot spell takes a fresh emitted spelling on that target, recorded beside the authored name, and the host calls each by the name written. A class or namespace member is flattened to Owner_member first. A module function whose name its target predeclares is emitted under a fresh name, fract_ and then fract_1, with every call through it (Rule 9.5). A module constant, a module variable, a binding, an override or a struct whose name WGSL predeclares takes a fresh WGSL spelling, since WGSL lets a module-scope declaration hide the predeclared name in the whole module (Proposal 0070, Q1b). An entry point whose name its target predeclares takes a fresh emitted spelling too (D7). A local or a helper parameter named like a builtin its function calls takes a fresh spelling, since it would hide the builtin (D-C10-1). A host-owned binding and the fields of its struct keep their names, and one its target cannot spell is refused with a clear error.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

Rationale

the shading language’s identifier restrictions govern emitted text; changing a spelling does not change the source program. Binding, override, entry, struct and field names also participate in host or interface contracts, so the record names each emitted spelling beside the authored name, and the host binds and calls by the authored name (Proposal 0070). A module function that is not an entry has no such contract: the host never names it, and the CPU calls it by the name the file gave it.

Derives from

WGSL’s identifier and reserved-word restrictions, the GLSL ES 3.00 identifier rules, and the source-name contract for the IR and debugger.

How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

  • sanitizeVariableNames in src/core/passes/variable-names.ts, for locals and helper parameters, with collision avoidance against authored and generated names; and spellModule in src/core/passes/spell-names.ts, which applies the spelling plan to module-scope names and entry parameters (Proposal 0070);
  • src/compiler/ts/declared-builtin-names.test.ts for an entry point named like something WGSL predeclares, which takes a fresh emitted spelling (Proposal 0070, D7), and for a local or helper parameter named like a builtin its function calls (D-C10-1);
  • renamePredeclaredFunctions in src/core/passes/rename-predeclared.ts for a module function whose name its target predeclares, pinned by src/core/passes/rename-predeclared.test.ts;
  • src/compiler/ts/reserved-names.test.ts, including target, dollar and Unicode variables, nested scopes, constants, module variables, CPU values and the editor;
  • src/compiler/ts/function-shadowing.test.ts for function parameters and locals shadowing module values, nearest closure bindings and unchanged same-scope duplicate refusals;
  • linkProgram in src/compiler/ts/link.ts for names shared by a program’s files (Rule 3.9), pinned by src/compiler/ts/link.test.ts.

The files that verify it at commit af54ddad5, each at the first line that names the rule:

Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

See also

Source

The rule at commit af54ddad5:

Edit this page Report a problem