---
title: "규칙 3.2: 텍스트 구조와 이름, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 3.2(텍스트 구조와 이름)입니다. A local variable, parameter, module constant or module variable may use any identifier TypeScript permits."
url: https://typeshade.dev/ko/reference/rules/3-2/
language: ko
---

# 규칙 3.2

3장, 텍스트 구조와 이름 테스트

A local variable, parameter, module constant or module variable may use any identifier TypeScript permits. Function parameters and body locals occupy a lexical scope inside the module’s: they may shadow a module value, and a closure resolves the nearest declaration. Duplicate declarations in the same scope remain errors. The backend must give a name its target cannot spell a fresh identifier, rewriting its declarations and references consistently. The authored IR, CPU oracle, diagnostics and debugger retain the source name. Every other declaration follows the same rule (Proposal 0070): a binding, an override, a struct, a field, a helper function or an entry point whose name a target cannot spell takes a fresh emitted spelling on that target, recorded beside the authored name, and the host calls each by the name written. A class or namespace member is flattened to `Owner_member` first. A module function whose name its target predeclares is emitted under a fresh name, `fract_` and then `fract_1`, with every call through it ([Rule 9.5](https://typeshade.dev/ko/reference/rules/9-5/)). A module constant, a module variable, a binding, an override or a struct whose name WGSL predeclares takes a fresh WGSL spelling, since WGSL lets a module-scope declaration hide the predeclared name in the whole module (Proposal 0070, Q1b). An entry point whose name its target predeclares takes a fresh emitted spelling too (D7). A local or a helper parameter named like a builtin its function calls takes a fresh spelling, since it would hide the builtin (D-C10-1). A host-owned binding and the fields of its struct keep their names, and one its target cannot spell is refused with a clear error.

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

## 근거

the shading language’s identifier restrictions govern emitted text; changing a spelling does not change the source program. Binding, override, entry, struct and field names also participate in host or interface contracts, so the record names each emitted spelling beside the authored name, and the host binds and calls by the authored name (Proposal 0070). A module function that is not an entry has no such contract: the host never names it, and the CPU calls it by the name the file gave it.

## 출처

WGSL’s identifier and reserved-word restrictions, the GLSL ES 3.00 identifier rules, and the source-name contract for the IR and debugger.

## 검증 방식

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

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

- `sanitizeVariableNames` in `src/core/passes/variable-names.ts`, for locals and helper parameters, with collision avoidance against authored and generated names; and `spellModule` in `src/core/passes/spell-names.ts`, which applies the spelling plan to module-scope names and entry parameters (Proposal 0070);
- `src/compiler/ts/declared-builtin-names.test.ts` for an entry point named like something WGSL predeclares, which takes a fresh emitted spelling (Proposal 0070, D7), and for a local or helper parameter named like a builtin its function calls (D-C10-1);
- `renamePredeclaredFunctions` in `src/core/passes/rename-predeclared.ts` for a module function whose name its target predeclares, pinned by `src/core/passes/rename-predeclared.test.ts`;
- `src/compiler/ts/reserved-names.test.ts`, including `target`, dollar and Unicode variables, nested scopes, constants, module variables, CPU values and the editor;
- `src/compiler/ts/function-shadowing.test.ts` for function parameters and locals shadowing module values, nearest closure bindings and unchanged same-scope duplicate refusals;
- `linkProgram` in `src/compiler/ts/link.ts` for names shared by a program’s files ([Rule 3.9](https://typeshade.dev/ko/reference/rules/3-9/)), pinned by `src/compiler/ts/link.test.ts`.

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

- [`examples/emit-goldens.test.ts:20`](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/emit-goldens.test.ts#L20)
- [`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/function-shadowing.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/function-shadowing.test.ts#L1)
- [`src/compiler/ts/link.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/link.test.ts#L2)
- [`src/compiler/ts/link.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/link.ts#L1)
- [`src/compiler/ts/reserved-names.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/reserved-names.test.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:4`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/rename-predeclared.test.ts#L4)
- [`src/core/passes/rename-predeclared.ts:40`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/rename-predeclared.ts#L40)
- [`src/core/passes/spell-names.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/spell-names.ts#L2)
- [`src/core/passes/variable-names.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/variable-names.ts#L2)
- [`src/core/spelling-plan.ts:14`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/spelling-plan.ts#L14)

## 설명하는 절

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

- [§21 Block scope](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#21-block-scope)
- [§68 Importing another shader module](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#68-importing-another-shader-module)

## 함께 보기

- [규칙 3.1](https://typeshade.dev/ko/reference/rules/3-1/) 테스트
- [규칙 3.3](https://typeshade.dev/ko/reference/rules/3-3/) 테스트
- [규칙 3.9](https://typeshade.dev/ko/reference/rules/3-9/)
- [규칙 9.5](https://typeshade.dev/ko/reference/rules/9-5/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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