Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add a --force flag to force a full recompile #4054

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion tooling/nargo/src/ops/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +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) {
match noirc_driver::compile_main(&mut context, crate_id, compile_options, None) {
Ok(program_and_warnings) => program_and_warnings,
Err(errors) => {
return Err(errors);
Expand Down
43 changes: 20 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,30 @@ 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) =
match noirc_driver::compile_main(&mut context, crate_id, compile_options, cached_program) {
Ok(program_and_warnings) => program_and_warnings,
Err(errors) => {
return Err(errors);
}
};

// Apply backend specific optimizations.
let optimized_program = nargo::ops::optimize_program(program, expression_width);
Expand Down
Loading