Skip to content
2 changes: 1 addition & 1 deletion packages/typegpu/src/tgsl/wgslGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,7 @@ ${this.ctx.pre}else ${alternate}`,
: value instanceof ArrayExpression
? value.elements
: Array.from({ length: knownEnd.value as number }, (_, i) =>
forOfUtils.getElementSnippet(iterableSnippet, snip(i, u32, 'constant')),
forOfUtils.getElementSnippet(iterableSnippet, snip(i, u32, 'constant', false)),
);

if (elements.length === 0) {
Expand Down
14 changes: 14 additions & 0 deletions packages/typegpu/tests/unroll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,4 +985,18 @@ describe('tgpu.unroll', () => {
}"
`);
});

it('does not introduce possibleSideEffects', () => {
const arr = tgpu.accessor(d.arrayOf(d.f32, 3), [1, 2, 3]);

const f = () => {
'use gpu';
for (const value of tgpu.unroll(arr.$)) {
const _known = std.isKnownAtComptime(value);
Comment thread
pullfrog[bot] marked this conversation as resolved.
}
};

const code = tgpu.resolve([f]);
expect(code).toMatchNTimes(/true/g, 3);
});
});
Loading