Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: nargo info now prints information as a prettified table #2282

Merged
merged 9 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"]

6 changes: 5 additions & 1 deletion crates/nargo_cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
38 changes: 27 additions & 11 deletions crates/nargo_cli/src/cli/info_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -55,18 +56,19 @@ fn count_opcodes_and_gates_in_package<B: Backend>(
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(())
}
Expand All @@ -91,10 +93,24 @@ fn count_opcodes_and_gates_in_contracts<B: Backend>(
})
.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(())
Expand Down
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
"pedersen",
"peekable",
"preprocess",
"prettytable",
"printstd",
"pseudocode",
"schnorr",
"sdiv",
Expand Down