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
39 changes: 28 additions & 11 deletions compiler/noirc_evaluator/src/ssa/opt/array_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@ fn array_set_optimization_pre_check(func: &Function) {

let reachable_blocks = func.reachable_blocks();

if !func.runtime().is_entry_point() {
assert_eq!(
reachable_blocks.len(),
1,
"Expected there to be 1 block remaining in ACIR function for array_set optimization"
);
}
assert_eq!(
reachable_blocks.len(),
1,
"Expected there to be 1 block remaining in ACIR function for array_set optimization"
);

for block_id in reachable_blocks {
let instruction_ids = func.dfg[block_id].instructions();
Expand Down Expand Up @@ -129,10 +127,8 @@ impl Function {
}

let mut context = Context::new(&self.dfg);

for block in self.reachable_blocks() {
context.analyze_last_uses(block);
}
let entry_block = self.entry_block();
context.analyze_last_uses(entry_block);

let instructions_to_update = mem::take(&mut context.instructions_that_can_be_made_mutable);
make_mutable(&mut self.dfg, &instructions_to_update);
Expand Down Expand Up @@ -261,6 +257,7 @@ mod tests {
assert_ssa_snapshot,
ssa::{Ssa, opt::assert_ssa_does_not_change},
};
use test_case::test_case;

#[test]
fn does_not_mutate_array_used_in_make_array() {
Expand Down Expand Up @@ -390,4 +387,24 @@ mod tests {
let ssa = Ssa::from_str(src).unwrap();
let _ssa = ssa.array_set_optimization();
}

#[test_case("inline")]
#[test_case("fold")]
#[should_panic = "Expected there to be 1 block remaining in ACIR function for array_set optimization"]
fn disallows_multiple_blocks(inline_type: &str) {
let src = format!(
"
acir({inline_type}) fn main f0 {{
b0():
v1 = make_array [Field 0] : [Field; 1]
v2 = array_set v1, index u32 0, value Field 1
jmp b1()
b1():
v3 = array_get v2, index u32 0 -> Field
return v3
}}"
);
let ssa = Ssa::from_str(&src).unwrap();
let _ssa = ssa.array_set_optimization();
}
}
Loading