Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unnecessary AcirValues #2823

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 4 additions & 12 deletions compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,12 @@ impl AcirContext {

// Compute the inverse with brillig code
let inverse_code = brillig_directive::directive_invert();
let field_type = AcirType::NumericType(NumericType::NativeField);

let results = self.brillig(
predicate,
inverse_code,
vec![AcirValue::Var(var, field_type.clone())],
vec![field_type],
vec![AcirValue::Var(var, AcirType::field())],
vec![AcirType::field()],
)?;
let inverted_var = Self::expect_one_var(results);

Expand Down Expand Up @@ -1007,17 +1006,10 @@ impl AcirContext {
AcirValue::DynamicArray(AcirDynamicArray { block_id, len }) => {
for i in 0..len {
// We generate witnesses corresponding to the array values
let index = AcirValue::Var(
self.add_constant(FieldElement::from(i as u128)),
AcirType::NumericType(NumericType::NativeField),
);
let index_var = index.into_var()?;
let index_var = self.add_constant(FieldElement::from(i as u128));

let value_read_var = self.read_from_memory(block_id, &index_var)?;
let value_read = AcirValue::Var(
value_read_var,
AcirType::NumericType(NumericType::NativeField),
);
let value_read = AcirValue::Var(value_read_var, AcirType::field());

self.brillig_array_input(var_expressions, value_read)?;
}
Expand Down
32 changes: 8 additions & 24 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,8 @@ impl Context {

let mut read_dynamic_array_index =
|block_id: BlockId, array_index: usize| -> Result<AcirVar, InternalError> {
let index = AcirValue::Var(
self.acir_context.add_constant(FieldElement::from(array_index as u128)),
AcirType::NumericType(NumericType::NativeField),
);
let index_var = index.into_var()?;
let index_var =
self.acir_context.add_constant(FieldElement::from(array_index as u128));

self.acir_context.read_from_memory(block_id, &index_var)
};
Expand Down Expand Up @@ -896,16 +893,10 @@ impl Context {
// Initialize the new array with the values from the old array
result_block_id = self.block_id(result_id);
let init_values = try_vecmap(0..array_len, |i| {
let index = AcirValue::Var(
self.acir_context.add_constant(FieldElement::from(i as u128)),
AcirType::NumericType(NumericType::NativeField),
);
let var = index.into_var()?;
let read = self.acir_context.read_from_memory(block_id, &var)?;
Ok::<AcirValue, RuntimeError>(AcirValue::Var(
read,
AcirType::NumericType(NumericType::NativeField),
))
let index_var = self.acir_context.add_constant(FieldElement::from(i as u128));

let read = self.acir_context.read_from_memory(block_id, &index_var)?;
Ok::<AcirValue, RuntimeError>(AcirValue::Var(read, AcirType::field()))
})?;
self.initialize_array(
result_block_id,
Expand Down Expand Up @@ -1609,18 +1600,11 @@ impl Context {
AcirValue::DynamicArray(AcirDynamicArray { block_id, len }) => {
for i in 0..len {
// We generate witnesses corresponding to the array values
let index = AcirValue::Var(
self.acir_context.add_constant(FieldElement::from(i as u128)),
AcirType::NumericType(NumericType::NativeField),
);
let index_var = self.acir_context.add_constant(FieldElement::from(i as u128));

let index_var = index.into_var()?;
let value_read_var =
self.acir_context.read_from_memory(block_id, &index_var)?;
let value_read = AcirValue::Var(
value_read_var,
AcirType::NumericType(NumericType::NativeField),
);
let value_read = AcirValue::Var(value_read_var, AcirType::field());

old_slice.push_back(value_read);
}
Expand Down