Skip to content

dx: More robust snippet testing#2716

Open
aleksanderkatan wants to merge 10 commits into
mainfrom
dx/more-robust-snippet-testing
Open

dx: More robust snippet testing#2716
aleksanderkatan wants to merge 10 commits into
mainfrom
dx/more-robust-snippet-testing

Conversation

@aleksanderkatan

Copy link
Copy Markdown
Contributor

No description provided.

@aleksanderkatan aleksanderkatan linked an issue Jul 13, 2026 that may be closed by this pull request
@aleksanderkatan

Copy link
Copy Markdown
Contributor Author

@pullfrog review

@github-actions

github-actions Bot commented Jul 13, 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/tgpu-gen@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@bc3fb3ef84762d85b9f3c7e95f4a03ad0eee781e

benchmark
view benchmark

commit
view commit

@github-actions

github-actions Bot commented Jul 13, 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.14 kB ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 255.63 kB ($${\color{green}-3.3\%}$$)
tgpu_resolve.ts 161.62 kB ($${\color{green}-38.9\%}$$)
tgpu_resolveWithContext.ts 161.55 kB ($${\color{green}-38.9\%}$$)
tgpu_bindGroupLayout.ts 68.88 kB ($${\color{green}-74.0\%}$$)
tgpu_mutableAccessor.ts 65.83 kB ($${\color{green}-75.1\%}$$)
tgpu_accessor.ts 65.81 kB ($${\color{green}-75.1\%}$$)
tgpu_privateVar.ts 65.23 kB ($${\color{green}-75.3\%}$$)
tgpu_workgroupVar.ts 65.23 kB ($${\color{green}-75.3\%}$$)
tgpu_const.ts 64.48 kB ($${\color{green}-75.6\%}$$)
tgpu_fn.ts 38.07 kB ($${\color{green}-85.6\%}$$)
tgpu_fragmentFn.ts 37.97 kB ($${\color{green}-85.6\%}$$)
tgpu_vertexFn.ts 37.78 kB ($${\color{green}-85.7\%}$$)
tgpu_computeFn.ts 37.49 kB ($${\color{green}-85.8\%}$$)
tgpu_vertexLayout.ts 26.62 kB ($${\color{green}-89.9\%}$$)
tgpu_comptime.ts 14.42 kB ($${\color{green}-94.5\%}$$)
tgpu_unroll.ts 2.59 kB ($${\color{green}-99.0\%}$$)
tgpu_slot.ts 1.54 kB ($${\color{green}-99.4\%}$$)
tgpu_lazy.ts 1.19 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 13, 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.90, 1.74, 3.90, 5.17, 6.51, 11.09, 20.62, 21.35]
  line [0.85, 1.71, 3.75, 5.46, 6.32, 10.85, 19.57, 21.39]
  line [0.88, 1.80, 3.78, 5.45, 6.62, 10.52, 21.39, 22.25]
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.29, 0.45, 0.60, 0.73, 0.98, 1.08, 1.27, 1.43]
  line [0.31, 0.48, 0.65, 0.77, 1.05, 1.07, 1.31, 1.41]
  line [0.32, 0.51, 0.68, 0.85, 1.11, 1.17, 1.34, 1.49]
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.74, 2.00, 3.32, 5.81, 10.80, 23.52, 48.10, 96.90]
  line [0.81, 1.86, 3.53, 5.62, 10.92, 22.82, 48.50, 99.44]
  line [0.78, 1.86, 3.74, 7.06, 11.20, 23.23, 48.54, 101.33]
Loading

@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.

Important

The new capture.ts file imports tinyest at runtime, but packages/typegpu-testing-utility/package.json does not declare it as a dependency. Running pnpm vitest run --project=!browser packages/typegpu/tests/internal/capturedSnippets.test.ts fails with ERR_MODULE_NOT_FOUND in a clean workspace install (verified locally). Adding tinyest to the testing utility's dependencies resolves the failure.

Reviewed changes — adds a CAPTURE-based snippet extraction utility for more robust TGSL tests, plus the internal exports it needs.

  • Add CapturingGenerator, CAPTURE, captureSnippets, and simplifyType in typegpu-testing-utility to intercept and collect WGSL snippets during resolution.
  • Export dualImpl from typegpu/~internal so the utility can build a dual-implementation marker function.
  • Add unit tests in packages/typegpu/tests/internal/capturedSnippets.test.ts covering regular-resolve no-op behavior, snippet extraction, repeated captures, and inner-to-outer capture ordering.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

Comment thread packages/typegpu-testing-utility/src/capture.ts

@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 since last review — the follow-up commit adds the missing tinyest dependency to packages/typegpu-testing-utility/package.json (and the lockfile) so the new capture.ts module can resolve its runtime import in a clean pnpm workspace.

  • Add tinyest as a runtime dependency of typegpu-testing-utility using the workspace:* spec.

I verified pnpm vitest run --project=!browser packages/typegpu/tests/internal/capturedSnippets.test.ts now passes and both typegpu-testing-utility and typegpu typecheck cleanly.

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

@aleksanderkatan aleksanderkatan marked this pull request as ready for review July 13, 2026 16:11
Copilot AI review requested due to automatic review settings July 13, 2026 16:11

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@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 — added a CAPTURE dual-impl helper and captureSnippets utility to the testing package, plus internal exports needed to support them.

  • Add CAPTURE/captureSnippets/simplifyType to typegpu-testing-utilityCAPTURE is transparent in normal resolves and records its argument's snippet when resolved through CapturingGenerator.
  • Expose dualImpl from typegpu/~internal — required to declare CAPTURE as a DualFn.
  • Add capturedSnippets.test.ts — covers normal resolution transparency, snippet extraction, re-capture, and nested capture ordering.

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

Comment thread packages/typegpu-testing-utility/src/capture.ts Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

  it('works with typedExpression - struct', () => {
    const Boid = d.struct({
      pos: d.vec3f,
    });

    const fn = tgpu.fn(
      [],
      Boid,
    )(() => {
      'use gpu';
      return CAPTURE({ pos: d.vec3f() });
    });

    const captured = captureSnippets(fn);
    expect(captured[0]?.value).toMatchInlineSnapshot(`"Boid(vec3f())"`);
  });

  it('works with typedExpression - numeric', () => {
    const fn = tgpu.fn(
      [],
      d.u32,
    )(() => {
      'use gpu';
      return CAPTURE(d.f32(1.67));
    });

    const captured = captureSnippets(fn);
    expect(captured[0]?.value).toMatchInlineSnapshot(`1.6699999570846558`);
  });

Could you add these tests?
The second test needs to be fixed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So I think we decided that this is intended behavior, and that we want to remove expected type stack, right? I created an issue for that: #2726

@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.

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

@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 since last review — the new commit cleans up the capture.ts imports and adds a regression test verifying struct-literal capture before return-type casting.

  • Consolidate typegpu/~internal imports in capture.ts — pulls dualImpl into the existing typegpu/~internal import rather than importing it separately.
  • Add captures structs after casting test — verifies that CAPTURE records the original Boid struct data type of { pos: d.vec3f() } before the function return type casts it.

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.

test: More robust snippet testing

3 participants