---
title: "FuseScope: interface in Runtime, TypeShade API reference"
description: "FuseScope, an interface in Runtime. What the body of a fuse call receives: the scope that records the kernel calls the body makes…"
url: https://typeshade.dev/api/fusescope/
language: en
---

# `FuseScope`

Interface in Runtime

What the body of a fuse call receives: the scope that records the kernel calls the body makes, and makes the scratch arrays they share.

`import type { FuseScope } from 'typeshade/fuse'`

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

## Syntax

```ts
interface FuseScope {
  readonly recorded: number;
  scratch(length: number, element?: 'f32'): ScratchBuffer<'f32'>;
  scratch(length: number, element: 'i32'): ScratchBuffer<'i32'>;
  scratch(length: number, element: 'u32'): ScratchBuffer<'u32'>;
  scratch(length: number, element: 'vec4f'): ScratchBuffer<'vec4f'>;
}
```

## Instance properties

**`recorded` read only `number`**

How many kernel calls the body has made so far. The scope has recorded them and has not run them: they run when the body returns.

## Instance methods

**`scratch` `(length: number, element?: 'f32'): ScratchBuffer<'f32'>`**

Make a scratch array: a handle for an intermediate between the calls of the body, which the host never reads. A kernel call in the body takes it where it takes an `array<f32>`, `array<i32>`, `array<u32>` or `array<vec4f>`, as the `element` says. It holds zeros when the plan starts, as a new buffer does. A `'vec4f'` array holds `length` vectors, so `4 × length` numbers. It is a `Buffer` (change 0138, Amendment A10, slice 1): a `Buffer<vec4f>` for `'vec4f'`, whose `length` counts vectors (Amendment A11, Q5).

Where the plan fuses every call that takes it into one dispatch, and each call reaches it at exactly the loop’s counter and never by its length, the fused entry holds it as a local: no device buffer and no host array of `length` elements is made. Otherwise the plan makes a zeroed device buffer for the scope, or on the CPU tier and WebGL2 a zeroed host array when the first call needs it, and frees it when the plan has run, on success and on failure.

`read()`, `set()`, `resize()`, `at()` and `needsUpdate` of the handle are a `TypeError` naming it as scratch, and so is a kernel call that takes it outside the body of the scope that made it or after the plan has run. So is an entry call that takes it, in the body or after the plan has run: only a kernel call of the body may take a scratch array. `dispose()` does nothing: the plan frees the array, so a host that disposes every handle it holds stays correct. A `Buffer` from `array()` keeps its buffer and its write inside a fused group, so the host may read it after the scope.

**`scratch` `(length: number, element: 'i32'): ScratchBuffer<'i32'>`**

**`scratch` `(length: number, element: 'u32'): ScratchBuffer<'u32'>`**

**`scratch` `(length: number, element: 'vec4f'): ScratchBuffer<'vec4f'>`**

## Source

[`src/core/fuse-plan.ts`, line 85](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/fuse-plan.ts#L85), at commit af54ddad5
