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

chore: Add a flag to nargo to silence warnings #3032

Merged
merged 2 commits into from Oct 9, 2023
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
6 changes: 5 additions & 1 deletion compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ pub struct CompileOptions {
pub print_acir: bool,

/// Treat all warnings as errors
#[arg(long)]
#[arg(long, conflicts_with = "silence_warnings")]
kevaundray marked this conversation as resolved.
Show resolved Hide resolved
pub deny_warnings: bool,

/// Suppress warnings
#[arg(long, conflicts_with = "deny_warnings")]
pub silence_warnings: bool,
}

/// Helper type used to signify where only warnings are expected in file diagnostics
Expand Down
6 changes: 5 additions & 1 deletion compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,15 @@ pub fn report_all<'files>(
files: &'files impl Files<'files, FileId = fm::FileId>,
diagnostics: &[FileDiagnostic],
deny_warnings: bool,
silence_warnings: bool,
) -> ReportedErrors {
// Report warnings before any errors
let (mut diagnostics, mut errors): (Vec<_>, _) =
let (warnings, mut errors): (Vec<_>, _) =
diagnostics.iter().partition(|item| item.diagnostic.is_warning());

let mut diagnostics = if silence_warnings { Vec::new() } else { warnings };
diagnostics.append(&mut errors);

let error_count =
diagnostics.iter().map(|error| error.report(files, deny_warnings) as u32).sum();

Expand Down
15 changes: 13 additions & 2 deletions tooling/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ pub(crate) fn run(
fn check_package(package: &Package, compile_options: &CompileOptions) -> Result<(), CompileError> {
let (mut context, crate_id) =
prepare_package(package, Box::new(|path| std::fs::read_to_string(path)));
check_crate_and_report_errors(&mut context, crate_id, compile_options.deny_warnings)?;
check_crate_and_report_errors(
&mut context,
crate_id,
compile_options.deny_warnings,
compile_options.silence_warnings,
)?;

if package.is_library() || package.is_contract() {
// Libraries do not have ABIs while contracts have many, so we cannot generate a `Prover.toml` file.
Expand Down Expand Up @@ -171,7 +176,13 @@ pub(crate) fn check_crate_and_report_errors(
context: &mut Context,
crate_id: CrateId,
deny_warnings: bool,
silence_warnings: bool,
) -> Result<(), CompileError> {
let result = check_crate(context, crate_id, deny_warnings);
super::compile_cmd::report_errors(result, &context.file_manager, deny_warnings)
super::compile_cmd::report_errors(
result,
&context.file_manager,
deny_warnings,
silence_warnings,
)
}
37 changes: 32 additions & 5 deletions tooling/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,23 @@ pub(super) fn compile_workspace(
let compiled_programs: Vec<CompiledProgram> = program_results
.into_iter()
.map(|(file_manager, compilation_result)| {
report_errors(compilation_result, &file_manager, compile_options.deny_warnings)
report_errors(
compilation_result,
&file_manager,
compile_options.deny_warnings,
compile_options.silence_warnings,
)
})
.collect::<Result<_, _>>()?;
let compiled_contracts: Vec<CompiledContract> = contract_results
.into_iter()
.map(|(file_manager, compilation_result)| {
report_errors(compilation_result, &file_manager, compile_options.deny_warnings)
report_errors(
compilation_result,
&file_manager,
compile_options.deny_warnings,
compile_options.silence_warnings,
)
})
.collect::<Result<_, _>>()?;

Expand Down Expand Up @@ -164,7 +174,12 @@ pub(crate) fn compile_bin_package(
&is_opcode_supported,
);

let program = report_errors(compilation_result, &file_manager, compile_options.deny_warnings)?;
let program = report_errors(
compilation_result,
&file_manager,
compile_options.deny_warnings,
compile_options.silence_warnings,
)?;

Ok(program)
}
Expand Down Expand Up @@ -323,11 +338,23 @@ pub(crate) fn report_errors<T>(
result: CompilationResult<T>,
file_manager: &FileManager,
deny_warnings: bool,
silence_warnings: bool,
) -> Result<T, CompileError> {
let (t, warnings) = result.map_err(|errors| {
noirc_errors::reporter::report_all(file_manager.as_file_map(), &errors, deny_warnings)
noirc_errors::reporter::report_all(
file_manager.as_file_map(),
&errors,
deny_warnings,
silence_warnings,
)
})?;

noirc_errors::reporter::report_all(file_manager.as_file_map(), &warnings, deny_warnings);
noirc_errors::reporter::report_all(
file_manager.as_file_map(),
&warnings,
deny_warnings,
silence_warnings,
);

Ok(t)
}
7 changes: 6 additions & 1 deletion tooling/nargo_cli/src/cli/fmt_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ pub(crate) fn run(_args: FormatCommand, config: NargoConfig) -> Result<(), CliEr
})
.collect();

let _ = super::compile_cmd::report_errors::<()>(Err(errors), &file_manager, false);
let _ = super::compile_cmd::report_errors::<()>(
Err(errors),
&file_manager,
false,
false,
);
return Ok(());
}

Expand Down
9 changes: 8 additions & 1 deletion tooling/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ fn run_tests<S: BlackBoxFunctionSolver>(
) -> Result<(), CliError> {
let (mut context, crate_id) =
prepare_package(package, Box::new(|path| std::fs::read_to_string(path)));
check_crate_and_report_errors(&mut context, crate_id, compile_options.deny_warnings)?;
check_crate_and_report_errors(
&mut context,
crate_id,
compile_options.deny_warnings,
compile_options.silence_warnings,
)?;

let test_functions = context.get_all_test_functions_in_crate_matching(&crate_id, test_name);

Expand Down Expand Up @@ -119,6 +124,7 @@ fn run_tests<S: BlackBoxFunctionSolver>(
context.file_manager.as_file_map(),
&[diag],
compile_options.deny_warnings,
compile_options.silence_warnings,
);
}
failing += 1;
Expand All @@ -128,6 +134,7 @@ fn run_tests<S: BlackBoxFunctionSolver>(
context.file_manager.as_file_map(),
&[err],
compile_options.deny_warnings,
compile_options.silence_warnings,
);
failing += 1;
}
Expand Down