layouter: rich and careful errors

This commit is contained in:
Dzmitry Malyshau committed 2022-01-14 12:44:27 -05:00
1 parent a069361bf4
commit ab02ec7904
10 files changed
+90 -48

No files matched your search

+4 -3
View File
@@ -824,6 +824,7 @@ impl super::Validator {
module: &crate::Module,
mod_info: &ModuleInfo,
) -> Result<FunctionInfo, WithSpan<FunctionError>> {
#[cfg_attr(not(feature = "validate"), allow(unused_mut))]
let mut info = mod_info.process_function(fun, module, self.flags)?;
#[cfg(feature = "validate")]
@@ -842,13 +843,13 @@ impl super::Validator {
#[cfg(feature = "validate")]
for (index, argument) in fun.arguments.iter().enumerate() {
let ty = module.types.get_handle(argument.ty).ok_or(
let ty = module.types.get_handle(argument.ty).ok_or_else(|| {
FunctionError::InvalidArgumentType {
index,
name: argument.name.clone().unwrap_or_default(),
}
.with_span_handle(argument.ty, &module.types),
)?;
.with_span_handle(argument.ty, &module.types)
})?;
match ty.inner.pointer_class() {
Some(crate::StorageClass::Private)
| Some(crate::StorageClass::Function)
+3 -3
View File
@@ -10,7 +10,7 @@ use crate::arena::{Arena, UniqueArena};
use crate::{
arena::Handle,
proc::{InvalidBaseType, Layouter},
proc::{LayoutError, Layouter},
FastHashSet,
};
use bit_set::BitSet;
@@ -127,7 +127,7 @@ pub enum ConstantError {
#[derive(Clone, Debug, thiserror::Error)]
pub enum ValidationError {
#[error(transparent)]
Layouter(#[from] InvalidBaseType),
Layouter(#[from] LayoutError),
#[error("Type {handle:?} '{name}' is invalid")]
Type {
handle: Handle<crate::Type>,
@@ -278,7 +278,7 @@ impl Validator {
self.layouter
.update(&module.types, &module.constants)
.map_err(|e| {
let InvalidBaseType(handle) = e;
let handle = e.ty;
ValidationError::from(e).with_span_handle(handle, &module.types)
})?;
+5 -2
View File
@@ -326,7 +326,8 @@ impl super::Validator {
return Err(TypeError::InvalidArrayBaseType(base));
}
let base_size = types[base].inner.span(constants);
//Note: `unwrap()` is fine, since `Layouter` goes first and calls it
let base_size = types[base].inner.size(constants).unwrap();
if stride < base_size {
return Err(TypeError::InsufficientArrayStride { stride, base_size });
}
@@ -478,7 +479,9 @@ impl super::Validator {
});
}
}
let base_size = types[member.ty].inner.span(constants);
//Note: `unwrap()` is fine because `Layouter` goes first and checks this
let base_size = types[member.ty].inner.size(constants).unwrap();
min_offset = member.offset + base_size;
if min_offset > span {
return Err(TypeError::MemberOutOfBounds {