From 2587db1c9bb044c1994a293c4e7cf0eb3e3459b2 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 20 Dec 2024 07:33:29 -0800 Subject: [PATCH] [naga] In compaction, fix array lengths as part of type adjustment. (#6790) Adjust the `Handle` values that appear in `TypeInner::Array` via `PendingArraySize::Expression` as part of the normal type adjustment process in `ModuleMap::adjust_type`, rather than cloning the type arena so we can iterate over it and call `UniqueArena::replace`. Fixes #6789. --- naga/src/compact/mod.rs | 24 ------------------------ naga/src/compact/types.rs | 12 ++++++++++-- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/naga/src/compact/mod.rs b/naga/src/compact/mod.rs index 9dff4a6cc2..6b41a2c9e2 100644 --- a/naga/src/compact/mod.rs +++ b/naga/src/compact/mod.rs @@ -216,30 +216,6 @@ pub fn compact(module: &mut crate::Module) { } } - for (handle, ty) in module.types.clone().iter() { - if let crate::TypeInner::Array { - base, - size: crate::ArraySize::Pending(crate::PendingArraySize::Expression(mut size_expr)), - stride, - } = ty.inner - { - module_map.global_expressions.adjust(&mut size_expr); - module.types.replace( - handle, - crate::Type { - name: None, - inner: crate::TypeInner::Array { - base, - size: crate::ArraySize::Pending(crate::PendingArraySize::Expression( - size_expr, - )), - stride, - }, - }, - ); - } - } - // Temporary storage to help us reuse allocations of existing // named expression tables. let mut reused_named_expressions = crate::NamedExpressions::default(); diff --git a/naga/src/compact/types.rs b/naga/src/compact/types.rs index ec75e3ae2a..ae4ae35580 100644 --- a/naga/src/compact/types.rs +++ b/naga/src/compact/types.rs @@ -82,9 +82,17 @@ impl ModuleMap { } => adjust(base), Ti::Array { ref mut base, - size: _, + ref mut size, stride: _, - } => adjust(base), + } => { + adjust(base); + if let crate::ArraySize::Pending(crate::PendingArraySize::Expression( + ref mut size_expr, + )) = *size + { + self.global_expressions.adjust(size_expr); + } + } Ti::Struct { ref mut members, span: _,