diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 8ec92597a7c..ec7a5091ffd 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -4,7 +4,6 @@ #![warn(clippy::semicolon_if_nothing_returned)] use clap::Args; -use debug::filter_relevant_files; use fm::FileId; use iter_extended::vecmap; use noirc_abi::{AbiParameter, AbiType, ContractEvent}; @@ -23,6 +22,8 @@ mod contract; mod debug; mod program; +use debug::filter_relevant_files; + pub use contract::{CompiledContract, ContractFunction, ContractFunctionType}; pub use debug::DebugFile; pub use program::CompiledProgram; @@ -69,13 +70,6 @@ pub type ErrorsAndWarnings = Vec; /// Helper type for connecting a compilation artifact to the errors or warnings which were produced during compilation. pub type CompilationResult = Result<(T, Warnings), ErrorsAndWarnings>; -// This is here for backwards compatibility -// with the restricted version which only uses one file -pub fn compile_file(context: &mut Context, root_file: &Path) -> CompilationResult { - let crate_id = prepare_crate(context, root_file); - compile_main(context, crate_id, &CompileOptions::default(), None, true) -} - /// Adds the file from the file system at `Path` to the crate graph as a root file pub fn prepare_crate(context: &mut Context, file_name: &Path) -> CrateId { let path_to_std_lib_file = Path::new(STD_CRATE_NAME).join("lib.nr"); @@ -167,17 +161,14 @@ pub fn compile_main( ) -> CompilationResult { let (_, mut warnings) = check_crate(context, crate_id, options.deny_warnings)?; - let main = match context.get_main_function(&crate_id) { - Some(m) => m, - None => { - // TODO(#2155): This error might be a better to exist in Nargo - let err = CustomDiagnostic::from_message( - "cannot compile crate into a program as it does not contain a `main` function", - ) - .in_file(FileId::default()); - return Err(vec![err]); - } - }; + let main = context.get_main_function(&crate_id).ok_or_else(|| { + // TODO(#2155): This error might be a better to exist in Nargo + let err = CustomDiagnostic::from_message( + "cannot compile crate into a program as it does not contain a `main` function", + ) + .in_file(FileId::default()); + vec![err] + })?; let compiled_program = compile_no_check(context, options, main, cached_program, force_compile) .map_err(FileDiagnostic::from)?; @@ -330,11 +321,9 @@ fn compile_contract_inner( } } -/// Compile the current crate. Assumes self.check_crate is called beforehand! +/// Compile the current crate using `main_function` as the entrypoint. /// -/// This function also assumes all errors in experimental_create_circuit and create_circuit -/// are not warnings. -#[allow(deprecated)] +/// This function assumes [`check_crate`] is called beforehand. pub fn compile_no_check( context: &Context, options: &CompileOptions, @@ -345,15 +334,15 @@ pub fn compile_no_check( let program = monomorphize(main_function, &context.def_interner); let hash = fxhash::hash64(&program); + let hashes_match = cached_program.as_ref().map_or(false, |program| program.hash == hash); // If user has specified that they want to see intermediate steps printed then we should // force compilation even if the program hasn't changed. - if !(force_compile || options.print_acir || options.show_brillig || options.show_ssa) { - if let Some(cached_program) = cached_program { - if hash == cached_program.hash { - return Ok(cached_program); - } - } + let force_compile = + force_compile || options.print_acir || options.show_brillig || options.show_ssa; + + if !force_compile && hashes_match { + return Ok(cached_program.expect("cache must exist for hashes to match")); } let (circuit, debug, abi, warnings) = diff --git a/tooling/nargo_toml/src/semver.rs b/tooling/nargo_toml/src/semver.rs index 8ee80858f31..de722f06bd8 100644 --- a/tooling/nargo_toml/src/semver.rs +++ b/tooling/nargo_toml/src/semver.rs @@ -155,7 +155,7 @@ mod tests { required_compiler_version: "0.2.0".to_string(), compiler_version_found: "0.1.0".to_string(), }; - assert_eq!(got_err, expected_version_error.into()); + assert_eq!(got_err, expected_version_error); } #[test]