Skip to content

Conversation

@aleksanderkatan
Copy link
Contributor

@aleksanderkatan aleksanderkatan commented Dec 15, 2025

wgslGenerator.ts

// Logical/Binary/Assignment Expression
const [exprType, lhs, op, rhs] = expression;
const lhsExpr = this.expression(lhs);

After this, the lhsExpression already is a constant snippet, so I decided to just update the error message for assigning to a constant.

Case 1:

let a = undefined;
const f = tgpu.fn([])(() => {
  a = 2;
});

as was before, an error Identifier a not found is thrown.

Case 2:

let a = 0;
const f = tgpu.fn([])(() => {
  a = 2;
});

Now the error message is '${lhsStr} = ${rhsStr}' is invalid, because ${lhsStr} is a constant. This error may also occur when assigning to a value defined outside of a TypeGPU function's scope.

@aleksanderkatan aleksanderkatan linked an issue Dec 15, 2025 that may be closed by this pull request
@github-actions
Copy link

github-actions bot commented Dec 15, 2025

pkg.pr.new

packages
Ready to be installed by your favorite package manager ⬇️

https://pkg.pr.new/software-mansion/TypeGPU/typegpu@cf6dac45754231060405289d811e165648715939
https://pkg.pr.new/software-mansion/TypeGPU/@typegpu/noise@cf6dac45754231060405289d811e165648715939
https://pkg.pr.new/software-mansion/TypeGPU/unplugin-typegpu@cf6dac45754231060405289d811e165648715939

benchmark
view benchmark

commit
view commit

@cieplypolar
Copy link
Collaborator

cieplypolar commented Dec 18, 2025

I am not sure if this is proper way to detect 'assignment to variables defined outside TGSL'. We are adding support for 'for ... of ...' loop, so tinyest will change. Maybe you'll find a better place for that in tinyest parsers?

EDIT: Nevermind, too much work for 1 error. LGTM

@github-actions
Copy link

github-actions bot commented Jan 12, 2026

## 📊 Bundle Size Comparison
🟢 Decreased ➖ Unchanged 🔴 Increased ❔ Unknown
0 309 15 0

👀 Notable results

Static test results:

No major changes.

Dynamic test results:

No major changes.

📋 All results

