Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

chore!: Return an iterator from new_locations() instead of collecting #507

Merged
merged 1 commit into from
Aug 30, 2023
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
40 changes: 12 additions & 28 deletions acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,25 @@ pub struct AcirTransformationMap {
}

impl AcirTransformationMap {
pub fn new_locations(&self, old_location: OpcodeLocation) -> Vec<OpcodeLocation> {
pub fn new_locations(
&self,
old_location: OpcodeLocation,
) -> impl Iterator<Item = OpcodeLocation> + '_ {
let old_acir_index = match old_location {
OpcodeLocation::Acir(index) => index,
OpcodeLocation::Brillig { acir_index, .. } => acir_index,
};

let new_opcode_indexes: Vec<usize> = self
.acir_opcode_positions
self.acir_opcode_positions
.iter()
.enumerate()
.filter_map(
|(new_index, &old_index)| {
if old_index == old_acir_index {
Some(new_index)
} else {
None
}
},
)
.collect();

match old_location {
OpcodeLocation::Acir(_) => new_opcode_indexes
.iter()
.map(|&new_index| OpcodeLocation::Acir(new_index))
.collect(),
OpcodeLocation::Brillig { brillig_index, .. } => {
assert!(
new_opcode_indexes.len() == 1,
"The transformation must not decompose or remove brillig opcodes"
);

vec![OpcodeLocation::Brillig { acir_index: new_opcode_indexes[0], brillig_index }]
}
}
.filter(move |(_, &old_index)| old_index == old_acir_index)
.map(move |(new_index, _)| match old_location {
OpcodeLocation::Acir(_) => OpcodeLocation::Acir(new_index),
OpcodeLocation::Brillig { brillig_index, .. } => {
OpcodeLocation::Brillig { acir_index: new_index, brillig_index }
}
})
}
}

Expand Down