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

# Rule 8.20

Chapter 8, Functions and entry points 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). A parameter whose default reads a binding, an `override` or a module variable, or calls a function, stays required in the host call until a host call fills it (Rule 8.21, change 0164). An exported `@compute` entry is callable too, and a full-screen `@fragment` entry draws into a canvas, as Rule 8.24 says; a kernel function ([Rule 8.22](https://typeshade.dev/reference/rules/8-22/)) is callable, asynchronously, as this rule’s last paragraph says; a vertex entry is not callable yet. An exported constant and an `enum` are values of the host face, and so is an exported class (change 0109): the view declares it as a class, `abstract` where it is, and with its `extends` where the class above it is exported as a class too, and the module exports a class of its name, which `new` builds on the CPU tier and whose constructor, methods, accessors, static functions and fields that hold a function ([Rule 8.16](https://typeshade.dev/reference/rules/8-16/)) run there; this rule’s conditions admit each of those members as they admit a function, and one that fails one is declared `never` in the class with the reason, the class staying a value (decision D3). An exported `interface` or `type` is a type of the host face, as is a struct another file declares where an export’s signature names it, and so is a class with a field that has no host value (Rule 8.21), with the reason (decision D4); a generic class is declared `never`; what a module re-exports from a shader file it imports ([Rule 3.9](https://typeshade.dev/reference/rules/3-9/)) is one of its exports; every other export is declared `never` in the host view, with the reason and the work that adds it, so a call of one is a type error at the host’s own line.

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

## Rationale

a host call runs on the CPU tier ([Rule 11.7](https://typeshade.dev/reference/rules/11-7/)). A function that reaches a binding, a workgroup variable or a builtin that a host call does not run yet is not supported yet as a host call, and the host face lists what the function reaches as the reason; a generic function and a function that takes a function exist only as the copies the module’s own calls make ([Rules 8.9](https://typeshade.dev/reference/rules/8-9/) and [8.18](https://typeshade.dev/reference/rules/8-18/)), and a host call names no such copy. The IR does not keep the source’s export list (a generic function is its instances, a method is `P_len`, an enum is its member constants), so the host face is read off the source’s `export`s and the lowering’s symbol table. A class’s constructor and members are functions of the module (`P_new`, `P_len`), so each is admitted as a function is, and a class that extends another runs the functions lowered for it, its inherited bodies among them, so a call on an instance dispatches as it does in TypeScript (Rule 8.9). An export the host cannot use is still declared, as `never`, because an import of a name the view leaves out would be `any` in a host program that does not check it, and a crash at run time.

## Derives from

`docs/roadmap.md` item 16 (“The run layer has no import”); change `0009` in `changes/`; change `0109` (an exported class); [Rule 8.9](https://typeshade.dev/reference/rules/8-9/); [Rule 8.16](https://typeshade.dev/reference/rules/8-16/); [Rule 8.18](https://typeshade.dev/reference/rules/8-18/).

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

`hostFace` in `src/compiler/ts/host-face.ts`, which computes the callable set and the reason for each other export, and each exported class’s members with the reason for each it refuses (`classFace`); pinned by `src/compiler/ts/host-face.test.ts`, one case per exclusion, and by its host programs type-checked against the view, in which a call of an export declared `never` is TS2349; the class by `src/compiler/ts/host-class.test.ts`, which holds the view, `new`, each kind of member, each refusal and a host program type-checked against the view (change 0109), and by the import journey, which builds instances with `new` and calls their methods on the CPU tier from the packed tarball.

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

- [`src/compiler/ts/host-class.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-class.test.ts#L1)
- [`src/compiler/ts/host-face-cpu-tier.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-face-cpu-tier.test.ts#L1)
- [`src/compiler/ts/host-face-default-param.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-face-default-param.test.ts#L1)
- [`src/compiler/ts/host-face.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-face.test.ts#L1)
- [`src/compiler/ts/host-face.ts:81`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-face.ts#L81)

## Explained in

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

- [§64 Calling a module from host code](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#64-calling-a-module-from-host-code)

## See also

- [Rule 8.19](https://typeshade.dev/reference/rules/8-19/) Test
- [Rule 8.21](https://typeshade.dev/reference/rules/8-21/) Test
- [Rule 3.9](https://typeshade.dev/reference/rules/3-9/)
- [Rule 8.9](https://typeshade.dev/reference/rules/8-9/)
- [Rule 8.16](https://typeshade.dev/reference/rules/8-16/)
- [Rule 8.18](https://typeshade.dev/reference/rules/8-18/)
- [Rule 8.22](https://typeshade.dev/reference/rules/8-22/)
- [Rule 8.24](https://typeshade.dev/reference/rules/8-24/)
- [Rule 11.7](https://typeshade.dev/reference/rules/11-7/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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