Skip to content

Commit

Permalink
revert #5547
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic committed Jul 19, 2024
1 parent 5972dc9 commit 34c9720
Showing 1 changed file with 13 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use iter_extended::vecmap;

use crate::ssa::ir::types::Type;

use super::{
basic_block::BasicBlockId,
dfg::{CallStack, InsertInstructionResult},
function::{Function, RuntimeType},
function::Function,
instruction::{Instruction, InstructionId},
value::ValueId,
};
Expand All @@ -22,7 +20,7 @@ pub(crate) struct FunctionInserter<'f> {
/// array unnecessarily. An extra bool is included as part of the key to
/// distinguish between Type::Array and Type::Slice, as both are valid
/// types for a Value::Array
const_arrays: HashMap<(im::Vector<ValueId>, bool), ValueId>,
const_arrays: HashMap<im::Vector<ValueId>, ValueId>,
}

impl<'f> FunctionInserter<'f> {
Expand All @@ -44,26 +42,15 @@ impl<'f> FunctionInserter<'f> {
let new_array: im::Vector<ValueId> =
array.iter().map(|id| self.resolve(*id)).collect();

// Flag to determine the type of the value's array list
let is_array = matches!(typ, Type::Array { .. });
if let Some(fetched_value) =
self.const_arrays.get(&(new_array.clone(), is_array))
{
// Arrays in ACIR are immutable, but in Brillig arrays are copy-on-write
// so for function's with a Brillig runtime we make sure to check that value
// in our constants array map matches the resolved array value id.
if matches!(self.function.runtime(), RuntimeType::Acir(_)) {
return *fetched_value;
} else if *fetched_value == value {
return value;
}
};

let new_array_clone = new_array.clone();
let new_id = self.function.dfg.make_array(new_array, typ);
self.values.insert(value, new_id);
self.const_arrays.insert((new_array_clone, is_array), new_id);
new_id
if self.const_arrays.get(&new_array) == Some(&value) {
value
} else {
let new_array_clone = new_array.clone();
let new_id = self.function.dfg.make_array(new_array, typ);
self.values.insert(value, new_id);
self.const_arrays.insert(new_array_clone, new_id);
new_id
}
}
_ => value,
},
Expand Down Expand Up @@ -127,6 +114,7 @@ impl<'f> FunctionInserter<'f> {
block: BasicBlockId,
call_stack: CallStack,
) -> InsertInstructionResult {
let toto = self.function.name().clone().to_string();
let results = self.function.dfg.instruction_results(id);
let results = vecmap(results, |id| self.function.dfg.resolve(*id));

Expand All @@ -139,6 +127,7 @@ impl<'f> FunctionInserter<'f> {
block,
ctrl_typevars,
call_stack,
&toto,
);

Self::insert_new_instruction_results(&mut self.values, &results, &new_results);
Expand Down

0 comments on commit 34c9720

Please sign in to comment.