[naga] Disallow logical operators &&
and ||
on vectors
#7368
+65
−5
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
Fixes #6856
Description
This change disallows the logical operators
&&
and||
on vectors, which WGSL does not allow. There are two relevant codepaths, one for constant evaluation and one for type checking of expressions to be evaluated at runtime.I tested this change locally in combination with #7339. The two changes actually do not conflict and interact minimally. In #7339, I implemented a transformation while lowering to IR that gets applied only if the operands have a correct (scalar) type. If the operands are not scalars, the expression is passed through with the expectation that validation rejects it. This change affects what will ultimately pass validation.
Arguably, these operators should be removed from the Naga IR entirely. I have not done that, because the
BinaryOperator
enum is shared by the AST and IR representations.Testing
Added tests in wgsl_errors to verify both operators are rejected in both const and runtime contexts.
Squash or Rebase? Squash
Checklist
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.