Skip to content

Commit 42a3247

Browse files
committed
wip
1 parent a0fab21 commit 42a3247

6 files changed

Lines changed: 166 additions & 185 deletions

File tree

naga/src/back/pipeline_constants.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use alloc::{
22
borrow::Cow,
3+
boxed::Box,
34
string::{String, ToString},
45
vec::Vec,
56
};
@@ -40,7 +41,7 @@ pub enum PipelineConstantError {
4041
#[error(transparent)]
4142
ConstantEvaluatorError(#[from] ConstantEvaluatorError),
4243
#[error(transparent)]
43-
ValidationError(#[from] WithSpan<ValidationError>),
44+
ValidationError(#[from] WithSpan<Box<ValidationError>>),
4445
#[error("workgroup_size override isn't strictly positive")]
4546
NegativeWorkgroupSize,
4647
#[error("max vertices or max primitives is negative")]

naga/src/valid/expression.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ pub const fn check_literal_value(literal: crate::Literal) -> Result<(), LiteralE
14871487
fn validate_with_expression(
14881488
expr: crate::Expression,
14891489
caps: super::Capabilities,
1490-
) -> Result<ModuleInfo, crate::span::WithSpan<super::ValidationError>> {
1490+
) -> Result<ModuleInfo, crate::span::WithSpan<Box<super::ValidationError>>> {
14911491
use crate::span::Span;
14921492

14931493
let mut function = crate::Function::default();
@@ -1510,7 +1510,7 @@ fn validate_with_expression(
15101510
fn validate_with_const_expression(
15111511
expr: crate::Expression,
15121512
caps: super::Capabilities,
1513-
) -> Result<ModuleInfo, crate::span::WithSpan<super::ValidationError>> {
1513+
) -> Result<ModuleInfo, crate::span::WithSpan<Box<super::ValidationError>>> {
15141514
use crate::span::Span;
15151515

15161516
let mut module = crate::Module::default();
@@ -1531,7 +1531,7 @@ fn f64_runtime_literals() {
15311531
let error = result.unwrap_err().into_inner();
15321532
assert!(matches!(
15331533
error.as_ref(),
1534-
crate::valid::ValidationErrorInner::Function {
1534+
crate::valid::ValidationError::Function {
15351535
source: super::FunctionError::Expression {
15361536
source: ExpressionError::Literal(LiteralError::Width(
15371537
super::r#type::WidthError::MissingCapability {
@@ -1562,7 +1562,7 @@ fn f64_const_literals() {
15621562
let error = result.unwrap_err().into_inner();
15631563
assert!(matches!(
15641564
error.as_ref(),
1565-
crate::valid::ValidationErrorInner::ConstExpression {
1565+
crate::valid::ValidationError::ConstExpression {
15661566
source: ConstExpressionError::Literal(LiteralError::Width(
15671567
super::r#type::WidthError::MissingCapability {
15681568
name: "f64",

naga/src/valid/handles.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
//! Implementation of `Validator::validate_module_handles`.
22
3+
use alloc::boxed::Box;
34
use core::{convert::TryInto, hash::Hash};
45

5-
use super::{TypeError, ValidationErrorInner};
6+
use super::{TypeError, ValidationError};
67
use crate::non_max_u32::NonMaxU32;
78
use crate::{
89
arena::{BadHandle, BadRangeError},
@@ -32,7 +33,7 @@ impl super::Validator {
3233
/// validation pass.
3334
pub(super) fn validate_module_handles(
3435
module: &crate::Module,
35-
) -> Result<(), ValidationErrorInner> {
36+
) -> Result<(), Box<ValidationError>> {
3637
let &crate::Module {
3738
ref constants,
3839
ref overrides,
@@ -302,7 +303,7 @@ impl super::Validator {
302303
.contains(&struct_member_index)
303304
.then_some(())
304305
// TODO: what errors should this be?
305-
.ok_or_else(|| ValidationErrorInner::Type {
306+
.ok_or_else(|| ValidationError::Type {
306307
handle: ty,
307308
name: struct_type.name.as_ref().map_or_else(
308309
|| "members length incorrect".to_string(),
@@ -314,14 +315,14 @@ impl super::Validator {
314315
_ => {
315316
// TODO: internal error ? We should never get here.
316317
// If entering there, it's probably that we forgot to adjust a handle in the compact phase.
317-
return Err(ValidationErrorInner::Type {
318+
return Err(Box::new(ValidationError::Type {
318319
handle: ty,
319320
name: struct_type
320321
.name
321322
.as_ref()
322323
.map_or_else(|| "Unknown".to_string(), |name| name.to_string()),
323324
source: TypeError::InvalidData(ty),
324-
});
325+
}));
325326
}
326327
}
327328
for (&function, _) in doc_comments_for_functions.iter() {
@@ -887,21 +888,27 @@ impl super::Validator {
887888
}
888889
}
889890

890-
impl From<BadHandle> for ValidationErrorInner {
891+
impl From<BadHandle> for Box<ValidationError> {
891892
fn from(source: BadHandle) -> Self {
892-
ValidationErrorInner::InvalidHandle(source.into())
893+
Box::new(ValidationError::InvalidHandle(source.into()))
893894
}
894895
}
895896

896-
impl From<FwdDepError> for ValidationErrorInner {
897+
impl From<FwdDepError> for Box<ValidationError> {
897898
fn from(source: FwdDepError) -> Self {
898-
ValidationErrorInner::InvalidHandle(source.into())
899+
Box::new(ValidationError::InvalidHandle(source.into()))
899900
}
900901
}
901902

902-
impl From<BadRangeError> for ValidationErrorInner {
903+
impl From<BadRangeError> for Box<ValidationError> {
903904
fn from(source: BadRangeError) -> Self {
904-
ValidationErrorInner::InvalidHandle(source.into())
905+
Box::new(ValidationError::InvalidHandle(source.into()))
906+
}
907+
}
908+
909+
impl From<InvalidHandleError> for Box<ValidationError> {
910+
fn from(value: InvalidHandleError) -> Self {
911+
Box::new(ValidationError::from(value))
905912
}
906913
}
907914

naga/src/valid/mod.rs

Lines changed: 16 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod interface;
1212
mod r#type;
1313

1414
use alloc::{boxed::Box, string::String, vec, vec::Vec};
15-
use core::ops::{self, Deref, DerefMut};
15+
use core::ops;
1616

1717
use bit_set::BitSet;
1818

@@ -474,35 +474,7 @@ pub enum OverrideError {
474474

475475
#[derive(Clone, Debug, thiserror::Error)]
476476
#[cfg_attr(test, derive(PartialEq))]
477-
#[error(transparent)]
478-
pub struct ValidationError(Box<ValidationErrorInner>);
479-
480-
impl<T> From<T> for ValidationError
481-
where
482-
T: Into<ValidationErrorInner>,
483-
{
484-
fn from(value: T) -> Self {
485-
ValidationError(Box::new(value.into()))
486-
}
487-
}
488-
489-
impl Deref for ValidationError {
490-
type Target = Box<ValidationErrorInner>;
491-
492-
fn deref(&self) -> &Self::Target {
493-
&self.0
494-
}
495-
}
496-
497-
impl DerefMut for ValidationError {
498-
fn deref_mut(&mut self) -> &mut Self::Target {
499-
&mut self.0
500-
}
501-
}
502-
503-
#[derive(Clone, Debug, thiserror::Error)]
504-
#[cfg_attr(test, derive(PartialEq))]
505-
pub enum ValidationErrorInner {
477+
pub enum ValidationError {
506478
#[error(transparent)]
507479
InvalidHandle(#[from] InvalidHandleError),
508480
#[error(transparent)]
@@ -761,7 +733,7 @@ impl Validator {
761733
pub fn validate(
762734
&mut self,
763735
module: &crate::Module,
764-
) -> Result<ModuleInfo, WithSpan<ValidationError>> {
736+
) -> Result<ModuleInfo, WithSpan<Box<ValidationError>>> {
765737
self.overrides_resolved = false;
766738
self.validate_impl(module)
767739
}
@@ -776,23 +748,23 @@ impl Validator {
776748
pub fn validate_resolved_overrides(
777749
&mut self,
778750
module: &crate::Module,
779-
) -> Result<ModuleInfo, WithSpan<ValidationError>> {
751+
) -> Result<ModuleInfo, WithSpan<Box<ValidationError>>> {
780752
self.overrides_resolved = true;
781753
self.validate_impl(module)
782754
}
783755

784756
fn validate_impl(
785757
&mut self,
786758
module: &crate::Module,
787-
) -> Result<ModuleInfo, WithSpan<ValidationError>> {
759+
) -> Result<ModuleInfo, WithSpan<Box<ValidationError>>> {
788760
self.reset();
789761
self.reset_types(module.types.len());
790762

791-
Self::validate_module_handles(module).map_err(|e| ValidationError::from(e).with_span())?;
763+
Self::validate_module_handles(module).map_err(|e| e.with_span())?;
792764

793765
self.layouter.update(module.to_ctx()).map_err(|e| {
794766
let handle = e.ty;
795-
ValidationError::from(e).with_span_handle(handle, &module.types)
767+
Box::new(ValidationError::from(e)).with_span_handle(handle, &module.types)
796768
})?;
797769

798770
// These should all get overwritten.
@@ -813,7 +785,7 @@ impl Validator {
813785
let ty_info = self
814786
.validate_type(handle, module.to_ctx())
815787
.map_err(|source| {
816-
ValidationError::from(ValidationErrorInner::Type {
788+
Box::new(ValidationError::Type {
817789
handle,
818790
name: ty.name.clone().unwrap_or_default(),
819791
source,
@@ -835,7 +807,7 @@ impl Validator {
835807
mod_info
836808
.process_const_expression(handle, &resolve_context, module.to_ctx())
837809
.map_err(|source| {
838-
ValidationError::from(ValidationErrorInner::ConstExpression {
810+
Box::new(ValidationError::ConstExpression {
839811
handle,
840812
source,
841813
})
@@ -855,15 +827,15 @@ impl Validator {
855827
&global_expr_kind,
856828
)
857829
.map_err(|source| {
858-
ValidationError::from(ValidationErrorInner::ConstExpression { handle, source })
830+
Box::new(ValidationError::ConstExpression { handle, source })
859831
.with_span_handle(handle, &module.global_expressions)
860832
})?
861833
}
862834

863835
for (handle, constant) in module.constants.iter() {
864836
self.validate_constant(handle, module.to_ctx(), &mod_info, &global_expr_kind)
865837
.map_err(|source| {
866-
ValidationError::from(ValidationErrorInner::Constant {
838+
Box::new(ValidationError::Constant {
867839
handle,
868840
name: constant.name.clone().unwrap_or_default(),
869841
source,
@@ -875,7 +847,7 @@ impl Validator {
875847
for (handle, r#override) in module.overrides.iter() {
876848
self.validate_override(handle, module.to_ctx(), &mod_info)
877849
.map_err(|source| {
878-
ValidationError::from(ValidationErrorInner::Override {
850+
Box::new(ValidationError::Override {
879851
handle,
880852
name: r#override.name.clone().unwrap_or_default(),
881853
source,
@@ -888,7 +860,7 @@ impl Validator {
888860
for (var_handle, var) in module.global_variables.iter() {
889861
self.validate_global_var(var, module.to_ctx(), &mod_info, &global_expr_kind)
890862
.map_err(|source| {
891-
ValidationError::from(ValidationErrorInner::GlobalVariable {
863+
Box::new(ValidationError::GlobalVariable {
892864
handle: var_handle,
893865
name: var.name.clone().unwrap_or_default(),
894866
source,
@@ -902,7 +874,7 @@ impl Validator {
902874
Ok(info) => mod_info.functions.push(info),
903875
Err(error) => {
904876
return Err(error.and_then(|source| {
905-
ValidationError::from(ValidationErrorInner::Function {
877+
Box::new(ValidationError::Function {
906878
handle,
907879
name: fun.name.clone().unwrap_or_default(),
908880
source,
@@ -916,7 +888,7 @@ impl Validator {
916888
let mut ep_map = FastHashSet::default();
917889
for ep in module.entry_points.iter() {
918890
if !ep_map.insert((ep.stage, &ep.name)) {
919-
return Err(ValidationError::from(ValidationErrorInner::EntryPoint {
891+
return Err(Box::new(ValidationError::EntryPoint {
920892
stage: ep.stage,
921893
name: ep.name.clone(),
922894
source: EntryPointError::Conflict,
@@ -928,7 +900,7 @@ impl Validator {
928900
Ok(info) => mod_info.entry_points.push(info),
929901
Err(error) => {
930902
return Err(error.and_then(|source| {
931-
ValidationError::from(ValidationErrorInner::EntryPoint {
903+
Box::new(ValidationError::EntryPoint {
932904
stage: ep.stage,
933905
name: ep.name.clone(),
934906
source,

0 commit comments

Comments
 (0)