---
title: "규칙 6.6: 선언과 리소스, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 6.6(선언과 리소스)입니다. An entry point's inputs and outputs are explicit parameters and return values."
url: https://typeshade.dev/ko/reference/rules/6-6/
language: ko
---

# 규칙 6.6

6장, 선언과 리소스 테스트

An entry point’s inputs and outputs are explicit parameters and return values. A built-in value carries `builtin<N>`, whose type WGSL gives (`builtin<"clip_distances", array<f32, N>>` writes its type); every other input or output is user-defined, and the compiler gives it its location, which `location<n, T>` may state. The builtin name must be one WGSL defines for that stage and direction (change 0111, D2; change 0135). Each attribute type means its value type: `pos: builtin<"position">` is a `vec4` to the compiler and to the editor, the type WGSL gives `position`, and `uv: location<0, vec2>` is a `vec2`. A written type that WGSL fixes, `builtin<"vertex_index", u32>`, is the migration form: it must compile with a [`TS8028`](https://typeshade.dev/ko/reference/errors/ts8028/) warning that names `builtin<"vertex_index">` and `tshc migrate` in the release that ships change 0135, and the release after it refuses the written type (decision D1.2); a written type that is not WGSL’s is [`TS8003`](https://typeshade.dev/ko/reference/errors/ts8003/). `builtin<"clip_distances">`, the one name whose type the author chooses, is `TS8003`. The other attributes of an input or an output are an object type of options. On a built-in value the options are the second argument, `builtin<"position", { invariant: true }>` (D1.3). On a user-defined value they are the third argument of `location<n, T, O>`, so a value that states an option writes its location: `location<1, u32, { interpolate: "flat" }>`, `location<0, vec4, { blend_src: 1 }>` (change 0111, D7; change 0135, D2.3). A written `n` is always the location. Where a user-defined value stands decides what it is and the location the compiler gives it when none is written (change 0135, D2.1):

| Where the value stands | What it is | Its location when none is written |
| --- | --- | --- |
| A vertex entry’s parameter, or a field of one | A vertex attribute | The lowest number no written location of that entry holds, in declaration order (the order [Rule 6.8](https://typeshade.dev/ko/reference/rules/6-8/) packs the buffer in) |
| A field of a struct that a vertex entry returns | A value between stages | The lowest number no written location of that struct holds, in declaration order. The scope is the struct, so a struct has one set of locations wherever it is used |
| A fragment entry’s input (a field of a struct no vertex entry returns, or a bare parameter) | A value between stages | The location the field of the same name has in the vertex results of the program. Refused ([`TS8010`](https://typeshade.dev/ko/reference/errors/ts8010/)) when no vertex result has the name, or two give it different locations |
| A fragment entry’s result, or a field of it | A render target | The lowest number no written location of that entry holds, in declaration order; a bare result is location 0 |
| A compute entry’s parameter, or a field of one | Refused | None: [`TS8029`](https://typeshade.dev/ko/reference/errors/ts8029/), since a compute entry has no user-defined input |

A fragment input that is a field of the struct a vertex entry returns has that struct’s locations. A value between stages is linked by its name, as GLSL ES 3.00 links a varying. In the mixed case each struct keeps its written numbers: with `interface A { pos: builtin<"position">; uv: location<0, vec2>; n: vec3 }` and `interface B { pos: builtin<"position">; n: location<0, vec3> }`, `A.n` is 1, the lowest number no written field of `A` holds, and `B.n` stays 0, as written. If `B` is a fragment input and writes no number on `n`, `B.n` takes the location `n` has in the vertex results; with `A` the only one, that is 1. An entry I/O struct may be a `class`, an `interface` or a `type` ([Rule 6.9](https://typeshade.dev/ko/reference/rules/6-9/)), and a field of one writes its attribute in its type where it writes one (a user-defined input or output may leave its location to the compiler), and needs no initializer and no `!`; a written `!` is accepted and changes nothing, and the language service sets `strictPropertyInitialization: false` in the TypeShade program, since an entry I/O field is filled by the stage that produces it, not by an initializer. No attribute decorator is written on an entry’s parameter or on a field of an entry I/O struct: `@builtin("...")` or `@location(n)` there stays accepted with a `TS8028` warning until the release that refuses it (change 0111, D5), and the language service hides TypeScript’s TS1206 on it only while `compile()` warns. A parameter qualifier on a function of the file is no entry I/O attribute ([Rule 8.25](https://typeshade.dev/ko/reference/rules/8-25/)).

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

## 근거

an implicit stage input hides a dependency, and the input stays an explicit parameter or field. WGSL refuses an entry I/O member with no attribute, and the emitted WGSL keeps an explicit attribute on each one: that requirement binds the emitted module and not the TypeShade source (OD-1, [Rule 1.1](https://typeshade.dev/ko/reference/rules/1-1/)). The compiler knows the type of a built-in value and can count a location, so the author writes neither (OD-3). An input or an output is a value that flows in or out, so its attribute, when it is written, is part of its type ([Rule 1.8](https://typeshade.dev/ko/reference/rules/1-8/), OD-5).

## 출처

- [Shader Interface](https://gpuweb.github.io/gpuweb/wgsl/#shader-interface);
- [Inter-stage Input and Output Interface](https://gpuweb.github.io/gpuweb/wgsl/#stage-inputs-outputs), whose definition of a stage input reads “each datum is either a built-in input value, or a user-defined input”;
- its subsection [Input-output Locations](https://gpuweb.github.io/gpuweb/wgsl/#input-output-locations), which carries the two requirements (“each user-defined input and output must have an explicitly specified IO location”; “each structure member in the entry point IO must be one of either a built-in value, or assigned a location”, each a shader-creation error);
- [`builtin`](https://gpuweb.github.io/gpuweb/wgsl/#builtin-attr) and [`location`](https://gpuweb.github.io/gpuweb/wgsl/#location-attr);
- change `0111` in `changes/` (D2, D7); change `0130`; change `0135` (D1.2, D2.1); change `0137`;
- surface §3.

## 검증 방식

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

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

- `src/compiler/ts/attribute-types.ts`, which reads each attribute type as the decorators it stands for, so every check below reads both forms; pinned by `src/compiler/ts/attribute-types.test.ts` (a `class`, an `interface` and a `type` give the decorated form’s WGSL and GLSL ES 3.00, and the editor reports nothing) and the language-service check that reports no TS1206 and no TS2564 on any example (`src/language-service/new-entry-forms.test.ts`);
- `TS8024 BUILTIN_NAME` and `TS8025 BUILTIN_STAGE` for the builtin name and its stage;
- `src/compiler/ts/type-map.ts`, which reads `builtin<N>` as the type `WGSL_BUILTIN_TYPES` gives `N`, and the ambient `builtin` type, whose default is generated from the same table ([Rule 12.7](https://typeshade.dev/ko/reference/rules/12-7/)); `src/compiler/ts/builtin-type-form.ts` for the [`TS8028`](https://typeshade.dev/ko/reference/errors/ts8028/) warning on a written type that WGSL fixes (`"vertex_index" has the type WGSL gives it, u32: write builtin<"vertex_index">, or run "tshc migrate".`), the [`TS8003`](https://typeshade.dev/ko/reference/errors/ts8003/) of `builtin<"clip_distances">` (`Builtin "clip_distances" has no single type: write builtin<"clip_distances", array<f32, N>> with N from 1 to 8.`) and the one diagnostic of an unknown name that writes no type; pinned in both halves, with the hover, by `src/compiler/ts/builtin-type-form.test.ts`;
- `src/compiler/ts/entry-locations.ts`, which gives each user-defined input and output that writes no location its location by the table above, once every entry is read, in the IR’s field and parameter that a written location fills; a fragment input whose name no vertex result has, or two give different locations, is [`TS8010`](https://typeshade.dev/ko/reference/errors/ts8010/) (`"FsIn.n" has no location and the vertex results give "n" none: write location<n, T> on it.`; `… give "n" 1 in "A" and 0 in "C": …`); a field that two places of its struct would give two numbers is `TS8010` (`"S.a" has no location and its uses give it 1 as an input of "v1" and 0 as an input of "v2": write location<n, T> on it.`); a user-defined value of a type that cannot cross is `TS8003`, in the sentence a `location<n, bool>` has; pinned in both halves by `src/compiler/ts/entry-locations.test.ts`, which also holds the emit of the short forms to the emit of the written ones byte for byte, an inferred result included ([Rule 8.19](https://typeshade.dev/ko/reference/rules/8-19/)), and `reflect()` to the same locations;
- `src/language-service/hover.ts`, which shows that location under the type in the editor’s hover, written or given, read off the same IR with the reader `reflect()` uses (Rule 12.7); pinned beside `reflect()`’s location on the same source by `src/language-service/entry-location-hover.test.ts`;
- `TS8029 STRUCT_FIELD_MISSING_ATTR` for a user-defined input of a compute entry, a bare parameter or a field of its struct, with a `location<…>` or with no attribute (`"x" is a user-defined input of a compute entry, which has no user IO: a compute shader reads its work from resources and the builtin<…> invocation ids.`); measured against Tint with its valid neighbours by the compile gate ([Rules 12.6](https://typeshade.dev/ko/reference/rules/12-6/) and [13.3](https://typeshade.dev/ko/reference/rules/13-3/));
- `src/cli/migrate.ts`, which rewrites a written type that WGSL fixes to the short form, pinned by `src/cli/migrate.test.ts`.

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

- [`src/cli/migrate.test.ts:8`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/cli/migrate.test.ts#L8)
- [`src/cli/migrate.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/cli/migrate.ts#L3)
- [`src/compiler/ts/attribute-types.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/attribute-types.test.ts#L1)
- [`src/compiler/ts/attribute-types.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/attribute-types.ts#L1)
- [`src/compiler/ts/builtin-type-form.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtin-type-form.test.ts#L1)
- [`src/compiler/ts/builtin-type-form.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtin-type-form.ts#L1)
- [`src/compiler/ts/builtin-values.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/builtin-values.test.ts#L1)
- [`src/compiler/ts/decorated-form.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/decorated-form.test.ts#L1)
- [`src/compiler/ts/entry-locations.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/entry-locations.test.ts#L1)
- [`src/compiler/ts/entry-locations.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/entry-locations.ts#L1)
- [`src/compiler/ts/io-attribute-arguments.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/io-attribute-arguments.test.ts#L1)
- [`src/compiler/ts/io-name-cascades.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/io-name-cascades.test.ts#L1)
- [`src/compiler/ts/stage3.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/stage3.test.ts#L1)
- [`src/compiler/ts/type-map.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/type-map.ts#L1)
- [`src/language-service/entry-location-hover-imports-programs.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/entry-location-hover-imports-programs.test.ts#L1)
- [`src/language-service/entry-location-hover-imports-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/entry-location-hover-imports-refusals.test.ts#L1)
- [`src/language-service/entry-location-hover-imports.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/entry-location-hover-imports.test.ts#L1)
- [`src/language-service/entry-location-hover-places.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/entry-location-hover-places.test.ts#L1)
- [`src/language-service/entry-location-hover.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/entry-location-hover.test.ts#L1)
- [`src/language-service/hover.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/hover.ts#L1)
- [`src/language-service/new-entry-forms.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/new-entry-forms.test.ts#L1)

## 설명하는 절

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

- [§3 Entries — stage attributes and explicit builtins](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#3-entries--stage-attributes-and-explicit-builtins)
- [§7 Diagnostics (required)](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#7-diagnostics-required)
- [§53 Entry IO: the interpolation an integer varying has no choice about](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#53-entry-io-the-interpolation-an-integer-varying-has-no-choice-about)

## 적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

**[`TS8003`](https://typeshade.dev/ko/reference/errors/ts8003/) `TYPE_MISMATCH`**

연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(`T | undefined`, `T | null`, `T | null | undefined`)을 읽거나([규칙 7.10](https://typeshade.dev/ko/reference/rules/7-10/)), 컴파일러가 접는 상수를 WGSL이 거부합니다. 31을 넘는 시프트 양, 0인 제수, 서로 엇갈린 clamp 경계, 범위를 넘는 `f32` 값, `Math.pow(-2., 2.)`처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다.

**[`TS8010`](https://typeshade.dev/ko/reference/errors/ts8010/) `STRUCT_FIELD`**

구조체 필드나 선언의 모양이 잘못되었습니다. 필드가 없는 클래스는 받아들입니다. 이 코드는 잘못된 필드 선언, 클래스가 아닌 빈 구조체, 적용되지 않는 필드의 `@align`, 사용처마다 location이 둘로 갈리는 사용자 정의 값을 다룹니다(규칙 6.6).

**[`TS8024`](https://typeshade.dev/ko/reference/errors/ts8024/) `BUILTIN_NAME`**

`@builtin("...")`의 이름 인자가 잘못되었거나, WGSL 내장 어휘에 없는 id입니다.

**[`TS8025`](https://typeshade.dev/ko/reference/errors/ts8025/) `BUILTIN_STAGE`**

`@builtin(...)` id를 다른 스테이지의 입력이나 출력으로 씁니다. 예를 들어 정점 반환에 `frag_depth`를, 정점 매개변수에 `front_facing`을 씁니다.

**[`TS8028`](https://typeshade.dev/ko/reference/errors/ts8028/) `ATTRIBUTE_NAME`**

이 표면이 읽지 않는 데코레이터나 진입점 형태입니다. 속성 어휘(`@vertex`, `@fragment`, `@compute`, `@builtin`, `@location`) 밖의 식별자(`@vertx` 같은 오타), 표면이 다른 방식으로 쓰거나 빌려 오지 않는 WGSL 속성(직접 쓴 `@diagnostic(…)` 같은 것), `vertex(f)`처럼 호출로 쓴 스테이지, `export default`처럼 [규칙 8.1](https://typeshade.dev/ko/reference/rules/8-1/)이 거부하는 형태로 쓴 진입점, 데코레이터를 받지 않는 선언이나 자리에 붙은 데코레이터가 그렇습니다([규칙 6.7](https://typeshade.dev/ko/reference/rules/6-7/)). 이 코드가 없으면 데코레이터를 붙인 함수나 필드가 아무 말 없이 진입점이나 IO 필드가 아니게 됩니다.

**[`TS8029`](https://typeshade.dev/ko/reference/errors/ts8029/) `STRUCT_FIELD_MISSING_ATTR`**

compute 진입점의 사용자 정의 입력입니다. `builtin<…>`가 없는 매개변수나 그 구조체의 필드가 그렇습니다. WGSL의 compute 진입점에는 사용자 정의 입력이 없으므로 프런트엔드가 거부합니다. 정점이나 프래그먼트 진입점에서는 속성이 없는 값이 사용자 정의 값이고, 컴파일러가 location을 줍니다(규칙 6.6).

## 함께 보기

- [규칙 6.5](https://typeshade.dev/ko/reference/rules/6-5/) 테스트
- [규칙 6.7](https://typeshade.dev/ko/reference/rules/6-7/) 테스트
- [규칙 1.1](https://typeshade.dev/ko/reference/rules/1-1/)
- [규칙 1.8](https://typeshade.dev/ko/reference/rules/1-8/)
- [규칙 6.8](https://typeshade.dev/ko/reference/rules/6-8/)
- [규칙 6.9](https://typeshade.dev/ko/reference/rules/6-9/)
- [규칙 8.19](https://typeshade.dev/ko/reference/rules/8-19/)
- [규칙 8.25](https://typeshade.dev/ko/reference/rules/8-25/)
- [규칙 12.6](https://typeshade.dev/ko/reference/rules/12-6/)
- [규칙 12.7](https://typeshade.dev/ko/reference/rules/12-7/)
- [규칙 13.3](https://typeshade.dev/ko/reference/rules/13-3/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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