---
title: "규칙 9.5: 내장 함수와 TypeShade 확장, TypeShade 셰이더 언어 설계 규칙과 그 근거"
description: "TypeShade 언어 설계 규칙 9.5(내장 함수와 TypeShade 확장)입니다. A function the file declares or imports (Rule 3.9) must win over every builtin function of its name…"
url: https://typeshade.dev/ko/reference/rules/9-5/
language: ko
---

# 규칙 9.5

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

A function the file declares or imports ([Rule 3.9](https://typeshade.dev/ko/reference/rules/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](https://typeshade.dev/ko/reference/rules/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](https://typeshade.dev/ko/reference/rules/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](https://typeshade.dev/ko/reference/rules/3-2/)); the host calls it by the name written (D7). A name a function’s body declares, a local function ([Rule 8.17](https://typeshade.dev/ko/reference/rules/8-17/)) or a parameter that takes a function ([Rule 8.18](https://typeshade.dev/ko/reference/rules/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](https://github.com/typeshade/typeshade/issues/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](https://typeshade.dev/ko/reference/rules/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](https://gpuweb.github.io/gpuweb/wgsl/#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](https://typeshade.dev/ko/reference/rules/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](https://tc39.es/ecma262/#sec-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](https://github.com/typeshade/typeshade/issues/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에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.

- [`scripts/compile-gate.ts:55`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/compile-gate.ts#L55)
- [`src/compiler/ts/builtins.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtins.test.ts#L1)
- [`src/compiler/ts/closures.test.ts:638`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/closures.test.ts#L638)
- [`src/compiler/ts/declared-builtin-names.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/declared-builtin-names.test.ts#L1)
- [`src/compiler/ts/higher-order.test.ts:1015`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/higher-order.test.ts#L1015)
- [`src/compiler/ts/link.test.ts:5`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/link.test.ts#L5)
- [`src/compiler/ts/lower/constructors.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/constructors.ts#L1)
- [`src/compiler/ts/math-binding.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-binding.test.ts#L1)
- [`src/compiler/ts/math-binding.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-binding.ts#L1)
- [`src/core/backends/glsl-spelling.test.ts:6`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/glsl-spelling.test.ts#L6)
- [`src/core/backends/wgsl-spelling.test.ts:5`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/wgsl-spelling.test.ts#L5)
- [`src/core/passes/predeclared-names.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/predeclared-names.ts#L3)
- [`src/core/passes/rename-predeclared.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/rename-predeclared.test.ts#L2)
- [`src/core/passes/rename-predeclared.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/rename-predeclared.ts#L3)
- [`src/core/passes/spell-names.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/spell-names.ts#L2)
- [`src/core/reserved-words.ts:94`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/reserved-words.ts#L94)
- [`src/core/spec-conformance/predeclared-names.test.ts:11`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/spec-conformance/predeclared-names.test.ts#L11)

## 설명하는 절

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

- [§10 Builtins, casts and `discard`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#10-builtins-casts-and-discard)
- [§77 The subgroup built-in functions: `subgroupAdd` and the twenty beside it](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#77-the-subgroup-built-in-functions-subgroupadd-and-the-twenty-beside-it)

## 함께 보기

- [규칙 9.4](https://typeshade.dev/ko/reference/rules/9-4/) 테스트
- [규칙 9.6](https://typeshade.dev/ko/reference/rules/9-6/) 테스트
- [규칙 3.2](https://typeshade.dev/ko/reference/rules/3-2/)
- [규칙 3.9](https://typeshade.dev/ko/reference/rules/3-9/)
- [규칙 4.2](https://typeshade.dev/ko/reference/rules/4-2/)
- [규칙 8.17](https://typeshade.dev/ko/reference/rules/8-17/)
- [규칙 8.18](https://typeshade.dev/ko/reference/rules/8-18/)
- [규칙 12.7](https://typeshade.dev/ko/reference/rules/12-7/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

- [`docs/language-design.md:1249`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L1249) (설계 문서)
- [`reqs/rules/RULE-0905.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0905.md) (추적 항목)
