From 5278d21309b4c01d41e05f4e42e1cfe6d0d4f633 Mon Sep 17 00:00:00 2001 From: Tom French Date: Mon, 9 Dec 2024 21:52:17 +0000 Subject: [PATCH 1/2] chore: free memory for silenced warnings early --- compiler/noirc_driver/src/lib.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 5bedefaf563..61ea88e015a 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -10,7 +10,7 @@ use clap::Args; use fm::{FileId, FileManager}; use iter_extended::vecmap; use noirc_abi::{AbiParameter, AbiType, AbiValue}; -use noirc_errors::{CustomDiagnostic, FileDiagnostic}; +use noirc_errors::{CustomDiagnostic, DiagnosticKind, FileDiagnostic}; use noirc_evaluator::create_program; use noirc_evaluator::errors::RuntimeError; use noirc_evaluator::ssa::{SsaLogging, SsaProgramArtifact}; @@ -301,7 +301,6 @@ pub fn check_crate( crate_id: CrateId, options: &CompileOptions, ) -> CompilationResult<()> { - let mut errors = vec![]; let error_on_unused_imports = true; let diagnostics = CrateDefMap::collect_defs( crate_id, @@ -309,15 +308,22 @@ pub fn check_crate( options.debug_comptime_in_file.as_deref(), error_on_unused_imports, ); - errors.extend(diagnostics.into_iter().map(|(error, file_id)| { - let diagnostic = CustomDiagnostic::from(&error); - diagnostic.in_file(file_id) - })); + let warnings_and_errors: Vec = diagnostics + .into_iter() + .map(|(error, file_id)| { + let diagnostic = CustomDiagnostic::from(&error); + diagnostic.in_file(file_id) + }) + .filter(|diagnostic| { + // We filter out any warnings if they're going to be ignored later on to free up memory. + !options.silence_warnings || diagnostic.diagnostic.kind == DiagnosticKind::Warning + }) + .collect(); - if has_errors(&errors, options.deny_warnings) { - Err(errors) + if has_errors(&warnings_and_errors, options.deny_warnings) { + Err(warnings_and_errors) } else { - Ok(((), errors)) + Ok(((), warnings_and_errors)) } } From dcd2b3027a2c1a9dc8f25dc28da41e7d7e4e75e1 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 9 Dec 2024 22:07:56 +0000 Subject: [PATCH 2/2] Update compiler/noirc_driver/src/lib.rs Co-authored-by: Akosh Farkash --- compiler/noirc_driver/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 61ea88e015a..da5297f4a4a 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -316,7 +316,7 @@ pub fn check_crate( }) .filter(|diagnostic| { // We filter out any warnings if they're going to be ignored later on to free up memory. - !options.silence_warnings || diagnostic.diagnostic.kind == DiagnosticKind::Warning + !options.silence_warnings || diagnostic.diagnostic.kind != DiagnosticKind::Warning }) .collect();