[naga] Warn, rather than error, on unreachable statements #7554
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.
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 useVec<ValidationError>
for the diagnostics, but the difficulty with that is that creating aValidationError
from aFunctionError
requires knowing the function name (not too bad) and theHandle
for the function (harder), which aren't readily available at the point where the diagnostic is generated, because in error cases the conversion to aValidationError
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
cargo fmt
.taplo format
.cargo clippy --tests
. If applicable, add:--target wasm32-unknown-unknown
cargo xtask test
to run tests.CHANGELOG.md
entry.