규칙 11.27
11장, 대상과 오라클 테스트
A function of an emitted module must hold no constant expression that its target refuses to evaluate, or evaluates to another value than the operation has at run time: the pass that settles constant expressions binds an operand of such an operation to a let, and the operation is evaluated when the shader runs.
규칙 본문과 그 아래 항목은 설계 문서에 적힌 컴파일러 원문이라 한국어 페이지에서도 영어로 둡니다.
근거
WGSL evaluates a constant expression when it creates the shader and makes one outside a builtin’s domain or past the range of its type an error; the compiler can give such an operation its run-time value by evaluating it when the shader runs, so the form is not refused (OD-9), whether the author wrote the constants in the call or passed them through a helper, and the same source does not compile or fail by optimization level. A WebGL2 driver accepts such an expression and folds it to a value of its own (pow(-2.0, 2.0) to 0).
출처
검증 방식
테스트로 확인합니다. 테스트나 게이트 스크립트, CI 워크플로가 이 규칙을 가리키고, 아래 파일 가운데 하나라도 규칙을 더는 가리키지 않으면 추적 검사가 실패합니다.
컴파일러가 이 규칙을 적용하는 곳을 규칙이 직접 적은 내용입니다.
settleConstExprs (src/core/passes/const-expr.ts) and constFold (src/core/passes/opt/const-fold.ts), pinned by src/core/passes/const-bind.test.ts (each class of the scope table, and what stays unbound), src/core/passes/const-bind-emit.test.ts (each emit path) and src/core/backends/glsl-const-bind.test.ts (the operand in a local on GLSL ES 3.00); both halves read the helper forms and the twelve forms of #1876 in src/compiler/ts/const-bind-forms.test.ts, and the refusals that stay in src/compiler/ts/const-bind-refusals.test.ts; the const-bind leg of scripts/compile-gate.ts judges the programs on Tint and WebGL2 and hands Tint the text that the baseline emitted for each class (Rule 13.3).
커밋 af54ddad5에서 이 규칙을 확인하는 파일입니다. 파일마다 규칙을 처음 가리키는 줄로 연결했습니다.
-
scripts/compile-gate.ts:134 -
src/compiler/ts/const-bind-forms.test.ts:1 -
src/compiler/ts/const-bind-refusals.test.ts:1 -
src/core/backends/glsl-const-bind.test.ts:1 -
src/core/passes/const-bind-emit.test.ts:1 -
src/core/passes/const-bind.test.ts:1 -
src/core/passes/const-bind.ts:1 -
src/core/passes/const-expr.ts:1 -
src/core/passes/opt/const-fold.ts:1
함께 보기
소스
커밋 af54ddad5의 규칙 원문:
docs/language-design.md:1709(설계 문서)reqs/rules/RULE-1127.md(추적 항목)