Skip to content

wgsl: grammar for LHS is ambiguous about grouping its subexpressions, affects type checking #3530

@dneto0

Description

@dneto0

The grammar change for assignments, from #2265, is unintentionally too restrictive, and leads to ambiguous type-check.

lhs_expression :
| ( star | and ) * core_lhs_expression component_or_swizzle_specifier ?

core_lhs_expression :
| ident

| paren_left lhs_expression paren_right

Problem 1: m[0][1] = 1; should parse, but the grammar says it shouldn't. There is no way to chain component_or_swizzle_specifiers.

Problem 2 is in the structure of lhs_expression itself. It doesn't say whether we're forming expressions left-associatively or right-associatively:

  • if left-associatively, then we're binding the & and * operators to the core_lhs_expression first, and then applying the effect of the component_or_swizzle_specifier
  • if right-associatively, then we're applying the component_or_swizzle_specifier to the core_lhs_expression first, and then applying indirections and address-ofs.

Example:

fn foo() {
  var m: mat2x2<f32>; 
  let p = &m; 
  *p[0] = m[1];
} 

Is that LHS parsed and type checked as (*p)[0] which will then work, or is it parsed as *(p[0]) which will fail type-check due to #1580 not being supported.


edit: Problem 1 doesn't exist. I was missed the recursive nature of component_or_swizzle_specifier

Metadata

Metadata

Assignees

No one assigned

    Labels

    wgslWebGPU Shading Language Issueswgsl resolvedResolved - waiting for a change to the WGSL specification

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions