Module brace_init

Module brace_init 

Source
Expand description

Pass: lower T x = { … }; brace-init local declarations to T x = T(…); constructor calls.

HLSL accepts brace initialisers on matrix and vector locals:

float2x2 rot = { cos(q9), sin(q9), -sin(q9), cos(q9) };
float3   c   = { 0.1, 0.2, 0.3 };

WGSL has no brace-initialiser form for vec/mat types — both var x: mat2x2<f32> = { … } and the post-translation mat2x2<f32> x = { … }; get rejected with expected '(', found '<ident>' because the parser is in declarator position when it hits the offending {.

The downstream regex pipeline (rewrite_local_declarations, LOCAL_DECL_REGEX) explicitly excludes { from its capture group to avoid greedy-swallowing function bodies, so these decls fall through the regex untouched and naga rejects them at parse.

This pass rewrites every applicable LocalDecl so the init is a constructor call. Targets float2x2/float3x3/float4x4 (the dominant corpus shape — 8 warp presets on the 2 000-sample, all containing the rot rotation matrix pattern above) and the analogous floatN vector form when an explicit brace-init is used.

Edits are minimal: replace just the { … } span with T(…). The enclosing T x = and the trailing ; survive verbatim so the downstream local-decl regex sees a well-formed T x = T(...); shape and converts it to var x: T = T(...); on its next pass.

Functions§

constructor_name 🔒
ctx_slice 🔒
expected_elem_count 🔒
rewrite_brace_init 🔒
walk_block 🔒
walk_stmt 🔒