Skip to content

[naga] Warn, rather than error, on unreachable statements #7554

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

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

andyleiserson
Copy link
Contributor

Earlier versions of WGSL specified that unreachable code was an error, but that is no longer the case. This PR updates naga accordingly.

Fixes #7536

I have added a mechanism to collect warnings during validation. Mostly to make them accessible to the tests, I add an API on Validator to retrieve the diagnostics. However, even with the warning that the diagnostics are not stable, I'm not sure if we really want this to be a public API. Another possibility is changing the tests to unit tests so they can retrieve the diagnostics without having a public API.

I also made some changes in the Span module to support boxed errors for the diagnostics. It would be better to just use Vec<ValidationError> for the diagnostics, but the difficulty with that is that creating a ValidationError from a FunctionError requires knowing the function name (not too bad) and the Handle for the function (harder), which aren't readily available at the point where the diagnostic is generated, because in error cases the conversion to a ValidationError happens as the error propagates upwards.

Testing
Added tests in the validation suite and added/updated tests in wgsl_errors.

Squash or Rebase? Squash

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy --tests. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • If this contains user-facing changes, add a CHANGELOG.md entry.

@ErichDonGubler
Copy link
Member

I haven't taken a deep look at this, and I'm not sure I'll be the primary reviewer, but: We might usefully make this use Severity::report_diag, so warnings can eventually get rolled into the effort to migrate it to satisfy #6458.

@andyleiserson
Copy link
Contributor Author

I haven't taken a deep look at this, and I'm not sure I'll be the primary reviewer, but: We might usefully make this use Severity::report_diag, so warnings can eventually get rolled into the effort to migrate it to satisfy #6458.

Like this? 😀

Severity::Warning.report_diag(

(In the long term, hardcoding Severity::Warning is not great, but it seemed non-trivial to plumb a diagnostic context to this check so I didn't tackle that right now.)

@ErichDonGubler ErichDonGubler self-assigned this Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Instructions after return" is reported incorrectly
2 participants