diff --git a/naga/src/front/glsl/parser.rs b/naga/src/front/glsl/parser.rs index 79001d870..d26c7764d 100644 --- a/naga/src/front/glsl/parser.rs +++ b/naga/src/front/glsl/parser.rs @@ -14,7 +14,7 @@ use super::{ variables::{GlobalOrConstant, VarDeclaration}, Frontend, Result, }; -use crate::{arena::Handle, proc::U32EvalError, Expression, Module, Span, Type}; +use crate::{arena::Handle, proc::ConstValueError, Expression, Module, Span, Type}; mod declarations; mod expressions; @@ -215,11 +215,11 @@ impl<'source> ParsingContext<'source> { let int = match res { Ok(value) => Ok(value), - Err(U32EvalError::Negative) => Err(Error { + Err(ConstValueError::Negative) => Err(Error { kind: ErrorKind::SemanticError("int constant overflows".into()), meta, }), - Err(U32EvalError::NonConst) => Err(Error { + Err(ConstValueError::NonConst) => Err(Error { kind: ErrorKind::SemanticError("Expected a uint constant".into()), meta, }), diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index 14525c76f..ef8b052b4 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -538,11 +538,11 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { fn const_eval_expr_to_u32( &self, handle: Handle, - ) -> core::result::Result { + ) -> core::result::Result { match self.expr_type { ExpressionContextType::Runtime(ref ctx) => { if !ctx.local_expression_kind_tracker.is_const(handle) { - return Err(proc::U32EvalError::NonConst); + return Err(proc::ConstValueError::NonConst); } self.module @@ -556,7 +556,7 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { .eval_expr_to_u32_from(handle, &ctx.function.expressions) } ExpressionContextType::Constant(None) => self.module.to_ctx().eval_expr_to_u32(handle), - ExpressionContextType::Override => Err(proc::U32EvalError::NonConst), + ExpressionContextType::Override => Err(proc::ConstValueError::NonConst), } } @@ -718,10 +718,12 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> { .to_ctx() .eval_expr_to_u32_from(expr, &rctx.function.expressions) .map_err(|err| match err { - proc::U32EvalError::NonConst => { + proc::ConstValueError::NonConst => { Error::ExpectedConstExprConcreteIntegerScalar(component_span) } - proc::U32EvalError::Negative => Error::ExpectedNonNegative(component_span), + proc::ConstValueError::Negative => { + Error::ExpectedNonNegative(component_span) + } })?; ir::SwizzleComponent::XYZW .get(index as usize) @@ -4203,8 +4205,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { .to_ctx() .eval_expr_to_u32(expr) .map_err(|err| match err { - proc::U32EvalError::NonConst => Error::ExpectedConstExprConcreteIntegerScalar(span), - proc::U32EvalError::Negative => Error::ExpectedNonNegative(span), + proc::ConstValueError::NonConst => Error::ExpectedConstExprConcreteIntegerScalar(span), + proc::ConstValueError::Negative => Error::ExpectedNonNegative(span), })?; Ok((value, span)) } @@ -4222,10 +4224,10 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { Ok(value) => { let len = ctx.const_eval_expr_to_u32(value).map_err(|err| { Box::new(match err { - proc::U32EvalError::NonConst => { + proc::ConstValueError::NonConst => { Error::ExpectedConstExprConcreteIntegerScalar(span) } - proc::U32EvalError::Negative => { + proc::ConstValueError::Negative => { Error::ExpectedPositiveArrayLength(span) } }) diff --git a/naga/src/proc/mod.rs b/naga/src/proc/mod.rs index bc1e72e11..562fe24ba 100644 --- a/naga/src/proc/mod.rs +++ b/naga/src/proc/mod.rs @@ -425,7 +425,7 @@ impl crate::Module { } #[derive(Debug)] -pub(super) enum U32EvalError { +pub(super) enum ConstValueError { NonConst, Negative, } @@ -455,7 +455,7 @@ impl GlobalCtx<'_> { pub(super) fn eval_expr_to_u32( &self, handle: crate::Handle, - ) -> Result { + ) -> Result { self.eval_expr_to_u32_from(handle, self.global_expressions) } @@ -464,13 +464,13 @@ impl GlobalCtx<'_> { &self, handle: crate::Handle, arena: &crate::Arena, - ) -> Result { + ) -> Result { match self.eval_expr_to_literal_from(handle, arena) { Some(crate::Literal::U32(value)) => Ok(value), Some(crate::Literal::I32(value)) => { - value.try_into().map_err(|_| U32EvalError::Negative) + value.try_into().map_err(|_| ConstValueError::Negative) } - _ => Err(U32EvalError::NonConst), + _ => Err(ConstValueError::NonConst), } } @@ -562,8 +562,8 @@ impl crate::ArraySize { return Err(ResolveArraySizeError::NonConstArrayLength); }; let length = gctx.eval_expr_to_u32(expr).map_err(|err| match err { - U32EvalError::NonConst => ResolveArraySizeError::NonConstArrayLength, - U32EvalError::Negative => ResolveArraySizeError::ExpectedPositiveArrayLength, + ConstValueError::NonConst => ResolveArraySizeError::NonConstArrayLength, + ConstValueError::Negative => ResolveArraySizeError::ExpectedPositiveArrayLength, })?; if length == 0 { diff --git a/naga/src/valid/expression.rs b/naga/src/valid/expression.rs index bf5a265c1..9cb12cc0c 100644 --- a/naga/src/valid/expression.rs +++ b/naga/src/valid/expression.rs @@ -308,10 +308,10 @@ impl super::Validator { } } } - Err(crate::proc::U32EvalError::Negative) => { + Err(crate::proc::ConstValueError::Negative) => { return Err(ExpressionError::NegativeIndex(base)) } - Err(crate::proc::U32EvalError::NonConst) => {} + Err(crate::proc::ConstValueError::NonConst) => {} } ShaderStages::all()