Skip to content

Commit 0b8ba8f

Browse files
committed
chore: remove mutable references to vecs
1 parent 323a628 commit 0b8ba8f

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

compiler/noirc_evaluator/src/ssa/opt/unrolling.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ impl Ssa {
4444
pub(crate) fn unroll_loops_iteratively(mut ssa: Ssa) -> Result<Ssa, RuntimeError> {
4545
for (_, function) in ssa.functions.iter_mut() {
4646
// Try to unroll loops first:
47-
let mut unroll_errors: Vec<RuntimeError> = Vec::new();
48-
function.try_to_unroll_loops(&mut unroll_errors);
47+
let unroll_errors = function.try_to_unroll_loops();
4948

5049
// Keep unrolling until no more errors are found
5150
while !unroll_errors.is_empty() {
@@ -60,8 +59,7 @@ impl Ssa {
6059
function.mem2reg();
6160

6261
// Unroll again
63-
unroll_errors = Vec::new();
64-
function.try_to_unroll_loops(&mut unroll_errors);
62+
let mut unroll_errors = function.try_to_unroll_loops();
6563
// If we didn't manage to unroll any more loops, exit
6664
if unroll_errors.len() >= prev_unroll_err_count {
6765
return Err(unroll_errors.swap_remove(0));
@@ -74,12 +72,14 @@ impl Ssa {
7472
}
7573

7674
impl Function {
77-
pub(crate) fn try_to_unroll_loops(&mut self, errors: &mut Vec<RuntimeError>) {
75+
fn try_to_unroll_loops(&mut self) -> Vec<RuntimeError> {
7876
// Loop unrolling in brillig can lead to a code explosion currently. This can
7977
// also be true for ACIR, but we have no alternative to unrolling in ACIR.
8078
// Brillig also generally prefers smaller code rather than faster code.
8179
if !matches!(self.runtime(), RuntimeType::Brillig(_)) {
82-
errors.extend(find_all_loops(self).unroll_each_loop(self));
80+
find_all_loops(self).unroll_each_loop(self)
81+
} else {
82+
Vec::new()
8383
}
8484
}
8585
}

0 commit comments

Comments
 (0)