diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 4f45e88f536..f95c9de7c2c 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -131,53 +131,15 @@ pub struct CompileOptions { pub skip_underconstrained_check: bool, } -/// Similar to CompileOptions but with some extra fields specific for `check_crate`. #[derive(Clone, Debug, Default)] pub struct CheckOptions { - pub expression_width: Option, - pub bounded_codegen: bool, - pub force_compile: bool, - pub show_ssa: bool, - pub emit_ssa: bool, - pub show_brillig: bool, - pub print_acir: bool, - pub benchmark_codegen: bool, - pub deny_warnings: bool, - pub silence_warnings: bool, - pub disable_macros: bool, - pub show_monomorphized: bool, - pub instrument_debug: bool, - pub force_brillig: bool, - pub debug_comptime_in_file: Option, - pub show_artifact_paths: bool, - pub arithmetic_generics: bool, - pub skip_underconstrained_check: bool, + pub compile_options: CompileOptions, pub error_on_unused_imports: bool, } impl CheckOptions { - pub fn from_compile_options(options: &CompileOptions, error_on_unused_imports: bool) -> Self { - Self { - expression_width: options.expression_width, - bounded_codegen: options.bounded_codegen, - force_compile: options.force_compile, - show_ssa: options.show_ssa, - emit_ssa: options.emit_ssa, - show_brillig: options.show_brillig, - print_acir: options.print_acir, - benchmark_codegen: options.benchmark_codegen, - deny_warnings: options.deny_warnings, - silence_warnings: options.silence_warnings, - disable_macros: options.disable_macros, - show_monomorphized: options.show_monomorphized, - instrument_debug: options.instrument_debug, - force_brillig: options.force_brillig, - debug_comptime_in_file: options.debug_comptime_in_file.clone(), - show_artifact_paths: options.show_artifact_paths, - arithmetic_generics: options.arithmetic_generics, - skip_underconstrained_check: options.skip_underconstrained_check, - error_on_unused_imports, - } + pub fn new(compile_options: &CompileOptions, error_on_unused_imports: bool) -> Self { + Self { compile_options: compile_options.clone(), error_on_unused_imports } } } @@ -328,8 +290,10 @@ pub fn add_dep( pub fn check_crate( context: &mut Context, crate_id: CrateId, - options: &CheckOptions, + check_options: &CheckOptions, ) -> CompilationResult<()> { + let options = &check_options.compile_options; + let macros: &[&dyn MacroProcessor] = if options.disable_macros { &[] } else { &[&aztec_macros::AztecMacro] }; @@ -339,7 +303,7 @@ pub fn check_crate( context, options.debug_comptime_in_file.as_deref(), options.arithmetic_generics, - options.error_on_unused_imports, + check_options.error_on_unused_imports, macros, ); errors.extend(diagnostics.into_iter().map(|(error, file_id)| { @@ -374,7 +338,7 @@ pub fn compile_main( cached_program: Option, ) -> CompilationResult { let error_on_unused_imports = true; - let check_options = CheckOptions::from_compile_options(options, error_on_unused_imports); + let check_options = CheckOptions::new(options, error_on_unused_imports); let (_, mut warnings) = check_crate(context, crate_id, &check_options)?; @@ -412,7 +376,7 @@ pub fn compile_contract( options: &CompileOptions, ) -> CompilationResult { let error_on_unused_imports = true; - let check_options = CheckOptions::from_compile_options(options, error_on_unused_imports); + let check_options = CheckOptions::new(options, error_on_unused_imports); let (_, warnings) = check_crate(context, crate_id, &check_options)?; // TODO: We probably want to error if contracts is empty diff --git a/tooling/nargo_cli/src/cli/check_cmd.rs b/tooling/nargo_cli/src/cli/check_cmd.rs index ed9d8ccd1eb..1130a82fdfc 100644 --- a/tooling/nargo_cli/src/cli/check_cmd.rs +++ b/tooling/nargo_cli/src/cli/check_cmd.rs @@ -82,8 +82,7 @@ fn check_package( ) -> Result { let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); let error_on_unused_imports = package.error_on_unused_imports(); - let check_options = - CheckOptions::from_compile_options(compile_options, error_on_unused_imports); + let check_options = CheckOptions::new(compile_options, error_on_unused_imports); check_crate_and_report_errors(&mut context, crate_id, &check_options)?; if package.is_library() || package.is_contract() { @@ -153,9 +152,10 @@ fn create_input_toml_template( pub(crate) fn check_crate_and_report_errors( context: &mut Context, crate_id: CrateId, - options: &CheckOptions, + check_options: &CheckOptions, ) -> Result<(), CompileError> { - let result = check_crate(context, crate_id, options); + let options = &check_options.compile_options; + let result = check_crate(context, crate_id, check_options); report_errors(result, &context.file_manager, options.deny_warnings, options.silence_warnings) } diff --git a/tooling/nargo_cli/src/cli/export_cmd.rs b/tooling/nargo_cli/src/cli/export_cmd.rs index d2e504b9dfc..5721dd33e27 100644 --- a/tooling/nargo_cli/src/cli/export_cmd.rs +++ b/tooling/nargo_cli/src/cli/export_cmd.rs @@ -84,8 +84,7 @@ fn compile_exported_functions( ) -> Result<(), CliError> { let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); let error_on_unused_imports = package.error_on_unused_imports(); - let check_options = - CheckOptions::from_compile_options(compile_options, error_on_unused_imports); + let check_options = CheckOptions::new(compile_options, error_on_unused_imports); check_crate_and_report_errors(&mut context, crate_id, &check_options)?; let exported_functions = context.get_all_exported_functions_in_crate(&crate_id); diff --git a/tooling/nargo_cli/src/cli/test_cmd.rs b/tooling/nargo_cli/src/cli/test_cmd.rs index 25f95f7b826..2b0c0fd58db 100644 --- a/tooling/nargo_cli/src/cli/test_cmd.rs +++ b/tooling/nargo_cli/src/cli/test_cmd.rs @@ -182,8 +182,7 @@ fn run_test + Default>( let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); let error_on_unused_imports = package.error_on_unused_imports(); - let check_options = - CheckOptions::from_compile_options(compile_options, error_on_unused_imports); + let check_options = CheckOptions::new(compile_options, error_on_unused_imports); check_crate(&mut context, crate_id, &check_options) .expect("Any errors should have occurred when collecting test functions"); @@ -214,7 +213,7 @@ fn get_tests_in_package( ) -> Result, CliError> { let (mut context, crate_id) = prepare_package(file_manager, parsed_files, package); let error_on_unused_imports = package.error_on_unused_imports(); - let check_options = CheckOptions::from_compile_options(options, error_on_unused_imports); + let check_options = CheckOptions::new(options, error_on_unused_imports); check_crate_and_report_errors(&mut context, crate_id, &check_options)?; Ok(context