Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into type_aliases_2
Browse files Browse the repository at this point in the history
merge master
  • Loading branch information
Ethan-000 committed Jul 25, 2023
2 parents 5d10c18 + 2d87c87 commit 7d82d82
Show file tree
Hide file tree
Showing 292 changed files with 1,079 additions and 361 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ result
**/target
!crates/nargo_cli/tests/test_data/*/target
!crates/nargo_cli/tests/test_data/*/target/witness.tr
!crates/nargo_cli/tests/test_data_ssa_refactor/*/target
!crates/nargo_cli/tests/test_data_ssa_refactor/*/target/witness.tr
34 changes: 18 additions & 16 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ edition = "2021"
rust-version = "1.66"

[workspace.dependencies]
acvm = "0.19.1"
acvm = "0.20.0"
arena = { path = "crates/arena" }
fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
Expand Down Expand Up @@ -57,4 +57,4 @@ wasm-bindgen-test = "0.3.33"
base64 = "0.21.2"

[patch.crates-io]
async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" }
async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" }
4 changes: 1 addition & 3 deletions crates/lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,14 @@ fn on_code_lens_request(
let tests = context.get_all_test_functions_in_crate_matching(&crate_id, "");

let mut lenses: Vec<CodeLens> = vec![];
for func_id in tests {
for (func_name, func_id) in tests {
let location = context.function_meta(&func_id).name.location;
let file_id = location.file;
// TODO(#1681): This file_id never be 0 because the "path" where it maps is the directory, not a file
if file_id.as_usize() != 0 {
continue;
}

let func_name = context.function_name(&func_id);

let range =
byte_span_to_range(files, file_id.as_usize(), location.span.into()).unwrap_or_default();

Expand Down
4 changes: 1 addition & 3 deletions crates/lsp/src/lib_hacky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,14 @@ pub fn on_code_lens_request(
let tests = context.get_all_test_functions_in_crate_matching(&crate_id, "");

let mut lenses: Vec<CodeLens> = vec![];
for func_id in tests {
for (func_name, func_id) in tests {
let location = context.function_meta(&func_id).name.location;
let file_id = location.file;
// TODO(#1681): This file_id never be 0 because the "path" where it maps is the directory, not a file
if file_id.as_usize() != 0 {
continue;
}

let func_name = context.function_name(&func_id);

let range =
byte_span_to_range(files, file_id.as_usize(), location.span.into()).unwrap_or_default();

Expand Down
3 changes: 2 additions & 1 deletion crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ color-eyre = "0.6.2"
tokio = { version = "1.0", features = ["io-std"] }

# Backends
acvm-backend-barretenberg = { version = "0.9.0", default-features = false }
acvm-backend-barretenberg = { version = "0.9.1", default-features = false }

[dev-dependencies]
tempdir = "0.3.7"
Expand All @@ -62,3 +62,4 @@ default = ["plonk_bn254"]
plonk_bn254 = ["acvm-backend-barretenberg/native"]
plonk_bn254_wasm = ["acvm-backend-barretenberg/wasm"]
flat_witness = ["acvm-backend-barretenberg/native"]

56 changes: 56 additions & 0 deletions crates/nargo_cli/src/cli/init_cmd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use crate::{
constants::{PKG_FILE, SRC_DIR},
errors::CliError,
};

use super::fs::{create_named_dir, write_to_file};
use super::{NargoConfig, CARGO_PKG_VERSION};
use acvm::Backend;
use clap::Args;
use const_format::formatcp;
use std::path::PathBuf;

/// Create a Noir project in the current directory.
#[derive(Debug, Clone, Args)]
pub(crate) struct InitCommand;

const SETTINGS: &str = formatcp!(
r#"[package]
authors = [""]
compiler_version = "{CARGO_PKG_VERSION}"
[dependencies]"#,
);

const EXAMPLE: &str = r#"fn main(x : Field, y : pub Field) {
assert(x != y);
}
#[test]
fn test_main() {
main(1, 2);
// Uncomment to make test fail
// main(1, 1);
}
"#;

pub(crate) fn run<B: Backend>(
// Backend is currently unused, but we might want to use it to inform the "new" template in the future
_backend: &B,
_args: InitCommand,
config: NargoConfig,
) -> Result<(), CliError<B>> {
initialize_project(config.program_dir);
Ok(())
}

/// Initializes a new Noir project in `package_dir`.
pub(crate) fn initialize_project(package_dir: PathBuf) {
let src_dir = package_dir.join(SRC_DIR);
create_named_dir(&src_dir, "src");

write_to_file(SETTINGS.as_bytes(), &package_dir.join(PKG_FILE));
write_to_file(EXAMPLE.as_bytes(), &src_dir.join("main.nr"));
println!("Project successfully created! Binary located at {}", package_dir.display());
}
5 changes: 4 additions & 1 deletion crates/nargo_cli/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ mod codegen_verifier_cmd;
mod compile_cmd;
mod execute_cmd;
mod gates_cmd;
mod init_cmd;
mod lsp_cmd;
mod new_cmd;
mod prove_cmd;
Expand Down Expand Up @@ -51,6 +52,7 @@ enum NargoCommand {
#[command(alias = "build")]
Compile(compile_cmd::CompileCommand),
New(new_cmd::NewCommand),
Init(init_cmd::InitCommand),
Execute(execute_cmd::ExecuteCommand),
Prove(prove_cmd::ProveCommand),
Verify(verify_cmd::VerifyCommand),
Expand All @@ -63,14 +65,15 @@ pub fn start_cli() -> eyre::Result<()> {
let NargoCli { command, mut config } = NargoCli::parse();

// Search through parent directories to find package root if necessary.
if !matches!(command, NargoCommand::New(_) | NargoCommand::Lsp(_)) {
if !matches!(command, NargoCommand::New(_) | NargoCommand::Init(_) | NargoCommand::Lsp(_)) {
config.program_dir = find_package_root(&config.program_dir)?;
}

let backend = crate::backends::ConcreteBackend::default();

match command {
NargoCommand::New(args) => new_cmd::run(&backend, args, config),
NargoCommand::Init(args) => init_cmd::run(&backend, args, config),
NargoCommand::Check(args) => check_cmd::run(&backend, args, config),
NargoCommand::Compile(args) => compile_cmd::run(&backend, args, config),
NargoCommand::Execute(args) => execute_cmd::run(&backend, args, config),
Expand Down
41 changes: 5 additions & 36 deletions crates/nargo_cli/src/cli/new_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
use crate::{
constants::{PKG_FILE, SRC_DIR},
errors::CliError,
};
use crate::errors::CliError;

use super::fs::{create_named_dir, write_to_file};
use super::{NargoConfig, CARGO_PKG_VERSION};
use super::{init_cmd::initialize_project, NargoConfig};
use acvm::Backend;
use clap::Args;
use const_format::formatcp;
use std::path::{Path, PathBuf};
use std::path::PathBuf;

/// Create a new binary project
/// Create a Noir project in a new directory.
#[derive(Debug, Clone, Args)]
pub(crate) struct NewCommand {
/// Name of the package
Expand All @@ -19,27 +14,6 @@ pub(crate) struct NewCommand {
path: Option<PathBuf>,
}

const SETTINGS: &str = formatcp!(
r#"[package]
authors = [""]
compiler_version = "{CARGO_PKG_VERSION}"
[dependencies]"#,
);

const EXAMPLE: &str = r#"fn main(x : Field, y : pub Field) {
assert(x != y);
}
#[test]
fn test_main() {
main(1, 2);
// Uncomment to make test fail
// main(1, 1);
}
"#;

pub(crate) fn run<B: Backend>(
// Backend is currently unused, but we might want to use it to inform the "new" template in the future
_backend: &B,
Expand All @@ -52,11 +26,6 @@ pub(crate) fn run<B: Backend>(
return Err(CliError::DestinationAlreadyExists(package_dir));
}

let src_dir = package_dir.join(Path::new(SRC_DIR));
create_named_dir(&src_dir, "src");

write_to_file(SETTINGS.as_bytes(), &package_dir.join(PKG_FILE));
write_to_file(EXAMPLE.as_bytes(), &src_dir.join("main.nr"));
println!("Project successfully created! Binary located at {}", package_dir.display());
initialize_project(package_dir);
Ok(())
}
15 changes: 10 additions & 5 deletions crates/nargo_cli/src/cli/test_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ pub(crate) struct TestCommand {
/// If given, only tests with names containing this string will be run
test_name: Option<String>,

/// Display output of `println` statements
#[arg(long)]
show_output: bool,

#[clap(flatten)]
compile_options: CompileOptions,
}
Expand All @@ -31,13 +35,14 @@ pub(crate) fn run<B: Backend>(
) -> Result<(), CliError<B>> {
let test_name: String = args.test_name.unwrap_or_else(|| "".to_owned());

run_tests(backend, &config.program_dir, &test_name, &args.compile_options)
run_tests(backend, &config.program_dir, &test_name, args.show_output, &args.compile_options)
}

fn run_tests<B: Backend>(
backend: &B,
program_dir: &Path,
test_name: &str,
show_output: bool,
compile_options: &CompileOptions,
) -> Result<(), CliError<B>> {
let (mut context, crate_id) = resolve_root_manifest(program_dir, None)?;
Expand All @@ -61,12 +66,11 @@ fn run_tests<B: Backend>(
let writer = StandardStream::stderr(ColorChoice::Always);
let mut writer = writer.lock();

for test_function in test_functions {
let test_name = context.function_name(&test_function);
for (test_name, test_function) in test_functions {
writeln!(writer, "Testing {test_name}...").expect("Failed to write to stdout");
writer.flush().ok();

match run_test(backend, test_name, test_function, &context, compile_options) {
match run_test(backend, &test_name, test_function, &context, show_output, compile_options) {
Ok(_) => {
writer.set_color(ColorSpec::new().set_fg(Some(Color::Green))).ok();
writeln!(writer, "ok").ok();
Expand Down Expand Up @@ -94,9 +98,10 @@ fn run_test<B: Backend>(
test_name: &str,
main: FuncId,
context: &Context,
show_output: bool,
config: &CompileOptions,
) -> Result<(), CliError<B>> {
let mut program = compile_no_check(context, config, main)
let mut program = compile_no_check(context, show_output, config, main)
.map_err(|_| CliError::Generic(format!("Test '{test_name}' failed to compile")))?;
// Note: We could perform this test using the unoptimized ACIR as generated by `compile_no_check`.
program.circuit = optimize_circuit(backend, program.circuit).unwrap().0;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"input","type":{"kind":"field"},"visibility":"private"}],"param_witnesses":{"input":[1]},"return_type":{"kind":"field"},"return_witnesses":[2]},"bytecode":"H4sIAAAAAAAA/62PQQ6AIAwEi36opS20N78isfz/CcYEY8JV5rJ7muzuAJDg4+3HSPwHpeGcvYxFJGoOYjoxezNF0VaMjNT0ysYcJla9eUUn4aCuzn2It3Ubcf7+uG/100MmGAEAAA==","proving_key":null,"verification_key":null}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[],"param_witnesses":{},"return_type":null,"return_witnesses":[]},"bytecode":[155,194,56,97,194,4,0],"proving_key":null,"verification_key":null}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/9WUTW6EMAyFPfwOQwdVVdVuuuAImMAQdr1KUZn7H6FEjaUUseO5Giyh4AhenC9+eSeiD/qN0/JEfqyDPFrlsc/l25P//9OPzb5gWYewug2tYqcuy0uyaKQhwGQFLPU5bcAyza3r5qGd2fBX046T7Zuun26WLfe2/26tMbPt7DBO49CM3JmZ7/1o7n7x8NCQus9K4GMF+KA6OQVqIflpGS2VxsXqqhktWzRyMZGD4ibqIM9Jz2gCC637QscwWoark3OgFpKfltFyaVysrprRzotGISZyUNxEHeQF6RlNYKF1X+kYRjvj6uQCqIXkp2W0QhoXq6tmtMuiUYqJHBQ3UQd5SXpGE1ho3Tc6htEuuDq5BGr9F7+95xwr8dtb1xOQXxb4Iwz0xYWsOaz3Grwnfow2eiJT2BOt1llzrDbmoItrHNJVQbciXPNr7bvCn9Gfy+nRmYbxA5t52qU1EwAA","proving_key":null,"verification_key":null}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/+1Yy27CMBAckkCBFsqjqKoqqtx6tfOA5NZfKWr4/09orDrFSQsHMouCxEooMZDxeHbtsfMG4B0/0Ss/nr2GTttrtH3brv4L53kTH/aq2oXu8bCUFEePyDEoMfoNTemCGsJBI6F923bDFxQqVpskKbZRoWP9qaJ8l6UqSXebTGc6zdKvKIvjIkuybb7LtyrXSVzofZrHewvWJ2INiFiVngNHT4mCC/7Bbcv9GfzJJlFHzNzfEXlJ6eeR9et1Uz91MxOumQxLjBEuYCamoxAHMxnhusxkRMQag28mY8iayRB8M3kBrsJMmLm/J/KS0q/LZkLU72TNtOXpE/UbEnk9EPUzG9g/xgH++sPk7PKdOPcB6rXv1sRAYExo9NPUcQpBU5ZK0kQAdwpe8UuNe8rPUW1x6rKm1Y6czdFMCk9YVwKurm4eS4xZlSxD3HwROu0Zju/QGEnwBXBfcRm3VedFTXwSTz0jYjH181B3hC7v0gga/uYWjWDhzkuMBXCYoHMcVjLP/hg2OmdvE4nvG6iFu24/xsiOUZ/ST50XtSSyxrwg5nWNTi+cVVDfkzL1WxL1u9QxhcnZ5fvk3N+OKS0xl1ZQNu4K3T6mmHGv+DkSPaawNXXjG0o9g/fSHgAA","proving_key":null,"verification_key":null}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/81WUW6DMAw1AdoOUPe37x4hJklJ/naVoYX7H2GwJVOIKvUjdoUllBihl+fnp+B3APiAv6jWR4T1luQiy+uQx29jiLB+hlWWBVaEWIIOS0IWhbgYN82K0aaNaMI+5m0QPo06I6HkXWs/jR4VfsnRzdZIbea7RYvGmu/RKuWttpOb3SQdauVxMU4tgURFiEUoOl6ZGlgzNJGq5pawF6/Sr5RnfVD9ToT6bVjpxRmjovFiDKTknPI9J/smrOKBJ04MNUF2Tq7j9cE70sM5mnRmwL0Anfm56r7Q92h3OR1Z03x6IuZqWzj+xPO2YnSx+E2Q7cUtyTvgm3j88huOQKhdQYVY/5gdYQOfma3UzARco4YOmMzWrxgDMP4doml72I/tA/CP7V051hiwsCfkNTAZg9rAPfDdlj/vGtOvZA8AAA==","proving_key":null,"verification_key":null}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"backend":"acvm-backend-barretenberg","abi":{"parameters":[{"name":"x","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"y","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"},{"name":"z","type":{"kind":"integer","sign":"unsigned","width":32},"visibility":"private"}],"param_witnesses":{"x":[1],"y":[2],"z":[3]},"return_type":null,"return_witnesses":[]},"bytecode":"H4sIAAAAAAAA/81UbQrDIAy19pOO7Qw7gvGj1X+7ysrs/Y+wjkWwUvZjRuiDkqTIM3kveGGMXdkX1fZxjPeo5kldYx3OBnCMD4wiD1BFXEpMWvtZelDwFNIt1ghtlsmCBWPNS1qlvNV2doubhQOtPKzGqRXJeH5fEBKWgIq32Tja2IgG81C3KHyMOmkiV6iK0RnICbnG/Bklzgi/9BP/YWci1cwtoa8jXV+i5P7VJ9WvI9TvwxU/nAEVzS4GAGXPcb99lDcY+cFOdAVmYsk9qY63g3+kl5cwqS/AOzC65S8190Dv0e5xOrumMd6CLnYfigkAAA==","proving_key":null,"verification_key":null}
Binary file not shown.
Loading

0 comments on commit 7d82d82

Please sign in to comment.