Skip to content

fix(wgsl): 8 WGSL validation fixes — Rust naga parity (#66)#68

Merged
kolkov merged 10 commits into
mainfrom
fix/wgsl-validation-hardening
Apr 30, 2026
Merged

fix(wgsl): 8 WGSL validation fixes — Rust naga parity (#66)#68
kolkov merged 10 commits into
mainfrom
fix/wgsl-validation-hardening

Conversation

@kolkov

@kolkov kolkov commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

Summary

WGSL validation hardening — 8 spec-compliance fixes, all verified against Rust naga.

Fixes

  • Mandatory semicolons — 16 parser sites enforced per WGSL grammar
  • @must_use enforcement — reject discarded results from must-use functions
  • @compute requires @workgroup_size — missing attribute now errors
  • const_assert evaluationconst_assert false now fails at compile time
  • @binding/@group pairing — both required together on resource variables
  • Zero-sized arraysarray<T, 0> rejected per spec
  • Invalid swizzle — GLSL stpq rejected, mixed namespaces (v.xg) rejected
  • Argument type validationvec2<u32> passed as u32 now errors (Function argument type missmatch silently compiled #66)

Validation parity

All 8 fixes independently verified against Rust naga — identical rejection behavior.

Test plan

  • 35+ new unit tests across 3 test files
  • go test ./wgsl/ ./ir/ — pass
  • go test -run TestRustReference — 100%
  • go test -run TestDxilValSummary — 161/170
  • golangci-lint run --timeout=5m — clean
  • go fmt ./... — clean
  • CI green (Linux, macOS, Windows)

kolkov added 10 commits April 30, 2026 14:29
16 places changed from p.match(TokenSemicolon) to p.expectSemicolon().
For-loop init/update use inForHeader flag to skip (separator, not terminator).
Declarations (const, var, let, override, alias, const_assert) and
statements (return, break, continue, discard, assign, expr) all require ;.
WGSL spec only allows xyzw and rgba swizzle components. GLSL-only
s/t/p/q components were incorrectly accepted. Additionally, mixing
namespaces (e.g., v.xg combining xyzw with rgba) was not rejected.

Matches Rust naga Components::new() which validates all characters
belong to the same namespace (xyzw or rgba).

BUG-WGSL-004: reject stpq swizzle
BUG-WGSL-008: reject mixed swizzle namespace
@compute entry points without @workgroup_size were silently accepted,
defaulting to [1,1,1]. WGSL spec requires @workgroup_size to be
explicitly present on compute shader entry points.

Matches Rust naga: Error::MissingWorkgroupSize.

BUG-WGSL-003
array<f32, 0> was silently accepted. WGSL spec requires array size
to be a positive integer. Now returns a clear error message.

BUG-WGSL-007
Previously const_assert was parsed but treated as a no-op during
lowering. Now const_assert expressions are evaluated at both module
and function scope, matching Rust naga's ConstAssertFailed / NotBool
behavior.

Supports bool literals, negation (!), logical operators (&&, ||),
comparison operators (==, !=, <, <=, >, >=), and named constants.
WGSL spec requires both @binding and @group on resource variables.
Previously @binding(0) without @group compiled silently. Now the
lowerer validates that both attributes are present and reports a
clear error when one is missing.
Functions marked with @must_use now produce an error when their
return value is discarded as a statement (e.g. foo();). The result
must be used in an assignment, return, expression, or phony (_ =).
Matches Rust naga's FunctionMustUseUnused validation.
Complex const_assert expressions (select(), all(), float comparisons)
are silently accepted when they cannot be evaluated by the simple
constant evaluator. This prevents regressions on valid shaders like
const_assert.wgsl and select.wgsl while still catching the common
case of const_assert false.
@codecov

codecov Bot commented Apr 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.72189% with 63 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
wgsl/parser.go 19.04% 20 Missing and 14 partials ⚠️
wgsl/lower.go 77.16% 27 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@kolkov kolkov merged commit 4059c86 into main Apr 30, 2026
11 checks passed
@kolkov kolkov deleted the fix/wgsl-validation-hardening branch May 8, 2026 19:05
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.

1 participant