Rule 12.6
Chapter 12, Diagnostics Test
A requirement the front end can check must be checked at the front end, in the author’s words, and not left to Tint or a driver.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
WGSL checks each requirement at the earliest opportunity, and for TypeShade the earliest opportunity is the source line.
Derives from
Errors (“each requirement will be checked at the earliest opportunity”); surface §3 and §7.
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:
TS8029, TS8031, TS8036, TS8038, TS8068, and the rest of the front-end codes, among them TS8002 for a type the file declares nowhere, which used to be emitted as a struct of that name for Tint to refuse (src/compiler/ts/unknown-names.test.ts); the requirements proposal 0008 moved forward from Tint: a for update the lowering does not count, refused instead of dropped with its loop (Rule 7.5), an operator WGSL has no overload for on its operands’ kind (Rule 7.1), a vector of bools in a uniform or storage binding (Rule 6.8), a decorator nothing reads, @group and @binding on a declaration among them (Rule 6.7), a barrier, a derivative or a workgroupUniformLoad after a non-uniform break or continue (Rule 8.5), and a while condition that is not a bool (Rule 7.5), each pinned where that rule’s Enforced-by names it, and a loop’s hidden counter, which an author’s _w or _i reached (Rule 2.2), pinned by src/compiler/ts/loop-shapes.test.ts; two constant expressions Tint refused, now folded as a divisor is and refused with TS8003: a clamp whose bounds cross (src/compiler/ts/clamp-bounds.test.ts, #373) and an f32 value past the range (src/compiler/ts/f32-const-range.test.ts, #374); the debts of Appendix B are the requirements not yet moved forward.
The files that verify it at commit af54ddad5, each at the first line that names the rule:
-
src/compiler/ts/array-minmax-types.test.ts:1 -
src/compiler/ts/clamp-bounds.test.ts:1 -
src/compiler/ts/compute-stage-reachability.test.ts:1 -
src/compiler/ts/const-call-domain.test.ts:1 -
src/compiler/ts/f32-const-range.test.ts:1 -
src/compiler/ts/honest-refusals-tuples.test.ts:1 -
src/compiler/ts/honest-refusals.test.ts:1 -
src/compiler/ts/index-bound.test.ts:1 -
src/compiler/ts/io-attribute-arguments.test.ts:1 -
src/compiler/ts/loop-shapes.test.ts:1 -
src/compiler/ts/lower/runtime-array.ts:1 -
src/compiler/ts/module-vars-atomic.test.ts:1 -
src/compiler/ts/runtime-array-values.test.ts:1 -
src/compiler/ts/struct-cycle.test.ts:1 -
src/compiler/ts/switch-validation.test.ts:1 -
src/compiler/ts/unknown-names.test.ts:2
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:
-
TS8002UNKNOWN_TYPE - A type name that nothing declares, in a parameter, a type argument, an alias, an
implementsclause 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 isSTRUCT_FIELD. -
TS8003TYPE_MISMATCH - Two types that do not fit where they meet (an operator, a condition, a declaration, a return or an argument), a read of an optional value (
T | undefined,T | nullorT | null | undefined) that no test narrowed (Rule 7.10), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross, anf32past its range or a builtin call outside its domain, such asMath.pow(-2., 2.). -
TS8029STRUCT_FIELD_MISSING_ATTR - A user-defined input of a compute entry: a parameter, or a field of its struct, that carries no
builtin<…>. A compute entry has no user-defined input in WGSL, so the front end refuses it. On a vertex or fragment entry a value with no attribute is user-defined, and the compiler gives it its location (Rule 6.6). -
TS8031RECURSION - A call cycle: a function that reaches itself, directly or through other functions. WGSL has no call stack, so the compiler refuses the cycle before a target sees it.
-
TS8036MATH_ARGUMENT - A math builtin called with arguments that its signature does not take: two shapes that had to agree (
dot(vec3, vec2)), an element kind that the builtin has no form for (sinon an integer vector), a scalar where a vector is due (normalize(s)), or a factor, exponent, offset or count of the wrong type. The message names the offending argument and, where one is short, the fix: splat the scalar, cast one side, or give the vectors one size. -
TS8038F64_ENTRY_IO - An emulated double (
f64or avec64) on an entry's IO boundary: a@locationparameter, a@locationfield of an IO struct or an entry's return. A double is a pair off32words after lowering, and a varying interpolates each word on its own. Narrow withf32(x), or read the double in the stage that needs it, since a uniform or a storage binding carries anf64. -
TS8068RESERVED_NAME evalorargumentsbound 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:
docs/language-design.md:1758(the design document)reqs/rules/RULE-1206.md(its traceability item)