규칙 6.3
이 페이지에서

규칙 6.3

6장, 선언과 리소스 테스트

A top-level const is a module constant: a scalar must fold to one value carried at double precision for the oracle and at the target’s precision for emit, and a vector, array, or struct must carry a constant-foldable expression every backend evaluates. A scalar f64 initializer folds its permitted operations and builtin calls at compile time. Its final double and both words of its GPU literal pair must be finite. Within this initializer, explicit f32 conversions and f32 arithmetic or builtin calls round their operands and results to f32 at each operation or call; widening preserves the rounded value. An earlier scalar constant contributes its recorded compile-time value, rounded to f32 when its type is f32, without re-evaluating its GPU expression. Literal-only f64 expressions keep double precision. CPU negative zero is preserved; GPU zero sign and underflow follow the existing split and emit behavior (change 0123). A top-level const whose initializer is Math with an object pattern, or a Math member, binds each name to that member (Rule 9.4) and declares no module constant of its own.

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

근거

a module constant must be one value on every backend, and the dual-precision scalar is how the oracle stays exact where the target rounds.

출처

Value Declarations (const); AGENTS.md (“module constants are scalar dual-precision by default”); surface §12.

검증 방식

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

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

src/compiler/ts/module-const.ts, module-const.test.ts and module-const-f64.test.ts (scalar double folding, precision boundaries and finite pair range, change 0123); src/compiler/ts/math-binding.ts and math-binding.test.ts for the Math binding (change 0113); a bool constant is true, false, 1, or 0 (TS8003, Module const "K" is bool, but 2 is neither true nor false. Write true, false, 1 or 0., pinned by rejects a bool module const that is neither true nor false).

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

설명하는 절

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

적용하는 오류 코드

규칙이 Enforced by 항목에서 가리키는 진단 코드와, 레지스트리 설명에서 이 규칙을 가리키는 진단 코드입니다.

TS8003 TYPE_MISMATCH
연산자나 조건, 선언, 반환, 인자처럼 두 값이 만나는 자리에서 타입이 서로 맞지 않거나, 검사로 좁히지 않은 선택적 값(T | undefined, T | null, T | null | undefined)을 읽거나(규칙 7.10), 컴파일러가 접는 상수를 WGSL이 거부합니다. 31을 넘는 시프트 양, 0인 제수, 서로 엇갈린 clamp 경계, 범위를 넘는 f32 값, Math.pow(-2., 2.)처럼 정의역 밖에서 부르는 내장 함수가 그렇습니다.

함께 보기

소스

커밋 af54ddad5의 규칙 원문:

이 페이지 편집 문제 보고