diff --git a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs index 78b857e9fd5..533eb987073 100644 --- a/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs +++ b/compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs @@ -191,7 +191,7 @@ impl<'f> PerFunctionContext<'f> { // so that for example if the value is an array and contains a reference, // then that reference gets to keep its last store. let typ = self.inserter.function.dfg.type_of_value(value); - if Self::contains_references(&typ) { + if typ.contains_reference() { if let Some(expression) = references.expressions.get(&value) { if let Some(aliases) = references.aliases.get(expression) { aliases.for_each(|alias| { @@ -528,7 +528,7 @@ impl<'f> PerFunctionContext<'f> { let array = *array; let array_typ = self.inserter.function.dfg.type_of_value(array); - if Self::contains_references(&array_typ) { + if array_typ.contains_reference() { references.for_each_alias_of(array, |_, alias| { self.instruction_input_references.insert(alias); }); @@ -545,7 +545,7 @@ impl<'f> PerFunctionContext<'f> { references.mark_value_used(*array, self.inserter.function); let element_type = self.inserter.function.dfg.type_of_value(*value); - if Self::contains_references(&element_type) { + if element_type.contains_reference() { let result = self.inserter.function.dfg.instruction_results(instruction)[0]; let array = *array; @@ -590,7 +590,7 @@ impl<'f> PerFunctionContext<'f> { Instruction::MakeArray { elements, typ } => { // If `array` is an array constant that contains reference types, then insert each element // as a potential alias to the array itself. - if Self::contains_references(typ) { + if typ.contains_reference() { let array = self.inserter.function.dfg.instruction_results(instruction)[0]; let expr = Expression::ArrayElement(Box::new(Expression::Other(array))); @@ -604,7 +604,7 @@ impl<'f> PerFunctionContext<'f> { let result = self.inserter.function.dfg.instruction_results(instruction)[0]; let result_type = self.inserter.function.dfg.type_of_value(result); - if Self::contains_references(&result_type) { + if result_type.contains_reference() { let expr = Expression::Other(result); references.expressions.insert(result, expr.clone()); references.aliases.insert( @@ -629,17 +629,6 @@ impl<'f> PerFunctionContext<'f> { } } - fn contains_references(typ: &Type) -> bool { - match typ { - Type::Numeric(_) => false, - Type::Function => false, - Type::Reference(_) => true, - Type::Array(elements, _) | Type::Slice(elements) => { - elements.iter().any(Self::contains_references) - } - } - } - fn set_aliases(&self, references: &mut Block, address: ValueId, new_aliases: AliasSet) { let expression = references.expressions.entry(address).or_insert(Expression::Other(address)); @@ -650,7 +639,7 @@ impl<'f> PerFunctionContext<'f> { fn mark_all_unknown(&self, values: &[ValueId], references: &mut Block) { for value in values { let typ = self.inserter.function.dfg.type_of_value(*value); - if Self::contains_references(&typ) { + if typ.contains_reference() { let value = *value; references.set_unknown(value); references.mark_value_used(value, self.inserter.function);