규칙 8.21
8장, 함수와 진입점 테스트
A host call passes and returns host values by value: an f32, f64, i32 or u32 is a number, a bool a boolean, a vector a readonly tuple of its components as an argument and a tuple as a result, a matrix a flat column-major array of its components, an array<T, N> an array of N host values of T, a struct an object of its fields, and an enum member its number.
A fieldless class is {} on the host and CPU. Its reflected memory footprint accounts for the
GPU’s internal carrier: four bytes under natural layout, sixteen under std140, with no visible
fields. Nested fields and array strides follow that footprint.
Each argument is checked and converted: an ArrayLike of the right length becomes a fresh array, an f32 is rounded as a buffer write rounds it, and a value that does not fit is refused with a TypeError naming the function, the parameter and its TypeShade type; the result aliases no argument and nothing the module keeps (Rule 8.8), and an exported constant is a frozen copy.
A call of a function this rule and Rule 8.20 admit is synchronous, and no later tier changes that; as a helper’s parameter, a runtime-sized array, an atomic, a texture, a sampler and a binding have no host value.
A binding of an entry a host calls (Rule 8.24) takes a host value too: a uniform<T> or a sized storage<T> takes T’s, a runtime-sized storage<array<T>> of scalars or vectors takes the scalar’s typed array (Float32Array, Int32Array, Uint32Array, or Float64Array for an f64 and a vecNf64) with the vector’s components one after another, which the call pads to the element’s stride, one of structs takes an array of objects, and either may be a Resident of it (Rule 11.8), an atomic takes its integer’s, a texture_2d<f32> takes an image source (ImageBitmap, ImageData, HTMLImageElement, HTMLCanvasElement, HTMLVideoElement or OffscreenCanvas), uploaded at the call, and a sampler takes { filter?, address? } ('nearest' or 'linear'; 'clamp', 'repeat' or 'mirror'), or nothing for linear and clamp. An emulated f64 (change 0013’s split) is held by the GPU as two f32s, hi and lo, and a vecNf64 as a plane of each: the runtime splits a double into them and joins them back, and binds the _fp64 guard of a module that emulates one, which the host never passes; a matNxN<f64> has no host value yet.
A storage binding the entry writes is read back into the caller’s value in place, so a written binding whose type is one scalar is passed as a typed array of length one.
A kernel function (Rule 8.22) is called asynchronously: it returns Promise<void>, or Promise<R> for a result R; its value parameters take the host values above, its arrays with no size take the scalar’s typed array (Float32Array, Int32Array, Uint32Array, a vector’s components one after another) or, for a struct, an array of objects, and each array it writes is read back into the caller’s in place; each array may be a Resident of it instead (Rule 11.8), and a call whose written arrays are all resident and that returns nothing has a second signature, returning void, since nothing waits on it; before anything runs, the call checks each array against the indices a loop writes at a*i + c and refuses one too short with a TypeError naming the function, the parameter and both numbers.
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
the representation is the one the CPU tier already runs on (src/core/cpu-runtime.ts), typed precisely in the host view, so there is nothing to construct and a wrong shape is a type error before it is a TypeError.
The check at the call is for the caller tsc did not read: an IR node passed as a vector gave NaN in silence, and a Float32Array added to another gave a string.
A later tier takes new shapes (an entry point, a runtime-sized array parameter) that are asynchronous from the day they appear, so a helper’s call site never gains an await it does not need (docs/dx.md principle 4).
출처
change 0009 in changes/ (“Host values were undefined”); Rule 8.8; docs/dx.md.
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
toShader and fromShader in src/core/host-values.ts, which the generated module calls at every argument and result; the view’s types, from hostTypeOf in src/compiler/ts/host-face.ts; pinned by src/compiler/ts/host-face.test.ts, which checks every row in the view, a Float32Array vector, each refusal’s text, and that a result aliases no argument; the binding rows by src/compiler/ts/host-entry.test.ts and src/compiler/ts/host-draw.test.ts.
커밋 c66579bf에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
설명하는 절
커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.
함께 보기
소스
커밋 c66579bf의 규칙 원문:
docs/language-design.md:848(설계 문서)reqs/rules/RULE-0821.md(추적 항목)