Skip to content

Commit 61fd166

Browse files
WIP: refactor(naga): allow ExpressionErrors to control presented spans
1 parent b24de23 commit 61fd166

2 files changed

Lines changed: 71 additions & 2 deletions

File tree

naga/src/valid/expression.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,66 @@ pub enum ExpressionError {
140140
UnsupportedWidth(crate::MathFunction, crate::ScalarKind, crate::Bytes),
141141
}
142142

143+
impl ExpressionError {
144+
pub(crate) fn expr_handles(&self) -> impl Iterator<Item = (Handle<crate::Expression>, String)> {
145+
match *self {
146+
Self::NotInScope => Vec::new(),
147+
Self::InvalidBaseType(..) => Vec::new(),
148+
Self::InvalidIndexType(..) => Vec::new(),
149+
Self::NegativeIndex(..) => Vec::new(),
150+
Self::IndexOutOfBounds(..) => Vec::new(),
151+
Self::FunctionArgumentDoesntExist(..) => Vec::new(),
152+
Self::InvalidPointerType(..) => Vec::new(),
153+
Self::InvalidArrayType(..) => Vec::new(),
154+
Self::InvalidRayQueryType(..) => Vec::new(),
155+
Self::InvalidSplatType(..) => Vec::new(),
156+
Self::InvalidVectorType(..) => Vec::new(),
157+
Self::InvalidSwizzleComponent(..) => Vec::new(),
158+
Self::Compose(..) => Vec::new(),
159+
Self::IndexableLength(..) => Vec::new(),
160+
Self::InvalidUnaryOperandType(..) => Vec::new(),
161+
Self::InvalidBinaryOperandTypes { .. } => Vec::new(),
162+
Self::SelectValuesTypeMismatch { .. } => Vec::new(),
163+
Self::SelectConditionNotABool { .. } => Vec::new(),
164+
Self::InvalidBooleanVector(..) => Vec::new(),
165+
Self::InvalidFloatArgument(..) => Vec::new(),
166+
Self::Type(..) => Vec::new(),
167+
Self::ExpectedGlobalVariable => Vec::new(),
168+
Self::ExpectedGlobalOrArgument => Vec::new(),
169+
Self::ExpectedBindingArrayType(..) => Vec::new(),
170+
Self::ExpectedImageType(..) => Vec::new(),
171+
Self::ExpectedSamplerType(..) => Vec::new(),
172+
Self::InvalidImageClass(..) => Vec::new(),
173+
Self::InvalidDerivative => Vec::new(),
174+
Self::InvalidImageArrayIndex => Vec::new(),
175+
Self::InvalidImageOtherIndex => Vec::new(),
176+
Self::InvalidImageArrayIndexType(..) => Vec::new(),
177+
Self::InvalidImageOtherIndexType(..) => Vec::new(),
178+
Self::InvalidImageCoordinateType(..) => Vec::new(),
179+
Self::ComparisonSamplingMismatch { .. } => Vec::new(),
180+
Self::InvalidSampleOffsetExprType => Vec::new(),
181+
Self::InvalidSampleOffset(..) => Vec::new(),
182+
Self::InvalidDepthReference(..) => Vec::new(),
183+
Self::InvalidDepthSampleLevel => Vec::new(),
184+
Self::InvalidGatherLevel => Vec::new(),
185+
Self::InvalidGatherComponent(..) => Vec::new(),
186+
Self::InvalidGatherDimension(..) => Vec::new(),
187+
Self::InvalidSampleLevelExactType(..) => Vec::new(),
188+
Self::InvalidSampleLevelBiasType(..) => Vec::new(),
189+
Self::InvalidSampleLevelBiasDimension(..) => Vec::new(),
190+
Self::InvalidSampleLevelGradientType(..) => Vec::new(),
191+
Self::InvalidCastArgument => Vec::new(),
192+
Self::WrongArgumentCount(..) => Vec::new(),
193+
Self::InvalidArgumentType(..) => Vec::new(),
194+
Self::InvalidWorkGroupUniformLoadResultType(..) => Vec::new(),
195+
Self::MissingCapabilities(..) => Vec::new(),
196+
Self::Literal(..) => Vec::new(),
197+
Self::UnsupportedWidth(..) => Vec::new(),
198+
}
199+
.into_iter()
200+
}
201+
}
202+
143203
#[derive(Clone, Debug, thiserror::Error)]
144204
#[cfg_attr(test, derive(PartialEq))]
145205
pub enum ConstExpressionError {

naga/src/valid/function.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,8 +1743,17 @@ impl super::Validator {
17431743
) {
17441744
Ok(stages) => info.available_stages &= stages,
17451745
Err(source) => {
1746-
return Err(FunctionError::Expression { handle, source }
1747-
.with_span_handle(handle, &fun.expressions))
1746+
let expr_handles = source.expr_handles().collect::<Vec<_>>();
1747+
let mut err = FunctionError::Expression { handle, source }.with_span();
1748+
if expr_handles.is_empty() {
1749+
err = err.with_handle(handle, &fun.expressions);
1750+
} else {
1751+
for (handle, context) in expr_handles {
1752+
let span = fun.expressions.get_span(handle);
1753+
err = err.with_context((span, context));
1754+
}
1755+
}
1756+
return Err(err);
17481757
}
17491758
}
17501759
}

0 commit comments

Comments
 (0)