---
title: "규칙 6.2: 선언과 리소스, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 6.2(선언과 리소스)입니다. A storage binding's access mode is inferred from what the program does…"
url: https://typeshade.dev/ko/reference/rules/6-2/
language: ko
---

# 규칙 6.2

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

A storage binding’s access mode is inferred from what the program does: a binding that some entry writes, by assignment, a mutating method, an atomic builtin, or a write through a function or a reference parameter, is `var<storage, read_write>`, and every other storage binding is `var<storage, read>`. A write inside a function that no entry reaches does not make the binding `read_write` and draws no [`TS8005`](https://typeshade.dev/ko/reference/errors/ts8005/), and a function that no entry reaches and that writes such a binding is not emitted (change 0114, Amendment A17). A write to a binding that `readonly` or `"read"` promises is refused wherever it stands, because the editor reads that promise from the type. `readonly` in the value type (`storage<readonly T[]>`) is the author’s promise that nothing writes the binding, and a write to it is refused. The compiler still accepts an explicit second type argument: `"read_write"` keeps `var<storage, read_write>` and `"read"` keeps `var<storage, read>`, and the only two words it takes are `"read"` and `"read_write"`, spelled as string literal types. Change 0114, decision D3, removes the `"read_write"` argument in S4; D3 does not name `"read"`. A `uniform` binding is read-only and has no access mode, so `uniform<T>` takes one type argument. A write to a read-only resource must be refused, by the compiler and by the editor. A binding that the module writes and a vertex entry reads is refused, and so is a binding declared `"read_write"` that a vertex entry reads, written or not, and a storage binding that a vertex entry writes, directly or through a function it calls, because WebGPU allows no writable storage buffer in the vertex stage.

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

## 근거

the compiler reads the access mode from the program, as it reads the address space of a module variable from a top-level `let` (OD-3), and `readonly` is TypeScript’s own word for “not written”; the host’s bind group layout follows the inferred mode, so an edit that adds or removes a write changes the layout; the declaration keyword cannot carry the mode, because a TypeScript `const` array forbids rebinding the name and permits `arr[0] = 1`.

## 출처

[`var` Declarations](https://gpuweb.github.io/gpuweb/wgsl/#var-decls) and [Memory Access Mode](https://gpuweb.github.io/gpuweb/wgsl/#memory-access-mode); surface §7. The two words are WGSL’s own enumerants and already appear on this surface in `texture_storage_2d<"r32float", "read_write">`, so neither takes a §9.3 row.

## 검증 방식

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

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

- [`TS8002`](https://typeshade.dev/ko/reference/errors/ts8002/) for an access word outside the two, and for a second type argument on a `uniform<T>`, raised in `src/compiler/ts/bindings.ts`, which recovers the binding as `read_write` so that the author’s own write is not a second sentence on the same program; the inference is `src/compiler/ts/storage-access.ts`, which also refuses a written binding that a vertex entry reads, a binding declared `"read_write"` that a vertex entry reads, and a storage binding that a vertex entry writes, each with [`TS8099`](https://typeshade.dev/ko/reference/errors/ts8099/), and which drops a function that no entry reaches and that writes a binding the program leaves `read`, so that the write draws no [`TS8005`](https://typeshade.dev/ko/reference/errors/ts8005/);
- `TS8099` for the retired `{ access }` option of the call form, raised in the same file, whose sentence names the type-argument spelling to write;
- `TS8005 CONST_ASSIGN` for a write to a read-only resource, whose sentence names the `storage<T>` remedy for a write to a binding whose value type is `readonly` (`src/compiler/ts/lower/readonly-promise.ts`) and the `storage<T, "read_write">` remedy for every other storage binding the write is refused on (`writableRemedy` in `src/compiler/ts/context.ts`; the `"read_write"` spelling in that remedy is one that change 0114, decision D3, removes in S4), and for an atomic builtin on a read binding, whose sentence names the mode rather than the keyword (`src/compiler/ts/lower/atomics.ts`). It names no line in the two cases where no line would close the program: when the binding’s declared value type was itself refused and recovered, since the line would be built from a type the compiler could not read (`storage<mat2x3<f64>>` was answered with `storage<mat2x3, "read_write">`, the `<f64>` dropped), and when the target is no place on either mode, which is why the root’s access is checked after the target is known to be one, for an element (`md[0]` on an `f64` matrix) and for a member after every one of that branch’s refusals (`src.length`, an emulated-double lane `dv[0].x`, a multi-component swizzle `v.xy`);
- TypeScript’s own codes in the editor, because the ambient library resolves `uniform<T>` and `storage<T, "read">` to `ReadView<T>` and `storage<T>` and `storage<T, "read_write">` to `T` itself, so a `readonly` value type draws the error from its own type: `TS2542` on an indexed write (`src[0] = 1.`), `TS2540` on a field write (`u.scale = 1.`), `TS2344` on an access word outside the two and `TS2314` on a second type argument to a `uniform` (`src/language-service/ambient-storage-access.test.ts`);
- `src/compiler/ts/declare-bind.test.ts` for the access mode each spelling collects, and `src/compiler/ts/remedy-lines.test.ts` for the lines these sentences name: every refusal that quotes a declaration has that declaration written back into its own program, which must then compile clean and be clean in the editor;
- not by the editor in two places, which Appendix B records: an atomic builtin on a read binding and a mutating method on a class-typed read binding are refused by the compiler alone.

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

- [`src/compiler/ts/bindings.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/bindings.ts#L1)
- [`src/compiler/ts/context.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/context.ts#L1)
- [`src/compiler/ts/declare-bind.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/declare-bind.test.ts#L1)
- [`src/compiler/ts/lower/atomics.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/atomics.ts#L1)
- [`src/compiler/ts/lower/readonly-promise.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/readonly-promise.ts#L1)
- [`src/compiler/ts/member-assign-emit.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/member-assign-emit.test.ts#L1)
- [`src/compiler/ts/member-assign-places.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/member-assign-places.test.ts#L1)
- [`src/compiler/ts/member-assign.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/member-assign.test.ts#L1)
- [`src/compiler/ts/remedy-lines.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/remedy-lines.test.ts#L1)
- [`src/compiler/ts/storage-access-paths.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/storage-access-paths.test.ts#L1)
- [`src/compiler/ts/storage-access.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/storage-access.test.ts#L1)
- [`src/compiler/ts/storage-access.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/storage-access.ts#L1)
- [`src/language-service/ambient-matrix-index.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-matrix-index.test.ts#L1)
- [`src/language-service/ambient-storage-access.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-storage-access.test.ts#L1)
- [`src/language-service/ambient-texture-lowering.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-texture-lowering.test.ts#L1)
- [`src/language-service/ambient-texture-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-texture-refusals.test.ts#L1)
- [`src/language-service/ambient-vector-math.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient-vector-math.test.ts#L1)
- [`src/language-service/ambient.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/ambient.test.ts#L1)

## 설명하는 절

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

- [§1 Resources — `declare`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#1-resources--declare)
- [§7 Diagnostics (required)](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#7-diagnostics-required)
- [§9 Assignment targets](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#9-assignment-targets)
- [§23 Atomics](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#23-atomics)

## 적용하는 오류 코드

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

**[`TS8002`](https://typeshade.dev/ko/reference/errors/ts8002/) `UNKNOWN_TYPE`**

아무것도 선언하지 않은 타입 이름입니다. 매개변수, 타입 인자, 별칭, `implements` 절, 기반 클래스 어디에 써도 걸리고, 이 표면이 매퍼가 읽는 자리에서 받지 않는 타입도 여기에 속합니다([규칙 2.1](https://typeshade.dev/ko/reference/rules/2-1/)). 파일이 선언했지만 구조체로 모으지 않은 기반은 `STRUCT_FIELD`입니다.

**[`TS8005`](https://typeshade.dev/ko/reference/errors/ts8005/) `CONST_ASSIGN`**

바뀔 수 없는 이름이나 자리에 값을 대입합니다. `const`에 담은 수나 벡터, `const` 벡터나 행렬의 성분, `readonly` 필드나 static, 그리고 `readonly`나 `"read"`로 쓰지 않겠다고 약속한 스토리지 바인딩에는 값을 쓸 수 없습니다. `const` 객체의 필드나 원소에 쓰는 것은 여기에 해당하지 않습니다. `const`는 객체를 담고 있을 뿐이고, 객체는 JavaScript에서처럼 계속 쓸 수 있기 때문입니다([규칙 6.10](https://typeshade.dev/ko/reference/rules/6-10/)).

**[`TS8099`](https://typeshade.dev/ko/reference/errors/ts8099/) `UNSUPPORTED`**

자기 코드를 받을 만하지 않은 진단을 위한 포괄 코드입니다. 순차 범위 뒤인 TS8099에 따로 둡니다.

## 함께 보기

- [규칙 6.1](https://typeshade.dev/ko/reference/rules/6-1/) 테스트
- [규칙 6.3](https://typeshade.dev/ko/reference/rules/6-3/) 테스트
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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