---
title: "규칙 8.25: 함수와 진입점, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 8.25(함수와 진입점)입니다. An object parameter that its function writes is the caller's object…"
url: https://typeshade.dev/ko/reference/rules/8-25/
language: ko
---

# 규칙 8.25

8장, 함수와 진입점 테스트

An object parameter that its function writes is the caller’s object, and the call passes the variable itself, unmarked: reading the parameter reads that object, and assigning to a field or an element of it writes it, for the call (change 0142). The compiler reads which parameters a function writes (`isWrittenObjectParameter` in `src/compiler/ts/object-reference/written.ts`, [Rule 8.8](https://typeshade.dev/ko/reference/rules/8-8/)); the author writes no qualifier. A function declared at the top of the file or of a namespace takes its object parameters this way; the other kinds take values in this version (Rule 8.8). The argument takes what a method that changes its object takes as that object ([Rule 8.10](https://typeshade.dev/ko/reference/rules/8-10/)): a `let`, a `const` whose initializer built its value or names a place ([Rules 6.10](https://typeshade.dev/ko/reference/rules/6-10/) and 8.8, rule 1), a module variable, an element of a `read_write` storage binding, `this` where it may be written, a parameter the function writes, or a field or an element of one of those, of exactly the parameter’s type; a parameter that holds a copy, any other `const`, a read-only binding and a component of a vector must be refused with the edit; a column of a matrix is a place. A parameter the function writes is passed on as itself. A literal, a `new`, an object literal or a call that gives a new object is no refusal: the compiler holds the value in a local for the call, where nothing else sees the write. A call that may give back an object that has a name (Rule 8.8, rule 3) is refused as not supported yet ([`TS8073`](https://typeshade.dev/ko/reference/errors/ts8073/), change 0142, stage 2): the sentence says the expression “may be an object that already has a name” and asks for a name first. A call of a function whose every `return` names one parameter is named by a `const` (Rule 8.8, rule 1), and the name is passed. A number, a `bool`, a vector and a matrix parameter is a value, and a write to it, or to a component of it, is [`TS8018`](https://typeshade.dev/ko/reference/errors/ts8018/) whose sentence says to return the value. A list assignment, `[a, b] = f(a, b)`, takes two results apart; each place of the list is a name, a field or an element, and a rest element, a hole and a default are refused (`TS8018`, `lowerListAssign` in `src/compiler/ts/lower/statement.ts`). `@inout` and `@out` are removed (change 0142): a parameter written with one is `TS8073`, with one sentence for an object parameter (`"@inout" was removed (change 0142): an object parameter is the caller's object with no mark. Delete "@inout".`) and one for a value parameter (`"@inout" was removed (change 0142): a number, a bool, a vector and a matrix are values. Return the value, and write [a, b] = f(a, b) for more than one.`), the same in both halves. The type forms `a: inout<T>` and `a: out<T>` must be refused with [`TS8028`](https://typeshade.dev/ko/reference/errors/ts8028/), which carries the removal sentence, wherever a type is written. No call fills an array parameter with zeros, and an argument assigns no variable of the caller ([Rule 7.6](https://typeshade.dev/ko/reference/rules/7-6/)): an array parameter holds the values the caller gave it. The place is the one the argument names when the call is made: an index is evaluated once, before the body runs, and a write the call makes to it moves nothing. One call must not take two references whose places share a root (the local, module variable or binding they are reached through) when the callee writes either, nor a reference to a module variable or a binding the callee reads or writes by its name when either side is written; a method’s object and a variable a local function writes count as references (Rules 8.10 and [8.17](https://typeshade.dev/ko/reference/rules/8-17/)), and an argument the callee only reads in place ([Rule 8.28](https://typeshade.dev/ko/reference/rules/8-28/)) counts as a read, which Rule 8.28 passes as a copy where the callee writes its place. The refusal is [`TS8074`](https://typeshade.dev/ko/reference/errors/ts8074/), and it says that the form is not supported yet (change 0142, stage 2): JavaScript allows `f(a, a)`, and the stage that follows which name each write reaches ends it. A local function captures a parameter that its function writes as it captures any variable (Rule 8.17): it reads and writes the caller’s object, and hands it on as itself. A reference reaches each target as its own spelling of the parameter the callee writes through: a pointer on WGSL, `ptr<AS, T>` with `&place` at the call and one copy of the function for each address space its calls use, an `inout` parameter on GLSL ES 3.00, or there, for a module variable, a copy of the function that writes the variable by its name (Rule 8.28), and on the CPU a copy in and a store back to the same place on return.

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

## 근거

in JavaScript an object argument is the object itself, so a function that writes its parameter changes the caller’s object. The compiler reads which parameters a function writes, so no mark says it (OD-3, OD-5); the model is the one TypeShade already gives `this` ([Rule 8.10](https://typeshade.dev/ko/reference/rules/8-10/)), so no new IR reaches the surface. The call is unmarked, as a GLSL or HLSL call with `inout` is. A number is a value in JavaScript, so a function that changes one returns it, and `[a, b] = f(a, b)` takes two results apart. A reference lives for one call because a target copies only there: GLSL ES 3.00 copies an `inout` argument in at the call and out at the return, in an order it leaves undefined, so two references to one place in one call are the one way two targets could disagree, and WGSL’s alias analysis refuses exactly those calls. A vector’s component is no place WGSL takes the address of; a matrix’s column is one, and the CPU paths read and store it back through their column helpers, as they write `m[i] = v`. A local function’s capture outlives no call: the local function is a function of the module that takes what it captures as parameters ([Rule 8.17](https://typeshade.dev/ko/reference/rules/8-17/)), so a captured reference is a reference handed on, which each target already spells.

## 출처

change `0040` in `changes/` (the lowering); change `0142` in `changes/`; `docs/owner-decisions.md`, OD-5 and OD-9; [Alias analysis](https://gpuweb.github.io/gpuweb/wgsl/#alias-analysis) and [Function calls](https://gpuweb.github.io/gpuweb/wgsl/#function-calls) in the WGSL specification; the GLSL ES 3.00 specification, section 6.1.1.

## 검증 방식

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

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

`TS8073 REFERENCE` for an argument that is no place and `TS8074 REFERENCE_ALIAS` in `src/compiler/ts/lower/references.ts`, whose comment records the alias rule measured on Tint; `isWrittenObjectParameter` in `src/compiler/ts/object-reference/written.ts`, which reads the parameters a function writes from the source, and `src/compiler/ts/object-share.ts`, which reads the stores and the places that must stay ([Rule 8.8](https://typeshade.dev/ko/reference/rules/8-8/), rules 2, 4 and 5); [`TS8073`](https://typeshade.dev/ko/reference/errors/ts8073/) for a written qualifier (`refuseRemovedQualifiers` in `src/compiler/ts/decorated-form.ts`) and [`TS8028`](https://typeshade.dev/ko/reference/errors/ts8028/) for the type form, which `tshc migrate` (`src/cli/migrate.ts`) removes from an object parameter and reports on a value parameter; the editor’s TS1206 filter for a removed qualifier in `src/language-service/diagnostics.ts`; the store back to a field or an element in `src/core/oracle.ts`, `src/core/cpu-codegen.ts` and `src/core/debug/interp.ts`; pinned by `src/compiler/ts/reference-parameters.test.ts`, which reads each program in the compiler and the editor, `src/compiler/ts/object-reference.test.ts` and `src/compiler/ts/host-kernel-out.test.ts`, and `examples/gallery/reference-parameters/reference-parameters.shade.ts` through the compile gate.

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

- [`examples/shade-examples.test.ts:28`](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/shade-examples.test.ts#L28)
- [`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/decorated-form.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/decorated-form.ts#L1)
- [`src/compiler/ts/definite-assignment.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/definite-assignment.test.ts#L1)
- [`src/compiler/ts/host-face.test.ts:163`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-face.test.ts#L163)
- [`src/compiler/ts/host-kernel-out.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-out.test.ts#L2)
- [`src/compiler/ts/lower/references.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/references.ts#L1)
- [`src/compiler/ts/object-reference-removed-forms.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-reference-removed-forms.test.ts#L1)
- [`src/compiler/ts/object-reference-reviews.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-reference-reviews.test.ts#L1)
- [`src/compiler/ts/object-reference-unread.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-reference-unread.test.ts#L1)
- [`src/compiler/ts/object-reference.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-reference.test.ts#L1)
- [`src/compiler/ts/object-reference.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-reference.ts#L1)
- [`src/compiler/ts/object-reference/written.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-reference/written.ts#L1)
- [`src/compiler/ts/object-share.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/object-share.ts#L1)
- [`src/compiler/ts/reference-parameters.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/reference-parameters.test.ts#L1)
- [`src/compiler/ts/reference-reads.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/reference-reads.test.ts#L1)
- [`src/core/cpu-codegen.ts:207`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/cpu-codegen.ts#L207)
- [`src/core/debug/interp.ts:145`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/debug/interp.ts#L145)
- [`src/core/oracle.ts:216`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/oracle.ts#L216)
- [`src/language-service/diagnostics.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/language-service/diagnostics.ts#L1)

## 적용하는 오류 코드

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

**[`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 필드가 아니게 됩니다.

**[`TS8073`](https://typeshade.dev/ko/reference/errors/ts8073/) `REFERENCE`**

아직 지원하지 않는 참조 형태입니다([규칙 8.8](https://typeshade.dev/ko/reference/rules/8-8/), 변경 0142). 객체 매개변수는 표시 없이도 호출자의 객체이므로 없앤 `@inout`과 `@out`, 이름이 있는 객체를 돌려줄 수 있는 호출이 그렇습니다. 메시지가 고칠 방법을 알려 줍니다.

**[`TS8074`](https://typeshade.dev/ko/reference/errors/ts8074/) `REFERENCE_ALIAS`**

한 호출에서 한 객체에 이름이 둘이고, 그중 하나에 쓰기가 닿습니다. 둘 중 하나를 쓰는 `f`에 `f(a, a)`를 넘기거나, 이름을 직접 쓰는 함수에 모듈 변수를 넘기는 경우입니다. 메시지는 이 형태를 아직 지원하지 않는다고 말합니다(변경 0142).

## 함께 보기

- [규칙 8.24](https://typeshade.dev/ko/reference/rules/8-24/) 테스트
- [규칙 8.28](https://typeshade.dev/ko/reference/rules/8-28/) 테스트
- [규칙 6.10](https://typeshade.dev/ko/reference/rules/6-10/)
- [규칙 7.6](https://typeshade.dev/ko/reference/rules/7-6/)
- [규칙 8.8](https://typeshade.dev/ko/reference/rules/8-8/)
- [규칙 8.10](https://typeshade.dev/ko/reference/rules/8-10/)
- [규칙 8.17](https://typeshade.dev/ko/reference/rules/8-17/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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