From 1c2cee56f61e8122c7d62e617dd407a55d08a3ce Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Mon, 29 May 2023 18:52:27 +0100 Subject: [PATCH] return optimized circuit --- crates/noirc_evaluator/src/ssa_refactor.rs | 27 ++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/crates/noirc_evaluator/src/ssa_refactor.rs b/crates/noirc_evaluator/src/ssa_refactor.rs index 2959aef9661..199f6328090 100644 --- a/crates/noirc_evaluator/src/ssa_refactor.rs +++ b/crates/noirc_evaluator/src/ssa_refactor.rs @@ -50,8 +50,8 @@ pub(crate) fn optimize_into_acir(program: Program) -> GeneratedAcir { /// to use the new ssa module to process Noir code. pub fn experimental_create_circuit( program: Program, - _np_language: Language, - _is_opcode_supported: &impl Fn(&AcirOpcode) -> bool, + np_language: Language, + is_opcode_supported: &impl Fn(&AcirOpcode) -> bool, _enable_logging: bool, _show_output: bool, ) -> Result<(Circuit, Abi), RuntimeError> { @@ -65,8 +65,27 @@ pub fn experimental_create_circuit( let public_parameters = PublicInputs(public_abi.param_witnesses.values().flatten().copied().collect()); let return_values = PublicInputs(return_witnesses.into_iter().collect()); - let circuit = Circuit { current_witness_index, opcodes, public_parameters, return_values }; - Ok((circuit, abi)) + + // This region of code will optimize the ACIR bytecode for a particular backend + // it will be removed in the near future and we will subsequently only return the + // unoptimized backend-agnostic bytecode here + let optimized_circuit = { + use crate::errors::RuntimeErrorKind; + use acvm::compiler::optimizers::simplify::CircuitSimplifier; + + let abi_len = abi.field_count(); + + let simplifier = CircuitSimplifier::new(abi_len); + acvm::compiler::compile( + Circuit { current_witness_index, opcodes, public_parameters, return_values }, + np_language, + is_opcode_supported, + &simplifier, + ) + .map_err(|_| RuntimeErrorKind::Spanless(String::from("produced an acvm compile error")))? + }; + + Ok((optimized_circuit, abi)) } impl Ssa {