Skip to content

Commit

Permalink
Describe the return statement (gpuweb#710)
Browse files Browse the repository at this point in the history
* Describe the return statement

Also, in the grammar, the expression is optional.

* Updates from review

- Make a return_stmt grammar element
- Combine the return value paragraphs into one.

* Remove duplicate return_stmt grammar rule
  • Loading branch information
dneto0 authored Apr 21, 2020
1 parent adfae01 commit d05d63c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions wgsl/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,7 @@ statements

statement
: SEMICOLON
| RETURN logical_or_expression SEMICOLON
OpReturn
OpReturnValue
| return_stmt SEMICOLON
| if_stmt
| unless_stmt
| switch_stmt
Expand Down Expand Up @@ -1306,6 +1304,25 @@ const_expr
</xmp>
</div>

## Return statement ## {#return-statement}

<pre>
return_stmt
: RETURN logical_or_expression?
</pre>

A `return` statement ends execution of the current function.
If the function is an entry point, then the current shader invocation
is terminated.
Otherwise, evaluation continues with the next expression or statement after
the evaluation of the call site of the current function invocation.

If the return type of the function is the void type, then the return statement
must not have an expression.
Otherwise the expression must be present, and is called the *return value*.
In this case the call site of this function invocation evaluates to the return value.
The type of the return value must match the return type of the function.

# Validation # {#validation}

Each validation item will be given a unique ID and a test must be provided
Expand Down

0 comments on commit d05d63c

Please sign in to comment.