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

# Rule 8.4

Chapter 8, Functions and entry points 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.

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

## Rationale

WGSL has no call stack, and matching the optimizer would make the answer depend on constant folding an author cannot predict. A call on a value (`this.g(n)`, `o.m()`), a read or write of an accessor and `new` name no function in their text, so the check reads them as lowered; before that, a cycle through a method reached Tint.

## Derives from

[Restrictions on Functions](https://gpuweb.github.io/gpuweb/wgsl/#function-restriction) (“recursion is disallowed because cycles are not permitted among any kinds of declarations”); surface §4.

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

`TS8031 RECURSION`, on the call that closes the cycle, naming the whole cycle as the author writes its members (`Recursive call: "N.f" -> "N.g" -> "N.f". WGSL has no call stack, so a function must not take part in a call cycle.`), once for a body a class inherits and once for every instance of a generic function; pinned by `src/compiler/ts/namespace.test.ts`, `src/compiler/ts/default-args.test.ts` and `src/compiler/ts/class-syntax.test.ts`.

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

- [`src/compiler/ts/class-syntax.test.ts:1798`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/class-syntax.test.ts#L1798)
- [`src/compiler/ts/default-args.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/default-args.test.ts#L1)
- [`src/compiler/ts/namespace.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/namespace.test.ts#L1)
- [`src/compiler/ts/recursion.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/recursion.test.ts#L1)

## Explained in

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

- [§4 What we will not do](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#4-what-we-will-not-do)
- [§26 Classes with methods, a constructor and static functions](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#26-classes-with-methods-a-constructor-and-static-functions)
- [§68 Importing another shader module](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#68-importing-another-shader-module)

## Error codes that enforce it

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

**[`TS8031`](https://typeshade.dev/reference/errors/ts8031/) `RECURSION`**

A call cycle: a function that reaches itself, directly or through other functions. WGSL has no call stack, so the compiler refuses the cycle before a target sees it.

## See also

- [Rule 8.3](https://typeshade.dev/reference/rules/8-3/) Test
- [Rule 8.5](https://typeshade.dev/reference/rules/8-5/) Test
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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