Skip to content

Commit

Permalink
feat: add a --force flag to force a full recompile (#4054)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves #2798 

## Summary\*

This PR adds ` --force` flag which will ignore any existing build
artifacts when compiling a circuit.

## Additional Context



## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [x] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Jan 16, 2024
1 parent 15237b3 commit 27a8e68
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 34 deletions.
10 changes: 7 additions & 3 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -206,7 +210,6 @@ pub fn compile_main(
crate_id: CrateId,
options: &CompileOptions,
cached_program: Option<CompiledProgram>,
force_compile: bool,
) -> CompilationResult<CompiledProgram> {
let (_, mut warnings) =
check_crate(context, crate_id, options.deny_warnings, options.disable_macros)?;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion compiler/wasm/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion compiler/wasm/src/compile_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions tooling/nargo/src/ops/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
38 changes: 15 additions & 23 deletions tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 27a8e68

Please sign in to comment.