From 721b7b4c2007de62b49b5bea56651e40956fd141 Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 23 Oct 2023 09:55:53 +0000 Subject: [PATCH 01/17] recompile artifacts from a different noir version --- compiler/noirc_driver/src/lib.rs | 9 ++++++++- compiler/noirc_driver/src/program.rs | 1 + tooling/nargo/src/artifacts/program.rs | 1 + tooling/nargo_cli/src/cli/compile_cmd.rs | 6 +++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 44e50f94874..00894138f4a 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -342,5 +342,12 @@ pub fn compile_no_check( let file_map = filter_relevant_files(&[debug.clone()], &context.file_manager); - Ok(CompiledProgram { hash, circuit, debug, abi, file_map }) + Ok(CompiledProgram { + hash, + circuit, + debug, + abi, + file_map, + noir_version: env!("CARGO_PKG_VERSION").to_string(), + }) } diff --git a/compiler/noirc_driver/src/program.rs b/compiler/noirc_driver/src/program.rs index 8a13092aeb6..550029655ac 100644 --- a/compiler/noirc_driver/src/program.rs +++ b/compiler/noirc_driver/src/program.rs @@ -21,6 +21,7 @@ pub struct CompiledProgram { #[serde(serialize_with = "serialize_circuit", deserialize_with = "deserialize_circuit")] pub circuit: Circuit, pub abi: noirc_abi::Abi, + pub noir_version: String, pub debug: DebugInfo, pub file_map: BTreeMap, } diff --git a/tooling/nargo/src/artifacts/program.rs b/tooling/nargo/src/artifacts/program.rs index 190b4c76897..26fbef32ae9 100644 --- a/tooling/nargo/src/artifacts/program.rs +++ b/tooling/nargo/src/artifacts/program.rs @@ -17,6 +17,7 @@ pub struct PreprocessedProgram { pub backend: String, pub abi: Abi, + pub noir_version: String, #[serde( serialize_with = "super::serialize_circuit", diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index a332d63e062..041d3837d53 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -28,6 +28,7 @@ use super::fs::program::{ save_contract_to_file, save_debug_artifact_to_file, save_program_to_file, }; use super::NargoConfig; +use super::CARGO_PKG_VERSION; use rayon::prelude::*; // TODO(#1388): pull this from backend. @@ -203,6 +204,7 @@ fn compile_program( hash: preprocessed_program.hash, circuit: preprocessed_program.bytecode, abi: preprocessed_program.abi, + noir_version: preprocessed_program.noir_version, debug: DebugInfo::default(), file_map: BTreeMap::new(), }) @@ -211,7 +213,8 @@ fn compile_program( }; // If we want to output the debug information then we need to perform a full recompilation of the ACIR. - let force_recompile = output_debug; + let force_recompile = output_debug + || cached_program.as_ref().map_or(false, |p| p.noir_version != CARGO_PKG_VERSION); let (program, warnings) = match noirc_driver::compile_main( &mut context, @@ -274,6 +277,7 @@ fn save_program( hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, + noir_version: CARGO_PKG_VERSION.to_owned(), bytecode: program.circuit, }; From 12eb3f068346dd89f332dc5d05df2843aa5ac06e Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 23 Oct 2023 10:42:02 +0000 Subject: [PATCH 02/17] noir version also for wasm --- compiler/wasm/src/compile.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/wasm/src/compile.rs b/compiler/wasm/src/compile.rs index 0f7baff4819..7c4d2a5adaf 100644 --- a/compiler/wasm/src/compile.rs +++ b/compiler/wasm/src/compile.rs @@ -118,6 +118,7 @@ fn preprocess_program(program: CompiledProgram) -> PreprocessedProgram { hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, + noir_version: program.noir_version, bytecode: program.circuit, } } From 3bfa955c64aa9969596e93908272dfda07fec992 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 23 Oct 2023 12:36:47 +0100 Subject: [PATCH 03/17] chore: move empty circuits to `compile_success_empty` (#3247) --- .../conditional_regression_547/target/acir.gz | Bin 39 -> 0 bytes .../target/witness.gz | Bin 45 -> 0 bytes .../conditional_regression_579/target/acir.gz | Bin 24 -> 0 bytes .../target/witness.gz | Bin 23 -> 0 bytes .../target/acir.gz | Bin 24 -> 0 bytes .../target/witness.gz | Bin 23 -> 0 bytes .../acir_artifacts/main_return/target/acir.gz | Bin 40 -> 0 bytes .../main_return/target/witness.gz | Bin 46 -> 0 bytes .../references_aliasing/target/acir.gz | Bin 24 -> 0 bytes .../references_aliasing/target/witness.gz | Bin 23 -> 0 bytes .../simple_array_param/target/acir.gz | Bin 42 -> 0 bytes .../simple_array_param/target/witness.gz | Bin 49 -> 0 bytes .../target/acir.gz | Bin 24 -> 0 bytes .../target/witness.gz | Bin 23 -> 0 bytes .../trait_as_return_type/target/acir.gz | Bin 0 -> 46 bytes .../target/witness.gz | Bin .../target/acir.gz | Bin 24 -> 0 bytes .../target/witness.gz | Bin 23 -> 0 bytes .../target/acir.gz | Bin 38 -> 0 bytes .../trait_function_calls/target/acir.gz | Bin 24 -> 0 bytes .../trait_function_calls/target/witness.gz | Bin 23 -> 0 bytes .../trait_multi_module_test/target/acir.gz | Bin 24 -> 0 bytes .../trait_multi_module_test/target/witness.gz | Bin 23 -> 0 bytes .../target/acir.gz | Bin 38 -> 0 bytes .../target/witness.gz | Bin 46 -> 0 bytes .../acir_artifacts/trait_self/target/acir.gz | Bin 24 -> 0 bytes .../trait_self/target/witness.gz | Bin 23 -> 0 bytes .../trait_where_clause/target/acir.gz | Bin 24 -> 0 bytes .../trait_where_clause/target/witness.gz | Bin 23 -> 0 bytes .../conditional_regression_547/Nargo.toml | 0 .../conditional_regression_547/Prover.toml | 0 .../conditional_regression_547/src/main.nr | 0 .../conditional_regression_579/Nargo.toml | 0 .../conditional_regression_579/Prover.toml | 0 .../conditional_regression_579/src/main.nr | 0 .../conditional_regression_to_bits/Nargo.toml | 0 .../Prover.toml | 0 .../src/main.nr | 0 .../main_return/Nargo.toml | 0 .../main_return/Prover.toml | 0 .../main_return/src/main.nr | 0 .../references_aliasing/src/main.nr | 27 +++++++++++++--- .../simple_array_param/Nargo.toml | 0 .../simple_array_param/Prover.toml | 0 .../simple_array_param/src/main.nr | 0 .../Nargo.toml | 0 .../Prover.toml | 0 .../src/main.nr | 0 .../Nargo.toml | 0 .../Prover.toml | 0 .../src/main.nr | 0 .../trait_default_implementation/Nargo.toml | 0 .../trait_default_implementation/Prover.toml | 0 .../trait_default_implementation/src/main.nr | 0 .../trait_function_calls/Nargo.toml | 0 .../trait_function_calls}/Prover.toml | 0 .../trait_function_calls/src/main.nr | 0 .../trait_multi_module_test/Nargo.toml | 0 .../trait_multi_module_test}/Prover.toml | 0 .../trait_multi_module_test/src/main.nr | 0 .../trait_multi_module_test/src/module1.nr | 0 .../trait_multi_module_test/src/module2.nr | 0 .../trait_multi_module_test/src/module3.nr | 0 .../trait_multi_module_test/src/module4.nr | 0 .../trait_multi_module_test/src/module5.nr | 0 .../trait_multi_module_test/src/module6.nr | 0 .../trait_override_implementation/Nargo.toml | 0 .../trait_override_implementation/Prover.toml | 0 .../trait_override_implementation/src/main.nr | 0 .../trait_self/Nargo.toml | 0 .../trait_self/src/main.nr | 0 .../trait_self/trait_self/Nargo.toml | 0 .../trait_self/trait_self/src/main.nr | 0 .../trait_where_clause/Nargo.toml | 0 .../trait_where_clause/src/main.nr | 0 .../trait_where_clause/src/the_trait.nr | 0 .../references_aliasing/Nargo.toml | 7 ----- .../references_aliasing/src/main.nr | 29 ------------------ .../trait_multi_module_test/Prover.toml | 0 79 files changed, 23 insertions(+), 40 deletions(-) delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/conditional_regression_547/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/conditional_regression_547/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/conditional_regression_579/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/conditional_regression_579/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/conditional_regression_to_bits/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/conditional_regression_to_bits/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/main_return/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/main_return/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/references_aliasing/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/references_aliasing/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/simple_array_param/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/simple_array_param/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_allowed_item_name_matches/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_allowed_item_name_matches/target/witness.gz create mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_as_return_type/target/acir.gz rename tooling/nargo_cli/tests/acir_artifacts/{trait_default_implementation => trait_as_return_type}/target/witness.gz (100%) delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_default_implementation/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_function_calls/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_function_calls/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_multi_module_test/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_multi_module_test/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_override_implementation/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_override_implementation/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_self/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_self/target/witness.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_where_clause/target/acir.gz delete mode 100644 tooling/nargo_cli/tests/acir_artifacts/trait_where_clause/target/witness.gz rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_547/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_547/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_547/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_579/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_579/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_579/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_to_bits/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_to_bits/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/conditional_regression_to_bits/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/main_return/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/main_return/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/main_return/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/simple_array_param/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/simple_array_param/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/simple_array_param/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_allowed_item_name_matches/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success/references_aliasing => compile_success_empty/trait_allowed_item_name_matches}/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_allowed_item_name_matches/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_associated_member_names_clashes/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success/trait_allowed_item_name_matches => compile_success_empty/trait_associated_member_names_clashes}/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_associated_member_names_clashes/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_default_implementation/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_default_implementation/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_default_implementation/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_function_calls/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success/trait_associated_member_names_clashes => compile_success_empty/trait_function_calls}/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_function_calls/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success/trait_function_calls => compile_success_empty/trait_multi_module_test}/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/module1.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/module2.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/module3.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/module4.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/module5.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_multi_module_test/src/module6.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_override_implementation/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_override_implementation/Prover.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_override_implementation/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_self/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_self/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_self/trait_self/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_self/trait_self/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_where_clause/Nargo.toml (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_where_clause/src/main.nr (100%) rename tooling/nargo_cli/tests/{execution_success => compile_success_empty}/trait_where_clause/src/the_trait.nr (100%) delete mode 100644 tooling/nargo_cli/tests/execution_success/references_aliasing/Nargo.toml delete mode 100644 tooling/nargo_cli/tests/execution_success/references_aliasing/src/main.nr delete mode 100644 tooling/nargo_cli/tests/execution_success/trait_multi_module_test/Prover.toml diff --git a/tooling/nargo_cli/tests/acir_artifacts/conditional_regression_547/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/conditional_regression_547/target/acir.gz deleted file mode 100644 index 090578ca4e3da83386c1be71ed2b91b72b1de1ce..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 39 pcmb2|=3oGW|D`7maspXR2kz9roaeYe{^5y7d0~~pyID*36@Gu>`nUTHW-%61!jqLpWhAYnJKj#Ruwpb7XR0IGwrw*(D diff --git a/tooling/nargo_cli/tests/acir_artifacts/conditional_regression_579/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/conditional_regression_579/target/acir.gz deleted file mode 100644 index 2639a2e0809384eac56475a35d011104cd4b4686..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24 acmb2|=3oGW|H%moatsVIX)4V+Kmhh)Q@ef)6 diff --git a/tooling/nargo_cli/tests/acir_artifacts/simple_array_param/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/simple_array_param/target/witness.gz deleted file mode 100644 index a8e277ea7959fc5fcbdad4fcdfabfc566b551e19..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 49 zcmb2|=3oE;rvGbuHgYmBa2(zu{*wJ){nVzv3wT+KSU*0od?VEO{wnwXPnod`fC>St C5))Yf diff --git a/tooling/nargo_cli/tests/acir_artifacts/trait_allowed_item_name_matches/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/trait_allowed_item_name_matches/target/acir.gz deleted file mode 100644 index 2639a2e0809384eac56475a35d011104cd4b4686..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24 acmb2|=3oGW|H%moatsVIX)4V+Kmh~&V6Et^^NuVX*=x7IUCwsy>$G(aKxF`J_7RT& literal 0 HcmV?d00001 diff --git a/tooling/nargo_cli/tests/acir_artifacts/trait_default_implementation/target/witness.gz b/tooling/nargo_cli/tests/acir_artifacts/trait_as_return_type/target/witness.gz similarity index 100% rename from tooling/nargo_cli/tests/acir_artifacts/trait_default_implementation/target/witness.gz rename to tooling/nargo_cli/tests/acir_artifacts/trait_as_return_type/target/witness.gz diff --git a/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/acir.gz b/tooling/nargo_cli/tests/acir_artifacts/trait_associated_member_names_clashes/target/acir.gz deleted file mode 100644 index 2639a2e0809384eac56475a35d011104cd4b4686..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 24 acmb2|=3oGW|H%moatsVIX)4V+Kmh Date: Mon, 23 Oct 2023 04:38:01 -0700 Subject: [PATCH 04/17] chore: add constructor formatter (#3243) --- tooling/nargo_fmt/src/config.rs | 2 +- tooling/nargo_fmt/src/lib.rs | 3 +- tooling/nargo_fmt/src/utils.rs | 74 +++++-- tooling/nargo_fmt/src/visitor.rs | 30 +-- tooling/nargo_fmt/src/visitor/expr.rs | 225 ++++++++++++++------- tooling/nargo_fmt/src/visitor/item.rs | 2 +- tooling/nargo_fmt/src/visitor/stmt.rs | 2 +- tooling/nargo_fmt/tests/expected/array.nr | 30 ++- tooling/nargo_fmt/tests/expected/expr.nr | 4 + tooling/nargo_fmt/tests/expected/let.nr | 34 ++++ tooling/nargo_fmt/tests/expected/struct.nr | 6 +- tooling/nargo_fmt/tests/input/expr.nr | 5 + tooling/nargo_fmt/tests/input/let.nr | 12 ++ 13 files changed, 312 insertions(+), 117 deletions(-) diff --git a/tooling/nargo_fmt/src/config.rs b/tooling/nargo_fmt/src/config.rs index 1514937caff..aaa5cbac3d0 100644 --- a/tooling/nargo_fmt/src/config.rs +++ b/tooling/nargo_fmt/src/config.rs @@ -46,7 +46,7 @@ config! { tab_spaces: usize, 4, "Number of spaces per tab"; remove_nested_parens: bool, true, "Remove nested parens"; short_array_element_width_threshold: usize, 10, "Width threshold for an array element to be considered short"; - array_width: usize, 60, "Maximum width of an array literal before falling back to vertical formatting"; + array_width: usize, 100, "Maximum width of an array literal before falling back to vertical formatting"; } impl Config { diff --git a/tooling/nargo_fmt/src/lib.rs b/tooling/nargo_fmt/src/lib.rs index 887e71be735..3e8ee570c09 100644 --- a/tooling/nargo_fmt/src/lib.rs +++ b/tooling/nargo_fmt/src/lib.rs @@ -20,9 +20,8 @@ /// in both placement and content during the formatting process. mod config; pub mod errors; -#[macro_use] -mod visitor; mod utils; +mod visitor; use noirc_frontend::ParsedModule; use visitor::FmtVisitor; diff --git a/tooling/nargo_fmt/src/utils.rs b/tooling/nargo_fmt/src/utils.rs index 4bea21be939..d1c642b87d2 100644 --- a/tooling/nargo_fmt/src/utils.rs +++ b/tooling/nargo_fmt/src/utils.rs @@ -2,7 +2,7 @@ use crate::visitor::FmtVisitor; use noirc_frontend::hir::resolution::errors::Span; use noirc_frontend::lexer::Lexer; use noirc_frontend::token::Token; -use noirc_frontend::Expression; +use noirc_frontend::{Expression, Ident}; pub(crate) fn recover_comment_removed(original: &str, new: String) -> String { if changed_comment_content(original, &new) { @@ -46,19 +46,15 @@ impl Expr { } } -pub(crate) struct Exprs<'me> { +pub(crate) struct Exprs<'me, T> { pub(crate) visitor: &'me FmtVisitor<'me>, - pub(crate) elements: std::iter::Peekable>, + pub(crate) elements: std::iter::Peekable>, pub(crate) last_position: u32, pub(crate) end_position: u32, } -impl<'me> Exprs<'me> { - pub(crate) fn new( - visitor: &'me FmtVisitor<'me>, - span: Span, - elements: Vec, - ) -> Self { +impl<'me, T: Item> Exprs<'me, T> { + pub(crate) fn new(visitor: &'me FmtVisitor<'me>, span: Span, elements: Vec) -> Self { Self { visitor, last_position: span.start() + 1, /*(*/ @@ -68,33 +64,33 @@ impl<'me> Exprs<'me> { } } -impl Iterator for Exprs<'_> { +impl Iterator for Exprs<'_, T> { type Item = Expr; fn next(&mut self) -> Option { let element = self.elements.next()?; - let element_span = element.span; + let element_span = element.span(); let start = self.last_position; let end = element_span.start(); let is_last = self.elements.peek().is_none(); - let next_start = self.elements.peek().map_or(self.end_position, |expr| expr.span.start()); + let next_start = self.elements.peek().map_or(self.end_position, |expr| expr.start()); let (leading, different_line) = self.leading(start, end); - let expr = self.visitor.format_expr(element); + let expr = element.format(self.visitor); let trailing = self.trailing(element_span.end(), next_start, is_last); Expr { leading, value: expr, trailing, different_line }.into() } } -impl<'me> Exprs<'me> { +impl<'me, T> Exprs<'me, T> { pub(crate) fn leading(&mut self, start: u32, end: u32) -> (String, bool) { let mut different_line = false; - let leading = slice!(self.visitor, start, end); - let leading_trimmed = slice!(self.visitor, start, end).trim(); + let leading = self.visitor.slice(start..end); + let leading_trimmed = leading.trim(); let starts_with_block_comment = leading_trimmed.starts_with("/*"); let ends_with_block_comment = leading_trimmed.ends_with("*/"); @@ -114,7 +110,7 @@ impl<'me> Exprs<'me> { } pub(crate) fn trailing(&mut self, start: u32, end: u32, is_last: bool) -> String { - let slice = slice!(self.visitor, start, end); + let slice = self.visitor.slice(start..end); let comment_end = find_comment_end(slice, is_last); let trailing = slice[..comment_end].trim_matches(',').trim(); self.last_position = start + (comment_end as u32); @@ -201,3 +197,47 @@ fn comment_len(comment: &str) -> usize { } } } + +pub(crate) trait Item { + fn span(&self) -> Span; + + fn format(self, visitor: &FmtVisitor) -> String; + + fn start(&self) -> u32 { + self.span().start() + } + + fn end(&self) -> u32 { + self.span().end() + } +} + +impl Item for Expression { + fn span(&self) -> Span { + self.span + } + + fn format(self, visitor: &FmtVisitor) -> String { + visitor.format_expr(self) + } +} + +impl Item for (Ident, Expression) { + fn span(&self) -> Span { + let (name, value) = self; + (name.span().start()..value.span.end()).into() + } + + fn format(self, visitor: &FmtVisitor) -> String { + let (name, expr) = self; + + let name = name.0.contents; + let expr = visitor.format_expr(expr); + + if name == expr { + name + } else { + format!("{name}: {expr}") + } + } +} diff --git a/tooling/nargo_fmt/src/visitor.rs b/tooling/nargo_fmt/src/visitor.rs index f357fb2f12b..32e41cb34db 100644 --- a/tooling/nargo_fmt/src/visitor.rs +++ b/tooling/nargo_fmt/src/visitor.rs @@ -1,18 +1,10 @@ -/// A macro to create a slice from a given data source, helping to avoid borrow checker errors. -#[macro_export] -macro_rules! slice { - ($this:expr, $start:expr, $end:expr) => { - &$this.source[$start as usize..$end as usize] - }; -} - mod expr; mod item; mod stmt; -use noirc_frontend::hir::resolution::errors::Span; +use noirc_frontend::{hir::resolution::errors::Span, token::Token}; -use crate::config::Config; +use crate::{config::Config, utils::FindToken}; pub(crate) struct FmtVisitor<'me> { config: &'me Config, @@ -33,6 +25,20 @@ impl<'me> FmtVisitor<'me> { } } + pub(crate) fn slice(&self, span: impl Into) -> &'me str { + let span = span.into(); + &self.source[span.start() as usize..span.end() as usize] + } + + fn span_before(&self, span: impl Into, token: Token) -> Span { + let span = span.into(); + + let slice = self.slice(span); + let offset = slice.find_token(token).unwrap(); + + (span.start() + offset..span.end()).into() + } + fn shape(&self) -> Shape { Shape { width: self.config.max_width.saturating_sub(self.indent.width()), @@ -110,7 +116,7 @@ impl<'me> FmtVisitor<'me> { return; } - let slice = slice!(self, start, end); + let slice = self.slice(start..end); self.last_position = end; if slice.trim().is_empty() && !self.at_start() { @@ -147,7 +153,7 @@ impl<'me> FmtVisitor<'me> { } pub(crate) fn format_comment(&self, span: Span) -> String { - let slice = slice!(self, span.start(), span.end()).trim(); + let slice = self.slice(span).trim(); let pos = slice.find('/'); if !slice.is_empty() && pos.is_some() { diff --git a/tooling/nargo_fmt/src/visitor/expr.rs b/tooling/nargo_fmt/src/visitor/expr.rs index 8d996276a10..89674f3f17a 100644 --- a/tooling/nargo_fmt/src/visitor/expr.rs +++ b/tooling/nargo_fmt/src/visitor/expr.rs @@ -1,13 +1,11 @@ -use std::ops::Range; - use noirc_frontend::{ - hir::resolution::errors::Span, token::Token, ArrayLiteral, BlockExpression, Expression, - ExpressionKind, Literal, Statement, UnaryOp, + hir::resolution::errors::Span, token::Token, ArrayLiteral, BlockExpression, + ConstructorExpression, Expression, ExpressionKind, Literal, Statement, UnaryOp, }; use super::{FmtVisitor, Shape}; use crate::{ - utils::{self, Expr, FindToken}, + utils::{self, Expr, FindToken, Item}, Config, }; @@ -16,8 +14,7 @@ impl FmtVisitor<'_> { let span = expr.span; let rewrite = self.format_expr(expr); - let rewrite = - utils::recover_comment_removed(slice!(self, span.start(), span.end()), rewrite); + let rewrite = utils::recover_comment_removed(self.slice(span), rewrite); self.push_rewrite(rewrite, span); self.last_position = span.end(); @@ -58,23 +55,23 @@ impl FmtVisitor<'_> { ) } ExpressionKind::Call(call_expr) => { - let span = call_expr.func.span.end()..span.end(); - let span = - skip_useless_tokens(Token::LeftParen, slice!(self, span.start, span.end), span); + let args_span = + self.span_before(call_expr.func.span.end()..span.end(), Token::LeftParen); let callee = self.format_expr(*call_expr.func); - let args = format_parens(self.fork(), false, call_expr.arguments, span); + let args = format_parens(self.fork(), false, call_expr.arguments, args_span); format!("{callee}{args}") } ExpressionKind::MethodCall(method_call_expr) => { - let span = method_call_expr.method_name.span().end()..span.end(); - let span = - skip_useless_tokens(Token::LeftParen, slice!(self, span.start, span.end), span); + let args_span = self.span_before( + method_call_expr.method_name.span().end()..span.end(), + Token::LeftParen, + ); let object = self.format_expr(method_call_expr.object); let method = method_call_expr.method_name.to_string(); - let args = format_parens(self.fork(), false, method_call_expr.arguments, span); + let args = format_parens(self.fork(), false, method_call_expr.arguments, args_span); format!("{object}.{method}{args}") } @@ -83,16 +80,11 @@ impl FmtVisitor<'_> { format!("{}.{}", lhs_str, member_access_expr.rhs) } ExpressionKind::Index(index_expr) => { - let span = index_expr.collection.span.end()..span.end(); - - let span = skip_useless_tokens( - Token::LeftBracket, - slice!(self, span.start, span.end), - span, - ); + let index_span = self + .span_before(index_expr.collection.span.end()..span.end(), Token::LeftBracket); let collection = self.format_expr(index_expr.collection); - let index = format_brackets(self.fork(), false, vec![index_expr.index], span); + let index = format_brackets(self.fork(), false, vec![index_expr.index], index_span); format!("{collection}{index}") } @@ -101,7 +93,7 @@ impl FmtVisitor<'_> { } ExpressionKind::Literal(literal) => match literal { Literal::Integer(_) | Literal::Bool(_) | Literal::Str(_) | Literal::FmtStr(_) => { - slice!(self, span.start(), span.end()).to_string() + self.slice(span).to_string() } Literal::Array(ArrayLiteral::Repeated { repeated_element, length }) => { let repeated = self.format_expr(*repeated_element); @@ -172,11 +164,56 @@ impl FmtVisitor<'_> { result } } + ExpressionKind::Constructor(constructor) => { + let type_name = self.slice(constructor.type_name.span()); + let fields_span = self + .span_before(constructor.type_name.span().end()..span.end(), Token::LeftBrace); + + self.format_struct_lit(type_name, fields_span, *constructor) + } // TODO: - _expr => slice!(self, span.start(), span.end()).to_string(), + _expr => self.slice(span).to_string(), } } + fn format_struct_lit( + &self, + type_name: &str, + fields_span: Span, + constructor: ConstructorExpression, + ) -> String { + let fields = { + let mut visitor = self.fork(); + + visitor.indent.block_indent(visitor.config); + + let nested_indent = visitor.shape(); + let exprs: Vec<_> = + utils::Exprs::new(&visitor, fields_span, constructor.fields).collect(); + let exprs = format_exprs( + visitor.config, + Tactic::HorizontalVertical, + false, + exprs, + nested_indent, + ); + + visitor.indent.block_unindent(visitor.config); + + if exprs.contains('\n') { + format!( + "{}{exprs}{}", + nested_indent.indent.to_string_with_newline(), + visitor.shape().indent.to_string_with_newline() + ) + } else { + format!(" {exprs} ") + } + }; + + format!("{type_name} {{{fields}}}") + } + pub(crate) fn visit_block( &mut self, block: BlockExpression, @@ -197,7 +234,7 @@ impl FmtVisitor<'_> { this.visit_stmts(block.0); }); - let slice = slice!(self, self.last_position, block_span.end() - 1).trim_end(); + let slice = self.slice(self.last_position..block_span.end() - 1).trim_end(); self.push_str(slice); self.last_position = block_span.end(); @@ -211,7 +248,7 @@ impl FmtVisitor<'_> { fn trim_spaces_after_opening_brace(&mut self, block: &[Statement]) { if let Some(first_stmt) = block.first() { - let slice = slice!(self, self.last_position, first_stmt.span.start()); + let slice = self.slice(self.last_position..first_stmt.span.start()); let len = slice.chars().take_while(|ch| ch.is_whitespace()).collect::().rfind('\n'); self.last_position += len.unwrap_or(0) as u32; @@ -219,7 +256,7 @@ impl FmtVisitor<'_> { } fn visit_empty_block(&mut self, block_span: Span, should_indent: bool) { - let slice = slice!(self, block_span.start(), block_span.end()); + let slice = self.slice(block_span); let comment_str = slice[1..slice.len() - 1].trim(); let block_str = if comment_str.is_empty() { "{}".to_string() @@ -237,24 +274,24 @@ impl FmtVisitor<'_> { } } -fn format_expr_seq( +fn format_expr_seq( prefix: &str, - sufix: &str, + suffix: &str, mut visitor: FmtVisitor, trailing_comma: bool, - exprs: Vec, + exprs: Vec, span: Span, - limit: Option, + tactic: Tactic, ) -> String { visitor.indent.block_indent(visitor.config); let nested_indent = visitor.shape(); let exprs: Vec<_> = utils::Exprs::new(&visitor, span, exprs).collect(); - let exprs = format_exprs(visitor.config, trailing_comma, exprs, nested_indent, limit); + let exprs = format_exprs(visitor.config, tactic, trailing_comma, exprs, nested_indent); visitor.indent.block_unindent(visitor.config); - wrap_exprs(prefix, sufix, exprs, nested_indent, visitor.shape()) + wrap_exprs(prefix, suffix, exprs, nested_indent, visitor.shape()) } fn format_brackets( @@ -264,7 +301,15 @@ fn format_brackets( span: Span, ) -> String { let array_width = visitor.config.array_width; - format_expr_seq("[", "]", visitor, trailing_comma, exprs, span, array_width.into()) + format_expr_seq( + "[", + "]", + visitor, + trailing_comma, + exprs, + span, + Tactic::LimitedHorizontalVertical(array_width), + ) } fn format_parens( @@ -273,20 +318,20 @@ fn format_parens( exprs: Vec, span: Span, ) -> String { - format_expr_seq("(", ")", visitor, trailing_comma, exprs, span, None) + format_expr_seq("(", ")", visitor, trailing_comma, exprs, span, Tactic::Horizontal) } fn format_exprs( config: &Config, + tactic: Tactic, trailing_comma: bool, exprs: Vec, shape: Shape, - limit: Option, ) -> String { let mut result = String::new(); let indent_str = shape.indent.to_string(); - let tactic = Tactic::of(&exprs, config.short_array_element_width_threshold, limit); + let tactic = tactic.definitive(&exprs, config.short_array_element_width_threshold); let mut exprs = exprs.into_iter().enumerate().peekable(); let mut line_len = 0; let mut prev_expr_trailing_comment = false; @@ -297,14 +342,16 @@ fn format_exprs( let separate_len = usize::from(separate); match tactic { - Tactic::Vertical if !is_first && !expr.value.is_empty() && !result.is_empty() => { + DefinitiveTactic::Vertical + if !is_first && !expr.value.is_empty() && !result.is_empty() => + { result.push('\n'); result.push_str(&indent_str); } - Tactic::Horizontal if !is_first => { + DefinitiveTactic::Horizontal if !is_first => { result.push(' '); } - Tactic::Mixed => { + DefinitiveTactic::Mixed => { let total_width = expr.total_width() + separate_len; if line_len > 0 && line_len + 1 + total_width > shape.width @@ -335,7 +382,7 @@ fn format_exprs( result.push_str(&expr.value); - if tactic == Tactic::Horizontal { + if tactic == DefinitiveTactic::Horizontal { result.push_str(&expr.trailing); } @@ -343,7 +390,7 @@ fn format_exprs( result.push(','); } - if tactic != Tactic::Horizontal { + if tactic != DefinitiveTactic::Horizontal { prev_expr_trailing_comment = !expr.trailing.is_empty(); if !expr.different_line && !expr.trailing.is_empty() { @@ -359,7 +406,7 @@ fn format_exprs( fn wrap_exprs( prefix: &str, - sufix: &str, + suffix: &str, exprs: String, nested_shape: Shape, shape: Shape, @@ -380,46 +427,84 @@ fn wrap_exprs( String::new() }; - format!("{prefix}{exprs}{trailing_newline}{sufix}") + format!("{prefix}{exprs}{trailing_newline}{suffix}") } else { let nested_indent_str = nested_shape.indent.to_string_with_newline(); - let indent_str = shape.indent.to_string(); + let indent_str = shape.indent.to_string_with_newline(); - format!("{prefix}{nested_indent_str}{exprs}{indent_str}{sufix}") + format!("{prefix}{nested_indent_str}{exprs}{indent_str}{suffix}") } } -#[derive(Debug, PartialEq, Eq, Clone, Copy)] +#[derive(PartialEq, Eq)] enum Tactic { - Vertical, Horizontal, + HorizontalVertical, + LimitedHorizontalVertical(usize), Mixed, } impl Tactic { - fn of(exprs: &[Expr], max_width: usize, limit: Option) -> Self { - let mut tactic = if exprs.iter().any(|item| { - has_single_line_comment(&item.leading) || has_single_line_comment(&item.trailing) - }) { - Tactic::Vertical - } else { - Tactic::Horizontal + fn definitive( + self, + exprs: &[Expr], + short_array_element_width_threshold: usize, + ) -> DefinitiveTactic { + let tactic = || { + let has_single_line_comment = exprs.iter().any(|item| { + has_single_line_comment(&item.leading) || has_single_line_comment(&item.trailing) + }); + + let limit = match self { + _ if has_single_line_comment => return DefinitiveTactic::Vertical, + + Tactic::Horizontal => return DefinitiveTactic::Horizontal, + Tactic::LimitedHorizontalVertical(limit) => limit, + Tactic::HorizontalVertical | Tactic::Mixed => 100, + }; + + let (sep_count, total_width): (usize, usize) = exprs + .iter() + .map(|expr| expr.total_width()) + .fold((0, 0), |(sep_count, total_width), width| { + (sep_count + 1, total_width + width) + }); + + let total_sep_len = sep_count.saturating_sub(1); + let real_total = total_width + total_sep_len; + + if real_total <= limit && !exprs.iter().any(|expr| expr.is_multiline()) { + DefinitiveTactic::Horizontal + } else if self == Tactic::Mixed { + DefinitiveTactic::Mixed + } else { + DefinitiveTactic::Vertical + } }; - if tactic == Tactic::Vertical && no_long_exprs(exprs, max_width) { - tactic = Tactic::Mixed; - } + tactic().reduce(exprs, short_array_element_width_threshold) + } +} - if let Some(limit) = limit { - let total_width: usize = exprs.iter().map(|expr| expr.total_width()).sum(); - if total_width <= limit && !exprs.iter().any(|expr| expr.is_multiline()) { - tactic = Tactic::Horizontal; - } else { - tactic = Tactic::Mixed; +#[derive(Debug, PartialEq, Eq, Clone, Copy)] +enum DefinitiveTactic { + Vertical, + Horizontal, + Mixed, +} + +impl DefinitiveTactic { + fn reduce(self, exprs: &[Expr], short_array_element_width_threshold: usize) -> Self { + match self { + DefinitiveTactic::Vertical + if no_long_exprs(exprs, short_array_element_width_threshold) => + { + DefinitiveTactic::Mixed + } + DefinitiveTactic::Vertical | DefinitiveTactic::Horizontal | DefinitiveTactic::Mixed => { + self } } - - tactic } } @@ -427,12 +512,6 @@ fn has_single_line_comment(slice: &str) -> bool { slice.trim_start().starts_with("//") } -fn skip_useless_tokens(token: Token, slice: &str, mut span: Range) -> Span { - let offset = slice.find_token(token).unwrap(); - span.start += offset; - span.into() -} - fn no_long_exprs(exprs: &[Expr], max_width: usize) -> bool { exprs.iter().all(|expr| expr.value.len() <= max_width) } diff --git a/tooling/nargo_fmt/src/visitor/item.rs b/tooling/nargo_fmt/src/visitor/item.rs index 1e32ab22747..09031082fa3 100644 --- a/tooling/nargo_fmt/src/visitor/item.rs +++ b/tooling/nargo_fmt/src/visitor/item.rs @@ -5,7 +5,7 @@ use noirc_frontend::{ impl super::FmtVisitor<'_> { fn format_fn_before_block(&self, func: NoirFunction, start: u32) -> (String, bool) { - let slice = slice!(self, start, func.span().start()); + let slice = self.slice(start..func.span().start()); let force_brace_newline = slice.contains("//"); (slice.trim_end().to_string(), force_brace_newline) } diff --git a/tooling/nargo_fmt/src/visitor/stmt.rs b/tooling/nargo_fmt/src/visitor/stmt.rs index d7a43db1e00..724f6bc7156 100644 --- a/tooling/nargo_fmt/src/visitor/stmt.rs +++ b/tooling/nargo_fmt/src/visitor/stmt.rs @@ -11,7 +11,7 @@ impl super::FmtVisitor<'_> { } StatementKind::Let(let_stmt) => { let let_str = - slice!(self, span.start(), let_stmt.expression.span.start()).trim_end(); + self.slice(span.start()..let_stmt.expression.span.start()).trim_end(); let expr_str = self.format_expr(let_stmt.expression); self.push_rewrite(format!("{let_str} {expr_str};"), span); diff --git a/tooling/nargo_fmt/tests/expected/array.nr b/tooling/nargo_fmt/tests/expected/array.nr index c0ffa30a85e..fdf81d3595c 100644 --- a/tooling/nargo_fmt/tests/expected/array.nr +++ b/tooling/nargo_fmt/tests/expected/array.nr @@ -1,9 +1,29 @@ fn big_array() { - [1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, - 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, - 10000000000000000, 100000000000000000, 1000000000000000000, 10000000000000000000, - 100000000000000000000, 1000000000000000000000, 10000000000000000000000, - 100000000000000000000000, 1000000000000000000000000]; + [1, + 10, + 100, + 1000, + 10000, + 100000, + 1000000, + 10000000, + 100000000, + 1000000000, + 10000000000, + 100000000000, + 1000000000000, + 10000000000000, + 100000000000000, + 1000000000000000, + 10000000000000000, + 100000000000000000, + 1000000000000000000, + 10000000000000000000, + 100000000000000000000, + 1000000000000000000000, + 10000000000000000000000, + 100000000000000000000000, + 1000000000000000000000000]; [1, 10]; diff --git a/tooling/nargo_fmt/tests/expected/expr.nr b/tooling/nargo_fmt/tests/expected/expr.nr index c4fd1633bdb..6c95b6925ef 100644 --- a/tooling/nargo_fmt/tests/expected/expr.nr +++ b/tooling/nargo_fmt/tests/expected/expr.nr @@ -90,3 +90,7 @@ fn parenthesized() { x as Field ) } + +fn constructor() { + Point { x: 5, y: 10 }; +} diff --git a/tooling/nargo_fmt/tests/expected/let.nr b/tooling/nargo_fmt/tests/expected/let.nr index 261982cf3e1..c53f43c7e65 100644 --- a/tooling/nargo_fmt/tests/expected/let.nr +++ b/tooling/nargo_fmt/tests/expected/let.nr @@ -14,4 +14,38 @@ fn let_() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + + let a = BigUint56 { + limbs: [ + 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + ] + }; + + let person = Person { + first_name: "John", + last_name: "Doe", + home_address: Address { street: "123 Main St", city: "Exampleville", zip_code: "12345" } + }; + + let person = Person { + first_name: "John", + last_name: "Doe", + home_address: Address { + street: "123 Main St", + city: "Exampleville", + zip_code: "12345", + master: Person { + first_name: "John", + last_name: "Doe", + home_address: Address { street: "123 Main St", city: "Exampleville", zip_code: "12345" } + } + } + }; + + let expr = Expr { + // A boolean literal (true, false). + kind: ExprKind::Bool(true) + }; + + let expr = Expr { /*A boolean literal (true, false).*/ kind: ExprKind::Bool(true) }; } diff --git a/tooling/nargo_fmt/tests/expected/struct.nr b/tooling/nargo_fmt/tests/expected/struct.nr index f662e5757a5..6734dec68a6 100644 --- a/tooling/nargo_fmt/tests/expected/struct.nr +++ b/tooling/nargo_fmt/tests/expected/struct.nr @@ -34,11 +34,7 @@ struct MyStruct { my_nest: Nested, } fn test_struct_in_tuple(a_bool : bool,x:Field, y:Field) -> (MyStruct, bool) { - let my_struct = MyStruct { - my_bool: a_bool, - my_int: 5, - my_nest: Nested{a:x,b:y}, - }; + let my_struct = MyStruct { my_bool: a_bool, my_int: 5, my_nest: Nested { a: x, b: y } }; (my_struct, a_bool) } diff --git a/tooling/nargo_fmt/tests/input/expr.nr b/tooling/nargo_fmt/tests/input/expr.nr index 0baef877169..ff2ac1e10a2 100644 --- a/tooling/nargo_fmt/tests/input/expr.nr +++ b/tooling/nargo_fmt/tests/input/expr.nr @@ -99,3 +99,8 @@ fn parenthesized() { x as Field ) } + +fn constructor() { + Point{x :5, + y: 10 }; +} \ No newline at end of file diff --git a/tooling/nargo_fmt/tests/input/let.nr b/tooling/nargo_fmt/tests/input/let.nr index d73a6450a33..c603d44a4ad 100644 --- a/tooling/nargo_fmt/tests/input/let.nr +++ b/tooling/nargo_fmt/tests/input/let.nr @@ -12,4 +12,16 @@ fn let_() { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]; + + let a = BigUint56 {limbs:[1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]}; + + let person = Person { first_name: "John", last_name: "Doe", home_address: Address { street: "123 Main St", city: "Exampleville", zip_code: "12345" } }; + + let person = Person { first_name: "John", last_name: "Doe", home_address: Address { street: "123 Main St", city: "Exampleville", zip_code: "12345", master: Person { first_name: "John", last_name: "Doe", home_address: Address { street: "123 Main St", city: "Exampleville", zip_code: "12345" } } } }; + + let expr = Expr {// A boolean literal (true, false). +kind: ExprKind::Bool(true), + }; + + let expr = Expr {/*A boolean literal (true, false).*/kind: ExprKind::Bool(true),}; } From b519e286f8adcc347ceacbbec857a04fbe4e2569 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 23 Oct 2023 15:08:54 +0100 Subject: [PATCH 05/17] chore(ci): Generate circuit benchmark summaries on PRs (#3250) --- .github/workflows/gates_report.yml | 90 +++++++++++++++++++++++++ .gitignore | 3 + Cargo.lock | 20 ++---- cspell.json | 1 + tooling/nargo_cli/Cargo.toml | 2 +- tooling/nargo_cli/tests/gates_report.sh | 36 ++++++++++ 6 files changed, 135 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/gates_report.yml create mode 100755 tooling/nargo_cli/tests/gates_report.sh diff --git a/.github/workflows/gates_report.yml b/.github/workflows/gates_report.yml new file mode 100644 index 00000000000..e2d6bdd56b7 --- /dev/null +++ b/.github/workflows/gates_report.yml @@ -0,0 +1,90 @@ +name: Report gates diff + +on: + push: + branches: + - master + pull_request: + +jobs: + build-nargo: + runs-on: ubuntu-latest + strategy: + matrix: + target: [x86_64-unknown-linux-gnu] + + steps: + - name: Checkout Noir repo + uses: actions/checkout@v4 + + - name: Setup toolchain + uses: dtolnay/rust-toolchain@1.66.0 + + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ matrix.target }} + cache-on-failure: true + save-if: ${{ github.event_name != 'merge_group' }} + + - name: Build Nargo + run: cargo build --package nargo_cli --release + + - name: Package artifacts + run: | + mkdir dist + cp ./target/release/nargo ./dist/nargo + 7z a -ttar -so -an ./dist/* | 7z a -si ./nargo-x86_64-unknown-linux-gnu.tar.gz + + - name: Upload artifact + uses: actions/upload-artifact@v3 + with: + name: nargo + path: ./dist/* + retention-days: 3 + + + compare_gas_reports: + needs: [build-nargo] + runs-on: ubuntu-latest + permissions: + pull-requests: write + + steps: + - uses: actions/checkout@v3 + with: + submodules: recursive + + - name: Download nargo binary + uses: actions/download-artifact@v3 + with: + name: nargo + path: ./nargo + + - name: Set nargo on PATH + run: | + nargo_binary="${{ github.workspace }}/nargo/nargo" + chmod +x $nargo_binary + echo "$(dirname $nargo_binary)" >> $GITHUB_PATH + export PATH="$PATH:$(dirname $nargo_binary)" + nargo -V + + - name: Generate gates report + working-directory: ./tooling/nargo_cli/tests + run: | + ./gates_report.sh + mv gates_report.json ../../../gates_report.json + + - name: Compare gates reports + id: gates_diff + uses: TomAFrench/noir-gates-diff@e7cf131b7e7f044c01615f93f0b855f65ddc02d4 + with: + report: gates_report.json + summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%) + + - name: Add gates diff to sticky comment + if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target' + uses: marocchino/sticky-pull-request-comment@v2 + with: + # delete the comment in case changes no longer impact circuit sizes + delete: ${{ !steps.gates_diff.outputs.markdown }} + message: ${{ steps.gates_diff.outputs.markdown }} diff --git a/.gitignore b/.gitignore index 94e8f1a8db0..169353af2b6 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,9 @@ result !tooling/nargo_cli/tests/acir_artifacts/*/target !tooling/nargo_cli/tests/acir_artifacts/*/target/witness.gz !compiler/wasm/noir-script/target + +gates_report.json + # Github Actions scratch space # This gives a location to download artifacts into the repository in CI without making git dirty. libbarretenberg-wasm32 diff --git a/Cargo.lock b/Cargo.lock index c9c60fc62ed..8fb282dda98 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1116,16 +1116,6 @@ dependencies = [ "itertools", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - [[package]] name = "crossbeam-deque" version = "0.8.3" @@ -3187,9 +3177,9 @@ dependencies = [ [[package]] name = "rayon" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b" +checksum = "9c27db03db7734835b3f53954b534c91069375ce6ccaa2e065441e07d9b6cdb1" dependencies = [ "either", "rayon-core", @@ -3197,14 +3187,12 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d" +checksum = "5ce3fb6ad83f861aac485e76e1985cd109d9a3713802152be56c3b1f0e0658ed" dependencies = [ - "crossbeam-channel", "crossbeam-deque", "crossbeam-utils", - "num_cpus", ] [[package]] diff --git a/cspell.json b/cspell.json index ac7953e0653..4df858ffcfa 100644 --- a/cspell.json +++ b/cspell.json @@ -88,6 +88,7 @@ "prettytable", "printstd", "pseudocode", + "quantile", "rustc", "rustup", "schnorr", diff --git a/tooling/nargo_cli/Cargo.toml b/tooling/nargo_cli/Cargo.toml index cb824b41428..a1440dc2ecb 100644 --- a/tooling/nargo_cli/Cargo.toml +++ b/tooling/nargo_cli/Cargo.toml @@ -37,7 +37,7 @@ toml.workspace = true serde.workspace = true serde_json.workspace = true prettytable-rs = "0.10" -rayon = "1.7.0" +rayon = "1.8.0" thiserror.workspace = true tower.workspace = true async-lsp = { version = "0.0.5", default-features = false, features = [ diff --git a/tooling/nargo_cli/tests/gates_report.sh b/tooling/nargo_cli/tests/gates_report.sh new file mode 100755 index 00000000000..e06e6812e9d --- /dev/null +++ b/tooling/nargo_cli/tests/gates_report.sh @@ -0,0 +1,36 @@ +#!/bin/bash +set -e + +# These tests are incompatible with gas reporting +excluded_dirs=("workspace" "workspace_default_member") + +# These tests cause failures in CI with a stack overflow for some reason. +ci_excluded_dirs=("eddsa") + +current_dir=$(pwd) +base_path="$current_dir/execution_success" +test_dirs=$(ls $base_path) + +# We generate a Noir workspace which contains all of the test cases +# This allows us to generate a gates report using `nargo info` for all of them at once. + +echo "[workspace]" > Nargo.toml +echo "members = [" >> Nargo.toml + +for dir in $test_dirs; do + if [[ " ${excluded_dirs[@]} " =~ " ${dir} " ]]; then + continue + fi + + if [[ ${CI-false} = "true" ]] && [[ " ${ci_excluded_dirs[@]} " =~ " ${dir} " ]]; then + continue + fi + + echo " \"execution_success/$dir\"," >> Nargo.toml +done + +echo "]" >> Nargo.toml + +nargo info --json > gates_report.json + +rm Nargo.toml From 07ca18129efb676d27b925c803ec00f523341a9b Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 23 Oct 2023 16:18:52 +0000 Subject: [PATCH 06/17] add git commit to noir_version --- compiler/wasm/src/compile.rs | 6 +++++- tooling/nargo/src/artifacts/contract.rs | 2 ++ tooling/nargo_cli/src/cli/compile_cmd.rs | 9 ++++++--- tooling/nargo_cli/src/cli/mod.rs | 4 ++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/compiler/wasm/src/compile.rs b/compiler/wasm/src/compile.rs index 7c4d2a5adaf..477117a2c9a 100644 --- a/compiler/wasm/src/compile.rs +++ b/compiler/wasm/src/compile.rs @@ -17,6 +17,9 @@ use crate::errors::JsCompileError; const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; +const NOIR_ARTIFACT_VERSION_STRING: &str = + concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); + #[wasm_bindgen] extern "C" { #[wasm_bindgen(extends = Array, js_name = "StringArray", typescript_type = "string[]")] @@ -118,7 +121,7 @@ fn preprocess_program(program: CompiledProgram) -> PreprocessedProgram { hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, - noir_version: program.noir_version, + noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), bytecode: program.circuit, } } @@ -137,6 +140,7 @@ fn preprocess_contract(contract: CompiledContract) -> PreprocessedContract { .collect(); PreprocessedContract { + noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), name: contract.name, backend: String::from(BACKEND_IDENTIFIER), functions: preprocessed_functions, diff --git a/tooling/nargo/src/artifacts/contract.rs b/tooling/nargo/src/artifacts/contract.rs index fa161b63a5b..4f1ae0e10a0 100644 --- a/tooling/nargo/src/artifacts/contract.rs +++ b/tooling/nargo/src/artifacts/contract.rs @@ -10,6 +10,8 @@ use serde::{Deserialize, Serialize}; /// - Proving and verification keys have been pregenerated based on this ACIR. #[derive(Serialize, Deserialize)] pub struct PreprocessedContract { + /// Version of noir used to compile this contract + pub noir_version: String, /// The name of the contract. pub name: String, /// The identifier of the proving backend which this contract has been compiled for. diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 041d3837d53..3916f446008 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -28,7 +28,7 @@ use super::fs::program::{ save_contract_to_file, save_debug_artifact_to_file, save_program_to_file, }; use super::NargoConfig; -use super::CARGO_PKG_VERSION; +use super::NOIR_ARTIFACT_VERSION_STRING; use rayon::prelude::*; // TODO(#1388): pull this from backend. @@ -214,7 +214,9 @@ fn compile_program( // If we want to output the debug information then we need to perform a full recompilation of the ACIR. let force_recompile = output_debug - || cached_program.as_ref().map_or(false, |p| p.noir_version != CARGO_PKG_VERSION); + || 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, @@ -277,7 +279,7 @@ fn save_program( hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, - noir_version: CARGO_PKG_VERSION.to_owned(), + noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), bytecode: program.circuit, }; @@ -315,6 +317,7 @@ fn save_contract( }); let preprocessed_contract = PreprocessedContract { + noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), name: contract.name, backend: String::from(BACKEND_IDENTIFIER), functions: preprocessed_functions, diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index a0ef778e1a5..7a5a3d0752e 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -28,6 +28,10 @@ const GIT_HASH: &str = env!("GIT_COMMIT"); const IS_DIRTY: &str = env!("GIT_DIRTY"); const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); +/// Version string that gets placed in artifacts that Noir builds +pub(crate) const NOIR_ARTIFACT_VERSION_STRING: &str = + concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); + static VERSION_STRING: &str = formatcp!("{} (git version hash: {}, is dirty: {})", CARGO_PKG_VERSION, GIT_HASH, IS_DIRTY); From 36ba1a6dda04b9ab4361442cdf454801d52d16a7 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:19:01 +0100 Subject: [PATCH 07/17] feat: Cache debug artifacts (#3133) Co-authored-by: kevaundray --- .../nargo_cli/src/cli/codegen_verifier_cmd.rs | 1 - tooling/nargo_cli/src/cli/compile_cmd.rs | 99 ++++++------------- tooling/nargo_cli/src/cli/debug_cmd.rs | 12 +-- tooling/nargo_cli/src/cli/execute_cmd.rs | 1 - tooling/nargo_cli/src/cli/fs/program.rs | 11 +++ tooling/nargo_cli/src/cli/info_cmd.rs | 1 - tooling/nargo_cli/src/cli/prove_cmd.rs | 1 - tooling/nargo_cli/src/cli/verify_cmd.rs | 1 - 8 files changed, 44 insertions(+), 83 deletions(-) diff --git a/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs b/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs index 35538ef1a83..856970544b8 100644 --- a/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ b/tooling/nargo_cli/src/cli/codegen_verifier_cmd.rs @@ -76,7 +76,6 @@ fn smart_contract_for_package( workspace, package, compile_options, - false, np_language, &is_opcode_supported, )?; diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 3916f446008..e10071745e8 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -1,4 +1,3 @@ -use std::collections::BTreeMap; use std::path::Path; use acvm::acir::circuit::Opcode; @@ -15,7 +14,6 @@ use nargo::prepare_package; use nargo::workspace::Workspace; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{CompilationResult, CompileOptions, CompiledContract, CompiledProgram}; -use noirc_errors::debug_info::DebugInfo; use noirc_frontend::graph::CrateName; use clap::Args; @@ -23,9 +21,9 @@ use clap::Args; use crate::backends::Backend; use crate::errors::{CliError, CompileError}; -use super::fs::program::read_program_from_file; use super::fs::program::{ - save_contract_to_file, save_debug_artifact_to_file, save_program_to_file, + read_debug_artifact_from_file, read_program_from_file, save_contract_to_file, + save_debug_artifact_to_file, save_program_to_file, }; use super::NargoConfig; use super::NOIR_ARTIFACT_VERSION_STRING; @@ -41,10 +39,6 @@ pub(crate) struct CompileCommand { #[arg(long)] include_keys: bool, - /// Output debug files - #[arg(long, hide = true)] - output_debug: bool, - /// The name of the package to compile #[clap(long, conflicts_with = "workspace")] package: Option, @@ -83,12 +77,11 @@ pub(crate) fn run( np_language, &opcode_support, &args.compile_options, - args.output_debug, )?; // Save build artifacts to disk. for (package, contract) in contract_packages.into_iter().zip(compiled_contracts) { - save_contract(contract, &package, &circuit_dir, args.output_debug); + save_contract(contract, &package, &circuit_dir); } Ok(()) @@ -101,7 +94,6 @@ pub(super) fn compile_workspace( np_language: Language, opcode_support: &BackendOpcodeSupport, compile_options: &CompileOptions, - output_debug: bool, ) -> Result<(Vec, Vec), CliError> { let is_opcode_supported = |opcode: &_| opcode_support.is_opcode_supported(opcode); @@ -109,14 +101,7 @@ pub(super) fn compile_workspace( let program_results: Vec<(FileManager, CompilationResult)> = binary_packages .par_iter() .map(|package| { - compile_program( - workspace, - package, - compile_options, - output_debug, - np_language, - &is_opcode_supported, - ) + compile_program(workspace, package, compile_options, np_language, &is_opcode_supported) }) .collect(); let contract_results: Vec<(FileManager, CompilationResult)> = @@ -158,7 +143,6 @@ pub(crate) fn compile_bin_package( workspace: &Workspace, package: &Package, compile_options: &CompileOptions, - output_debug: bool, np_language: Language, is_opcode_supported: &impl Fn(&Opcode) -> bool, ) -> Result { @@ -166,14 +150,8 @@ pub(crate) fn compile_bin_package( return Err(CompileError::LibraryCrate(package.name.clone()).into()); } - let (file_manager, compilation_result) = compile_program( - workspace, - package, - compile_options, - output_debug, - np_language, - &is_opcode_supported, - ); + let (file_manager, compilation_result) = + compile_program(workspace, package, compile_options, np_language, &is_opcode_supported); let program = report_errors( compilation_result, @@ -189,34 +167,34 @@ fn compile_program( workspace: &Workspace, package: &Package, compile_options: &CompileOptions, - output_debug: bool, np_language: Language, is_opcode_supported: &impl Fn(&Opcode) -> bool, ) -> (FileManager, CompilationResult) { let (mut context, crate_id) = prepare_package(package, Box::new(|path| std::fs::read_to_string(path))); - let cached_program = if let Ok(preprocessed_program) = - read_program_from_file(workspace.package_build_path(package)) - { - // TODO: Load debug information. + let program_artifact_path = workspace.package_build_path(package); + let mut debug_artifact_path = program_artifact_path.clone(); + debug_artifact_path.set_file_name(format!("debug_{}.json", package.name)); + let cached_program = if let (Ok(preprocessed_program), Ok(mut debug_artifact)) = ( + read_program_from_file(program_artifact_path), + read_debug_artifact_from_file(debug_artifact_path), + ) { Some(CompiledProgram { hash: preprocessed_program.hash, circuit: preprocessed_program.bytecode, abi: preprocessed_program.abi, noir_version: preprocessed_program.noir_version, - debug: DebugInfo::default(), - file_map: BTreeMap::new(), + debug: debug_artifact.debug_symbols.remove(0), + file_map: debug_artifact.file_map, }) } else { None }; // If we want to output the debug information then we need to perform a full recompilation of the ACIR. - let force_recompile = output_debug - || cached_program - .as_ref() - .map_or(false, |p| p.noir_version != NOIR_ARTIFACT_VERSION_STRING); + 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, @@ -236,12 +214,7 @@ fn compile_program( nargo::ops::optimize_program(program, np_language, &is_opcode_supported) .expect("Backend does not support an opcode that is in the IR"); - save_program( - optimized_program.clone(), - package, - &workspace.target_directory_path(), - output_debug, - ); + save_program(optimized_program.clone(), package, &workspace.target_directory_path()); (context.file_manager, Ok((optimized_program, warnings))) } @@ -269,12 +242,7 @@ fn compile_contract( (context.file_manager, Ok((optimized_contract, warnings))) } -fn save_program( - program: CompiledProgram, - package: &Package, - circuit_dir: &Path, - output_debug: bool, -) { +fn save_program(program: CompiledProgram, package: &Package, circuit_dir: &Path) { let preprocessed_program = PreprocessedProgram { hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), @@ -285,20 +253,13 @@ fn save_program( save_program_to_file(&preprocessed_program, &package.name, circuit_dir); - if output_debug { - let debug_artifact = - DebugArtifact { debug_symbols: vec![program.debug], file_map: program.file_map }; - let circuit_name: String = (&package.name).into(); - save_debug_artifact_to_file(&debug_artifact, &circuit_name, circuit_dir); - } + let debug_artifact = + DebugArtifact { debug_symbols: vec![program.debug], file_map: program.file_map }; + let circuit_name: String = (&package.name).into(); + save_debug_artifact_to_file(&debug_artifact, &circuit_name, circuit_dir); } -fn save_contract( - contract: CompiledContract, - package: &Package, - circuit_dir: &Path, - output_debug: bool, -) { +fn save_contract(contract: CompiledContract, package: &Package, circuit_dir: &Path) { // TODO(#1389): I wonder if it is incorrect for nargo-core to know anything about contracts. // As can be seen here, It seems like a leaky abstraction where ContractFunctions (essentially CompiledPrograms) // are compiled via nargo-core and then the PreprocessedContract is constructed here. @@ -330,13 +291,11 @@ fn save_contract( circuit_dir, ); - if output_debug { - save_debug_artifact_to_file( - &debug_artifact, - &format!("{}-{}", package.name, preprocessed_contract.name), - circuit_dir, - ); - } + save_debug_artifact_to_file( + &debug_artifact, + &format!("{}-{}", package.name, preprocessed_contract.name), + circuit_dir, + ); } /// Helper function for reporting any errors in a `CompilationResult` diff --git a/tooling/nargo_cli/src/cli/debug_cmd.rs b/tooling/nargo_cli/src/cli/debug_cmd.rs index 7d8c0dc9a15..82cd3349ec4 100644 --- a/tooling/nargo_cli/src/cli/debug_cmd.rs +++ b/tooling/nargo_cli/src/cli/debug_cmd.rs @@ -52,14 +52,10 @@ pub(crate) fn run( return Ok(()); }; - let compiled_program = compile_bin_package( - &workspace, - package, - &args.compile_options, - true, - np_language, - &|opcode| opcode_support.is_opcode_supported(opcode), - )?; + let compiled_program = + compile_bin_package(&workspace, package, &args.compile_options, np_language, &|opcode| { + opcode_support.is_opcode_supported(opcode) + })?; println!("[{}] Starting debugger", package.name); let (return_value, solved_witness) = diff --git a/tooling/nargo_cli/src/cli/execute_cmd.rs b/tooling/nargo_cli/src/cli/execute_cmd.rs index c61dc6db69c..1819c9a6f06 100644 --- a/tooling/nargo_cli/src/cli/execute_cmd.rs +++ b/tooling/nargo_cli/src/cli/execute_cmd.rs @@ -57,7 +57,6 @@ pub(crate) fn run( &workspace, package, &args.compile_options, - false, np_language, &|opcode| opcode_support.is_opcode_supported(opcode), )?; diff --git a/tooling/nargo_cli/src/cli/fs/program.rs b/tooling/nargo_cli/src/cli/fs/program.rs index 377786627be..e82f2d55264 100644 --- a/tooling/nargo_cli/src/cli/fs/program.rs +++ b/tooling/nargo_cli/src/cli/fs/program.rs @@ -60,3 +60,14 @@ pub(crate) fn read_program_from_file>( Ok(program) } + +pub(crate) fn read_debug_artifact_from_file>( + debug_artifact_path: P, +) -> Result { + let input_string = std::fs::read(&debug_artifact_path) + .map_err(|_| FilesystemError::PathNotValid(debug_artifact_path.as_ref().into()))?; + let program = serde_json::from_slice(&input_string) + .map_err(|err| FilesystemError::ProgramSerializationError(err.to_string()))?; + + Ok(program) +} diff --git a/tooling/nargo_cli/src/cli/info_cmd.rs b/tooling/nargo_cli/src/cli/info_cmd.rs index e55b1b7886f..50021e842c4 100644 --- a/tooling/nargo_cli/src/cli/info_cmd.rs +++ b/tooling/nargo_cli/src/cli/info_cmd.rs @@ -63,7 +63,6 @@ pub(crate) fn run( np_language, &opcode_support, &args.compile_options, - false, )?; let program_info = binary_packages diff --git a/tooling/nargo_cli/src/cli/prove_cmd.rs b/tooling/nargo_cli/src/cli/prove_cmd.rs index 5571117e2d4..af300b7ebe0 100644 --- a/tooling/nargo_cli/src/cli/prove_cmd.rs +++ b/tooling/nargo_cli/src/cli/prove_cmd.rs @@ -59,7 +59,6 @@ pub(crate) fn run( &workspace, package, &args.compile_options, - false, np_language, &|opcode| opcode_support.is_opcode_supported(opcode), )?; diff --git a/tooling/nargo_cli/src/cli/verify_cmd.rs b/tooling/nargo_cli/src/cli/verify_cmd.rs index a5a39e9aef9..6ae2b78fd0c 100644 --- a/tooling/nargo_cli/src/cli/verify_cmd.rs +++ b/tooling/nargo_cli/src/cli/verify_cmd.rs @@ -50,7 +50,6 @@ pub(crate) fn run( &workspace, package, &args.compile_options, - false, np_language, &|opcode| opcode_support.is_opcode_supported(opcode), )?; From 6dd738f372de85e64378a935cdfa8496ea924e20 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:19:01 +0100 Subject: [PATCH 08/17] feat: Cache debug artifacts (#3133) Co-authored-by: kevaundray --- ex/noir-trie-proofs | 1 + 1 file changed, 1 insertion(+) create mode 160000 ex/noir-trie-proofs diff --git a/ex/noir-trie-proofs b/ex/noir-trie-proofs new file mode 160000 index 00000000000..ef66f4b5753 --- /dev/null +++ b/ex/noir-trie-proofs @@ -0,0 +1 @@ +Subproject commit ef66f4b5753c97b659945ba05b2992a418421c19 From 5ff3cbe47b410875bba8f0866a60e1071819ddc4 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:19:01 +0100 Subject: [PATCH 09/17] feat: Cache debug artifacts (#3133) Co-authored-by: kevaundray --- tooling/nargo_cli/src/cli/compile_cmd.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index e10071745e8..a85654c739f 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -191,6 +191,7 @@ fn compile_program( } else { None }; + // If we want to output the debug information then we need to perform a full recompilation of the ACIR. let force_recompile = From 5604bdd6c61b066f6b8a021638937ee90f2f1fa9 Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 23 Oct 2023 16:40:08 +0000 Subject: [PATCH 10/17] format --- tooling/nargo_cli/src/cli/compile_cmd.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index a85654c739f..e10071745e8 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -191,7 +191,6 @@ fn compile_program( } else { None }; - // If we want to output the debug information then we need to perform a full recompilation of the ACIR. let force_recompile = From 1c4a0f7ac14f296f15fc2b8e71d2f7ed78a9f057 Mon Sep 17 00:00:00 2001 From: guipublic Date: Mon, 23 Oct 2023 17:38:39 +0000 Subject: [PATCH 11/17] code reivew: remove tmp file --- ex/noir-trie-proofs | 1 - 1 file changed, 1 deletion(-) delete mode 160000 ex/noir-trie-proofs diff --git a/ex/noir-trie-proofs b/ex/noir-trie-proofs deleted file mode 160000 index ef66f4b5753..00000000000 --- a/ex/noir-trie-proofs +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ef66f4b5753c97b659945ba05b2992a418421c19 From edad212445d9e017ee63416f5836da36c8a73387 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 23 Oct 2023 19:32:21 +0000 Subject: [PATCH 12/17] move noirc_version to noirc_driver --- Cargo.lock | 1 + compiler/noirc_driver/Cargo.toml | 3 +++ compiler/noirc_driver/build.rs | 14 ++++++++++++++ compiler/noirc_driver/src/contract.rs | 2 ++ compiler/noirc_driver/src/lib.rs | 12 +++++++++++- compiler/noirc_driver/src/program.rs | 2 +- compiler/wasm/build.rs | 10 ---------- compiler/wasm/src/compile.rs | 7 ++----- compiler/wasm/src/lib.rs | 7 ++++--- tooling/nargo/src/artifacts/program.rs | 3 ++- tooling/nargo_cli/src/cli/compile_cmd.rs | 6 +++--- tooling/nargo_cli/src/cli/init_cmd.rs | 5 +++-- tooling/nargo_cli/src/cli/mod.rs | 9 +++------ 13 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 compiler/noirc_driver/build.rs diff --git a/Cargo.lock b/Cargo.lock index 8fb282dda98..4cc03fcfdcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2623,6 +2623,7 @@ version = "0.17.0" dependencies = [ "acvm", "base64", + "build-data", "clap", "fm", "fxhash", diff --git a/compiler/noirc_driver/Cargo.toml b/compiler/noirc_driver/Cargo.toml index f1c21f74aab..f1c120e1687 100644 --- a/compiler/noirc_driver/Cargo.toml +++ b/compiler/noirc_driver/Cargo.toml @@ -7,6 +7,9 @@ license.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[build-dependencies] +build-data = "0.1.3" + [dependencies] clap.workspace = true noirc_errors.workspace = true diff --git a/compiler/noirc_driver/build.rs b/compiler/noirc_driver/build.rs new file mode 100644 index 00000000000..bb864aefffc --- /dev/null +++ b/compiler/noirc_driver/build.rs @@ -0,0 +1,14 @@ +const GIT_COMMIT: &&str = &"GIT_COMMIT"; + +fn main() { + // Rebuild if the tests have changed + println!("cargo:rerun-if-changed=tests"); + + // Only use build_data if the environment variable isn't set + // The environment variable is always set when working via Nix + if std::env::var(GIT_COMMIT).is_err() { + build_data::set_GIT_COMMIT(); + build_data::set_GIT_DIRTY(); + build_data::no_debug_rebuilds(); + } +} \ No newline at end of file diff --git a/compiler/noirc_driver/src/contract.rs b/compiler/noirc_driver/src/contract.rs index a16da313ff6..da097d4cb86 100644 --- a/compiler/noirc_driver/src/contract.rs +++ b/compiler/noirc_driver/src/contract.rs @@ -28,6 +28,8 @@ pub enum ContractFunctionType { #[derive(Serialize, Deserialize)] pub struct CompiledContract { + pub noir_version: String, + /// The name of the contract. pub name: String, /// Each of the contract's functions are compiled into a separate `CompiledProgram` diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 00894138f4a..566603e8f11 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -28,6 +28,15 @@ pub use program::CompiledProgram; const STD_CRATE_NAME: &str = "std"; +pub const GIT_COMMIT : &str = env!("GIT_COMMIT"); +pub const GIT_DIRTY : &str = env!("GIT_DIRTY"); +pub const NOIRC_VERSION : &str = env!("CARGO_PKG_VERSION"); + +/// Version string that gets placed in artifacts that Noir builds. +/// Note: You can't directly use the value of a constant produced with env! inside a concat! macro. +pub const NOIR_ARTIFACT_VERSION_STRING: &str = +concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); + #[derive(Args, Clone, Debug, Default, Serialize, Deserialize)] pub struct CompileOptions { /// Emit debug information for the intermediate SSA IR @@ -305,6 +314,7 @@ fn compile_contract_inner( .collect(), functions, file_map, + noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(), }) } else { Err(errors) @@ -348,6 +358,6 @@ pub fn compile_no_check( debug, abi, file_map, - noir_version: env!("CARGO_PKG_VERSION").to_string(), + noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(), }) } diff --git a/compiler/noirc_driver/src/program.rs b/compiler/noirc_driver/src/program.rs index 550029655ac..fe991567180 100644 --- a/compiler/noirc_driver/src/program.rs +++ b/compiler/noirc_driver/src/program.rs @@ -12,6 +12,7 @@ use super::debug::DebugFile; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct CompiledProgram { + pub noir_version: String, /// Hash of the [`Program`][noirc_frontend::monomorphization::ast::Program] from which this [`CompiledProgram`] /// was compiled. /// @@ -21,7 +22,6 @@ pub struct CompiledProgram { #[serde(serialize_with = "serialize_circuit", deserialize_with = "deserialize_circuit")] pub circuit: Circuit, pub abi: noirc_abi::Abi, - pub noir_version: String, pub debug: DebugInfo, pub file_map: BTreeMap, } diff --git a/compiler/wasm/build.rs b/compiler/wasm/build.rs index 3b96be74ef3..dc46037a1d9 100644 --- a/compiler/wasm/build.rs +++ b/compiler/wasm/build.rs @@ -1,14 +1,4 @@ -const GIT_COMMIT: &&str = &"GIT_COMMIT"; - fn main() { - // Only use build_data if the environment variable isn't set - // The environment variable is always set when working via Nix - if std::env::var(GIT_COMMIT).is_err() { - build_data::set_GIT_COMMIT(); - build_data::set_GIT_DIRTY(); - build_data::no_debug_rebuilds(); - } - build_data::set_SOURCE_TIMESTAMP(); build_data::no_debug_rebuilds(); } diff --git a/compiler/wasm/src/compile.rs b/compiler/wasm/src/compile.rs index 477117a2c9a..66f08dbabf5 100644 --- a/compiler/wasm/src/compile.rs +++ b/compiler/wasm/src/compile.rs @@ -7,7 +7,7 @@ use nargo::artifacts::{ }; use noirc_driver::{ add_dep, compile_contract, compile_main, prepare_crate, prepare_dependency, CompileOptions, - CompiledContract, CompiledProgram, + CompiledContract, CompiledProgram, NOIR_ARTIFACT_VERSION_STRING, }; use noirc_frontend::{graph::CrateGraph, hir::Context}; use std::path::Path; @@ -17,9 +17,6 @@ use crate::errors::JsCompileError; const BACKEND_IDENTIFIER: &str = "acvm-backend-barretenberg"; -const NOIR_ARTIFACT_VERSION_STRING: &str = - concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); - #[wasm_bindgen] extern "C" { #[wasm_bindgen(extends = Array, js_name = "StringArray", typescript_type = "string[]")] @@ -121,7 +118,7 @@ fn preprocess_program(program: CompiledProgram) -> PreprocessedProgram { hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, - noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), + noir_version: NOIR_ARTIFACT_VERSION_STRING.to_string(), bytecode: program.circuit, } } diff --git a/compiler/wasm/src/lib.rs b/compiler/wasm/src/lib.rs index 3a8e00bc6dd..d9ebeba0999 100644 --- a/compiler/wasm/src/lib.rs +++ b/compiler/wasm/src/lib.rs @@ -7,6 +7,7 @@ use getrandom as _; use gloo_utils::format::JsValueSerdeExt; use log::Level; +use noirc_driver::{GIT_COMMIT, GIT_DIRTY, NOIRC_VERSION}; use serde::{Deserialize, Serialize}; use std::str::FromStr; use wasm_bindgen::prelude::*; @@ -38,9 +39,9 @@ pub fn init_log_level(level: String) { } const BUILD_INFO: BuildInfo = BuildInfo { - git_hash: env!("GIT_COMMIT"), - version: env!("CARGO_PKG_VERSION"), - dirty: env!("GIT_DIRTY"), + git_hash: GIT_COMMIT, + version: NOIRC_VERSION, + dirty: GIT_DIRTY, }; #[wasm_bindgen] diff --git a/tooling/nargo/src/artifacts/program.rs b/tooling/nargo/src/artifacts/program.rs index 26fbef32ae9..5988f3f59cb 100644 --- a/tooling/nargo/src/artifacts/program.rs +++ b/tooling/nargo/src/artifacts/program.rs @@ -9,6 +9,8 @@ use serde::{Deserialize, Serialize}; /// - Proving and verification keys have been pregenerated based on this ACIR. #[derive(Serialize, Deserialize, Debug)] pub struct PreprocessedProgram { + pub noir_version: String, + /// Hash of the [`Program`][noirc_frontend::monomorphization::ast::Program] from which this [`PreprocessedProgram`] /// was compiled. /// @@ -17,7 +19,6 @@ pub struct PreprocessedProgram { pub backend: String, pub abi: Abi, - pub noir_version: String, #[serde( serialize_with = "super::serialize_circuit", diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index ec3f98f67bf..5d5d2ac86c9 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -13,6 +13,7 @@ use nargo::package::Package; use nargo::prepare_package; use nargo::workspace::Workspace; use nargo_toml::{get_package_manifest, resolve_workspace_from_toml, PackageSelection}; +use noirc_driver::NOIR_ARTIFACT_VERSION_STRING; use noirc_driver::{CompilationResult, CompileOptions, CompiledContract, CompiledProgram}; use noirc_frontend::graph::CrateName; @@ -26,7 +27,6 @@ use super::fs::program::{ save_debug_artifact_to_file, save_program_to_file, }; use super::NargoConfig; -use super::NOIR_ARTIFACT_VERSION_STRING; use rayon::prelude::*; // TODO(#1388): pull this from backend. @@ -246,7 +246,7 @@ fn save_program(program: CompiledProgram, package: &Package, circuit_dir: &Path) hash: program.hash, backend: String::from(BACKEND_IDENTIFIER), abi: program.abi, - noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), + noir_version: program.noir_version, bytecode: program.circuit, }; @@ -277,7 +277,7 @@ fn save_contract(contract: CompiledContract, package: &Package, circuit_dir: &Pa }); let preprocessed_contract = PreprocessedContract { - noir_version: String::from(NOIR_ARTIFACT_VERSION_STRING), + noir_version: contract.noir_version, name: contract.name, backend: String::from(BACKEND_IDENTIFIER), functions: preprocessed_functions, diff --git a/tooling/nargo_cli/src/cli/init_cmd.rs b/tooling/nargo_cli/src/cli/init_cmd.rs index 6dc7b9bd98e..ae8d5f8e5f4 100644 --- a/tooling/nargo_cli/src/cli/init_cmd.rs +++ b/tooling/nargo_cli/src/cli/init_cmd.rs @@ -2,7 +2,8 @@ use crate::backends::Backend; use crate::errors::CliError; use super::fs::{create_named_dir, write_to_file}; -use super::{NargoConfig, CARGO_PKG_VERSION}; +use super::NargoConfig; +use noirc_driver::NOIRC_VERSION; use clap::Args; use nargo::constants::{PKG_FILE, SRC_DIR}; use nargo::package::PackageType; @@ -72,7 +73,7 @@ pub(crate) fn initialize_project( name = "{package_name}" type = "{package_type}" authors = [""] -compiler_version = "{CARGO_PKG_VERSION}" +compiler_version = "{NOIRC_VERSION}" [dependencies]"# ); diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index 7a5a3d0752e..985084d16c1 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -2,6 +2,7 @@ use clap::{Args, Parser, Subcommand}; use const_format::formatcp; use nargo_toml::find_package_root; use std::path::PathBuf; +use noirc_driver::NOIR_ARTIFACT_VERSION_STRING; use color_eyre::eyre; @@ -26,14 +27,10 @@ mod verify_cmd; const GIT_HASH: &str = env!("GIT_COMMIT"); const IS_DIRTY: &str = env!("GIT_DIRTY"); -const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); - -/// Version string that gets placed in artifacts that Noir builds -pub(crate) const NOIR_ARTIFACT_VERSION_STRING: &str = - concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); +const NARGO_VERSION: &str = env!("CARGO_PKG_VERSION"); static VERSION_STRING: &str = - formatcp!("{} (git version hash: {}, is dirty: {})", CARGO_PKG_VERSION, GIT_HASH, IS_DIRTY); + formatcp!("nargo version = {}, noirc version = {} (git version hash: {}, is dirty: {})", NARGO_VERSION, NOIR_ARTIFACT_VERSION_STRING, GIT_HASH, IS_DIRTY); #[derive(Parser, Debug)] #[command(name="nargo", author, version=VERSION_STRING, about, long_about = None)] From dc40dc61d2db6af191998d34f6441ee4d20cbebc Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 23 Oct 2023 20:00:48 +0000 Subject: [PATCH 13/17] cargo fmt --- compiler/noirc_driver/build.rs | 2 +- compiler/noirc_driver/src/lib.rs | 8 ++++---- compiler/wasm/src/lib.rs | 7 ++----- tooling/nargo_cli/src/cli/init_cmd.rs | 2 +- tooling/nargo_cli/src/cli/mod.rs | 11 ++++++++--- 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/compiler/noirc_driver/build.rs b/compiler/noirc_driver/build.rs index bb864aefffc..7b5a645c026 100644 --- a/compiler/noirc_driver/build.rs +++ b/compiler/noirc_driver/build.rs @@ -11,4 +11,4 @@ fn main() { build_data::set_GIT_DIRTY(); build_data::no_debug_rebuilds(); } -} \ No newline at end of file +} diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 566603e8f11..58a97472625 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -28,14 +28,14 @@ pub use program::CompiledProgram; const STD_CRATE_NAME: &str = "std"; -pub const GIT_COMMIT : &str = env!("GIT_COMMIT"); -pub const GIT_DIRTY : &str = env!("GIT_DIRTY"); -pub const NOIRC_VERSION : &str = env!("CARGO_PKG_VERSION"); +pub const GIT_COMMIT: &str = env!("GIT_COMMIT"); +pub const GIT_DIRTY: &str = env!("GIT_DIRTY"); +pub const NOIRC_VERSION: &str = env!("CARGO_PKG_VERSION"); /// Version string that gets placed in artifacts that Noir builds. /// Note: You can't directly use the value of a constant produced with env! inside a concat! macro. pub const NOIR_ARTIFACT_VERSION_STRING: &str = -concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); + concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); #[derive(Args, Clone, Debug, Default, Serialize, Deserialize)] pub struct CompileOptions { diff --git a/compiler/wasm/src/lib.rs b/compiler/wasm/src/lib.rs index d9ebeba0999..9f2f558f85c 100644 --- a/compiler/wasm/src/lib.rs +++ b/compiler/wasm/src/lib.rs @@ -38,11 +38,8 @@ pub fn init_log_level(level: String) { }); } -const BUILD_INFO: BuildInfo = BuildInfo { - git_hash: GIT_COMMIT, - version: NOIRC_VERSION, - dirty: GIT_DIRTY, -}; +const BUILD_INFO: BuildInfo = + BuildInfo { git_hash: GIT_COMMIT, version: NOIRC_VERSION, dirty: GIT_DIRTY }; #[wasm_bindgen] pub fn build_info() -> JsValue { diff --git a/tooling/nargo_cli/src/cli/init_cmd.rs b/tooling/nargo_cli/src/cli/init_cmd.rs index ae8d5f8e5f4..9d7700a6598 100644 --- a/tooling/nargo_cli/src/cli/init_cmd.rs +++ b/tooling/nargo_cli/src/cli/init_cmd.rs @@ -3,10 +3,10 @@ use crate::errors::CliError; use super::fs::{create_named_dir, write_to_file}; use super::NargoConfig; -use noirc_driver::NOIRC_VERSION; use clap::Args; use nargo::constants::{PKG_FILE, SRC_DIR}; use nargo::package::PackageType; +use noirc_driver::NOIRC_VERSION; use noirc_frontend::graph::CrateName; use std::path::PathBuf; diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index 985084d16c1..63abe9c223b 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -1,8 +1,8 @@ use clap::{Args, Parser, Subcommand}; use const_format::formatcp; use nargo_toml::find_package_root; -use std::path::PathBuf; use noirc_driver::NOIR_ARTIFACT_VERSION_STRING; +use std::path::PathBuf; use color_eyre::eyre; @@ -29,8 +29,13 @@ const GIT_HASH: &str = env!("GIT_COMMIT"); const IS_DIRTY: &str = env!("GIT_DIRTY"); const NARGO_VERSION: &str = env!("CARGO_PKG_VERSION"); -static VERSION_STRING: &str = - formatcp!("nargo version = {}, noirc version = {} (git version hash: {}, is dirty: {})", NARGO_VERSION, NOIR_ARTIFACT_VERSION_STRING, GIT_HASH, IS_DIRTY); +static VERSION_STRING: &str = formatcp!( + "nargo version = {}, noirc version = {} (git version hash: {}, is dirty: {})", + NARGO_VERSION, + NOIR_ARTIFACT_VERSION_STRING, + GIT_HASH, + IS_DIRTY +); #[derive(Parser, Debug)] #[command(name="nargo", author, version=VERSION_STRING, about, long_about = None)] From 561036f4b29ad9458559bf7dd6a6fa54ae7f3431 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 23 Oct 2023 20:13:47 +0000 Subject: [PATCH 14/17] modify versioning format --- tooling/nargo_cli/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tooling/nargo_cli/src/cli/mod.rs b/tooling/nargo_cli/src/cli/mod.rs index 63abe9c223b..8d22fb1b204 100644 --- a/tooling/nargo_cli/src/cli/mod.rs +++ b/tooling/nargo_cli/src/cli/mod.rs @@ -30,7 +30,7 @@ const IS_DIRTY: &str = env!("GIT_DIRTY"); const NARGO_VERSION: &str = env!("CARGO_PKG_VERSION"); static VERSION_STRING: &str = formatcp!( - "nargo version = {}, noirc version = {} (git version hash: {}, is dirty: {})", + "version = {}\nnoirc version = {}\n(git version hash: {}, is dirty: {})", NARGO_VERSION, NOIR_ARTIFACT_VERSION_STRING, GIT_HASH, From 661c0e36f9eb311ecbcfb088af8824eab7410766 Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 23 Oct 2023 20:13:54 +0000 Subject: [PATCH 15/17] change regex in test --- release-tests/test/version.test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release-tests/test/version.test.js b/release-tests/test/version.test.js index 07051d1edce..7a70639d83e 100644 --- a/release-tests/test/version.test.js +++ b/release-tests/test/version.test.js @@ -21,9 +21,12 @@ test("promise resolved", async () => { test("prints version", async () => { const processOutput = (await $`${NARGO_BIN} --version`).toString(); - assert.match(processOutput, /nargo\s\d{1,2}.\d{1,2}/); + + // Regex to match the "nargo version" part of the output + assert.match(processOutput, /nargo version = \d{1,2}\.\d{1,2}\.\d{1,2}/); }); + test("reports a clean commit", async () => { const processOutput = (await $`${NARGO_BIN} --version`).toString(); assert.not.match(processOutput, /is dirty: true/) From 8a527863c27c285e6698307c2bf8a7f12ec9104f Mon Sep 17 00:00:00 2001 From: kevaundray Date: Mon, 23 Oct 2023 21:15:17 +0000 Subject: [PATCH 16/17] remove outdated comment --- tooling/nargo_cli/src/cli/compile_cmd.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/tooling/nargo_cli/src/cli/compile_cmd.rs b/tooling/nargo_cli/src/cli/compile_cmd.rs index 5d5d2ac86c9..56f91843914 100644 --- a/tooling/nargo_cli/src/cli/compile_cmd.rs +++ b/tooling/nargo_cli/src/cli/compile_cmd.rs @@ -192,7 +192,6 @@ fn compile_program( None }; - // If we want to output the debug information then we need to perform a full recompilation of the ACIR. 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( From 1f2827ccfb53f5ad06140783eb4547250157f5ce Mon Sep 17 00:00:00 2001 From: kevaundray Date: Tue, 24 Oct 2023 00:54:23 +0100 Subject: [PATCH 17/17] Update compiler/noirc_driver/src/lib.rs --- compiler/noirc_driver/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/noirc_driver/src/lib.rs b/compiler/noirc_driver/src/lib.rs index 58a97472625..f8908efc596 100644 --- a/compiler/noirc_driver/src/lib.rs +++ b/compiler/noirc_driver/src/lib.rs @@ -32,10 +32,10 @@ pub const GIT_COMMIT: &str = env!("GIT_COMMIT"); pub const GIT_DIRTY: &str = env!("GIT_DIRTY"); pub const NOIRC_VERSION: &str = env!("CARGO_PKG_VERSION"); -/// Version string that gets placed in artifacts that Noir builds. +/// Version string that gets placed in artifacts that Noir builds. This is semver compatible. /// Note: You can't directly use the value of a constant produced with env! inside a concat! macro. pub const NOIR_ARTIFACT_VERSION_STRING: &str = - concat!(env!("CARGO_PKG_VERSION"), "-", env!("GIT_COMMIT")); + concat!(env!("CARGO_PKG_VERSION"), "+", env!("GIT_COMMIT")); #[derive(Args, Clone, Debug, Default, Serialize, Deserialize)] pub struct CompileOptions {