diff --git a/.resources/release-version b/.resources/release-version index 02e8c95da5..0408c30b42 100644 --- a/.resources/release-version +++ b/.resources/release-version @@ -1 +1 @@ -v1.1.8 \ No newline at end of file +v1.2.0 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 62883698c4..d783152ca3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,9 +50,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.37" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee67c11feeac938fae061b232e38e0b6d94f97a9df10e6271319325ac4c56a86" +checksum = "afddf7f520a80dbf76e6f50a35bca42a2331ef227a28b3b6dc5c2e2338d114b1" [[package]] name = "arrayref" @@ -277,7 +277,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b9434b9a5aa1450faa3f9cb14ea0e8c53bb5d2b3c1bfd1ab4fc03e9f33fbfb0" dependencies = [ - "rustc_version", + "rustc_version 0.2.3", ] [[package]] @@ -801,9 +801,18 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" [[package]] name = "futures" -version = "0.1.30" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c7e4c2612746b0df8fed4ce0c69156021b704c9aefa360311c04e6e9e002eed" +checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] [[package]] name = "futures-channel" @@ -812,6 +821,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" dependencies = [ "futures-core", + "futures-sink", ] [[package]] @@ -820,12 +830,35 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "847ce131b72ffb13b6109a221da9ad97a64cbe48feb1028356b836b47b8f1748" +[[package]] +name = "futures-executor" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4caa2b2b68b880003057c1dd49f1ed937e38f22fcf6c212188a121f08cf40a65" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + [[package]] name = "futures-io" version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "611834ce18aaa1bd13c4b374f5d653e1027cf99b6b502584ff8c9a64413b30bb" +[[package]] +name = "futures-macro" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77408a692f1f97bcc61dc001d752e00643408fbc922e4d634c655df50d595556" +dependencies = [ + "proc-macro-hack", + "proc-macro2 1.0.24", + "quote 1.0.7", + "syn 1.0.60", +] + [[package]] name = "futures-sink" version = "0.3.8" @@ -847,12 +880,17 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" dependencies = [ + "futures-channel", "futures-core", "futures-io", + "futures-macro", + "futures-sink", "futures-task", "memchr", "pin-project 1.0.2", "pin-utils", + "proc-macro-hack", + "proc-macro-nested", "slab", ] @@ -874,7 +912,7 @@ dependencies = [ "cc", "libc", "log", - "rustc_version", + "rustc_version 0.2.3", "winapi 0.3.9", ] @@ -1197,9 +1235,9 @@ dependencies = [ [[package]] name = "jsonrpc-core" -version = "14.2.0" +version = "17.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0747307121ffb9703afd93afbd0fb4f854c38fb873f2c8b90e0e902f27c7b62" +checksum = "07569945133257ff557eb37b015497104cea61a2c9edaf126c1cbd6e8332397f" dependencies = [ "futures", "log", @@ -1232,7 +1270,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leo-asg" -version = "1.1.8" +version = "1.2.0" dependencies = [ "criterion", "indexmap", @@ -1247,7 +1285,7 @@ dependencies = [ [[package]] name = "leo-ast" -version = "1.1.8" +version = "1.2.0" dependencies = [ "criterion", "indexmap", @@ -1261,7 +1299,7 @@ dependencies = [ [[package]] name = "leo-compiler" -version = "1.1.8" +version = "1.2.0" dependencies = [ "bincode", "hex", @@ -1295,7 +1333,7 @@ dependencies = [ [[package]] name = "leo-gadgets" -version = "1.1.8" +version = "1.2.0" dependencies = [ "criterion", "rand", @@ -1308,7 +1346,7 @@ dependencies = [ [[package]] name = "leo-grammar" -version = "1.1.8" +version = "1.2.0" dependencies = [ "criterion", "from-pest", @@ -1324,7 +1362,7 @@ dependencies = [ [[package]] name = "leo-imports" -version = "1.1.8" +version = "1.2.0" dependencies = [ "indexmap", "leo-asg", @@ -1336,7 +1374,7 @@ dependencies = [ [[package]] name = "leo-input" -version = "1.1.8" +version = "1.2.0" dependencies = [ "from-pest", "pest", @@ -1348,7 +1386,7 @@ dependencies = [ [[package]] name = "leo-lang" -version = "1.1.8" +version = "1.2.0" dependencies = [ "clap", "colored", @@ -1387,11 +1425,11 @@ dependencies = [ [[package]] name = "leo-linter" -version = "1.1.8" +version = "1.2.0" [[package]] name = "leo-package" -version = "1.1.8" +version = "1.2.0" dependencies = [ "lazy_static", "serde", @@ -1404,7 +1442,7 @@ dependencies = [ [[package]] name = "leo-state" -version = "1.1.8" +version = "1.2.0" dependencies = [ "indexmap", "leo-ast", @@ -1996,6 +2034,50 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2 1.0.24", + "quote 1.0.7", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.7", + "version_check", +] + +[[package]] +name = "proc-macro-hack" +version = "0.5.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" + +[[package]] +name = "proc-macro-nested" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc881b2c22681370c6a780e47af9840ef841837bc98118431d4e1868bd0c1086" + [[package]] name = "proc-macro2" version = "0.4.30" @@ -2261,6 +2343,15 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +dependencies = [ + "semver 0.11.0", +] + [[package]] name = "rusty-hook" version = "0.11.2" @@ -2451,9 +2542,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.2" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e7aab86fe2149bad8c507606bdb3f4ef5e7b2380eb92350f56122cca72a42a8" +checksum = "fa827a14b29ab7f44778d14a88d3cb76e949c45083f7dbfa507d0cb699dc12de" dependencies = [ "block-buffer 0.9.0", "cfg-if 1.0.0", @@ -2495,20 +2586,20 @@ checksum = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" [[package]] name = "smallvec" -version = "1.5.1" +version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae524f056d7d770e174287294f562e95044c68e88dec909a00d2094805db9d75" +checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "snarkvm-algorithms" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bdc4273884a3c5b1858e9ccb3dd6d7acfa60c0c38bb4876aeeb3181936dbe5f3" +checksum = "ceb01228059c36bb95507d1df131dea4e7b600c87ac26dc66c07a651d8a03f6e" dependencies = [ "blake2", "derivative", "digest 0.8.1", - "itertools 0.9.0", + "itertools 0.10.0", "rand", "rand_chacha", "rayon", @@ -2522,14 +2613,14 @@ dependencies = [ [[package]] name = "snarkvm-curves" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c0ab5c370fa0e394acc14474ce0ed162ca673e87ac496e733d402b5c71f177" +checksum = "e7f9bb31389dce334a6c0c5855829afbb1e4469c4c03143e167c5353ccb1e307" dependencies = [ "derivative", "rand", "rand_xorshift", - "rustc_version", + "rustc_version 0.3.3", "serde", "snarkvm-errors", "snarkvm-models", @@ -2538,10 +2629,12 @@ dependencies = [ [[package]] name = "snarkvm-derives" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b74eecab3b4bbcef183819fb414ad3498b6c962f21a41a2afaf73af2822eec98" +checksum = "1ccaf7047e41bc356a3af8257e9ffe13a5b619c9f51278c019d5201790ddd677" dependencies = [ + "proc-macro-crate", + "proc-macro-error", "proc-macro2 1.0.24", "quote 1.0.7", "syn 1.0.60", @@ -2549,15 +2642,15 @@ dependencies = [ [[package]] name = "snarkvm-dpc" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a3bbd6dcb0e100d514fa0f8cfb2fd8e0422660d5d816a47409d8111c536dddc" +checksum = "ea20c9a289304d22755ddfc644e164e1232f41ebe016edc8bf7f0007b828b92d" dependencies = [ "anyhow", "blake2", "derivative", "hex", - "itertools 0.9.0", + "itertools 0.10.0", "rand", "snarkvm-algorithms", "snarkvm-curves", @@ -2572,9 +2665,9 @@ dependencies = [ [[package]] name = "snarkvm-errors" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7b46326076d2797280a335f6a4c3538e5ba57db37704233e55134b3e1ab2e79" +checksum = "4dcff02240b6b5b36f47953ea9be5c29aef109164b0cebd84e7260ef7bf67f6c" dependencies = [ "base58", "bech32", @@ -2589,13 +2682,13 @@ dependencies = [ [[package]] name = "snarkvm-gadgets" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12ec20358b56a972bf280690ace5e5c1ba809e4cd31d31932f0bd15491f9be0d" +checksum = "e5692f39b5b9351b6584e1f9a2739b13d82e5a4a74a074eb0b743e9d7583fdb5" dependencies = [ "derivative", "digest 0.8.1", - "itertools 0.9.0", + "itertools 0.10.0", "snarkvm-algorithms", "snarkvm-curves", "snarkvm-errors", @@ -2605,17 +2698,17 @@ dependencies = [ [[package]] name = "snarkvm-models" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6d7532cfc6b888e8566e05e62384c4c7103fa3036555c54b98726fba4bb100" +checksum = "e622885901322b1d2b26c1bc8d94a717df1e83672cbc41a16f2afc4d2702afab" dependencies = [ "anyhow", "bincode", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "derivative", "fxhash", "indexmap", - "itertools 0.9.0", + "itertools 0.10.0", "rand", "rand_xorshift", "serde", @@ -2625,9 +2718,9 @@ dependencies = [ [[package]] name = "snarkvm-objects" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd3ca38c2a7744f4dca2bdae9441da634b06f40f762323c9e361d6a2582f3353" +checksum = "cd47dd986ba53600dd5762c72214250b37af114720dc494770114e9bf8281819" dependencies = [ "base58", "bech32", @@ -2647,9 +2740,9 @@ dependencies = [ [[package]] name = "snarkvm-parameters" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02a6590e3860f1dc78335a2ef498b21cffa4655de4cfb7cc9027d29b1093d887" +checksum = "dd0e2f9bdbce0750aa0def386e4324f278c7e0d58cfbdb42128c03d246c862f4" dependencies = [ "curl", "hex", @@ -2661,15 +2754,15 @@ dependencies = [ [[package]] name = "snarkvm-profiler" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9ec5eadd049ee06e676070d5402401373fe278a42b515141a9b14ca86a795a" +checksum = "d5f9c37df04e66b18ef0c4a69861eaf1f83170f1e71509e208d6006c20e65b91" [[package]] name = "snarkvm-storage" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf798e9883014175e2f019f019fc4db1756cf7d57408602315b270b93992258" +checksum = "1cb4f7e299b888749224eada35624347e4c99d2e5972c1c416d2d18e005fe23b" dependencies = [ "anyhow", "bincode", @@ -2689,9 +2782,9 @@ dependencies = [ [[package]] name = "snarkvm-utilities" -version = "0.0.2" +version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d78a4a12c67cc013d6a9574f3231aaf915589cebfd38d27d5f8ad24f1be5794f" +checksum = "e7518dfe2e8dc37beeaf3131ef5c77e4e9818843e6c33e7b665240dc8ec805b1" dependencies = [ "bincode", "rand", diff --git a/Cargo.toml b/Cargo.toml index 18b30ea5a2..50b38fb2e3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-lang" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "The Leo programming language" homepage = "https://aleo.org" @@ -26,6 +26,7 @@ path = "leo/main.rs" [workspace] members = [ + "asg", "ast", "compiler", "gadgets", @@ -34,60 +35,59 @@ members = [ "input", "linter", "package", - "state", - "asg" + "state" ] [dependencies.leo-ast] path = "./ast" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-compiler] path = "./compiler" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-gadgets] path = "./gadgets" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-imports] path = "./imports" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-input] path = "./input" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-package] path = "./package" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-state] path = "./state" -version = "1.1.8" +version = "1.2.0" [dependencies.snarkvm-algorithms] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-curves] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-errors] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-models] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.2" +version = "0.0.3" [dependencies.clap] version = "2.33.3" diff --git a/asg/Cargo.toml b/asg/Cargo.toml index 97a15f674a..d7fed3edc6 100644 --- a/asg/Cargo.toml +++ b/asg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-asg" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "ASG of the Leo programming language" homepage = "https://aleo.org" @@ -30,11 +30,11 @@ version = "1.6" version = "1.0" [dependencies.leo-ast] -version = "1.1" +version = "1.2.0" path = "../ast" [dependencies.leo-grammar] -version = "1.1" +version = "1.2.0" path = "../grammar" [dependencies.uuid] diff --git a/asg/src/expression/array_access.rs b/asg/src/expression/array_access.rs index ee963d59e3..01e9b22855 100644 --- a/asg/src/expression/array_access.rs +++ b/asg/src/expression/array_access.rs @@ -22,6 +22,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct ArrayAccessExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index 3f11e62e13..73033884ff 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -21,6 +21,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct ArrayInitExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index 2a34d875b8..ad4de160fd 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -22,6 +22,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct ArrayInlineExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/array_range_access.rs b/asg/src/expression/array_range_access.rs index 3cd1de4ca3..4ca809b720 100644 --- a/asg/src/expression/array_range_access.rs +++ b/asg/src/expression/array_range_access.rs @@ -22,6 +22,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct ArrayRangeAccessExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/binary.rs b/asg/src/expression/binary.rs index 6291ca5122..0dd5a6e5f4 100644 --- a/asg/src/expression/binary.rs +++ b/asg/src/expression/binary.rs @@ -22,6 +22,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct BinaryExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index e05ec761d6..306301576c 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -29,13 +29,14 @@ use crate::{ Span, Type, }; -pub use leo_ast::BinaryOperation; +pub use leo_ast::{BinaryOperation, Node as AstNode}; use std::{ cell::RefCell, sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct CallExpression { pub parent: RefCell>>, pub span: Option, @@ -194,25 +195,33 @@ impl FromAst for CallExpression { )); } } - if value.arguments.len() != function.argument_types.len() { + if value.arguments.len() != function.arguments.len() { return Err(AsgConvertError::unexpected_call_argument_count( - function.argument_types.len(), + function.arguments.len(), value.arguments.len(), &value.span, )); } + let arguments = value + .arguments + .iter() + .zip(function.arguments.iter()) + .map(|(expr, argument)| { + let argument = argument.borrow(); + let converted = + Arc::::from_ast(scope, expr, Some(argument.type_.clone().strong().partial()))?; + if argument.const_ && !converted.is_consty() { + return Err(AsgConvertError::unexpected_nonconst(&expr.span())); + } + Ok(converted) + }) + .collect::, AsgConvertError>>()?; + Ok(CallExpression { parent: RefCell::new(None), span: Some(value.span.clone()), - arguments: value - .arguments - .iter() - .zip(function.argument_types.iter()) - .map(|(expr, argument)| { - Arc::::from_ast(scope, expr, Some(argument.clone().strong().partial())) - }) - .collect::, AsgConvertError>>()?, + arguments, function, target, }) diff --git a/asg/src/expression/circuit_access.rs b/asg/src/expression/circuit_access.rs index 1a80b3b9f6..f7e0a07139 100644 --- a/asg/src/expression/circuit_access.rs +++ b/asg/src/expression/circuit_access.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::{ AsgConvertError, Circuit, @@ -52,6 +36,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct CircuitAccessExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/circuit_init.rs b/asg/src/expression/circuit_init.rs index 6a199eaf62..c05dbe6ae8 100644 --- a/asg/src/expression/circuit_init.rs +++ b/asg/src/expression/circuit_init.rs @@ -36,6 +36,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct CircuitInitExpression { pub parent: RefCell>>, pub span: Option, @@ -166,7 +167,7 @@ impl Into for &CircuitInitExpression { members: self .values .iter() - .map(|(name, value)| leo_ast::CircuitVariableDefinition { + .map(|(name, value)| leo_ast::CircuitImpliedVariableDefinition { identifier: name.clone(), expression: value.as_ref().into(), }) diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index 084ebf160a..e2cfe82512 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -34,6 +34,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct Constant { pub parent: RefCell>>, pub span: Option, @@ -173,6 +174,11 @@ impl FromAst for Constant { span: Some(span.clone()), value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), }, + Some(PartialType::Type(Type::Group)) => Constant { + parent: RefCell::new(None), + span: Some(span.clone()), + value: ConstValue::Group(GroupValue::Single(value.to_string())), + }, Some(PartialType::Type(Type::Address)) => Constant { parent: RefCell::new(None), span: Some(span.clone()), diff --git a/asg/src/expression/mod.rs b/asg/src/expression/mod.rs index 0a79a1148d..a60747022e 100644 --- a/asg/src/expression/mod.rs +++ b/asg/src/expression/mod.rs @@ -66,6 +66,7 @@ use crate::{AsgConvertError, ConstValue, FromAst, Node, PartialType, Scope, Span use std::sync::{Arc, Weak}; +#[derive(Debug)] pub enum Expression { VariableRef(VariableRef), Constant(Constant), diff --git a/asg/src/expression/ternary.rs b/asg/src/expression/ternary.rs index 12c7909ddd..7f000eb581 100644 --- a/asg/src/expression/ternary.rs +++ b/asg/src/expression/ternary.rs @@ -21,6 +21,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct TernaryExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/tuple_access.rs b/asg/src/expression/tuple_access.rs index 25774fa9f4..3a491eec18 100644 --- a/asg/src/expression/tuple_access.rs +++ b/asg/src/expression/tuple_access.rs @@ -21,6 +21,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct TupleAccessExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/tuple_init.rs b/asg/src/expression/tuple_init.rs index 169198db69..2772238e2c 100644 --- a/asg/src/expression/tuple_init.rs +++ b/asg/src/expression/tuple_init.rs @@ -21,6 +21,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct TupleInitExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index 1cddf0cd3f..2d0dafc49e 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -22,6 +22,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct UnaryExpression { pub parent: RefCell>>, pub span: Option, diff --git a/asg/src/expression/variable_ref.rs b/asg/src/expression/variable_ref.rs index b317a7de9a..9bfdf6da3f 100644 --- a/asg/src/expression/variable_ref.rs +++ b/asg/src/expression/variable_ref.rs @@ -29,7 +29,6 @@ use crate::{ Statement, Type, Variable, - VariableDeclaration, }; use std::{ @@ -37,6 +36,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct VariableRef { pub parent: RefCell>>, pub span: Option, @@ -61,7 +61,7 @@ impl ExpressionNode for VariableRef { fn enforce_parents(&self, _expr: &Arc) {} fn get_type(&self) -> Option { - Some(self.variable.borrow().type_.clone()) + Some(self.variable.borrow().type_.clone().strong()) } fn is_mut_ref(&self) -> bool { @@ -103,7 +103,7 @@ impl ExpressionNode for VariableRef { fn is_consty(&self) -> bool { let variable = self.variable.borrow(); - if variable.declaration == VariableDeclaration::IterationDefinition { + if variable.const_ { return true; } if variable.mutable || variable.assignments.len() != 1 { diff --git a/asg/src/input.rs b/asg/src/input.rs index d896f6315a..b814927f2a 100644 --- a/asg/src/input.rs +++ b/asg/src/input.rs @@ -23,7 +23,7 @@ use std::{ }; /// Stores program input values as asg nodes. -#[derive(Clone)] +#[derive(Debug, Clone)] pub struct Input { pub registers: Arc, pub state: Arc, @@ -127,8 +127,9 @@ impl Input { container: Arc::new(RefCell::new(crate::InnerVariable { id: uuid::Uuid::new_v4(), name: Identifier::new("input".to_string()), - type_: Type::Circuit(container_circuit), + type_: Type::Circuit(container_circuit).weak(), mutable: false, + const_: false, declaration: crate::VariableDeclaration::Input, references: vec![], assignments: vec![], diff --git a/asg/src/lib.rs b/asg/src/lib.rs index 76eb75f661..f93d3b4791 100644 --- a/asg/src/lib.rs +++ b/asg/src/lib.rs @@ -67,9 +67,9 @@ pub use type_::*; pub mod variable; pub use variable::*; -pub use leo_ast::{Identifier, Span}; +pub use leo_ast::{Ast, Identifier, Span}; -use std::path::Path; +use std::{cell::RefCell, path::Path, sync::Arc}; /// The abstract semantic graph (ASG) for a Leo program. /// @@ -77,42 +77,41 @@ use std::path::Path; /// These data types form a graph that begins from a [`Program`] type node. /// /// A new [`Asg`] can be created from an [`Ast`] generated in the `ast` module. -// #[derive(Debug, Eq, PartialEq)] -// pub struct Asg { -// asg: InnerProgram, -// } -// -// impl Asg { -// /// Creates a new asg from a given ast tree and import resolver. -// pub fn new( -// content: leo_ast::Program, -// resolver: &mut T, -// ) -> Result { -// InnerProgram::new(&content, resolver) -// } -// -// /// Returns a reference to the inner program ast representation. -// pub fn into_repr(self) -> Program { -// self.asg -// } -// } +#[derive(Debug, Clone)] +pub struct Asg { + asg: Arc>, +} -pub fn load_ast, Y: AsRef>(path: T, content: Y) -> Result { +impl Asg { + /// Creates a new ASG from a given AST and import resolver. + pub fn new(ast: &Ast, resolver: &mut T) -> Result { + Ok(Self { + asg: InternalProgram::new(&ast.as_repr(), resolver)?, + }) + } + + /// Returns the internal program ASG representation. + pub fn as_repr(&self) -> Arc> { + self.asg.clone() + } + + // /// Serializes the ast into a JSON string. + // pub fn to_json_string(&self) -> Result { + // serde_json::to_string_pretty(&self.asg) + // } + // + // /// Deserializes the JSON string into a ast. + // pub fn from_json_string(json: &str) -> Result { + // let ast: Program = serde_json::from_str(json)?; + // Ok(Self { ast }) + // } +} + +// TODO (howardwu): Remove this. +pub fn load_asg(content: &str, resolver: &mut T) -> Result { // Parses the Leo file and constructs a grammar ast. - let ast = leo_grammar::Grammar::new(path.as_ref(), content.as_ref()) + let ast = leo_grammar::Grammar::new(&Path::new("input.leo"), content) .map_err(|e| AsgConvertError::InternalError(format!("ast: {:?}", e)))?; - // Parses the pest ast and constructs a Leo ast. - Ok(leo_ast::Ast::new("load_ast", &ast)?.into_repr()) -} - -pub fn load_asg_from_ast( - content: leo_ast::Program, - resolver: &mut T, -) -> Result { - InnerProgram::new(&content, resolver) -} - -pub fn load_asg(content: &str, resolver: &mut T) -> Result { - InnerProgram::new(&load_ast("input.leo", content)?, resolver) + InternalProgram::new(leo_ast::Ast::new("load_ast", &ast)?.as_repr(), resolver) } diff --git a/asg/src/prelude.rs b/asg/src/prelude.rs index 8aa1199e06..a567b2ff72 100644 --- a/asg/src/prelude.rs +++ b/asg/src/prelude.rs @@ -14,12 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//todo: we should merge this with core +// TODO (protryon): We should merge this with core use crate::{AsgConvertError, Program}; -// todo: make asg deep copy so we can cache resolved core modules -// todo: figure out how to do headers without bogus returns +// TODO (protryon): Make asg deep copy so we can cache resolved core modules +// TODO (protryon): Figure out how to do headers without bogus returns pub fn resolve_core_module(module: &str) -> Result, AsgConvertError> { match module { diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index a9565d508a..120ab48322 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -23,16 +23,19 @@ use std::{ }; use uuid::Uuid; +#[derive(Debug)] pub enum CircuitMemberBody { Variable(Type), Function(Arc), } +#[derive(Debug)] pub enum CircuitMember { Variable(WeakType), Function(Arc), } +#[derive(Debug)] pub struct Circuit { pub id: Uuid, pub name: RefCell, @@ -51,6 +54,7 @@ impl PartialEq for Circuit { } impl Eq for Circuit {} +#[derive(Debug)] pub struct CircuitBody { pub scope: Scope, pub span: Option, diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 255acb0128..daff1741f6 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -38,19 +38,20 @@ use std::{ }; use uuid::Uuid; -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub enum FunctionQualifier { SelfRef, MutSelfRef, Static, } +#[derive(Debug)] pub struct Function { pub id: Uuid, pub name: RefCell, pub output: WeakType, pub has_input: bool, - pub argument_types: Vec, + pub arguments: Vec, pub circuit: RefCell>>, pub body: RefCell>, pub qualifier: FunctionQualifier, @@ -66,10 +67,10 @@ impl PartialEq for Function { } impl Eq for Function {} +#[derive(Debug)] pub struct FunctionBody { pub span: Option, pub function: Arc, - pub arguments: Vec, pub body: Arc, pub scope: Scope, } @@ -92,7 +93,7 @@ impl Function { let mut qualifier = FunctionQualifier::Static; let mut has_input = false; - let mut argument_types = vec![]; + let mut arguments = vec![]; { for input in value.input.iter() { match input { @@ -105,8 +106,24 @@ impl Function { FunctionInput::MutSelfKeyword(_) => { qualifier = FunctionQualifier::MutSelfRef; } - FunctionInput::Variable(leo_ast::FunctionInputVariable { type_, .. }) => { - argument_types.push(scope.borrow().resolve_ast_type(&type_)?.into()); + FunctionInput::Variable(leo_ast::FunctionInputVariable { + identifier, + mutable, + const_, + type_, + span: _span, + }) => { + let variable = Arc::new(RefCell::new(crate::InnerVariable { + id: Uuid::new_v4(), + name: identifier.clone(), + type_: scope.borrow().resolve_ast_type(&type_)?.weak(), + mutable: *mutable, + const_: *const_, + declaration: crate::VariableDeclaration::Parameter, + references: vec![], + assignments: vec![], + })); + arguments.push(variable.clone()); } } } @@ -119,7 +136,7 @@ impl Function { name: RefCell::new(value.identifier.clone()), output: output.into(), has_input, - argument_types, + arguments, circuit: RefCell::new(None), body: RefCell::new(Weak::new()), qualifier, @@ -134,7 +151,6 @@ impl FunctionBody { function: Arc, ) -> Result { let new_scope = InnerScope::make_subscope(scope); - let mut arguments = vec![]; { let mut scope_borrow = new_scope.borrow_mut(); if function.qualifier != FunctionQualifier::Static { @@ -142,8 +158,9 @@ impl FunctionBody { let self_variable = Arc::new(RefCell::new(crate::InnerVariable { id: Uuid::new_v4(), name: Identifier::new("self".to_string()), - type_: Type::Circuit(circuit.as_ref().unwrap().upgrade().unwrap()), + type_: WeakType::Circuit(circuit.as_ref().unwrap().clone()), mutable: function.qualifier == FunctionQualifier::MutSelfRef, + const_: false, declaration: crate::VariableDeclaration::Parameter, references: vec![], assignments: vec![], @@ -151,30 +168,9 @@ impl FunctionBody { scope_borrow.variables.insert("self".to_string(), self_variable); } scope_borrow.function = Some(function.clone()); - for input in value.input.iter() { - match input { - FunctionInput::InputKeyword(_) => {} - FunctionInput::SelfKeyword(_) => {} - FunctionInput::MutSelfKeyword(_) => {} - FunctionInput::Variable(leo_ast::FunctionInputVariable { - identifier, - mutable, - type_, - span: _span, - }) => { - let variable = Arc::new(RefCell::new(crate::InnerVariable { - id: Uuid::new_v4(), - name: identifier.clone(), - type_: scope_borrow.resolve_ast_type(&type_)?, - mutable: *mutable, - declaration: crate::VariableDeclaration::Parameter, - references: vec![], - assignments: vec![], - })); - arguments.push(variable.clone()); - scope_borrow.variables.insert(identifier.name.clone(), variable); - } - } + for argument in function.arguments.iter() { + let name = argument.borrow().name.name.clone(); + scope_borrow.variables.insert(name, argument.clone()); } } let main_block = BlockStatement::from_ast(&new_scope, &value.block, None)?; @@ -198,7 +194,6 @@ impl FunctionBody { Ok(FunctionBody { span: Some(value.span.clone()), function, - arguments, body: Arc::new(Statement::Block(main_block)), scope: new_scope, }) @@ -209,14 +204,16 @@ impl Into for &Function { fn into(self) -> leo_ast::Function { let (input, body, span) = match self.body.borrow().upgrade() { Some(body) => ( - body.arguments + body.function + .arguments .iter() .map(|variable| { let variable = variable.borrow(); leo_ast::FunctionInput::Variable(leo_ast::FunctionInputVariable { identifier: variable.name.clone(), mutable: variable.mutable, - type_: (&variable.type_).into(), + const_: variable.const_, + type_: (&variable.type_.clone().strong()).into(), span: Span::default(), }) }) diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 224474a11d..d70c2cacf8 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -32,8 +32,8 @@ use std::{cell::RefCell, sync::Arc}; use uuid::Uuid; /// Stores the Leo program abstract semantic graph (ASG). -#[derive(Clone)] -pub struct InnerProgram { +#[derive(Debug, Clone)] +pub struct InternalProgram { /// The unique id of the program. pub id: Uuid, @@ -57,7 +57,7 @@ pub struct InnerProgram { pub scope: Scope, } -pub type Program = Arc>; +pub type Program = Arc>; /// Enumerates what names are imported from a package. enum ImportSymbol { @@ -120,22 +120,22 @@ fn resolve_import_package_access( } } -impl InnerProgram { - /// Returns a new Leo program asg from the given Leo program ast and imports. +impl InternalProgram { + /// Returns a new Leo program ASG from the given Leo program AST and its imports. /// - /// stages: + /// Stages: /// 1. resolve imports into super scope /// 2. finalize declared types /// 3. finalize declared functions /// 4. resolve all asg nodes /// pub fn new( - value: &leo_ast::Program, + program: &leo_ast::Program, import_resolver: &mut T, ) -> Result { // Recursively extract imported symbols. let mut imported_symbols: Vec<(Vec, ImportSymbol, Span)> = vec![]; - for import in value.imports.iter() { + for import in program.imports.iter() { resolve_import_package(&mut imported_symbols, vec![], &import.package_type); } @@ -223,7 +223,7 @@ impl InnerProgram { // Prepare header-like scope entries. let mut proto_circuits = IndexMap::new(); - for (name, circuit) in value.circuits.iter() { + for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); let asg_circuit = Circuit::init(circuit); @@ -244,7 +244,7 @@ impl InnerProgram { function: None, })); - for (name, circuit) in value.circuits.iter() { + for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); let asg_circuit = proto_circuits.get(&name.name).unwrap(); @@ -252,7 +252,7 @@ impl InnerProgram { } let mut proto_test_functions = IndexMap::new(); - for (name, test_function) in value.tests.iter() { + for (name, test_function) in program.tests.iter() { assert_eq!(name.name, test_function.function.identifier.name); let function = Arc::new(Function::from_ast(&scope, &test_function.function)?); @@ -260,7 +260,7 @@ impl InnerProgram { } let mut proto_functions = IndexMap::new(); - for (name, function) in value.functions.iter() { + for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); let asg_function = Arc::new(Function::from_ast(&scope, function)?); @@ -273,7 +273,7 @@ impl InnerProgram { // Load concrete definitions. let mut test_functions = IndexMap::new(); - for (name, test_function) in value.tests.iter() { + for (name, test_function) in program.tests.iter() { assert_eq!(name.name, test_function.function.identifier.name); let function = proto_test_functions.get(&name.name).unwrap(); @@ -288,7 +288,7 @@ impl InnerProgram { } let mut functions = IndexMap::new(); - for (name, function) in value.functions.iter() { + for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); let asg_function = proto_functions.get(&name.name).unwrap(); @@ -299,7 +299,7 @@ impl InnerProgram { } let mut circuits = IndexMap::new(); - for (name, circuit) in value.circuits.iter() { + for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); let asg_circuit = proto_circuits.get(&name.name).unwrap(); let body = Arc::new(CircuitBody::from_ast(&scope, circuit, asg_circuit.clone())?); @@ -308,9 +308,9 @@ impl InnerProgram { circuits.insert(name.name.clone(), body); } - Ok(Arc::new(RefCell::new(InnerProgram { + Ok(Arc::new(RefCell::new(InternalProgram { id: Uuid::new_v4(), - name: value.name.clone(), + name: program.name.clone(), test_functions, functions, circuits, @@ -342,7 +342,7 @@ impl Iterator for InternalIdentifierGenerator { Some(out) } } -/// Returns an ast from the given asg program. +/// Returns an AST from the given ASG program. pub fn reform_ast(program: &Program) -> leo_ast::Program { let mut all_programs: IndexMap = IndexMap::new(); let mut program_stack = program.borrow().imported_modules.clone(); @@ -427,7 +427,7 @@ pub fn reform_ast(program: &Program) -> leo_ast::Program { } } -impl Into for &InnerProgram { +impl Into for &InternalProgram { fn into(self) -> leo_ast::Program { leo_ast::Program { name: self.name.clone(), diff --git a/asg/src/reducer/monoidal_reducer.rs b/asg/src/reducer/monoidal_reducer.rs index a49091c0d8..cd37dd601d 100644 --- a/asg/src/reducer/monoidal_reducer.rs +++ b/asg/src/reducer/monoidal_reducer.rs @@ -157,7 +157,7 @@ pub trait MonoidalReducerProgram: MonoidalReducerStatement { fn reduce_program( &mut self, - input: &InnerProgram, + input: &InternalProgram, imported_modules: Vec, test_functions: Vec, functions: Vec, diff --git a/asg/src/scope.rs b/asg/src/scope.rs index 29195c927c..52e43f5bed 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -21,6 +21,7 @@ use std::{cell::RefCell, sync::Arc}; use uuid::Uuid; /// An abstract data type that track the current bindings for variables, functions, and circuits. +#[derive(Debug)] pub struct InnerScope { /// The unique id of the scope. pub id: Uuid, diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index be3bc7423c..10d7be7dc2 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -37,6 +37,7 @@ use leo_ast::AssigneeAccess as AstAssigneeAccess; use std::sync::{Arc, Weak}; +#[derive(Debug)] pub enum AssignAccess { ArrayRange(Option>, Option>), ArrayIndex(Arc), @@ -44,6 +45,7 @@ pub enum AssignAccess { Member(Identifier), } +#[derive(Debug)] pub struct AssignStatement { pub parent: Option>, pub span: Option, @@ -92,7 +94,7 @@ impl FromAst for Arc { if !variable.borrow().mutable { return Err(AsgConvertError::immutable_assignment(&name, &statement.span)); } - let mut target_type: Option = Some(variable.borrow().type_.clone().into()); + let mut target_type: Option = Some(variable.borrow().type_.clone().strong().into()); let mut target_accesses = vec![]; for access in statement.assignee.accesses.iter() { diff --git a/asg/src/statement/block.rs b/asg/src/statement/block.rs index e1703b3e25..ce417e24eb 100644 --- a/asg/src/statement/block.rs +++ b/asg/src/statement/block.rs @@ -18,6 +18,7 @@ use crate::{AsgConvertError, FromAst, InnerScope, Node, PartialType, Scope, Span use std::sync::{Arc, Weak}; +#[derive(Debug)] pub struct BlockStatement { pub parent: Option>, pub span: Option, diff --git a/asg/src/statement/conditional.rs b/asg/src/statement/conditional.rs index 5b1869ce06..449d995ea7 100644 --- a/asg/src/statement/conditional.rs +++ b/asg/src/statement/conditional.rs @@ -18,6 +18,7 @@ use crate::{AsgConvertError, BlockStatement, Expression, FromAst, Node, PartialT use std::sync::{Arc, Weak}; +#[derive(Debug)] pub struct ConditionalStatement { pub parent: Option>, pub span: Option, diff --git a/asg/src/statement/console.rs b/asg/src/statement/console.rs index 970ee6da75..3c0b8af10b 100644 --- a/asg/src/statement/console.rs +++ b/asg/src/statement/console.rs @@ -19,7 +19,8 @@ use leo_ast::ConsoleFunction as AstConsoleFunction; use std::sync::{Arc, Weak}; -//todo: refactor to not require/depend on span +// TODO (protryon): Refactor to not require/depend on span +#[derive(Debug)] pub struct FormattedString { pub string: String, pub containers: Vec, @@ -27,6 +28,7 @@ pub struct FormattedString { pub span: Span, } +#[derive(Debug)] pub enum ConsoleFunction { Assert(Arc), Debug(FormattedString), @@ -34,6 +36,7 @@ pub enum ConsoleFunction { Log(FormattedString), } +#[derive(Debug)] pub struct ConsoleStatement { pub parent: Option>, pub span: Option, diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index 0876653c4a..438b26b29c 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -34,6 +34,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct DefinitionStatement { pub parent: Option>, pub span: Option, @@ -98,8 +99,10 @@ impl FromAst for Arc { id: uuid::Uuid::new_v4(), name: variable.identifier.clone(), type_: type_ - .ok_or_else(|| AsgConvertError::unresolved_type(&variable.identifier.name, &statement.span))?, + .ok_or_else(|| AsgConvertError::unresolved_type(&variable.identifier.name, &statement.span))? + .weak(), mutable: variable.mutable, + const_: false, declaration: crate::VariableDeclaration::Definition, references: vec![], assignments: vec![], @@ -144,7 +147,7 @@ impl Into for &DefinitionStatement { span: variable.name.span.clone(), }); if type_.is_none() { - type_ = Some((&variable.type_).into()); + type_ = Some((&variable.type_.clone().strong()).into()); } } diff --git a/asg/src/statement/expression.rs b/asg/src/statement/expression.rs index 068453ba03..03f5c34689 100644 --- a/asg/src/statement/expression.rs +++ b/asg/src/statement/expression.rs @@ -18,6 +18,7 @@ use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span use std::sync::{Arc, Weak}; +#[derive(Debug)] pub struct ExpressionStatement { pub parent: Option>, pub span: Option, diff --git a/asg/src/statement/iteration.rs b/asg/src/statement/iteration.rs index bc4c182a5a..bd19f0ab68 100644 --- a/asg/src/statement/iteration.rs +++ b/asg/src/statement/iteration.rs @@ -35,6 +35,7 @@ use std::{ sync::{Arc, Weak}, }; +#[derive(Debug)] pub struct IterationStatement { pub parent: Option>, pub span: Option, @@ -64,8 +65,10 @@ impl FromAst for Arc { name: statement.variable.clone(), type_: start .get_type() - .ok_or_else(|| AsgConvertError::unresolved_type(&statement.variable.name, &statement.span))?, + .ok_or_else(|| AsgConvertError::unresolved_type(&statement.variable.name, &statement.span))? + .weak(), mutable: false, + const_: true, declaration: crate::VariableDeclaration::IterationDefinition, references: vec![], assignments: vec![], diff --git a/asg/src/statement/mod.rs b/asg/src/statement/mod.rs index ef7f689970..d6d8432b32 100644 --- a/asg/src/statement/mod.rs +++ b/asg/src/statement/mod.rs @@ -46,6 +46,7 @@ use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span}; use std::sync::Arc; +#[derive(Debug)] pub enum Statement { Return(ReturnStatement), Definition(DefinitionStatement), diff --git a/asg/src/statement/return_.rs b/asg/src/statement/return_.rs index a288903f95..2a33e98cb7 100644 --- a/asg/src/statement/return_.rs +++ b/asg/src/statement/return_.rs @@ -18,6 +18,7 @@ use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span use std::sync::{Arc, Weak}; +#[derive(Debug)] pub struct ReturnStatement { pub parent: Option>, pub span: Option, diff --git a/asg/src/type_.rs b/asg/src/type_.rs index 9964cda9c0..078d9a6cf9 100644 --- a/asg/src/type_.rs +++ b/asg/src/type_.rs @@ -22,8 +22,8 @@ use std::{ sync::{Arc, Weak}, }; -/// A type in an asg. -#[derive(Clone, PartialEq)] +/// A type in an ASG. +#[derive(Debug, Clone, PartialEq)] pub enum Type { // Data types Address, @@ -38,13 +38,13 @@ pub enum Type { Circuit(Arc), } -#[derive(Clone)] +#[derive(Debug, Clone)] pub enum WeakType { Type(Type), // circuit not allowed Circuit(Weak), } -#[derive(Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq)] pub enum PartialType { Type(Type), // non-array or tuple Integer(Option, Option), // specific, context-specific @@ -157,6 +157,10 @@ impl Type { self.into() } + pub fn weak(self) -> WeakType { + self.into() + } + pub fn is_unit(&self) -> bool { matches!(self, Type::Tuple(t) if t.is_empty()) } diff --git a/asg/src/variable.rs b/asg/src/variable.rs index f255f56ec8..d519da53de 100644 --- a/asg/src/variable.rs +++ b/asg/src/variable.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Statement, Type}; +use crate::{Expression, Statement, WeakType}; use leo_ast::Identifier; use std::{ @@ -24,7 +24,7 @@ use std::{ use uuid::Uuid; /// Specifies how a program variable was declared. -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub enum VariableDeclaration { Definition, IterationDefinition, @@ -33,11 +33,13 @@ pub enum VariableDeclaration { } /// Stores information on a program variable. +#[derive(Debug)] pub struct InnerVariable { pub id: Uuid, pub name: Identifier, - pub type_: Type, + pub type_: WeakType, pub mutable: bool, + pub const_: bool, // only function arguments, const var definitions NOT included pub declaration: VariableDeclaration, pub references: Vec>, // all Expression::VariableRef or panic pub assignments: Vec>, // all Statement::Assign or panic -- must be 1 if not mutable, or 0 if declaration == input | parameter diff --git a/asg/tests/fail/address/mod.rs b/asg/tests/fail/address/mod.rs index 159dd9bf0d..0ee77207c6 100644 --- a/asg/tests/fail/address/mod.rs +++ b/asg/tests/fail/address/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/array/mod.rs b/asg/tests/fail/array/mod.rs index 7e75a94039..1a9eaf4ae5 100644 --- a/asg/tests/fail/array/mod.rs +++ b/asg/tests/fail/array/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; // Expressions diff --git a/asg/tests/fail/boolean/mod.rs b/asg/tests/fail/boolean/mod.rs index 4f20d97b61..4712d5b89c 100644 --- a/asg/tests/fail/boolean/mod.rs +++ b/asg/tests/fail/boolean/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/circuits/mod.rs b/asg/tests/fail/circuits/mod.rs index a1f8a10f0b..f88d9ec42d 100644 --- a/asg/tests/fail/circuits/mod.rs +++ b/asg/tests/fail/circuits/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; // Expressions diff --git a/asg/tests/fail/console/mod.rs b/asg/tests/fail/console/mod.rs index 04266ef925..9f967460f3 100644 --- a/asg/tests/fail/console/mod.rs +++ b/asg/tests/fail/console/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/core/mod.rs b/asg/tests/fail/core/mod.rs index 323ffe37d5..00ee4ad03a 100644 --- a/asg/tests/fail/core/mod.rs +++ b/asg/tests/fail/core/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/definition/mod.rs b/asg/tests/fail/definition/mod.rs index 2491ffe4b0..ff53f73aae 100644 --- a/asg/tests/fail/definition/mod.rs +++ b/asg/tests/fail/definition/mod.rs @@ -13,19 +13,3 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . - -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . diff --git a/asg/tests/fail/field/mod.rs b/asg/tests/fail/field/mod.rs index 2491ffe4b0..ff53f73aae 100644 --- a/asg/tests/fail/field/mod.rs +++ b/asg/tests/fail/field/mod.rs @@ -13,19 +13,3 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . - -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . diff --git a/asg/tests/fail/function/mod.rs b/asg/tests/fail/function/mod.rs index 40f0119183..07d80c4a1f 100644 --- a/asg/tests/fail/function/mod.rs +++ b/asg/tests/fail/function/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/group/mod.rs b/asg/tests/fail/group/mod.rs index a7f66eb128..01a3059bde 100644 --- a/asg/tests/fail/group/mod.rs +++ b/asg/tests/fail/group/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/import/mod.rs b/asg/tests/fail/import/mod.rs index 2491ffe4b0..ff53f73aae 100644 --- a/asg/tests/fail/import/mod.rs +++ b/asg/tests/fail/import/mod.rs @@ -13,19 +13,3 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . - -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . diff --git a/asg/tests/fail/integers/i128/mod.rs b/asg/tests/fail/integers/i128/mod.rs index 33133bf33f..c6fe80d4f9 100644 --- a/asg/tests/fail/integers/i128/mod.rs +++ b/asg/tests/fail/integers/i128/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI128); diff --git a/asg/tests/fail/integers/i16/mod.rs b/asg/tests/fail/integers/i16/mod.rs index 1d5d215911..fd0d2bee1f 100644 --- a/asg/tests/fail/integers/i16/mod.rs +++ b/asg/tests/fail/integers/i16/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI16); diff --git a/asg/tests/fail/integers/i32/mod.rs b/asg/tests/fail/integers/i32/mod.rs index 64f7110c6e..37b6b714dd 100644 --- a/asg/tests/fail/integers/i32/mod.rs +++ b/asg/tests/fail/integers/i32/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI32); diff --git a/asg/tests/fail/integers/i64/mod.rs b/asg/tests/fail/integers/i64/mod.rs index 4b7678d91a..4ea12a11df 100644 --- a/asg/tests/fail/integers/i64/mod.rs +++ b/asg/tests/fail/integers/i64/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI64); diff --git a/asg/tests/fail/integers/i8/mod.rs b/asg/tests/fail/integers/i8/mod.rs index 47e03e410d..245d20a169 100644 --- a/asg/tests/fail/integers/i8/mod.rs +++ b/asg/tests/fail/integers/i8/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI8); diff --git a/asg/tests/fail/integers/int_macro.rs b/asg/tests/fail/integers/int_macro.rs index 430ed938e4..cd06cba948 100644 --- a/asg/tests/fail/integers/int_macro.rs +++ b/asg/tests/fail/integers/int_macro.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - macro_rules! test_int { ($name: ident) => { pub struct $name {} diff --git a/asg/tests/fail/integers/integer_tester.rs b/asg/tests/fail/integers/integer_tester.rs index db76fcea36..ca6ead5f72 100644 --- a/asg/tests/fail/integers/integer_tester.rs +++ b/asg/tests/fail/integers/integer_tester.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - pub trait IntegerTester { /// Tests defining the smallest value - 1 fn test_min_fail(); diff --git a/asg/tests/fail/integers/mod.rs b/asg/tests/fail/integers/mod.rs index 6195351f1c..0cfd4f643c 100644 --- a/asg/tests/fail/integers/mod.rs +++ b/asg/tests/fail/integers/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - #[macro_use] pub mod int_macro; diff --git a/asg/tests/fail/integers/u128/mod.rs b/asg/tests/fail/integers/u128/mod.rs index dbd33d57fd..3fe52ea09d 100644 --- a/asg/tests/fail/integers/u128/mod.rs +++ b/asg/tests/fail/integers/u128/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU128); diff --git a/asg/tests/fail/integers/u16/mod.rs b/asg/tests/fail/integers/u16/mod.rs index 18bd1424fd..f2def8f598 100644 --- a/asg/tests/fail/integers/u16/mod.rs +++ b/asg/tests/fail/integers/u16/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU16); diff --git a/asg/tests/fail/integers/u32/mod.rs b/asg/tests/fail/integers/u32/mod.rs index 49cc232815..967257bd52 100644 --- a/asg/tests/fail/integers/u32/mod.rs +++ b/asg/tests/fail/integers/u32/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU32); diff --git a/asg/tests/fail/integers/u64/mod.rs b/asg/tests/fail/integers/u64/mod.rs index 0af81e075b..6705c17392 100644 --- a/asg/tests/fail/integers/u64/mod.rs +++ b/asg/tests/fail/integers/u64/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU64); diff --git a/asg/tests/fail/integers/u8/mod.rs b/asg/tests/fail/integers/u8/mod.rs index cd876caa89..14ea74d5f9 100644 --- a/asg/tests/fail/integers/u8/mod.rs +++ b/asg/tests/fail/integers/u8/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU8); diff --git a/asg/tests/fail/integers/uint_macro.rs b/asg/tests/fail/integers/uint_macro.rs index 5aa251aabf..6b718dbeda 100644 --- a/asg/tests/fail/integers/uint_macro.rs +++ b/asg/tests/fail/integers/uint_macro.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - macro_rules! test_uint { ($name: ident) => { pub struct $name {} diff --git a/asg/tests/fail/mod.rs b/asg/tests/fail/mod.rs index dd8ca1943e..9807db3177 100644 --- a/asg/tests/fail/mod.rs +++ b/asg/tests/fail/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - pub mod address; pub mod array; pub mod boolean; diff --git a/asg/tests/fail/mutability/mod.rs b/asg/tests/fail/mutability/mod.rs index 14cf69ae1e..84b481b9f3 100644 --- a/asg/tests/fail/mutability/mod.rs +++ b/asg/tests/fail/mutability/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/statements/mod.rs b/asg/tests/fail/statements/mod.rs index ada1007318..42ba3243ad 100644 --- a/asg/tests/fail/statements/mod.rs +++ b/asg/tests/fail/statements/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/fail/tuples/mod.rs b/asg/tests/fail/tuples/mod.rs index 2491ffe4b0..ff53f73aae 100644 --- a/asg/tests/fail/tuples/mod.rs +++ b/asg/tests/fail/tuples/mod.rs @@ -13,19 +13,3 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . - -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . diff --git a/asg/tests/mod.rs b/asg/tests/mod.rs index 54e018cbee..78c1f436e6 100644 --- a/asg/tests/mod.rs +++ b/asg/tests/mod.rs @@ -15,16 +15,28 @@ // along with the Leo library. If not, see . use leo_asg::*; +use leo_ast::Ast; +use leo_grammar::Grammar; + +use std::path::Path; mod fail; mod pass; -fn load_asg(content: &str) -> Result { - leo_asg::load_asg(content, &mut NullImportResolver) +const TESTING_FILEPATH: &str = "input.leo"; +const TESTING_PROGRAM_NAME: &str = "test_program"; + +fn load_asg(program_string: &str) -> Result { + load_asg_imports(program_string, &mut NullImportResolver) } -fn load_asg_imports(content: &str, imports: &mut T) -> Result { - leo_asg::load_asg(content, imports) +fn load_asg_imports( + program_string: &str, + imports: &mut T, +) -> Result { + let grammar = Grammar::new(Path::new(&TESTING_FILEPATH), program_string)?; + let ast = Ast::new(TESTING_PROGRAM_NAME, &grammar)?; + InternalProgram::new(&ast.as_repr(), imports) } fn mocked_resolver() -> MockedImportResolver { diff --git a/asg/tests/pass/address/mod.rs b/asg/tests/pass/address/mod.rs index e55ebc5d71..7cd18d57a2 100644 --- a/asg/tests/pass/address/mod.rs +++ b/asg/tests/pass/address/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/array/mod.rs b/asg/tests/pass/array/mod.rs index 04f6532d07..bca1da1a97 100644 --- a/asg/tests/pass/array/mod.rs +++ b/asg/tests/pass/array/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; // Registers diff --git a/asg/tests/pass/boolean/mod.rs b/asg/tests/pass/boolean/mod.rs index ef8c03dcd1..64f9172507 100644 --- a/asg/tests/pass/boolean/mod.rs +++ b/asg/tests/pass/boolean/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/circuits/mod.rs b/asg/tests/pass/circuits/mod.rs index 4b1fae898c..2f0c433e9f 100644 --- a/asg/tests/pass/circuits/mod.rs +++ b/asg/tests/pass/circuits/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; // Expressions diff --git a/asg/tests/pass/console/mod.rs b/asg/tests/pass/console/mod.rs index 876359c0dd..4f1a243012 100644 --- a/asg/tests/pass/console/mod.rs +++ b/asg/tests/pass/console/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/core/mod.rs b/asg/tests/pass/core/mod.rs index 05564fbe84..69d528d54c 100644 --- a/asg/tests/pass/core/mod.rs +++ b/asg/tests/pass/core/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/definition/mod.rs b/asg/tests/pass/definition/mod.rs index 7768810196..921dc3e16d 100644 --- a/asg/tests/pass/definition/mod.rs +++ b/asg/tests/pass/definition/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/field/mod.rs b/asg/tests/pass/field/mod.rs index ba3107e2e4..56074af7a3 100644 --- a/asg/tests/pass/field/mod.rs +++ b/asg/tests/pass/field/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/form_ast.rs b/asg/tests/pass/form_ast.rs index cc4b196f0b..c45f9e77ae 100644 --- a/asg/tests/pass/form_ast.rs +++ b/asg/tests/pass/form_ast.rs @@ -15,6 +15,10 @@ // along with the Leo library. If not, see . use crate::load_asg; +use leo_ast::Ast; +use leo_grammar::Grammar; + +use std::path::Path; #[test] fn test_basic() { @@ -73,14 +77,19 @@ fn test_imports() { console.assert(foo() == 1u32); } "#; + + let test_import_grammar = Grammar::new(Path::new("test-import.leo"), test_import).unwrap(); println!( "{}", - serde_json::to_string(&crate::load_ast("test-import.leo", test_import).unwrap()).unwrap() + serde_json::to_string(Ast::new("test-import", &test_import_grammar).unwrap().as_repr()).unwrap() ); + + let test_grammar = Grammar::new(Path::new("test.leo"), program_string).unwrap(); println!( "{}", - serde_json::to_string(&crate::load_ast("test.leo", program_string).unwrap()).unwrap() + serde_json::to_string(Ast::new("test", &test_grammar).unwrap().as_repr()).unwrap() ); + let asg = crate::load_asg_imports(program_string, &mut imports).unwrap(); let reformed_ast = leo_asg::reform_ast(&asg); println!("{}", serde_json::to_string(&reformed_ast).unwrap()); diff --git a/asg/tests/pass/function/mod.rs b/asg/tests/pass/function/mod.rs index 4e1af4f151..abdbd93b7c 100644 --- a/asg/tests/pass/function/mod.rs +++ b/asg/tests/pass/function/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] @@ -44,6 +28,66 @@ fn test_iteration() { load_asg(program_string).unwrap(); } +#[test] +fn test_const_args() { + let program_string = r#" + function one(const value: u32) -> u32 { + return value + 1 + } + + function main() { + let mut a = 0u32; + + for i in 0..10 { + a += one(i); + } + + console.assert(a == 20u32); + } + "#; + load_asg(program_string).unwrap(); +} + +#[test] +fn test_const_args_used() { + let program_string = r#" + function index(arr: [u8; 3], const value: u32) -> u8 { + return arr[value] + } + + function main() { + let mut a = 0u8; + let arr = [1u8, 2, 3]; + + for i in 0..3 { + a += index(arr, i); + } + + console.assert(a == 6u8); + } + "#; + load_asg(program_string).unwrap(); +} + +#[test] +fn test_const_args_fail() { + let program_string = r#" + function index(arr: [u8; 3], const value: u32) -> u8 { + return arr[value] + } + + function main(x_value: u32) { + let mut a = 0u8; + let arr = [1u8, 2, 3]; + + a += index(arr, x_value); + + console.assert(a == 1u8); + } + "#; + load_asg(program_string).err().unwrap(); +} + #[test] fn test_iteration_repeated() { let program_string = include_str!("iteration_repeated.leo"); diff --git a/asg/tests/pass/group/mod.rs b/asg/tests/pass/group/mod.rs index cbe7aef3fa..58514957dd 100644 --- a/asg/tests/pass/group/mod.rs +++ b/asg/tests/pass/group/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] @@ -38,6 +22,16 @@ fn test_one() { load_asg(program_string).unwrap(); } +#[test] +fn test_implicit() { + let program_string = r#" + function main() { + let element: group = 0; + } + "#; + load_asg(program_string).unwrap(); +} + #[test] fn test_zero() { let program_string = include_str!("zero.leo"); diff --git a/asg/tests/pass/import/imports/bar/src/baz.leo b/asg/tests/pass/import/imports/bar/src/baz.leo index 6c1df2d4b9..1bb268a84c 100755 --- a/asg/tests/pass/import/imports/bar/src/baz.leo +++ b/asg/tests/pass/import/imports/bar/src/baz.leo @@ -1,3 +1,7 @@ circuit Baz { z: u32 +} + +circuit Bazzar { + a: u32 } \ No newline at end of file diff --git a/asg/tests/pass/import/many_import.leo b/asg/tests/pass/import/many_import.leo index 339700fd68..08ae494c4f 100644 --- a/asg/tests/pass/import/many_import.leo +++ b/asg/tests/pass/import/many_import.leo @@ -5,7 +5,7 @@ import test-import.( // local import import bar.( // imports directory import Bar, - baz.Baz, + baz.(Baz, Bazzar), bat.bat.Bat, ); @@ -17,6 +17,7 @@ function main() { const bar = Bar { r: 1u32 }; const baz = Baz { z: 1u32 }; + const bazzar = Bazzar { a: 1u32 }; const bat = Bat { t: 1u32 }; const car = Car { c: 1u32 }; diff --git a/asg/tests/pass/import/mod.rs b/asg/tests/pass/import/mod.rs index 1dfa59be83..c7de7adadf 100644 --- a/asg/tests/pass/import/mod.rs +++ b/asg/tests/pass/import/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::{load_asg, load_asg_imports, mocked_resolver}; #[test] diff --git a/asg/tests/pass/input_files/mod.rs b/asg/tests/pass/input_files/mod.rs index d9d41ccf12..46817206d2 100644 --- a/asg/tests/pass/input_files/mod.rs +++ b/asg/tests/pass/input_files/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - mod program_input; mod program_input_and_program_state; mod program_state; diff --git a/asg/tests/pass/input_files/program_input/mod.rs b/asg/tests/pass/input_files/program_input/mod.rs index f8e68e13af..a223bd970e 100644 --- a/asg/tests/pass/input_files/program_input/mod.rs +++ b/asg/tests/pass/input_files/program_input/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/input_files/program_input_and_program_state/mod.rs b/asg/tests/pass/input_files/program_input_and_program_state/mod.rs index 2d1af96f2b..0df6849508 100644 --- a/asg/tests/pass/input_files/program_input_and_program_state/mod.rs +++ b/asg/tests/pass/input_files/program_input_and_program_state/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/input_files/program_state/mod.rs b/asg/tests/pass/input_files/program_state/mod.rs index 004345dc26..ce09adf28d 100644 --- a/asg/tests/pass/input_files/program_state/mod.rs +++ b/asg/tests/pass/input_files/program_state/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/integers/i128/mod.rs b/asg/tests/pass/integers/i128/mod.rs index a15de363f2..410e399df2 100644 --- a/asg/tests/pass/integers/i128/mod.rs +++ b/asg/tests/pass/integers/i128/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI128); diff --git a/asg/tests/pass/integers/i16/mod.rs b/asg/tests/pass/integers/i16/mod.rs index d27140edca..7da2ab7038 100644 --- a/asg/tests/pass/integers/i16/mod.rs +++ b/asg/tests/pass/integers/i16/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI16); diff --git a/asg/tests/pass/integers/i32/mod.rs b/asg/tests/pass/integers/i32/mod.rs index fd75e17ba2..e890904bb5 100644 --- a/asg/tests/pass/integers/i32/mod.rs +++ b/asg/tests/pass/integers/i32/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI32); diff --git a/asg/tests/pass/integers/i64/mod.rs b/asg/tests/pass/integers/i64/mod.rs index 00c64123ff..1446308045 100644 --- a/asg/tests/pass/integers/i64/mod.rs +++ b/asg/tests/pass/integers/i64/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI64); diff --git a/asg/tests/pass/integers/i8/mod.rs b/asg/tests/pass/integers/i8/mod.rs index 9f39f152fe..85402e7628 100644 --- a/asg/tests/pass/integers/i8/mod.rs +++ b/asg/tests/pass/integers/i8/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_int!(TestI8); diff --git a/asg/tests/pass/integers/int_macro.rs b/asg/tests/pass/integers/int_macro.rs index 4afdca8ecc..b9c7e7bc28 100644 --- a/asg/tests/pass/integers/int_macro.rs +++ b/asg/tests/pass/integers/int_macro.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - macro_rules! test_int { ($name: ident) => { pub struct $name {} diff --git a/asg/tests/pass/integers/integer_tester.rs b/asg/tests/pass/integers/integer_tester.rs index 00c72b5ce4..4eb177b42b 100644 --- a/asg/tests/pass/integers/integer_tester.rs +++ b/asg/tests/pass/integers/integer_tester.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - pub trait IntegerTester { /// Tests defining the smalled value that can be represented by the integer type fn test_min(); diff --git a/asg/tests/pass/integers/mod.rs b/asg/tests/pass/integers/mod.rs index 6195351f1c..0cfd4f643c 100644 --- a/asg/tests/pass/integers/mod.rs +++ b/asg/tests/pass/integers/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - #[macro_use] pub mod int_macro; diff --git a/asg/tests/pass/integers/u128/mod.rs b/asg/tests/pass/integers/u128/mod.rs index 8a6d0bd606..7de4918199 100644 --- a/asg/tests/pass/integers/u128/mod.rs +++ b/asg/tests/pass/integers/u128/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU128); diff --git a/asg/tests/pass/integers/u16/mod.rs b/asg/tests/pass/integers/u16/mod.rs index bc83b5fa61..1544e09e00 100644 --- a/asg/tests/pass/integers/u16/mod.rs +++ b/asg/tests/pass/integers/u16/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU16); diff --git a/asg/tests/pass/integers/u32/mod.rs b/asg/tests/pass/integers/u32/mod.rs index 8fdac0d9e5..0fe1d534db 100644 --- a/asg/tests/pass/integers/u32/mod.rs +++ b/asg/tests/pass/integers/u32/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU32); diff --git a/asg/tests/pass/integers/u64/mod.rs b/asg/tests/pass/integers/u64/mod.rs index e97c784cdf..146aaa5415 100644 --- a/asg/tests/pass/integers/u64/mod.rs +++ b/asg/tests/pass/integers/u64/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU64); diff --git a/asg/tests/pass/integers/u8/mod.rs b/asg/tests/pass/integers/u8/mod.rs index c1fee383e2..27fd40ed97 100644 --- a/asg/tests/pass/integers/u8/mod.rs +++ b/asg/tests/pass/integers/u8/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use super::IntegerTester; test_uint!(TestU8); diff --git a/asg/tests/pass/integers/uint_macro.rs b/asg/tests/pass/integers/uint_macro.rs index 93b27faaa7..7d555f10e3 100644 --- a/asg/tests/pass/integers/uint_macro.rs +++ b/asg/tests/pass/integers/uint_macro.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - macro_rules! test_uint { ($name: ident) => { pub struct $name {} diff --git a/asg/tests/pass/mod.rs b/asg/tests/pass/mod.rs index 62e9004bf4..fea1f43ae6 100644 --- a/asg/tests/pass/mod.rs +++ b/asg/tests/pass/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - pub mod address; pub mod array; pub mod boolean; diff --git a/asg/tests/pass/mutability/mod.rs b/asg/tests/pass/mutability/mod.rs index 9d757c1085..5da14da0ae 100644 --- a/asg/tests/pass/mutability/mod.rs +++ b/asg/tests/pass/mutability/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] @@ -81,7 +65,6 @@ fn test_function_input_mut() { } #[test] -#[ignore] fn test_swap() { let program_string = include_str!("swap.leo"); load_asg(program_string).unwrap(); diff --git a/asg/tests/pass/mutability/swap.leo b/asg/tests/pass/mutability/swap.leo index 8234a3cfb7..0a209149ee 100644 --- a/asg/tests/pass/mutability/swap.leo +++ b/asg/tests/pass/mutability/swap.leo @@ -1,5 +1,5 @@ // Swap two elements of an array. -function swap(mut a: [u32; 2], i: u32, j: u32) -> [u32; 2] { +function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { let t = a[i]; a[i] = a[j]; a[j] = t; diff --git a/asg/tests/pass/statements/conditional/mod.rs b/asg/tests/pass/statements/conditional/mod.rs index 35f54f4846..73a987bb94 100644 --- a/asg/tests/pass/statements/conditional/mod.rs +++ b/asg/tests/pass/statements/conditional/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/asg/tests/pass/statements/mod.rs b/asg/tests/pass/statements/mod.rs index 2874b5aa31..f6123b86db 100644 --- a/asg/tests/pass/statements/mod.rs +++ b/asg/tests/pass/statements/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; pub mod conditional; diff --git a/asg/tests/pass/tuples/mod.rs b/asg/tests/pass/tuples/mod.rs index 25949c41d7..19f5dc5267 100644 --- a/asg/tests/pass/tuples/mod.rs +++ b/asg/tests/pass/tuples/mod.rs @@ -14,22 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// Copyright (C) 2019-2021 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - use crate::load_asg; #[test] diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 4934464275..c3f346ba0f 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-ast" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Core AST of the Leo programming language" homepage = "https://aleo.org" @@ -28,11 +28,11 @@ harness = false [dependencies.leo-grammar] path = "../grammar" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-input] path = "../input" -version = "1.1.8" +version = "1.2.0" [dependencies.indexmap] version = "1.6.1" diff --git a/ast/src/circuits/circuit_implied_variable_definition.rs b/ast/src/circuits/circuit_implied_variable_definition.rs new file mode 100644 index 0000000000..963c153bec --- /dev/null +++ b/ast/src/circuits/circuit_implied_variable_definition.rs @@ -0,0 +1,41 @@ +// Copyright (C) 2019-2021 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use crate::{Expression, Identifier}; +use leo_grammar::circuits::CircuitImpliedVariable; + +use serde::{Deserialize, Serialize}; + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +pub struct CircuitImpliedVariableDefinition { + pub identifier: Identifier, + pub expression: Expression, +} + +impl<'ast> From> for CircuitImpliedVariableDefinition { + fn from(member: CircuitImpliedVariable<'ast>) -> Self { + match member { + CircuitImpliedVariable::CircuitVariable(circuit_variable) => Self { + identifier: Identifier::from(circuit_variable.identifier), + expression: Expression::from(circuit_variable.expression), + }, + CircuitImpliedVariable::Identifier(identifier) => Self { + identifier: Identifier::from(identifier.clone()), + expression: Expression::from(identifier), + }, + } + } +} diff --git a/ast/src/circuits/mod.rs b/ast/src/circuits/mod.rs index 8d0db90cfa..b77c90dbbd 100644 --- a/ast/src/circuits/mod.rs +++ b/ast/src/circuits/mod.rs @@ -20,5 +20,8 @@ pub use circuit::*; pub mod circuit_variable_definition; pub use circuit_variable_definition::*; +pub mod circuit_implied_variable_definition; +pub use circuit_implied_variable_definition::*; + pub mod circuit_member; pub use circuit_member::*; diff --git a/ast/src/expression/circuit_init.rs b/ast/src/expression/circuit_init.rs index d189d3521f..9f79f3c9ba 100644 --- a/ast/src/expression/circuit_init.rs +++ b/ast/src/expression/circuit_init.rs @@ -19,7 +19,7 @@ use super::*; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct CircuitInitExpression { pub name: Identifier, - pub members: Vec, + pub members: Vec, pub span: Span, } @@ -28,6 +28,7 @@ impl fmt::Display for CircuitInitExpression { write!(f, "{} {{", self.name)?; for (i, member) in self.members.iter().enumerate() { write!(f, "{}: {}", member.identifier, member.expression)?; + if i < self.members.len() - 1 { write!(f, ", ")?; } diff --git a/ast/src/expression/mod.rs b/ast/src/expression/mod.rs index b276079099..f629d9d0d4 100644 --- a/ast/src/expression/mod.rs +++ b/ast/src/expression/mod.rs @@ -16,7 +16,7 @@ use crate::{ ArrayDimensions, - CircuitVariableDefinition, + CircuitImpliedVariableDefinition, GroupValue, Identifier, IntegerType, @@ -181,8 +181,8 @@ impl<'ast> From> for Expression { let members = expression .members .into_iter() - .map(CircuitVariableDefinition::from) - .collect::>(); + .map(CircuitImpliedVariableDefinition::from) + .collect::>(); Expression::CircuitInit(CircuitInitExpression { name: circuit_name, @@ -485,3 +485,9 @@ impl<'ast> From> for Expression { Expression::Identifier(Identifier::from(identifier)) } } + +impl From for Expression { + fn from(identifier: Identifier) -> Self { + Expression::Identifier(identifier) + } +} diff --git a/ast/src/functions/input/function_input.rs b/ast/src/functions/input/function_input.rs index 755892d9bd..8cece828ad 100644 --- a/ast/src/functions/input/function_input.rs +++ b/ast/src/functions/input/function_input.rs @@ -23,6 +23,7 @@ use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct FunctionInputVariable { pub identifier: Identifier, + pub const_: bool, pub mutable: bool, pub type_: Type, pub span: Span, @@ -32,6 +33,7 @@ impl<'ast> From> for FunctionInputVariable { fn from(parameter: GrammarFunctionInput<'ast>) -> Self { FunctionInputVariable { identifier: Identifier::from(parameter.identifier), + const_: parameter.const_.is_some(), mutable: parameter.mutable.is_some(), type_: Type::from(parameter.type_), span: Span::from(parameter.span), @@ -42,6 +44,9 @@ impl<'ast> From> for FunctionInputVariable { impl FunctionInputVariable { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { // mut var: bool + if self.const_ { + write!(f, "const ")?; + } if self.mutable { write!(f, "mut ")?; } diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 514be205cd..51fd09e848 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -63,7 +63,7 @@ pub use node::*; use leo_grammar::Grammar; -/// The abstract syntax tree (ast) for a Leo program. +/// The abstract syntax tree (AST) for a Leo program. /// /// The [`Ast`] type represents a Leo program as a series of recursive data types. /// These data types form a tree that begins from a [`Program`] type root. @@ -75,16 +75,16 @@ pub struct Ast { } impl Ast { - /// Creates a new ast from a given program name and grammar tree. - pub fn new<'ast>(program_name: &str, ast: &Grammar<'ast>) -> Result { + /// Creates a new AST from a given program name and grammar tree. + pub fn new<'ast>(program_name: &str, grammar: &Grammar<'ast>) -> Result { Ok(Self { - ast: Program::from(program_name, ast.as_repr())?, + ast: Program::from(program_name, grammar.as_repr())?, }) } - /// Returns a reference to the inner program ast representation. - pub fn into_repr(self) -> Program { - self.ast + /// Returns a reference to the inner program AST representation. + pub fn as_repr(&self) -> &Program { + &self.ast } /// Serializes the ast into a JSON string. diff --git a/ast/tests/serialization/json.rs b/ast/tests/serialization/json.rs index 119dc90260..5a58ff12c5 100644 --- a/ast/tests/serialization/json.rs +++ b/ast/tests/serialization/json.rs @@ -44,7 +44,7 @@ fn test_serialize() { }; // Serializes the ast into JSON format. - let serialized_ast: Program = serde_json::from_value(serde_json::to_value(ast.into_repr()).unwrap()).unwrap(); + let serialized_ast: Program = serde_json::from_value(serde_json::to_value(ast.as_repr()).unwrap()).unwrap(); // Load the expected ast. let expected: Program = serde_json::from_str(include_str!("expected_leo_ast.json")).unwrap(); diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 9da3356ed8..1b7dad1763 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-compiler" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Compiler of the Leo programming language" homepage = "https://aleo.org" @@ -19,62 +19,62 @@ edition = "2018" [dependencies.leo-ast] path = "../ast" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-gadgets] path = "../gadgets" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-grammar] path = "../grammar" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-imports] path = "../imports" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-input] path = "../input" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-package] path = "../package" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-state] path = "../state" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-asg] path = "../asg" -version = "1.1.8" +version = "1.2.0" [dependencies.snarkvm-curves] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-errors] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-models] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-objects] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.2" +version = "0.0.3" [dependencies.bincode] version = "1.0" @@ -116,7 +116,7 @@ features = [ "v4", "serde" ] version = "0.3" [dev-dependencies.snarkvm-algorithms] -version = "0.0.2" +version = "0.0.3" default-features = false [features] diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index f272113f2e..e0dd355ae9 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -23,13 +23,13 @@ use crate::{ OutputBytes, OutputFile, }; +use leo_asg::Asg; use leo_ast::{Ast, Input, MainInput, Program}; use leo_grammar::Grammar; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use leo_state::verify_local_data_commitment; -use leo_asg::Program as AsgProgram; use snarkvm_dpc::{base_dpc::instantiated::Components, SystemParameters}; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::{ @@ -47,12 +47,12 @@ use std::{ /// Stores information to compile a Leo program. #[derive(Clone)] pub struct Compiler> { - package_name: String, + program_name: String, main_file_path: PathBuf, output_directory: PathBuf, program: Program, program_input: Input, - asg: Option, + asg: Option, _engine: PhantomData, _group: PhantomData, } @@ -63,7 +63,7 @@ impl> Compiler { /// pub fn new(package_name: String, main_file_path: PathBuf, output_directory: PathBuf) -> Self { Self { - package_name: package_name.clone(), + program_name: package_name.clone(), main_file_path, output_directory, program: Program::new(package_name), @@ -88,7 +88,7 @@ impl> Compiler { ) -> Result { let mut compiler = Self::new(package_name, main_file_path, output_directory); - compiler.parse_and_check_program()?; + compiler.parse_program()?; Ok(compiler) } @@ -114,7 +114,7 @@ impl> Compiler { compiler.parse_input(input_string, input_path, state_string, state_path)?; - compiler.parse_and_check_program()?; + compiler.parse_program()?; Ok(compiler) } @@ -156,51 +156,16 @@ impl> Compiler { Ok(()) } - /// - /// Runs program parser and type inference checker consecutively. - /// - pub(crate) fn parse_and_check_program(&mut self) -> Result<(), CompilerError> { - self.parse_program() - } - /// /// Parses and stores the main program file, constructs a syntax tree, and generates a program. /// /// Parses and stores all programs imported by the main program file. /// - pub(crate) fn parse_program(&mut self) -> Result<(), CompilerError> { + pub fn parse_program(&mut self) -> Result<(), CompilerError> { // Load the program file. let program_string = Grammar::load_file(&self.main_file_path)?; - // Use the parser to construct the pest abstract syntax tree (ast). - let pest_ast = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| { - e.set_path(&self.main_file_path); - - e - })?; - - // Construct the core ast from the pest ast. - let core_ast = Ast::new(&self.package_name, &pest_ast)?; - - // Store the main program file. - self.program = core_ast.into_repr(); - - tracing::debug!("Program parsing complete\n{:#?}", self.program); - - self.program_asg_generate()?; - - Ok(()) - } - - pub(crate) fn program_asg_generate(&mut self) -> Result<(), CompilerError> { - // Create a new symbol table from the program, imported_programs, and program_input. - let asg = leo_asg::InnerProgram::new(&self.program, &mut leo_imports::ImportParser::default())?; - - tracing::debug!("ASG generation complete"); - - self.asg = Some(asg); - - Ok(()) + self.parse_program_from_string(&program_string) } /// @@ -208,52 +173,56 @@ impl> Compiler { /// file path. /// pub fn parse_program_from_string(&mut self, program_string: &str) -> Result<(), CompilerError> { - // Use the given bytes to construct the abstract syntax tree. - let ast = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| { + // Use the parser to construct the pest abstract syntax tree (ast). + let grammar = Grammar::new(&self.main_file_path, &program_string).map_err(|mut e| { e.set_path(&self.main_file_path); e })?; - // Derive the package name. - let package_name = &self.package_name; - - // Construct the core ast from the pest ast. - let core_ast = Ast::new(package_name, &ast)?; + // Construct the AST from the grammar. + let core_ast = Ast::new(&self.program_name, &grammar)?; // Store the main program file. - self.program = core_ast.into_repr(); + self.program = core_ast.as_repr().clone(); tracing::debug!("Program parsing complete\n{:#?}", self.program); - self.program_asg_generate()?; + // Create a new symbol table from the program, imported_programs, and program_input. + let asg = Asg::new(&core_ast, &mut leo_imports::ImportParser::default())?; + + tracing::debug!("ASG generation complete"); + + // Store the ASG. + self.asg = Some(asg); Ok(()) } /// - /// Manually sets main function input. + /// Synthesizes the circuit with program input to verify correctness. /// - /// Used for testing only. - /// - pub fn set_main_input(&mut self, input: MainInput) { - self.program_input.set_main_input(input); + pub fn compile_constraints>(&self, cs: &mut CS) -> Result { + generate_constraints::(cs, &self.asg.as_ref().unwrap(), &self.program_input).map_err(|mut error| { + error.set_path(&self.main_file_path); + error + }) } /// - /// Verifies the input to the program. + /// Synthesizes the circuit for test functions with program input. /// - pub fn verify_local_data_commitment( - &self, - system_parameters: &SystemParameters, - ) -> Result { - let result = verify_local_data_commitment(system_parameters, &self.program_input)?; - - Ok(result) + pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), CompilerError> { + generate_test_constraints::( + &self.asg.as_ref().unwrap(), + input_pairs, + &self.main_file_path, + &self.output_directory, + ) } /// - /// Returns a Sha256 checksum of the program file. + /// Returns a SHA256 checksum of the program file. /// pub fn checksum(&self) -> Result { // Read in the main file as string @@ -268,43 +237,27 @@ impl> Compiler { Ok(hex::encode(hash)) } + /// TODO (howardwu): Incorporate this for real program executions and intentionally-real + /// test executions. Exclude it for test executions on dummy data. /// - /// Synthesizes the circuit without program input to verify correctness. + /// Verifies the input to the program. /// - pub fn compile_constraints>(self, cs: &mut CS) -> Result { - let path = self.main_file_path; - - generate_constraints::(cs, self.asg.as_ref().unwrap(), &self.program_input).map_err(|mut error| { - error.set_path(&path); - - error - }) - } - - /// - /// Synthesizes the circuit for test functions with program input. - /// - pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), CompilerError> { - generate_test_constraints::( - self.asg.as_ref().unwrap(), - input_pairs, - &self.main_file_path, - &self.output_directory, - ) - } - - /// - /// Calls the internal generate_constraints method with arguments. - /// - pub fn generate_constraints_helper>( + pub fn verify_local_data_commitment( &self, - cs: &mut CS, - ) -> Result { - let path = &self.main_file_path; - generate_constraints::<_, G, _>(cs, self.asg.as_ref().unwrap(), &self.program_input).map_err(|mut error| { - error.set_path(&path); - error - }) + system_parameters: &SystemParameters, + ) -> Result { + let result = verify_local_data_commitment(system_parameters, &self.program_input)?; + + Ok(result) + } + + /// + /// Manually sets main function input. + /// + /// Used for testing only. + /// + pub fn set_main_input(&mut self, input: MainInput) { + self.program_input.set_main_input(input); } } @@ -314,8 +267,8 @@ impl> ConstraintSynthesizer for Compil /// fn generate_constraints>(&self, cs: &mut CS) -> Result<(), SynthesisError> { let output_directory = self.output_directory.clone(); - let package_name = self.package_name.clone(); - let result = self.generate_constraints_helper(cs).map_err(|e| { + let package_name = self.program_name.clone(); + let result = self.compile_constraints(cs).map_err(|e| { tracing::error!("{}", e); SynthesisError::Unsatisfiable })?; diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 6b45a3402e..593b70a2b0 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -17,7 +17,7 @@ //! Generates R1CS constraints for a compiled Leo program. use crate::{errors::CompilerError, ConstrainedProgram, GroupType, OutputBytes, OutputFile}; -use leo_asg::Program; +use leo_asg::Asg; use leo_ast::Input; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; @@ -30,9 +30,10 @@ use std::path::Path; pub fn generate_constraints, CS: ConstraintSystem>( cs: &mut CS, - program: &Program, + asg: &Asg, input: &Input, ) -> Result { + let program = asg.as_repr(); let mut resolved_program = ConstrainedProgram::::new(program.clone()); let main = { @@ -50,11 +51,12 @@ pub fn generate_constraints, CS: Constrai } pub fn generate_test_constraints>( - program: &Program, + asg: &Asg, input: InputPairs, main_file_path: &Path, output_directory: &Path, ) -> Result<(u32, u32), CompilerError> { + let program = asg.as_repr(); let mut resolved_program = ConstrainedProgram::::new(program.clone()); let program_name = program.borrow().name.clone(); diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 6df2c0a444..efa2ebf29b 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -52,7 +52,7 @@ impl> ConstrainedProgram { None }; - if function.arguments.len() != arguments.len() { + if function.function.arguments.len() != arguments.len() { return Err(FunctionError::input_not_found( "arguments length invalid".to_string(), function.span.clone().unwrap_or_default(), @@ -60,7 +60,7 @@ impl> ConstrainedProgram { } // Store input values as new variables in resolved program - for (variable, input_expression) in function.arguments.iter().zip(arguments.iter()) { + for (variable, input_expression) in function.function.arguments.iter().zip(arguments.iter()) { let input_value = self.enforce_expression(cs, input_expression)?; let variable = variable.borrow(); diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index f1003f8c6c..e858db1b73 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -64,7 +64,7 @@ impl> ConstrainedProgram { let mut arguments = vec![]; - for input_variable in function.arguments.iter() { + for input_variable in function.function.arguments.iter() { { let input_variable = input_variable.borrow(); let name = input_variable.name.name.clone(); @@ -73,7 +73,7 @@ impl> ConstrainedProgram { })?; let input_value = self.allocate_main_function_input( cs, - &input_variable.type_, + &input_variable.type_.clone().strong(), &name, input_option, &function.span.clone().unwrap_or_default(), diff --git a/compiler/tests/circuits/inline_member_fail.leo b/compiler/tests/circuits/inline_member_fail.leo new file mode 100644 index 0000000000..7f0b8f7889 --- /dev/null +++ b/compiler/tests/circuits/inline_member_fail.leo @@ -0,0 +1,8 @@ +circuit Foo { + x: u8 +} + +function main() { + let y: u8 = 1; + let a = Foo { y }; +} \ No newline at end of file diff --git a/compiler/tests/circuits/inline_member_pass.leo b/compiler/tests/circuits/inline_member_pass.leo new file mode 100644 index 0000000000..5541a65638 --- /dev/null +++ b/compiler/tests/circuits/inline_member_pass.leo @@ -0,0 +1,13 @@ +circuit Foo { + x: u8 + + function new(x: u8) -> Self { + return Self { x } + } +} + +function main() { + let x: u8 = 1; + let a = Foo { x }; + let b = Foo::new(x); +} \ No newline at end of file diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs index dbed6c7e41..488b639d0b 100644 --- a/compiler/tests/circuits/mod.rs +++ b/compiler/tests/circuits/mod.rs @@ -248,6 +248,24 @@ fn test_self_member_undefined() { expect_asg_error(error); } +// Inline circuit member + +#[test] +fn test_inline_member_pass() { + let program_string = include_str!("inline_member_pass.leo"); + let program = parse_program(program_string).unwrap(); + + assert_satisfied(program); +} + +#[test] +fn test_inline_member_fail() { + let program_string = include_str!("inline_member_fail.leo"); + let error = parse_program(program_string).err().unwrap(); + + expect_asg_error(error); +} + // All #[test] diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 7c29d5add8..d1eee03f8b 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -146,7 +146,7 @@ pub fn parse_program_with_input_and_state( pub(crate) fn get_output(program: EdwardsTestCompiler) -> OutputBytes { // synthesize the circuit on the test constraint system let mut cs = TestConstraintSystem::::new(); - let output = program.generate_constraints_helper(&mut cs).unwrap(); + let output = program.compile_constraints(&mut cs).unwrap(); // assert the constraint system is satisfied assert!(cs.is_satisfied()); @@ -164,7 +164,7 @@ pub(crate) fn assert_satisfied(program: EdwardsTestCompiler) { pub(crate) fn expect_compiler_error(program: EdwardsTestCompiler) -> CompilerError { let mut cs = TestConstraintSystem::::new(); - program.generate_constraints_helper(&mut cs).unwrap_err() + program.compile_constraints(&mut cs).unwrap_err() } pub(crate) fn expect_asg_error(error: CompilerError) { diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index 8acd3f9e51..6c1555c870 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -149,7 +149,6 @@ fn test_function_input_mut() { } #[test] -#[ignore] fn test_swap() { let program_string = include_str!("swap.leo"); let program = parse_program(program_string).unwrap(); diff --git a/compiler/tests/mutability/swap.leo b/compiler/tests/mutability/swap.leo index 8234a3cfb7..0a209149ee 100644 --- a/compiler/tests/mutability/swap.leo +++ b/compiler/tests/mutability/swap.leo @@ -1,5 +1,5 @@ // Swap two elements of an array. -function swap(mut a: [u32; 2], i: u32, j: u32) -> [u32; 2] { +function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { let t = a[i]; a[i] = a[j]; a[j] = t; diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index b760b5891d..04d0565f98 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-gadgets" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Gadgets of the Leo programming language" homepage = "https://aleo.org" @@ -18,15 +18,15 @@ license = "GPL-3.0" edition = "2018" [dependencies.snarkvm-errors] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-models] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.2" +version = "0.0.3" [dependencies.rand] version = "0.7" diff --git a/grammar/Cargo.toml b/grammar/Cargo.toml index cb4930e05b..1325e5b017 100644 --- a/grammar/Cargo.toml +++ b/grammar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-grammar" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "AST generated by pest from the Leo grammar rules" homepage = "https://aleo.org" @@ -22,8 +22,8 @@ name = "leo_grammar" path = "src/main.rs" [[bench]] -name = "ast" -path = "benches/ast.rs" +name = "grammar" +path = "benches/grammar.rs" harness = false [dependencies.from-pest] diff --git a/grammar/benches/ast.rs b/grammar/benches/grammar.rs similarity index 100% rename from grammar/benches/ast.rs rename to grammar/benches/grammar.rs diff --git a/grammar/benches/main.leo b/grammar/benches/main.leo index 6b094d9aae..a769e0fdff 100644 --- a/grammar/benches/main.leo +++ b/grammar/benches/main.leo @@ -2,7 +2,7 @@ circuit PedersenHash { parameters: [group; 256], // Instantiates a Pedersen hash circuit - static function new(parameters: [group; 256]) -> Self { + function new(self, parameters: [group; 256]) -> Self { return Self { parameters: parameters } } diff --git a/grammar/src/ast.rs b/grammar/src/ast.rs index 48a4a2802e..0da55a7a31 100644 --- a/grammar/src/ast.rs +++ b/grammar/src/ast.rs @@ -44,8 +44,8 @@ use pest::{ #[grammar = "leo.pest"] pub struct LanguageParser; -pub fn parse(input: &str) -> Result, Error> { - LanguageParser::parse(Rule::file, input) +pub fn parse(program_string: &str) -> Result, Error> { + LanguageParser::parse(Rule::file, program_string) } pub(crate) fn span_into_string(span: Span) -> String { diff --git a/grammar/src/circuits/circuit_implied_variable.rs b/grammar/src/circuits/circuit_implied_variable.rs new file mode 100644 index 0000000000..eeb9aee4bb --- /dev/null +++ b/grammar/src/circuits/circuit_implied_variable.rs @@ -0,0 +1,27 @@ +// Copyright (C) 2019-2021 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use crate::{ast::Rule, circuits::CircuitVariable, common::Identifier}; + +use pest_ast::FromPest; +use serde::Serialize; + +#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[pest_ast(rule(Rule::circuit_implied_variable))] +pub enum CircuitImpliedVariable<'ast> { + CircuitVariable(CircuitVariable<'ast>), + Identifier(Identifier<'ast>), +} diff --git a/grammar/src/circuits/mod.rs b/grammar/src/circuits/mod.rs index ddbe004951..7b9a25eed6 100644 --- a/grammar/src/circuits/mod.rs +++ b/grammar/src/circuits/mod.rs @@ -17,6 +17,9 @@ pub mod circuit; pub use circuit::*; +pub mod circuit_implied_variable; +pub use circuit_implied_variable::*; + pub mod circuit_variable; pub use circuit_variable::*; diff --git a/grammar/src/common/eoi.rs b/grammar/src/common/eoi.rs index 26d13e339e..b37cf4f230 100644 --- a/grammar/src/common/eoi.rs +++ b/grammar/src/common/eoi.rs @@ -17,8 +17,8 @@ use crate::ast::Rule; use pest_ast::FromPest; -use serde::Serialize; +use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] +#[derive(Clone, Debug, FromPest, PartialEq, Serialize, Deserialize)] #[pest_ast(rule(Rule::EOI))] pub struct EOI; diff --git a/grammar/src/expressions/circuit_inline_expression.rs b/grammar/src/expressions/circuit_inline_expression.rs index bfb3a5bac8..6a51792bae 100644 --- a/grammar/src/expressions/circuit_inline_expression.rs +++ b/grammar/src/expressions/circuit_inline_expression.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, circuits::CircuitVariable, common::Identifier, types::SelfType, SpanDef}; +use crate::{ast::Rule, circuits::CircuitImpliedVariable, common::Identifier, types::SelfType, SpanDef}; use pest::Span; use pest_ast::FromPest; @@ -24,7 +24,7 @@ use serde::Serialize; #[pest_ast(rule(Rule::expression_circuit_inline))] pub struct CircuitInlineExpression<'ast> { pub name: CircuitName<'ast>, - pub members: Vec>, + pub members: Vec>, #[pest_ast(outer())] #[serde(with = "SpanDef")] pub span: Span<'ast>, diff --git a/grammar/src/functions/input/function_input.rs b/grammar/src/functions/input/function_input.rs index efce2a17db..3cac32b798 100644 --- a/grammar/src/functions/input/function_input.rs +++ b/grammar/src/functions/input/function_input.rs @@ -16,7 +16,7 @@ use crate::{ ast::Rule, - common::{Identifier, Mutable}, + common::{Const, Identifier, Mutable}, types::Type, SpanDef, }; @@ -28,6 +28,7 @@ use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize)] #[pest_ast(rule(Rule::function_input))] pub struct FunctionInput<'ast> { + pub const_: Option, pub mutable: Option, pub identifier: Identifier<'ast>, pub type_: Type<'ast>, diff --git a/grammar/src/leo.pest b/grammar/src/leo.pest index 968d6c3dec..f215d16f13 100644 --- a/grammar/src/leo.pest +++ b/grammar/src/leo.pest @@ -327,6 +327,12 @@ circuit = { "circuit " ~ identifier ~ "{" ~ circuit_member* ~ "}" } // Declared in circuits/circuit_variable.rs circuit_variable = { identifier ~ ":" ~ expression } +// Declared in circuits/circuit_implied_variable.rs +circuit_implied_variable = { + circuit_variable + | identifier +} + // Declared in circuits/circuit_variable_definition.rs circuit_variable_definition = { identifier ~ ":" ~ type_ ~ ","?} @@ -376,7 +382,7 @@ circuit_name = { } // Declared in expressions/circuit_inline_expression.rs -circuit_variable_list = _{ (circuit_variable ~ ("," ~ circuit_variable)*)? ~ ","? } +circuit_variable_list = _{ (circuit_implied_variable ~ ("," ~ circuit_implied_variable)*)? ~ ","? } // Declared in expressions/unary_expression.rs expression_unary = { operation_unary ~ expression_term } @@ -430,7 +436,7 @@ statement_return = { "return " ~ expression} function = { "function " ~ identifier ~ input_tuple ~ ("->" ~ type_)? ~ block } // Declared in functions/input/function_input.rs -function_input = { mutable? ~ identifier ~ ":" ~ type_ } +function_input = { const_? ~ mutable? ~ identifier ~ ":" ~ type_ } // Declared in functions/input/input_keyword.rs input_keyword = { "input" } diff --git a/grammar/src/lib.rs b/grammar/src/lib.rs index d38b826c08..2f9e0fac02 100644 --- a/grammar/src/lib.rs +++ b/grammar/src/lib.rs @@ -53,19 +53,23 @@ pub(crate) use span::*; use from_pest::FromPest; use std::{fs, path::Path}; -/// The pest abstract syntax tree (ast) for a Leo program. +/// +/// The grammar of a Leo program, encoded as an abstract syntax tree (AST). /// /// The [`Grammar`] type represents a Leo program as a series of recursive data types. /// These data types form a tree that begins from a [`File`] type root. /// /// A new [`Grammar`] type can be created from a `*.leo` file at a [`Path`]. /// A [`Grammar`] type can be used to create a new [`Ast`] type. +/// pub struct Grammar<'ast> { ast: files::File<'ast>, } impl<'ast> Grammar<'ast> { - /// Creates a new abstract syntax tree given the file path. + /// + /// Creates a new abstract syntax tree from a given program string, and optional file path. + /// pub fn new(file_path: &'ast Path, program_string: &'ast str) -> Result { // TODO (howardwu): Turn this check back on after fixing the testing module. // assert_eq!(program_string, fs::read_to_string(file_path).map_err(|_| ParserError::FileReadError(file_path.clone()))?); @@ -83,17 +87,23 @@ impl<'ast> Grammar<'ast> { // TODO (howardwu): Remove this in favor of a dedicated file loader to verify checksums // and maintain a global cache of program strings during the compilation process. + /// /// Loads the Leo code as a string from the given file path. + /// pub fn load_file(file_path: &'ast Path) -> Result { fs::read_to_string(file_path).map_err(|_| ParserError::FileReadError(file_path.to_owned())) } + /// /// Returns a reference to the inner abstract syntax tree representation. + /// pub fn as_repr(&self) -> &files::File<'ast> { &self.ast } + /// /// Serializes the abstract syntax tree into a JSON string. + /// pub fn to_json_string(&self) -> Result { Ok(serde_json::to_string_pretty(&self.ast)?) } diff --git a/grammar/src/span.rs b/grammar/src/span.rs index 3ad9dead75..f7c0eae89d 100644 --- a/grammar/src/span.rs +++ b/grammar/src/span.rs @@ -15,11 +15,11 @@ // along with the Leo library. If not, see . use pest::Span; -use serde::Serialize; +use serde::{Deserialize, Serialize}; // Provide getters for every private field of the remote struct. The getter must // return either `T` or `&T` where `T` is the type of the field. -#[derive(Serialize)] +#[derive(Serialize, Deserialize)] #[serde(remote = "Span")] pub(crate) struct SpanDef<'i> { /// # Attention diff --git a/grammar/tests/circuits.rs b/grammar/tests/circuits.rs new file mode 100644 index 0000000000..33c77151ca --- /dev/null +++ b/grammar/tests/circuits.rs @@ -0,0 +1,116 @@ +// Copyright (C) 2019-2021 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use leo_grammar::ast::{LanguageParser, Rule}; + +use pest::*; + +#[test] +fn circuit_definition() { + parses_to! { + parser: LanguageParser, + input: "circuit Foo { a: u32, }", + rule: Rule::circuit, + tokens: [ + circuit(0, 23, [ + identifier(8, 11, []), + circuit_member(14, 21, + [circuit_variable_definition(14, 21, [ + identifier(14, 15, []), + type_(17, 20, [type_data(17, 20, [type_integer(17, 20, [type_integer_unsigned(17, 20, [type_u32(17, 20, [])])])])]) + ]) + ]) + ]) + ] + } +} + +#[test] +fn circuit_instantiation() { + parses_to! { + parser: LanguageParser, + input: r#"circuit Foo { a: u32, } + function main() { let foo = Foo { a, b: 1u32 }; }"#, + rule: Rule::file, + tokens: [ + file(0, 77, [ + definition(0, 23, [ + circuit(0, 23, [ + identifier(8, 11, []), + circuit_member(14, 21, + [circuit_variable_definition(14, 21, [ + identifier(14, 15, []), + type_(17, 20, [type_data(17, 20, [type_integer(17, 20, [type_integer_unsigned(17, 20, [type_u32(17, 20, [])])])])]) + ]) + ]) + ]), + ]), + definition(28, 77, [ + function(28, 77, [ + identifier(37, 41, []), + block(44, 77, [ + statement(46, 75, [ + statement_definition(46, 75, [ + declare(46, 50, [ + let_(46, 50, []), + ]), + variables(50, 54, [ + variable_name(50, 53, [ + identifier(50, 53, []) + ]) + ]), + expression(56, 74, [ + expression_term(56, 74, [ + expression_circuit_inline(56, 74, [ + circuit_name(56, 59, [ + identifier(56, 59, []) + ]), + circuit_implied_variable(62, 63, [ + identifier(62, 63, []) + ]), + circuit_implied_variable(65, 73, [ + circuit_variable(65, 73, [ + identifier(65, 66, []), + expression(68, 73, [ + expression_term(68, 72, [ + value(68, 72, [ + value_integer(68, 72, [ + value_integer_unsigned(68, 72, [ + number_positive(68, 69, []), + type_integer_unsigned(69, 72, [ + type_u32(69, 72, []) + ]) + ]), + ]) + ]) + ]) + ]) + ]) + ]) + ]) + ]) + ]), + LINE_END(74, 75, []) + ]) + ]) + ]) + ]) + ]), + EOI(77, 77, []) + ]) + ] + } +} diff --git a/grammar/tests/imports.rs b/grammar/tests/imports.rs new file mode 100644 index 0000000000..fb8cdd9a06 --- /dev/null +++ b/grammar/tests/imports.rs @@ -0,0 +1,91 @@ +// Copyright (C) 2019-2021 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use leo_grammar::ast::{LanguageParser, Rule}; + +use pest::*; + +#[test] +fn test_import_package_rule() { + parses_to! { + parser: LanguageParser, + input: "import p.*;", + rule: Rule::import, + tokens: [ + import(0, 11, [ + package_type(7, 10, [ + package(7, 10, [ + package_name(7, 8, []), + package_access(9, 10, [star(9, 10, [])]) + ]) + ]), + LINE_END(10, 11, []) + ]), + ] + } +} + +#[test] +fn test_import_packages_rule() { + parses_to! { + parser: LanguageParser, + input: "import p.(x, y);", + rule: Rule::import, + tokens: [ + import(0, 16, [ + package_type(7, 15, [ + packages(7, 15, [ + package_name(7, 8, []), + package_access(10, 11, [ + import_symbol(10, 11, [identifier(10, 11, [])]), + ]), + package_access(13, 14, [ + import_symbol(13, 14, [identifier(13, 14, [])]), + ]), + ]) + ]), + LINE_END(15, 16, []) + ]) + ] + } +} + +#[test] +fn test_complex_import_rule() { + parses_to! { + parser: LanguageParser, + input: "import p.(q.(x, y), z);", + rule: Rule::import, + tokens: [ + import(0, 23, [ + package_type(7, 22, [ + packages(7, 22, [ + package_name(7, 8, []), + package_access(10, 18, [ + packages(10, 18, [ + package_name(10, 11, []), + package_access(13, 14, [import_symbol(13, 14, [identifier(13, 14, [])])]), + package_access(16, 17, [import_symbol(16, 17, [identifier(16, 17, [])])]), + ]), + ]), + package_access(20, 21, [import_symbol(20, 21, [identifier(20, 21, [])])]), + ]) + ]), + LINE_END(22, 23, []) + ]) + ] + } +} diff --git a/imports/Cargo.toml b/imports/Cargo.toml index defe38e0e7..cae4108447 100644 --- a/imports/Cargo.toml +++ b/imports/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-imports" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Import parser for Leo program package dependencies" homepage = "https://aleo.org" @@ -19,15 +19,15 @@ edition = "2018" [dependencies.leo-ast] path = "../ast" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-grammar] path = "../grammar" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-asg] path = "../asg" -version = "1.1.7" +version = "1.2.0" [dependencies.indexmap] version = "1.6.1" diff --git a/imports/src/parser/parse_package.rs b/imports/src/parser/parse_package.rs index 6a1dd68e0a..d6aa4706b5 100644 --- a/imports/src/parser/parse_package.rs +++ b/imports/src/parser/parse_package.rs @@ -34,7 +34,7 @@ impl ImportParser { return self.parse_package(package.path(), remaining_segments, span); } let program = Self::parse_import_file(package, span)?; - let asg = leo_asg::InnerProgram::new(&program, self)?; + let asg = leo_asg::InternalProgram::new(&program, self)?; Ok(asg) } diff --git a/input/Cargo.toml b/input/Cargo.toml index ce7d6bb84f..8c02fb42c6 100644 --- a/input/Cargo.toml +++ b/input/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-input" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Input parser of the Leo programming language" homepage = "https://aleo.org" diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index bfe4a6b257..8a06b55e1d 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -20,6 +20,7 @@ use leo_package::{outputs::ProofFile, root::Manifest}; use snarkvm_algorithms::snark::groth16::{Groth16, PreparedVerifyingKey, Proof}; use snarkvm_curves::bls12_377::{Bls12_377, Fr}; use snarkvm_models::algorithms::SNARK; +use snarkvm_utilities::bytes::ToBytes; use clap::ArgMatches; use rand::thread_rng; diff --git a/linter/Cargo.toml b/linter/Cargo.toml index a508775c94..8331a36106 100644 --- a/linter/Cargo.toml +++ b/linter/Cargo.toml @@ -2,7 +2,7 @@ dependencies = { } [package] name = "leo-linter" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Linter of the Leo programming language" homepage = "https://aleo.org" diff --git a/package/Cargo.toml b/package/Cargo.toml index fd99c4bdb1..dfa3cd1849 100644 --- a/package/Cargo.toml +++ b/package/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-package" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "Package parser of the Leo programming language" homepage = "https://aleo.org" diff --git a/state/Cargo.toml b/state/Cargo.toml index 2c60f67587..87634d6b6a 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-state" -version = "1.1.8" +version = "1.2.0" authors = [ "The Aleo Team " ] description = "State parser of the Leo programming language" homepage = "https://aleo.org" @@ -19,38 +19,38 @@ edition = "2018" [dependencies.leo-input] path = "../input" -version = "1.1.8" +version = "1.2.0" [dependencies.leo-ast] path = "../ast" -version = "1.1.8" +version = "1.2.0" [dependencies.snarkvm-algorithms] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-curves] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-errors] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-models] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-objects] -version = "0.0.2" +version = "0.0.3" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.2" +version = "0.0.3" [dependencies.indexmap] version = "1.6.1" @@ -66,4 +66,4 @@ version = "0.2" version = "1.0" [dev-dependencies.snarkvm-storage] -version = "0.0.2" +version = "0.0.3" diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index 02bd5d7ca9..62d3d43e79 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -31,18 +31,18 @@ use snarkvm_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; /// Returns `true` if the path to the local data commitment leaf is a valid path in the record -/// commitment merkle tree. +/// commitment Merkle tree. pub fn verify_local_data_commitment( system_parameters: &SystemParameters, ast_input: &AstInput, ) -> Result { - // verify record commitment. + // Verify record commitment. let typed_record = ast_input.get_record(); let dpc_record_values = verify_record_commitment(system_parameters, typed_record)?; let record_commitment: Vec = dpc_record_values.commitment; let record_serial_number: Vec = dpc_record_values.serial_number; - // parse typed state values. + // Parse typed state values. let typed_state = ast_input.get_state(); let state_values = StateValues::try_from(typed_state)?; let leaf_index: u32 = state_values.leaf_index; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 69e649a0a7..db5562c418 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -98,7 +98,7 @@ fn test_generate_values_from_dpc() { let payload: [u8; 32] = rng.gen(); let old_record = DPC::generate_record( - system_parameters.clone(), + &system_parameters, sn_nonce, dummy_account.address, false,