[naga wgsl-in] Short-circuiting of && and || operators #7339
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Connections
Possible fix for #4394 and #6302.
Description
The WGSL
&&
and||
operators should short-circuit, i.e., not evaluate their RHS if the result can be determined from the LHS alone. This is accomplished by transforming expressions with these operators into anif
statement, guarding the evaluation of the RHS. In the case of nested expressions using these operators, it is necessary to emit nestedif
statements.Things I am not sure about:
with_nested_runtime_expression_ctx
to emit the expressions for the RHS within the if statement. I don't understand the code well enough yet to be confident this approach is sound.Things that aren't done yet:
Testing
Adds one snapshot test, but more tests are needed.
Squash or Rebase?
TBD
Checklist
cargo fmt
.taplo format
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.