diff --git a/examples/convert.rs b/examples/convert.rs index 01522b1f37..7e832e0162 100644 --- a/examples/convert.rs +++ b/examples/convert.rs @@ -158,16 +158,16 @@ fn main() { } }; - // validate the IR - let analysis = naga::proc::Validator::new() - .validate(&module) - .unwrap_pretty(); - if args.len() <= 2 { println!("{:#?}", module); return; } + // validate the IR + let analysis = naga::proc::Validator::new() + .validate(&module) + .unwrap_pretty(); + match Path::new(&args[2]) .extension() .expect("Output has no extension?") diff --git a/src/back/glsl/mod.rs b/src/back/glsl/mod.rs index 50d238eb87..ae22cb213e 100644 --- a/src/back/glsl/mod.rs +++ b/src/back/glsl/mod.rs @@ -44,7 +44,7 @@ pub use features::Features; use crate::{ - proc::{analyzer::Analysis, NameKey, Namer, ResolveContext, ResolveError, Typifier}, + proc::{analyzer::Analysis, NameKey, Namer, ResolveContext, TypifyError, Typifier}, Arena, ArraySize, BinaryOperator, Binding, BuiltIn, Bytes, ConservativeDepth, Constant, ConstantInner, DerivativeAxis, Expression, FastHashMap, Function, GlobalVariable, Handle, ImageClass, Interpolation, LocalVariable, Module, RelationalFunction, ScalarKind, ScalarValue, @@ -220,7 +220,7 @@ pub enum Error { IoError(#[from] IoError), /// The [`Module`](crate::Module) failed type resolution #[error("Type error: {0}")] - Type(#[from] ResolveError), + Type(#[from] TypifyError), /// The specified [`Version`](Version) doesn't have all required [`Features`](super) /// /// Contains the missing [`Features`](Features) diff --git a/src/back/msl/mod.rs b/src/back/msl/mod.rs index 0953a5dadc..585593ab50 100644 --- a/src/back/msl/mod.rs +++ b/src/back/msl/mod.rs @@ -16,7 +16,7 @@ we move them up to the root output structure that we define ourselves. use crate::{ arena::Handle, - proc::{analyzer::Analysis, ResolveError}, + proc::{analyzer::Analysis, TypifyError}, FastHashMap, }; use std::{ @@ -60,7 +60,7 @@ enum ResolvedBinding { pub enum Error { IO(IoError), Utf8(FromUtf8Error), - Type(ResolveError), + Type(TypifyError), MissingBindTarget(BindSource), InvalidImageAccess(crate::StorageAccess), BadName(String), @@ -87,8 +87,8 @@ impl From for Error { } } -impl From for Error { - fn from(e: ResolveError) -> Self { +impl From for Error { + fn from(e: TypifyError) -> Self { Error::Type(e) } } @@ -155,10 +155,8 @@ impl Options { group, binding, }; - self.binding_map - .get(&source) - .cloned() - .map(ResolvedBinding::Resource) + ResolvedBinding::Resource( + self.binding_map.get(&source).cloned(). .ok_or(Error::MissingBindTarget(source)) } None => { diff --git a/src/back/spv/writer.rs b/src/back/spv/writer.rs index d71a84db25..a6c279358d 100644 --- a/src/back/spv/writer.rs +++ b/src/back/spv/writer.rs @@ -4,7 +4,7 @@ use crate::{ arena::{Arena, Handle}, proc::{ analyzer::{Analysis, FunctionInfo}, - Layouter, ResolveContext, ResolveError, Typifier, + Layouter, ResolveContext, TypifyError, Typifier, }, }; use spirv::Word; @@ -22,7 +22,7 @@ pub enum Error { #[error("unimplemented {0:}")] FeatureNotImplemented(&'static str), #[error(transparent)] - Resolve(#[from] ResolveError), + Resolve(#[from] TypifyError), } struct Block { diff --git a/src/proc/mod.rs b/src/proc/mod.rs index 3f545fb278..5ec34408b7 100644 --- a/src/proc/mod.rs +++ b/src/proc/mod.rs @@ -12,7 +12,7 @@ pub use interface::{Interface, Visitor}; pub use layouter::{Alignment, Layouter}; pub use namer::{EntryPointIndex, NameKey, Namer}; pub use terminator::ensure_block_returns; -pub use typifier::{ResolveContext, ResolveError, Typifier}; +pub use typifier::{ResolveContext, ResolveError, Typifier, TypifyError}; pub use validator::{ValidationError, Validator}; impl From for super::ScalarKind { diff --git a/src/proc/typifier.rs b/src/proc/typifier.rs index 9bea6137cc..8cffd5bfdb 100644 --- a/src/proc/typifier.rs +++ b/src/proc/typifier.rs @@ -62,6 +62,10 @@ pub enum ResolveError { }, } +#[derive(Clone, Debug, Error, PartialEq)] +#[error("Type resolution of {0:?} failed: {1}")] +pub struct TypifyError(Handle, #[source] ResolveError); + pub struct ResolveContext<'a> { pub constants: &'a Arena, pub global_vars: &'a Arena, @@ -527,10 +531,12 @@ impl Typifier { expressions: &Arena, types: &Arena, ctx: &ResolveContext, - ) -> Result<(), ResolveError> { + ) -> Result<(), TypifyError> { self.clear(); - for (_, expr) in expressions.iter() { - let resolution = self.resolve_impl(expr, types, ctx)?; + for (handle, expr) in expressions.iter() { + let resolution = self + .resolve_impl(expr, types, ctx) + .map_err(|err| TypifyError(handle, err))?; self.resolutions.push(resolution); } Ok(()) diff --git a/src/proc/validator.rs b/src/proc/validator.rs index 50dc7ac792..55bc960235 100644 --- a/src/proc/validator.rs +++ b/src/proc/validator.rs @@ -1,6 +1,6 @@ use super::{ analyzer::{Analysis, AnalysisError, FunctionInfo, GlobalUse}, - typifier::{ResolveContext, ResolveError, Typifier}, + typifier::{TypifyError, ResolveContext, Typifier}, }; use crate::arena::{Arena, Handle}; use bit_set::BitSet; @@ -78,7 +78,7 @@ pub enum LocalVariableError { #[derive(Clone, Debug, thiserror::Error)] pub enum FunctionError { #[error(transparent)] - Resolve(#[from] ResolveError), + Resolve(#[from] TypifyError), #[error("There are instructions after `return`/`break`/`continue`")] InvalidControlFlowExitTail, #[error("Local variable {handle:?} '{name}' is invalid: {error:?}")]