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) for each parameter and for its result, and reaches, through the calls of its body, no binding, no workgroup variable and no builtin only a GPU computes (a derivative, a barrier, an atomic, an implicit-LOD texture sample).
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) 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 an exported struct is a type of it, as is a struct another file declares where an export’s signature names it; what a module re-exports from a shader file it imports (Rule 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), which has no device, so what it reaches must be computable there with nothing a host call does not pass; a generic function and a function that takes a function exist only as the copies the module’s own calls make (Rules 8.9 and 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 exports and the lowering’s symbol table.
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
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; 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 files that verify it at commit 26de7be8, each at the first line that names the rule:
Explained in
The sections of the surface document that explain this rule, at commit 26de7be8:
See also
Source
The rule at commit 26de7be8:
docs/language-design.md:833(the design document)reqs/rules/RULE-0820.md(its traceability item)