규칙 8.25
8장, 함수와 진입점 테스트
A parameter declared Ref<T> names the caller’s place, and the call passes it as ref(place): reading the parameter reads that place, and assigning to it, or to a field, component or element of it, writes it, for the call.
A Ref<T> parameter belongs to a function declared at the top of the file or of a namespace; an entry, a method, a constructor, an accessor, a local function, a function written as an argument and a generic function take their parameters by value, and Ref<T> written anywhere but on such a parameter (a return type, a field, a local, a module declaration) must be refused.
ref(place) takes what a method that changes its object takes as that object (Rule 8.10): a let, a const whose initializer built its value (Rule 6.10), a module variable, an element of a read_write storage binding, this where it may be written, a Ref<T> parameter, or a field or an element of one of those, of exactly the type T; a value parameter, any other const, a read-only binding, a literal, a value nothing holds and a component of a vector must be refused with the edit; a column of a matrix is a place. A Ref<T> parameter the function holds is passed on as itself or as ref of it, and ref(...) written anywhere but as such an argument must be refused.
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).
A local function must not capture a Ref<T> parameter.
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, and on the CPU a copy in and a store back to the same place on return.
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
a function that changes its argument is what a GLSL or HLSL helper with inout does, and what an author porting one writes; the model is the one TypeShade already gives this (Rule 8.10), so no new syntax and no new IR reach the surface, and a reference is told apart from a value by the parameter’s declared type, as GLSL tells inout from in.
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.
출처
change 0040 in changes/; Alias analysis and Function calls in the WGSL specification; the GLSL ES 3.00 specification, section 6.1.1.
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
TS8073 REFERENCE and TS8074 REFERENCE_ALIAS in src/compiler/ts/lower/references.ts, whose comment records the alias rule measured on Tint; 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, and examples/reference-parameters.shade.ts through the compile gate.
커밋 c66579bf에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
설명하는 절
커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.
적용하는 오류 코드
규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.
-
TS8073REFERENCE - A reference parameter written or passed where this version does not take one (Rule 8.25, surface §70, proposal 0040): a
Ref<T>parameter handed a value rather thanref(x);ref(...)handed something that is not a place a function may write (a value parameter, aconstthat may share its value, a read-only binding, a literal, a temporary, a component of a vector);ref(...)anywhere but as the argument of aRef<T>parameter, and handed to a parameter that takes a value;Ref<T>anywhere but as a parameter of a function declared at the top of the file or of a namespace (a return, a field, a local, a method's, a local function's, an entry's, a generic function's); and a local function that captures aRef<T>parameter. -
TS8074REFERENCE_ALIAS - Two references to one place in one call (Rule 8.25, surface §70, proposal 0040): two arguments a callee takes by reference whose places share a root (
swap(ref(x), ref(x)),swap(ref(o.a), ref(o.b))), a method's object or a variable a local function writes beside aref(...)of the same root, and aref(...)of a module variable or binding that the callee also reads or writes directly.
함께 보기
소스
커밋 c66579bf의 규칙 원문:
docs/language-design.md:908(설계 문서)reqs/rules/RULE-0825.md(추적 항목)