Rule 2.2
Chapter 2, Sources of the surface Test
A compiler-internal name (§2.1) must not be authorable. It must not be declared in the ambient library, as a name, as a signature or an overload of an allowed name, or as a member of an allowed type. It must not be given a row of §9.3, under its own id or under any other spelling of the same thing.
The rule text and the parts under it are the compiler's own English, as the design document writes them.
Rationale
an internal helper is a contract between two passes, and an author who can write it can also write it wrong, with no specification to say what wrong means.
Derives from
the same section of PR #166, written on the f64FromParts case (§2.4).
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:
surface-names.test.ts(no pre-emit intrinsic id is declared or listed), which asserts that every id ofPRE_EMIT_INTRINSICSother than the type namef64is neither declared inSHADE_DTSnor a row ofTYPESHADE_EXTENSIONS;- the same test (
reports an internal helper by name when one reaches the surface), for the sentence a stray declaration gets; - the same test (
the front end resolves no pre-emit id as a builtin), for the call route, sinceresolveMathFninsrc/compiler/ts/math-alias.tsresolves an alias only whenisKnownIntrinsicaccepts its id, exemptingf32,atan2, andmod, none of which is pre-emit, sof64Parts(x)in a shader isTS8004 Unknown function; - the same test’s first case, which catches a generated backend name that is declared, as a stray;
- the same test (
the f64 family declares only the constructor forms WGSL gives the type it stands in for), for the overload route, which pins every declared signature off64to one argument and every signature ofvec2f64,vec3f64, andvec4f64to WGSL’s vector constructor forms (a splat, N components, or a narrowerf64vector plus components); - that same case, which reports
f64(hi: f32, lo: f32)appended to the library; - the same test (
the compiler refuses a second argument to f64), for the call route of the same overload,TS8019 f64() expects 1 argument.; - the call route of the IR builder’s
.swizzle(), which no call reaches by its name since proposal 0008:v.swizzle("yxz")isTS8022, a member the vector does not have, which names the member it is written as,v.yxz, pinned bysrc/compiler/ts/swizzle-random.test.ts; - review under §2.1’s definition (Rule 9.8), since a name that denotes an internal representation under an id outside
PRE_EMIT_INTRINSICSpasses every case of the test once it has a row.
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:
Error codes that enforce it
The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:
-
TS8004UNKNOWN_FN - A call to a function the file neither declares nor imports.
-
TS8019ARITY_MISMATCH - Wrong number of arguments, elements, or fields at a call or constructor site.
-
TS8022UNKNOWN_NAME - Reference to a name TypeShade cannot resolve (identifier, struct field, or struct shape) that is not a function call (
UNKNOWN_FN) or a type name (UNKNOWN_TYPE), in a body a call lowers or in one no call lowers; a name the library declares for TypeScript's own use (Object,Math,Symbol), or the file declares as an enum, a namespace, a class or a type, read as a value says what it is.
See also
Source
The rule at commit 26de7be8:
docs/language-design.md:101(the design document)reqs/rules/RULE-0202.md(its traceability item)