diff --git a/Cargo.lock b/Cargo.lock index 1c7078c9c09..42476cea2a4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1016,7 +1016,6 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", "syn", ] @@ -1051,37 +1050,6 @@ dependencies = [ "syn", ] -[[package]] -name = "derive_builder" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d67778784b508018359cbc8696edb3db78160bab2c2a28ba7f56ef6932997f8" -dependencies = [ - "derive_builder_macro", -] - -[[package]] -name = "derive_builder_core" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c11bdc11a0c47bc7d37d582b5285da6849c96681023680b906673c5707af7b0f" -dependencies = [ - "darling", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "derive_builder_macro" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebcda35c7a396850a55ffeac740804b40ffec779b98fffbb1738f4033f0ee79e" -dependencies = [ - "derive_builder_core", - "syn", -] - [[package]] name = "digest" version = "0.9.0" @@ -2066,7 +2034,6 @@ name = "noirc_driver" version = "0.2.0" dependencies = [ "acvm 0.4.1", - "derive_builder", "dirs 4.0.0", "fm", "noirc_abi", diff --git a/crates/nargo/src/cli/check_cmd.rs b/crates/nargo/src/cli/check_cmd.rs index 26a3a18fcea..73af6b30f8e 100644 --- a/crates/nargo/src/cli/check_cmd.rs +++ b/crates/nargo/src/cli/check_cmd.rs @@ -3,7 +3,7 @@ use acvm::ProofSystemCompiler; use clap::Args; use iter_extended::btree_map; use noirc_abi::{Abi, AbiParameter, AbiType}; -use noirc_driver::CompileOptionsBuilder; +use noirc_driver::CompileOptions; use std::{ collections::BTreeMap, path::{Path, PathBuf}, @@ -15,27 +15,24 @@ use crate::constants::{PROVER_INPUT_FILE, VERIFIER_INPUT_FILE}; /// Checks the constraint system for errors #[derive(Debug, Clone, Args)] -pub(crate) struct CheckCommand { - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, -} +pub(crate) struct CheckCommand {} -pub(crate) fn run(args: CheckCommand, config: NargoConfig) -> Result<(), CliError> { - check_from_path(config.program_dir, args.allow_warnings)?; +pub(crate) fn run(_args: CheckCommand, config: NargoConfig) -> Result<(), CliError> { + check_from_path(config.program_dir, &CompileOptions::from(config.compile_options))?; println!("Constraint system successfully built!"); Ok(()) } // This is exposed so that we can run the examples and verify that they pass -pub fn check_from_path>(p: P, allow_warnings: bool) -> Result<(), CliError> { +pub(crate) fn check_from_path>( + p: P, + compile_options: &CompileOptions, +) -> Result<(), CliError> { let backend = crate::backends::ConcreteBackend; - let config = CompileOptionsBuilder::default().allow_warnings(allow_warnings).build().unwrap(); - let mut driver = Resolver::resolve_root_config(p.as_ref(), backend.np_language())?; add_std_lib(&mut driver); - if driver.check_crate(&config).is_err() { + if driver.check_crate(compile_options).is_err() { std::process::exit(1); } @@ -75,6 +72,8 @@ fn build_empty_map(abi: Abi) -> BTreeMap { #[cfg(test)] mod tests { + use noirc_driver::CompileOptions; + const TEST_DATA_DIR: &str = "tests/target_tests_data"; #[test] @@ -82,11 +81,12 @@ mod tests { let mut pass_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); pass_dir.push(&format!("{TEST_DATA_DIR}/pass")); + let config = CompileOptions::default(); let paths = std::fs::read_dir(pass_dir).unwrap(); for path in paths.flatten() { let path = path.path(); assert!( - super::check_from_path(path.clone(), false).is_ok(), + super::check_from_path(path.clone(), &config).is_ok(), "path: {}", path.display() ); @@ -99,11 +99,12 @@ mod tests { let mut fail_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); fail_dir.push(&format!("{TEST_DATA_DIR}/fail")); + let config = CompileOptions::default(); let paths = std::fs::read_dir(fail_dir).unwrap(); for path in paths.flatten() { let path = path.path(); assert!( - super::check_from_path(path.clone(), false).is_err(), + super::check_from_path(path.clone(), &config).is_err(), "path: {}", path.display() ); @@ -115,10 +116,17 @@ mod tests { let mut pass_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); pass_dir.push(&format!("{TEST_DATA_DIR}/pass_dev_mode")); + let mut config = CompileOptions::default(); + config.allow_warnings = true; + let paths = std::fs::read_dir(pass_dir).unwrap(); for path in paths.flatten() { let path = path.path(); - assert!(super::check_from_path(path.clone(), true).is_ok(), "path: {}", path.display()); + assert!( + super::check_from_path(path.clone(), &config).is_ok(), + "path: {}", + path.display() + ); } } } diff --git a/crates/nargo/src/cli/compile_cmd.rs b/crates/nargo/src/cli/compile_cmd.rs index 44d0fe7f4ae..248ff8bff7f 100644 --- a/crates/nargo/src/cli/compile_cmd.rs +++ b/crates/nargo/src/cli/compile_cmd.rs @@ -1,6 +1,6 @@ use acvm::acir::circuit::Circuit; use acvm::ProofSystemCompiler; -use noirc_driver::CompileOptionsBuilder; +use noirc_driver::CompileOptions; use std::path::{Path, PathBuf}; use clap::Args; @@ -15,10 +15,6 @@ use super::{add_std_lib, NargoConfig}; pub(crate) struct CompileCommand { /// The name of the ACIR file circuit_name: String, - - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, } pub(crate) fn run(args: CompileCommand, config: NargoConfig) -> Result<(), CliError> { @@ -29,7 +25,7 @@ pub(crate) fn run(args: CompileCommand, config: NargoConfig) -> Result<(), CliEr &args.circuit_name, config.program_dir, circuit_path, - args.allow_warnings, + &CompileOptions::from(config.compile_options), )?; println!("Generated ACIR code into {}", circuit_path.display()); @@ -41,9 +37,9 @@ fn compile_and_preprocess_circuit>( circuit_name: &str, program_dir: P, circuit_dir: P, - allow_warnings: bool, + compile_options: &CompileOptions, ) -> Result { - let compiled_program = compile_circuit(program_dir, false, allow_warnings)?; + let compiled_program = compile_circuit(program_dir, compile_options)?; let circuit_path = save_acir_to_dir(&compiled_program.circuit, circuit_name, &circuit_dir); preprocess_with_path(circuit_name, circuit_dir, compiled_program.circuit)?; @@ -53,19 +49,13 @@ fn compile_and_preprocess_circuit>( pub fn compile_circuit>( program_dir: P, - show_ssa: bool, - allow_warnings: bool, + compile_options: &CompileOptions, ) -> Result { let backend = crate::backends::ConcreteBackend; let mut driver = Resolver::resolve_root_config(program_dir.as_ref(), backend.np_language())?; add_std_lib(&mut driver); - let config = CompileOptionsBuilder::default() - .allow_warnings(allow_warnings) - .show_ssa(show_ssa) - .build() - .unwrap(); - driver.into_compiled_program(&config).map_err(|_| std::process::exit(1)) + driver.into_compiled_program(compile_options).map_err(|_| std::process::exit(1)) } fn preprocess_with_path>( diff --git a/crates/nargo/src/cli/contract_cmd.rs b/crates/nargo/src/cli/contract_cmd.rs index 1aa2711d679..4b78c98607c 100644 --- a/crates/nargo/src/cli/contract_cmd.rs +++ b/crates/nargo/src/cli/contract_cmd.rs @@ -3,17 +3,15 @@ use super::NargoConfig; use crate::{cli::compile_cmd::compile_circuit, constants::CONTRACT_DIR, errors::CliError}; use acvm::SmartContract; use clap::Args; +use noirc_driver::CompileOptions; /// Generates a Solidity verifier smart contract for the program #[derive(Debug, Clone, Args)] -pub(crate) struct ContractCommand { - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, -} +pub(crate) struct ContractCommand {} -pub(crate) fn run(args: ContractCommand, config: NargoConfig) -> Result<(), CliError> { - let compiled_program = compile_circuit(config.program_dir.clone(), false, args.allow_warnings)?; +pub(crate) fn run(_args: ContractCommand, config: NargoConfig) -> Result<(), CliError> { + let compiled_program = + compile_circuit(config.program_dir.clone(), &CompileOptions::from(config.compile_options))?; let backend = crate::backends::ConcreteBackend; let smart_contract_string = backend.eth_contract_from_cs(compiled_program.circuit); diff --git a/crates/nargo/src/cli/execute_cmd.rs b/crates/nargo/src/cli/execute_cmd.rs index 761f376d8f8..1fb783f657b 100644 --- a/crates/nargo/src/cli/execute_cmd.rs +++ b/crates/nargo/src/cli/execute_cmd.rs @@ -4,7 +4,7 @@ use acvm::PartialWitnessGenerator; use clap::Args; use noirc_abi::input_parser::{Format, InputValue}; use noirc_abi::{InputMap, WitnessMap}; -use noirc_driver::CompiledProgram; +use noirc_driver::{CompileOptions, CompiledProgram}; use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir}; use super::NargoConfig; @@ -19,19 +19,11 @@ use crate::{ pub(crate) struct ExecuteCommand { /// Write the execution witness to named file witness_name: Option, - - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, - - /// Emit debug information for the intermediate SSA IR - #[arg(short, long)] - show_ssa: bool, } pub(crate) fn run(args: ExecuteCommand, config: NargoConfig) -> Result<(), CliError> { let (return_value, solved_witness) = - execute_with_path(&config.program_dir, args.show_ssa, args.allow_warnings)?; + execute_with_path(&config.program_dir, &CompileOptions::from(config.compile_options))?; println!("Circuit witness successfully solved"); if let Some(return_value) = return_value { @@ -50,10 +42,9 @@ pub(crate) fn run(args: ExecuteCommand, config: NargoConfig) -> Result<(), CliEr fn execute_with_path>( program_dir: P, - show_ssa: bool, - allow_warnings: bool, + compile_options: &CompileOptions, ) -> Result<(Option, WitnessMap), CliError> { - let compiled_program = compile_circuit(&program_dir, show_ssa, allow_warnings)?; + let compiled_program = compile_circuit(&program_dir, compile_options)?; // Parse the initial witness values from Prover.toml let (inputs_map, _) = read_inputs_from_file( diff --git a/crates/nargo/src/cli/gates_cmd.rs b/crates/nargo/src/cli/gates_cmd.rs index bae5dd22953..fa38d599d83 100644 --- a/crates/nargo/src/cli/gates_cmd.rs +++ b/crates/nargo/src/cli/gates_cmd.rs @@ -1,5 +1,6 @@ use acvm::ProofSystemCompiler; use clap::Args; +use noirc_driver::CompileOptions; use std::path::Path; use crate::cli::compile_cmd::compile_circuit; @@ -9,26 +10,17 @@ use super::NargoConfig; /// Counts the occurrences of different gates in circuit #[derive(Debug, Clone, Args)] -pub(crate) struct GatesCommand { - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, - - /// Emit debug information for the intermediate SSA IR - #[arg(short, long)] - show_ssa: bool, -} +pub(crate) struct GatesCommand {} -pub(crate) fn run(args: GatesCommand, config: NargoConfig) -> Result<(), CliError> { - count_gates_with_path(config.program_dir, args.show_ssa, args.allow_warnings) +pub(crate) fn run(_args: GatesCommand, config: NargoConfig) -> Result<(), CliError> { + count_gates_with_path(config.program_dir, &CompileOptions::from(config.compile_options)) } pub fn count_gates_with_path>( program_dir: P, - show_ssa: bool, - allow_warnings: bool, + compile_options: &CompileOptions, ) -> Result<(), CliError> { - let compiled_program = compile_circuit(program_dir.as_ref(), show_ssa, allow_warnings)?; + let compiled_program = compile_circuit(program_dir.as_ref(), compile_options)?; let num_opcodes = compiled_program.circuit.opcodes.len(); let backend = crate::backends::ConcreteBackend; diff --git a/crates/nargo/src/cli/mod.rs b/crates/nargo/src/cli/mod.rs index b0b778ad226..2a21472e5e2 100644 --- a/crates/nargo/src/cli/mod.rs +++ b/crates/nargo/src/cli/mod.rs @@ -1,8 +1,7 @@ -pub use check_cmd::check_from_path; use clap::{Args, Parser, Subcommand}; use const_format::formatcp; use noirc_abi::InputMap; -use noirc_driver::Driver; +use noirc_driver::{CompileOptions, Driver}; use noirc_frontend::graph::{CrateName, CrateType}; use std::path::{Path, PathBuf}; extern crate tempdir; @@ -42,6 +41,34 @@ struct NargoCli { pub(crate) struct NargoConfig { #[arg(short, long, hide=true, default_value_os_t = std::env::current_dir().unwrap())] program_dir: PathBuf, + + #[clap(flatten)] + compile_options: NargoCompileOptions, +} + +#[derive(Args, Clone, Debug, Default)] +pub(crate) struct NargoCompileOptions { + /// Emit debug information for the intermediate SSA IR + #[arg(short, long)] + pub show_ssa: bool, + + /// Issue a warning for each unused variable instead of an error + #[arg(short, long)] + pub allow_warnings: bool, + + /// Display output of println statements during tests + #[arg(long)] + pub show_output: bool, +} + +impl From for CompileOptions { + fn from(value: NargoCompileOptions) -> Self { + let mut options = CompileOptions::default(); + options.show_ssa = value.show_ssa; + options.allow_warnings = value.allow_warnings; + options.show_output = value.show_output; + options + } } #[non_exhaustive] @@ -80,14 +107,19 @@ pub fn start_cli() { // helper function which tests noir programs by trying to generate a proof and verify it pub fn prove_and_verify(proof_name: &str, prg_dir: &Path, show_ssa: bool) -> bool { let tmp_dir = TempDir::new("p_and_v_tests").unwrap(); + let compile_options = CompileOptions::from(NargoCompileOptions { + show_ssa, + allow_warnings: false, + show_output: false, + }); + match prove_cmd::prove_with_path( Some(proof_name.to_owned()), prg_dir, &tmp_dir.into_path(), None, true, - show_ssa, - false, + &compile_options, ) { Ok(_) => true, Err(error) => { diff --git a/crates/nargo/src/cli/prove_cmd.rs b/crates/nargo/src/cli/prove_cmd.rs index e71185fa732..61acda76b91 100644 --- a/crates/nargo/src/cli/prove_cmd.rs +++ b/crates/nargo/src/cli/prove_cmd.rs @@ -3,6 +3,7 @@ use std::path::{Path, PathBuf}; use acvm::ProofSystemCompiler; use clap::Args; use noirc_abi::input_parser::Format; +use noirc_driver::CompileOptions; use super::fs::{ inputs::{read_inputs_from_file, write_inputs_to_file}, @@ -16,7 +17,7 @@ use crate::{ errors::CliError, }; -// Create proof for this program. The proof is returned as a hex encoded string. +/// Create proof for this program. The proof is returned as a hex encoded string. #[derive(Debug, Clone, Args)] pub(crate) struct ProveCommand { /// The name of the proof @@ -28,14 +29,6 @@ pub(crate) struct ProveCommand { /// Verify proof after proving #[arg(short, long)] verify: bool, - - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, - - /// Emit debug information for the intermediate SSA IR - #[arg(short, long)] - show_ssa: bool, } pub(crate) fn run(args: ProveCommand, config: NargoConfig) -> Result<(), CliError> { @@ -57,8 +50,7 @@ pub(crate) fn run(args: ProveCommand, config: NargoConfig) -> Result<(), CliErro proof_dir, circuit_build_path, args.verify, - args.show_ssa, - args.allow_warnings, + &CompileOptions::from(config.compile_options), )?; Ok(()) @@ -70,11 +62,10 @@ pub fn prove_with_path>( proof_dir: P, circuit_build_path: Option

, check_proof: bool, - show_ssa: bool, - allow_warnings: bool, + compile_options: &CompileOptions, ) -> Result, CliError> { let compiled_program = - super::compile_cmd::compile_circuit(program_dir.as_ref(), show_ssa, allow_warnings)?; + super::compile_cmd::compile_circuit(program_dir.as_ref(), compile_options)?; let (proving_key, verification_key) = match circuit_build_path { Some(circuit_build_path) => { fetch_pk_and_vk(&compiled_program.circuit, circuit_build_path, true, true)? diff --git a/crates/nargo/src/cli/test_cmd.rs b/crates/nargo/src/cli/test_cmd.rs index 878a9873488..de2f2ca9b4f 100644 --- a/crates/nargo/src/cli/test_cmd.rs +++ b/crates/nargo/src/cli/test_cmd.rs @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, io::Write, path::Path}; use acvm::{PartialWitnessGenerator, ProofSystemCompiler}; use clap::Args; -use noirc_driver::{CompileOptions, CompileOptionsBuilder, Driver}; +use noirc_driver::{CompileOptions, Driver}; use noirc_frontend::node_interner::FuncId; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -15,40 +15,25 @@ use super::{add_std_lib, NargoConfig}; pub(crate) struct TestCommand { /// If given, only tests with names containing this string will be run test_name: Option, - - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, - - /// Display output of println statements during tests - #[arg(long)] - show_logs: bool, } pub(crate) fn run(args: TestCommand, config: NargoConfig) -> Result<(), CliError> { let test_name: String = args.test_name.unwrap_or_else(|| "".to_owned()); - run_tests(&config.program_dir, &test_name, args.allow_warnings, args.show_logs) + run_tests(&config.program_dir, &test_name, &CompileOptions::from(config.compile_options)) } fn run_tests( program_dir: &Path, test_name: &str, - allow_warnings: bool, - show_output: bool, + compile_options: &CompileOptions, ) -> Result<(), CliError> { let backend = crate::backends::ConcreteBackend; - let config = CompileOptionsBuilder::default() - .allow_warnings(allow_warnings) - .show_output(show_output) - .build() - .unwrap(); - let mut driver = Resolver::resolve_root_config(program_dir, backend.np_language())?; add_std_lib(&mut driver); - if driver.check_crate(&config).is_err() { + if driver.check_crate(&compile_options).is_err() { std::process::exit(1); } @@ -64,7 +49,7 @@ fn run_tests( writeln!(writer, "Testing {test_name}...").expect("Failed to write to stdout"); writer.flush().ok(); - match run_test(test_name, test_function, &driver, &config) { + match run_test(test_name, test_function, &driver, &compile_options) { Ok(_) => { writer.set_color(ColorSpec::new().set_fg(Some(Color::Green))).ok(); writeln!(writer, "ok").ok(); diff --git a/crates/nargo/src/cli/verify_cmd.rs b/crates/nargo/src/cli/verify_cmd.rs index 8f5a1cc5789..f222c4454f9 100644 --- a/crates/nargo/src/cli/verify_cmd.rs +++ b/crates/nargo/src/cli/verify_cmd.rs @@ -7,7 +7,7 @@ use crate::{ use acvm::{FieldElement, ProofSystemCompiler}; use clap::Args; use noirc_abi::input_parser::{Format, InputValue}; -use noirc_driver::CompiledProgram; +use noirc_driver::{CompileOptions, CompiledProgram}; use std::path::{Path, PathBuf}; /// Given a proof and a program, verify whether the proof is valid @@ -18,10 +18,6 @@ pub(crate) struct VerifyCommand { /// The name of the circuit build files (ACIR, proving and verification keys) circuit_name: Option, - - /// Issue a warning for each unused variable instead of an error - #[arg(short, long)] - allow_warnings: bool, } pub(crate) fn run(args: VerifyCommand, config: NargoConfig) -> Result<(), CliError> { @@ -37,17 +33,21 @@ pub(crate) fn run(args: VerifyCommand, config: NargoConfig) -> Result<(), CliErr circuit_build_path }); - verify_with_path(config.program_dir, proof_path, circuit_build_path, false, args.allow_warnings) + verify_with_path( + config.program_dir, + proof_path, + circuit_build_path, + CompileOptions::from(config.compile_options), + ) } fn verify_with_path>( program_dir: P, proof_path: PathBuf, circuit_build_path: Option

, - show_ssa: bool, - allow_warnings: bool, + compile_options: CompileOptions, ) -> Result<(), CliError> { - let compiled_program = compile_circuit(program_dir.as_ref(), show_ssa, allow_warnings)?; + let compiled_program = compile_circuit(program_dir.as_ref(), &compile_options)?; let (_, verification_key) = match circuit_build_path { Some(circuit_build_path) => { fetch_pk_and_vk(&compiled_program.circuit, circuit_build_path, false, true)? diff --git a/crates/noirc_driver/Cargo.toml b/crates/noirc_driver/Cargo.toml index 749bd86a39f..67cf385c8c4 100644 --- a/crates/noirc_driver/Cargo.toml +++ b/crates/noirc_driver/Cargo.toml @@ -15,4 +15,3 @@ acvm.workspace = true fm.workspace = true serde.workspace = true dirs.workspace = true -derive_builder = "0.12.0" diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 3de473826d7..4cf7ce8569a 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -2,7 +2,6 @@ use acvm::acir::circuit::Circuit; use acvm::Language; -use derive_builder::Builder; use fm::FileType; use noirc_abi::Abi; use noirc_errors::{reporter, ReportedError}; @@ -21,8 +20,7 @@ pub struct Driver { } #[non_exhaustive] -#[derive(Debug, Default, Builder)] -#[builder(default)] +#[derive(Debug, Default)] pub struct CompileOptions { pub show_ssa: bool, pub allow_warnings: bool,