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 all 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
62 changes: 49 additions & 13 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 @@ -36,37 +37,66 @@ pub(crate) fn run<B: Backend>(
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(())
}

fn count_opcodes_and_gates_in_package<B: Backend>(
backend: &B,
package: &Package,
compile_options: &CompileOptions,
table: &mut Table,
) -> Result<(), CliError<B>> {
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(())
}
Expand All @@ -75,6 +105,7 @@ fn count_opcodes_and_gates_in_contracts<B: Backend>(
backend: &B,
package: &Package,
compile_options: &CompileOptions,
table: &mut Table,
) -> Result<(), CliError<B>> {
let (mut context, crate_id) = prepare_package(package);
let result = compile_contracts(&mut context, crate_id, compile_options);
Expand All @@ -92,8 +123,13 @@ fn count_opcodes_and_gates_in_contracts<B: Backend>(
.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),
]);
}
}

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