diff --git a/wgsl/index.bs b/wgsl/index.bs index 434213235a..d0d61df96f 100644 --- a/wgsl/index.bs +++ b/wgsl/index.bs @@ -4829,19 +4829,29 @@ compound_statement ## Assignment Statement ## {#assignment} -An assignment statement replaces the contents of a variable, -or a portion of a variable, with a new value. +An assignment evaluates an expression, +and optionally stores it in memory (thus updating the contents of a variable). -The -expression to the left of the equals token is the left-hand side, +
+assignment_statement
+  : (unary_expression | UNDERSCORE) EQUAL short_circuit_or_expression
+
+ + +The text to the left of the equals token is the left-hand side, and the expression to the right of the equals token is the right-hand side. +### Updating Assignment ### {#updating-assignment-section} + +When the [=left-hand side=] of an assignment is an expression, the assignment is an updating assignment: +The value of the right-hand side is written to the memory referenced by the left-hand side. + - +
PreconditionStatementDescription
|r|: ref<|SC|,|T|,|A|>,
|A| is [=access/write=] or [=access/read_write=]
|e|: |T|,
@@ -4858,8 +4868,8 @@ expression to the right of the equals token is the right-hand side (OpStore)
-In the simplest case, the left hand side of the assignment statement is the -name of a variable. See [[#forming-references-and-pointers]] for other cases. +In the simplest case, the left hand side is the name of a variable. +See [[#forming-references-and-pointers]] for other cases.
@@ -4888,18 +4898,11 @@ name of a variable. See [[#forming-references-and-pointers]] for other cases.
-
-assignment_statement
-  : unary_expression EQUAL short_circuit_or_expression
-      If unary_expression is a variable, this maps to OpStore to the variable.
-      Otherwise, unary expression is a pointer expression in an Assigning (L-value) context
-      which maps to OpAccessChain followed by OpStore
-
+### Phony Assignment ### {#phony-assignment-section} -## Phony-Assignment Statement ## {#phony-assignment-statement} - -A phony-assignment statement evaluates an expression, -and does nothing with the resulting value. +When the [=left-hand side=] of an assignment is an underscore token, +the assignment is an phony assignment: +The right-hand side is evaluated, and then ignored. @@ -4918,7 +4921,8 @@ and does nothing with the resulting value. A phony-assignment is useful for: * Calling a function that returns a value, but clearly expressing that the resulting value is not needed. -* Establishing a particular variable as part of the [=resource interface of a shader|shader's resource interface=]. +* [=statically accessed|Statically accessing=] a variable, thus establishing it as a part of + the [=resource interface of a shader|shader's resource interface=]. Note: A variable's store type may not be constructible, e.g. it contains an atomic type, or a runtime-sized array. In these cases, use a pointer to the variable's contents instead. @@ -4963,12 +4967,6 @@ A phony-assignment is useful for: -
-phony_assignment_statement
-  : UNDERSCORE EQUAL short_circuit_or_expression
-
- - ## Control flow TODO ## {#control-flow} ### Sequence TODO ### {#sequence-statement} @@ -5162,9 +5160,9 @@ for_statement : FOR PAREN_LEFT for_header PAREN_RIGHT compound_statement for_header - : (variable_statement | assignment_statement | phony_assignment_statement | func_call_statement)? SEMICOLON + : (variable_statement | assignment_statement | func_call_statement)? SEMICOLON short_circuit_or_expression? SEMICOLON - (assignment_statement | phony_assignment_statement | func_call_statement)? + (assignment_statement | func_call_statement)? The for statement takes the form @@ -5453,7 +5451,6 @@ statement | continue_statement SEMICOLON | DISCARD SEMICOLON | assignment_statement SEMICOLON - | phony_assignment_statement SEMICOLON | compound_statement