---
title: "Rule 6.5: Declarations and resources in TypeShade"
description: "Rule 6.5 of the TypeShade language design, in Declarations and resources."
url: https://typeshade.dev/reference/rules/6-5/
language: en
---

# Rule 6.5

Chapter 6, Declarations and resources Test

A top-level `let` is a module variable in the per-invocation (`private`) address space; workgroup memory must be written `let x: workgroup<T>`; a module variable must take no `declare`. A sized array in workgroup memory may use a scalar integer override as its outer element count; its default is the count used by the CPU oracle, and the selected override specializes the WGSL array.

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

## Rationale

a module-level `let` already says “a value this invocation owns”, so the address space is read off the syntax and only the space TypeScript cannot express gets a wrapper.

## Derives from

[Address Spaces](https://gpuweb.github.io/gpuweb/wgsl/#address-space); surface §24; the roadmap’s first rule.

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

`TS8033 MODULE_VAR` and `src/compiler/ts/module-vars.test.ts`.

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

- [`src/compiler/ts/module-vars-atomic.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-vars-atomic.test.ts#L1)
- [`src/compiler/ts/module-vars.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/module-vars.test.ts#L1)

## Explained in

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

- [§24 Module variables](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#24-module-variables)

## Error codes that enforce it

The diagnostic codes the rule names under Enforced by, or whose registry text names the rule:

**[`TS8033`](https://typeshade.dev/reference/errors/ts8033/) `MODULE_VAR`**

A module variable declared or used where its address space forbids it: a `const` with an address-space wrapper, a `workgroup` variable with an initializer, a type that the space cannot hold (a texture, a runtime-sized array, an atomic in a per-invocation variable), an initializer that is not a constant, or a `workgroup` variable reached from a vertex or fragment entry. Also the retired `perInvocation<T>` wrapper, which a plain top-level `let` replaced.

## See also

- [Rule 6.4](https://typeshade.dev/reference/rules/6-4/) Test
- [Rule 6.6](https://typeshade.dev/reference/rules/6-6/) Test
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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