From e3b005ea8226ba4ac0abe638e848e8c49e52874d Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Wed, 9 Apr 2025 10:20:02 -0700 Subject: [PATCH] [naga wgsl-in] Avoid crashes when logging types. In `naga::front::wgsl::lower`, change logging in `ExpressionContext::automatic_conversion_consensus` to use `TypeResolution`s instead of `TypeInner`s, so that structs don't cause a crash. --- naga/src/front/wgsl/lower/conversion.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/naga/src/front/wgsl/lower/conversion.rs b/naga/src/front/wgsl/lower/conversion.rs index 7433d4e5c..681fd9a6f 100644 --- a/naga/src/front/wgsl/lower/conversion.rs +++ b/naga/src/front/wgsl/lower/conversion.rs @@ -311,17 +311,19 @@ impl<'source> super::ExpressionContext<'source, '_, '_> { I::IntoIter: Clone, // for debugging { let types = &self.module.types; - let mut inners = components - .into_iter() - .map(|&c| self.typifier()[c].inner_with(types)); + let components_iter = components.into_iter(); log::debug!( "wgsl automatic_conversion_consensus: {}", - inners + components_iter .clone() - .map(|inner| self.type_inner_to_string(inner)) + .map(|&expr| { + let res = &self.typifier()[expr]; + self.type_resolution_to_string(res) + }) .collect::>() .join(", ") ); + let mut inners = components_iter.map(|&c| self.typifier()[c].inner_with(types)); let mut best = inners.next().unwrap().scalar().ok_or(0_usize)?; for (inner, i) in inners.zip(1..) { let scalar = inner.scalar().ok_or(i)?;