Conversation
|
pkg.pr.new packages benchmark commit |
There was a problem hiding this comment.
🟡 Changes recommended
Add regression coverage for descending ranges ending at zero.
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Fixes tgpu.unroll for descending ranges ending at zero.
Changes:
- Removes the premature zero-endpoint return.
- Checks materialized elements before omitting empty loops.
File summaries
| File | Summary | Review comment |
|---|---|---|
packages/typegpu/src/tgsl/wgslGenerator.ts |
Corrects compile-time range unrolling. | Add a regression test for std.range(3, 0, -1) and ideally negative endpoints. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.91, 1.74, 3.79, 6.38, 7.56, 10.91, 22.23, 25.07]
line [0.94, 1.84, 4.01, 6.21, 6.69, 12.73, 23.83, 22.62]
line [0.88, 1.83, 3.80, 6.36, 7.08, 11.83, 23.18, 24.30]
---
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.30, 0.49, 0.66, 0.73, 1.03, 1.06, 1.29, 1.43]
line [0.34, 0.44, 0.68, 0.76, 1.03, 1.15, 1.46, 1.46]
line [0.33, 0.50, 0.60, 0.74, 1.10, 1.06, 1.28, 1.50]
---
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, 1.98, 3.67, 6.46, 11.33, 24.08, 53.82, 110.30]
line [0.98, 1.95, 3.75, 7.02, 11.49, 25.13, 54.70, 107.80]
line [0.92, 1.96, 3.50, 6.29, 11.63, 26.19, 54.30, 108.45]
|
Bundle size comparison (
|
| 🟢 Decreased | ➖ Unchanged | 🔴 Increased | ❔ Unknown |
|---|---|---|---|
| 0 | 325 | 0 | 0 |
No notable changes.
If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor suggestion. The fix itself is correct and verified.
Reviewed changes
- Correct empty-range detection in
tgpu.unroll—packages/typegpu/src/tgsl/wgslGenerator.tsnow buildselementsfirst and returns empty code only whenelements.length === 0, instead of bailing whenrange.end.value === 0. This removes the end-value/element-count conflation that dropped descending ranges ending at zero, and it also avoids the previousundefinedelements[0]path for empty ranges whose end is non-zero (e.g.std.range(0, 5, -1)). - I verified the PR's case resolves to 3 iterations (
3i,2i,1i), thatstd.range(3, -1, -1)resolves to 4, and thatstd.range(0, 5, -1)/std.range(0)still emit an empty body. The existing 28 tests inpackages/typegpu/tests/unroll.test.tsall pass.
ℹ️ Missing regression test
This is a bug fix but ships without a committed test — changed_files: 1, and the failing snippet in the PR description was not added. unroll.test.ts has no descending-range (negative step) case, so nothing pins this behavior and a future refactor could silently reintroduce it.
Technical details
# Add a regression test for descending ranges / zero-end ranges
## Affected sites
- `packages/typegpu/tests/unroll.test.ts` — no `std.range` case with a negative step; existing range tests use `std.range(1, 9, 2)` (L813) and `std.range(1, 10)` (L906).
## Required outcome
- A test that fails against the pre-fix `wgslGenerator.ts` and passes now. The PR description's `std.range(3, 0, -1)` case is ideal (expects unrolled iterations `#0`→`3i`, `#1`→`2i`, `#2`→`1i`).
- Optionally also pin the empty-but-nonzero-end case (`std.range(0, 5, -1)`), which previously crashed on `elements[0]`.
## Suggested approach
- Add an `it(...)` to `packages/typegpu/tests/unroll.test.ts` using the existing `tgpu.resolve([fn])` + `toMatchInlineSnapshot` idiom, alongside the `'unrolls a range'` test (L809).DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Added regression test for descending ranges ending at zero —
packages/typegpu/tests/tgsl/wgslGenerator.test.tsnow pinstgpu.unroll(std.range(3, 0, -1))to three unrolled iterations (3i,2i,1i) plus a CPUmain() === 6assertion. - Added regression test for empty ranges with a nonzero endpoint — pins
std.range(3, 3)to an empty body and CPUmain() === 0, covering the previouselements[0]undefinedcrash. - Both tests were verified to fail against the pre-fix generator (snapshot mismatch for the descending case;
TypeErrorinisAliasfor the empty case) and to pass with the fix. The fullwgslGenerator.test.ts(104 tests) andunroll.test.ts(28 tests) suites pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

before fix: