Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 8 additions & 29 deletions compiler/noirc_evaluator/src/ssa/opt/array_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
impl Function {
pub(crate) fn array_set_optimization(&mut self) {
if matches!(self.runtime(), RuntimeType::Brillig(_)) {
// Brillig is supposed to use refcounting to decide whether to mutate an array;

Check warning on line 32 in compiler/noirc_evaluator/src/ssa/opt/array_set.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (refcounting)
// array mutation was only meant for ACIR. We could use it with Brillig as well,
// but then some of the optimizations that we can do in ACIR around shared
// references have to be skipped, which makes it more cumbersome.
Expand All @@ -53,9 +53,7 @@
}

let instructions_to_update = mem::take(&mut context.instructions_that_can_be_made_mutable);
for block in reachable_blocks {
make_mutable(&mut self.dfg, block, &instructions_to_update);
}
make_mutable(&mut self.dfg, &instructions_to_update);
}
}

Expand Down Expand Up @@ -159,34 +157,15 @@
}

/// Make each ArraySet instruction in `instructions_to_update` mutable.
fn make_mutable(
dfg: &mut DataFlowGraph,
block_id: BasicBlockId,
instructions_to_update: &HashSet<InstructionId>,
) {
if instructions_to_update.is_empty() {
return;
}

// Take the instructions temporarily so we can mutate the DFG while we iterate through them
let block = &mut dfg[block_id];
let instructions = block.take_instructions();

for instruction in &instructions {
if instructions_to_update.contains(instruction) {
let instruction = &mut dfg[*instruction];

if let Instruction::ArraySet { mutable, .. } = instruction {
*mutable = true;
} else {
unreachable!(
"Non-ArraySet instruction in instructions_to_update!\n{instruction:?}"
);
}
fn make_mutable(dfg: &mut DataFlowGraph, instructions_to_update: &HashSet<InstructionId>) {
for instruction_id in instructions_to_update {
let instruction = &mut dfg[*instruction_id];
if let Instruction::ArraySet { mutable, .. } = instruction {
*mutable = true;
} else {
unreachable!("Non-ArraySet instruction in instructions_to_update!\n{instruction:?}");
}
}

*dfg[block_id].instructions_mut() = instructions;
}

#[cfg(test)]
Expand Down
Loading