schell / schell/wgsl-rs

`for i in 0..1 { let x: u32 = i+1; }` compiles successfully but generates invalid wgsl

Open
#154 1 comment 0 reactions 0 assignees View on GitHub
bug P2
Dominant language
Rust
Stars
61
Forks
4
Avg merge
1d 21h
Merged PRs (30d)
9

Description

if you write:
```rust
#[wgsl]
pub my_shader{
// ...
for i in 0..1{
let x: u32 = i+1;
}
// ...
}
```
it compiles successfully, but when you try to run the wgsl shader:
```
Shader validation error: Entry point compute at Compute is invalid
┌─ compute:839:21

839 │ let x:u32 = i+1;
│ ^^^^ naga::ir::Expression [40]

= Expression [40] is invalid
= Operation Add can't work with [20] (of type Scalar(Scalar { kind: Uint, width: 4 })) and [39] (of type Scalar(Scalar { kind: Sint, width: 4 }))
```

If you try
```rust
#[wgsl]
pub my_shader{
// ...
for i in 0..1u32{
let x: u32 = i+1;
}
// ...
}
```
The generated wgsl loop var and the condition have different types:
```
Shader validation error: Entry point compute at Compute is invalid
┌─ compute:838:21

838 │ for (var i = 0; i < 1u; i++) {
│ ^^^^^^ naga::ir::Expression [37]

= Expression [37] is invalid
```

To get it to work you have to write:
```rust
#[wgsl]
pub my_shader{
// ...
for i in 0u32..1u32{
let x: u32 = i+1;
}
// ...
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the #[wgsl] loop expansion that produces the generated WGSL shown in the report, and trace how range bounds and the loop variable types are inferred. Reproduce both failing examples, then verify that generated loops using u32 bounds validate successfully without requiring redundant casts.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.