mirror of
https://github.com/storytold/wgpu.git
synced 2026-11-21 23:11:01 +01:00
refactor(naga): Rename U32EvalError to ConstValueError
This commit is contained in:
1 parent
bf075e7694
commit
c4df1af1fd
4 files changed
+23
-21
No files matched your search
@@ -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,
|
||||
}),
|
||||
|
||||
@@ -538,11 +538,11 @@ impl<'source, 'temp, 'out> ExpressionContext<'source, 'temp, 'out> {
|
||||
fn const_eval_expr_to_u32(
|
||||
&self,
|
||||
handle: Handle<ir::Expression>,
|
||||
) -> core::result::Result<u32, proc::U32EvalError> {
|
||||
) -> core::result::Result<u32, proc::ConstValueError> {
|
||||
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)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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<crate::Expression>,
|
||||
) -> Result<u32, U32EvalError> {
|
||||
) -> Result<u32, ConstValueError> {
|
||||
self.eval_expr_to_u32_from(handle, self.global_expressions)
|
||||
}
|
||||
|
||||
@@ -464,13 +464,13 @@ impl GlobalCtx<'_> {
|
||||
&self,
|
||||
handle: crate::Handle<crate::Expression>,
|
||||
arena: &crate::Arena<crate::Expression>,
|
||||
) -> Result<u32, U32EvalError> {
|
||||
) -> Result<u32, ConstValueError> {
|
||||
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 {
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in new issue
Block a user