Rule 9.5
Chapter 9, Built-in functions and the TypeShade extensions Test
A function the file declares or imports (Rule 3.9) must win over a builtin of the same name, as a module-scope declaration hides a predeclared object in WGSL.
The builtins that predate the rule (those not in USER_FIRST_BUILTINS: clamp, pow, f32, and the rest of the original set) keep their precedence over a function of the module, which is a recorded divergence from WGSL in the direction of Rule 4.2.
A name a function’s body declares, a local function (Rule 8.17) or a parameter that takes a function (Rule 8.18), must win over every builtin, as TypeScript’s lookup finds it before any global.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
a program that meant the author’s function before a builtin existed must keep meaning it, and a program that meant the builtin before the rule existed must keep meaning that.
No program calling a name its own body declares meant a builtin: step(i) on a parameter step, and a local const mix = … called as mix(…), reached WGSL’s builtin before, a wrong arity or a silently different value, where TypeScript calls the author’s function.
Derives from
Declaration and Scope (the example “Shadowing predeclared objects”) for the first clause; surface §10 and USER_FIRST_BUILTINS in math-alias.ts for the second, which WGSL does not have; ECMAScript ResolveBinding (the innermost environment first) for the third.
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/compiler/ts/builtins.test.ts; src/compiler/ts/closures.test.ts and src/compiler/ts/higher-order.test.ts for a local function and a parameter.
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:
See also
Source
The rule at commit 26de7be8:
docs/language-design.md:938(the design document)reqs/rules/RULE-0905.md(its traceability item)