---
title: "TypeShade design rules: the language's rules, by chapter"
description: "The 137 rules the TypeShade language is designed by, each with its rationale, what it derives from, how it is verified and the error codes that enforce it."
url: https://typeshade.dev/reference/rules/
language: en
---

# Design rules

137 rules

Every rule of the compiler's design document, `docs/language-design.md`, read from its traceability tree at commit af54ddad5. A rule constrains an author writing a `"use typeshade"` file or the compiler itself. Each one states one requirement, why it holds, what it derives from, and where the compiler enforces it.

How each rule is verified, as the traceability tree records it:

- Test 128 rules: a test, a gate script or a CI workflow names the rule.
- Code only 2 rules: only the implementation carries the rule, and no test checks it yet.
- Not enforced 0 rules: listed as not yet enforced, in Appendix B of the design document.
- Review 7 rules: held by review, and no file checks them.

[What is guaranteed](https://typeshade.dev/reference/rules/guarantees/) lists the rules of each kind, with the files that verify each one.

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

## Changes since the previous pin

Between the previous pin, cddff54d0 (2026-12-03), and this one, af54ddad5, as the compiler's traceability tree records them. A rule changed when its fingerprint moved, which happens when its text or the files that verify it change. 0 added, 0 removed, 2 changed.

### Changed

- [Rule 4.6](https://typeshade.dev/reference/rules/4-6/) compiler commits [`99af991f8`](https://github.com/typeshade/typeshade/commit/99af991f8)
- [Rule 12.7](https://typeshade.dev/reference/rules/12-7/) compiler commits [`99af991f8`](https://github.com/typeshade/typeshade/commit/99af991f8)

## 1. Introduction

**[Rule 1.1](https://typeshade.dev/reference/rules/1-1/) Test**

A `"use typeshade"` program must mean what this document defines.

**[Rule 1.2](https://typeshade.dev/reference/rules/1-2/) Code only**

GLSL ES 3.00 is a target of the compiler; it must not be the definition of a construct.

**[Rule 1.3](https://typeshade.dev/reference/rules/1-3/) Test**

The CPU oracle is the reference evaluation of the meaning this document defines ([Rule 1.1](https://typeshade.dev/reference/rules/1-1/)): ECMAScript’s result for a form borrowed from ECMAScript, with the arithmetic of the WGSL types the program uses, WGSL’s result for a form borrowed from WGSL, the recorded result where a rule gives another, and, where WGSL leaves room (§11), one of the permitted answers.

**[Rule 1.4](https://typeshade.dev/reference/rules/1-4/) Test**

Where ECMAScript has a form that carries the GPU meaning, the surface must borrow TypeScript’s spelling; a WGSL spelling is borrowed only where no ECMAScript spelling carries the meaning, and the borrowing must keep every WGSL capability reachable ([Rule 11.14](https://typeshade.dev/reference/rules/11-14/)).

**[Rule 1.5](https://typeshade.dev/reference/rules/1-5/) Review**

The representation of a form ECMAScript defines is the compiler’s: a value on the stack, a binding, or memory the compiler owns, and it may change between versions while every observable answer stays the one [Rule 1.1](https://typeshade.dev/reference/rules/1-1/) defines.

**[Rule 1.6](https://typeshade.dev/reference/rules/1-6/) Review**

TypeShade code is compute code: it computes results from data, may run in parallel, and gives the same answer on every target.

**[Rule 1.7](https://typeshade.dev/reference/rules/1-7/) Test**

Every form the surface takes beyond TypeScript must be one the language service can give TypeScript’s checker so that the checker serves the editor ([Rule 12.7](https://typeshade.dev/reference/rules/12-7/)): projected to valid TypeScript, or kept as a form TypeScript parses, whose grammar report the language service drops and whose content it checks with the compiler’s own check of that form (a stage attribute, [Rule 8.1](https://typeshade.dev/reference/rules/8-1/), or `@workgroup_size`, [Rule 8.22](https://typeshade.dev/reference/rules/8-22/)).

**[Rule 1.8](https://typeshade.dev/reference/rules/1-8/) Test**

A construct of the language is written in the language’s own syntax: the directive, a type of the surface, or an attribute `@name` or `@name(…)` on the declaration it marks.

## 2. Sources of the surface

**[Rule 2.1](https://typeshade.dev/reference/rules/2-1/) Test**

Every author-facing name must come from exactly one of three sources:

**[Rule 2.2](https://typeshade.dev/reference/rules/2-2/) Test**

A compiler-internal name (§2.1) must not be authorable.

**[Rule 2.3](https://typeshade.dev/reference/rules/2-3/) Test**

A value sometimes has to cross between a representation the compiler chose and one the target has: an `f64` and the two `f32` halves that carry it across an interface of `f32`.

**[Rule 2.4](https://typeshade.dev/reference/rules/2-4/) Test**

An ECMAScript name that has a WGSL meaning must lower to that meaning, and an ECMAScript name that has no WGSL meaning is still an ECMAScript name, whatever the backend expands it to.

## 3. Textual structure and names

**[Rule 3.1](https://typeshade.dev/reference/rules/3-1/) Test**

A shader file must begin with the directive `"use typeshade"` as its first statement.

**[Rule 3.2](https://typeshade.dev/reference/rules/3-2/) Test**

A local variable, parameter, module constant or module variable may use any identifier TypeScript permits.

**[Rule 3.3](https://typeshade.dev/reference/rules/3-3/) Test**

A declaration named by a WGSL keyword or reserved word must receive a fresh WGSL spelling, with every reference rewritten, whatever its kind (Proposal 0070).

**[Rule 3.4](https://typeshade.dev/reference/rules/3-4/) Test**

A local variable, parameter, module constant or module variable that collides with a GLSL ES 3.00 identifier restriction must be renamed consistently by the GLSL writer; helper function renaming retains its existing behavior.

**[Rule 3.5](https://typeshade.dev/reference/rules/3-5/) Test**

A name the compiler generates (the mangler, the type aliaser) must not be a keyword or reserved word of either target.

**[Rule 3.6](https://typeshade.dev/reference/rules/3-6/) Test**

A type name an author writes is spelled as its source spells it: lowercase where WGSL declares it, as ECMAScript spells it where ECMAScript declares it (`Map`, `Set`, `boolean`), and capitalized where TypeShade declares it.

**[Rule 3.7](https://typeshade.dev/reference/rules/3-7/) Review**

A new surface section must take the next free `§` number in `docs/use-typeshade-surface.md` as the current tree makes it, and a new diagnostic must take the next free `TS80xx` code in `src/compiler/ts/codes.ts`.

**[Rule 3.8](https://typeshade.dev/reference/rules/3-8/) Test**

A shader module that host code imports is named `*.shade.ts`, and a host import of a `.ts` file that begins with the directive under any other name must be refused with the rename.

**[Rule 3.9](https://typeshade.dev/reference/rules/3-9/) Test**

A shader file may import what another shader file exports, by a relative specifier or, from a package, by the package’s name; the file a compile starts from and every shader file it imports, directly or through another, are one program, which emits one module, and each file keeps the scope TypeScript gives it.

## 4. Types

**[Rule 4.1](https://typeshade.dev/reference/rules/4-1/) Test**

Every type an author writes must be a type borrowed from WGSL under a TypeScript spelling, a member of the `f64` family ([Rule 4.4](https://typeshade.dev/reference/rules/4-4/)), a key type, or a type ECMAScript defines that the compiler represents ([Rule 1.5](https://typeshade.dev/reference/rules/1-5/)).

**[Rule 4.2](https://typeshade.dev/reference/rules/4-2/) Test**

A type alias is another name for its target.

**[Rule 4.3](https://typeshade.dev/reference/rules/4-3/) Test**

A brand must be erased: `f32 & { readonly [m]: 'm' }` and `{ readonly __brand: 'm' }` are the carrier type, and the brand must reach no emitted text.

**[Rule 4.4](https://typeshade.dev/reference/rules/4-4/) Test**

The `f64` family (`f64`, `vec2f64`, `vec3f64`, `vec4f64`, the short spellings `vec2d`, `vec3d`, and `vec4d` and, by type argument, `mat2<f64>`, `mat3<f64>`, and `mat4<f64>`) is the one numeric type family TypeShade adds that WGSL does not have.

**[Rule 4.5](https://typeshade.dev/reference/rules/4-5/) Test**

A TypeScript type the compiler cannot represent on a target must be refused in one sentence naming the reason and what to write instead; the list is surface §28 and is not repeated here.

**[Rule 4.6](https://typeshade.dev/reference/rules/4-6/) Test**

`boolean` written as a type must mean `bool`, and `number` written as a type must mean that the type is inferred from its uses (OD-7); where no use decides, the type must be `f32`.

**[Rule 4.7](https://typeshade.dev/reference/rules/4-7/) Test**

`f16` and the `h` spellings must not be authorable until the roadmap’s After 1.0 row is picked up; the `f16` capability may be declared through the EDSL and nothing an author writes uses it.

**[Rule 4.8](https://typeshade.dev/reference/rules/4-8/) Test**

Every `matCxR` with `C` and `R` in 2, 3, 4 must be a type, and a square one must also answer to `matN`.

## 5. Literals and typing

**[Rule 5.1](https://typeshade.dev/reference/rules/5-1/) Test**

An integer-written literal must take the integer type the position around it declares.

**[Rule 5.2](https://typeshade.dev/reference/rules/5-2/) Test**

A written number beside a typed peer in an arithmetic operator or a builtin call must take the peer’s kind; a written number beside an `f64` or an `f64` vector must become an `f64` literal carrying the full double.

**[Rule 5.3](https://typeshade.dev/reference/rules/5-3/) Test**

There is no implicit conversion between concrete types; an `i32` beside a `u32`, or an integer beside a float, must be refused with the cast to write.

**[Rule 5.4](https://typeshade.dev/reference/rules/5-4/) Test**

A literal must fit the type it takes; `-1` in a `u32` position and `2147483648` in an `i32` position are refused as written.

**[Rule 5.5](https://typeshade.dev/reference/rules/5-5/) Test**

A single float-written literal valued as a whole number may take a declared integer type in a declaration only; a return, an argument, and a field must not take that carve-out.

## 6. Declarations and resources

**[Rule 6.1](https://typeshade.dev/reference/rules/6-1/) Test**

A resource must be written `declare const x: uniform<T>`, `declare const x: storage<T>`, `declare const x: storage<T, "read_write">`, or `declare const x: <texture or sampler type>`.

**[Rule 6.2](https://typeshade.dev/reference/rules/6-2/) Test**

A storage binding’s access mode is inferred from what the program does: a binding that some entry writes, by assignment, a mutating method, an atomic builtin, or a write through a function or a reference parameter, is `var<storage, read_write>`, and every other storage binding is `var<storage, read>`.

**[Rule 6.3](https://typeshade.dev/reference/rules/6-3/) 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.

**[Rule 6.4](https://typeshade.dev/reference/rules/6-4/) Test**

A pipeline-overridable constant must be written `const x: override<T> = default` or `declare const x: override<T>`.

**[Rule 6.5](https://typeshade.dev/reference/rules/6-5/) Test**

A top-level `let` is a module variable in the per-invocation (`private`) address space; workgroup memory must be written `let x: workgroup<T>`; a module variable must take no `declare`.

**[Rule 6.6](https://typeshade.dev/reference/rules/6-6/) Test**

An entry point’s inputs and outputs are explicit parameters and return values.

**[Rule 6.7](https://typeshade.dev/reference/rules/6-7/) Test**

The attribute names the compiler reads are `vertex`, `fragment`, `compute`, `workgroup_size`, `builtin`, `location`, `interpolate`, `invariant` and `blend_src` (the last three since [#168](https://github.com/typeshade/typeshade/issues/168), surface §53).

**[Rule 6.8](https://typeshade.dev/reference/rules/6-8/) Test**

The byte layout the emitted module assumes for a resource and the layout `reflect()` reports must agree byte for byte, under WGSL’s uniform and storage layout rules, and so must the layout the manifest carries ([Rule 11.10](https://typeshade.dev/reference/rules/11-10/)); a vertex entry’s vertex buffer is one layout, its `@location` inputs tightly packed in the order written and numbered in that order where no `location<n, T>` states the number ([Rule 6.6](https://typeshade.dev/reference/rules/6-6/)), which `reflect().vertex` and the manifest both report.

**[Rule 6.9](https://typeshade.dev/reference/rules/6-9/) Test**

A struct must be the members written in it, in one of four spellings (`class`, `interface`, a `type` over an object literal, an object type literal written where a type stands).

**[Rule 6.10](https://typeshade.dev/reference/rules/6-10/) Test**

A local `const` binds its name once and leaves what it holds as writable as TypeScript does.

**[Rule 6.11](https://typeshade.dev/reference/rules/6-11/) Test**

The compiler adds one binding an author did not write for a `console` call, and only when a compile asks for GPU recording (`compile(src, { console: 'gpu' })`): `_console`, a `read_write` storage buffer of `struct _Console { cursor: atomic<u32>, dropped: atomic<u32>, words: array<u32> }`, at group 0, the first binding past the module’s own group-0 bindings, the slot the `_fp64` guard takes by the same rule (the guard, when there is one, comes one past it).

## 7. Expressions and statements

**[Rule 7.1](https://typeshade.dev/reference/rules/7-1/) Test**

An operator, a swizzle, an index, and a call must mean what WGSL’s typing table gives them.

**[Rule 7.2](https://typeshade.dev/reference/rules/7-2/) Test**

Where TypeShade lowers a TypeScript form to a WGSL form, the mapping must be a rule with a recorded divergence; the mappings today are:

**[Rule 7.3](https://typeshade.dev/reference/rules/7-3/) Test**

An empty `switch` case directly above a case with a body is one clause with several selectors (`case 0: case 1:` is WGSL’s `case 0, 1:`); an empty case with no case below it or directly above `default:`, and an empty `default:` with a case after it, must be refused; a case body must not fall through into the body of a case below it.

**[Rule 7.4](https://typeshade.dev/reference/rules/7-4/) Test**

A shift amount the compiler can fold must be in 0 to 31; a divisor the compiler can prove to be zero must be refused where the division is lowered.

**[Rule 7.5](https://typeshade.dev/reference/rules/7-5/) Test**

A `for` loop means what it means in TypeScript: its initializer runs once, its condition (`true` when it has none) is tested before each trip, and its update runs after each trip and at each `continue` (change 0136).

**[Rule 7.6](https://typeshade.dev/reference/rules/7-6/) Test**

A read of a local before it is assigned on every path must be refused ([`TS8075`](https://typeshade.dev/reference/errors/ts8075/)), by TypeScript’s rule for its TS2454; an argument is a read, as TypeScript reads it, and no call assigns the caller’s local (change 0142); every target starts a local declared with no initializer at the zero of its type.

**[Rule 7.7](https://typeshade.dev/reference/rules/7-7/) Test**

`discard` must be written as a bare statement, the identifier alone (`discard`), and may stand in a fragment entry and in a helper no vertex or compute entry can reach.

**[Rule 7.8](https://typeshade.dev/reference/rules/7-8/) Test**

The refusals of surface §28 (a union of two GPU types, a string type, an absent literal outside the positions of [Rule 7.10](https://typeshade.dev/reference/rules/7-10/), a mixed tuple, a rest tuple, `symbol`, an intersection of carriers, `instanceof`, `in`) must apply to expressions as they do to types, each in one sentence.

**[Rule 7.9](https://typeshade.dev/reference/rules/7-9/) Test**

An expression must be evaluated left to right, as TypeScript and WGSL both evaluate it, and a call that writes (its object, a module variable, a storage binding, an atomic location) inside a larger expression must take effect in that order on every target.

**[Rule 7.10](https://typeshade.dev/reference/rules/7-10/) Test**

`T | undefined` and `T | null` are optional values.

## 8. Functions and entry points

**[Rule 8.1](https://typeshade.dev/reference/rules/8-1/) Test**

An entry point is a function declaration at the top of the file or of a namespace, exported or not, with exactly one stage attribute written before the declaration: `@vertex export function vs(…)`, `@fragment …`, or `@compute([x, y?, z?]) …`.

**[Rule 8.2](https://typeshade.dev/reference/rules/8-2/) Test**

A vertex entry must return the position, as a bare `vec4` or as a struct with a `builtin<"position">` field; a fragment entry returns one value at location 0, a struct of render targets, or nothing.

**[Rule 8.3](https://typeshade.dev/reference/rules/8-3/) Test**

A builtin WGSL confines by stage may be used in an entry of a permitted stage, and in a helper that no entry of an excluded stage can reach.

**[Rule 8.4](https://typeshade.dev/reference/rules/8-4/) Test**

A function must not take part in a call cycle, directly or through other functions; the check reads the calls a body writes, and the calls a method call, an accessor and `new` lower to, before any optimisation, so a call in a branch the optimizer would drop is a cycle too.

**[Rule 8.5](https://typeshade.dev/reference/rules/8-5/) Test**

A collective operation (a derivative, an implicit-LOD texture sample, a barrier) must be in uniform control flow.

**[Rule 8.6](https://typeshade.dev/reference/rules/8-6/) Test**

An entry point must not be called from another function, and neither may a kernel function ([Rule 8.22](https://typeshade.dev/reference/rules/8-22/)).

**[Rule 8.7](https://typeshade.dev/reference/rules/8-7/) Test**

`@compute` carries the workgroup size as an array literal of one to three positive whole-number literals, integer module constants or `u32` override names, `x`, `y` and `z`, a missing `y` or `z` being 1, and the default is 64; every default extent reaches reflection and the manifest, and each override name reaches WGSL’s `@workgroup_size`.

**[Rule 8.8](https://typeshade.dev/reference/rules/8-8/) Test**

An object has the identity a JavaScript object has (change 0142).

**[Rule 8.9](https://typeshade.dev/reference/rules/8-9/) Test**

Method dispatch must be static, and a generic function or class must be compiled once per set of type arguments the program uses ([Rule 3.9](https://typeshade.dev/reference/rules/3-9/)).

**[Rule 8.10](https://typeshade.dev/reference/rules/8-10/) Test**

A method that writes its object (assigns to `this` or to a field, a component or an element of it, applies `++` or `--` to one, hands one to a parameter that its function writes ([Rule 8.25](https://typeshade.dev/reference/rules/8-25/)), or calls such a method or reads such a getter on `this`, on a field, a component or an element of it whatever class that field is, or through `super`) must take the object by reference, and may return a value like any other method; a base’s body that a class calls through `super` and that writes its object takes it by reference too, and so does the copy of a method that takes a function ([Rule 8.18](https://typeshade.dev/reference/rules/8-18/)) when a function handed over writes the variable the call is on.

**[Rule 8.11](https://typeshade.dev/reference/rules/8-11/) Test**

A `get` or `set` accessor is a function of the module, `Owner_get_x` or `Owner_set_x`, which takes its object as a method does ([Rules 8.10](https://typeshade.dev/reference/rules/8-10/) and [8.28](https://typeshade.dev/reference/rules/8-28/)); a read of `o.x` must call the getter, and an assignment, a compound assignment, `++` and `--` must call the setter with the new value, the compound forms reading the old one through the getter.

**[Rule 8.12](https://typeshade.dev/reference/rules/8-12/) Test**

A private name `#x` must be emitted without its `#`: a field as the struct member `x`, a method as `Owner_x`, an accessor as `Owner_get_x` and `Owner_set_x`, a static field as `Owner_x`.

**[Rule 8.13](https://typeshade.dev/reference/rules/8-13/) Test**

A static field must be a module constant `Owner_x` when nothing in the program writes it, and a module variable in the per-invocation space ([Rule 6.5](https://typeshade.dev/reference/rules/6-5/)) when something does; a `readonly` static is never written.

**[Rule 8.14](https://typeshade.dev/reference/rules/8-14/) Test**

A constructor’s parameter property (`constructor(public x: f32)`, or `private`, `protected` or `readonly` in place of `public`) is a field of its class, at the constructor’s place among the members, which the constructor assigns from the parameter before the field initializers run.

**[Rule 8.15](https://typeshade.dev/reference/rules/8-15/) Test**

A member declared `private` may be named only inside the body of the class that declares it, and one declared `protected` only inside the bodies of that class and of the classes that extend it, on an object of the naming body’s own class or of one that extends it; a name either rule does not allow must be refused with the remedy.

**[Rule 8.16](https://typeshade.dev/reference/rules/8-16/) Test**

An instance field that holds an arrow function or a function expression is a method of its class under the field’s name: the function’s parameters, return type and body are the method’s, an expression body is the value it returns, and `this` in it is the object, as it is in TypeScript.

**[Rule 8.17](https://typeshade.dev/reference/rules/8-17/) Test**

A local function (a `const` that holds an arrow function or a function expression, or a `function` declaration, written inside a function’s body) is a function of the module named after the body that declares it (surface §14), and it may read and write the variables of the functions around it, as a TypeScript closure does.

**[Rule 8.18](https://typeshade.dev/reference/rules/8-18/) Test**

A function whose parameter has a function type, written out (`f: (x: f32) => f32`) or through a type alias of one, takes a function: a function declared at the top of the file or of a namespace, a method, a static method, a constructor, a field that holds a function ([Rule 8.16](https://typeshade.dev/reference/rules/8-16/)) and a local function ([Rule 8.17](https://typeshade.dev/reference/rules/8-17/)).

**[Rule 8.19](https://typeshade.dev/reference/rules/8-19/) Test**

A function that writes no return type returns what its body does, as TypeScript infers it: a function of the file or of a namespace, a local function ([Rule 8.17](https://typeshade.dev/reference/rules/8-17/)), each instance of a generic function ([Rule 8.9](https://typeshade.dev/reference/rules/8-9/)) and of a function that takes a function ([Rule 8.18](https://typeshade.dev/reference/rules/8-18/)), a method, a getter and a field that holds a function ([Rule 8.16](https://typeshade.dev/reference/rules/8-16/)) take the type of their first `return` with a value, the `return`s after it are typed against that type as against a written one, and one with no such `return` returns nothing.

**[Rule 8.20](https://typeshade.dev/reference/rules/8-20/) Test**

A function a host file can call through an import of its module is an exported function that is not an entry point, is not generic, takes no function, has a host value ([Rule 8.21](https://typeshade.dev/reference/rules/8-21/)) for each parameter and for its result, and reaches, through the calls of its body, no binding, no workgroup variable and no builtin that a host call does not run yet (a derivative or a barrier: not supported yet on the CPU tier of a host call, [Rule 8.24](https://typeshade.dev/reference/rules/8-24/), [Rule 11.7](https://typeshade.dev/reference/rules/11-7/); an atomic and an implicit-LOD texture sample reach a binding or a workgroup variable, which the first two clauses already exclude).

**[Rule 8.21](https://typeshade.dev/reference/rules/8-21/) Test**

A host call passes and returns host values: an `f32`, `f64`, `i32` or `u32` is a `number`, a `bool` a `boolean`, a vector a tuple of its components, `readonly` in the host view as an argument and as a result (change 0116, decision D1), a matrix a flat column-major array of its components, an `array<T, N>` an array of `N` host values of `T`, a struct an object of its fields, an instance of its exported class among them (change 0109), an `enum` member its number, and a value of a key type ([Rule 4.1](https://typeshade.dev/reference/rules/4-1/)), as a parameter or a result, one of its members as a string, which the call refuses when it is none of them, and a `Record` over a key type, as a parameter or a result, an object with one property for each member, which the call refuses when one is missing or another is there (change 0081); in a binding and in an array with no size, a key is its id, a number, and a `Record` the array of its values in id order.

**[Rule 8.22](https://typeshade.dev/reference/rules/8-22/) Test**

A kernel function is an exported function that is not an entry point, a function declaration, and takes at least one array with no size (`array<T>`) or one 2D storage texture (`texture_storage_2d<F, A>`, change 0077), or returns an array with no size that its body makes ([Rule 8.23](https://typeshade.dev/reference/rules/8-23/), change 0114, S5); a sampled texture alone does not make one, so an exported helper that reads one stays a helper an entry calls; its candidate loops are the `for` and `for…of` statements at the top level of its body, and no other loop is ever a candidate.

**[Rule 8.23](https://typeshade.dev/reference/rules/8-23/) Test**

A kernel function’s parameter of an array with no size is the caller’s array (change 0142): the body reads its elements and its `.length`, writes its elements in place, and cannot assign it whole ([`TS8018`](https://typeshade.dev/reference/errors/ts8018/)).

**[Rule 8.24](https://typeshade.dev/reference/rules/8-24/) Test**

An exported `@compute` entry is called from host code as `entry(bindings, workgroups)`.

**[Rule 8.25](https://typeshade.dev/reference/rules/8-25/) Test**

An object parameter that its function writes is the caller’s object, and the call passes the variable itself, unmarked: reading the parameter reads that object, and assigning to a field or an element of it writes it, for the call (change 0142).

**[Rule 8.28](https://typeshade.dev/reference/rules/8-28/) Test**

A call must not copy a struct or a fixed-size array that its callee only reads when the argument is a place: a `let` local, a module variable, an element or a field of a binding, a reference the caller holds (a parameter it writes through or reads in place), or a field or an element of one of those.

**[Rule 8.29](https://typeshade.dev/reference/rules/8-29/) Test**

A class is its struct and its functions.

## 9. Built-in functions and the TypeShade extensions

**[Rule 9.1](https://typeshade.dev/reference/rules/9-1/) Test**

Every builtin id the compiler can emit must be classified as portable (`PORTABLE_INTRINSICS`) or as a row of the `INTRINSICS` registry; an unclassified id must not reach a backend.

**[Rule 9.2](https://typeshade.dev/reference/rules/9-2/) Test**

A builtin’s signature must be WGSL’s, checked at the call.

**[Rule 9.3](https://typeshade.dev/reference/rules/9-3/) Test**

A WGSL builtin GLSL ES 3.00 has no spelling for must be behind a capability, and the GLSL emit must fail closed on it.

**[Rule 9.4](https://typeshade.dev/reference/rules/9-4/) Test**

A `Math` member must lower to the WGSL builtin of the same meaning, and so must its free-function spelling where WGSL has a builtin of that name (`sqrt`, `max`; [Rule 9.9](https://typeshade.dev/reference/rules/9-9/) removed `pow`); a `Math` member with no WGSL builtin must be expanded into WGSL arithmetic, stays an ECMAScript name and has no free spelling; `Math.fround(x)` is `f32(x)`.

**[Rule 9.5](https://typeshade.dev/reference/rules/9-5/) Test**

A function the file declares or imports ([Rule 3.9](https://typeshade.dev/reference/rules/3-9/)) must win over every builtin function of its name, whether a WGSL built-in function, the free spelling of a `Math` member ([Rule 9.4](https://typeshade.dev/reference/rules/9-4/)) or a TypeShade extension that is a function (§9.3), as a module-scope declaration hides a predeclared function in WGSL and as TypeScript’s lookup finds the file’s own name before a global: a call of the name reaches the declaration in the constant folder, on the CPU, on WebGPU and on WebGL2, and a function handed by its name to a fold, to an array method or to a function that takes one follows the call.

**[Rule 9.6](https://typeshade.dev/reference/rules/9-6/) Test**

The author-facing names of source (c) must be exactly the rows below; the table is shrink-only, and a name may join it only by [Rule 13.6](https://typeshade.dev/reference/rules/13-6/).

**[Rule 9.7](https://typeshade.dev/reference/rules/9-7/) Test**

A name must be added to the table in this order and in no other: the rationale is written into this section (and into [Rule 4.4](https://typeshade.dev/reference/rules/4-4/)’s family for an `f64` type), the row is added to `TYPESHADE_EXTENSIONS` with the same reason, the surface document gains or extends a `§`, and `CHANGELOG.md` gains an entry under `[Unreleased]`.

**[Rule 9.8](https://typeshade.dev/reference/rules/9-8/) Test**

A row, a declaration, a signature, an overload, or a member must never be added for a compiler-internal name (§2.1), under its own id, under an allowed id, or under a new spelling that denotes the same thing.

**[Rule 9.9](https://typeshade.dev/reference/rules/9-9/) Test**

A WGSL built-in function, an overload of one, or a §9.3 name must not be authorable when an ECMAScript spelling the compiler supports carries every case it accepts with the same meaning ([Rule 1.4](https://typeshade.dev/reference/rules/1-4/)).

## 10. Extensions and capabilities

**[Rule 10.1](https://typeshade.dev/reference/rules/10-1/) Test**

A `"use typeshade"` file must not spell a WGSL `enable` or `requires` statement.

**[Rule 10.2](https://typeshade.dev/reference/rules/10-2/) Test**

The compiler must derive `requiredFeatures` from the module and must report them through `reflect()`, with every implied capability included.

**[Rule 10.3](https://typeshade.dev/reference/rules/10-3/) Test**

A GLSL ES 3.00 emit that lacks a capability’s row must fail closed with the target sentence, which opens `backend 'glsl-es300' cannot emit this module` and ends `missing capabilities: <ids>`; on a module with a render entry that is a [`TS8015`](https://typeshade.dev/reference/errors/ts8015/) warning that leaves `wgsl` in place, and on a compute-only module it is silence, `glsl` being `undefined`.

**[Rule 10.4](https://typeshade.dev/reference/rules/10-4/) Test**

Every capability must have a witness: a module shape an author can write that uses the feature; a declarable capability with no witness is recorded as such and never advertised as usable.

**[Rule 10.5](https://typeshade.dev/reference/rules/10-5/) Test**

A GLSL lowering of a WGSL-only feature (the family [#130](https://github.com/typeshade/typeshade/issues/130) to [#139](https://github.com/typeshade/typeshade/issues/139): 1d, multisampled, depth read both ways, gather, cube array, storage texture, read-write storage, atomics, and barriers) is deferred by the maintainer, and must not be written until the deferral is lifted.

## 11. Targets and the oracle

**[Rule 11.1](https://typeshade.dev/reference/rules/11-1/) Test**

There must be one IR, and the WGSL writer, the GLSL ES 3.00 writer, and the CPU oracle must consume it over one shared tree walk; a new emit feature must go into the shared walk, or the oracle and the GLSL writer drift.

**[Rule 11.2](https://typeshade.dev/reference/rules/11-2/) Test**

A divergence between targets, or between a target and the oracle, must be measured on Tint and on a WebGL2 driver before it is kept, and recorded where the emit is decided: a comment on the `INTRINSICS` row with the measured text, and a row of the determinism report (surface §38) where the results may differ.

**[Rule 11.3](https://typeshade.dev/reference/rules/11-3/) Test**

Every registered example must compile on Tint and, where the module has a GLSL row for each capability it needs, on a WebGL2 driver; an example that is WGSL-only says so with `renderable: false` and a stated reason.

**[Rule 11.4](https://typeshade.dev/reference/rules/11-4/) Test**

An emit golden is a reviewed artifact: a change to `examples/__emit-goldens__/` must be read as a diff and must not be re-baked as a rubber stamp.

**[Rule 11.5](https://typeshade.dev/reference/rules/11-5/) Code only**

Where WGSL fixes a result and GLSL ES 3.00 does not, the oracle must follow WGSL; where a GLSL spelling answers differently on an input WGSL settles, the determinism report must list the operation as `target`.

**[Rule 11.6](https://typeshade.dev/reference/rules/11-6/) Test**

The public API surface (`src/__api__/surface.md`) is generated and must not be edited by hand; an exported name or type may change only with a re-bake.

**[Rule 11.7](https://typeshade.dev/reference/rules/11-7/) Test**

The CPU tier, which runs a host call of a module’s function and, where there is no GPU tier, the invocations of an entry a host calls and the pixels of a fragment entry a host draws ([Rule 8.24](https://typeshade.dev/reference/rules/8-24/)), is the oracle’s generated code (`generateModuleJs`) at `f32` precision, written into the module the bundler reads as module code, with no `new Function`, over the op library alone, `typeshade/runtime/internal`.

**[Rule 11.8](https://typeshade.dev/reference/rules/11-8/) Test**

A kernel function’s call ([Rule 8.21](https://typeshade.dev/reference/rules/8-21/)) runs on the first tier of its owner’s policy that can run it (change 0085).

**[Rule 11.9](https://typeshade.dev/reference/rules/11-9/) Test**

A `console` call computes nothing a shader reads: its arguments must be evaluated once, in order, on every target, and the call then delivers an event, `{ method, args, span, invocation }`.

**[Rule 11.10](https://typeshade.dev/reference/rules/11-10/) Test**

A compiled program’s manifest, what `packModule()` returns and what the default export of a module’s host import is, must be one JSON object that carries its schema (`schema`, 3) and the package version that wrote it (`compiler`); each binding, struct, field, override, entry and vertex or varying name the host uses with its authored name and its emitted name (`emitted`, the WGSL spelling; a binding and an override also carry `emittedGlsl`, the GLSL spelling, which equals `emitted` where the two agree, changes 0070 and 0151); each binding with its group and slot, its resource in `reflect()`’s vocabulary, the stages that reach it, and a buffer’s byte layout with every offset, size and stride under the rule of its space ([Rule 6.8](https://typeshade.dev/reference/rules/6-8/)), the `_fp64` guard the emit adds among them; each entry with its stage, its default workgroup size and optional axis override names, its inputs and outputs with their locations, builtins and interpolation, the bindings it reaches and which it writes, a vertex entry’s vertex buffer, and its line; the overrides and the WebGPU features; with `console`, the recorded variant, its WGSL, its log table and its bindings; with `ir`, the program as portable IR and the package version that wrote it, which emitted again gives every other field byte for byte; and what the WebGL2 tier uses, each full-screen fragment entry’s GLSL ES 3.00 program, block names and texture-sampler pairs, and each storage array’s data texture.

**[Rule 11.11](https://typeshade.dev/reference/rules/11-11/) Test**

The program runtime, `typeshade/runtime`, loads a manifest ([Rule 11.10](https://typeshade.dev/reference/rules/11-10/)) and runs its entries on WebGPU, on the host’s device or on one it requests with the features and the limits the programs need and the limits `createRuntime({ limits })` names (change 0051), and reports the device’s limits as `rt.limits`, or on WebGL2, on the host’s context or on one it makes, in the order `createRuntime({ prefer })` gives and reports as `rt.tier` (change 0054); on WebGL2 it runs a compute entry as the pass program the manifest carries (`gl.computes`) and never builds one, refuses an entry with none with a `TypeError` that gives the reason, and draws with the vertex and fragment programs the manifest carries (`gl.vertices`, `gl.draws`), keeping WebGPU’s conventions: a texture’s row 0 is the top row a pass draws, a fragment’s `position` and a stored depth are WebGPU’s, and a pass into the canvas is turned over onto the screen, and each WebGL2 pass sets its viewport, depth range and blend constant at its start and gives the host’s back at its end; it refuses with a `TypeError` what the tier does not support yet (a multisampled, layered or 3D texture, a storage texture in a draw (a compute entry’s storage texture runs as its pass program, [Rule 10.5](https://typeshade.dev/reference/rules/10-5/) and [Rule 11.8](https://typeshade.dev/reference/rules/11-8/)), targets that blend or mask apart, a depth range other than 0 to 1 under a fragment that writes `frag_depth`, a depth bias on a format other than `depth24plus`, `depth32float` and `depth24plus-stencil8`, a non-zero depth-bias clamp when the context lacks `EXT_polygon_offset_clamp`, a texture bound from the depth attachment of the pass that draws), a fallback for each of these being later work (OD-11), and what only WebGPU has, with no fallback meant (a `GPUCommandEncoder`, a pass’s `GPURenderPassEncoder`); its module closure must hold no file of `src/compiler/` and no package, and its bundle must stay within the size budget `scripts/bundle-budget.json` records.

**[Rule 11.12](https://typeshade.dev/reference/rules/11-12/) Test**

An integer division, remainder and shift, and a float’s conversion to an integer, must give WGSL’s answer on GLSL ES 3.00 for every input WGSL settles: the GLSL writer spells each through a helper that settles the inputs GLSL ES 3.00 leaves undefined, and uses the bare operator only where the operands cannot reach one.

**[Rule 11.13](https://typeshade.dev/reference/rules/11-13/) Test**

A fuse scope, `fuse(body)` from `typeshade/fuse` (change 0058), runs the kernel calls ([Rule 8.21](https://typeshade.dev/reference/rules/8-21/)) its body makes as one plan, and must give every array they write, and every result, the bits the same calls give run apart ([Rule 11.8](https://typeshade.dev/reference/rules/11-8/)).

**[Rule 11.14](https://typeshade.dev/reference/rules/11-14/) Test**

Every capability of WebGPU and of WebGL2, as the sources of Appendix C enumerate them, must have exactly one status per target in the coverage table: `typed`, `raw`, `refused`, `planned`, `gap` or `n/a`.

**[Rule 11.15](https://typeshade.dev/reference/rules/11-15/) Test**

A test must fail when a member of a source has no row, and when a row names a member that no source has.

**[Rule 11.16](https://typeshade.dev/reference/rules/11-16/) Test**

A capability that only WebGL2 has must enter the surface only as a row of §9.3 (an author-facing name) or as a capability of §10 (a host feature a module declares or derives); it must not become a language construct, a built-in value or a type by another route.

**[Rule 11.17](https://typeshade.dev/reference/rules/11-17/) Test**

A `raw` row must name one documented escape hatch, and the escape hatches are exactly these: `Frame.encoder`, `RenderPass.raw`, `Texture.texture`, `Sampler.sampler`, `Runtime.device`, `createRuntime({ device })`, a host `GPUBuffer`, `GPUTexture`, `GPUTextureView`, `GPUSampler`, `WebGLBuffer`, `WebGLTexture` or `WebGLSampler` passed as a binding, a target or a geometry buffer, `RenderPipeline.draw(pass, …)` and `ComputePipeline.dispatch(target, …)` into the host’s own encoders, and `Runtime.submit(…encoders)`.

**[Rule 11.18](https://typeshade.dev/reference/rules/11-18/) Test**

A `typed` row must name the test that verifies the capability on each target where it is `typed`; the test must read both halves where the capability is a language spelling ([Rule 12.7](https://typeshade.dev/reference/rules/12-7/)).

**[Rule 11.19](https://typeshade.dev/reference/rules/11-19/) Test**

The package root exports no IR builder.

**[Rule 11.20](https://typeshade.dev/reference/rules/11-20/) Test**

A common module is a shader package the compiler repository publishes under a `typeshade/<name>` subpath: `typeshade/algorithms` and `typeshade/random` (change 0072).

**[Rule 11.21](https://typeshade.dev/reference/rules/11-21/) Test**

On the CPU oracle and on GLSL ES 3.00, a subgroup is one invocation: `subgroup_size` is 1, `subgroup_invocation_id` is 0, `subgroup_id` is `local_invocation_index` and `num_subgroups` is the workgroup’s invocation count; each subgroup built-in function must give the value it gives a subgroup of one lane (surface §77’s table).

**[Rule 11.22](https://typeshade.dev/reference/rules/11-22/) Test**

No source construct opts a function into a floating-point rewrite; change 0131 removed the `numerics` contract of change 0107.

**[Rule 11.23](https://typeshade.dev/reference/rules/11-23/) Test**

A compiled program may carry more than one WGSL text of a compute entry (a variant).

**[Rule 11.27](https://typeshade.dev/reference/rules/11-27/) 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.

## 12. Diagnostics

**[Rule 12.1](https://typeshade.dev/reference/rules/12-1/) Test**

A diagnostic must name the offending thing and the remedy in at most two sentences: the first states the mistake, and the second, when there is one, states the remedy or the reason.

**[Rule 12.2](https://typeshade.dev/reference/rules/12-2/) Review**

A code must be `TS8` followed by a sequential number in the order codes were added, or a number from a block handed to a parallel branch ([Rule 3.7](https://typeshade.dev/reference/rules/3-7/)), whose unused numbers stay a gap.

**[Rule 12.3](https://typeshade.dev/reference/rules/12-3/) Test**

Severity must follow the target’s role: a program WGSL refuses must be an error; a shortfall of GLSL ES 3.00 on a module with a render entry must be a warning that leaves `wgsl` in place; a compute-only module’s GLSL shortfall must be no diagnostic at all.

**[Rule 12.4](https://typeshade.dev/reference/rules/12-4/) Test**

One mistake reads as one diagnostic; a refusal must not be followed by further diagnostics about the same mistake.

**[Rule 12.5](https://typeshade.dev/reference/rules/12-5/) Test**

The message text is part of the contract: a test that pins a refusal must assert the code and the text, and a change to the text is a change to the surface.

**[Rule 12.6](https://typeshade.dev/reference/rules/12-6/) Test**

A requirement the front end can check must be checked at the front end, in the author’s words, and not left to Tint or a driver.

**[Rule 12.7](https://typeshade.dev/reference/rules/12-7/) Test**

The language service and the compiler must name one vocabulary: the ambient library’s declarations are derived from the compiler’s own tables and never retyped, a builtin’s overloads from Tint’s `core.def` through the TypeShade overlay, and a program the compiler accepts must draw no error in the editor or in `tshc check`.

## 13. Change control

**[Rule 13.1](https://typeshade.dev/reference/rules/13-1/) Review**

An issue or pull request that changes what an author can write must cite the rule of this document it rests on.

**[Rule 13.2](https://typeshade.dev/reference/rules/13-2/) Review**

A change the rules do not cover must change the rules first: the rule is written or amended in this document, in the same pull request, before the surface moves.

**[Rule 13.3](https://typeshade.dev/reference/rules/13-3/) Test**

A design that a target might refuse must be measured on Tint, on a WebGL2 driver, or on a device before it is kept, and the measured text must be recorded in the plan and in the code comment.

**[Rule 13.4](https://typeshade.dev/reference/rules/13-4/) Test**

Every change must pass the mechanical gates: `bun run build`; `bun run test`, with `surface-names.test.ts`, `intrinsic-coverage.test.ts`, `capability-reachability.test.ts`, `determinism.test.ts`, `api-surface.test.ts`, `emit-reflection-conformance.test.ts`, and the emit goldens among them; `bun run gate:compile`; the docs snippet test `src/compiler/ts/doc-snippets.test.ts`, which compiles every snippet of the surface document.

**[Rule 13.5](https://typeshade.dev/reference/rules/13-5/) Review**

A hot-spot file must be edited only after reading what the branch already did to it, and a claim of a `§` number, a `TS80xx` code, or an `INTRINSICS` row must be made in the issue before the branch is opened.

**[Rule 13.6](https://typeshade.dev/reference/rules/13-6/) Test**

A new author-facing name must be added only by its source: a WGSL name by citing the specification section that declares it, and an ECMAScript name by citing the section of ECMA-262, or the declaration of TypeScript’s standard library, that defines it.

**[Rule 13.7](https://typeshade.dev/reference/rules/13-7/) Test**

The extension table must shrink when WGSL grows a builtin or a type a row was standing in for, or when a spelling is withdrawn; the row must be deleted, the surface document must say so, and the CHANGELOG must record it.

**[Rule 13.8](https://typeshade.dev/reference/rules/13-8/) Test**

Every change to the surface must carry a CHANGELOG entry under `[Unreleased]` in the house style (a bold lead naming the feature and the § or roadmap item, then what an author can now write, what each target emits, what is refused and how, and what was measured) and a surface `§` whose snippets compile.

**[Rule 13.9](https://typeshade.dev/reference/rules/13-9/) Test**

An official release must follow Semantic Versioning 2.0.0, and before `1.0.0` the minor is the breaking position: a breaking change must ship only in a new `0.N.0`, and a `0.N.P` must only fix and add.

**[Rule 13.10](https://typeshade.dev/reference/rules/13-10/) Test**

A change that keeps a program compiling and makes it compute something other than what an official release ([Rule 13.9](https://typeshade.dev/reference/rules/13-9/)) computed for it must ship in two steps, and the second must come no earlier than the next breaking release after the first step’s official release was published (the next minor before `1.0.0`, the next major after it).
