From b31071777b2e10b07016442d1ad4cba57ed0de34 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Mon, 7 Feb 2022 11:37:57 -0500 Subject: [PATCH] stabilize leo-package --- Cargo.lock | 398 +-------------------------- Cargo.toml | 86 +++--- compiler/Cargo.toml | 3 + compiler/src/lib.rs | 23 +- errors/src/package/package_errors.rs | 238 +++++++++++++++- leo/commands/build.rs | 164 +++++------ leo/commands/mod.rs | 68 ++--- leo/main.rs | 236 ++++++++-------- 8 files changed, 539 insertions(+), 677 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4b4327c80..52898d734f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -45,65 +45,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "aleo-std" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4618148b254f38b9283c9e00a4938187f8f3f20aa2dafc59cf7377b27cb764b" -dependencies = [ - "aleo-std-cpu", - "aleo-std-storage", - "aleo-std-time", - "aleo-std-timed", - "aleo-std-timer", -] - -[[package]] -name = "aleo-std-cpu" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1dcc739555d14733cbe4756f144b81d64f01843df359189b4d71bd5e521e2ee" - -[[package]] -name = "aleo-std-storage" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "503e2538d5158b869bc9c30c9754f9a23f4210987008014a9f118db99f22c217" -dependencies = [ - "dirs", -] - -[[package]] -name = "aleo-std-time" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7065e071b26763f3e5b1b5a587828227562365bee84fdd2629361ea0a08bfc8d" -dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - -[[package]] -name = "aleo-std-timed" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b85aed1b7ca965b6613d14ab243c746316180401cbb9ba3b2cb22bff16fc08f" -dependencies = [ - "proc-macro2 1.0.36", - "quote 1.0.15", - "syn 1.0.86", -] - -[[package]] -name = "aleo-std-timer" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23bed34621f0713d3e750b59acdd3961a8950650fa7615b7cb40e6bc062a1d0b" -dependencies = [ - "colored", -] - [[package]] name = "ansi_term" version = "0.12.1" @@ -119,18 +60,6 @@ version = "1.0.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0" -[[package]] -name = "arrayref" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" - -[[package]] -name = "arrayvec" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" - [[package]] name = "assert_cmd" version = "2.0.4" @@ -183,43 +112,12 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "blake2" -version = "0.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" -dependencies = [ - "crypto-mac", - "digest 0.9.0", - "opaque-debug 0.3.0", -] - -[[package]] -name = "blake2s_simd" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db539cc2b5f6003621f1cd9ef92d7ded8ea5232c7de0f9faa2de251cd98730d4" -dependencies = [ - "arrayref", - "arrayvec", - "constant_time_eq", -] - [[package]] name = "block-buffer" version = "0.7.3" @@ -410,12 +308,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "core-foundation" version = "0.9.2" @@ -539,16 +431,6 @@ dependencies = [ "generic-array 0.14.5", ] -[[package]] -name = "crypto-mac" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" -dependencies = [ - "generic-array 0.14.5", - "subtle", -] - [[package]] name = "csv" version = "1.1.6" @@ -597,15 +479,6 @@ dependencies = [ "generic-array 0.12.4", ] -[[package]] -name = "digest" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.5", -] - [[package]] name = "digest" version = "0.10.1" @@ -1005,12 +878,6 @@ dependencies = [ "libc", ] -[[package]] -name = "hex" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" - [[package]] name = "http" version = "0.2.6" @@ -1259,31 +1126,6 @@ dependencies = [ "anyhow", ] -[[package]] -name = "leo-asg" -version = "1.5.3" -dependencies = [ - "criterion", - "indexmap", - "leo-ast", - "leo-ast-passes", - "leo-errors", - "leo-parser", - "num-bigint", - "serde", - "serde_json", - "tendril", - "typed-arena", -] - -[[package]] -name = "leo-asg-passes" -version = "1.5.3" -dependencies = [ - "leo-asg", - "leo-errors", -] - [[package]] name = "leo-ast" version = "1.5.3" @@ -1318,6 +1160,7 @@ dependencies = [ "leo-ast", "leo-errors", "leo-parser", + "sha2", ] [[package]] @@ -1337,19 +1180,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "leo-imports" -version = "1.5.3" -dependencies = [ - "indexmap", - "leo-ast", - "leo-ast-passes", - "leo-errors", - "leo-parser", - "leo-span", - "tracing", -] - [[package]] name = "leo-input" version = "1.5.3" @@ -1379,12 +1209,8 @@ dependencies = [ "leo-ast", "leo-compiler", "leo-errors", - "leo-imports", - "leo-input", "leo-package", "leo-parser", - "leo-stdlib", - "leo-synthesizer", "notify", "rand 0.8.4", "rand_core 0.6.3", @@ -1393,11 +1219,6 @@ dependencies = [ "self_update", "serde", "serde_json", - "snarkvm-algorithms", - "snarkvm-curves", - "snarkvm-gadgets", - "snarkvm-r1cs", - "snarkvm-utilities", "structopt", "test_dir", "toml", @@ -1406,10 +1227,6 @@ dependencies = [ "zip", ] -[[package]] -name = "leo-linter" -version = "1.5.3" - [[package]] name = "leo-package" version = "1.5.3" @@ -1467,23 +1284,6 @@ dependencies = [ "leo-parser", ] -[[package]] -name = "leo-synthesizer" -version = "1.5.3" -dependencies = [ - "eyre", - "hex", - "leo-errors", - "num-bigint", - "serde", - "serde_json", - "sha2", - "snarkvm-curves", - "snarkvm-fields", - "snarkvm-gadgets", - "snarkvm-r1cs", -] - [[package]] name = "leo-test-framework" version = "1.5.3" @@ -1496,20 +1296,6 @@ dependencies = [ "structopt", ] -[[package]] -name = "leo-wasm" -version = "1.5.3" -dependencies = [ - "leo-asg", - "leo-ast", - "leo-ast-passes", - "leo-errors", - "leo-parser", - "serde", - "serde_json", - "wasm-bindgen", -] - [[package]] name = "libc" version = "0.2.117" @@ -1740,27 +1526,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "num-bigint" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-integer" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" -dependencies = [ - "autocfg", - "num-traits", -] - [[package]] name = "num-traits" version = "0.2.14" @@ -1813,12 +1578,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" -[[package]] -name = "opaque-debug" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" - [[package]] name = "openssl" version = "0.10.38" @@ -2002,15 +1761,6 @@ dependencies = [ "termtree", ] -[[package]] -name = "proc-macro-crate" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" -dependencies = [ - "toml", -] - [[package]] name = "proc-macro-error" version = "1.0.4" @@ -2484,7 +2234,7 @@ dependencies = [ "block-buffer 0.7.3", "digest 0.8.1", "fake-simd", - "opaque-debug 0.2.3", + "opaque-debug", ] [[package]] @@ -2531,136 +2281,6 @@ dependencies = [ "serde", ] -[[package]] -name = "snarkvm-algorithms" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "aleo-std", - "anyhow", - "blake2", - "blake2s_simd", - "crossbeam-channel", - "derivative", - "digest 0.9.0", - "hex", - "itertools 0.10.3", - "lazy_static", - "num_cpus", - "once_cell", - "rand 0.8.4", - "rand_chacha 0.3.1", - "rayon", - "serde", - "sha2", - "smallvec", - "snarkvm-curves", - "snarkvm-fields", - "snarkvm-profiler", - "snarkvm-r1cs", - "snarkvm-utilities", - "thiserror", -] - -[[package]] -name = "snarkvm-curves" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "derivative", - "rand 0.8.4", - "rustc_version", - "serde", - "snarkvm-fields", - "snarkvm-utilities", - "thiserror", -] - -[[package]] -name = "snarkvm-derives" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "proc-macro-crate", - "proc-macro-error", - "proc-macro2 1.0.36", - "quote 1.0.15", - "syn 1.0.86", -] - -[[package]] -name = "snarkvm-fields" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "anyhow", - "derivative", - "rand 0.8.4", - "rayon", - "serde", - "snarkvm-utilities", - "thiserror", -] - -[[package]] -name = "snarkvm-gadgets" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "anyhow", - "derivative", - "digest 0.9.0", - "itertools 0.10.3", - "num-bigint", - "num-integer", - "num-traits", - "snarkvm-algorithms", - "snarkvm-curves", - "snarkvm-fields", - "snarkvm-r1cs", - "snarkvm-utilities", - "thiserror", -] - -[[package]] -name = "snarkvm-profiler" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" - -[[package]] -name = "snarkvm-r1cs" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "anyhow", - "cfg-if 1.0.0", - "fxhash", - "indexmap", - "itertools 0.10.3", - "snarkvm-curves", - "snarkvm-fields", - "snarkvm-utilities", - "thiserror", -] - -[[package]] -name = "snarkvm-utilities" -version = "0.7.5" -source = "git+https://github.com/AleoHQ/snarkVM.git?rev=51633e2#51633e2fac247bc829bd316a93f59b6ba0759661" -dependencies = [ - "aleo-std", - "anyhow", - "bincode", - "itertools 0.10.3", - "num-bigint", - "num_cpus", - "rand 0.8.4", - "rayon", - "serde", - "snarkvm-derives", - "thiserror", -] - [[package]] name = "socket2" version = "0.4.4" @@ -2707,12 +2327,6 @@ dependencies = [ "syn 1.0.86", ] -[[package]] -name = "subtle" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" - [[package]] name = "syn" version = "0.15.44" @@ -3002,12 +2616,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "typed-arena" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0685c84d5d54d1c26f7d3eb96cd41550adb97baed141a761cf335d3d33bcd0ae" - [[package]] name = "typenum" version = "1.15.0" @@ -3159,8 +2767,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "25f1af7423d8588a3d840681122e72e6a24ddbcb3f0ec385cac0d12d24256c06" dependencies = [ "cfg-if 1.0.0", - "serde", - "serde_json", "wasm-bindgen-macro", ] diff --git a/Cargo.toml b/Cargo.toml index ff9bf37f44..ee9d9276c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,24 +27,24 @@ path = "leo/main.rs" [workspace] members = [ - "asg", - "asg-passes", +# "asg", +# "asg-passes", "ast", "ast-passes", "compiler", "errors", "grammar", - "imports", - "input", - "linter", +# "imports", +# "input", +# "linter", "package", "parser", "span", # "state", - "stdlib", - "synthesizer", - "test-framework", - "wasm" +# "stdlib", +# "synthesizer", +# "test-framework", +# "wasm" ] [dependencies.leo-ast] @@ -59,13 +59,13 @@ version = "1.5.3" path = "./errors" version = "1.5.3" -[dependencies.leo-imports] -path = "./imports" -version = "1.5.3" - -[dependencies.leo-input] -path = "./input" -version = "1.5.3" +#[dependencies.leo-imports] +#path = "./imports" +#version = "1.5.3" +# +#[dependencies.leo-input] +#path = "./input" +#version = "1.5.3" [dependencies.leo-package] path = "./package" @@ -79,36 +79,32 @@ version = "1.5.3" #path = "./state" #version = "1.5.3" -[dependencies.leo-stdlib] -path = "./stdlib" -version = "1.5.3" +#[dependencies.leo-stdlib] +#path = "./stdlib" +#version = "1.5.3" -[dependencies.leo-synthesizer] -path = "./synthesizer" -version = "1.5.3" - -[dependencies.snarkvm-algorithms] -git = "https://github.com/AleoHQ/snarkVM.git" -rev = "51633e2" - -[dependencies.snarkvm-curves] -git = "https://github.com/AleoHQ/snarkVM.git" -rev = "51633e2" -default-features = false - -[dependencies.snarkvm-gadgets] -git = "https://github.com/AleoHQ/snarkVM.git" -rev = "51633e2" -default-features = false - -[dependencies.snarkvm-r1cs] -git = "https://github.com/AleoHQ/snarkVM.git" -rev = "51633e2" -default-features = false - -[dependencies.snarkvm-utilities] -git = "https://github.com/AleoHQ/snarkVM.git" -rev = "51633e2" +#[dependencies.snarkvm-algorithms] +#git = "https://github.com/AleoHQ/snarkVM.git" +#rev = "51633e2" +# +#[dependencies.snarkvm-curves] +#git = "https://github.com/AleoHQ/snarkVM.git" +#rev = "51633e2" +#default-features = false +# +#[dependencies.snarkvm-gadgets] +#git = "https://github.com/AleoHQ/snarkVM.git" +#rev = "51633e2" +#default-features = false +# +#[dependencies.snarkvm-r1cs] +#git = "https://github.com/AleoHQ/snarkVM.git" +#rev = "51633e2" +#default-features = false +# +#[dependencies.snarkvm-utilities] +#git = "https://github.com/AleoHQ/snarkVM.git" +#rev = "51633e2" [dependencies.clap] version = "3.0.10" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index fc6698ad3e..4fc58e75fd 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -30,6 +30,9 @@ version = "1.5.3" path = "../parser" version = "1.5.3" +[dependencies.sha2] +version = "0.10" + [features] default = [ ] ci_skip = [ "leo-ast/ci_skip" ] diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index 861dc8d30a..176aaea6dd 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -25,16 +25,17 @@ use leo_errors::emitter::Handler; use leo_errors::{CompilerError, Result}; +use sha2::{Digest, Sha256}; use std::fs; use std::path::PathBuf; /// The primary entry point of the Leo compiler. -pub struct RunCompiler<'a> { +pub struct Compiler<'a> { handler: &'a Handler, main_file_path: PathBuf, } -impl<'a> RunCompiler<'a> { +impl<'a> Compiler<'a> { /// /// Returns a new Leo compiler. /// @@ -45,10 +46,26 @@ impl<'a> RunCompiler<'a> { } } + /// + /// Returns a SHA256 checksum of the program file. + /// + pub fn checksum(&self) -> Result { + // Read in the main file as string + let unparsed_file = fs::read_to_string(&self.main_file_path) + .map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e))?; + + // Hash the file contents + let mut hasher = Sha256::new(); + hasher.update(unparsed_file.as_bytes()); + let hash = hasher.finalize(); + + Ok(format!("{:x}", hash)) + } + /// /// Returns a compiled Leo program. /// - pub fn run(self) -> Result { + pub fn compile(self) -> Result { // Load the program file. let program_string = fs::read_to_string(&self.main_file_path) .map_err(|e| CompilerError::file_read_error(self.main_file_path.clone(), e))?; diff --git a/errors/src/package/package_errors.rs b/errors/src/package/package_errors.rs index 945c2da8b7..2413b5fda8 100644 --- a/errors/src/package/package_errors.rs +++ b/errors/src/package/package_errors.rs @@ -35,6 +35,14 @@ create_errors!( help: None, } + /// For when creating the imports directory failed. + @backtraced + failed_to_create_imports_directory { + args: (error: impl ErrorArg), + msg: format!("failed creating imports directory {}", error), + help: None, + } + /// For when removing the imports directory failed. @backtraced failed_to_remove_imports_directory { @@ -75,6 +83,22 @@ create_errors!( help: None, } + /// For when creating the inputs directory failed. + @backtraced + failed_to_create_inputs_directory { + args: (error: impl ErrorArg), + msg: format!("failed creating inputs directory {}", error), + help: None, + } + + /// For when reading the circuit file failed. + @backtraced + failed_to_read_circuit_file { + args: (path: impl Debug), + msg: format!("Cannot read circuit file from the provided file path - {:?}", path), + help: None, + } + /// For when reading the input directory failed. @backtraced failed_to_read_inputs_directory { @@ -91,6 +115,39 @@ create_errors!( help: None, } + /// For when reading the state file failed. + @backtraced + failed_to_read_state_file { + args: (path: impl Debug), + msg: format!("Cannot read state file from the provided file path - {:?}", path), + help: None, + } + + + /// For when reading the snapshot file failed. + @backtraced + failed_to_read_snapshot_file { + args: (path: impl Debug), + msg: format!("Cannot read snapshot file from the provided file path - {:?}", path), + help: None, + } + + /// For when reading the checksum file failed. + @backtraced + failed_to_read_checksum_file { + args: (path: impl Debug), + msg: format!("Cannot read checksum file from the provided file path - {:?}", path), + help: None, + } + + /// For when reading the proof file failed. + @backtraced + failed_to_read_proof_file { + args: (path: impl Debug), + msg: format!("Cannot read proof file from the provided file path - {:?}", path), + help: None, + } + /// For when reading the proving key failed. @backtraced failed_to_read_proving_key_file { @@ -107,6 +164,14 @@ create_errors!( help: None, } + /// For when creating the manifest file failed. + @backtraced + failed_to_create_manifest_file { + args: (filename: impl Display, error: impl ErrorArg), + msg: format!("failed creating manifest file `{}` {}", filename, error), + help: None, + } + /// For when parsing the manifest file failed. @backtraced failed_to_parse_manifest_file { @@ -115,6 +180,14 @@ create_errors!( help: None, } + /// For when opening the manifest file failed. + @backtraced + failed_to_open_manifest_file { + args: (filename: impl Display, error: impl ErrorArg), + msg: format!("failed openining manifest file `{}` {}", filename, error), + help: None, + } + /// For when reading the manifest file failed. @backtraced failed_to_read_manifest_file { @@ -123,6 +196,31 @@ create_errors!( help: None, } + /// For when writing the manifest file failed. + @backtraced + failed_to_write_manifest_file { + args: (filename: impl Display, error: impl ErrorArg), + msg: format!("failed writing manifest file `{}` {}", filename, error), + help: None, + } + + /// For when the manifest file has an IO error. + @backtraced + io_error_manifest_file { + args: (error: impl ErrorArg), + msg: format!("IO error manifest file from the provided file path - {}", error), + help: None, + } + + /// For when getting the manifest metadata file failed. + @backtraced + failed_to_get_manifest_metadata_file { + args: (filename: impl Display, error: impl ErrorArg), + msg: format!("failed getting manifest metadata file `{}` {}", filename, error), + help: None, + } + + /// For when creating the zip file failed. @backtraced failed_to_create_zip_file { @@ -163,6 +261,62 @@ create_errors!( help: None, } + /// For when the circuit file has an IO error. + @backtraced + io_error_circuit_file { + args: (error: impl ErrorArg), + msg: format!("IO error circuit file from the provided file path - {}", error), + help: None, + } + + /// For when the checksum file has an IO error. + @backtraced + io_error_checksum_file { + args: (error: impl ErrorArg), + msg: format!("IO error checksum file from the provided file path - {}", error), + help: None, + } + + /// For when the proof file has an IO error. + @backtraced + io_error_proof_file { + args: (error: impl ErrorArg), + msg: format!("IO error proof file from the provided file path - {}", error), + help: None, + } + + /// For when the readme file has an IO error. + @backtraced + io_error_readme_file { + args: (error: impl ErrorArg), + msg: format!("IO error readme file from the provided file path - {}", error), + help: None, + } + + /// For when the main file has an IO error. + @backtraced + io_error_main_file { + args: (error: impl ErrorArg), + msg: format!("IO error main file from the provided file path - {}", error), + help: None, + } + + /// For when removing the circuit file failed. + @backtraced + failed_to_remove_circuit_file { + args: (path: impl Debug), + msg: format!("failed removing circuit file from the provided file path - {:?}", path), + help: None, + } + + /// For when removing the checksum file failed. + @backtraced + failed_to_remove_checksum_file { + args: (path: impl Debug), + msg: format!("failed removing checksum file from the provided file path - {:?}", path), + help: None, + } + /// For when removing the zip file failed. @backtraced failed_to_remove_zip_file { @@ -171,6 +325,88 @@ create_errors!( help: None, } + /// For when removing the snapshot file failed. + @backtraced + failed_to_remove_snapshot_file { + args: (path: impl Debug), + msg: format!("failed removing snapshot file from the provided file path - {:?}", path), + help: None, + } + + + /// For when removing the proof file failed. + @backtraced + failed_to_remove_proof_file { + args: (path: impl Debug), + msg: format!("failed removing proof file from the provided file path - {:?}", path), + help: None, + } + + /// For when removing the proving_key file failed. + @backtraced + failed_to_remove_proving_key_file { + args: (path: impl Debug), + msg: format!("failed removing proving_key file from the provided file path - {:?}", path), + help: None, + } + + /// For when removing the verification_key file failed. + @backtraced + failed_to_remove_verification_key_file { + args: (path: impl Debug), + msg: format!("failed removing verification_key file from the provided file path - {:?}", path), + help: None, + } + + /// For when the input file has an IO error. + @backtraced + io_error_input_file { + args: (error: impl ErrorArg), + msg: format!("IO error input file from the provided file path - {}", error), + help: None, + } + + + /// For when the state file has an IO error. + @backtraced + io_error_state_file { + args: (error: impl ErrorArg), + msg: format!("IO error state file from the provided file path - {}", error), + help: None, + } + + /// For when the proving_key file has an IO error. + @backtraced + io_error_proving_key_file { + args: (error: impl ErrorArg), + msg: format!("IO error proving_key file from the provided file path - {}", error), + help: None, + } + + /// For when the verification_key file has an IO error. + @backtraced + io_error_verification_key_file { + args: (error: impl ErrorArg), + msg: format!("IO error verification_key file from the provided file path - {}", error), + help: None, + } + + /// For when the gitignore file has an IO error. + @backtraced + io_error_gitignore_file { + args: (error: impl ErrorArg), + msg: format!("IO error gitignore file from the provided file path - {}", error), + help: None, + } + + /// For when creating the source directory failed. + @backtraced + failed_to_create_source_directory { + args: (error: impl ErrorArg), + msg: format!("failed creating source directory {}", error), + help: None, + } + /// For when getting a source file entry failed. @backtraced failed_to_get_source_file_entry { @@ -230,7 +466,7 @@ create_errors!( @backtraced failed_to_create_lock_file { args: (filename: impl Display, error: impl ErrorArg), - msg: format!("failed creating manifest file `{}` {}", filename, error), + msg: format!("failed creating lock file `{}` {}", filename, error), help: None, } diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 90c591009d..3161d24f7b 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -15,21 +15,15 @@ // along with the Leo library. If not, see . use crate::{commands::Command, context::Context}; -use leo_compiler::{ - compiler::{thread_leaked_context, Compiler}, - group::targets::edwards_bls12::EdwardsGroupType, - AstSnapshotOptions, CompilerOptions, -}; +use leo_compiler::Compiler; use leo_errors::{CliError, Result}; use leo_package::{ inputs::*, outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, source::{MainFile, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, }; -use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit}; -use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq}; -use snarkvm_r1cs::ConstraintSystem; +use leo_ast::Ast; use structopt::StructOpt; use tracing::span::Span; @@ -57,43 +51,43 @@ pub struct BuildOptions { pub enable_type_inferenced_ast_snapshot: bool, } -impl From for CompilerOptions { - fn from(options: BuildOptions) -> Self { - if options.disable_all_optimizations { - CompilerOptions { - constant_folding_enabled: false, - dead_code_elimination_enabled: false, - } - } else { - CompilerOptions { - constant_folding_enabled: !options.disable_constant_folding, - dead_code_elimination_enabled: !options.disable_code_elimination, - } - } - } -} +// impl From for CompilerOptions { +// fn from(options: BuildOptions) -> Self { +// if options.disable_all_optimizations { +// CompilerOptions { +// constant_folding_enabled: false, +// dead_code_elimination_enabled: false, +// } +// } else { +// CompilerOptions { +// constant_folding_enabled: !options.disable_constant_folding, +// dead_code_elimination_enabled: !options.disable_code_elimination, +// } +// } +// } +// } -impl From for AstSnapshotOptions { - fn from(options: BuildOptions) -> Self { - if options.enable_all_ast_snapshots { - AstSnapshotOptions { - spans_enabled: options.enable_spans, - initial: true, - imports_resolved: true, - canonicalized: true, - type_inferenced: true, - } - } else { - AstSnapshotOptions { - spans_enabled: options.enable_spans, - initial: options.enable_initial_ast_snapshot, - imports_resolved: options.enable_imports_resolved_ast_snapshot, - canonicalized: options.enable_canonicalized_ast_snapshot, - type_inferenced: options.enable_type_inferenced_ast_snapshot, - } - } - } -} +// impl From for AstSnapshotOptions { +// fn from(options: BuildOptions) -> Self { +// if options.enable_all_ast_snapshots { +// AstSnapshotOptions { +// spans_enabled: options.enable_spans, +// initial: true, +// imports_resolved: true, +// canonicalized: true, +// type_inferenced: true, +// } +// } else { +// AstSnapshotOptions { +// spans_enabled: options.enable_spans, +// initial: options.enable_initial_ast_snapshot, +// imports_resolved: options.enable_imports_resolved_ast_snapshot, +// canonicalized: options.enable_canonicalized_ast_snapshot, +// type_inferenced: options.enable_type_inferenced_ast_snapshot, +// } +// } +// } +// } /// Compile and build program command. #[derive(StructOpt, Debug)] @@ -105,7 +99,7 @@ pub struct Build { impl Command for Build { type Input = (); - type Output = (Compiler<'static, Fq, EdwardsGroupType>, bool); + type Output = (Ast, bool); fn log_span(&self) -> Span { tracing::span!(tracing::Level::INFO, "Build") @@ -152,60 +146,68 @@ impl Command for Build { main_file_path.push(MAIN_FILENAME); // Load the input file at `package_name.in` - let (input_string, input_path) = InputFile::new(&package_name).read_from(&path)?; + // let (input_string, input_path) = InputFile::new(&package_name).read_from(&path)?; // Load the state file at `package_name.in` - let (state_string, state_path) = StateFile::new(&package_name).read_from(&path)?; + // let (state_string, state_path) = StateFile::new(&package_name).read_from(&path)?; // Log compilation of files to console tracing::info!("Compiling main program... ({:?})", main_file_path); - let imports_map = if context.lock_file_exists()? { - context.lock_file()?.to_import_map() - } else { - Default::default() - }; + // let imports_map = if context.lock_file_exists()? { + // context.lock_file()?.to_import_map() + // } else { + // Default::default() + // }; // Load the program at `main_file_path` - let program = Compiler::::parse_program_with_input( - package_name.clone(), - main_file_path, - output_directory, - &input_string, - &input_path, - &state_string, - &state_path, - thread_leaked_context(), - Some(self.compiler_options.clone().into()), - imports_map, - Some(self.compiler_options.into()), - )?; + // let program = Compiler::::parse_program_with_input( + // package_name.clone(), + // main_file_path, + // output_directory, + // &input_string, + // &input_path, + // &state_string, + // &state_path, + // thread_leaked_context(), + // Some(self.compiler_options.clone().into()), + // imports_map, + // Some(self.compiler_options.into()), + // )?; + + // Initialize error handler + let handler = leo_errors::emitter::Handler::default(); + + let program = Compiler::new(&handler, main_file_path); // Compute the current program checksum let program_checksum = program.checksum()?; + // Compile the program + let program_compiled = program.compile()?; + // Generate the program on the constraint system and verify correctness { - let mut cs = CircuitSynthesizer:: { - constraints: Default::default(), - public_variables: Default::default(), - private_variables: Default::default(), - namespaces: Default::default(), - }; - let temporary_program = program.clone(); - let output = temporary_program.compile_constraints(&mut cs)?; - - tracing::debug!("Compiled output - {:#?}", output); - tracing::info!("Number of constraints - {:#?}", cs.num_constraints()); + // let mut cs = CircuitSynthesizer:: { + // constraints: Default::default(), + // public_variables: Default::default(), + // private_variables: Default::default(), + // namespaces: Default::default(), + // }; + // let temporary_program = program.clone(); + // let output = temporary_program.compile_constraints(&mut cs)?; + // + // tracing::debug!("Compiled output - {:#?}", output); + // tracing::info!("Number of constraints - {:#?}", cs.num_constraints()); // Serialize the circuit - let circuit_object = SerializedCircuit::from(cs); - let json = circuit_object.to_json_string().unwrap(); + // let circuit_object = SerializedCircuit::from(cs); + // let json = circuit_object.to_json_string().unwrap(); // println!("json: {}", json); // Write serialized circuit to circuit `.json` file. - let circuit_file = CircuitFile::new(&package_name); - circuit_file.write_to(&path, json)?; + // let circuit_file = CircuitFile::new(&package_name); + // circuit_file.write_to(&path, json)?; // Check that we can read the serialized circuit file // let serialized = circuit_file.read_from(&package_path)?; @@ -236,6 +238,6 @@ impl Command for Build { tracing::info!("Complete"); - Ok((program, checksum_differs)) + Ok((program_compiled, checksum_differs)) } } diff --git a/leo/commands/mod.rs b/leo/commands/mod.rs index b20bde89fe..cf3142f10a 100644 --- a/leo/commands/mod.rs +++ b/leo/commands/mod.rs @@ -23,42 +23,42 @@ use tracing::span::Span; // local program commands pub mod build; pub use build::Build; - -pub mod clean; -pub use clean::Clean; - -pub mod deploy; -pub use deploy::Deploy; - -pub mod init; -pub use init::Init; - -pub mod lint; -pub use lint::Lint; - -pub mod new; -pub use new::New; - -pub mod prove; -pub use prove::Prove; - -pub mod run; -pub use run::Run; - -pub mod setup; -pub use setup::Setup; - -pub mod test; -pub use test::Test; - -pub mod update; -pub use update::{Automatic as UpdateAutomatic, Update}; - -pub mod watch; -pub use watch::Watch; +// +// pub mod clean; +// pub use clean::Clean; +// +// pub mod deploy; +// pub use deploy::Deploy; +// +// pub mod init; +// pub use init::Init; +// +// pub mod lint; +// pub use lint::Lint; +// +// pub mod new; +// pub use new::New; +// +// pub mod prove; +// pub use prove::Prove; +// +// pub mod run; +// pub use run::Run; +// +// pub mod setup; +// pub use setup::Setup; +// +// pub mod test; +// pub use test::Test; +// +// pub mod update; +// pub use update::{Automatic as UpdateAutomatic, Update}; +// +// pub mod watch; +// pub use watch::Watch; // Aleo PM related commands -pub mod package; +// pub mod package; /// Base trait for the Leo CLI, see methods and their documentation for details. pub trait Command { diff --git a/leo/main.rs b/leo/main.rs index eb500655af..494e920c85 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -22,8 +22,11 @@ pub mod logger; pub mod updater; use commands::{ - package::{Clone, Fetch, Login, Logout, Publish}, - Build, Clean, Command, Deploy, Init, Lint, New, Prove, Run, Setup, Test, Update, Watch, + // package::{Clone, Fetch, Login, Logout, Publish}, + Build, + // Clean, + Command, + // Deploy, Init, Lint, New, Prove, Run, Setup, Test, Update, Watch, }; use leo_errors::Result; @@ -59,117 +62,116 @@ struct Opt { #[derive(StructOpt, Debug)] #[structopt(setting = AppSettings::ColoredHelp)] enum CommandOpts { - #[structopt(about = "Create a new Leo package in an existing directory")] - Init { - #[structopt(flatten)] - command: Init, - }, - - #[structopt(about = "Create a new Leo package in a new directory")] - New { - #[structopt(flatten)] - command: New, - }, - + // #[structopt(about = "Create a new Leo package in an existing directory")] + // Init { + // #[structopt(flatten)] + // command: Init, + // }, + // + // #[structopt(about = "Create a new Leo package in a new directory")] + // New { + // #[structopt(flatten)] + // command: New, + // }, #[structopt(about = "Compile the current package as a program")] Build { #[structopt(flatten)] command: Build, }, - - #[structopt(about = "Run a program setup")] - Setup { - #[structopt(flatten)] - command: Setup, - }, - - #[structopt(about = "Run the program and produce a proof")] - Prove { - #[structopt(flatten)] - command: Prove, - }, - - #[structopt(about = "Run a program with input variables")] - Run { - #[structopt(flatten)] - command: Run, - }, - - #[structopt(about = "Clean the output directory")] - Clean { - #[structopt(flatten)] - command: Clean, - }, - - #[structopt(about = "Watch for changes of Leo source files")] - Watch { - #[structopt(flatten)] - command: Watch, - }, - - #[structopt(about = "Update Leo to the latest version")] - Update { - #[structopt(flatten)] - command: Update, - }, - - #[structopt(about = "Compile and run all tests in the current package")] - Test { - #[structopt(flatten)] - command: Test, - }, - + // + // #[structopt(about = "Run a program setup")] + // Setup { + // #[structopt(flatten)] + // command: Setup, + // }, + // + // #[structopt(about = "Run the program and produce a proof")] + // Prove { + // #[structopt(flatten)] + // command: Prove, + // }, + // + // #[structopt(about = "Run a program with input variables")] + // Run { + // #[structopt(flatten)] + // command: Run, + // }, + // + // #[structopt(about = "Clean the output directory")] + // Clean { + // #[structopt(flatten)] + // command: Clean, + // }, + // + // #[structopt(about = "Watch for changes of Leo source files")] + // Watch { + // #[structopt(flatten)] + // command: Watch, + // }, + // + // #[structopt(about = "Update Leo to the latest version")] + // Update { + // #[structopt(flatten)] + // command: Update, + // }, + // + // #[structopt(about = "Compile and run all tests in the current package")] + // Test { + // #[structopt(flatten)] + // command: Test, + // }, + // // #[structopt(about = "Import a package from the Aleo Package Manager")] // Add { // #[structopt(flatten)] // command: Add, // }, - #[structopt(about = "Pull dependencies from Aleo Package Manager")] - Fetch { - #[structopt(flatten)] - command: Fetch, - }, - - #[structopt(about = "Clone a package from the Aleo Package Manager")] - Clone { - #[structopt(flatten)] - command: Clone, - }, - - #[structopt(about = "Login to the Aleo Package Manager")] - Login { - #[structopt(flatten)] - command: Login, - }, - - #[structopt(about = "Logout of the Aleo Package Manager")] - Logout { - #[structopt(flatten)] - command: Logout, - }, - - #[structopt(about = "Publish the current package to the Aleo Package Manager")] - Publish { - #[structopt(flatten)] - command: Publish, - }, - + // #[structopt(about = "Pull dependencies from Aleo Package Manager")] + // Fetch { + // #[structopt(flatten)] + // command: Fetch, + // }, + // + // #[structopt(about = "Clone a package from the Aleo Package Manager")] + // Clone { + // #[structopt(flatten)] + // command: Clone, + // }, + // + // #[structopt(about = "Login to the Aleo Package Manager")] + // Login { + // #[structopt(flatten)] + // command: Login, + // }, + // + // #[structopt(about = "Logout of the Aleo Package Manager")] + // Logout { + // #[structopt(flatten)] + // command: Logout, + // }, + // + // #[structopt(about = "Publish the current package to the Aleo Package Manager")] + // Publish { + // #[structopt(flatten)] + // command: Publish, + // }, + // // #[structopt(about = "Uninstall a package from the current package")] // Remove { // #[structopt(flatten)] // command: Remove, // }, - #[structopt(about = "Lints the Leo files in the package (*)")] - Lint { - #[structopt(flatten)] - command: Lint, - }, - - #[structopt(about = "Deploy the current package as a program to the network (*)")] - Deploy { - #[structopt(flatten)] - command: Deploy, - }, + // #[structopt(about = "Lints the Leo files in the package (*)")] + // Lint { + // #[structopt(flatten)] + // command: Lint, + // }, + // + // #[structopt(about = "Deploy the current package as a program to the network (*)")] + // Deploy { + // #[structopt(flatten)] + // command: Deploy, + // }, } fn main() { @@ -197,26 +199,26 @@ fn run_with_args(opt: Opt) -> Result<()> { }); match opt.command { - CommandOpts::Init { command } => command.try_execute(context), - CommandOpts::New { command } => command.try_execute(context), + // CommandOpts::Init { command } => command.try_execute(context), + // CommandOpts::New { command } => command.try_execute(context), CommandOpts::Build { command } => command.try_execute(context), - CommandOpts::Setup { command } => command.try_execute(context), - CommandOpts::Prove { command } => command.try_execute(context), - CommandOpts::Test { command } => command.try_execute(context), - CommandOpts::Run { command } => command.try_execute(context), - CommandOpts::Clean { command } => command.try_execute(context), - CommandOpts::Watch { command } => command.try_execute(context), - CommandOpts::Update { command } => command.try_execute(context), - - // CommandOpts::Add { command } => command.try_execute(context), - CommandOpts::Fetch { command } => command.try_execute(context), - CommandOpts::Clone { command } => command.try_execute(context), - CommandOpts::Login { command } => command.try_execute(context), - CommandOpts::Logout { command } => command.try_execute(context), - CommandOpts::Publish { command } => command.try_execute(context), - // CommandOpts::Remove { command } => command.try_execute(context), - CommandOpts::Lint { command } => command.try_execute(context), - CommandOpts::Deploy { command } => command.try_execute(context), + // CommandOpts::Setup { command } => command.try_execute(context), + // CommandOpts::Prove { command } => command.try_execute(context), + // CommandOpts::Test { command } => command.try_execute(context), + // CommandOpts::Run { command } => command.try_execute(context), + // CommandOpts::Clean { command } => command.try_execute(context), + // CommandOpts::Watch { command } => command.try_execute(context), + // CommandOpts::Update { command } => command.try_execute(context), + // + // // CommandOpts::Add { command } => command.try_execute(context), + // CommandOpts::Fetch { command } => command.try_execute(context), + // CommandOpts::Clone { command } => command.try_execute(context), + // CommandOpts::Login { command } => command.try_execute(context), + // CommandOpts::Logout { command } => command.try_execute(context), + // CommandOpts::Publish { command } => command.try_execute(context), + // // CommandOpts::Remove { command } => command.try_execute(context), + // CommandOpts::Lint { command } => command.try_execute(context), + // CommandOpts::Deploy { command } => command.try_execute(context), } }