[naga wgsl-in] Use String in error, not Box<str>.

Use `String` in variants of `naga::front::wgsl::Error`, not
`Box<str>`.

Delete test `naga::front::wgsl::error::test_error_size`. Since `Error`
is always returned boxed, its size should have no effect on `Result`
size.
This commit is contained in:
Jim Blandy
2025-03-15 15:32:31 -07:00
committed by Erich Gubler
parent 5c9c6ea093
commit b85a451dc9
4 changed files with 24 additions and 29 deletions

View File

@@ -174,8 +174,8 @@ pub(crate) enum Error<'a> {
BadTexture(Span),
BadTypeCast {
span: Span,
from_type: Box<str>,
to_type: Box<str>,
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<str>,
got: Box<str>,
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<str>,
pub dest_type: String,
pub source_span: Span,
pub source_type: Box<str>,
pub source_type: String,
}
#[derive(Clone, Debug)]
pub(crate) struct AutoConversionLeafScalarError {
pub dest_span: Span,
pub dest_scalar: Box<str>,
pub dest_scalar: String,
pub source_span: Span,
pub source_type: Box<str>,
pub source_type: String,
}
#[derive(Clone, Debug)]
pub(crate) struct ConcretizationFailedError {
pub expr_span: Span,
pub expr_type: Box<str>,
pub scalar: Box<str>,
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::<Error<'_>>() <= 48);
}

View File

@@ -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),
}));
}

View File

@@ -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,
}))
})?;

View File

@@ -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),
}));
}
};