Rule 6.3
On this page

Rule 6.3

Chapter 6, Declarations and resources Test

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.

The rule text and the parts under it are the compiler's own English, as the design document writes them.

Rationale

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.

Derives from

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

How it is verified

Checked by a test. A test, a gate script or a CI workflow names this rule, and the traceability check fails when a file listed below stops naming it.

Where the rule says the compiler enforces it:

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).

The files that verify it at commit af54ddad5, each at the first line that names the rule:

Explained in

The sections of the surface document that explain this rule, at commit af54ddad5:

Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

TS8003 TYPE_MISMATCH
Two types that do not fit where they meet (an operator, a condition, a declaration, a return or an argument), a read of an optional value (T | undefined, T | null or T | null | undefined) that no test narrowed (Rule 7.10), or a constant the compiler folds that WGSL refuses: a shift amount past 31, a divisor of 0, clamp bounds that cross, an f32 past its range or a builtin call outside its domain, such as Math.pow(-2., 2.).

See also

Source

The rule at commit af54ddad5:

Edit this page Report a problem