From afa67494c564b68b667535f2d8ef234fbc4bec12 Mon Sep 17 00:00:00 2001 From: joss-aztec <94053499+joss-aztec@users.noreply.github.com> Date: Thu, 4 May 2023 13:50:09 +0100 Subject: [PATCH] feat(ssa refactor): experimental-ssa compiler flag (#1289) * feat(ssa refactor): experimental-ssa compiler flag * move experimental method into ssa_refactor * check the experimental flag in the driver module * undo changes to `create_circuit` --------- Co-authored-by: Kevaundray Wedderburn --- crates/nargo_cli/src/cli/mod.rs | 7 ++++- crates/noirc_driver/src/lib.rs | 34 ++++++++++++++++------ crates/noirc_evaluator/src/ssa_refactor.rs | 16 ++++++++++ 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index ef54682ab50..5450bb39660 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -85,7 +85,12 @@ pub fn start_cli() -> eyre::Result<()> { // helper function which tests noir programs by trying to generate a proof and verify it pub fn prove_and_verify(proof_name: &str, program_dir: &Path, show_ssa: bool) -> bool { - let compile_options = CompileOptions { show_ssa, allow_warnings: false, show_output: false }; + let compile_options = CompileOptions { + show_ssa, + allow_warnings: false, + show_output: false, + experimental_ssa: false, + }; let proof_dir = program_dir.join(PROOFS_DIR); match prove_cmd::prove_with_path( diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 2fcef5bc578..a2fbed21885 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -10,7 +10,7 @@ use fm::FileType; use iter_extended::try_vecmap; use noirc_abi::FunctionSignature; use noirc_errors::{reporter, ReportedError}; -use noirc_evaluator::create_circuit; +use noirc_evaluator::{create_circuit, ssa_refactor::experimental_create_circuit}; use noirc_frontend::graph::{CrateId, CrateName, CrateType, LOCAL_CRATE}; use noirc_frontend::hir::def_map::{Contract, CrateDefMap}; use noirc_frontend::hir::Context; @@ -43,11 +43,15 @@ pub struct CompileOptions { /// Display output of `println` statements #[arg(long)] pub show_output: bool, + + /// Compile and optimize using the new experimental SSA pass + #[arg(long)] + pub experimental_ssa: bool, } impl Default for CompileOptions { fn default() -> Self { - Self { show_ssa: false, allow_warnings: false, show_output: true } + Self { show_ssa: false, allow_warnings: false, show_output: true, experimental_ssa: false } } } @@ -254,13 +258,25 @@ impl Driver { let np_language = self.language.clone(); let is_opcode_supported = acvm::default_is_opcode_supported(np_language.clone()); - match create_circuit( - program, - np_language, - is_opcode_supported, - options.show_ssa, - options.show_output, - ) { + let circuit_abi = if options.experimental_ssa { + experimental_create_circuit( + program, + np_language, + is_opcode_supported, + options.show_ssa, + options.show_output, + ) + } else { + create_circuit( + program, + np_language, + is_opcode_supported, + options.show_ssa, + options.show_output, + ) + }; + + match circuit_abi { Ok((circuit, abi)) => Ok(CompiledProgram { circuit, abi }), Err(err) => { // The FileId here will be the file id of the file with the main file diff --git a/crates/noirc_evaluator/src/ssa_refactor.rs b/crates/noirc_evaluator/src/ssa_refactor.rs index a55f61f71d6..83f76c85ec1 100644 --- a/crates/noirc_evaluator/src/ssa_refactor.rs +++ b/crates/noirc_evaluator/src/ssa_refactor.rs @@ -7,6 +7,10 @@ //! This module heavily borrows from Cranelift #![allow(dead_code)] +use crate::errors::RuntimeError; +use acvm::{acir::circuit::Circuit, compiler::transformers::IsOpcodeSupported, Language}; +use noirc_abi::Abi; + use noirc_frontend::monomorphization::ast::Program; use self::acir_gen::Acir; @@ -22,3 +26,15 @@ pub mod ssa_gen; pub fn optimize_into_acir(program: Program) -> Acir { ssa_gen::generate_ssa(program).into_acir() } +/// Compiles the Program into ACIR and applies optimizations to the arithmetic gates +/// This is analogous to `ssa:create_circuit` and this method is called when one wants +/// to use the new ssa module to process Noir code. +pub fn experimental_create_circuit( + _program: Program, + _np_language: Language, + _is_opcode_supported: IsOpcodeSupported, + _enable_logging: bool, + _show_output: bool, +) -> Result<(Circuit, Abi), RuntimeError> { + todo!("this is a stub function for the new SSA refactor module") +}