fix: Accessors correctly infer input type from array schema#2699
fix: Accessors correctly infer input type from array schema#2699cieplypolar wants to merge 1 commit into
Conversation
|
pkg.pr.new packages benchmark commit |
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 321 | 0 | 0 |
import { ... } in PR vs import * as ... in PR (is the library tree-Shakeable?):
| Test | tsdown |
|---|---|
| tgpu_init.ts | 256.41 kB ( |
| tgpu_initFromDevice.ts | 255.90 kB ( |
| tgpu_resolve.ts | 187.13 kB ( |
| tgpu_resolveWithContext.ts | 187.07 kB ( |
| tgpu_bindGroupLayout.ts | 69.01 kB ( |
| tgpu_mutableAccessor.ts | 65.98 kB ( |
| tgpu_accessor.ts | 65.97 kB ( |
| tgpu_privateVar.ts | 65.30 kB ( |
| tgpu_workgroupVar.ts | 65.30 kB ( |
| tgpu_const.ts | 64.53 kB ( |
| tgpu_fn.ts | 37.94 kB ( |
| tgpu_fragmentFn.ts | 37.87 kB ( |
| tgpu_vertexFn.ts | 37.69 kB ( |
| tgpu_computeFn.ts | 37.39 kB ( |
| tgpu_vertexLayout.ts | 26.61 kB ( |
| tgpu_comptime.ts | 14.41 kB ( |
| tgpu_unroll.ts | 2.60 kB ( |
| tgpu_slot.ts | 1.57 kB ( |
| tgpu_lazy.ts | 1.22 kB ( |
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
Resolution Time Benchmark---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Random Branching (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.97, 1.98, 4.59, 6.21, 8.06, 11.10, 22.49, 23.01]
line [0.94, 1.90, 4.55, 6.85, 8.56, 11.11, 21.79, 25.82]
line [0.99, 1.92, 3.98, 7.16, 7.07, 11.42, 21.26, 25.11]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Linear Recursion (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.37, 0.57, 0.72, 0.89, 1.15, 1.25, 1.45, 1.65]
line [0.31, 0.53, 0.75, 0.86, 1.18, 1.16, 1.45, 1.57]
line [0.35, 0.56, 0.70, 0.82, 1.14, 1.23, 1.42, 1.59]
---
config:
themeVariables:
xyChart:
plotColorPalette: "#E63946, #3B82F6, #059669"
---
xychart
title "Full Tree (🔴 PR | 🔵 main | 🟢 release)"
x-axis "max depth" [1, 2, 3, 4, 5, 6, 7, 8]
y-axis "time (ms)"
line [0.91, 2.17, 4.11, 6.45, 12.59, 26.01, 55.68, 115.13]
line [0.99, 2.03, 3.65, 6.59, 13.05, 26.52, 56.66, 116.19]
line [0.95, 2.08, 4.07, 6.63, 12.67, 26.44, 56.69, 114.67]
|
There was a problem hiding this comment.
Pull request overview
Fixes a TypeScript inference bug where tgpu.accessor could not infer the correct defaultValue input type when given an ephemeral fixed-size array schema (e.g. d.arrayOf(d.u32, 1)), resolving issue #2698.
Changes:
- Added overload signatures for
accessorandmutableAccessorto improve schema/default-value type inference (especially for callable schemas liked.arrayOf(...)). - Added a type-level regression test to ensure array schema input types infer correctly for
tgpu.accessor.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/typegpu/src/core/slot/accessor.ts | Adds overloads for accessor/mutableAccessor to improve TypeScript inference for array schemas and runtime constructors. |
| packages/typegpu/tests/accessor.test.ts | Adds a regression test validating correct inferred types when using an ephemeral fixed-size array schema as an accessor schema. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('correctly infers input type from array schema', () => { | ||
| const accessor = tgpu.accessor(d.arrayOf(d.u32, 1), d.arrayOf(d.u32, 1)([1])); | ||
| expectTypeOf(accessor).toEqualTypeOf<TgpuAccessor<d.WgslArray<d.U32>>>(); | ||
| }); |
There was a problem hiding this comment.
NA since such array is immutable
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — PR adds function overloads to accessor() and mutableAccessor() so array schemas are inferred as concrete array data types instead of being widened by the AnyData | ((count: number) => AnyData) union, plus a regression type test.
- Add split overloads in
packages/typegpu/src/core/slot/accessor.tsforAnyDataschemas and runtime-sized schema constructors, fixing inference ford.arrayOf(...)inputs. - Add regression type test in
packages/typegpu/tests/accessor.test.tsassertingaccessor(d.arrayOf(d.u32, 1), d.arrayOf(d.u32, 1)([1]))returnsTgpuAccessor<d.WgslArray<d.U32>>.
Kimi K2 (free via Pullfrog for OSS) | 𝕏

Closes #2698.