---
title: "Rule 11.8: Targets and the oracle, a TypeShade design rule"
description: "Rule 11.8 of the TypeShade language design, in Targets and the oracle."
url: https://typeshade.dev/reference/rules/11-8/
language: en
---

# Rule 11.8

Chapter 11, Targets and the oracle Test

A kernel function’s call ([Rule 8.21](https://typeshade.dev/reference/rules/8-21/)) runs on the first tier of its owner’s policy that can run it (change 0085). A default-owner call uses `configure({ prefer })`, WebGPU, WebGL2 and the CPU tier being the default order: WebGPU when the function lowers ([Rule 8.22](https://typeshade.dev/reference/rules/8-22/)) and there is a device, the one that `configure({ limits, features })` asks for (change 0051), WebGL2 when every loop writes one array of 4-byte elements (`f32`, `i32`, `u32`) at exactly `i` and every scalar parameter is a number or a vector, each loop one fragment program into an `R32UI` target that starts out holding the array, so an iteration that writes nothing leaves its element, and the CPU tier always; a list of one tier makes that tier required, and a call no tier on the list can run throws an `Error` naming each tier’s reason. A WebGPU loop runs at the workgroup size its function declares (Rule 8.22); WebGL2 and the CPU tier have no workgroup, and their results do not depend on it. A loop that pushes onto an array (change 0078) runs on WebGPU in three dispatches of one submission, count, scan and store, the scan in one workgroup of 256, and the call reads the total back for the function’s result; it runs on the CPU tier when its counting step, which runs the iteration and stores nothing, would change what it computes (a second pushed array, a reduction, a scatter, a texture store, a write it reads back); WebGL2 runs none and says so. An array that two loops push onto, or whose length the stores after the loops read, has a length word on WebGPU (change 0094): the first invocation of each loop’s scan starts the offsets at the length the word holds and writes the new length into it, so the second loop appends after the first and the entry that stores reads the length there; the call makes the word, a zeroed `u32`, when the caller holds none, and such a loop that runs no iteration runs its scan alone, so the length after it is known. A call that passes a held length ([Rule 8.23](https://typeshade.dev/reference/rules/8-23/)) runs a second WGSL text on WebGPU, in which every array a loop pushes onto has its word, bound as the buffer the held length’s `Buffer<u32>` has on the device: the new length stays there, and a call that returns nothing reads nothing back. The CPU tier brings the held length’s host copy up to date, starts the array’s count at it and writes the new length into it. A loop that adds to a `Map` or a `Set` (change 0080) runs on WebGPU as a loop that pushes: each `add` or `set` pushes a record, its key and a `Map`’s value, onto a binding the call makes, `n` times the most an iteration adds long, and the call applies the records to the caller’s collection in order, which gives ECMAScript’s entries and insertion order; a loop that reads a `Map` or a `Set` no loop of the function adds to finds a key by a binary search over the keys the call uploads, sorted by an order word that SameValueZero makes equal for equal keys, with a `Map`’s values beside them; a loop that reads what an earlier loop of the function added searches the collection after the call has applied that loop’s records, and the call uploads it once; a loop that adds after one that reads, two loops that add to one, and an `add` inside a nested loop run the function on the CPU tier, and WebGL2 runs none and says so. A function that stores into its arrays after its loops (Rule 8.22, change 0094) runs the stores on WebGPU in an entry of one invocation, which the call dispatches after the loops’ dispatches, in the plan’s one submission inside a `fuse` scope: the entry combines each variable a loop reduced with what the GPU folded, as the result’s tail does, and stores into the arrays it binds, so a store into a `Buffer` stays on the device, and a call that returns nothing reads nothing back; a function with no loop is that entry alone. WebGL2 draws the loops and then runs the stores on the CPU tier over its host copies, and runs no function with no loop; the CPU tier runs the function as written. A store whose index is past the array’s end is dropped on every tier. Such a function runs on the CPU tier, and says why, when a statement after its loops reaches an array a loop scatters into or reads a texture, and when it takes a `Map` or a `Set`; on a device that allows a stage fewer storage buffers than the entry that stores binds (every array, the partials of each loop that reduces and the length words), the call runs on the next tier and says why. A loop whose range the device holds (Rule 8.22, change 0094) maps on WebGPU from counts that no host reads: the call makes a trip buffer with the usages `STORAGE` and `INDIRECT`, eight `u32`s for each such loop, and frees it once the call has run. Before each such loop, a range entry of one invocation runs the statements before the loop over the bound arrays, computes the start and the trip count as the call computes a range on the host, and writes the start’s bits, the trip count and the workgroup count `[x, y, 1]` of the loop’s entry into the buffer, a count past 65,535 workgroups spilling into `y`; the loop’s entry reads its start and trip count there, from a read-only binding of the same buffer, and the call dispatches it with `dispatchWorkgroupsIndirect` from those counts, so a trip count of 0 dispatches no workgroup. The range entry of a loop runs after the dispatches of the loops before it, in the same submission as its loop, and in the plan’s one submission inside a `fuse` scope; nothing is read back. The entry guards each write by the array’s `arrayLength`, so a write past the end is dropped. WebGL2 computes such a range on the CPU tier over its host copies, brought up to date, once the draws before it have written them, and draws the iterations whose `i` lies inside the array the loop writes; the CPU tier runs the function as written, the guarded writes dropping a write past the end. On a device that allows a stage fewer storage buffers than such a loop’s entries bind (every array, the trip buffer and the length words), the call runs on the next tier and says why. Every tier computes a reduction in the tree order ([Rule 7.2](https://typeshade.dev/reference/rules/7-2/)). Kernel calls run one after another in the order they were made, whether or not the caller awaits them. A call that takes a resource (Rule 8.21, change 0138, R2) is recorded, and it joins that order when the runtime submits it. The runtime submits the recorded calls, in the order they were made, when the current microtask checkpoint ends (change 0138, Amendment A5, Q4). JavaScript cannot see that point, so this version submits them in the next task, and the calls that tasks before that one record join the same submission (deviation D-f of change 0138, open). A `read()` of a `Buffer`, a kernel call, an entry call or a draw with plain data only, and every other use of the order first submit the calls recorded before it (Amendment A5, defaults 2, 4 and 9). Before a recorded call runs, the ranges it copied out are written to the `Buffer`’s device copy: on WebGPU one `writeBuffer` for each dirty range, and on the CPU tier into the tier’s elements. The first call that takes a `Buffer`, and the first after `set(data)` or `resize()`, copy the whole array instead, which uploads whole. A recorded call runs on the device that the owner of a call (below) gives it (change 0138, R3). On WebGL2, when a submission ends, the runtime flushes each context that a recorded kernel call or entry call used. A `read()` of a `Buffer` that such a call wrote waits once on a fence (Amendment A5, default 6). A lost context ends the wait, since the values are on the host already. A call with plain data only places no flush and no fence. The WebGL2 tier still reads each call’s values back inside the call, and the fence is made at `read()`, not at the end of the submission: deviation D-c of change 0138 is closed in form only, and that remainder is open (milestone 3). A kernel function on a `Buffer` of structs runs on WebGPU or the CPU tier. A recorded call that fails leaves its error for the next `read()` or call, wherever it is, which throws it once (Rule 8.21). The calls a `fuse` body records ([Rule 11.13](https://typeshade.dev/reference/rules/11-13/)) run together as one item of that order, at the place `fuse` was called: the calls and the reads made after it see what they wrote. On WebGL2 the calls of a scope run apart, each as it runs outside a scope. A `Buffer` of scalars (Rule 8.21; change 0138, Amendment A10, Q-I), which `array(xs)` makes of a typed array, holds its own copy: a call on WebGPU uploads it the first time and binds the same buffer at every call after, reading nothing back, and `await b.read()` waits for the calls made before it and returns a new typed array of what it holds; `b.set(data)` replaces what it holds with its own copy of `data` and `b.dispose()` releases its buffer, each after the calls made before it, or at once when none waits, a use after `dispose()` being a `TypeError` (Amendment A11, Q1). `array(length, element)` makes a zeroed `Buffer` of `length` numbers, `element` being `'f32'`, `'i32'` or `'u32'`, which has no element default: it holds no host copy and writes no byte to a queue when it is made; a call on WebGPU makes a zeroed storage buffer and writes no byte to it, and a call that writes it leaves the device copy the newer; `read()` returns a new array of zeros, with no host copy kept, when no call has written it and `set()` has not run, and otherwise downloads the device buffer once. Its refusals are `TypeError`s: a length that is not a whole number from 1 to 4294967295, an element that is not `'f32'`, `'i32'` or `'u32'`, and a first argument that is not a number when an element is given. A scratch array of a `fuse` scope (Rule 11.13) is a `Buffer` the host never reads or writes: its `read()` rejects with a `TypeError`, and its `set()`, `resize()`, `at()` and `needsUpdate` throw one. One `Buffer` must not be two parameters of one call. The same `Buffer` is a buffer of the program runtime too, for a storage array with no size and a geometry’s vertices and indices, bound by any draw or dispatch of a runtime on the same device, and `configure({ runtime })` puts default-owner calls on that runtime’s device ([Rule 11.11](https://typeshade.dev/reference/rules/11-11/)); a program runtime’s `Texture` passed where a call takes an image is bound as it is, and a draw that falls to WebGL2 refuses it with a `TypeError`. A host may open an owner of its calls, `createDevice()` from `typeshade/runtime` (change 0071): on the first tier of `createDevice({ prefer })` that opens, which the device reports as `tier` with each earlier tier’s reason in `skipped`, on a `GPUDevice` the host hands in, or on a program runtime’s device (Rule 11.11); the tiers after the one that opened stay the fallback of a call that tier cannot run. `device.array(value)` and `device.array(length, element)` make a `Buffer` of scalars as `array()` does, owned by the device; `device.release(b)` gives it back, and the device keeps it for a later `array()` of the same element and length while the pool that `poolBytes` bounds has room, the oldest released array leaving first, and frees it otherwise; a reused array of `array(length, element)` holds zeros, cleared on the device where its buffer exists. One `Buffer` belongs to one owner for its life: a call takes the arrays of its own owner only, a `Buffer` of another owner being a `TypeError` that names both owners, and `array()` with no device in use makes the default owner’s. `device.limits` is the device’s limits (change 0051), empty on a tier with none; `device.lost` resolves when the browser invalidates the WebGPU device; `device.wait()` resolves when the device has completed every plan submitted so far; `device.dispose()` waits for the plans in flight, lands in the region what a call of the device wrote into each exported storage array and drops the device’s copy of it (change 0138, R3), destroys every array the device holds, each once, and the WebGPU device it requested, never a device or a runtime the host handed in, and a use after it is a `TypeError`. Two devices in one context are independent. The process-global `configure()` and `fuse()` describe the default owner. An ordinary kernel, compute-entry or draw call selects the unique owner of its `Buffer`s and device-created textures; an indirect workgroup count participates too (change 0085). A kernel call or an entry call also selects the owner of its `Buffer`s (change 0138, R3). These are the call’s owned resources. Plain host values and an exported binding select no owner, and a `Uniform` takes no part in the choice (change 0138, Amendment A8). A kernel call or an entry call with no owned resource runs on the device in use (below), and on the default owner when no device is in use (R3). A draw with no owned resource keeps the default owner, in a block of `device.use()` too. So does every call of a `fuse()` scope of `typeshade/fuse` (deviation D-h of change 0138, open). Mixing distinct owners, including an explicitly default-owned `Buffer`, is a `TypeError` naming both before execution. A scope fixes its calls’ owner. Owner inference preserves validation, copy-back, ordering and fallback. Disposal completes captured calls and refuses new calls after it starts. A draw with owned resources joins the call queue. An inferred device owner’s draw follows its tier policy; a draw with no device-owned resource retains the fixed WebGPU, WebGL2, CPU order. A canvas retains its first drawing tier, and refuses an owner whose policy excludes it; switching WebGPU owners rebuilds device-specific drawing resources. An owner has a flavor of the emulated double (changes 0073 and 0085). `createDevice({ fp64Flavor })` and `configure({ fp64Flavor })` take `'auto'`, `'float'` or `'integer'`, defaulting to `'auto'`. Automatic selection uses the executing device’s identity, its retained creation adapter or the actual WebGL context, with the existing user-agent fallback; it requests no unrelated adapter. Apple or Metal signals select `'integer'`; other or unknown GPU signals select `'float'`, and CPU selects `'float'`. Unknown signals do not establish hardware precision. Explicit flavors remain overrides. `device.fp64Flavor` reports a resolved flavor, and `configure({})` restores automatic selection. An unknown setting is a `TypeError` naming the three choices. `DeviceOptions` encodes mutually exclusive `prefer`, `device` and `runtime` sources; conflicting combinations fail TypeScript checking and runtime validation. A kernel call, an entry call and a draw of a module that emulates `f64` dispatch the WGSL of their owner’s flavor, read at the call (Rule 8.22), the `_fp64` guard bound under `'float'` and absent under `'integer'`; a module that emulates none runs as it did, and the WebGL2 tier and the CPU tier have one form each, which the flavor does not change. A kernel call takes a texture parameter (Rule 8.23, change 0077): a sampled `texture_2d<f32>` takes an image source or a program runtime’s or a device’s `Texture`, and a 2D storage texture takes a `Texture` a device made with `device.texture({ size, format, storage: true })`, of the parameter’s format. `device.texture()` makes a 2D texture its owner holds, with the usages of a program runtime’s texture, and `dispose()` destroys it; a texture belongs to one owner as a `Buffer` does, and a call of another owner refuses it with a `TypeError` naming both. Before anything runs the call checks each texture a loop stores into at `vec2(i % W, i / W)`: `W` is at most the texture’s width and the last iteration’s row is inside its height, or the call is a `TypeError` naming the parameter, its size and the texels. A texture call runs on WebGPU and on the CPU tier ([Rule 11.7](https://typeshade.dev/reference/rules/11-7/)), which reads an `ImageData` and a texture of its own memory and says why it cannot read any other; WebGL2 binds no texture parameter yet, and says so. `device.texture()` on a device with no WebGPU device makes a texture of the CPU tier’s memory, of a format that tier holds, and refuses another format with a `TypeError` that names the formats. `createDevice({ limits, features })` declares instance-local WebGPU requirements (change 0085), independent of `configure()`. Omitted requirements are empty. Values are validated and copied before requesting an adapter. A requested device negotiates the named limits and features; an unsupported requirement or a failed WebGPU request records its reason in `skipped` and tries only the remaining tiers in that owner’s `prefer`. A WebGPU-only preference refuses that failure. WebGL2 and CPU fallbacks have no WebGPU capabilities. A supplied device or runtime must already enable every requested feature and meet each named limit, with minimum limits checked in the opposite direction to maximum limits. Missing capabilities are a `TypeError`, and no adapter is requested to validate a supplied device. No owner changes the default owner’s request or another owner’s native capabilities. `configure()` remains the default-owner compatibility API, including its existing refusal of late capability changes. `configure()` is deprecated (change 0138, Amendment A1): it still does what this rule says and prints one `console.warn` at its first call. `array(value)` and `array(length, element)` from `typeshade/runtime` make the default owner’s `Buffer` when no device is in use, and in a block of `device.use()` the `Buffer` that `device.array()` makes on that device (change 0138, R3); an error that tells the host how to make an array names `array()`. A device is opened by `createDevice()` alone, and `device.use()` makes it the device in use until the handle it returns is disposed (the default device of Amendment A2), which `using _ = device.use()` does at the end of the block; uses nest, and the innermost is the device in use. `texture(options)` from `typeshade/runtime` makes its texture on that device, as `device.texture(options)` does, and is a `TypeError` when no device is in use. Data decides the device of a call (change 0138, R3). A resource belongs to the device in use when `zeros()`, `array()` or `uniform()` makes it, or to the default owner when no device is in use. What they make stays that device’s after the block. A `Uniform` takes no part in the choice of a call’s device (Amendment A8): a call copies its value (deviation D-b of change 0138), so it joins a call on any device. A kernel call or an entry call runs on the device of its owned resources (its `Buffer`s and the textures a device made), else on the device in use, else on the default owner. A call that takes owned resources of two devices is a `TypeError` at the call that names both, and changes no `Buffer`. An exported binding belongs to no one device. An exported storage array keeps one device copy for each device whose call takes it. Each copy takes the dirty ranges the host set since that copy’s last call, and the whole array after `read()` lands what a call on another device wrote. After a call on one device writes an exported storage array, a call on another device is a `TypeError` that says to await `read()` first. The uses of `device.use()` are one stack for each instance of the runtime module, not one for each async task. So while a task awaits inside a block, a resource that another task makes, or a call with no owned resource that it makes, takes that block’s device. Caution, not a promise of this rule: do not await inside a block while other tasks may make resources or calls. An owner has a time budget (change 0074): `createDevice({ timeBudgetMs })` takes the time one chunk of a long kernel may take, in milliseconds, 250 by default, which `device.timeBudgetMs` reports, and a value that is not a finite number from 1 to 60000 is a `RangeError` naming the range. `device.chunkSize(key, max, min = 1)` is the units of the next chunk of `key`: `min`, capped at `max`, before a chunk of `key` was measured, so the first chunk teaches the rate; after it, the units that fit eight tenths of the budget at the learned rate, at most four times the last chunk’s units, at least `min` and at least 1, and never more than `max`. A `max` or a `min` that is not a whole number of 1 or more is a `RangeError`, a `key` that is not a non-empty string a `TypeError`, and on the CPU tier, which has no watchdog, the answer is `max`. `device.chunkRates` holds, for each key a chunked plan named (Rule 11.13), a `ChunkRate`, `{ msPerUnit, chunks, longestMs, lastUnits }`, exported from `typeshade/runtime` and the root: the rate per unit is the first chunk’s measured one, then the mean of the previous rate and the measured one, and a chunk counts at least one unit and at least one microsecond. The default owner, `configure()` and `fuse()`, has no budget. A `@compute` entry’s call ([Rule 8.24](https://typeshade.dev/reference/rules/8-24/)) runs in the same order as kernel calls, and on the first tier of its selected owner’s policy that can run it: WebGPU when there is a device, WebGL2 when there is a context and the entry reaches no texture, as a pass program over textures of 32-bit words with its barriers and atomic operations in the phased order of change 0054, so it leaves what the CPU oracle leaves, and the CPU tier when the entry reaches no barrier and no texture; a call no tier on the list can run throws, a `TypeError` naming what the entry reaches when the CPU tier refused it, an `Error` naming each tier’s reason otherwise. A storage array binding with no size may be a `Buffer` of the scalars, bound on WebGPU as its device buffer and read back by nobody; a call that takes one is a call on a resource (Rule 8.21), and a `Buffer` of scalars for any other binding, or as two bindings of one call, is a `TypeError`. In the body of a `fuse` scope (Rule 11.13) the call runs in the scope’s plan, in the order of the plan, on the same tiers. Every buffer of a `Buffer` of scalars has the usage `INDIRECT` too (change 0075), so an entry call takes a `Buffer<u32>` as its workgroup count (Rule 8.24). WebGPU dispatches it with `dispatchWorkgroupsIndirect` at four times the offset, uploading a host copy that is the newer and reading nothing back. The CPU tier and WebGL2 read the three counts from the host copy, brought up to date, when the call runs, and run that grid. A count with a 0 in it, or one greater than the `maxComputeWorkgroupsPerDimension` of the owner’s WebGPU device (65535 where the owner holds none), runs no workgroup on every tier and throws nothing, since WebGPU’s queue runs nothing for such a count and cannot report it without a read. The counts array is held to the owner of the call as a binding is. A draw follows its inferred device owner’s tier policy, or the fixed WebGPU, WebGL2, CPU order with no device-owned resource. A canvas keeps the tier of its first draw; a draw may read a `Buffer` of scalars for a storage array with no size, and then runs in the order of kernel and entry calls, seeing what the calls before it wrote, with the `Buffer` bound as its device buffer on WebGPU and its copy brought up to date on the CPU tier; a `Buffer` of scalars for any other binding is a `TypeError`.

Generated kernel, compute-entry and fragment-entry calls propagate failed incoming `Buffer` contents at their queue position (change 0129): a call made before the failure is known, which a call on a resource is checked when it is made, finds its inputs failed when it runs; a call made after it is refused at the call (Rule 8.21; A7, decision b). After ordinary argument validation, a content read rejects with the input’s identical error before execution, uploads or submission. The rejected call retains that error on every `Buffer` it would write; a rejected draw preserves the canvas image. Parameter or binding order selects among failed inputs, with each held length beside its array and an indirect count after bindings. Fixed-capacity length queries and unused parameters read no contents; held lengths, device-held bounds and indirect counts do. Read/write inputs propagate failure; proven write-only destinations can recover, and successful writers clear their errors even for partial or zero-trip work. Outside today’s `fuse()`, a write-only call recovers a failed `Buffer` only when it was queued before the failure was known, since a call made after is refused at the call (change 0138, Amendment A12, D-n; A7, decision b). `set(data)` and `resize()` of a `Buffer` clear a previous call error (A7, decision b); unrelated calls and owners continue normally. The compiler checks whole-function access through the shared operand catalogue and carries private facts separately from public host metadata. Unproved access counts as a read, including a pushed-count inspection whose facts do not separate the count from its array. An older artifact without sufficient facts remains loadable and conservatively treats its `Buffer`s as content inputs. This policy does not change manually encoded program-runtime calls or `Frame` submissions, whose recording and submission contracts remain separate.

Entry-call constants (Rule 8.24, change 0084) select pipelines cached per device, entry, normalized values and owner-selected fp64 flavor. The generated CPU closure receives the same values and resolved invocation shape, and its reachable workgroup arrays have their selected lengths. Device workgroup limits are checked before uploads; specialized CPU calls use WebGPU’s portable minimum workgroup limits. The CPU barrier refusal remains. WebGL2 pins ordinary constants in its prebuilt program. A non-default workgroup shape or workgroup-array length is not supported yet on the WebGL2 tier (change 0084).

`Device.info` (change 0083) is a deeply frozen, JSON-serializable snapshot of the opened device: `build`, `tier`, and nullable `webgpu` and `webgl` sections. It describes the opened device, not each call’s effective tier or the aggregate `FuseReport.tier`. WebGPU identity comes from that device’s `adapterInfo`, its retained creation adapter, or stays unavailable; no unrelated adapter is requested. Enabled features and device limits are copied, not adapter maxima. WebGL strings come only from the actual context, with nullable debug strings. CPU has no GPU section. The snapshot remains readable as historical metadata after loss or disposal, without claiming current availability. It contains no native handles, persistent device identifier, browser user agent, storage or automatic telemetry.

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

## Rationale

a chain of calls over the same data (a particle step, a relaxation) should pay one upload and one read, not one of each per call: [#252](https://github.com/typeshade/typeshade/issues/252) measured the conversion of a million 32-byte structs at about 220 ms in and 1.3 s out, which residency pays once. The order of the tiers is the caller’s to set, and a caller that needs the GPU says so and gets an error that names why rather than a slow answer ([#252](https://github.com/typeshade/typeshade/issues/252)’s open question 6). The calls keep their order because a queued call has no await to order it by. A GPU watchdog resets a device whose one submission runs too long (about two seconds on Windows), so a kernel that iterates inside one dispatch runs as chunks, and the owner, which has the fence, the tier and a clock, sizes them from what it measured rather than each consumer (change 0074).

## Derives from

change `0013` in `changes/` (“Tiers”, “`resident(array)`”, which `array()` replaces, change 0138, Amendments A1 and A10); change `0016` (“Tiers”); change `0051` (the call layer’s device, `configure({ limits, features })` and `callDevice()`); change `0058` (the place of a scope in the order); change `0065` (the zeroed array, now `array(length, element)`); change `0074` (the time budget, `chunkSize` and `chunkRates`); change `0075` (the usage `INDIRECT` and the indirect count on each tier); change `0094` (the stores after the loops, the length words, the held length and a range the device holds on each tier); change `0109` (Amendment 1, decision D5: instances read back as instances, now from a `Buffer` of the class, change 0138, Amendment A11, Q4); change `0138` (Amendments A10 and A11: one `Buffer`); `docs/dx.md`; [Rule 11.7](https://typeshade.dev/reference/rules/11-7/).

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

the `Buffer` of scalars (`handleOf`, `makeResident`), `configure` and the call queue in `src/core/resident.ts` (the limits and features, C1 to C4 of change 0051), the call layer’s device and its report in `src/core/host-entry.ts` (`gpuDevice`, `callDevice`; pinned by `src/core/host-entry.test.ts`), which `callKernel` in `src/core/host-kernel.ts`, `callCompute` in `src/core/host-compute.ts` and `callDraw` in `src/runtime/host/draw.ts` read, the WebGL2 programs from `lowerKernelGl` in `src/core/passes/kernel-lower.ts`, drawn by `src/core/host-kernel-gl.ts`, the stores after the loops (change 0094) by the finish entry `onDevice` dispatches after the loops and by `finishOnHost` on WebGL2, both in `src/core/host-kernel.ts` (pinned by `src/compiler/ts/host-kernel-finish.test.ts` and `src/fuse.test.ts`, the storage buffers of the entry against the device’s limit among them), the length words and the held length (change 0094) by `onDevice` and `onCpu` in `src/core/host-kernel.ts` (pinned by `src/compiler/ts/host-kernel-push.test.ts`, `src/fuse.test.ts` and the generated kernels of `scripts/gpu-differential.ts`, held to the `f32` oracle on WebGPU), a range the device holds (change 0094) by `onDevice` in `src/core/host-kernel.ts`, which dispatches the range entry and the loop’s entry indirectly from the trip buffer, and by `glRange` in the same file on WebGL2 (pinned by `src/compiler/ts/host-kernel-range.test.ts`, `src/fuse.test.ts`, the storage buffers of the entries against the device’s limit among them, and the generated kernels of `scripts/gpu-differential.ts`, held to the `f32` oracle on WebGPU, with the range entries and the WebGL2 programs of such functions compiled by `scripts/compile-gate.ts`), and the host view’s two signatures from `hostFace` in `src/compiler/ts/host-face.ts`; pinned by `src/compiler/ts/host-kernel.test.ts` (the view under `tsc`, a queued call read back, an error kept for `read()`, each tier’s reason, one handle as two parameters, the zeroed form’s types under `tsc` and its three refusals, a zeroed handle read as zeros and written on the CPU tier), by `src/fuse.test.ts` on the recording device (a zeroed handle made and used on WebGPU with no write, read as zeros, uploaded once a `set()` gives it contents), by `src/compiler/ts/host-entry.test.ts` (an entry’s view under `tsc`, an entry and a kernel function queued on one handle, each refusal, each tier’s reason), by `src/compiler/ts/host-draw.test.ts` (a draw between two queued kernel calls on one handle) and by the import journey, which renders into and reduces over `Buffer`s of scalars on WebGPU, runs ordinary calls over device-owned textures, refuses a foreign owner’s scope, and alternates two native owners on one canvas (change 0085), chains two entry calls through one, draws one a kernel function filled on WebGPU and the CPU tier, and runs two maps with WebGL2 required, in Chromium; the compile gate links each kernel’s WebGL2 program on a WebGL2 context; the handle as a program runtime’s binding, `set`, `dispose` and `configure({ runtime })` by `src/runtime/runtime.test.ts`. Inside the body of a `fuse` ([Rule 11.13](https://typeshade.dev/reference/rules/11-13/)) the slot `fuseSlot`, which `read()`, `set()`, `resize()` and `dispose()` and the queue in `src/core/resident.ts`, `callKernel` in `src/core/host-kernel.ts`, `callCompute` in `src/core/host-compute.ts` and `callDraw` in `src/runtime/host/draw.ts` ask first, takes the kernel calls and refuses the rest, and the plan runs each call it recorded through `runChecked` in `src/core/host-kernel.ts`; pinned by `src/fuse.test.ts` (the place of a scope in the order, every refusal, a scratch array’s `read()` and `set()`, and the calls of a scope on the CPU tier) and by the journey `journeys/loop-fuse`, which runs a scope on WebGL2 and holds each call that has a program there to a draw of its own; the flavor of the emulated double of a device and of the default owner, the WGSL each dispatches and the guard each binds, by `src/runtime/device.test.ts` (changes 0073 and 0085), with instance capability negotiation, supplied-device validation, requirement snapshots and policy fallback pinned by `src/runtime/device-capabilities.test.ts` and the packed import fixture `journeys/_host-import/src/device-capabilities.ts`, and the source-option types checked by `src/runtime/device-options-types.test.ts` and automatic metadata selection by `src/core/device-info.test.ts`; the time budget, its refusals, `chunkSize` on each tier and `chunkRates` by `src/runtime/device.test.ts`, and the arithmetic `fitChunk` and `learnRate` of `src/runtime/chunk.ts` by `src/runtime/chunk.test.ts` (change 0074); a texture parameter’s checks, its owner and each tier’s reason by `checkTexture`, `rangesOf` and `runChecked` in `src/core/host-kernel.ts`, pinned by `src/compiler/ts/host-kernel-texture.test.ts`, and `device.texture()`, its refusals and its disposal by `src/runtime/device.test.ts` (change 0077); the deprecations, `device.use()` and `texture()` by `src/core/deprecation.ts`, `src/runtime/default-device.ts` and `src/runtime/resource.ts`, pinned by `src/runtime/resource.test.ts` and `src/runtime/exported-binding.test.ts` (change 0138); the indirect count by `runEntry` in `src/core/host-compute.ts` and the dispatch batch in `src/core/host-entry.ts`, pinned by `src/fuse.test.ts` (the buffer’s usage, the indirect dispatch, an upload of a newer host copy, the counts read on the CPU tier and on WebGL2, a count with a 0, a count past the limit), by `src/runtime/device.test.ts` (the owner of the counts array, a pooled array of counts cleared before its pass) and by the import journey (change 0075); the copy that a `Buffer` holds and that `read()` returns, which keeps the class of each object, by `copyOf` in `src/core/resident.ts` (change 0109, Amendment 1), pinned by `src/compiler/ts/host-class.test.ts` (a kernel call that writes it on the CPU tier, `set()`, `device.array()`, a plain object and an instance that a field holds, and a host program under `tsc` that runs over the generated module), by `src/fuse.test.ts` on the recording device (the device buffer read into the host copy in place) and by `src/runtime/runtime.test.ts` (each host value copied with no `structuredClone`). The calls that take a resource (change 0138, R2) by `src/runtime/resource-call.test.ts` on the CPU tier, and on WebGPU, with the entry call on WebGL2, by the `resource` arm of `scripts/gpu-differential.ts` (`scripts/resource-call-arm.ts`, run by `bun run gate:differential`), held bit for bit to the CPU tier and to hand-computed values.

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

- [`journeys/_host-import/src/device-capabilities.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/journeys/_host-import/src/device-capabilities.ts#L2)
- [`scripts/compile-gate.ts:18`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/compile-gate.ts#L18)
- [`scripts/gpu-differential.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/gpu-differential.ts#L1)
- [`scripts/kernel-length-cases.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/kernel-length-cases.ts#L2)
- [`scripts/resource-call-arm.ts:184`](https://github.com/typeshade/typeshade/blob/af54ddad5/scripts/resource-call-arm.ts#L184)
- [`src/compiler/ts/host-class.test.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-class.test.ts#L3)
- [`src/compiler/ts/host-content-access.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-content-access.ts#L1)
- [`src/compiler/ts/host-draw.test.ts:296`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-draw.test.ts#L296)
- [`src/compiler/ts/host-entry.test.ts:163`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-entry.test.ts#L163)
- [`src/compiler/ts/host-face.ts:549`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-face.ts#L549)
- [`src/compiler/ts/host-failed-input.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-failed-input.test.ts#L1)
- [`src/compiler/ts/host-kernel-finish.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-finish.test.ts#L2)
- [`src/compiler/ts/host-kernel-gl-length.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-gl-length.test.ts#L1)
- [`src/compiler/ts/host-kernel-made-gl.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-made-gl.test.ts#L2)
- [`src/compiler/ts/host-kernel-push.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-push.test.ts#L1)
- [`src/compiler/ts/host-kernel-range.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-range.test.ts#L2)
- [`src/compiler/ts/host-kernel-texture.test.ts:4`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel-texture.test.ts#L4)
- [`src/compiler/ts/host-kernel.test.ts:410`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-kernel.test.ts#L410)
- [`src/compiler/ts/host-override-calls.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/host-override-calls.test.ts#L1)
- [`src/core/deprecation.ts:7`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/deprecation.ts#L7)
- [`src/core/device-info.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/device-info.test.ts#L1)
- [`src/core/host-compute.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-compute.ts#L1)
- [`src/core/host-entry.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-entry.test.ts#L1)
- [`src/core/host-entry.ts:12`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-entry.ts#L12)
- [`src/core/host-failure.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-failure.ts#L1)
- [`src/core/host-kernel-gl.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-kernel-gl.ts#L1)
- [`src/core/host-kernel.ts:427`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-kernel.ts#L427)
- [`src/core/host-resident-check.test.ts:9`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/host-resident-check.test.ts#L9)
- [`src/core/passes/kernel-lower.ts:62`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/passes/kernel-lower.ts#L62)
- [`src/core/resident.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/resident.ts#L2)
- [`src/core/submission.test.ts:7`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/submission.test.ts#L7)
- [`src/fuse.test.ts:22`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/fuse.test.ts#L22)
- [`src/runtime/buffer-kinds.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/buffer-kinds.test.ts#L2)
- [`src/runtime/buffer-scalar.test.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/buffer-scalar.test.ts#L3)
- [`src/runtime/chunk.test.ts:11`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/chunk.test.ts#L11)
- [`src/runtime/chunk.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/chunk.ts#L1)
- [`src/runtime/default-device.ts:3`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/default-device.ts#L3)
- [`src/runtime/device-capabilities.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/device-capabilities.test.ts#L1)
- [`src/runtime/device-options-types.test.ts:2`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/device-options-types.test.ts#L2)
- [`src/runtime/device.test.ts:12`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/device.test.ts#L12)
- [`src/runtime/exported-binding.test.ts:297`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/exported-binding.test.ts#L297)
- [`src/runtime/host/draw.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/host/draw.ts#L1)
- [`src/runtime/info.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/info.test.ts#L1)
- [`src/runtime/resource-call.test.ts:10`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resource-call.test.ts#L10)
- [`src/runtime/resource-device.test.ts:12`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resource-device.test.ts#L12)
- [`src/runtime/resource.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resource.test.ts#L1)
- [`src/runtime/resource.ts:1119`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/resource.ts#L1119)
- [`src/runtime/runtime.test.ts:8`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/runtime/runtime.test.ts#L8)

## Explained in

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

- [§20 The length of a runtime-sized storage array](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#20-the-length-of-a-runtime-sized-storage-array)
- [§23 Atomics](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#23-atomics)
- [§24 Module variables](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#24-module-variables)
- [§48 Compare-exchange, the uniform load and the texture barrier](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#48-compare-exchange-the-uniform-load-and-the-texture-barrier)
- [§62 A name a target reserves](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#62-a-name-a-target-reserves)
- [§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)
- [§65 A loop that runs as a kernel](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#65-a-loop-that-runs-as-a-kernel)
- [§67 Calling an entry point from host code](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#67-calling-an-entry-point-from-host-code)
- [§69 Running a compiled program](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#69-running-a-compiled-program)
- [§71 A chain of kernel calls in one dispatch: `fuse`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#71-a-chain-of-kernel-calls-in-one-dispatch-fuse)
- [§72 The common algorithms: `typeshade/algorithms`](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#72-the-common-algorithms-typeshadealgorithms)
- [§74 A Map and a Set in a kernel function](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#74-a-map-and-a-set-in-a-kernel-function)

## See also

- [Rule 11.7](https://typeshade.dev/reference/rules/11-7/) Test
- [Rule 11.9](https://typeshade.dev/reference/rules/11-9/) Test
- [Rule 7.2](https://typeshade.dev/reference/rules/7-2/)
- [Rule 8.21](https://typeshade.dev/reference/rules/8-21/)
- [Rule 8.22](https://typeshade.dev/reference/rules/8-22/)
- [Rule 8.23](https://typeshade.dev/reference/rules/8-23/)
- [Rule 8.24](https://typeshade.dev/reference/rules/8-24/)
- [Rule 11.11](https://typeshade.dev/reference/rules/11-11/)
- [Rule 11.13](https://typeshade.dev/reference/rules/11-13/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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