diff --git a/naga/src/back/msl/writer.rs b/naga/src/back/msl/writer.rs index 458214b23..4ba478c85 100644 --- a/naga/src/back/msl/writer.rs +++ b/naga/src/back/msl/writer.rs @@ -630,7 +630,13 @@ impl<'a> ExpressionContext<'a> { base: Handle, index: index::GuardedIndex, ) -> Option { - index::access_needs_check(base, index, self.module, self.function, self.info) + index::access_needs_check( + base, + index, + self.module, + &self.function.expressions, + self.info, + ) } fn get_packed_vec_kind(&self, expr_handle: Handle) -> Option { diff --git a/naga/src/back/spv/block.rs b/naga/src/back/spv/block.rs index fee9b9300..65c48d9e7 100644 --- a/naga/src/back/spv/block.rs +++ b/naga/src/back/spv/block.rs @@ -357,8 +357,11 @@ impl<'w> BlockContext<'w> { } crate::TypeInner::Array { .. } | crate::TypeInner::Matrix { .. } => { // See if `index` is known at compile time. - match GuardedIndex::from_expression(index, self.ir_function, self.ir_module) - { + match GuardedIndex::from_expression( + index, + &self.ir_function.expressions, + self.ir_module, + ) { GuardedIndex::Known(value) => { // If `index` is known and in bounds, we can just use // `OpCompositeExtract`. diff --git a/naga/src/back/spv/index.rs b/naga/src/back/spv/index.rs index f1122ee4a..0b806d881 100644 --- a/naga/src/back/spv/index.rs +++ b/naga/src/back/spv/index.rs @@ -512,7 +512,7 @@ impl<'w> BlockContext<'w> { block: &mut Block, ) -> Result { // If the value of `index` is known at compile time, find it now. - index.try_resolve_to_constant(self.ir_function, self.ir_module); + index.try_resolve_to_constant(&self.ir_function.expressions, self.ir_module); let policy = self.writer.bounds_check_policies.choose_policy( base, diff --git a/naga/src/proc/index.rs b/naga/src/proc/index.rs index 810f42e41..d0a7f73e2 100644 --- a/naga/src/proc/index.rs +++ b/naga/src/proc/index.rs @@ -250,7 +250,7 @@ pub fn find_checked_indexes( base, GuardedIndex::Expression(index), module, - function, + &function.expressions, info, ) .is_some() @@ -311,7 +311,7 @@ pub fn access_needs_check( base: Handle, mut index: GuardedIndex, module: &crate::Module, - function: &crate::Function, + expressions: &crate::Arena, info: &valid::FunctionInfo, ) -> Option { let base_inner = info[base].ty.inner_with(&module.types); @@ -319,7 +319,7 @@ pub fn access_needs_check( // length constants, but `access_needs_check` is only used by back ends, so // validation should have caught those problems. let length = base_inner.indexable_length(module).unwrap(); - index.try_resolve_to_constant(function, module); + index.try_resolve_to_constant(expressions, module); if let (&GuardedIndex::Known(index), &IndexableLength::Known(length)) = (&index, &length) { if index < length { // Index is statically known to be in bounds, no check needed. @@ -336,23 +336,20 @@ impl GuardedIndex { /// Return values that are already `Known` unchanged. pub(crate) fn try_resolve_to_constant( &mut self, - function: &crate::Function, + expressions: &crate::Arena, module: &crate::Module, ) { if let GuardedIndex::Expression(expr) = *self { - *self = GuardedIndex::from_expression(expr, function, module); + *self = GuardedIndex::from_expression(expr, expressions, module); } } pub(crate) fn from_expression( expr: Handle, - function: &crate::Function, + expressions: &crate::Arena, module: &crate::Module, ) -> Self { - match module - .to_ctx() - .eval_expr_to_u32_from(expr, &function.expressions) - { + match module.to_ctx().eval_expr_to_u32_from(expr, expressions) { Ok(value) => Self::Known(value), Err(_) => Self::Expression(expr), }