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. Other declarations retain their existing emitted-name contract: a name containing $, exactly _, or starting with __ is refused for WGSL; a class or namespace member is flattened to Owner_member.

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 local spelling does not change the source program. Binding, override, entry, struct and field names also participate in host or interface contracts and keep their existing checks.

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, used on an emitted copy by both backends, with collision avoidance against authored and generated names;
  • reportReservedNames in src/compiler/ts/reserved-names.ts for declarations whose emitted spelling remains part of the contract;
  • 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 26de7be8, each at the first line that names the rule:

Explained in

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

Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

TS8068 RESERVED_NAME
A declared name that a target reserves, checked on the name the emit actually carries: half as a struct field, which ANGLE answers with "Illegal use of reserved word" in generated text the author never wrote.

See also

Source

The rule at commit 26de7be8:

Edit this page Report a problem