Skip to content

[wgsl-in] Report concrete type mismatches in WGSL terms - #9973

Open
emilk wants to merge 2 commits into
gfx-rs:trunkfrom
emilk:emilk/wgsl-type-mismatch-error
Open

[wgsl-in] Report concrete type mismatches in WGSL terms#9973
emilk wants to merge 2 commits into
gfx-rs:trunkfrom
emilk:emilk/wgsl-type-mismatch-error

Conversation

@emilk

@emilk emilk commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Connections

Description

try_automatic_conversions passed concrete values through untouched, deliberately leaving the type error to the IR validator. But the validator can only name operands by handle index, and prints handles from different arenas identically, so a return mismatch read The `return` expression Some([1]) does not match the declared return type Some([1]) — where one [1] is an expression and the other a type.

The punt was about message quality: calling a plain mismatch a failed automatic conversion would mislead. So report a type mismatch instead. That single choke point covers return, call arguments, composite constructors and var/let initializers, and no future caller can forget to check.

Testing

New/updated check snapshots in wgsl_errors.rs; three check_validation! tests are now parse errors. Also parsed every .wgsl in the repo (nothing newly rejected) and regenerated all Targets::IR snapshots (no diff).

Squash or Rebase?

Rebase — single commit.

Checklist

  • I self-reviewed…
  • …and fully understand this PR.
  • WebGPU implementations built with wgpu may be affected behaviorally.
  • Validation and feature gates are in place to confine behavioral changes.
  • Tests demonstrate the validation and altered logic works.
  • CHANGELOG.md entries for the user-facing effects of this change are present.
  • The PR is minimal, and doesn't make sense to land as multiple PRs.
  • Commits are logically scoped and individually reviewable.
  • The PR description has enough context to understand the motivation and solution implemented.

🤖 Generated with Claude Code

`try_automatic_conversions` passed concrete values through untouched,
deliberately leaving the type error to the IR validator. But the
validator can only name operands by handle index, and prints handles from
different arenas identically, so a `return` mismatch read:

    The `return` expression Some([1]) does not match the declared return type Some([1])

where one `[1]` is an expression and the other a type. Function call
arguments were equally opaque, and a composite constructor with a
wrong-typed component became "Composing 0's component type is not
expected".

The reason for the punt was message quality: reporting a plain mismatch
as a failed automatic conversion would mislead. So report a type
mismatch instead. Every caller of `try_automatic_conversions` now gets a
diagnostic with spans and WGSL type names, and no future caller can
forget to check.

`var`/`let` initializers keep their existing wording by mapping the new
error, which also makes their follow-up `compare_types` check redundant.

Fixes gfx-rs#7419.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Comment thread naga/src/front/wgsl/error.rs Outdated
@emilk
emilk marked this pull request as ready for review July 30, 2026 12:18
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.

Validation errors show handle number instead of name

1 participant