Skip to content

Commit

Permalink
Merge branch 'master' into assert-eq-builtin
Browse files Browse the repository at this point in the history
* master:
  feat: Add slice append (#2241)
  chore: Bump `async-lsp` to v0.0.5 (#2186)
  chore: Move the remaining `nargo_cli` lib funcs into `nargo` crate (#2225)
  chore: Add test for eddsa (#2237)
  chore: Split `Nargo.toml` operations into separate package (#2224)
  fix(stdlib): correct `tecurve::contains` formula (#1821)
  feat: Remove `comptime` and warn upon usage (#2178)
  fix: Remove last vestige of array of structs to struct of arrays conversion (#2217)
  fix: Add foreign impl error (#2216)
  feat(nargo)!: Replace `--contracts` flag with `contract` package type (#2204)
  feat: Optimize `x < 0` for unsigned `x` to false (#2206)
  fix: Initialize numeric generics' type to a polymorphic integer when used in an expression (#2179)
  chore(nargo)!: remove `flat_witness` feature flag (#2208)
  chore: Revert "feat: Only create new witnesses for distinctiveness when duplicates exist" (#2209)
  • Loading branch information
TomAFrench committed Aug 10, 2023
2 parents 3aa708f + 90c5d18 commit 7b2b9cb
Show file tree
Hide file tree
Showing 92 changed files with 925 additions and 1,404 deletions.
38 changes: 32 additions & 6 deletions Cargo.lock

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

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"crates/noirc_driver",
"crates/nargo",
"crates/nargo_cli",
"crates/nargo_toml",
"crates/fm",
"crates/arena",
"crates/noirc_abi",
Expand All @@ -30,6 +31,7 @@ fm = { path = "crates/fm" }
iter-extended = { path = "crates/iter-extended" }
nargo = { path = "crates/nargo" }
nargo_cli = { path = "crates/nargo_cli" }
nargo_toml = { path = "crates/nargo_toml" }
noir_lsp = { path = "crates/lsp" }
noirc_abi = { path = "crates/noirc_abi" }
noirc_driver = { path = "crates/noirc_driver" }
Expand All @@ -55,6 +57,3 @@ url = "2.2.0"
wasm-bindgen = { version = "=0.2.86", features = ["serde-serialize"] }
wasm-bindgen-test = "0.3.33"
base64 = "0.21.2"

[patch.crates-io]
async-lsp = { git = "https://github.com/oxalica/async-lsp", rev = "09dbcc11046f7a188a80137f8d36484d86c78c78" }
2 changes: 1 addition & 1 deletion crates/lsp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ noirc_frontend.workspace = true
serde_json.workspace = true
toml.workspace = true
tower.workspace = true
async-lsp = { version = "0.0.4", default-features = false, features = ["omni-trait"] }
async-lsp = { version = "0.0.5", default-features = false, features = ["omni-trait"] }

[dev-dependencies]
tokio = { version = "1.0", features = ["macros"] }
1 change: 1 addition & 0 deletions crates/nargo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rustc_version = "0.4.0"

[dependencies]
acvm.workspace = true
fm.workspace = true
noirc_abi.workspace = true
noirc_driver.workspace = true
noirc_frontend.workspace = true
Expand Down
39 changes: 39 additions & 0 deletions crates/nargo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,43 @@ pub mod ops;
pub mod package;
pub mod workspace;

use std::collections::BTreeMap;

use fm::FileManager;
use noirc_driver::{add_dep, prepare_crate};
use noirc_frontend::{
graph::{CrateGraph, CrateId, CrateName},
hir::Context,
};
use package::{Dependency, Package};

pub use self::errors::NargoError;

pub fn prepare_dependencies(
context: &mut Context,
parent_crate: CrateId,
dependencies: &BTreeMap<CrateName, Dependency>,
) {
for (dep_name, dep) in dependencies.iter() {
match dep {
Dependency::Remote { package } | Dependency::Local { package } => {
let crate_id = prepare_crate(context, &package.entry_path);
add_dep(context, parent_crate, crate_id, dep_name.clone());
prepare_dependencies(context, crate_id, &package.dependencies);
}
}
}
}

pub fn prepare_package(package: &Package) -> (Context, CrateId) {
// TODO: FileManager continues to leak into various crates
let fm = FileManager::new(&package.root_dir);
let graph = CrateGraph::default();
let mut context = Context::new(fm, graph);

let crate_id = prepare_crate(&mut context, &package.entry_path);

prepare_dependencies(&mut context, crate_id, &package.dependencies);

(context, crate_id)
}
6 changes: 6 additions & 0 deletions crates/nargo/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ use crate::constants::{PROVER_INPUT_FILE, VERIFIER_INPUT_FILE};
pub enum PackageType {
Library,
Binary,
Contract,
}

impl Display for PackageType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Library => write!(f, "lib"),
Self::Binary => write!(f, "bin"),
Self::Contract => write!(f, "contract"),
}
}
}
Expand Down Expand Up @@ -64,6 +66,10 @@ impl Package {
self.package_type == PackageType::Binary
}

pub fn is_contract(&self) -> bool {
self.package_type == PackageType::Contract
}

pub fn is_library(&self) -> bool {
self.package_type == PackageType::Library
}
Expand Down
10 changes: 5 additions & 5 deletions crates/nargo_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,34 @@ build-data = "0.1.3"
toml.workspace = true

[dependencies]
cfg-if.workspace = true
clap.workspace = true
dirs.workspace = true
url.workspace = true
iter-extended.workspace = true
nargo.workspace = true
nargo_toml.workspace = true
noir_lsp.workspace = true
noirc_driver.workspace = true
noirc_frontend.workspace = true
noirc_abi.workspace = true
noirc_errors.workspace = true
acvm.workspace = true
fm.workspace = true
toml.workspace = true
serde.workspace = true
serde_json.workspace = true
thiserror.workspace = true
tower.workspace = true
async-lsp = { version = "0.0.4", default-features = false, features = [
async-lsp = { version = "0.0.5", default-features = false, features = [
"client-monitor",
"stdio",
"tracing",
"tokio"
] }
const_format = "0.2.30"
hex = "0.4.2"
termcolor = "1.1.2"
color-eyre = "0.6.2"
tokio = { version = "1.0", features = ["io-std"] }
tokio-util = { version = "0.7.8", features = ["compat"] }

# Backends
acvm-backend-barretenberg = { version = "0.10.0", default-features = false }
Expand All @@ -55,11 +55,11 @@ tempdir = "0.3.7"
assert_cmd = "2.0.8"
assert_fs = "1.0.10"
predicates = "2.1.5"
fm.workspace = true

[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"]
flat_witness = ["acvm-backend-barretenberg/native"]

2 changes: 1 addition & 1 deletion crates/nargo_cli/src/backends.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub(crate) use acvm_backend_barretenberg::Barretenberg as ConcreteBackend;

#[cfg(not(any(feature = "plonk_bn254", feature = "plonk_bn254_wasm", feature = "flat_witness")))]
#[cfg(not(any(feature = "plonk_bn254", feature = "plonk_bn254_wasm")))]
compile_error!("please specify a backend to compile with");

#[cfg(all(feature = "plonk_bn254", feature = "plonk_bn254_wasm"))]
Expand Down
13 changes: 4 additions & 9 deletions crates/nargo_cli/src/cli/check_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
use crate::{
errors::{CliError, CompileError},
find_package_manifest,
manifest::resolve_workspace_from_toml,
prepare_package,
};
use crate::errors::{CliError, CompileError};
use acvm::Backend;
use clap::Args;
use iter_extended::btree_map;
use nargo::package::Package;
use nargo::{package::Package, prepare_package};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_abi::{AbiParameter, AbiType, MAIN_RETURN_NAME};
use noirc_driver::{check_crate, compute_function_signature, CompileOptions};
use noirc_frontend::{
Expand Down Expand Up @@ -116,11 +112,10 @@ fn create_input_toml_template(
mod tests {
use std::path::PathBuf;

use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_abi::{AbiParameter, AbiType, AbiVisibility, Sign};
use noirc_driver::CompileOptions;

use crate::{find_package_manifest, manifest::resolve_workspace_from_toml};

use super::create_input_toml_template;

const TEST_DATA_DIR: &str = "tests/target_tests_data";
Expand Down
2 changes: 1 addition & 1 deletion crates/nargo_cli/src/cli/codegen_verifier_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use super::{
},
};
use crate::errors::CliError;
use crate::{find_package_manifest, manifest::resolve_workspace_from_toml};
use acvm::Backend;
use clap::Args;
use nargo::{
ops::{codegen_verifier, preprocess_program},
package::Package,
};
use nargo_toml::{find_package_manifest, resolve_workspace_from_toml};
use noirc_driver::CompileOptions;
use noirc_frontend::graph::CrateName;

Expand Down
20 changes: 7 additions & 13 deletions crates/nargo_cli/src/cli/compile_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use acvm::{acir::circuit::Circuit, Backend};
use iter_extended::try_vecmap;
use iter_extended::vecmap;
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, CompiledProgram, ErrorsAndWarnings, Warnings,
};
Expand All @@ -15,8 +17,6 @@ use clap::Args;
use nargo::ops::{preprocess_contract_function, preprocess_program};

use crate::errors::{CliError, CompileError};
use crate::manifest::resolve_workspace_from_toml;
use crate::{find_package_manifest, prepare_package};

use super::fs::{
common_reference_string::{
Expand All @@ -37,10 +37,6 @@ pub(crate) struct CompileCommand {
#[arg(long)]
include_keys: bool,

/// Compile each contract function used within the program
#[arg(short, long)]
contracts: bool,

/// The name of the package to compile
#[clap(long)]
package: Option<CrateName>,
Expand All @@ -60,10 +56,10 @@ pub(crate) fn run<B: Backend>(

let mut common_reference_string = read_cached_common_reference_string();

// If contracts is set we're compiling every function in a 'contract' rather than just 'main'.
if args.contracts {
for package in &workspace {
let (mut context, crate_id) = prepare_package(package);
for package in &workspace {
let (mut context, crate_id) = prepare_package(package);
// If `contract` package type, we're compiling every function in a 'contract' rather than just 'main'.
if package.is_contract() {
let result = compile_contracts(&mut context, crate_id, &args.compile_options);
let contracts = report_errors(result, &context, args.compile_options.deny_warnings)?;

Expand Down Expand Up @@ -105,9 +101,7 @@ pub(crate) fn run<B: Backend>(
&circuit_dir,
);
}
}
} else {
for package in &workspace {
} else {
let (_, program) = compile_package(backend, package, &args.compile_options)?;

common_reference_string =
Expand Down
3 changes: 1 addition & 2 deletions crates/nargo_cli/src/cli/execute_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +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 noirc_abi::input_parser::{Format, InputValue};
use noirc_abi::{Abi, InputMap};
use noirc_driver::{CompileOptions, CompiledProgram};
Expand All @@ -16,8 +17,6 @@ use super::compile_cmd::compile_package;
use super::fs::{inputs::read_inputs_from_file, witness::save_witness_to_dir};
use super::NargoConfig;
use crate::errors::CliError;
use crate::find_package_manifest;
use crate::manifest::resolve_workspace_from_toml;

/// Executes a circuit to calculate its return value
#[derive(Debug, Clone, Args)]
Expand Down
Loading

0 comments on commit 7b2b9cb

Please sign in to comment.