-
Notifications
You must be signed in to change notification settings - Fork 340
Add break-if as optional at end of continuing #2618
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4984,6 +4984,12 @@ from the start of the next statement until the end of the compound statement. | |
| [=syntax/brace_left=] [=syntax/statement=] * [=syntax/brace_right=] | ||
</div> | ||
|
||
There are two special forms of compound statement: | ||
* a [=syntax/continuing_compound_statement=] forms the body of a [[#continuing-statement|continuing]] statement, | ||
and allows an optional [[#break-if-statement|break-if]] statement at the end. | ||
* a [=syntax/case_compound_statement=] forms the body of a `case` or `default` clause in a [[#switch-statement|switch]] statement, | ||
and allows an optional [=syntax/fallthrough_statement|fallthrough=] statement at the end. | ||
|
||
## Assignment Statement ## {#assignment} | ||
|
||
An <dfn noexport dfn-for="statement">assignment</dfn> evaluates an expression, | ||
|
@@ -5338,19 +5344,22 @@ An `if` statement is executed as follows: | |
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>switch_body</dfn> : | ||
|
||
| [=syntax/case=] [=syntax/case_selectors=] [=syntax/colon=] [=syntax/brace_left=] [=syntax/case_body=] ? [=syntax/brace_right=] | ||
| [=syntax/case=] [=syntax/case_selectors=] [=syntax/colon=] [=syntax/case_compound_statement=] | ||
|
||
| [=syntax/default=] [=syntax/colon=] [=syntax/brace_left=] [=syntax/case_body=] ? [=syntax/brace_right=] | ||
| [=syntax/default=] [=syntax/colon=] [=syntax/case_compound_statement=] | ||
</div> | ||
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>case_selectors</dfn> : | ||
|
||
| [=syntax/const_literal=] ( [=syntax/comma=] [=syntax/const_literal=] ) * [=syntax/comma=] ? | ||
</div> | ||
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>case_body</dfn> : | ||
<dfn for=syntax>case_compound_statement</dfn> : | ||
|
||
| [=syntax/statement=] [=syntax/case_body=] ? | ||
| [=syntax/brace_left=] [=syntax/statement=] * [=syntax/fallthrough_statement=] ? [=syntax/brace_right=] | ||
</div> | ||
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>fallthrough_statement</dfn> : | ||
|
||
| [=syntax/fallthrough=] [=syntax/semicolon=] | ||
</div> | ||
|
@@ -5609,19 +5618,13 @@ The following statement forms are equivalent: | |
A <dfn noexport dfn-for="statement">break</dfn> statement transfers control to the first statement | ||
after the body of the nearest-enclosing [=statement/loop=] | ||
or [=statement/switch=] statement. | ||
A `break` statement must only be used within [=statement/loop=], [=statement/for=], and [=statement/switch=] statements. | ||
|
||
When a `break` statement is placed such that it would exit from a loop's [=statement/continuing=] statement, | ||
then: | ||
A `break` statement must only be used within [=statement/loop=], [=statement/for=], and [=statement/switch=] statements. | ||
|
||
* The `break` statement must appear as either: | ||
* The only statement in the `if` clause of an `if` statement that has: | ||
* no `else` clause or an empty `else` clause | ||
* no `else if` clauses | ||
* The only statement in the `else` clause of an `if` statement that has an empty `if` clause and no `else if` clauses. | ||
* That `if` statement must appear last in the `continuing` clause. | ||
A `break` statement must not placed such that it would exit from a loop's [[#continuing-statement|continuing]] statement. | ||
dneto0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Use a [[#break-if-statement|break-if]] statement instead. | ||
|
||
<div class='example wgsl function-scope' heading="WGSL Valid loop if-break from a continuing clause"> | ||
<div class='example wgsl function-scope' heading="WGSL Invalid loop break from a continuing clause"> | ||
<xmp> | ||
var a: i32 = 2; | ||
var i: i32 = 0; | ||
|
@@ -5634,36 +5637,30 @@ then: | |
|
||
continuing { | ||
i = i + step; | ||
if i >= 4 { break; } | ||
if i >= 4 { break; } // Invalid. Use break-if instead. | ||
} | ||
} | ||
</xmp> | ||
</div> | ||
|
||
<div class='example wgsl function-scope' heading="WGSL Valid loop if-else-break from a continuing clause"> | ||
<xmp> | ||
var a: i32 = 2; | ||
var i: i32 = 0; | ||
loop { | ||
let step: i32 = 1; | ||
### Break-If Statement ### {#break-if-statement} | ||
|
||
if i % 2 == 0 { continue; } | ||
|
||
a = a * 2; | ||
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>break_if_statement</dfn> : | ||
|
||
continuing { | ||
i = i + step; | ||
if i < 4 {} else { break; } | ||
} | ||
} | ||
</xmp> | ||
| [=syntax/break=] [=syntax/if=] [=syntax/expression=] [=syntax/semicolon=] | ||
</div> | ||
|
||
<div class='example wgsl function-scope expect-error' heading="WGSL Invalid breaks from a continuing clause"> | ||
A <dfn noexport dfn-for="statement">break-if</dfn> statement evaluates a boolean condition, and if the condition | ||
is true, transfers control to the first statement after the body of the nearest-enclosing [=statement/loop=] statement. | ||
|
||
|
||
Note: A break-if statement may only appear as the last statement in the body of a [[#continuing-statement|continuing]] | ||
statement. | ||
|
||
<div class='example wgsl function-scope' heading="WGSL Valid loop break-if from a continuing clause"> | ||
<xmp> | ||
var a: i32 = 2; | ||
var i: i32 = 0; | ||
|
||
loop { | ||
let step: i32 = 1; | ||
|
||
|
@@ -5673,9 +5670,7 @@ then: | |
|
||
continuing { | ||
i = i + step; | ||
break; // Invalid: too early | ||
if i < 4 { i++; } else { break; } // Invalid: if is too complex, and too early | ||
if i >= 4 { break; } else { i++; } // Invalid: if is too complex | ||
break if i >= 4; | ||
} | ||
} | ||
</xmp> | ||
|
@@ -5724,7 +5719,13 @@ control past a declaration used in the targeted [=statement/continuing=] stateme | |
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>continuing_statement</dfn> : | ||
|
||
| [=syntax/continuing=] [=syntax/compound_statement=] | ||
| [=syntax/continuing=] [=syntax/continuing_compound_statement=] | ||
</div> | ||
|
||
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>continuing_compound_statement</dfn> : | ||
|
||
| [=syntax/brace_left=] [=syntax/statement=] * [=syntax/break_if_statement=] ? [=syntax/brace_right=] | ||
</div> | ||
|
||
A <dfn dfn-for="statement">continuing</dfn> statement specifies a [=compound statement=] to be executed at the end of a loop [=iteration=]. | ||
|
@@ -5818,6 +5819,8 @@ Note: If the function [=return value|returns a value=], that value is ignored. | |
|
||
## Statements Grammar Summary ## {#statements-summary} | ||
|
||
The [=syntax/statement=] rule matches statements that can be used in most places inside a function body. | ||
|
||
<div class='syntax' noexport='true'> | ||
<dfn for=syntax>statement</dfn> : | ||
|
||
|
@@ -5854,6 +5857,11 @@ Note: If the function [=return value|returns a value=], that value is ignored. | |
| [=syntax/decrement_statement=] [=syntax/semicolon=] | ||
</div> | ||
|
||
Additionally, certain statements may only be used in very specific contexts: | ||
* [=syntax/break_if_statement=] | ||
* [=syntax/case_compound_statement=] | ||
* [=syntax/continuing_compound_statement=] | ||
* [=syntax/fallthrough_statement=] | ||
|
||
## Statements Behavior Analysis ## {#behaviors} | ||
|
||
|
@@ -5959,6 +5967,10 @@ The reason is that only functions without a return type can have such a [=behavi | |
<td>break; | ||
<td> | ||
<td>{Break} | ||
<tr algorithm="break if behavior"> | ||
dneto0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<td>break if |e|; | ||
<td class="nowrap">|e|: |B| | ||
<td>|B| ∪ {Break} | ||
<tr algorithm="continue behavior"> | ||
<td>continue; | ||
<td> | ||
|
Uh oh!
There was an error while loading. Please reload this page.