Skip to content

Commit 9baaadc

Browse files
WIP: refactor(naga): allow ExpressionErrors to control presented spans
1 parent 41009bd commit 9baaadc

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
@@ -143,6 +143,66 @@ pub enum ExpressionError {
143143
UnsupportedWidth(crate::MathFunction, crate::ScalarKind, crate::Bytes),
144144
}
145145

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

naga/src/valid/function.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,8 +1763,17 @@ impl super::Validator {
17631763
) {
17641764
Ok(stages) => info.available_stages &= stages,
17651765
Err(source) => {
1766-
return Err(FunctionError::Expression { handle, source }
1767-
.with_span_handle(handle, &fun.expressions))
1766+
let expr_handles = source.expr_handles().collect::<Vec<_>>();
1767+
let mut err = FunctionError::Expression { handle, source }.with_span();
1768+
if expr_handles.is_empty() {
1769+
err = err.with_handle(handle, &fun.expressions);
1770+
} else {
1771+
for (handle, context) in expr_handles {
1772+
let span = fun.expressions.get_span(handle);
1773+
err = err.with_context((span, context));
1774+
}
1775+
}
1776+
return Err(err);
17681777
}
17691778
}
17701779
}

0 commit comments

Comments
 (0)