Rule 9.2
Chapter 9, Built-in functions and the TypeShade extensions Test
A builtin’s signature must be WGSL’s, checked at the call.
The two recorded exceptions are atan(y, x) (WGSL’s atan2) and the ECMAScript arity of the Math members.
A name of the f64 family, which has no WGSL signature, must take the signatures WGSL gives the type it stands in for (f64(x) as f32(x), vecNf64 as WGSL’s vector constructors), and a further signature of one is a new name under Rule 2.2.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
an argument shape Tint refuses should be refused at the source line, with the splat or the cast to write; and a signature is a spelling, so an overload that no WGSL form has is a spelling from nowhere (§2.1).
Derives from
Numeric Built-in Functions; Value Constructor Built-in Functions for the scalar and vector constructor forms; surface §10 (#57), §39.
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:
TS8036 MATH_ARGUMENT and src/compiler/ts/lower/math-args.ts, whose rule for a name with SUPPORTED core.def rows is derived from those rows (0017); TS8019 for f64(a, b) (f64() expects 1 argument.) and surface-names.test.ts (the f64 family declares only the constructor forms WGSL gives the type it stands in for, the compiler refuses a second argument to f64).
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:
-
TS8019ARITY_MISMATCH - A wrong number of arguments, elements or fields at a call or a constructor.
-
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.
See also
Source
The rule at commit af54ddad5:
docs/language-design.md:1228(the design document)reqs/rules/RULE-0902.md(its traceability item)