这是indexloc提供的服务,不要输入任何密码
Skip to content

wgsl: Statement must not be only a type-constructor. #3819

@dneto0

Description

@dneto0

We'd like to reconsider part of #3813

We'd like to disallow the a statement whose top-level thing is a type-constructor expression.

Example:

struct S { a: i32 }
fn foo_bad() {
    i32();  // This parses, but we should disallow this.  
    S(15);  // This parses, but we should disallow this.
    42;     // Already disallowed; this doesn't even parse in the first place.
}

A type-constructor does not have side effects (once you've evaluated its arguments). So there is no use for it.

If you really want to evaluate a type constructor, then use a phone assignment, even though that is silly: _ = i32();

We do explicitly allow function calls as statements. The desirable use case is to capture the side effects, like this:

var<workgroup> p: i32;
fn foo_ok() {
    workgroupBarrier();  // allowed
    atomicStore(&p, 0); // allowed
    my_helper_does_something(); // allowed, whether or not the helper returns a value.
}

Metadata

Metadata

Assignees

Labels

wgslWebGPU Shading Language Issues

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions