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

# Rule 6.8

Chapter 6, Declarations and resources Test

The byte layout the emitted module assumes for a resource and the layout `reflect()` reports must agree byte for byte, under WGSL’s uniform and storage layout rules, and so must the layout the manifest carries ([Rule 11.10](https://typeshade.dev/reference/rules/11-10/)); a vertex entry’s vertex buffer is one layout, its `@location` inputs tightly packed in the order written and numbered in that order where no `location<n, T>` states the number ([Rule 6.6](https://typeshade.dev/reference/rules/6-6/)), which `reflect().vertex` and the manifest both report.

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

## Rationale

a buffer the host fills from `reflect()` and the shader reads by its own offsets is a dynamic error nothing detects.

## Derives from

[Memory Layout](https://gpuweb.github.io/gpuweb/wgsl/#memory-layouts) (“it is a dynamic error if buffer producers and consumers do not agree on the memory layout”).

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

`examples/emit-reflection-conformance.test.ts` for bindings, locations, and entry points, `src/core/manifest.test.ts`, which holds every example’s manifest to `reflect()`’s slots, struct offsets and vertex layout, and the one layout engine behind `reflect()` in `src/core/reflect.ts` (its code is in the directory `src/core/reflect/`) that the GLSL writer also uses, whose layout checks are the two-row matrix of [Rule 4.8](https://typeshade.dev/reference/rules/4-8/) and the uniform-address-space rules of surface §51 ([#156](https://github.com/typeshade/typeshade/issues/156)): an array in a uniform is padded to a 16-byte stride and `reflect()` agrees; a `bool`, alone or in a vector, in a uniform or storage binding (a struct field, a runtime array’s element or the binding’s whole type, `"U.b" is a vec3b; a uniform binding holds no bool, alone or in a vector (WGSL's host-shareable rule). Use vec3u.`), a runtime-sized array in a uniform, and one that is not a struct’s last field are `TS8051 LAYOUT`; a field `@align` is [`TS8010`](https://typeshade.dev/reference/errors/ts8010/) (`@align on a field is not applied.`) and a field `@size` is [`TS8028`](https://typeshade.dev/reference/errors/ts8028/); pinned by `src/compiler/ts/uniform-layout.test.ts`.

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

- [`examples/emit-reflection-conformance.test.ts:31`](https://github.com/typeshade/typeshade/blob/af54ddad5/examples/emit-reflection-conformance.test.ts#L31)
- [`src/compiler/ts/bare-uniform-glsl.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/bare-uniform-glsl.test.ts#L1)
- [`src/compiler/ts/entry-locations.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/entry-locations.test.ts#L1)
- [`src/compiler/ts/entry-locations.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/entry-locations.ts#L1)
- [`src/compiler/ts/uniform-layout-matrix.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/uniform-layout-matrix.test.ts#L1)
- [`src/compiler/ts/uniform-layout-padded.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/uniform-layout-padded.test.ts#L1)
- [`src/compiler/ts/uniform-layout-refused.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/uniform-layout-refused.test.ts#L1)
- [`src/compiler/ts/uniform-layout.test.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/compiler/ts/uniform-layout.test.ts#L1)
- [`src/core/manifest.test.ts:6`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/manifest.test.ts#L6)
- [`src/core/reflect.ts:1`](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/reflect.ts#L1)

## Explained in

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

- [§3 Entries — stage attributes and explicit builtins](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#3-entries--stage-attributes-and-explicit-builtins)
- [§51 What a uniform lays out: the 16-byte array rule, and the shapes a struct hides](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#51-what-a-uniform-lays-out-the-16-byte-array-rule-and-the-shapes-a-struct-hides)
- [§69 Running a compiled program](https://github.com/typeshade/typeshade/blob/af54ddad5/docs/use-typeshade-surface.md#69-running-a-compiled-program)

## Error codes that enforce it

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

**[`TS8010`](https://typeshade.dev/reference/errors/ts8010/) `STRUCT_FIELD`**

An invalid struct field or declaration shape. A class with no fields is accepted; this code covers an invalid field declaration, an empty struct that is not a class, an `@align` on a field, which is not applied, and a user-defined value whose uses give it two locations ([Rule 6.6](https://typeshade.dev/reference/rules/6-6/)).

**[`TS8028`](https://typeshade.dev/reference/errors/ts8028/) `ATTRIBUTE_NAME`**

A decorator or an entry form that this surface does not read: an identifier outside the attribute vocabulary (`@vertex`, `@fragment`, `@compute`, `@builtin`, `@location`), such as a misspelled `@vertx`; a WGSL attribute that the surface writes another way or does not borrow, such as a written `@diagnostic(…)`; a stage written as a call, such as `vertex(f)`; an entry that is written in a form that [Rule 8.1](https://typeshade.dev/reference/rules/8-1/) refuses, such as `export default`; or a decorator on a declaration or in a place that takes none ([Rule 6.7](https://typeshade.dev/reference/rules/6-7/)). Without this code the decorated function or field would silently stop being an entry point or an I/O field.

**[`TS8051`](https://typeshade.dev/reference/errors/ts8051/) `LAYOUT`**

A buffer binding's store type that breaks one of WGSL's host-shareable rules: a `bool`, alone or in a vector, in a `uniform` or `storage` binding; a runtime-sized `array<T>` that is not the last member of its struct; a runtime-sized array in a uniform; or a two-row matrix (`mat2x2`, `mat3x2`, `mat4x2`) in a uniform, which WGSL and std140 lay out at different offsets ([Rule 4.8](https://typeshade.dev/reference/rules/4-8/)).

## See also

- [Rule 6.7](https://typeshade.dev/reference/rules/6-7/) Test
- [Rule 6.9](https://typeshade.dev/reference/rules/6-9/) Test
- [Rule 4.8](https://typeshade.dev/reference/rules/4-8/)
- [Rule 6.6](https://typeshade.dev/reference/rules/6-6/)
- [Rule 11.10](https://typeshade.dev/reference/rules/11-10/)
- [Design rules](https://typeshade.dev/reference/rules/)
- [Error codes](https://typeshade.dev/reference/errors/)

## Source

The rule at commit af54ddad5:

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