From 1ad9199bcfbc5dd52166038a25ddfc7b03d90981 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 11 Aug 2023 09:38:39 -0700 Subject: [PATCH 01/14] feat(nargo): Add `--exact` flag to `nargo test` (#2272) * feat(nargo): Add `--exact` flag to `nargo test` * fix(lsp): Make test command work in context of workspaces * reviews --- crates/lsp/src/lib.rs | 11 ++++-- crates/nargo_cli/src/cli/test_cmd.rs | 27 ++++++++++++--- crates/noirc_frontend/src/hir/mod.rs | 52 ++++++++++++++++++++-------- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index b0b0871ad3f..83e196a183b 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -22,6 +22,7 @@ use nargo::prepare_package; use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; use noirc_driver::check_crate; use noirc_errors::{DiagnosticKind, FileDiagnostic}; +use noirc_frontend::hir::FunctionNameMatch; use serde_json::Value as JsonValue; use tower::Service; @@ -176,7 +177,8 @@ fn on_code_lens_request( let fm = &context.file_manager; let files = fm.as_simple_files(); - let tests = context.get_all_test_functions_in_crate_matching(&crate_id, ""); + let tests = context + .get_all_test_functions_in_crate_matching(&crate_id, FunctionNameMatch::Anything); for (func_name, func_id) in tests { let location = context.function_meta(&func_id).name.location; @@ -196,7 +198,12 @@ fn on_code_lens_request( let command = Command { title: TEST_CODELENS_TITLE.into(), command: TEST_COMMAND.into(), - arguments: Some(vec![func_name.into()]), + arguments: Some(vec![ + "--package".into(), + format!("{}", package.name).into(), + "--exact".into(), + func_name.into(), + ]), }; let lens = CodeLens { range, command: command.into(), data: None }; diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index ecbee5b4668..95d7f907196 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -5,7 +5,11 @@ use clap::Args; use nargo::{ops::execute_circuit, package::Package, prepare_package}; use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; use noirc_driver::{compile_no_check, CompileOptions}; -use noirc_frontend::{graph::CrateName, hir::Context, node_interner::FuncId}; +use noirc_frontend::{ + graph::CrateName, + hir::{Context, FunctionNameMatch}, + node_interner::FuncId, +}; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use crate::{cli::check_cmd::check_crate_and_report_errors, errors::CliError}; @@ -22,6 +26,10 @@ pub(crate) struct TestCommand { #[arg(long)] show_output: bool, + /// Only run tests that match exactly + #[clap(long)] + exact: bool, + /// The name of the package to test #[clap(long)] package: Option, @@ -35,13 +43,22 @@ pub(crate) fn run( args: TestCommand, config: NargoConfig, ) -> Result<(), CliError> { - let test_name: String = args.test_name.unwrap_or_else(|| "".to_owned()); - let toml_path = find_package_manifest(&config.program_dir)?; let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let pattern = match &args.test_name { + Some(name) => { + if args.exact { + FunctionNameMatch::Exact(name) + } else { + FunctionNameMatch::Contains(name) + } + } + None => FunctionNameMatch::Anything, + }; + for package in &workspace { - run_tests(backend, package, &test_name, args.show_output, &args.compile_options)?; + run_tests(backend, package, pattern, args.show_output, &args.compile_options)?; } Ok(()) @@ -50,7 +67,7 @@ pub(crate) fn run( fn run_tests( backend: &B, package: &Package, - test_name: &str, + test_name: FunctionNameMatch, show_output: bool, compile_options: &CompileOptions, ) -> Result<(), CliError> { diff --git a/crates/noirc_frontend/src/hir/mod.rs b/crates/noirc_frontend/src/hir/mod.rs index 91a6006d096..497935c8ece 100644 --- a/crates/noirc_frontend/src/hir/mod.rs +++ b/crates/noirc_frontend/src/hir/mod.rs @@ -25,6 +25,13 @@ pub struct Context { pub storage_slots: HashMap, } +#[derive(Debug, Copy, Clone)] +pub enum FunctionNameMatch<'a> { + Anything, + Exact(&'a str), + Contains(&'a str), +} + pub type StorageSlot = u32; impl Context { @@ -52,10 +59,29 @@ impl Context { self.crate_graph.iter_keys() } + // TODO: Decide if we actually need `function_name` and `fully_qualified_function_name` pub fn function_name(&self, id: &FuncId) -> &str { self.def_interner.function_name(id) } + pub fn fully_qualified_function_name(&self, crate_id: &CrateId, id: &FuncId) -> String { + let def_map = self.def_map(crate_id).expect("The local crate should be analyzed already"); + + let name = self.def_interner.function_name(id); + + let meta = self.def_interner.function_meta(id); + let module = self.module(meta.module_id); + + let parent = + def_map.get_module_path_with_separator(meta.module_id.local_id.0, module.parent, "::"); + + if parent.is_empty() { + name.into() + } else { + format!("{parent}::{name}") + } + } + pub fn function_meta(&self, func_id: &FuncId) -> FuncMeta { self.def_interner.function_meta(func_id) } @@ -76,7 +102,7 @@ impl Context { pub fn get_all_test_functions_in_crate_matching( &self, crate_id: &CrateId, - pattern: &str, + pattern: FunctionNameMatch, ) -> Vec<(String, FuncId)> { let interner = &self.def_interner; let def_map = self.def_map(crate_id).expect("The local crate should be analyzed already"); @@ -84,20 +110,16 @@ impl Context { def_map .get_all_test_functions(interner) .filter_map(|id| { - let name = interner.function_name(&id); - - let meta = interner.function_meta(&id); - let module = self.module(meta.module_id); - - let parent = def_map.get_module_path_with_separator( - meta.module_id.local_id.0, - module.parent, - "::", - ); - let path = - if parent.is_empty() { name.into() } else { format!("{parent}::{name}") }; - - path.contains(pattern).then_some((path, id)) + let fully_qualified_name = self.fully_qualified_function_name(crate_id, &id); + match &pattern { + FunctionNameMatch::Anything => Some((fully_qualified_name, id)), + FunctionNameMatch::Exact(pattern) => { + (&fully_qualified_name == pattern).then_some((fully_qualified_name, id)) + } + FunctionNameMatch::Contains(pattern) => { + fully_qualified_name.contains(pattern).then_some((fully_qualified_name, id)) + } + } }) .collect() } From 9824ca567c6c151c0cc5469be402ffba2cbaa9cc Mon Sep 17 00:00:00 2001 From: Santiago Palladino Date: Fri, 11 Aug 2023 13:44:02 -0300 Subject: [PATCH 02/14] feat: Include struct names in ABIs (#2266) * feat: Include struct names in ABIs * Update crates/nargo_cli/src/cli/check_cmd.rs Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> * Fix spelling --------- Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- crates/nargo_cli/src/cli/check_cmd.rs | 3 ++- crates/noirc_abi/src/input_parser/json.rs | 4 ++-- crates/noirc_abi/src/input_parser/mod.rs | 1 + crates/noirc_abi/src/input_parser/toml.rs | 4 ++-- crates/noirc_abi/src/lib.rs | 3 ++- crates/noirc_abi/src/serialization.rs | 2 ++ crates/noirc_frontend/src/hir_def/types.rs | 2 +- 7 files changed, 12 insertions(+), 7 deletions(-) diff --git a/crates/nargo_cli/src/cli/check_cmd.rs b/crates/nargo_cli/src/cli/check_cmd.rs index 432e0b9599c..a1b5018d334 100644 --- a/crates/nargo_cli/src/cli/check_cmd.rs +++ b/crates/nargo_cli/src/cli/check_cmd.rs @@ -88,7 +88,7 @@ fn create_input_toml_template( .collect(); toml::Value::Array(default_value_vec) } - AbiType::Struct { fields } => { + AbiType::Struct { fields, .. } => { let default_value_map = toml::map::Map::from_iter( fields.into_iter().map(|(name, typ)| (name, default_value(typ))), ); @@ -128,6 +128,7 @@ mod tests { typed_param( "d", AbiType::Struct { + name: String::from("MyStruct"), fields: vec![ (String::from("d1"), AbiType::Field), ( diff --git a/crates/noirc_abi/src/input_parser/json.rs b/crates/noirc_abi/src/input_parser/json.rs index 6468b48c857..c8a421c8353 100644 --- a/crates/noirc_abi/src/input_parser/json.rs +++ b/crates/noirc_abi/src/input_parser/json.rs @@ -96,7 +96,7 @@ impl JsonTypes { (InputValue::String(s), AbiType::String { .. }) => JsonTypes::String(s.to_string()), - (InputValue::Struct(map), AbiType::Struct { fields }) => { + (InputValue::Struct(map), AbiType::Struct { fields, .. }) => { let map_with_json_types = try_btree_map(fields, |(key, field_type)| { JsonTypes::try_from_input_value(&map[key], field_type) .map(|json_value| (key.to_owned(), json_value)) @@ -155,7 +155,7 @@ impl InputValue { InputValue::Vec(array_elements) } - (JsonTypes::Table(table), AbiType::Struct { fields }) => { + (JsonTypes::Table(table), AbiType::Struct { fields, .. }) => { let native_table = try_btree_map(fields, |(field_name, abi_type)| { // Check that json contains a value for each field of the struct. let field_id = format!("{arg_name}.{field_name}"); diff --git a/crates/noirc_abi/src/input_parser/mod.rs b/crates/noirc_abi/src/input_parser/mod.rs index e4adbb3d8cf..3a317697534 100644 --- a/crates/noirc_abi/src/input_parser/mod.rs +++ b/crates/noirc_abi/src/input_parser/mod.rs @@ -162,6 +162,7 @@ mod serialization_tests { AbiParameter { name: "bar".into(), typ: AbiType::Struct { + name: "MyStruct".into(), fields: vec![ ("field1".into(), AbiType::Integer { sign: Sign::Unsigned, width: 8 }), ( diff --git a/crates/noirc_abi/src/input_parser/toml.rs b/crates/noirc_abi/src/input_parser/toml.rs index d96496410d9..3f7ec30e355 100644 --- a/crates/noirc_abi/src/input_parser/toml.rs +++ b/crates/noirc_abi/src/input_parser/toml.rs @@ -94,7 +94,7 @@ impl TomlTypes { (InputValue::String(s), AbiType::String { .. }) => TomlTypes::String(s.to_string()), - (InputValue::Struct(map), AbiType::Struct { fields }) => { + (InputValue::Struct(map), AbiType::Struct { fields, .. }) => { let map_with_toml_types = try_btree_map(fields, |(key, field_type)| { TomlTypes::try_from_input_value(&map[key], field_type) .map(|toml_value| (key.to_owned(), toml_value)) @@ -138,7 +138,7 @@ impl InputValue { InputValue::Vec(array_elements) } - (TomlTypes::Table(table), AbiType::Struct { fields }) => { + (TomlTypes::Table(table), AbiType::Struct { fields, .. }) => { let native_table = try_btree_map(fields, |(field_name, abi_type)| { // Check that json contains a value for each field of the struct. let field_id = format!("{arg_name}.{field_name}"); diff --git a/crates/noirc_abi/src/lib.rs b/crates/noirc_abi/src/lib.rs index 5f8c22a6652..4c394fb9ff0 100644 --- a/crates/noirc_abi/src/lib.rs +++ b/crates/noirc_abi/src/lib.rs @@ -55,6 +55,7 @@ pub enum AbiType { }, Boolean, Struct { + name: String, #[serde( serialize_with = "serialization::serialize_struct_fields", deserialize_with = "serialization::deserialize_struct_fields" @@ -308,7 +309,7 @@ impl Abi { encoded_value.extend(str_as_fields); } - (InputValue::Struct(object), AbiType::Struct { fields }) => { + (InputValue::Struct(object), AbiType::Struct { fields, .. }) => { for (field, typ) in fields { encoded_value.extend(Self::encode_value(object[field].clone(), typ)?); } diff --git a/crates/noirc_abi/src/serialization.rs b/crates/noirc_abi/src/serialization.rs index 3fdf5507383..7d32874bb7e 100644 --- a/crates/noirc_abi/src/serialization.rs +++ b/crates/noirc_abi/src/serialization.rs @@ -92,6 +92,7 @@ mod tests { \"name\":\"thing3\", \"type\": { \"kind\":\"struct\", + \"name\": \"MyStruct\", \"fields\": [ { \"name\": \"field1\", @@ -119,6 +120,7 @@ mod tests { let expected_struct = AbiParameter { name: "thing3".to_string(), typ: AbiType::Struct { + name: "MyStruct".to_string(), fields: vec![ ("field1".to_string(), AbiType::Integer { sign: Sign::Unsigned, width: 3 }), ( diff --git a/crates/noirc_frontend/src/hir_def/types.rs b/crates/noirc_frontend/src/hir_def/types.rs index d938421cb0e..fea3c31bf98 100644 --- a/crates/noirc_frontend/src/hir_def/types.rs +++ b/crates/noirc_frontend/src/hir_def/types.rs @@ -986,7 +986,7 @@ impl Type { let struct_type = def.borrow(); let fields = struct_type.get_fields(args); let fields = vecmap(fields, |(name, typ)| (name, typ.as_abi_type())); - AbiType::Struct { fields } + AbiType::Struct { fields, name: struct_type.name.to_string() } } Type::Tuple(_) => todo!("as_abi_type not yet implemented for tuple types"), Type::TypeVariable(_, _) => unreachable!(), From c8fe6175fa69abdfa29d7a9e1c5c653af5f15f1d Mon Sep 17 00:00:00 2001 From: Ethan-000 Date: Fri, 11 Aug 2023 18:18:52 +0100 Subject: [PATCH 03/14] feat: Add basic benchmarking (#2213) * bench * . * . * . * . * . * . * . * . * . * . * . * . * . * . * / * remove prove * . * . * . * . --- Cargo.lock | 326 ++++++++++++++++++++++++++ crates/nargo_cli/Cargo.toml | 17 +- crates/nargo_cli/benches/criterion.rs | 33 +++ crates/nargo_cli/benches/iai.rs | 25 ++ crates/nargo_cli/benches/utils.rs | 14 ++ cspell.json | 3 + 6 files changed, 417 insertions(+), 1 deletion(-) create mode 100644 crates/nargo_cli/benches/criterion.rs create mode 100644 crates/nargo_cli/benches/iai.rs create mode 100644 crates/nargo_cli/benches/utils.rs diff --git a/Cargo.lock b/Cargo.lock index 7535d132a96..d9e30e08156 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c99f64d1e06488f620f932677e24bc6e2897582980441ae90a671415bd7ec2f" dependencies = [ "cfg-if", + "getrandom", "once_cell", "version_check", ] @@ -152,6 +153,12 @@ dependencies = [ "libc", ] +[[package]] +name = "anes" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" + [[package]] name = "anstream" version = "0.3.2" @@ -325,6 +332,12 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "assert_cmd" version = "2.0.12" @@ -593,6 +606,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "bytemuck" +version = "1.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" + [[package]] name = "bytes" version = "1.4.0" @@ -605,6 +624,12 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5" +[[package]] +name = "cast" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" + [[package]] name = "cc" version = "1.0.79" @@ -650,6 +675,33 @@ dependencies = [ "stacker", ] +[[package]] +name = "ciborium" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "effd91f6c78e5a4ace8a5d3c0b6bfaec9e2baaef55f3efc00e45fb2e477ee926" +dependencies = [ + "ciborium-io", + "ciborium-ll", + "serde", +] + +[[package]] +name = "ciborium-io" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdf919175532b369853f5d5e20b26b43112613fd6fe7aee757e35f7a44642656" + +[[package]] +name = "ciborium-ll" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "defaa24ecc093c77630e6c15e17c51f5e187bf35ee514f4e2d67baaa96dae22b" +dependencies = [ + "ciborium-io", + "half", +] + [[package]] name = "clang-sys" version = "1.6.1" @@ -822,6 +874,15 @@ dependencies = [ "windows-sys 0.33.0", ] +[[package]] +name = "cpp_demangle" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee34052ee3d93d6d8f3e6f81d85c47921f6653a19a7b70e939e3e602d893a674" +dependencies = [ + "cfg-if", +] + [[package]] name = "cpufeatures" version = "0.2.9" @@ -899,6 +960,42 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "criterion" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" +dependencies = [ + "anes", + "cast", + "ciborium", + "clap", + "criterion-plot", + "is-terminal", + "itertools", + "num-traits", + "once_cell", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_derive", + "serde_json", + "tinytemplate", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-channel" version = "0.5.8" @@ -998,6 +1095,15 @@ dependencies = [ "syn 2.0.26", ] +[[package]] +name = "debugid" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef552e6f588e446098f6ba40d89ac146c8c7b64aade83c051ee00bb5d2bc18d" +dependencies = [ + "uuid", +] + [[package]] name = "der" version = "0.6.1" @@ -1212,6 +1318,18 @@ dependencies = [ "subtle", ] +[[package]] +name = "findshlibs" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40b9e59cd0f7e0806cca4be089683ecb6434e602038df21fe6bf6711b2f07f64" +dependencies = [ + "cc", + "lazy_static", + "libc", + "winapi", +] + [[package]] name = "flate2" version = "1.0.26" @@ -1470,6 +1588,12 @@ dependencies = [ "tracing", ] +[[package]] +name = "half" +version = "1.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" + [[package]] name = "hashbrown" version = "0.11.2" @@ -1602,6 +1726,12 @@ dependencies = [ "tokio-rustls", ] +[[package]] +name = "iai" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71a816c97c42258aa5834d07590b718b4c9a598944cd39a52dc25b351185d678" + [[package]] name = "iana-time-zone" version = "0.1.57" @@ -1699,6 +1829,24 @@ dependencies = [ "hashbrown 0.14.0", ] +[[package]] +name = "inferno" +version = "0.11.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fb7c1b80a1dfa604bb4a649a5c5aeef3d913f7c520cb42b40e534e8a61bcdfc" +dependencies = [ + "ahash 0.8.3", + "indexmap 1.9.3", + "is-terminal", + "itoa", + "log", + "num-format", + "once_cell", + "quick-xml", + "rgb", + "str_stack", +] + [[package]] name = "instant" version = "0.1.12" @@ -1840,6 +1988,16 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.19" @@ -2005,9 +2163,11 @@ dependencies = [ "clap", "color-eyre", "const_format", + "criterion", "dirs", "fm", "hex", + "iai", "iter-extended", "nargo", "nargo_toml", @@ -2016,6 +2176,8 @@ dependencies = [ "noirc_driver", "noirc_errors", "noirc_frontend", + "paste", + "pprof", "predicates 2.1.5", "rustc_version", "serde", @@ -2043,6 +2205,18 @@ dependencies = [ "url", ] +[[package]] +name = "nix" +version = "0.26.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfdda3d196821d6af13126e40375cdf7da646a96114af134d5f417a9a1dc8e1a" +dependencies = [ + "bitflags 1.3.2", + "cfg-if", + "libc", + "static_assertions", +] + [[package]] name = "noir_lsp" version = "0.9.0" @@ -2185,6 +2359,16 @@ dependencies = [ "num-traits", ] +[[package]] +name = "num-format" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" +dependencies = [ + "arrayvec", + "itoa", +] + [[package]] name = "num-integer" version = "0.1.45" @@ -2241,6 +2425,12 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "owo-colors" version = "3.5.0" @@ -2258,6 +2448,29 @@ dependencies = [ "sha2", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets", +] + [[package]] name = "paste" version = "1.0.14" @@ -2304,6 +2517,56 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" +[[package]] +name = "plotters" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2c224ba00d7cadd4d5c660deaf2098e5e80e07846537c51f9cfa4be50c1fd45" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e76628b4d3a7581389a35d5b6e2139607ad7c75b17aed325f210aa91f4a9609" + +[[package]] +name = "plotters-svg" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38f6d39893cca0701371e3c27294f09797214b86f1fb951b89ade8ec04e2abab" +dependencies = [ + "plotters-backend", +] + +[[package]] +name = "pprof" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978385d59daf9269189d052ca8a84c1acfd0715c0599a5d5188d4acc078ca46a" +dependencies = [ + "backtrace", + "cfg-if", + "criterion", + "findshlibs", + "inferno", + "libc", + "log", + "nix", + "once_cell", + "parking_lot", + "smallvec", + "symbolic-demangle", + "tempfile", + "thiserror", +] + [[package]] name = "ppv-lite86" version = "0.2.17" @@ -2414,6 +2677,15 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "quick-xml" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" +dependencies = [ + "memchr", +] + [[package]] name = "quote" version = "1.0.31" @@ -2675,6 +2947,15 @@ dependencies = [ "zeroize", ] +[[package]] +name = "rgb" +version = "0.8.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20ec2d3e3fc7a92ced357df9cebd5a10b6fb2aa1ee797bf7e9ce2f17dffc8f59" +dependencies = [ + "bytemuck", +] + [[package]] name = "ring" version = "0.16.20" @@ -3179,6 +3460,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "str_stack" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" + [[package]] name = "strsim" version = "0.10.0" @@ -3210,6 +3503,29 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" +[[package]] +name = "symbolic-common" +version = "12.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167a4ffd7c35c143fd1030aa3c2caf76ba42220bd5a6b5f4781896434723b8c3" +dependencies = [ + "debugid", + "memmap2", + "stable_deref_trait", + "uuid", +] + +[[package]] +name = "symbolic-demangle" +version = "12.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e378c50e80686c1c5c205674e1f86a2858bec3d2a7dfdd690331a8a19330f293" +dependencies = [ + "cpp_demangle", + "rustc-demangle", + "symbolic-common", +] + [[package]] name = "syn" version = "1.0.109" @@ -3324,6 +3640,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.6.0" diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index fd052e9dc95..96d218d1593 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -56,10 +56,25 @@ assert_cmd = "2.0.8" assert_fs = "1.0.10" predicates = "2.1.5" fm.workspace = true +criterion = "0.5.0" +paste = "1.0.14" +pprof = { version = "0.12", features = [ + "flamegraph", + "frame-pointer", + "criterion", +] } +iai = "0.1.1" + +[[bench]] +name = "criterion" +harness = false + +[[bench]] +name = "iai" +harness = false [features] default = ["plonk_bn254"] # The plonk backend can only use bn254, so we do not specify the field plonk_bn254 = ["acvm-backend-barretenberg/native"] plonk_bn254_wasm = ["acvm-backend-barretenberg/wasm"] - diff --git a/crates/nargo_cli/benches/criterion.rs b/crates/nargo_cli/benches/criterion.rs new file mode 100644 index 00000000000..a7b094fd7aa --- /dev/null +++ b/crates/nargo_cli/benches/criterion.rs @@ -0,0 +1,33 @@ +//! Select representative tests to bench with criterion +use assert_cmd::prelude::{CommandCargoExt, OutputAssertExt}; +use criterion::{criterion_group, criterion_main, Criterion}; +use paste::paste; +use pprof::criterion::{Output, PProfProfiler}; +use std::process::Command; +include!("./utils.rs"); + +macro_rules! criterion_command { + ($command_name:tt, $command_string:expr) => { + paste! { + fn [](c: &mut Criterion) { + let test_program_dirs = get_selected_tests(); + for test_program_dir in test_program_dirs { + let mut cmd = Command::cargo_bin("nargo").unwrap(); + cmd.arg("--program-dir").arg(&test_program_dir); + cmd.arg($command_string); + + c.bench_function(&format!("{}_{}", test_program_dir.file_name().unwrap().to_str().unwrap(), $command_string), |b| { + b.iter(|| cmd.assert()) + }); + } + } + } + }; +} +criterion_command!(execution, "execute"); +criterion_group! { + name = benches; + config = Criterion::default().sample_size(20).with_profiler(PProfProfiler::new(100, Output::Flamegraph(None))); + targets = criterion_selected_tests_execution +} +criterion_main!(benches); diff --git a/crates/nargo_cli/benches/iai.rs b/crates/nargo_cli/benches/iai.rs new file mode 100644 index 00000000000..bcd60111ccf --- /dev/null +++ b/crates/nargo_cli/benches/iai.rs @@ -0,0 +1,25 @@ +//! Select representative tests to bench with iai +use assert_cmd::prelude::{CommandCargoExt, OutputAssertExt}; +use iai::black_box; +use paste::paste; +use std::process::Command; +include!("./utils.rs"); + +macro_rules! iai_command { + ($command_name:tt, $command_string:expr) => { + paste! { + fn []() { + let test_program_dirs = get_selected_tests(); + for test_program_dir in test_program_dirs { + let mut cmd = Command::cargo_bin("nargo").unwrap(); + cmd.arg("--program-dir").arg(&test_program_dir); + cmd.arg($command_string); + + black_box(cmd.assert()); + } + } + } + }; +} +iai_command!(execution, "execute"); +iai::main!(iai_selected_tests_execution); diff --git a/crates/nargo_cli/benches/utils.rs b/crates/nargo_cli/benches/utils.rs new file mode 100644 index 00000000000..52a6b718c44 --- /dev/null +++ b/crates/nargo_cli/benches/utils.rs @@ -0,0 +1,14 @@ +use std::path::PathBuf; + +#[allow(unused)] +fn get_selected_tests() -> Vec { + let manifest_dir = match std::env::var("CARGO_MANIFEST_DIR") { + Ok(dir) => PathBuf::from(dir), + Err(_) => std::env::current_dir().unwrap().join("crates").join("nargo_cli"), + }; + let test_dir = manifest_dir.join("tests").join("execution_success"); + + let selected_tests = + vec!["8_integration", "sha256_blocks", "struct", "eddsa", "regression", "regression_2099"]; + selected_tests.into_iter().map(|t| test_dir.join(t)).collect() +} diff --git a/cspell.json b/cspell.json index 8da1d65fb56..5629742faee 100644 --- a/cspell.json +++ b/cspell.json @@ -21,7 +21,9 @@ "defunctionalized", "defunctionalization", "desugared", + "eddsa", "endianness", + "Flamegraph", "forall", "foralls", "Guillaume", @@ -49,6 +51,7 @@ "nand", "pedersen", "peekable", + "pprof", "preprocess", "pseudocode", "schnorr", From 79af8e6fd359723716395913b23057beddcbdb83 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Fri, 11 Aug 2023 18:19:35 +0100 Subject: [PATCH 04/14] feat: Execute brillig opcodes with constant inputs at compile-time (#2190) * feat: execute brillig opcodes with constant inputs at compile-time * chore: use iterator to read from memory * chore: remove copy when reading from memory * chore: update artifacts * chore: update artifacts * chore: remove unnecessary Prover.tomls * Update crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs --- .../brillig_cast/Nargo.toml | 0 .../brillig_cast/src/main.nr | 0 .../brillig_to_bits/Nargo.toml | 0 .../brillig_to_bits/src/main.nr | 0 .../compile_success/let_stmt/Prover.toml | 0 .../numeric_generics/Prover.toml | 0 .../regression_2099/Nargo.toml | 0 .../regression_2099/src/main.nr | 0 .../unconstrained_empty/Nargo.toml | 0 .../unconstrained_empty/src/main.nr | 0 .../target/brillig_calls_conditionals.json | 2 +- .../brillig_cast/Prover.toml | 0 .../brillig_cast/target/brillig_cast.json | 1 - .../brillig_cast/target/witness.tr | Bin 23 -> 0 bytes .../brillig_field_binary_operations.json | 2 +- .../target/witness.tr | Bin 96 -> 77 bytes .../brillig_integer_binary_operations.json | 2 +- .../target/witness.tr | Bin 160 -> 110 bytes .../brillig_keccak/target/brillig_keccak.json | 2 +- .../brillig_keccak/target/witness.tr | Bin 3315 -> 2893 bytes .../brillig_loop/target/brillig_loop.json | 2 +- .../brillig_loop/target/witness.tr | Bin 73 -> 66 bytes .../brillig_modulo/target/brillig_modulo.json | 2 +- .../brillig_modulo/target/witness.tr | Bin 128 -> 102 bytes .../target/brillig_to_bits.json | 1 - .../brillig_to_bits/target/witness.tr | Bin 23 -> 0 bytes .../target/regression_2099.json | 1 - .../regression_2099/target/witness.tr | Bin 23 -> 0 bytes .../unconstrained_empty/Prover.toml | 1 - .../target/unconstrained_empty.json | 1 - .../unconstrained_empty/target/witness.tr | Bin 23 -> 0 bytes .../src/ssa/acir_gen/acir_ir/acir_variable.rs | 159 ++++++++++++++++++ 32 files changed, 165 insertions(+), 11 deletions(-) rename crates/nargo_cli/tests/{execution_success => compile_success}/brillig_cast/Nargo.toml (100%) rename crates/nargo_cli/tests/{execution_success => compile_success}/brillig_cast/src/main.nr (100%) rename crates/nargo_cli/tests/{execution_success => compile_success}/brillig_to_bits/Nargo.toml (100%) rename crates/nargo_cli/tests/{execution_success => compile_success}/brillig_to_bits/src/main.nr (100%) delete mode 100644 crates/nargo_cli/tests/compile_success/let_stmt/Prover.toml delete mode 100644 crates/nargo_cli/tests/compile_success/numeric_generics/Prover.toml rename crates/nargo_cli/tests/{execution_success => compile_success}/regression_2099/Nargo.toml (100%) rename crates/nargo_cli/tests/{execution_success => compile_success}/regression_2099/src/main.nr (100%) rename crates/nargo_cli/tests/{execution_success => compile_success}/unconstrained_empty/Nargo.toml (100%) rename crates/nargo_cli/tests/{execution_success => compile_success}/unconstrained_empty/src/main.nr (100%) delete mode 100644 crates/nargo_cli/tests/execution_success/brillig_cast/Prover.toml delete mode 100644 crates/nargo_cli/tests/execution_success/brillig_cast/target/brillig_cast.json delete mode 100644 crates/nargo_cli/tests/execution_success/brillig_cast/target/witness.tr delete mode 100644 crates/nargo_cli/tests/execution_success/brillig_to_bits/target/brillig_to_bits.json delete mode 100644 crates/nargo_cli/tests/execution_success/brillig_to_bits/target/witness.tr delete mode 100644 crates/nargo_cli/tests/execution_success/regression_2099/target/regression_2099.json delete mode 100644 crates/nargo_cli/tests/execution_success/regression_2099/target/witness.tr delete mode 100644 crates/nargo_cli/tests/execution_success/unconstrained_empty/Prover.toml delete mode 100644 crates/nargo_cli/tests/execution_success/unconstrained_empty/target/unconstrained_empty.json delete mode 100644 crates/nargo_cli/tests/execution_success/unconstrained_empty/target/witness.tr diff --git a/crates/nargo_cli/tests/execution_success/brillig_cast/Nargo.toml b/crates/nargo_cli/tests/compile_success/brillig_cast/Nargo.toml similarity index 100% rename from crates/nargo_cli/tests/execution_success/brillig_cast/Nargo.toml rename to crates/nargo_cli/tests/compile_success/brillig_cast/Nargo.toml diff --git a/crates/nargo_cli/tests/execution_success/brillig_cast/src/main.nr b/crates/nargo_cli/tests/compile_success/brillig_cast/src/main.nr similarity index 100% rename from crates/nargo_cli/tests/execution_success/brillig_cast/src/main.nr rename to crates/nargo_cli/tests/compile_success/brillig_cast/src/main.nr diff --git a/crates/nargo_cli/tests/execution_success/brillig_to_bits/Nargo.toml b/crates/nargo_cli/tests/compile_success/brillig_to_bits/Nargo.toml similarity index 100% rename from crates/nargo_cli/tests/execution_success/brillig_to_bits/Nargo.toml rename to crates/nargo_cli/tests/compile_success/brillig_to_bits/Nargo.toml diff --git a/crates/nargo_cli/tests/execution_success/brillig_to_bits/src/main.nr b/crates/nargo_cli/tests/compile_success/brillig_to_bits/src/main.nr similarity index 100% rename from crates/nargo_cli/tests/execution_success/brillig_to_bits/src/main.nr rename to crates/nargo_cli/tests/compile_success/brillig_to_bits/src/main.nr diff --git a/crates/nargo_cli/tests/compile_success/let_stmt/Prover.toml b/crates/nargo_cli/tests/compile_success/let_stmt/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/nargo_cli/tests/compile_success/numeric_generics/Prover.toml b/crates/nargo_cli/tests/compile_success/numeric_generics/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/nargo_cli/tests/execution_success/regression_2099/Nargo.toml b/crates/nargo_cli/tests/compile_success/regression_2099/Nargo.toml similarity index 100% rename from crates/nargo_cli/tests/execution_success/regression_2099/Nargo.toml rename to crates/nargo_cli/tests/compile_success/regression_2099/Nargo.toml diff --git a/crates/nargo_cli/tests/execution_success/regression_2099/src/main.nr b/crates/nargo_cli/tests/compile_success/regression_2099/src/main.nr similarity index 100% rename from crates/nargo_cli/tests/execution_success/regression_2099/src/main.nr rename to crates/nargo_cli/tests/compile_success/regression_2099/src/main.nr diff --git a/crates/nargo_cli/tests/execution_success/unconstrained_empty/Nargo.toml b/crates/nargo_cli/tests/compile_success/unconstrained_empty/Nargo.toml similarity index 100% rename from crates/nargo_cli/tests/execution_success/unconstrained_empty/Nargo.toml rename to crates/nargo_cli/tests/compile_success/unconstrained_empty/Nargo.toml diff --git a/crates/nargo_cli/tests/execution_success/unconstrained_empty/src/main.nr b/crates/nargo_cli/tests/compile_success/unconstrained_empty/src/main.nr similarity index 100% rename from crates/nargo_cli/tests/execution_success/unconstrained_empty/src/main.nr rename to crates/nargo_cli/tests/compile_success/unconstrained_empty/src/main.nr diff --git a/crates/nargo_cli/tests/execution_success/brillig_calls_conditionals/target/brillig_calls_conditionals.json b/crates/nargo_cli/tests/execution_success/brillig_calls_conditionals/target/brillig_calls_conditionals.json index 323ec175852..59f1cb780ea 100644 --- a/crates/nargo_cli/tests/execution_success/brillig_calls_conditionals/target/brillig_calls_conditionals.json +++ b/crates/nargo_cli/tests/execution_success/brillig_calls_conditionals/target/brillig_calls_conditionals.json @@ -1 +1 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"array","length":3,"type":{"kind":"integer","sign":"unsigned","width":32}},"visibility":"private"}],"param_witnesses":{"x":[1,2,3]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2b226jSBCG2waMG3xKZi9W2r2YB9gLfJpgaS/8KonWudh9zp3nmmGGVn53fKrQjUujv6TIYHDV1wXBNMn3yRjzh/kZg+8/w/b1M6wPvfWkXc/azyXe55P2Z2Deh3tv375W3WI5C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xauH2y0MKlhSthoYVLC1fCQguXFu4lPlq4l/tjvP64oIV7OwstXFq4EhZauLRwJSy0cGnhXmOhhRufhRYuLVwJCy1cWrgSFlq4tHAlLLRwaeFW3YIWrvnFLdwx5OoqzdkAuVoLd9eXgGfD5ToS8ApYpoXbMac1x7O9UHlLE+7kjzXuMvwxqiCl6p72dRFITJyLwASWaeF+OGjhtnlp4dLChaCF2xMLLVxauBIWWri0cCUsgzuz0MKNz0ILlxauhIUWLi1cCQstXFq4t/THeP1xQQv3dhZauLRwJSy0cGnhSlho4dLC7ZOFFi4tXAkLLVxauBIWWri0cC/x0cK93B/j9ccFLdzbWWjh0sKVsNDCpYUrYaGFSwv3Ggst3PgstHBp4UpYaOHSwpWw0MKlhSthoYVLC7fqFrRwzS9u4U4gV1dpbhogV2vh1n0JeNNwuY4EPPxnMFq4HXNOPehQeecm3Mkfa9zz8MeogpSqe3ruIhC2H6tnrIF/EaI5++GgOdvmpTlLcxaC5mxPLDRnac5KWGjO0pyVsAzuzEJzNj4LzVmasxIWmrM0ZyUsNGdpzt7SH+P1xwXN2dtZaM7SnJWw0JylOSthoTlLc7ZPFpqzNGclLDRnac5KWGjO0py9xEdz9nJ/jNcfFzRnb2ehOUtzVsJCc5bmrISF5izN2WssNGfjs9CcpTkrYaE5S3NWwkJzluashIXmLM3ZqlvQnDUKzNm+LNJFuFxHFukDLNMi7Zhz0TY0dN5HyKXRIm3G/Rj+GFWQUnVPE2Bsfnl8K7GJbwpW52lU7QAA","proving_key":null,"verification_key":null} \ No newline at end of file +{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"array","length":3,"type":{"kind":"integer","sign":"unsigned","width":32}},"visibility":"private"}],"param_witnesses":{"x":[1,2,3]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2by27jNhSGaetKXWwn00WBdjEP0IXky0QGuvCrTFBn0T5n+1ytpiLym5Edc0QqB4OfQGDRks/5eCTTopDvk1LqF/V/W/z3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LLRwaeG6sNDCpYV7T32UVR/TaOHez0ILlxauCwstXFq4Liy0cGnhzslCC5cWrgsLLVxauC4stHBp4d7io4V7uz7Kqo9ptHDvZ6GFSwvXhYUWLi1cFxZauLRw32OhhRuehRYuLVwXFlq4tHBdWGjh0sJ1YaGFSwu3mdZo4aof3MLNIdZUaU57iDVYuMe5BDztL9aFgFfANi3ciTG1ulzt+YpbKn8Xf6hxl/7PUQMhRdd0rkkgUmEmgQq2aeF+d6OFO8SlhUsLFxot3JlYaOHSwnVhoYVLC9eFZfHBLLRww7PQwqWF68JCC5cWrgsLLVxauPfUR1n1MY0W7v0stHBp4bqw0MKlhevCQguXFu6cLLRwaeG6sNDCpYXrwkILlxbuLT5auLfro6z6mEYL934WWri0cF1YaOHSwnVhoYVLC/c9Flq44Vlo4dLCdWGhhUsL14WFFi4tXBcWWri0cJtpjRau+sEt3ApiTZXmag+xBgu3m0vAq/3FuhDw8J/BaOFOjFlb0L7irpW/iz/UuNf+z1EDIcXX9Brn1Ngbj/Wca7LyyYy8D7DNyWpizM1QUN9xH5Xsyaof96P/cxR0svJZ0wgY+y+PrY337V8ow1m/u7cAAA==","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/brillig_cast/Prover.toml b/crates/nargo_cli/tests/execution_success/brillig_cast/Prover.toml deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/crates/nargo_cli/tests/execution_success/brillig_cast/target/brillig_cast.json b/crates/nargo_cli/tests/execution_success/brillig_cast/target/brillig_cast.json deleted file mode 100644 index 7c2348cceb4..00000000000 --- a/crates/nargo_cli/tests/execution_success/brillig_cast/target/brillig_cast.json +++ /dev/null @@ -1 +0,0 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2WzW7CMBCEHYeQXwgh5FRVolVvvZCCeu67tOr7P0LrxiNGbuiB7gYhsRJysFY7u1+seCJjTGKGiM3pQM6c9t78uvtnuJqRcE3X78zXWn7/UtKQHqC/gTsvbuDOjD/B7a8cnNOIRTVeD3PSkOrbcbDE2FLfM3oHiYIu6ide19J/4/tATunXhSLbVGFGPr8z6jsltpms7iGi+jiX6CMjtshZT8C2kJ3xh21ujsF9F7RXiur2765mpTBLEcyCvivaWyjoon4UaBS0v/TPic/Jg95iyrn3q+ZZWonWHDjU5hgZ9b0i/o3wLBHVT7wu+miILXKeJmDbitYc2OL7ErJtldm2Adv1CFvkPE/AthOtObDdmHG2nTLbLmC7GWGLnBdiezFD+UhAhHWv1lC6D7mlF+YiJ11LzKS1HS8YPbduSTemFTmhARQ2ax8KRuyXAbTUd0a8M+KMVdgw9WyYwBu6BfFGThvwFjY9n1qGBucEvCuaA7zxXBLvWraXfWictqRbE2/k3AW8ZT/au97NDSPR0NzCF37PFz4uB+i2NDdyHmhu1cvBnIgvzUgn0D0UAAA=","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/brillig_cast/target/witness.tr b/crates/nargo_cli/tests/execution_success/brillig_cast/target/witness.tr deleted file mode 100644 index 4e90289d5e1eafa19edb881b1256718356260d8b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23 Zcmb2|=3oE;rvJ$a4GavK_mxsX0suJI1kL~e diff --git a/crates/nargo_cli/tests/execution_success/brillig_field_binary_operations/target/brillig_field_binary_operations.json b/crates/nargo_cli/tests/execution_success/brillig_field_binary_operations/target/brillig_field_binary_operations.json index e08b7dc3b1d..811f409701c 100644 --- a/crates/nargo_cli/tests/execution_success/brillig_field_binary_operations/target/brillig_field_binary_operations.json +++ b/crates/nargo_cli/tests/execution_success/brillig_field_binary_operations/target/brillig_field_binary_operations.json @@ -1 +1 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2Y3W7CMAyFDf2BMujY3R4jadI2vdurrFp5/0cYFalwUXaznlRVG0soFoGDj230CT6I6JMeEd0fe/o7vuwppoX2qF3smCbP3+yZWZ/8PnP4TvG1iZR9JkozuWscmI8hBj+5PWPHXcTel7y8jvdkuDvQuKdII5IcBQ7aSlRad3XRSSW/RdG0phS6bCsjjSxN+VMYpTqjTd20TS0aqVUnb2WjblZ8B9Ta4zxXkauhBF8SCaxZ8Hojlscvs+P3HhZ/tC+uPubkeVl9DCnyoBsTbvl9+Y7xMxJMctE9XRt1E5YH6j49b466CVArxXku5qIusOYRdQ8sD9SdqJnS+BuG0j3Ssqnb+z7iZ+SVusiero26nEKBus/nN0fdDKh1wnk2c1EXWLNw/YHEFydQ95+aJ9tQtO6Zlk3d3vcZPyOv1EX2dG3UvbA8UPcRfMaboe4FqJXjPM/2WxdY84i67ywP1J2omduGonWvtGzq9r6v+Bl5pS66p674BXI9tT78HQAA","proving_key":null,"verification_key":null} \ No newline at end of file +{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2UQQ6DIBBFp0K1WttVDwICCrtepaZ4/yM0piwmVrthSDBxNkxYfN78If8GAA/4rVM4n+FUotfaD52XSr5E50ZrhDZjb6WVxpp3Z5XyVtvBjW4QTmrl5WScmsS3TkhLRBZDfP+YRVxJSmbMW6Cer9yxcJYJZoLFO0sf7yt3pI+nWFKRQJcB3edPNTej35FAktl7usUZq81hf2FFyYx5z6g/wipSkwdDqXVLyDusePggxDtKGlbUnm5xxmpXsL+womTGvBfUH2EVqVkFQ6l1a8g7rOa5a/odJQ0rak+3OGO1G9hfWFEyY94r6o+witRsgqHUui3kHVbz3C39jpKGFbWna/UBXDJMO9gSAAA=","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/brillig_field_binary_operations/target/witness.tr b/crates/nargo_cli/tests/execution_success/brillig_field_binary_operations/target/witness.tr index 908ac53760e9cb08f3e2171afce2431192f01391..3e291a6c8c535690a992b66843c5236fe4bda514 100644 GIT binary patch literal 77 zcmb2|=3oE;rvGdEZ*npy@EqN9o^P@Aj{hNCWzEkV7se|Jet&*n_V4sU#uV4St->#+ gI)*VyYrnYa5XLUe{=(F8T0^gRZJU|a3}yxf0C)5qO#lD@ literal 96 zcmV-m0H6OKiwFP!00002|E>AwMA6yDT|-e1;?ex0QqT9{tIV*o)#vil<*q7w2s=$mIv<%pn1^>%|89itPu&)k242R^%1ONb{ CWhun~ diff --git a/crates/nargo_cli/tests/execution_success/brillig_integer_binary_operations/target/brillig_integer_binary_operations.json b/crates/nargo_cli/tests/execution_success/brillig_integer_binary_operations/target/brillig_integer_binary_operations.json index cb58e907a68..5a9a1494b04 100644 --- a/crates/nargo_cli/tests/execution_success/brillig_integer_binary_operations/target/brillig_integer_binary_operations.json +++ b/crates/nargo_cli/tests/execution_success/brillig_integer_binary_operations/target/brillig_integer_binary_operations.json @@ -1 +1 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2dC5hd0xXH9zwySSYzk4c85H3zFIrOmVfuaDCUNBQNRUPRZJKZhqKhaKikoaShaCgaioaioWgoGoqGoqFoKBqKhqKhaBSNolHnZC/zuyd7VDJrzzePfb4v3132Xmv9/2v/77n7zDn3LlsZYyaYDUfBR//yTfNHnX0tb9lR4zF3RR5y0i6xr91tnZzv7qi7SJ9beREwtXJ2+ShHV9Qhh9RTZjELMZfBfAFiu1i7EGOyDl0cayVzXU3uWmsWGBlHUZK7srymqqphfEVDVBlNK6+orc9Wl1dV19dko2xUna2eUZGtrGzIVmXH19bXji+vjaoqG6LG6trKRps8TzFXvl7N2QLXghr1N0+kyLmcfAtgF6a047yHEyLn/eJaxzLj+c3qQ6QCD3kLjd6b31fdhfoalSNlm17TjrYbd4EdduOmmjMm7MYfL55WriK9mqtaazdW5JyzG3eFHXbjFuYsMrlnmFbebqZt78Zx3d30NfK6G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fYD491MxvvT+LzAFn3p/qItZ/vEC2kP0/hDY62USfmLng/N68PShd15eE3RpCjPhAk7i+wHmC1z8kbPQ2hv9P73QX6KL+GBM/GSu3bYfG66YK6NYc2u1H1PknNN+bATs0H6shTkzdkG18440em9+X3WP1NfIa/sxzTXtaB2MRsGeGzoYKeKGDkahg1HoYPRp1rMYXOtM6GAUH/kmdDD6pHUKHYzcROMcoYNR6GAUOhht0jKGDkYYG4v40MEodDDyoXfoYOQmGucIHYxCB6PQwWiTljF0MMLYRMSHDkahg5EPvUMHIzfROEfoYBQ6GIUORpu0jKGDEcYaER86GIUORj70Dh2M3ETjHKGDUehgFDoYbdIyhg5GGJuP+NDBKHQw8qF36GDkPEIHIx3M0MEIY6GDUehgFDoY5dr5JnQw2swjdDBq/ggdjHQwQwcjjIUORqGDUehglGvnm9DBaDOP0MGo+SN0MNLBDB2MMBY6GIUORqGDUa6db0IHo808Qgej5o/QwUgHM3QwwljoYNQ5OxjF8Rn7yrjmOhgVWbuLo6tRUXvvajRKMddotZqjbGt1NdLjnNvVaAzs0NWohTlH2wXVzjvW6L35fdU9Vl8jr12NtNfUdfwPogjmdfLSAAA=","proving_key":null,"verification_key":null} \ No newline at end of file +{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+2Uy27CMBBFB5JCobwKhdI/6NLOgzi7/kqjhv//hCqqF6M0ZjPXki3Zm1hZ3Jy5E50PIvqk/2dmn1/2WapbVfVN0etSf6ui7Uytqrq7GW10beqfwpRlbyrTtF3bqFZXZa/vdVve1d+ZsSwlPBnje8SsZEcjmTnvnN3ziXeZfS48zESj74x73E28g37cx5LmHnIzwv38vubO8DtSLDL4Tl2c0uyc4pMVkpnzPrF7kpUwM7eFonMXFLascvuDgHfkVVboTl2c0uwlxScrJDPnfWb3JCth5tIWis5dUdiyGuZe4XfkVVboTl2c0uw1xScrJDPnfWH3JCth5toWis7dUNiyGube4HfkVVboTl2c0uwtxScrJDPn3bF7kpUwczuCRuXuKWxZDXPv8TvyKit0py5OafaB4pMVkpnzvrJ7kpUw82ALReceKWxZDXMf8TvyKit0py5OafaJ4pMVkpnzvrF7kpUw82QLReeeKWxZDXOf8TvyKit0py5OafaF4pMVkpnzvrN7kpUw82ILRedeKWxZDXNf8TvyKit0p1PnF6lyuYaMJQAA","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/brillig_integer_binary_operations/target/witness.tr b/crates/nargo_cli/tests/execution_success/brillig_integer_binary_operations/target/witness.tr index 95ca3d20bb4cc89aeab2e4283144360689c4f5e6..a52e8a76601d3e2af0c08355cae8359b2f686b7d 100644 GIT binary patch literal 110 zcmV-!0FnP6iwFP!00002|E+M z{&4|hg^qPZ&?| Qg{%!WUYia+1t_tzO=9dY=#XInQ;@?_B48K3vzMlecr*|IV*JS}H?c zkeoDfC^MZ_j%CxG)||+h&d8Z3q0-s@#d$+`eBk0qBGEZu{>y0h+Ejb!N*TwkDkdkq zW--^`c_un5*|UZa%4$1bUdB^tAHy|2a|s!?*_ZD>zHE9eCT7#T;MZaUTIa$NKwo$)$G%SBN1nH_qt9}Q&Ltm7EfUD#Un1M#(Qsxhf|(S zl)hSuz!zz3_NeCjPmB+x4*Z6~in&84BCV=JNY&W5Px5_RE{8sCwDzl@u*0K6{TI}N zPj?x%p$Pet8n-=`6OP408&c}v`?}hkDwQ3jvfdgsNNIEM zFg<-S006<`*Jg9p2{S7A8D;1_J)4)i0gwUks%V@lI-^$!->U*mf^!q~&>!u{ADrW7 z^Z3&hqOLv64wN9~B#e^D68-{!mjGTCjgv)ZFJaso?u762Ck z9-PL3(-}_6cqa(7K$puvptYUIP|x_|m-uL=C|QM>a7-Xkg^B%G!f*h52k=a291}Vt zR2d%%fj-maK1HCboyb+5@qK^rdkRI#%FF~~fkXu+_F)On0pJqAJ4E9gqBF3{cq|0k zs>{8NK$D!vL@98I-y?N^FcVA!5_On3fF+Csz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IxD?dKBF~cqHR~GC8?Jb$4KK6YXO0d5ipTL5WVt6Bq9ThO(>=V7^JJhx5q} z8RRor_Q&zr`=4dn=Cx5;53WprRLAXt-#tDyo2p&P&NQ)WdCh0Msyca@HjK<))hqqG z_Ra2F`-hNq7zqrgtErzK$BG)j0a zyLx&5R%mW1PJvXfM8ti}OZ{<9)o-?JcD+YOCx<{*yUrhN4k(El&*YRoQhS-Cy<6aG=CF^%?mXfu8ho_@v8f? zcjOdTH_xr!XYu%KD;Y(F(_UQr^W1UM*Ly%-N;`5%>q-X;%TCb9OlUismd z{3QMY_r7PoB4v2;OqPR9?H_fM@z>yqDAIs@C;95y4l;eCG(9kD#n^0{vXy4-`lF(Y zNxxS_PTp%ye(;;SulIA~COs$Am#ZsNKYG1-b_w6?=J#q6R$mE@w1ti~6V56QIA>W= zJ^fnOhM#z!OcYA6SJh5yjq`mo3(t-*1<1*UCd_%Ig@31k{+LUbO)J_2U5}^Btw;7- z9|*wdu>{pDAGXu4)z2u&6oJ_zcOGB=e3l#MjgUogv*j8U-!!3BBllE1;$R=)RV&SR zhm;CFpu4LNzP$dcQOU89bmCVMJK3c0XM09$b7;|kTw(v4@*otoFOE4=yHR`#Q;v7B zrqlB&u0P7O2Sy5;Ob35?&Q$`NbG;*!tah;aGNKG$zj_^EY8&5TGAl>wmnY67k9t+s znYOkC_6_tJWVCp2vIZ{;?s@C?wD(~%$FII{(q%I6Yq}6Iy<}X;!Sr)TE^+6mzR+a iL9g7k<^pakVXJ~(HS}uW#um0Z=(PY!nL=w=2mk<1Fgh;) diff --git a/crates/nargo_cli/tests/execution_success/brillig_to_bits/target/brillig_to_bits.json b/crates/nargo_cli/tests/execution_success/brillig_to_bits/target/brillig_to_bits.json deleted file mode 100644 index 01a973d5190..00000000000 --- a/crates/nargo_cli/tests/execution_success/brillig_to_bits/target/brillig_to_bits.json +++ /dev/null @@ -1 +0,0 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":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Ofn5+fn5+fn5+fn5+fn5+fn5+dvmssf/Pz8/Pz8/Ct+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fv7g5+fn5+fn5+fn5+fn5+fn5+fn52+ayx/8/Pz8/Pz8K35+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fn5+fv6nBn/w8/Pz8/Pz8/PX/qj2rMb5dpxnw/VLtS/XPR3XN+O67D1Oe/642s2L0fm+sbP2HI1zyZmmn5V9J8N1njx7o2/Y2FPjb5Xg/QstDAQA","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/brillig_to_bits/target/witness.tr b/crates/nargo_cli/tests/execution_success/brillig_to_bits/target/witness.tr deleted file mode 100644 index 4e90289d5e1eafa19edb881b1256718356260d8b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23 Zcmb2|=3oE;rvJ$a4GavK_mxsX0suJI1kL~e diff --git a/crates/nargo_cli/tests/execution_success/regression_2099/target/regression_2099.json b/crates/nargo_cli/tests/execution_success/regression_2099/target/regression_2099.json deleted file mode 100644 index 4c3bb072cb3..00000000000 --- a/crates/nargo_cli/tests/execution_success/regression_2099/target/regression_2099.json +++ /dev/null @@ -1 +0,0 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/2NkIAwAQGbG/yQAAAA=","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/regression_2099/target/witness.tr b/crates/nargo_cli/tests/execution_success/regression_2099/target/witness.tr deleted file mode 100644 index 4e90289d5e1eafa19edb881b1256718356260d8b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23 Zcmb2|=3oE;rvJ$a4GavK_mxsX0suJI1kL~e diff --git a/crates/nargo_cli/tests/execution_success/unconstrained_empty/Prover.toml b/crates/nargo_cli/tests/execution_success/unconstrained_empty/Prover.toml deleted file mode 100644 index 11497a473bc..00000000000 --- a/crates/nargo_cli/tests/execution_success/unconstrained_empty/Prover.toml +++ /dev/null @@ -1 +0,0 @@ -x = "0" diff --git a/crates/nargo_cli/tests/execution_success/unconstrained_empty/target/unconstrained_empty.json b/crates/nargo_cli/tests/execution_success/unconstrained_empty/target/unconstrained_empty.json deleted file mode 100644 index d6e9953cd42..00000000000 --- a/crates/nargo_cli/tests/execution_success/unconstrained_empty/target/unconstrained_empty.json +++ /dev/null @@ -1 +0,0 @@ -{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/62Puw0AIAhEj6jYOYtu4P5TqZHiGip4CbmE4j4CQPAp8GmmSr9tOoModcjyfH2reY17nTKyByw4HCZCYW5dAQAA","proving_key":null,"verification_key":null} \ No newline at end of file diff --git a/crates/nargo_cli/tests/execution_success/unconstrained_empty/target/witness.tr b/crates/nargo_cli/tests/execution_success/unconstrained_empty/target/witness.tr deleted file mode 100644 index 4e90289d5e1eafa19edb881b1256718356260d8b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 23 Zcmb2|=3oE;rvJ$a4GavK_mxsX0suJI1kL~e diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs b/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs index 03dc414f3fb..cf4c4160e9b 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs @@ -10,6 +10,7 @@ use acvm::acir::{ brillig::Opcode as BrilligOpcode, circuit::brillig::{BrilligInputs, BrilligOutputs}, }; +use acvm::brillig_vm::{brillig::Value, Registers, VMStatus, VM}; use acvm::{ acir::{ circuit::opcodes::FunctionInput, @@ -18,6 +19,7 @@ use acvm::{ }, FieldElement, }; +use acvm::{BlackBoxFunctionSolver, BlackBoxResolutionError}; use iter_extended::{try_vecmap, vecmap}; use noirc_errors::Location; use std::collections::HashMap; @@ -865,6 +867,14 @@ impl AcirContext { } })?; + // Optimistically try executing the brillig now, if we can complete execution they just return the results. + // This is a temporary measure pending SSA optimizations being applied to Brillig which would remove constant-input opcodes (See #2066) + if let Some(brillig_outputs) = self.execute_brillig(code.clone(), &b_inputs, &outputs) { + return Ok(brillig_outputs); + } + + // Otherwise we must generate ACIR for it and execute at runtime. + let mut b_outputs = Vec::new(); let outputs_var = vecmap(outputs, |output| match output { AcirType::NumericType(_) => { @@ -951,6 +961,66 @@ impl AcirContext { (AcirValue::Array(array_values), witnesses) } + fn execute_brillig( + &mut self, + code: Vec, + inputs: &[BrilligInputs], + outputs_types: &[AcirType], + ) -> Option> { + let (registers, memory) = execute_brillig(code, inputs)?; + + let outputs_var = vecmap(outputs_types.iter().enumerate(), |(index, output)| { + let register_value = registers.get(index.into()); + match output { + AcirType::NumericType(_) => { + let var = self.add_data(AcirVarData::Const(register_value.to_field())); + AcirValue::Var(var, output.clone()) + } + AcirType::Array(element_types, size) => { + let mem_ptr = register_value.to_usize(); + self.brillig_constant_array_output( + element_types, + *size, + &mut memory.iter().skip(mem_ptr), + ) + } + } + }); + + Some(outputs_var) + } + + /// Recursively create [`AcirValue`]s for returned arrays. This is necessary because a brillig returned array can have nested arrays as elements. + fn brillig_constant_array_output<'a>( + &mut self, + element_types: &[AcirType], + size: usize, + memory_iter: &mut impl Iterator, + ) -> AcirValue { + let mut array_values = im::Vector::new(); + for _ in 0..size { + for element_type in element_types { + match element_type { + AcirType::Array(nested_element_types, nested_size) => { + let nested_acir_value = self.brillig_constant_array_output( + nested_element_types, + *nested_size, + memory_iter, + ); + array_values.push_back(nested_acir_value); + } + AcirType::NumericType(_) => { + let memory_value = + memory_iter.next().expect("ICE: Unexpected end of memory"); + let var = self.add_data(AcirVarData::Const(memory_value.to_field())); + array_values.push_back(AcirValue::Var(var, element_type.clone())); + } + } + } + } + AcirValue::Array(array_values) + } + /// Generate output variables that are constrained to be the sorted inputs /// The outputs are the sorted inputs iff /// outputs are sorted and @@ -1112,3 +1182,92 @@ impl AcirVarData { /// A Reference to an `AcirVarData` #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub(crate) struct AcirVar(usize); + +/// Attempts to execute the provided [`Brillig`][`acvm::acir::brillig`] bytecode +/// +/// Returns the finished state of the Brillig VM if execution can complete. +/// +/// Returns `None` if complete execution of the Brillig bytecode is not possible. +fn execute_brillig( + code: Vec, + inputs: &[BrilligInputs], +) -> Option<(Registers, Vec)> { + struct NullBbSolver; + + impl BlackBoxFunctionSolver for NullBbSolver { + fn schnorr_verify( + &self, + _public_key_x: &FieldElement, + _public_key_y: &FieldElement, + _signature: &[u8], + _message: &[u8], + ) -> Result { + Err(BlackBoxResolutionError::Unsupported(BlackBoxFunc::SchnorrVerify)) + } + fn pedersen( + &self, + _inputs: &[FieldElement], + _domain_separator: u32, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + Err(BlackBoxResolutionError::Unsupported(BlackBoxFunc::Pedersen)) + } + fn fixed_base_scalar_mul( + &self, + _input: &FieldElement, + ) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> { + Err(BlackBoxResolutionError::Unsupported(BlackBoxFunc::FixedBaseScalarMul)) + } + } + + // Set input values + let mut input_register_values: Vec = Vec::with_capacity(inputs.len()); + let mut input_memory: Vec = Vec::new(); + // Each input represents a constant or array of constants. + // Iterate over each input and push it into registers and/or memory. + for input in inputs { + match input { + BrilligInputs::Single(expr) => { + input_register_values.push(expr.to_const()?.into()); + } + BrilligInputs::Array(expr_arr) => { + // Attempt to fetch all array input values + let memory_pointer = input_memory.len(); + for expr in expr_arr.iter() { + input_memory.push(expr.to_const()?.into()); + } + + // Push value of the array pointer as a register + input_register_values.push(Value::from(memory_pointer)); + } + } + } + + // Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode. + let input_registers = Registers::load(input_register_values); + let mut vm = VM::new(input_registers, input_memory, code, Vec::new(), &NullBbSolver); + + // Run the Brillig VM on these inputs, bytecode, etc! + let vm_status = vm.process_opcodes(); + + // Check the status of the Brillig VM. + // It may be finished, in-progress, failed, or may be waiting for results of a foreign call. + // If it's finished then we can omit the opcode and just write in the return values. + match vm_status { + VMStatus::Finished => Some((vm.get_registers().clone(), vm.get_memory().clone())), + VMStatus::InProgress => unreachable!("Brillig VM has not completed execution"), + VMStatus::Failure { .. } => { + // TODO: Return an error stating that the brillig function failed. + None + } + VMStatus::ForeignCallWait { .. } => { + // If execution can't complete then keep the opcode + + // TODO: We could bake in all the execution up to this point by replacing the inputs + // such that they initialize the registers/memory to the current values and then discard + // any opcodes prior to the one which performed this foreign call. + // + // Seems overkill for now however. + None + } + } +} From 7834fcee0bda8f72d97a65964605fd82742ea75f Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 11 Aug 2023 11:09:15 -0700 Subject: [PATCH 05/14] fix(nargo): Allow `--program-dir` flag anywhere in a command (#2290) --- crates/nargo_cli/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 2774d4cb6a4..58e84207484 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -39,7 +39,7 @@ struct NargoCli { #[non_exhaustive] #[derive(Args, Clone, Debug)] pub(crate) struct NargoConfig { - #[arg(short, long, hide=true, default_value_os_t = std::env::current_dir().unwrap())] + #[arg(short, long, hide=true, global=true, default_value_os_t = std::env::current_dir().unwrap())] program_dir: PathBuf, } From 92e1802979e5713ec4287d8932e4675c95439861 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Fri, 11 Aug 2023 11:57:06 -0700 Subject: [PATCH 06/14] fix(lsp): Pass `--program-dir` to test command from codelens (#2292) --- crates/lsp/src/lib.rs | 2 ++ crates/nargo_cli/src/cli/mod.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index 83e196a183b..b0768ccdeaa 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -199,6 +199,8 @@ fn on_code_lens_request( title: TEST_CODELENS_TITLE.into(), command: TEST_COMMAND.into(), arguments: Some(vec![ + "--program-dir".into(), + format!("{}", workspace.root_dir.display()).into(), "--package".into(), format!("{}", package.name).into(), "--exact".into(), diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 58e84207484..2ab34c11e40 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -39,6 +39,7 @@ struct NargoCli { #[non_exhaustive] #[derive(Args, Clone, Debug)] pub(crate) struct NargoConfig { + // REMINDER: Also change this flag in the LSP test lens if renamed #[arg(short, long, hide=true, global=true, default_value_os_t = std::env::current_dir().unwrap())] program_dir: PathBuf, } From 053662ad98e4c9846c1db818d764c38eca3d9b4a Mon Sep 17 00:00:00 2001 From: Ethan-000 Date: Mon, 14 Aug 2023 13:19:14 +0100 Subject: [PATCH 07/14] chore: `nargo info` now prints information as a prettified table (#2282) --- Cargo.lock | 74 ++++++++++++++++++++++++++++ crates/nargo_cli/Cargo.toml | 3 +- crates/nargo_cli/build.rs | 6 ++- crates/nargo_cli/src/cli/info_cmd.rs | 62 ++++++++++++++++++----- cspell.json | 2 + 5 files changed, 132 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9e30e08156..053ee03771b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1061,6 +1061,27 @@ dependencies = [ "typenum", ] +[[package]] +name = "csv" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626ae34994d3d8d668f4269922248239db4ae42d538b14c398b74a52208e8086" +dependencies = [ + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + [[package]] name = "darling" version = "0.20.3" @@ -1151,6 +1172,16 @@ dependencies = [ "dirs-sys", ] +[[package]] +name = "dirs-next" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98cf8ebf19c3d1b223e151f99a4f9f0690dca41414773390fc824184ac833e1" +dependencies = [ + "cfg-if", + "dirs-sys-next", +] + [[package]] name = "dirs-sys" version = "0.3.7" @@ -1162,6 +1193,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "dirs-sys-next" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" +dependencies = [ + "libc", + "redox_users", + "winapi", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -1206,6 +1248,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "encode_unicode" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" + [[package]] name = "encoding_rs" version = "0.8.32" @@ -2179,6 +2227,7 @@ dependencies = [ "paste", "pprof", "predicates 2.1.5", + "prettytable-rs", "rustc_version", "serde", "serde_json", @@ -2615,6 +2664,20 @@ dependencies = [ "termtree", ] +[[package]] +name = "prettytable-rs" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eea25e07510aa6ab6547308ebe3c036016d162b8da920dbb079e3ba8acf3d95a" +dependencies = [ + "csv", + "encode_unicode", + "is-terminal", + "lazy_static", + "term", + "unicode-width", +] + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -3584,6 +3647,17 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "term" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c59df8ac95d96ff9bede18eb7300b0fda5e5d8d90960e76f8e14ae765eedbf1f" +dependencies = [ + "dirs-next", + "rustversion", + "winapi", +] + [[package]] name = "termcolor" version = "1.2.0" diff --git a/crates/nargo_cli/Cargo.toml b/crates/nargo_cli/Cargo.toml index 96d218d1593..13205c00022 100644 --- a/crates/nargo_cli/Cargo.toml +++ b/crates/nargo_cli/Cargo.toml @@ -32,13 +32,14 @@ acvm.workspace = true toml.workspace = true serde.workspace = true serde_json.workspace = true +prettytable-rs = "0.10" thiserror.workspace = true tower.workspace = true async-lsp = { version = "0.0.5", default-features = false, features = [ "client-monitor", "stdio", "tracing", - "tokio" + "tokio", ] } const_format = "0.2.30" hex = "0.4.2" diff --git a/crates/nargo_cli/build.rs b/crates/nargo_cli/build.rs index 6d8dae136e2..68ae2b31efd 100644 --- a/crates/nargo_cli/build.rs +++ b/crates/nargo_cli/build.rs @@ -110,7 +110,11 @@ fn compile_success_{test_name}() {{ cmd.arg("info"); // `compile_success` tests should be able to compile down to an empty circuit. - cmd.assert().stdout(predicate::str::contains("Total ACIR opcodes generated for language PLONKCSat {{ width: 3 }}: 0")); + cmd.assert().stdout(predicate::str::contains("| Package") + .and(predicate::str::contains("| Language")) + .and(predicate::str::contains("| ACIR Opcodes | Backend Circuit Size |")) + .and(predicate::str::contains("| PLONKCSat {{ width: 3 }} |")) + .and(predicate::str::contains("| 0 | 1 |"))); }} "#, test_dir = test_dir.display(), diff --git a/crates/nargo_cli/src/cli/info_cmd.rs b/crates/nargo_cli/src/cli/info_cmd.rs index d972aeb0511..a2900a6e249 100644 --- a/crates/nargo_cli/src/cli/info_cmd.rs +++ b/crates/nargo_cli/src/cli/info_cmd.rs @@ -5,6 +5,7 @@ use nargo::{package::Package, prepare_package}; use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; use noirc_driver::{compile_contracts, CompileOptions}; use noirc_frontend::graph::CrateName; +use prettytable::{row, Table}; use crate::{cli::compile_cmd::compile_package, errors::CliError}; @@ -36,14 +37,44 @@ pub(crate) fn run( let toml_path = find_package_manifest(&config.program_dir)?; let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let mut package_table = Table::new(); + package_table.add_row( + row![Fm->"Package", Fm->"Language", Fm->"ACIR Opcodes", Fm->"Backend Circuit Size"], + ); + let mut contract_table = Table::new(); + contract_table.add_row(row![ + Fm->"Contract", + Fm->"Function", + Fm->"Language", + Fm->"ACIR Opcodes", + Fm->"Backend Circuit Size" + ]); + for package in &workspace { if package.is_contract() { - count_opcodes_and_gates_in_contracts(backend, package, &args.compile_options)?; + count_opcodes_and_gates_in_contracts( + backend, + package, + &args.compile_options, + &mut contract_table, + )?; } else { - count_opcodes_and_gates_in_package(backend, package, &args.compile_options)?; + count_opcodes_and_gates_in_package( + backend, + package, + &args.compile_options, + &mut package_table, + )?; } } + if package_table.len() > 1 { + package_table.printstd(); + } + if contract_table.len() > 1 { + contract_table.printstd(); + } + Ok(()) } @@ -51,22 +82,21 @@ fn count_opcodes_and_gates_in_package( backend: &B, package: &Package, compile_options: &CompileOptions, + table: &mut Table, ) -> Result<(), CliError> { let (_, compiled_program) = compile_package(backend, package, compile_options)?; let num_opcodes = compiled_program.circuit.opcodes.len(); - - println!( - "[{}] Total ACIR opcodes generated for language {:?}: {}", - package.name, - backend.np_language(), - num_opcodes - ); - let exact_circuit_size = backend .get_exact_circuit_size(&compiled_program.circuit) .map_err(CliError::ProofSystemCompilerError)?; - println!("[{}] Backend circuit size: {exact_circuit_size}", package.name); + + table.add_row(row![ + Fm->format!("{}", package.name), + format!("{:?}", backend.np_language()), + Fc->format!("{}", num_opcodes), + Fc->format!("{}", exact_circuit_size), + ]); Ok(()) } @@ -75,6 +105,7 @@ fn count_opcodes_and_gates_in_contracts( backend: &B, package: &Package, compile_options: &CompileOptions, + table: &mut Table, ) -> Result<(), CliError> { let (mut context, crate_id) = prepare_package(package); let result = compile_contracts(&mut context, crate_id, compile_options); @@ -92,8 +123,13 @@ fn count_opcodes_and_gates_in_contracts( .map_err(CliError::ProofSystemCompilerError)?; for info in function_info { - println!("[{}]({}) Total ACIR opcodes generated: {}", contract.name, info.0, info.1,); - println!("[{}]({}) Backend circuit size: {}", contract.name, info.0, info.2); + table.add_row(row![ + Fm->format!("{}", contract.name), + Fc->format!("{}", info.0), + format!("{:?}", backend.np_language()), + Fc->format!("{}", info.1), + Fc->format!("{}", info.2), + ]); } } diff --git a/cspell.json b/cspell.json index 5629742faee..9953b6f0cd0 100644 --- a/cspell.json +++ b/cspell.json @@ -53,6 +53,8 @@ "peekable", "pprof", "preprocess", + "prettytable", + "printstd", "pseudocode", "schnorr", "sdiv", From edded24d2256a074e8e390285e123e39f926551d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Rodr=C3=ADguez?= Date: Mon, 14 Aug 2023 17:01:17 +0200 Subject: [PATCH 08/14] feat: optionally output a debug artifact on compile (#2260) Co-authored-by: Tom French <15848336+TomAFrench@users.noreply.github.com> --- crates/fm/src/file_map.rs | 4 +- crates/fm/src/lib.rs | 2 +- crates/nargo/src/artifacts/debug.rs | 50 ++++++++++ crates/nargo/src/artifacts/mod.rs | 1 + crates/nargo/src/ops/preprocess.rs | 23 +++-- crates/nargo_cli/src/cli/compile_cmd.rs | 97 +++++++++++++------ crates/nargo_cli/src/cli/fs/program.rs | 19 +++- crates/noirc_driver/src/contract.rs | 3 + crates/noirc_driver/src/lib.rs | 1 + crates/noirc_errors/src/debug_info.rs | 8 +- .../ssa/acir_gen/acir_ir/generated_acir.rs | 4 +- 11 files changed, 162 insertions(+), 50 deletions(-) create mode 100644 crates/nargo/src/artifacts/debug.rs diff --git a/crates/fm/src/file_map.rs b/crates/fm/src/file_map.rs index 8bbfcf99dd7..22ac6d4e179 100644 --- a/crates/fm/src/file_map.rs +++ b/crates/fm/src/file_map.rs @@ -34,7 +34,9 @@ impl From<&PathBuf> for PathString { pub struct FileMap(SimpleFiles); // XXX: Note that we derive Default here due to ModuleOrigin requiring us to set a FileId -#[derive(Default, Debug, Clone, PartialEq, Eq, Copy, Hash, Serialize, Deserialize)] +#[derive( + Default, Debug, Clone, PartialEq, Eq, Copy, Hash, Serialize, Deserialize, PartialOrd, Ord, +)] pub struct FileId(usize); impl FileId { diff --git a/crates/fm/src/lib.rs b/crates/fm/src/lib.rs index 4c2ce39dd40..ef976a80dbd 100644 --- a/crates/fm/src/lib.rs +++ b/crates/fm/src/lib.rs @@ -70,7 +70,7 @@ impl FileManager { assert!(old_value.is_none(), "ice: the same path was inserted into the file manager twice"); } - pub fn fetch_file(&mut self, file_id: FileId) -> File { + pub fn fetch_file(&self, file_id: FileId) -> File { // Unwrap as we ensure that all file_id's map to a corresponding file in the file map self.file_map.get_file(file_id).unwrap() } diff --git a/crates/nargo/src/artifacts/debug.rs b/crates/nargo/src/artifacts/debug.rs new file mode 100644 index 00000000000..31c15311f06 --- /dev/null +++ b/crates/nargo/src/artifacts/debug.rs @@ -0,0 +1,50 @@ +use serde::{Deserialize, Serialize}; +use std::{ + collections::{BTreeMap, BTreeSet}, + path::PathBuf, +}; + +use fm::FileId; +use noirc_errors::debug_info::DebugInfo; +use noirc_frontend::hir::Context; + +/// For a given file, we store the source code and the path to the file +/// so consumers of the debug artifact can reconstruct the original source code structure. +#[derive(Debug, Serialize, Deserialize)] +pub struct DebugFile { + pub source: String, + pub path: PathBuf, +} + +/// A Debug Artifact stores, for a given program, the debug info for every function +/// along with a map of file Id to the source code so locations in debug info can be mapped to source code they point to. +#[derive(Debug, Serialize, Deserialize)] +pub struct DebugArtifact { + pub debug_symbols: Vec, + pub file_map: BTreeMap, +} + +impl DebugArtifact { + pub fn new(debug_symbols: Vec, compilation_context: &Context) -> Self { + let mut file_map = BTreeMap::new(); + + let files_with_debug_symbols: BTreeSet = debug_symbols + .iter() + .flat_map(|function_symbols| function_symbols.locations.values().map(|loc| loc.file)) + .collect(); + + for file_id in files_with_debug_symbols { + let file_source = compilation_context.file_manager.fetch_file(file_id).source(); + + file_map.insert( + file_id, + DebugFile { + source: file_source.to_string(), + path: compilation_context.file_manager.path(file_id).to_path_buf(), + }, + ); + } + + Self { debug_symbols, file_map } + } +} diff --git a/crates/nargo/src/artifacts/mod.rs b/crates/nargo/src/artifacts/mod.rs index 1ba12c49af7..33311e0856e 100644 --- a/crates/nargo/src/artifacts/mod.rs +++ b/crates/nargo/src/artifacts/mod.rs @@ -8,6 +8,7 @@ use base64::Engine; use serde::{Deserializer, Serializer}; pub mod contract; +pub mod debug; pub mod program; // TODO: move these down into ACVM. diff --git a/crates/nargo/src/ops/preprocess.rs b/crates/nargo/src/ops/preprocess.rs index d07da256ede..0ee4e2590f9 100644 --- a/crates/nargo/src/ops/preprocess.rs +++ b/crates/nargo/src/ops/preprocess.rs @@ -42,7 +42,7 @@ pub fn preprocess_contract_function( include_keys: bool, common_reference_string: &[u8], func: ContractFunction, -) -> Result { +) -> Result<(PreprocessedContractFunction, DebugInfo), B::Error> { // TODO: currently `func`'s bytecode is already optimized for the backend. // In future we'll need to apply those optimizations here. let optimized_bytecode = func.bytecode; @@ -54,14 +54,17 @@ pub fn preprocess_contract_function( (None, None) }; - Ok(PreprocessedContractFunction { - name: func.name, - function_type: func.function_type, - is_internal: func.is_internal, - abi: func.abi, + Ok(( + PreprocessedContractFunction { + name: func.name, + function_type: func.function_type, + is_internal: func.is_internal, + abi: func.abi, - bytecode: optimized_bytecode, - proving_key, - verification_key, - }) + bytecode: optimized_bytecode, + proving_key, + verification_key, + }, + func.debug, + )) } diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index fad9783e654..2a6f802f748 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -2,14 +2,16 @@ use acvm::acir::circuit::OpcodeLabel; use acvm::{acir::circuit::Circuit, Backend}; use iter_extended::try_vecmap; use iter_extended::vecmap; +use nargo::artifacts::debug::DebugArtifact; use nargo::package::Package; use nargo::prepare_package; use nargo::{artifacts::contract::PreprocessedContract, NargoError}; use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; use noirc_driver::{ compile_contracts, compile_main, CompileOptions, CompiledContract, CompiledProgram, - ContractFunction, ErrorsAndWarnings, Warnings, + ErrorsAndWarnings, Warnings, }; +use noirc_errors::debug_info::DebugInfo; use noirc_frontend::graph::CrateName; use noirc_frontend::hir::Context; @@ -19,6 +21,7 @@ use nargo::ops::{preprocess_contract_function, preprocess_program}; use crate::errors::{CliError, CompileError}; +use super::fs::program::save_debug_artifact_to_file; use super::fs::{ common_reference_string::{ read_cached_common_reference_string, update_common_reference_string, @@ -38,6 +41,10 @@ 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)] package: Option, @@ -70,49 +77,72 @@ pub(crate) fn run( // 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. // This is due to EACH function needing it's own CRS, PKey, and VKey from the backend. - let preprocessed_contracts: Result, CliError> = - try_vecmap(optimized_contracts, |contract| { - let preprocessed_contract_functions = try_vecmap(contract.functions, |func| { - common_reference_string = update_common_reference_string( - backend, - &common_reference_string, - &func.bytecode, - ) - .map_err(CliError::CommonReferenceStringError)?; - - preprocess_contract_function( - backend, - args.include_keys, - &common_reference_string, - func, - ) - .map_err(CliError::ProofSystemCompilerError) - })?; - - Ok(PreprocessedContract { + let preprocessed_contracts: Result< + Vec<(PreprocessedContract, Vec)>, + CliError, + > = try_vecmap(optimized_contracts, |contract| { + let preprocess_result = try_vecmap(contract.functions, |func| { + common_reference_string = update_common_reference_string( + backend, + &common_reference_string, + &func.bytecode, + ) + .map_err(CliError::CommonReferenceStringError)?; + + preprocess_contract_function( + backend, + args.include_keys, + &common_reference_string, + func, + ) + .map_err(CliError::ProofSystemCompilerError) + })?; + + let (preprocessed_contract_functions, debug_infos): (Vec<_>, Vec<_>) = + preprocess_result.into_iter().unzip(); + + Ok(( + PreprocessedContract { name: contract.name, backend: String::from(BACKEND_IDENTIFIER), functions: preprocessed_contract_functions, - }) - }); - for contract in preprocessed_contracts? { + }, + debug_infos, + )) + }); + for (contract, debug_infos) in preprocessed_contracts? { save_contract_to_file( &contract, &format!("{}-{}", package.name, contract.name), &circuit_dir, ); + + if args.output_debug { + let debug_artifact = DebugArtifact::new(debug_infos, &context); + save_debug_artifact_to_file( + &debug_artifact, + &format!("{}-{}", package.name, contract.name), + &circuit_dir, + ); + } } } else { - let (_, program) = compile_package(backend, package, &args.compile_options)?; + let (context, program) = compile_package(backend, package, &args.compile_options)?; common_reference_string = update_common_reference_string(backend, &common_reference_string, &program.circuit) .map_err(CliError::CommonReferenceStringError)?; - let (preprocessed_program, _) = + let (preprocessed_program, debug_info) = preprocess_program(backend, args.include_keys, &common_reference_string, program) .map_err(CliError::ProofSystemCompilerError)?; save_program_to_file(&preprocessed_program, &package.name, &circuit_dir); + + if args.output_debug { + let debug_artifact = DebugArtifact::new(vec![debug_info], &context); + let circuit_name: String = (&package.name).into(); + save_debug_artifact_to_file(&debug_artifact, &circuit_name, &circuit_dir); + } } } @@ -167,9 +197,18 @@ pub(super) fn optimize_contract( backend: &B, contract: CompiledContract, ) -> Result> { - let functions = try_vecmap(contract.functions, |func| { - let optimized_bytecode = optimize_circuit(backend, func.bytecode)?.0; - Ok::<_, CliError>(ContractFunction { bytecode: optimized_bytecode, ..func }) + let functions = try_vecmap(contract.functions, |mut func| { + let (optimized_bytecode, opcode_labels) = optimize_circuit(backend, func.bytecode)?; + let opcode_ids = vecmap(opcode_labels, |label| match label { + OpcodeLabel::Unresolved => { + unreachable!("Compiled circuit opcodes must resolve to some index") + } + OpcodeLabel::Resolved(index) => index as usize, + }); + + func.bytecode = optimized_bytecode; + func.debug.update_acir(opcode_ids); + Ok::<_, CliError>(func) })?; Ok(CompiledContract { functions, ..contract }) diff --git a/crates/nargo_cli/src/cli/fs/program.rs b/crates/nargo_cli/src/cli/fs/program.rs index 311923a6686..3f7107de667 100644 --- a/crates/nargo_cli/src/cli/fs/program.rs +++ b/crates/nargo_cli/src/cli/fs/program.rs @@ -1,6 +1,8 @@ use std::path::{Path, PathBuf}; -use nargo::artifacts::{contract::PreprocessedContract, program::PreprocessedProgram}; +use nargo::artifacts::{ + contract::PreprocessedContract, debug::DebugArtifact, program::PreprocessedProgram, +}; use noirc_frontend::graph::CrateName; use crate::errors::FilesystemError; @@ -15,6 +17,7 @@ pub(crate) fn save_program_to_file>( let circuit_name: String = crate_name.into(); save_build_artifact_to_file(compiled_program, &circuit_name, circuit_dir) } + pub(crate) fn save_contract_to_file>( compiled_contract: &PreprocessedContract, circuit_name: &str, @@ -22,13 +25,23 @@ pub(crate) fn save_contract_to_file>( ) -> PathBuf { save_build_artifact_to_file(compiled_contract, circuit_name, circuit_dir) } + +pub(crate) fn save_debug_artifact_to_file>( + debug_artifact: &DebugArtifact, + circuit_name: &str, + circuit_dir: P, +) -> PathBuf { + let artifact_name = format!("debug_{}", circuit_name); + save_build_artifact_to_file(debug_artifact, &artifact_name, circuit_dir) +} + fn save_build_artifact_to_file, T: ?Sized + serde::Serialize>( build_artifact: &T, - circuit_name: &str, + artifact_name: &str, circuit_dir: P, ) -> PathBuf { create_named_dir(circuit_dir.as_ref(), "target"); - let circuit_path = circuit_dir.as_ref().join(circuit_name).with_extension("json"); + let circuit_path = circuit_dir.as_ref().join(artifact_name).with_extension("json"); write_to_file(&serde_json::to_vec(build_artifact).unwrap(), &circuit_path); diff --git a/crates/noirc_driver/src/contract.rs b/crates/noirc_driver/src/contract.rs index a25d258c9be..a1820ff2e47 100644 --- a/crates/noirc_driver/src/contract.rs +++ b/crates/noirc_driver/src/contract.rs @@ -1,6 +1,7 @@ use crate::program::{deserialize_circuit, serialize_circuit}; use acvm::acir::circuit::Circuit; use noirc_abi::Abi; +use noirc_errors::debug_info::DebugInfo; use serde::{Deserialize, Serialize}; /// Describes the types of smart contract functions that are allowed. @@ -47,6 +48,8 @@ pub struct ContractFunction { #[serde(serialize_with = "serialize_circuit", deserialize_with = "deserialize_circuit")] pub bytecode: Circuit, + + pub debug: DebugInfo, } impl ContractFunctionType { diff --git a/crates/noirc_driver/src/lib.rs b/crates/noirc_driver/src/lib.rs index 2919d2fd3ea..0e6a3c519b5 100644 --- a/crates/noirc_driver/src/lib.rs +++ b/crates/noirc_driver/src/lib.rs @@ -249,6 +249,7 @@ fn compile_contract( is_internal: func_meta.is_internal.unwrap_or(false), abi: function.abi, bytecode: function.circuit, + debug: function.debug, }); } diff --git a/crates/noirc_errors/src/debug_info.rs b/crates/noirc_errors/src/debug_info.rs index 3217dba7a38..0c05bee61d5 100644 --- a/crates/noirc_errors/src/debug_info.rs +++ b/crates/noirc_errors/src/debug_info.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::collections::BTreeMap; use crate::Location; use serde::{Deserialize, Serialize}; @@ -6,11 +6,11 @@ use serde::{Deserialize, Serialize}; #[derive(Default, Debug, Clone, Deserialize, Serialize)] pub struct DebugInfo { /// Map opcode index of an ACIR circuit into the source code location - pub locations: HashMap, + pub locations: BTreeMap, } impl DebugInfo { - pub fn new(locations: HashMap) -> Self { + pub fn new(locations: BTreeMap) -> Self { DebugInfo { locations } } @@ -24,7 +24,7 @@ impl DebugInfo { /// This is the case during fallback or width 'optimization' /// opcode_indices is this list of mixed indices pub fn update_acir(&mut self, opcode_indices: Vec) { - let mut new_locations = HashMap::new(); + let mut new_locations = BTreeMap::new(); for (i, idx) in opcode_indices.iter().enumerate() { if self.locations.contains_key(idx) { new_locations.insert(i, self.locations[idx]); diff --git a/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs b/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs index b425eab42d3..fd88921bb3d 100644 --- a/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs +++ b/crates/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs @@ -1,6 +1,6 @@ //! `GeneratedAcir` is constructed as part of the `acir_gen` pass to accumulate all of the ACIR //! program as it is being converted from SSA form. -use std::collections::HashMap; +use std::collections::BTreeMap; use crate::{ brillig::brillig_gen::brillig_directive, @@ -46,7 +46,7 @@ pub(crate) struct GeneratedAcir { pub(crate) input_witnesses: Vec, /// Correspondance between an opcode index (in opcodes) and the source code location which generated it - pub(crate) locations: HashMap, + pub(crate) locations: BTreeMap, /// Source code location of the current instruction being processed /// None if we do not know the location From cc2af74e586bbbba0c45aa0b7c9f9a9e6480f851 Mon Sep 17 00:00:00 2001 From: Alex Vitkov <44268717+alexvitkov@users.noreply.github.com> Date: Mon, 14 Aug 2023 18:07:00 +0300 Subject: [PATCH 09/14] fix(nargo)!: Remove `-p` short flag from the `--program-dir` flag (#2300) --- crates/nargo_cli/src/cli/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/src/cli/mod.rs b/crates/nargo_cli/src/cli/mod.rs index 2ab34c11e40..df5eed7b297 100644 --- a/crates/nargo_cli/src/cli/mod.rs +++ b/crates/nargo_cli/src/cli/mod.rs @@ -40,7 +40,7 @@ struct NargoCli { #[derive(Args, Clone, Debug)] pub(crate) struct NargoConfig { // REMINDER: Also change this flag in the LSP test lens if renamed - #[arg(short, long, hide=true, global=true, default_value_os_t = std::env::current_dir().unwrap())] + #[arg(long, hide=true, global=true, default_value_os_t = std::env::current_dir().unwrap())] program_dir: PathBuf, } From 87174ac4927c4e237a2d0dbd6290da309e9f70c0 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:42:13 +0100 Subject: [PATCH 10/14] fix: Require package names to be non-empty (#2293) Co-authored-by: Blaine Bublitz --- crates/nargo_cli/src/cli/init_cmd.rs | 17 ++++++---- crates/nargo_cli/src/cli/new_cmd.rs | 14 ++++++--- crates/nargo_cli/src/errors.rs | 3 ++ .../invalid_dependency_name/Nargo.toml | 8 +++++ .../invalid_dependency_name/src/main.nr | 1 + .../package_name_empty/Nargo.toml | 7 +++++ .../package_name_empty/src/main.nr | 1 + .../package_name_hyphen/Nargo.toml | 7 +++++ .../package_name_hyphen/src/main.nr | 1 + .../tests/test_libraries/bad_name/Nargo.toml | 7 +++++ .../tests/test_libraries/bad_name/src/lib.nr | 0 crates/nargo_toml/src/errors.rs | 8 +++-- crates/nargo_toml/src/lib.rs | 10 ++++-- crates/noirc_frontend/src/graph/mod.rs | 31 ++++++++++++++++--- 14 files changed, 96 insertions(+), 19 deletions(-) create mode 100644 crates/nargo_cli/tests/compile_failure/invalid_dependency_name/Nargo.toml create mode 100644 crates/nargo_cli/tests/compile_failure/invalid_dependency_name/src/main.nr create mode 100644 crates/nargo_cli/tests/compile_failure/package_name_empty/Nargo.toml create mode 100644 crates/nargo_cli/tests/compile_failure/package_name_empty/src/main.nr create mode 100644 crates/nargo_cli/tests/compile_failure/package_name_hyphen/Nargo.toml create mode 100644 crates/nargo_cli/tests/compile_failure/package_name_hyphen/src/main.nr create mode 100644 crates/nargo_cli/tests/test_libraries/bad_name/Nargo.toml create mode 100644 crates/nargo_cli/tests/test_libraries/bad_name/src/lib.nr diff --git a/crates/nargo_cli/src/cli/init_cmd.rs b/crates/nargo_cli/src/cli/init_cmd.rs index d6ad172ce26..e6020e3cfd9 100644 --- a/crates/nargo_cli/src/cli/init_cmd.rs +++ b/crates/nargo_cli/src/cli/init_cmd.rs @@ -6,6 +6,7 @@ use acvm::Backend; use clap::Args; use nargo::constants::{PKG_FILE, SRC_DIR}; use nargo::package::PackageType; +use noirc_frontend::graph::CrateName; use std::path::PathBuf; /// Create a Noir project in the current directory. @@ -13,7 +14,7 @@ use std::path::PathBuf; pub(crate) struct InitCommand { /// Name of the package [default: current directory name] #[clap(long)] - name: Option, + name: Option, /// Use a library template #[arg(long, conflicts_with = "bin", conflicts_with = "contract")] @@ -67,9 +68,13 @@ pub(crate) fn run( args: InitCommand, config: NargoConfig, ) -> Result<(), CliError> { - let package_name = args - .name - .unwrap_or_else(|| config.program_dir.file_name().unwrap().to_str().unwrap().to_owned()); + let package_name = match args.name { + Some(name) => name, + None => { + let name = config.program_dir.file_name().unwrap().to_str().unwrap(); + name.parse().map_err(|_| CliError::InvalidPackageName(name.into()))? + } + }; let package_type = if args.lib { PackageType::Library @@ -78,14 +83,14 @@ pub(crate) fn run( } else { PackageType::Binary }; - initialize_project(config.program_dir, &package_name, package_type); + initialize_project(config.program_dir, package_name, package_type); Ok(()) } /// Initializes a new Noir project in `package_dir`. pub(crate) fn initialize_project( package_dir: PathBuf, - package_name: &str, + package_name: CrateName, package_type: PackageType, ) { let src_dir = package_dir.join(SRC_DIR); diff --git a/crates/nargo_cli/src/cli/new_cmd.rs b/crates/nargo_cli/src/cli/new_cmd.rs index dbdeddef712..d6a9d00257b 100644 --- a/crates/nargo_cli/src/cli/new_cmd.rs +++ b/crates/nargo_cli/src/cli/new_cmd.rs @@ -4,6 +4,7 @@ use super::{init_cmd::initialize_project, NargoConfig}; use acvm::Backend; use clap::Args; use nargo::package::PackageType; +use noirc_frontend::graph::CrateName; use std::path::PathBuf; /// Create a Noir project in a new directory. @@ -14,7 +15,7 @@ pub(crate) struct NewCommand { /// Name of the package [default: package directory name] #[clap(long)] - name: Option, + name: Option, /// Use a library template #[arg(long, conflicts_with = "bin", conflicts_with = "contract")] @@ -41,8 +42,13 @@ pub(crate) fn run( return Err(CliError::DestinationAlreadyExists(package_dir)); } - let package_name = - args.name.unwrap_or_else(|| args.path.file_name().unwrap().to_str().unwrap().to_owned()); + let package_name = match args.name { + Some(name) => name, + None => { + let name = args.path.file_name().unwrap().to_str().unwrap(); + name.parse().map_err(|_| CliError::InvalidPackageName(name.into()))? + } + }; let package_type = if args.lib { PackageType::Library } else if args.contract { @@ -50,6 +56,6 @@ pub(crate) fn run( } else { PackageType::Binary }; - initialize_project(package_dir, &package_name, package_type); + initialize_project(package_dir, package_name, package_type); Ok(()) } diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index d801a56d3f5..dade4262431 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -41,6 +41,9 @@ pub(crate) enum CliError { #[error("Failed to verify proof {}", .0.display())] InvalidProof(PathBuf), + #[error("Invalid package name {0}. Did you mean to use `--name`?")] + InvalidPackageName(String), + /// ABI encoding/decoding error #[error(transparent)] AbiError(#[from] AbiError), diff --git a/crates/nargo_cli/tests/compile_failure/invalid_dependency_name/Nargo.toml b/crates/nargo_cli/tests/compile_failure/invalid_dependency_name/Nargo.toml new file mode 100644 index 00000000000..69b56a2e7d0 --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/invalid_dependency_name/Nargo.toml @@ -0,0 +1,8 @@ +[package] +name = "invalid_dependency_name" +type = "bin" +authors = [""] +compiler_version = "0.9.0" + +[dependencies] +bad_name = { path = "../../test_libraries/bad_name" } diff --git a/crates/nargo_cli/tests/compile_failure/invalid_dependency_name/src/main.nr b/crates/nargo_cli/tests/compile_failure/invalid_dependency_name/src/main.nr new file mode 100644 index 00000000000..faf1ba0045a --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/invalid_dependency_name/src/main.nr @@ -0,0 +1 @@ +fn main(x: Field) { } diff --git a/crates/nargo_cli/tests/compile_failure/package_name_empty/Nargo.toml b/crates/nargo_cli/tests/compile_failure/package_name_empty/Nargo.toml new file mode 100644 index 00000000000..7c4dbd0c994 --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/package_name_empty/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "" +type = "bin" +authors = [""] +compiler_version = "0.9.0" + +[dependencies] diff --git a/crates/nargo_cli/tests/compile_failure/package_name_empty/src/main.nr b/crates/nargo_cli/tests/compile_failure/package_name_empty/src/main.nr new file mode 100644 index 00000000000..faf1ba0045a --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/package_name_empty/src/main.nr @@ -0,0 +1 @@ +fn main(x: Field) { } diff --git a/crates/nargo_cli/tests/compile_failure/package_name_hyphen/Nargo.toml b/crates/nargo_cli/tests/compile_failure/package_name_hyphen/Nargo.toml new file mode 100644 index 00000000000..f8d0a85db4a --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/package_name_hyphen/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "hyphenated-name" +type = "bin" +authors = [""] +compiler_version = "0.9.0" + +[dependencies] diff --git a/crates/nargo_cli/tests/compile_failure/package_name_hyphen/src/main.nr b/crates/nargo_cli/tests/compile_failure/package_name_hyphen/src/main.nr new file mode 100644 index 00000000000..faf1ba0045a --- /dev/null +++ b/crates/nargo_cli/tests/compile_failure/package_name_hyphen/src/main.nr @@ -0,0 +1 @@ +fn main(x: Field) { } diff --git a/crates/nargo_cli/tests/test_libraries/bad_name/Nargo.toml b/crates/nargo_cli/tests/test_libraries/bad_name/Nargo.toml new file mode 100644 index 00000000000..313e2411e83 --- /dev/null +++ b/crates/nargo_cli/tests/test_libraries/bad_name/Nargo.toml @@ -0,0 +1,7 @@ +[package] +name = "bad-name" +type = "lib" +authors = [""] +compiler_version = "0.7.1" + +[dependencies] diff --git a/crates/nargo_cli/tests/test_libraries/bad_name/src/lib.nr b/crates/nargo_cli/tests/test_libraries/bad_name/src/lib.nr new file mode 100644 index 00000000000..e69de29bb2d diff --git a/crates/nargo_toml/src/errors.rs b/crates/nargo_toml/src/errors.rs index 42c5a59cba6..e986a181e43 100644 --- a/crates/nargo_toml/src/errors.rs +++ b/crates/nargo_toml/src/errors.rs @@ -38,9 +38,11 @@ pub enum ManifestError { )] MissingDefaultEntryFile { toml: PathBuf, entry: PathBuf, package_type: PackageType }, - /// Invalid character `-` in package name - #[error("invalid character `-` in package name")] - InvalidPackageName, + #[error("{} found in {toml}", if name.is_empty() { "Empty package name".into() } else { format!("Invalid package name `{name}`") })] + InvalidPackageName { toml: PathBuf, name: String }, + + #[error("{} found in {toml}", if name.is_empty() { "Empty dependency name".into() } else { format!("Invalid dependency name `{name}`") })] + InvalidDependencyName { toml: PathBuf, name: String }, /// Encountered error while downloading git repository. #[error("{0}")] diff --git a/crates/nargo_toml/src/lib.rs b/crates/nargo_toml/src/lib.rs index 4a9238ee021..0e05a0a7901 100644 --- a/crates/nargo_toml/src/lib.rs +++ b/crates/nargo_toml/src/lib.rs @@ -72,14 +72,20 @@ struct PackageConfig { impl PackageConfig { fn resolve_to_package(&self, root_dir: &Path) -> Result { let name = if let Some(name) = &self.package.name { - name.parse().map_err(|_| ManifestError::InvalidPackageName)? + name.parse().map_err(|_| ManifestError::InvalidPackageName { + toml: root_dir.join("Nargo.toml"), + name: name.into(), + })? } else { return Err(ManifestError::MissingNameField { toml: root_dir.join("Nargo.toml") }); }; let mut dependencies: BTreeMap = BTreeMap::new(); for (name, dep_config) in self.dependencies.iter() { - let name = name.parse().map_err(|_| ManifestError::InvalidPackageName)?; + let name = name.parse().map_err(|_| ManifestError::InvalidDependencyName { + toml: root_dir.join("Nargo.toml"), + name: name.into(), + })?; let resolved_dep = dep_config.resolve_to_dependency(root_dir)?; dependencies.insert(name, resolved_dep); diff --git a/crates/noirc_frontend/src/graph/mod.rs b/crates/noirc_frontend/src/graph/mod.rs index 2c251432e9b..7a1daef45fd 100644 --- a/crates/noirc_frontend/src/graph/mod.rs +++ b/crates/noirc_frontend/src/graph/mod.rs @@ -29,6 +29,12 @@ impl CrateId { #[derive(Debug, Clone, PartialEq, Eq, Hash, Ord, PartialOrd)] pub struct CrateName(SmolStr); +impl CrateName { + fn is_valid_name(name: &str) -> bool { + !name.is_empty() && name.chars().all(|n| !CHARACTER_BLACK_LIST.contains(&n)) + } +} + impl Display for CrateName { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { self.0.fmt(f) @@ -54,11 +60,28 @@ impl FromStr for CrateName { type Err = String; fn from_str(name: &str) -> Result { - let is_invalid = name.chars().any(|n| CHARACTER_BLACK_LIST.contains(&n)); - if is_invalid { - Err(name.into()) - } else { + if Self::is_valid_name(name) { Ok(Self(SmolStr::new(name))) + } else { + Err("Package names must be non-empty and cannot contain hyphens".into()) + } + } +} + +#[cfg(test)] +mod crate_name { + use super::{CrateName, CHARACTER_BLACK_LIST}; + + #[test] + fn it_rejects_empty_string() { + assert!(!CrateName::is_valid_name("")); + } + + #[test] + fn it_rejects_blacklisted_chars() { + for bad_char in CHARACTER_BLACK_LIST { + let bad_char_string = bad_char.to_string(); + assert!(!CrateName::is_valid_name(&bad_char_string)); } } } From 094aef191a3eafeccba714823e43d8e73ede8f50 Mon Sep 17 00:00:00 2001 From: Yordan Madzhunkov <52652109+yordanmadzhunkov@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:36:59 +0300 Subject: [PATCH 11/14] fix: Fix 3 parser test cases in parsing (#2284) Co-authored-by: Yordan Madzhunkov --- crates/noirc_errors/src/reporter.rs | 2 +- crates/noirc_frontend/src/parser/parser.rs | 66 +++++++++++++++------- 2 files changed, 47 insertions(+), 21 deletions(-) diff --git a/crates/noirc_errors/src/reporter.rs b/crates/noirc_errors/src/reporter.rs index 23b6970a913..6a595e5d4f6 100644 --- a/crates/noirc_errors/src/reporter.rs +++ b/crates/noirc_errors/src/reporter.rs @@ -75,7 +75,7 @@ impl CustomDiagnostic { matches!(self.kind, DiagnosticKind::Error) } - pub fn is_warrning(&self) -> bool { + pub fn is_warning(&self) -> bool { matches!(self.kind, DiagnosticKind::Warning) } } diff --git a/crates/noirc_frontend/src/parser/parser.rs b/crates/noirc_frontend/src/parser/parser.rs index efa4e694cdc..0c95af77a5a 100644 --- a/crates/noirc_frontend/src/parser/parser.rs +++ b/crates/noirc_frontend/src/parser/parser.rs @@ -1468,16 +1468,33 @@ mod test { { vecmap(programs, move |program| { let message = format!("Failed to parse:\n{}", program); - let (op_t, errors) = parse_recover(&parser, program); - for e in errors { - if !e.is_warrning() { - panic!("{}", &message); + let (op_t, diagnostics) = parse_recover(&parser, program); + diagnostics.iter().for_each(|diagnostic| { + if diagnostic.is_error() { + panic!("{} with error {}", &message, diagnostic); } - } + }); op_t.expect(&message) }) } + fn parse_all_warnings(parser: P, programs: Vec<&str>) -> Vec + where + P: NoirParser, + T: std::fmt::Display, + { + programs + .into_iter() + .flat_map(|program| { + let (_expr, diagnostics) = parse_recover(&parser, program); + diagnostics.iter().for_each(|diagnostic| if diagnostic.is_error() { + unreachable!("Expected this input to pass with warning:\n{program}\nYet it failed with error:\n{diagnostic}") + }); + diagnostics + }) + .collect() + } + fn parse_all_failing(parser: P, programs: Vec<&str>) -> Vec where P: NoirParser, @@ -1486,11 +1503,21 @@ mod test { programs .into_iter() .flat_map(|program| match parse_with(&parser, program) { - Ok(expr) => unreachable!( - "Expected this input to fail:\n{}\nYet it successfully parsed as:\n{}", - program, expr - ), - Err(error) => error, + Ok(expr) => { + unreachable!( + "Expected this input to fail:\n{}\nYet it successfully parsed as:\n{}", + program, expr + ) + } + Err(diagnostics) => { + if diagnostics.iter().all(|diagnostic: &CustomDiagnostic| diagnostic.is_warning()) { + unreachable!( + "Expected at least one error when parsing:\n{}\nYet it successfully parsed without errors:\n", + program + ) + }; + diagnostics + } }) .collect() } @@ -1679,7 +1706,7 @@ mod test { // The first (inner) `==` is a predicate which returns 0/1 // The outer layer is an infix `==` which is // associated with the Constrain statement - let errors = parse_all_failing( + let errors = parse_all_warnings( constrain(expression()), vec![ "constrain ((x + y) == k) + z == y", @@ -1690,7 +1717,9 @@ mod test { ], ); assert_eq!(errors.len(), 5); - assert!(errors.iter().all(|err| { format!("{}", err).contains("deprecated") })); + assert!(errors + .iter() + .all(|err| { err.is_warning() && format!("{}", err).contains("deprecated") })) } /// This is the standard way to declare an assert statement @@ -1784,6 +1813,8 @@ mod test { "fn f(f: pub Field, y : Field, z : comptime Field) -> u8 { x + a }", "fn f(f: pub Field, y : T, z : comptime Field) -> u8 { x + a }", "fn func_name(f: Field, y : T) where T: SomeTrait {}", + // The following should produce compile error on later stage. From the parser's perspective it's fine + "fn func_name(f: Field, y : Field, z : Field) where T: SomeTrait {}", ], ); @@ -1798,9 +1829,6 @@ mod test { "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where SomeTrait {}", "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) SomeTrait {}", "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where T: SomeTrait {}", - // TODO(GenericParameterNotFoundInFunction) - // Consider making this a compilation error: - // "fn func_name(f: Field, y : pub Field, z : pub [u8;5],) where T: SomeTrait {}", ], ); } @@ -1820,6 +1848,9 @@ mod test { "trait TraitWithAssociatedType { type Element; fn item(self, index: Field) -> Self::Element; }", "trait TraitWithAssociatedConstant { let Size: Field; }", "trait TraitWithAssociatedConstantWithDefaultValue { let Size: Field = 10; }", + "trait GenericTrait { fn elem(&mut self, index: Field) -> T; }", + "trait GenericTraitWithConstraints where T: SomeTrait { fn elem(self, index: Field) -> T; }", + "trait TraitWithMultipleGenericParams where A: SomeTrait, B: AnotherTrait { let Size: Field; fn zero() -> Self; }", ], ); @@ -1829,11 +1860,6 @@ mod test { "trait MissingBody", "trait WrongDelimiter { fn foo() -> u8, fn bar() -> u8 }", "trait WhereClauseWithoutGenerics where A: SomeTrait { }", - // TODO: when implemnt generics in traits the following 3 should pass - "trait GenericTrait { fn elem(&mut self, index: Field) -> T; }", - "trait GenericTraitWithConstraints where T: SomeTrait { fn elem(self, index: Field) -> T; }", - "trait TraitWithMultipleGenericParams where A: SomeTrait, B: AnotherTrait { comptime Size: Field; fn zero() -> Self; }", - ], ); } From ed62b5be6f246f66bb56525652d3354a176765f1 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 14 Aug 2023 13:07:26 -0700 Subject: [PATCH 12/14] chore(frontend): Replace `ModuleOrigin` with `Location` on `ModuleData` (#2308) --- .../src/hir/def_collector/dc_crate.rs | 6 +-- .../src/hir/def_collector/dc_mod.rs | 7 ++-- crates/noirc_frontend/src/hir/def_map/mod.rs | 15 +++---- .../src/hir/def_map/module_data.rs | 39 ++----------------- .../src/hir/resolution/resolver.rs | 8 ++-- .../noirc_frontend/src/hir/type_check/mod.rs | 5 ++- .../src/monomorphization/mod.rs | 8 ++-- 7 files changed, 28 insertions(+), 60 deletions(-) diff --git a/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs b/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs index e256bbd8cb8..ac83e81ea71 100644 --- a/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs +++ b/crates/noirc_frontend/src/hir/def_collector/dc_crate.rs @@ -137,7 +137,7 @@ impl DefCollector { let current_def_map = context.def_maps.get(&crate_id).unwrap(); errors.extend(vecmap(unresolved_imports, |(error, module_id)| { - let file_id = current_def_map.modules[module_id.0].origin.file_id(); + let file_id = current_def_map.file_id(module_id); let error = DefCollectorErrorKind::PathResolutionError(error); error.into_file_diagnostic(file_id) })); @@ -229,7 +229,7 @@ fn collect_impls( let path_resolver = StandardPathResolver::new(ModuleId { local_id: *module_id, krate: crate_id }); - let file = def_maps[&crate_id].module_file_id(*module_id); + let file = def_maps[&crate_id].file_id(*module_id); for (generics, span, unresolved) in methods { let mut resolver = Resolver::new(interner, &path_resolver, def_maps, file); @@ -425,7 +425,7 @@ fn resolve_impls( let path_resolver = StandardPathResolver::new(ModuleId { local_id: module_id, krate: crate_id }); - let file = def_maps[&crate_id].module_file_id(module_id); + let file = def_maps[&crate_id].file_id(module_id); for (generics, _, functions) in methods { let mut resolver = Resolver::new(interner, &path_resolver, def_maps, file); diff --git a/crates/noirc_frontend/src/hir/def_collector/dc_mod.rs b/crates/noirc_frontend/src/hir/def_collector/dc_mod.rs index 545375dc64a..53ed397e647 100644 --- a/crates/noirc_frontend/src/hir/def_collector/dc_mod.rs +++ b/crates/noirc_frontend/src/hir/def_collector/dc_mod.rs @@ -1,5 +1,5 @@ use fm::FileId; -use noirc_errors::FileDiagnostic; +use noirc_errors::{FileDiagnostic, Location}; use crate::{ graph::CrateId, hir::def_collector::dc_crate::UnresolvedStruct, node_interner::StructId, @@ -11,7 +11,7 @@ use super::{ dc_crate::{DefCollector, UnresolvedFunctions, UnresolvedGlobal, UnresolvedTypeAlias}, errors::{DefCollectorErrorKind, DuplicateType}, }; -use crate::hir::def_map::{parse_file, LocalModuleId, ModuleData, ModuleId, ModuleOrigin}; +use crate::hir::def_map::{parse_file, LocalModuleId, ModuleData, ModuleId}; use crate::hir::resolution::import::ImportDirective; use crate::hir::Context; @@ -315,7 +315,8 @@ impl<'a> ModCollector<'a> { errors: &mut Vec, ) -> Option { let parent = Some(self.module_id); - let new_module = ModuleData::new(parent, ModuleOrigin::File(file_id), is_contract); + let location = Location::new(mod_name.span(), file_id); + let new_module = ModuleData::new(parent, location, is_contract); let module_id = self.def_collector.def_map.modules.insert(new_module); let modules = &mut self.def_collector.def_map.modules; diff --git a/crates/noirc_frontend/src/hir/def_map/mod.rs b/crates/noirc_frontend/src/hir/def_map/mod.rs index b32f332bd25..f264d3f40b8 100644 --- a/crates/noirc_frontend/src/hir/def_map/mod.rs +++ b/crates/noirc_frontend/src/hir/def_map/mod.rs @@ -6,7 +6,7 @@ use crate::parser::{parse_program, ParsedModule}; use crate::token::Attribute; use arena::{Arena, Index}; use fm::{FileId, FileManager}; -use noirc_errors::FileDiagnostic; +use noirc_errors::{FileDiagnostic, Location}; use std::collections::HashMap; mod module_def; @@ -87,8 +87,8 @@ impl CrateDefMap { // Allocate a default Module for the root, giving it a ModuleId let mut modules: Arena = Arena::default(); - let origin = ModuleOrigin::CrateRoot(root_file_id); - let root = modules.insert(ModuleData::new(None, origin, false)); + let location = Location::new(Default::default(), root_file_id); + let root = modules.insert(ModuleData::new(None, location, false)); let def_map = CrateDefMap { root: LocalModuleId(root), @@ -120,13 +120,8 @@ impl CrateDefMap { root_module.find_func_with_name(&MAIN_FUNCTION.into()) } - pub fn root_file_id(&self) -> FileId { - let root_module = &self.modules()[self.root.0]; - root_module.origin.into() - } - - pub fn module_file_id(&self, module_id: LocalModuleId) -> FileId { - self.modules[module_id.0].origin.file_id() + pub fn file_id(&self, module_id: LocalModuleId) -> FileId { + self.modules[module_id.0].location.file } /// Go through all modules in this crate, and find all functions in diff --git a/crates/noirc_frontend/src/hir/def_map/module_data.rs b/crates/noirc_frontend/src/hir/def_map/module_data.rs index 5b93d04fea7..5382ca6ad15 100644 --- a/crates/noirc_frontend/src/hir/def_map/module_data.rs +++ b/crates/noirc_frontend/src/hir/def_map/module_data.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use fm::FileId; +use noirc_errors::Location; use crate::{ node_interner::{FuncId, StmtId, StructId, TypeAliasId}, @@ -23,24 +23,20 @@ pub struct ModuleData { /// Contains only the definitions directly defined in the current module definitions: ItemScope, - pub origin: ModuleOrigin, + pub location: Location, /// True if this module is a `contract Foo { ... }` module containing contract functions pub is_contract: bool, } impl ModuleData { - pub fn new( - parent: Option, - origin: ModuleOrigin, - is_contract: bool, - ) -> ModuleData { + pub fn new(parent: Option, location: Location, is_contract: bool) -> ModuleData { ModuleData { parent, children: HashMap::new(), scope: ItemScope::default(), definitions: ItemScope::default(), - origin, + location, is_contract, } } @@ -99,30 +95,3 @@ impl ModuleData { self.definitions.values().values().map(|(id, _)| *id) } } - -#[derive(Debug, PartialEq, Eq, Copy, Clone)] -pub enum ModuleOrigin { - CrateRoot(FileId), - File(FileId), -} - -impl ModuleOrigin { - pub fn file_id(&self) -> FileId { - match self { - ModuleOrigin::CrateRoot(file_id) => *file_id, - ModuleOrigin::File(file_id) => *file_id, - } - } -} - -impl From for FileId { - fn from(origin: ModuleOrigin) -> Self { - origin.file_id() - } -} - -impl Default for ModuleOrigin { - fn default() -> Self { - ModuleOrigin::CrateRoot(FileId::default()) - } -} diff --git a/crates/noirc_frontend/src/hir/resolution/resolver.rs b/crates/noirc_frontend/src/hir/resolution/resolver.rs index 4bfb5428ed7..a2f675542c2 100644 --- a/crates/noirc_frontend/src/hir/resolution/resolver.rs +++ b/crates/noirc_frontend/src/hir/resolution/resolver.rs @@ -1485,8 +1485,9 @@ mod test { use fm::FileId; use iter_extended::vecmap; + use noirc_errors::Location; - use crate::hir::def_map::{ModuleData, ModuleId, ModuleOrigin}; + use crate::hir::def_map::{ModuleData, ModuleId}; use crate::hir::resolution::errors::ResolverError; use crate::hir::resolution::import::PathResolutionError; use crate::hir::resolution::resolver::StmtId; @@ -1520,7 +1521,8 @@ mod test { let file = FileId::default(); let mut modules = arena::Arena::new(); - modules.insert(ModuleData::new(None, ModuleOrigin::File(file), false)); + let location = Location::new(Default::default(), file); + modules.insert(ModuleData::new(None, location, false)); let path_resolver = TestPathResolver(HashMap::new()); @@ -1924,7 +1926,7 @@ mod test { fn main() { let string = f"this is i: {i}"; println(string); - + println(f"I want to print {0}"); let new_val = 10; diff --git a/crates/noirc_frontend/src/hir/type_check/mod.rs b/crates/noirc_frontend/src/hir/type_check/mod.rs index 8768120af2f..484d668af64 100644 --- a/crates/noirc_frontend/src/hir/type_check/mod.rs +++ b/crates/noirc_frontend/src/hir/type_check/mod.rs @@ -137,7 +137,7 @@ mod test { use noirc_errors::{Location, Span}; use crate::graph::CrateId; - use crate::hir::def_map::{ModuleData, ModuleId, ModuleOrigin}; + use crate::hir::def_map::{ModuleData, ModuleId}; use crate::hir::resolution::import::PathResolutionError; use crate::hir_def::expr::HirIdent; use crate::hir_def::stmt::HirLetStatement; @@ -380,7 +380,8 @@ mod test { let file = FileId::default(); let mut modules = arena::Arena::new(); - modules.insert(ModuleData::new(None, ModuleOrigin::File(file), false)); + let location = Location::new(Default::default(), file); + modules.insert(ModuleData::new(None, location, false)); def_maps.insert( CrateId::dummy_id(), diff --git a/crates/noirc_frontend/src/monomorphization/mod.rs b/crates/noirc_frontend/src/monomorphization/mod.rs index 783d9f3133e..998f3093d49 100644 --- a/crates/noirc_frontend/src/monomorphization/mod.rs +++ b/crates/noirc_frontend/src/monomorphization/mod.rs @@ -1303,13 +1303,12 @@ mod tests { use fm::FileId; use iter_extended::vecmap; + use noirc_errors::Location; use crate::{ graph::CrateId, hir::{ - def_map::{ - CrateDefMap, LocalModuleId, ModuleData, ModuleDefId, ModuleId, ModuleOrigin, - }, + def_map::{CrateDefMap, LocalModuleId, ModuleData, ModuleDefId, ModuleId}, resolution::{ import::PathResolutionError, path_resolver::PathResolver, resolver::Resolver, }, @@ -1349,7 +1348,8 @@ mod tests { let file = FileId::default(); let mut modules = arena::Arena::new(); - modules.insert(ModuleData::new(None, ModuleOrigin::File(file), false)); + let location = Location::new(Default::default(), file); + modules.insert(ModuleData::new(None, location, false)); def_maps.insert( CrateId::dummy_id(), From d6deb0c96bf8a12e21881bf10bbd139bc6531796 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Mon, 14 Aug 2023 15:41:35 -0700 Subject: [PATCH 13/14] feat(nargo): Add `--workspace` flag to run commands in every package (#2313) --- crates/lsp/src/lib.rs | 6 +-- crates/nargo_cli/src/cli/check_cmd.rs | 13 +++-- .../nargo_cli/src/cli/codegen_verifier_cmd.rs | 13 +++-- crates/nargo_cli/src/cli/compile_cmd.rs | 13 +++-- crates/nargo_cli/src/cli/execute_cmd.rs | 13 +++-- crates/nargo_cli/src/cli/info_cmd.rs | 13 +++-- crates/nargo_cli/src/cli/prove_cmd.rs | 13 +++-- crates/nargo_cli/src/cli/test_cmd.rs | 13 +++-- crates/nargo_cli/src/cli/verify_cmd.rs | 13 +++-- crates/nargo_toml/src/lib.rs | 51 ++++++++++++------- 10 files changed, 117 insertions(+), 44 deletions(-) diff --git a/crates/lsp/src/lib.rs b/crates/lsp/src/lib.rs index b0768ccdeaa..e6608e84625 100644 --- a/crates/lsp/src/lib.rs +++ b/crates/lsp/src/lib.rs @@ -19,7 +19,7 @@ use lsp_types::{ PublishDiagnosticsParams, Range, ServerCapabilities, TextDocumentSyncOptions, }; use nargo::prepare_package; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::check_crate; use noirc_errors::{DiagnosticKind, FileDiagnostic}; use noirc_frontend::hir::FunctionNameMatch; @@ -156,7 +156,7 @@ fn on_code_lens_request( return future::ready(Ok(None)); } }; - let workspace = match resolve_workspace_from_toml(&toml_path, None) { + let workspace = match resolve_workspace_from_toml(&toml_path, PackageSelection::All) { Ok(workspace) => workspace, Err(err) => { // If we found a manifest, but the workspace is invalid, we raise an error about it @@ -281,7 +281,7 @@ fn on_did_save_text_document( return ControlFlow::Continue(()); } }; - let workspace = match resolve_workspace_from_toml(&toml_path, None) { + let workspace = match resolve_workspace_from_toml(&toml_path, PackageSelection::All) { Ok(workspace) => workspace, Err(err) => { // If we found a manifest, but the workspace is invalid, we raise an error about it diff --git a/crates/nargo_cli/src/cli/check_cmd.rs b/crates/nargo_cli/src/cli/check_cmd.rs index a1b5018d334..4364c78a6dc 100644 --- a/crates/nargo_cli/src/cli/check_cmd.rs +++ b/crates/nargo_cli/src/cli/check_cmd.rs @@ -3,7 +3,7 @@ use acvm::Backend; use clap::Args; use iter_extended::btree_map; use nargo::{package::Package, prepare_package}; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME}; use noirc_driver::{check_crate, compute_function_signature, CompileOptions}; use noirc_frontend::{ @@ -18,9 +18,13 @@ use super::NargoConfig; #[derive(Debug, Clone, Args)] pub(crate) struct CheckCommand { /// The name of the package to check - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Check all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -31,7 +35,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; for package in &workspace { check_package(package, &args.compile_options)?; diff --git a/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs b/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs index bc7e1c80c0f..2a6cec1534a 100644 --- a/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs +++ b/crates/nargo_cli/src/cli/codegen_verifier_cmd.rs @@ -20,7 +20,7 @@ use nargo::{ ops::{codegen_verifier, preprocess_program}, package::Package, }; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::CompileOptions; use noirc_frontend::graph::CrateName; @@ -28,9 +28,13 @@ use noirc_frontend::graph::CrateName; #[derive(Debug, Clone, Args)] pub(crate) struct CodegenVerifierCommand { /// The name of the package to codegen - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Codegen all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -41,7 +45,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; for package in &workspace { let circuit_build_path = workspace.package_build_path(package); diff --git a/crates/nargo_cli/src/cli/compile_cmd.rs b/crates/nargo_cli/src/cli/compile_cmd.rs index 2a6f802f748..08a24091a59 100644 --- a/crates/nargo_cli/src/cli/compile_cmd.rs +++ b/crates/nargo_cli/src/cli/compile_cmd.rs @@ -6,7 +6,7 @@ use nargo::artifacts::debug::DebugArtifact; use nargo::package::Package; use nargo::prepare_package; use nargo::{artifacts::contract::PreprocessedContract, NargoError}; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{ compile_contracts, compile_main, CompileOptions, CompiledContract, CompiledProgram, ErrorsAndWarnings, Warnings, @@ -46,9 +46,13 @@ pub(crate) struct CompileCommand { output_debug: bool, /// The name of the package to compile - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Compile all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -59,7 +63,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let circuit_dir = workspace.target_directory_path(); let mut common_reference_string = read_cached_common_reference_string(); diff --git a/crates/nargo_cli/src/cli/execute_cmd.rs b/crates/nargo_cli/src/cli/execute_cmd.rs index 1f0095fed5a..82455ea3163 100644 --- a/crates/nargo_cli/src/cli/execute_cmd.rs +++ b/crates/nargo_cli/src/cli/execute_cmd.rs @@ -5,7 +5,7 @@ use clap::Args; use nargo::constants::PROVER_INPUT_FILE; use nargo::package::Package; use nargo::NargoError; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_abi::input_parser::{Format, InputValue}; use noirc_abi::{Abi, InputMap}; use noirc_driver::{CompileOptions, CompiledProgram}; @@ -29,9 +29,13 @@ pub(crate) struct ExecuteCommand { prover_name: String, /// The name of the package to execute - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Execute all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -42,7 +46,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let witness_dir = &workspace.target_directory_path(); for package in &workspace { diff --git a/crates/nargo_cli/src/cli/info_cmd.rs b/crates/nargo_cli/src/cli/info_cmd.rs index a2900a6e249..48ccd76f9cd 100644 --- a/crates/nargo_cli/src/cli/info_cmd.rs +++ b/crates/nargo_cli/src/cli/info_cmd.rs @@ -2,7 +2,7 @@ use acvm::Backend; use clap::Args; use iter_extended::try_vecmap; use nargo::{package::Package, prepare_package}; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{compile_contracts, CompileOptions}; use noirc_frontend::graph::CrateName; use prettytable::{row, Table}; @@ -22,9 +22,13 @@ use super::{ #[derive(Debug, Clone, Args)] pub(crate) struct InfoCommand { /// The name of the package to detail - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Detail all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -35,7 +39,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let mut package_table = Table::new(); package_table.add_row( diff --git a/crates/nargo_cli/src/cli/prove_cmd.rs b/crates/nargo_cli/src/cli/prove_cmd.rs index 018e150f89f..66129f8748f 100644 --- a/crates/nargo_cli/src/cli/prove_cmd.rs +++ b/crates/nargo_cli/src/cli/prove_cmd.rs @@ -6,7 +6,7 @@ use nargo::artifacts::program::PreprocessedProgram; use nargo::constants::{PROVER_INPUT_FILE, VERIFIER_INPUT_FILE}; use nargo::ops::{preprocess_program, prove_execution, verify_proof}; use nargo::package::Package; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_abi::input_parser::Format; use noirc_driver::CompileOptions; use noirc_frontend::graph::CrateName; @@ -40,9 +40,13 @@ pub(crate) struct ProveCommand { verify: bool, /// The name of the package to prove - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Prove all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -53,7 +57,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let proof_dir = workspace.proofs_directory_path(); for package in &workspace { diff --git a/crates/nargo_cli/src/cli/test_cmd.rs b/crates/nargo_cli/src/cli/test_cmd.rs index 95d7f907196..bdce8e35096 100644 --- a/crates/nargo_cli/src/cli/test_cmd.rs +++ b/crates/nargo_cli/src/cli/test_cmd.rs @@ -3,7 +3,7 @@ use std::io::Write; use acvm::{acir::native_types::WitnessMap, Backend}; use clap::Args; use nargo::{ops::execute_circuit, package::Package, prepare_package}; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_driver::{compile_no_check, CompileOptions}; use noirc_frontend::{ graph::CrateName, @@ -31,9 +31,13 @@ pub(crate) struct TestCommand { exact: bool, /// The name of the package to test - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Test all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -44,7 +48,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let pattern = match &args.test_name { Some(name) => { diff --git a/crates/nargo_cli/src/cli/verify_cmd.rs b/crates/nargo_cli/src/cli/verify_cmd.rs index 5af28b4e25b..5319d7a4f39 100644 --- a/crates/nargo_cli/src/cli/verify_cmd.rs +++ b/crates/nargo_cli/src/cli/verify_cmd.rs @@ -18,7 +18,7 @@ use clap::Args; use nargo::constants::{PROOF_EXT, VERIFIER_INPUT_FILE}; use nargo::ops::{preprocess_program, verify_proof}; use nargo::{artifacts::program::PreprocessedProgram, package::Package}; -use nargo_toml::{find_package_manifest, resolve_workspace_from_toml}; +use nargo_toml::{find_package_manifest, resolve_workspace_from_toml, PackageSelection}; use noirc_abi::input_parser::Format; use noirc_driver::CompileOptions; use noirc_frontend::graph::CrateName; @@ -32,9 +32,13 @@ pub(crate) struct VerifyCommand { verifier_name: String, /// The name of the package verify - #[clap(long)] + #[clap(long, conflicts_with = "workspace")] package: Option, + /// Verify all packages in the workspace + #[clap(long, conflicts_with = "package")] + workspace: bool, + #[clap(flatten)] compile_options: CompileOptions, } @@ -45,7 +49,10 @@ pub(crate) fn run( config: NargoConfig, ) -> Result<(), CliError> { let toml_path = find_package_manifest(&config.program_dir)?; - let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; + let default_selection = + if args.workspace { PackageSelection::All } else { PackageSelection::DefaultOrAll }; + let selection = args.package.map_or(default_selection, PackageSelection::Selected); + let workspace = resolve_workspace_from_toml(&toml_path, selection)?; let proofs_dir = workspace.proofs_directory_path(); for package in &workspace { diff --git a/crates/nargo_toml/src/lib.rs b/crates/nargo_toml/src/lib.rs index 0e05a0a7901..6189d6426ba 100644 --- a/crates/nargo_toml/src/lib.rs +++ b/crates/nargo_toml/src/lib.rs @@ -249,19 +249,20 @@ impl DependencyConfig { fn toml_to_workspace( nargo_toml: NargoToml, - selected_package: Option, + package_selection: PackageSelection, ) -> Result { let workspace = match nargo_toml.config { Config::Package { package_config } => { let member = package_config.resolve_to_package(&nargo_toml.root_dir)?; - if selected_package.is_none() || Some(&member.name) == selected_package.as_ref() { - Workspace { + match &package_selection { + PackageSelection::Selected(selected_name) if selected_name != &member.name => { + return Err(ManifestError::MissingSelectedPackage(member.name)) + } + _ => Workspace { root_dir: nargo_toml.root_dir, selected_package_index: Some(0), members: vec![member], - } - } else { - return Err(ManifestError::MissingSelectedPackage(member.name)); + }, } } Config::Workspace { workspace_config } => { @@ -272,17 +273,18 @@ fn toml_to_workspace( let package_toml_path = package_root_dir.join("Nargo.toml"); let member = resolve_package_from_toml(&package_toml_path)?; - match selected_package.as_ref() { - Some(selected_name) => { + match &package_selection { + PackageSelection::Selected(selected_name) => { if &member.name == selected_name { selected_package_index = Some(index); } } - None => { + PackageSelection::DefaultOrAll => { if Some(&member_path) == workspace_config.default_member.as_ref() { selected_package_index = Some(index); } } + PackageSelection::All => selected_package_index = None, } members.push(member); @@ -290,13 +292,21 @@ fn toml_to_workspace( // If the selected_package_index is still `None` but we have see a default_member or selected package, // we want to present an error to users - if selected_package_index.is_none() { - if let Some(selected_name) = selected_package { - return Err(ManifestError::MissingSelectedPackage(selected_name)); - } - if let Some(default_path) = workspace_config.default_member { - return Err(ManifestError::MissingDefaultPackage(default_path)); + match package_selection { + PackageSelection::Selected(selected_name) => { + if selected_package_index.is_none() { + return Err(ManifestError::MissingSelectedPackage(selected_name)); + } } + PackageSelection::DefaultOrAll => match workspace_config.default_member { + // If `default-member` is specified but we don't have a selected_package_index, we need to fail + Some(default_path) if selected_package_index.is_none() => { + return Err(ManifestError::MissingDefaultPackage(default_path)); + } + // However, if there wasn't a `default-member`, we select All, so no error is needed + _ => (), + }, + PackageSelection::All => (), } Workspace { root_dir: nargo_toml.root_dir, members, selected_package_index } @@ -331,14 +341,21 @@ fn resolve_package_from_toml(toml_path: &Path) -> Result } } +#[derive(Debug, PartialEq, Eq)] +pub enum PackageSelection { + Selected(CrateName), + DefaultOrAll, + All, +} + /// Resolves a Nargo.toml file into a `Workspace` struct as defined by our `nargo` core. pub fn resolve_workspace_from_toml( toml_path: &Path, - selected_package: Option, + package_selection: PackageSelection, ) -> Result { let nargo_toml = read_toml(toml_path)?; - toml_to_workspace(nargo_toml, selected_package) + toml_to_workspace(nargo_toml, package_selection) } #[test] From 7d0178987641f5cb8f8e95507c54c3cc367bf7d2 Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Mon, 14 Aug 2023 23:45:53 +0100 Subject: [PATCH 14/14] chore: Reuse workspace target directory in wasm build script (#2312) --- crates/wasm/build.sh | 2 +- crates/wasm/buildPhaseCargoCommand.sh | 2 +- flake.nix | 3 ++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/wasm/build.sh b/crates/wasm/build.sh index 22814b74936..61b5b17d34d 100755 --- a/crates/wasm/build.sh +++ b/crates/wasm/build.sh @@ -30,7 +30,7 @@ require_command wasm-opt self_path=$(dirname "$(readlink -f "$0")") export pname=$(toml2json < ${self_path}/Cargo.toml | jq -r .package.name) -export CARGO_TARGET_DIR=$self_path/target +export CARGO_TARGET_DIR=$self_path/../../target rm -rf $self_path/outputs >/dev/null 2>&1 rm -rf $self_path/result >/dev/null 2>&1 diff --git a/crates/wasm/buildPhaseCargoCommand.sh b/crates/wasm/buildPhaseCargoCommand.sh index 5fff9eff808..5ba924dbb7b 100755 --- a/crates/wasm/buildPhaseCargoCommand.sh +++ b/crates/wasm/buildPhaseCargoCommand.sh @@ -25,7 +25,7 @@ fi # TODO: Handle the wasm target being built in release mode TARGET=wasm32-unknown-unknown -WASM_BINARY=${self_path}/../../target/${TARGET}/release/${pname}.wasm +WASM_BINARY=${CARGO_TARGET_DIR}/${TARGET}/release/${pname}.wasm NODE_DIR=${self_path}/pkg/nodejs/ BROWSER_DIR=${self_path}/pkg/web/ diff --git a/flake.nix b/flake.nix index ea677501147..912b035d359 100644 --- a/flake.nix +++ b/flake.nix @@ -88,7 +88,7 @@ BARRETENBERG_BIN_DIR = "${pkgs.barretenberg-wasm}/bin"; }; - testEnvironment = sharedEnvironment // {}; + testEnvironment = sharedEnvironment // { }; # The `self.rev` property is only available when the working tree is not dirty GIT_COMMIT = if (self ? rev) then self.rev else "unknown"; @@ -295,6 +295,7 @@ COMMIT_SHORT = builtins.substring 0 7 GIT_COMMIT; VERSION_APPENDIX = if GIT_DIRTY == "true" then "-dirty" else ""; PKG_PATH = "./pkg"; + CARGO_TARGET_DIR = "./target"; nativeBuildInputs = with pkgs; [ which