feat: Mutability tracking#2390
feat: Mutability tracking#2390aleksanderkatan wants to merge 28 commits intorefactor/naming-cleanupfrom
Conversation
|
pkg.pr.new packages benchmark commit |
📊 Bundle Size Comparison
👀 Notable resultsStatic test results:No major changes. Dynamic test results:
📋 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. |
d7926fa to
5b7b6eb
Compare
…at/mutability-tracking
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.96, 3.93, 6.18, 7.27, 12.21, 21.17, 23.61]
line [0.90, 1.90, 4.04, 6.21, 6.84, 10.32, 19.39, 22.06]
line [0.94, 1.87, 4.17, 6.16, 7.07, 9.85, 21.01, 23.34]
---
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.34, 0.51, 0.68, 0.84, 1.10, 1.15, 1.49, 1.62]
line [0.29, 0.50, 0.64, 0.80, 1.06, 1.12, 1.38, 1.55]
line [0.34, 0.50, 0.65, 0.77, 1.06, 1.15, 1.43, 1.52]
---
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.85, 1.95, 4.15, 6.38, 12.59, 26.71, 55.32, 111.91]
line [0.76, 1.97, 3.93, 5.83, 11.61, 25.11, 53.42, 106.48]
line [0.77, 1.76, 3.82, 5.96, 11.86, 24.55, 53.55, 108.26]
|
5b7b6eb to
2afcfb8
Compare
…at/mutability-tracking
2afcfb8 to
d5d4be5
Compare
| if (targetType === snippet.dataType) { | ||
| return snippet; | ||
| } | ||
|
|
||
| return snip( | ||
| snippet.value, | ||
| targetType, | ||
| // if it was a ref, then it's still a ref | ||
| /* origin */ snippet.origin, | ||
| ); |
There was a problem hiding this comment.
| return snippet; |
There was a problem hiding this comment.
I know that I wrote this fragment of code, but now I think this check in unnecessary.
There was a problem hiding this comment.
I don't understand, what can be simplified? Action 'none' does not mean return as-is, but it also replaces the dataType with targetType
There was a problem hiding this comment.
Pull request overview
Implements function-scope mutability tracking so the WGSL generator can emit let for locals that are never mutated, while still emitting var when mutation is detected (closing #2356).
Changes:
- Add per-function placeholder + “modified variables” tracking to defer choosing
letvsvaruntil after the function body is generated. - Mark variables as modified on assignment/update operations and in select reference-taking cases (
ref,unroll, implicit pointer creation). - Update a large set of inline-snapshot tests to reflect
var→letwhere no mutation occurs.
Reviewed changes
Copilot reviewed 78 out of 78 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/typegpu/src/types.ts | Extends FunctionScopeLayer with placeholder + modified-variable tracking. |
| packages/typegpu/src/resolutionCtx.ts | Initializes new function-scope tracking structures when pushing a function scope. |
| packages/typegpu/src/tgsl/wgslGenerator.ts | Core implementation: emit placeholder decls, track mutations, and replace placeholders with let/var at function end. |
| packages/typegpu/src/tgsl/conversion.ts | Minor optimization: preserve snippet when no-op conversion targets the same type. |
| packages/typegpu/tests/vector.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/unroll.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgslFn.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgsl/wgslGenerator.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgsl/typeInference.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgsl/operatorOverloads.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgsl/infixOperators.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgsl/consoleLog.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/tgsl/codeGen.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/struct.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/texture/textureLoad.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/texture/textureGather.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/range.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/numeric/bitShift.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/matrix/translate.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/matrix/scale.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/matrix/rotate.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/std/boolean/not.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/slot.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/renderPipeline.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/pipeline-resolution.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/lazy.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/indent.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/computePipeline.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/array.test.ts | Snapshot updates for var → let. |
| packages/typegpu/tests/accessor.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/xor-dev-runner.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/xor-dev-centrifuge-2.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/wgsl-resolution.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/vaporrave.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/uniformity.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/two-boxes.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/tgsl-parsing-test.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/stencil.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/stable-fluid.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/square.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/smoky-triangle.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/slime-mold.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/slime-mold-3d.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/simple-shadow.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/ray-marching.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/probability.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/point-light-shadow.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/phong-reflection.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/perlin-noise.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/oklab.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/log-test.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/liquid-glass.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/lines-combinations.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/jump-flood-voronoi.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/jump-flood-distance.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/image-tuning.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/gravity.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/global-wind-map.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/game-of-life.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/function-visualizer.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/fluid-double-buffering.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/disco.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/cubemap-reflection.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/confetti.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/clouds.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/circles.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/chroma-keying.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/caustics.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/camera-thresholding.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/box-raytracing.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/boids.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/blur.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/ascii-filter.test.ts | Snapshot updates for var → let. |
| apps/typegpu-docs/tests/individual-example-tests/3d-fish.test.ts | Snapshot updates for var → let. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
We should probably test atomics as well, atomic load takes address of its argument |
Closes #2356
We could keep and propagate info about unmodified consts (WGSL
const) to handle cases like the below, but I think it is outside the scope of this PRI don't really like how this is implemented, but I see no better way. Maybe we could mark at implicit pointer dereference in
convertToCommonTypeto avoid some of the ref/unroll calls, but this requires better origin tracking.