Skip to content

fix: Accessors correctly infer input type from array schema#2699

Open
cieplypolar wants to merge 1 commit into
mainfrom
fix/array-in-accessor
Open

fix: Accessors correctly infer input type from array schema#2699
cieplypolar wants to merge 1 commit into
mainfrom
fix/array-in-accessor

Conversation

@cieplypolar

Copy link
Copy Markdown
Collaborator

Closes #2698.

Copilot AI review requested due to automatic review settings July 8, 2026 14:08
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@4b856b1923256e994c0de2fc2ba4ebe3229498e1
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@4b856b1923256e994c0de2fc2ba4ebe3229498e1
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@4b856b1923256e994c0de2fc2ba4ebe3229498e1
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@4b856b1923256e994c0de2fc2ba4ebe3229498e1
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@4b856b1923256e994c0de2fc2ba4ebe3229498e1

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

Bundle size comparison (import * as ... in PR vs import * as ... in target):

🟢 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 ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 255.90 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 187.13 kB ($${\color{green}-29.4\%}$$)
tgpu_resolveWithContext.ts 187.07 kB ($${\color{green}-29.4\%}$$)
tgpu_bindGroupLayout.ts 69.01 kB ($${\color{green}-73.9\%}$$)
tgpu_mutableAccessor.ts 65.98 kB ($${\color{green}-75.1\%}$$)
tgpu_accessor.ts 65.97 kB ($${\color{green}-75.1\%}$$)
tgpu_privateVar.ts 65.30 kB ($${\color{green}-75.3\%}$$)
tgpu_workgroupVar.ts 65.30 kB ($${\color{green}-75.3\%}$$)
tgpu_const.ts 64.53 kB ($${\color{green}-75.6\%}$$)
tgpu_fn.ts 37.94 kB ($${\color{green}-85.7\%}$$)
tgpu_fragmentFn.ts 37.87 kB ($${\color{green}-85.7\%}$$)
tgpu_vertexFn.ts 37.69 kB ($${\color{green}-85.8\%}$$)
tgpu_computeFn.ts 37.39 kB ($${\color{green}-85.9\%}$$)
tgpu_vertexLayout.ts 26.61 kB ($${\color{green}-90.0\%}$$)
tgpu_comptime.ts 14.41 kB ($${\color{green}-94.6\%}$$)
tgpu_unroll.ts 2.60 kB ($${\color{green}-99.0\%}$$)
tgpu_slot.ts 1.57 kB ($${\color{green}-99.4\%}$$)
tgpu_lazy.ts 1.22 kB ($${\color{green}-99.5\%}$$)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

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]
Loading
---
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]
Loading
---
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]
Loading

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 accessor and mutableAccessor to improve schema/default-value type inference (especially for callable schemas like d.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.

Comment on lines +537 to +540
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>>>();
});

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NA since such array is immutable

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.ts for AnyData schemas and runtime-sized schema constructors, fixing inference for d.arrayOf(...) inputs.
  • Add regression type test in packages/typegpu/tests/accessor.test.ts asserting accessor(d.arrayOf(d.u32, 1), d.arrayOf(d.u32, 1)([1])) returns TgpuAccessor<d.WgslArray<d.U32>>.

Pullfrog  | View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: tgpu.accessor cannot infer type of ephemeral array schema

4 participants