fix: Better std.range internal variables type inference#2384
Merged
Conversation
std.range internal variables type inference
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:No major changes. 📋 All resultsClick to reveal the results table (350 entries).
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.93, 1.88, 4.25, 6.32, 7.08, 11.72, 21.89, 23.32]
line [0.95, 1.95, 4.06, 6.43, 7.76, 9.27, 21.76, 23.80]
line [0.91, 1.82, 3.92, 6.32, 7.37, 11.10, 21.05, 23.42]
---
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.31, 0.55, 0.76, 0.91, 1.18, 1.24, 1.48, 1.61]
line [0.29, 0.53, 0.70, 0.90, 1.16, 1.19, 1.46, 1.62]
line [0.32, 0.55, 0.68, 0.85, 1.12, 1.16, 1.40, 1.53]
---
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.80, 1.95, 4.02, 6.15, 12.23, 25.35, 55.62, 114.27]
line [0.87, 2.01, 3.96, 6.20, 12.56, 25.53, 57.26, 115.80]
line [0.83, 1.99, 3.64, 6.03, 12.20, 25.00, 57.26, 112.25]
|
There was a problem hiding this comment.
Pull request overview
This PR improves WGSL generation for for ... of ... loops over std.range by inferring the loop/index variable’s integer type (signed vs unsigned) from the range parameters, and updates/adds snapshots to cover the intended output.
Changes:
- Infer
std.rangeloop variable type asu32for non-negative ranges (instead of alwaysi32). - Update WGSL generator to use the inferred range type when binding the user loop variable.
- Add/adjust tests and inline snapshots to validate
std.rangefor ... of ...codegen.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/typegpu/src/tgsl/forOfUtils.ts | Changes range snippet typing logic (i32/u32 inference for start/end/step). |
| packages/typegpu/src/tgsl/wgslGenerator.ts | Uses the inferred range snippet type when exposing the loop variable inside the loop body. |
| packages/typegpu/tests/std/range.test.ts | Updates GPU snapshot expectation to match new unsigned range loop generation. |
| packages/typegpu/tests/tgsl/wgslGenerator.test.ts | Adds a test asserting correct for ... of std.range(n) WGSL output and typing. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
aleksanderkatan
approved these changes
Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.