From ec0e0a17cfcc3c718814e7f3988f9fa8b218c900 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 14 Jun 2023 09:40:30 -0500 Subject: [PATCH 1/5] Fix #1645 --- crates/nargo_cli/src/cli/compile_cmd.rs | 14 ++++++++++---- .../src/ssa_refactor/opt/inlining.rs | 2 +- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index d2b5532cf24..1d867675556 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -2,6 +2,7 @@ use acvm::Backend; use iter_extended::try_vecmap; use nargo::artifacts::contract::PreprocessedContract; use noirc_driver::{CompileOptions, CompiledProgram, Driver}; +use noirc_errors::reporter; use std::path::Path; use clap::Args; @@ -49,9 +50,11 @@ pub(crate) fn run( // If contracts is set we're compiling every function in a 'contract' rather than just 'main'. if args.contracts { let mut driver = setup_driver(backend, &config.program_dir)?; - let compiled_contracts = driver - .compile_contracts(&args.compile_options) - .map_err(|_| CliError::CompilationError)?; + let compiled_contracts = + driver.compile_contracts(&args.compile_options).map_err(|errors| { + reporter::report_all(driver.file_manager(), &errors, false); + CliError::CompilationError + })?; // TODO(#1389): I wonder if it is incorrect for nargo-core to know anything about contracts. // As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms) @@ -118,5 +121,8 @@ pub(crate) fn compile_circuit( compile_options: &CompileOptions, ) -> Result> { let mut driver = setup_driver(backend, program_dir)?; - driver.compile_main(compile_options).map_err(|_| CliError::CompilationError) + driver.compile_main(compile_options).map_err(|errors| { + reporter::report_all(driver.file_manager(), &errors, false); + CliError::CompilationError + }) } diff --git a/crates/noirc_evaluator/src/ssa_refactor/opt/inlining.rs b/crates/noirc_evaluator/src/ssa_refactor/opt/inlining.rs index bfb4911f1c2..80e491e79f1 100644 --- a/crates/noirc_evaluator/src/ssa_refactor/opt/inlining.rs +++ b/crates/noirc_evaluator/src/ssa_refactor/opt/inlining.rs @@ -263,7 +263,7 @@ impl<'function> PerFunctionContext<'function> { _ => { self.context.failed_to_inline_a_call = true; None - }, + } } } From cc83da2631f1015b7ad3aa2f24f6e3ba617ae39f Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 14 Jun 2023 12:46:53 -0500 Subject: [PATCH 2/5] Do not fail when only warnings are given --- crates/nargo_cli/src/cli/check_cmd.rs | 12 +-- crates/nargo_cli/src/cli/compile_cmd.rs | 14 ++- crates/nargo_cli/src/cli/test_cmd.rs | 11 +-- crates/nargo_cli/src/errors.rs | 14 ++- crates/noirc_driver/src/lib.rs | 110 +++++++++++++++++------- crates/noirc_errors/src/reporter.rs | 32 +++---- 6 files changed, 110 insertions(+), 83 deletions(-) diff --git a/crates/nargo_cli/src/cli/check_cmd.rs b/crates/nargo_cli/src/cli/check_cmd.rs index 26006723797..5c4888b8048 100644 --- a/crates/nargo_cli/src/cli/check_cmd.rs +++ b/crates/nargo_cli/src/cli/check_cmd.rs @@ -4,7 +4,6 @@ use clap::Args; use iter_extended::btree_map; use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME}; use noirc_driver::CompileOptions; -use noirc_errors::reporter; use std::path::{Path, PathBuf}; use super::NargoConfig; @@ -34,16 +33,7 @@ fn check_from_path>( compile_options: &CompileOptions, ) -> Result<(), CliError> { let mut driver = setup_driver(backend, program_dir.as_ref())?; - - let result = driver.check_crate(); - if let Err(errs) = result { - let file_manager = driver.file_manager(); - let error_count = reporter::report_all(file_manager, &errs, compile_options.deny_warnings); - if error_count != 0 { - reporter::finish_report(error_count); - return Err(CliError::CompilationError); - } - } + driver.check_crate_and_report_errors(compile_options.deny_warnings)?; // XXX: We can have a --overwrite flag to determine if you want to overwrite the Prover/Verifier.toml files if let Some((parameters, return_type)) = driver.compute_function_signature() { diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index 1d867675556..059cf11edd2 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -2,7 +2,6 @@ use acvm::Backend; use iter_extended::try_vecmap; use nargo::artifacts::contract::PreprocessedContract; use noirc_driver::{CompileOptions, CompiledProgram, Driver}; -use noirc_errors::reporter; use std::path::Path; use clap::Args; @@ -50,11 +49,10 @@ pub(crate) fn run( // If contracts is set we're compiling every function in a 'contract' rather than just 'main'. if args.contracts { let mut driver = setup_driver(backend, &config.program_dir)?; + + let result = driver.compile_contracts(&args.compile_options); let compiled_contracts = - driver.compile_contracts(&args.compile_options).map_err(|errors| { - reporter::report_all(driver.file_manager(), &errors, false); - CliError::CompilationError - })?; + driver.report_errors(result, args.compile_options.deny_warnings)?; // TODO(#1389): I wonder if it is incorrect for nargo-core to know anything about contracts. // As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms) @@ -121,8 +119,6 @@ pub(crate) fn compile_circuit( compile_options: &CompileOptions, ) -> Result> { let mut driver = setup_driver(backend, program_dir)?; - driver.compile_main(compile_options).map_err(|errors| { - reporter::report_all(driver.file_manager(), &errors, false); - CliError::CompilationError - }) + let result = driver.compile_main(compile_options); + driver.report_errors(result, compile_options.deny_warnings).map_err(Into::into) } diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index ebb83bd2aa1..5a913268205 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -4,7 +4,6 @@ use acvm::{acir::native_types::WitnessMap, Backend}; use clap::Args; use nargo::ops::execute_circuit; use noirc_driver::{CompileOptions, Driver}; -use noirc_errors::reporter; use noirc_frontend::node_interner::FuncId; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -40,15 +39,7 @@ fn run_tests( ) -> Result<(), CliError> { let mut driver = setup_driver(backend, program_dir)?; - let result = driver.check_crate(); - if let Err(errs) = result { - let file_manager = driver.file_manager(); - let error_count = reporter::report_all(file_manager, &errs, compile_options.deny_warnings); - if error_count != 0 { - reporter::finish_report(error_count); - return Err(CliError::CompilationError); - } - } + driver.check_crate_and_report_errors(compile_options.deny_warnings)?; let test_functions = driver.get_all_test_functions_in_crate_matching(test_name); println!("Running {} test functions...", test_functions.len()); diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index c3e295183d1..f9220d55b1c 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -5,6 +5,7 @@ use acvm::{ use hex::FromHexError; use nargo::NargoError; use noirc_abi::errors::{AbiError, InputParserError}; +use noirc_errors::reporter::ReportedErrors; use std::path::PathBuf; use thiserror::Error; @@ -43,9 +44,10 @@ pub(crate) enum CliError { #[error(transparent)] ResolutionError(#[from] DependencyResolutionError), - /// Error while compiling Noir into ACIR. - #[error("Failed to compile circuit")] - CompilationError, + /// Errors encountered while compiling the noir program. + /// These errors are already written to stderr. + #[error("Aborting due to {} previous error{}", .0.error_count, if .0.error_count == 1 { "" } else { "s" })] + ReportedErrors(ReportedErrors), /// ABI encoding/decoding error #[error(transparent)] @@ -74,3 +76,9 @@ pub(crate) enum CliError { #[error(transparent)] CommonReferenceStringError(::Error), // Unfortunately, Rust won't let us `impl From` over an Associated Type on a generic } + +impl From for CliError { + fn from(errors: ReportedErrors) -> Self { + Self::ReportedErrors(errors) + } +} diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 9b9105cfaae..90b6c2053e7 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -8,7 +8,8 @@ use acvm::Language; use clap::Args; use fm::{FileId, FileManager, FileType}; use noirc_abi::FunctionSignature; -use noirc_errors::{reporter, CustomDiagnostic, FileDiagnostic}; +use noirc_errors::reporter::ReportedErrors; +use noirc_errors::{CustomDiagnostic, FileDiagnostic}; 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}; @@ -65,6 +66,12 @@ impl Default for CompileOptions { } } +/// Helper type used to signify where only warnings are expected in file diagnostics +pub type Warnings = Vec; + +/// Helper type used to signify where errors or warnings are expected in file diagnostics +pub type ErrorsAndWarnings = Vec; + impl Driver { pub fn new(language: &Language, is_opcode_supported: Box bool>) -> Self { Driver { context: Context::default(), language: language.clone(), is_opcode_supported } @@ -81,22 +88,12 @@ impl Driver { root_file: PathBuf, language: &Language, is_opcode_supported: Box bool>, - ) -> Result> { + ) -> Result<(CompiledProgram, Warnings), ErrorsAndWarnings> { let mut driver = Driver::new(language, is_opcode_supported); driver.create_local_crate(root_file, CrateType::Binary); driver.compile_main(&CompileOptions::default()) } - /// Compiles a file and returns true if compilation was successful - /// - /// This is used for tests. - pub fn file_compiles(&mut self) -> bool { - let mut errs = vec![]; - CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errs); - reporter::report_all(&self.context.file_manager, &errs, false); - errs.is_empty() - } - /// Adds the File with the local crate root to the file system /// and adds the local crate to the graph /// XXX: This may pose a problem with workspaces, where you can change the local crate and where @@ -169,18 +166,46 @@ impl Driver { } } - /// Run the lexing, parsing, name resolution, and type checking passes, - /// returning Err(FrontendError) and printing any errors that were found. - pub fn check_crate(&mut self) -> Result<(), Vec> { - let mut errs = vec![]; - CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errs); - if errs.is_empty() { - Ok(()) + /// Run the lexing, parsing, name resolution, and type checking passes. + /// + /// This returns a (possibly empty) vector of any warnings found on success. + /// On error, this returns a non-empty vector of warnings and error messages, with at least one error. + pub fn check_crate(&mut self, deny_warnings: bool) -> Result { + let mut errors = vec![]; + CrateDefMap::collect_defs(LOCAL_CRATE, &mut self.context, &mut errors); + + if Self::has_errors(&errors, deny_warnings) { + Err(errors) } else { - Err(errs) + Ok(errors) } } + /// Run the lexing, parsing, name resolution, and type checking passes and report any warnings + /// and errors found. + pub fn check_crate_and_report_errors( + &mut self, + deny_warnings: bool, + ) -> Result<(), ReportedErrors> { + let result = self.check_crate(deny_warnings).map(|warnings| ((), warnings)); + self.report_errors(result, deny_warnings) + } + + /// Helper function for reporting any errors in a Result<(T, Warnings), ErrorsAndWarnings> + /// structure that is commonly used as a return result in this file. + pub fn report_errors( + &self, + result: Result<(T, Warnings), ErrorsAndWarnings>, + deny_warnings: bool, + ) -> Result { + let (t, warnings) = result.map_err(|errors| { + noirc_errors::reporter::report_all(self.file_manager(), &errors, deny_warnings) + })?; + + noirc_errors::reporter::report_all(self.file_manager(), &warnings, deny_warnings); + Ok(t) + } + pub fn compute_function_signature(&self) -> Option { let local_crate = self.context.def_map(LOCAL_CRATE).unwrap(); @@ -192,11 +217,15 @@ impl Driver { } /// Run the frontend to check the crate for errors then compile the main function if there were none + /// + /// On success this returns the compiled program alongside any warnings that were found. + /// On error this returns the non-empty list of warnings and errors. pub fn compile_main( &mut self, options: &CompileOptions, - ) -> Result> { - self.check_crate()?; + ) -> Result<(CompiledProgram, Warnings), ErrorsAndWarnings> { + let warnings = self.check_crate(options.deny_warnings)?; + let main = match self.main_function() { Some(m) => m, None => { @@ -204,33 +233,41 @@ impl Driver { file_id: FileId::default(), diagnostic: CustomDiagnostic::from_message("cannot compile crate into a program as the local crate is not a binary. For libraries, please use the check command") }; - return Err(err.into()); + return Err(vec![err]); } }; + let compiled_program = self.compile_no_check(options, main)?; + if options.print_acir { println!("Compiled ACIR for main:"); println!("{}", compiled_program.circuit); } - Ok(compiled_program) + + Ok((compiled_program, warnings)) } /// Run the frontend to check the crate for errors then compile all contracts if there were none pub fn compile_contracts( &mut self, options: &CompileOptions, - ) -> Result, Vec> { - self.check_crate()?; + ) -> Result<(Vec, Warnings), ErrorsAndWarnings> { + let warnings = self.check_crate(options.deny_warnings)?; + let contracts = self.get_all_contracts(); let mut compiled_contracts = vec![]; - let mut errs = vec![]; + let mut errors = warnings; + for contract in contracts { match self.compile_contract(contract, options) { Ok(contract) => compiled_contracts.push(contract), - Err(err) => errs.push(err), + Err(mut more_errors) => errors.append(&mut more_errors), } } - if errs.is_empty() { + + if Self::has_errors(&errors, options.deny_warnings) { + Err(errors) + } else { if options.print_acir { for compiled_contract in &compiled_contracts { for contract_function in &compiled_contract.functions { @@ -242,9 +279,17 @@ impl Driver { } } } - Ok(compiled_contracts) + // errors here is either empty or contains only warnings + Ok((compiled_contracts, errors)) + } + } + + /// True if there are (non-warning) errors present and we should halt compilation + fn has_errors(errors: &[FileDiagnostic], deny_warnings: bool) -> bool { + if deny_warnings { + !errors.is_empty() } else { - Err(errs.concat()) + errors.iter().filter(|error| error.diagnostic.is_error()).count() != 0 } } @@ -305,6 +350,9 @@ impl Driver { } /// Compile the current crate. Assumes self.check_crate is called beforehand! + /// + /// This function also assumes all errors in experimental_create_circuit and create_circuit + /// are not warnings. #[allow(deprecated)] pub fn compile_no_check( &self, diff --git a/crates/noirc_errors/src/reporter.rs b/crates/noirc_errors/src/reporter.rs index d09f27d03f1..da862f70174 100644 --- a/crates/noirc_errors/src/reporter.rs +++ b/crates/noirc_errors/src/reporter.rs @@ -1,10 +1,7 @@ use crate::{FileDiagnostic, Span}; use codespan_reporting::diagnostic::{Diagnostic, Label}; use codespan_reporting::term; -use codespan_reporting::term::termcolor::{ - Color, ColorChoice, ColorSpec, StandardStream, WriteColor, -}; -use std::io::Write; +use codespan_reporting::term::termcolor::{ColorChoice, StandardStream}; #[derive(Debug, Clone, PartialEq, Eq)] pub struct CustomDiagnostic { @@ -20,6 +17,12 @@ pub enum DiagnosticKind { Warning, } +/// A count of errors that have been already reported to stderr +#[derive(Debug, Copy, Clone)] +pub struct ReportedErrors { + pub error_count: u32, +} + impl CustomDiagnostic { pub fn from_message(msg: &str) -> CustomDiagnostic { Self { @@ -68,7 +71,7 @@ impl CustomDiagnostic { self.secondaries.push(CustomLabel::new(message, span)); } - fn is_error(&self) -> bool { + pub fn is_error(&self) -> bool { matches!(self.kind, DiagnosticKind::Error) } } @@ -107,11 +110,13 @@ pub fn report_all( files: &fm::FileManager, diagnostics: &[FileDiagnostic], deny_warnings: bool, -) -> u32 { - diagnostics +) -> ReportedErrors { + let error_count = diagnostics .iter() .map(|error| report(files, &error.diagnostic, Some(error.file_id), deny_warnings) as u32) - .sum() + .sum(); + + ReportedErrors { error_count } } /// Report the given diagnostic, and return true if it was an error @@ -155,14 +160,3 @@ fn convert_diagnostic( diagnostic.with_message(&cd.message).with_labels(secondary_labels).with_notes(cd.notes.clone()) } - -pub fn finish_report(error_count: u32) { - if error_count != 0 { - let writer = StandardStream::stderr(ColorChoice::Always); - let mut writer = writer.lock(); - - writer.set_color(ColorSpec::new().set_fg(Some(Color::Red))).unwrap(); - writeln!(&mut writer, "error: aborting due to {error_count} previous errors").unwrap(); - writer.reset().ok(); - } -} From 9dea632df2f51595ac5e84ac59375f78a4ed2b51 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 14 Jun 2023 12:53:15 -0500 Subject: [PATCH 3/5] Fix test --- crates/nargo_cli/src/cli/mod.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 861e322fd9e..77fea7e258d 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -167,6 +167,7 @@ pub fn prove_and_verify(program_dir: &Path, experimental_ssa: bool) -> bool { #[cfg(test)] mod tests { use noirc_driver::Driver; + use noirc_errors::reporter; use noirc_frontend::graph::CrateType; use std::path::{Path, PathBuf}; @@ -184,7 +185,17 @@ mod tests { ); driver.create_local_crate(&root_file, CrateType::Binary); crate::resolver::add_std_lib(&mut driver); - driver.file_compiles() + + let result = driver.check_crate(false); + let success = result.is_ok(); + + let errors = match result { + Ok(warnings) => warnings, + Err(errors) => errors, + }; + + reporter::report_all(driver.file_manager(), &errors, false); + success } #[test] From 661412e928dc92630836cc9fd4f79991cd40ba57 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 14 Jun 2023 13:56:58 -0500 Subject: [PATCH 4/5] Move methods to free functions --- crates/nargo_cli/src/cli/check_cmd.rs | 13 ++++++++++++- crates/nargo_cli/src/cli/compile_cmd.rs | 25 +++++++++++++++++++----- crates/nargo_cli/src/cli/test_cmd.rs | 8 +++++--- crates/noirc_driver/src/lib.rs | 26 ------------------------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/crates/nargo_cli/src/cli/check_cmd.rs b/crates/nargo_cli/src/cli/check_cmd.rs index 5c4888b8048..b464945d375 100644 --- a/crates/nargo_cli/src/cli/check_cmd.rs +++ b/crates/nargo_cli/src/cli/check_cmd.rs @@ -4,6 +4,7 @@ use clap::Args; use iter_extended::btree_map; use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME}; use noirc_driver::CompileOptions; +use noirc_errors::reporter::ReportedErrors; use std::path::{Path, PathBuf}; use super::NargoConfig; @@ -33,7 +34,7 @@ fn check_from_path>( compile_options: &CompileOptions, ) -> Result<(), CliError> { let mut driver = setup_driver(backend, program_dir.as_ref())?; - driver.check_crate_and_report_errors(compile_options.deny_warnings)?; + check_crate_and_report_errors(&mut driver, compile_options.deny_warnings)?; // XXX: We can have a --overwrite flag to determine if you want to overwrite the Prover/Verifier.toml files if let Some((parameters, return_type)) = driver.compute_function_signature() { @@ -204,3 +205,13 @@ d2 = ["", "", ""] } } } + +/// Run the lexing, parsing, name resolution, and type checking passes and report any warnings +/// and errors found. +pub(crate) fn check_crate_and_report_errors( + driver: &mut noirc_driver::Driver, + deny_warnings: bool, +) -> Result<(), ReportedErrors> { + let result = driver.check_crate(deny_warnings).map(|warnings| ((), warnings)); + super::compile_cmd::report_errors(result, driver, deny_warnings) +} diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index 059cf11edd2..6d8fd8a2288 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -1,7 +1,8 @@ use acvm::Backend; use iter_extended::try_vecmap; use nargo::artifacts::contract::PreprocessedContract; -use noirc_driver::{CompileOptions, CompiledProgram, Driver}; +use noirc_driver::{CompileOptions, CompiledProgram, Driver, ErrorsAndWarnings, Warnings}; +use noirc_errors::reporter::ReportedErrors; use std::path::Path; use clap::Args; @@ -51,15 +52,14 @@ pub(crate) fn run( let mut driver = setup_driver(backend, &config.program_dir)?; let result = driver.compile_contracts(&args.compile_options); - let compiled_contracts = - driver.report_errors(result, args.compile_options.deny_warnings)?; + let contracts = report_errors(result, &driver, args.compile_options.deny_warnings)?; // TODO(#1389): I wonder if it is incorrect for nargo-core to know anything about contracts. // As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms) // are compiled via nargo-core and then the PreprocessedContract is constructed here. // This is due to EACH function needing it's own CRS, PKey, and VKey from the backend. let preprocessed_contracts: Result, CliError> = - try_vecmap(compiled_contracts, |contract| { + try_vecmap(contracts, |contract| { let preprocessed_contract_functions = try_vecmap(contract.functions, |func| { common_reference_string = update_common_reference_string( backend, @@ -120,5 +120,20 @@ pub(crate) fn compile_circuit( ) -> Result> { let mut driver = setup_driver(backend, program_dir)?; let result = driver.compile_main(compile_options); - driver.report_errors(result, compile_options.deny_warnings).map_err(Into::into) + report_errors(result, &driver, compile_options.deny_warnings).map_err(Into::into) +} + +/// Helper function for reporting any errors in a Result<(T, Warnings), ErrorsAndWarnings> +/// structure that is commonly used as a return result in this file. +pub(crate) fn report_errors( + result: Result<(T, Warnings), ErrorsAndWarnings>, + driver: &Driver, + deny_warnings: bool, +) -> Result { + let (t, warnings) = result.map_err(|errors| { + noirc_errors::reporter::report_all(driver.file_manager(), &errors, deny_warnings) + })?; + + noirc_errors::reporter::report_all(driver.file_manager(), &warnings, deny_warnings); + Ok(t) } diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index 5a913268205..4f4364144c2 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -7,7 +7,10 @@ use noirc_driver::{CompileOptions, Driver}; use noirc_frontend::node_interner::FuncId; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; -use crate::{cli::compile_cmd::setup_driver, errors::CliError}; +use crate::{ + cli::{check_cmd::check_crate_and_report_errors, compile_cmd::setup_driver}, + errors::CliError, +}; use super::NargoConfig; @@ -38,8 +41,7 @@ fn run_tests( compile_options: &CompileOptions, ) -> Result<(), CliError> { let mut driver = setup_driver(backend, program_dir)?; - - driver.check_crate_and_report_errors(compile_options.deny_warnings)?; + check_crate_and_report_errors(&mut driver, compile_options.deny_warnings)?; let test_functions = driver.get_all_test_functions_in_crate_matching(test_name); println!("Running {} test functions...", test_functions.len()); diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 90b6c2053e7..2df60fa75b5 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -8,7 +8,6 @@ use acvm::Language; use clap::Args; use fm::{FileId, FileManager, FileType}; use noirc_abi::FunctionSignature; -use noirc_errors::reporter::ReportedErrors; use noirc_errors::{CustomDiagnostic, FileDiagnostic}; use noirc_evaluator::{create_circuit, ssa_refactor::experimental_create_circuit}; use noirc_frontend::graph::{CrateId, CrateName, CrateType, LOCAL_CRATE}; @@ -181,31 +180,6 @@ impl Driver { } } - /// Run the lexing, parsing, name resolution, and type checking passes and report any warnings - /// and errors found. - pub fn check_crate_and_report_errors( - &mut self, - deny_warnings: bool, - ) -> Result<(), ReportedErrors> { - let result = self.check_crate(deny_warnings).map(|warnings| ((), warnings)); - self.report_errors(result, deny_warnings) - } - - /// Helper function for reporting any errors in a Result<(T, Warnings), ErrorsAndWarnings> - /// structure that is commonly used as a return result in this file. - pub fn report_errors( - &self, - result: Result<(T, Warnings), ErrorsAndWarnings>, - deny_warnings: bool, - ) -> Result { - let (t, warnings) = result.map_err(|errors| { - noirc_errors::reporter::report_all(self.file_manager(), &errors, deny_warnings) - })?; - - noirc_errors::reporter::report_all(self.file_manager(), &warnings, deny_warnings); - Ok(t) - } - pub fn compute_function_signature(&self) -> Option { let local_crate = self.context.def_map(LOCAL_CRATE).unwrap(); From bb4a20118a12f76b469b49c46acc947608bb3879 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Wed, 14 Jun 2023 15:20:16 -0500 Subject: [PATCH 5/5] Update wasm crate --- crates/wasm/src/compile.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/wasm/src/compile.rs b/crates/wasm/src/compile.rs index e0b03180264..f5a53ea402e 100644 --- a/crates/wasm/src/compile.rs +++ b/crates/wasm/src/compile.rs @@ -91,12 +91,13 @@ pub fn compile(args: JsValue) -> JsValue { // We are always adding std lib implicitly. It comes bundled with binary. add_noir_lib(&mut driver, "std"); - driver.check_crate().expect("Crate check failed"); + driver.check_crate(false).expect("Crate check failed"); if options.contracts { let compiled_contracts = driver .compile_contracts(&options.compile_options) - .expect("Contract compilation failed"); + .expect("Contract compilation failed") + .0; ::from_serde(&compiled_contracts).unwrap() } else {