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

feat(ssa refactor): experimental-ssa compiler flag #1289

Merged
merged 4 commits into from
May 4, 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
7 changes: 6 additions & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
34 changes: 25 additions & 9 deletions crates/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
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 }
}
}

Expand Down Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions crates/noirc_evaluator/src/ssa_refactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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")
}