Skip to content

dx: More robust snippet testing#2716

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

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

Conversation

@aleksanderkatan

Copy link
Copy Markdown
Member

No description provided.

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

Copy link
Copy Markdown
Member 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/eslint-plugin-typegpu@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/tgpu-gen@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/tinyest-for-wgsl@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/typegpu@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/cli@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/color@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/gl@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/radiance-cascades@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/react@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/sdf@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/three@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@8e9cea0fd8f1318b0e1f6e4d5c3a74609f3fa23c

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.97 kB ($${\color{green}-3.2\%}$$)
tgpu_initFromDevice.ts 256.46 kB ($${\color{green}-3.4\%}$$)
tgpu_resolve.ts 164.34 kB ($${\color{green}-38.1\%}$$)
tgpu_resolveWithContext.ts 164.27 kB ($${\color{green}-38.1\%}$$)
tgpu_bindGroupLayout.ts 68.96 kB ($${\color{green}-74.0\%}$$)
tgpu_mutableAccessor.ts 65.97 kB ($${\color{green}-75.2\%}$$)
tgpu_accessor.ts 65.96 kB ($${\color{green}-75.2\%}$$)
tgpu_privateVar.ts 65.31 kB ($${\color{green}-75.4\%}$$)
tgpu_workgroupVar.ts 65.30 kB ($${\color{green}-75.4\%}$$)
tgpu_const.ts 64.55 kB ($${\color{green}-75.7\%}$$)
tgpu_fn.ts 38.14 kB ($${\color{green}-85.6\%}$$)
tgpu_fragmentFn.ts 38.13 kB ($${\color{green}-85.6\%}$$)
tgpu_vertexFn.ts 37.95 kB ($${\color{green}-85.7\%}$$)
tgpu_computeFn.ts 37.66 kB ($${\color{green}-85.8\%}$$)
tgpu_vertexLayout.ts 26.79 kB ($${\color{green}-89.9\%}$$)
tgpu_comptime.ts 14.48 kB ($${\color{green}-94.5\%}$$)
tgpu_unroll.ts 1.66 kB ($${\color{green}-99.4\%}$$)
tgpu_slot.ts 1.54 kB ($${\color{green}-99.4\%}$$)
tgpu_lazy.ts 1.19 kB ($${\color{green}-99.6\%}$$)

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.80, 1.52, 3.21, 5.71, 6.95, 9.52, 19.96, 20.89]
  line [0.76, 1.67, 3.62, 5.54, 6.44, 9.17, 18.35, 21.66]
  line [0.85, 1.71, 3.65, 5.86, 6.62, 10.93, 20.03, 22.30]
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.28, 0.54, 0.66, 0.79, 1.06, 1.02, 1.28, 1.36]
  line [0.30, 0.50, 0.67, 0.81, 1.02, 1.14, 1.29, 1.48]
  line [0.31, 0.54, 0.70, 0.80, 1.09, 1.11, 1.37, 1.50]
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.68, 1.78, 3.20, 5.51, 10.94, 23.43, 48.67, 96.94]
  line [0.65, 1.88, 3.76, 5.82, 10.69, 22.45, 48.25, 98.86]
  line [0.79, 1.80, 3.81, 5.65, 10.80, 22.90, 51.62, 104.55]
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
Member 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) | 𝕏

@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 — merged latest main into the feature branch and updated the possibleSideEffects snapshot that became stale due to main's new side-effect tracking.

  • Synced main into the branch — incorporates recent changes including the more comprehensive side-effect tracking that now marks captured constant abstract expressions as possibleSideEffects: false.
  • Updated allows snippet extraction snapshot in packages/typegpu/tests/internal/capturedSnippets.test.ts so the test matches the new behavior from main.

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

Snapshot update aligns the allows snippet extraction test with main's new side-effect tracking for constant abstract expressions.

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