Rule 2.1
On this page

Rule 2.1

Chapter 2, Sources of the surface Test

Every author-facing name must come from exactly one of three sources:

  • (a) WGSL, as the specification spells it: a built-in function, a predeclared type or type-generator including the predeclared vecNf/vecNi/vecNu aliases, an attribute reached as a decorator, a built-in value passed as a string, or an extension name;
  • (b) ECMAScript, as TypeScript’s standard library declares it: a literal, an operator, a statement, the declaration forms, and a type, a function, an object or a member of the standard library, with the members the compiler represents. Declared today: a member of Math, a method of console, a method Array.prototype has, written on an array (surface §63), the declaration forms class, interface, enum, and namespace, the standard-library declarations the ambient file restates for a lib: [] program (Map and Set among them, with the members a kernel function’s parameter has, change 0080), and the shapes surface §14 and §28 admit;
  • (c) the TypeShade extensions enumerated in §9.3 of this document, one row per name with its reason.

An attribute name with which a stage or a dispatch is written (vertex, fragment, compute, workgroup_size) is an author-facing name reached as a decorator (2.1(a)); @compute([…]) folds WGSL’s @compute and @workgroup_size into one TypeShade spelling.

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

Rationale

a name with a source has a meaning an author can look up; a name with no source has only the compiler’s word for what it does.

Derives from

PR #166’s body, section “A design rule this lane settled” (“No TypeShade-internal helper becomes an author-facing spelling”), and Declaration and Scope; changes/0100-typescript-meaning.md (section 2) for source (b).

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:

src/core/spec-conformance/surface-names.test.ts, which classifies every declared name against fixtures/wgsl-names.json, the running engine’s Math and console, and TYPESHADE_EXTENSIONS, and holds each method the library declares on an array to the running engine’s Array.prototype; and the front end, which resolves a name by what declares it and never by its spelling (proposal 0008): a name nothing declares is TS8022 for a value and TS8004 for a callee, in a body a call lowers and in one no call lowers alike, and TS8002 for a type wherever it is written, the base a class or an interface extends and an argument of a WGSL generic that is a type argument of a class included, except inside the extents of @compute([…]) or @workgroup_size([…]), where a name nothing declares is TS8037, in the compiler and in the editor alike (Rule 8.7), once, in the compiler and in the editor alike (TypeScript’s TS2304, TS2583, TS2584, TS2591 and TS2580 merge into it, and TS2585 for a Map or a Set read as a value, change 0080), a name the file declares is the file’s whatever it spells, ahead of a type the library declares of the name, and a declaration of the file wins over a §9.3 constant of its name, and an enum, a namespace, a class or a type the file declares, read as a value, says what it is and the value it offers, once (TS8022, TypeScript’s report about its typeof merged into it), pinned by src/compiler/ts/host-names.test.ts and src/language-service/diagnostics.test.ts; the two spellings ECMAScript’s strict mode lets no declaration bind, eval and arguments, are refused once where a variable, a parameter or a function binds one, TS8068, as TypeScript’s TS1215 refuses them (TS1215, TS1210 and TS1100 merge into it, and so does what TypeScript says of a later write of the name), while a class, an enum, a namespace or a type of the name is the file’s, as TypeScript takes it, pinned by src/compiler/ts/host-names.test.ts; a new finds its class the same way, with what another block of a namespace exports, and a type annotation inside a namespace finds the class the new there builds, pinned by src/compiler/ts/new-expression.test.ts; the ambient library’s own types and values are names the compiler knows are declared, a type of its own says it is one where a type, a value or a callee is read (TypeScript’s TS2693 merges into it), and a shader type is none of them, pinned by src/language-service/ambient-parity.test.ts and src/compiler/ts/host-names.test.ts; and a member is looked up on its receiver, so a class field reverse or a method swizzle is the class’s, pinned by src/compiler/ts/class-methods.test.ts; a function a namespace of the file declares under the name ref is an ordinary function of the file, since the library no longer declares one (Rule 8.25), pinned by src/compiler/ts/reference-parameters.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:

Error codes that enforce it

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

TS8002 UNKNOWN_TYPE
A type name that nothing declares, in a parameter, a type argument, an alias, an implements clause or a base class, or a type that this surface does not take where the mapper reads one (Rule 2.1). A base that the file declares and does not collect as a struct is STRUCT_FIELD.
TS8004 UNKNOWN_FN
A call to a function the file neither declares nor imports, or to a builtin the language removed because ECMAScript spells it, such as arrayLength(xs), whose message names xs.length (Rule 9.9).
TS8011
Retired codes.
TS8012
Retired codes.
TS8022 UNKNOWN_NAME
A reference to a name that TypeShade cannot resolve and that is not a function call (UNKNOWN_FN) or a type name (UNKNOWN_TYPE). A name that the library declares for TypeScript's own use (Object, Math, Symbol), or that the file declares as an enum, a namespace, a class or a type, and that is read as a value, says what it is.
TS8037 WORKGROUP_ARG
@compute(...) with an argument that is not an array literal of one to three whole numbers: an object, a bare number, an identifier, or an empty or four-wide array. The check of the default limits is WORKGROUP_SHAPE.
TS8068 RESERVED_NAME
eval or arguments bound by a variable, a parameter or a function, which ECMAScript's strict mode, and TypeScript with it, lets no declaration do (Rule 2.1).

See also

Source

The rule at commit af54ddad5:

Edit this page Report a problem