규칙 8.28
이 페이지에서

규칙 8.28

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

A call must not copy a struct or a fixed-size array that its callee only reads when the argument is a place: a let local, a module variable, an element or a field of a binding, a reference the caller holds (a parameter it writes through or reads in place), or a field or an element of one of those. The arguments it covers are a method’s or a getter’s object, the object of a base’s body called through super, and a struct or an array argument of a function of the file that does not write that parameter; an entry’s parameters are not covered. The callee reads the caller’s place for the whole call: on WGSL through a pointer, ptr<AS, T> with &place at the call (ptr<storage, T, read> for a read binding), and one copy of the function for each address space its calls use; on GLSL ES 3.00, for a module-scope place (a uniform block, an element of a read storage binding, a module variable), through a copy of the function that reads the place by its name, each index the place is reached through passed as a parameter and evaluated once at the call. A local on GLSL ES 3.00, where no reference only reads, and an argument that is no place stay a copy taken at the call. On WGSL every struct or fixed-size array local is a place: one that WGSL would declare with let is declared as a var that nothing writes, with the same value (change 0105). So does a place that can change while the callee runs, which is a place the callee or a function it calls writes by its name, a place another argument of the call is a reference the callee writes through to, and memory other invocations share (a workgroup variable, an element of a read_write storage binding) when the callee or a function it calls runs a barrier. On GLSL ES 3.00 a reference a callee writes through (Rules 8.10 and 8.25) to a module variable is also reached through a copy of the function that writes the variable by its name. A local must not copy a struct or a fixed-size array either: a const or a let local of such a type whose initializer is a place is a second name of that place (Rule 8.8, rule 1, change 0142), the front end emits no declaration for it, and each read of the name reads the place, written or not (changes 0104 and 0142). Each index the place is reached through that is no literal is evaluated once, where the local is declared, into a name of the compiler’s own. A write to the place shows through the name, and a write through the name shows in the place, as in JavaScript; a barrier changes nothing, because the name reads the place where the name is read. On WGSL a struct or a fixed-size array that a function of the module returns into a local, a module variable or a read_write storage binding, or a field or an element of one, is written there through a pointer, f_into(&dst, …), when that saves a copy: the function builds its result in the one local every return returns, which then is the destination, or returns values that are no place; a call inside such a copy that returns into the destination is written there too. A call keeps its copy when an argument reads the destination or writes a name the destination is spelled with, and, for a module-scope destination, when the function or a function it calls reads or writes it by its name (change 0105). GLSL ES 3.00’s out parameter is a copy back, so the return stays there.

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

근거

in TypeScript an object argument and a method’s this are the object itself, so an author who writes items[i].area() writes a read of the fields area reads, not a load of the element whole; a struct parameter that its function only reads has the value of a copy, so the copy is the compiler’s to avoid, and a driver that inlines the call does not remove every one: an array field read at a dynamic index needs the copy in memory, a storage element loads every field nothing proves dead, a chain of methods copies at each level, and GLSL ES 3.00 rebuilt a uniform block from its members at each call and refused a method on an emulated storage element. The callee reads the place for as long as it runs, where the copy was taken once at the call, and the two read one value unless the place changes during the call; the three routes that can change it keep the copy, so no program computes another value, and the first two are also the calls WGSL’s alias analysis refuses. A copy of the function that names the global is the form a target without pointers has, and the one Tint gives a pointer parameter when it writes HLSL or MSL. A local of a place is the place for the reason a parameter that only reads is: a copy would load the element whole, on each iteration of a loop, and an array field it indexes needs the copy in memory, and where the local or its place is written a copy would not have JavaScript’s result; the place is always the value the name holds. A struct a function returns is built in the callee and copied into the caller’s local, and a constructor’s self_ is the one local it returns, so the caller’s local can be built in place. A let has no address on WGSL, so a method called on one copies it, and so does each method that one calls in turn; a var that nothing writes holds the same one value and is a place.

출처

changes 0103, 0104, 0105 and 0142 in changes/; Function calls, Alias analysis and the language extension unrestricted_pointer_parameters in the WGSL specification; the GLSL ES 3.00 specification, section 6.1.1.

검증 방식

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

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

the pointer-space pass in src/core/backends/wgsl-ptr.ts, the GLSL-local pass in src/core/backends/glsl-global-places.ts, the local pass in src/core/passes/local-places.ts, the binding of a local to its place in src/compiler/ts/lower/second-name.ts, the WGSL local-place pass in src/core/backends/wgsl-let-places.ts and the WGSL return pass in src/core/backends/wgsl-return-into.ts, pinned by src/compiler/ts/local-places.test.ts for the locals and the returns and by src/compiler/ts/reference-reads.test.ts, which compiles each place and each route that keeps the copy, holds the three CPU paths to one value for them, and reads the language service’s diagnostics on the same sources.

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

설명하는 절

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

함께 보기

소스

커밋 af54ddad5의 규칙 원문:

이 페이지 편집 문제 보고