---
title: "Rule 11.27: Targets and the oracle, a TypeShade design rule"
description: "Rule 11.27 of the TypeShade language design, in Targets and the oracle."
url: https://typeshade.dev/reference/rules/11-27/
language: en
---

# Rule 11.27

Chapter 11, Targets and the oracle Test

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.

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

## Rationale

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

## Derives from

`changes/0156-optimizer-makes-no-refused-constant.md` (P1 to P5, amendment A1); [#368](https://github.com/typeshade/typeshade/issues/368); [#613](https://github.com/typeshade/typeshade/issues/613); [#1789](https://github.com/typeshade/typeshade/issues/1789); [#1876](https://github.com/typeshade/typeshade/issues/1876); OD-3; OD-9.

## 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:

`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](https://github.com/typeshade/typeshade/issues/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](https://typeshade.dev/reference/rules/13-3/)).

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

- [`scripts/compile-gate.ts:134`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/compile-gate.ts#L134)
- [`src/compiler/ts/const-bind-forms.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/const-bind-forms.test.ts#L1)
- [`src/compiler/ts/const-bind-refusals.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/const-bind-refusals.test.ts#L1)
- [`src/core/backends/glsl-const-bind.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/glsl-const-bind.test.ts#L1)
- [`src/core/passes/const-bind-emit.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/const-bind-emit.test.ts#L1)
- [`src/core/passes/const-bind.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/const-bind.test.ts#L1)
- [`src/core/passes/const-bind.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/const-bind.ts#L1)
- [`src/core/passes/const-expr.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/const-expr.ts#L1)
- [`src/core/passes/opt/const-fold.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/opt/const-fold.ts#L1)

## See also

- [Rule 11.23](https://typeshade.dev/reference/rules/11-23/) Test
- [Rule 12.1](https://typeshade.dev/reference/rules/12-1/) Test
- [Rule 13.3](https://typeshade.dev/reference/rules/13-3/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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