Skip to content

Commit

Permalink
chore: remove usage of expect in assert_eq
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Aug 21, 2023
1 parent b445a10 commit 3f6e4ed
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions crates/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,17 +984,22 @@ impl Context {
lhs: AcirValue,
rhs: AcirValue,
read_from_index: &mut impl FnMut(BlockId, usize) -> Result<AcirVar, InternalError>,
) -> Vec<(AcirVar, AcirVar)> {
) -> Result<Vec<(AcirVar, AcirVar)>, InternalError> {
match (lhs, rhs) {
(AcirValue::Var(lhs, _), AcirValue::Var(rhs, _)) => vec![(lhs, rhs)],
(AcirValue::Array(lhs_values), AcirValue::Array(rhs_values)) => lhs_values
.into_iter()
.zip(rhs_values)
.flat_map(|(lhs, rhs)| {
get_var_equality_assertions(lhs, rhs, read_from_index)
})
.collect(),

(AcirValue::Var(lhs, _), AcirValue::Var(rhs, _)) => Ok(vec![(lhs, rhs)]),
(AcirValue::Array(lhs_values), AcirValue::Array(rhs_values)) => {
let var_equality_assertions = lhs_values
.into_iter()
.zip(rhs_values)
.map(|(lhs, rhs)| {
get_var_equality_assertions(lhs, rhs, read_from_index)
})
.collect::<Result<Vec<_>, _>>()?
.into_iter()
.flatten()
.collect();
Ok(var_equality_assertions)
}
(
AcirValue::DynamicArray(AcirDynamicArray {
block_id: lhs_block_id,
Expand All @@ -1007,12 +1012,12 @@ impl Context {
) => {
let mut var_equality_assertions = Vec::with_capacity(len);
for i in 0..len {
let lhs_var = read_from_index(lhs_block_id, i).expect("temporary");
let rhs_var = read_from_index(rhs_block_id, i).expect("temporary");
let lhs_var = read_from_index(lhs_block_id, i)?;
let rhs_var = read_from_index(rhs_block_id, i)?;

var_equality_assertions.push((lhs_var, rhs_var));
}
var_equality_assertions
Ok(var_equality_assertions)
}
_ => unreachable!("ICE: lhs and rhs should be of the same type"),
}
Expand All @@ -1030,7 +1035,7 @@ impl Context {
};

for (lhs, rhs) in
get_var_equality_assertions(lhs, rhs, &mut read_dynamic_array_index)
get_var_equality_assertions(lhs, rhs, &mut read_dynamic_array_index)?
{
self.acir_context.assert_eq_var(lhs, rhs)?;
}
Expand Down

0 comments on commit 3f6e4ed

Please sign in to comment.