From 9704bd0abfe2dba1e7a4aef6cdb6cc83d70b929e Mon Sep 17 00:00:00 2001 From: Maxim Vezenov Date: Tue, 23 Apr 2024 14:59:03 +0100 Subject: [PATCH] chore: Delete unused brillig methods (#4887) # Description ## Problem\* Leftover work from #4848 that I forgot to include ## Summary\* ## Additional Context ## Documentation\* Check one: - [X] No documentation needed. - [ ] Documentation included in this PR. - [ ] **[For Experimental Features]** 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. --- .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 91 ------------------- .../ssa/acir_gen/acir_ir/generated_acir.rs | 31 +------ 2 files changed, 1 insertion(+), 121 deletions(-) diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 5e94f60b82a..3f5e4129dd0 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -1468,97 +1468,6 @@ impl AcirContext { id } - // TODO: Delete this method once we remove the `Brillig` opcode - pub(crate) fn brillig( - &mut self, - predicate: AcirVar, - generated_brillig: GeneratedBrillig, - inputs: Vec, - outputs: Vec, - attempt_execution: bool, - unsafe_return_values: bool, - ) -> Result, RuntimeError> { - let b_inputs = try_vecmap(inputs, |i| -> Result<_, InternalError> { - match i { - AcirValue::Var(var, _) => Ok(BrilligInputs::Single(self.var_to_expression(var)?)), - AcirValue::Array(vars) => { - let mut var_expressions: Vec = Vec::new(); - for var in vars { - self.brillig_array_input(&mut var_expressions, var)?; - } - Ok(BrilligInputs::Array(var_expressions)) - } - AcirValue::DynamicArray(AcirDynamicArray { block_id, .. }) => { - Ok(BrilligInputs::MemoryArray(block_id)) - } - } - })?; - - // Optimistically try executing the brillig now, if we can complete execution they just return the results. - // This is a temporary measure pending SSA optimizations being applied to Brillig which would remove constant-input opcodes (See #2066) - // - // We do _not_ want to do this in the situation where the `main` function is unconstrained, as if execution succeeds - // the entire program will be replaced with witness constraints to its outputs. - if attempt_execution { - if let Some(brillig_outputs) = - self.execute_brillig(&generated_brillig.byte_code, &b_inputs, &outputs) - { - return Ok(brillig_outputs); - } - } - - // Otherwise we must generate ACIR for it and execute at runtime. - let mut b_outputs = Vec::new(); - let outputs_var = vecmap(outputs, |output| match output { - AcirType::NumericType(_) => { - let witness_index = self.acir_ir.next_witness_index(); - b_outputs.push(BrilligOutputs::Simple(witness_index)); - let var = self.add_data(AcirVarData::Witness(witness_index)); - AcirValue::Var(var, output.clone()) - } - AcirType::Array(element_types, size) => { - let (acir_value, witnesses) = self.brillig_array_output(&element_types, size); - b_outputs.push(BrilligOutputs::Array(witnesses)); - acir_value - } - }); - let predicate = self.var_to_expression(predicate)?; - self.acir_ir.brillig(Some(predicate), generated_brillig, b_inputs, b_outputs); - - fn range_constraint_value( - context: &mut AcirContext, - value: &AcirValue, - ) -> Result<(), RuntimeError> { - match value { - AcirValue::Var(var, typ) => { - let numeric_type = match typ { - AcirType::NumericType(numeric_type) => numeric_type, - _ => unreachable!("`AcirValue::Var` may only hold primitive values"), - }; - context.range_constrain_var(*var, numeric_type, None)?; - } - AcirValue::Array(values) => { - for value in values { - range_constraint_value(context, value)?; - } - } - AcirValue::DynamicArray(_) => { - unreachable!("Brillig opcodes cannot return dynamic arrays") - } - } - Ok(()) - } - - // This is a hack to ensure that if we're compiling a brillig entrypoint function then - // we don't also add a number of range constraints. - if !unsafe_return_values { - for output_var in &outputs_var { - range_constraint_value(self, output_var)?; - } - } - Ok(outputs_var) - } - #[allow(clippy::too_many_arguments)] pub(crate) fn brillig_call( &mut self, diff --git a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index ab5fa0c5245..0b04d1b63ab 100644 --- a/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -10,7 +10,7 @@ use crate::{ use acvm::acir::{ circuit::{ - brillig::{Brillig as AcvmBrillig, BrilligInputs, BrilligOutputs}, + brillig::{BrilligInputs, BrilligOutputs}, opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode}, OpcodeLocation, }, @@ -625,35 +625,6 @@ impl GeneratedAcir { Ok(()) } - // TODO: Delete this method once we remove the `Brillig` opcode - pub(crate) fn brillig( - &mut self, - predicate: Option, - generated_brillig: GeneratedBrillig, - inputs: Vec, - outputs: Vec, - ) { - let opcode = AcirOpcode::Brillig(AcvmBrillig { - inputs, - outputs, - bytecode: generated_brillig.byte_code, - predicate, - }); - self.push_opcode(opcode); - for (brillig_index, call_stack) in generated_brillig.locations { - self.locations.insert( - OpcodeLocation::Brillig { acir_index: self.opcodes.len() - 1, brillig_index }, - call_stack, - ); - } - for (brillig_index, message) in generated_brillig.assert_messages { - self.assert_messages.insert( - OpcodeLocation::Brillig { acir_index: self.opcodes.len() - 1, brillig_index }, - message, - ); - } - } - pub(crate) fn brillig_call( &mut self, predicate: Option,