---
title: "FuncDecl: interface in IR, TypeShade API reference"
description: "FuncDecl, an interface in IR. A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (stage set)."
url: https://typeshade.dev/api/funcdecl/
language: en
---

# `FuncDecl`

Interface in IR

A ModuleDecl.funcs entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (stage set).

`import type { FuncDecl } from 'typeshade'`
`import type { FuncDecl } from 'typeshade/core/ir'`

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

## Syntax

```ts
interface FuncDecl {
  readonly name: string;
  readonly params: readonly { name: string; type: ShaderType; builtin?: string; location?: number; interpolate?: string; attr?: string; /** How the function takes this parameter. Absent is by value, which is every parameter * but one that the callee writes through to the caller's own value. `'inout'` says it * does: GLSL ES 3.00 spells that `inout T name`, WGSL a pointer. * * The IR says WHICH parameters are written, not how a target spells it, because the two * targets do not agree on that. GLSL's `inout` is copy-in/copy-out and takes any l-value * argument; WGSL's pointer is a reference and carries the ADDRESS SPACE in its type, so a * function taking `ptr<function, T>` cannot be handed `&buf[i]`. The WGSL backend's own * pass makes one copy of the function per address space its calls use; nothing about * that reaches here, and GLSL emits the one function. */ mode?: 'inout'; }[];
  readonly ret: ShaderType;
  readonly body: readonly Stmt[];
  readonly attrs?: readonly string[];
  readonly stage?: 'vertex' | 'fragment' | 'compute';
  readonly workgroupSize?: number;
  readonly workgroupShape?: WorkgroupShape;
  readonly workgroupSizeOverrides?: readonly [ string | undefined, string | undefined, string | undefined, ];
  readonly portable?: boolean;
  readonly kernel?: boolean;
  readonly retAttr?: string;
  readonly retBuiltin?: string;
  readonly opaque?: boolean;
  readonly span?: SourceSpan;
  readonly nameSpan?: SourceSpan;
  readonly allowEarlyReturn?: boolean;
  readonly lintDisable?: readonly string[];
  readonly [ASSEMBLED_AS]?: string;
}
```

## Description