Click to reveal the results table (323 entries).
Test tsdown
dataImportEverything.ts 80.03 kB (➖)
dataImportOneDirect.ts 40.28 kB (➖)
dataImportOneStar.ts 40.28 kB (➖)
functionWithUseGpu.ts 268 B (➖)
functionWithoutUseGpu.ts 24 B (➖)
importEntireLibrary.ts 256.83 kB ($${\color{red}+0.0\%}$$)
stdImportEverything.ts 113.10 kB (➖)
stdImportOneDirect.ts 61.97 kB (➖)
stdImportOneStar.ts 61.97 kB (➖)
tgpuImportEverything.ts 237.83 kB ($${\color{red}+0.0\%}$$)
tgpuImportOne.ts 237.84 kB ($${\color{red}+0.0\%}$$)
MissingBindGroupsError from typegpu.ts 1.06 kB (➖)
MissingLinksError from typegpu.ts 208 B (➖)
MissingSlotValueError from typegpu.ts 153 B (➖)
MissingVertexBuffersError from typegpu.ts 1.07 kB (➖)
NotUniformError from typegpu.ts 1.02 kB (➖)
ResolutionError from typegpu.ts 1.26 kB (➖)
Void from typegpudata.ts 610 B (➖)
abs from typegpustd.ts 79.52 kB (➖)
acos from typegpustd.ts 79.52 kB (➖)
acosh from typegpustd.ts 79.52 kB (➖)
add from typegpustd.ts 61.97 kB (➖)
align from typegpudata.ts 41.96 kB (➖)
alignmentOf from typegpudata.ts 38.37 kB (➖)
allEq from typegpustd.ts 64.32 kB (➖)
all from typegpustd.ts 64.32 kB (➖)
and from typegpustd.ts 64.32 kB (➖)
any from typegpustd.ts 64.33 kB (➖)
arrayLength from typegpustd.ts 10.82 kB (➖)
arrayOf from typegpudata.ts 42.41 kB (➖)
asin from typegpustd.ts 79.52 kB (➖)
asinh from typegpustd.ts 79.52 kB (➖)
atan2 from typegpustd.ts 79.52 kB (➖)
atan from typegpustd.ts 79.52 kB (➖)
atanh from typegpustd.ts 79.52 kB (➖)
atomicAdd from typegpustd.ts 12.33 kB (➖)
atomicAnd from typegpustd.ts 12.33 kB (➖)
atomicLoad from typegpustd.ts 12.32 kB (➖)
atomicMax from typegpustd.ts 12.33 kB (➖)
atomicMin from typegpustd.ts 12.33 kB (➖)
atomicOr from typegpustd.ts 12.33 kB (➖)
atomicStore from typegpustd.ts 12.33 kB (➖)
atomicSub from typegpustd.ts 12.33 kB (➖)
atomicXor from typegpustd.ts 12.33 kB (➖)
atomic from typegpudata.ts 649 B (➖)
bitcastU32toF32 from typegpustd.ts 59.73 kB (➖)
bitcastU32toI32 from typegpustd.ts 59.74 kB (➖)
bool from typegpudata.ts 10.36 kB (➖)
builtin from typegpudata.ts 44.77 kB (➖)
ceil from typegpustd.ts 79.52 kB (➖)
clamp from typegpustd.ts 79.52 kB (➖)
comparisonSampler from typegpudata.ts 629 B (➖)
cos from typegpustd.ts 79.52 kB (➖)
cosh from typegpustd.ts 79.52 kB (➖)
countLeadingZeros from typegpustd.ts 79.52 kB (➖)
countOneBits from typegpustd.ts 79.52 kB (➖)
countTrailingZeros from typegpustd.ts 79.52 kB (➖)
cross from typegpustd.ts 79.52 kB (➖)
deepEqual from typegpudata.ts 2.49 kB (➖)
degrees from typegpustd.ts 79.52 kB (➖)
determinant from typegpustd.ts 79.52 kB (➖)
disarrayOf from typegpudata.ts 39.17 kB (➖)
discard from typegpustd.ts 8.97 kB (➖)
distance from typegpustd.ts 79.52 kB (➖)
div from typegpustd.ts 61.97 kB (➖)
dot4I8Packed from typegpustd.ts 79.52 kB (➖)
dot4U8Packed from typegpustd.ts 79.52 kB (➖)
dot from typegpustd.ts 79.51 kB (➖)
dpdxCoarse from typegpustd.ts 9.77 kB (➖)
dpdxFine from typegpustd.ts 9.77 kB (➖)
dpdx from typegpustd.ts 9.77 kB (➖)
dpdyCoarse from typegpustd.ts 9.77 kB (➖)
dpdyFine from typegpustd.ts 9.77 kB (➖)
dpdy from typegpustd.ts 9.77 kB (➖)
eq from typegpustd.ts 64.32 kB (➖)
exp2 from typegpustd.ts 79.52 kB (➖)
exp from typegpustd.ts 79.52 kB (➖)
extensionEnabled from typegpustd.ts 12.03 kB (➖)
extractBits from typegpustd.ts 79.52 kB (➖)
f16 from typegpudata.ts 10.36 kB (➖)
f32 from typegpudata.ts 10.36 kB (➖)
faceForward from typegpustd.ts 79.52 kB (➖)
firstLeadingBit from typegpustd.ts 79.52 kB (➖)
firstTrailingBit from typegpustd.ts 79.52 kB (➖)
float16 from typegpudata.ts 36.56 kB (➖)
float16x2 from typegpudata.ts 36.56 kB (➖)
float16x4 from typegpudata.ts 36.56 kB (➖)
float32 from typegpudata.ts 36.56 kB (➖)
float32x2 from typegpudata.ts 36.56 kB (➖)
float32x3 from typegpudata.ts 36.56 kB (➖)
float32x4 from typegpudata.ts 36.56 kB (➖)
floor from typegpustd.ts 79.52 kB (➖)
fma from typegpustd.ts 79.52 kB (➖)
formatToWGSLType from typegpudata.ts 37.08 kB (➖)
fract from typegpustd.ts 79.52 kB (➖)
frexp from typegpustd.ts 79.52 kB (➖)
fwidthCoarse from typegpustd.ts 9.77 kB (➖)
fwidthFine from typegpustd.ts 9.77 kB (➖)
fwidth from typegpustd.ts 9.77 kB (➖)
ge from typegpustd.ts 64.32 kB (➖)
gt from typegpustd.ts 64.33 kB (➖)
i32 from typegpudata.ts 10.36 kB (➖)
identity2 from typegpustd.ts 42.86 kB (➖)
identity3 from typegpustd.ts 42.86 kB (➖)
identity4 from typegpustd.ts 42.86 kB (➖)
insertBits from typegpustd.ts 79.52 kB (➖)
interpolate from typegpudata.ts 41.96 kB (➖)
invariant from typegpudata.ts 42.33 kB (➖)
inverseSqrt from typegpustd.ts 79.52 kB (➖)
isAlignAttrib from typegpudata.ts 631 B (➖)
isAtomic from typegpudata.ts 631 B (➖)
isBufferShorthand from typegpu.ts 1.39 kB (➖)
isBuffer from typegpu.ts 96.76 kB (➖)
isBuiltinAttrib from typegpudata.ts 633 B (➖)
isBuiltin from typegpudata.ts 40.37 kB (➖)
isCloseTo from typegpustd.ts 64.33 kB (➖)
isComparisonSampler from typegpu.ts 64.03 kB (➖)
isData from typegpudata.ts 2.10 kB (➖)
isDecorated from typegpudata.ts 634 B (➖)
isDerived from typegpu.ts 71 B (➖)
isDisarray from typegpudata.ts 1.40 kB (➖)
isInterpolateAttrib from typegpudata.ts 637 B (➖)
isLocationAttrib from typegpudata.ts 634 B (➖)
isLooseData from typegpudata.ts 1.44 kB (➖)
isLooseDecorated from typegpudata.ts 1.41 kB (➖)
isPackedData from typegpudata.ts 37.15 kB (➖)
isPtr from typegpudata.ts 628 B (➖)
isSampler from typegpu.ts 64.02 kB (➖)
isSizeAttrib from typegpudata.ts 630 B (➖)
isSlot from typegpu.ts 68 B (➖)
isTexture from typegpu.ts 64.01 kB (➖)
isTgpuFn from typegpu.ts 641 B (➖)
isUnstruct from typegpudata.ts 1.40 kB (➖)
isUsableAsRender from typegpu.ts 62 B (➖)
isUsableAsSampled from typegpu.ts 63 B (➖)
isUsableAsStorage from typegpu.ts 63 B (➖)
isUsableAsUniform from typegpu.ts 64.77 kB (➖)
isUsableAsVertex from typegpu.ts 96.76 kB (➖)
isVariable from typegpu.ts 65.76 kB (➖)
isWgslArray from typegpudata.ts 630 B (➖)
isWgslData from typegpudata.ts 1.19 kB (➖)
isWgslStruct from typegpudata.ts 631 B (➖)
ldexp from typegpustd.ts 79.52 kB (➖)
le from typegpustd.ts 64.33 kB (➖)
length from typegpustd.ts 79.51 kB (➖)
location from typegpudata.ts 41.96 kB (➖)
log2 from typegpustd.ts 79.52 kB (➖)
log from typegpustd.ts 79.52 kB (➖)
lt from typegpustd.ts 64.32 kB (➖)
mat2x2f from typegpudata.ts 42.86 kB (➖)
mat3x3f from typegpudata.ts 42.86 kB (➖)
mat4x4f from typegpudata.ts 42.85 kB (➖)
matToArray from typegpudata.ts 42.99 kB (➖)
max from typegpustd.ts 79.52 kB (➖)
min from typegpustd.ts 79.52 kB (➖)
mix from typegpustd.ts 79.52 kB (➖)
mod from typegpustd.ts 61.97 kB (➖)
modf from typegpustd.ts 79.52 kB (➖)
mul from typegpustd.ts 61.97 kB (➖)
ne from typegpustd.ts 64.32 kB (➖)
neg from typegpustd.ts 61.97 kB (➖)
normalize from typegpustd.ts 79.52 kB (➖)
not from typegpustd.ts 64.32 kB (➖)
or from typegpustd.ts 64.32 kB (➖)
pack2x16float from typegpustd.ts 51.30 kB (➖)
pack4x8unorm from typegpustd.ts 51.30 kB (➖)
packedFormats from typegpudata.ts 37.11 kB (➖)
pow from typegpustd.ts 79.52 kB (➖)
ptrFn from typegpudata.ts 735 B (➖)
ptrHandle from typegpudata.ts 727 B (➖)
ptrPrivate from typegpudata.ts 734 B (➖)
ptrStorage from typegpudata.ts 732 B (➖)
ptrUniform from typegpudata.ts 728 B (➖)
ptrWorkgroup from typegpudata.ts 736 B (➖)
quantizeToF16 from typegpustd.ts 79.52 kB (➖)
radians from typegpustd.ts 79.52 kB (➖)
ref from typegpudata.ts 3.73 kB (➖)
reflect from typegpustd.ts 79.52 kB (➖)
refract from typegpustd.ts 79.52 kB (➖)
reverseBits from typegpustd.ts 79.52 kB (➖)
rotateX4 from typegpustd.ts 62.76 kB (➖)
rotateY4 from typegpustd.ts 62.76 kB (➖)
rotateZ4 from typegpustd.ts 62.76 kB (➖)
rotationX4 from typegpustd.ts 42.86 kB (➖)
rotationY4 from typegpustd.ts 42.86 kB (➖)
rotationZ4 from typegpustd.ts 42.86 kB (➖)
round from typegpustd.ts 79.52 kB (➖)
sampler from typegpudata.ts 618 B (➖)
saturate from typegpustd.ts 79.52 kB (➖)
scale4 from typegpustd.ts 62.76 kB (➖)
scaling4 from typegpustd.ts 42.86 kB (➖)
select from typegpustd.ts 64.33 kB (➖)
sign from typegpustd.ts 79.52 kB (➖)
sin from typegpustd.ts 79.52 kB (➖)
sinh from typegpustd.ts 79.52 kB (➖)
sint16 from typegpudata.ts 36.56 kB (➖)
sint16x2 from typegpudata.ts 36.56 kB (➖)
sint16x4 from typegpudata.ts 36.56 kB (➖)
sint32 from typegpudata.ts 36.56 kB (➖)
sint32x2 from typegpudata.ts 36.56 kB (➖)
sint32x3 from typegpudata.ts 36.56 kB (➖)
sint32x4 from typegpudata.ts 36.56 kB (➖)
sint8 from typegpudata.ts 36.56 kB (➖)
sint8x2 from typegpudata.ts 36.56 kB (➖)
sint8x4 from typegpudata.ts 36.56 kB (➖)
sizeOf from typegpudata.ts 40.29 kB (➖)
size from typegpudata.ts 41.96 kB (➖)
smoothstep from typegpustd.ts 79.52 kB (➖)
snorm16 from typegpudata.ts 36.56 kB (➖)
snorm16x2 from typegpudata.ts 36.56 kB (➖)
snorm16x4 from typegpudata.ts 36.56 kB (➖)
snorm8 from typegpudata.ts 36.56 kB (➖)
snorm8x2 from typegpudata.ts 36.56 kB (➖)
snorm8x4 from typegpudata.ts 36.56 kB (➖)
sqrt from typegpustd.ts 79.52 kB (➖)
step from typegpustd.ts 79.52 kB (➖)
storageBarrier from typegpustd.ts 12.33 kB (➖)
struct from typegpudata.ts 39.17 kB (➖)
sub from typegpustd.ts 61.97 kB (➖)
subgroupAdd from typegpustd.ts 39.28 kB (➖)
subgroupAll from typegpustd.ts 39.29 kB (➖)
subgroupAnd from typegpustd.ts 39.29 kB (➖)
subgroupAny from typegpustd.ts 39.29 kB (➖)
subgroupBallot from typegpustd.ts 39.29 kB (➖)
subgroupBroadcastFirst from typegpustd.ts 39.29 kB (➖)
subgroupBroadcast from typegpustd.ts 39.29 kB (➖)
subgroupElect from typegpustd.ts 39.29 kB (➖)
subgroupExclusiveAdd from typegpustd.ts 39.29 kB (➖)
subgroupExclusiveMul from typegpustd.ts 39.29 kB (➖)
subgroupInclusiveAdd from typegpustd.ts 39.29 kB (➖)
subgroupInclusiveMul from typegpustd.ts 39.29 kB (➖)
subgroupMax from typegpustd.ts 39.29 kB (➖)
subgroupMin from typegpustd.ts 39.29 kB (➖)
subgroupMul from typegpustd.ts 39.29 kB (➖)
subgroupOr from typegpustd.ts 39.29 kB (➖)
subgroupShuffleDown from typegpustd.ts 39.29 kB (➖)
subgroupShuffleUp from typegpustd.ts 39.29 kB (➖)
subgroupShuffleXor from typegpustd.ts 39.29 kB (➖)
subgroupShuffle from typegpustd.ts 39.29 kB (➖)
subgroupXor from typegpustd.ts 39.29 kB (➖)
tan from typegpustd.ts 79.52 kB (➖)
tanh from typegpustd.ts 79.52 kB (➖)
texture1d from typegpudata.ts 10.82 kB (➖)
texture2dArray from typegpudata.ts 10.84 kB (➖)
texture2d from typegpudata.ts 10.82 kB (➖)
texture3d from typegpudata.ts 10.82 kB (➖)
textureBarrier from typegpustd.ts 12.33 kB (➖)
textureCubeArray from typegpudata.ts 10.84 kB (➖)
textureCube from typegpudata.ts 10.82 kB (➖)
textureDepth2dArray from typegpudata.ts 10.83 kB (➖)
textureDepth2d from typegpudata.ts 10.81 kB (➖)
textureDepthCubeArray from typegpudata.ts 10.83 kB (➖)
textureDepthCube from typegpudata.ts 10.81 kB (➖)
textureDepthMultisampled2d from typegpudata.ts 10.83 kB (➖)
textureDimensions from typegpustd.ts 39.91 kB (➖)
textureExternal from typegpudata.ts 749 B (➖)
textureLoad from typegpustd.ts 39.91 kB (➖)
textureMultisampled2d from typegpudata.ts 10.84 kB (➖)
textureSampleBaseClampToEdge from typegpustd.ts 39.91 kB (➖)
textureSampleBias from typegpustd.ts 39.91 kB (➖)
textureSampleCompare from typegpustd.ts 39.91 kB (➖)
textureSampleLevel from typegpustd.ts 39.91 kB (➖)
textureSample from typegpustd.ts 39.91 kB (➖)
textureStorage1d from typegpudata.ts 913 B (➖)
textureStorage2dArray from typegpudata.ts 931 B (➖)
textureStorage2d from typegpudata.ts 913 B (➖)
textureStorage3d from typegpudata.ts 913 B (➖)
textureStore from typegpustd.ts 39.91 kB (➖)
tgpu.bindGroupLayout from typegpu.ts 237.86 kB ($${\color{red}+0.0\%}$$)
tgpu.const from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu.fn from typegpu.ts 237.84 kB ($${\color{red}+0.0\%}$$)
tgpu.initFromDevice from typegpu.ts 237.86 kB ($${\color{red}+0.0\%}$$)
tgpu.init from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu.privateVar from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu.resolveWithContext from typegpu.ts 237.86 kB ($${\color{red}+0.0\%}$$)
tgpu.resolve from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu.slot from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu.vertexLayout from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu.workgroupVar from typegpu.ts 237.85 kB ($${\color{red}+0.0\%}$$)
tgpu from typegpu.ts 237.84 kB ($${\color{red}+0.0\%}$$)
translate4 from typegpustd.ts 62.76 kB (➖)
translation4 from typegpustd.ts 42.86 kB (➖)
transpose from typegpustd.ts 79.52 kB (➖)
trunc from typegpustd.ts 79.52 kB (➖)
u16 from typegpudata.ts 10.39 kB (➖)
u32 from typegpudata.ts 10.36 kB (➖)
uint16 from typegpudata.ts 36.56 kB (➖)
uint16x2 from typegpudata.ts 36.56 kB (➖)
uint16x4 from typegpudata.ts 36.56 kB (➖)
uint32 from typegpudata.ts 36.56 kB (➖)
uint32x2 from typegpudata.ts 36.56 kB (➖)
uint32x3 from typegpudata.ts 36.56 kB (➖)
uint32x4 from typegpudata.ts 36.56 kB (➖)
uint8 from typegpudata.ts 36.56 kB (➖)
uint8x2 from typegpudata.ts 36.56 kB (➖)
uint8x4 from typegpudata.ts 36.56 kB (➖)
unorm10 10 10 2 from typegpudata.ts 36.56 kB (➖)
unorm16 from typegpudata.ts 36.56 kB (➖)
unorm16x2 from typegpudata.ts 36.56 kB (➖)
unorm16x4 from typegpudata.ts 36.56 kB (➖)
unorm8 from typegpudata.ts 36.56 kB (➖)
unorm8x2 from typegpudata.ts 36.56 kB (➖)
unorm8x4 bgra from typegpudata.ts 36.56 kB (➖)
unorm8x4 from typegpudata.ts 36.56 kB (➖)
unpack2x16float from typegpustd.ts 51.30 kB (➖)
unpack4x8unorm from typegpustd.ts 51.30 kB (➖)
unstruct from typegpudata.ts 37.43 kB (➖)
vec2b from typegpudata.ts 35.80 kB (➖)
vec2f from typegpudata.ts 35.80 kB (➖)
vec2h from typegpudata.ts 35.80 kB (➖)
vec2i from typegpudata.ts 35.80 kB (➖)
vec2u from typegpudata.ts 35.80 kB (➖)
vec3b from typegpudata.ts 35.80 kB (➖)
vec3f from typegpudata.ts 35.80 kB (➖)
vec3h from typegpudata.ts 35.80 kB (➖)
vec3i from typegpudata.ts 35.80 kB (➖)
vec3u from typegpudata.ts 35.80 kB (➖)
vec4b from typegpudata.ts 35.80 kB (➖)
vec4f from typegpudata.ts 35.80 kB (➖)
vec4h from typegpudata.ts 35.80 kB (➖)
vec4i from typegpudata.ts 35.80 kB (➖)
vec4u from typegpudata.ts 35.80 kB (➖)
workgroupBarrier from typegpustd.ts 12.33 kB (➖)

If you wish to run a comparison for other, slower bundlers, run the 'Tree-shake test' from the GitHub Actions menu.

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.

fix: Assignment to values from outer scope

3 participants