---
title: "Rule 6.3: Declarations and resources in TypeShade"
description: "Rule 6.3 of the TypeShade language design, in Declarations and resources."
url: https://typeshade.dev/reference/rules/6-3/
language: en
---

# 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](https://typeshade.dev/reference/rules/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](https://gpuweb.github.io/gpuweb/wgsl/#value-decls) (`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`](https://typeshade.dev/reference/errors/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:

- [`src/compiler/ts/math-binding.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-binding.test.ts#L1)
- [`src/compiler/ts/math-binding.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/math-binding.ts#L1)
- [`src/compiler/ts/module-const-f64.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-const-f64.test.ts#L1)
- [`src/compiler/ts/module-const.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-const.test.ts#L1)
- [`src/compiler/ts/module-const.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-const.ts#L1)

## Explained in

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

- [§12 Module constants](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#12-module-constants)
- [§39 `f64`: the emulated double](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#39-f64-the-emulated-double)

## Error codes that enforce it

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

**[`TS8003`](https://typeshade.dev/reference/errors/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](https://typeshade.dev/reference/rules/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

- [Rule 6.2](https://typeshade.dev/reference/rules/6-2/) Test
- [Rule 6.4](https://typeshade.dev/reference/rules/6-4/) Test
- [Rule 9.4](https://typeshade.dev/reference/rules/9-4/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

- [`docs/language-design.md:504`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/language-design.md#L504) (the design document)
- [`reqs/rules/RULE-0603.md`](https://github.com/typeshade/typeshade/blob/af54ddad5/reqs/rules/RULE-0603.md) (its traceability item)
