Skip to content
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

WGSL: Const. eval. short-circuiting #6302

Open
ErichDonGubler opened this issue Sep 20, 2024 · 1 comment
Open

WGSL: Const. eval. short-circuiting #6302

ErichDonGubler opened this issue Sep 20, 2024 · 1 comment
Labels
area: correctness We're behaving incorrectly area: cts Issues stemming from the WebGPU Conformance Test Suite area: naga processing Passes over IR in the middle area: validation Issues related to validation, diagnostics, and error handling

Comments

@ErichDonGubler
Copy link
Member

Description

Naga currently rejects programs with constant expressions such as this one:

const asdf = false && (123 / 0 > 0);

An uninformed reader might assume that dividing by zero yielding an error is expected. Indeed, Naga will happily report an error here:

Could not parse WGSL:
error: Division by zero
  ┌─ in.wgsl:1:24
  │
1 │ const asdf = false && (123 / 0 > 0);
  │                        ^^^^^^^ see msg

And yet, this is not standard behavior! The WGSL spec. clearly states that we should only be attempting const. eval. on the RHS of expressions when it cannot short-circuit. In the current WGSL spec.'s section 8.1.1:

The evaluation rule implies that short-circuiting operators && and || guard evaluation of their right-hand side subexpressions unless there is a subexpression that requires evaluation to determine a [static type](https://www.w3.org/TR/WGSL/#static-type).

Repro steps

Validate the above shader via naga as a file, i.e., in.wgsl. One can do this with a repo. checkout as follows:

$ cargo run -p naga-cli -- in.wgsl

Expected vs observed behavior

Already described, I hope!

Extra materials

Platform

@ErichDonGubler ErichDonGubler added area: validation Issues related to validation, diagnostics, and error handling area: correctness We're behaving incorrectly area: cts Issues stemming from the WebGPU Conformance Test Suite area: naga processing Passes over IR in the middle labels Sep 20, 2024
@sagudev
Copy link
Contributor

sagudev commented Sep 21, 2024

This will be complicated as evaluator already evals them to bool when doing logical and:

(Literal::Bool(a), Literal::Bool(b)) => Literal::Bool(match op {
BinaryOperator::LogicalAnd => a && b,
BinaryOperator::LogicalOr => a || b,
_ => return Err(ConstantEvaluatorError::InvalidBinaryOpArgs),
}),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: correctness We're behaving incorrectly area: cts Issues stemming from the WebGPU Conformance Test Suite area: naga processing Passes over IR in the middle area: validation Issues related to validation, diagnostics, and error handling
Projects
Status: Todo
Development

No branches or pull requests

2 participants