diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 7136580b770..db69d41c704 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -45,6 +45,10 @@ pub const NOIR_ARTIFACT_VERSION_STRING: &str = #[derive(Args, Clone, Debug, Default, Serialize, Deserialize)] pub struct CompileOptions { + /// Force a full recompilation. + #[arg(long = "force")] + pub force_compile: bool, + /// Emit debug information for the intermediate SSA IR #[arg(long, hide = true)] pub show_ssa: bool, @@ -206,7 +210,6 @@ pub fn compile_main( crate_id: CrateId, options: &CompileOptions, cached_program: Option, - force_compile: bool, ) -> CompilationResult { let (_, mut warnings) = check_crate(context, crate_id, options.deny_warnings, options.disable_macros)?; @@ -220,8 +223,9 @@ pub fn compile_main( vec![err] })?; - let compiled_program = compile_no_check(context, options, main, cached_program, force_compile) - .map_err(FileDiagnostic::from)?; + let compiled_program = + compile_no_check(context, options, main, cached_program, options.force_compile) + .map_err(FileDiagnostic::from)?; let compilation_warnings = vecmap(compiled_program.warnings.clone(), FileDiagnostic::from); if options.deny_warnings && !compilation_warnings.is_empty() { return Err(compilation_warnings); diff --git a/compiler/wasm/src/compile.rs b/compiler/wasm/src/compile.rs index 54fdccf1369..151dde2eea6 100644 --- a/compiler/wasm/src/compile.rs +++ b/compiler/wasm/src/compile.rs @@ -198,7 +198,7 @@ pub fn compile( let compile_output = generate_contract_artifact(optimized_contract); Ok(JsCompileResult::new(compile_output)) } else { - let compiled_program = compile_main(&mut context, crate_id, &compile_options, None, true) + let compiled_program = compile_main(&mut context, crate_id, &compile_options, None) .map_err(|errs| { CompileError::with_file_diagnostics( "Failed to compile program", diff --git a/compiler/wasm/src/compile_new.rs b/compiler/wasm/src/compile_new.rs index 9ac080ffcae..3cb20bd0b5c 100644 --- a/compiler/wasm/src/compile_new.rs +++ b/compiler/wasm/src/compile_new.rs @@ -97,7 +97,7 @@ impl CompilerContext { let root_crate_id = *self.context.root_crate_id(); let compiled_program = - compile_main(&mut self.context, root_crate_id, &compile_options, None, true) + compile_main(&mut self.context, root_crate_id, &compile_options, None) .map_err(|errs| { CompileError::with_file_diagnostics( "Failed to compile program", diff --git a/tooling/nargo/src/ops/compile.rs b/tooling/nargo/src/ops/compile.rs index bd395d03f67..043e2a367a5 100644 --- a/tooling/nargo/src/ops/compile.rs +++ b/tooling/nargo/src/ops/compile.rs @@ -74,12 +74,7 @@ pub fn compile_program( debug_artifact_path.set_file_name(format!("debug_{}.json", package.name)); let (program, warnings) = - match noirc_driver::compile_main(&mut context, crate_id, compile_options, None, true) { - Ok(program_and_warnings) => program_and_warnings, - Err(errors) => { - return Err(errors); - } - }; + noirc_driver::compile_main(&mut context, crate_id, compile_options, None)?; // Apply backend specific optimizations. let optimized_program = crate::ops::optimize_program(program, expression_width); diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 31105ebe68f..8bc35080fd7 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -176,33 +176,25 @@ fn compile_program( read_program_from_file(program_artifact_path), read_debug_artifact_from_file(debug_artifact_path), ) { - Some(CompiledProgram { - hash: program_artifact.hash, - circuit: program_artifact.bytecode, - abi: program_artifact.abi, - noir_version: program_artifact.noir_version, - debug: debug_artifact.debug_symbols.remove(0), - file_map: debug_artifact.file_map, - warnings: debug_artifact.warnings, - }) + if program_artifact.noir_version == NOIR_ARTIFACT_VERSION_STRING { + Some(CompiledProgram { + hash: program_artifact.hash, + circuit: program_artifact.bytecode, + abi: program_artifact.abi, + noir_version: program_artifact.noir_version, + debug: debug_artifact.debug_symbols.remove(0), + file_map: debug_artifact.file_map, + warnings: debug_artifact.warnings, + }) + } else { + None + } } else { None }; - let force_recompile = - cached_program.as_ref().map_or(false, |p| p.noir_version != NOIR_ARTIFACT_VERSION_STRING); - let (program, warnings) = match noirc_driver::compile_main( - &mut context, - crate_id, - compile_options, - cached_program, - force_recompile, - ) { - Ok(program_and_warnings) => program_and_warnings, - Err(errors) => { - return Err(errors); - } - }; + let (program, warnings) = + noirc_driver::compile_main(&mut context, crate_id, compile_options, cached_program)?; // Apply backend specific optimizations. let optimized_program = nargo::ops::optimize_program(program, expression_width);