---
title: "Rule 8.29: Functions and entry points in TypeShade"
description: "Rule 8.29 of the TypeShade language design, in Functions and entry points. A class is its struct and its functions."
url: https://typeshade.dev/reference/rules/8-29/
language: en
---

# Rule 8.29

Chapter 8, Functions and entry points Test

A class is its struct and its functions. Every rule that applies to a struct applies to the class’s fields, and every rule that applies to a function applies to its constructor, its methods, its accessors and its static functions, in every place a struct or a function can be: a binding, a local, a workgroup variable, a kernel function’s array, a `Buffer`, the host face, the CPU tier, the oracle, the host view, reflection and a package. A method that changes its object ([Rule 8.10](https://typeshade.dev/reference/rules/8-10/)) is, at a call, a write to the object it is called on, as an argument of a parameter that its function writes is ([Rule 8.25](https://typeshade.dev/reference/rules/8-25/)), for the proof of [Rule 8.22](https://typeshade.dev/reference/rules/8-22/) and for the facts of [Rule 11.13](https://typeshade.dev/reference/rules/11-13/). Where a place admits a function under a condition ([Rule 8.20](https://typeshade.dev/reference/rules/8-20/)), it admits a method under the same condition and refuses it with the same reason. Construction is a call of the constructor wherever it happens.

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

## Rationale

the compiler lowers a class to a struct and to functions (surface §26): `new P(…)` is `P_new(…)` and nothing is allocated, a method is a function over its object, and a method that changes its object takes it by reference, as a parameter that its function writes is, by the model of change 0040. So a class written once means one thing wherever it stands, and a library whose units are classes rests on that; this rule says so, and the class arm holds it, as [Rule 11.20](https://typeshade.dev/reference/rules/11-20/) is held for the common modules. The rule states no symmetry it cannot keep. A method that reaches a binding, a workgroup variable or a builtin that a host call does not run yet has no host call yet, and the host view says so with the reason ([Rule 8.20](https://typeshade.dev/reference/rules/8-20/)). A host call of a method runs on the CPU tier and never dispatches (proposal 0109). A read of a `Buffer` is asynchronous ([Rule 11.8](https://typeshade.dev/reference/rules/11-8/)).

## Derives from

surface §26; changes `0040` and `0110` in `changes/`; proposal `0109` in `changes/`; [Rule 8.10](https://typeshade.dev/reference/rules/8-10/); [Rule 8.20](https://typeshade.dev/reference/rules/8-20/); [Rule 8.25](https://typeshade.dev/reference/rules/8-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 class arm of the differential gate, `scripts/class-arm.ts`, which `bun run gate:differential` runs: for each exported class of the `.shade.ts` examples and of `journeys/class-twins/` it writes a twin module that imports the class, and holds each member a host could call, built and called as an entry’s local and as a kernel function’s element, on WebGPU, WebGL2, the CPU tier and the oracle, and as a host calls it on the host class of change 0109, to the `f32` oracle’s own constructor and member function, bit for bit or within the envelope of a determinism row; a member the host face refuses is listed with the face’s reason, and the host class must refuse it with that reason; pinned for the proof by `src/compiler/ts/kernel-loops.test.ts` and for the facts by `src/core/fuse-plan.test.ts`, each form (a method that changes its object, one that reads it, a static function, and a method that hands a field to a parameter that its function writes) written through a member and inline, the proof’s verdict and the planner’s groups, dispatches and reasons the same.

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

- [`scripts/class-arm.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/class-arm.ts#L1)
- [`src/compiler/ts/abstract-super.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/abstract-super.test.ts#L1)
- [`src/compiler/ts/kernel-loops.test.ts:4`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/kernel-loops.test.ts#L4)
- [`src/core/fuse-plan.test.ts:12`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/fuse-plan.test.ts#L12)

## Explained in

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

- [§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)
- [§65 A loop that runs as a kernel](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#65-a-loop-that-runs-as-a-kernel)
- [§71 A chain of kernel calls in one dispatch: `fuse`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#71-a-chain-of-kernel-calls-in-one-dispatch-fuse)

## See also

- [Rule 8.28](https://typeshade.dev/reference/rules/8-28/) Test
- [Rule 9.1](https://typeshade.dev/reference/rules/9-1/) Test
- [Rule 8.10](https://typeshade.dev/reference/rules/8-10/)
- [Rule 8.20](https://typeshade.dev/reference/rules/8-20/)
- [Rule 8.22](https://typeshade.dev/reference/rules/8-22/)
- [Rule 8.25](https://typeshade.dev/reference/rules/8-25/)
- [Rule 11.8](https://typeshade.dev/reference/rules/11-8/)
- [Rule 11.13](https://typeshade.dev/reference/rules/11-13/)
- [Rule 11.20](https://typeshade.dev/reference/rules/11-20/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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