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

[naga] Don't treat Emit statements as return statements during ensure_block_returns() #7013

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

jamienicol
Copy link
Contributor

Connections
Fixes #4395

Description
terminator.rs' ensure_block_returns() function was incorrectly treating Emit statements as a valid return. This causes us to omit appending a Statement::Return { value: None } statement to some functions. Without such statement we cannot validate that the (lack of) value returned from the function matches the function's return type.

Testing
Added new test

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

…_block_returns()

Doing so caused proc::ensure_block_returns() to skip appending a
return statement to some blocks, without which we are unable to
validate that non-void functions have explicit return statements.

A consequence of this change would be that some void functions
generated by the backends would now end with useless return
statements. This already occurs in some cases, but would become more
common. To avoid this, we now only call ensure_block_terminates() for
a function if it has a return type. This removes a lot of unnecessary
return statements from our shader test snapshots.
@jamienicol jamienicol requested a review from a team January 28, 2025 14:50
@ErichDonGubler ErichDonGubler merged commit b245b35 into gfx-rs:trunk Jan 28, 2025
31 checks passed
@ErichDonGubler
Copy link
Member

ErichDonGubler commented Jan 28, 2025

Oh, shoot, I realized that there's not a CHANGELOG entry yet. Could we get that in, too, @jamienicol?

jamienicol added a commit to jamienicol/wgpu that referenced this pull request Jan 29, 2025
This is a partial reversion of gfx-rs#7013. The fix for the actual
validation bug remains - ie ensuring that validation correctly rejects
shaders containing functions with return types that do not return a
value. But this reverts the additional change made to avoid adding
superfluous return statements to the end of functions *without* return
types. This was done for aesthetics without proper discussion of the
technicalities. Perhaps we will revisit this when we follow up in

Additionally add a changelog entry for gfx-rs#7013.
@jamienicol
Copy link
Contributor Author

@ErichDonGubler I added a changelog entry in #7021 (and reverted the part which removes the return statement from void functions)

@jamienicol jamienicol deleted the missing-return branch January 29, 2025 09:31
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.

[wgsl-in] Function with missing return statement is sometimes accepted without an error
2 participants