---
title: "규칙 8.8: 함수와 진입점, TypeShade 셰이더 언어 설계 규칙과 그 근거, 출처, 검증 방식"
description: "TypeShade 언어 설계 규칙 8.8(함수와 진입점)입니다. An object has the identity a JavaScript object has (change 0142)."
url: https://typeshade.dev/ko/reference/rules/8-8/
language: ko
---

# 규칙 8.8

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

An object has the identity a JavaScript object has (change 0142). An object is a struct, an instance of a class, or an array, with a size or with none. A function of the file or of a namespace changes the caller’s object when it writes a field or an element of its object parameter, calls `push` or `fill` on it, calls on it a method that writes its object ([Rule 8.10](https://typeshade.dev/ko/reference/rules/8-10/)), or hands it to a parameter that its function writes. The author writes no qualifier: the compiler reads the source and passes the caller’s place ([Rule 8.25](https://typeshade.dev/ko/reference/rules/8-25/)). A number, a `bool`, a vector and a matrix are values, as a JavaScript primitive is. A function gives a value back by returning it, and a list assignment, `[a, b] = f(a, b)`, takes two results apart. An author writes no pointer value: no `ptr`, no `&` and no qualifier. Whole-value assignment, compound assignment and integer updates of a value parameter must rebind a mutable local initialized from the input, leaving the caller’s value unchanged. A whole assignment to an object parameter (`p = new P()`) makes `p` name a local, and the caller’s object does not change. Where the body writes the caller’s object through `p` before that assignment, the assignment is [`TS8099`](https://typeshade.dev/ko/reference/errors/ts8099/), not supported yet (change 0142, stage 2): the compiler does not yet keep the caller’s object and the local apart under one name. A loop name, `for (let p of ps)`, follows the same rule. Only a parameter whose declaration a whole write resolves to gets this local; a shadowing declaration does not count. Within that body’s scope the local may be written through its fields or elements. A value parameter with no whole write retains its existing read-only place semantics. Resource handles and the reference-backed arrays of [Rule 8.23](https://typeshade.dev/ko/reference/rules/8-23/) are not local-copy values. A second name of an object is that object, as in JavaScript, and the compiler never compiles a copy that JavaScript would not make (OD-9; change 0142, Amendments A3 and A4). Six rules keep it. Rules 1 to 5 read one function, and rule 6 reads the module. A refusal is `TS8099`, “One object under two names is not supported yet (change 0142, stage N)”, unless a rule below names another code. Rule 1. A second name is the same place. `const q = p`, `let q = p`, `const q = ps[i]`, `const q = h.c`, `for (const q of ps)` and `let b = f(a)`, where every `return` of `f` names one parameter, make `q` a name of that place. The compiler makes no copy, and it reads an index in the place once, where the name is declared. A second name that is assigned whole later, or that a function inside the body uses, is `TS8099`; so is an index that the statement cannot hold once. Rule 2. A store is a move. A statement that puts an object that has a name into another holder (`xs[i] = p`, `h.c = p`, `[p, …]`, `{ c: p }`, `new B(p)`, `xs.push(p)`, `q = p` for a `q` that exists) is accepted only where `p` is a local of the function that the function does not use after the statement. After the statement the holder is the one name of the object. Every other such statement is `TS8099`. `xs.fill(o)` of a new object is `TS8099` too, because every element is then one object. Rule 3. A new object is one the source shows to be new: `new`, an object or an array literal, `structuredClone(v)` of a struct that is no class, `xs.slice()` and `xs.map(f)` of values, and a call of a function of the file whose every `return` gives an object that the function built and stored nowhere else. A store of a new object is no refusal. Rule 4. The result of any other call that gives an object may be an object that has a name. A `const` may take it where the function, after that declaration, writes no object and only reads the `const`. Any other declaration of it, a `let` included, is `TS8099`. Rule 5. A place that a second name names stays that place while the name is read. A statement that assigns the place, or a holder of it, with a read of the name after it, is `TS8099`. A call of a function declared inside the function runs that function’s body where the call is, and a use of a getter or a setter that may write runs its body on its object; rules 4 and 5 and the loop of rule 1 read both there. Rule 6. An object of a type that the program never writes is a copy, because no write shows through a second name and `===` between objects is refused ([`TS8003`](https://typeshade.dev/ko/reference/errors/ts8003/)). So a store of such an object (rule 2), a name for such an object that a call or a conditional gives (rule 4) and a `let` second name that is assigned whole later (rule 1) are accepted, and the compiler makes a copy. A struct or an array type is written where a store, an atomic or a texture store reaches a field or an element through a value of that type, and a type is never written where it and every struct and array type inside it are not. A constructor’s own stores to its object build it and do not count. The compiler reads the lowered program whole, by type and not by name, and holds a refusal that rule 6 can lift until every function is lowered. Rule 6 lifts no other refusal: rule 5, a parameter or a loop name assigned whole after a write, [`TS8074`](https://typeshade.dev/ko/reference/errors/ts8074/), `xs.slice()` of objects and `structuredClone` of a class instance keep theirs. A copy is written with a name JavaScript has, and the language adds no copy construct (change 0142, Table 3): `xs.slice()` of numbers or vectors, and `structuredClone(v)` of a struct that is no class or of an array with a size. `[...xs]` alone is [`TS8013`](https://typeshade.dev/ko/reference/errors/ts8013/), and its sentence names `xs.slice()`; `structuredClone` of an instance of a class and `slice()` of an array of objects are `TS8099`, not supported yet (stage 3). `f(a, a)` where `f` writes one of the two, a module variable passed to a function that also uses its name (`TS8074`), and `===` or `!==` between objects (`TS8003`) are refused as not supported yet (change 0142, stage 2). A parameter of a method, a constructor, a setter, a local function, a function handed as an argument and a generic function takes a value in this version, and a write to an object one is [`TS8018`](https://typeshade.dev/ko/reference/errors/ts8018/) until stage 2 of change 0142. An entry’s parameter is the pipeline’s value, which no caller in the program holds. A write to a field or an element of it is `TS8018` in this version, not supported yet: copy the value into a `let` and write that. The object of a method that changes its object, and a variable of the function around it that a local function writes, are not parameters an author writes: Rules 8.10 and [8.17](https://typeshade.dev/ko/reference/rules/8-17/) govern them, and each is passed by reference. A kernel function’s parameter of an array with no size is the caller’s storage (Rule 8.23).

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

## 근거

a struct, an instance of a class and an array are objects in JavaScript, and a function that writes its parameter changes the caller’s object there. The compiler reads which parameters a function writes, so the author writes no mark for it (OD-3, OD-5). A number is a value in JavaScript, so a function that changes one returns it. The contract is about identity and sharing only: which object a name refers to, and who sees a write to it, is never other than what JavaScript says. Where the compiler does not implement a form yet, it refuses the form with a text that says so (OD-9). The two references of [Rules 8.10](https://typeshade.dev/ko/reference/rules/8-10/) and [8.17](https://typeshade.dev/ko/reference/rules/8-17/) are how the emitted function keeps TypeScript’s own meaning (a method writes the object it was called on, a closure writes the variable it closes over), and no author writes either one.

## 출처

change `0040` in `changes/`, which took the roadmap’s “pointers and reference parameters”; change `0142` in `changes/`; `docs/owner-decisions.md`, OD-5 and OD-9; [Function Calls](https://gpuweb.github.io/gpuweb/wgsl/#function-calls).

## 검증 방식

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

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

`TS8020 FUNCTION_SHAPE` for a parameter shape the surface does not take, which since change 0093 includes an optional parameter `x?: T` on an entry point or on a kernel function and `x?: T = d` (the sentences are in [Rule 7.10](https://typeshade.dev/ko/reference/rules/7-10/)’s “Enforced by”, from `src/compiler/ts/lower/function.ts`), and no longer an optional parameter on any other function, which Rule 7.10 takes (change 0093). The reading of which object parameters a function writes is `isWrittenObjectParameter` in `src/compiler/ts/object-reference/written.ts`, and the reading of the six rules is `src/compiler/ts/object-share.ts` (rules 2, 4 and 5), `src/compiler/ts/new-object.ts` (rule 3), `secondNameOf` and `copyOfObject` in `src/compiler/ts/lower/second-name.ts` (rules 1 and 4), `src/compiler/ts/written-types.ts` with `src/compiler/ts/lower/pending-shares.ts` (rule 6) and `reportSharedObjects` in `src/compiler/ts/lower/function.ts`, pinned by `src/compiler/ts/second-name.test.ts`, which holds each rule and the three examples of Amendment A3 and the programs of Amendment A4 in both halves and on the CPU oracle, and by `src/compiler/ts/object-reference.test.ts`. Value rebinding, caller isolation, captures, class bodies, generic/higher-order copies and entry inputs are pinned by `src/compiler/ts/mutable-parameters.test.ts`; the immutable GPU input and distinct local by `src/compiler/ts/tint-invalid.test.ts`; the packed-package path by `journeys/mutable-parameters/`.

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

- [`src/compiler/ts/lower/function.ts:2307`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function.ts#L2307)
- [`src/compiler/ts/lower/pending-shares.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/pending-shares.ts#L1)
- [`src/compiler/ts/lower/second-name.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/second-name.ts#L1)
- [`src/compiler/ts/mutable-parameters.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/mutable-parameters.test.ts#L1)
- [`src/compiler/ts/new-object.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/new-object.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/overloads.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/overloads.test.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/second-name-copies.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/second-name-copies.test.ts#L1)
- [`src/compiler/ts/second-name.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/second-name.test.ts#L1)
- [`src/compiler/ts/tint-invalid.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/tint-invalid.test.ts#L1)
- [`src/compiler/ts/written-types.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/written-types.ts#L1)

## 설명하는 절

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

- [§14 TypeScript shapes the parser already had](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#14-typescript-shapes-the-parser-already-had)
- [§26 Classes with methods, a constructor and static functions](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#26-classes-with-methods-a-constructor-and-static-functions)
- [§52 Operators, switch and statements: what WGSL spells, and what it does not](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#52-operators-switch-and-statements-what-wgsl-spells-and-what-it-does-not)
- [§65 A loop that runs as a kernel](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#65-a-loop-that-runs-as-a-kernel)
- [§70 Objects, passed as JavaScript passes them](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#70-objects-passed-as-javascript-passes-them)

## 적용하는 오류 코드

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

**[`TS8020`](https://typeshade.dev/ko/reference/errors/ts8020/) `FUNCTION_SHAPE`**

TypeShade가 지원하지 않는 함수 선언이나 매개변수 모양입니다. 이름이나 본문이 없는 경우, 나머지 매개변수, 구조 분해 매개변수가 그렇습니다.

## 함께 보기

- [규칙 8.7](https://typeshade.dev/ko/reference/rules/8-7/) 테스트
- [규칙 8.9](https://typeshade.dev/ko/reference/rules/8-9/) 테스트
- [규칙 7.10](https://typeshade.dev/ko/reference/rules/7-10/)
- [규칙 8.10](https://typeshade.dev/ko/reference/rules/8-10/)
- [규칙 8.17](https://typeshade.dev/ko/reference/rules/8-17/)
- [규칙 8.23](https://typeshade.dev/ko/reference/rules/8-23/)
- [규칙 8.25](https://typeshade.dev/ko/reference/rules/8-25/)
- [설계 규칙](https://typeshade.dev/ko/reference/rules/)
- [오류 코드](https://typeshade.dev/ko/reference/errors/)

## 소스

커밋 af54ddad5의 규칙 원문:

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