---
title: "Rule 8.3: Functions and entry points in TypeShade"
description: "Rule 8.3 of the TypeShade language design, in Functions and entry points."
url: https://typeshade.dev/reference/rules/8-3/
language: en
---

# Rule 8.3

Chapter 8, Functions and entry points 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. The derivatives, implicit-LOD sampling, and `discard` may be used in the fragment stage only. Barriers and workgroup memory may be used in the compute stage only. The atomic builtins may be used in the compute and fragment stages, and must not be used in the vertex stage.

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

## Rationale

the stage rule is Tint’s, and the call graph is how a helper inherits it.

## Derives from

- [Derivative Built-in Functions](https://gpuweb.github.io/gpuweb/wgsl/#derivative-builtin-functions) (“must only be used in a fragment shader stage”);
- [Discard Statement](https://gpuweb.github.io/gpuweb/wgsl/#discard-statement);
- [Synchronization Built-in Functions](https://gpuweb.github.io/gpuweb/wgsl/#sync-builtin-functions) (“all synchronization functions must only be used in the compute shader stage”);
- [Address Spaces](https://gpuweb.github.io/gpuweb/wgsl/#address-space) (“variables in the workgroup address space must only be statically accessed in a compute shader stage”);
- [Atomic Built-in Functions](https://gpuweb.github.io/gpuweb/wgsl/#atomic-builtin-functions) (“atomic built-in functions must not be used in a vertex shader stage”, with no other stage restriction);
- surface §10, §24, and §25.

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

- the reachability check in `src/compiler/ts/stage-restrictions.ts` ([`TS8099`](https://typeshade.dev/reference/errors/ts8099/) names the builtin, the helper, and the entry) for the fragment-only builtins;
- [`TS8033`](https://typeshade.dev/reference/errors/ts8033/) for workgroup memory, and [`TS8034`](https://typeshade.dev/reference/errors/ts8034/) for a barrier outside a compute entry (a barrier in a branch is [Rule 8.5](https://typeshade.dev/reference/rules/8-5/)’s [`TS8052`](https://typeshade.dev/reference/errors/ts8052/));
- `TS8099` for an atomic builtin in a `@vertex` entry or in a helper it reaches (`"atomicAdd" is only valid in a fragment or compute shader; "vs" is a vertex entry. WGSL allows an atomic built-in in a fragment or compute stage only.`), pinned by `src/compiler/ts/atomics.test.ts` (`refuses atomicAdd in a vertex entry`).

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

- [`src/compiler/ts/atomics.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/atomics.test.ts#L1)
- [`src/compiler/ts/compute-stage-reachability.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/compute-stage-reachability.test.ts#L1)
- [`src/compiler/ts/lower/function.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/lower/function.ts#L1)
- [`src/compiler/ts/stage-restrictions.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/stage-restrictions.ts#L1)

## Explained in

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

- [§10 Builtins, casts and `discard`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#10-builtins-casts-and-discard)

## Error codes that enforce it

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

**[`TS8033`](https://typeshade.dev/reference/errors/ts8033/) `MODULE_VAR`**

A module variable declared or used where its address space forbids it: a `const` with an address-space wrapper, a `workgroup` variable with an initializer, a type that the space cannot hold (a texture, a runtime-sized array, an atomic in a per-invocation variable), an initializer that is not a constant, or a `workgroup` variable reached from a vertex or fragment entry. Also the retired `perInvocation<T>` wrapper, which a plain top-level `let` replaced.

**[`TS8034`](https://typeshade.dev/reference/errors/ts8034/) `BARRIER_PLACEMENT`**

`workgroupBarrier()` or `storageBarrier()` where a barrier cannot stand: in a vertex or fragment entry, which has no workgroup, or as a value, since a barrier is a statement. A barrier under control flow that the invocations do not share is `UNIFORMITY`.

**[`TS8052`](https://typeshade.dev/reference/errors/ts8052/) `UNIFORMITY`**

A barrier, a `workgroupUniformLoad`, or a derivative or implicit-LOD sample that the compiler's rewrite cannot reach, reached under a condition on a non-uniform value, or after a `return`, `break` or `continue` taken under one ([Rule 8.5](https://typeshade.dev/reference/rules/8-5/)). The message names the value as the author wrote it and the statement.

**[`TS8099`](https://typeshade.dev/reference/errors/ts8099/) `UNSUPPORTED`**

The catch-all for a diagnostic whose site does not yet deserve its own code. It stays parked at TS8099, past the sequential range.

## See also

- [Rule 8.2](https://typeshade.dev/reference/rules/8-2/) Test
- [Rule 8.4](https://typeshade.dev/reference/rules/8-4/) Test
- [Rule 8.5](https://typeshade.dev/reference/rules/8-5/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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