A `ModuleDecl.funcs` entry: a WGSL/GLSL function, either an ordinary helper or a pipeline entry point (`stage` set). This is the object [`fn`](https://typeshade.dev/api/fn/) builds: the [`FnHandle`](https://typeshade.dev/api/fnhandle/) it returns mixes these fields onto itself, so it is at once a typed callable in other function bodies and, unwrapped, the plain `FuncDecl` that `module({ funcs })` collects. Every backend (WGSL, GLSL, CPU) walks `body` directly.

## Instance properties

**`name` read only `string`**

**`params` read only ``readonly { name: string; type: ShaderType; builtin?: string; location?: number; interpolate?: string; attr?: string; /** How the function takes this parameter. Absent is by value, which is every parameter * but one that the callee writes through to the caller's own value. `'inout'` says it * does: GLSL ES 3.00 spells that `inout T name`, WGSL a pointer. * * The IR says WHICH parameters are written, not how a target spells it, because the two * targets do not agree on that. GLSL's `inout` is copy-in/copy-out and takes any l-value * argument; WGSL's pointer is a reference and carries the ADDRESS SPACE in its type, so a * function taking `ptr<function, T>` cannot be handed `&buf[i]`. The WGSL backend's own * pass makes one copy of the function per address space its calls use; nothing about * that reaches here, and GLSL emits the one function. */ mode?: 'inout'; }[]``**

**`ret` read only `ShaderType`**

**`body` read only `readonly Stmt[]`**

**`attrs` optional read only `readonly string[]`**

Stage and pipeline attributes emitted before `fn`, such as `@compute` or `@workgroup_size(64)`. Empty for ordinary helper functions. This is the emitted spelling; `stage` and `workgroupSize` below are what [`reflect`](https://typeshade.dev/api/reflect/) and the backends read first, with these strings as the fallback for a hand-built `FuncDecl` literal.

**`stage` optional read only `'vertex' | 'fragment' | 'compute'`**

Structured pipeline stage. Set by `fn()`’s `opts.stage`.

**`workgroupSize` optional read only `number`**

Structured workgroup size for a compute stage: the `x` extent.

**`workgroupShape` optional read only `WorkgroupShape`**

The three workgroup extents of a compute stage, present when `y` or `z` is not 1. An absent shape is `[workgroupSize, 1, 1]`; read it through [`workgroupShapeOf`](https://typeshade.dev/api/workgroupshapeof/).

**`workgroupSizeOverrides` optional read only `readonly [ string | undefined, string | undefined, string | undefined, ]`**

Override identifiers that specialize the corresponding workgroup-shape axes. The numeric `workgroupShape` retains each override’s declared default.

**`portable` optional read only `boolean`**

Marks a compute entry as a portable kernel. Set by `fn()`’s `opts.portable`, which rejects it on any other stage with [`SD0110`](https://typeshade.dev/reference/errors/sd0110/). A portable kernel emits on both backends: as a native `@compute` entry on WGSL, and through the [`lowerComputeToFragment`](https://typeshade.dev/api/lowercomputetofragment/) rewrite on GLSL ES 3.00, which runs it as a fragment shader. The kernel must keep to the gather-only shape, where each invocation reads freely and stores exactly once to its own index of the output; any construct outside that shape fails validation with [`SD0111`](https://typeshade.dev/reference/errors/sd0111/) on every emit, on both backends.

Structured only, with no `attrs` spelling: `portable` is not a WGSL attribute, so declaring it changes nothing in the emitted source.

**`kernel` optional read only `boolean`**

Marks a kernel function ([Rule 8.22](https://typeshade.dev/reference/rules/8-22/)): an exported function, not an entry, that takes an array with no size. It runs on the host’s side of the call, which dispatches its loops, so the WGSL and GLSL backends leave it out of what they emit, and no function calls it ([Rule 8.6](https://typeshade.dev/reference/rules/8-6/)). Its array parameters are the caller’s storage, passed by reference ([Rule 8.23](https://typeshade.dev/reference/rules/8-23/)).

Structured only, with no `attrs` spelling: it is not a WGSL attribute.

**`retAttr` optional read only `string`**

Return-value attribute for a bare (non-struct) stage output, e.g. a fragment `-> @location(0) vec4<f32>`.

**`retBuiltin` optional read only `string`**

Structured builtin id when `retAttr` came from a `builtin(name, type)` [`FieldSpec`](https://typeshade.dev/api/fieldspec/). The spelling stays in `retAttr`; the id lives here so a backend can check it against its builtin vocabulary without re-parsing the attribute string.

**`opaque` optional read only `boolean`**

Keep this function’s body out of its call sites: the emit optimizer never inlines a call to it. [`fp64Lower`](https://typeshade.dev/api/fp64lower/) sets it on every double-float helper it injects, because those bodies are error-free transformations that are algebraically trivial (`e = b - (s - a)` is 0 in real arithmetic), and flattening them hands the terms to passes and drivers that may legally cancel them.

It is a property of the declaration, so it survives every rename a production emit applies to the function’s name.

Structured only, with no `attrs` spelling (like `portable` above): it is not a WGSL attribute and changes nothing in the emitted source.

**`span` optional read only `SourceSpan`**

Where this function was declared in its authored `"use typeshade"` source: the whole declaration, from the first decorator or the `export` keyword through the closing brace. Absent on an EDSL-authored or pass-synthesised function. Read it with [`sourceSpanOf`](https://typeshade.dev/api/sourcespanof/).

**`nameSpan` optional read only `SourceSpan`**

The span of just this function’s name in its authored source, so a stack frame can highlight the identifier rather than the whole body. Absent whenever `span` is.

**`allowEarlyReturn` optional read only `boolean`**

Documented deviation from the single-exit lint rule: when true, the rule skips this function because it has an intentional early return, such as a guard that skips an expensive loop. Use sparingly, with a comment stating why.

**`lintDisable` optional read only `readonly string[]`**

Documented lint deviations: rule ids whose diagnostics are suppressed for this function (the general form of `allowEarlyReturn`). Use sparingly, with a comment stating why.

## See also

- [`fn`](https://typeshade.dev/api/fn/)
- [`FnHandle`](https://typeshade.dev/api/fnhandle/)
- [`reflect`](https://typeshade.dev/api/reflect/)
- [`workgroupShapeOf`](https://typeshade.dev/api/workgroupshapeof/)
- [`lowerComputeToFragment`](https://typeshade.dev/api/lowercomputetofragment/)
- [`FieldSpec`](https://typeshade.dev/api/fieldspec/)
- [`fp64Lower`](https://typeshade.dev/api/fp64lower/)
- [`sourceSpanOf`](https://typeshade.dev/api/sourcespanof/)
- [`module`](https://typeshade.dev/api/module/)

## Source

[`src/core/ir/nodes.ts`, line 402](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/nodes.ts#L402), at commit af54ddad5
