Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions wgsl/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -970,9 +970,24 @@ pipeline_stage
## Statements ## {#statements}

<pre class='def'>
branch_stmt
: RETURN logical_or_expression SEMICOLON
OpReturn
OpReturnValue
| break_stmt SEMICOLON
| continue_stmt SEMICOLON
| KILL SEMICOLON

body_stmt:
: BRACKET_LEFT statements BRACKET_RIGHT
| branch_stmt
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be too general as this makes it grammatically correct to say

fn foo() -> f32
   return 2.3;

Seems like we should have an if_body_stmt and then we need to update the if section so you can't do something like:

if (a)
  break;
else if (b)
  continue;
else
 kill;

as I don't think that should be allowed?

</pre>

While `body_stmt` is generally `{ statements }`, it also allows omitting brackets around some control-flow statements.
This can better preserve author intent for cases like `if (expr) break;`, where adding statements within the body block would have more semantic impact than expected.
`if (condition) { break/continue/return; }` is a common pattern where where the body block is unnecessary, since when the first statement branches/jumps, further statements in that block are unreachable.

<pre class='def'>
paren_rhs_stmt
: PAREN_LEFT logical_or_expression PAREN_RIGHT

Expand All @@ -981,17 +996,12 @@ statements

statement
: SEMICOLON
| RETURN logical_or_expression SEMICOLON
OpReturn
OpReturnValue
| branch_stmt
| if_stmt
| unless_stmt
| switch_stmt
| loop_stmt
| variable_stmt SEMICOLON
| break_stmt SEMICOLON
| continue_stmt SEMICOLON
| KILL SEMICOLON
| NOP SEMICOLON
| assignment_stmt SEMICOLON

Expand Down