규칙 7.2
이 페이지에서

규칙 7.2

7장, 표현식과 문 테스트

Where TypeShade lowers a TypeScript form to a WGSL form, the mapping must be a rule with a recorded divergence; the mappings today are:

TypeScript formWGSL formDivergence recorded in
whole-value parameter reassignmenta fresh mutable local initialized from the immutable parameter; body reads and writes use that localRule 8.8; surface §14 and §52
c ? a : b on a scalar or vectorselect(b, a, c), WGSL’s own argument ordersurface §10; CHANGELOG.md (ternary as select); select
c ? a : b on a struct or an arrayan if with a temporary, since WGSL has no select over a compositesurface §31 (#113)
a ** bpow(a, b), float-onlysurface §10
atan(y, x)atan2(y, x)surface §10
switchWGSL’s switch, which never falls through; a trailing break is droppedsurface §14; Switch Statement
x << n, x >> nthe amount is a u32; an i32 amount is cast (x << u32(n)), binary and compound alikesurface §14, §22 and §52; Bit Expressions
[a, b] in a typed positionarray<T, 2>(a, b)surface §18 and §28
{ field: value } in a typed positiona struct constructorsurface §16
obj.method()Cls_method(obj, …), dispatched staticallysurface §26
o.x, o.x = v on an accessorCls_get_x(o), Cls_set_x(&o, v); o.x += v goes through bothRule 8.11; surface §26
a private name #xx, private through the front end’s check aloneRule 8.12; surface §26
a static field the file writesa var<private> Cls_f, as a top-level let isRule 8.13; surface §26
a call that writes, in an expressiona let ahead of it, in source order; an if for ?:, && and ||Rule 7.9; surface §26
v.setX(1.).setY(2.) as a statementV_setX(&v, 1.0); V_setY(&v, 2.0);, each call on the chain’s rootRule 8.10; surface §26
D.f() on a static D inheritsD_f, the base’s body lowered again with this as DRule 8.13; surface §26
const v = new V(); v.bump()var v: V = V_new(); V_bump(&v);, a var from the first write through itRule 6.10; surface §26
f = (x: f32): f32 => … in a classCls_f, a method under the field’s nameRule 8.16; surface §26
a local function that reads n of the function around itfs_f(n, …): n is a parameter of fs_f, which every call passesRule 8.17; surface §14
a local function that writes n of the function around itfs_f(&n, …), n: ptr<function, T> in fs_f (inout in GLSL ES 3.00)Rule 8.17; surface §14
apply(sq, x), f a parameter of function typeapply_sq(x): apply once for each function its calls hand itRule 8.18; surface §14
s.each(sq), each a method that takes a functionSwarm_each_sq(s), and &s where a function handed over writes s, the one reference both useRules 8.10 and 8.18; surface §26
an arrow function written as an argumenta local function of the calling body, typed by the parameterRule 8.18; surface §14
a function, a method or an accessor with no return typethe type of its first return with a value, -> f32; none without oneRule 8.19; surface §14
() => n += k with no return typethe assignment as a statement, and the function returns nothing, where TypeScript returns the new nRule 8.19; surface §14
return g(), g returning nothingg(); return;Rule 8.19; surface §14
const w = v, let w = v on a structa copy, where TypeScript shares one object; a write through either name is not seen through the otherRule 6.10; surface §26
for (const x of a) over an arraya counted for over a’s indices, x a copy of a[i] read at the top of each tripRule 7.5; surface §17
xs.map(f) and the other methods of an arraya call of a function made for the array’s type and f, a counted for: array_map_sq(xs)Rule 8.18; surface §63
the index an array’s method passes its functionan i32, where TypeScript passes a numberRule 7.5; surface §63
the value of xs.map(f)an array<R, N> value that a const holds a copy of, where TypeScript builds a new array objectRule 6.10; surface §63
s += x in a loop of a kernel function the proof acceptsa fold in the tree order on every tier, where TypeScript adds in iteration order; an f32 or f64 sum or product may differ from that reading in the last places, and the determinism report lists it as orderRule 8.22; surface §65; src/core/kernel-tree.ts
a[k] += e into an integer array in such a loopan atomic* on a[k] over array<atomic<T>>, the same bytes; exact in any order, where TypeScript adds in iteration orderRule 8.22; surface §65

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

근거

a TypeScript reader expects the TypeScript meaning, so every place the two languages differ has to be written down where the reader will look.

출처

the rows above.

검증 방식

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

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

the emit goldens and the tests each row’s surface section names; the tree order of a kernel function’s reduction by src/core/kernel-tree.test.ts on the CPU backends, and by the import journey on WebGPU.

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

설명하는 절

커밋 c66579bf의 표면 문서에서 이 규칙을 설명하는 절입니다.

함께 보기

소스

커밋 c66579bf의 규칙 원문:

이 페이지 편집 문제 보고