Skip to content

Commit

Permalink
chore: remove concept of constraining non-primitive types from acir-g…
Browse files Browse the repository at this point in the history
…en (#4085)

# Description

## Problem\*

Followup to #3916

## Summary\*

`Instruction::Constrain` is now only defined for primitive types so we
don't require handling for array equalities in ACIR-gen as this should
be decomposed in SSA.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jan 18, 2024
1 parent 9d15ae6 commit 43ff613
Showing 1 changed file with 3 additions and 55 deletions.
58 changes: 3 additions & 55 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,62 +410,10 @@ impl Context {
self.define_result_var(dfg, instruction_id, result_acir_var);
}
Instruction::Constrain(lhs, rhs, assert_message) => {
let lhs = self.convert_value(*lhs, dfg);
let rhs = self.convert_value(*rhs, dfg);

fn get_var_equality_assertions(
lhs: AcirValue,
rhs: AcirValue,
read_from_index: &mut impl FnMut(BlockId, usize) -> Result<AcirVar, InternalError>,
) -> Result<Vec<(AcirVar, AcirVar)>, InternalError> {
match (lhs, rhs) {
(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,
len,
..
}),
AcirValue::DynamicArray(AcirDynamicArray {
block_id: rhs_block_id,
..
}),
) => try_vecmap(0..len, |i| {
let lhs_var = read_from_index(lhs_block_id, i)?;
let rhs_var = read_from_index(rhs_block_id, i)?;
Ok((lhs_var, rhs_var))
}),
_ => {
unreachable!("ICE: lhs and rhs should be of the same type")
}
}
}

let mut read_dynamic_array_index =
|block_id: BlockId, array_index: usize| -> Result<AcirVar, InternalError> {
let index_var = self.acir_context.add_constant(array_index);
let lhs = self.convert_numeric_value(*lhs, dfg)?;
let rhs = self.convert_numeric_value(*rhs, dfg)?;

self.acir_context.read_from_memory(block_id, &index_var)
};

for (lhs, rhs) in
get_var_equality_assertions(lhs, rhs, &mut read_dynamic_array_index)?
{
self.acir_context.assert_eq_var(lhs, rhs, assert_message.clone())?;
}
self.acir_context.assert_eq_var(lhs, rhs, assert_message.clone())?;
}
Instruction::Cast(value_id, _) => {
let acir_var = self.convert_numeric_value(*value_id, dfg)?;
Expand Down

0 comments on commit 43ff613

Please sign in to comment.