[msl] derive thiserror

This commit is contained in:
Dzmitry Malyshau 2021-02-19 16:40:44 -05:00 committed by Dzmitry Malyshau
parent db0a8875d9
commit 0e3f745fb2
5 changed files with 38 additions and 46 deletions

View File

@ -44,7 +44,7 @@
pub use features::Features;
use crate::{
proc::{analyzer::Analysis, NameKey, Namer, ResolveContext, TypifyError, Typifier},
proc::{analyzer::Analysis, NameKey, Namer, ResolveContext, Typifier, TypifyError},
Arena, ArraySize, BinaryOperator, Binding, BuiltIn, Bytes, ConservativeDepth, Constant,
ConstantInner, DerivativeAxis, Expression, FastHashMap, Function, GlobalVariable, Handle,
ImageClass, Interpolation, LocalVariable, Module, RelationalFunction, ScalarKind, ScalarValue,

View File

@ -56,43 +56,30 @@ enum ResolvedBinding {
// Note: some of these should be removed in favor of proper IR validation.
#[derive(Debug)]
#[derive(Debug, thiserror::Error)]
pub enum Error {
IO(IoError),
Utf8(FromUtf8Error),
Type(TypifyError),
#[error(transparent)]
IO(#[from] IoError),
#[error(transparent)]
Utf8(#[from] FromUtf8Error),
#[error(transparent)]
Type(#[from] TypifyError),
#[error("bind source for {0:?} is missing from the map")]
MissingBindTarget(BindSource),
InvalidImageAccess(crate::StorageAccess),
BadName(String),
#[error("bind target {0:?} is empty")]
UnimplementedBindTarget(BindTarget),
#[error("composing of {0:?} is not implemented yet")]
UnsupportedCompose(Handle<crate::Type>),
#[error("operation {0:?} is not implemented yet")]
UnsupportedBinaryOp(crate::BinaryOperator),
UnexpectedSampleLevel(crate::SampleLevel),
#[error("standard function '{0}' is not implemented yet")]
UnsupportedCall(String),
UnsupportedDynamicArrayLength,
#[error("feature '{0}' is not implemented yet")]
FeatureNotImplemented(String),
/// The source IR is not valid.
#[error("module is not valid")]
Validation,
}
impl From<IoError> for Error {
fn from(e: IoError) -> Self {
Error::IO(e)
}
}
impl From<FromUtf8Error> for Error {
fn from(e: FromUtf8Error) -> Self {
Error::Utf8(e)
}
}
impl From<TypifyError> for Error {
fn from(e: TypifyError) -> Self {
Error::Type(e)
}
}
#[derive(Clone, Copy, Debug)]
enum LocationMode {
VertexInput,
@ -155,8 +142,10 @@ impl Options {
group,
binding,
};
ResolvedBinding::Resource(
self.binding_map.get(&source).cloned().
self.binding_map
.get(&source)
.cloned()
.map(ResolvedBinding::Resource)
.ok_or(Error::MissingBindTarget(source))
}
None => {

View File

@ -680,20 +680,23 @@ impl<W: Write> Writer<W> {
} => {
self.put_local_call(function, arguments, context)?;
}
crate::Expression::ArrayLength(expr) => match *self
.typifier
.get(expr, &context.module.types)
{
crate::TypeInner::Array {
size: crate::ArraySize::Constant(const_handle),
..
} => {
let size_str = &self.names[&NameKey::Constant(const_handle)];
write!(self.out, "{}", size_str)?;
crate::Expression::ArrayLength(expr) => {
match *self.typifier.get(expr, &context.module.types) {
crate::TypeInner::Array {
size: crate::ArraySize::Constant(const_handle),
..
} => {
let size_str = &self.names[&NameKey::Constant(const_handle)];
write!(self.out, "{}", size_str)?;
}
crate::TypeInner::Array { .. } => {
return Err(Error::FeatureNotImplemented(
"dynamic array size".to_string(),
))
}
_ => return Err(Error::Validation),
}
crate::TypeInner::Array { .. } => return Err(Error::UnsupportedDynamicArrayLength),
_ => return Err(Error::Validation),
},
}
}
Ok(())
}
@ -1025,7 +1028,7 @@ impl<W: Write> Writer<W> {
} else if global.storage_access.contains(crate::StorageAccess::LOAD) {
"read"
} else {
return Err(Error::InvalidImageAccess(global.storage_access));
return Err(Error::Validation);
};
("texture", "", format.into(), access)
}

View File

@ -4,7 +4,7 @@ use crate::{
arena::{Arena, Handle},
proc::{
analyzer::{Analysis, FunctionInfo},
Layouter, ResolveContext, TypifyError, Typifier,
Layouter, ResolveContext, Typifier, TypifyError,
},
};
use spirv::Word;

View File

@ -1,6 +1,6 @@
use super::{
analyzer::{Analysis, AnalysisError, FunctionInfo, GlobalUse},
typifier::{TypifyError, ResolveContext, Typifier},
typifier::{ResolveContext, Typifier, TypifyError},
};
use crate::arena::{Arena, Handle};
use bit_set::BitSet;