---
title: "CompileResult: interface in Authoring, TypeShade API"
description: "CompileResult, an interface in Authoring. What compile() returns. The builder a shader is written with: modules, functions, variables and control flow."
url: https://typeshade.dev/api/compileresult/
language: en
---

# `CompileResult`

Interface in Authoring

What compile() returns.

`import type { CompileResult } from 'typeshade'`

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

## Syntax

```ts
interface CompileResult {
  readonly diagnostics: readonly TsCompilerDiagnostic[];
  readonly module: ModuleDecl;
  readonly wgsl?: string;
  readonly glsl?: { readonly vertex: string; readonly fragment: string };
  readonly determinism: readonly DeterminismEntry[];
  readonly eval: (name: string, args?: readonly unknown[]) => unknown;
  readonly console?: ConsoleLog;
}
```

## Description

The one rule behind every optional field: shader text and a runnable oracle exist only for a program that compiled with no error diagnostic. A caller that reads `wgsl` without checking `diagnostics` gets `undefined`, never text for a program that did not compile.

## Instance properties

**`diagnostics` read only `readonly TsCompilerDiagnostic[]`**

Every diagnostic the front end and the backends produced, in the order they were found. A `"use typeshade"`-less file has exactly one, [`TS8001`](https://typeshade.dev/reference/errors/ts8001/) (`MISSING_DIRECTIVE`); a parse error has only [`TS8030`](https://typeshade.dev/reference/errors/ts8030/) (`SYNTAX`) entries; a backend that threw on a program the front end accepted adds one [`TS8015`](https://typeshade.dev/reference/errors/ts8015/) (`BACKEND`) entry anchored on the file’s first statement: an `error` when the WGSL emitter threw, a `warning` when only the GLSL emitter threw on a vertex+fragment module (a binding whose GLSL lowering is not supported yet, [Rule 10.5](https://typeshade.dev/reference/rules/10-5/)), and one `warning` for each compute entry of such a module that has no WebGL2 pass program. A program with no `error` entry compiled.

**`module` read only `ModuleDecl`**

The lowered IR module: the consts, structs, bindings and functions the front end built. Always present. When `diagnostics` has an error the module is partial (the front end stops lowering a declaration at its first error and may drop it), so it is for inspection and diagnostics tooling, not for emitting.

**`wgsl` optional read only `string`**

The module’s WGSL. `undefined` when any diagnostic has category `error`, including a `BACKEND` error from a WGSL emitter that threw. Present otherwise, even for a module with no functions (a file of consts or structs emits their declarations), and kept when only the GLSL emitter failed: the WGSL is the program, GLSL a second target of it.

**`glsl` optional read only `{ readonly vertex: string; readonly fragment: string }`**

The module’s GLSL ES 3.00 vertex and fragment programs. Present when no diagnostic has category `error` and the GLSL emitter took the module; a module with only one render stage still gets both programs (the missing stage is a header-only program). A compute entry beside the render entries is not in them: it runs on WebGL2 as its pass program (change 0054), and the programs hold what the render entries reach. A module the GLSL backend refuses gets `undefined` here while `wgsl` is still present: silently for a compute-only module, which has no vertex or fragment program ([Rule 11.8](https://typeshade.dev/reference/rules/11-8/), [Rule 11.11](https://typeshade.dev/reference/rules/11-11/)), and with the throw recorded as a `BACKEND` warning for a module with a `@vertex` or `@fragment` entry.

**`determinism` read only `readonly DeterminismEntry[]`**

The operations in `module` whose result may differ by driver: a builtin WGSL §15.7.4 gives a ULP or absolute bound (`sin`, `exp`, `atan2`, `/`), one inherited from a formula the driver may reassociate or fuse (`pow`, `mix`, `fma`, `fract`, the matrix products), a derivative, a filtered texture read or gather, an operation the GLSL ES 3.00 spelling may answer differently (`ldexp`, the `pack` builtins), and every emulated `f64` arithmetic operator and bounded builtin, each with the spec’s bound in words, its count and where it occurs. Empty when every operation has one answer, so a GPU result and the CPU oracle can differ only by the oracle’s own rounding. Computed on the front end’s IR even when `diagnostics` has an error, since a partial module still says what it uses. See [`determinismReport`](https://typeshade.dev/api/determinismreport/).

**`eval` read only `(name: string, args?: readonly unknown[]) => unknown`**

Run one function of the module on the CPU oracle: `eval('fs')` calls the fragment entry with no arguments, `eval('add', [1, 2])` a helper with two. When `diagnostics` has an error, every call throws an `Error` naming the first error diagnostic (file, line and message), so a host that ignores `diagnostics` cannot run a broken shader on the oracle. It also throws for a function name the module does not have.

**`console` optional read only `ConsoleLog`**

Where the WGSL records its `console` calls and what each entry of the buffer means, under `console: 'gpu'`: the slot of the `_console` storage buffer and the site table [`decodeConsole`](https://typeshade.dev/api/decodeconsole/) reads. `undefined` when the option is `'cpu'`, when the module did not compile, or when no call is recorded. Surface §66.

## See also

- [`determinismReport`](https://typeshade.dev/api/determinismreport/)
- [`decodeConsole`](https://typeshade.dev/api/decodeconsole/)

## Source

[`src/compiler/ts/compile.ts`, line 26](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/compile.ts#L26), at commit af54ddad5
