규칙 9.5
이 페이지에서

규칙 9.5

9장, 내장 함수와 TypeShade 확장 테스트

A function the file declares or imports (Rule 3.9) must win over every builtin function of its name, whether a WGSL built-in function, the free spelling of a Math member (Rule 9.4) or a TypeShade extension that is a function (§9.3), as a module-scope declaration hides a predeclared function in WGSL and as TypeScript’s lookup finds the file’s own name before a global: a call of the name reaches the declaration in the constant folder, on the CPU, on WebGPU and on WebGL2, and a function handed by its name to a fold, to an array method or to a function that takes one follows the call. A value constructor (a scalar cast, a vector, a matrix or array) must keep its precedence over a declaration of its name, as a type name does over an alias (Rule 4.2); bool and f64 are the exception and stay the declaration’s, and a declaration of a constructor’s name is refused where it is handed by that name, since no callback is a constructor. Each writer must emit a declared function whose name its target predeclares under a name the target does not have, and every call through the declaration with it, so that a builtin call, the author’s and the compiler’s own alike, keeps the builtin: fract_, then fract_1 where that is taken, on both targets. An entry point whose name its target predeclares receives a fresh emitted name, recorded beside the authored name (Rule 3.2); the host calls it by the name written (D7). 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. A name a const binds to a Math member is a declaration of the file and wins over a builtin of its name in its scope, as TypeScript’s lookup finds it; a call the member’s signature refuses is refused in that scope, with a sentence that names the builtin and how to reach it.

규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.

근거

the rule once kept the builtins that predate it in front of a function of the module, so that a program that meant the builtin kept meaning it, and that held in the constant folder and on the CPU only. No program declaring such a name ever meant the builtin on WebGPU, where WGSL calls the declaration, and GLSL ES 3.00 does not let a program redeclare one of its built-in functions at all, so #403’s fract had three answers: the declaration on WebGPU, the builtin on the CPU and none on WebGL2, where ANGLE refuses the module. The editor resolves the call to the declaration as TypeScript does, so keeping the builtin promised in the editor what the compiler did not do (Rule 12.7). The rename is what lets one module hold both. WGSL hides a predeclared name for the whole module beside a module-scope declaration, a type included (a declared f32 hides the type in every x: f32), so without it every fract(…) reached the declaration, and random(p), which expands to a call of fract, called the author’s function. 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.

출처

Declaration and Scope (the example “Shadowing predeclared objects”) for the first clause and for the names WGSL predeclares; section 8 of the GLSL ES 3.00 specification for the names GLSL does, measured on ANGLE through the compile gate; Rule 4.2 for the constructors, and surface §10 for the two casts that stay the declaration’s, bool and f64, which WGSL does not have; ECMAScript ResolveBinding (the innermost environment first) for a name a body declares.

검증 방식

테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.

컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.

  • src/compiler/ts/builtins.test.ts and src/compiler/ts/declared-builtin-names.test.ts, which declare and call every builtin function a file can call and hold the folder, the three CPU walks, both writers and the editor to one answer;
  • renamePredeclaredFunctions in src/core/passes/rename-predeclared.ts, pinned by src/core/passes/rename-predeclared.test.ts, and the two lists it renames by, WGSL_PREDECLARED and GLSL_ES300_BUILTIN_FUNCTIONS in src/core/reserved-words.ts, held to the specification’s names by src/core/spec-conformance/predeclared-names.test.ts;
  • the compile gate (scripts/compile-gate.ts, its declared-names leg), which gives Tint and ANGLE a function declared under every name a writer renames, and runs #403’s program on WebGPU against the CPU oracle;
  • src/compiler/ts/closures.test.ts and src/compiler/ts/higher-order.test.ts for a local function and a parameter.

커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

설명하는 절

커밋 af54ddad5의 언어 문서에서 이 규칙을 설명하는 절입니다.

함께 보기

소스

커밋 af54ddad5의 규칙 원문:

이 페이지 편집 문제 보고