Skip to content

Commit f867db0

Browse files
committed
[naga wgsl-in] In Lowerer::call, handle constructors first.
Rearrange `naga::front::wgsl::lower::Lowerer::call` to check for construction expressions for predeclared types before checking for any builtin function names, including those that take template parameter lists like `bitcast` and `coopLoad`.
1 parent 687c035 commit f867db0

1 file changed

Lines changed: 33 additions & 33 deletions

File tree

  • naga/src/front/wgsl/lower

naga/src/front/wgsl/lower/mod.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,39 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
30283028
Ok(result)
30293029
}
30303030
None => {
3031+
let ty = conv::map_predeclared_type(
3032+
&ctx.enable_extensions,
3033+
function_span,
3034+
function_name,
3035+
)?;
3036+
if let Some(ty) = ty {
3037+
let empty_template_list = call_phrase.function.template_list.is_empty();
3038+
let constructor_ty = match ty {
3039+
conv::PredeclaredType::TypeGenerator(conv::TypeGenerator::Vector {
3040+
size,
3041+
}) if empty_template_list => Constructor::PartialVector { size },
3042+
conv::PredeclaredType::TypeGenerator(conv::TypeGenerator::Matrix {
3043+
columns,
3044+
rows,
3045+
}) if empty_template_list => Constructor::PartialMatrix { columns, rows },
3046+
conv::PredeclaredType::TypeGenerator(conv::TypeGenerator::Array)
3047+
if empty_template_list =>
3048+
{
3049+
Constructor::PartialArray
3050+
}
3051+
conv::PredeclaredType::TypeGenerator(
3052+
conv::TypeGenerator::CooperativeMatrix { .. },
3053+
) if empty_template_list => {
3054+
return Err(Box::new(Error::UnderspecifiedCooperativeMatrix));
3055+
}
3056+
_ => Constructor::Type(self.finalize_type(ctx, ty, &mut tl, None)?),
3057+
};
3058+
tl.finish(ctx)?;
3059+
let handle =
3060+
self.construct(span, constructor_ty, function_span, arguments, ctx)?;
3061+
return Ok(Some(handle));
3062+
};
3063+
30313064
match function_name {
30323065
"bitcast" => {
30333066
let ty = tl.ty(self, ctx)?;
@@ -3111,39 +3144,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
31113144
_ => {}
31123145
}
31133146

3114-
let ty = conv::map_predeclared_type(
3115-
&ctx.enable_extensions,
3116-
function_span,
3117-
function_name,
3118-
)?;
3119-
if let Some(ty) = ty {
3120-
let empty_template_list = call_phrase.function.template_list.is_empty();
3121-
let constructor_ty = match ty {
3122-
conv::PredeclaredType::TypeGenerator(conv::TypeGenerator::Vector {
3123-
size,
3124-
}) if empty_template_list => Constructor::PartialVector { size },
3125-
conv::PredeclaredType::TypeGenerator(conv::TypeGenerator::Matrix {
3126-
columns,
3127-
rows,
3128-
}) if empty_template_list => Constructor::PartialMatrix { columns, rows },
3129-
conv::PredeclaredType::TypeGenerator(conv::TypeGenerator::Array)
3130-
if empty_template_list =>
3131-
{
3132-
Constructor::PartialArray
3133-
}
3134-
conv::PredeclaredType::TypeGenerator(
3135-
conv::TypeGenerator::CooperativeMatrix { .. },
3136-
) if empty_template_list => {
3137-
return Err(Box::new(Error::UnderspecifiedCooperativeMatrix));
3138-
}
3139-
_ => Constructor::Type(self.finalize_type(ctx, ty, &mut tl, None)?),
3140-
};
3141-
tl.finish(ctx)?;
3142-
let handle =
3143-
self.construct(span, constructor_ty, function_span, arguments, ctx)?;
3144-
return Ok(Some(handle));
3145-
};
3146-
31473147
tl.finish(ctx)?;
31483148

31493149
let span = function_span;

0 commit comments

Comments
 (0)