Repository navigation
fix(tgpu-gen): Sort structs used in nested arrays before the structs that hold them - #3317
RaphaelFakhri wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Nested-array dependency unwrapping —
topologicalSortnow walks everyArrayInfo.formatlayer down to the innermost element type before checkingallStructNames, so a struct used inarray<array<Cell, 4>, 4>(or a runtime-sizedarray<array<Cell, 2>>) is recorded as a dependency of its holder and emitted first. - Regression test —
structs.test.tsadds aGrid/Cellcase that assertsCellis generated beforeGridand that the member renders asd.arrayOf(d.arrayOf(Cell, 4), 4).
The change is a strict superset of the previous dependency detection: it adds only real array-element edges, so ordering changes only for inputs that previously threw Unknown data type. I ran the tgpu-gen suite (33 tests pass) and also generated runtime-sized nested arrays, three-level nesting, and an aliased nested-array member locally — all order correctly.
( ◦°^°◦) 🏴☠️ Arr, I read the whole diff, ran the tgpu-gen tests, and found no leaks in this here nested-array fix.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

tgpu-gensorts structs topologically so that each struct is generated after the structs it uses.topologicalSortonly looks at the member type and, for arrays, the element type. When a struct is used inside an array of arrays, such asarray<array<Cell, 4>, 4>, and is declared later in the WGSL, it is not recorded as a dependency, and generation fails withUnknown data type: Cell.Changes
topologicalSortunwraps nested arrays down to their innermost element type before checking for a struct dependency. This also covers the single-level array case that the old code handled separately.Testing
The
packages/tgpu-gentests pass: 33 tests. Without thegen.mjschange, the new test fails withError: Unknown data type: Cell.Fixes #3316