From b85a451dc999b8b23d4f52fb6a0906d5e7d45ac0 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Sat, 15 Mar 2025 15:32:31 -0700 Subject: [PATCH] [naga wgsl-in] Use `String` in error, not `Box`. Use `String` in variants of `naga::front::wgsl::Error`, not `Box`. Delete test `naga::front::wgsl::error::test_error_size`. Since `Error` is always returned boxed, its size should have no effect on `Result` size. --- naga/src/front/wgsl/error.rs | 25 +++++++++-------------- naga/src/front/wgsl/lower/construction.rs | 4 ++-- naga/src/front/wgsl/lower/conversion.rs | 12 +++++------ naga/src/front/wgsl/lower/mod.rs | 12 +++++------ 4 files changed, 24 insertions(+), 29 deletions(-) diff --git a/naga/src/front/wgsl/error.rs b/naga/src/front/wgsl/error.rs index 6bbf9f476c..ac6bc617ea 100644 --- a/naga/src/front/wgsl/error.rs +++ b/naga/src/front/wgsl/error.rs @@ -174,8 +174,8 @@ pub(crate) enum Error<'a> { BadTexture(Span), BadTypeCast { span: Span, - from_type: Box, - to_type: Box, + from_type: String, + to_type: String, }, BadTextureSampleType { span: Span, @@ -211,8 +211,8 @@ pub(crate) enum Error<'a> { TypeNotInferable(Span), InitializationTypeMismatch { name: Span, - expected: Box, - got: Box, + expected: String, + got: String, }, DeclMissingTypeAndInit(Span), MissingAttribute(&'static str, Span), @@ -342,24 +342,24 @@ impl From<&'static str> for DiagnosticAttributeNotSupportedPosition { #[derive(Clone, Debug)] pub(crate) struct AutoConversionError { pub dest_span: Span, - pub dest_type: Box, + pub dest_type: String, pub source_span: Span, - pub source_type: Box, + pub source_type: String, } #[derive(Clone, Debug)] pub(crate) struct AutoConversionLeafScalarError { pub dest_span: Span, - pub dest_scalar: Box, + pub dest_scalar: String, pub source_span: Span, - pub source_type: Box, + pub source_type: String, } #[derive(Clone, Debug)] pub(crate) struct ConcretizationFailedError { pub expr_span: Span, - pub expr_type: Box, - pub scalar: Box, + pub expr_type: String, + pub scalar: String, pub inner: ConstantEvaluatorError, } @@ -1179,8 +1179,3 @@ impl<'a> Error<'a> { } } } - -#[test] -fn test_error_size() { - assert!(size_of::>() <= 48); -} diff --git a/naga/src/front/wgsl/lower/construction.rs b/naga/src/front/wgsl/lower/construction.rs index d2de1a1bb1..0acb90f321 100644 --- a/naga/src/front/wgsl/lower/construction.rs +++ b/naga/src/front/wgsl/lower/construction.rs @@ -536,11 +536,11 @@ impl<'source> Lowerer<'source, '_> { // Bad conversion (type cast) (Components::One { span, ty_inner, .. }, constructor) => { - let from_type = ty_inner.to_wgsl(&ctx.module.to_ctx()).into(); + let from_type = ty_inner.to_wgsl(&ctx.module.to_ctx()); return Err(Box::new(Error::BadTypeCast { span, from_type, - to_type: constructor.to_error_string(ctx).into(), + to_type: constructor.to_error_string(ctx), })); } diff --git a/naga/src/front/wgsl/lower/conversion.rs b/naga/src/front/wgsl/lower/conversion.rs index 9dbb08de36..a72141522d 100644 --- a/naga/src/front/wgsl/lower/conversion.rs +++ b/naga/src/front/wgsl/lower/conversion.rs @@ -54,8 +54,8 @@ impl<'source> super::ExpressionContext<'source, '_, '_> { Some(scalars) => scalars, None => { let gctx = &self.module.to_ctx(); - let source_type = expr_resolution.to_wgsl(gctx).into(); - let dest_type = goal_ty.to_wgsl(gctx).into(); + let source_type = expr_resolution.to_wgsl(gctx); + let dest_type = goal_ty.to_wgsl(gctx); return Err(Box::new(super::Error::AutoConversion(Box::new( AutoConversionError { @@ -96,10 +96,10 @@ impl<'source> super::ExpressionContext<'source, '_, '_> { let make_error = || { let gctx = &self.module.to_ctx(); - let source_type = expr_resolution.to_wgsl(gctx).into(); + let source_type = expr_resolution.to_wgsl(gctx); super::Error::AutoConversionLeafScalar(Box::new(AutoConversionLeafScalarError { dest_span: goal_span, - dest_scalar: goal_scalar.to_wgsl().into(), + dest_scalar: goal_scalar.to_wgsl(), source_span: expr_span, source_type, })) @@ -275,8 +275,8 @@ impl<'source> super::ExpressionContext<'source, '_, '_> { let expr_type = &self.typifier()[expr]; super::Error::ConcretizationFailed(Box::new(ConcretizationFailedError { expr_span, - expr_type: expr_type.to_wgsl(&self.module.to_ctx()).into(), - scalar: concretized.to_wgsl().into(), + expr_type: expr_type.to_wgsl(&self.module.to_ctx()), + scalar: concretized.to_wgsl(), inner: err, })) })?; diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index 706b07f7af..00246e3156 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -1256,8 +1256,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { if !explicit_inner.equivalent(init_inner, &ectx.module.types) { return Err(Box::new(Error::InitializationTypeMismatch { name: name.span, - expected: explicit_inner.to_wgsl(&ectx.module.to_ctx()).into(), - got: init_inner.to_wgsl(&ectx.module.to_ctx()).into(), + expected: explicit_inner.to_wgsl(&ectx.module.to_ctx()), + got: init_inner.to_wgsl(&ectx.module.to_ctx()), })); } ty = explicit_ty; @@ -1490,8 +1490,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let gctx = &ctx.module.to_ctx(); return Err(Box::new(Error::InitializationTypeMismatch { name: l.name.span, - expected: ty.to_wgsl(gctx).into(), - got: init_ty.to_wgsl(gctx).into(), + expected: ty.to_wgsl(gctx), + got: init_ty.to_wgsl(gctx), })); } } @@ -2194,9 +2194,9 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let ty = resolve!(ctx, expr); let gctx = &ctx.module.to_ctx(); return Err(Box::new(Error::BadTypeCast { - from_type: ty.to_wgsl(gctx).into(), + from_type: ty.to_wgsl(gctx), span: ty_span, - to_type: to_resolved.to_wgsl(gctx).into(), + to_type: to_resolved.to_wgsl(gctx), })); } };