From 940fc9e06745bc363eae0de1c0b027c78d121654 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 11:32:46 +0100 Subject: [PATCH 1/9] table info --- Cargo.lock | 74 +++++++++++++++++++ crates/nargo_cli/Cargo.toml | 4 +- crates/nargo_cli/src/cli/info_cmd.rs | 38 +++++++--- .../contracts/target/contracts-Foo.json | 1 + 4 files changed, 104 insertions(+), 13 deletions(-) create mode 100644 crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json diff --git a/Cargo.lock b/Cargo.lock index 7535d132a96..482e45e543b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -964,6 +964,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" @@ -1045,6 +1066,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" @@ -1056,6 +1087,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" @@ -1100,6 +1142,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" @@ -2017,6 +2065,7 @@ dependencies = [ "noirc_errors", "noirc_frontend", "predicates 2.1.5", + "prettytable-rs", "rustc_version", "serde", "serde_json", @@ -2352,6 +2401,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" @@ -3268,6 +3331,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 fd052e9dc95..eeffdbfdd50 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" @@ -62,4 +63,3 @@ 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/src/cli/info_cmd.rs b/crates/nargo_cli/src/cli/info_cmd.rs index d972aeb0511..b7af3f883a1 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}; @@ -55,18 +56,19 @@ fn count_opcodes_and_gates_in_package( 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); + + let mut table = Table::new(); + table.add_row(row!["Package", "Language", "ACIR Opcodes", "Backend Circuit Size"]); + table.add_row(row![ + format!("{}", package.name), + format!("{:?}", backend.np_language()), + format!("{}", num_opcodes), + format!("{}", exact_circuit_size), + ]); + table.printstd(); Ok(()) } @@ -91,10 +93,24 @@ fn count_opcodes_and_gates_in_contracts( }) .map_err(CliError::ProofSystemCompilerError)?; + let mut table = Table::new(); + table.add_row(row![ + "Contract", + "Function", + "Language", + "ACIR Opcodes", + "Backend Circuit Size" + ]); 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![ + format!("{}", contract.name), + format!("{}", info.0), + format!("{:?}", backend.np_language()), + format!("{}", info.1), + format!("{}", info.2), + ]); } + table.printstd(); } Ok(()) diff --git a/crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json b/crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json new file mode 100644 index 00000000000..c0347299bbe --- /dev/null +++ b/crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json @@ -0,0 +1 @@ +{"name":"Foo","backend":"acvm-backend-barretenberg","functions":[{"name":"double","function_type":"Secret","is_internal":false,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62Quw2AMAxEHVjI38TuWIUIZ/8RaIIUiRKuue7p7u0AUOCdbfYxG7+Fy8ISrKrZOEnoRI7uhmq9OjmZ28Uukq7eokfDIJWkYSFjwrb/duHzfXVQFgc3HuAeFCABAAA=","proving_key":null,"verification_key":null},{"name":"quadruple","function_type":"Secret","is_internal":true,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62QsQ3AIAwEDVnIxjbYXVYJitl/hDREQkoZvvnu9H8HACT4Js8+Z+O/SFpYjFUkWgliurB4N0XRXo2M1PQuxhwm1rx7QyfhoKHOY8Lyvl34fl8dpMXBA1aGLewgAQAA","proving_key":null,"verification_key":null},{"name":"skibbidy","function_type":"Open","is_internal":true,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62SQQrAMAgETU1SQqFvMYfe/f+rSqjCUrzFvbgouBMJE1GhTwwe5T21KnuaJW+XIO8B/rI6fv2lDl6TOHr+naQB6wjeedu85uY+awdDludVYGnmObizz04K/pPmQE5fjAEFoF/Kw2xu2QIAAA==","proving_key":null,"verification_key":null},{"name":"triple","function_type":"Secret","is_internal":false,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62QsQ3AIAwEDVnIxjbYXVYJitl/hDREQkoZvvnu9H8HACT4Js8+Z+O/cFpYjFUkWgliurB4N0XRXo2M1PQuxhwm1rx7QyfhoKHOY8Lyvl34fl8dpMXBAz1zOYkgAQAA","proving_key":null,"verification_key":null}]} \ No newline at end of file From 83d5fe4f37422e98f1f09fe15eeb21138e904ef1 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 11:34:02 +0100 Subject: [PATCH 2/9] . --- .../tests/execution_success/contracts/target/contracts-Foo.json | 1 - 1 file changed, 1 deletion(-) delete mode 100644 crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json diff --git a/crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json b/crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json deleted file mode 100644 index c0347299bbe..00000000000 --- a/crates/nargo_cli/tests/execution_success/contracts/target/contracts-Foo.json +++ /dev/null @@ -1 +0,0 @@ -{"name":"Foo","backend":"acvm-backend-barretenberg","functions":[{"name":"double","function_type":"Secret","is_internal":false,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62Quw2AMAxEHVjI38TuWIUIZ/8RaIIUiRKuue7p7u0AUOCdbfYxG7+Fy8ISrKrZOEnoRI7uhmq9OjmZ28Uukq7eokfDIJWkYSFjwrb/duHzfXVQFgc3HuAeFCABAAA=","proving_key":null,"verification_key":null},{"name":"quadruple","function_type":"Secret","is_internal":true,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62QsQ3AIAwEDVnIxjbYXVYJitl/hDREQkoZvvnu9H8HACT4Js8+Z+O/SFpYjFUkWgliurB4N0XRXo2M1PQuxhwm1rx7QyfhoKHOY8Lyvl34fl8dpMXBA1aGLewgAQAA","proving_key":null,"verification_key":null},{"name":"skibbidy","function_type":"Open","is_internal":true,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62SQQrAMAgETU1SQqFvMYfe/f+rSqjCUrzFvbgouBMJE1GhTwwe5T21KnuaJW+XIO8B/rI6fv2lDl6TOHr+naQB6wjeedu85uY+awdDludVYGnmObizz04K/pPmQE5fjAEFoF/Kw2xu2QIAAA==","proving_key":null,"verification_key":null},{"name":"triple","function_type":"Secret","is_internal":false,"abi":{"parameters":[{"name":"x","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"x":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62QsQ3AIAwEDVnIxjbYXVYJitl/hDREQkoZvvnu9H8HACT4Js8+Z+O/cFpYjFUkWgliurB4N0XRXo2M1PQuxhwm1rx7QyfhoKHOY8Lyvl34fl8dpMXBAz1zOYkgAQAA","proving_key":null,"verification_key":null}]} \ No newline at end of file From a4c72ef3e21f589c1ee5154597a4299352f5b015 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 11:38:13 +0100 Subject: [PATCH 3/9] . --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 8da1d65fb56..93470f6e76a 100644 --- a/cspell.json +++ b/cspell.json @@ -50,6 +50,7 @@ "pedersen", "peekable", "preprocess", + "prettytable", "pseudocode", "schnorr", "sdiv", From d618608b10c7581a11609d7bf3988dd23e3a52bc Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 11:59:49 +0100 Subject: [PATCH 4/9] . --- crates/nargo_cli/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/build.rs b/crates/nargo_cli/build.rs index 6d8dae136e2..6df05d6912a 100644 --- a/crates/nargo_cli/build.rs +++ b/crates/nargo_cli/build.rs @@ -110,7 +110,7 @@ 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("ACIR Opcodes | Backend Circuit Size")); }} "#, test_dir = test_dir.display(), From a8ab6172b9e07d90a8a768156d62acfc0d41b2ce Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 12:03:09 +0100 Subject: [PATCH 5/9] . --- cspell.json | 1 + 1 file changed, 1 insertion(+) diff --git a/cspell.json b/cspell.json index 93470f6e76a..8bac11dfbe5 100644 --- a/cspell.json +++ b/cspell.json @@ -51,6 +51,7 @@ "peekable", "preprocess", "prettytable", + "printstd", "pseudocode", "schnorr", "sdiv", From aff840f9cc58834df1877ed0e8986b2b8c2c5eb3 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 14:12:19 +0100 Subject: [PATCH 6/9] review --- crates/nargo_cli/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/nargo_cli/build.rs b/crates/nargo_cli/build.rs index 6df05d6912a..c8429617a41 100644 --- a/crates/nargo_cli/build.rs +++ b/crates/nargo_cli/build.rs @@ -110,7 +110,7 @@ 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("ACIR Opcodes | Backend Circuit Size")); + cmd.assert().stdout(predicate::str::contains("ACIR Opcodes | Backend Circuit Size").and(predicate::str::contains("| 0 | 1 |"))); }} "#, test_dir = test_dir.display(), From 3c08a8cd5dec613199b73ac0f53f77539f228265 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Fri, 11 Aug 2023 14:16:45 +0100 Subject: [PATCH 7/9] review --- crates/nargo_cli/build.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/nargo_cli/build.rs b/crates/nargo_cli/build.rs index c8429617a41..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("ACIR Opcodes | Backend Circuit Size").and(predicate::str::contains("| 0 | 1 |"))); + 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(), From 27c2a41bcd57b03f1dc54eb4c3b5613e404c5575 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Mon, 14 Aug 2023 10:32:46 +0100 Subject: [PATCH 8/9] merge --- crates/nargo_cli/src/cli/info_cmd.rs | 46 +++++++++++++++++++--------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/crates/nargo_cli/src/cli/info_cmd.rs b/crates/nargo_cli/src/cli/info_cmd.rs index b7af3f883a1..9517bb1a21a 100644 --- a/crates/nargo_cli/src/cli/info_cmd.rs +++ b/crates/nargo_cli/src/cli/info_cmd.rs @@ -37,14 +37,42 @@ 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!["Package", "Language", "ACIR Opcodes", "Backend Circuit Size"]); + let mut contract_table = Table::new(); + contract_table.add_row(row![ + "Contract", + "Function", + "Language", + "ACIR Opcodes", + "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(()) } @@ -52,6 +80,7 @@ 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)?; @@ -60,15 +89,12 @@ fn count_opcodes_and_gates_in_package( .get_exact_circuit_size(&compiled_program.circuit) .map_err(CliError::ProofSystemCompilerError)?; - let mut table = Table::new(); - table.add_row(row!["Package", "Language", "ACIR Opcodes", "Backend Circuit Size"]); table.add_row(row![ format!("{}", package.name), format!("{:?}", backend.np_language()), format!("{}", num_opcodes), format!("{}", exact_circuit_size), ]); - table.printstd(); Ok(()) } @@ -77,6 +103,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); @@ -93,14 +120,6 @@ fn count_opcodes_and_gates_in_contracts( }) .map_err(CliError::ProofSystemCompilerError)?; - let mut table = Table::new(); - table.add_row(row![ - "Contract", - "Function", - "Language", - "ACIR Opcodes", - "Backend Circuit Size" - ]); for info in function_info { table.add_row(row![ format!("{}", contract.name), @@ -110,7 +129,6 @@ fn count_opcodes_and_gates_in_contracts( format!("{}", info.2), ]); } - table.printstd(); } Ok(()) From f34d84a91dcc65cf3040afe8051e5e4ff8581a85 Mon Sep 17 00:00:00 2001 From: ethan-000 Date: Mon, 14 Aug 2023 10:54:56 +0100 Subject: [PATCH 9/9] add colour --- crates/nargo_cli/src/cli/info_cmd.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/crates/nargo_cli/src/cli/info_cmd.rs b/crates/nargo_cli/src/cli/info_cmd.rs index 9517bb1a21a..a2900a6e249 100644 --- a/crates/nargo_cli/src/cli/info_cmd.rs +++ b/crates/nargo_cli/src/cli/info_cmd.rs @@ -38,14 +38,16 @@ pub(crate) fn run( let workspace = resolve_workspace_from_toml(&toml_path, args.package)?; let mut package_table = Table::new(); - package_table.add_row(row!["Package", "Language", "ACIR Opcodes", "Backend Circuit Size"]); + 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![ - "Contract", - "Function", - "Language", - "ACIR Opcodes", - "Backend Circuit Size" + Fm->"Contract", + Fm->"Function", + Fm->"Language", + Fm->"ACIR Opcodes", + Fm->"Backend Circuit Size" ]); for package in &workspace { @@ -90,10 +92,10 @@ fn count_opcodes_and_gates_in_package( .map_err(CliError::ProofSystemCompilerError)?; table.add_row(row![ - format!("{}", package.name), + Fm->format!("{}", package.name), format!("{:?}", backend.np_language()), - format!("{}", num_opcodes), - format!("{}", exact_circuit_size), + Fc->format!("{}", num_opcodes), + Fc->format!("{}", exact_circuit_size), ]); Ok(()) @@ -122,11 +124,11 @@ fn count_opcodes_and_gates_in_contracts( for info in function_info { table.add_row(row![ - format!("{}", contract.name), - format!("{}", info.0), + Fm->format!("{}", contract.name), + Fc->format!("{}", info.0), format!("{:?}", backend.np_language()), - format!("{}", info.1), - format!("{}", info.2), + Fc->format!("{}", info.1), + Fc->format!("{}", info.2), ]); } }