Rule 12.6
On this page

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:

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.
TS8003 TYPE_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 | null or T | 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, an f32 past its range or a builtin call outside its domain, such as Math.pow(-2., 2.).
TS8029 STRUCT_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).
TS8031 RECURSION
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.
TS8036 MATH_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 (sin on 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.
TS8038 F64_ENTRY_IO
An emulated double (f64 or a vec64) on an entry's IO boundary: a @location parameter, a @location field of an IO struct or an entry's return. A double is a pair of f32 words after lowering, and a varying interpolates each word on its own. Narrow with f32(x), or read the double in the stage that needs it, since a uniform or a storage binding carries an f64.
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