From 6c9f93b7de42136c5c09f195fc1c4999e5962347 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Fri, 13 Dec 2024 11:15:51 -0500 Subject: [PATCH] diag(naga): clarify `select` built-in type mismatch messages --- naga/src/valid/expression.rs | 24 +++++++++++++++++++----- naga/tests/validation.rs | 4 ++-- naga/tests/wgsl_errors.rs | 2 +- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/naga/src/valid/expression.rs b/naga/src/valid/expression.rs index 28b9321cce..5f3c0a819c 100644 --- a/naga/src/valid/expression.rs +++ b/naga/src/valid/expression.rs @@ -54,8 +54,13 @@ pub enum ExpressionError { rhs_expr: Handle, rhs_type: crate::TypeInner, }, - #[error("Selecting is not possible")] - InvalidSelectTypes, + #[error("Expected selection argument types to match, but reject value of type {reject:?} does not match accept value of value {accept:?}")] + SelectValuesTypeMismatch { + accept: crate::TypeInner, + reject: crate::TypeInner, + }, + #[error("Expected selection condition to be a boolean value, got {actual:?}")] + SelectConditionNotABool { actual: crate::TypeInner }, #[error("Relational argument {0:?} is not a boolean vector")] InvalidBooleanVector(Handle), #[error("Relational argument {0:?} is not a float")] @@ -901,7 +906,8 @@ impl super::Validator { } => { let accept_inner = &resolver[accept]; let reject_inner = &resolver[reject]; - let condition_good = match resolver[condition] { + let condition_ty = &resolver[condition]; + let condition_good = match *condition_ty { Ti::Scalar(Sc { kind: Sk::Bool, width: _, @@ -928,8 +934,16 @@ impl super::Validator { }, _ => false, }; - if !condition_good || accept_inner != reject_inner { - return Err(ExpressionError::InvalidSelectTypes); + if accept_inner != reject_inner { + return Err(ExpressionError::SelectValuesTypeMismatch { + accept: accept_inner.clone(), + reject: reject_inner.clone(), + }); + } + if !condition_good { + return Err(ExpressionError::SelectConditionNotABool { + actual: condition_ty.clone(), + }); } ShaderStages::all() } diff --git a/naga/tests/validation.rs b/naga/tests/validation.rs index cd56355d1e..3ffb231e25 100644 --- a/naga/tests/validation.rs +++ b/naga/tests/validation.rs @@ -650,7 +650,7 @@ error: Entry point main at Compute is invalid │ ^^^^^^ naga::Expression [3] │ = Expression [3] is invalid - = Selecting is not possible + = Expected selection condition to be a boolean value, got Scalar(Scalar { kind: Sint, width: 4 }) ", ), @@ -670,7 +670,7 @@ error: Entry point main at Compute is invalid │ ^^^^^^ naga::Expression [3] │ = Expression [3] is invalid - = Selecting is not possible + = Expected selection argument types to match, but reject value of type Scalar(Scalar { kind: Bool, width: 1 }) does not match accept value of value Scalar(Scalar { kind: Sint, width: 4 }) ", ), diff --git a/naga/tests/wgsl_errors.rs b/naga/tests/wgsl_errors.rs index acc2f32cbf..2d1669ada2 100644 --- a/naga/tests/wgsl_errors.rs +++ b/naga/tests/wgsl_errors.rs @@ -1543,7 +1543,7 @@ fn select() { naga::valid::ValidationError::Function { name, source: naga::valid::FunctionError::Expression { - source: naga::valid::ExpressionError::InvalidSelectTypes, + source: naga::valid::ExpressionError::SelectConditionNotABool { .. }, .. }, ..