Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wgsl-in] Redefinition incorrectly passes validation #1480

Closed
Herschel opened this issue Oct 26, 2021 · 2 comments
Closed

[wgsl-in] Redefinition incorrectly passes validation #1480

Herschel opened this issue Oct 26, 2021 · 2 comments
Labels
area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language

Comments

@Herschel
Copy link

Herschel commented Oct 26, 2021

Naga allows reusing a name in the same scope:

fn foo() {}
fn foo() {}

[[block]]
struct Globals {
    bar: vec4<f32>;
};

[[group(0), binding(0)]]
var<uniform> a: Globals;
[[group(0), binding(1)]]
var<uniform> a: Globals;

This passes validation in Naga, but this is not allowed by the WGSL spec:

A declaration must not introduce a name when that identifier is already in scope with the same end scope as another instance of that name.

Tint rejects the code with this message:

d:\projects\naga\color.wgsl:2:1 error: redefinition of 'foo'
fn foo() {}
^^

d:\projects\naga\color.wgsl:1:1 note: previous definition is here
fn foo() {}
^^

I hit this because learn wgpu book uses main for both vertex and fragment entry points. Tint disagrees with this, so I was caught by surprise when my shader worked in wgpu desktop but not Chrome.

naga @ 5cf11ab

@Herschel
Copy link
Author

Sorry, just noticed this is somewhat of a dupe of #1044 and #1454. However, those issues discuss local variable shadowing, but the issue also occurs at module scope.

@JCapucho JCapucho added area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language labels Oct 26, 2021
Bobo1239 added a commit to Bobo1239/wgpu that referenced this issue Nov 15, 2021
From the spec: "A declaration must not introduce a name when that
identifier is already in scope with the same end scope as another
instance of that name."

naga doesn't yet check this (gfx-rs/naga#1480) but Chrome/Tint rightly
complains with: error: redefinition of 'main'
kvark pushed a commit to gfx-rs/wgpu that referenced this issue Nov 17, 2021
From the spec: "A declaration must not introduce a name when that
identifier is already in scope with the same end scope as another
instance of that name."

naga doesn't yet check this (gfx-rs/naga#1480) but Chrome/Tint rightly
complains with: error: redefinition of 'main'
@jimblandy
Copy link
Member

I think this was fixed in dba6beb. If that's not the case, please re-open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: front-end Input formats for conversion kind: bug Something isn't working lang: WGSL WebGPU shading language
Projects
None yet
Development

No branches or pull requests

3 participants