diff --git a/wgsl/index.bs b/wgsl/index.bs index 5b3a7e6351..3bee745195 100644 --- a/wgsl/index.bs +++ b/wgsl/index.bs @@ -970,9 +970,24 @@ pipeline_stage ## Statements ## {#statements}
+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 ++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. + +
paren_rhs_stmt : PAREN_LEFT logical_or_expression PAREN_RIGHT @@ -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