From b751e870e53f0e036e3e760497b3088ca5b4a83c Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Feb 2021 19:23:58 -0800 Subject: [PATCH 01/92] Adds initial wasm template --- .cargo/config | 5 +- Cargo.lock | 79 ++++++++--- Cargo.toml | 3 +- wasm/.resources/basic/expected_ast.json | 138 +++++++++---------- wasm/.resources/basic/main.leo | 3 +- wasm/.resources/dummy_pedersen_hash/main.leo | 2 +- wasm/Cargo.toml | 33 +++++ wasm/src/asg.rs | 123 ++++++++--------- wasm/src/ast.rs | 62 +++++++++ wasm/src/compiler.rs | 47 +++++++ wasm/src/lib.rs | 21 +++ 11 files changed, 357 insertions(+), 159 deletions(-) create mode 100644 wasm/Cargo.toml create mode 100644 wasm/src/lib.rs diff --git a/.cargo/config b/.cargo/config index d6e0c4437c..7c6d594717 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,5 +1,2 @@ -[build] +[target.'cfg(not(target_arch = "wasm32"))'] rustflags = ["-C", "target-cpu=native"] - -[net] -git-fetch-with-cli = true diff --git a/Cargo.lock b/Cargo.lock index f4ce3ed157..df932d21a7 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" @@ -385,6 +385,16 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "console_error_panic_hook" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" +dependencies = [ + "cfg-if 0.1.10", + "wasm-bindgen", +] + [[package]] name = "const_fn" version = "0.4.4" @@ -1188,9 +1198,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" +checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" dependencies = [ "wasm-bindgen", ] @@ -1422,6 +1432,19 @@ dependencies = [ "thiserror", ] +[[package]] +name = "leo-wasm" +version = "1.2.0" +dependencies = [ + "js-sys", + "leo-asg", + "leo-ast", + "leo-grammar", + "serde", + "wasm-bindgen", + "wasm-bindgen-test", +] + [[package]] name = "libc" version = "0.2.81" @@ -3158,9 +3181,9 @@ checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasm-bindgen" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" +checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" dependencies = [ "cfg-if 1.0.0", "serde", @@ -3170,9 +3193,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" +checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" dependencies = [ "bumpalo", "lazy_static", @@ -3185,9 +3208,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3197,9 +3220,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" +checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" dependencies = [ "quote 1.0.7", "wasm-bindgen-macro-support", @@ -3207,9 +3230,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" +checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.7", @@ -3220,9 +3243,33 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" +checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" + +[[package]] +name = "wasm-bindgen-test" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0d4da138503a4cf86801b94d95781ee3619faa8feca830569cc6b54997b8b5c" +dependencies = [ + "console_error_panic_hook", + "js-sys", + "scoped-tls", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-bindgen-test-macro", +] + +[[package]] +name = "wasm-bindgen-test-macro" +version = "0.3.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3199c33f06500c731d5544664c24d0c2b742b98debc6b1c6f0c6d6e8fb7c19b" +dependencies = [ + "proc-macro2 1.0.24", + "quote 1.0.7", +] [[package]] name = "web-sys" diff --git a/Cargo.toml b/Cargo.toml index 83896b2c51..ef8e828d59 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,7 @@ path = "leo/main.rs" [workspace] members = [ + "asg", "ast", "compiler", "gadgets", @@ -35,7 +36,7 @@ members = [ "linter", "package", "state", - "asg" + "wasm" ] [dependencies.leo-ast] diff --git a/wasm/.resources/basic/expected_ast.json b/wasm/.resources/basic/expected_ast.json index cbbcf20a69..809ce782cf 100644 --- a/wasm/.resources/basic/expected_ast.json +++ b/wasm/.resources/basic/expected_ast.json @@ -1,85 +1,77 @@ { - "definitions": [ - { - "Function": { - "identifier": { - "value": "main", - "span": { - "input": "main", - "start": 9, - "end": 13 - } - }, - "parameters": [], - "returns": null, - "block": { - "statements": [ - { - "Return": { - "expression": { - "Binary": { - "operation": "Add", - "left": { - "Value": { - "Implicit": { - "Positive": { - "value": "1", - "span": { - "input": "1", - "start": 29, - "end": 30 - } - } + "name": "basic", + "expected_input": [], + "imports": [], + "circuits": {}, + "functions": { + "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}": { + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}", + "input": [], + "output": null, + "block": { + "statements": [ + { + "Return": { + "expression": { + "Binary": { + "left": { + "Value": { + "Implicit": [ + "1", + { + "text": " return 1 + 1", + "line": 2, + "start": 12, + "end": 13 } - } - }, - "right": { - "Value": { - "Implicit": { - "Positive": { - "value": "1", - "span": { - "input": "1", - "start": 33, - "end": 34 - } - } - } - } - }, - "span": { - "input": "1 + 1", - "start": 29, - "end": 34 + ] } + }, + "op": "Add", + "right": { + "Value": { + "Implicit": [ + "1", + { + "text": " return 1 + 1", + "line": 2, + "start": 16, + "end": 17 + } + ] + } + }, + "span": { + "text": " return 1 + 1", + "line": 2, + "start": 12, + "end": 17 } - }, - "span": { - "input": "return 1 + 1", - "start": 22, - "end": 34 } + }, + "span" : { + "text": " return 1 + 1", + "line": 2, + "start": 5, + "end": 17 } } - ], - "span": { - "input": "{\n return 1 + 1\n}", - "start": 16, - "end": 36 } - }, - "span": { - "input": "function main() {\n return 1 + 1\n}", - "start": 0, - "end": 36 + ], + "span" : { + "text": " return 1 + 1", + "line": 2, + "start": 5, + "end": 17 } + }, + "span": { + "text": " function main() {", + "line": 1, + "start": 1, + "end": 1 } } - ], - "eoi": null, - "span": { - "input": "function main() {\n return 1 + 1\n}\n", - "start": 0, - "end": 37 - } + }, + "tests": {} } \ No newline at end of file diff --git a/wasm/.resources/basic/main.leo b/wasm/.resources/basic/main.leo index 41db522f5f..ef22115243 100644 --- a/wasm/.resources/basic/main.leo +++ b/wasm/.resources/basic/main.leo @@ -1,4 +1,3 @@ -// The dummy 'pedersen-hash' main function. -function main() -> u32 { +function main() { return 1 + 1 } diff --git a/wasm/.resources/dummy_pedersen_hash/main.leo b/wasm/.resources/dummy_pedersen_hash/main.leo index af8fdfe2bc..a3413bbe39 100644 --- a/wasm/.resources/dummy_pedersen_hash/main.leo +++ b/wasm/.resources/dummy_pedersen_hash/main.leo @@ -17,7 +17,7 @@ circuit PedersenHash { } } -// The dummy 'pedersen-hash' main function. +// The 'dummy-pedersen-hash' main function. function main() -> group { const parameters = [1group; 256]; const pedersen = PedersenHash::new(parameters); diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml new file mode 100644 index 0000000000..aedba85363 --- /dev/null +++ b/wasm/Cargo.toml @@ -0,0 +1,33 @@ +[package] +name = "leo-wasm" +version = "1.2.0" +authors = [ "The Aleo Team " ] +description = "WASM interpreter of the Leo programming language" +homepage = "https://aleo.org" +repository = "https://github.com/AleoHQ/leo" +keywords = [ + "aleo", + "cryptography", + "leo", + "programming-language", + "zero-knowledge" +] +categories = [ "cryptography::cryptocurrencies", "web-programming" ] +include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] +license = "GPL-3.0" +edition = "2018" + +[lib] +crate-type = ["cdylib", "rlib"] + +[dependencies] +leo-asg = { path = "../asg", version = "1.2.0" } +leo-ast = { path = "../ast", version = "1.2.0" } +leo-grammar = { path = "../grammar", version = "1.2.0" } + +js-sys = "0.3.47" +serde = { version = "1.0", features = ["derive"] } +wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } + +[dev-dependencies] +wasm-bindgen-test = { version = "0.3.20" } diff --git a/wasm/src/asg.rs b/wasm/src/asg.rs index fd066a357d..1ee108b086 100644 --- a/wasm/src/asg.rs +++ b/wasm/src/asg.rs @@ -1,62 +1,61 @@ -// 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_ast::Ast as LeoAst; -use leo_grammar::Grammar as LeoGrammar; - -use std::path::Path; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -pub struct Ast(String); - -#[wasm_bindgen] -impl Ast { - #[wasm_bindgen(constructor)] - pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { - let grammar = LeoGrammar::new(&Path::new(filepath), &program_string).unwrap(); - let ast = LeoAst::new(program_name, &grammar).unwrap(); - Self(ast.to_json_string().unwrap()) - } - - #[wasm_bindgen] - pub fn to_string(&self) -> String { - self.0.clone() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use wasm_bindgen_test::*; - - #[wasm_bindgen_test] - fn ast_test() { - let expected = include_str!("../.resources/basic/expected_ast.json"); - - let filepath = "../.resources/basic/main.leo"; - let program_name = "basic"; - let program_string = include_str!("../.resources/basic/main.leo"); - - let candidate = Ast::new(filepath, program_name, program_string).to_string(); - - let expected = JsValue::from_str(expected); - let candidate = JsValue::from_serde(&candidate).unwrap(); - - assert_eq!(expected, candidate); - } -} +// // 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_asg::Asg as LeoAsg; +// use leo_grammar::Grammar as LeoGrammar; +// +// use std::path::Path; +// use wasm_bindgen::prelude::*; +// +// #[wasm_bindgen] +// pub struct Ast(String); +// +// #[wasm_bindgen] +// impl Ast { +// #[wasm_bindgen(constructor)] +// pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { +// let asg = LeoAsg::new(&self.program, &mut leo_imports::ImportParser::default())?; +// Self(ast.to_json_string().unwrap()) +// } +// +// #[wasm_bindgen] +// pub fn to_string(&self) -> String { +// self.0.clone() +// } +// } +// +// #[cfg(test)] +// mod tests { +// use super::*; +// +// use wasm_bindgen_test::*; +// +// #[wasm_bindgen_test] +// fn ast_test() { +// let expected = include_str!("../.resources/basic/expected_ast.json"); +// +// let filepath = "../.resources/basic/main.leo"; +// let program_name = "basic"; +// let program_string = include_str!("../.resources/basic/main.leo"); +// +// let candidate = Ast::new(filepath, program_name, program_string).to_string(); +// +// let expected = JsValue::from_str(expected); +// let candidate = JsValue::from_serde(&candidate).unwrap(); +// +// assert_eq!(expected, candidate); +// } +// } diff --git a/wasm/src/ast.rs b/wasm/src/ast.rs index e69de29bb2..b0661c8eab 100644 --- a/wasm/src/ast.rs +++ b/wasm/src/ast.rs @@ -0,0 +1,62 @@ +// 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_ast::Ast as LeoAst; +use leo_grammar::Grammar as LeoGrammar; + +use std::path::Path; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub struct Ast(LeoAst); + +#[wasm_bindgen] +impl Ast { + #[wasm_bindgen(constructor)] + pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { + let grammar = LeoGrammar::new(&Path::new(filepath), &program_string).unwrap(); + let ast = LeoAst::new(program_name, &grammar).unwrap(); + Self(ast) + } + + #[wasm_bindgen] + pub fn to_string(&self) -> String { + self.0.to_json_string().unwrap() + } +} + +// #[cfg(test)] +// mod tests { +// use super::*; +// +// use wasm_bindgen_test::*; +// +// #[wasm_bindgen_test] +// fn ast_test() { +// let expected = include_str!("../.resources/basic/expected_ast.json"); +// +// let filepath = "../.resources/basic/main.leo"; +// let program_name = "basic"; +// let program_string = include_str!("../.resources/basic/main.leo"); +// +// let candidate = Ast::new(filepath, program_name, program_string).to_string(); +// +// let expected = JsValue::from_str(expected); +// let candidate = JsValue::from_serde(&candidate).unwrap(); +// +// assert_eq!(expected, candidate); +// } +// } diff --git a/wasm/src/compiler.rs b/wasm/src/compiler.rs index e69de29bb2..ea5430574a 100644 --- a/wasm/src/compiler.rs +++ b/wasm/src/compiler.rs @@ -0,0 +1,47 @@ +// // 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::Ast; +// +// use std::path::Path; +// use wasm_bindgen::prelude::*; +// +// #[wasm_bindgen] +// pub struct Compiler(String); +// +// #[wasm_bindgen] +// impl Compiler { +// #[wasm_bindgen(constructor)] +// pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { +// let ast = Ast::new(filepath, program_name, program_string).unwrap(); +// Self(ast.to_string()) +// } +// +// #[wasm_bindgen] +// pub fn to_string(&self) -> String { +// self.0.clone() +// } +// } +// +// #[cfg(test)] +// mod tests { +// use super::*; +// +// use wasm_bindgen_test::*; +// +// #[wasm_bindgen_test] +// fn ast_test() {} +// } diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs new file mode 100644 index 0000000000..1b5e5d9baa --- /dev/null +++ b/wasm/src/lib.rs @@ -0,0 +1,21 @@ +// 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 ast; +pub use ast::*; + +// pub mod compiler; +// pub use compiler::*; From d8fad177925b7b41623aedc4c03c205dae5cb701 Mon Sep 17 00:00:00 2001 From: howardwu Date: Fri, 5 Feb 2021 12:46:19 -0800 Subject: [PATCH 02/92] Checkpoint state --- Cargo.lock | 2 -- wasm/.resources/basic/expected_ast.json | 18 +++++++++--------- wasm/Cargo.toml | 4 ++-- wasm/src/lib.rs | 6 +++--- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ca9243c30a..4393ae3db2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1438,10 +1438,8 @@ dependencies = [ name = "leo-wasm" version = "1.2.0" dependencies = [ - "leo-asg", "leo-ast", "leo-grammar", - "leo-imports", "serde", "wasm-bindgen", "wasm-bindgen-test", diff --git a/wasm/.resources/basic/expected_ast.json b/wasm/.resources/basic/expected_ast.json index dec3baf947..5703033471 100644 --- a/wasm/.resources/basic/expected_ast.json +++ b/wasm/.resources/basic/expected_ast.json @@ -8,7 +8,7 @@ "identifier": "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}", "input": [], "output": null, - "block": { + "block" : { "statements": [ { "Return": { @@ -27,6 +27,7 @@ ] } }, + "op": "Add", "right": { "Value": { "Implicit": [ @@ -40,7 +41,6 @@ ] } }, - "op": "Add", "span": { "text": " return 1 + 1", "line": 2, @@ -49,7 +49,7 @@ } } }, - "span": { + "span" : { "text": " return 1 + 1", "line": 2, "start": 5, @@ -58,18 +58,18 @@ } } ], - "span": { - "text": " function main() {", - "line": 1, - "start": 17, - "end": 2 + "span" : { + "text": " return 1 + 1", + "line": 2, + "start": 5, + "end": 17 } }, "span": { "text": " function main() {", "line": 1, "start": 1, - "end": 2 + "end": 1 } } }, diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index 100b210dc5..efad2a57fa 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -21,9 +21,9 @@ edition = "2018" crate-type = ["cdylib", "rlib"] [dependencies] -leo-asg = { path = "../asg", version = "1.2.0" } +#leo-asg = { path = "../asg", version = "1.2.0" } leo-ast = { path = "../ast", version = "1.2.0" } -leo-imports = { path = "../imports", version = "1.2.0" } +#leo-imports = { path = "../imports", version = "1.2.0" } leo-grammar = { path = "../grammar", version = "1.2.0" } serde = { version = "1.0", features = ["derive"] } diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index c1808960b3..d457955975 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -13,9 +13,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . - -pub mod asg; -pub use asg::*; +// +// pub mod asg; +// pub use asg::*; pub mod ast; pub use ast::*; From 6398f3cb1e07dd6753420e0083176f7256a11d8b Mon Sep 17 00:00:00 2001 From: howardwu Date: Fri, 5 Feb 2021 13:00:45 -0800 Subject: [PATCH 03/92] Add grammar check --- wasm/.resources/basic/expected_ast.json | 18 ++--- wasm/.resources/basic/expected_grammar.json | 85 +++++++++++++++++++++ wasm/src/grammar.rs | 60 +++++++++++++++ wasm/src/lib.rs | 3 + 4 files changed, 157 insertions(+), 9 deletions(-) create mode 100644 wasm/.resources/basic/expected_grammar.json create mode 100644 wasm/src/grammar.rs diff --git a/wasm/.resources/basic/expected_ast.json b/wasm/.resources/basic/expected_ast.json index 5703033471..dec3baf947 100644 --- a/wasm/.resources/basic/expected_ast.json +++ b/wasm/.resources/basic/expected_ast.json @@ -8,7 +8,7 @@ "identifier": "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}", "input": [], "output": null, - "block" : { + "block": { "statements": [ { "Return": { @@ -27,7 +27,6 @@ ] } }, - "op": "Add", "right": { "Value": { "Implicit": [ @@ -41,6 +40,7 @@ ] } }, + "op": "Add", "span": { "text": " return 1 + 1", "line": 2, @@ -49,7 +49,7 @@ } } }, - "span" : { + "span": { "text": " return 1 + 1", "line": 2, "start": 5, @@ -58,18 +58,18 @@ } } ], - "span" : { - "text": " return 1 + 1", - "line": 2, - "start": 5, - "end": 17 + "span": { + "text": " function main() {", + "line": 1, + "start": 17, + "end": 2 } }, "span": { "text": " function main() {", "line": 1, "start": 1, - "end": 1 + "end": 2 } } }, diff --git a/wasm/.resources/basic/expected_grammar.json b/wasm/.resources/basic/expected_grammar.json new file mode 100644 index 0000000000..6c0e4c9404 --- /dev/null +++ b/wasm/.resources/basic/expected_grammar.json @@ -0,0 +1,85 @@ +{ + "definitions": [ + { + "Function": { + "identifier": { + "value": "main", + "span": { + "input": "main", + "start": 9, + "end": 13 + } + }, + "parameters": [], + "returns": null, + "block": { + "statements": [ + { + "Return": { + "expression": { + "Binary": { + "operation": "Add", + "left": { + "Value": { + "Implicit": { + "Positive": { + "value": "1", + "span": { + "input": "1", + "start": 29, + "end": 30 + } + } + } + } + }, + "right": { + "Value": { + "Implicit": { + "Positive": { + "value": "1", + "span": { + "input": "1", + "start": 33, + "end": 34 + } + } + } + } + }, + "span": { + "input": "1 + 1", + "start": 29, + "end": 34 + } + } + }, + "span": { + "input": "return 1 + 1", + "start": 22, + "end": 34 + } + } + } + ], + "span": { + "input": "{\n return 1 + 1\n}", + "start": 16, + "end": 36 + } + }, + "span": { + "input": "function main() {\n return 1 + 1\n}", + "start": 0, + "end": 36 + } + } + } + ], + "eoi": null, + "span": { + "input": "function main() {\n return 1 + 1\n}\n", + "start": 0, + "end": 37 + } +} \ No newline at end of file diff --git a/wasm/src/grammar.rs b/wasm/src/grammar.rs new file mode 100644 index 0000000000..d181661446 --- /dev/null +++ b/wasm/src/grammar.rs @@ -0,0 +1,60 @@ +// 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_ast::Ast as LeoAst; +use leo_grammar::Grammar as LeoGrammar; + +use std::path::Path; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub struct Grammar(pub(crate) String); + +#[wasm_bindgen] +impl Grammar { + #[wasm_bindgen(constructor)] + pub fn new(filepath: &str, program_string: &str) -> Self { + let grammar = LeoGrammar::new(&Path::new(filepath), &program_string).unwrap(); + Self(grammar.to_json_string().unwrap()) + } + + #[wasm_bindgen] + pub fn to_string(&self) -> String { + self.0.clone() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + use wasm_bindgen_test::*; + + #[wasm_bindgen_test] + fn grammar_test() { + let expected = include_str!("../.resources/basic/expected_grammar.json"); + + let filepath = "../.resources/basic/main.leo"; + let program_string = include_str!("../.resources/basic/main.leo"); + + let candidate = Grammar::new(filepath, program_string).to_string(); + + let expected = JsValue::from_str(expected); + let candidate = JsValue::from_serde(&candidate).unwrap(); + + assert_eq!(expected, candidate); + } +} diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index d457955975..624e19f64c 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -20,5 +20,8 @@ pub mod ast; pub use ast::*; +pub mod grammar; +pub use grammar::*; + // pub mod compiler; // pub use compiler::*; From b7456ce97629836672a0ce6bdd30767d8d7d9ae3 Mon Sep 17 00:00:00 2001 From: howardwu Date: Sun, 7 Feb 2021 08:07:28 -0800 Subject: [PATCH 04/92] chore(leo): bump version for new release --- .resources/release-version | 2 +- Cargo.lock | 24 ++++++++++++------------ Cargo.toml | 16 ++++++++-------- asg/Cargo.toml | 6 +++--- ast/Cargo.toml | 6 +++--- compiler/Cargo.toml | 18 +++++++++--------- gadgets/Cargo.toml | 2 +- grammar/Cargo.toml | 2 +- imports/Cargo.toml | 8 ++++---- input/Cargo.toml | 2 +- linter/Cargo.toml | 2 +- package/Cargo.toml | 2 +- state/Cargo.toml | 6 +++--- wasm/Cargo.toml | 29 ++++++++++++++++++----------- 14 files changed, 66 insertions(+), 59 deletions(-) diff --git a/.resources/release-version b/.resources/release-version index 0408c30b42..24e56e03c0 100644 --- a/.resources/release-version +++ b/.resources/release-version @@ -1 +1 @@ -v1.2.0 \ No newline at end of file +v1.2.1 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 4393ae3db2..0356295a80 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1244,7 +1244,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leo-asg" -version = "1.2.0" +version = "1.2.1" dependencies = [ "criterion", "indexmap", @@ -1259,7 +1259,7 @@ dependencies = [ [[package]] name = "leo-ast" -version = "1.2.0" +version = "1.2.1" dependencies = [ "criterion", "indexmap", @@ -1273,7 +1273,7 @@ dependencies = [ [[package]] name = "leo-compiler" -version = "1.2.0" +version = "1.2.1" dependencies = [ "bincode", "hex", @@ -1307,7 +1307,7 @@ dependencies = [ [[package]] name = "leo-gadgets" -version = "1.2.0" +version = "1.2.1" dependencies = [ "criterion", "rand", @@ -1320,7 +1320,7 @@ dependencies = [ [[package]] name = "leo-grammar" -version = "1.2.0" +version = "1.2.1" dependencies = [ "criterion", "from-pest", @@ -1336,7 +1336,7 @@ dependencies = [ [[package]] name = "leo-imports" -version = "1.2.0" +version = "1.2.1" dependencies = [ "indexmap", "leo-asg", @@ -1348,7 +1348,7 @@ dependencies = [ [[package]] name = "leo-input" -version = "1.2.0" +version = "1.2.1" dependencies = [ "from-pest", "pest", @@ -1360,7 +1360,7 @@ dependencies = [ [[package]] name = "leo-lang" -version = "1.2.0" +version = "1.2.1" dependencies = [ "clap", "colored", @@ -1399,11 +1399,11 @@ dependencies = [ [[package]] name = "leo-linter" -version = "1.2.0" +version = "1.2.1" [[package]] name = "leo-package" -version = "1.2.0" +version = "1.2.1" dependencies = [ "lazy_static", "serde", @@ -1416,7 +1416,7 @@ dependencies = [ [[package]] name = "leo-state" -version = "1.2.0" +version = "1.2.1" dependencies = [ "indexmap", "leo-ast", @@ -1436,7 +1436,7 @@ dependencies = [ [[package]] name = "leo-wasm" -version = "1.2.0" +version = "1.2.1" dependencies = [ "leo-ast", "leo-grammar", diff --git a/Cargo.toml b/Cargo.toml index ef8e828d59..225420e66e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-lang" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "The Leo programming language" homepage = "https://aleo.org" @@ -41,31 +41,31 @@ members = [ [dependencies.leo-ast] path = "./ast" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-compiler] path = "./compiler" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-gadgets] path = "./gadgets" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-imports] path = "./imports" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-input] path = "./input" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-package] path = "./package" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-state] path = "./state" -version = "1.2.0" +version = "1.2.1" [dependencies.snarkvm-algorithms] version = "0.0.2" diff --git a/asg/Cargo.toml b/asg/Cargo.toml index 930a989ced..5327a690fd 100644 --- a/asg/Cargo.toml +++ b/asg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-asg" -version = "1.2.0" +version = "1.2.1" 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.2.0" +version = "1.2.1" path = "../ast" [dependencies.leo-grammar] -version = "1.2.0" +version = "1.2.1" path = "../grammar" [dependencies.uuid] diff --git a/ast/Cargo.toml b/ast/Cargo.toml index c3f346ba0f..3ddabd306a 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-ast" -version = "1.2.0" +version = "1.2.1" 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.2.0" +version = "1.2.1" [dependencies.leo-input] path = "../input" -version = "1.2.0" +version = "1.2.1" [dependencies.indexmap] version = "1.6.1" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index a3634405c4..32b319417a 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-compiler" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "Compiler of the Leo programming language" homepage = "https://aleo.org" @@ -19,35 +19,35 @@ edition = "2018" [dependencies.leo-ast] path = "../ast" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-gadgets] path = "../gadgets" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-grammar] path = "../grammar" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-imports] path = "../imports" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-input] path = "../input" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-package] path = "../package" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-state] path = "../state" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-asg] path = "../asg" -version = "1.2.0" +version = "1.2.1" [dependencies.snarkvm-curves] version = "0.0.2" diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index 4483f1cff6..46fe339ef6 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-gadgets" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "Gadgets of the Leo programming language" homepage = "https://aleo.org" diff --git a/grammar/Cargo.toml b/grammar/Cargo.toml index 1325e5b017..c8f3f1c176 100644 --- a/grammar/Cargo.toml +++ b/grammar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-grammar" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "AST generated by pest from the Leo grammar rules" homepage = "https://aleo.org" diff --git a/imports/Cargo.toml b/imports/Cargo.toml index cae4108447..4e62890695 100644 --- a/imports/Cargo.toml +++ b/imports/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-imports" -version = "1.2.0" +version = "1.2.1" 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.2.0" +version = "1.2.1" [dependencies.leo-grammar] path = "../grammar" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-asg] path = "../asg" -version = "1.2.0" +version = "1.2.1" [dependencies.indexmap] version = "1.6.1" diff --git a/input/Cargo.toml b/input/Cargo.toml index 8c02fb42c6..97756e32f8 100644 --- a/input/Cargo.toml +++ b/input/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-input" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "Input parser of the Leo programming language" homepage = "https://aleo.org" diff --git a/linter/Cargo.toml b/linter/Cargo.toml index 8331a36106..ebeabf332a 100644 --- a/linter/Cargo.toml +++ b/linter/Cargo.toml @@ -2,7 +2,7 @@ dependencies = { } [package] name = "leo-linter" -version = "1.2.0" +version = "1.2.1" 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 dfa3cd1849..6dba6092bc 100644 --- a/package/Cargo.toml +++ b/package/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-package" -version = "1.2.0" +version = "1.2.1" 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 4acd7d4c15..fb6e281fd8 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-state" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "State parser of the Leo programming language" homepage = "https://aleo.org" @@ -19,11 +19,11 @@ edition = "2018" [dependencies.leo-input] path = "../input" -version = "1.2.0" +version = "1.2.1" [dependencies.leo-ast] path = "../ast" -version = "1.2.0" +version = "1.2.1" [dependencies.snarkvm-algorithms] version = "0.0.2" diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index efad2a57fa..570fdfc80c 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-wasm" -version = "1.2.0" +version = "1.2.1" authors = [ "The Aleo Team " ] description = "WASM interpreter of the Leo programming language" homepage = "https://aleo.org" @@ -18,16 +18,23 @@ license = "GPL-3.0" edition = "2018" [lib] -crate-type = ["cdylib", "rlib"] +crate-type = [ "cdylib", "rlib" ] -[dependencies] -#leo-asg = { path = "../asg", version = "1.2.0" } -leo-ast = { path = "../ast", version = "1.2.0" } -#leo-imports = { path = "../imports", version = "1.2.0" } -leo-grammar = { path = "../grammar", version = "1.2.0" } +[dependencies.leo-ast] +path = "../ast" +version = "1.2.1" -serde = { version = "1.0", features = ["derive"] } -wasm-bindgen = { version = "0.2", features = ["serde-serialize"] } +[dependencies.leo-grammar] +path = "../grammar" +version = "1.2.1" -[dev-dependencies] -wasm-bindgen-test = { version = "0.3.20" } +[dependencies.serde] +version = "1.0" +features = [ "derive" ] + +[dependencies.wasm-bindgen] +version = "0.2" +features = [ "serde-serialize" ] + +[dev-dependencies.wasm-bindgen-test] +version = "0.3.20" From 317fc08fc572268d9b6c98074633b72125247977 Mon Sep 17 00:00:00 2001 From: gluax Date: Wed, 17 Feb 2021 11:27:33 -0500 Subject: [PATCH 05/92] implicit value at start of array failing fix --- asg/src/expression/array_inline.rs | 22 ++++++++++++++++++++++ asg/src/expression/constant.rs | 4 +++- asg/tests/pass/array/implicit.leo | 6 ++++++ asg/tests/pass/array/mod.rs | 6 ++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 asg/tests/pass/array/implicit.leo diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index ad4de160fd..e716d6208a 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -105,6 +105,7 @@ impl FromAst for ArrayInlineExpression { value: &leo_ast::ArrayInlineExpression, expected_type: Option, ) -> Result { + // println!("v: {:?}", value); let (mut expected_item, expected_len) = match expected_type { Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims), None => (None, None), @@ -118,6 +119,27 @@ impl FromAst for ArrayInlineExpression { }; let mut len = 0; + + if len == 0 && expected_item.is_none() { + for expr in value.elements.iter() { + expected_item = match expr { + SpreadOrExpression::Expression(e) => { + match Arc::::from_ast(scope, e, expected_item.clone()) { + Ok(expr) => { + expr.get_type().map(Type::partial) + }, + Err(_) => continue, + } + }, + _ => None + }; + + if expected_item.is_some() { + break; + } + } + } + let output = ArrayInlineExpression { parent: RefCell::new(None), span: Some(value.span.clone()), diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index e2cfe82512..a2e5349140 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -161,7 +161,9 @@ impl FromAst for Constant { } } Implicit(value, span) => match expected_type { - None => return Err(AsgConvertError::unresolved_type("unknown", span)), + None => { + return Err(AsgConvertError::unresolved_type("unknown", span)) + }, Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => { Constant { parent: RefCell::new(None), diff --git a/asg/tests/pass/array/implicit.leo b/asg/tests/pass/array/implicit.leo new file mode 100644 index 0000000000..a7077c8389 --- /dev/null +++ b/asg/tests/pass/array/implicit.leo @@ -0,0 +1,6 @@ +function main(){ + let a = [1u8, 2u8, 3u8, 4]; + let b = [1u8, 2u8, 3, 4u8]; + let c = [1u8, 2, 3u8, 4u8]; + let d = [1, 2u8, 3u8, 4u8]; +} \ No newline at end of file diff --git a/asg/tests/pass/array/mod.rs b/asg/tests/pass/array/mod.rs index bca1da1a97..60caab461d 100644 --- a/asg/tests/pass/array/mod.rs +++ b/asg/tests/pass/array/mod.rs @@ -104,6 +104,12 @@ fn test_slice_lower() { load_asg(program_string).unwrap(); } +#[test] +fn test_implicit() { + let program_string = include_str!("implicit.leo"); + load_asg(program_string).unwrap(); +} + #[test] fn test_type_nested_value_nested_3x2() { let program_string = include_str!("type_nested_value_nested_3x2.leo"); From e0fdb734350ac05e77ec38b211cac60babe31ec6 Mon Sep 17 00:00:00 2001 From: gluax Date: Wed, 17 Feb 2021 11:33:54 -0500 Subject: [PATCH 06/92] forgot to push fmted code --- asg/src/expression/array_inline.rs | 8 +++----- asg/src/expression/constant.rs | 4 +--- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index e716d6208a..158a7bb174 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -125,13 +125,11 @@ impl FromAst for ArrayInlineExpression { expected_item = match expr { SpreadOrExpression::Expression(e) => { match Arc::::from_ast(scope, e, expected_item.clone()) { - Ok(expr) => { - expr.get_type().map(Type::partial) - }, + Ok(expr) => expr.get_type().map(Type::partial), Err(_) => continue, } - }, - _ => None + } + _ => None, }; if expected_item.is_some() { diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index a2e5349140..e2cfe82512 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -161,9 +161,7 @@ impl FromAst for Constant { } } Implicit(value, span) => match expected_type { - None => { - return Err(AsgConvertError::unresolved_type("unknown", span)) - }, + None => return Err(AsgConvertError::unresolved_type("unknown", span)), Some(PartialType::Integer(Some(sub_type), _)) | Some(PartialType::Integer(None, Some(sub_type))) => { Constant { parent: RefCell::new(None), From f8e43e5bd0fe228a6a16996d1e68547a7a593510 Mon Sep 17 00:00:00 2001 From: damirka Date: Mon, 22 Feb 2021 19:12:25 +0300 Subject: [PATCH 07/92] adds publishing workflow to actions --- .github/workflows/leo-publish.yml | 49 +++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/leo-publish.yml diff --git a/.github/workflows/leo-publish.yml b/.github/workflows/leo-publish.yml new file mode 100644 index 0000000000..c86fc32c97 --- /dev/null +++ b/.github/workflows/leo-publish.yml @@ -0,0 +1,49 @@ +name: leo-publish +on: + pull_request: + push: + branches: + - master + paths-ignore: + - 'docs/**' + - 'documentation/**' +env: + RUST_BACKTRACE: 1 + +jobs: + add: + name: Add Package ('leo add') + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: nightly + override: true + components: rustfmt + + - name: Install Leo + uses: actions-rs/cargo@v1 + env: + CARGO_NET_GIT_FETCH_WITH_CLI: true + with: + command: install + args: --path . + + - name: 'leo login, publish and logout' + env: + USER: ${{ secrets.ALEO_PM_USERNAME }} + PASS: ${{ secrets.ALEO_PM_PASSWORD }} + run: | + cd .. && leo new test-app && cd test-app + leo login -u "$USER" -p "$PASS" + cat Leo.toml | sed "s/0.1.0/0.1.$GITHUB_RUN_ID/g" | sed "s/\[AUTHOR\]/$USER/g" > Leo.toml + leo publish + leo logout + + + From 944d93fe4e655ff31dcbc66afb462244e209a239 Mon Sep 17 00:00:00 2001 From: damirka Date: Thu, 25 Feb 2021 16:03:55 +0300 Subject: [PATCH 08/92] added comment for publishing workflow --- .github/workflows/leo-publish.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/leo-publish.yml b/.github/workflows/leo-publish.yml index c86fc32c97..0e08d44422 100644 --- a/.github/workflows/leo-publish.yml +++ b/.github/workflows/leo-publish.yml @@ -34,6 +34,10 @@ jobs: command: install args: --path . + # sed command below takes 0.1.0 version (which is default for new programs) + # and replaces it with GITHUB_RUN_ID - a unique incremental number for each + # GH Actions run; [AUTHOR] gets replaced with $USER variable; and we're ready + # to publish package with newer version and correct author - name: 'leo login, publish and logout' env: USER: ${{ secrets.ALEO_PM_USERNAME }} From 6d19c9470a6957f2a7e649873a9089c704580f84 Mon Sep 17 00:00:00 2001 From: damirka Date: Thu, 25 Feb 2021 16:05:11 +0300 Subject: [PATCH 09/92] fixes copy-paste naming --- .github/workflows/leo-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/leo-publish.yml b/.github/workflows/leo-publish.yml index 0e08d44422..7760898d70 100644 --- a/.github/workflows/leo-publish.yml +++ b/.github/workflows/leo-publish.yml @@ -11,8 +11,8 @@ env: RUST_BACKTRACE: 1 jobs: - add: - name: Add Package ('leo add') + publish: + name: Publish Package ('leo publish') runs-on: ubuntu-latest steps: - name: Checkout From be398437c6566f8fc1ef06b061edc4892494d556 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 08:56:20 -0800 Subject: [PATCH 10/92] Updates snarkVM to 0.0.5, updates rand usage --- Cargo.lock | 648 +++++++----------- Cargo.toml | 14 +- compiler/Cargo.toml | 29 +- .../core/packages/unstable/blake2s/mod.rs | 3 +- gadgets/Cargo.toml | 13 +- gadgets/tests/signed_integer/i128.rs | 11 +- gadgets/tests/signed_integer/i16.rs | 19 +- gadgets/tests/signed_integer/i32.rs | 19 +- gadgets/tests/signed_integer/i64.rs | 19 +- gadgets/tests/signed_integer/i8.rs | 11 +- state/Cargo.toml | 23 +- .../test_verify_local_data_commitment.rs | 3 +- state/tests/test_verify_record_commitment.rs | 2 +- 13 files changed, 340 insertions(+), 474 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3b8a622e03..c0f10ec277 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,18 +2,18 @@ # It is not intended for manual editing. [[package]] name = "addr2line" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c0929d69e78dd9bf5408269919fcbcaeb2e35e5d43e5815517cdc6a8e11a423" +checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" dependencies = [ "gimli", ] [[package]] name = "adler" -version = "0.2.3" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2a4ec343196209d6594e19543ae87a39f96d5534d7174822a3ad825dd6ed7e" +checksum = "bedc89c5c7b5550ffb9372eb5c5ffc7f9f705cc3f4a128bd4669b9745f555093" [[package]] name = "adler32" @@ -85,14 +85,14 @@ checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" [[package]] name = "backtrace" -version = "0.3.55" +version = "0.3.56" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef5140344c85b01f9bbb4d4b7288a8aa4b3287ccef913a14bcc78a1063623598" +checksum = "9d117600f438b1707d4e4ae15d3595657288f8235a0eb593e80ecc98ab34e1bc" dependencies = [ "addr2line", "cfg-if 1.0.0", "libc", - "miniz_oxide 0.4.3", + "miniz_oxide 0.4.4", "object", "rustc-demangle", ] @@ -142,7 +142,7 @@ dependencies = [ "log", "peeking_take_while", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "regex", "rustc-hash", "shlex", @@ -157,14 +157,13 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "blake2" -version = "0.8.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94cb07b0da6a73955f8fb85d24c466778e70cda767a568229b104f0264089330" +checksum = "10a5720225ef5daecf08657f23791354e1685a8c91a4c60c7f3d3b2892f978f4" dependencies = [ - "byte-tools", "crypto-mac", - "digest 0.8.1", - "opaque-debug 0.2.3", + "digest 0.9.0", + "opaque-debug 0.3.0", ] [[package]] @@ -210,9 +209,9 @@ dependencies = [ [[package]] name = "bstr" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "473fc6b38233f9af7baa94fb5852dca389e3d95b8e21c8e3719301462c5d9faf" +checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d" dependencies = [ "lazy_static", "memchr", @@ -222,9 +221,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.4.0" +version = "3.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e8c087f005730276d1096a652e92a8bacee2e2472bcc9715a74d2bec38b5820" +checksum = "63396b8a4b9de3f4fdfb320ab6080762242f66a8ef174c49d8e19b674db4cdbe" [[package]] name = "byte-tools" @@ -240,15 +239,9 @@ checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de" [[package]] name = "bytes" -version = "0.5.6" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e4cec68f03f32e44924783795810fa50a7035d8c8ebe78580ad7e6c703fba38" - -[[package]] -name = "bytes" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1f8e949d755f9d79112b5bb46938e0ef9d3804a0b16dfab13aafcaa5f0fa72" +checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" [[package]] name = "bzip2" @@ -262,9 +255,9 @@ dependencies = [ [[package]] name = "bzip2-sys" -version = "0.1.9+1.0.8" +version = "0.1.10+1.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad3b39a260062fca31f7b0b12f207e8f2590a67d32ec7d59c20484b07ea7285e" +checksum = "17fa3d1ac1ca21c5c4e36a97f3c3eb25084576f6fc47bf0139c1123434216c6c" dependencies = [ "cc", "libc", @@ -282,9 +275,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.66" +version = "1.0.67" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c0496836a84f8d0495758516b8621a622beb77c0fed418570e50764093ced48" +checksum = "e3c69b077ad434294d3ce9f1f6143a2a4b89a8a2d54ef813d85003a4fd1137fd" dependencies = [ "jobserver", ] @@ -385,12 +378,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "const_fn" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd51eab21ab4fd6a3bf889e2d0958c0a6e3a61ad04260325e919e652a2a62826" - [[package]] name = "constant_time_eq" version = "0.1.5" @@ -487,12 +474,11 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.1" +version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1aaa739f95311c2c7887a76863f500026092fb1dce0161dab577e559ef3569d" +checksum = "2584f639eb95fea8c798496315b297cf81b9b58b6d30ab066a75455333cf4b12" dependencies = [ "cfg-if 1.0.0", - "const_fn", "crossbeam-utils", "lazy_static", "memoffset", @@ -501,9 +487,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02d96d1e189ef58269ebe5b97953da3274d83a93af647c2ddd6f9dab28cedb8d" +checksum = "e7e9d99fa91428effe99c5c6d4634cdeba32b8cf784fc428a2a687f61a952c49" dependencies = [ "autocfg", "cfg-if 1.0.0", @@ -512,11 +498,11 @@ dependencies = [ [[package]] name = "crypto-mac" -version = "0.7.0" +version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.12.3", + "generic-array 0.14.4", "subtle", ] @@ -559,9 +545,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.39+curl-7.74.0" +version = "0.4.40+curl-7.75.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07a8ce861e7b68a0b394e814d7ee9f1b2750ff8bd10372c6ad3bacc10e86f874" +checksum = "2ffafc1c35958318bd7fdd0582995ce4c72f4f461a8e70499ccee83a619fd562" dependencies = [ "cc", "libc", @@ -574,12 +560,12 @@ dependencies = [ [[package]] name = "derivative" -version = "2.1.1" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb582b60359da160a9477ee80f15c8d784c477e69c217ef2cdd4169c24ea380f" +checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] @@ -635,9 +621,9 @@ checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" [[package]] name = "encoding_rs" -version = "0.8.26" +version = "0.8.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "801bbab217d7f79c0062f4f7205b5d4427c6d1a7bd7aafdd1475f7c59d62b283" +checksum = "80df024fbc5ac80f87dfef0d9f5209a252f2a497f7f42944cff24d8253cac065" dependencies = [ "cfg-if 1.0.0", ] @@ -682,7 +668,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", "synstructure", ] @@ -695,13 +681,13 @@ checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" [[package]] name = "filetime" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c122a393ea57648015bf06fbd3d372378992e86b9ff5a7a497b076a28c79efe" +checksum = "1d34cfa13a63ae058bfa601fe9e313bbdb3746427c1459185464ce0fcf62e1e8" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall", + "redox_syscall 0.2.5", "winapi 0.3.9", ] @@ -740,9 +726,9 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ece68d15c92e84fa4f19d3780f1294e5ca82a78a6d515f1efaabcc144688be00" +checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" dependencies = [ "matches", "percent-encoding", @@ -799,98 +785,51 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -[[package]] -name = "futures" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3b0c040a1fe6529d30b3c5944b280c7f0dcb2930d2c3062bca967b602583d0" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7109687aa4e177ef6fe84553af6280ef2778bdb7783ba44c9dc3399110fe64" +checksum = "8c2dd2df839b57db9ab69c2c9d8f3e8c81984781937fe2807dc6dcf3b2ad2939" dependencies = [ "futures-core", - "futures-sink", ] [[package]] name = "futures-core" -version = "0.3.8" +version = "0.3.13" 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", -] +checksum = "15496a72fabf0e62bdc3df11a59a3787429221dd0710ba8ef163d6f7a9112c94" [[package]] name = "futures-io" -version = "0.3.8" +version = "0.3.13" 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", -] +checksum = "d71c2c65c57704c32f5241c1223167c2c3294fd34ac020c807ddbe6db287ba59" [[package]] name = "futures-sink" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f878195a49cee50e006b02b93cf7e0a95a38ac7b776b4c4d9cc1207cd20fcb3d" +checksum = "85754d98985841b7d4f5e8e6fbfa4a4ac847916893ec511a2917ccd8525b8bb3" [[package]] name = "futures-task" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c554eb5bf48b2426c4771ab68c6b14468b6e76cc90996f528c3338d761a4d0d" -dependencies = [ - "once_cell", -] +checksum = "fa189ef211c15ee602667a6fcfe1c1fd9e07d42250d2156382820fba33c9df80" [[package]] name = "futures-util" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d304cff4a7b99cfb7986f7d43fbe93d175e72e704a8860787cc95e9ffd85cbd2" +checksum = "1812c7ab8aedf8d6f2701a43e1243acdbcc2b36ab26e2ad421eb99ac963d96d1" dependencies = [ - "futures-channel", "futures-core", "futures-io", - "futures-macro", - "futures-sink", "futures-task", "memchr", - "pin-project 1.0.2", + "pin-project-lite", "pin-utils", - "proc-macro-hack", - "proc-macro-nested", "slab", ] @@ -903,19 +842,6 @@ dependencies = [ "byteorder", ] -[[package]] -name = "generator" -version = "0.6.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cdc09201b2e8ca1b19290cf7e65de2246b8e91fb6874279722189c4de7b94dc" -dependencies = [ - "cc", - "libc", - "log", - "rustc_version 0.2.3", - "winapi 0.3.9", -] - [[package]] name = "generic-array" version = "0.12.3" @@ -946,11 +872,11 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc587bc0ec293155d5bfa6b9891ec18a1e330c234f896ea47fbada4cadbe47e6" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "wasi 0.9.0+wasi-snapshot-preview1", ] @@ -963,7 +889,7 @@ checksum = "c9495705279e7140bf035dde1f6e750c162df8b625267cd52cc44e0b156732c8" dependencies = [ "cfg-if 1.0.0", "libc", - "wasi 0.10.0+wasi-snapshot-preview1", + "wasi 0.10.2+wasi-snapshot-preview1", ] [[package]] @@ -984,7 +910,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" dependencies = [ - "bytes 1.0.0", + "bytes", "fnv", "futures-core", "futures-sink", @@ -1000,9 +926,9 @@ dependencies = [ [[package]] name = "half" -version = "1.6.0" +version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d36fab90f82edc3c747f9d438e06cf0a491055896f2a279638bb5beed6c40177" +checksum = "62aca2aba2d62b4a7f5b33f3712cb1b0692779a56fb510499d5c0aa594daeaf3" [[package]] name = "hashbrown" @@ -1021,9 +947,9 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "322f4de77956e22ed0e5032c359a0f1273f1f7f0d79bfa3b8ffbc730d7fbcc5c" dependencies = [ "libc", ] @@ -1036,11 +962,11 @@ checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" [[package]] name = "http" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84129d298a6d57d246960ff8eb831ca4af3f96d29e2e28848dae275408658e26" +checksum = "7245cd7449cc792608c3c8a9eaf69bd4eabbabf802713748fd739c98b82f0747" dependencies = [ - "bytes 0.5.6", + "bytes", "fnv", "itoa", ] @@ -1051,15 +977,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2861bd27ee074e5ee891e8b539837a9430012e249d7f0ca2d795650f579c1994" dependencies = [ - "bytes 1.0.0", + "bytes", "http", ] [[package]] name = "httparse" -version = "1.3.4" +version = "1.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +checksum = "615caabe2c3160b313d52ccc905335f4ed5f10881dd63dc5699d47e90be85691" [[package]] name = "httpdate" @@ -1078,11 +1004,11 @@ dependencies = [ [[package]] name = "hyper" -version = "0.14.2" +version = "0.14.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12219dc884514cb4a6a03737f4413c0e01c23a1b059b0156004b23f1e19dccbe" +checksum = "e8e946c2b1349055e0b72ae281b238baf1a3ea7307c7e9f9d64673bdd9c26ac7" dependencies = [ - "bytes 1.0.0", + "bytes", "futures-channel", "futures-core", "futures-util", @@ -1092,7 +1018,7 @@ dependencies = [ "httparse", "httpdate", "itoa", - "pin-project 1.0.2", + "pin-project", "socket2", "tokio", "tower-service", @@ -1106,7 +1032,7 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" dependencies = [ - "bytes 1.0.0", + "bytes", "hyper", "native-tls", "tokio", @@ -1115,9 +1041,9 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.0" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" +checksum = "89829a5d69c23d348314a7ac337fe39173b61149a9864deabd260983aed48c21" dependencies = [ "matches", "unicode-bidi", @@ -1160,9 +1086,9 @@ dependencies = [ [[package]] name = "inotify-sys" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4563555856585ab3180a5bf0b2f9f8d301a728462afffc8195b3f5394229c55" +checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" dependencies = [ "libc", ] @@ -1220,9 +1146,9 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736" [[package]] name = "jobserver" @@ -1235,26 +1161,13 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf3d7383929f7c9c7c2d0fa596f325832df98c3704f2c60553080f7127a58175" +checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" dependencies = [ "wasm-bindgen", ] -[[package]] -name = "jsonrpc-core" -version = "17.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07569945133257ff557eb37b015497104cea61a2c9edaf126c1cbd6e8332397f" -dependencies = [ - "futures", - "log", - "serde", - "serde_derive", - "serde_json", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -1325,6 +1238,7 @@ dependencies = [ "num-bigint", "pest", "rand", + "rand_core", "rand_xorshift", "serde", "sha2", @@ -1347,6 +1261,7 @@ version = "1.2.2" dependencies = [ "criterion", "rand", + "rand_core", "rand_xorshift", "snarkvm-errors", "snarkvm-models", @@ -1415,7 +1330,7 @@ dependencies = [ "notify", "num-bigint", "rand", - "rand_core 0.6.2", + "rand_core", "reqwest", "rusty-hook", "self_update", @@ -1460,6 +1375,7 @@ dependencies = [ "leo-ast", "leo-input", "rand", + "rand_core", "rand_xorshift", "snarkvm-algorithms", "snarkvm-curves", @@ -1474,9 +1390,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.81" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" [[package]] name = "libloading" @@ -1523,24 +1439,11 @@ dependencies = [ [[package]] name = "log" -version = "0.4.11" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fabed175da42fed1fa0746b0ea71f412aa9d35e76e95e59b192c64b9dc2bf8b" +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710" dependencies = [ - "cfg-if 0.1.10", -] - -[[package]] -name = "loom" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0e8460f2f2121162705187214720353c517b97bdfb3494c0b1e33d83ebe4bed" -dependencies = [ - "cfg-if 0.1.10", - "generator", - "scoped-tls", - "serde", - "serde_json", + "cfg-if 1.0.0", ] [[package]] @@ -1606,9 +1509,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f2d26ec3309788e423cfbf68ad1800f061638098d76a83681af979dc4eda19d" +checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b" dependencies = [ "adler", "autocfg", @@ -1635,9 +1538,9 @@ dependencies = [ [[package]] name = "mio" -version = "0.7.7" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e50ae3f04d169fcc9bde0b547d1c205219b7157e07ded9c5aff03e0637cb3ed7" +checksum = "a5dede4e2065b3842b8b0af444119f3aa331cc7cc2dd20388bfb0f5d5a38823a" dependencies = [ "libc", "log", @@ -1682,9 +1585,9 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.6" +version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fcc7939b5edc4e4f86b1b4a04bb1498afaaf871b1a6691838ed06fcb48d3a3f" +checksum = "b8d96b2e1c8da3957d58100b09f102c6d9cfdfced01b7ec5a8974044bb09dbd4" dependencies = [ "lazy_static", "libc", @@ -1800,15 +1703,15 @@ checksum = "17b02fc0ff9a9e4b35b3342880f48e896ebf69f2967921fe8646bf5b7125956a" [[package]] name = "object" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" -version = "1.5.2" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" +checksum = "10acf907b94fc1b1a152d08ef97e7759650268cf986bf127f387e602b02c7e5a" [[package]] name = "oorandom" @@ -1830,9 +1733,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.31" +version = "0.10.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d008f51b1acffa0d3450a68606e6a51c123012edaacb0f4e1426bd978869187" +checksum = "038d43985d1ddca7a9900630d8cd031b56e4794eecc2e9ea39dd17aa04399a70" dependencies = [ "bitflags", "cfg-if 1.0.0", @@ -1850,9 +1753,9 @@ checksum = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" [[package]] name = "openssl-sys" -version = "0.9.59" +version = "0.9.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de52d8eabd217311538a39bba130d7dea1f1e118010fee7a033d966845e7d5fe" +checksum = "921fc71883267538946025deffb622905ecad223c28efbfdef9bb59a0175f3e6" dependencies = [ "autocfg", "cc", @@ -1874,14 +1777,14 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c6d9b8427445284a09c55be860a15855ab580a417ccad9da88f5a06787ced0" +checksum = "fa7a782938e745763fe6907fc6ba86946d72f49fe7e21de074e08128a99fb018" dependencies = [ "cfg-if 1.0.0", "instant", "libc", - "redox_syscall", + "redox_syscall 0.2.5", "smallvec", "winapi 0.3.9", ] @@ -1939,7 +1842,7 @@ dependencies = [ "pest", "pest_meta", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] @@ -1956,49 +1859,29 @@ dependencies = [ [[package]] name = "pin-project" -version = "0.4.27" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ffbc8e94b38ea3d2d8ba92aea2983b503cd75d0888d75b86bb37970b5698e15" +checksum = "96fa8ebb90271c4477f144354485b8068bd8f6b78b428b01ba892ca26caf0b63" dependencies = [ - "pin-project-internal 0.4.27", -] - -[[package]] -name = "pin-project" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ccc2237c2c489783abd8c4c80e5450fc0e98644555b1364da68cc29aa151ca7" -dependencies = [ - "pin-project-internal 1.0.2", + "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "0.4.27" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65ad2ae56b6abe3a1ee25f15ee605bacadb9a764edaba9c2bf4103800d4a1895" +checksum = "758669ae3558c6f74bd2a18b41f7ac0b5a195aea6639d6a9b5e5d1ad5ba24c0b" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", - "syn 1.0.60", -] - -[[package]] -name = "pin-project-internal" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8e8d2bf0b23038a4424865103a4df472855692821aab4e4f5c3312d461d9e5f" -dependencies = [ - "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "pin-project-lite" -version = "0.2.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b063f57ec186e6140e2b8b6921e5f1bd89c7356dda5b33acc5401203ca6131c" +checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" [[package]] name = "pin-utils" @@ -2063,7 +1946,7 @@ checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" dependencies = [ "proc-macro-error-attr", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", "version_check", ] @@ -2075,22 +1958,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "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" @@ -2135,43 +2006,33 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7" dependencies = [ "proc-macro2 1.0.24", ] [[package]] name = "rand" -version = "0.7.3" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +checksum = "0ef9e7e66b4468674bfcb0c81af8b7fa0bb154fa9f28eb840da5c447baeb8d7e" dependencies = [ - "getrandom 0.1.15", "libc", "rand_chacha", - "rand_core 0.5.1", + "rand_core", "rand_hc", ] [[package]] name = "rand_chacha" -version = "0.2.2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +checksum = "e12735cf05c9e10bf21534da50a147b924d555dc7a547c42e6bb2d5b6017ae0d" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", -] - -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" -dependencies = [ - "getrandom 0.1.15", + "rand_core", ] [[package]] @@ -2179,23 +2040,26 @@ name = "rand_core" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" +dependencies = [ + "getrandom 0.2.2", +] [[package]] name = "rand_hc" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +checksum = "3190ef7066a446f2e7f42e239d161e905420ccab01eb967c9eb27d21b2322a73" dependencies = [ - "rand_core 0.5.1", + "rand_core", ] [[package]] name = "rand_xorshift" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77d416b86801d23dde1aa643023b775c3a462efc0ed96443add11546cdf1dca8" +checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core 0.5.1", + "rand_core", ] [[package]] @@ -2229,22 +2093,31 @@ version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" +[[package]] +name = "redox_syscall" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94341e4e44e24f6b591b59e47a8a027df12e008d73fd5672dbea9cc22f4507d9" +dependencies = [ + "bitflags", +] + [[package]] name = "redox_users" version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de0737333e7a9502c789a36d7c7fa6092a49895d4faa31ca5df163857ded2e9d" dependencies = [ - "getrandom 0.1.15", - "redox_syscall", + "getrandom 0.1.16", + "redox_syscall 0.1.57", "rust-argon2", ] [[package]] name = "regex" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cf2c13ed4745de91a5eb834e11c00bcc3709e773173b2ce4c56c9fbde04b9c" +checksum = "d9251239e129e16308e70d853559389de218ac275b515068abc96829d05b948a" dependencies = [ "aho-corasick", "memchr", @@ -2264,9 +2137,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.21" +version = "0.6.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b181ba2dcf07aaccad5448e8ead58db5b742cf85dfe035e2227f137a539a189" +checksum = "b5eb417147ba9860a96cfe72a0b93bf88fee1744b5636ec99ab20c1aa9376581" [[package]] name = "remove_dir_all" @@ -2284,7 +2157,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0460542b551950620a3648c6aa23318ac6b3cd779114bd873209e6e8b5eb1c34" dependencies = [ "base64", - "bytes 1.0.0", + "bytes", "encoding_rs", "futures-core", "futures-util", @@ -2402,12 +2275,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "scopeguard" version = "1.1.0" @@ -2416,9 +2283,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1759c2e3c8580017a484a7ac56d3abc5a6c1feadf88db2f3633f12ae4268c69" +checksum = "c6af1b6204f89cf0069736daf8b852573e3bc34898eee600e95d3dd855c12e81" dependencies = [ "bitflags", "core-foundation", @@ -2429,9 +2296,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f99b9d5e26d2a71633cc4f2ebae7cc9f874044e0c351a27e17892d76dce5678b" +checksum = "31531d257baab426203cf81c5ce1b0b55159dda7ed602ac81b582ccd62265741" dependencies = [ "core-foundation-sys", "libc", @@ -2470,7 +2337,7 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" dependencies = [ - "semver-parser 0.10.1", + "semver-parser 0.10.2", ] [[package]] @@ -2481,9 +2348,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "semver-parser" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42ef146c2ad5e5f4b037cd6ce2ebb775401729b19a82040c1beac9d36c7d1428" +checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" dependencies = [ "pest", ] @@ -2514,7 +2381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9391c295d64fc0abb2c556bad848f33cb8296276b1ad2677d1ae1ace4f258f31" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] @@ -2568,12 +2435,11 @@ dependencies = [ [[package]] name = "sharded-slab" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b4921be914e16899a80adefb821f8ddb7974e3f1250223575a44ed994882127" +checksum = "79c719719ee05df97490f80a45acfc99e5a30ce98a1e4fb67aee422745ae14e3" dependencies = [ "lazy_static", - "loom", ] [[package]] @@ -2605,13 +2471,13 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "snarkvm-algorithms" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d13ddcfa5b127d425986460cd28c79f55fdc1c80fe167ed6e51ce8729bdc3e9" +checksum = "739c2aaf5dbf6322d3a40bbb9739a87d458f32460da1b8affeae45214ec88e8c" dependencies = [ "blake2", "derivative", - "digest 0.8.1", + "digest 0.9.0", "itertools 0.10.0", "rand", "rand_chacha", @@ -2626,9 +2492,9 @@ dependencies = [ [[package]] name = "snarkvm-curves" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0903eb67aa8b74475755ccfa56065ba53cca2c1220c9c509be82e5feb320f36" +checksum = "5c39148bec803c5e41b0696326a60817d9b84c4c2c1df6ea5be56f857b078988" dependencies = [ "derivative", "rand", @@ -2642,22 +2508,22 @@ dependencies = [ [[package]] name = "snarkvm-derives" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91bf0426e73d23e5ee17f20da28f00e8520736f4613c14aa796162a607823d23" +checksum = "24c5c4170d43a65e23bce115d6d2940c7fc66e1562a7822dd460db56f1fb07b1" dependencies = [ "proc-macro-crate", "proc-macro-error", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "snarkvm-dpc" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff878d1c7de705cf0fe63abca97661830b57bc68b067fe4ae44c4d6acd8edd8f" +checksum = "e3feb5d2cec547779e0acec01cd58f5d5fe6aac60cc4804e5e3cf9c807bb1880" dependencies = [ "anyhow", "blake2", @@ -2678,29 +2544,26 @@ dependencies = [ [[package]] name = "snarkvm-errors" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a05d620a0ffff945800ab2ef231631a02bed1f7b3e6d962aeea993779892be4f" +checksum = "2cfe9f6fac097aed079fa68a63c8989783b2cf21705de75bc91672dec60c9684" dependencies = [ "base58", "bech32", "bincode", "curl", "hex", - "jsonrpc-core", - "rocksdb", "thiserror", - "toml", ] [[package]] name = "snarkvm-gadgets" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc86cb000059c6038d48f6618915100a7b2ca2c2e1ee29232a5831de1fc0caf1" +checksum = "978bcc75bce7a1274f51b2adc4d69c30d866930aa37c656b4b8c1be5d631891c" dependencies = [ "derivative", - "digest 0.8.1", + "digest 0.9.0", "itertools 0.10.0", "snarkvm-algorithms", "snarkvm-curves", @@ -2711,9 +2574,9 @@ dependencies = [ [[package]] name = "snarkvm-models" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1020532f62f262ce5a0debc60b3fd11088e69b81ce3583cfd53a6bb7fde49094" +checksum = "2c8da5920c6f4062c0d348e93ff0f72d17681c34f3c13ee4e99196495d896ed9" dependencies = [ "anyhow", "bincode", @@ -2731,9 +2594,9 @@ dependencies = [ [[package]] name = "snarkvm-objects" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ec339886c4270f8dbc737b3268521ab3702188fbd5246ed2bbfab6fa029a10e" +checksum = "4641e23002d38caeb51fa3244320355cab07eaf22d17dc44b481c763b63b5f4d" dependencies = [ "base58", "bech32", @@ -2753,9 +2616,9 @@ dependencies = [ [[package]] name = "snarkvm-parameters" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d920ae9aff766409ff4222da7121bc7edf44a76460ea07b8ca070c3aa73efd" +checksum = "8cb0f27fbccad7dee0ad4c2e5aeb0832c393fec76b4ad5d834c2e6cc0297e9a9" dependencies = [ "curl", "hex", @@ -2767,15 +2630,15 @@ dependencies = [ [[package]] name = "snarkvm-profiler" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acd1cc18cc2c34eb1229481218862fddc5e03df217ab23e6494459f7c483c0a1" +checksum = "3fb5e9b964cb9653588607d8793bc7d6d0dfa78763a02d61aa3daa6c7d665e2b" [[package]] name = "snarkvm-storage" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1768bcc70e02813149b3b1d3e7215d9c45b3fb4245fb478ea6496081df49a3ff" +checksum = "3ef134de5e33fe0577f3936e9dcf9bfac1973a0d820390e19558672808bad6b9" dependencies = [ "anyhow", "bincode", @@ -2795,9 +2658,9 @@ dependencies = [ [[package]] name = "snarkvm-utilities" -version = "0.0.4" +version = "0.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bce6e8fc5be0967a1b1d16a0c87b3ff8f9920089efe7541304b562a118f8ae4a" +checksum = "872c2ee1675c5039caf8cb4c5ef37b0ad844ffe7e0d81b68fb39f713da199561" dependencies = [ "bincode", "rand", @@ -2807,9 +2670,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.3.18" +version = "0.3.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97e0e9fd577458a4f61fb91fcb559ea2afecc54c934119421f9f5d3d5b1a1057" +checksum = "122e570113d28d773067fab24266b66753f6ea915758651696b6e35e49f88d6e" dependencies = [ "cfg-if 1.0.0", "libc", @@ -2842,15 +2705,15 @@ dependencies = [ "heck", "proc-macro-error", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "subtle" -version = "1.0.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" +checksum = "1e81da0851ada1f3e9d4312c704aa4f8806f0f9d69faaf8df2f3464b4a9437c2" [[package]] name = "syn" @@ -2870,7 +2733,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c700597eca8a5a762beb35753ef6b94df201c81cca676604f547495a0d7f0081" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "unicode-xid 0.2.1", ] @@ -2881,21 +2744,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b834f2d66f734cb897113e34aaff2f1ab4719ca946f9a7358dba8f8064148701" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", "unicode-xid 0.2.1", ] [[package]] name = "tempfile" -version = "3.1.0" +version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" +checksum = "dac1c663cfc93810f88aed9b8941d48cabf856a1b111c29a40439018d870eb22" dependencies = [ - "cfg-if 0.1.10", + "cfg-if 1.0.0", "libc", "rand", - "redox_syscall", + "redox_syscall 0.2.5", "remove_dir_all", "winapi 0.3.9", ] @@ -2911,9 +2774,9 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.1.15" +version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bd2d183bd3fac5f5fe38ddbeb4dc9aec4a39a9d7d59e7491d900302da01cbe1" +checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406" dependencies = [ "libc", "winapi 0.3.9", @@ -2944,35 +2807,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7765189610d8241a44529806d6fd1f2e0a08734313a35d5b3a556f92b381f3c0" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] [[package]] name = "thread_local" -version = "1.0.1" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14" +checksum = "8018d24e04c95ac8790716a5987d0fec4f8b27249ffa0f7d33f1369bdfb88cbd" dependencies = [ - "lazy_static", + "once_cell", ] [[package]] name = "time" -version = "0.1.44" +version = "0.1.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255" +checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" dependencies = [ "libc", - "wasi 0.10.0+wasi-snapshot-preview1", "winapi 0.3.9", ] [[package]] name = "tinytemplate" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d3dc76004a03cec1c5932bca4cdc2e39aaa798e3f82363dd94f9adf6098c12f" +checksum = "a2ada8616fad06a2d0c455adc530de4ef57605a8120cc65da9653e0e9623ca74" dependencies = [ "serde", "serde_json", @@ -2980,9 +2842,9 @@ dependencies = [ [[package]] name = "tinyvec" -version = "1.1.0" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf8dbc19eb42fba10e8feaaec282fb50e2c14b2726d6301dbfeed0f73306a6f" +checksum = "317cca572a0e89c3ce0ca1f1bdc9369547fe318a683418e42ac8f59d14701023" dependencies = [ "tinyvec_macros", ] @@ -2995,15 +2857,15 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.0.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d258221f566b6c803c7b4714abadc080172b272090cdc5e244a6d4dd13c3a6bd" +checksum = "e8190d04c665ea9e6b6a0dc45523ade572c088d2e6566244c1122671dbf4ae3a" dependencies = [ "autocfg", - "bytes 1.0.0", + "bytes", "libc", "memchr", - "mio 0.7.7", + "mio 0.7.9", "num_cpus", "pin-project-lite", ] @@ -3018,30 +2880,18 @@ dependencies = [ "tokio", ] -[[package]] -name = "tokio-stream" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4cdeb73537e63f98adcd73138af75e3f368ccaecffaa29d7eb61b9f5a440457" -dependencies = [ - "futures-core", - "pin-project-lite", - "tokio", -] - [[package]] name = "tokio-util" -version = "0.6.0" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36135b7e7da911f5f8b9331209f7fab4cc13498f3fff52f72a710c78187e3148" +checksum = "ebb7cb2f00c5ae8df755b252306272cd1790d39728363936e01827e11f0b017b" dependencies = [ - "bytes 1.0.0", + "bytes", "futures-core", "futures-sink", "log", "pin-project-lite", "tokio", - "tokio-stream", ] [[package]] @@ -3055,9 +2905,9 @@ dependencies = [ [[package]] name = "tower-service" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e987b6bf443f4b5b3b6f38704195592cca41c5bb7aedd3c3693c7081f8289860" +checksum = "360dfd1d6d30e05fda32ace2c8c70e9c0a9da713275777f5a4dbb8a1893930c6" [[package]] name = "tracing" @@ -3078,7 +2928,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8a9bd1db7706f2373a190b0d067146caa39350c486f3d455b0e33b431f94c07" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", ] @@ -3093,11 +2943,11 @@ dependencies = [ [[package]] name = "tracing-futures" -version = "0.2.4" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab7bb6f14721aa00656086e9335d363c5c8747bae02ebe32ea2c7dece5689b4c" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" dependencies = [ - "pin-project 0.4.27", + "pin-project", "tracing", ] @@ -3188,9 +3038,9 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.16" +version = "0.1.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a13e63ab62dbe32aeee58d1c5408d35c36c392bba5d9d3142287219721afe606" +checksum = "07fbfce1c8a97d547e8b5334978438d9d6ec8c20e38f56d4a4374d181493eaef" dependencies = [ "tinyvec", ] @@ -3221,9 +3071,9 @@ checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" [[package]] name = "url" -version = "2.2.0" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5909f2b0817350449ed73e8bcd81c8c3c8d9a7a5d8acba4b27db277f1868976e" +checksum = "9ccd964113622c8e9322cfac19eb1004a07e636c545f325da085d5cdde6f1f8b" dependencies = [ "form_urlencoded", "idna", @@ -3294,15 +3144,15 @@ checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" [[package]] name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" +version = "0.10.2+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cd364751395ca0f68cafb17666eee36b63077fb5ecd972bbcd74c90c4bf736e" +checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" dependencies = [ "cfg-if 1.0.0", "serde", @@ -3312,24 +3162,24 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1114f89ab1f4106e5b55e688b828c0ab0ea593a1ea7c094b141b14cbaaec2d62" +checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" dependencies = [ "bumpalo", "lazy_static", "log", "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.19" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1fe9756085a84584ee9457a002b7cdfe0bfff169f45d2591d8be1345a6780e35" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3339,22 +3189,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6ac8995ead1f084a8dea1e65f194d0973800c7f571f6edd70adf06ecf77084" +checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" dependencies = [ - "quote 1.0.7", + "quote 1.0.9", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5a48c72f299d80557c7c62e37e7225369ecc0c963964059509fbafe917c7549" +checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" dependencies = [ "proc-macro2 1.0.24", - "quote 1.0.7", + "quote 1.0.9", "syn 1.0.60", "wasm-bindgen-backend", "wasm-bindgen-shared", @@ -3362,15 +3212,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.69" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e7811dd7f9398f14cc76efd356f98f03aa30419dea46aa810d71e819fc97158" +checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" [[package]] name = "web-sys" -version = "0.3.46" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222b1ef9334f92a21d3fb53dc3fd80f30836959a90f9274a626d7e06315ba3c3" +checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/Cargo.toml b/Cargo.toml index 51323712b8..86f7d2f5b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,27 +67,27 @@ path = "./state" version = "1.2.2" [dependencies.snarkvm-algorithms] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-curves] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-errors] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-models] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.4" +version = "0.0.5" [dependencies.anyhow] version = "1.0" @@ -120,7 +120,7 @@ version = "4.0.15" version = "0.3" [dependencies.rand] -version = "0.7" +version = "0.8" [dependencies.rand_core] version = "0.6.2" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index f4987c9ab4..0a2b113124 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -50,31 +50,31 @@ path = "../asg" version = "1.2.2" [dependencies.snarkvm-curves] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-errors] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-models] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-objects] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.4" +version = "0.0.5" [dependencies.bincode] version = "1.3" @@ -90,11 +90,7 @@ features = [ "serde-1" ] version = "2.0" [dependencies.rand] -version = "0.7" - -[dependencies.rand_xorshift] -version = "0.2" -default-features = false +version = "0.8" [dependencies.serde] version = "1.0" @@ -115,8 +111,15 @@ features = [ "v4", "serde" ] [dev-dependencies.num-bigint] version = "0.3" +[dev-dependencies.rand_core] +version = "0.6.2" + +[dev-dependencies.rand_xorshift] +version = "0.3" +default-features = false + [dev-dependencies.snarkvm-algorithms] -version = "0.0.4" +version = "0.0.5" default-features = false [features] diff --git a/compiler/tests/core/packages/unstable/blake2s/mod.rs b/compiler/tests/core/packages/unstable/blake2s/mod.rs index b989fc5f6e..98bffe41e2 100644 --- a/compiler/tests/core/packages/unstable/blake2s/mod.rs +++ b/compiler/tests/core/packages/unstable/blake2s/mod.rs @@ -25,7 +25,8 @@ use crate::{ use leo_ast::InputValue; use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType}; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use snarkvm_algorithms::prf::blake2s::Blake2s as B2SPRF; use snarkvm_models::algorithms::PRF; diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index 46bef4eaf6..a3e3d627f9 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -18,22 +18,22 @@ license = "GPL-3.0" edition = "2018" [dependencies.snarkvm-errors] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-models] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.4" +version = "0.0.5" [dependencies.rand] -version = "0.7" +version = "0.8" default-features = false [dependencies.rand_xorshift] -version = "0.2" +version = "0.3" default-features = false [dependencies.thiserror] @@ -42,6 +42,9 @@ version = "1.0" [dev-dependencies.criterion] version = "0.3" +[dev-dependencies.rand_core] +version = "0.6.2" + [[bench]] name = "integer_arithmetic" path = "benches/integer_arithmetic.rs" diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index c1eb5d0436..d9d29a5e2d 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -24,7 +24,8 @@ use snarkvm_models::{ }, }; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use std::i128; @@ -238,8 +239,8 @@ fn test_int128_mul_constants() { let max = i64::MAX as i128; let min = i64::MIN as i128; - let a: i128 = rng.gen_range(min, max); - let b: i128 = rng.gen_range(min, max); + let a: i128 = rng.gen_range(min..max); + let b: i128 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -267,8 +268,8 @@ fn test_int128_mul() { let max = i64::MAX as i128; let min = i64::MIN as i128; - let a: i128 = rng.gen_range(min, max); - let b: i128 = rng.gen_range(min, max); + let a: i128 = rng.gen_range(min..max); + let b: i128 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index 9b1d862f3f..ff2341554a 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -24,7 +24,8 @@ use snarkvm_models::{ }, }; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use std::i16; @@ -238,8 +239,8 @@ fn test_int16_mul_constants() { let max = i8::MAX as i16; let min = i8::MIN as i16; - let a: i16 = rng.gen_range(min, max); - let b: i16 = rng.gen_range(min, max); + let a: i16 = rng.gen_range(min..max); + let b: i16 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -267,8 +268,8 @@ fn test_int16_mul() { let max = i8::MAX as i16; let min = i8::MIN as i16; - let a: i16 = rng.gen_range(min, max); - let b: i16 = rng.gen_range(min, max); + let a: i16 = rng.gen_range(min..max); + let b: i16 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -366,8 +367,8 @@ fn test_int16_pow_constants() { for _ in 0..10 { let mut cs = TestConstraintSystem::::new(); - let a: i16 = rng.gen_range(-16, 16); - let b: i16 = rng.gen_range(-4, 4); + let a: i16 = rng.gen_range(-16..16); + let b: i16 = rng.gen_range(-4..4); let expected = match a.checked_pow(b as u32) { Some(valid) => valid, @@ -392,8 +393,8 @@ fn test_int16_pow() { for _ in 0..3 { let mut cs = TestConstraintSystem::::new(); - let a: i16 = rng.gen_range(-16, 16); - let b: i16 = rng.gen_range(-4, 4); + let a: i16 = rng.gen_range(-16..16); + let b: i16 = rng.gen_range(-4..4); let expected = match a.checked_pow(b as u32) { Some(valid) => valid, diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index c7dd61b035..6407301654 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -24,7 +24,8 @@ use snarkvm_models::{ }, }; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use std::i32; @@ -238,8 +239,8 @@ fn test_int32_mul_constants() { let max = i16::MAX as i32; let min = i16::MIN as i32; - let a: i32 = rng.gen_range(min, max); - let b: i32 = rng.gen_range(min, max); + let a: i32 = rng.gen_range(min..max); + let b: i32 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -267,8 +268,8 @@ fn test_int32_mul() { let max = i16::MAX as i32; let min = i16::MIN as i32; - let a: i32 = rng.gen_range(min, max); - let b: i32 = rng.gen_range(min, max); + let a: i32 = rng.gen_range(min..max); + let b: i32 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -367,8 +368,8 @@ fn test_int32_pow_constants() { for _ in 0..3 { let mut cs = TestConstraintSystem::::new(); - let a: i32 = rng.gen_range(-16, 16); - let b: i32 = rng.gen_range(-8, 8); + let a: i32 = rng.gen_range(-16..16); + let b: i32 = rng.gen_range(-8..8); let expected = match a.checked_pow(b as u32) { Some(valid) => valid, @@ -394,8 +395,8 @@ fn test_int32_pow() { for _ in 0..3 { let mut cs = TestConstraintSystem::::new(); - let a: i32 = rng.gen_range(-16, 16); - let b: i32 = rng.gen_range(-8, 8); + let a: i32 = rng.gen_range(-16..16); + let b: i32 = rng.gen_range(-8..8); let expected = match a.checked_pow(b as u32) { Some(valid) => valid, diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 6405cc1866..03259c7ece 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -24,7 +24,8 @@ use snarkvm_models::{ }, }; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use std::i64; @@ -238,8 +239,8 @@ fn test_int64_mul_constants() { let max = i32::MAX as i64; let min = i32::MIN as i64; - let a: i64 = rng.gen_range(min, max); - let b: i64 = rng.gen_range(min, max); + let a: i64 = rng.gen_range(min..max); + let b: i64 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -267,8 +268,8 @@ fn test_int64_mul() { let max = i32::MAX as i64; let min = i32::MIN as i64; - let a: i64 = rng.gen_range(min, max); - let b: i64 = rng.gen_range(min, max); + let a: i64 = rng.gen_range(min..max); + let b: i64 = rng.gen_range(min..max); let expected = match a.checked_mul(b) { Some(valid) => valid, @@ -366,8 +367,8 @@ fn test_int64_pow_constants() { let mut cs = TestConstraintSystem::::new(); - let a: i64 = rng.gen_range(-16, 16); - let b: i64 = rng.gen_range(-12, 12); + let a: i64 = rng.gen_range(-16..16); + let b: i64 = rng.gen_range(-12..12); let expected = a.checked_pow(b as u32).unwrap(); @@ -388,8 +389,8 @@ fn test_int64_pow() { let mut cs = TestConstraintSystem::::new(); - let a: i64 = rng.gen_range(-16, 16); - let b: i64 = rng.gen_range(-12, 12); + let a: i64 = rng.gen_range(-16..16); + let b: i64 = rng.gen_range(-12..12); let expected = a.checked_pow(b as u32).unwrap(); diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index ef4cc707b4..d9d3923410 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -24,7 +24,8 @@ use snarkvm_models::{ }, }; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use std::i8; @@ -360,8 +361,8 @@ fn test_int8_pow_constants() { for _ in 0..100 { let mut cs = TestConstraintSystem::::new(); - let a: i8 = rng.gen_range(-4, 4); - let b: i8 = rng.gen_range(-4, 4); + let a: i8 = rng.gen_range(-4..4); + let b: i8 = rng.gen_range(-4..4); let expected = match a.checked_pow(b as u32) { Some(valid) => valid, @@ -386,8 +387,8 @@ fn test_int8_pow() { for _ in 0..10 { let mut cs = TestConstraintSystem::::new(); - let a: i8 = rng.gen_range(-4, 4); - let b: i8 = rng.gen_range(-4, 4); + let a: i8 = rng.gen_range(-4..4); + let b: i8 = rng.gen_range(-4..4); let expected = match a.checked_pow(b as u32) { Some(valid) => valid, diff --git a/state/Cargo.toml b/state/Cargo.toml index 5b002c1f8d..a81375903b 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -26,44 +26,47 @@ path = "../ast" version = "1.2.2" [dependencies.snarkvm-algorithms] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-curves] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-errors] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-models] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-objects] -version = "0.0.4" +version = "0.0.5" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.4" +version = "0.0.5" [dependencies.indexmap] version = "1.6.1" features = [ "serde-1" ] [dependencies.rand] -version = "0.7" +version = "0.8" [dependencies.rand_xorshift] -version = "0.2" +version = "0.3" [dependencies.thiserror] version = "1.0" [dev-dependencies.snarkvm-storage] -version = "0.0.4" +version = "0.0.5" + +[dev-dependencies.rand_core] +version = "0.6.2" diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index db5562c418..bf43267337 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -27,7 +27,8 @@ use snarkvm_models::{ use snarkvm_objects::Account; use snarkvm_utilities::{bytes::ToBytes, to_bytes}; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use snarkvm_models::dpc::DPCScheme; use snarkvm_storage::Ledger; diff --git a/state/tests/test_verify_record_commitment.rs b/state/tests/test_verify_record_commitment.rs index 3cc2a736cb..1871e71859 100644 --- a/state/tests/test_verify_record_commitment.rs +++ b/state/tests/test_verify_record_commitment.rs @@ -20,7 +20,7 @@ use leo_state::verify_record_commitment; use snarkvm_dpc::base_dpc::instantiated::*; -use rand::SeedableRng; +use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; // TODO (Collin): Update input to reflect new parameter ordering. From 4fc5f3f30ca0f5f51d3ce8c2df42b97fd0a7858c Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 09:29:50 -0800 Subject: [PATCH 11/92] Adds 'leo clone' command --- .circleci/leo-publish.sh | 4 + leo/commands/package/add.rs | 31 ++++--- leo/commands/package/clone.rs | 160 ++++++++++++++++++++++++++++++++++ leo/commands/package/mod.rs | 3 + leo/main.rs | 11 ++- 5 files changed, 191 insertions(+), 18 deletions(-) create mode 100755 .circleci/leo-publish.sh create mode 100644 leo/commands/package/clone.rs diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh new file mode 100755 index 0000000000..ab7724cd4a --- /dev/null +++ b/.circleci/leo-publish.sh @@ -0,0 +1,4 @@ +mkdir hello-world && cd hello-world || exit 1 +$LEO init +ls -la +$LEO run diff --git a/leo/commands/package/add.rs b/leo/commands/package/add.rs index 0b97c67bb4..d70f7be8b1 100644 --- a/leo/commands/package/add.rs +++ b/leo/commands/package/add.rs @@ -25,7 +25,7 @@ use std::{ use structopt::StructOpt; use tracing::Span; -/// Add package from Aleo Package Manager +/// Add a package from Aleo Package Manager #[derive(StructOpt, Debug)] #[structopt(setting = structopt::clap::AppSettings::ColoredHelp)] pub struct Add { @@ -58,7 +58,7 @@ impl Add { } /// Try to parse author/package string from self.remote - pub fn try_read_arguments(&self) -> Result<(String, String)> { + fn try_read_arguments(&self) -> Result<(String, String)> { if let Some(val) = &self.remote { let v: Vec<&str> = val.split('/').collect(); if v.len() == 2 { @@ -91,42 +91,41 @@ impl Command for Add { } fn apply(self, context: Context, _: Self::Input) -> Result { - // checking that manifest exists... + // Check that a manifest exists for the current package. if context.manifest().is_err() { - return Err(anyhow!("Package Manifest not found, try running leo init or leo new")); + return Err(anyhow!("Package manifest not found, try running `leo init`")); }; let (author, package_name) = match self.try_read_arguments() { Ok((author, package)) => (author, package), Err(err) => return Err(err), }; - let version = self.version; - // build request body (Options are skipped when sealizing) - let fetch = Fetch { - author, - package_name: package_name.clone(), - version, + // Attempt to fetch the package. + let reader = { + let fetch = Fetch { + author, + package_name: package_name.clone(), + version: self.version, + }; + let bytes = context.api.run_route(fetch)?.bytes()?; + std::io::Cursor::new(bytes) }; - let bytes = context.api.run_route(fetch)?.bytes()?; + // Construct the directory structure. let mut path = context.dir()?; - { - // setup directory structure since request was success ImportsDirectory::create(&path)?; path.push(IMPORTS_DIRECTORY_NAME); path.push(package_name); create_dir_all(&path)?; }; - let reader = std::io::Cursor::new(bytes); - + // Proceed to unzip and parse the fetched bytes. let mut zip_archive = match zip::ZipArchive::new(reader) { Ok(zip) => zip, Err(error) => return Err(anyhow!(error)), }; - for i in 0..zip_archive.len() { let file = match zip_archive.by_index(i) { Ok(file) => file, diff --git a/leo/commands/package/clone.rs b/leo/commands/package/clone.rs new file mode 100644 index 0000000000..37d829aaf4 --- /dev/null +++ b/leo/commands/package/clone.rs @@ -0,0 +1,160 @@ +// 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::{api::Fetch, commands::Command, context::Context}; + +use anyhow::{anyhow, Result}; +use std::{ + borrow::Cow, + fs::{self, File}, + io::{Read, Write}, + path::Path, +}; +use structopt::StructOpt; +use tracing::Span; + +/// Clone a package from Aleo Package Manager +#[derive(StructOpt, Debug)] +#[structopt(setting = structopt::clap::AppSettings::ColoredHelp)] +pub struct Clone { + #[structopt(name = "REMOTE")] + remote: Option, + + #[structopt(name = "author", help = "Specify a package author", long = "author", short = "a")] + author: Option, + + #[structopt(name = "package", help = "Specify a package name", long = "package", short = "p")] + package: Option, + + #[structopt(name = "version", help = "Specify a package version", long = "version", short = "v")] + version: Option, +} + +impl Clone { + pub fn new( + remote: Option, + author: Option, + package: Option, + version: Option, + ) -> Self { + Self { + remote, + author, + package, + version, + } + } + + /// Try to parse author/package string from self.remote + fn try_read_arguments(&self) -> Result<(String, String)> { + if let Some(val) = &self.remote { + let v: Vec<&str> = val.split('/').collect(); + if v.len() == 2 { + Ok((v[0].to_string(), v[1].to_string())) + } else { + Err(anyhow!( + "Incorrect argument, please use --help for information on command use" + )) + } + } else if let (Some(author), Some(package)) = (&self.author, &self.package) { + Ok((author.clone(), package.clone())) + } else { + Err(anyhow!( + "Incorrect argument, please use --help for information on command use" + )) + } + } + + /// Creates a directory at the provided path with the given directory name. + fn create_directory(path: &Path, directory_name: &str) -> Result<()> { + let mut path = Cow::from(path); + + // Check that the path ends in the directory name. + // If it does not, proceed to append the directory name to the path. + if path.is_dir() && !path.ends_with(directory_name) { + path.to_mut().push(directory_name); + } + + Ok(fs::create_dir_all(&path)?) + } +} + +impl Command for Clone { + type Input = (); + type Output = (); + + fn log_span(&self) -> Span { + tracing::span!(tracing::Level::INFO, "Cloning") + } + + fn prelude(&self) -> Result { + Ok(()) + } + + fn apply(self, context: Context, _: Self::Input) -> Result { + let (author, package_name) = match self.try_read_arguments() { + Ok((author, package)) => (author, package), + Err(err) => return Err(err), + }; + + // Attempt to fetch the package. + let reader = { + let fetch = Fetch { + author, + package_name: package_name.clone(), + version: self.version, + }; + let bytes = context.api.run_route(fetch)?.bytes()?; + std::io::Cursor::new(bytes) + }; + + // Construct the directory structure. + let mut path = context.dir()?; + path.push(package_name.clone()); + Self::create_directory(&path, &package_name)?; + + // Proceed to unzip and parse the fetched bytes. + let mut zip_archive = match zip::ZipArchive::new(reader) { + Ok(zip) => zip, + Err(error) => return Err(anyhow!(error)), + }; + for i in 0..zip_archive.len() { + let file = match zip_archive.by_index(i) { + Ok(file) => file, + Err(error) => return Err(anyhow!(error)), + }; + + let file_name = file.name(); + + let mut file_path = path.clone(); + file_path.push(file_name); + + if file_name.ends_with('/') { + fs::create_dir_all(file_path)?; + } else { + if let Some(parent_directory) = path.parent() { + fs::create_dir_all(parent_directory)?; + } + + File::create(file_path)?.write_all(&file.bytes().map(|e| e.unwrap()).collect::>())?; + } + } + + tracing::info!("Successfully cloned {}", package_name); + + Ok(()) + } +} diff --git a/leo/commands/package/mod.rs b/leo/commands/package/mod.rs index f3b292715f..ce8c637f59 100644 --- a/leo/commands/package/mod.rs +++ b/leo/commands/package/mod.rs @@ -17,6 +17,9 @@ pub mod add; pub use add::Add; +pub mod clone; +pub use clone::Clone; + pub mod login; pub use login::Login; diff --git a/leo/main.rs b/leo/main.rs index 6fe3cf92ac..f42cd412f6 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -23,7 +23,7 @@ pub mod synthesizer; pub mod updater; use commands::{ - package::{Add, Login, Logout, Publish, Remove}, + package::{Add, Clone, Login, Logout, Publish, Remove}, Build, Clean, Command, @@ -121,12 +121,18 @@ enum CommandOpts { command: Test, }, - #[structopt(about = "Install a package from the Aleo Package Manager")] + #[structopt(about = "Import a package from the Aleo Package Manager")] Add { #[structopt(flatten)] command: Add, }, + #[structopt(about = "Clone a package from the Aleo Package Manager")] + Clone { + #[structopt(flatten)] + command: Clone, + }, + #[structopt(about = "Login to the Aleo Package Manager")] Login { #[structopt(flatten)] @@ -189,6 +195,7 @@ fn main() { CommandOpts::Update { command } => command.try_execute(), CommandOpts::Add { command } => command.try_execute(), + CommandOpts::Clone { command } => command.try_execute(), CommandOpts::Login { command } => command.try_execute(), CommandOpts::Logout { command } => command.try_execute(), CommandOpts::Publish { command } => command.try_execute(), From dd4ee7dd9ad215cfd2c8ddece1c15bac93a22efa Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 09:34:06 -0800 Subject: [PATCH 12/92] Add leo clone and publish for circleci --- .circleci/config.yml | 31 ++++++++++++++++++++++++++++++- .circleci/leo-clone.sh | 16 ++++++++++++++++ .circleci/leo-publish.sh | 15 +++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100755 .circleci/leo-clone.sh diff --git a/.circleci/config.yml b/.circleci/config.yml index d758e2dadd..b40a1e33df 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -138,6 +138,32 @@ jobs: export LEO=/home/circleci/project/project/bin/leo ./project/.circleci/leo-login-logout.sh + leo-clone: + docker: + - image: cimg/rust:1.50.0 + resource_class: xlarge + steps: + - attach_workspace: + at: /home/circleci/project/ + - run: + name: leo clone + command: | + export LEO=/home/circleci/project/project/bin/leo + ./project/.circleci/leo-clone.sh + + leo-publish: + docker: + - image: cimg/rust:1.50.0 + resource_class: xlarge + steps: + - attach_workspace: + at: /home/circleci/project/ + - run: + name: leo publish + command: | + export LEO=/home/circleci/project/project/bin/leo + ./project/.circleci/leo-publish.sh + workflows: version: 2 main-workflow: @@ -160,4 +186,7 @@ workflows: - rust-stable - leo-login-logout: requires: - - rust-stable \ No newline at end of file + - rust-stable + - leo-publish: + requires: + - rust-stable diff --git a/.circleci/leo-clone.sh b/.circleci/leo-clone.sh new file mode 100755 index 0000000000..2374663137 --- /dev/null +++ b/.circleci/leo-clone.sh @@ -0,0 +1,16 @@ +# leo clone + +$LEO clone leobot/test-app + +# Assert that the 'test-app' folder is not empty + +cd test-app || exit 1 +if [ "$(ls -A $DIR)" ]; then + echo "$DIR is not empty" +else + echo "$DIR is empty" + exit 1 +fi + +ls -la +$LEO run diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index ab7724cd4a..99f4b1bd61 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -1,4 +1,19 @@ +# leo login, publish and logout + +$LEO new test-app && cd test-app +$LEO login -u "ALEO_PM_USERNAME" -p "ALEO_PM_PASSWORD" + +# sed command below takes 0.1.0 version (which is default for new programs) +# and replaces it with GITHUB_RUN_ID - a unique incremental number for each +# GH Actions run; [AUTHOR] gets replaced with $USER variable; and we're ready +# to publish package with newer version and correct author +cat Leo.toml | sed "s/0.1.0/0.1.$GITHUB_RUN_ID/g" | sed "s/\[AUTHOR\]/$USER/g" > Leo.toml + +$LEO publish +$LEO logout + mkdir hello-world && cd hello-world || exit 1 $LEO init ls -la $LEO run + From 52ff071ad371bdbda7ac8499c7037f7ecdb3aaef Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 09:57:22 -0800 Subject: [PATCH 13/92] Update leo-publish CI --- .circleci/leo-publish.sh | 56 +++++++++++++++++++++++++++++++--------- 1 file changed, 44 insertions(+), 12 deletions(-) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index 99f4b1bd61..ac0bd0246a 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -1,19 +1,51 @@ # leo login, publish and logout -$LEO new test-app && cd test-app +# Login $LEO login -u "ALEO_PM_USERNAME" -p "ALEO_PM_PASSWORD" -# sed command below takes 0.1.0 version (which is default for new programs) -# and replaces it with GITHUB_RUN_ID - a unique incremental number for each -# GH Actions run; [AUTHOR] gets replaced with $USER variable; and we're ready -# to publish package with newer version and correct author -cat Leo.toml | sed "s/0.1.0/0.1.$GITHUB_RUN_ID/g" | sed "s/\[AUTHOR\]/$USER/g" > Leo.toml +# Clone the test-app package. +$LEO clone test-app +# Fetch the current Leo package version number. +# +# 1. Print out the Leo.toml file. +# 2. Search for a line with the word "version". +# 3. Isolate that into a single line. +# 4. Split the line from the '=' sign and keep the right-hand side. +# 5. Remove the quotes around the version number. +# 6. Trim any excess whitespace. +export CURRENT=$(cat Leo.toml \ +| grep version \ +| head -1 \ +| awk -F= '{ print $2 }' \ +| sed 's/[",]//g' \ +| xargs) + +# Increment the current Leo package version number by 1. +# +# 1. Print out the Leo.toml file. +# 2. Search for a line with the word "version". +# 3. Isolate that into a single line. +# 4. Split the line from the '=' sign and keep the right-hand side. +# 5. Remove the quotes around the version number. +# 6. Trim any excess whitespace. +# 7. Increment the version number by 1 (on the semver patch). +# +# https://stackoverflow.com/questions/8653126/how-to-increment-version-number-in-a-shell-script +export UPDATED=$(cat Leo.toml \ +| grep version \ +| head -1 \ +| awk -F= '{ print $2 }' \ +| sed 's/[",]//g' \ +| xargs \ +| awk -F. -v OFS=. 'NF==1{print ++$NF}; NF>1{if(length($NF+1)>length($NF))$(NF-1)++; $NF=sprintf("%0*d", length($NF), ($NF+1)%(10^length($NF))); print}') + +# Write the updated Leo package version number to the Leo.toml file. +export TOML=$(cat Leo.toml | sed "s/$CURRENT/$UPDATED/g") +echo $TOML > Leo.toml + +# Publish the package to Aleo.pm $LEO publish + +# Logout $LEO logout - -mkdir hello-world && cd hello-world || exit 1 -$LEO init -ls -la -$LEO run - From 23a460479423d5a7acc4b82d8b0f8b3e2197affa Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 09:58:25 -0800 Subject: [PATCH 14/92] Fix variables in ci --- .circleci/leo-publish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index ac0bd0246a..c9c0232e6b 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -1,7 +1,7 @@ # leo login, publish and logout # Login -$LEO login -u "ALEO_PM_USERNAME" -p "ALEO_PM_PASSWORD" +$LEO login -u "$ALEO_PM_USERNAME" -p "$ALEO_PM_PASSWORD" # Clone the test-app package. $LEO clone test-app From 7c6dfeb5994d52bac40704eb73aadd9252efa8fe Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:02:31 -0800 Subject: [PATCH 15/92] Remove leo publish from GA --- .github/workflows/leo-publish.yml | 53 ------------------------------- 1 file changed, 53 deletions(-) delete mode 100644 .github/workflows/leo-publish.yml diff --git a/.github/workflows/leo-publish.yml b/.github/workflows/leo-publish.yml deleted file mode 100644 index 7760898d70..0000000000 --- a/.github/workflows/leo-publish.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: leo-publish -on: - pull_request: - push: - branches: - - master - paths-ignore: - - 'docs/**' - - 'documentation/**' -env: - RUST_BACKTRACE: 1 - -jobs: - publish: - name: Publish Package ('leo publish') - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: rustfmt - - - name: Install Leo - uses: actions-rs/cargo@v1 - env: - CARGO_NET_GIT_FETCH_WITH_CLI: true - with: - command: install - args: --path . - - # sed command below takes 0.1.0 version (which is default for new programs) - # and replaces it with GITHUB_RUN_ID - a unique incremental number for each - # GH Actions run; [AUTHOR] gets replaced with $USER variable; and we're ready - # to publish package with newer version and correct author - - name: 'leo login, publish and logout' - env: - USER: ${{ secrets.ALEO_PM_USERNAME }} - PASS: ${{ secrets.ALEO_PM_PASSWORD }} - run: | - cd .. && leo new test-app && cd test-app - leo login -u "$USER" -p "$PASS" - cat Leo.toml | sed "s/0.1.0/0.1.$GITHUB_RUN_ID/g" | sed "s/\[AUTHOR\]/$USER/g" > Leo.toml - leo publish - leo logout - - - From f596dc88876391d46b41ffc2027be05b499ccfb6 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:03:17 -0800 Subject: [PATCH 16/92] Add leo clone workflow --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index b40a1e33df..5bbb00055f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -187,6 +187,9 @@ workflows: - leo-login-logout: requires: - rust-stable + - leo-clone: + requires: + - rust-stable - leo-publish: requires: - rust-stable From 0c6a0ff9af975a0baabe63af148c0a7636f9bd6c Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:10:21 -0800 Subject: [PATCH 17/92] Fix publish CI --- .circleci/leo-publish.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index c9c0232e6b..ef539b0f22 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -5,6 +5,7 @@ $LEO login -u "$ALEO_PM_USERNAME" -p "$ALEO_PM_PASSWORD" # Clone the test-app package. $LEO clone test-app +cd test-app || exit 1 # Fetch the current Leo package version number. # From 69397f908b07d52b4408dbdbaaff647828f28209 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:17:52 -0800 Subject: [PATCH 18/92] Fix publish remote --- .circleci/leo-publish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index ef539b0f22..f15ca9aa49 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -4,7 +4,7 @@ $LEO login -u "$ALEO_PM_USERNAME" -p "$ALEO_PM_PASSWORD" # Clone the test-app package. -$LEO clone test-app +$LEO clone "$ALEO_PM_USERNAME/test-app" cd test-app || exit 1 # Fetch the current Leo package version number. From 9192c4a082a4f7867911a1f518a5e2f70690df80 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:24:07 -0800 Subject: [PATCH 19/92] Update publish --- .circleci/leo-publish.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index f15ca9aa49..fda0a36b1d 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -4,7 +4,8 @@ $LEO login -u "$ALEO_PM_USERNAME" -p "$ALEO_PM_PASSWORD" # Clone the test-app package. -$LEO clone "$ALEO_PM_USERNAME/test-app" +export PACKAGE="$ALEO_PM_USERNAME/test-app" +$LEO clone $PACKAGE cd test-app || exit 1 # Fetch the current Leo package version number. From 9a609991e41369a902250527373f0a52d062e4da Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:35:51 -0800 Subject: [PATCH 20/92] Add Leo run to publish for sanity check --- .circleci/leo-publish.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index fda0a36b1d..0731ae67cd 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -46,6 +46,11 @@ export UPDATED=$(cat Leo.toml \ export TOML=$(cat Leo.toml | sed "s/$CURRENT/$UPDATED/g") echo $TOML > Leo.toml +# Run the package to confirm the manifest remains well-formed. +$LEO run + +cat Leo.toml + # Publish the package to Aleo.pm $LEO publish From a839f387184c5c12c6d231dc98069a5fb758b180 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:50:10 -0800 Subject: [PATCH 21/92] Properly stringify it --- .circleci/leo-publish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index 0731ae67cd..57c02cc337 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -44,7 +44,7 @@ export UPDATED=$(cat Leo.toml \ # Write the updated Leo package version number to the Leo.toml file. export TOML=$(cat Leo.toml | sed "s/$CURRENT/$UPDATED/g") -echo $TOML > Leo.toml +echo "$TOML" > Leo.toml # Run the package to confirm the manifest remains well-formed. $LEO run From ffd0566c65f6486df94dd450d97b53039a048437 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 25 Feb 2021 10:58:52 -0800 Subject: [PATCH 22/92] Cleanup --- .circleci/leo-clone.sh | 4 +++- .circleci/leo-publish.sh | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.circleci/leo-clone.sh b/.circleci/leo-clone.sh index 2374663137..c625b8d355 100755 --- a/.circleci/leo-clone.sh +++ b/.circleci/leo-clone.sh @@ -1,6 +1,8 @@ # leo clone -$LEO clone leobot/test-app +# Clone the test-app package. +export PACKAGE="$ALEO_PM_USERNAME/test-app" +$LEO clone $PACKAGE # Assert that the 'test-app' folder is not empty diff --git a/.circleci/leo-publish.sh b/.circleci/leo-publish.sh index 57c02cc337..f41109dffd 100755 --- a/.circleci/leo-publish.sh +++ b/.circleci/leo-publish.sh @@ -49,8 +49,6 @@ echo "$TOML" > Leo.toml # Run the package to confirm the manifest remains well-formed. $LEO run -cat Leo.toml - # Publish the package to Aleo.pm $LEO publish From 0d7c6d0b652d9eb250849bc11e77a6509df23f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Garillot?= Date: Thu, 28 Jan 2021 13:27:21 -0800 Subject: [PATCH 23/92] Simplifies a number of pattern-matches Into the direct `Result` / `Option` combinator they correspond to, for concision / clarity. Reviewed from automated suggestions generated from [comby-rust](https://github.com/huitseeker/comby-rust). --- asg/src/reducer/visitor_director.rs | 10 ++-------- compiler/src/expression/function/core_circuit.rs | 6 +----- compiler/src/function/function.rs | 6 +----- leo/commands/package/add.rs | 5 +---- leo/commands/package/clone.rs | 5 +---- leo/commands/package/publish.rs | 8 ++++---- leo/context.rs | 10 ++-------- leo/synthesizer/serialized_circuit.rs | 4 ++-- 8 files changed, 14 insertions(+), 40 deletions(-) diff --git a/asg/src/reducer/visitor_director.rs b/asg/src/reducer/visitor_director.rs index d71926d2d0..4edc95d106 100644 --- a/asg/src/reducer/visitor_director.rs +++ b/asg/src/reducer/visitor_director.rs @@ -71,10 +71,7 @@ impl<'a, R: ExpressionVisitor<'a>> VisitorDirector<'a, R> { } fn visit_opt_expression(&mut self, input: &Cell>>) -> ConcreteVisitResult { - let interior = match input.get() { - Some(expr) => Some(Cell::new(expr)), - None => None, - }; + let interior = input.get().map(Cell::new); if let Some(interior) = interior.as_ref() { let result = self.visit_expression(interior); input.replace(Some(interior.get())); @@ -246,10 +243,7 @@ impl<'a, R: StatementVisitor<'a>> VisitorDirector<'a, R> { } fn visit_opt_statement(&mut self, input: &Cell>>) -> ConcreteVisitResult { - let interior = match input.get() { - Some(expr) => Some(Cell::new(expr)), - None => None, - }; + let interior = input.get().map(Cell::new); if let Some(interior) = interior.as_ref() { let result = self.visit_statement(interior); input.replace(Some(interior.get())); diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 0658d6c8e6..663973f4df 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -34,11 +34,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { arguments: &[Cell<&'a Expression<'a>>], span: &Span, ) -> Result, ExpressionError> { - let target_value = if let Some(target) = target { - Some(self.enforce_expression(cs, target)?) - } else { - None - }; + let target_value = target.map(|target| self.enforce_expression(cs, target)).transpose()?; // Get the value of each core function argument let arguments = arguments diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 53145ee3db..23dcda03b2 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -34,11 +34,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { target: Option<&'a Expression<'a>>, arguments: &[Cell<&'a Expression<'a>>], ) -> Result, FunctionError> { - let target_value = if let Some(target) = target { - Some(self.enforce_expression(cs, target)?) - } else { - None - }; + let target_value = target.map(|target| self.enforce_expression(cs, target)).transpose()?; let self_var = if let Some(target) = &target_value { let self_var = function diff --git a/leo/commands/package/add.rs b/leo/commands/package/add.rs index d70f7be8b1..ef1491f2f9 100644 --- a/leo/commands/package/add.rs +++ b/leo/commands/package/add.rs @@ -96,10 +96,7 @@ impl Command for Add { return Err(anyhow!("Package manifest not found, try running `leo init`")); }; - let (author, package_name) = match self.try_read_arguments() { - Ok((author, package)) => (author, package), - Err(err) => return Err(err), - }; + let (author, package_name) = self.try_read_arguments()?; // Attempt to fetch the package. let reader = { diff --git a/leo/commands/package/clone.rs b/leo/commands/package/clone.rs index 37d829aaf4..da28e74fe2 100644 --- a/leo/commands/package/clone.rs +++ b/leo/commands/package/clone.rs @@ -105,10 +105,7 @@ impl Command for Clone { } fn apply(self, context: Context, _: Self::Input) -> Result { - let (author, package_name) = match self.try_read_arguments() { - Ok((author, package)) => (author, package), - Err(err) => return Err(err), - }; + let (author, package_name) = self.try_read_arguments()?; // Attempt to fetch the package. let reader = { diff --git a/leo/commands/package/publish.rs b/leo/commands/package/publish.rs index ffcc1725e2..7b86763c67 100644 --- a/leo/commands/package/publish.rs +++ b/leo/commands/package/publish.rs @@ -93,10 +93,10 @@ impl Command for Publish { // Client for make POST request let client = Client::new(); - let token = match context.api.auth_token() { - Some(token) => token, - None => return Err(anyhow!("Login before publishing package: try leo login --help")), - }; + let token = context + .api + .auth_token() + .ok_or_else(|| anyhow!("Login before publishing package: try leo login --help"))?; // Headers for request to publish package let mut headers = HeaderMap::new(); diff --git a/leo/context.rs b/leo/context.rs index 077f382428..bddd54e5f2 100644 --- a/leo/context.rs +++ b/leo/context.rs @@ -49,10 +49,7 @@ impl Context { /// Create a new context for the current directory. pub fn create_context(path: PathBuf) -> Result { - let token = match config::read_token() { - Ok(token) => Some(token), - Err(_) => None, - }; + let token = config::read_token().ok(); let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token); @@ -61,10 +58,7 @@ pub fn create_context(path: PathBuf) -> Result { /// Returns project context. pub fn get_context() -> Result { - let token = match config::read_token() { - Ok(token) => Some(token), - Err(_) => None, - }; + let token = config::read_token().ok(); let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token); diff --git a/leo/synthesizer/serialized_circuit.rs b/leo/synthesizer/serialized_circuit.rs index 6f52560e1d..702a067914 100644 --- a/leo/synthesizer/serialized_circuit.rs +++ b/leo/synthesizer/serialized_circuit.rs @@ -174,11 +174,11 @@ impl TryFrom for CircuitSynthesizer { } Ok(CircuitSynthesizer:: { - input_assignment, - aux_assignment, at, bt, ct, + input_assignment, + aux_assignment, }) } } From 77a0af18fe6f1fc81a1d688f0141d921c560b5c9 Mon Sep 17 00:00:00 2001 From: howardwu Date: Fri, 26 Feb 2021 19:42:35 -0800 Subject: [PATCH 24/92] chore(leo): bump version for new release --- .resources/release-version | 2 +- Cargo.lock | 22 +++++++++++----------- Cargo.toml | 18 +++++++++--------- asg/Cargo.toml | 6 +++--- ast/Cargo.toml | 6 +++--- compiler/Cargo.toml | 18 +++++++++--------- gadgets/Cargo.toml | 2 +- grammar/Cargo.toml | 2 +- imports/Cargo.toml | 8 ++++---- input/Cargo.toml | 2 +- linter/Cargo.toml | 2 +- package/Cargo.toml | 2 +- state/Cargo.toml | 6 +++--- 13 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.resources/release-version b/.resources/release-version index 06043b8e35..a064add5ff 100644 --- a/.resources/release-version +++ b/.resources/release-version @@ -1 +1 @@ -v1.2.2 \ No newline at end of file +v1.2.3 \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 928ca77404..726ff890b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1192,7 +1192,7 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "leo-asg" -version = "1.2.2" +version = "1.2.3" dependencies = [ "criterion", "indexmap", @@ -1207,7 +1207,7 @@ dependencies = [ [[package]] name = "leo-ast" -version = "1.2.2" +version = "1.2.3" dependencies = [ "criterion", "indexmap", @@ -1221,7 +1221,7 @@ dependencies = [ [[package]] name = "leo-compiler" -version = "1.2.2" +version = "1.2.3" dependencies = [ "bincode", "hex", @@ -1255,7 +1255,7 @@ dependencies = [ [[package]] name = "leo-gadgets" -version = "1.2.2" +version = "1.2.3" dependencies = [ "criterion", "rand", @@ -1269,7 +1269,7 @@ dependencies = [ [[package]] name = "leo-grammar" -version = "1.2.2" +version = "1.2.3" dependencies = [ "criterion", "from-pest", @@ -1285,7 +1285,7 @@ dependencies = [ [[package]] name = "leo-imports" -version = "1.2.2" +version = "1.2.3" dependencies = [ "indexmap", "leo-asg", @@ -1297,7 +1297,7 @@ dependencies = [ [[package]] name = "leo-input" -version = "1.2.2" +version = "1.2.3" dependencies = [ "from-pest", "pest", @@ -1309,7 +1309,7 @@ dependencies = [ [[package]] name = "leo-lang" -version = "1.2.2" +version = "1.2.3" dependencies = [ "anyhow", "clap", @@ -1350,11 +1350,11 @@ dependencies = [ [[package]] name = "leo-linter" -version = "1.2.2" +version = "1.2.3" [[package]] name = "leo-package" -version = "1.2.2" +version = "1.2.3" dependencies = [ "lazy_static", "serde", @@ -1367,7 +1367,7 @@ dependencies = [ [[package]] name = "leo-state" -version = "1.2.2" +version = "1.2.3" dependencies = [ "indexmap", "leo-ast", diff --git a/Cargo.toml b/Cargo.toml index 86f7d2f5b9..f67a8d646e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-lang" -version = "1.2.2" +version = "1.2.3" authors = [ "The Aleo Team " ] description = "The Leo programming language" homepage = "https://aleo.org" @@ -35,36 +35,36 @@ members = [ "input", "linter", "package", - "state", + "state" ] [dependencies.leo-ast] path = "./ast" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-compiler] path = "./compiler" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-gadgets] path = "./gadgets" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-imports] path = "./imports" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-input] path = "./input" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-package] path = "./package" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-state] path = "./state" -version = "1.2.2" +version = "1.2.3" [dependencies.snarkvm-algorithms] version = "0.0.5" diff --git a/asg/Cargo.toml b/asg/Cargo.toml index 39295ecead..2bd668b36b 100644 --- a/asg/Cargo.toml +++ b/asg/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-asg" -version = "1.2.2" +version = "1.2.3" 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.2.2" +version = "1.2.3" path = "../ast" [dependencies.leo-grammar] -version = "1.2.2" +version = "1.2.3" path = "../grammar" [dependencies.num-bigint] diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 459fca8dc5..75a84f0111 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-ast" -version = "1.2.2" +version = "1.2.3" 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.2.2" +version = "1.2.3" [dependencies.leo-input] path = "../input" -version = "1.2.2" +version = "1.2.3" [dependencies.indexmap] version = "1.6.1" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index c2b7ab0c82..b846086b0c 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-compiler" -version = "1.2.2" +version = "1.2.3" authors = [ "The Aleo Team " ] description = "Compiler of the Leo programming language" homepage = "https://aleo.org" @@ -19,35 +19,35 @@ edition = "2018" [dependencies.leo-ast] path = "../ast" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-gadgets] path = "../gadgets" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-grammar] path = "../grammar" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-imports] path = "../imports" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-input] path = "../input" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-package] path = "../package" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-state] path = "../state" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-asg] path = "../asg" -version = "1.2.2" +version = "1.2.3" [dependencies.snarkvm-curves] version = "0.0.5" diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index a3e3d627f9..e7e83c9554 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-gadgets" -version = "1.2.2" +version = "1.2.3" authors = [ "The Aleo Team " ] description = "Gadgets of the Leo programming language" homepage = "https://aleo.org" diff --git a/grammar/Cargo.toml b/grammar/Cargo.toml index 76adca9992..6f123a6d50 100644 --- a/grammar/Cargo.toml +++ b/grammar/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-grammar" -version = "1.2.2" +version = "1.2.3" authors = [ "The Aleo Team " ] description = "AST generated by pest from the Leo grammar rules" homepage = "https://aleo.org" diff --git a/imports/Cargo.toml b/imports/Cargo.toml index 3ced7110f4..f7a53f98fc 100644 --- a/imports/Cargo.toml +++ b/imports/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-imports" -version = "1.2.2" +version = "1.2.3" 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.2.2" +version = "1.2.3" [dependencies.leo-grammar] path = "../grammar" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-asg] path = "../asg" -version = "1.2.2" +version = "1.2.3" [dependencies.indexmap] version = "1.6.1" diff --git a/input/Cargo.toml b/input/Cargo.toml index 0bff7d54cf..c3375511dd 100644 --- a/input/Cargo.toml +++ b/input/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-input" -version = "1.2.2" +version = "1.2.3" authors = [ "The Aleo Team " ] description = "Input parser of the Leo programming language" homepage = "https://aleo.org" diff --git a/linter/Cargo.toml b/linter/Cargo.toml index 472ade7820..f934e454bb 100644 --- a/linter/Cargo.toml +++ b/linter/Cargo.toml @@ -2,7 +2,7 @@ dependencies = { } [package] name = "leo-linter" -version = "1.2.2" +version = "1.2.3" 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 1dfc658802..d3bdb61029 100644 --- a/package/Cargo.toml +++ b/package/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-package" -version = "1.2.2" +version = "1.2.3" 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 a81375903b..77b8cc2c46 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "leo-state" -version = "1.2.2" +version = "1.2.3" authors = [ "The Aleo Team " ] description = "State parser of the Leo programming language" homepage = "https://aleo.org" @@ -19,11 +19,11 @@ edition = "2018" [dependencies.leo-input] path = "../input" -version = "1.2.2" +version = "1.2.3" [dependencies.leo-ast] path = "../ast" -version = "1.2.2" +version = "1.2.3" [dependencies.snarkvm-algorithms] version = "0.0.5" From 5d605178e4979489e93319a7072fee454f4d1947 Mon Sep 17 00:00:00 2001 From: howardwu Date: Fri, 26 Feb 2021 23:13:55 -0800 Subject: [PATCH 25/92] Reenable ASG --- wasm/Cargo.toml | 8 ++++++++ wasm/src/asg.rs | 7 ++++--- wasm/src/lib.rs | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index f26e7ac6d5..f28e878836 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -20,6 +20,10 @@ edition = "2018" [lib] crate-type = [ "cdylib", "rlib" ] +[dependencies.leo-asg] +path = "../asg" +version = "1.2.3" + [dependencies.leo-ast] path = "../ast" version = "1.2.3" @@ -28,6 +32,10 @@ version = "1.2.3" path = "../grammar" version = "1.2.3" +[dependencies.leo-imports] +path = "../imports" +version = "1.2.3" + [dependencies.serde] version = "1.0" features = [ "derive" ] diff --git a/wasm/src/asg.rs b/wasm/src/asg.rs index ab5e0ec762..933e217433 100644 --- a/wasm/src/asg.rs +++ b/wasm/src/asg.rs @@ -15,20 +15,21 @@ // along with the Leo library. If not, see . use crate::ast::Ast; -use leo_asg::Asg as LeoAsg; +use leo_asg::{new_alloc_context, new_context, Asg as LeoAsg}; use leo_grammar::Grammar as LeoGrammar; use std::path::Path; use wasm_bindgen::prelude::*; #[wasm_bindgen] -pub struct Asg(LeoAsg); +pub struct Asg(LeoAsg<'static>); #[wasm_bindgen] impl Asg { #[wasm_bindgen(constructor)] pub fn from(ast: &Ast) -> Self { - let asg = LeoAsg::new(&ast.0, &mut leo_imports::ImportParser::default()).unwrap(); + let arena = new_alloc_context(); + let asg = LeoAsg::new(new_context(&arena), &ast.0, &mut leo_imports::ImportParser::default()).unwrap(); Self(asg) } } diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs index 624e19f64c..e702ef0d4a 100644 --- a/wasm/src/lib.rs +++ b/wasm/src/lib.rs @@ -13,9 +13,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -// -// pub mod asg; -// pub use asg::*; + +pub mod asg; +pub use asg::*; pub mod ast; pub use ast::*; From ec056a2877cc6f90a22caa1474818bead99cfae4 Mon Sep 17 00:00:00 2001 From: howardwu Date: Sat, 27 Feb 2021 08:48:20 -0800 Subject: [PATCH 26/92] Migrates synthesizer to a dedicated module --- Cargo.lock | 16 ++- Cargo.toml | 8 +- leo/commands/build.rs | 7 +- leo/lib.rs | 1 - leo/main.rs | 1 - synthesizer/Cargo.toml | 40 ++++++++ .../src}/circuit_synthesizer.rs | 10 +- .../mod.rs => synthesizer/src/lib.rs | 0 .../src}/serialized_circuit.rs | 2 +- .../src}/serialized_field.rs | 0 .../src}/serialized_index.rs | 0 wasm/src/asg.rs | 24 ++++- wasm/src/compiler.rs | 99 ++++++++++--------- 13 files changed, 140 insertions(+), 68 deletions(-) create mode 100644 synthesizer/Cargo.toml rename {leo/synthesizer => synthesizer/src}/circuit_synthesizer.rs (94%) rename leo/synthesizer/mod.rs => synthesizer/src/lib.rs (100%) rename {leo/synthesizer => synthesizer/src}/serialized_circuit.rs (98%) rename {leo/synthesizer => synthesizer/src}/serialized_field.rs (100%) rename {leo/synthesizer => synthesizer/src}/serialized_index.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index ea2353f8fd..c872ec721b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1334,8 +1334,8 @@ dependencies = [ "leo-input", "leo-package", "leo-state", + "leo-synthesizer", "notify", - "num-bigint", "rand", "rand_core", "reqwest", @@ -1395,12 +1395,26 @@ dependencies = [ "thiserror", ] +[[package]] +name = "leo-synthesizer" +version = "1.2.3" +dependencies = [ + "num-bigint", + "serde", + "serde_json", + "snarkvm-curves", + "snarkvm-errors", + "snarkvm-models", +] + [[package]] name = "leo-wasm" version = "1.2.3" dependencies = [ + "leo-asg", "leo-ast", "leo-grammar", + "leo-imports", "serde", "wasm-bindgen", "wasm-bindgen-test", diff --git a/Cargo.toml b/Cargo.toml index 28f67cd4a9..ba064319f5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,7 @@ members = [ "linter", "package", "state", + "synthesizer", "wasm" ] @@ -67,6 +68,10 @@ version = "1.2.3" path = "./state" version = "1.2.3" +[dependencies.leo-synthesizer] +path = "./synthesizer" +version = "1.2.3" + [dependencies.snarkvm-algorithms] version = "0.0.5" default-features = false @@ -117,9 +122,6 @@ version = "1.4.0" [dependencies.notify] version = "4.0.15" -[dependencies.num-bigint] -version = "0.3" - [dependencies.rand] version = "0.8" diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 9f562dd85a..f29dac7739 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -14,11 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - commands::Command, - context::Context, - synthesizer::{CircuitSynthesizer, SerializedCircuit}, -}; +use crate::{commands::Command, context::Context}; use leo_compiler::{ compiler::{thread_leaked_context, Compiler}, group::targets::edwards_bls12::EdwardsGroupType, @@ -28,6 +24,7 @@ use leo_package::{ outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, }; +use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit}; use anyhow::Result; use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq}; diff --git a/leo/lib.rs b/leo/lib.rs index 5c1c7c74e2..94ce90e005 100644 --- a/leo/lib.rs +++ b/leo/lib.rs @@ -19,7 +19,6 @@ pub mod commands; pub mod config; pub mod context; pub mod logger; -pub mod synthesizer; pub mod updater; #[cfg(test)] diff --git a/leo/main.rs b/leo/main.rs index f42cd412f6..a0d256230c 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -19,7 +19,6 @@ pub mod commands; pub mod config; pub mod context; pub mod logger; -pub mod synthesizer; pub mod updater; use commands::{ diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml new file mode 100644 index 0000000000..931f8627a3 --- /dev/null +++ b/synthesizer/Cargo.toml @@ -0,0 +1,40 @@ +[package] +name = "leo-synthesizer" +version = "1.2.3" +authors = [ "The Aleo Team " ] +description = "Circuit synthesizer of the Leo programming language" +homepage = "https://aleo.org" +repository = "https://github.com/AleoHQ/leo" +keywords = [ + "aleo", + "cryptography", + "leo", + "programming-language", + "zero-knowledge" +] +categories = [ "cryptography::cryptocurrencies", "web-programming" ] +include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] +license = "GPL-3.0" +edition = "2018" + +[dependencies.snarkvm-curves] +version = "0.0.5" +default-features = false + +[dependencies.snarkvm-errors] +version = "0.0.5" +default-features = false + +[dependencies.snarkvm-models] +version = "0.0.5" +default-features = false + +[dependencies.num-bigint] +version = "0.3" + +[dependencies.serde] +version = "1.0" +features = [ "derive" ] + +[dependencies.serde_json] +version = "1.0" diff --git a/leo/synthesizer/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs similarity index 94% rename from leo/synthesizer/circuit_synthesizer.rs rename to synthesizer/src/circuit_synthesizer.rs index 3acaf080db..1cf17b9261 100644 --- a/leo/synthesizer/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -22,13 +22,13 @@ use snarkvm_models::{ pub struct CircuitSynthesizer { // Constraints - pub(crate) at: Vec>, - pub(crate) bt: Vec>, - pub(crate) ct: Vec>, + pub at: Vec>, + pub bt: Vec>, + pub ct: Vec>, // Assignments of variables - pub(crate) input_assignment: Vec, - pub(crate) aux_assignment: Vec, + pub input_assignment: Vec, + pub aux_assignment: Vec, } impl ConstraintSystem for CircuitSynthesizer { diff --git a/leo/synthesizer/mod.rs b/synthesizer/src/lib.rs similarity index 100% rename from leo/synthesizer/mod.rs rename to synthesizer/src/lib.rs diff --git a/leo/synthesizer/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs similarity index 98% rename from leo/synthesizer/serialized_circuit.rs rename to synthesizer/src/serialized_circuit.rs index 702a067914..ef8df3f619 100644 --- a/leo/synthesizer/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -24,7 +24,7 @@ use snarkvm_models::{ gadgets::r1cs::{ConstraintSystem, Index}, }; -use crate::synthesizer::{CircuitSynthesizer, SerializedField, SerializedIndex}; +use crate::{CircuitSynthesizer, SerializedField, SerializedIndex}; #[derive(Serialize, Deserialize)] pub struct SerializedCircuit { diff --git a/leo/synthesizer/serialized_field.rs b/synthesizer/src/serialized_field.rs similarity index 100% rename from leo/synthesizer/serialized_field.rs rename to synthesizer/src/serialized_field.rs diff --git a/leo/synthesizer/serialized_index.rs b/synthesizer/src/serialized_index.rs similarity index 100% rename from leo/synthesizer/serialized_index.rs rename to synthesizer/src/serialized_index.rs diff --git a/wasm/src/asg.rs b/wasm/src/asg.rs index 933e217433..cd0b094a24 100644 --- a/wasm/src/asg.rs +++ b/wasm/src/asg.rs @@ -15,12 +15,24 @@ // along with the Leo library. If not, see . use crate::ast::Ast; -use leo_asg::{new_alloc_context, new_context, Asg as LeoAsg}; +use leo_asg::{new_alloc_context, new_context, Asg as LeoAsg, AsgContext}; use leo_grammar::Grammar as LeoGrammar; -use std::path::Path; +use std::{boxed::Box, path::Path}; use wasm_bindgen::prelude::*; +thread_local! { + static THREAD_GLOBAL_CONTEXT: AsgContext<'static> = { + let leaked = Box::leak(Box::new(leo_asg::new_alloc_context())); + leo_asg::new_context(leaked) + } +} + +/// Convenience function to return a leaked thread-local global context. Should only be used for transient programs. +pub fn thread_leaked_context() -> AsgContext<'static> { + THREAD_GLOBAL_CONTEXT.with(|f| *f) +} + #[wasm_bindgen] pub struct Asg(LeoAsg<'static>); @@ -28,8 +40,12 @@ pub struct Asg(LeoAsg<'static>); impl Asg { #[wasm_bindgen(constructor)] pub fn from(ast: &Ast) -> Self { - let arena = new_alloc_context(); - let asg = LeoAsg::new(new_context(&arena), &ast.0, &mut leo_imports::ImportParser::default()).unwrap(); + let asg = LeoAsg::new( + thread_leaked_context(), + &ast.0, + &mut leo_imports::ImportParser::default(), + ) + .unwrap(); Self(asg) } } diff --git a/wasm/src/compiler.rs b/wasm/src/compiler.rs index ea5430574a..28fb0a0496 100644 --- a/wasm/src/compiler.rs +++ b/wasm/src/compiler.rs @@ -1,47 +1,52 @@ -// // 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::Ast; -// -// use std::path::Path; -// use wasm_bindgen::prelude::*; -// -// #[wasm_bindgen] -// pub struct Compiler(String); -// -// #[wasm_bindgen] -// impl Compiler { -// #[wasm_bindgen(constructor)] -// pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { -// let ast = Ast::new(filepath, program_name, program_string).unwrap(); -// Self(ast.to_string()) -// } -// -// #[wasm_bindgen] -// pub fn to_string(&self) -> String { -// self.0.clone() -// } -// } -// -// #[cfg(test)] -// mod tests { -// use super::*; -// -// use wasm_bindgen_test::*; -// -// #[wasm_bindgen_test] -// fn ast_test() {} -// } +// 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::{asg::Asg, ast::Ast}; +use leo_compiler::generate_constraints; + +use std::path::Path; +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub struct Compiler(String); + +#[wasm_bindgen] +impl Compiler { + #[wasm_bindgen(constructor)] + pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { + let ast = Ast::new(filepath, program_name, program_string).unwrap(); + let asg = Asg::from(&ast); + + // TODO (howardwu): Support program inputs. + generate_constraints(cs, &asg.as_ref().unwrap(), &Input::new()).unwrap(); + Self(ast.to_string()) + } + + #[wasm_bindgen] + pub fn to_string(&self) -> String { + self.0.clone() + } +} + +#[cfg(test)] +mod tests { + use super::*; + + use wasm_bindgen_test::*; + + #[wasm_bindgen_test] + fn ast_test() {} +} From a0b6dba14d033c82ab211239adf3a807fa1c3e00 Mon Sep 17 00:00:00 2001 From: howardwu Date: Sat, 27 Feb 2021 08:57:44 -0800 Subject: [PATCH 27/92] Checkpoint for further wasm compatibility --- wasm/Cargo.toml | 9 +++++++++ wasm/src/compiler.rs | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml index f28e878836..c706f09b9c 100644 --- a/wasm/Cargo.toml +++ b/wasm/Cargo.toml @@ -20,6 +20,10 @@ edition = "2018" [lib] crate-type = [ "cdylib", "rlib" ] +#[dependencies.snarkvm-curves] +#version = "0.0.5" +#default-features = false + [dependencies.leo-asg] path = "../asg" version = "1.2.3" @@ -36,6 +40,11 @@ version = "1.2.3" path = "../imports" version = "1.2.3" +#[dependencies.leo-synthesizer] +#path = "../synthesizer" +#version = "1.2.3" +#default-features = false + [dependencies.serde] version = "1.0" features = [ "derive" ] diff --git a/wasm/src/compiler.rs b/wasm/src/compiler.rs index 28fb0a0496..e45868fad1 100644 --- a/wasm/src/compiler.rs +++ b/wasm/src/compiler.rs @@ -16,6 +16,9 @@ use crate::{asg::Asg, ast::Ast}; use leo_compiler::generate_constraints; +// use leo_synthesizer::CircuitSynthesizer; + +// use snarkvm_curves::Bls12_377; use std::path::Path; use wasm_bindgen::prelude::*; @@ -30,6 +33,39 @@ impl Compiler { let ast = Ast::new(filepath, program_name, program_string).unwrap(); let asg = Asg::from(&ast); + // Generate the program on the constraint system and verify correctness + { + // let mut cs = CircuitSynthesizer:: { + // at: vec![], + // bt: vec![], + // ct: vec![], + // input_assignment: vec![], + // aux_assignment: vec![], + // }; + // let temporary_program = program.clone(); + // let output = temporary_program.compile_constraints(&mut cs)?; + // + // tracing::debug!("Compiled output - {:#?}", output); + // tracing::info!("Number of constraints - {:#?}", cs.num_constraints()); + // + // // Serialize the circuit + // let circuit_object = SerializedCircuit::from(cs); + // let json = circuit_object.to_json_string().unwrap(); + // // println!("json: {}", json); + // + // // Write serialized circuit to circuit `.json` file. + // let circuit_file = CircuitFile::new(&package_name); + // circuit_file.write_to(&path, json)?; + + // Check that we can read the serialized circuit file + // let serialized = circuit_file.read_from(&package_path)?; + + // Deserialize the circuit + // let deserialized = SerializedCircuit::from_json_string(&serialized).unwrap(); + // let _circuit_synthesizer = CircuitSynthesizer::::try_from(deserialized).unwrap(); + // println!("deserialized {:?}", circuit_synthesizer.num_constraints()); + } + // TODO (howardwu): Support program inputs. generate_constraints(cs, &asg.as_ref().unwrap(), &Input::new()).unwrap(); Self(ast.to_string()) From 8a05594b42de831663a64f3f39f45d1dd54243d8 Mon Sep 17 00:00:00 2001 From: howardwu Date: Sat, 27 Feb 2021 13:10:39 -0800 Subject: [PATCH 28/92] Bump snarkvm to v0.0.6 --- Cargo.lock | 118 +++++++------------- Cargo.toml | 13 +-- compiler/Cargo.toml | 16 +-- gadgets/Cargo.toml | 6 +- state/Cargo.toml | 16 +-- synthesizer/Cargo.toml | 6 +- wasm/.resources/basic/expected_ast.json | 77 ------------- wasm/.resources/basic/expected_grammar.json | 85 -------------- wasm/.resources/basic/main.leo | 3 - wasm/Cargo.toml | 57 ---------- wasm/src/asg.rs | 75 ------------- wasm/src/ast.rs | 62 ---------- wasm/src/compiler.rs | 88 --------------- wasm/src/grammar.rs | 60 ---------- wasm/src/lib.rs | 27 ----- 15 files changed, 69 insertions(+), 640 deletions(-) delete mode 100644 wasm/.resources/basic/expected_ast.json delete mode 100644 wasm/.resources/basic/expected_grammar.json delete mode 100644 wasm/.resources/basic/main.leo delete mode 100644 wasm/Cargo.toml delete mode 100644 wasm/src/asg.rs delete mode 100644 wasm/src/ast.rs delete mode 100644 wasm/src/compiler.rs delete mode 100644 wasm/src/grammar.rs delete mode 100644 wasm/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index c872ec721b..dc53565464 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -378,16 +378,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "console_error_panic_hook" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8d976903543e0c48546a91908f21588a680a8c8f984df9a5d69feccb2b2a211" -dependencies = [ - "cfg-if 0.1.10", - "wasm-bindgen", -] - [[package]] name = "constant_time_eq" version = "0.1.5" @@ -1407,19 +1397,6 @@ dependencies = [ "snarkvm-models", ] -[[package]] -name = "leo-wasm" -version = "1.2.3" -dependencies = [ - "leo-asg", - "leo-ast", - "leo-grammar", - "leo-imports", - "serde", - "wasm-bindgen", - "wasm-bindgen-test", -] - [[package]] name = "libc" version = "0.2.86" @@ -2307,12 +2284,6 @@ dependencies = [ "winapi 0.3.9", ] -[[package]] -name = "scoped-tls" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea6a9290e3c9cf0f18145ef7ffa62d68ee0bf5fcd651017e586dc7fd5da448c2" - [[package]] name = "scopeguard" version = "1.1.0" @@ -2509,9 +2480,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "snarkvm-algorithms" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "739c2aaf5dbf6322d3a40bbb9739a87d458f32460da1b8affeae45214ec88e8c" +checksum = "7d3de956d0221ff897ebcc2a36e8a88482dee06acaebce67f7819c41be843a11" dependencies = [ "blake2", "derivative", @@ -2530,9 +2501,9 @@ dependencies = [ [[package]] name = "snarkvm-curves" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c39148bec803c5e41b0696326a60817d9b84c4c2c1df6ea5be56f857b078988" +checksum = "dd45a9c60e9c81bbfc4568f8c7d4c3fd0b6dc7b75916086eb16795fc3ea854b2" dependencies = [ "derivative", "rand", @@ -2546,9 +2517,9 @@ dependencies = [ [[package]] name = "snarkvm-derives" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24c5c4170d43a65e23bce115d6d2940c7fc66e1562a7822dd460db56f1fb07b1" +checksum = "1b3339f816745870549adbcf7f5b1db3441c8d73377278fec9c7829a87ebdc07" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -2559,9 +2530,9 @@ dependencies = [ [[package]] name = "snarkvm-dpc" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3feb5d2cec547779e0acec01cd58f5d5fe6aac60cc4804e5e3cf9c807bb1880" +checksum = "f9d43c0c63eedf067284496e068527f2448ea3ecba1ba9c44d486c3fb66e04e2" dependencies = [ "anyhow", "blake2", @@ -2582,9 +2553,9 @@ dependencies = [ [[package]] name = "snarkvm-errors" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cfe9f6fac097aed079fa68a63c8989783b2cf21705de75bc91672dec60c9684" +checksum = "ce13866aa05abf33972261ab9803b2f223bd5bee9e5336aac0618c2aa8249f24" dependencies = [ "base58", "bech32", @@ -2596,9 +2567,9 @@ dependencies = [ [[package]] name = "snarkvm-gadgets" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978bcc75bce7a1274f51b2adc4d69c30d866930aa37c656b4b8c1be5d631891c" +checksum = "e5f6de0307dba124bf510fdf52b870a9ba76ad3177b2b742f91c87ee39a038d8" dependencies = [ "derivative", "digest 0.9.0", @@ -2612,9 +2583,9 @@ dependencies = [ [[package]] name = "snarkvm-models" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8da5920c6f4062c0d348e93ff0f72d17681c34f3c13ee4e99196495d896ed9" +checksum = "21afc37b95e310387d9a7ea25e439c7e5f444896a760e5f3893d4e6ef387d48c" dependencies = [ "anyhow", "bincode", @@ -2632,9 +2603,9 @@ dependencies = [ [[package]] name = "snarkvm-objects" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4641e23002d38caeb51fa3244320355cab07eaf22d17dc44b481c763b63b5f4d" +checksum = "724332214a919a1c14f07c458c191319101cc3252319cf2f9e8f122fd2a5f5d5" dependencies = [ "base58", "bech32", @@ -2654,29 +2625,46 @@ dependencies = [ [[package]] name = "snarkvm-parameters" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cb0f27fbccad7dee0ad4c2e5aeb0832c393fec76b4ad5d834c2e6cc0297e9a9" +checksum = "9e69a1db7cba8b07538943c0a9c547f515a4d726d8863dc1d40c5f9266a8af27" dependencies = [ "curl", "hex", "snarkvm-algorithms", "snarkvm-errors", "snarkvm-models", + "snarkvm-polycommit", + "snarkvm-utilities", +] + +[[package]] +name = "snarkvm-polycommit" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1f29eab35b3214dee0847deae11ea3af13c42e3beefb8cf7c22ed567cf3a70e" +dependencies = [ + "derivative", + "digest 0.9.0", + "rand_core", + "snarkvm-algorithms", + "snarkvm-errors", + "snarkvm-models", + "snarkvm-profiler", "snarkvm-utilities", ] [[package]] name = "snarkvm-profiler" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb5e9b964cb9653588607d8793bc7d6d0dfa78763a02d61aa3daa6c7d665e2b" +checksum = "37ce2100d7198526f11290d70d83a1bb6a1dd578f43821ceb544421ebd398312" [[package]] name = "snarkvm-storage" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ef134de5e33fe0577f3936e9dcf9bfac1973a0d820390e19558672808bad6b9" +checksum = "b57ef27e6b3073f4681332ac018158cea1f28c8a14e2187085e2c656f1641550" dependencies = [ "anyhow", "bincode", @@ -2696,9 +2684,9 @@ dependencies = [ [[package]] name = "snarkvm-utilities" -version = "0.0.5" +version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "872c2ee1675c5039caf8cb4c5ef37b0ad844ffe7e0d81b68fb39f713da199561" +checksum = "272b8758ef7fed8dc70cc01ecfd13e9add23edbabcaae1c5c7cfaca54d0fcae5" dependencies = [ "bincode", "rand", @@ -3234,30 +3222,6 @@ version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" -[[package]] -name = "wasm-bindgen-test" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2ea9e4f0050d5498a160e6b9d278a9699598e445b51dacd05598da55114c801a" -dependencies = [ - "console_error_panic_hook", - "js-sys", - "scoped-tls", - "wasm-bindgen", - "wasm-bindgen-futures", - "wasm-bindgen-test-macro", -] - -[[package]] -name = "wasm-bindgen-test-macro" -version = "0.3.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f40402f495d92df6cdd0d329e7cc2580c8f99bcd74faff0e468923a764b7d4" -dependencies = [ - "proc-macro2 1.0.24", - "quote 1.0.9", -] - [[package]] name = "web-sys" version = "0.3.48" diff --git a/Cargo.toml b/Cargo.toml index ba064319f5..84ef126ea8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,7 +37,6 @@ members = [ "package", "state", "synthesizer", - "wasm" ] [dependencies.leo-ast] @@ -73,27 +72,27 @@ path = "./synthesizer" version = "1.2.3" [dependencies.snarkvm-algorithms] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-curves] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-errors] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-models] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.5" +version = "0.0.6" [dependencies.anyhow] version = "1.0" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index b846086b0c..6e9b5c71d6 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -50,31 +50,31 @@ path = "../asg" version = "1.2.3" [dependencies.snarkvm-curves] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-errors] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-models] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-objects] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.5" +version = "0.0.6" [dependencies.bincode] version = "1.3" @@ -115,7 +115,7 @@ version = "0.3" default-features = false [dev-dependencies.snarkvm-algorithms] -version = "0.0.5" +version = "0.0.6" default-features = false [features] diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index e7e83c9554..b32f462072 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -18,15 +18,15 @@ license = "GPL-3.0" edition = "2018" [dependencies.snarkvm-errors] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-models] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.5" +version = "0.0.6" [dependencies.rand] version = "0.8" diff --git a/state/Cargo.toml b/state/Cargo.toml index 77b8cc2c46..0482e51f8d 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -26,31 +26,31 @@ path = "../ast" version = "1.2.3" [dependencies.snarkvm-algorithms] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-curves] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-errors] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-models] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-objects] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.5" +version = "0.0.6" [dependencies.indexmap] version = "1.6.1" @@ -66,7 +66,7 @@ version = "0.3" version = "1.0" [dev-dependencies.snarkvm-storage] -version = "0.0.5" +version = "0.0.6" [dev-dependencies.rand_core] version = "0.6.2" diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 931f8627a3..a9e497988d 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -18,15 +18,15 @@ license = "GPL-3.0" edition = "2018" [dependencies.snarkvm-curves] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-errors] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.snarkvm-models] -version = "0.0.5" +version = "0.0.6" default-features = false [dependencies.num-bigint] diff --git a/wasm/.resources/basic/expected_ast.json b/wasm/.resources/basic/expected_ast.json deleted file mode 100644 index dec3baf947..0000000000 --- a/wasm/.resources/basic/expected_ast.json +++ /dev/null @@ -1,77 +0,0 @@ -{ - "name": "basic", - "expected_input": [], - "imports": [], - "circuits": {}, - "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}": { - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}", - "input": [], - "output": null, - "block": { - "statements": [ - { - "Return": { - "expression": { - "Binary": { - "left": { - "Value": { - "Implicit": [ - "1", - { - "text": " return 1 + 1", - "line": 2, - "start": 12, - "end": 13 - } - ] - } - }, - "right": { - "Value": { - "Implicit": [ - "1", - { - "text": " return 1 + 1", - "line": 2, - "start": 16, - "end": 17 - } - ] - } - }, - "op": "Add", - "span": { - "text": " return 1 + 1", - "line": 2, - "start": 12, - "end": 17 - } - } - }, - "span": { - "text": " return 1 + 1", - "line": 2, - "start": 5, - "end": 17 - } - } - } - ], - "span": { - "text": " function main() {", - "line": 1, - "start": 17, - "end": 2 - } - }, - "span": { - "text": " function main() {", - "line": 1, - "start": 1, - "end": 2 - } - } - }, - "tests": {} -} \ No newline at end of file diff --git a/wasm/.resources/basic/expected_grammar.json b/wasm/.resources/basic/expected_grammar.json deleted file mode 100644 index 6c0e4c9404..0000000000 --- a/wasm/.resources/basic/expected_grammar.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "definitions": [ - { - "Function": { - "identifier": { - "value": "main", - "span": { - "input": "main", - "start": 9, - "end": 13 - } - }, - "parameters": [], - "returns": null, - "block": { - "statements": [ - { - "Return": { - "expression": { - "Binary": { - "operation": "Add", - "left": { - "Value": { - "Implicit": { - "Positive": { - "value": "1", - "span": { - "input": "1", - "start": 29, - "end": 30 - } - } - } - } - }, - "right": { - "Value": { - "Implicit": { - "Positive": { - "value": "1", - "span": { - "input": "1", - "start": 33, - "end": 34 - } - } - } - } - }, - "span": { - "input": "1 + 1", - "start": 29, - "end": 34 - } - } - }, - "span": { - "input": "return 1 + 1", - "start": 22, - "end": 34 - } - } - } - ], - "span": { - "input": "{\n return 1 + 1\n}", - "start": 16, - "end": 36 - } - }, - "span": { - "input": "function main() {\n return 1 + 1\n}", - "start": 0, - "end": 36 - } - } - } - ], - "eoi": null, - "span": { - "input": "function main() {\n return 1 + 1\n}\n", - "start": 0, - "end": 37 - } -} \ No newline at end of file diff --git a/wasm/.resources/basic/main.leo b/wasm/.resources/basic/main.leo deleted file mode 100644 index ef22115243..0000000000 --- a/wasm/.resources/basic/main.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - return 1 + 1 -} diff --git a/wasm/Cargo.toml b/wasm/Cargo.toml deleted file mode 100644 index c706f09b9c..0000000000 --- a/wasm/Cargo.toml +++ /dev/null @@ -1,57 +0,0 @@ -[package] -name = "leo-wasm" -version = "1.2.3" -authors = [ "The Aleo Team " ] -description = "WASM interpreter of the Leo programming language" -homepage = "https://aleo.org" -repository = "https://github.com/AleoHQ/leo" -keywords = [ - "aleo", - "cryptography", - "leo", - "programming-language", - "zero-knowledge" -] -categories = [ "cryptography::cryptocurrencies", "web-programming" ] -include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] -license = "GPL-3.0" -edition = "2018" - -[lib] -crate-type = [ "cdylib", "rlib" ] - -#[dependencies.snarkvm-curves] -#version = "0.0.5" -#default-features = false - -[dependencies.leo-asg] -path = "../asg" -version = "1.2.3" - -[dependencies.leo-ast] -path = "../ast" -version = "1.2.3" - -[dependencies.leo-grammar] -path = "../grammar" -version = "1.2.3" - -[dependencies.leo-imports] -path = "../imports" -version = "1.2.3" - -#[dependencies.leo-synthesizer] -#path = "../synthesizer" -#version = "1.2.3" -#default-features = false - -[dependencies.serde] -version = "1.0" -features = [ "derive" ] - -[dependencies.wasm-bindgen] -version = "0.2" -features = [ "serde-serialize" ] - -[dev-dependencies.wasm-bindgen-test] -version = "0.3.20" diff --git a/wasm/src/asg.rs b/wasm/src/asg.rs deleted file mode 100644 index cd0b094a24..0000000000 --- a/wasm/src/asg.rs +++ /dev/null @@ -1,75 +0,0 @@ -// 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::Ast; -use leo_asg::{new_alloc_context, new_context, Asg as LeoAsg, AsgContext}; -use leo_grammar::Grammar as LeoGrammar; - -use std::{boxed::Box, path::Path}; -use wasm_bindgen::prelude::*; - -thread_local! { - static THREAD_GLOBAL_CONTEXT: AsgContext<'static> = { - let leaked = Box::leak(Box::new(leo_asg::new_alloc_context())); - leo_asg::new_context(leaked) - } -} - -/// Convenience function to return a leaked thread-local global context. Should only be used for transient programs. -pub fn thread_leaked_context() -> AsgContext<'static> { - THREAD_GLOBAL_CONTEXT.with(|f| *f) -} - -#[wasm_bindgen] -pub struct Asg(LeoAsg<'static>); - -#[wasm_bindgen] -impl Asg { - #[wasm_bindgen(constructor)] - pub fn from(ast: &Ast) -> Self { - let asg = LeoAsg::new( - thread_leaked_context(), - &ast.0, - &mut leo_imports::ImportParser::default(), - ) - .unwrap(); - Self(asg) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use wasm_bindgen_test::*; - - #[wasm_bindgen_test] - fn asg_test() { - // let expected = include_str!("../.resources/basic/expected_ast.json"); - - let filepath = "../.resources/basic/main.leo"; - let program_name = "basic"; - let program_string = include_str!("../.resources/basic/main.leo"); - - let ast = Ast::new(filepath, program_name, program_string); - let candidate = Asg::from(&ast); - - // let expected = JsValue::from_str(expected); - // let candidate = JsValue::from_serde(&candidate).unwrap(); - // - // assert_eq!(expected, candidate); - } -} diff --git a/wasm/src/ast.rs b/wasm/src/ast.rs deleted file mode 100644 index 48683509a5..0000000000 --- a/wasm/src/ast.rs +++ /dev/null @@ -1,62 +0,0 @@ -// 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_ast::Ast as LeoAst; -use leo_grammar::Grammar as LeoGrammar; - -use std::path::Path; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -pub struct Ast(pub(crate) LeoAst); - -#[wasm_bindgen] -impl Ast { - #[wasm_bindgen(constructor)] - pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { - let grammar = LeoGrammar::new(&Path::new(filepath), &program_string).unwrap(); - let ast = LeoAst::new(program_name, &grammar).unwrap(); - Self(ast) - } - - #[wasm_bindgen] - pub fn to_string(&self) -> String { - self.0.to_json_string().unwrap() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use wasm_bindgen_test::*; - - #[wasm_bindgen_test] - fn ast_test() { - let expected = include_str!("../.resources/basic/expected_ast.json"); - - let filepath = "../.resources/basic/main.leo"; - let program_name = "basic"; - let program_string = include_str!("../.resources/basic/main.leo"); - - let candidate = Ast::new(filepath, program_name, program_string).to_string(); - - let expected = JsValue::from_str(expected); - let candidate = JsValue::from_serde(&candidate).unwrap(); - - assert_eq!(expected, candidate); - } -} diff --git a/wasm/src/compiler.rs b/wasm/src/compiler.rs deleted file mode 100644 index e45868fad1..0000000000 --- a/wasm/src/compiler.rs +++ /dev/null @@ -1,88 +0,0 @@ -// 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::{asg::Asg, ast::Ast}; -use leo_compiler::generate_constraints; -// use leo_synthesizer::CircuitSynthesizer; - -// use snarkvm_curves::Bls12_377; - -use std::path::Path; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -pub struct Compiler(String); - -#[wasm_bindgen] -impl Compiler { - #[wasm_bindgen(constructor)] - pub fn new(filepath: &str, program_name: &str, program_string: &str) -> Self { - let ast = Ast::new(filepath, program_name, program_string).unwrap(); - let asg = Asg::from(&ast); - - // Generate the program on the constraint system and verify correctness - { - // let mut cs = CircuitSynthesizer:: { - // at: vec![], - // bt: vec![], - // ct: vec![], - // input_assignment: vec![], - // aux_assignment: vec![], - // }; - // let temporary_program = program.clone(); - // let output = temporary_program.compile_constraints(&mut cs)?; - // - // tracing::debug!("Compiled output - {:#?}", output); - // tracing::info!("Number of constraints - {:#?}", cs.num_constraints()); - // - // // Serialize the circuit - // let circuit_object = SerializedCircuit::from(cs); - // let json = circuit_object.to_json_string().unwrap(); - // // println!("json: {}", json); - // - // // Write serialized circuit to circuit `.json` file. - // let circuit_file = CircuitFile::new(&package_name); - // circuit_file.write_to(&path, json)?; - - // Check that we can read the serialized circuit file - // let serialized = circuit_file.read_from(&package_path)?; - - // Deserialize the circuit - // let deserialized = SerializedCircuit::from_json_string(&serialized).unwrap(); - // let _circuit_synthesizer = CircuitSynthesizer::::try_from(deserialized).unwrap(); - // println!("deserialized {:?}", circuit_synthesizer.num_constraints()); - } - - // TODO (howardwu): Support program inputs. - generate_constraints(cs, &asg.as_ref().unwrap(), &Input::new()).unwrap(); - Self(ast.to_string()) - } - - #[wasm_bindgen] - pub fn to_string(&self) -> String { - self.0.clone() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use wasm_bindgen_test::*; - - #[wasm_bindgen_test] - fn ast_test() {} -} diff --git a/wasm/src/grammar.rs b/wasm/src/grammar.rs deleted file mode 100644 index d181661446..0000000000 --- a/wasm/src/grammar.rs +++ /dev/null @@ -1,60 +0,0 @@ -// 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_ast::Ast as LeoAst; -use leo_grammar::Grammar as LeoGrammar; - -use std::path::Path; -use wasm_bindgen::prelude::*; - -#[wasm_bindgen] -pub struct Grammar(pub(crate) String); - -#[wasm_bindgen] -impl Grammar { - #[wasm_bindgen(constructor)] - pub fn new(filepath: &str, program_string: &str) -> Self { - let grammar = LeoGrammar::new(&Path::new(filepath), &program_string).unwrap(); - Self(grammar.to_json_string().unwrap()) - } - - #[wasm_bindgen] - pub fn to_string(&self) -> String { - self.0.clone() - } -} - -#[cfg(test)] -mod tests { - use super::*; - - use wasm_bindgen_test::*; - - #[wasm_bindgen_test] - fn grammar_test() { - let expected = include_str!("../.resources/basic/expected_grammar.json"); - - let filepath = "../.resources/basic/main.leo"; - let program_string = include_str!("../.resources/basic/main.leo"); - - let candidate = Grammar::new(filepath, program_string).to_string(); - - let expected = JsValue::from_str(expected); - let candidate = JsValue::from_serde(&candidate).unwrap(); - - assert_eq!(expected, candidate); - } -} diff --git a/wasm/src/lib.rs b/wasm/src/lib.rs deleted file mode 100644 index e702ef0d4a..0000000000 --- a/wasm/src/lib.rs +++ /dev/null @@ -1,27 +0,0 @@ -// 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 asg; -pub use asg::*; - -pub mod ast; -pub use ast::*; - -pub mod grammar; -pub use grammar::*; - -// pub mod compiler; -// pub use compiler::*; From 2bfb64f83ed2180e3ff46d72b281363f83814bba Mon Sep 17 00:00:00 2001 From: howardwu Date: Sat, 27 Feb 2021 13:21:29 -0800 Subject: [PATCH 29/92] Update synthesizer to support new terminology --- compiler/src/value/field/field_type.rs | 6 ++-- .../src/value/group/targets/edwards_bls12.rs | 6 ++-- leo/commands/build.rs | 4 +-- synthesizer/src/circuit_synthesizer.rs | 28 ++++++++++------ synthesizer/src/serialized_circuit.rs | 32 +++++++++---------- synthesizer/src/serialized_index.rs | 12 +++---- 6 files changed, 48 insertions(+), 40 deletions(-) diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index f38c82e155..db192bbad9 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -23,7 +23,7 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::{ curves::PrimeField, gadgets::{ - curves::{FieldGadget, FpGadget}, + curves::{AllocatedFp, FieldGadget, FpGadget}, r1cs::ConstraintSystem, utilities::{ alloc::AllocGadget, @@ -187,7 +187,7 @@ impl FieldType { match self { FieldType::Constant(constant) => FpGadget::alloc(&mut cs.ns(|| format!("{:?}", constant)), || Ok(constant)), FieldType::Allocated(allocated) => FpGadget::alloc(&mut cs.ns(|| format!("{:?}", allocated)), || { - allocated.value.ok_or(SynthesisError::AssignmentMissing) + allocated.get_value().ok_or(SynthesisError::AssignmentMissing) }), } } @@ -273,7 +273,7 @@ impl ConditionalEqGadget for FieldType { // c - a = a - c (FieldType::Constant(constant_value), FieldType::Allocated(allocated_value)) | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => { - let constant_gadget = FpGadget::from(&mut cs, constant_value); + let constant_gadget = FpGadget::from(AllocatedFp::from(&mut cs, constant_value)); constant_gadget.conditional_enforce_equal(cs, allocated_value, condition) } diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 85c2b391e3..b9176f90f3 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -26,7 +26,7 @@ use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; use snarkvm_models::{ curves::{AffineCurve, Fp256, One, TEModelParameters, Zero}, gadgets::{ - curves::{FieldGadget, FpGadget, GroupGadget}, + curves::{AllocatedFp, FieldGadget, FpGadget, GroupGadget}, r1cs::ConstraintSystem, utilities::{ alloc::AllocGadget, @@ -459,8 +459,8 @@ impl ConditionalEqGadget for EdwardsGroupType { // c - a = a - c (EdwardsGroupType::Constant(constant_value), EdwardsGroupType::Allocated(allocated_value)) | (EdwardsGroupType::Allocated(allocated_value), EdwardsGroupType::Constant(constant_value)) => { - let x = FpGadget::from(&mut cs, &constant_value.x); - let y = FpGadget::from(&mut cs, &constant_value.y); + let x = FpGadget::from(AllocatedFp::from(&mut cs, &constant_value.x)); + let y = FpGadget::from(AllocatedFp::from(&mut cs, &constant_value.y)); let constant_gadget = EdwardsBlsGadget::new(x, y); constant_gadget.conditional_enforce_equal(cs, allocated_value, condition) diff --git a/leo/commands/build.rs b/leo/commands/build.rs index f29dac7739..dd3d0f3c17 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -125,8 +125,8 @@ impl Command for Build { at: vec![], bt: vec![], ct: vec![], - input_assignment: vec![], - aux_assignment: vec![], + public_variables: vec![], + private_variables: vec![], }; let temporary_program = program.clone(); let output = temporary_program.compile_constraints(&mut cs)?; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 1cf17b9261..9a59c44e12 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -27,8 +27,8 @@ pub struct CircuitSynthesizer { pub ct: Vec>, // Assignments of variables - pub input_assignment: Vec, - pub aux_assignment: Vec, + pub public_variables: Vec, + pub private_variables: Vec, } impl ConstraintSystem for CircuitSynthesizer { @@ -41,9 +41,9 @@ impl ConstraintSystem for CircuitSynthesizer { A: FnOnce() -> AR, AR: AsRef, { - let index = self.aux_assignment.len(); - self.aux_assignment.push(f()?); - Ok(Variable::new_unchecked(Index::Aux(index))) + let index = self.private_variables.len(); + self.private_variables.push(f()?); + Ok(Variable::new_unchecked(Index::Private(index))) } #[inline] @@ -53,9 +53,9 @@ impl ConstraintSystem for CircuitSynthesizer { A: FnOnce() -> AR, AR: AsRef, { - let index = self.input_assignment.len(); - self.input_assignment.push(f()?); - Ok(Variable::new_unchecked(Index::Input(index))) + let index = self.public_variables.len(); + self.public_variables.push(f()?); + Ok(Variable::new_unchecked(Index::Public(index))) } #[inline] @@ -99,13 +99,21 @@ impl ConstraintSystem for CircuitSynthesizer { fn num_constraints(&self) -> usize { self.at.len() } + + fn num_public_variables(&self) -> usize { + self.public_variables.len() + } + + fn num_private_variables(&self) -> usize { + self.private_variables.len() + } } fn push_constraints(l: LinearCombination, constraints: &mut [Vec<(F, Index)>], this_constraint: usize) { for (var, coeff) in l.as_ref() { match var.get_unchecked() { - Index::Input(i) => constraints[this_constraint].push((*coeff, Index::Input(i))), - Index::Aux(i) => constraints[this_constraint].push((*coeff, Index::Aux(i))), + Index::Public(i) => constraints[this_constraint].push((*coeff, Index::Public(i))), + Index::Private(i) => constraints[this_constraint].push((*coeff, Index::Private(i))), } } } diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index ef8df3f619..de3fe6d57b 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -28,12 +28,12 @@ use crate::{CircuitSynthesizer, SerializedField, SerializedIndex}; #[derive(Serialize, Deserialize)] pub struct SerializedCircuit { - pub num_inputs: usize, - pub num_aux: usize, + pub num_public_variables: usize, + pub num_private_variables: usize, pub num_constraints: usize, - pub input_assignment: Vec, - pub aux_assignment: Vec, + pub public_variables: Vec, + pub private_variables: Vec, pub at: Vec>, pub bt: Vec>, @@ -52,8 +52,8 @@ impl SerializedCircuit { impl From> for SerializedCircuit { fn from(synthesizer: CircuitSynthesizer) -> Self { - let num_inputs = synthesizer.input_assignment.len(); - let num_aux = synthesizer.aux_assignment.len(); + let num_public_variables = synthesizer.num_public_variables(); + let num_private_variables = synthesizer.num_private_variables(); let num_constraints = synthesizer.num_constraints(); // Serialize assignments @@ -61,8 +61,8 @@ impl From> for SerializedCircuit { assignments.iter().map(SerializedField::from).collect() } - let input_assignment = get_serialized_assignments::(&synthesizer.input_assignment); - let aux_assignment = get_serialized_assignments::(&synthesizer.aux_assignment); + let public_variables = get_serialized_assignments::(&synthesizer.public_variables); + let private_variables = get_serialized_assignments::(&synthesizer.private_variables); // Serialize constraints fn get_serialized_constraints( @@ -102,11 +102,11 @@ impl From> for SerializedCircuit { } Self { - num_inputs, - num_aux, + num_public_variables, + num_private_variables, num_constraints, - input_assignment, - aux_assignment, + public_variables, + private_variables, at, bt, ct, @@ -133,8 +133,8 @@ impl TryFrom for CircuitSynthesizer { Ok(deserialized) } - let input_assignment = get_deserialized_assignments(&serialized.input_assignment)?; - let aux_assignment = get_deserialized_assignments(&serialized.aux_assignment)?; + let public_variables = get_deserialized_assignments(&serialized.public_variables)?; + let private_variables = get_deserialized_assignments(&serialized.private_variables)?; // Deserialize constraints fn get_deserialized_constraints( @@ -177,8 +177,8 @@ impl TryFrom for CircuitSynthesizer { at, bt, ct, - input_assignment, - aux_assignment, + public_variables, + private_variables, }) } } diff --git a/synthesizer/src/serialized_index.rs b/synthesizer/src/serialized_index.rs index 029edef18a..ab42aeef0c 100644 --- a/synthesizer/src/serialized_index.rs +++ b/synthesizer/src/serialized_index.rs @@ -19,15 +19,15 @@ use snarkvm_models::gadgets::r1cs::Index; #[derive(Serialize, Deserialize)] pub enum SerializedIndex { - Input(usize), - Aux(usize), + Public(usize), + Private(usize), } impl From for SerializedIndex { fn from(index: Index) -> Self { match index { - Index::Input(idx) => Self::Input(idx), - Index::Aux(idx) => Self::Aux(idx), + Index::Public(idx) => Self::Public(idx), + Index::Private(idx) => Self::Private(idx), } } } @@ -35,8 +35,8 @@ impl From for SerializedIndex { impl From<&SerializedIndex> for Index { fn from(serialized_index: &SerializedIndex) -> Self { match serialized_index { - SerializedIndex::Input(idx) => Index::Input(*idx), - SerializedIndex::Aux(idx) => Index::Aux(*idx), + SerializedIndex::Public(idx) => Index::Public(*idx), + SerializedIndex::Private(idx) => Index::Private(*idx), } } } From b86e8f01e9eb8a9b054af4a1fd22196202f4907f Mon Sep 17 00:00:00 2001 From: howardwu Date: Sat, 27 Feb 2021 13:22:37 -0800 Subject: [PATCH 30/92] Adds README.md --- synthesizer/LICENSE.md | 596 +++++++++++++++++++++++++++++++++++++++++ synthesizer/README.md | 5 + 2 files changed, 601 insertions(+) create mode 100644 synthesizer/LICENSE.md create mode 100644 synthesizer/README.md diff --git a/synthesizer/LICENSE.md b/synthesizer/LICENSE.md new file mode 100644 index 0000000000..b95c626e2a --- /dev/null +++ b/synthesizer/LICENSE.md @@ -0,0 +1,596 @@ +GNU General Public License +========================== + +Version 3, 29 June 2007 + +Copyright © 2007 Free Software Foundation, Inc. <> + +Everyone is permitted to copy and distribute verbatim copies of this license +document, but changing it is not allowed. + +## Preamble + +The GNU General Public License is a free, copyleft license for software and other +kinds of works. + +The licenses for most software and other practical works are designed to take away +your freedom to share and change the works. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change all versions of a +program--to make sure it remains free software for all its users. We, the Free +Software Foundation, use the GNU General Public License for most of our software; it +applies also to any other work released this way by its authors. You can apply it to +your programs, too. + +When we speak of free software, we are referring to freedom, not price. Our General +Public Licenses are designed to make sure that you have the freedom to distribute +copies of free software (and charge for them if you wish), that you receive source +code or can get it if you want it, that you can change the software or use pieces of +it in new free programs, and that you know you can do these things. + +To protect your rights, we need to prevent others from denying you these rights or +asking you to surrender the rights. Therefore, you have certain responsibilities if +you distribute copies of the software, or if you modify it: responsibilities to +respect the freedom of others. + +For example, if you distribute copies of such a program, whether gratis or for a fee, +you must pass on to the recipients the same freedoms that you received. You must make +sure that they, too, receive or can get the source code. And you must show them these +terms so they know their rights. + +Developers that use the GNU GPL protect your rights with two steps: **(1)** assert +copyright on the software, and **(2)** offer you this License giving you legal permission +to copy, distribute and/or modify it. + +For the developers' and authors' protection, the GPL clearly explains that there is +no warranty for this free software. For both users' and authors' sake, the GPL +requires that modified versions be marked as changed, so that their problems will not +be attributed erroneously to authors of previous versions. + +Some devices are designed to deny users access to install or run modified versions of +the software inside them, although the manufacturer can do so. This is fundamentally +incompatible with the aim of protecting users' freedom to change the software. The +systematic pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we have designed +this version of the GPL to prohibit the practice for those products. If such problems +arise substantially in other domains, we stand ready to extend this provision to +those domains in future versions of the GPL, as needed to protect the freedom of +users. + +Finally, every program is threatened constantly by software patents. States should +not allow patents to restrict development and use of software on general-purpose +computers, but in those that do, we wish to avoid the special danger that patents +applied to a free program could make it effectively proprietary. To prevent this, the +GPL assures that patents cannot be used to render the program non-free. + +The precise terms and conditions for copying, distribution and modification follow. + +## TERMS AND CONDITIONS + +### 0. Definitions + +“This License” refers to version 3 of the GNU General Public License. + +“Copyright” also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + +“The Program” refers to any copyrightable work licensed under this +License. Each licensee is addressed as “you”. “Licensees” and +“recipients” may be individuals or organizations. + +To “modify” a work means to copy from or adapt all or part of the work in +a fashion requiring copyright permission, other than the making of an exact copy. The +resulting work is called a “modified version” of the earlier work or a +work “based on” the earlier work. + +A “covered work” means either the unmodified Program or a work based on +the Program. + +To “propagate” a work means to do anything with it that, without +permission, would make you directly or secondarily liable for infringement under +applicable copyright law, except executing it on a computer or modifying a private +copy. Propagation includes copying, distribution (with or without modification), +making available to the public, and in some countries other activities as well. + +To “convey” a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through a computer +network, with no transfer of a copy, is not conveying. + +An interactive user interface displays “Appropriate Legal Notices” to the +extent that it includes a convenient and prominently visible feature that **(1)** +displays an appropriate copyright notice, and **(2)** tells the user that there is no +warranty for the work (except to the extent that warranties are provided), that +licensees may convey the work under this License, and how to view a copy of this +License. If the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + +### 1. Source Code + +The “source code” for a work means the preferred form of the work for +making modifications to it. “Object code” means any non-source form of a +work. + +A “Standard Interface” means an interface that either is an official +standard defined by a recognized standards body, or, in the case of interfaces +specified for a particular programming language, one that is widely used among +developers working in that language. + +The “System Libraries” of an executable work include anything, other than +the work as a whole, that **(a)** is included in the normal form of packaging a Major +Component, but which is not part of that Major Component, and **(b)** serves only to +enable use of the work with that Major Component, or to implement a Standard +Interface for which an implementation is available to the public in source code form. +A “Major Component”, in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system (if any) on which +the executable work runs, or a compiler used to produce the work, or an object code +interpreter used to run it. + +The “Corresponding Source” for a work in object code form means all the +source code needed to generate, install, and (for an executable work) run the object +code and to modify the work, including scripts to control those activities. However, +it does not include the work's System Libraries, or general-purpose tools or +generally available free programs which are used unmodified in performing those +activities but which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for the work, and +the source code for shared libraries and dynamically linked subprograms that the work +is specifically designed to require, such as by intimate data communication or +control flow between those subprograms and other parts of the work. + +The Corresponding Source need not include anything that users can regenerate +automatically from other parts of the Corresponding Source. + +The Corresponding Source for a work in source code form is that same work. + +### 2. Basic Permissions + +All rights granted under this License are granted for the term of copyright on the +Program, and are irrevocable provided the stated conditions are met. This License +explicitly affirms your unlimited permission to run the unmodified Program. The +output from running a covered work is covered by this License only if the output, +given its content, constitutes a covered work. This License acknowledges your rights +of fair use or other equivalent, as provided by copyright law. + +You may make, run and propagate covered works that you do not convey, without +conditions so long as your license otherwise remains in force. You may convey covered +works to others for the sole purpose of having them make modifications exclusively +for you, or provide you with facilities for running those works, provided that you +comply with the terms of this License in conveying all material for which you do not +control copyright. Those thus making or running the covered works for you must do so +exclusively on your behalf, under your direction and control, on terms that prohibit +them from making any copies of your copyrighted material outside their relationship +with you. + +Conveying under any other circumstances is permitted solely under the conditions +stated below. Sublicensing is not allowed; section 10 makes it unnecessary. + +### 3. Protecting Users' Legal Rights From Anti-Circumvention Law + +No covered work shall be deemed part of an effective technological measure under any +applicable law fulfilling obligations under article 11 of the WIPO copyright treaty +adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention +of such measures. + +When you convey a covered work, you waive any legal power to forbid circumvention of +technological measures to the extent such circumvention is effected by exercising +rights under this License with respect to the covered work, and you disclaim any +intention to limit operation or modification of the work as a means of enforcing, +against the work's users, your or third parties' legal rights to forbid circumvention +of technological measures. + +### 4. Conveying Verbatim Copies + +You may convey verbatim copies of the Program's source code as you receive it, in any +medium, provided that you conspicuously and appropriately publish on each copy an +appropriate copyright notice; keep intact all notices stating that this License and +any non-permissive terms added in accord with section 7 apply to the code; keep +intact all notices of the absence of any warranty; and give all recipients a copy of +this License along with the Program. + +You may charge any price or no price for each copy that you convey, and you may offer +support or warranty protection for a fee. + +### 5. Conveying Modified Source Versions + +You may convey a work based on the Program, or the modifications to produce it from +the Program, in the form of source code under the terms of section 4, provided that +you also meet all of these conditions: + +* **a)** The work must carry prominent notices stating that you modified it, and giving a +relevant date. +* **b)** The work must carry prominent notices stating that it is released under this +License and any conditions added under section 7. This requirement modifies the +requirement in section 4 to “keep intact all notices”. +* **c)** You must license the entire work, as a whole, under this License to anyone who +comes into possession of a copy. This License will therefore apply, along with any +applicable section 7 additional terms, to the whole of the work, and all its parts, +regardless of how they are packaged. This License gives no permission to license the +work in any other way, but it does not invalidate such permission if you have +separately received it. +* **d)** If the work has interactive user interfaces, each must display Appropriate Legal +Notices; however, if the Program has interactive interfaces that do not display +Appropriate Legal Notices, your work need not make them do so. + +A compilation of a covered work with other separate and independent works, which are +not by their nature extensions of the covered work, and which are not combined with +it such as to form a larger program, in or on a volume of a storage or distribution +medium, is called an “aggregate” if the compilation and its resulting +copyright are not used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work in an aggregate +does not cause this License to apply to the other parts of the aggregate. + +### 6. Conveying Non-Source Forms + +You may convey a covered work in object code form under the terms of sections 4 and +5, provided that you also convey the machine-readable Corresponding Source under the +terms of this License, in one of these ways: + +* **a)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by the Corresponding Source fixed on a +durable physical medium customarily used for software interchange. +* **b)** Convey the object code in, or embodied in, a physical product (including a +physical distribution medium), accompanied by a written offer, valid for at least +three years and valid for as long as you offer spare parts or customer support for +that product model, to give anyone who possesses the object code either **(1)** a copy of +the Corresponding Source for all the software in the product that is covered by this +License, on a durable physical medium customarily used for software interchange, for +a price no more than your reasonable cost of physically performing this conveying of +source, or **(2)** access to copy the Corresponding Source from a network server at no +charge. +* **c)** Convey individual copies of the object code with a copy of the written offer to +provide the Corresponding Source. This alternative is allowed only occasionally and +noncommercially, and only if you received the object code with such an offer, in +accord with subsection 6b. +* **d)** Convey the object code by offering access from a designated place (gratis or for +a charge), and offer equivalent access to the Corresponding Source in the same way +through the same place at no further charge. You need not require recipients to copy +the Corresponding Source along with the object code. If the place to copy the object +code is a network server, the Corresponding Source may be on a different server +(operated by you or a third party) that supports equivalent copying facilities, +provided you maintain clear directions next to the object code saying where to find +the Corresponding Source. Regardless of what server hosts the Corresponding Source, +you remain obligated to ensure that it is available for as long as needed to satisfy +these requirements. +* **e)** Convey the object code using peer-to-peer transmission, provided you inform +other peers where the object code and Corresponding Source of the work are being +offered to the general public at no charge under subsection 6d. + +A separable portion of the object code, whose source code is excluded from the +Corresponding Source as a System Library, need not be included in conveying the +object code work. + +A “User Product” is either **(1)** a “consumer product”, which +means any tangible personal property which is normally used for personal, family, or +household purposes, or **(2)** anything designed or sold for incorporation into a +dwelling. In determining whether a product is a consumer product, doubtful cases +shall be resolved in favor of coverage. For a particular product received by a +particular user, “normally used” refers to a typical or common use of +that class of product, regardless of the status of the particular user or of the way +in which the particular user actually uses, or expects or is expected to use, the +product. A product is a consumer product regardless of whether the product has +substantial commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + +“Installation Information” for a User Product means any methods, +procedures, authorization keys, or other information required to install and execute +modified versions of a covered work in that User Product from a modified version of +its Corresponding Source. The information must suffice to ensure that the continued +functioning of the modified object code is in no case prevented or interfered with +solely because modification has been made. + +If you convey an object code work under this section in, or with, or specifically for +use in, a User Product, and the conveying occurs as part of a transaction in which +the right of possession and use of the User Product is transferred to the recipient +in perpetuity or for a fixed term (regardless of how the transaction is +characterized), the Corresponding Source conveyed under this section must be +accompanied by the Installation Information. But this requirement does not apply if +neither you nor any third party retains the ability to install modified object code +on the User Product (for example, the work has been installed in ROM). + +The requirement to provide Installation Information does not include a requirement to +continue to provide support service, warranty, or updates for a work that has been +modified or installed by the recipient, or for the User Product in which it has been +modified or installed. Access to a network may be denied when the modification itself +materially and adversely affects the operation of the network or violates the rules +and protocols for communication across the network. + +Corresponding Source conveyed, and Installation Information provided, in accord with +this section must be in a format that is publicly documented (and with an +implementation available to the public in source code form), and must require no +special password or key for unpacking, reading or copying. + +### 7. Additional Terms + +“Additional permissions” are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. Additional +permissions that are applicable to the entire Program shall be treated as though they +were included in this License, to the extent that they are valid under applicable +law. If additional permissions apply only to part of the Program, that part may be +used separately under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + +When you convey a copy of a covered work, you may at your option remove any +additional permissions from that copy, or from any part of it. (Additional +permissions may be written to require their own removal in certain cases when you +modify the work.) You may place additional permissions on material, added by you to a +covered work, for which you have or can give appropriate copyright permission. + +Notwithstanding any other provision of this License, for material you add to a +covered work, you may (if authorized by the copyright holders of that material) +supplement the terms of this License with terms: + +* **a)** Disclaiming warranty or limiting liability differently from the terms of +sections 15 and 16 of this License; or +* **b)** Requiring preservation of specified reasonable legal notices or author +attributions in that material or in the Appropriate Legal Notices displayed by works +containing it; or +* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that +modified versions of such material be marked in reasonable ways as different from the +original version; or +* **d)** Limiting the use for publicity purposes of names of licensors or authors of the +material; or +* **e)** Declining to grant rights under trademark law for use of some trade names, +trademarks, or service marks; or +* **f)** Requiring indemnification of licensors and authors of that material by anyone +who conveys the material (or modified versions of it) with contractual assumptions of +liability to the recipient, for any liability that these contractual assumptions +directly impose on those licensors and authors. + +All other non-permissive additional terms are considered “further +restrictions” within the meaning of section 10. If the Program as you received +it, or any part of it, contains a notice stating that it is governed by this License +along with a term that is a further restriction, you may remove that term. If a +license document contains a further restriction but permits relicensing or conveying +under this License, you may add to a covered work material governed by the terms of +that license document, provided that the further restriction does not survive such +relicensing or conveying. + +If you add terms to a covered work in accord with this section, you must place, in +the relevant source files, a statement of the additional terms that apply to those +files, or a notice indicating where to find the applicable terms. + +Additional terms, permissive or non-permissive, may be stated in the form of a +separately written license, or stated as exceptions; the above requirements apply +either way. + +### 8. Termination + +You may not propagate or modify a covered work except as expressly provided under +this License. Any attempt otherwise to propagate or modify it is void, and will +automatically terminate your rights under this License (including any patent licenses +granted under the third paragraph of section 11). + +However, if you cease all violation of this License, then your license from a +particular copyright holder is reinstated **(a)** provisionally, unless and until the +copyright holder explicitly and finally terminates your license, and **(b)** permanently, +if the copyright holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + +Moreover, your license from a particular copyright holder is reinstated permanently +if the copyright holder notifies you of the violation by some reasonable means, this +is the first time you have received notice of violation of this License (for any +work) from that copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + +Termination of your rights under this section does not terminate the licenses of +parties who have received copies or rights from you under this License. If your +rights have been terminated and not permanently reinstated, you do not qualify to +receive new licenses for the same material under section 10. + +### 9. Acceptance Not Required for Having Copies + +You are not required to accept this License in order to receive or run a copy of the +Program. Ancillary propagation of a covered work occurring solely as a consequence of +using peer-to-peer transmission to receive a copy likewise does not require +acceptance. However, nothing other than this License grants you permission to +propagate or modify any covered work. These actions infringe copyright if you do not +accept this License. Therefore, by modifying or propagating a covered work, you +indicate your acceptance of this License to do so. + +### 10. Automatic Licensing of Downstream Recipients + +Each time you convey a covered work, the recipient automatically receives a license +from the original licensors, to run, modify and propagate that work, subject to this +License. You are not responsible for enforcing compliance by third parties with this +License. + +An “entity transaction” is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an organization, or +merging organizations. If propagation of a covered work results from an entity +transaction, each party to that transaction who receives a copy of the work also +receives whatever licenses to the work the party's predecessor in interest had or +could give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if the predecessor +has it or can get it with reasonable efforts. + +You may not impose any further restrictions on the exercise of the rights granted or +affirmed under this License. For example, you may not impose a license fee, royalty, +or other charge for exercise of rights granted under this License, and you may not +initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging +that any patent claim is infringed by making, using, selling, offering for sale, or +importing the Program or any portion of it. + +### 11. Patents + +A “contributor” is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The work thus +licensed is called the contributor's “contributor version”. + +A contributor's “essential patent claims” are all patent claims owned or +controlled by the contributor, whether already acquired or hereafter acquired, that +would be infringed by some manner, permitted by this License, of making, using, or +selling its contributor version, but do not include claims that would be infringed +only as a consequence of further modification of the contributor version. For +purposes of this definition, “control” includes the right to grant patent +sublicenses in a manner consistent with the requirements of this License. + +Each contributor grants you a non-exclusive, worldwide, royalty-free patent license +under the contributor's essential patent claims, to make, use, sell, offer for sale, +import and otherwise run, modify and propagate the contents of its contributor +version. + +In the following three paragraphs, a “patent license” is any express +agreement or commitment, however denominated, not to enforce a patent (such as an +express permission to practice a patent or covenant not to sue for patent +infringement). To “grant” such a patent license to a party means to make +such an agreement or commitment not to enforce a patent against the party. + +If you convey a covered work, knowingly relying on a patent license, and the +Corresponding Source of the work is not available for anyone to copy, free of charge +and under the terms of this License, through a publicly available network server or +other readily accessible means, then you must either **(1)** cause the Corresponding +Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the +patent license for this particular work, or **(3)** arrange, in a manner consistent with +the requirements of this License, to extend the patent license to downstream +recipients. “Knowingly relying” means you have actual knowledge that, but +for the patent license, your conveying the covered work in a country, or your +recipient's use of the covered work in a country, would infringe one or more +identifiable patents in that country that you have reason to believe are valid. + +If, pursuant to or in connection with a single transaction or arrangement, you +convey, or propagate by procuring conveyance of, a covered work, and grant a patent +license to some of the parties receiving the covered work authorizing them to use, +propagate, modify or convey a specific copy of the covered work, then the patent +license you grant is automatically extended to all recipients of the covered work and +works based on it. + +A patent license is “discriminatory” if it does not include within the +scope of its coverage, prohibits the exercise of, or is conditioned on the +non-exercise of one or more of the rights that are specifically granted under this +License. You may not convey a covered work if you are a party to an arrangement with +a third party that is in the business of distributing software, under which you make +payment to the third party based on the extent of your activity of conveying the +work, and under which the third party grants, to any of the parties who would receive +the covered work from you, a discriminatory patent license **(a)** in connection with +copies of the covered work conveyed by you (or copies made from those copies), or **(b)** +primarily for and in connection with specific products or compilations that contain +the covered work, unless you entered into that arrangement, or that patent license +was granted, prior to 28 March 2007. + +Nothing in this License shall be construed as excluding or limiting any implied +license or other defenses to infringement that may otherwise be available to you +under applicable patent law. + +### 12. No Surrender of Others' Freedom + +If conditions are imposed on you (whether by court order, agreement or otherwise) +that contradict the conditions of this License, they do not excuse you from the +conditions of this License. If you cannot convey a covered work so as to satisfy +simultaneously your obligations under this License and any other pertinent +obligations, then as a consequence you may not convey it at all. For example, if you +agree to terms that obligate you to collect a royalty for further conveying from +those to whom you convey the Program, the only way you could satisfy both those terms +and this License would be to refrain entirely from conveying the Program. + +### 13. Use with the GNU Affero General Public License + +Notwithstanding any other provision of this License, you have permission to link or +combine any covered work with a work licensed under version 3 of the GNU Affero +General Public License into a single combined work, and to convey the resulting work. +The terms of this License will continue to apply to the part which is the covered +work, but the special requirements of the GNU Affero General Public License, section +13, concerning interaction through a network will apply to the combination as such. + +### 14. Revised Versions of this License + +The Free Software Foundation may publish revised and/or new versions of the GNU +General Public License from time to time. Such new versions will be similar in spirit +to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Program specifies that +a certain numbered version of the GNU General Public License “or any later +version” applies to it, you have the option of following the terms and +conditions either of that numbered version or of any later version published by the +Free Software Foundation. If the Program does not specify a version number of the GNU +General Public License, you may choose any version ever published by the Free +Software Foundation. + +If the Program specifies that a proxy can decide which future versions of the GNU +General Public License can be used, that proxy's public statement of acceptance of a +version permanently authorizes you to choose that version for the Program. + +Later license versions may give you additional or different permissions. However, no +additional obligations are imposed on any author or copyright holder as a result of +your choosing to follow a later version. + +### 15. Disclaimer of Warranty + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER +EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE +QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE +DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + +### 16. Limitation of Liability + +IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY +COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS +PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, +INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE +OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE +WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + +### 17. Interpretation of Sections 15 and 16 + +If the disclaimer of warranty and limitation of liability provided above cannot be +given local legal effect according to their terms, reviewing courts shall apply local +law that most closely approximates an absolute waiver of all civil liability in +connection with the Program, unless a warranty or assumption of liability accompanies +a copy of the Program in return for a fee. + +_END OF TERMS AND CONDITIONS_ + +## How to Apply These Terms to Your New Programs + +If you develop a new program, and you want it to be of the greatest possible use to +the public, the best way to achieve this is to make it free software which everyone +can redistribute and change under these terms. + +To do so, attach the following notices to the program. It is safest to attach them +to the start of each source file to most effectively state the exclusion of warranty; +and each file should have at least the “copyright” line and a pointer to +where the full notice is found. + + + Copyright (C) + + This program 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. + + This program 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 this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + +If the program does terminal interaction, make it output a short notice like this +when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type 'show c' for details. + +The hypothetical commands `show w` and `show c` should show the appropriate parts of +the General Public License. Of course, your program's commands might be different; +for a GUI interface, you would use an “about box”. + +You should also get your employer (if you work as a programmer) or school, if any, to +sign a “copyright disclaimer” for the program, if necessary. For more +information on this, and how to apply and follow the GNU GPL, see +<>. + +The GNU General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may consider it +more useful to permit linking proprietary applications with the library. If this is +what you want to do, use the GNU Lesser General Public License instead of this +License. But first, please read +<>. diff --git a/synthesizer/README.md b/synthesizer/README.md new file mode 100644 index 0000000000..4e4671a2ec --- /dev/null +++ b/synthesizer/README.md @@ -0,0 +1,5 @@ +# leo-synthesizer + +[![Crates.io](https://img.shields.io/crates/v/leo-synthesizer.svg?color=neon)](https://crates.io/crates/leo-synthesizer) +[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS) +[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md) From 315938ec457187731efd35cff1b5a4bb48232086 Mon Sep 17 00:00:00 2001 From: howardwu Date: Sat, 27 Feb 2021 13:24:00 -0800 Subject: [PATCH 31/92] Removes unused travis --- .travis.yml | 70 ------------------------------------- .travis/travis-snarkos.enc | Bin 1840 -> 0 bytes 2 files changed, 70 deletions(-) delete mode 100644 .travis.yml delete mode 100644 .travis/travis-snarkos.enc diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0962bf1c94..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,70 +0,0 @@ -language: rust - -before_install: - - set -e - - export SCCACHE_CACHE_SIZE=200M - - export SCCACHE_DIR="$TRAVIS_HOME/.cache/sccache" - - mkdir "$TRAVIS_HOME/.bin" - - wget https://github.com/mozilla/sccache/releases/download/0.2.13/sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz - - tar -C "$TRAVIS_HOME/.bin" -xvf sccache-0.2.13-x86_64-unknown-linux-musl.tar.gz - - mv $TRAVIS_HOME/.bin/sccache-0.2.13-x86_64-unknown-linux-musl/sccache $TRAVIS_HOME/.bin/sccache - - export PATH="$PATH:$TRAVIS_HOME/.bin" - - export RUSTC_WRAPPER="sccache" - - | - declare -r SSH_FILE="$(mktemp -u $HOME/.ssh/XXXXX)" - openssl aes-256-cbc -K $encrypted_beefc4a47cdc_key -iv $encrypted_beefc4a47cdc_iv -in .travis/travis-snarkvm.enc -out $SSH_FILE -d - chmod 600 "$SSH_FILE" \ - && printf "%s\n" \ - "Host github.com" \ - " IdentityFile $SSH_FILE" \ - " LogLevel ERROR" >> ~/.ssh/config - - git clone --progress --verbose git@github.com:AleoHQ/snarkOS.git - - mv snarkOS .. - -cache: - directories: - - $TRAVIS_HOME/.cache/sccache - - $TRAVIS_HOME/.cargo - -# See https://levans.fr/rust_travis_cache.html -before_cache: - - rm -rf "$TRAVIS_HOME/.cargo/registry" - -after_script: - - (sccache -s||true) - - set +e - -matrix: - fast_finish: true - include: - - rust: stable - env: TEST_COVERAGE=1 - addons: - apt: - packages: - - libcurl4-openssl-dev - - libelf-dev - - libdw-dev - - cmake - - gcc - - binutils-dev - - libiberty-dev - script: - - cargo test --all - after_success: - - wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz - - tar xzf master.tar.gz && cd kcov-master - - mkdir build && cd build && cmake .. && make && sudo make install - - cd ../.. && rm -rf kcov-master - - for file in target/debug/deps/*-*; do if [[ "$file" != *\.* ]]; then mkdir -p "target/cov/$(basename $file)"; kcov --exclude-pattern=/.cargo,/usr/lib --verify "target/cov/$(basename $file)" "$file"; fi done - - bash <(curl -s https://codecov.io/bash) - - echo "Uploaded code coverage" - - rust: nightly-2020-03-18 - install: - - rustup component add rustfmt - script: - - cargo fmt -- --check - - cargo test --all - -script: - - echo "leo" diff --git a/.travis/travis-snarkos.enc b/.travis/travis-snarkos.enc deleted file mode 100644 index 08b0365ab08abe2d7d67f91bc220c01d7ac9fa52..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1840 zcmV-02haGE1S_g=*Kd5az~h0{M$>1Zm6Yn|&)i<{;XDd0$=aah$A3PlvfCcQzvN(; z2;Xr&zu?8#tnh-np#Yw`DU$9JO|~KdL@|b{K1jttjuRMJ?|f=701FG*UWAAs%0irp zy)IBvo4k6_p~DjK3=!TohnDB11fC0U=IJwSk2TO1<+A(Is#W1~Z3A*_A}9-{g{}o( z!euq6^gR0bg;0<_%3R1HQ9d6~|2|69V@5!2Xm;RUk9J%pyP}2o(A9o31F!eQ-N?DT zXMF#$ScoG|h|>7j~X*ZwB@Jpl79LmrtQO20!F4dzrL78RYurA}Huuk<&`SRvl- zr`-_f3wWtDGGKSf5lp6sRsK5!%awp@q021&7_nY%>jh!{pl>`s4Wi-+1ZK1#ATR&V z(|cNEG6@Fm{6tsC_09*%`?t*gDlSX^p0FVM@v+E%chOkd*_F61q65>cp4?9K`l8y= zL4XYh?2A9G9Gf}EUU5k4P|i2*aFC@yr2tsv?Z@<;Je%;)IvCH7$Fv$*zSpQ(Dvp#k z%O+ogo)FKIBVAX$%;+fw$F9CZ)xo~YIRd`|L>Ueo9$Ef^FAkHq98KxKGg4t-sGSOC zv(C0`K#&S;EuVh1{aBDh2Tiy?HhUcH;IkHoK|fE%ATz~2MfDmj>r~O=&AJG;Oj^q7 zBKn7(SKx@40fkh}x)XwZ;ujcZ!(Ly)H`OS)v$WkG@)8cB2xZB@BK$`M@7!AH=3tHe z=8UvY=k*FRwe?ph>Ot81y^I4R?=INmOkN8nHt}yE8 zE$Vd(T*jik-Fb`N6zbZ#bRpQAff*uim+l5^o$pE6u6rRA%Su;@#QfCj4X4ti|$-04&J9p$N;kQj6^`c@S2_L!Dc+L-JH%S>2Wo^i>JptSZtu|SOJ#dvq&+AC7Edxb{TAO{H&h>fwsH z5es}a&MWGaJ0D#T8ToG{x*hof#z~g zxMzQ(;yXHwKtJ@O4JO0vhA%Wq^v6WjcL&LWPk08=0#Nk9^3l`W;aBcPQla+sWp^hn%N*_cxI@(5mXEVJ7N^ zDBlql!C*R1lf5ZO4rg9{7wxkXD{ilsJ~l;W*F&3_4c9oVICy}yTv~bns;Me5#K?^` z#2Lhr%=h)lJy#3SBZ46m?w!w^8p{Uxhh{L-+{^3KY!FJwg$;C$)+dv6B4(rC9G5|% zWw_SNxb)m;PZDoIiAUB_Sx$@5w>xC}VVa@IN43aj4D%7e09b2B+D7|Pr z%s|eIHH|+~Y4bX0ZNGPos?=?gjpJl9%Ujh!>SU!~-+UUNvl_!hHAZAxZI5E#AwP4O z+)P*!%KdUs87%q!|9R|PuQHT!>)ZEnz^xyKxq5K1jl4j_5W^Js|kw^_ zIemxhorV@dmE|e&{CG(qLJ6L_7)9p%G)Qkw#X;^YD30xIj-T}Ty1rl>BmheqrNBvA ztq14<_0VjR`EU6bQT5~PO(=RA%D`5p;o0PUTypFE)Ca@*g&}c0*BeoH|Ex(t4%qyU zv`B32cr4z^c7DQyqZ!*gnU$aIo6+AM>T``+2(%6y$bo}r-&o$_?`T`fn)ICx4(Fn; eY-TsDoLB^ZELf5zV%a8kgILa5daUVNLi$L+*`a3u From 9695442e7780d202af31368f931314c338ec0c50 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 2 Mar 2021 15:50:23 +0100 Subject: [PATCH 32/92] fix: fix build OOMs by performing out-of-scope cleanups for CircuitSynthesizer objects Signed-off-by: ljedrz --- leo/commands/build.rs | 11 ++-- synthesizer/src/circuit_synthesizer.rs | 79 +++++++++++++++++++------- synthesizer/src/serialized_circuit.rs | 34 ++++++----- 3 files changed, 83 insertions(+), 41 deletions(-) diff --git a/leo/commands/build.rs b/leo/commands/build.rs index dd3d0f3c17..c239eb57ca 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -122,11 +122,12 @@ impl Command for Build { // Generate the program on the constraint system and verify correctness { let mut cs = CircuitSynthesizer:: { - at: vec![], - bt: vec![], - ct: vec![], - public_variables: vec![], - private_variables: vec![], + at: Default::default(), + bt: Default::default(), + ct: Default::default(), + public_variables: Default::default(), + private_variables: Default::default(), + namespaces: Default::default(), }; let temporary_program = program.clone(); let output = temporary_program.compile_constraints(&mut cs)?; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 9a59c44e12..52eb228b24 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -17,18 +17,31 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::{ curves::{Field, PairingEngine}, - gadgets::r1cs::{ConstraintSystem, Index, LinearCombination, Variable}, + gadgets::{ + r1cs::{ConstraintSystem, Index, LinearCombination, Variable}, + utilities::OptionalVec, + }, }; +#[derive(Default)] +pub struct Namespace { + constraint_indices: Vec, + public_var_indices: Vec, + private_var_indices: Vec, +} + pub struct CircuitSynthesizer { // Constraints - pub at: Vec>, - pub bt: Vec>, - pub ct: Vec>, + pub at: OptionalVec>, + pub bt: OptionalVec>, + pub ct: OptionalVec>, // Assignments of variables - pub public_variables: Vec, - pub private_variables: Vec, + pub public_variables: OptionalVec, + pub private_variables: OptionalVec, + + // Technical namespaces used to remove of out-of-scope objects. + pub namespaces: Vec, } impl ConstraintSystem for CircuitSynthesizer { @@ -41,8 +54,10 @@ impl ConstraintSystem for CircuitSynthesizer { A: FnOnce() -> AR, AR: AsRef, { - let index = self.private_variables.len(); - self.private_variables.push(f()?); + let index = self.private_variables.insert(f()?); + if let Some(ref mut ns) = self.namespaces.last_mut() { + ns.private_var_indices.push(index); + } Ok(Variable::new_unchecked(Index::Private(index))) } @@ -53,8 +68,10 @@ impl ConstraintSystem for CircuitSynthesizer { A: FnOnce() -> AR, AR: AsRef, { - let index = self.public_variables.len(); - self.public_variables.push(f()?); + let index = self.public_variables.insert(f()?); + if let Some(ref mut ns) = self.namespaces.last_mut() { + ns.public_var_indices.push(index); + } Ok(Variable::new_unchecked(Index::Public(index))) } @@ -67,17 +84,17 @@ impl ConstraintSystem for CircuitSynthesizer { LB: FnOnce(LinearCombination) -> LinearCombination, LC: FnOnce(LinearCombination) -> LinearCombination, { - let num_constraints = self.num_constraints(); + let index = self.at.insert(Vec::new()); + self.bt.insert(Vec::new()); + self.ct.insert(Vec::new()); - self.at.push(Vec::new()); - self.bt.push(Vec::new()); - self.ct.push(Vec::new()); + push_constraints(a(LinearCombination::zero()), &mut self.at, index); + push_constraints(b(LinearCombination::zero()), &mut self.bt, index); + push_constraints(c(LinearCombination::zero()), &mut self.ct, index); - push_constraints(a(LinearCombination::zero()), &mut self.at, num_constraints); - - push_constraints(b(LinearCombination::zero()), &mut self.bt, num_constraints); - - push_constraints(c(LinearCombination::zero()), &mut self.ct, num_constraints); + if let Some(ref mut ns) = self.namespaces.last_mut() { + ns.constraint_indices.push(index); + } } fn push_namespace(&mut self, _: N) @@ -85,11 +102,25 @@ impl ConstraintSystem for CircuitSynthesizer { NR: AsRef, N: FnOnce() -> NR, { - // Do nothing; we don't care about namespaces in this context. + self.namespaces.push(Namespace::default()); } fn pop_namespace(&mut self) { - // Do nothing; we don't care about namespaces in this context. + if let Some(ns) = self.namespaces.pop() { + for idx in ns.constraint_indices { + self.at.remove(idx); + self.bt.remove(idx); + self.ct.remove(idx); + } + + for idx in ns.private_var_indices { + self.private_variables.remove(idx); + } + + for idx in ns.public_var_indices { + self.public_variables.remove(idx); + } + } } fn get_root(&mut self) -> &mut Self::Root { @@ -109,7 +140,11 @@ impl ConstraintSystem for CircuitSynthesizer { } } -fn push_constraints(l: LinearCombination, constraints: &mut [Vec<(F, Index)>], this_constraint: usize) { +fn push_constraints( + l: LinearCombination, + constraints: &mut OptionalVec>, + this_constraint: usize, +) { for (var, coeff) in l.as_ref() { match var.get_unchecked() { Index::Public(i) => constraints[this_constraint].push((*coeff, Index::Public(i))), diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index de3fe6d57b..4c53b48eb4 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -21,7 +21,10 @@ use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_errors::curves::FieldError; use snarkvm_models::{ curves::PairingEngine, - gadgets::r1cs::{ConstraintSystem, Index}, + gadgets::{ + r1cs::{ConstraintSystem, Index}, + utilities::OptionalVec, + }, }; use crate::{CircuitSynthesizer, SerializedField, SerializedIndex}; @@ -57,12 +60,14 @@ impl From> for SerializedCircuit { let num_constraints = synthesizer.num_constraints(); // Serialize assignments - fn get_serialized_assignments(assignments: &[E::Fr]) -> Vec { - assignments.iter().map(SerializedField::from).collect() + fn get_serialized_assignments<'a, E: PairingEngine, I: Iterator>( + assignments: I, + ) -> Vec { + assignments.map(SerializedField::from).collect() } - let public_variables = get_serialized_assignments::(&synthesizer.public_variables); - let private_variables = get_serialized_assignments::(&synthesizer.private_variables); + let public_variables = get_serialized_assignments::(synthesizer.public_variables.iter()); + let private_variables = get_serialized_assignments::(synthesizer.private_variables.iter()); // Serialize constraints fn get_serialized_constraints( @@ -121,13 +126,13 @@ impl TryFrom for CircuitSynthesizer { // Deserialize assignments fn get_deserialized_assignments( assignments: &[SerializedField], - ) -> Result::Fr>, FieldError> { - let mut deserialized = Vec::with_capacity(assignments.len()); + ) -> Result::Fr>, FieldError> { + let mut deserialized = OptionalVec::with_capacity(assignments.len()); for serialized_assignment in assignments { let field = ::Fr::try_from(serialized_assignment)?; - deserialized.push(field); + deserialized.insert(field); } Ok(deserialized) @@ -152,25 +157,25 @@ impl TryFrom for CircuitSynthesizer { Ok(deserialized) } - let mut at = Vec::with_capacity(serialized.num_constraints); - let mut bt = Vec::with_capacity(serialized.num_constraints); - let mut ct = Vec::with_capacity(serialized.num_constraints); + let mut at = OptionalVec::with_capacity(serialized.num_constraints); + let mut bt = OptionalVec::with_capacity(serialized.num_constraints); + let mut ct = OptionalVec::with_capacity(serialized.num_constraints); for i in 0..serialized.num_constraints { // Deserialize at[i] let a_constraints = get_deserialized_constraints(&serialized.at[i])?; - at.push(a_constraints); + at.insert(a_constraints); // Deserialize bt[i] let b_constraints = get_deserialized_constraints(&serialized.bt[i])?; - bt.push(b_constraints); + bt.insert(b_constraints); // Deserialize ct[i] let c_constraints = get_deserialized_constraints(&serialized.ct[i])?; - ct.push(c_constraints); + ct.insert(c_constraints); } Ok(CircuitSynthesizer:: { @@ -179,6 +184,7 @@ impl TryFrom for CircuitSynthesizer { ct, public_variables, private_variables, + namespaces: Default::default(), }) } } From d400764e00414f2e871e4f369cca0027561eab02 Mon Sep 17 00:00:00 2001 From: Protryon Date: Wed, 3 Mar 2021 09:59:24 -0800 Subject: [PATCH 33/92] parser rewrite --- Cargo.lock | 37 +- Cargo.toml | 2 +- asg/Cargo.toml | 4 +- asg/src/const_value.rs | 37 ++ asg/src/error/mod.rs | 39 +- asg/src/expression/call.rs | 23 +- asg/src/expression/cast.rs | 109 ++++ asg/src/expression/circuit_init.rs | 16 +- asg/src/expression/mod.rs | 16 + asg/src/expression/unary.rs | 15 + asg/src/lib.rs | 13 +- asg/src/pass.rs | 2 +- asg/src/program/circuit.rs | 3 + asg/src/program/function.rs | 8 + asg/src/program/mod.rs | 47 -- asg/src/reducer/monoidal_director.rs | 14 +- asg/src/reducer/monoidal_reducer.rs | 6 +- asg/src/reducer/visitor.rs | 4 + asg/src/reducer/visitor_director.rs | 14 +- asg/src/statement/assign.rs | 6 +- asg/src/statement/console.rs | 24 +- asg/src/statement/definition.rs | 6 - asg/src/type_.rs | 4 + ast/Cargo.toml | 16 +- ast/src/annotation.rs | 85 +-- ast/src/circuits/circuit.rs | 10 - .../circuit_implied_variable_definition.rs | 18 +- ast/src/circuits/circuit_member.rs | 28 - .../circuits/circuit_variable_definition.rs | 10 - ast/src/common/array_dimensions.rs | 13 - ast/src/common/identifier.rs | 138 +--- ast/src/common/input_keyword.rs | 9 - ast/src/common/mut_self_keyword.rs | 9 - ast/src/common/positive_number.rs | 8 - ast/src/common/self_keyword.rs | 9 - ast/src/common/span.rs | 102 +-- ast/src/common/spread_or_expression.rs | 23 - ast/src/errors/error.rs | 127 ++-- ast/src/errors/mod.rs | 25 +- ast/src/expression/binary.rs | 21 + .../spread.rs => ast/src/expression/cast.rs | 33 +- ast/src/expression/circuit_init.rs | 6 +- ast/src/expression/mod.rs | 432 +------------ ast/src/expression/unary.rs | 2 + ast/src/functions/function.rs | 22 +- ast/src/functions/input/function_input.rs | 13 - ast/src/functions/input/input_variable.rs | 14 - ast/src/functions/mod.rs | 3 - ast/src/functions/test_function.rs | 35 - ast/src/groups/group_coordinate.rs | 45 -- ast/src/groups/group_value.rs | 29 - ast/src/imports/import.rs | 10 - ast/src/imports/import_symbol.rs | 11 - ast/src/imports/package.rs | 11 - ast/src/imports/package_access.rs | 26 +- ast/src/imports/package_or_packages.rs | 28 +- ast/src/imports/packages.rs | 11 - ast/src/input/input_value.rs | 22 +- ast/src/lib.rs | 21 +- ast/src/main.rs | 71 --- ast/src/program.rs | 90 +-- ast/src/statements/assign/assignee.rs | 37 -- ast/src/statements/assign/mod.rs | 38 +- ast/src/statements/block.rs | 10 - ast/src/statements/conditional.rs | 20 - .../statements/console/console_function.rs | 66 +- .../statements/console/console_statement.rs | 10 - .../statements/console/formatted_container.rs | 9 - .../statements/console/formatted_string.rs | 41 +- ast/src/statements/definition/declare.rs | 11 - ast/src/statements/definition/mod.rs | 22 - .../statements/definition/variable_name.rs | 11 - ast/src/statements/expression.rs | 11 - ast/src/statements/iteration.rs | 13 - ast/src/statements/return_statement.rs | 10 - ast/src/statements/statement.rs | 17 - ast/src/types/integer_type.rs | 38 -- ast/src/types/type_.rs | 50 -- compiler/Cargo.toml | 10 +- compiler/src/compiler.rs | 77 ++- compiler/src/console/assert.rs | 9 +- compiler/src/console/format.rs | 38 +- compiler/src/constraints/constraints.rs | 21 +- compiler/src/errors/compiler.rs | 42 +- compiler/src/errors/console.rs | 35 +- compiler/src/errors/expression.rs | 90 +-- compiler/src/errors/function.rs | 62 +- compiler/src/errors/import.rs | 22 +- compiler/src/errors/output_bytes.rs | 30 +- compiler/src/errors/statement.rs | 88 +-- compiler/src/errors/value/address.rs | 29 +- compiler/src/errors/value/boolean.rs | 27 +- compiler/src/errors/value/field.rs | 31 +- compiler/src/errors/value/group.rs | 41 +- compiler/src/errors/value/integer.rs | 49 +- compiler/src/errors/value/value.rs | 39 +- compiler/src/expression/arithmetic/add.rs | 2 +- .../src/expression/arithmetic/bit_not.rs | 27 +- compiler/src/expression/arithmetic/div.rs | 2 +- compiler/src/expression/arithmetic/mod.rs | 3 + compiler/src/expression/arithmetic/mul.rs | 2 +- compiler/src/expression/arithmetic/negate.rs | 5 +- compiler/src/expression/arithmetic/pow.rs | 2 +- compiler/src/expression/arithmetic/sub.rs | 2 +- compiler/src/expression/array/access.rs | 4 +- compiler/src/expression/array/array.rs | 2 +- compiler/src/expression/circuit/access.rs | 6 +- compiler/src/expression/circuit/circuit.rs | 2 +- .../src/expression/conditional/conditional.rs | 6 +- compiler/src/expression/expression.rs | 57 +- compiler/src/expression/function/function.rs | 4 +- compiler/src/expression/logical/and.rs | 6 +- compiler/src/expression/logical/not.rs | 2 +- compiler/src/expression/logical/or.rs | 6 +- compiler/src/expression/relational/eq.rs | 6 +- compiler/src/expression/relational/ge.rs | 6 +- compiler/src/expression/relational/gt.rs | 6 +- compiler/src/expression/relational/le.rs | 6 +- compiler/src/expression/relational/lt.rs | 6 +- compiler/src/expression/tuple/access.rs | 4 +- compiler/src/function/function.rs | 2 +- compiler/src/function/input/array.rs | 7 +- compiler/src/function/input/input_keyword.rs | 4 +- compiler/src/function/input/tuple.rs | 5 +- compiler/src/function/main_function.rs | 12 +- compiler/src/function/mut_target.rs | 15 +- compiler/src/function/result/result.rs | 8 +- compiler/src/output/output_bytes.rs | 4 +- compiler/src/prelude/blake2s.rs | 8 +- compiler/src/statement/assign/assign.rs | 12 +- compiler/src/statement/assign/assignee.rs | 43 +- .../src/statement/conditional/conditional.rs | 10 +- .../src/statement/definition/definition.rs | 4 +- compiler/src/statement/iteration/iteration.rs | 2 +- compiler/src/statement/statement.rs | 7 +- compiler/src/value/address/address.rs | 9 +- compiler/src/value/boolean/input.rs | 6 +- compiler/src/value/field/field_type.rs | 26 +- compiler/src/value/field/input.rs | 12 +- compiler/src/value/group/input.rs | 6 +- .../src/value/group/targets/edwards_bls12.rs | 48 +- compiler/src/value/integer/integer.rs | 120 ++-- compiler/src/value/integer/macros.rs | 64 +- compiler/tests/group/mod.rs | 4 +- compiler/tests/mutability/mod.rs | 17 + compiler/tests/syntax/mod.rs | 3 +- grammar/LICENSE.md | 596 ------------------ grammar/README.md | 13 - grammar/benches/grammar.rs | 35 - grammar/benches/main.leo | 26 - grammar/src/access/access.rs | 30 - grammar/src/access/array_access.rs | 30 - grammar/src/access/assignee_access.rs | 42 -- grammar/src/access/call_access.rs | 30 - grammar/src/access/member_access.rs | 30 - grammar/src/access/mod.rs | 41 -- grammar/src/access/self_access.rs | 27 - grammar/src/access/static_member_access.rs | 30 - grammar/src/access/tuple_access.rs | 30 - .../src/annotations/annotation_arguments.rs | 43 -- grammar/src/annotations/annotation_name.rs | 44 -- grammar/src/annotations/annotation_symbol.rs | 29 - grammar/src/annotations/annotations.rs | 36 -- grammar/src/annotations/mod.rs | 29 - grammar/src/ast.rs | 176 ------ grammar/src/circuits/circuit.rs | 31 - .../src/circuits/circuit_implied_variable.rs | 27 - grammar/src/circuits/circuit_member.rs | 27 - grammar/src/circuits/circuit_variable.rs | 31 - .../circuits/circuit_variable_definition.rs | 31 - grammar/src/circuits/mod.rs | 30 - grammar/src/common/assignee.rs | 45 -- grammar/src/common/declare.rs | 35 - grammar/src/common/eoi.rs | 24 - grammar/src/common/identifier.rs | 41 -- grammar/src/common/keyword_or_identifier.rs | 39 -- grammar/src/common/line_end.rs | 31 - grammar/src/common/mod.rs | 66 -- grammar/src/common/mut_self_keyword.rs | 42 -- grammar/src/common/mutable.rs | 24 - grammar/src/common/range.rs | 36 -- grammar/src/common/range_or_expression.rs | 50 -- grammar/src/common/self_keyword.rs | 41 -- .../src/common/self_keyword_or_identifier.rs | 40 -- grammar/src/common/static_.rs | 24 - grammar/src/common/variable_name.rs | 46 -- grammar/src/common/variables.rs | 52 -- grammar/src/console/console_assert.rs | 37 -- grammar/src/console/console_error.rs | 37 -- grammar/src/console/console_function.rs | 44 -- grammar/src/console/console_function_call.rs | 44 -- grammar/src/console/console_keyword.rs | 29 - grammar/src/console/console_log.rs | 37 -- grammar/src/console/formatted_container.rs | 36 -- grammar/src/console/formatted_string.rs | 45 -- grammar/src/console/mod.rs | 42 -- .../src/definitions/annotated_definition.rs | 31 - grammar/src/definitions/definition.rs | 36 -- grammar/src/definitions/deprecated.rs | 26 - grammar/src/definitions/mod.rs | 24 - grammar/src/errors/parser.rs | 64 -- grammar/src/errors/syntax.rs | 64 -- .../array_initializer_expression.rs | 31 - .../expressions/array_inline_expression.rs | 30 - grammar/src/expressions/binary_expression.rs | 29 - .../expressions/circuit_inline_expression.rs | 38 -- grammar/src/expressions/expression.rs | 114 ---- grammar/src/expressions/mod.rs | 45 -- grammar/src/expressions/postfix_expression.rs | 31 - .../expressions/self_postfix_expression.rs | 37 -- grammar/src/expressions/ternary_expression.rs | 32 - grammar/src/expressions/tuple_expression.rs | 30 - grammar/src/expressions/unary_expression.rs | 38 -- grammar/src/files/file.rs | 31 - grammar/src/files/mod.rs | 18 - grammar/src/functions/function.rs | 33 - grammar/src/functions/input/function_input.rs | 38 -- grammar/src/functions/input/input.rs | 33 - grammar/src/functions/input/input_keyword.rs | 41 -- grammar/src/functions/input/mod.rs | 26 - grammar/src/functions/mod.rs | 24 - grammar/src/functions/test_function.rs | 37 -- grammar/src/imports/import.rs | 31 - grammar/src/imports/import_symbol.rs | 31 - grammar/src/imports/package.rs | 35 - grammar/src/imports/package_access.rs | 32 - grammar/src/imports/package_name.rs | 41 -- grammar/src/imports/package_or_packages.rs | 30 - grammar/src/imports/packages.rs | 35 - grammar/src/imports/star.rs | 29 - grammar/src/leo.pest | 560 ---------------- grammar/src/lib.rs | 110 ---- grammar/src/main.rs | 68 -- grammar/src/operations/assign_operation.rs | 55 -- grammar/src/operations/binary_operation.rs | 38 -- grammar/src/operations/mod.rs | 24 - grammar/src/operations/unary_operation.rs | 45 -- grammar/src/span.rs | 69 -- grammar/src/statements/assign_statement.rs | 46 -- grammar/src/statements/block.rs | 45 -- .../conditional_nested_or_end_statement.rs | 40 -- .../src/statements/conditional_statement.rs | 48 -- .../src/statements/definition_statement.rs | 45 -- .../src/statements/expression_statement.rs | 31 - grammar/src/statements/for_statement.rs | 40 -- grammar/src/statements/mod.rs | 42 -- grammar/src/statements/return_statement.rs | 37 -- grammar/src/statements/statement.rs | 49 -- grammar/src/types/address_type.rs | 24 - grammar/src/types/array_dimensions.rs | 55 -- grammar/src/types/array_type.rs | 35 - grammar/src/types/boolean_type.rs | 24 - grammar/src/types/circuit_type.rs | 30 - grammar/src/types/data_type.rs | 33 - grammar/src/types/field_type.rs | 24 - grammar/src/types/group_type.rs | 24 - grammar/src/types/integer_type.rs | 30 - grammar/src/types/mod.rs | 57 -- grammar/src/types/self_type.rs | 41 -- grammar/src/types/signed_integer_type.rs | 63 -- grammar/src/types/tuple_type.rs | 30 - grammar/src/types/type_.rs | 43 -- grammar/src/types/unsigned_integer_type.rs | 63 -- grammar/src/values/address.rs | 41 -- grammar/src/values/address_value.rs | 38 -- grammar/src/values/boolean_value.rs | 41 -- grammar/src/values/field_value.rs | 38 -- grammar/src/values/group_coordinate.rs | 77 --- grammar/src/values/group_value.rs | 75 --- grammar/src/values/integer_value.rs | 50 -- grammar/src/values/mod.rs | 54 -- grammar/src/values/negative_number.rs | 41 -- grammar/src/values/number_value.rs | 50 -- grammar/src/values/positive_number.rs | 41 -- grammar/src/values/signed_integer_value.rs | 38 -- grammar/src/values/unsigned_integer_value.rs | 38 -- grammar/src/values/value.rs | 62 -- grammar/tests/annotated.rs | 43 -- grammar/tests/circuits.rs | 116 ---- grammar/tests/deprecated.rs | 56 -- grammar/tests/display.rs | 38 -- grammar/tests/expression.rs | 55 -- grammar/tests/function.rs | 135 ---- grammar/tests/imports.rs | 91 --- grammar/tests/leo-samples/multiline.leo | 54 -- grammar/tests/mod.rs | 21 - grammar/tests/multiline.rs | 24 - grammar/tests/self.rs | 50 -- grammar/tests/serialization/expected_ast.json | 85 --- grammar/tests/serialization/json.rs | 38 -- grammar/tests/serialization/main.leo | 3 - grammar/tests/serialization/mod.rs | 17 - grammar/tests/tuple.rs | 107 ---- imports/Cargo.toml | 8 +- imports/src/errors/import_parser.rs | 79 ++- imports/src/parser/parse_package.rs | 14 +- imports/src/parser/parse_symbol.rs | 19 +- input/src/errors/parser.rs | 47 +- {grammar => parser}/Cargo.toml | 27 +- {ast => parser}/benches/big_circuit.leo | 0 {ast => parser}/benches/big_if_else.leo | 0 {ast => parser}/benches/big_ternary.leo | 0 {ast => parser}/benches/leo_ast.rs | 44 +- {ast => parser}/benches/long_array.leo | 0 {ast => parser}/benches/long_expr.leo | 0 {ast => parser}/benches/many_assigns.leo | 0 {ast => parser}/benches/many_foos.leo | 0 parser/src/context.rs | 271 ++++++++ {ast => parser}/src/errors/deprecated.rs | 50 +- {grammar => parser}/src/errors/mod.rs | 7 +- parser/src/errors/syntax.rs | 108 ++++ parser/src/errors/token.rs | 51 ++ .../src/imports/mod.rs => parser/src/lib.rs | 34 +- parser/src/parser/expression.rs | 577 +++++++++++++++++ parser/src/parser/file.rs | 317 ++++++++++ .../src/parser/mod.rs | 36 +- parser/src/parser/statement.rs | 310 +++++++++ parser/src/parser/type_.rs | 116 ++++ parser/src/test.rs | 99 +++ parser/src/token.rs | 280 ++++++++ parser/src/tokenizer.rs | 557 ++++++++++++++++ {ast => parser}/tests/mod.rs | 0 .../tests/serialization/deprecated_error.leo | 0 .../tests/serialization/expected_leo_ast.json | 0 {ast => parser}/tests/serialization/json.rs | 31 +- {ast => parser}/tests/serialization/main.leo | 0 {ast => parser}/tests/serialization/mod.rs | 0 .../tests/serialization/parser_error.leo | 0 tests/fail/parse/address/empty.leo | 3 + tests/fail/parse/address/invalid_length.leo | 3 + tests/fail/parse/address/invalid_prefix.leo | 3 + tests/fail/parse/array/initializer_fail.leo | 3 + tests/fail/parse/array/type_fail.leo | 3 + tests/fail/parse/circuits/self_circuit.leo | 9 + tests/fail/parse/console/log_fail.leo | 3 + tests/fail/parse/import/names_a_dash.leo | 3 + tests/fail/parse/import/names_dash_a.leo | 3 + tests/fail/parse/import/names_dollar.leo | 3 + tests/fail/parse/syntax/address_fail.leo | 3 + tests/fail/parse/syntax/console_fail.leo | 3 + tests/fail/parse/syntax/field_fail.leo | 3 + tests/fail/parse/syntax/group_fail.leo | 3 + tests/fail/parse/syntax/i8_fail.leo | 3 + tests/fail/parse/syntax/input_fail.leo | 3 + tests/fail/parse/syntax/self_keyword_fail.leo | 3 + tests/fail/parse/syntax/self_type_fail.leo | 3 + tests/fail/parse/syntax/semicolon.leo | 3 + tests/fail/parse/syntax/true_fail.leo | 3 + tests/fail/parse/syntax/u8_fail.leo | 3 + .../parse/address/console_assert_fail.leo | 6 + .../parse/address/console_assert_pass.leo | 6 + tests/pass/parse/address/equal.leo | 3 + tests/pass/parse/address/implicit_invalid.leo | 3 + tests/pass/parse/address/implicit_valid.leo | 3 + tests/pass/parse/address/input.leo | 5 + tests/pass/parse/address/ternary.leo | 8 + tests/pass/parse/address/valid.leo | 3 + tests/pass/parse/array/initializer.leo | 3 + tests/pass/parse/array/initializer_input.leo | 3 + tests/pass/parse/array/inline.leo | 3 + tests/pass/parse/array/input_nested_3x2.leo | 3 + tests/pass/parse/array/input_tuple_3x2.leo | 3 + .../pass/parse/array/input_tuple_3x2_fail.leo | 3 + .../parse/array/multi_fail_initializer.leo | 3 + tests/pass/parse/array/multi_fail_inline.leo | 4 + tests/pass/parse/array/multi_initializer.leo | 7 + .../parse/array/multi_initializer_fail.leo | 3 + tests/pass/parse/array/nested.leo | 4 + tests/pass/parse/array/nested_3x2_value.leo | 8 + .../parse/array/nested_3x2_value_fail.leo | 4 + tests/pass/parse/array/registers.leo | 3 + tests/pass/parse/array/slice.leo | 6 + tests/pass/parse/array/slice_lower.leo | 8 + tests/pass/parse/array/spread.leo | 7 + tests/pass/parse/array/tuple_3x2_value.leo | 8 + .../pass/parse/array/tuple_3x2_value_fail.leo | 4 + tests/pass/parse/array/type_input_3x2.leo | 5 + tests/pass/parse/array/type_input_4x3x2.leo | 8 + .../array/type_nested_value_nested_3x2.leo | 7 + .../type_nested_value_nested_3x2_fail.leo | 3 + .../array/type_nested_value_nested_4x3x2.leo | 10 + .../type_nested_value_nested_4x3x2_fail.leo | 3 + .../array/type_nested_value_tuple_3x2.leo | 7 + .../type_nested_value_tuple_3x2_fail.leo | 3 + .../array/type_nested_value_tuple_4x3x2.leo | 10 + .../type_nested_value_tuple_4x3x2_fail.leo | 3 + .../array/type_tuple_value_nested_3x2.leo | 7 + .../type_tuple_value_nested_3x2_fail.leo | 3 + .../array/type_tuple_value_nested_4x3x2.leo | 10 + .../type_tuple_value_nested_4x3x2_fail.leo | 3 + .../array/type_tuple_value_tuple_3x2.leo | 7 + .../array/type_tuple_value_tuple_3x2_fail.leo | 3 + .../array/type_tuple_value_tuple_4x3x2.leo | 10 + .../type_tuple_value_tuple_4x3x2_fail.leo | 3 + .../pass/parse/array/variable_slice_fail.leo | 7 + tests/pass/parse/boolean/all.leo | 8 + tests/pass/parse/boolean/assert_eq_input.leo | 3 + tests/pass/parse/boolean/conditional_mut.leo | 6 + tests/pass/parse/boolean/false_and_false.leo | 5 + tests/pass/parse/boolean/false_or_false.leo | 5 + tests/pass/parse/boolean/not_false.leo | 3 + tests/pass/parse/boolean/not_mutable.leo | 4 + tests/pass/parse/boolean/not_true.leo | 3 + tests/pass/parse/boolean/not_u32.leo | 3 + tests/pass/parse/boolean/output_register.leo | 3 + tests/pass/parse/boolean/true_and_false.leo | 5 + tests/pass/parse/boolean/true_and_true.leo | 5 + tests/pass/parse/boolean/true_and_u32.leo | 3 + tests/pass/parse/boolean/true_or_false.leo | 5 + tests/pass/parse/boolean/true_or_true.leo | 5 + tests/pass/parse/boolean/true_or_u32.leo | 3 + ...define_circuit_inside_circuit_function.leo | 13 + .../parse/circuits/duplicate_name_context.leo | 13 + tests/pass/parse/circuits/inline.leo | 7 + tests/pass/parse/circuits/inline_fail.leo | 7 + .../parse/circuits/inline_member_fail.leo | 8 + .../parse/circuits/inline_member_pass.leo | 13 + .../pass/parse/circuits/inline_undefined.leo | 3 + tests/pass/parse/circuits/member_function.leo | 13 + .../parse/circuits/member_function_fail.leo | 10 + .../circuits/member_function_invalid.leo | 10 + .../parse/circuits/member_function_nested.leo | 18 + .../parse/circuits/member_static_function.leo | 11 + .../member_static_function_invalid.leo | 9 + .../member_static_function_nested.leo | 15 + .../member_static_function_undefined.leo | 9 + tests/pass/parse/circuits/member_variable.leo | 9 + .../circuits/member_variable_and_function.leo | 15 + .../parse/circuits/member_variable_fail.leo | 9 + .../pass/parse/circuits/mut_function_fail.leo | 11 + .../parse/circuits/mut_self_function_fail.leo | 15 + .../mut_self_static_function_fail.leo | 15 + .../pass/parse/circuits/mut_self_variable.leo | 22 + .../circuits/mut_self_variable_branch.leo | 32 + .../mut_self_variable_conditional.leo | 15 + .../parse/circuits/mut_self_variable_fail.leo | 13 + .../circuits/mut_static_function_fail.leo | 9 + tests/pass/parse/circuits/mut_variable.leo | 17 + .../pass/parse/circuits/mut_variable_fail.leo | 9 + tests/pass/parse/circuits/pedersen_mock.leo | 27 + tests/pass/parse/circuits/self_fail.leo | 3 + tests/pass/parse/circuits/self_member.leo | 14 + .../parse/circuits/self_member_invalid.leo | 12 + .../parse/circuits/self_member_undefined.leo | 10 + tests/pass/parse/compiler/main.leo | 3 + tests/pass/parse/console/assert.leo | 3 + .../pass/parse/console/conditional_assert.leo | 7 + tests/pass/parse/console/debug.leo | 3 + tests/pass/parse/console/error.leo | 3 + tests/pass/parse/console/log.leo | 3 + tests/pass/parse/console/log_conditional.leo | 6 + tests/pass/parse/console/log_input.leo | 3 + tests/pass/parse/console/log_parameter.leo | 3 + .../console/log_parameter_fail_empty.leo | 3 + .../parse/console/log_parameter_fail_none.leo | 3 + .../console/log_parameter_fail_unknown.leo | 3 + .../pass/parse/console/log_parameter_many.leo | 3 + .../pass/parse/core/arguments_length_fail.leo | 9 + tests/pass/parse/core/arguments_type_fail.leo | 10 + tests/pass/parse/core/blake2s_input.leo | 5 + tests/pass/parse/core/blake2s_random.leo | 7 + .../pass/parse/core/core_circuit_invalid.leo | 3 + .../parse/core/core_circuit_star_fail.leo | 3 + .../pass/parse/core/core_package_invalid.leo | 3 + .../core/core_unstable_package_invalid.leo | 3 + tests/pass/parse/core/unstable_blake2s.leo | 10 + tests/pass/parse/definition/out_of_order.leo | 6 + .../definition/out_of_order_with_import.leo | 7 + tests/pass/parse/field/add.leo | 3 + tests/pass/parse/field/console_assert.leo | 3 + tests/pass/parse/field/div.leo | 3 + tests/pass/parse/field/eq.leo | 3 + tests/pass/parse/field/field.leo | 4 + tests/pass/parse/field/mul.leo | 3 + tests/pass/parse/field/negate.leo | 3 + tests/pass/parse/field/sub.leo | 3 + tests/pass/parse/field/ternary.leo | 5 + tests/pass/parse/function/array_input.leo | 6 + .../function/array_params_direct_call.leo | 9 + .../parse/function/conditional_return.leo | 7 + tests/pass/parse/function/empty.leo | 5 + tests/pass/parse/function/iteration.leo | 13 + .../parse/function/iteration_repeated.leo | 15 + .../pass/parse/function/multiple_returns.leo | 10 + .../parse/function/multiple_returns_fail.leo | 7 + .../multiple_returns_fail_conditional.leo | 9 + .../parse/function/multiple_returns_main.leo | 3 + tests/pass/parse/function/newlines.leo | 9 + tests/pass/parse/function/repeated.leo | 9 + tests/pass/parse/function/return.leo | 7 + .../function/return_array_nested_fail.leo | 7 + .../function/return_array_nested_pass.leo | 12 + .../function/return_array_tuple_fail.leo | 7 + .../function/return_array_tuple_pass.leo | 12 + tests/pass/parse/function/return_tuple.leo | 11 + .../function/return_tuple_conditional.leo | 15 + tests/pass/parse/function/scope_fail.leo | 8 + tests/pass/parse/function/undefined.leo | 3 + tests/pass/parse/function/value_unchanged.leo | 19 + tests/pass/parse/group/add.leo | 3 + tests/pass/parse/group/assert_eq.leo | 3 + tests/pass/parse/group/both_sign_high.leo | 3 + tests/pass/parse/group/both_sign_inferred.leo | 3 + tests/pass/parse/group/both_sign_low.leo | 3 + tests/pass/parse/group/eq.leo | 3 + tests/pass/parse/group/input.leo | 3 + tests/pass/parse/group/negate.leo | 3 + tests/pass/parse/group/one.leo | 3 + tests/pass/parse/group/point.leo | 3 + tests/pass/parse/group/point_input.leo | 3 + .../parse/group/positive_and_negative.leo | 10 + tests/pass/parse/group/sub.leo | 3 + tests/pass/parse/group/ternary.leo | 5 + tests/pass/parse/group/x_and_y.leo | 3 + tests/pass/parse/group/x_sign_high.leo | 3 + tests/pass/parse/group/x_sign_inferred.leo | 3 + tests/pass/parse/group/x_sign_low.leo | 3 + tests/pass/parse/group/y_sign_high.leo | 3 + tests/pass/parse/group/y_sign_inferred.leo | 3 + tests/pass/parse/group/y_sign_low.leo | 3 + tests/pass/parse/group/zero.leo | 3 + tests/pass/parse/import/a-9.leo | 1 + tests/pass/parse/import/a0-f.leo | 1 + tests/pass/parse/import/alias.leo | 5 + tests/pass/parse/import/basic.leo | 5 + tests/pass/parse/import/bat.leo | 3 + tests/pass/parse/import/baz.leo | 7 + tests/pass/parse/import/hello-world.leo | 1 + tests/pass/parse/import/lib.leo | 3 + tests/pass/parse/import/many_import.leo | 26 + tests/pass/parse/import/many_import_star.leo | 19 + tests/pass/parse/import/multiple.leo | 10 + tests/pass/parse/import/names.leo | 5 + tests/pass/parse/import/names_underscore.leo | 3 + tests/pass/parse/import/star.leo | 7 + tests/pass/parse/import/star_fail.leo | 4 + tests/pass/parse/import/test-import.leo | 8 + tests/pass/parse/integers/i128/add.leo | 3 + .../parse/integers/i128/console_assert.leo | 3 + tests/pass/parse/integers/i128/div.leo | 3 + tests/pass/parse/integers/i128/eq.leo | 3 + tests/pass/parse/integers/i128/ge.leo | 3 + tests/pass/parse/integers/i128/gt.leo | 3 + tests/pass/parse/integers/i128/input.leo | 3 + tests/pass/parse/integers/i128/le.leo | 3 + tests/pass/parse/integers/i128/lt.leo | 3 + tests/pass/parse/integers/i128/max.leo | 3 + tests/pass/parse/integers/i128/max_fail.leo | 3 + tests/pass/parse/integers/i128/min.leo | 3 + tests/pass/parse/integers/i128/min_fail.leo | 3 + tests/pass/parse/integers/i128/mod.rs | 134 ++++ tests/pass/parse/integers/i128/mul.leo | 3 + tests/pass/parse/integers/i128/ne.leo | 3 + tests/pass/parse/integers/i128/negate.leo | 3 + tests/pass/parse/integers/i128/negate_min.leo | 4 + .../pass/parse/integers/i128/negate_zero.leo | 5 + tests/pass/parse/integers/i128/pow.leo | 3 + tests/pass/parse/integers/i128/sub.leo | 3 + tests/pass/parse/integers/i128/ternary.leo | 5 + tests/pass/parse/integers/i16/add.leo | 3 + .../parse/integers/i16/console_assert.leo | 3 + tests/pass/parse/integers/i16/div.leo | 3 + tests/pass/parse/integers/i16/eq.leo | 3 + tests/pass/parse/integers/i16/ge.leo | 3 + tests/pass/parse/integers/i16/gt.leo | 3 + tests/pass/parse/integers/i16/input.leo | 3 + tests/pass/parse/integers/i16/le.leo | 3 + tests/pass/parse/integers/i16/lt.leo | 3 + tests/pass/parse/integers/i16/max.leo | 3 + tests/pass/parse/integers/i16/max_fail.leo | 3 + tests/pass/parse/integers/i16/min.leo | 3 + tests/pass/parse/integers/i16/min_fail.leo | 3 + tests/pass/parse/integers/i16/mod.rs | 133 ++++ tests/pass/parse/integers/i16/mul.leo | 3 + tests/pass/parse/integers/i16/ne.leo | 3 + tests/pass/parse/integers/i16/negate.leo | 3 + tests/pass/parse/integers/i16/negate_min.leo | 4 + tests/pass/parse/integers/i16/negate_zero.leo | 5 + tests/pass/parse/integers/i16/pow.leo | 3 + tests/pass/parse/integers/i16/sub.leo | 3 + tests/pass/parse/integers/i16/ternary.leo | 5 + tests/pass/parse/integers/i32/add.leo | 3 + .../parse/integers/i32/console_assert.leo | 3 + tests/pass/parse/integers/i32/div.leo | 3 + tests/pass/parse/integers/i32/eq.leo | 3 + tests/pass/parse/integers/i32/ge.leo | 3 + tests/pass/parse/integers/i32/gt.leo | 3 + tests/pass/parse/integers/i32/input.leo | 3 + tests/pass/parse/integers/i32/le.leo | 3 + tests/pass/parse/integers/i32/lt.leo | 3 + tests/pass/parse/integers/i32/max.leo | 3 + tests/pass/parse/integers/i32/max_fail.leo | 3 + tests/pass/parse/integers/i32/min.leo | 3 + tests/pass/parse/integers/i32/min_fail.leo | 3 + tests/pass/parse/integers/i32/mod.rs | 133 ++++ tests/pass/parse/integers/i32/mul.leo | 3 + tests/pass/parse/integers/i32/ne.leo | 3 + tests/pass/parse/integers/i32/negate.leo | 3 + tests/pass/parse/integers/i32/negate_min.leo | 4 + tests/pass/parse/integers/i32/negate_zero.leo | 5 + tests/pass/parse/integers/i32/pow.leo | 3 + tests/pass/parse/integers/i32/sub.leo | 3 + tests/pass/parse/integers/i32/ternary.leo | 5 + tests/pass/parse/integers/i64/add.leo | 3 + .../parse/integers/i64/console_assert.leo | 3 + tests/pass/parse/integers/i64/div.leo | 3 + tests/pass/parse/integers/i64/eq.leo | 3 + tests/pass/parse/integers/i64/ge.leo | 3 + tests/pass/parse/integers/i64/gt.leo | 3 + tests/pass/parse/integers/i64/input.leo | 3 + tests/pass/parse/integers/i64/le.leo | 3 + tests/pass/parse/integers/i64/lt.leo | 3 + tests/pass/parse/integers/i64/max.leo | 3 + tests/pass/parse/integers/i64/max_fail.leo | 3 + tests/pass/parse/integers/i64/min.leo | 3 + tests/pass/parse/integers/i64/min_fail.leo | 3 + tests/pass/parse/integers/i64/mod.rs | 134 ++++ tests/pass/parse/integers/i64/mul.leo | 3 + tests/pass/parse/integers/i64/ne.leo | 3 + tests/pass/parse/integers/i64/negate.leo | 3 + tests/pass/parse/integers/i64/negate_min.leo | 4 + tests/pass/parse/integers/i64/negate_zero.leo | 5 + tests/pass/parse/integers/i64/pow.leo | 3 + tests/pass/parse/integers/i64/sub.leo | 3 + tests/pass/parse/integers/i64/ternary.leo | 5 + tests/pass/parse/integers/i8/add.leo | 3 + .../pass/parse/integers/i8/console_assert.leo | 3 + tests/pass/parse/integers/i8/div.leo | 3 + tests/pass/parse/integers/i8/eq.leo | 3 + tests/pass/parse/integers/i8/ge.leo | 3 + tests/pass/parse/integers/i8/gt.leo | 3 + tests/pass/parse/integers/i8/input.leo | 3 + tests/pass/parse/integers/i8/le.leo | 3 + tests/pass/parse/integers/i8/lt.leo | 3 + tests/pass/parse/integers/i8/max.leo | 3 + tests/pass/parse/integers/i8/max_fail.leo | 3 + tests/pass/parse/integers/i8/min.leo | 3 + tests/pass/parse/integers/i8/min_fail.leo | 3 + tests/pass/parse/integers/i8/mod.rs | 133 ++++ tests/pass/parse/integers/i8/mul.leo | 3 + tests/pass/parse/integers/i8/ne.leo | 3 + tests/pass/parse/integers/i8/negate.leo | 3 + tests/pass/parse/integers/i8/negate_min.leo | 4 + tests/pass/parse/integers/i8/negate_zero.leo | 5 + tests/pass/parse/integers/i8/pow.leo | 3 + tests/pass/parse/integers/i8/sub.leo | 3 + tests/pass/parse/integers/i8/ternary.leo | 5 + tests/pass/parse/integers/u128/add.leo | 3 + .../parse/integers/u128/console_assert.leo | 3 + tests/pass/parse/integers/u128/div.leo | 3 + tests/pass/parse/integers/u128/eq.leo | 3 + tests/pass/parse/integers/u128/ge.leo | 3 + tests/pass/parse/integers/u128/gt.leo | 3 + tests/pass/parse/integers/u128/input.leo | 3 + tests/pass/parse/integers/u128/le.leo | 3 + tests/pass/parse/integers/u128/lt.leo | 3 + tests/pass/parse/integers/u128/max.leo | 3 + tests/pass/parse/integers/u128/max_fail.leo | 3 + tests/pass/parse/integers/u128/min.leo | 3 + tests/pass/parse/integers/u128/min_fail.leo | 3 + tests/pass/parse/integers/u128/mod.rs | 118 ++++ tests/pass/parse/integers/u128/mul.leo | 3 + tests/pass/parse/integers/u128/ne.leo | 3 + tests/pass/parse/integers/u128/pow.leo | 3 + tests/pass/parse/integers/u128/sub.leo | 3 + tests/pass/parse/integers/u128/ternary.leo | 5 + tests/pass/parse/integers/u16/add.leo | 3 + .../parse/integers/u16/console_assert.leo | 3 + tests/pass/parse/integers/u16/div.leo | 3 + tests/pass/parse/integers/u16/eq.leo | 3 + tests/pass/parse/integers/u16/ge.leo | 3 + tests/pass/parse/integers/u16/gt.leo | 3 + tests/pass/parse/integers/u16/input.leo | 3 + tests/pass/parse/integers/u16/le.leo | 3 + tests/pass/parse/integers/u16/lt.leo | 3 + tests/pass/parse/integers/u16/max.leo | 3 + tests/pass/parse/integers/u16/max_fail.leo | 3 + tests/pass/parse/integers/u16/min.leo | 3 + tests/pass/parse/integers/u16/min_fail.leo | 3 + tests/pass/parse/integers/u16/mod.rs | 118 ++++ tests/pass/parse/integers/u16/mul.leo | 3 + tests/pass/parse/integers/u16/ne.leo | 3 + tests/pass/parse/integers/u16/pow.leo | 3 + tests/pass/parse/integers/u16/sub.leo | 3 + tests/pass/parse/integers/u16/ternary.leo | 5 + tests/pass/parse/integers/u32/add.leo | 3 + .../parse/integers/u32/console_assert.leo | 3 + tests/pass/parse/integers/u32/div.leo | 3 + tests/pass/parse/integers/u32/eq.leo | 3 + tests/pass/parse/integers/u32/ge.leo | 3 + tests/pass/parse/integers/u32/gt.leo | 3 + tests/pass/parse/integers/u32/input.leo | 3 + tests/pass/parse/integers/u32/le.leo | 3 + tests/pass/parse/integers/u32/lt.leo | 3 + tests/pass/parse/integers/u32/max.leo | 3 + tests/pass/parse/integers/u32/max_fail.leo | 3 + tests/pass/parse/integers/u32/min.leo | 3 + tests/pass/parse/integers/u32/min_fail.leo | 3 + tests/pass/parse/integers/u32/mod.rs | 118 ++++ tests/pass/parse/integers/u32/mul.leo | 3 + tests/pass/parse/integers/u32/ne.leo | 3 + tests/pass/parse/integers/u32/pow.leo | 3 + tests/pass/parse/integers/u32/sub.leo | 3 + tests/pass/parse/integers/u32/ternary.leo | 5 + tests/pass/parse/integers/u64/add.leo | 3 + .../parse/integers/u64/console_assert.leo | 3 + tests/pass/parse/integers/u64/div.leo | 3 + tests/pass/parse/integers/u64/eq.leo | 3 + tests/pass/parse/integers/u64/ge.leo | 3 + tests/pass/parse/integers/u64/gt.leo | 3 + tests/pass/parse/integers/u64/input.leo | 3 + tests/pass/parse/integers/u64/le.leo | 3 + tests/pass/parse/integers/u64/lt.leo | 3 + tests/pass/parse/integers/u64/max.leo | 3 + tests/pass/parse/integers/u64/max_fail.leo | 3 + tests/pass/parse/integers/u64/min.leo | 3 + tests/pass/parse/integers/u64/min_fail.leo | 3 + tests/pass/parse/integers/u64/mod.rs | 118 ++++ tests/pass/parse/integers/u64/mul.leo | 3 + tests/pass/parse/integers/u64/ne.leo | 3 + tests/pass/parse/integers/u64/pow.leo | 3 + tests/pass/parse/integers/u64/sub.leo | 3 + tests/pass/parse/integers/u64/ternary.leo | 5 + tests/pass/parse/integers/u8/add.leo | 3 + .../pass/parse/integers/u8/console_assert.leo | 3 + tests/pass/parse/integers/u8/div.leo | 3 + tests/pass/parse/integers/u8/eq.leo | 3 + tests/pass/parse/integers/u8/ge.leo | 3 + tests/pass/parse/integers/u8/gt.leo | 3 + tests/pass/parse/integers/u8/input.leo | 3 + tests/pass/parse/integers/u8/le.leo | 3 + tests/pass/parse/integers/u8/lt.leo | 3 + tests/pass/parse/integers/u8/max.leo | 3 + tests/pass/parse/integers/u8/max_fail.leo | 3 + tests/pass/parse/integers/u8/min.leo | 3 + tests/pass/parse/integers/u8/min_fail.leo | 3 + tests/pass/parse/integers/u8/mod.rs | 118 ++++ tests/pass/parse/integers/u8/mul.leo | 3 + tests/pass/parse/integers/u8/ne.leo | 3 + tests/pass/parse/integers/u8/pow.leo | 3 + tests/pass/parse/integers/u8/sub.leo | 3 + tests/pass/parse/integers/u8/ternary.leo | 5 + tests/pass/parse/mutability/array.leo | 5 + tests/pass/parse/mutability/array_mut.leo | 7 + .../parse/mutability/array_splice_mut.leo | 9 + .../pass/parse/mutability/array_tuple_mut.leo | 8 + tests/pass/parse/mutability/circuit.leo | 9 + .../parse/mutability/circuit_function_mut.leo | 9 + tests/pass/parse/mutability/circuit_mut.leo | 11 + .../circuit_static_function_mut.leo | 9 + .../parse/mutability/circuit_variable_mut.leo | 11 + tests/pass/parse/mutability/const.leo | 5 + .../pass/parse/mutability/function_input.leo | 4 + .../parse/mutability/function_input_mut.leo | 6 + tests/pass/parse/mutability/let.leo | 5 + tests/pass/parse/mutability/let_mut.leo | 7 + .../pass/parse/mutability/let_mut_nested.leo | 5 + tests/pass/parse/mutability/swap.leo | 20 + tests/pass/parse/statements/assert.leo | 7 + tests/pass/parse/statements/block.leo | 9 + tests/pass/parse/statements/chain.leo | 13 + tests/pass/parse/statements/for_loop.leo | 13 + .../pass/parse/statements/iteration_basic.leo | 8 + .../parse/statements/multiple_returns.leo | 7 + tests/pass/parse/statements/mutate.leo | 15 + tests/pass/parse/statements/nested.leo | 12 + .../parse/statements/num_returns_fail.leo | 3 + tests/pass/parse/statements/ternary_basic.leo | 5 + .../parse/syntax/compare_mismatched_types.leo | 3 + tests/pass/parse/syntax/undefined.leo | 3 + tests/pass/parse/tuples/access.leo | 6 + tests/pass/parse/tuples/basic.leo | 3 + tests/pass/parse/tuples/function.leo | 10 + tests/pass/parse/tuples/function_multiple.leo | 10 + tests/pass/parse/tuples/function_typed.leo | 10 + tests/pass/parse/tuples/input.leo | 3 + tests/pass/parse/tuples/multiple.leo | 6 + tests/pass/parse/tuples/multiple_typed.leo | 6 + tests/pass/parse/tuples/nested.leo | 4 + tests/pass/parse/tuples/nested_access.leo | 8 + tests/pass/parse/tuples/nested_typed.leo | 4 + tests/pass/parse/tuples/typed.leo | 3 + 782 files changed, 7794 insertions(+), 9916 deletions(-) create mode 100644 asg/src/expression/cast.rs rename grammar/src/common/spread.rs => ast/src/expression/cast.rs (63%) delete mode 100644 ast/src/functions/test_function.rs delete mode 100644 ast/src/main.rs rename grammar/src/console/console_debug.rs => compiler/src/expression/arithmetic/bit_not.rs (57%) delete mode 100644 grammar/LICENSE.md delete mode 100644 grammar/README.md delete mode 100644 grammar/benches/grammar.rs delete mode 100644 grammar/benches/main.leo delete mode 100644 grammar/src/access/access.rs delete mode 100644 grammar/src/access/array_access.rs delete mode 100644 grammar/src/access/assignee_access.rs delete mode 100644 grammar/src/access/call_access.rs delete mode 100644 grammar/src/access/member_access.rs delete mode 100644 grammar/src/access/mod.rs delete mode 100644 grammar/src/access/self_access.rs delete mode 100644 grammar/src/access/static_member_access.rs delete mode 100644 grammar/src/access/tuple_access.rs delete mode 100644 grammar/src/annotations/annotation_arguments.rs delete mode 100644 grammar/src/annotations/annotation_name.rs delete mode 100644 grammar/src/annotations/annotation_symbol.rs delete mode 100644 grammar/src/annotations/annotations.rs delete mode 100644 grammar/src/annotations/mod.rs delete mode 100644 grammar/src/ast.rs delete mode 100644 grammar/src/circuits/circuit.rs delete mode 100644 grammar/src/circuits/circuit_implied_variable.rs delete mode 100644 grammar/src/circuits/circuit_member.rs delete mode 100644 grammar/src/circuits/circuit_variable.rs delete mode 100644 grammar/src/circuits/circuit_variable_definition.rs delete mode 100644 grammar/src/circuits/mod.rs delete mode 100644 grammar/src/common/assignee.rs delete mode 100644 grammar/src/common/declare.rs delete mode 100644 grammar/src/common/eoi.rs delete mode 100644 grammar/src/common/identifier.rs delete mode 100644 grammar/src/common/keyword_or_identifier.rs delete mode 100644 grammar/src/common/line_end.rs delete mode 100644 grammar/src/common/mod.rs delete mode 100644 grammar/src/common/mut_self_keyword.rs delete mode 100644 grammar/src/common/mutable.rs delete mode 100644 grammar/src/common/range.rs delete mode 100644 grammar/src/common/range_or_expression.rs delete mode 100644 grammar/src/common/self_keyword.rs delete mode 100644 grammar/src/common/self_keyword_or_identifier.rs delete mode 100644 grammar/src/common/static_.rs delete mode 100644 grammar/src/common/variable_name.rs delete mode 100644 grammar/src/common/variables.rs delete mode 100644 grammar/src/console/console_assert.rs delete mode 100644 grammar/src/console/console_error.rs delete mode 100644 grammar/src/console/console_function.rs delete mode 100644 grammar/src/console/console_function_call.rs delete mode 100644 grammar/src/console/console_keyword.rs delete mode 100644 grammar/src/console/console_log.rs delete mode 100644 grammar/src/console/formatted_container.rs delete mode 100644 grammar/src/console/formatted_string.rs delete mode 100644 grammar/src/console/mod.rs delete mode 100644 grammar/src/definitions/annotated_definition.rs delete mode 100644 grammar/src/definitions/definition.rs delete mode 100644 grammar/src/definitions/deprecated.rs delete mode 100644 grammar/src/definitions/mod.rs delete mode 100644 grammar/src/errors/parser.rs delete mode 100644 grammar/src/errors/syntax.rs delete mode 100644 grammar/src/expressions/array_initializer_expression.rs delete mode 100644 grammar/src/expressions/array_inline_expression.rs delete mode 100644 grammar/src/expressions/binary_expression.rs delete mode 100644 grammar/src/expressions/circuit_inline_expression.rs delete mode 100644 grammar/src/expressions/expression.rs delete mode 100644 grammar/src/expressions/mod.rs delete mode 100644 grammar/src/expressions/postfix_expression.rs delete mode 100644 grammar/src/expressions/self_postfix_expression.rs delete mode 100644 grammar/src/expressions/ternary_expression.rs delete mode 100644 grammar/src/expressions/tuple_expression.rs delete mode 100644 grammar/src/expressions/unary_expression.rs delete mode 100644 grammar/src/files/file.rs delete mode 100644 grammar/src/files/mod.rs delete mode 100644 grammar/src/functions/function.rs delete mode 100644 grammar/src/functions/input/function_input.rs delete mode 100644 grammar/src/functions/input/input.rs delete mode 100644 grammar/src/functions/input/input_keyword.rs delete mode 100644 grammar/src/functions/input/mod.rs delete mode 100644 grammar/src/functions/mod.rs delete mode 100644 grammar/src/functions/test_function.rs delete mode 100644 grammar/src/imports/import.rs delete mode 100644 grammar/src/imports/import_symbol.rs delete mode 100644 grammar/src/imports/package.rs delete mode 100644 grammar/src/imports/package_access.rs delete mode 100644 grammar/src/imports/package_name.rs delete mode 100644 grammar/src/imports/package_or_packages.rs delete mode 100644 grammar/src/imports/packages.rs delete mode 100644 grammar/src/imports/star.rs delete mode 100644 grammar/src/leo.pest delete mode 100644 grammar/src/lib.rs delete mode 100644 grammar/src/main.rs delete mode 100644 grammar/src/operations/assign_operation.rs delete mode 100644 grammar/src/operations/binary_operation.rs delete mode 100644 grammar/src/operations/mod.rs delete mode 100644 grammar/src/operations/unary_operation.rs delete mode 100644 grammar/src/span.rs delete mode 100644 grammar/src/statements/assign_statement.rs delete mode 100644 grammar/src/statements/block.rs delete mode 100644 grammar/src/statements/conditional_nested_or_end_statement.rs delete mode 100644 grammar/src/statements/conditional_statement.rs delete mode 100644 grammar/src/statements/definition_statement.rs delete mode 100644 grammar/src/statements/expression_statement.rs delete mode 100644 grammar/src/statements/for_statement.rs delete mode 100644 grammar/src/statements/mod.rs delete mode 100644 grammar/src/statements/return_statement.rs delete mode 100644 grammar/src/statements/statement.rs delete mode 100644 grammar/src/types/address_type.rs delete mode 100644 grammar/src/types/array_dimensions.rs delete mode 100644 grammar/src/types/array_type.rs delete mode 100644 grammar/src/types/boolean_type.rs delete mode 100644 grammar/src/types/circuit_type.rs delete mode 100644 grammar/src/types/data_type.rs delete mode 100644 grammar/src/types/field_type.rs delete mode 100644 grammar/src/types/group_type.rs delete mode 100644 grammar/src/types/integer_type.rs delete mode 100644 grammar/src/types/mod.rs delete mode 100644 grammar/src/types/self_type.rs delete mode 100644 grammar/src/types/signed_integer_type.rs delete mode 100644 grammar/src/types/tuple_type.rs delete mode 100644 grammar/src/types/type_.rs delete mode 100644 grammar/src/types/unsigned_integer_type.rs delete mode 100644 grammar/src/values/address.rs delete mode 100644 grammar/src/values/address_value.rs delete mode 100644 grammar/src/values/boolean_value.rs delete mode 100644 grammar/src/values/field_value.rs delete mode 100644 grammar/src/values/group_coordinate.rs delete mode 100644 grammar/src/values/group_value.rs delete mode 100644 grammar/src/values/integer_value.rs delete mode 100644 grammar/src/values/mod.rs delete mode 100644 grammar/src/values/negative_number.rs delete mode 100644 grammar/src/values/number_value.rs delete mode 100644 grammar/src/values/positive_number.rs delete mode 100644 grammar/src/values/signed_integer_value.rs delete mode 100644 grammar/src/values/unsigned_integer_value.rs delete mode 100644 grammar/src/values/value.rs delete mode 100644 grammar/tests/annotated.rs delete mode 100644 grammar/tests/circuits.rs delete mode 100644 grammar/tests/deprecated.rs delete mode 100644 grammar/tests/display.rs delete mode 100644 grammar/tests/expression.rs delete mode 100644 grammar/tests/function.rs delete mode 100644 grammar/tests/imports.rs delete mode 100644 grammar/tests/leo-samples/multiline.leo delete mode 100644 grammar/tests/mod.rs delete mode 100644 grammar/tests/multiline.rs delete mode 100644 grammar/tests/self.rs delete mode 100644 grammar/tests/serialization/expected_ast.json delete mode 100644 grammar/tests/serialization/json.rs delete mode 100644 grammar/tests/serialization/main.leo delete mode 100644 grammar/tests/serialization/mod.rs delete mode 100644 grammar/tests/tuple.rs rename {grammar => parser}/Cargo.toml (74%) rename {ast => parser}/benches/big_circuit.leo (100%) rename {ast => parser}/benches/big_if_else.leo (100%) rename {ast => parser}/benches/big_ternary.leo (100%) rename {ast => parser}/benches/leo_ast.rs (54%) rename {ast => parser}/benches/long_array.leo (100%) rename {ast => parser}/benches/long_expr.leo (100%) rename {ast => parser}/benches/many_assigns.leo (100%) rename {ast => parser}/benches/many_foos.leo (100%) create mode 100644 parser/src/context.rs rename {ast => parser}/src/errors/deprecated.rs (51%) rename {grammar => parser}/src/errors/mod.rs (90%) create mode 100644 parser/src/errors/syntax.rs create mode 100644 parser/src/errors/token.rs rename grammar/src/imports/mod.rs => parser/src/lib.rs (64%) create mode 100644 parser/src/parser/expression.rs create mode 100644 parser/src/parser/file.rs rename grammar/src/common/spread_or_expression.rs => parser/src/parser/mod.rs (54%) create mode 100644 parser/src/parser/statement.rs create mode 100644 parser/src/parser/type_.rs create mode 100644 parser/src/test.rs create mode 100644 parser/src/token.rs create mode 100644 parser/src/tokenizer.rs rename {ast => parser}/tests/mod.rs (100%) rename {ast => parser}/tests/serialization/deprecated_error.leo (100%) rename {ast => parser}/tests/serialization/expected_leo_ast.json (100%) rename {ast => parser}/tests/serialization/json.rs (76%) rename {ast => parser}/tests/serialization/main.leo (100%) rename {ast => parser}/tests/serialization/mod.rs (100%) rename {ast => parser}/tests/serialization/parser_error.leo (100%) create mode 100644 tests/fail/parse/address/empty.leo create mode 100644 tests/fail/parse/address/invalid_length.leo create mode 100644 tests/fail/parse/address/invalid_prefix.leo create mode 100644 tests/fail/parse/array/initializer_fail.leo create mode 100644 tests/fail/parse/array/type_fail.leo create mode 100644 tests/fail/parse/circuits/self_circuit.leo create mode 100644 tests/fail/parse/console/log_fail.leo create mode 100644 tests/fail/parse/import/names_a_dash.leo create mode 100644 tests/fail/parse/import/names_dash_a.leo create mode 100644 tests/fail/parse/import/names_dollar.leo create mode 100644 tests/fail/parse/syntax/address_fail.leo create mode 100644 tests/fail/parse/syntax/console_fail.leo create mode 100644 tests/fail/parse/syntax/field_fail.leo create mode 100644 tests/fail/parse/syntax/group_fail.leo create mode 100644 tests/fail/parse/syntax/i8_fail.leo create mode 100644 tests/fail/parse/syntax/input_fail.leo create mode 100644 tests/fail/parse/syntax/self_keyword_fail.leo create mode 100644 tests/fail/parse/syntax/self_type_fail.leo create mode 100644 tests/fail/parse/syntax/semicolon.leo create mode 100644 tests/fail/parse/syntax/true_fail.leo create mode 100644 tests/fail/parse/syntax/u8_fail.leo create mode 100644 tests/pass/parse/address/console_assert_fail.leo create mode 100644 tests/pass/parse/address/console_assert_pass.leo create mode 100644 tests/pass/parse/address/equal.leo create mode 100644 tests/pass/parse/address/implicit_invalid.leo create mode 100644 tests/pass/parse/address/implicit_valid.leo create mode 100644 tests/pass/parse/address/input.leo create mode 100644 tests/pass/parse/address/ternary.leo create mode 100644 tests/pass/parse/address/valid.leo create mode 100644 tests/pass/parse/array/initializer.leo create mode 100644 tests/pass/parse/array/initializer_input.leo create mode 100644 tests/pass/parse/array/inline.leo create mode 100644 tests/pass/parse/array/input_nested_3x2.leo create mode 100644 tests/pass/parse/array/input_tuple_3x2.leo create mode 100644 tests/pass/parse/array/input_tuple_3x2_fail.leo create mode 100644 tests/pass/parse/array/multi_fail_initializer.leo create mode 100644 tests/pass/parse/array/multi_fail_inline.leo create mode 100644 tests/pass/parse/array/multi_initializer.leo create mode 100644 tests/pass/parse/array/multi_initializer_fail.leo create mode 100644 tests/pass/parse/array/nested.leo create mode 100644 tests/pass/parse/array/nested_3x2_value.leo create mode 100644 tests/pass/parse/array/nested_3x2_value_fail.leo create mode 100644 tests/pass/parse/array/registers.leo create mode 100644 tests/pass/parse/array/slice.leo create mode 100644 tests/pass/parse/array/slice_lower.leo create mode 100644 tests/pass/parse/array/spread.leo create mode 100644 tests/pass/parse/array/tuple_3x2_value.leo create mode 100644 tests/pass/parse/array/tuple_3x2_value_fail.leo create mode 100644 tests/pass/parse/array/type_input_3x2.leo create mode 100644 tests/pass/parse/array/type_input_4x3x2.leo create mode 100644 tests/pass/parse/array/type_nested_value_nested_3x2.leo create mode 100644 tests/pass/parse/array/type_nested_value_nested_3x2_fail.leo create mode 100644 tests/pass/parse/array/type_nested_value_nested_4x3x2.leo create mode 100644 tests/pass/parse/array/type_nested_value_nested_4x3x2_fail.leo create mode 100644 tests/pass/parse/array/type_nested_value_tuple_3x2.leo create mode 100644 tests/pass/parse/array/type_nested_value_tuple_3x2_fail.leo create mode 100644 tests/pass/parse/array/type_nested_value_tuple_4x3x2.leo create mode 100644 tests/pass/parse/array/type_nested_value_tuple_4x3x2_fail.leo create mode 100644 tests/pass/parse/array/type_tuple_value_nested_3x2.leo create mode 100644 tests/pass/parse/array/type_tuple_value_nested_3x2_fail.leo create mode 100644 tests/pass/parse/array/type_tuple_value_nested_4x3x2.leo create mode 100644 tests/pass/parse/array/type_tuple_value_nested_4x3x2_fail.leo create mode 100644 tests/pass/parse/array/type_tuple_value_tuple_3x2.leo create mode 100644 tests/pass/parse/array/type_tuple_value_tuple_3x2_fail.leo create mode 100644 tests/pass/parse/array/type_tuple_value_tuple_4x3x2.leo create mode 100644 tests/pass/parse/array/type_tuple_value_tuple_4x3x2_fail.leo create mode 100644 tests/pass/parse/array/variable_slice_fail.leo create mode 100644 tests/pass/parse/boolean/all.leo create mode 100644 tests/pass/parse/boolean/assert_eq_input.leo create mode 100644 tests/pass/parse/boolean/conditional_mut.leo create mode 100644 tests/pass/parse/boolean/false_and_false.leo create mode 100644 tests/pass/parse/boolean/false_or_false.leo create mode 100644 tests/pass/parse/boolean/not_false.leo create mode 100644 tests/pass/parse/boolean/not_mutable.leo create mode 100644 tests/pass/parse/boolean/not_true.leo create mode 100644 tests/pass/parse/boolean/not_u32.leo create mode 100644 tests/pass/parse/boolean/output_register.leo create mode 100644 tests/pass/parse/boolean/true_and_false.leo create mode 100644 tests/pass/parse/boolean/true_and_true.leo create mode 100644 tests/pass/parse/boolean/true_and_u32.leo create mode 100644 tests/pass/parse/boolean/true_or_false.leo create mode 100644 tests/pass/parse/boolean/true_or_true.leo create mode 100644 tests/pass/parse/boolean/true_or_u32.leo create mode 100644 tests/pass/parse/circuits/define_circuit_inside_circuit_function.leo create mode 100644 tests/pass/parse/circuits/duplicate_name_context.leo create mode 100644 tests/pass/parse/circuits/inline.leo create mode 100644 tests/pass/parse/circuits/inline_fail.leo create mode 100644 tests/pass/parse/circuits/inline_member_fail.leo create mode 100644 tests/pass/parse/circuits/inline_member_pass.leo create mode 100644 tests/pass/parse/circuits/inline_undefined.leo create mode 100644 tests/pass/parse/circuits/member_function.leo create mode 100644 tests/pass/parse/circuits/member_function_fail.leo create mode 100644 tests/pass/parse/circuits/member_function_invalid.leo create mode 100644 tests/pass/parse/circuits/member_function_nested.leo create mode 100644 tests/pass/parse/circuits/member_static_function.leo create mode 100644 tests/pass/parse/circuits/member_static_function_invalid.leo create mode 100644 tests/pass/parse/circuits/member_static_function_nested.leo create mode 100644 tests/pass/parse/circuits/member_static_function_undefined.leo create mode 100644 tests/pass/parse/circuits/member_variable.leo create mode 100644 tests/pass/parse/circuits/member_variable_and_function.leo create mode 100644 tests/pass/parse/circuits/member_variable_fail.leo create mode 100644 tests/pass/parse/circuits/mut_function_fail.leo create mode 100644 tests/pass/parse/circuits/mut_self_function_fail.leo create mode 100644 tests/pass/parse/circuits/mut_self_static_function_fail.leo create mode 100644 tests/pass/parse/circuits/mut_self_variable.leo create mode 100644 tests/pass/parse/circuits/mut_self_variable_branch.leo create mode 100644 tests/pass/parse/circuits/mut_self_variable_conditional.leo create mode 100644 tests/pass/parse/circuits/mut_self_variable_fail.leo create mode 100644 tests/pass/parse/circuits/mut_static_function_fail.leo create mode 100644 tests/pass/parse/circuits/mut_variable.leo create mode 100644 tests/pass/parse/circuits/mut_variable_fail.leo create mode 100644 tests/pass/parse/circuits/pedersen_mock.leo create mode 100644 tests/pass/parse/circuits/self_fail.leo create mode 100644 tests/pass/parse/circuits/self_member.leo create mode 100644 tests/pass/parse/circuits/self_member_invalid.leo create mode 100644 tests/pass/parse/circuits/self_member_undefined.leo create mode 100644 tests/pass/parse/compiler/main.leo create mode 100644 tests/pass/parse/console/assert.leo create mode 100644 tests/pass/parse/console/conditional_assert.leo create mode 100644 tests/pass/parse/console/debug.leo create mode 100644 tests/pass/parse/console/error.leo create mode 100644 tests/pass/parse/console/log.leo create mode 100644 tests/pass/parse/console/log_conditional.leo create mode 100644 tests/pass/parse/console/log_input.leo create mode 100644 tests/pass/parse/console/log_parameter.leo create mode 100644 tests/pass/parse/console/log_parameter_fail_empty.leo create mode 100644 tests/pass/parse/console/log_parameter_fail_none.leo create mode 100644 tests/pass/parse/console/log_parameter_fail_unknown.leo create mode 100644 tests/pass/parse/console/log_parameter_many.leo create mode 100644 tests/pass/parse/core/arguments_length_fail.leo create mode 100644 tests/pass/parse/core/arguments_type_fail.leo create mode 100644 tests/pass/parse/core/blake2s_input.leo create mode 100644 tests/pass/parse/core/blake2s_random.leo create mode 100644 tests/pass/parse/core/core_circuit_invalid.leo create mode 100644 tests/pass/parse/core/core_circuit_star_fail.leo create mode 100644 tests/pass/parse/core/core_package_invalid.leo create mode 100644 tests/pass/parse/core/core_unstable_package_invalid.leo create mode 100644 tests/pass/parse/core/unstable_blake2s.leo create mode 100644 tests/pass/parse/definition/out_of_order.leo create mode 100644 tests/pass/parse/definition/out_of_order_with_import.leo create mode 100644 tests/pass/parse/field/add.leo create mode 100644 tests/pass/parse/field/console_assert.leo create mode 100644 tests/pass/parse/field/div.leo create mode 100644 tests/pass/parse/field/eq.leo create mode 100644 tests/pass/parse/field/field.leo create mode 100644 tests/pass/parse/field/mul.leo create mode 100644 tests/pass/parse/field/negate.leo create mode 100644 tests/pass/parse/field/sub.leo create mode 100644 tests/pass/parse/field/ternary.leo create mode 100644 tests/pass/parse/function/array_input.leo create mode 100644 tests/pass/parse/function/array_params_direct_call.leo create mode 100644 tests/pass/parse/function/conditional_return.leo create mode 100644 tests/pass/parse/function/empty.leo create mode 100644 tests/pass/parse/function/iteration.leo create mode 100644 tests/pass/parse/function/iteration_repeated.leo create mode 100644 tests/pass/parse/function/multiple_returns.leo create mode 100644 tests/pass/parse/function/multiple_returns_fail.leo create mode 100644 tests/pass/parse/function/multiple_returns_fail_conditional.leo create mode 100644 tests/pass/parse/function/multiple_returns_main.leo create mode 100644 tests/pass/parse/function/newlines.leo create mode 100644 tests/pass/parse/function/repeated.leo create mode 100644 tests/pass/parse/function/return.leo create mode 100644 tests/pass/parse/function/return_array_nested_fail.leo create mode 100644 tests/pass/parse/function/return_array_nested_pass.leo create mode 100644 tests/pass/parse/function/return_array_tuple_fail.leo create mode 100644 tests/pass/parse/function/return_array_tuple_pass.leo create mode 100644 tests/pass/parse/function/return_tuple.leo create mode 100644 tests/pass/parse/function/return_tuple_conditional.leo create mode 100644 tests/pass/parse/function/scope_fail.leo create mode 100644 tests/pass/parse/function/undefined.leo create mode 100644 tests/pass/parse/function/value_unchanged.leo create mode 100644 tests/pass/parse/group/add.leo create mode 100644 tests/pass/parse/group/assert_eq.leo create mode 100644 tests/pass/parse/group/both_sign_high.leo create mode 100644 tests/pass/parse/group/both_sign_inferred.leo create mode 100644 tests/pass/parse/group/both_sign_low.leo create mode 100644 tests/pass/parse/group/eq.leo create mode 100644 tests/pass/parse/group/input.leo create mode 100644 tests/pass/parse/group/negate.leo create mode 100644 tests/pass/parse/group/one.leo create mode 100644 tests/pass/parse/group/point.leo create mode 100644 tests/pass/parse/group/point_input.leo create mode 100644 tests/pass/parse/group/positive_and_negative.leo create mode 100644 tests/pass/parse/group/sub.leo create mode 100644 tests/pass/parse/group/ternary.leo create mode 100644 tests/pass/parse/group/x_and_y.leo create mode 100644 tests/pass/parse/group/x_sign_high.leo create mode 100644 tests/pass/parse/group/x_sign_inferred.leo create mode 100644 tests/pass/parse/group/x_sign_low.leo create mode 100644 tests/pass/parse/group/y_sign_high.leo create mode 100644 tests/pass/parse/group/y_sign_inferred.leo create mode 100644 tests/pass/parse/group/y_sign_low.leo create mode 100644 tests/pass/parse/group/zero.leo create mode 100644 tests/pass/parse/import/a-9.leo create mode 100644 tests/pass/parse/import/a0-f.leo create mode 100644 tests/pass/parse/import/alias.leo create mode 100644 tests/pass/parse/import/basic.leo create mode 100755 tests/pass/parse/import/bat.leo create mode 100755 tests/pass/parse/import/baz.leo create mode 100644 tests/pass/parse/import/hello-world.leo create mode 100755 tests/pass/parse/import/lib.leo create mode 100644 tests/pass/parse/import/many_import.leo create mode 100644 tests/pass/parse/import/many_import_star.leo create mode 100644 tests/pass/parse/import/multiple.leo create mode 100644 tests/pass/parse/import/names.leo create mode 100644 tests/pass/parse/import/names_underscore.leo create mode 100644 tests/pass/parse/import/star.leo create mode 100644 tests/pass/parse/import/star_fail.leo create mode 100644 tests/pass/parse/import/test-import.leo create mode 100644 tests/pass/parse/integers/i128/add.leo create mode 100644 tests/pass/parse/integers/i128/console_assert.leo create mode 100644 tests/pass/parse/integers/i128/div.leo create mode 100644 tests/pass/parse/integers/i128/eq.leo create mode 100644 tests/pass/parse/integers/i128/ge.leo create mode 100644 tests/pass/parse/integers/i128/gt.leo create mode 100644 tests/pass/parse/integers/i128/input.leo create mode 100644 tests/pass/parse/integers/i128/le.leo create mode 100644 tests/pass/parse/integers/i128/lt.leo create mode 100644 tests/pass/parse/integers/i128/max.leo create mode 100644 tests/pass/parse/integers/i128/max_fail.leo create mode 100644 tests/pass/parse/integers/i128/min.leo create mode 100644 tests/pass/parse/integers/i128/min_fail.leo create mode 100644 tests/pass/parse/integers/i128/mod.rs create mode 100644 tests/pass/parse/integers/i128/mul.leo create mode 100644 tests/pass/parse/integers/i128/ne.leo create mode 100644 tests/pass/parse/integers/i128/negate.leo create mode 100644 tests/pass/parse/integers/i128/negate_min.leo create mode 100644 tests/pass/parse/integers/i128/negate_zero.leo create mode 100644 tests/pass/parse/integers/i128/pow.leo create mode 100644 tests/pass/parse/integers/i128/sub.leo create mode 100644 tests/pass/parse/integers/i128/ternary.leo create mode 100644 tests/pass/parse/integers/i16/add.leo create mode 100644 tests/pass/parse/integers/i16/console_assert.leo create mode 100644 tests/pass/parse/integers/i16/div.leo create mode 100644 tests/pass/parse/integers/i16/eq.leo create mode 100644 tests/pass/parse/integers/i16/ge.leo create mode 100644 tests/pass/parse/integers/i16/gt.leo create mode 100644 tests/pass/parse/integers/i16/input.leo create mode 100644 tests/pass/parse/integers/i16/le.leo create mode 100644 tests/pass/parse/integers/i16/lt.leo create mode 100644 tests/pass/parse/integers/i16/max.leo create mode 100644 tests/pass/parse/integers/i16/max_fail.leo create mode 100644 tests/pass/parse/integers/i16/min.leo create mode 100644 tests/pass/parse/integers/i16/min_fail.leo create mode 100644 tests/pass/parse/integers/i16/mod.rs create mode 100644 tests/pass/parse/integers/i16/mul.leo create mode 100644 tests/pass/parse/integers/i16/ne.leo create mode 100644 tests/pass/parse/integers/i16/negate.leo create mode 100644 tests/pass/parse/integers/i16/negate_min.leo create mode 100644 tests/pass/parse/integers/i16/negate_zero.leo create mode 100644 tests/pass/parse/integers/i16/pow.leo create mode 100644 tests/pass/parse/integers/i16/sub.leo create mode 100644 tests/pass/parse/integers/i16/ternary.leo create mode 100644 tests/pass/parse/integers/i32/add.leo create mode 100644 tests/pass/parse/integers/i32/console_assert.leo create mode 100644 tests/pass/parse/integers/i32/div.leo create mode 100644 tests/pass/parse/integers/i32/eq.leo create mode 100644 tests/pass/parse/integers/i32/ge.leo create mode 100644 tests/pass/parse/integers/i32/gt.leo create mode 100644 tests/pass/parse/integers/i32/input.leo create mode 100644 tests/pass/parse/integers/i32/le.leo create mode 100644 tests/pass/parse/integers/i32/lt.leo create mode 100644 tests/pass/parse/integers/i32/max.leo create mode 100644 tests/pass/parse/integers/i32/max_fail.leo create mode 100644 tests/pass/parse/integers/i32/min.leo create mode 100644 tests/pass/parse/integers/i32/min_fail.leo create mode 100644 tests/pass/parse/integers/i32/mod.rs create mode 100644 tests/pass/parse/integers/i32/mul.leo create mode 100644 tests/pass/parse/integers/i32/ne.leo create mode 100644 tests/pass/parse/integers/i32/negate.leo create mode 100644 tests/pass/parse/integers/i32/negate_min.leo create mode 100644 tests/pass/parse/integers/i32/negate_zero.leo create mode 100644 tests/pass/parse/integers/i32/pow.leo create mode 100644 tests/pass/parse/integers/i32/sub.leo create mode 100644 tests/pass/parse/integers/i32/ternary.leo create mode 100644 tests/pass/parse/integers/i64/add.leo create mode 100644 tests/pass/parse/integers/i64/console_assert.leo create mode 100644 tests/pass/parse/integers/i64/div.leo create mode 100644 tests/pass/parse/integers/i64/eq.leo create mode 100644 tests/pass/parse/integers/i64/ge.leo create mode 100644 tests/pass/parse/integers/i64/gt.leo create mode 100644 tests/pass/parse/integers/i64/input.leo create mode 100644 tests/pass/parse/integers/i64/le.leo create mode 100644 tests/pass/parse/integers/i64/lt.leo create mode 100644 tests/pass/parse/integers/i64/max.leo create mode 100644 tests/pass/parse/integers/i64/max_fail.leo create mode 100644 tests/pass/parse/integers/i64/min.leo create mode 100644 tests/pass/parse/integers/i64/min_fail.leo create mode 100644 tests/pass/parse/integers/i64/mod.rs create mode 100644 tests/pass/parse/integers/i64/mul.leo create mode 100644 tests/pass/parse/integers/i64/ne.leo create mode 100644 tests/pass/parse/integers/i64/negate.leo create mode 100644 tests/pass/parse/integers/i64/negate_min.leo create mode 100644 tests/pass/parse/integers/i64/negate_zero.leo create mode 100644 tests/pass/parse/integers/i64/pow.leo create mode 100644 tests/pass/parse/integers/i64/sub.leo create mode 100644 tests/pass/parse/integers/i64/ternary.leo create mode 100644 tests/pass/parse/integers/i8/add.leo create mode 100644 tests/pass/parse/integers/i8/console_assert.leo create mode 100644 tests/pass/parse/integers/i8/div.leo create mode 100644 tests/pass/parse/integers/i8/eq.leo create mode 100644 tests/pass/parse/integers/i8/ge.leo create mode 100644 tests/pass/parse/integers/i8/gt.leo create mode 100644 tests/pass/parse/integers/i8/input.leo create mode 100644 tests/pass/parse/integers/i8/le.leo create mode 100644 tests/pass/parse/integers/i8/lt.leo create mode 100644 tests/pass/parse/integers/i8/max.leo create mode 100644 tests/pass/parse/integers/i8/max_fail.leo create mode 100644 tests/pass/parse/integers/i8/min.leo create mode 100644 tests/pass/parse/integers/i8/min_fail.leo create mode 100644 tests/pass/parse/integers/i8/mod.rs create mode 100644 tests/pass/parse/integers/i8/mul.leo create mode 100644 tests/pass/parse/integers/i8/ne.leo create mode 100644 tests/pass/parse/integers/i8/negate.leo create mode 100644 tests/pass/parse/integers/i8/negate_min.leo create mode 100644 tests/pass/parse/integers/i8/negate_zero.leo create mode 100644 tests/pass/parse/integers/i8/pow.leo create mode 100644 tests/pass/parse/integers/i8/sub.leo create mode 100644 tests/pass/parse/integers/i8/ternary.leo create mode 100644 tests/pass/parse/integers/u128/add.leo create mode 100644 tests/pass/parse/integers/u128/console_assert.leo create mode 100644 tests/pass/parse/integers/u128/div.leo create mode 100644 tests/pass/parse/integers/u128/eq.leo create mode 100644 tests/pass/parse/integers/u128/ge.leo create mode 100644 tests/pass/parse/integers/u128/gt.leo create mode 100644 tests/pass/parse/integers/u128/input.leo create mode 100644 tests/pass/parse/integers/u128/le.leo create mode 100644 tests/pass/parse/integers/u128/lt.leo create mode 100644 tests/pass/parse/integers/u128/max.leo create mode 100644 tests/pass/parse/integers/u128/max_fail.leo create mode 100644 tests/pass/parse/integers/u128/min.leo create mode 100644 tests/pass/parse/integers/u128/min_fail.leo create mode 100644 tests/pass/parse/integers/u128/mod.rs create mode 100644 tests/pass/parse/integers/u128/mul.leo create mode 100644 tests/pass/parse/integers/u128/ne.leo create mode 100644 tests/pass/parse/integers/u128/pow.leo create mode 100644 tests/pass/parse/integers/u128/sub.leo create mode 100644 tests/pass/parse/integers/u128/ternary.leo create mode 100644 tests/pass/parse/integers/u16/add.leo create mode 100644 tests/pass/parse/integers/u16/console_assert.leo create mode 100644 tests/pass/parse/integers/u16/div.leo create mode 100644 tests/pass/parse/integers/u16/eq.leo create mode 100644 tests/pass/parse/integers/u16/ge.leo create mode 100644 tests/pass/parse/integers/u16/gt.leo create mode 100644 tests/pass/parse/integers/u16/input.leo create mode 100644 tests/pass/parse/integers/u16/le.leo create mode 100644 tests/pass/parse/integers/u16/lt.leo create mode 100644 tests/pass/parse/integers/u16/max.leo create mode 100644 tests/pass/parse/integers/u16/max_fail.leo create mode 100644 tests/pass/parse/integers/u16/min.leo create mode 100644 tests/pass/parse/integers/u16/min_fail.leo create mode 100644 tests/pass/parse/integers/u16/mod.rs create mode 100644 tests/pass/parse/integers/u16/mul.leo create mode 100644 tests/pass/parse/integers/u16/ne.leo create mode 100644 tests/pass/parse/integers/u16/pow.leo create mode 100644 tests/pass/parse/integers/u16/sub.leo create mode 100644 tests/pass/parse/integers/u16/ternary.leo create mode 100644 tests/pass/parse/integers/u32/add.leo create mode 100644 tests/pass/parse/integers/u32/console_assert.leo create mode 100644 tests/pass/parse/integers/u32/div.leo create mode 100644 tests/pass/parse/integers/u32/eq.leo create mode 100644 tests/pass/parse/integers/u32/ge.leo create mode 100644 tests/pass/parse/integers/u32/gt.leo create mode 100644 tests/pass/parse/integers/u32/input.leo create mode 100644 tests/pass/parse/integers/u32/le.leo create mode 100644 tests/pass/parse/integers/u32/lt.leo create mode 100644 tests/pass/parse/integers/u32/max.leo create mode 100644 tests/pass/parse/integers/u32/max_fail.leo create mode 100644 tests/pass/parse/integers/u32/min.leo create mode 100644 tests/pass/parse/integers/u32/min_fail.leo create mode 100644 tests/pass/parse/integers/u32/mod.rs create mode 100644 tests/pass/parse/integers/u32/mul.leo create mode 100644 tests/pass/parse/integers/u32/ne.leo create mode 100644 tests/pass/parse/integers/u32/pow.leo create mode 100644 tests/pass/parse/integers/u32/sub.leo create mode 100644 tests/pass/parse/integers/u32/ternary.leo create mode 100644 tests/pass/parse/integers/u64/add.leo create mode 100644 tests/pass/parse/integers/u64/console_assert.leo create mode 100644 tests/pass/parse/integers/u64/div.leo create mode 100644 tests/pass/parse/integers/u64/eq.leo create mode 100644 tests/pass/parse/integers/u64/ge.leo create mode 100644 tests/pass/parse/integers/u64/gt.leo create mode 100644 tests/pass/parse/integers/u64/input.leo create mode 100644 tests/pass/parse/integers/u64/le.leo create mode 100644 tests/pass/parse/integers/u64/lt.leo create mode 100644 tests/pass/parse/integers/u64/max.leo create mode 100644 tests/pass/parse/integers/u64/max_fail.leo create mode 100644 tests/pass/parse/integers/u64/min.leo create mode 100644 tests/pass/parse/integers/u64/min_fail.leo create mode 100644 tests/pass/parse/integers/u64/mod.rs create mode 100644 tests/pass/parse/integers/u64/mul.leo create mode 100644 tests/pass/parse/integers/u64/ne.leo create mode 100644 tests/pass/parse/integers/u64/pow.leo create mode 100644 tests/pass/parse/integers/u64/sub.leo create mode 100644 tests/pass/parse/integers/u64/ternary.leo create mode 100644 tests/pass/parse/integers/u8/add.leo create mode 100644 tests/pass/parse/integers/u8/console_assert.leo create mode 100644 tests/pass/parse/integers/u8/div.leo create mode 100644 tests/pass/parse/integers/u8/eq.leo create mode 100644 tests/pass/parse/integers/u8/ge.leo create mode 100644 tests/pass/parse/integers/u8/gt.leo create mode 100644 tests/pass/parse/integers/u8/input.leo create mode 100644 tests/pass/parse/integers/u8/le.leo create mode 100644 tests/pass/parse/integers/u8/lt.leo create mode 100644 tests/pass/parse/integers/u8/max.leo create mode 100644 tests/pass/parse/integers/u8/max_fail.leo create mode 100644 tests/pass/parse/integers/u8/min.leo create mode 100644 tests/pass/parse/integers/u8/min_fail.leo create mode 100644 tests/pass/parse/integers/u8/mod.rs create mode 100644 tests/pass/parse/integers/u8/mul.leo create mode 100644 tests/pass/parse/integers/u8/ne.leo create mode 100644 tests/pass/parse/integers/u8/pow.leo create mode 100644 tests/pass/parse/integers/u8/sub.leo create mode 100644 tests/pass/parse/integers/u8/ternary.leo create mode 100644 tests/pass/parse/mutability/array.leo create mode 100644 tests/pass/parse/mutability/array_mut.leo create mode 100644 tests/pass/parse/mutability/array_splice_mut.leo create mode 100644 tests/pass/parse/mutability/array_tuple_mut.leo create mode 100644 tests/pass/parse/mutability/circuit.leo create mode 100644 tests/pass/parse/mutability/circuit_function_mut.leo create mode 100644 tests/pass/parse/mutability/circuit_mut.leo create mode 100644 tests/pass/parse/mutability/circuit_static_function_mut.leo create mode 100644 tests/pass/parse/mutability/circuit_variable_mut.leo create mode 100644 tests/pass/parse/mutability/const.leo create mode 100644 tests/pass/parse/mutability/function_input.leo create mode 100644 tests/pass/parse/mutability/function_input_mut.leo create mode 100644 tests/pass/parse/mutability/let.leo create mode 100644 tests/pass/parse/mutability/let_mut.leo create mode 100644 tests/pass/parse/mutability/let_mut_nested.leo create mode 100644 tests/pass/parse/mutability/swap.leo create mode 100644 tests/pass/parse/statements/assert.leo create mode 100644 tests/pass/parse/statements/block.leo create mode 100644 tests/pass/parse/statements/chain.leo create mode 100644 tests/pass/parse/statements/for_loop.leo create mode 100644 tests/pass/parse/statements/iteration_basic.leo create mode 100644 tests/pass/parse/statements/multiple_returns.leo create mode 100644 tests/pass/parse/statements/mutate.leo create mode 100644 tests/pass/parse/statements/nested.leo create mode 100644 tests/pass/parse/statements/num_returns_fail.leo create mode 100644 tests/pass/parse/statements/ternary_basic.leo create mode 100644 tests/pass/parse/syntax/compare_mismatched_types.leo create mode 100644 tests/pass/parse/syntax/undefined.leo create mode 100644 tests/pass/parse/tuples/access.leo create mode 100644 tests/pass/parse/tuples/basic.leo create mode 100644 tests/pass/parse/tuples/function.leo create mode 100644 tests/pass/parse/tuples/function_multiple.leo create mode 100644 tests/pass/parse/tuples/function_typed.leo create mode 100644 tests/pass/parse/tuples/input.leo create mode 100644 tests/pass/parse/tuples/multiple.leo create mode 100644 tests/pass/parse/tuples/multiple_typed.leo create mode 100644 tests/pass/parse/tuples/nested.leo create mode 100644 tests/pass/parse/tuples/nested_access.leo create mode 100644 tests/pass/parse/tuples/nested_typed.leo create mode 100644 tests/pass/parse/tuples/typed.leo diff --git a/Cargo.lock b/Cargo.lock index dc53565464..b6e5ac29f5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1196,7 +1196,7 @@ dependencies = [ "criterion", "indexmap", "leo-ast", - "leo-grammar", + "leo-parser", "num-bigint", "serde", "serde_json", @@ -1210,7 +1210,6 @@ version = "1.2.3" dependencies = [ "criterion", "indexmap", - "leo-grammar", "leo-input", "pest", "serde", @@ -1228,10 +1227,10 @@ dependencies = [ "leo-asg", "leo-ast", "leo-gadgets", - "leo-grammar", "leo-imports", "leo-input", "leo-package", + "leo-parser", "leo-state", "num-bigint", "pest", @@ -1266,22 +1265,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "leo-grammar" -version = "1.2.3" -dependencies = [ - "criterion", - "from-pest", - "lazy_static", - "pest", - "pest-ast", - "pest_derive", - "serde", - "serde_json", - "thiserror", - "tracing", -] - [[package]] name = "leo-imports" version = "1.2.3" @@ -1289,7 +1272,7 @@ dependencies = [ "indexmap", "leo-asg", "leo-ast", - "leo-grammar", + "leo-parser", "thiserror", "tracing", ] @@ -1364,6 +1347,20 @@ dependencies = [ "zip", ] +[[package]] +name = "leo-parser" +version = "1.2.3" +dependencies = [ + "criterion", + "indexmap", + "lazy_static", + "leo-ast", + "serde", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "leo-state" version = "1.2.3" diff --git a/Cargo.toml b/Cargo.toml index 84ef126ea8..7ba70c3dbc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,11 +30,11 @@ members = [ "ast", "compiler", "gadgets", - "grammar", "imports", "input", "linter", "package", + "parser", "state", "synthesizer", ] diff --git a/asg/Cargo.toml b/asg/Cargo.toml index 2bd668b36b..770c031200 100644 --- a/asg/Cargo.toml +++ b/asg/Cargo.toml @@ -33,9 +33,9 @@ version = "1.0" version = "1.2.3" path = "../ast" -[dependencies.leo-grammar] +[dependencies.leo-parser] version = "1.2.3" -path = "../grammar" +path = "../parser" [dependencies.num-bigint] version = "0.3" diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index bab4aa5b3b..f093a65559 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -188,8 +188,30 @@ impl ConstInt { const_int_map!(value_negate, x, x.checked_neg()?); + const_int_map!(value_bit_negate, x, !x); + const_int_op!(to_usize, Option, x, (*x).try_into().ok()); + const_int_op!(to_u128, u128, x, *x as u128); + + const_int_op!(to_u64, u64, x, *x as u64); + + const_int_op!(to_u32, u32, x, *x as u32); + + const_int_op!(to_u16, u16, x, *x as u16); + + const_int_op!(to_u8, u8, x, *x as u8); + + const_int_op!(to_i128, i128, x, *x as i128); + + const_int_op!(to_i64, i64, x, *x as i64); + + const_int_op!(to_i32, i32, x, *x as i32); + + const_int_op!(to_i16, i16, x, *x as i16); + + const_int_op!(to_i8, i8, x, *x as i8); + const_int_op!(to_string, String, x, (*x).to_string()); const_int_bimap!(value_add, x, y, x.checked_add(*y)?); @@ -226,6 +248,21 @@ impl ConstInt { } } + pub fn cast_to(&self, target: &IntegerType) -> ConstInt { + match target { + IntegerType::I8 => ConstInt::I8(self.to_i8()), + IntegerType::I16 => ConstInt::I16(self.to_i16()), + IntegerType::I32 => ConstInt::I32(self.to_i32()), + IntegerType::I64 => ConstInt::I64(self.to_i64()), + IntegerType::I128 => ConstInt::I128(self.to_i128()), + IntegerType::U8 => ConstInt::U8(self.to_u8()), + IntegerType::U16 => ConstInt::U16(self.to_u16()), + IntegerType::U32 => ConstInt::U32(self.to_u32()), + IntegerType::U64 => ConstInt::U64(self.to_u64()), + IntegerType::U128 => ConstInt::U128(self.to_u128()), + } + } + pub fn get_type<'a>(&self) -> Type<'a> { Type::Integer(self.get_int_type()) } diff --git a/asg/src/error/mod.rs b/asg/src/error/mod.rs index 39e60735dc..74f7f3944e 100644 --- a/asg/src/error/mod.rs +++ b/asg/src/error/mod.rs @@ -17,14 +17,11 @@ //! Errors encountered when attempting to convert to an asg from an ast. use crate::Span; -use leo_ast::{AstError, Error as FormattedError}; -use leo_grammar::ParserError; +use leo_ast::{FormattedError, LeoError}; +use leo_parser::SyntaxError; #[derive(Debug, Error)] pub enum AsgConvertError { - #[error("{}", _0)] - AstError(#[from] AstError), - #[error("{}", _0)] Error(#[from] FormattedError), @@ -35,12 +32,32 @@ pub enum AsgConvertError { InternalError(String), #[error("{}", _0)] - ParserError(#[from] ParserError), + SyntaxError(#[from] SyntaxError), +} + +impl LeoError for AsgConvertError { + fn get_path(&self) -> Option<&str> { + match self { + AsgConvertError::Error(error) => error.get_path(), + AsgConvertError::SyntaxError(error) => error.get_path(), + AsgConvertError::ImportError(error) => error.get_path(), + AsgConvertError::InternalError(_) => None, + } + } + + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + AsgConvertError::Error(error) => error.set_path(path, contents), + AsgConvertError::SyntaxError(error) => error.set_path(path, contents), + AsgConvertError::ImportError(error) => error.set_path(path, contents), + AsgConvertError::InternalError(_) => {} + } + } } impl AsgConvertError { fn new_from_span(message: String, span: &Span) -> Self { - AsgConvertError::Error(FormattedError::new_from_span(message, span.clone())) + AsgConvertError::Error(FormattedError::new_from_span(message, span)) } pub fn unresolved_circuit(name: &str, span: &Span) -> Self { @@ -256,6 +273,14 @@ impl AsgConvertError { ) } + pub fn call_test_function(span: &Span) -> Self { + Self::new_from_span("cannot call test function".to_string(), span) + } + + pub fn circuit_test_function(span: &Span) -> Self { + Self::new_from_span("cannot have test function as member of circuit".to_string(), span) + } + pub fn parse_index_error() -> Self { AsgConvertError::InternalError("failed to parse index".to_string()) } diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index 52572a4907..8c91f86da5 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -109,7 +109,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { return Err(AsgConvertError::unexpected_type( "circuit", type_.map(|x| x.to_string()).as_deref(), - &span, + span, )); } }; @@ -117,26 +117,26 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { let member = circuit.members.borrow(); let member = member .get(&name.name) - .ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, &span))?; + .ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, span))?; match member { CircuitMember::Function(body) => { if body.qualifier == FunctionQualifier::Static { return Err(AsgConvertError::circuit_static_call_invalid( &circuit_name, &name.name, - &span, + span, )); } else if body.qualifier == FunctionQualifier::MutSelfRef && !target.is_mut_ref() { return Err(AsgConvertError::circuit_member_mut_call_invalid( &circuit_name, &name.name, - &span, + span, )); } (Some(target), *body) } CircuitMember::Variable(_) => { - return Err(AsgConvertError::circuit_variable_call(&circuit_name, &name.name, &span)); + return Err(AsgConvertError::circuit_variable_call(&circuit_name, &name.name, span)); } } } @@ -150,27 +150,27 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { .resolve_circuit(&circuit_name.name) .ok_or_else(|| AsgConvertError::unresolved_circuit(&circuit_name.name, &circuit_name.span))? } else { - return Err(AsgConvertError::unexpected_type("circuit", None, &span)); + return Err(AsgConvertError::unexpected_type("circuit", None, span)); }; let circuit_name = circuit.name.borrow().name.clone(); let member = circuit.members.borrow(); let member = member .get(&name.name) - .ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, &span))?; + .ok_or_else(|| AsgConvertError::unresolved_circuit_member(&circuit_name, &name.name, span))?; match member { CircuitMember::Function(body) => { if body.qualifier != FunctionQualifier::Static { return Err(AsgConvertError::circuit_member_call_invalid( &circuit_name, &name.name, - &span, + span, )); } (None, *body) } CircuitMember::Variable(_) => { - return Err(AsgConvertError::circuit_variable_call(&circuit_name, &name.name, &span)); + return Err(AsgConvertError::circuit_variable_call(&circuit_name, &name.name, span)); } } } @@ -206,12 +206,15 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { let argument = argument.get().borrow(); let converted = <&Expression<'a>>::from_ast(scope, expr, Some(argument.type_.clone().partial()))?; if argument.const_ && !converted.is_consty() { - return Err(AsgConvertError::unexpected_nonconst(&expr.span())); + return Err(AsgConvertError::unexpected_nonconst(expr.span())); } Ok(Cell::new(converted)) }) .collect::, AsgConvertError>>()?; + if function.is_test() { + return Err(AsgConvertError::call_test_function(&value.span)); + } Ok(CallExpression { parent: Cell::new(None), span: Some(value.span.clone()), diff --git a/asg/src/expression/cast.rs b/asg/src/expression/cast.rs new file mode 100644 index 0000000000..e7060492d4 --- /dev/null +++ b/asg/src/expression/cast.rs @@ -0,0 +1,109 @@ +// 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, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +pub use leo_ast::UnaryOperation; + +use std::cell::Cell; + +#[derive(Clone)] +pub struct CastExpression<'a> { + pub parent: Cell>>, + pub span: Option, + pub inner: Cell<&'a Expression<'a>>, + pub target_type: Type<'a>, +} + +impl<'a> Node for CastExpression<'a> { + fn span(&self) -> Option<&Span> { + self.span.as_ref() + } +} + +impl<'a> ExpressionNode<'a> for CastExpression<'a> { + fn set_parent(&self, parent: &'a Expression<'a>) { + self.parent.replace(Some(parent)); + } + + fn get_parent(&self) -> Option<&'a Expression<'a>> { + self.parent.get() + } + + fn enforce_parents(&self, expr: &'a Expression<'a>) { + self.inner.get().set_parent(expr); + } + + fn get_type(&self) -> Option> { + Some(self.target_type.clone()) + } + + fn is_mut_ref(&self) -> bool { + false + } + + fn const_value(&self) -> Option { + let value = self.inner.get().const_value()?; + match value { + ConstValue::Int(int) => match &self.target_type { + Type::Integer(target) => Some(ConstValue::Int(int.cast_to(target))), + _ => None, + }, + _ => None, + } + } + + fn is_consty(&self) -> bool { + self.inner.get().is_consty() + } +} + +impl<'a> FromAst<'a, leo_ast::CastExpression> for CastExpression<'a> { + fn from_ast( + scope: &'a Scope<'a>, + value: &leo_ast::CastExpression, + expected_type: Option>, + ) -> Result, AsgConvertError> { + let target_type = scope.resolve_ast_type(&value.target_type)?; + if let Some(expected_type) = &expected_type { + if !expected_type.matches(&target_type) { + return Err(AsgConvertError::unexpected_type( + &expected_type.to_string(), + Some(&target_type.to_string()), + &value.span, + )); + } + } + + let inner = <&Expression<'a>>::from_ast(scope, &*value.inner, None)?; + + Ok(CastExpression { + parent: Cell::new(None), + span: Some(value.span.clone()), + inner: Cell::new(inner), + target_type, + }) + } +} + +impl<'a> Into for &CastExpression<'a> { + fn into(self) -> leo_ast::CastExpression { + leo_ast::CastExpression { + target_type: (&self.target_type).into(), + inner: Box::new(self.inner.get().into()), + span: self.span.clone().unwrap_or_default(), + } + } +} diff --git a/asg/src/expression/circuit_init.rs b/asg/src/expression/circuit_init.rs index b7ec7a764b..8c26379072 100644 --- a/asg/src/expression/circuit_init.rs +++ b/asg/src/expression/circuit_init.rs @@ -99,10 +99,10 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' )); } } - let members: IndexMap<&String, (&Identifier, &leo_ast::Expression)> = value + let members: IndexMap<&String, (&Identifier, Option<&leo_ast::Expression>)> = value .members .iter() - .map(|x| (&x.identifier.name, (&x.identifier, &x.expression))) + .map(|x| (&x.identifier.name, (&x.identifier, x.expression.as_ref()))) .collect(); let mut values: Vec<(Identifier, Cell<&'a Expression<'a>>)> = vec![]; @@ -125,7 +125,15 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' continue; }; if let Some((identifier, receiver)) = members.get(&name) { - let received = <&Expression<'a>>::from_ast(scope, *receiver, Some(type_.partial()))?; + let received = if let Some(receiver) = *receiver { + <&Expression<'a>>::from_ast(scope, receiver, Some(type_.partial()))? + } else { + <&Expression<'a>>::from_ast( + scope, + &leo_ast::Expression::Identifier((*identifier).clone()), + Some(type_.partial()), + )? + }; values.push(((*identifier).clone(), Cell::new(received))); } else { return Err(AsgConvertError::missing_circuit_member( @@ -165,7 +173,7 @@ impl<'a> Into for &CircuitInitExpression<'a> { .iter() .map(|(name, value)| leo_ast::CircuitImpliedVariableDefinition { identifier: name.clone(), - expression: value.get().into(), + expression: Some(value.get().into()), }) .collect(), span: self.span.clone().unwrap_or_default(), diff --git a/asg/src/expression/mod.rs b/asg/src/expression/mod.rs index 720bac0781..781f30f497 100644 --- a/asg/src/expression/mod.rs +++ b/asg/src/expression/mod.rs @@ -62,6 +62,9 @@ pub use unary::*; mod variable_ref; pub use variable_ref::*; +mod cast; +pub use cast::*; + use crate::{AsgConvertError, ConstValue, FromAst, Node, PartialType, Scope, Span, Type}; #[derive(Clone)] @@ -71,6 +74,7 @@ pub enum Expression<'a> { Binary(BinaryExpression<'a>), Unary(UnaryExpression<'a>), Ternary(TernaryExpression<'a>), + Cast(CastExpression<'a>), ArrayInline(ArrayInlineExpression<'a>), ArrayInit(ArrayInitExpression<'a>), @@ -95,6 +99,7 @@ impl<'a> Node for Expression<'a> { Binary(x) => x.span(), Unary(x) => x.span(), Ternary(x) => x.span(), + Cast(x) => x.span(), ArrayInline(x) => x.span(), ArrayInit(x) => x.span(), ArrayAccess(x) => x.span(), @@ -128,6 +133,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.set_parent(parent), Unary(x) => x.set_parent(parent), Ternary(x) => x.set_parent(parent), + Cast(x) => x.set_parent(parent), ArrayInline(x) => x.set_parent(parent), ArrayInit(x) => x.set_parent(parent), ArrayAccess(x) => x.set_parent(parent), @@ -148,6 +154,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.get_parent(), Unary(x) => x.get_parent(), Ternary(x) => x.get_parent(), + Cast(x) => x.get_parent(), ArrayInline(x) => x.get_parent(), ArrayInit(x) => x.get_parent(), ArrayAccess(x) => x.get_parent(), @@ -168,6 +175,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.enforce_parents(expr), Unary(x) => x.enforce_parents(expr), Ternary(x) => x.enforce_parents(expr), + Cast(x) => x.enforce_parents(expr), ArrayInline(x) => x.enforce_parents(expr), ArrayInit(x) => x.enforce_parents(expr), ArrayAccess(x) => x.enforce_parents(expr), @@ -188,6 +196,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.get_type(), Unary(x) => x.get_type(), Ternary(x) => x.get_type(), + Cast(x) => x.get_type(), ArrayInline(x) => x.get_type(), ArrayInit(x) => x.get_type(), ArrayAccess(x) => x.get_type(), @@ -208,6 +217,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.is_mut_ref(), Unary(x) => x.is_mut_ref(), Ternary(x) => x.is_mut_ref(), + Cast(x) => x.is_mut_ref(), ArrayInline(x) => x.is_mut_ref(), ArrayInit(x) => x.is_mut_ref(), ArrayAccess(x) => x.is_mut_ref(), @@ -228,6 +238,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.const_value(), Unary(x) => x.const_value(), Ternary(x) => x.const_value(), + Cast(x) => x.const_value(), ArrayInline(x) => x.const_value(), ArrayInit(x) => x.const_value(), ArrayAccess(x) => x.const_value(), @@ -248,6 +259,7 @@ impl<'a> ExpressionNode<'a> for Expression<'a> { Binary(x) => x.is_consty(), Unary(x) => x.is_consty(), Ternary(x) => x.is_consty(), + Cast(x) => x.is_consty(), ArrayInline(x) => x.is_consty(), ArrayInit(x) => x.is_consty(), ArrayAccess(x) => x.is_consty(), @@ -281,6 +293,9 @@ impl<'a> FromAst<'a, leo_ast::Expression> for &'a Expression<'a> { Ternary(conditional) => scope.alloc_expression( TernaryExpression::from_ast(scope, conditional, expected_type).map(Expression::Ternary)?, ), + Cast(cast) => { + scope.alloc_expression(CastExpression::from_ast(scope, cast, expected_type).map(Expression::Cast)?) + } ArrayInline(array_inline) => scope.alloc_expression( ArrayInlineExpression::from_ast(scope, array_inline, expected_type).map(Expression::ArrayInline)?, @@ -333,6 +348,7 @@ impl<'a> Into for &Expression<'a> { Binary(x) => leo_ast::Expression::Binary(x.into()), Unary(x) => leo_ast::Expression::Unary(x.into()), Ternary(x) => leo_ast::Expression::Ternary(x.into()), + Cast(x) => leo_ast::Expression::Cast(x.into()), ArrayInline(x) => leo_ast::Expression::ArrayInline(x.into()), ArrayInit(x) => leo_ast::Expression::ArrayInit(x.into()), ArrayAccess(x) => leo_ast::Expression::ArrayAccess(x.into()), diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index 0e5078e71c..fa8ac8474a 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -69,6 +69,10 @@ impl<'a> ExpressionNode<'a> for UnaryExpression<'a> { _ => None, } } + UnaryOperation::BitNot => match inner { + ConstValue::Int(value) => Some(ConstValue::Int(value.value_bit_negate()?)), + _ => None, + }, } } else { None @@ -110,6 +114,17 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { )); } }, + UnaryOperation::BitNot => match expected_type.map(|x| x.full()).flatten() { + Some(type_ @ Type::Integer(_)) => Some(type_), + None => None, + Some(type_) => { + return Err(AsgConvertError::unexpected_type( + &type_.to_string(), + Some("integer"), + &value.span, + )); + } + }, }; Ok(UnaryExpression { parent: Cell::new(None), diff --git a/asg/src/lib.rs b/asg/src/lib.rs index ada569edeb..098abf569a 100644 --- a/asg/src/lib.rs +++ b/asg/src/lib.rs @@ -76,8 +76,6 @@ pub use context::*; pub use leo_ast::{Ast, Identifier, Span}; -use std::path::Path; - /// The abstract semantic graph (ASG) for a Leo program. /// /// The [`Asg`] type represents a Leo program as a series of recursive data types. @@ -92,14 +90,14 @@ pub struct Asg<'a> { impl<'a> Asg<'a> { /// Creates a new ASG from a given AST and import resolver. - pub fn new>( + pub fn new, Y: AsRef>( context: AsgContext<'a>, - ast: &Ast, + ast: Y, resolver: &mut T, ) -> Result { Ok(Self { context, - asg: InternalProgram::new(context, &ast.as_repr(), resolver)?, + asg: InternalProgram::new(context, ast.as_ref(), resolver)?, }) } @@ -127,10 +125,9 @@ pub fn load_asg<'a, T: ImportResolver<'a>>( resolver: &mut T, ) -> Result, AsgConvertError> { // Parses the Leo file and constructs a grammar ast. - let ast = leo_grammar::Grammar::new(&Path::new("input.leo"), content) - .map_err(|e| AsgConvertError::InternalError(format!("ast: {:?}", e)))?; + let ast = leo_parser::parse_ast("input.leo", content)?; - InternalProgram::new(context, leo_ast::Ast::new("load_ast", &ast)?.as_repr(), resolver) + InternalProgram::new(context, ast.as_repr(), resolver) } pub fn new_alloc_context<'a>() -> Arena> { diff --git a/asg/src/pass.rs b/asg/src/pass.rs index facdf10e5f..9baa4f2a5a 100644 --- a/asg/src/pass.rs +++ b/asg/src/pass.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::Program; -pub use leo_ast::Error as FormattedError; +pub use leo_ast::FormattedError; pub trait AsgPass { fn do_pass(asg: &Program) -> Result<(), FormattedError>; diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index e44c8b8277..c2efd4f86b 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -92,6 +92,9 @@ impl<'a> Circuit<'a> { } let asg_function = Function::init(new_scope, function)?; asg_function.circuit.replace(Some(circuit)); + if asg_function.is_test() { + return Err(AsgConvertError::circuit_test_function(&function.identifier.span)); + } members.insert(function.identifier.name.clone(), CircuitMember::Function(asg_function)); } } diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 159d3ead3b..c74e15f850 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -29,6 +29,7 @@ use crate::{ Variable, }; use indexmap::IndexMap; +pub use leo_ast::Annotation; use leo_ast::FunctionInput; use std::cell::{Cell, RefCell}; @@ -52,6 +53,7 @@ pub struct Function<'a> { pub body: Cell>>, pub scope: &'a Scope<'a>, pub qualifier: FunctionQualifier, + pub annotations: Vec, } impl<'a> PartialEq for Function<'a> { @@ -126,6 +128,7 @@ impl<'a> Function<'a> { qualifier, scope: new_scope, span: Some(value.span.clone()), + annotations: value.annotations.clone(), }); function.scope.function.replace(Some(function)); @@ -177,6 +180,10 @@ impl<'a> Function<'a> { Ok(()) } + + pub fn is_test(&self) -> bool { + self.annotations.iter().any(|x| x.name.name == "test") + } } impl<'a> Into for &Function<'a> { @@ -213,6 +220,7 @@ impl<'a> Into for &Function<'a> { block: body, output: Some((&output).into()), span, + annotations: self.annotations.clone(), } } } diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index cccadd08d3..3ada521eb2 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -45,9 +45,6 @@ pub struct InternalProgram<'a> { /// these should generally not be accessed directly, but through scoped imports pub imported_modules: IndexMap>, - /// Maps test name => test code block. - pub test_functions: IndexMap, Option)>, // identifier = test input file - /// Maps function name => function code block. pub functions: IndexMap>, @@ -248,14 +245,6 @@ impl<'a> InternalProgram<'a> { scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit); } - let mut proto_test_functions = IndexMap::new(); - for (name, test_function) in program.tests.iter() { - assert_eq!(name.name, test_function.function.identifier.name); - let function = Function::init(scope, &test_function.function)?; - - proto_test_functions.insert(name.name.clone(), function); - } - for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); let function = Function::init(scope, function)?; @@ -264,16 +253,6 @@ impl<'a> InternalProgram<'a> { } // Load concrete definitions. - let mut test_functions = IndexMap::new(); - 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(); - - function.fill_from_ast(&test_function.function)?; - - test_functions.insert(name.name.clone(), (*function, test_function.input_file.clone())); - } - let mut functions = IndexMap::new(); for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); @@ -298,7 +277,6 @@ impl<'a> InternalProgram<'a> { context, id: context.get_id(), name: program.name.clone(), - test_functions, functions, circuits, imported_modules: resolved_packages @@ -350,7 +328,6 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program { let mut all_circuits: IndexMap> = IndexMap::new(); let mut all_functions: IndexMap> = IndexMap::new(); - let mut all_test_functions: IndexMap, Option)> = IndexMap::new(); let mut identifiers = InternalIdentifierGenerator { next: 0 }; for (_, program) in all_programs.into_iter() { for (name, circuit) in program.circuits.iter() { @@ -367,11 +344,6 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program { function.name.borrow_mut().name = identifier.clone(); all_functions.insert(identifier, *function); } - for (name, function) in program.test_functions.iter() { - let identifier = format!("{}{}", identifiers.next().unwrap(), name); - function.0.name.borrow_mut().name = identifier.clone(); - all_test_functions.insert(identifier, function.clone()); - } } leo_ast::Program { @@ -388,15 +360,6 @@ pub fn reform_ast<'a>(program: &Program<'a>) -> leo_ast::Program { }) .collect(), expected_input: vec![], - tests: all_test_functions - .into_iter() - .map(|(_, (function, ident))| { - (function.name.borrow().clone(), leo_ast::TestFunction { - function: function.into(), - input_file: ident, - }) - }) - .collect(), functions: all_functions .into_iter() .map(|(_, function)| (function.name.borrow().clone(), function.into())) @@ -424,16 +387,6 @@ impl<'a> Into for &InternalProgram<'a> { .iter() .map(|(_, function)| (function.name.borrow().clone(), (*function).into())) .collect(), - tests: self - .test_functions - .iter() - .map(|(_, function)| { - (function.0.name.borrow().clone(), leo_ast::TestFunction { - function: function.0.into(), - input_file: function.1.clone(), - }) - }) - .collect(), } } } diff --git a/asg/src/reducer/monoidal_director.rs b/asg/src/reducer/monoidal_director.rs index 40a55d4a30..101cb1116d 100644 --- a/asg/src/reducer/monoidal_director.rs +++ b/asg/src/reducer/monoidal_director.rs @@ -47,6 +47,7 @@ impl<'a, T: Monoid, R: MonoidalReducerExpression<'a, T>> MonoidalDirector<'a, T, Expression::CircuitAccess(e) => self.reduce_circuit_access(e), Expression::CircuitInit(e) => self.reduce_circuit_init(e), Expression::Ternary(e) => self.reduce_ternary_expression(e), + Expression::Cast(e) => self.reduce_cast_expression(e), Expression::Constant(e) => self.reduce_constant(e), Expression::TupleAccess(e) => self.reduce_tuple_access(e), Expression::TupleInit(e) => self.reduce_tuple_init(e), @@ -131,6 +132,12 @@ impl<'a, T: Monoid, R: MonoidalReducerExpression<'a, T>> MonoidalDirector<'a, T, .reduce_ternary_expression(input, condition, if_true, if_false) } + pub fn reduce_cast_expression(&mut self, input: &CastExpression<'a>) -> T { + let inner = self.reduce_expression(input.inner.get()); + + self.reducer.reduce_cast_expression(input, inner) + } + pub fn reduce_constant(&mut self, input: &Constant<'a>) -> T { self.reducer.reduce_constant(input) } @@ -299,15 +306,10 @@ impl<'a, T: Monoid, R: MonoidalReducerProgram<'a, T>> MonoidalDirector<'a, T, R> .iter() .map(|(_, import)| self.reduce_program(import)) .collect(); - let test_functions = input - .test_functions - .iter() - .map(|(_, (f, _))| self.reduce_function(f)) - .collect(); let functions = input.functions.iter().map(|(_, f)| self.reduce_function(f)).collect(); let circuits = input.circuits.iter().map(|(_, c)| self.reduce_circuit(c)).collect(); self.reducer - .reduce_program(&input, imported_modules, test_functions, functions, circuits) + .reduce_program(&input, imported_modules, functions, circuits) } } diff --git a/asg/src/reducer/monoidal_reducer.rs b/asg/src/reducer/monoidal_reducer.rs index ba7a177f5b..678255b91b 100644 --- a/asg/src/reducer/monoidal_reducer.rs +++ b/asg/src/reducer/monoidal_reducer.rs @@ -64,6 +64,10 @@ pub trait MonoidalReducerExpression<'a, T: Monoid> { condition.append(if_true).append(if_false) } + fn reduce_cast_expression(&mut self, input: &CastExpression<'a>, inner: T) -> T { + inner + } + fn reduce_constant(&mut self, input: &Constant<'a>) -> T { T::default() } @@ -157,13 +161,11 @@ pub trait MonoidalReducerProgram<'a, T: Monoid>: MonoidalReducerStatement<'a, T> &mut self, input: &InternalProgram, imported_modules: Vec, - test_functions: Vec, functions: Vec, circuits: Vec, ) -> T { T::default() .append_all(imported_modules.into_iter()) - .append_all(test_functions.into_iter()) .append_all(functions.into_iter()) .append_all(circuits.into_iter()) } diff --git a/asg/src/reducer/visitor.rs b/asg/src/reducer/visitor.rs index 415f3ed265..b0f4d3ee6a 100644 --- a/asg/src/reducer/visitor.rs +++ b/asg/src/reducer/visitor.rs @@ -72,6 +72,10 @@ pub trait ExpressionVisitor<'a> { Default::default() } + fn visit_cast_expression(&mut self, input: &CastExpression<'a>) -> VisitResult { + Default::default() + } + fn visit_constant(&mut self, input: &Constant<'a>) -> VisitResult { Default::default() } diff --git a/asg/src/reducer/visitor_director.rs b/asg/src/reducer/visitor_director.rs index 4edc95d106..83ac86072c 100644 --- a/asg/src/reducer/visitor_director.rs +++ b/asg/src/reducer/visitor_director.rs @@ -60,6 +60,7 @@ impl<'a, R: ExpressionVisitor<'a>> VisitorDirector<'a, R> { Expression::CircuitAccess(e) => self.visit_circuit_access(e), Expression::CircuitInit(e) => self.visit_circuit_init(e), Expression::Ternary(e) => self.visit_ternary_expression(e), + Expression::Cast(e) => self.visit_cast_expression(e), Expression::Constant(e) => self.visit_constant(e), Expression::TupleAccess(e) => self.visit_tuple_access(e), Expression::TupleInit(e) => self.visit_tuple_init(e), @@ -184,6 +185,16 @@ impl<'a, R: ExpressionVisitor<'a>> VisitorDirector<'a, R> { } } + pub fn visit_cast_expression(&mut self, input: &CastExpression<'a>) -> ConcreteVisitResult { + match self.visitor.visit_cast_expression(input) { + VisitResult::VisitChildren => { + self.visit_expression(&input.inner)?; + Ok(()) + } + x => x.into(), + } + } + pub fn visit_constant(&mut self, input: &Constant<'a>) -> ConcreteVisitResult { self.visitor.visit_constant(input).into() } @@ -419,9 +430,6 @@ impl<'a, R: ProgramVisitor<'a>> VisitorDirector<'a, R> { for (_, import) in input.imported_modules.iter() { self.visit_program(import)?; } - for (_, (function, _)) in input.test_functions.iter() { - self.visit_function(function)?; - } for (_, function) in input.functions.iter() { self.visit_function(function)?; } diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index 1eda9119ba..060a836f5a 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -72,10 +72,10 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { let variable = if name == "input" { if let Some(function) = scope.resolve_current_function() { if !function.has_input { - return Err(AsgConvertError::unresolved_reference(name, span)); + return Err(AsgConvertError::unresolved_reference(name, &span)); } } else { - return Err(AsgConvertError::unresolved_reference(name, span)); + return Err(AsgConvertError::unresolved_reference(name, &span)); } if let Some(input) = scope.resolve_input() { input.container @@ -87,7 +87,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { } else { scope .resolve_variable(&name) - .ok_or_else(|| AsgConvertError::unresolved_reference(name, span))? + .ok_or_else(|| AsgConvertError::unresolved_reference(name, &span))? }; if !variable.borrow().mutable { diff --git a/asg/src/statement/console.rs b/asg/src/statement/console.rs index fdcf2858e5..5820abb579 100644 --- a/asg/src/statement/console.rs +++ b/asg/src/statement/console.rs @@ -15,15 +15,14 @@ // along with the Leo library. If not, see . use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; -use leo_ast::ConsoleFunction as AstConsoleFunction; +use leo_ast::{ConsoleFunction as AstConsoleFunction, FormattedStringPart}; use std::cell::Cell; // TODO (protryon): Refactor to not require/depend on span #[derive(Clone)] pub struct FormattedString<'a> { - pub string: String, - pub containers: Vec, + pub parts: Vec, pub parameters: Vec>>, pub span: Span, } @@ -55,10 +54,15 @@ impl<'a> FromAst<'a, leo_ast::FormattedString> for FormattedString<'a> { value: &leo_ast::FormattedString, _expected_type: Option>, ) -> Result { - if value.parameters.len() != value.containers.len() { + let expected_param_len = value + .parts + .iter() + .filter(|x| matches!(x, FormattedStringPart::Container)) + .count(); + if value.parameters.len() != expected_param_len { // + 1 for formatting string as to not confuse user return Err(AsgConvertError::unexpected_call_argument_count( - value.containers.len() + 1, + expected_param_len + 1, value.parameters.len() + 1, &value.span, )); @@ -68,8 +72,7 @@ impl<'a> FromAst<'a, leo_ast::FormattedString> for FormattedString<'a> { parameters.push(Cell::new(<&Expression<'a>>::from_ast(scope, parameter, None)?)); } Ok(FormattedString { - string: value.string.clone(), - containers: value.containers.iter().map(|x| x.span.clone()).collect(), + parts: value.parts.clone(), parameters, span: value.span.clone(), }) @@ -79,12 +82,7 @@ impl<'a> FromAst<'a, leo_ast::FormattedString> for FormattedString<'a> { impl<'a> Into for &FormattedString<'a> { fn into(self) -> leo_ast::FormattedString { leo_ast::FormattedString { - string: self.string.clone(), - containers: self - .containers - .iter() - .map(|span| leo_ast::FormattedContainer { span: span.clone() }) - .collect(), + parts: self.parts.clone(), parameters: self.parameters.iter().map(|e| e.get().into()).collect(), span: self.span.clone(), } diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index a779454996..a6b0378705 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -28,7 +28,6 @@ use crate::{ Type, Variable, }; -use leo_ast::{AstError, DeprecatedError}; use std::cell::{Cell, RefCell}; @@ -90,11 +89,6 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { } for (variable, type_) in statement.variable_names.iter().zip(output_types.into_iter()) { - if statement.declaration_type == leo_ast::Declare::Const { - return Err(AsgConvertError::AstError(AstError::DeprecatedError( - DeprecatedError::const_statement(&statement.span), - ))); - } variables.push(&*scope.alloc_variable(RefCell::new(InnerVariable { id: scope.context.get_id(), name: variable.identifier.clone(), diff --git a/asg/src/type_.rs b/asg/src/type_.rs index 83c5f3d759..8421d436fc 100644 --- a/asg/src/type_.rs +++ b/asg/src/type_.rs @@ -123,6 +123,10 @@ impl<'a> Type<'a> { pub fn is_unit(&self) -> bool { matches!(self, Type::Tuple(t) if t.is_empty()) } + + pub fn can_cast_to(&self, to: &Type<'a>) -> bool { + matches!(self, Type::Integer(_)) && matches!(to, Type::Integer(_)) + } } impl<'a> fmt::Display for Type<'a> { diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 75a84f0111..c98dd62d73 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -17,19 +17,6 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "GPL-3.0" edition = "2018" -[[bin]] -name = "leo_ast" -path = "src/main.rs" - -[[bench]] -name = "leo_ast" -path = "benches/leo_ast.rs" -harness = false - -[dependencies.leo-grammar] -path = "../grammar" -version = "1.2.3" - [dependencies.leo-input] path = "../input" version = "1.2.3" @@ -43,6 +30,7 @@ version = "2.0" [dependencies.serde] version = "1.0" +features = ["derive", "rc"] [dependencies.serde_json] version = "1.0" @@ -55,4 +43,4 @@ version = "0.3" [features] default = [ ] -ci_skip = [ "leo-grammar/ci_skip" ] +ci_skip = [ ] diff --git a/ast/src/annotation.rs b/ast/src/annotation.rs index 9ccc5e833d..aebfd3b083 100644 --- a/ast/src/annotation.rs +++ b/ast/src/annotation.rs @@ -14,84 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Circuit, DeprecatedError, Function, FunctionInput, Identifier, ImportStatement, TestFunction}; -use leo_grammar::{ - annotations::{Annotation, AnnotationArguments, AnnotationName}, - definitions::{AnnotatedDefinition, Definition}, -}; +use crate::{Identifier, Span}; -use std::convert::TryFrom; +use serde::{Deserialize, Serialize}; -use indexmap::IndexMap; - -pub fn load_annotation( - annotated_definition: AnnotatedDefinition, - _imports: &mut Vec, - _circuits: &mut IndexMap, - _functions: &mut IndexMap, - tests: &mut IndexMap, - _expected: &mut Vec, -) -> Result<(), DeprecatedError> { - let ast_annotation = annotated_definition.annotation; - let ast_definition = *annotated_definition.definition; - - match ast_definition { - Definition::Import(_) => { - unimplemented!("annotated imports are not supported yet"); - } - Definition::Circuit(_) => { - unimplemented!("annotated circuits are not supported yet"); - } - Definition::Function(function) => match ast_annotation.name { - // If it's deprecated for more than one type of syntax, - // we could just call it before the match on ast_definition. - AnnotationName::Context(_) => Err(DeprecatedError::try_from(ast_annotation.name).unwrap()), - AnnotationName::Test(_) => { - let ident = Identifier::from(function.identifier.clone()); - _functions.remove(&ident); - - let test_function = leo_grammar::functions::TestFunction::from(function); - let test = TestFunction::from(test_function); - tests.insert(ident, test.clone()); - - load_annotated_test(test, ast_annotation, tests); - Ok(()) - } - }, - Definition::Deprecated(_) => Ok(()), - Definition::Annotated(_) => { - unimplemented!("nested annotations are not supported yet"); - } - } -} - -pub fn load_annotated_test(test: TestFunction, annotation: Annotation, tests: &mut IndexMap) { - let name = annotation.name; - let ast_arguments = annotation.arguments; - - match name { - AnnotationName::Test(_) if ast_arguments.is_some() => { - load_annotated_test_context(test, ast_arguments.unwrap(), tests) - } - _ => (), - } -} - -pub fn load_annotated_test_context( - mut test: TestFunction, - ast_arguments: AnnotationArguments, - tests: &mut IndexMap, -) { - let arguments = ast_arguments.arguments; - - if arguments.len() != 1 { - panic!("text context annotation must have one argument identifier") - } - - let ast_input_file = arguments[0].to_owned(); - let input_file = Identifier::from(ast_input_file); - - test.input_file = Some(input_file); - - tests.insert(test.function.identifier.clone(), test); +#[derive(Clone, Serialize, Deserialize, PartialEq, Eq)] +pub struct Annotation { + pub span: Span, + pub name: Identifier, + pub arguments: Vec, } diff --git a/ast/src/circuits/circuit.rs b/ast/src/circuits/circuit.rs index 79c2280cfc..8a6222aa2f 100644 --- a/ast/src/circuits/circuit.rs +++ b/ast/src/circuits/circuit.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{CircuitMember, Identifier}; -use leo_grammar::circuits::Circuit as GrammarCircuit; use serde::{Deserialize, Serialize}; use std::fmt; @@ -26,15 +25,6 @@ pub struct Circuit { pub members: Vec, } -impl<'ast> From> for Circuit { - fn from(circuit: GrammarCircuit<'ast>) -> Self { - let circuit_name = Identifier::from(circuit.identifier); - let members = circuit.members.into_iter().map(CircuitMember::from).collect(); - - Self { circuit_name, members } - } -} - impl Circuit { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "circuit {} {{ ", self.circuit_name)?; diff --git a/ast/src/circuits/circuit_implied_variable_definition.rs b/ast/src/circuits/circuit_implied_variable_definition.rs index 963c153bec..6dd5f570fb 100644 --- a/ast/src/circuits/circuit_implied_variable_definition.rs +++ b/ast/src/circuits/circuit_implied_variable_definition.rs @@ -15,27 +15,11 @@ // 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), - }, - } - } + pub expression: Option, } diff --git a/ast/src/circuits/circuit_member.rs b/ast/src/circuits/circuit_member.rs index 29b5777587..b9d30a8a17 100644 --- a/ast/src/circuits/circuit_member.rs +++ b/ast/src/circuits/circuit_member.rs @@ -15,10 +15,6 @@ // along with the Leo library. If not, see . use crate::{Function, Identifier, Type}; -use leo_grammar::{ - circuits::{CircuitMember as GrammarCircuitMember, CircuitVariableDefinition as GrammarCircuitVariableDefinition}, - functions::Function as GrammarFunction, -}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -31,30 +27,6 @@ pub enum CircuitMember { CircuitFunction(Function), } -impl<'ast> From> for CircuitMember { - fn from(circuit_value: GrammarCircuitVariableDefinition<'ast>) -> Self { - CircuitMember::CircuitVariable( - Identifier::from(circuit_value.identifier), - Type::from(circuit_value.type_), - ) - } -} - -impl<'ast> From> for CircuitMember { - fn from(circuit_function: GrammarFunction<'ast>) -> Self { - CircuitMember::CircuitFunction(Function::from(circuit_function)) - } -} - -impl<'ast> From> for CircuitMember { - fn from(object: GrammarCircuitMember<'ast>) -> Self { - match object { - GrammarCircuitMember::CircuitVariableDefinition(circuit_value) => CircuitMember::from(circuit_value), - GrammarCircuitMember::CircuitFunction(circuit_function) => CircuitMember::from(circuit_function), - } - } -} - impl fmt::Display for CircuitMember { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/ast/src/circuits/circuit_variable_definition.rs b/ast/src/circuits/circuit_variable_definition.rs index 6cd3484f88..9d997707b1 100644 --- a/ast/src/circuits/circuit_variable_definition.rs +++ b/ast/src/circuits/circuit_variable_definition.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Expression, Identifier}; -use leo_grammar::circuits::CircuitVariable; use serde::{Deserialize, Serialize}; @@ -24,12 +23,3 @@ pub struct CircuitVariableDefinition { pub identifier: Identifier, pub expression: Expression, } - -impl<'ast> From> for CircuitVariableDefinition { - fn from(member: CircuitVariable<'ast>) -> Self { - CircuitVariableDefinition { - identifier: Identifier::from(member.identifier), - expression: Expression::from(member.expression), - } - } -} diff --git a/ast/src/common/array_dimensions.rs b/ast/src/common/array_dimensions.rs index a401475200..bdcd6b3db9 100644 --- a/ast/src/common/array_dimensions.rs +++ b/ast/src/common/array_dimensions.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::PositiveNumber; -use leo_grammar::types::ArrayDimensions as GrammarArrayDimensions; use leo_input::types::ArrayDimensions as InputArrayDimensions; use serde::{Deserialize, Serialize}; @@ -104,18 +103,6 @@ impl ArrayDimensions { } } -/// Create a new [`ArrayDimensions`] from a [`GrammarArrayDimensions`] in a Leo program file. -impl<'ast> From> for ArrayDimensions { - fn from(dimensions: GrammarArrayDimensions<'ast>) -> Self { - Self(match dimensions { - GrammarArrayDimensions::Single(single) => vec![PositiveNumber::from(single.number)], - GrammarArrayDimensions::Multiple(multiple) => { - multiple.numbers.into_iter().map(PositiveNumber::from).collect() - } - }) - } -} - /// Create a new [`ArrayDimensions`] from a [`InputArrayDimensions`] in a Leo program file. impl<'ast> From> for ArrayDimensions { fn from(dimensions: InputArrayDimensions<'ast>) -> Self { diff --git a/ast/src/common/identifier.rs b/ast/src/common/identifier.rs index c24f4a9d8e..9efa38c143 100644 --- a/ast/src/common/identifier.rs +++ b/ast/src/common/identifier.rs @@ -14,21 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputKeyword, MutSelfKeyword, SelfKeyword, Span}; -use leo_grammar::{ - annotations::AnnotationArgument, - common::{ - Identifier as GrammarIdentifier, - KeywordOrIdentifier, - MutSelfKeyword as GrammarMutSelfKeyword, - SelfKeyword as GrammarSelfKeyword, - SelfKeywordOrIdentifier, - }, - expressions::CircuitName, - functions::InputKeyword as GrammarInputKeyword, - imports::PackageName as GrammarPackageName, - types::SelfType, -}; +use crate::Span; use leo_input::common::Identifier as InputIdentifier; use crate::Node; @@ -74,10 +60,10 @@ impl Identifier { } } - pub fn new_with_span(name: &str, span: &Span) -> Self { + pub fn new_with_span(name: &str, span: Span) -> Self { Self { name: name.to_owned(), - span: span.to_owned(), + span, } } @@ -90,24 +76,6 @@ impl Identifier { } } -impl<'ast> From> for Identifier { - fn from(identifier: GrammarIdentifier<'ast>) -> Self { - Self { - name: identifier.value, - span: Span::from(identifier.span), - } - } -} - -impl<'ast> From> for Identifier { - fn from(name: GrammarPackageName<'ast>) -> Self { - Self { - name: name.value, - span: Span::from(name.span), - } - } -} - impl<'ast> From> for Identifier { fn from(identifier: InputIdentifier<'ast>) -> Self { Self { @@ -117,106 +85,6 @@ impl<'ast> From> for Identifier { } } -impl<'ast> From> for Identifier { - fn from(argument: AnnotationArgument<'ast>) -> Self { - Self { - name: argument.value, - span: Span::from(argument.span), - } - } -} - -impl<'ast> From> for Identifier { - fn from(name: KeywordOrIdentifier<'ast>) -> Self { - match name { - KeywordOrIdentifier::Identifier(keyword) => Identifier::from(keyword), - KeywordOrIdentifier::SelfType(self_type) => Identifier::from(self_type), - KeywordOrIdentifier::Input(keyword) => Identifier::from(keyword), - } - } -} - -impl<'ast> From> for Identifier { - fn from(name: SelfKeywordOrIdentifier<'ast>) -> Self { - match name { - SelfKeywordOrIdentifier::Identifier(identifier) => Identifier::from(identifier), - SelfKeywordOrIdentifier::SelfKeyword(keyword) => Identifier::from(keyword), - } - } -} - -impl<'ast> From> for Identifier { - fn from(grammar: GrammarSelfKeyword<'ast>) -> Self { - Self { - name: grammar.keyword, - span: Span::from(grammar.span), - } - } -} - -impl From for Identifier { - fn from(keyword: SelfKeyword) -> Self { - Self { - name: keyword.to_string(), - span: keyword.span, - } - } -} - -impl<'ast> From> for Identifier { - fn from(grammar: GrammarMutSelfKeyword<'ast>) -> Self { - Self { - name: grammar.to_string(), - span: Span::from(grammar.span), - } - } -} - -impl From for Identifier { - fn from(keyword: MutSelfKeyword) -> Self { - Self { - name: keyword.to_string(), - span: keyword.span, - } - } -} - -impl<'ast> From> for Identifier { - fn from(grammar: GrammarInputKeyword<'ast>) -> Self { - Self { - name: grammar.keyword, - span: Span::from(grammar.span), - } - } -} - -impl From for Identifier { - fn from(keyword: InputKeyword) -> Self { - Self { - name: keyword.to_string(), - span: keyword.span, - } - } -} - -impl<'ast> From> for Identifier { - fn from(name: CircuitName<'ast>) -> Self { - match name { - CircuitName::SelfType(self_type) => Identifier::from(self_type), - CircuitName::Identifier(identifier) => Identifier::from(identifier), - } - } -} - -impl<'ast> From> for Identifier { - fn from(self_type: SelfType<'ast>) -> Self { - Self { - name: self_type.keyword, - span: Span::from(self_type.span), - } - } -} - impl fmt::Display for Identifier { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.name) diff --git a/ast/src/common/input_keyword.rs b/ast/src/common/input_keyword.rs index a6dd0d5e74..cc9d167861 100644 --- a/ast/src/common/input_keyword.rs +++ b/ast/src/common/input_keyword.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Node, Span}; -use leo_grammar::functions::InputKeyword as GrammarInputKeyword; use serde::{Deserialize, Serialize}; use std::fmt; @@ -27,14 +26,6 @@ pub struct InputKeyword { pub span: Span, } -impl<'ast> From> for InputKeyword { - fn from(grammar: GrammarInputKeyword<'ast>) -> Self { - Self { - span: Span::from(grammar.span), - } - } -} - impl fmt::Display for InputKeyword { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "input") diff --git a/ast/src/common/mut_self_keyword.rs b/ast/src/common/mut_self_keyword.rs index 0d4bf62168..34de7c9921 100644 --- a/ast/src/common/mut_self_keyword.rs +++ b/ast/src/common/mut_self_keyword.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Node, Span}; -use leo_grammar::common::MutSelfKeyword as GrammarMutSelfKeyword; use serde::{Deserialize, Serialize}; use std::fmt; @@ -26,14 +25,6 @@ pub struct MutSelfKeyword { pub span: Span, } -impl<'ast> From> for MutSelfKeyword { - fn from(grammar: GrammarMutSelfKeyword<'ast>) -> Self { - Self { - span: Span::from(grammar.span), - } - } -} - impl fmt::Display for MutSelfKeyword { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "mut self") diff --git a/ast/src/common/positive_number.rs b/ast/src/common/positive_number.rs index 667727b1b5..80fda5d71e 100644 --- a/ast/src/common/positive_number.rs +++ b/ast/src/common/positive_number.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::values::PositiveNumber as GrammarPositiveNumber; use leo_input::values::PositiveNumber as InputPositiveNumber; use serde::{Deserialize, Serialize}; @@ -35,13 +34,6 @@ impl PositiveNumber { } } -/// Create a new [`PositiveNumber`] from a [`GrammarPositiveNumber`] in a Leo program file. -impl<'ast> From> for PositiveNumber { - fn from(array: GrammarPositiveNumber<'ast>) -> Self { - Self { value: array.value } - } -} - /// Create a new [`PositiveNumber`] from an [`InputPositiveNumber`] in a Leo input file. impl<'ast> From> for PositiveNumber { fn from(array: InputPositiveNumber<'ast>) -> Self { diff --git a/ast/src/common/self_keyword.rs b/ast/src/common/self_keyword.rs index caa9e1b7f6..ba92db2160 100644 --- a/ast/src/common/self_keyword.rs +++ b/ast/src/common/self_keyword.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Node, Span}; -use leo_grammar::common::SelfKeyword as GrammarSelfKeyword; use serde::{Deserialize, Serialize}; use std::fmt; @@ -27,14 +26,6 @@ pub struct SelfKeyword { pub span: Span, } -impl<'ast> From> for SelfKeyword { - fn from(grammar: GrammarSelfKeyword<'ast>) -> Self { - Self { - span: Span::from(grammar.span), - } - } -} - impl fmt::Display for SelfKeyword { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "self") diff --git a/ast/src/common/span.rs b/ast/src/common/span.rs index e6e7a70388..ab6c3607c3 100644 --- a/ast/src/common/span.rs +++ b/ast/src/common/span.rs @@ -14,62 +14,84 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use pest::Span as GrammarSpan; +use std::{fmt, rc::Rc}; + use serde::{Deserialize, Serialize}; -use std::hash::{Hash, Hasher}; -#[derive(Clone, Debug, Default, Serialize, Deserialize)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, Hash)] pub struct Span { - /// text of input string - pub text: String, - /// program line - pub line: usize, - /// start column - pub start: usize, - /// end column - pub end: usize, + pub line_start: usize, + pub line_stop: usize, + pub col_start: usize, + pub col_stop: usize, + pub path: Rc, } -impl PartialEq for Span { - fn eq(&self, other: &Self) -> bool { - self.line == other.line && self.start == other.start && self.end == other.end +impl fmt::Display for Span { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if self.line_start == self.line_stop { + write!(f, "{}:{}-{}", self.line_start, self.col_start, self.col_stop) + } else { + write!( + f, + "{}:{}-{}:{}", + self.line_start, self.col_start, self.line_stop, self.col_stop + ) + } } } -impl Eq for Span {} +impl<'ast> From> for Span { + fn from(span: pest::Span) -> Self { + let start = span.start_pos().line_col(); + let end = span.end_pos().line_col(); -impl Hash for Span { - fn hash(&self, state: &mut H) { - self.line.hash(state); - self.start.hash(state); - self.end.hash(state); - } -} - -impl Span { - pub fn from_internal_string(value: &str) -> Span { Span { - text: value.to_string(), - line: 0, - start: 0, - end: 0, + line_start: start.0, + line_stop: end.0, + col_start: start.1, + col_stop: end.1, + path: Rc::new(String::new()), } } } -impl<'ast> From> for Span { - fn from(span: GrammarSpan<'ast>) -> Self { - let mut text = " ".to_string(); - let line_col = span.start_pos().line_col(); - let end = span.end_pos().line_col().1; +impl std::ops::Add for &Span { + type Output = Span; - text.push_str(span.start_pos().line_of().trim_end()); + fn add(self, other: &Span) -> Span { + self.clone() + other.clone() + } +} - Self { - text, - line: line_col.0, - start: line_col.1, - end, +impl std::ops::Add for Span { + type Output = Self; + + fn add(self, other: Self) -> Self { + if self.line_start == other.line_stop { + Span { + line_start: self.line_start, + line_stop: self.line_stop, + col_start: self.col_start.min(other.col_start), + col_stop: self.col_stop.max(other.col_stop), + path: self.path, + } + } else if self.line_start < other.line_start { + Span { + line_start: self.line_start, + line_stop: other.line_stop, + col_start: self.col_start, + col_stop: other.col_stop, + path: self.path, + } + } else { + Span { + line_start: other.line_start, + line_stop: self.line_stop, + col_start: other.col_start, + col_stop: self.col_stop, + path: self.path, + } } } } diff --git a/ast/src/common/spread_or_expression.rs b/ast/src/common/spread_or_expression.rs index 78f940a5af..b758d0b0ea 100644 --- a/ast/src/common/spread_or_expression.rs +++ b/ast/src/common/spread_or_expression.rs @@ -15,10 +15,6 @@ // along with the Leo library. If not, see . use crate::{Expression, Node, Span}; -use leo_grammar::{ - common::SpreadOrExpression as GrammarSpreadOrExpression, - expressions::Expression as GrammarExpression, -}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -30,25 +26,6 @@ pub enum SpreadOrExpression { Expression(Expression), } -impl<'ast> From> for SpreadOrExpression { - fn from(s_or_e: GrammarSpreadOrExpression<'ast>) -> Self { - match s_or_e { - GrammarSpreadOrExpression::Spread(spread) => { - SpreadOrExpression::Spread(Expression::from(spread.expression)) - } - GrammarSpreadOrExpression::Expression(expression) => { - SpreadOrExpression::Expression(Expression::from(expression)) - } - } - } -} - -impl<'ast> From> for SpreadOrExpression { - fn from(expression: GrammarExpression<'ast>) -> Self { - SpreadOrExpression::Expression(Expression::from(expression)) - } -} - impl fmt::Display for SpreadOrExpression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { diff --git a/ast/src/errors/error.rs b/ast/src/errors/error.rs index 103b0ea9cb..28b7d48f72 100644 --- a/ast/src/errors/error.rs +++ b/ast/src/errors/error.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Span; +use crate::{LeoError, Span}; -use std::{fmt, path::Path}; +use std::fmt; pub const INDENT: &str = " "; @@ -28,68 +28,59 @@ pub const INDENT: &str = " "; /// | /// = undefined value `x` #[derive(Clone, Debug, Eq, Hash, PartialEq)] -pub struct Error { +pub struct FormattedError { /// File path where error occurred pub path: Option, - /// Line number - pub line: usize, + /// Line start number + pub line_start: usize, + /// Line end number + pub line_stop: usize, /// Starting column pub start: usize, /// Ending column pub end: usize, - /// Text of errored line - pub text: String, + /// Text of errored lines + pub text: Option>, /// Error explanation pub message: String, } -impl Error { - pub fn new_from_span(message: String, span: Span) -> Self { +impl FormattedError { + pub fn new_from_span(message: String, span: &Span) -> Self { Self { path: None, - line: span.line, - start: span.start, - end: span.end, - text: span.text, + line_start: span.line_start, + line_stop: span.line_stop, + start: span.col_start, + end: span.col_stop, + text: None, message, } } +} - pub fn new_from_span_with_path(message: String, span: Span, path: &Path) -> Self { - Self { - path: Some(format!("{:?}", path)), - line: span.line, - start: span.start, - end: span.end, - text: span.text, - message, +impl LeoError for FormattedError { + fn set_path(&mut self, path: &str, content: &[String]) { + self.path = Some(path.to_string()); + if self.line_stop - 1 > content.len() { + self.text = Some(vec!["corrupt file".to_string()]); + return; } + assert!(self.line_stop >= self.line_start); + // if self.line_stop == self.line_start { + // self.text = Some(vec![content[self.line_start - 1][self.start - 1..self.end - 1].to_string()]); + // } else { + self.text = Some( + content[self.line_start - 1..self.line_stop] + .iter() + .map(|x| x.to_string()) + .collect(), + ); + // } } - pub fn set_path(&mut self, path: &Path) { - self.path = Some(format!("{:?}", path)); - } - - pub fn format(&self) -> String { - let path = self.path.as_ref().map(|path| format!("{}:", path)).unwrap_or_default(); - let underline = underline(self.start, self.end); - - format!( - "{indent }--> {path} {line}:{start}\n\ - {indent } |\n\ - {line:width$} | {text}\n\ - {indent } | {underline}\n\ - {indent } |\n\ - {indent } = {message}", - indent = INDENT, - width = INDENT.len(), - path = path, - line = self.line, - start = self.start, - text = self.text, - underline = underline, - message = self.message, - ) + fn get_path(&self) -> Option<&str> { + self.path.as_deref() } } @@ -112,13 +103,46 @@ fn underline(mut start: usize, mut end: usize) -> String { underline } -impl fmt::Display for Error { +impl fmt::Display for FormattedError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.format()) + let path = self.path.as_ref().map(|path| format!("{}:", path)).unwrap_or_default(); + let underline = underline(self.start - 1, self.end - 1); + + write!( + f, + "{indent }--> {path}{line_start}:{start}\n\ + {indent } |\n", + indent = INDENT, + path = path, + line_start = self.line_start, + start = self.start, + )?; + + if let Some(lines) = &self.text { + for (line_no, line) in lines.iter().enumerate() { + writeln!( + f, + "{line_no:width$} | {text}", + width = INDENT.len(), + line_no = self.line_start + line_no, + text = line, + )?; + } + } + + write!( + f, + "{indent } | {underline}\n\ + {indent } |\n\ + {indent } = {message}", + indent = INDENT, + underline = underline, + message = self.message, + ) } } -impl std::error::Error for Error { +impl std::error::Error for FormattedError { fn description(&self) -> &str { &self.message } @@ -126,12 +150,13 @@ impl std::error::Error for Error { #[test] fn test_error() { - let err = Error { + let err = FormattedError { path: Some("file.leo".to_string()), - line: 2, + line_start: 2, + line_stop: 2, start: 8, end: 9, - text: "let a = x;".to_string(), + text: Some(vec!["let a = x;".to_string()]), message: "undefined value `x`".to_string(), }; diff --git a/ast/src/errors/mod.rs b/ast/src/errors/mod.rs index d3bb4d70df..1e8b06996f 100644 --- a/ast/src/errors/mod.rs +++ b/ast/src/errors/mod.rs @@ -14,30 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -pub mod deprecated; -pub use deprecated::*; - pub mod error; pub use error::*; -use error::Error as FormattedError; +pub trait LeoError { + fn get_path(&self) -> Option<&str>; -use leo_grammar::ParserError; - -#[derive(Debug, Error)] -pub enum AstError { - #[error("{}", _0)] - DeprecatedError(#[from] DeprecatedError), - - #[error("{}", _0)] - Error(#[from] FormattedError), - - #[error("{}", _0)] - IoError(#[from] std::io::Error), - - #[error("{}", _0)] - ParserError(#[from] ParserError), - - #[error("{}", _0)] - JsonError(#[from] serde_json::error::Error), + fn set_path(&mut self, path: &str, contents: &[String]); } diff --git a/ast/src/expression/binary.rs b/ast/src/expression/binary.rs index d9c55c4f4d..dd556441ff 100644 --- a/ast/src/expression/binary.rs +++ b/ast/src/expression/binary.rs @@ -31,6 +31,13 @@ pub enum BinaryOperation { Gt, Le, Lt, + BitOr, + BitAnd, + BitXor, + Shr, + ShrSigned, + Shl, + Mod, } #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -55,6 +62,13 @@ impl AsRef for BinaryOperation { BinaryOperation::Gt => ">", BinaryOperation::Le => "<=", BinaryOperation::Lt => "<", + BinaryOperation::BitOr => "|", + BinaryOperation::BitAnd => "&", + BinaryOperation::BitXor => "^", + BinaryOperation::Shr => ">>", + BinaryOperation::ShrSigned => ">>>", + BinaryOperation::Shl => "<<", + BinaryOperation::Mod => "%", } } } @@ -66,6 +80,13 @@ impl BinaryOperation { | BinaryOperation::Sub | BinaryOperation::Mul | BinaryOperation::Div + | BinaryOperation::BitOr + | BinaryOperation::BitAnd + | BinaryOperation::BitXor + | BinaryOperation::Shr + | BinaryOperation::ShrSigned + | BinaryOperation::Shl + | BinaryOperation::Mod | BinaryOperation::Pow => BinaryOperationClass::Numeric, BinaryOperation::Or | BinaryOperation::And diff --git a/grammar/src/common/spread.rs b/ast/src/expression/cast.rs similarity index 63% rename from grammar/src/common/spread.rs rename to ast/src/expression/cast.rs index c9dd266816..32dd980651 100644 --- a/grammar/src/common/spread.rs +++ b/ast/src/expression/cast.rs @@ -14,24 +14,29 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::Type; -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; +use super::*; -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::spread))] -pub struct Spread<'ast> { - pub expression: Expression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, +#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +pub struct CastExpression { + pub inner: Box, + pub target_type: Type, + pub span: Span, } -impl<'ast> fmt::Display for Spread<'ast> { +impl fmt::Display for CastExpression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "...{}", self.expression) + write!(f, "{} as {}", self.inner, self.target_type) + } +} + +impl Node for CastExpression { + fn span(&self) -> &Span { + &self.span + } + + fn set_span(&mut self, span: Span) { + self.span = span; } } diff --git a/ast/src/expression/circuit_init.rs b/ast/src/expression/circuit_init.rs index 9f79f3c9ba..8ca5a230e9 100644 --- a/ast/src/expression/circuit_init.rs +++ b/ast/src/expression/circuit_init.rs @@ -27,7 +27,11 @@ impl fmt::Display for CircuitInitExpression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{} {{", self.name)?; for (i, member) in self.members.iter().enumerate() { - write!(f, "{}: {}", member.identifier, member.expression)?; + if let Some(expression) = &member.expression { + write!(f, "{}: {}", member.identifier, expression)?; + } else { + write!(f, "{}", member.identifier)?; + } if i < self.members.len() - 1 { write!(f, ", ")?; diff --git a/ast/src/expression/mod.rs b/ast/src/expression/mod.rs index fb4050f1f2..701efc50bc 100644 --- a/ast/src/expression/mod.rs +++ b/ast/src/expression/mod.rs @@ -24,33 +24,7 @@ use crate::{ Span, SpreadOrExpression, }; -use leo_grammar::{ - access::{Access, AssigneeAccess, SelfAccess}, - common::{Assignee, Identifier as GrammarIdentifier, RangeOrExpression as GrammarRangeOrExpression}, - expressions::{ - ArrayInitializerExpression, - ArrayInlineExpression as GrammarArrayInlineExpression, - BinaryExpression as GrammarBinaryExpression, - CircuitInlineExpression, - Expression as GrammarExpression, - PostfixExpression, - SelfPostfixExpression, - TernaryExpression as GrammarTernaryExpression, - UnaryExpression as GrammarUnaryExpression, - }, - operations::{BinaryOperation as GrammarBinaryOperation, UnaryOperation as GrammarUnaryOperation}, - values::{ - AddressValue, - BooleanValue, - FieldValue, - GroupValue as GrammarGroupValue, - IntegerValue, - NumberValue as GrammarNumber, - Value, - }, -}; -use leo_grammar::{access::TupleAccess, expressions::TupleExpression}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -84,6 +58,8 @@ mod value; pub use value::*; mod call; pub use call::*; +mod cast; +pub use cast::*; /// Expression that evaluates to a value #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] @@ -93,6 +69,7 @@ pub enum Expression { Binary(BinaryExpression), Unary(UnaryExpression), Ternary(TernaryExpression), + Cast(CastExpression), ArrayInline(ArrayInlineExpression), ArrayInit(ArrayInitExpression), @@ -128,6 +105,7 @@ impl Node for Expression { CircuitMemberAccess(n) => n.span(), CircuitStaticFunctionAccess(n) => n.span(), Call(n) => n.span(), + Cast(n) => n.span(), } } @@ -149,11 +127,12 @@ impl Node for Expression { CircuitMemberAccess(n) => n.set_span(span), CircuitStaticFunctionAccess(n) => n.set_span(span), Call(n) => n.set_span(span), + Cast(n) => n.set_span(span), } } } -impl<'ast> fmt::Display for Expression { +impl fmt::Display for Expression { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use Expression::*; match &self { @@ -172,404 +151,7 @@ impl<'ast> fmt::Display for Expression { CircuitMemberAccess(n) => n.fmt(f), CircuitStaticFunctionAccess(n) => n.fmt(f), Call(n) => n.fmt(f), + Cast(n) => n.fmt(f), } } } - -impl<'ast> From> for Expression { - fn from(expression: CircuitInlineExpression<'ast>) -> Self { - let circuit_name = Identifier::from(expression.name); - let members = expression - .members - .into_iter() - .map(CircuitImpliedVariableDefinition::from) - .collect::>(); - - Expression::CircuitInit(CircuitInitExpression { - name: circuit_name, - members, - span: Span::from(expression.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(expression: PostfixExpression<'ast>) -> Self { - let variable = Expression::Identifier(Identifier::from(expression.name)); - - // ast::PostFixExpression contains an array of "accesses": `a(34)[42]` is represented as `[a, [Call(34), Select(42)]]`, but Access call expressions - // are recursive, so it is `Select(Call(a, 34), 42)`. We apply this transformation here - - // we start with the id, and we fold the array of accesses by wrapping the current value - expression - .accesses - .into_iter() - .fold(variable, |acc, access| match access { - // Handle array accesses - Access::Array(array) => match array.expression { - GrammarRangeOrExpression::Expression(expression) => { - Expression::ArrayAccess(ArrayAccessExpression { - array: Box::new(acc), - index: Box::new(Expression::from(expression)), - span: Span::from(array.span), - }) - } - GrammarRangeOrExpression::Range(range) => { - Expression::ArrayRangeAccess(ArrayRangeAccessExpression { - array: Box::new(acc), - left: range.from.map(Expression::from).map(Box::new), - right: range.to.map(Expression::from).map(Box::new), - span: Span::from(array.span), - }) - } - }, - - // Handle tuple access - Access::Tuple(tuple) => Expression::TupleAccess(TupleAccessExpression { - tuple: Box::new(acc), - index: PositiveNumber::from(tuple.number), - span: Span::from(tuple.span), - }), - - // Handle function calls - Access::Call(function) => Expression::Call(CallExpression { - function: Box::new(acc), - arguments: function.expressions.into_iter().map(Expression::from).collect(), - span: Span::from(function.span), - }), - - // Handle circuit member accesses - Access::Object(circuit_object) => Expression::CircuitMemberAccess(CircuitMemberAccessExpression { - circuit: Box::new(acc), - name: Identifier::from(circuit_object.identifier), - span: Span::from(circuit_object.span), - }), - Access::StaticObject(circuit_object) => { - Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { - circuit: Box::new(acc), - name: Identifier::from(circuit_object.identifier), - span: Span::from(circuit_object.span), - }) - } - }) - } -} - -impl<'ast> From> for Expression { - fn from(expression: SelfPostfixExpression<'ast>) -> Self { - let variable = Expression::Identifier(Identifier::from(expression.name)); - - // Handle self expression access. - let self_expression = match expression.self_access { - // Handle circuit member accesses - SelfAccess::Object(circuit_object) => Expression::CircuitMemberAccess(CircuitMemberAccessExpression { - circuit: Box::new(variable), - name: Identifier::from(circuit_object.identifier), - span: Span::from(circuit_object.span), - }), - - // Handle static access - SelfAccess::StaticObject(circuit_object) => { - Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { - circuit: Box::new(variable), - name: Identifier::from(circuit_object.identifier), - span: Span::from(circuit_object.span), - }) - } - }; - // ast::SelfPostFixExpression contains an array of "accesses": `a(34)[42]` is represented as `[a, [Call(34), Select(42)]]`, but Access call expressions - // are recursive, so it is `Select(Call(a, 34), 42)`. We apply this transformation here - - // we start with the id, and we fold the array of accesses by wrapping the current value - expression - .accesses - .into_iter() - .fold(self_expression, |acc, access| match access { - // Handle array accesses - Access::Array(array) => match array.expression { - GrammarRangeOrExpression::Expression(expression) => { - Expression::ArrayAccess(ArrayAccessExpression { - array: Box::new(acc), - index: Box::new(Expression::from(expression)), - span: Span::from(array.span), - }) - } - GrammarRangeOrExpression::Range(range) => { - Expression::ArrayRangeAccess(ArrayRangeAccessExpression { - array: Box::new(acc), - left: range.from.map(Expression::from).map(Box::new), - right: range.to.map(Expression::from).map(Box::new), - span: Span::from(array.span), - }) - } - }, - - // Handle tuple access - Access::Tuple(tuple) => Expression::TupleAccess(TupleAccessExpression { - tuple: Box::new(acc), - index: PositiveNumber::from(tuple.number), - span: Span::from(tuple.span), - }), - - // Handle function calls - Access::Call(function) => Expression::Call(CallExpression { - function: Box::new(acc), - arguments: function.expressions.into_iter().map(Expression::from).collect(), - span: Span::from(function.span), - }), - - // Handle circuit member accesses - Access::Object(circuit_object) => Expression::CircuitMemberAccess(CircuitMemberAccessExpression { - circuit: Box::new(acc), - name: Identifier::from(circuit_object.identifier), - span: Span::from(circuit_object.span), - }), - Access::StaticObject(circuit_object) => { - Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { - circuit: Box::new(acc), - name: Identifier::from(circuit_object.identifier), - span: Span::from(circuit_object.span), - }) - } - }) - } -} - -impl<'ast> From> for Expression { - fn from(expression: GrammarExpression<'ast>) -> Self { - match expression { - GrammarExpression::Value(value) => Expression::from(value), - GrammarExpression::Identifier(variable) => Expression::from(variable), - GrammarExpression::Unary(expression) => Expression::from(*expression), - GrammarExpression::Binary(expression) => Expression::from(*expression), - GrammarExpression::Ternary(expression) => Expression::from(*expression), - GrammarExpression::ArrayInline(expression) => Expression::from(expression), - GrammarExpression::ArrayInitializer(expression) => Expression::from(*expression), - GrammarExpression::Tuple(expression) => Expression::from(expression), - GrammarExpression::CircuitInline(expression) => Expression::from(expression), - GrammarExpression::Postfix(expression) => Expression::from(expression), - GrammarExpression::SelfPostfix(expression) => Expression::from(expression), - } - } -} - -// Assignee -> Expression for operator assign statements -impl<'ast> From> for Expression { - fn from(assignee: Assignee<'ast>) -> Self { - let variable = Expression::Identifier(Identifier::from(assignee.name)); - - // we start with the id, and we fold the array of accesses by wrapping the current value - assignee - .accesses - .into_iter() - .fold(variable, |acc, access| match access { - AssigneeAccess::Member(circuit_member) => { - Expression::CircuitMemberAccess(CircuitMemberAccessExpression { - circuit: Box::new(acc), - name: Identifier::from(circuit_member.identifier), - span: Span::from(circuit_member.span), - }) - } - AssigneeAccess::Array(array) => match array.expression { - GrammarRangeOrExpression::Expression(expression) => { - Expression::ArrayAccess(ArrayAccessExpression { - array: Box::new(acc), - index: Box::new(Expression::from(expression)), - span: Span::from(array.span), - }) - } - GrammarRangeOrExpression::Range(range) => { - Expression::ArrayRangeAccess(ArrayRangeAccessExpression { - array: Box::new(acc), - left: range.from.map(Expression::from).map(Box::new), - right: range.to.map(Expression::from).map(Box::new), - span: Span::from(array.span), - }) - } - }, - AssigneeAccess::Tuple(tuple) => Expression::TupleAccess(TupleAccessExpression { - tuple: Box::new(acc), - index: PositiveNumber::from(tuple.number), - span: Span::from(tuple.span.clone()), - }), - }) - } -} - -impl<'ast> From> for Expression { - fn from(expression: GrammarBinaryExpression<'ast>) -> Self { - use GrammarBinaryOperation::*; - let operator = match expression.operation { - Or => BinaryOperation::Or, - And => BinaryOperation::And, - Eq => BinaryOperation::Eq, - Ne => BinaryOperation::Ne, - Ge => BinaryOperation::Ge, - Gt => BinaryOperation::Gt, - Le => BinaryOperation::Le, - Lt => BinaryOperation::Lt, - Add => BinaryOperation::Add, - Sub => BinaryOperation::Sub, - Mul => BinaryOperation::Mul, - Div => BinaryOperation::Div, - Pow => BinaryOperation::Pow, - }; - Expression::Binary(BinaryExpression { - left: Box::new(Expression::from(expression.left)), - right: Box::new(Expression::from(expression.right)), - op: operator, - span: Span::from(expression.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(expression: GrammarTernaryExpression<'ast>) -> Self { - Expression::Ternary(TernaryExpression { - condition: Box::new(Expression::from(expression.first)), - if_true: Box::new(Expression::from(expression.second)), - if_false: Box::new(Expression::from(expression.third)), - span: Span::from(expression.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(array: GrammarArrayInlineExpression<'ast>) -> Self { - Expression::ArrayInline(ArrayInlineExpression { - elements: array.expressions.into_iter().map(SpreadOrExpression::from).collect(), - span: Span::from(array.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(array: ArrayInitializerExpression<'ast>) -> Self { - Expression::ArrayInit(ArrayInitExpression { - element: Box::new(Expression::from(array.expression)), - dimensions: ArrayDimensions::from(array.dimensions), - span: Span::from(array.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(tuple: TupleExpression<'ast>) -> Self { - Expression::TupleInit(TupleInitExpression { - elements: tuple.expressions.into_iter().map(Expression::from).collect(), - span: Span::from(tuple.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(value: Value<'ast>) -> Self { - match value { - Value::Address(address) => Expression::from(address), - Value::Boolean(boolean) => Expression::from(boolean), - Value::Field(field) => Expression::from(field), - Value::Group(group) => Expression::from(group), - Value::Implicit(number) => Expression::from(number), - Value::Integer(integer) => Expression::from(integer), - } - } -} - -impl<'ast> From> for Expression { - fn from(expression: GrammarUnaryExpression<'ast>) -> Self { - use GrammarUnaryOperation::*; - let operator = match expression.operation { - Not(_) => UnaryOperation::Not, - Negate(_) => UnaryOperation::Negate, - }; - Expression::Unary(UnaryExpression { - inner: Box::new(Expression::from(expression.expression)), - op: operator, - span: Span::from(expression.span), - }) - } -} - -impl<'ast> From> for Expression { - fn from(address: AddressValue<'ast>) -> Self { - Expression::Value(ValueExpression::Address( - address.address.value, - Span::from(address.span), - )) - } -} - -impl<'ast> From> for Expression { - fn from(boolean: BooleanValue<'ast>) -> Self { - Expression::Value(ValueExpression::Boolean(boolean.value, Span::from(boolean.span))) - } -} - -impl<'ast> From> for Expression { - fn from(field: FieldValue<'ast>) -> Self { - Expression::Value(ValueExpression::Field(field.number.to_string(), Span::from(field.span))) - } -} - -impl<'ast> From> for Expression { - fn from(ast_group: GrammarGroupValue<'ast>) -> Self { - Expression::Value(ValueExpression::Group(Box::new(GroupValue::from(ast_group)))) - } -} - -impl<'ast> From> for Expression { - fn from(number: GrammarNumber<'ast>) -> Self { - let (value, span) = match number { - GrammarNumber::Positive(number) => (number.value, number.span), - GrammarNumber::Negative(number) => (number.value, number.span), - }; - - Expression::Value(ValueExpression::Implicit(value, Span::from(span))) - } -} - -impl<'ast> From> for Expression { - fn from(integer: IntegerValue<'ast>) -> Self { - let span = Span::from(integer.span().clone()); - let (type_, value) = match integer { - IntegerValue::Signed(integer) => { - let type_ = IntegerType::from(integer.type_); - let number = match integer.number { - GrammarNumber::Negative(number) => number.value, - GrammarNumber::Positive(number) => number.value, - }; - - (type_, number) - } - IntegerValue::Unsigned(integer) => { - let type_ = IntegerType::from(integer.type_); - let number = integer.number.value; - - (type_, number) - } - }; - - Expression::Value(ValueExpression::Integer(type_, value, span)) - } -} - -impl<'ast> From> for Expression { - fn from(tuple: TupleAccess<'ast>) -> Self { - Expression::Value(ValueExpression::Implicit( - tuple.number.to_string(), - Span::from(tuple.span), - )) - } -} - -impl<'ast> From> for Expression { - fn from(identifier: GrammarIdentifier<'ast>) -> Self { - Expression::Identifier(Identifier::from(identifier)) - } -} - -impl From for Expression { - fn from(identifier: Identifier) -> Self { - Expression::Identifier(identifier) - } -} diff --git a/ast/src/expression/unary.rs b/ast/src/expression/unary.rs index af5f2c685c..cb7eaac44e 100644 --- a/ast/src/expression/unary.rs +++ b/ast/src/expression/unary.rs @@ -20,6 +20,7 @@ use super::*; pub enum UnaryOperation { Not, Negate, + BitNot, } impl AsRef for UnaryOperation { @@ -27,6 +28,7 @@ impl AsRef for UnaryOperation { match self { UnaryOperation::Not => "!", UnaryOperation::Negate => "-", + UnaryOperation::BitNot => "~", } } } diff --git a/ast/src/functions/function.rs b/ast/src/functions/function.rs index e9cea0c8c3..d00c39a084 100644 --- a/ast/src/functions/function.rs +++ b/ast/src/functions/function.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Block, FunctionInput, Identifier, Node, Span, Type}; -use leo_grammar::functions::Function as GrammarFunction; +use crate::{Annotation, Block, FunctionInput, Identifier, Node, Span, Type}; use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Serialize, Deserialize)] pub struct Function { + pub annotations: Vec, pub identifier: Identifier, pub input: Vec, pub output: Option, @@ -37,24 +37,6 @@ impl PartialEq for Function { impl Eq for Function {} -impl<'ast> From> for Function { - fn from(function: GrammarFunction<'ast>) -> Self { - let function_name = Identifier::from(function.identifier); - - let parameters = function.parameters.into_iter().map(FunctionInput::from).collect(); - let returns = function.returns.map(Type::from); - let block = Block::from(function.block); - - Function { - identifier: function_name, - input: parameters, - output: returns, - block, - span: Span::from(function.span), - } - } -} - impl Function { pub fn get_name(&self) -> &str { &self.identifier.name diff --git a/ast/src/functions/input/function_input.rs b/ast/src/functions/input/function_input.rs index 8cece828ad..90f45f3d24 100644 --- a/ast/src/functions/input/function_input.rs +++ b/ast/src/functions/input/function_input.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Identifier, Node, Span, Type}; -use leo_grammar::functions::FunctionInput as GrammarFunctionInput; use serde::{Deserialize, Serialize}; use std::fmt; @@ -29,18 +28,6 @@ pub struct FunctionInputVariable { pub span: Span, } -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), - } - } -} - impl FunctionInputVariable { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { // mut var: bool diff --git a/ast/src/functions/input/input_variable.rs b/ast/src/functions/input/input_variable.rs index ecab44a959..f342cb3e1b 100644 --- a/ast/src/functions/input/input_variable.rs +++ b/ast/src/functions/input/input_variable.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{FunctionInputVariable, InputKeyword, MutSelfKeyword, Node, SelfKeyword, Span}; -use leo_grammar::functions::input::Input as GrammarInput; use serde::{Deserialize, Serialize}; use std::fmt; @@ -29,19 +28,6 @@ pub enum FunctionInput { Variable(FunctionInputVariable), } -impl<'ast> From> for FunctionInput { - fn from(input: GrammarInput<'ast>) -> Self { - match input { - GrammarInput::InputKeyword(keyword) => FunctionInput::InputKeyword(InputKeyword::from(keyword)), - GrammarInput::SelfKeyword(keyword) => FunctionInput::SelfKeyword(SelfKeyword::from(keyword)), - GrammarInput::MutSelfKeyword(keyword) => FunctionInput::MutSelfKeyword(MutSelfKeyword::from(keyword)), - GrammarInput::FunctionInput(function_input) => { - FunctionInput::Variable(FunctionInputVariable::from(function_input)) - } - } - } -} - impl FunctionInput { /// /// Returns `true` if the function input is the `self` or `mut self` keyword. diff --git a/ast/src/functions/mod.rs b/ast/src/functions/mod.rs index f16e3448d2..430fc3f77a 100644 --- a/ast/src/functions/mod.rs +++ b/ast/src/functions/mod.rs @@ -19,6 +19,3 @@ pub use function::*; pub mod input; pub use input::*; - -pub mod test_function; -pub use test_function::*; diff --git a/ast/src/functions/test_function.rs b/ast/src/functions/test_function.rs deleted file mode 100644 index eb9f09a346..0000000000 --- a/ast/src/functions/test_function.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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::{Function, Identifier}; -use leo_grammar::functions::TestFunction as GrammarTestFunction; - -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] -pub struct TestFunction { - pub function: Function, - pub input_file: Option, -} - -impl<'ast> From> for TestFunction { - fn from(test: GrammarTestFunction) -> Self { - TestFunction { - function: Function::from(test.function), - input_file: None, // pass custom input file with `@context` annotation - } - } -} diff --git a/ast/src/groups/group_coordinate.rs b/ast/src/groups/group_coordinate.rs index fd201856dd..5f64c476dc 100644 --- a/ast/src/groups/group_coordinate.rs +++ b/ast/src/groups/group_coordinate.rs @@ -15,13 +15,6 @@ // along with the Leo library. If not, see . use crate::common::span::Span; -use leo_grammar::values::{ - GroupCoordinate as GrammarGroupCoordinate, - Inferred as GrammarInferred, - NumberValue as GrammarNumberValue, - SignHigh as GrammarSignHigh, - SignLow as GrammarSignLow, -}; use leo_input::values::{ GroupCoordinate as InputGroupCoordinate, Inferred as InputInferred, @@ -41,17 +34,6 @@ pub enum GroupCoordinate { Inferred, } -impl<'ast> From> for GroupCoordinate { - fn from(coordinate: GrammarGroupCoordinate<'ast>) -> Self { - match coordinate { - GrammarGroupCoordinate::Number(number) => GroupCoordinate::from(number), - GrammarGroupCoordinate::SignHigh(sign_high) => GroupCoordinate::from(sign_high), - GrammarGroupCoordinate::SignLow(sign_low) => GroupCoordinate::from(sign_low), - GrammarGroupCoordinate::Inferred(inferred) => GroupCoordinate::from(inferred), - } - } -} - impl<'ast> From> for GroupCoordinate { fn from(coordinate: InputGroupCoordinate<'ast>) -> Self { match coordinate { @@ -74,33 +56,6 @@ impl fmt::Display for GroupCoordinate { } } -impl<'ast> From> for GroupCoordinate { - fn from(number: GrammarNumberValue<'ast>) -> Self { - let value = number.to_string(); - let span = Span::from(number.span().clone()); - - GroupCoordinate::Number(value, span) - } -} - -impl<'ast> From> for GroupCoordinate { - fn from(_sign: GrammarSignHigh<'ast>) -> Self { - GroupCoordinate::SignHigh - } -} - -impl<'ast> From> for GroupCoordinate { - fn from(_sign: GrammarSignLow<'ast>) -> Self { - GroupCoordinate::SignLow - } -} - -impl<'ast> From> for GroupCoordinate { - fn from(_sign: GrammarInferred<'ast>) -> Self { - GroupCoordinate::Inferred - } -} - impl<'ast> From> for GroupCoordinate { fn from(number: InputNumberValue<'ast>) -> Self { let value = number.to_string(); diff --git a/ast/src/groups/group_value.rs b/ast/src/groups/group_value.rs index 5e0c42113e..e36aba3659 100644 --- a/ast/src/groups/group_value.rs +++ b/ast/src/groups/group_value.rs @@ -15,11 +15,6 @@ // along with the Leo library. If not, see . use crate::{common::span::Span, groups::GroupCoordinate}; -use leo_grammar::values::{ - GroupRepresentation as GrammarGroupRepresentation, - GroupTuple as GrammarGroupTuple, - GroupValue as GrammarGroupValue, -}; use leo_input::values::{ GroupRepresentation as InputGroupRepresentation, GroupTuple as InputGroupTuple, @@ -51,17 +46,6 @@ impl GroupValue { } } -impl<'ast> From> for GroupValue { - fn from(ast_group: GrammarGroupValue) -> Self { - let span = Span::from(ast_group.span); - - match ast_group.value { - GrammarGroupRepresentation::Single(number) => GroupValue::Single(number.to_string(), span), - GrammarGroupRepresentation::Tuple(tuple) => GroupValue::Tuple(GroupTuple::from(tuple)), - } - } -} - impl<'ast> From> for GroupValue { fn from(ast_group: InputGroupValue) -> Self { let span = Span::from(ast_group.span); @@ -89,19 +73,6 @@ pub struct GroupTuple { pub span: Span, } -impl<'ast> From> for GroupTuple { - fn from(ast_group: GrammarGroupTuple<'ast>) -> Self { - let ast_x = ast_group.x; - let ast_y = ast_group.y; - - Self { - x: GroupCoordinate::from(ast_x), - y: GroupCoordinate::from(ast_y), - span: Span::from(ast_group.span), - } - } -} - impl<'ast> From> for GroupTuple { fn from(ast_group: InputGroupTuple<'ast>) -> Self { let ast_x = ast_group.x; diff --git a/ast/src/imports/import.rs b/ast/src/imports/import.rs index 246f61c3b1..93c4ad6f6d 100644 --- a/ast/src/imports/import.rs +++ b/ast/src/imports/import.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{PackageOrPackages, Span}; -use leo_grammar::imports::Import as GrammarImport; use serde::{Deserialize, Serialize}; use std::fmt; @@ -39,15 +38,6 @@ impl ImportStatement { } } -impl<'ast> From> for ImportStatement { - fn from(import: GrammarImport<'ast>) -> Self { - ImportStatement { - package_or_packages: PackageOrPackages::from(import.package_or_packages), - span: Span::from(import.span), - } - } -} - impl ImportStatement { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "import {};", self.package_or_packages) diff --git a/ast/src/imports/import_symbol.rs b/ast/src/imports/import_symbol.rs index 20d8650793..cc7a038dad 100644 --- a/ast/src/imports/import_symbol.rs +++ b/ast/src/imports/import_symbol.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Identifier, Span}; -use leo_grammar::imports::ImportSymbol as GrammarImportSymbol; use serde::{Deserialize, Serialize}; use std::fmt; @@ -27,16 +26,6 @@ pub struct ImportSymbol { pub span: Span, } -impl<'ast> From> for ImportSymbol { - fn from(symbol: GrammarImportSymbol<'ast>) -> Self { - ImportSymbol { - symbol: Identifier::from(symbol.value), - alias: symbol.alias.map(Identifier::from), - span: Span::from(symbol.span), - } - } -} - impl fmt::Display for ImportSymbol { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.alias.is_some() { diff --git a/ast/src/imports/package.rs b/ast/src/imports/package.rs index 091e72142d..1ccd3007b1 100644 --- a/ast/src/imports/package.rs +++ b/ast/src/imports/package.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{common::Identifier, PackageAccess, Span}; -use leo_grammar::imports::Package as GrammarPackage; use serde::{Deserialize, Serialize}; use std::fmt; @@ -27,16 +26,6 @@ pub struct Package { pub span: Span, } -impl<'ast> From> for Package { - fn from(package: GrammarPackage<'ast>) -> Self { - Package { - name: Identifier::from(package.name), - access: PackageAccess::from(package.access), - span: Span::from(package.span), - } - } -} - impl Package { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}.{}", self.name, self.access) diff --git a/ast/src/imports/package_access.rs b/ast/src/imports/package_access.rs index b329cc6b82..7245f900af 100644 --- a/ast/src/imports/package_access.rs +++ b/ast/src/imports/package_access.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ImportSymbol, Package, Packages, Span}; -use leo_grammar::imports::PackageAccess as GrammarPackageAccess; +use crate::{ImportSymbol, Node, Package, Packages, Span}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -28,13 +27,22 @@ pub enum PackageAccess { Multiple(Packages), } -impl<'ast> From> for PackageAccess { - fn from(access: GrammarPackageAccess<'ast>) -> Self { - match access { - GrammarPackageAccess::Star(star) => PackageAccess::Star(Span::from(star.span)), - GrammarPackageAccess::SubPackage(package) => PackageAccess::SubPackage(Box::new(Package::from(*package))), - GrammarPackageAccess::Symbol(symbol) => PackageAccess::Symbol(ImportSymbol::from(symbol)), - GrammarPackageAccess::Multiple(packages) => PackageAccess::Multiple(Packages::from(packages)), +impl Node for PackageAccess { + fn span(&self) -> &Span { + match self { + PackageAccess::Star(span) => span, + PackageAccess::SubPackage(package) => &package.span, + PackageAccess::Symbol(package) => &package.span, + PackageAccess::Multiple(package) => &package.span, + } + } + + fn set_span(&mut self, span: Span) { + match self { + PackageAccess::Star(package) => *package = span, + PackageAccess::SubPackage(package) => package.span = span, + PackageAccess::Symbol(package) => package.span = span, + PackageAccess::Multiple(package) => package.span = span, } } } diff --git a/ast/src/imports/package_or_packages.rs b/ast/src/imports/package_or_packages.rs index 2f1b9bc717..7f42d57fd7 100644 --- a/ast/src/imports/package_or_packages.rs +++ b/ast/src/imports/package_or_packages.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Package, Packages}; -use leo_grammar::imports::PackageOrPackages as GrammarPackageOrPackages; +use crate::{Node, Package, Packages, Span}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -26,15 +25,6 @@ pub enum PackageOrPackages { Packages(Packages), } -impl<'ast> From> for PackageOrPackages { - fn from(package_or_packages: GrammarPackageOrPackages<'ast>) -> Self { - match package_or_packages { - GrammarPackageOrPackages::Package(package) => PackageOrPackages::Package(Package::from(package)), - GrammarPackageOrPackages::Packages(packages) => PackageOrPackages::Packages(Packages::from(packages)), - } - } -} - impl PackageOrPackages { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -64,3 +54,19 @@ impl fmt::Display for PackageOrPackages { self.format(f) } } + +impl Node for PackageOrPackages { + fn span(&self) -> &Span { + match self { + PackageOrPackages::Package(package) => &package.span, + PackageOrPackages::Packages(packages) => &packages.span, + } + } + + fn set_span(&mut self, span: Span) { + match self { + PackageOrPackages::Package(package) => package.span = span, + PackageOrPackages::Packages(packages) => packages.span = span, + } + } +} diff --git a/ast/src/imports/packages.rs b/ast/src/imports/packages.rs index fab9542716..e561080807 100644 --- a/ast/src/imports/packages.rs +++ b/ast/src/imports/packages.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{common::Identifier, PackageAccess, Span}; -use leo_grammar::imports::Packages as GrammarPackages; use serde::{Deserialize, Serialize}; use std::fmt; @@ -27,16 +26,6 @@ pub struct Packages { pub span: Span, } -impl<'ast> From> for Packages { - fn from(packages: GrammarPackages<'ast>) -> Self { - Packages { - name: Identifier::from(packages.name), - accesses: packages.accesses.into_iter().map(PackageAccess::from).collect(), - span: Span::from(packages.span), - } - } -} - impl Packages { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}.(", self.name)?; diff --git a/ast/src/input/input_value.rs b/ast/src/input/input_value.rs index 5d6fba2a9e..daa4194dc9 100644 --- a/ast/src/input/input_value.rs +++ b/ast/src/input/input_value.rs @@ -114,7 +114,7 @@ impl InputValue { let array_dimensions_type = ArrayDimensions::from(array_type.dimensions.clone()); // Convert the array dimensions to usize. - let array_dimensions = parse_array_dimensions(array_dimensions_type, array_type.span.clone())?; + let array_dimensions = parse_array_dimensions(array_dimensions_type, &array_type.span)?; // Return an error if the outer array dimension does not equal the number of array elements. if array_dimensions[0] != inline.expressions.len() { @@ -146,7 +146,7 @@ impl InputValue { initializer: ArrayInitializerExpression, ) -> Result { let array_dimensions_type = ArrayDimensions::from(initializer.dimensions.clone()); - let array_dimensions = parse_array_dimensions(array_dimensions_type, array_type.span.clone())?; + let array_dimensions = parse_array_dimensions(array_dimensions_type, &array_type.span)?; if array_dimensions.len() > 1 { // The expression is an array initializer with tuple syntax @@ -169,7 +169,7 @@ impl InputValue { return Err(InputParserError::array_init_length( array_dimensions, initializer_dimensions, - initializer.span, + &initializer.span, )); } @@ -199,7 +199,7 @@ impl InputValue { let array_dimensions_type = ArrayDimensions::from(array_type.dimensions.clone()); // Convert the array dimensions to usize. - let array_dimensions = parse_array_dimensions(array_dimensions_type, array_type.span.clone())?; + let array_dimensions = parse_array_dimensions(array_dimensions_type, &array_type.span)?; let current_array_dimension = array_dimensions[0]; let current_initializer_dimension = initializer_dimensions[0]; @@ -209,7 +209,7 @@ impl InputValue { return Err(InputParserError::array_init_length( array_dimensions, initializer_dimensions, - initializer.span, + &initializer.span, )); } @@ -235,11 +235,7 @@ impl InputValue { let num_values = tuple.expressions.len(); if num_types != num_values { - return Err(InputParserError::tuple_length( - num_types, - num_values, - tuple_type.span.clone(), - )); + return Err(InputParserError::tuple_length(num_types, num_values, &tuple_type.span)); } let mut values = Vec::with_capacity(tuple_type.types_.len()); @@ -260,7 +256,7 @@ impl InputValue { /// is successful, the `usize` value is appended to the return vector. If parsing fails, an error /// is returned. /// -fn parse_array_dimensions(array_dimensions_type: ArrayDimensions, span: Span) -> Result, InputParserError> { +fn parse_array_dimensions(array_dimensions_type: ArrayDimensions, span: &Span) -> Result, InputParserError> { // Convert the array dimensions to usize. let mut array_dimensions = Vec::with_capacity(array_dimensions_type.0.len()); @@ -271,7 +267,7 @@ fn parse_array_dimensions(array_dimensions_type: ArrayDimensions, span: Span) -> // Convert the string to usize. let dimension_usize = match dimension_string.parse::() { Ok(dimension_usize) => dimension_usize, - Err(_) => return Err(InputParserError::array_index(dimension_string, span.clone())), + Err(_) => return Err(InputParserError::array_index(dimension_string, span)), }; // Collect dimension usize values. @@ -292,7 +288,7 @@ fn fetch_nested_array_type_dimensions( let array_dimensions_type = ArrayDimensions::from(array_type.dimensions.clone()); // Convert the array dimensions to usize. - let mut current_dimension = parse_array_dimensions(array_dimensions_type, array_type.span.clone())?; + let mut current_dimension = parse_array_dimensions(array_dimensions_type, &array_type.span)?; array_dimensions.append(&mut current_dimension); diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 51fd09e848..8131a97d6c 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -19,9 +19,6 @@ //! This module contains the [`Ast`] type, a wrapper around the [`Program`] type. //! The [`Ast`] type is intended to be parsed and modified by different passes //! of the Leo compiler. The Leo compiler can generate a set of R1CS constraints from any [`Ast`]. -#[macro_use] -extern crate thiserror; - pub mod annotation; pub use self::annotation::*; @@ -61,8 +58,6 @@ pub use self::types::*; mod node; pub use node::*; -use leo_grammar::Grammar; - /// The abstract syntax tree (AST) for a Leo program. /// /// The [`Ast`] type represents a Leo program as a series of recursive data types. @@ -76,10 +71,8 @@ pub struct Ast { impl Ast { /// 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, grammar.as_repr())?, - }) + pub fn new(program: Program) -> Self { + Self { ast: program } } /// Returns a reference to the inner program AST representation. @@ -87,6 +80,10 @@ impl Ast { &self.ast } + pub fn into_repr(self) -> Program { + self.ast + } + /// Serializes the ast into a JSON string. pub fn to_json_string(&self) -> Result { serde_json::to_string_pretty(&self.ast) @@ -98,3 +95,9 @@ impl Ast { Ok(Self { ast }) } } + +impl AsRef for Ast { + fn as_ref(&self) -> &Program { + &self.ast + } +} diff --git a/ast/src/main.rs b/ast/src/main.rs deleted file mode 100644 index 02f627cc4a..0000000000 --- a/ast/src/main.rs +++ /dev/null @@ -1,71 +0,0 @@ -// 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_ast::{Ast, AstError}; -use leo_grammar::Grammar; -use std::{env, fs, path::Path}; - -fn to_leo_tree(filepath: &Path) -> Result { - // Loads the Leo code as a string from the given file path. - let program_filepath = filepath.to_path_buf(); - let program_string = Grammar::load_file(&program_filepath)?; - - // Parses the Leo file and constructs a pest ast. - let ast = Grammar::new(&program_filepath, &program_string)?; - - // Parse the pest ast and constructs a ast. - let leo_ast = Ast::new("leo_tree", &ast)?; - - let serialized_leo_ast = Ast::to_json_string(&leo_ast)?; - - Ok(serialized_leo_ast) -} - -fn main() -> Result<(), AstError> { - // Parse the command-line arguments as strings. - let cli_arguments = env::args().collect::>(); - - // Check that the correct number of command-line arguments were passed in. - if cli_arguments.len() < 2 || cli_arguments.len() > 3 { - eprintln!("Warning - an invalid number of command-line arguments were provided."); - println!( - "\nCommand-line usage:\n\n\tleo_ast {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n" - ); - return Ok(()); // Exit innocently - } - - // Construct the input filepath. - let input_filepath = Path::new(&cli_arguments[1]); - - // Construct the serialized syntax tree. - let serialized_leo_tree = to_leo_tree(&input_filepath)?; - println!("{}", serialized_leo_tree); - - // Determine the output directory. - let output_directory = match cli_arguments.len() == 3 { - true => format!( - "{}/{}.json", - cli_arguments[2], - input_filepath.file_stem().unwrap().to_str().unwrap() - ), - false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()), - }; - - // Write the serialized syntax tree to the output directory. - fs::write(Path::new(&output_directory), serialized_leo_tree)?; - - Ok(()) -} diff --git a/ast/src/program.rs b/ast/src/program.rs index 531a6316bb..41602aac30 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -17,17 +17,7 @@ //! A Leo program consists of import, circuit, and function definitions. //! Each defined type consists of ast statements and expressions. -use crate::{ - load_annotation, - Circuit, - DeprecatedError, - Function, - FunctionInput, - Identifier, - ImportStatement, - TestFunction, -}; -use leo_grammar::{definitions::Definition, files::File}; +use crate::{Circuit, Function, FunctionInput, Identifier, ImportStatement}; use indexmap::IndexMap; use serde::{Deserialize, Serialize}; @@ -41,7 +31,12 @@ pub struct Program { pub imports: Vec, pub circuits: IndexMap, pub functions: IndexMap, - pub tests: IndexMap, +} + +impl AsRef for Program { + fn as_ref(&self) -> &Program { + self + } } impl fmt::Display for Program { @@ -60,80 +55,10 @@ impl fmt::Display for Program { function.fmt(f)?; writeln!(f,)?; } - for (_, test) in self.tests.iter() { - write!(f, "test ")?; - test.function.fmt(f)?; - writeln!(f,)?; - } write!(f, "") } } -const MAIN_FUNCTION_NAME: &str = "main"; - -impl<'ast> Program { - //! Logic to convert from an abstract syntax tree (ast) representation to a Leo program. - pub fn from(program_name: &str, program_ast: &File<'ast>) -> Result { - let mut imports = vec![]; - let mut circuits = IndexMap::new(); - let mut functions = IndexMap::new(); - let mut tests = IndexMap::new(); - let mut expected_input = vec![]; - - program_ast - .definitions - .to_owned() - .into_iter() - // Use of Infallible to say we never expect an Some(Ok(...)) - .find_map::, _>(|definition| match definition { - Definition::Import(import) => { - imports.push(ImportStatement::from(import)); - None - } - Definition::Circuit(circuit) => { - circuits.insert(Identifier::from(circuit.identifier.clone()), Circuit::from(circuit)); - None - } - Definition::Function(function_def) => { - let function = Function::from(function_def); - if function.identifier.name.eq(MAIN_FUNCTION_NAME) { - expected_input = function.input.clone(); - } - functions.insert(function.identifier.clone(), function); - None - } - Definition::Deprecated(deprecated) => { - Some(Err(DeprecatedError::from(deprecated))) - } - Definition::Annotated(annotated_definition) => { - let loaded_annotation = load_annotation( - annotated_definition, - &mut imports, - &mut circuits, - &mut functions, - &mut tests, - &mut expected_input, - ); - - match loaded_annotation { - Ok(_) => None, - Err(deprecated_err) => Some(Err(deprecated_err)) - } - } - }) - .transpose()?; - - Ok(Self { - name: program_name.to_string(), - expected_input, - imports, - circuits, - functions, - tests, - }) - } -} - impl Program { pub fn new(name: String) -> Self { Self { @@ -142,7 +67,6 @@ impl Program { imports: vec![], circuits: IndexMap::new(), functions: IndexMap::new(), - tests: IndexMap::new(), } } diff --git a/ast/src/statements/assign/assignee.rs b/ast/src/statements/assign/assignee.rs index e84cccf2a9..da73eb9d38 100644 --- a/ast/src/statements/assign/assignee.rs +++ b/ast/src/statements/assign/assignee.rs @@ -15,10 +15,6 @@ // along with the Leo library. If not, see . use crate::{Expression, Identifier, PositiveNumber, Span}; -use leo_grammar::{ - access::{ArrayAccess, AssigneeAccess as GrammarAssigneeAccess}, - common::{Assignee as GrammarAssignee, Range, RangeOrExpression}, -}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -31,25 +27,6 @@ pub enum AssigneeAccess { Member(Identifier), } -impl<'ast> From> for AssigneeAccess { - fn from(access: GrammarAssigneeAccess<'ast>) -> Self { - match access { - GrammarAssigneeAccess::Array(ArrayAccess { - expression: RangeOrExpression::Range(Range { from, to, .. }), - .. - }) => AssigneeAccess::ArrayRange(from.map(Expression::from), to.map(Expression::from)), - GrammarAssigneeAccess::Array(ArrayAccess { - expression: RangeOrExpression::Expression(index), - .. - }) => AssigneeAccess::ArrayIndex(Expression::from(index)), - GrammarAssigneeAccess::Tuple(tuple) => { - AssigneeAccess::Tuple(PositiveNumber::from(tuple.number), Span::from(tuple.span)) - } - GrammarAssigneeAccess::Member(member) => AssigneeAccess::Member(Identifier::from(member.identifier)), - } - } -} - /// Definition assignee: v, arr[0..2], Point p.x #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct Assignee { @@ -65,20 +42,6 @@ impl Assignee { } } -impl<'ast> From> for Assignee { - fn from(assignee: GrammarAssignee<'ast>) -> Self { - Assignee { - identifier: Identifier::from(assignee.name), - accesses: assignee - .accesses - .into_iter() - .map(AssigneeAccess::from) - .collect::>(), - span: Span::from(assignee.span), - } - } -} - impl fmt::Display for Assignee { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{}", self.identifier)?; diff --git a/ast/src/statements/assign/mod.rs b/ast/src/statements/assign/mod.rs index 947472d14c..ae88fda809 100644 --- a/ast/src/statements/assign/mod.rs +++ b/ast/src/statements/assign/mod.rs @@ -16,8 +16,6 @@ use crate::{Expression, Node, Span}; -pub use leo_grammar::operations::AssignOperation as GrammarAssignOperation; -use leo_grammar::statements::AssignStatement as GrammarAssignStatement; use serde::{Deserialize, Serialize}; use std::fmt; @@ -32,6 +30,15 @@ pub enum AssignOperation { Mul, Div, Pow, + Or, + And, + BitOr, + BitAnd, + BitXor, + Shr, + ShrSigned, + Shl, + Mod, } impl AsRef for AssignOperation { @@ -43,6 +50,15 @@ impl AsRef for AssignOperation { AssignOperation::Mul => "*=", AssignOperation::Div => "/=", AssignOperation::Pow => "**=", + AssignOperation::Or => "||=", + AssignOperation::And => "&&=", + AssignOperation::BitOr => "|=", + AssignOperation::BitAnd => "&=", + AssignOperation::BitXor => "^=", + AssignOperation::Shr => ">>=", + AssignOperation::ShrSigned => ">>>=", + AssignOperation::Shl => "<<=", + AssignOperation::Mod => "%=", } } } @@ -61,24 +77,6 @@ impl fmt::Display for AssignStatement { } } -impl<'ast> From> for AssignStatement { - fn from(statement: GrammarAssignStatement<'ast>) -> Self { - AssignStatement { - operation: match statement.assign { - GrammarAssignOperation::Assign(_) => AssignOperation::Assign, - GrammarAssignOperation::AddAssign(_) => AssignOperation::Add, - GrammarAssignOperation::SubAssign(_) => AssignOperation::Sub, - GrammarAssignOperation::MulAssign(_) => AssignOperation::Mul, - GrammarAssignOperation::DivAssign(_) => AssignOperation::Div, - GrammarAssignOperation::PowAssign(_) => AssignOperation::Pow, - }, - assignee: Assignee::from(statement.assignee), - value: Expression::from(statement.expression), - span: Span::from(statement.span), - } - } -} - impl Node for AssignStatement { fn span(&self) -> &Span { &self.span diff --git a/ast/src/statements/block.rs b/ast/src/statements/block.rs index d6cb72f26f..71270e0d19 100644 --- a/ast/src/statements/block.rs +++ b/ast/src/statements/block.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Node, Span, Statement}; -use leo_grammar::statements::Block as GrammarBlock; use serde::{Deserialize, Serialize}; use std::fmt; @@ -26,15 +25,6 @@ pub struct Block { pub span: Span, } -impl<'ast> From> for Block { - fn from(block: GrammarBlock<'ast>) -> Self { - Block { - statements: block.statements.into_iter().map(Statement::from).collect(), - span: Span::from(block.span), - } - } -} - impl fmt::Display for Block { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { writeln!(f, "{{")?; diff --git a/ast/src/statements/conditional.rs b/ast/src/statements/conditional.rs index cf836ef3ed..e2b11d98af 100644 --- a/ast/src/statements/conditional.rs +++ b/ast/src/statements/conditional.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Block, Expression, Node, Span, Statement}; -use leo_grammar::statements::{ConditionalNestedOrEndStatement, ConditionalStatement as GrammarConditionalStatement}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -28,25 +27,6 @@ pub struct ConditionalStatement { pub span: Span, } -impl<'ast> From> for ConditionalStatement { - fn from(statement: GrammarConditionalStatement<'ast>) -> Self { - ConditionalStatement { - condition: Expression::from(statement.condition), - block: Block::from(statement.block), - next: statement - .next - .map(|nested_statement| match nested_statement { - ConditionalNestedOrEndStatement::Nested(conditional_statement) => { - Statement::Conditional(ConditionalStatement::from(*conditional_statement)) - } - ConditionalNestedOrEndStatement::End(block) => Statement::Block(Block::from(block)), - }) - .map(Box::new), - span: Span::from(statement.span), - } - } -} - impl fmt::Display for ConditionalStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "if ({}) {}", self.condition, self.block)?; diff --git a/ast/src/statements/console/console_function.rs b/ast/src/statements/console/console_function.rs index 7e9f9892ca..16115878ce 100644 --- a/ast/src/statements/console/console_function.rs +++ b/ast/src/statements/console/console_function.rs @@ -14,19 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, FormattedString}; -use leo_grammar::console::{ - ConsoleAssert as GrammarConsoleAssert, - ConsoleDebug as GrammarConsoleDebug, - ConsoleError as GrammarConsoleError, - ConsoleFunction as GrammarConsoleFunction, - ConsoleLog as GrammarConsoleLog, -}; +use crate::{Expression, FormattedString, Node, Span}; use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub enum ConsoleFunction { Assert(Expression), Debug(FormattedString), @@ -34,41 +27,6 @@ pub enum ConsoleFunction { Log(FormattedString), } -impl<'ast> From> for ConsoleFunction { - fn from(console_function: GrammarConsoleFunction<'ast>) -> Self { - match console_function { - GrammarConsoleFunction::Assert(assert) => ConsoleFunction::from(assert), - GrammarConsoleFunction::Debug(debug) => ConsoleFunction::from(debug), - GrammarConsoleFunction::Error(error) => ConsoleFunction::from(error), - GrammarConsoleFunction::Log(log) => ConsoleFunction::from(log), - } - } -} - -impl<'ast> From> for ConsoleFunction { - fn from(assert: GrammarConsoleAssert<'ast>) -> Self { - ConsoleFunction::Assert(Expression::from(assert.expression)) - } -} - -impl<'ast> From> for ConsoleFunction { - fn from(debug: GrammarConsoleDebug<'ast>) -> Self { - ConsoleFunction::Debug(FormattedString::from(debug.string)) - } -} - -impl<'ast> From> for ConsoleFunction { - fn from(error: GrammarConsoleError<'ast>) -> Self { - ConsoleFunction::Error(FormattedString::from(error.string)) - } -} - -impl<'ast> From> for ConsoleFunction { - fn from(log: GrammarConsoleLog<'ast>) -> Self { - ConsoleFunction::Log(FormattedString::from(log.string)) - } -} - impl fmt::Display for ConsoleFunction { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -79,3 +37,23 @@ impl fmt::Display for ConsoleFunction { } } } + +impl Node for ConsoleFunction { + fn span(&self) -> &Span { + match self { + ConsoleFunction::Assert(assert) => assert.span(), + ConsoleFunction::Debug(formatted) | ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => { + &formatted.span + } + } + } + + fn set_span(&mut self, span: Span) { + match self { + ConsoleFunction::Assert(assert) => assert.set_span(span), + ConsoleFunction::Debug(formatted) | ConsoleFunction::Error(formatted) | ConsoleFunction::Log(formatted) => { + formatted.set_span(span) + } + } + } +} diff --git a/ast/src/statements/console/console_statement.rs b/ast/src/statements/console/console_statement.rs index ad837f42f5..de916205fa 100644 --- a/ast/src/statements/console/console_statement.rs +++ b/ast/src/statements/console/console_statement.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{ConsoleFunction, Node, Span}; -use leo_grammar::console::ConsoleFunctionCall as GrammarConsoleFunctionCall; use serde::{Deserialize, Serialize}; use std::fmt; @@ -26,15 +25,6 @@ pub struct ConsoleStatement { pub span: Span, } -impl<'ast> From> for ConsoleStatement { - fn from(console: GrammarConsoleFunctionCall<'ast>) -> Self { - ConsoleStatement { - function: ConsoleFunction::from(console.function), - span: Span::from(console.span), - } - } -} - impl fmt::Display for ConsoleStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "console.{};", self.function) diff --git a/ast/src/statements/console/formatted_container.rs b/ast/src/statements/console/formatted_container.rs index 4634aa4c4a..cca1a17220 100644 --- a/ast/src/statements/console/formatted_container.rs +++ b/ast/src/statements/console/formatted_container.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Node, Span}; -use leo_grammar::console::FormattedContainer as GrammarFormattedContainer; use serde::{Deserialize, Serialize}; use std::fmt; @@ -25,14 +24,6 @@ pub struct FormattedContainer { pub span: Span, } -impl<'ast> From> for FormattedContainer { - fn from(container: GrammarFormattedContainer<'ast>) -> Self { - Self { - span: Span::from(container.span), - } - } -} - impl fmt::Display for FormattedContainer { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{{}}") diff --git a/ast/src/statements/console/formatted_string.rs b/ast/src/statements/console/formatted_string.rs index f96baa1fe1..e5e653e745 100644 --- a/ast/src/statements/console/formatted_string.rs +++ b/ast/src/statements/console/formatted_string.rs @@ -14,39 +14,38 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, FormattedContainer, Node, Span}; -use leo_grammar::console::FormattedString as GrammarFormattedString; +use crate::{Expression, Node, Span}; use serde::{Deserialize, Serialize}; use std::fmt; +#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] +pub enum FormattedStringPart { + Const(String), + Container, +} + #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct FormattedString { - pub string: String, - pub containers: Vec, + pub parts: Vec, pub parameters: Vec, pub span: Span, } -impl<'ast> From> for FormattedString { - fn from(formatted: GrammarFormattedString<'ast>) -> Self { - let string = formatted.string; - let span = Span::from(formatted.span); - let containers = formatted.containers.into_iter().map(FormattedContainer::from).collect(); - let parameters = formatted.parameters.into_iter().map(Expression::from).collect(); - - Self { - string, - containers, - parameters, - span, - } - } -} - impl fmt::Display for FormattedString { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.string) + write!( + f, + "{}", + self.parts + .iter() + .map(|x| match x { + FormattedStringPart::Const(x) => x, + FormattedStringPart::Container => "{}", + }) + .collect::>() + .join("") + ) } } diff --git a/ast/src/statements/definition/declare.rs b/ast/src/statements/definition/declare.rs index de00d5f210..1c70e13fdc 100644 --- a/ast/src/statements/definition/declare.rs +++ b/ast/src/statements/definition/declare.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::common::Declare as GrammarDeclare; - use serde::{Deserialize, Serialize}; use std::fmt; @@ -25,15 +23,6 @@ pub enum Declare { Let, } -impl<'ast> From for Declare { - fn from(declare: GrammarDeclare) -> Self { - match declare { - GrammarDeclare::Const(_) => Declare::Const, - GrammarDeclare::Let(_) => Declare::Let, - } - } -} - impl fmt::Display for Declare { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/ast/src/statements/definition/mod.rs b/ast/src/statements/definition/mod.rs index 78ad5ea933..15d2893b2d 100644 --- a/ast/src/statements/definition/mod.rs +++ b/ast/src/statements/definition/mod.rs @@ -24,7 +24,6 @@ pub use variable_name::*; mod declare; pub use declare::*; -use leo_grammar::statements::DefinitionStatement as GrammarDefinitionStatement; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] pub struct DefinitionStatement { @@ -60,27 +59,6 @@ impl fmt::Display for DefinitionStatement { } } -impl<'ast> From> for DefinitionStatement { - fn from(statement: GrammarDefinitionStatement<'ast>) -> Self { - let variable_names = statement - .variables - .names - .into_iter() - .map(VariableName::from) - .collect::>(); - - let type_ = statement.variables.type_.map(Type::from); - - DefinitionStatement { - declaration_type: Declare::from(statement.declare), - variable_names, - type_, - value: Expression::from(statement.expression), - span: Span::from(statement.span), - } - } -} - impl Node for DefinitionStatement { fn span(&self) -> &Span { &self.span diff --git a/ast/src/statements/definition/variable_name.rs b/ast/src/statements/definition/variable_name.rs index 7384b8ee1d..c0fc5b09d6 100644 --- a/ast/src/statements/definition/variable_name.rs +++ b/ast/src/statements/definition/variable_name.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{Identifier, Node, Span}; -use leo_grammar::common::VariableName as GrammarVariableName; use serde::{Deserialize, Serialize}; use std::fmt; @@ -27,16 +26,6 @@ pub struct VariableName { pub span: Span, } -impl<'ast> From> for VariableName { - fn from(name: GrammarVariableName<'ast>) -> Self { - Self { - mutable: name.mutable.is_some(), - identifier: Identifier::from(name.identifier), - span: Span::from(name.span), - } - } -} - impl fmt::Display for VariableName { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if self.mutable { diff --git a/ast/src/statements/expression.rs b/ast/src/statements/expression.rs index f9ff66313c..9b86ea41a2 100644 --- a/ast/src/statements/expression.rs +++ b/ast/src/statements/expression.rs @@ -16,7 +16,6 @@ use crate::{Expression, Node, Span}; -use leo_grammar::statements::ExpressionStatement as GrammarExpressionStatement; use serde::{Deserialize, Serialize}; use std::fmt; @@ -32,16 +31,6 @@ impl fmt::Display for ExpressionStatement { } } -impl<'ast> From> for ExpressionStatement { - fn from(statement: GrammarExpressionStatement<'ast>) -> Self { - // why do we have this span-setting logic? - let span = Span::from(statement.span); - let mut expression = Expression::from(statement.expression); - expression.set_span(span.clone()); - ExpressionStatement { expression, span } - } -} - impl Node for ExpressionStatement { fn span(&self) -> &Span { &self.span diff --git a/ast/src/statements/iteration.rs b/ast/src/statements/iteration.rs index 70126ff8ad..a935f959f3 100644 --- a/ast/src/statements/iteration.rs +++ b/ast/src/statements/iteration.rs @@ -16,7 +16,6 @@ use crate::{Block, Expression, Identifier, Node, Span}; -use leo_grammar::statements::ForStatement; use serde::{Deserialize, Serialize}; use std::fmt; @@ -39,18 +38,6 @@ impl fmt::Display for IterationStatement { } } -impl<'ast> From> for IterationStatement { - fn from(statement: ForStatement<'ast>) -> Self { - IterationStatement { - variable: Identifier::from(statement.index), - start: Expression::from(statement.start), - stop: Expression::from(statement.stop), - block: Block::from(statement.block), - span: Span::from(statement.span), - } - } -} - impl Node for IterationStatement { fn span(&self) -> &Span { &self.span diff --git a/ast/src/statements/return_statement.rs b/ast/src/statements/return_statement.rs index e1279b09c2..4e2f813466 100644 --- a/ast/src/statements/return_statement.rs +++ b/ast/src/statements/return_statement.rs @@ -16,7 +16,6 @@ use crate::{Expression, Node, Span}; -use leo_grammar::statements::ReturnStatement as GrammarReturnStatement; use serde::{Deserialize, Serialize}; use std::fmt; @@ -32,15 +31,6 @@ impl fmt::Display for ReturnStatement { } } -impl<'ast> From> for ReturnStatement { - fn from(statement: GrammarReturnStatement<'ast>) -> Self { - ReturnStatement { - expression: Expression::from(statement.expression), - span: Span::from(statement.span), - } - } -} - impl Node for ReturnStatement { fn span(&self) -> &Span { &self.span diff --git a/ast/src/statements/statement.rs b/ast/src/statements/statement.rs index 31067093e7..f60c019edb 100644 --- a/ast/src/statements/statement.rs +++ b/ast/src/statements/statement.rs @@ -16,8 +16,6 @@ use crate::{ConditionalStatement, Node, Span}; -use leo_grammar::statements::Statement as GrammarStatement; - use super::*; use serde::{Deserialize, Serialize}; use std::fmt; @@ -35,21 +33,6 @@ pub enum Statement { Block(Block), } -impl<'ast> From> for Statement { - fn from(statement: GrammarStatement<'ast>) -> Self { - match statement { - GrammarStatement::Return(statement) => Statement::Return(ReturnStatement::from(statement)), - GrammarStatement::Definition(statement) => Statement::Definition(DefinitionStatement::from(statement)), - GrammarStatement::Assign(statement) => Statement::Assign(AssignStatement::from(statement)), - GrammarStatement::Conditional(statement) => Statement::Conditional(ConditionalStatement::from(statement)), - GrammarStatement::Iteration(statement) => Statement::Iteration(IterationStatement::from(statement)), - GrammarStatement::Console(statement) => Statement::Console(ConsoleStatement::from(statement)), - GrammarStatement::Expression(statement) => Statement::Expression(ExpressionStatement::from(statement)), - GrammarStatement::Block(statement) => Statement::Block(Block::from(statement)), - } - } -} - impl fmt::Display for Statement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { diff --git a/ast/src/types/integer_type.rs b/ast/src/types/integer_type.rs index 1ced1e76f7..36cd47d27b 100644 --- a/ast/src/types/integer_type.rs +++ b/ast/src/types/integer_type.rs @@ -14,11 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::types::{ - IntegerType as GrammarIntegerType, - SignedIntegerType as GrammarSignedIntegerType, - UnsignedIntegerType as GrammarUnsignedIntegerType, -}; use leo_input::types::{ IntegerType as InputIntegerType, SignedIntegerType as InputSignedIntegerType, @@ -44,39 +39,6 @@ pub enum IntegerType { I128, } -impl From for IntegerType { - fn from(integer_type: GrammarIntegerType) -> Self { - match integer_type { - GrammarIntegerType::Signed(signed) => Self::from(signed), - GrammarIntegerType::Unsigned(unsigned) => Self::from(unsigned), - } - } -} - -impl From for IntegerType { - fn from(integer_type: GrammarUnsignedIntegerType) -> Self { - match integer_type { - GrammarUnsignedIntegerType::U8Type(_type) => IntegerType::U8, - GrammarUnsignedIntegerType::U16Type(_type) => IntegerType::U16, - GrammarUnsignedIntegerType::U32Type(_type) => IntegerType::U32, - GrammarUnsignedIntegerType::U64Type(_type) => IntegerType::U64, - GrammarUnsignedIntegerType::U128Type(_type) => IntegerType::U128, - } - } -} - -impl From for IntegerType { - fn from(integer_type: GrammarSignedIntegerType) -> Self { - match integer_type { - GrammarSignedIntegerType::I8Type(_type) => IntegerType::I8, - GrammarSignedIntegerType::I16Type(_type) => IntegerType::I16, - GrammarSignedIntegerType::I32Type(_type) => IntegerType::I32, - GrammarSignedIntegerType::I64Type(_type) => IntegerType::I64, - GrammarSignedIntegerType::I128Type(_type) => IntegerType::I128, - } - } -} - impl From for IntegerType { fn from(integer_type: InputIntegerType) -> Self { match integer_type { diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index 1d20699c31..f919ce8df2 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::{ArrayDimensions, Identifier, IntegerType}; -use leo_grammar::types::{ArrayType, CircuitType, DataType, TupleType, Type as GrammarType}; use leo_input::types::{ ArrayType as InputArrayType, DataType as InputDataType, @@ -102,55 +101,6 @@ impl Type { } } -/// pest ast -> Explicit Type for defining circuit members and function params - -impl From for Type { - fn from(data_type: DataType) -> Self { - match data_type { - DataType::Address(_type) => Type::Address, - DataType::Boolean(_type) => Type::Boolean, - DataType::Field(_type) => Type::Field, - DataType::Group(_type) => Type::Group, - DataType::Integer(_type) => Type::IntegerType(IntegerType::from(_type)), - } - } -} - -impl<'ast> From> for Type { - fn from(array_type: ArrayType<'ast>) -> Self { - let element_type = Box::new(Type::from(*array_type.type_)); - let dimensions = ArrayDimensions::from(array_type.dimensions); - - Type::Array(element_type, dimensions) - } -} - -impl<'ast> From> for Type { - fn from(tuple_type: TupleType<'ast>) -> Self { - let types = tuple_type.types.into_iter().map(Type::from).collect(); - - Type::Tuple(types) - } -} - -impl<'ast> From> for Type { - fn from(circuit_type: CircuitType<'ast>) -> Self { - Type::Circuit(Identifier::from(circuit_type.identifier)) - } -} - -impl<'ast> From> for Type { - fn from(type_: GrammarType<'ast>) -> Self { - match type_ { - GrammarType::Basic(type_) => Type::from(type_), - GrammarType::Array(type_) => Type::from(type_), - GrammarType::Tuple(type_) => Type::from(type_), - GrammarType::Circuit(type_) => Type::from(type_), - GrammarType::SelfType(_type) => Type::SelfType, - } - } -} - /// input pest ast -> Explicit Type impl From for Type { diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 6e9b5c71d6..93e7a6a4cc 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -25,10 +25,6 @@ version = "1.2.3" path = "../gadgets" version = "1.2.3" -[dependencies.leo-grammar] -path = "../grammar" -version = "1.2.3" - [dependencies.leo-imports] path = "../imports" version = "1.2.3" @@ -49,6 +45,10 @@ version = "1.2.3" path = "../asg" version = "1.2.3" +[dependencies.leo-parser] +path = "../parser" +version = "1.2.3" + [dependencies.snarkvm-curves] version = "0.0.6" default-features = false @@ -120,4 +120,4 @@ default-features = false [features] default = [ ] -ci_skip = [ "leo-grammar/ci_skip", "leo-ast/ci_skip" ] +ci_skip = [ "leo-ast/ci_skip" ] diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index ee2a11b170..604f82eb4f 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -23,9 +23,9 @@ use crate::{ OutputBytes, OutputFile, }; +use indexmap::IndexMap; use leo_asg::Asg; -use leo_ast::{Ast, Input, MainInput, Program}; -use leo_grammar::Grammar; +use leo_ast::{Input, LeoError, MainInput, Program}; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use leo_state::verify_local_data_commitment; @@ -39,9 +39,11 @@ use snarkvm_models::{ use sha2::{Digest, Sha256}; use std::{ + cell::RefCell, fs, marker::PhantomData, path::{Path, PathBuf}, + rc::Rc, }; pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; @@ -68,6 +70,7 @@ pub struct Compiler<'a, F: PrimeField, G: GroupType> { program_input: Input, context: AsgContext<'a>, asg: Option>, + file_contents: RefCell>>>, _engine: PhantomData, _group: PhantomData, } @@ -90,6 +93,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { program_input: Input::new(), asg: None, context, + file_contents: RefCell::new(IndexMap::new()), _engine: PhantomData, _group: PhantomData, } @@ -156,23 +160,35 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { state_path: &Path, ) -> Result<(), CompilerError> { let input_syntax_tree = LeoInputParser::parse_file(&input_string).map_err(|mut e| { - e.set_path(input_path); + e.set_path( + input_path.to_str().unwrap_or_default(), + &input_string.lines().map(|x| x.to_string()).collect::>()[..], + ); e })?; let state_syntax_tree = LeoInputParser::parse_file(&state_string).map_err(|mut e| { - e.set_path(state_path); + e.set_path( + state_path.to_str().unwrap_or_default(), + &state_string.lines().map(|x| x.to_string()).collect::>()[..], + ); e })?; self.program_input.parse_input(input_syntax_tree).map_err(|mut e| { - e.set_path(input_path); + e.set_path( + input_path.to_str().unwrap_or_default(), + &input_string.lines().map(|x| x.to_string()).collect::>()[..], + ); e })?; self.program_input.parse_state(state_syntax_tree).map_err(|mut e| { - e.set_path(state_path); + e.set_path( + state_path.to_str().unwrap_or_default(), + &state_string.lines().map(|x| x.to_string()).collect::>()[..], + ); e })?; @@ -180,6 +196,20 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { Ok(()) } + fn resolve_content(&self, path: &str) -> Result>, CompilerError> { + let mut file_contents = self.file_contents.borrow_mut(); + if file_contents.contains_key(path) { + // using this pattern because of mutable reference in branch below + Ok(file_contents.get(path).unwrap().clone()) + } else { + let content = fs::read_to_string(path).map_err(|e| CompilerError::FileReadError(PathBuf::from(path), e))?; + + let content = Rc::new(content.lines().map(|x| x.to_string()).collect::>()); + file_contents.insert(path.to_string(), content); + Ok(file_contents.get(path).unwrap().clone()) + } + } + /// /// Parses and stores the main program file, constructs a syntax tree, and generates a program. /// @@ -187,9 +217,10 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { /// pub fn parse_program(&mut self) -> Result<(), CompilerError> { // Load the program file. - let program_string = Grammar::load_file(&self.main_file_path)?; + let content = fs::read_to_string(&self.main_file_path) + .map_err(|e| CompilerError::FileReadError(self.main_file_path.clone(), e))?; - self.parse_program_from_string(&program_string) + self.parse_program_from_string(&content) } /// @@ -197,23 +228,23 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { /// file path. /// pub fn parse_program_from_string(&mut self, program_string: &str) -> Result<(), CompilerError> { - // 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); + // Use the parser to construct the abstract syntax tree (ast). + let lines = program_string.lines().map(|x| x.to_string()).collect(); + self.file_contents.borrow_mut().insert( + self.main_file_path.to_str().map(|x| x.to_string()).unwrap_or_default(), + Rc::new(lines), + ); - e - })?; - - // Construct the AST from the grammar. - let core_ast = Ast::new(&self.program_name, &grammar)?; + let ast = leo_parser::parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?; // Store the main program file. - self.program = core_ast.as_repr().clone(); + self.program = ast.into_repr(); + self.program.name = self.program_name.clone(); tracing::debug!("Program parsing complete\n{:#?}", self.program); // Create a new symbol table from the program, imported_programs, and program_input. - let asg = Asg::new(self.context, &core_ast, &mut leo_imports::ImportParser::default())?; + let asg = Asg::new(self.context, &self.program, &mut leo_imports::ImportParser::default())?; tracing::debug!("ASG generation complete"); @@ -228,7 +259,13 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { /// 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); + if let Some(path) = error.get_path().map(|x| x.to_string()) { + let content = match self.resolve_content(&path) { + Err(e) => return e, + Ok(x) => x, + }; + error.set_path(&path, &content[..]); + } error }) } @@ -251,7 +288,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { pub fn checksum(&self) -> Result { // Read in the main file as string let unparsed_file = fs::read_to_string(&self.main_file_path) - .map_err(|_| CompilerError::FileReadError(self.main_file_path.clone()))?; + .map_err(|e| CompilerError::FileReadError(self.main_file_path.clone(), e))?; // Hash the file contents let mut hasher = Sha256::new(); diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index 9d47cd5afa..80a56339c3 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -51,16 +51,13 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let result_option = match assert_expression { ConstrainedValue::Boolean(boolean) => boolean.get_value(), _ => { - return Err(ConsoleError::assertion_must_be_boolean( - span.text.clone(), - span.to_owned(), - )); + return Err(ConsoleError::assertion_must_be_boolean(span)); } }; - let result_bool = result_option.ok_or_else(|| ConsoleError::assertion_depends_on_input(span.to_owned()))?; + let result_bool = result_option.ok_or_else(|| ConsoleError::assertion_depends_on_input(span))?; if !result_bool { - return Err(ConsoleError::assertion_failed(span.text.clone(), span.to_owned())); + return Err(ConsoleError::assertion_failed(span)); } Ok(()) diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index 048303a023..5606a6e7c0 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -19,6 +19,7 @@ use crate::{errors::ConsoleError, program::ConstrainedProgram, GroupType}; use leo_asg::FormattedString; +use leo_ast::FormattedStringPart; use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { @@ -28,30 +29,33 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { formatted: &FormattedString<'a>, ) -> Result { // Check that containers and parameters match - if formatted.containers.len() != formatted.parameters.len() { + let container_count = formatted + .parts + .iter() + .filter(|x| matches!(x, FormattedStringPart::Container)) + .count(); + if container_count != formatted.parameters.len() { return Err(ConsoleError::length( - formatted.containers.len(), + container_count, formatted.parameters.len(), - formatted.span.clone(), + &formatted.span, )); } - // Trim starting double quote `"` - let mut string = formatted.string.as_str(); - string = string.trim_start_matches('\"'); - - // Trim everything after the ending double quote `"` - let string = string.split('\"').next().unwrap(); - - // Insert the parameter for each container `{}` - let mut result = string.to_string(); - + let mut executed_containers = Vec::with_capacity(formatted.parameters.len()); for parameter in formatted.parameters.iter() { - let parameter_value = self.enforce_expression(cs, parameter.get())?; - - result = result.replacen("{}", ¶meter_value.to_string(), 1); + executed_containers.push(self.enforce_expression(cs, parameter.get())?.to_string()); } - Ok(result) + let mut out = vec![]; + let mut parameters = executed_containers.iter(); + for part in formatted.parts.iter() { + match part { + FormattedStringPart::Const(c) => out.push(&**c), + FormattedStringPart::Container => out.push(&**parameters.next().unwrap()), + } + } + + Ok(out.join("")) } } diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 412d8e30cc..8fb7921b7c 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -18,7 +18,7 @@ use crate::{errors::CompilerError, ConstrainedProgram, GroupType, OutputBytes, OutputFile}; use leo_asg::Asg; -use leo_ast::Input; +use leo_ast::{Input, LeoError}; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; @@ -63,22 +63,33 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType>( // Get default input let default = input.pairs.get(&program_name); - let tests = &program.test_functions; + let tests = program + .functions + .iter() + .filter(|(_name, func)| func.is_test()) + .collect::>(); tracing::info!("Running {} tests", tests.len()); // Count passed and failed tests let mut passed = 0; let mut failed = 0; - for (test_name, (function, input_file)) in tests.into_iter() { + for (test_name, function) in tests.into_iter() { let cs = &mut TestConstraintSystem::::new(); let full_test_name = format!("{}::{}", program_name.clone(), test_name); let mut output_file_name = program_name.clone(); + let input_file = function + .annotations + .iter() + .find(|x| x.name.name == "test") + .unwrap() + .arguments + .get(0); // get input file name from annotation or use test_name let input_pair = match input_file { Some(file_id) => { - let file_name = file_id.name.clone(); + let file_name = file_id.clone(); output_file_name = file_name.clone(); @@ -129,7 +140,7 @@ pub fn generate_test_constraints<'a, F: PrimeField, G: GroupType>( (false, _) => { // Set file location of error let mut error = result.unwrap_err(); - error.set_path(main_file_path); + error.set_path(main_file_path.to_str().unwrap_or_default(), &[]); tracing::error!("{} failed due to error\n\n{}\n", full_test_name, error); diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index c8e7b496a9..23a99a96f2 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -16,19 +16,19 @@ use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; use leo_asg::AsgConvertError; -use leo_ast::AstError; -use leo_grammar::ParserError; +use leo_ast::LeoError; use leo_imports::ImportParserError; use leo_input::InputParserError; +use leo_parser::SyntaxError; use leo_state::LocalDataVerificationError; use bincode::Error as SerdeError; -use std::path::{Path, PathBuf}; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum CompilerError { #[error("{}", _0)] - AstError(#[from] AstError), + SyntaxError(#[from] SyntaxError), #[error("{}", _0)] ImportError(#[from] ImportError), @@ -45,8 +45,8 @@ pub enum CompilerError { #[error("{}", _0)] FunctionError(#[from] FunctionError), - #[error("Cannot read from the provided file path - {:?}", _0)] - FileReadError(PathBuf), + #[error("Cannot read from the provided file path '{:?}': {}", _0, _1)] + FileReadError(PathBuf, std::io::Error), #[error("{}", _0)] LocalDataVerificationError(#[from] LocalDataVerificationError), @@ -66,9 +66,6 @@ pub enum CompilerError { #[error("{}", _0)] OutputStringError(#[from] OutputBytesError), - #[error("{}", _0)] - ParserError(#[from] ParserError), - #[error("{}", _0)] SerdeError(#[from] SerdeError), @@ -76,12 +73,29 @@ pub enum CompilerError { AsgConvertError(#[from] AsgConvertError), } -impl CompilerError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for CompilerError { + fn get_path(&self) -> Option<&str> { match self { - CompilerError::InputParserError(error) => error.set_path(path), - CompilerError::FunctionError(error) => error.set_path(path), - CompilerError::OutputStringError(error) => error.set_path(path), + CompilerError::SyntaxError(error) => error.get_path(), + CompilerError::ImportError(error) => error.get_path(), + CompilerError::ImportParserError(error) => error.get_path(), + CompilerError::InputParserError(error) => error.get_path(), + CompilerError::FunctionError(error) => error.get_path(), + CompilerError::OutputStringError(error) => error.get_path(), + CompilerError::AsgConvertError(error) => error.get_path(), + _ => None, + } + } + + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + CompilerError::SyntaxError(error) => error.set_path(path, contents), + CompilerError::ImportError(error) => error.set_path(path, contents), + CompilerError::ImportParserError(error) => error.set_path(path, contents), + CompilerError::InputParserError(error) => error.set_path(path, contents), + CompilerError::FunctionError(error) => error.set_path(path, contents), + CompilerError::OutputStringError(error) => error.set_path(path, contents), + CompilerError::AsgConvertError(error) => error.set_path(path, contents), _ => {} } } diff --git a/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index c68a0035dd..b6862c12a8 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -15,9 +15,7 @@ // along with the Leo library. If not, see . use crate::errors::ExpressionError; -use leo_ast::{Error as FormattedError, Span}; - -use std::path::Path; +use leo_ast::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum ConsoleError { @@ -28,19 +26,28 @@ pub enum ConsoleError { Expression(#[from] ExpressionError), } -impl ConsoleError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for ConsoleError { + fn get_path(&self) -> Option<&str> { match self { - ConsoleError::Expression(error) => error.set_path(path), - ConsoleError::Error(error) => error.set_path(path), + ConsoleError::Error(error) => error.get_path(), + ConsoleError::Expression(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + ConsoleError::Error(error) => error.set_path(path, contents), + ConsoleError::Expression(error) => error.set_path(path, contents), + } + } +} + +impl ConsoleError { + fn new_from_span(message: String, span: &Span) -> Self { ConsoleError::Error(FormattedError::new_from_span(message, span)) } - pub fn length(containers: usize, parameters: usize, span: Span) -> Self { + pub fn length(containers: usize, parameters: usize, span: &Span) -> Self { let message = format!( "Formatter given {} containers and found {} parameters", containers, parameters @@ -49,21 +56,21 @@ impl ConsoleError { Self::new_from_span(message, span) } - pub fn assertion_depends_on_input(span: Span) -> Self { + pub fn assertion_depends_on_input(span: &Span) -> Self { let message = "console.assert() failed to evaluate. This error is caused by empty input file values".to_string(); Self::new_from_span(message, span) } - pub fn assertion_failed(expression: String, span: Span) -> Self { - let message = format!("Assertion `{}` failed", expression); + pub fn assertion_failed(span: &Span) -> Self { + let message = "Assertion failed".to_string(); Self::new_from_span(message, span) } - pub fn assertion_must_be_boolean(expression: String, span: Span) -> Self { - let message = format!("Assertion expression `{}` must evaluate to a boolean value", expression); + pub fn assertion_must_be_boolean(span: &Span) -> Self { + let message = "Assertion expression must evaluate to a boolean value".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index 38d17fe2e3..ba396f6460 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -15,10 +15,9 @@ // along with the Leo library. If not, see . use crate::errors::{AddressError, BooleanError, FieldError, FunctionError, GroupError, IntegerError, ValueError}; -use leo_ast::{ArrayDimensions, Error as FormattedError, Identifier, PositiveNumber, Span}; +use leo_ast::{ArrayDimensions, FormattedError, Identifier, LeoError, PositiveNumber, Span}; use snarkvm_errors::gadgets::SynthesisError; -use std::path::Path; #[derive(Debug, Error)] pub enum ExpressionError { @@ -47,25 +46,40 @@ pub enum ExpressionError { ValueError(#[from] ValueError), } -impl ExpressionError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for ExpressionError { + fn get_path(&self) -> Option<&str> { match self { - ExpressionError::AddressError(error) => error.set_path(path), - ExpressionError::BooleanError(error) => error.set_path(path), - ExpressionError::Error(error) => error.set_path(path), - ExpressionError::FieldError(error) => error.set_path(path), - ExpressionError::FunctionError(error) => error.set_path(path), - ExpressionError::GroupError(error) => error.set_path(path), - ExpressionError::IntegerError(error) => error.set_path(path), - ExpressionError::ValueError(error) => error.set_path(path), + ExpressionError::AddressError(error) => error.get_path(), + ExpressionError::BooleanError(error) => error.get_path(), + ExpressionError::Error(error) => error.get_path(), + ExpressionError::FieldError(error) => error.get_path(), + ExpressionError::FunctionError(error) => error.get_path(), + ExpressionError::GroupError(error) => error.get_path(), + ExpressionError::IntegerError(error) => error.get_path(), + ExpressionError::ValueError(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + ExpressionError::AddressError(error) => error.set_path(path, contents), + ExpressionError::BooleanError(error) => error.set_path(path, contents), + ExpressionError::Error(error) => error.set_path(path, contents), + ExpressionError::FieldError(error) => error.set_path(path, contents), + ExpressionError::FunctionError(error) => error.set_path(path, contents), + ExpressionError::GroupError(error) => error.set_path(path, contents), + ExpressionError::IntegerError(error) => error.set_path(path, contents), + ExpressionError::ValueError(error) => error.set_path(path, contents), + } + } +} + +impl ExpressionError { + fn new_from_span(message: String, span: &Span) -> Self { ExpressionError::Error(FormattedError::new_from_span(message, span)) } - pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { + pub fn cannot_enforce(operation: String, error: SynthesisError, span: &Span) -> Self { let message = format!( "the gadget operation `{}` failed due to synthesis error `{:?}`", operation, error, @@ -74,37 +88,37 @@ impl ExpressionError { Self::new_from_span(message, span) } - pub fn cannot_evaluate(operation: String, span: Span) -> Self { + pub fn cannot_evaluate(operation: String, span: &Span) -> Self { let message = format!("Mismatched types found for operation `{}`", operation); Self::new_from_span(message, span) } - pub fn conditional_boolean(actual: String, span: Span) -> Self { + pub fn conditional_boolean(actual: String, span: &Span) -> Self { let message = format!("if, else conditional must resolve to a boolean, found `{}`", actual); Self::new_from_span(message, span) } - pub fn expected_circuit_member(expected: String, span: Span) -> Self { + pub fn expected_circuit_member(expected: String, span: &Span) -> Self { let message = format!("expected circuit member `{}`, not found", expected); Self::new_from_span(message, span) } - pub fn incompatible_types(operation: String, span: Span) -> Self { + pub fn incompatible_types(operation: String, span: &Span) -> Self { let message = format!("no implementation for `{}`", operation); Self::new_from_span(message, span) } - pub fn index_out_of_bounds(index: usize, span: Span) -> Self { + pub fn index_out_of_bounds(index: usize, span: &Span) -> Self { let message = format!("cannot access index {} of tuple out of bounds", index); Self::new_from_span(message, span) } - pub fn invalid_dimensions(expected: &ArrayDimensions, actual: &ArrayDimensions, span: Span) -> Self { + pub fn invalid_dimensions(expected: &ArrayDimensions, actual: &ArrayDimensions, span: &Span) -> Self { let message = format!( "expected array dimensions {}, found array dimensions {}", expected, actual @@ -113,7 +127,7 @@ impl ExpressionError { Self::new_from_span(message, span) } - pub fn invalid_first_dimension(expected: &PositiveNumber, actual: &PositiveNumber, span: Span) -> Self { + pub fn invalid_first_dimension(expected: &PositiveNumber, actual: &PositiveNumber, span: &Span) -> Self { let message = format!( "expected array dimension {}, found array dimension {}", expected, actual @@ -125,58 +139,58 @@ impl ExpressionError { pub fn invalid_index(actual: String, span: &Span) -> Self { let message = format!("index must resolve to an integer, found `{}`", actual); - Self::new_from_span(message, span.to_owned()) + Self::new_from_span(message, span) } - pub fn invalid_length(expected: usize, actual: usize, span: Span) -> Self { + pub fn invalid_length(expected: usize, actual: usize, span: &Span) -> Self { let message = format!("expected array length {}, found one with length {}", expected, actual); Self::new_from_span(message, span) } - pub fn invalid_spread(actual: String, span: Span) -> Self { + pub fn invalid_spread(actual: String, span: &Span) -> Self { let message = format!("spread should contain an array, found `{}`", actual); Self::new_from_span(message, span) } - pub fn invalid_member_access(member: String, span: Span) -> Self { + pub fn invalid_member_access(member: String, span: &Span) -> Self { let message = format!("non-static member `{}` must be accessed using `.` syntax", member); Self::new_from_span(message, span) } - pub fn invalid_static_access(member: String, span: Span) -> Self { + pub fn invalid_static_access(member: String, span: &Span) -> Self { let message = format!("static member `{}` must be accessed using `::` syntax", member); Self::new_from_span(message, span) } - pub fn function_no_return(function: String, span: Span) -> Self { + pub fn function_no_return(function: String, span: &Span) -> Self { let message = format!("inline function call to `{}` did not return", function); Self::new_from_span(message, span) } - pub fn self_keyword(span: Span) -> Self { + pub fn self_keyword(span: &Span) -> Self { let message = "cannot call keyword `Self` outside of a circuit function".to_string(); Self::new_from_span(message, span) } - pub fn undefined_array(actual: String, span: Span) -> Self { + pub fn undefined_array(actual: String, span: &Span) -> Self { let message = format!("array `{}` must be declared before it is used in an expression", actual); Self::new_from_span(message, span) } - pub fn undefined_tuple(actual: String, span: Span) -> Self { + pub fn undefined_tuple(actual: String, span: &Span) -> Self { let message = format!("tuple `{}` must be declared before it is used in an expression", actual); Self::new_from_span(message, span) } - pub fn undefined_circuit(actual: String, span: Span) -> Self { + pub fn undefined_circuit(actual: String, span: &Span) -> Self { let message = format!( "circuit `{}` must be declared before it is used in an expression", actual @@ -185,13 +199,13 @@ impl ExpressionError { Self::new_from_span(message, span) } - pub fn undefined_first_dimension(span: Span) -> Self { + pub fn undefined_first_dimension(span: &Span) -> Self { let message = "the first dimension of the array must be a number".to_string(); Self::new_from_span(message, span) } - pub fn undefined_function(function: String, span: Span) -> Self { + pub fn undefined_function(function: String, span: &Span) -> Self { let message = format!( "function `{}` must be declared before it is used in an inline expression", function @@ -203,28 +217,28 @@ impl ExpressionError { pub fn undefined_identifier(identifier: Identifier) -> Self { let message = format!("Cannot find value `{}` in this scope", identifier.name); - Self::new_from_span(message, identifier.span) + Self::new_from_span(message, &identifier.span) } - pub fn undefined_member_access(circuit: String, member: String, span: Span) -> Self { + pub fn undefined_member_access(circuit: String, member: String, span: &Span) -> Self { let message = format!("Circuit `{}` has no member `{}`", circuit, member); Self::new_from_span(message, span) } - pub fn undefined_static_access(circuit: String, member: String, span: Span) -> Self { + pub fn undefined_static_access(circuit: String, member: String, span: &Span) -> Self { let message = format!("Circuit `{}` has no static member `{}`", circuit, member); Self::new_from_span(message, span) } - pub fn unexpected_array(expected: String, span: Span) -> Self { + pub fn unexpected_array(expected: String, span: &Span) -> Self { let message = format!("expected type `{}`, found array with elements", expected); Self::new_from_span(message, span) } - pub fn unexpected_tuple(expected: String, actual: String, span: Span) -> Self { + pub fn unexpected_tuple(expected: String, actual: String, span: &Span) -> Self { let message = format!("expected type `{}`, found tuple with values `{}`", expected, actual); Self::new_from_span(message, span) diff --git a/compiler/src/errors/function.rs b/compiler/src/errors/function.rs index 5422761581..43a2179365 100644 --- a/compiler/src/errors/function.rs +++ b/compiler/src/errors/function.rs @@ -26,9 +26,7 @@ use crate::errors::{ ValueError, }; use leo_asg::AsgConvertError; -use leo_ast::{Error as FormattedError, Span}; - -use std::path::Path; +use leo_ast::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum FunctionError { @@ -66,34 +64,52 @@ pub enum FunctionError { ImportASGError(#[from] AsgConvertError), } -impl FunctionError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for FunctionError { + fn get_path(&self) -> Option<&str> { match self { - FunctionError::AddressError(error) => error.set_path(path), - FunctionError::BooleanError(error) => error.set_path(path), - FunctionError::ExpressionError(error) => error.set_path(path), - FunctionError::Error(error) => error.set_path(path), - FunctionError::FieldError(error) => error.set_path(path), - FunctionError::GroupError(error) => error.set_path(path), - FunctionError::IntegerError(error) => error.set_path(path), - FunctionError::OutputStringError(error) => error.set_path(path), - FunctionError::StatementError(error) => error.set_path(path), - FunctionError::ValueError(error) => error.set_path(path), - FunctionError::ImportASGError(_error) => (), + FunctionError::AddressError(error) => error.get_path(), + FunctionError::BooleanError(error) => error.get_path(), + FunctionError::ExpressionError(error) => error.get_path(), + FunctionError::Error(error) => error.get_path(), + FunctionError::FieldError(error) => error.get_path(), + FunctionError::GroupError(error) => error.get_path(), + FunctionError::IntegerError(error) => error.get_path(), + FunctionError::OutputStringError(error) => error.get_path(), + FunctionError::StatementError(error) => error.get_path(), + FunctionError::ValueError(error) => error.get_path(), + FunctionError::ImportASGError(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + FunctionError::AddressError(error) => error.set_path(path, contents), + FunctionError::BooleanError(error) => error.set_path(path, contents), + FunctionError::ExpressionError(error) => error.set_path(path, contents), + FunctionError::Error(error) => error.set_path(path, contents), + FunctionError::FieldError(error) => error.set_path(path, contents), + FunctionError::GroupError(error) => error.set_path(path, contents), + FunctionError::IntegerError(error) => error.set_path(path, contents), + FunctionError::OutputStringError(error) => error.set_path(path, contents), + FunctionError::StatementError(error) => error.set_path(path, contents), + FunctionError::ValueError(error) => error.set_path(path, contents), + FunctionError::ImportASGError(error) => error.set_path(path, contents), + } + } +} + +impl FunctionError { + fn new_from_span(message: String, span: &Span) -> Self { FunctionError::Error(FormattedError::new_from_span(message, span)) } - pub fn invalid_array(actual: String, span: Span) -> Self { + pub fn invalid_array(actual: String, span: &Span) -> Self { let message = format!("Expected function input array, found `{}`", actual); Self::new_from_span(message, span) } - pub fn invalid_input_array_dimensions(expected: usize, actual: usize, span: Span) -> Self { + pub fn invalid_input_array_dimensions(expected: usize, actual: usize, span: &Span) -> Self { let message = format!( "Input array dimensions mismatch expected {}, found array dimensions {}", expected, actual @@ -102,25 +118,25 @@ impl FunctionError { Self::new_from_span(message, span) } - pub fn invalid_tuple(actual: String, span: Span) -> Self { + pub fn invalid_tuple(actual: String, span: &Span) -> Self { let message = format!("Expected function input tuple, found `{}`", actual); Self::new_from_span(message, span) } - pub fn return_arguments_length(expected: usize, actual: usize, span: Span) -> Self { + pub fn return_arguments_length(expected: usize, actual: usize, span: &Span) -> Self { let message = format!("function expected {} returns, found {} returns", expected, actual); Self::new_from_span(message, span) } - pub fn return_argument_type(expected: String, actual: String, span: Span) -> Self { + pub fn return_argument_type(expected: String, actual: String, span: &Span) -> Self { let message = format!("Expected function return type `{}`, found `{}`", expected, actual); Self::new_from_span(message, span) } - pub fn input_not_found(expected: String, span: Span) -> Self { + pub fn input_not_found(expected: String, span: &Span) -> Self { let message = format!("main function input {} not found", expected); Self::new_from_span(message, span) diff --git a/compiler/src/errors/import.rs b/compiler/src/errors/import.rs index 74ee48cc83..a61b41000f 100644 --- a/compiler/src/errors/import.rs +++ b/compiler/src/errors/import.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 leo_ast::{Error as FormattedError, Identifier, ImportSymbol, Span}; +use leo_ast::{FormattedError, Identifier, ImportSymbol, LeoError, Span}; #[derive(Debug, Error)] pub enum ImportError { @@ -22,8 +22,22 @@ pub enum ImportError { Error(#[from] FormattedError), } +impl LeoError for ImportError { + fn get_path(&self) -> Option<&str> { + match self { + ImportError::Error(error) => error.get_path(), + } + } + + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + ImportError::Error(error) => error.set_path(path, contents), + } + } +} + impl ImportError { - fn new_from_span(message: String, span: Span) -> Self { + fn new_from_span(message: String, span: &Span) -> Self { ImportError::Error(FormattedError::new_from_span(message, span)) } @@ -33,12 +47,12 @@ impl ImportError { identifier.name ); - Self::new_from_span(message, identifier.span) + Self::new_from_span(message, &identifier.span) } pub fn unknown_symbol(symbol: ImportSymbol, file: String) -> Self { let message = format!("cannot find imported symbol `{}` in imported file `{}`", symbol, file); - let error = FormattedError::new_from_span(message, symbol.span); + let error = FormattedError::new_from_span(message, &symbol.span); ImportError::Error(error) } diff --git a/compiler/src/errors/output_bytes.rs b/compiler/src/errors/output_bytes.rs index 71649b0910..0dd08b026b 100644 --- a/compiler/src/errors/output_bytes.rs +++ b/compiler/src/errors/output_bytes.rs @@ -16,9 +16,7 @@ use crate::errors::ValueError; use leo_asg::{AsgConvertError, Type}; -use leo_ast::{Error as FormattedError, Span}; - -use std::path::Path; +use leo_ast::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum OutputBytesError { @@ -32,26 +30,36 @@ pub enum OutputBytesError { AsgConvertError(#[from] AsgConvertError), } -impl OutputBytesError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for OutputBytesError { + fn get_path(&self) -> Option<&str> { match self { - OutputBytesError::Error(error) => error.set_path(path), - OutputBytesError::ValueError(error) => error.set_path(path), - OutputBytesError::AsgConvertError(_error) => (), + OutputBytesError::Error(error) => error.get_path(), + OutputBytesError::ValueError(error) => error.get_path(), + OutputBytesError::AsgConvertError(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + OutputBytesError::Error(error) => error.set_path(path, contents), + OutputBytesError::ValueError(error) => error.set_path(path, contents), + OutputBytesError::AsgConvertError(error) => error.set_path(path, contents), + } + } +} + +impl OutputBytesError { + fn new_from_span(message: String, span: &Span) -> Self { OutputBytesError::Error(FormattedError::new_from_span(message, span)) } - pub fn not_enough_registers(span: Span) -> Self { + pub fn not_enough_registers(span: &Span) -> Self { let message = "number of input registers must be greater than or equal to output registers".to_string(); Self::new_from_span(message, span) } - pub fn mismatched_output_types(left: &Type, right: &Type, span: Span) -> Self { + pub fn mismatched_output_types(left: &Type, right: &Type, span: &Span) -> Self { let message = format!( "Mismatched types. Expected register output type `{}`, found type `{}`.", left, right diff --git a/compiler/src/errors/statement.rs b/compiler/src/errors/statement.rs index d915d40dff..4255d273ad 100644 --- a/compiler/src/errors/statement.rs +++ b/compiler/src/errors/statement.rs @@ -16,9 +16,7 @@ use crate::errors::{AddressError, BooleanError, ConsoleError, ExpressionError, IntegerError, ValueError}; use leo_asg::Type; -use leo_ast::{Error as FormattedError, Span}; - -use std::path::Path; +use leo_ast::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum StatementError { @@ -44,48 +42,62 @@ pub enum StatementError { ValueError(#[from] ValueError), } -impl StatementError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for StatementError { + fn get_path(&self) -> Option<&str> { match self { - StatementError::AddressError(error) => error.set_path(path), - StatementError::BooleanError(error) => error.set_path(path), - StatementError::Error(error) => error.set_path(path), - StatementError::ExpressionError(error) => error.set_path(path), - StatementError::IntegerError(error) => error.set_path(path), - StatementError::MacroError(error) => error.set_path(path), - StatementError::ValueError(error) => error.set_path(path), + StatementError::AddressError(error) => error.get_path(), + StatementError::BooleanError(error) => error.get_path(), + StatementError::Error(error) => error.get_path(), + StatementError::ExpressionError(error) => error.get_path(), + StatementError::IntegerError(error) => error.get_path(), + StatementError::MacroError(error) => error.get_path(), + StatementError::ValueError(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + StatementError::AddressError(error) => error.set_path(path, contents), + StatementError::BooleanError(error) => error.set_path(path, contents), + StatementError::Error(error) => error.set_path(path, contents), + StatementError::ExpressionError(error) => error.set_path(path, contents), + StatementError::IntegerError(error) => error.set_path(path, contents), + StatementError::MacroError(error) => error.set_path(path, contents), + StatementError::ValueError(error) => error.set_path(path, contents), + } + } +} + +impl StatementError { + fn new_from_span(message: String, span: &Span) -> Self { StatementError::Error(FormattedError::new_from_span(message, span)) } - pub fn arguments_type(expected: &Type, actual: &Type, span: Span) -> Self { + pub fn arguments_type(expected: &Type, actual: &Type, span: &Span) -> Self { let message = format!("expected return argument type `{}`, found type `{}`", expected, actual); Self::new_from_span(message, span) } - pub fn array_assign_index(span: Span) -> Self { + pub fn array_assign_index(span: &Span) -> Self { let message = "Cannot assign single index to array of values".to_string(); Self::new_from_span(message, span) } - pub fn array_assign_interior_index(span: Span) -> Self { + pub fn array_assign_interior_index(span: &Span) -> Self { let message = "Cannot assign single index to interior of array of values".to_string(); Self::new_from_span(message, span) } - pub fn array_assign_range(span: Span) -> Self { + pub fn array_assign_range(span: &Span) -> Self { let message = "Cannot assign range of array values to single value".to_string(); Self::new_from_span(message, span) } - pub fn array_assign_index_bounds(index: usize, length: usize, span: Span) -> Self { + pub fn array_assign_index_bounds(index: usize, length: usize, span: &Span) -> Self { let message = format!( "Array assign index `{}` out of range for array of length `{}`", index, length @@ -94,7 +106,7 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn array_assign_range_order(start: usize, stop: usize, length: usize, span: Span) -> Self { + pub fn array_assign_range_order(start: usize, stop: usize, length: usize, span: &Span) -> Self { let message = format!( "Array assign range `{}`..`{}` out of range for array of length `{}`", start, stop, length @@ -103,31 +115,31 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn conditional_boolean(actual: String, span: Span) -> Self { + pub fn conditional_boolean(actual: String, span: &Span) -> Self { let message = format!("If, else conditional must resolve to a boolean, found `{}`", actual); Self::new_from_span(message, span) } - pub fn immutable_assign(name: String, span: Span) -> Self { + pub fn immutable_assign(name: String, span: &Span) -> Self { let message = format!("Cannot assign to immutable variable `{}`", name); Self::new_from_span(message, span) } - pub fn immutable_circuit_function(name: String, span: Span) -> Self { + pub fn immutable_circuit_function(name: String, span: &Span) -> Self { let message = format!("Cannot mutate circuit function, `{}`", name); Self::new_from_span(message, span) } - pub fn immutable_circuit_variable(name: String, span: Span) -> Self { + pub fn immutable_circuit_variable(name: String, span: &Span) -> Self { let message = format!("Circuit member variable `{}` is immutable", name); Self::new_from_span(message, span) } - pub fn indicator_calculation(name: String, span: Span) -> Self { + pub fn indicator_calculation(name: String, span: &Span) -> Self { let message = format!( "Constraint system failed to evaluate branch selection indicator `{}`", name @@ -136,7 +148,7 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn invalid_number_of_definitions(expected: usize, actual: usize, span: Span) -> Self { + pub fn invalid_number_of_definitions(expected: usize, actual: usize, span: &Span) -> Self { let message = format!( "Multiple definition statement expected {} return values, found {} values", expected, actual @@ -145,7 +157,7 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn invalid_number_of_returns(expected: usize, actual: usize, span: Span) -> Self { + pub fn invalid_number_of_returns(expected: usize, actual: usize, span: &Span) -> Self { let message = format!( "Function return statement expected {} return values, found {} values", expected, actual @@ -154,20 +166,20 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn multiple_definition(value: String, span: Span) -> Self { + pub fn multiple_definition(value: String, span: &Span) -> Self { let message = format!("cannot assign multiple variables to a single value: {}", value,); Self::new_from_span(message, span) } - pub fn multiple_returns(span: Span) -> Self { + pub fn multiple_returns(span: &Span) -> Self { let message = "This function returns multiple times and produces unreachable circuits with undefined behavior." .to_string(); Self::new_from_span(message, span) } - pub fn no_returns(expected: &Type, span: Span) -> Self { + pub fn no_returns(expected: &Type, span: &Span) -> Self { let message = format!( "function expected `{}` return type but no valid branches returned a result", expected @@ -176,7 +188,7 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn select_fail(first: String, second: String, span: Span) -> Self { + pub fn select_fail(first: String, second: String, span: &Span) -> Self { let message = format!( "Conditional select gadget failed to select between `{}` or `{}`", first, second @@ -185,13 +197,13 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn tuple_assign_index(span: Span) -> Self { + pub fn tuple_assign_index(span: &Span) -> Self { let message = "Cannot assign single index to tuple of values".to_string(); Self::new_from_span(message, span) } - pub fn tuple_assign_index_bounds(index: usize, length: usize, span: Span) -> Self { + pub fn tuple_assign_index_bounds(index: usize, length: usize, span: &Span) -> Self { let message = format!( "Tuple assign index `{}` out of range for tuple of length `{}`", index, length @@ -200,31 +212,31 @@ impl StatementError { Self::new_from_span(message, span) } - pub fn tuple_type(type_: String, span: Span) -> Self { + pub fn tuple_type(type_: String, span: &Span) -> Self { let message = format!("Expected tuple type, found type `{}`", type_); Self::new_from_span(message, span) } - pub fn unassigned(name: String, span: Span) -> Self { - let message = format!("Expected assignment of return values for expression `{}`", name); + pub fn unassigned(span: &Span) -> Self { + let message = "Expected assignment of return values for expression".to_string(); Self::new_from_span(message, span) } - pub fn undefined_variable(name: String, span: Span) -> Self { + pub fn undefined_variable(name: String, span: &Span) -> Self { let message = format!("Attempted to assign to unknown variable `{}`", name); Self::new_from_span(message, span) } - pub fn undefined_circuit(name: String, span: Span) -> Self { + pub fn undefined_circuit(name: String, span: &Span) -> Self { let message = format!("Attempted to assign to unknown circuit `{}`", name); Self::new_from_span(message, span) } - pub fn undefined_circuit_variable(name: String, span: Span) -> Self { + pub fn undefined_circuit_variable(name: String, span: &Span) -> Self { let message = format!("Attempted to assign to unknown circuit member variable `{}`", name); Self::new_from_span(message, span) diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index aa5c769ffb..8a894d963f 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::{FormattedError, LeoError, Span}; use snarkvm_errors::{gadgets::SynthesisError, objects::account::AccountError}; -use std::path::Path; #[derive(Debug, Error)] pub enum AddressError { @@ -25,24 +24,32 @@ pub enum AddressError { Error(#[from] FormattedError), } -impl AddressError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for AddressError { + fn get_path(&self) -> Option<&str> { match self { - AddressError::Error(error) => error.set_path(path), + AddressError::Error(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + AddressError::Error(error) => error.set_path(path, contents), + } + } +} + +impl AddressError { + fn new_from_span(message: String, span: &Span) -> Self { AddressError::Error(FormattedError::new_from_span(message, span)) } - pub fn account_error(error: AccountError, span: Span) -> Self { + pub fn account_error(error: AccountError, span: &Span) -> Self { let message = format!("account creation failed due to `{}`", error); Self::new_from_span(message, span) } - pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { + pub fn cannot_enforce(operation: String, error: SynthesisError, span: &Span) -> Self { let message = format!( "the address operation `{:?}` failed due to the synthesis error `{}`", operation, error, @@ -51,19 +58,19 @@ impl AddressError { Self::new_from_span(message, span) } - pub fn cannot_evaluate(operation: String, span: Span) -> Self { + pub fn cannot_evaluate(operation: String, span: &Span) -> Self { let message = format!("no implementation found for `{}`", operation); Self::new_from_span(message, span) } - pub fn invalid_address(actual: String, span: Span) -> Self { + pub fn invalid_address(actual: String, span: &Span) -> Self { let message = format!("expected address input type, found `{}`", actual); Self::new_from_span(message, span) } - pub fn missing_address(span: Span) -> Self { + pub fn missing_address(span: &Span) -> Self { let message = "expected address input not found".to_string(); Self::new_from_span(message, span) diff --git a/compiler/src/errors/value/boolean.rs b/compiler/src/errors/value/boolean.rs index fd0a5d8470..5050184842 100644 --- a/compiler/src/errors/value/boolean.rs +++ b/compiler/src/errors/value/boolean.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::{FormattedError, LeoError, Span}; use snarkvm_errors::gadgets::SynthesisError; -use std::path::Path; #[derive(Debug, Error)] pub enum BooleanError { @@ -25,18 +24,26 @@ pub enum BooleanError { Error(#[from] FormattedError), } -impl BooleanError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for BooleanError { + fn get_path(&self) -> Option<&str> { match self { - BooleanError::Error(error) => error.set_path(path), + BooleanError::Error(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + BooleanError::Error(error) => error.set_path(path, contents), + } + } +} + +impl BooleanError { + fn new_from_span(message: String, span: &Span) -> Self { BooleanError::Error(FormattedError::new_from_span(message, span)) } - pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { + pub fn cannot_enforce(operation: String, error: SynthesisError, span: &Span) -> Self { let message = format!( "the boolean operation `{}` failed due to the synthesis error `{:?}`", operation, error, @@ -45,19 +52,19 @@ impl BooleanError { Self::new_from_span(message, span) } - pub fn cannot_evaluate(operation: String, span: Span) -> Self { + pub fn cannot_evaluate(operation: String, span: &Span) -> Self { let message = format!("no implementation found for `{}`", operation); Self::new_from_span(message, span) } - pub fn invalid_boolean(actual: String, span: Span) -> Self { + pub fn invalid_boolean(actual: String, span: &Span) -> Self { let message = format!("expected boolean input type, found `{}`", actual); Self::new_from_span(message, span) } - pub fn missing_boolean(expected: String, span: Span) -> Self { + pub fn missing_boolean(expected: String, span: &Span) -> Self { let message = format!("expected boolean input `{}` not found", expected); Self::new_from_span(message, span) diff --git a/compiler/src/errors/value/field.rs b/compiler/src/errors/value/field.rs index 55509037eb..d3110f008c 100644 --- a/compiler/src/errors/value/field.rs +++ b/compiler/src/errors/value/field.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::{FormattedError, LeoError, Span}; use snarkvm_errors::gadgets::SynthesisError; -use std::path::Path; #[derive(Debug, Error)] pub enum FieldError { @@ -25,24 +24,32 @@ pub enum FieldError { Error(#[from] FormattedError), } -impl FieldError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for FieldError { + fn get_path(&self) -> Option<&str> { match self { - FieldError::Error(error) => error.set_path(path), + FieldError::Error(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + FieldError::Error(error) => error.set_path(path, contents), + } + } +} + +impl FieldError { + fn new_from_span(message: String, span: &Span) -> Self { FieldError::Error(FormattedError::new_from_span(message, span)) } - pub fn negate_operation(error: SynthesisError, span: Span) -> Self { + pub fn negate_operation(error: SynthesisError, span: &Span) -> Self { let message = format!("field negation failed due to synthesis error `{:?}`", error,); Self::new_from_span(message, span) } - pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self { + pub fn binary_operation(operation: String, error: SynthesisError, span: &Span) -> Self { let message = format!( "the field binary operation `{}` failed due to synthesis error `{:?}`", operation, error, @@ -51,25 +58,25 @@ impl FieldError { Self::new_from_span(message, span) } - pub fn invalid_field(actual: String, span: Span) -> Self { + pub fn invalid_field(actual: String, span: &Span) -> Self { let message = format!("expected field element input type, found `{}`", actual); Self::new_from_span(message, span) } - pub fn missing_field(expected: String, span: Span) -> Self { + pub fn missing_field(expected: String, span: &Span) -> Self { let message = format!("expected field input `{}` not found", expected); Self::new_from_span(message, span) } - pub fn no_inverse(field: String, span: Span) -> Self { + pub fn no_inverse(field: String, span: &Span) -> Self { let message = format!("no multiplicative inverse found for field `{}`", field); Self::new_from_span(message, span) } - pub fn synthesis_error(error: SynthesisError, span: Span) -> Self { + pub fn synthesis_error(error: SynthesisError, span: &Span) -> Self { let message = format!("compilation failed due to field synthesis error `{:?}`", error); Self::new_from_span(message, span) diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index 3de87b9b99..df6347e907 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::{FormattedError, LeoError, Span}; use snarkvm_errors::gadgets::SynthesisError; -use std::path::Path; #[derive(Debug, Error)] pub enum GroupError { @@ -25,24 +24,32 @@ pub enum GroupError { Error(#[from] FormattedError), } -impl GroupError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for GroupError { + fn get_path(&self) -> Option<&str> { match self { - GroupError::Error(error) => error.set_path(path), + GroupError::Error(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + GroupError::Error(error) => error.set_path(path, contents), + } + } +} + +impl GroupError { + fn new_from_span(message: String, span: &Span) -> Self { GroupError::Error(FormattedError::new_from_span(message, span)) } - pub fn negate_operation(error: SynthesisError, span: Span) -> Self { + pub fn negate_operation(error: SynthesisError, span: &Span) -> Self { let message = format!("group negation failed due to the synthesis error `{:?}`", error,); Self::new_from_span(message, span) } - pub fn binary_operation(operation: String, error: SynthesisError, span: Span) -> Self { + pub fn binary_operation(operation: String, error: SynthesisError, span: &Span) -> Self { let message = format!( "the group binary operation `{}` failed due to the synthesis error `{:?}`", operation, error, @@ -51,55 +58,55 @@ impl GroupError { Self::new_from_span(message, span) } - pub fn invalid_group(actual: String, span: Span) -> Self { + pub fn invalid_group(actual: String, span: &Span) -> Self { let message = format!("expected group affine point input type, found `{}`", actual); Self::new_from_span(message, span) } - pub fn missing_group(expected: String, span: Span) -> Self { + pub fn missing_group(expected: String, span: &Span) -> Self { let message = format!("expected group input `{}` not found", expected); Self::new_from_span(message, span) } - pub fn synthesis_error(error: SynthesisError, span: Span) -> Self { + pub fn synthesis_error(error: SynthesisError, span: &Span) -> Self { let message = format!("compilation failed due to group synthesis error `{:?}`", error); Self::new_from_span(message, span) } - pub fn x_invalid(x: String, span: Span) -> Self { + pub fn x_invalid(x: String, span: &Span) -> Self { let message = format!("invalid x coordinate `{}`", x); Self::new_from_span(message, span) } - pub fn y_invalid(y: String, span: Span) -> Self { + pub fn y_invalid(y: String, span: &Span) -> Self { let message = format!("invalid y coordinate `{}`", y); Self::new_from_span(message, span) } - pub fn not_on_curve(element: String, span: Span) -> Self { + pub fn not_on_curve(element: String, span: &Span) -> Self { let message = format!("group element `{}` is not on the supported curve", element); Self::new_from_span(message, span) } - pub fn x_recover(span: Span) -> Self { + pub fn x_recover(span: &Span) -> Self { let message = "could not recover group element from x coordinate".to_string(); Self::new_from_span(message, span) } - pub fn y_recover(span: Span) -> Self { + pub fn y_recover(span: &Span) -> Self { let message = "could not recover group element from y coordinate".to_string(); Self::new_from_span(message, span) } - pub fn n_group(number: String, span: Span) -> Self { + pub fn n_group(number: String, span: &Span) -> Self { let message = format!("cannot multiply group generator by \"{}\"", number); Self::new_from_span(message, span) diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index 43be823d92..d51ed6df0f 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{error::Error as FormattedError, IntegerType, Span, Type}; -use leo_gadgets::errors::SignedIntegerError; +use leo_ast::{FormattedError, IntegerType, LeoError, Span, Type}; +use leo_gadgets::errors::SignedIntegerError; use snarkvm_errors::gadgets::SynthesisError; -use std::path::Path; #[derive(Debug, Error)] pub enum IntegerError { @@ -26,18 +25,26 @@ pub enum IntegerError { Error(#[from] FormattedError), } -impl IntegerError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for IntegerError { + fn get_path(&self) -> Option<&str> { match self { - IntegerError::Error(error) => error.set_path(path), + IntegerError::Error(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + IntegerError::Error(error) => error.set_path(path, contents), + } + } +} + +impl IntegerError { + fn new_from_span(message: String, span: &Span) -> Self { IntegerError::Error(FormattedError::new_from_span(message, span)) } - pub fn cannot_enforce(operation: String, error: SynthesisError, span: Span) -> Self { + pub fn cannot_enforce(operation: String, error: SynthesisError, span: &Span) -> Self { let message = format!( "the integer operation `{}` failed due to the synthesis error `{:?}`", operation, error, @@ -46,19 +53,19 @@ impl IntegerError { Self::new_from_span(message, span) } - pub fn signed(error: SignedIntegerError, span: Span) -> Self { + pub fn signed(error: SignedIntegerError, span: &Span) -> Self { let message = format!("integer operation failed due to the signed integer error `{:?}`", error,); Self::new_from_span(message, span) } - pub fn synthesis(error: SynthesisError, span: Span) -> Self { + pub fn synthesis(error: SynthesisError, span: &Span) -> Self { let message = format!("integer operation failed due to the synthesis error `{}`", error,); Self::new_from_span(message, span) } - pub fn signed_error(operation: String, error: SignedIntegerError, span: Span) -> Self { + pub fn signed_error(operation: String, error: SignedIntegerError, span: &Span) -> Self { let message = format!( "the integer operation `{}` failed due to the signed integer error `{:?}`", operation, error @@ -67,13 +74,13 @@ impl IntegerError { Self::new_from_span(message, span) } - pub fn negate_operation(span: Span) -> Self { + pub fn negate_operation(span: &Span) -> Self { let message = "integer negation can only be enforced on signed integers".to_string(); Self::new_from_span(message, span) } - pub fn binary_operation(operation: String, span: Span) -> Self { + pub fn binary_operation(operation: String, span: &Span) -> Self { let message = format!( "the integer binary operation `{}` can only be enforced on integers of the same type", operation @@ -82,7 +89,7 @@ impl IntegerError { Self::new_from_span(message, span) } - pub fn invalid_index(span: Span) -> Self { + pub fn invalid_index(span: &Span) -> Self { let message = "index must be a constant value unsigned integer. allocated indices produce a circuit of unknown size" .to_string(); @@ -90,27 +97,33 @@ impl IntegerError { Self::new_from_span(message, span) } - pub fn invalid_integer(actual: String, span: Span) -> Self { + pub fn invalid_integer(actual: String, span: &Span) -> Self { let message = format!("failed to parse `{}` as expected integer type", actual); Self::new_from_span(message, span) } - pub fn invalid_integer_type(expected: &IntegerType, actual: &IntegerType, span: Span) -> Self { + pub fn invalid_integer_type(expected: &IntegerType, actual: &IntegerType, span: &Span) -> Self { let message = format!("expected integer type {} found integer type {}", expected, actual); Self::new_from_span(message, span) } - pub fn invalid_type(actual: &Type, span: Span) -> Self { + pub fn invalid_type(actual: &Type, span: &Span) -> Self { let message = format!("expected type {}, found type IntegerType", actual); Self::new_from_span(message, span) } - pub fn missing_integer(expected: String, span: Span) -> Self { + pub fn missing_integer(expected: String, span: &Span) -> Self { let message = format!("expected integer input `{}` not found", expected); Self::new_from_span(message, span) } + + pub fn cannot_evaluate(operation: String, span: &Span) -> Self { + let message = format!("no implementation found for `{}`", operation); + + Self::new_from_span(message, span) + } } diff --git a/compiler/src/errors/value/value.rs b/compiler/src/errors/value/value.rs index 66a7d50e83..d3afeb8f73 100644 --- a/compiler/src/errors/value/value.rs +++ b/compiler/src/errors/value/value.rs @@ -15,9 +15,7 @@ // along with the Leo library. If not, see . use crate::errors::{AddressError, BooleanError, FieldError, GroupError, IntegerError}; -use leo_ast::{Error as FormattedError, Span}; - -use std::path::Path; +use leo_ast::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum ValueError { @@ -40,29 +38,42 @@ pub enum ValueError { IntegerError(#[from] IntegerError), } -impl ValueError { - pub fn set_path(&mut self, path: &Path) { +impl LeoError for ValueError { + fn get_path(&self) -> Option<&str> { match self { - ValueError::AddressError(error) => error.set_path(path), - ValueError::BooleanError(error) => error.set_path(path), - ValueError::Error(error) => error.set_path(path), - ValueError::FieldError(error) => error.set_path(path), - ValueError::GroupError(error) => error.set_path(path), - ValueError::IntegerError(error) => error.set_path(path), + ValueError::AddressError(error) => error.get_path(), + ValueError::BooleanError(error) => error.get_path(), + ValueError::Error(error) => error.get_path(), + ValueError::FieldError(error) => error.get_path(), + ValueError::GroupError(error) => error.get_path(), + ValueError::IntegerError(error) => error.get_path(), } } - fn new_from_span(message: String, span: Span) -> Self { + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + ValueError::AddressError(error) => error.set_path(path, contents), + ValueError::BooleanError(error) => error.set_path(path, contents), + ValueError::Error(error) => error.set_path(path, contents), + ValueError::FieldError(error) => error.set_path(path, contents), + ValueError::GroupError(error) => error.set_path(path, contents), + ValueError::IntegerError(error) => error.set_path(path, contents), + } + } +} + +impl ValueError { + fn new_from_span(message: String, span: &Span) -> Self { ValueError::Error(FormattedError::new_from_span(message, span)) } - pub fn implicit(value: String, span: Span) -> Self { + pub fn implicit(value: String, span: &Span) -> Self { let message = format!("explicit type needed for `{}`", value); Self::new_from_span(message, span) } - pub fn implicit_group(span: Span) -> Self { + pub fn implicit_group(span: &Span) -> Self { let message = "group coordinates should be in (x, y)group format".to_string(); Self::new_from_span(message, span) diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index e2edaa93c1..b3d18da0d2 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -39,7 +39,7 @@ pub fn enforce_add<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} + {}", val_1, val_2), - span.to_owned(), + span, )), } } diff --git a/grammar/src/console/console_debug.rs b/compiler/src/expression/arithmetic/bit_not.rs similarity index 57% rename from grammar/src/console/console_debug.rs rename to compiler/src/expression/arithmetic/bit_not.rs index 81b463947e..21bfd9d1ad 100644 --- a/grammar/src/console/console_debug.rs +++ b/compiler/src/expression/arithmetic/bit_not.rs @@ -14,24 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, console::FormattedString, SpanDef}; +//! Enforces a logical `!` operator in a resolved Leo program. -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; +use crate::{errors::IntegerError, value::ConstrainedValue, GroupType}; +use leo_asg::Span; -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_debug))] -pub struct ConsoleDebug<'ast> { - pub string: FormattedString<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} +use snarkvm_models::curves::PrimeField; -impl<'ast> fmt::Display for ConsoleDebug<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "debug({})", self.string) +pub fn evaluate_bit_not<'a, F: PrimeField, G: GroupType>( + value: ConstrainedValue<'a, F, G>, + span: &Span, +) -> Result, IntegerError> { + match value { + // ConstrainedValue::Integer(i) => Ok(ConstrainedValue::Integer(i.not())), + value => Err(IntegerError::cannot_evaluate(format!("~{}", value), span)), } } diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 1c8ea36f5d..5adbf86478 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -36,7 +36,7 @@ pub fn enforce_div<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} / {}", val_1, val_2,), - span.to_owned(), + span, )), } } diff --git a/compiler/src/expression/arithmetic/mod.rs b/compiler/src/expression/arithmetic/mod.rs index 5e5914ff2d..ac3b50d26b 100644 --- a/compiler/src/expression/arithmetic/mod.rs +++ b/compiler/src/expression/arithmetic/mod.rs @@ -33,3 +33,6 @@ pub use self::div::*; pub mod pow; pub use self::pow::*; + +pub mod bit_not; +pub use self::bit_not::*; diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index 0500ae7705..2f0f7dcbdd 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -36,7 +36,7 @@ pub fn enforce_mul<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} * {}", val_1, val_2), - span.to_owned(), + span, )), } } diff --git a/compiler/src/expression/arithmetic/negate.rs b/compiler/src/expression/arithmetic/negate.rs index 72891e9547..9ed65e698f 100644 --- a/compiler/src/expression/arithmetic/negate.rs +++ b/compiler/src/expression/arithmetic/negate.rs @@ -30,9 +30,6 @@ pub fn enforce_negate<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem Ok(ConstrainedValue::Integer(integer.negate(cs, span)?)), ConstrainedValue::Field(field) => Ok(ConstrainedValue::Field(field.negate(cs, span)?)), ConstrainedValue::Group(group) => Ok(ConstrainedValue::Group(group.negate(cs, span)?)), - value => Err(ExpressionError::incompatible_types( - format!("-{}", value), - span.to_owned(), - )), + value => Err(ExpressionError::incompatible_types(format!("-{}", value), span)), } } diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index 3df43fac76..34a333bb27 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -33,7 +33,7 @@ pub fn enforce_pow<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} ** {}", val_1, val_2,), - span.to_owned(), + span, )), } } diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index 1abac1547a..5c87af7dea 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -39,7 +39,7 @@ pub fn enforce_sub<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( } (val_1, val_2) => Err(ExpressionError::incompatible_types( format!("{} - {}", val_1, val_2), - span.to_owned(), + span, )), } } diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 8a9469ca7a..2586232afb 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -32,7 +32,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) -> Result, ExpressionError> { let array = match self.enforce_expression(cs, array)? { ConstrainedValue::Array(array) => array, - value => return Err(ExpressionError::undefined_array(value.to_string(), span.to_owned())), + value => return Err(ExpressionError::undefined_array(value.to_string(), span)), }; let index_resolved = self.enforce_index(cs, index, span)?; @@ -50,7 +50,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) -> Result, ExpressionError> { let array = match self.enforce_expression(cs, array)? { ConstrainedValue::Array(array) => array, - value => return Err(ExpressionError::undefined_array(value.to_string(), span.to_owned())), + value => return Err(ExpressionError::undefined_array(value.to_string(), span)), }; let from_resolved = match left { diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 04c60441b3..a217d8638c 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -29,7 +29,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { &mut self, cs: &mut CS, array: &[(Cell<&'a Expression<'a>>, bool)], - span: Span, + span: &Span, ) -> Result, ExpressionError> { let expected_dimension = None; diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 09d3327ca1..fd9b6e2a5e 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -40,19 +40,19 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Err(ExpressionError::undefined_member_access( expr.circuit.get().name.borrow().to_string(), expr.member.to_string(), - expr.member.span.clone(), + &expr.member.span, )) } } value => Err(ExpressionError::undefined_circuit( value.to_string(), - target.span().cloned().unwrap_or_default(), + &target.span().cloned().unwrap_or_default(), )), } } else { Err(ExpressionError::invalid_static_access( expr.member.to_string(), - expr.member.span.clone(), + &expr.member.span, )) } } diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index fba53cab5b..16bf49ba6a 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -48,7 +48,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let variable_value = self.enforce_expression(cs, inner.get())?; resolved_members.push(ConstrainedCircuitMember(name.clone(), variable_value)); } - _ => return Err(ExpressionError::expected_circuit_member(name.to_string(), span.clone())), + _ => return Err(ExpressionError::expected_circuit_member(name.to_string(), span)), } } diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index aa515d5346..426263dcc1 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -37,7 +37,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ) -> Result, ExpressionError> { let conditional_value = match self.enforce_expression(cs, conditional)? { ConstrainedValue::Boolean(resolved) => resolved, - value => return Err(ExpressionError::conditional_boolean(value.to_string(), span.to_owned())), + value => return Err(ExpressionError::conditional_boolean(value.to_string(), span)), }; let first_value = self.enforce_expression(cs, first)?; @@ -47,11 +47,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let unique_namespace = cs.ns(|| { format!( "select {} or {} {}:{}", - first_value, second_value, span.line, span.start + first_value, second_value, span.line_start, span.col_start ) }); ConstrainedValue::conditionally_select(unique_namespace, &conditional_value, &first_value, &second_value) - .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, span.to_owned())) + .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, span)) } } diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index e399d090ae..c55038b15b 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -40,18 +40,21 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { cs: &mut CS, expression: &'a Expression<'a>, ) -> Result, ExpressionError> { - let span = expression.span().cloned().unwrap_or_default(); + let span = &expression.span().cloned().unwrap_or_default(); match expression { + // Cast + Expression::Cast(_) => unimplemented!("casts not implemented"), + // Variables Expression::VariableRef(variable_ref) => self.evaluate_ref(variable_ref), // Values Expression::Constant(Constant { value, .. }) => { Ok(match value { - ConstValue::Address(value) => ConstrainedValue::Address(Address::constant(value.clone(), &span)?), + ConstValue::Address(value) => ConstrainedValue::Address(Address::constant(value.clone(), span)?), ConstValue::Boolean(value) => ConstrainedValue::Boolean(Boolean::Constant(*value)), - ConstValue::Field(value) => ConstrainedValue::Field(FieldType::constant(value.to_string(), &span)?), - ConstValue::Group(value) => ConstrainedValue::Group(G::constant(value, &span)?), + ConstValue::Field(value) => ConstrainedValue::Field(FieldType::constant(value.to_string(), span)?), + ConstValue::Group(value) => ConstrainedValue::Group(G::constant(value, span)?), ConstValue::Int(value) => ConstrainedValue::Integer(Integer::new(value)), ConstValue::Tuple(_) | ConstValue::Array(_) => unimplemented!(), // shouldnt be in the asg here }) @@ -64,24 +67,25 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let (resolved_left, resolved_right) = self.enforce_binary_expression(cs, left.get(), right.get())?; match operation { - BinaryOperation::Add => enforce_add(cs, resolved_left, resolved_right, &span), - BinaryOperation::Sub => enforce_sub(cs, resolved_left, resolved_right, &span), - BinaryOperation::Mul => enforce_mul(cs, resolved_left, resolved_right, &span), - BinaryOperation::Div => enforce_div(cs, resolved_left, resolved_right, &span), - BinaryOperation::Pow => enforce_pow(cs, resolved_left, resolved_right, &span), + BinaryOperation::Add => enforce_add(cs, resolved_left, resolved_right, span), + BinaryOperation::Sub => enforce_sub(cs, resolved_left, resolved_right, span), + BinaryOperation::Mul => enforce_mul(cs, resolved_left, resolved_right, span), + BinaryOperation::Div => enforce_div(cs, resolved_left, resolved_right, span), + BinaryOperation::Pow => enforce_pow(cs, resolved_left, resolved_right, span), BinaryOperation::Or => { - enforce_or(cs, resolved_left, resolved_right, &span).map_err(ExpressionError::BooleanError) + enforce_or(cs, resolved_left, resolved_right, span).map_err(ExpressionError::BooleanError) } BinaryOperation::And => { - enforce_and(cs, resolved_left, resolved_right, &span).map_err(ExpressionError::BooleanError) + enforce_and(cs, resolved_left, resolved_right, span).map_err(ExpressionError::BooleanError) } - BinaryOperation::Eq => evaluate_eq(cs, resolved_left, resolved_right, &span), - BinaryOperation::Ne => evaluate_not(evaluate_eq(cs, resolved_left, resolved_right, &span)?, &span) + BinaryOperation::Eq => evaluate_eq(cs, resolved_left, resolved_right, span), + BinaryOperation::Ne => evaluate_not(evaluate_eq(cs, resolved_left, resolved_right, span)?, span) .map_err(ExpressionError::BooleanError), - BinaryOperation::Ge => evaluate_ge(cs, resolved_left, resolved_right, &span), - BinaryOperation::Gt => evaluate_gt(cs, resolved_left, resolved_right, &span), - BinaryOperation::Le => evaluate_le(cs, resolved_left, resolved_right, &span), - BinaryOperation::Lt => evaluate_lt(cs, resolved_left, resolved_right, &span), + BinaryOperation::Ge => evaluate_ge(cs, resolved_left, resolved_right, span), + BinaryOperation::Gt => evaluate_gt(cs, resolved_left, resolved_right, span), + BinaryOperation::Le => evaluate_le(cs, resolved_left, resolved_right, span), + BinaryOperation::Lt => evaluate_lt(cs, resolved_left, resolved_right, span), + _ => unimplemented!("unimplemented binary operator"), } } @@ -89,9 +93,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Expression::Unary(UnaryExpression { inner, operation, .. }) => match operation { UnaryOperation::Negate => { let resolved_inner = self.enforce_expression(cs, inner.get())?; - enforce_negate(cs, resolved_inner, &span) + enforce_negate(cs, resolved_inner, span) } - UnaryOperation::Not => Ok(evaluate_not(self.enforce_expression(cs, inner.get())?, &span)?), + UnaryOperation::Not => Ok(evaluate_not(self.enforce_expression(cs, inner.get())?, span)?), + _ => unimplemented!("unimplemented unary operator"), }, Expression::Ternary(TernaryExpression { @@ -99,7 +104,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if_true, if_false, .. - }) => self.enforce_conditional_expression(cs, condition.get(), if_true.get(), if_false.get(), &span), + }) => self.enforce_conditional_expression(cs, condition.get(), if_true.get(), if_false.get(), span), // Arrays Expression::ArrayInline(ArrayInlineExpression { elements, .. }) => { @@ -109,20 +114,20 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { self.enforce_array_initializer(cs, element.get(), *len) } Expression::ArrayAccess(ArrayAccessExpression { array, index, .. }) => { - self.enforce_array_access(cs, array.get(), index.get(), &span) + self.enforce_array_access(cs, array.get(), index.get(), span) } Expression::ArrayRangeAccess(ArrayRangeAccessExpression { array, left, right, .. }) => { - self.enforce_array_range_access(cs, array.get(), left.get(), right.get(), &span) + self.enforce_array_range_access(cs, array.get(), left.get(), right.get(), span) } // Tuples Expression::TupleInit(TupleInitExpression { elements, .. }) => self.enforce_tuple(cs, &elements[..]), Expression::TupleAccess(TupleAccessExpression { tuple_ref, index, .. }) => { - self.enforce_tuple_access(cs, tuple_ref.get(), *index, &span) + self.enforce_tuple_access(cs, tuple_ref.get(), *index, span) } // Circuits - Expression::CircuitInit(expr) => self.enforce_circuit(cs, expr, &span), + Expression::CircuitInit(expr) => self.enforce_circuit(cs, expr, span), Expression::CircuitAccess(expr) => self.enforce_circuit_access(cs, expr), // Functions @@ -142,11 +147,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { function.get(), target.get(), &arguments[..], - &span, + span, ); } } - self.enforce_function_call_expression(cs, function.get(), target.get(), &arguments[..], &span) + self.enforce_function_call_expression(cs, function.get(), target.get(), &arguments[..], span) } } } diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index ba1888c4c6..a0dc8d7692 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -37,8 +37,8 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { format!( "function call {} {}:{}", function.name.borrow().clone(), - span.line, - span.start, + span.line_start, + span.col_start, ) }; diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 0d8ef3773d..9ade15394c 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -34,14 +34,14 @@ pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( if let (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) = (left, right) { let result = Boolean::and( - cs.ns(|| format!("{} {}:{}", name, span.line, span.start)), + cs.ns(|| format!("{} {}:{}", name, span.line_start, span.col_start)), &left_bool, &right_bool, ) - .map_err(|e| BooleanError::cannot_enforce("&&".to_string(), e, span.to_owned()))?; + .map_err(|e| BooleanError::cannot_enforce("&&".to_string(), e, span))?; return Ok(ConstrainedValue::Boolean(result)); } - Err(BooleanError::cannot_evaluate(name, span.to_owned())) + Err(BooleanError::cannot_evaluate(name, span)) } diff --git a/compiler/src/expression/logical/not.rs b/compiler/src/expression/logical/not.rs index 84d16c5be8..c4173ad8de 100644 --- a/compiler/src/expression/logical/not.rs +++ b/compiler/src/expression/logical/not.rs @@ -27,6 +27,6 @@ pub fn evaluate_not<'a, F: PrimeField, G: GroupType>( ) -> Result, BooleanError> { match value { ConstrainedValue::Boolean(boolean) => Ok(ConstrainedValue::Boolean(boolean.not())), - value => Err(BooleanError::cannot_evaluate(format!("!{}", value), span.clone())), + value => Err(BooleanError::cannot_evaluate(format!("!{}", value), span)), } } diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index ec1739d085..e637654028 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -34,14 +34,14 @@ pub fn enforce_or<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( if let (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) = (left, right) { let result = Boolean::or( - cs.ns(|| format!("{} {}:{}", name, span.line, span.start)), + cs.ns(|| format!("{} {}:{}", name, span.line_start, span.col_start)), &left_bool, &right_bool, ) - .map_err(|e| BooleanError::cannot_enforce("||".to_string(), e, span.to_owned()))?; + .map_err(|e| BooleanError::cannot_enforce("||".to_string(), e, span))?; return Ok(ConstrainedValue::Boolean(result)); } - Err(BooleanError::cannot_evaluate(name, span.to_owned())) + Err(BooleanError::cannot_evaluate(name, span)) } diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 99dfe39e42..551d30a22c 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -33,7 +33,7 @@ pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( right: ConstrainedValue<'a, F, G>, span: &Span, ) -> Result, ExpressionError> { - let namespace_string = format!("evaluate {} == {} {}:{}", left, right, span.line, span.start); + let namespace_string = format!("evaluate {} == {} {}:{}", left, right, span.line_start, span.col_start); let constraint_result = match (left, right) { (ConstrainedValue::Address(address_1), ConstrainedValue::Address(address_2)) => { let unique_namespace = cs.ns(|| namespace_string); @@ -77,12 +77,12 @@ pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( (val_1, val_2) => { return Err(ExpressionError::incompatible_types( format!("{} == {}", val_1, val_2,), - span.to_owned(), + span, )); } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), span.to_owned()))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index 0788633554..2e9e2cef29 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -28,7 +28,7 @@ pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( right: ConstrainedValue<'a, F, G>, span: &Span, ) -> Result, ExpressionError> { - let unique_namespace = cs.ns(|| format!("evaluate {} >= {} {}:{}", left, right, span.line, span.start)); + let unique_namespace = cs.ns(|| format!("evaluate {} >= {} {}:{}", left, right, span.line_start, span.col_start)); let constraint_result = match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { num_1.greater_than_or_equal(unique_namespace, &num_2) @@ -36,12 +36,12 @@ pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( (val_1, val_2) => { return Err(ExpressionError::incompatible_types( format!("{} >= {}", val_1, val_2), - span.to_owned(), + span, )); } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">=".to_string(), span.to_owned()))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">=".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index 8590e17b6c..5584d2d48b 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -28,7 +28,7 @@ pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( right: ConstrainedValue<'a, F, G>, span: &Span, ) -> Result, ExpressionError> { - let unique_namespace = cs.ns(|| format!("evaluate {} > {} {}:{}", left, right, span.line, span.start)); + let unique_namespace = cs.ns(|| format!("evaluate {} > {} {}:{}", left, right, span.line_start, span.col_start)); let constraint_result = match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { num_1.greater_than(unique_namespace, &num_2) @@ -36,12 +36,12 @@ pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( (val_1, val_2) => { return Err(ExpressionError::incompatible_types( format!("{} > {}", val_1, val_2), - span.to_owned(), + span, )); } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">".to_string(), span.to_owned()))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 38ba4ba6d1..8f37b5aac8 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -28,7 +28,7 @@ pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( right: ConstrainedValue<'a, F, G>, span: &Span, ) -> Result, ExpressionError> { - let unique_namespace = cs.ns(|| format!("evaluate {} <= {} {}:{}", left, right, span.line, span.start)); + let unique_namespace = cs.ns(|| format!("evaluate {} <= {} {}:{}", left, right, span.line_start, span.col_start)); let constraint_result = match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { num_1.less_than_or_equal(unique_namespace, &num_2) @@ -36,12 +36,12 @@ pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( (val_1, val_2) => { return Err(ExpressionError::incompatible_types( format!("{} <= {}", val_1, val_2), - span.to_owned(), + span, )); } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<=".to_string(), span.to_owned()))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<=".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 5282f60335..978f1d609a 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -28,7 +28,7 @@ pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( right: ConstrainedValue<'a, F, G>, span: &Span, ) -> Result, ExpressionError> { - let unique_namespace = cs.ns(|| format!("evaluate {} < {} {}:{}", left, right, span.line, span.start)); + let unique_namespace = cs.ns(|| format!("evaluate {} < {} {}:{}", left, right, span.line_start, span.col_start)); let constraint_result = match (left, right) { (ConstrainedValue::Integer(num_1), ConstrainedValue::Integer(num_2)) => { num_1.less_than(unique_namespace, &num_2) @@ -36,12 +36,12 @@ pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( (val_1, val_2) => { return Err(ExpressionError::incompatible_types( format!("{} < {}", val_1, val_2), - span.to_owned(), + span, )); } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<".to_string(), span.to_owned()))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 1f219a4d9a..0aa64024bd 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -33,13 +33,13 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { // Get the tuple values. let tuple = match self.enforce_expression(cs, tuple)? { ConstrainedValue::Tuple(tuple) => tuple, - value => return Err(ExpressionError::undefined_array(value.to_string(), span.to_owned())), + value => return Err(ExpressionError::undefined_array(value.to_string(), span)), }; // Check for out of bounds access. if index > tuple.len() - 1 { // probably safe to be a panic here - return Err(ExpressionError::index_out_of_bounds(index, span.to_owned())); + return Err(ExpressionError::index_out_of_bounds(index, span)); } Ok(tuple[index].to_owned()) diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 23dcda03b2..5564e9f7d0 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -50,7 +50,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if function.arguments.len() != arguments.len() { return Err(FunctionError::input_not_found( "arguments length invalid".to_string(), - function.span.clone().unwrap_or_default(), + &function.span.clone().unwrap_or_default(), )); } diff --git a/compiler/src/function/input/array.rs b/compiler/src/function/input/array.rs index ebf3bca676..cfef1540df 100644 --- a/compiler/src/function/input/array.rs +++ b/compiler/src/function/input/array.rs @@ -42,7 +42,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { return Err(FunctionError::invalid_input_array_dimensions( arr.len(), array_len, - span.clone(), + span, )); } @@ -68,10 +68,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } } _ => { - return Err(FunctionError::invalid_array( - input_value.unwrap().to_string(), - span.to_owned(), - )); + return Err(FunctionError::invalid_array(input_value.unwrap().to_string(), span)); } } diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index e7aaed9fd6..fb0e721dc9 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -29,7 +29,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_input_keyword>( &mut self, cs: &mut CS, - span: Span, + span: &Span, expected_type: &'a Circuit<'a>, input: &Input, ) -> Result, FunctionError> { @@ -49,7 +49,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }; let state_leaf_name = Identifier { name: STATE_LEAF_VARIABLE_NAME.to_string(), - span, + span: span.clone(), }; // Fetch each input variable's definitions diff --git a/compiler/src/function/input/tuple.rs b/compiler/src/function/input/tuple.rs index 0530a0790f..911fbc13a5 100644 --- a/compiler/src/function/input/tuple.rs +++ b/compiler/src/function/input/tuple.rs @@ -52,10 +52,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } } _ => { - return Err(FunctionError::invalid_tuple( - input_value.unwrap().to_string(), - span.to_owned(), - )); + return Err(FunctionError::invalid_tuple(input_value.unwrap().to_string(), span)); } } diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 45f6b28733..be86455cb5 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -41,12 +41,8 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .resolve_input() .expect("no input variable in scope when function is qualified"); - let value = self.allocate_input_keyword( - cs, - function.name.borrow().span.clone(), - &asg_input.container_circuit, - input, - )?; + let value = + self.allocate_input_keyword(cs, &function.name.borrow().span, &asg_input.container_circuit, input)?; self.store(asg_input.container.borrow().id, value); } @@ -65,7 +61,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let input_variable = input_variable.get().borrow(); let name = input_variable.name.name.clone(); let input_option = input.get(&name).ok_or_else(|| { - FunctionError::input_not_found(name.clone(), function.span.clone().unwrap_or_default()) + FunctionError::input_not_found(name.clone(), &function.span.clone().unwrap_or_default()) })?; let input_value = self.allocate_main_function_input( cs, @@ -89,7 +85,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let span = function.span.clone().unwrap_or_default(); let result_value = self.enforce_function(cs, function, None, &arguments)?; - let output_bytes = OutputBytes::new_from_constrained_value(&self.asg, registers, result_value, span)?; + let output_bytes = OutputBytes::new_from_constrained_value(&self.asg, registers, result_value, &span)?; Ok(output_bytes) } diff --git a/compiler/src/function/mut_target.rs b/compiler/src/function/mut_target.rs index dd2f1c6582..2c09c5f9b0 100644 --- a/compiler/src/function/mut_target.rs +++ b/compiler/src/function/mut_target.rs @@ -49,19 +49,16 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let inner = self.prepare_mut_access(cs, array.get(), span, output)?; let start_index = left .get() - .map(|start| self.enforce_index(cs, start, &span)) - .transpose()?; - let stop_index = right - .get() - .map(|stop| self.enforce_index(cs, stop, &span)) + .map(|start| self.enforce_index(cs, start, span)) .transpose()?; + let stop_index = right.get().map(|stop| self.enforce_index(cs, stop, span)).transpose()?; output.push(ResolvedAssigneeAccess::ArrayRange(start_index, stop_index)); Ok(inner) } Expression::ArrayAccess(ArrayAccessExpression { array, index, .. }) => { let inner = self.prepare_mut_access(cs, array.get(), span, output)?; - let index = self.enforce_index(cs, index.get(), &span)?; + let index = self.enforce_index(cs, index.get(), span)?; output.push(ResolvedAssigneeAccess::ArrayIndex(index)); Ok(inner) @@ -94,10 +91,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { cs: &mut CS, assignee: &'a Expression<'a>, ) -> Result>>, StatementError> { - let span = assignee.span().cloned().unwrap_or_default(); + let span = &assignee.span().cloned().unwrap_or_default(); let mut accesses = vec![]; - let target = self.prepare_mut_access(cs, assignee, &span, &mut accesses)?; + let target = self.prepare_mut_access(cs, assignee, span, &mut accesses)?; if target.is_none() { return Ok(None); } @@ -110,7 +107,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }]; for access in accesses { - result = Self::resolve_assignee_access(access, &span, result)?; + result = Self::resolve_assignee_access(access, span, result)?; } Ok(Some(result)) } diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 57d0ad0bc5..ba6294759b 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -64,7 +64,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if get_indicator_value(&indicator) { // Error if we already have a return value. if return_value.is_some() { - return Err(StatementError::multiple_returns(span.to_owned())); + return Err(StatementError::multiple_returns(span)); } else { // Set the function return value. return_value = Some(result); @@ -83,12 +83,12 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if let Some(value) = &return_value { return_value = Some( ConstrainedValue::conditionally_select( - cs.ns(|| format!("select result {} {}:{}", i, span.line, span.start)), + cs.ns(|| format!("select result {} {}:{}", i, span.line_start, span.col_start)), &indicator, &result, &value, ) - .map_err(|_| StatementError::select_fail(result.to_string(), value.to_string(), span.to_owned()))?, + .map_err(|_| StatementError::select_fail(result.to_string(), value.to_string(), span))?, ); } else { return_value = Some(result); // we ignore indicator for default -- questionable @@ -98,7 +98,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if expected_return.is_unit() { Ok(ConstrainedValue::Tuple(vec![])) } else { - return_value.ok_or_else(|| StatementError::no_returns(&expected_return, span.to_owned())) + return_value.ok_or_else(|| StatementError::no_returns(&expected_return, span)) } } } diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index df59b28f25..ef8ca5cc4a 100644 --- a/compiler/src/output/output_bytes.rs +++ b/compiler/src/output/output_bytes.rs @@ -35,7 +35,7 @@ impl OutputBytes { program: &Program<'a>, registers: &Registers, value: ConstrainedValue<'a, F, G>, - span: Span, + span: &Span, ) -> Result { let return_values = match value { ConstrainedValue::Tuple(values) => values, @@ -68,7 +68,7 @@ impl OutputBytes { // Check register type == return value type. let register_type = program.scope.resolve_ast_type(¶meter.type_)?; - let return_value_type = value.to_type(&span)?; + let return_value_type = value.to_type(span)?; if !register_type.is_assignable_from(&return_value_type) { return Err(OutputBytesError::mismatched_output_types( diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index 96e68b38c6..0c74def109 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -61,15 +61,13 @@ impl<'a, F: PrimeField, G: GroupType> CoreCircuit<'a, F, G> for Blake2s { let input = unwrap_argument(arguments.remove(1)); let seed = unwrap_argument(arguments.remove(0)); - let digest = - Blake2sGadget::check_evaluation_gadget(cs.ns(|| "blake2s hash"), &seed[..], &input[..]).map_err(|e| { - ExpressionError::cannot_enforce("Blake2s check evaluation gadget".to_owned(), e, span.clone()) - })?; + let digest = Blake2sGadget::check_evaluation_gadget(cs.ns(|| "blake2s hash"), &seed[..], &input[..]) + .map_err(|e| ExpressionError::cannot_enforce("Blake2s check evaluation gadget".to_owned(), e, span))?; Ok(ConstrainedValue::Array( digest .to_bytes(cs) - .map_err(|e| ExpressionError::cannot_enforce("Vec ToBytes".to_owned(), e, span.clone()))? + .map_err(|e| ExpressionError::cannot_enforce("Vec ToBytes".to_owned(), e, span))? .into_iter() .map(Integer::U8) .map(ConstrainedValue::Integer) diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 625dd7d2b6..360e3065f3 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -45,7 +45,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Self::enforce_assign_operation( cs, indicator, - format!("select {} {}:{}", new_value, &span.line, &span.start), + format!("select {} {}:{}", new_value, &span.line_start, &span.col_start), &statement.operation, resolved_assignee[0], new_value, @@ -62,7 +62,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Self::enforce_assign_operation( cs, indicator, - format!("select-splice {} {} {}:{}", i, new_value, &span.line, &span.start), + format!( + "select-splice {} {} {}:{}", + i, new_value, &span.line_start, &span.col_start + ), &statement.operation, old_ref, new_value, @@ -72,7 +75,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } _ => { return Err(StatementError::array_assign_range( - statement.span.clone().unwrap_or_default(), + &statement.span.clone().unwrap_or_default(), )); } }; @@ -97,9 +100,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { AssignOperation::Mul => enforce_mul(cs, target.clone(), new_value, span)?, AssignOperation::Div => enforce_div(cs, target.clone(), new_value, span)?, AssignOperation::Pow => enforce_pow(cs, target.clone(), new_value, span)?, + _ => unimplemented!("unimplemented assign operator"), }; let selected_value = ConstrainedValue::conditionally_select(cs.ns(|| scope), condition, &new_value, target) - .map_err(|_| StatementError::select_fail(new_value.to_string(), target.to_string(), span.clone()))?; + .map_err(|_| StatementError::select_fail(new_value.to_string(), target.to_string(), span))?; *target = selected_value; Ok(()) diff --git a/compiler/src/statement/assign/assignee.rs b/compiler/src/statement/assign/assignee.rs index 74bf99479f..9cb4497682 100644 --- a/compiler/src/statement/assign/assignee.rs +++ b/compiler/src/statement/assign/assignee.rs @@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let mut result = vec![match self.get_mut(variable.id) { Some(value) => value, - None => return Err(StatementError::undefined_variable(variable.name.to_string(), span)), + None => return Err(StatementError::undefined_variable(variable.name.to_string(), &span)), }]; for access in resolved_accesses { @@ -77,16 +77,12 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { start_index, stop_index, len, - span.clone(), + span, )) } else if start_index > len { - Err(StatementError::array_assign_index_bounds( - start_index, - len, - span.clone(), - )) + Err(StatementError::array_assign_index_bounds(start_index, len, span)) } else if stop_index > len { - Err(StatementError::array_assign_index_bounds(stop_index, len, span.clone())) + Err(StatementError::array_assign_index_bounds(stop_index, len, span)) } else { Ok(()) } @@ -101,21 +97,17 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { match access { ResolvedAssigneeAccess::ArrayIndex(index) => { if value.len() != 1 { - return Err(StatementError::array_assign_interior_index(span.clone())); + return Err(StatementError::array_assign_interior_index(span)); } match value.remove(0) { ConstrainedValue::Array(old) => { if index > old.len() { - Err(StatementError::array_assign_index_bounds( - index, - old.len(), - span.clone(), - )) + Err(StatementError::array_assign_index_bounds(index, old.len(), span)) } else { Ok(vec![old.get_mut(index).unwrap()]) } } - _ => Err(StatementError::array_assign_index(span.clone())), + _ => Err(StatementError::array_assign_index(span)), } } ResolvedAssigneeAccess::ArrayRange(start_index, stop_index) => { @@ -126,38 +118,38 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { match value.remove(0) { ConstrainedValue::Array(old) => { let stop_index = stop_index.unwrap_or(old.len()); - Self::check_range_index(start_index, stop_index, old.len(), &span)?; + Self::check_range_index(start_index, stop_index, old.len(), span)?; Ok(old[start_index..stop_index].iter_mut().collect()) } - _ => Err(StatementError::array_assign_index(span.clone())), + _ => Err(StatementError::array_assign_index(span)), } } else { // range of a range let stop_index = stop_index.unwrap_or(value.len()); - Self::check_range_index(start_index, stop_index, value.len(), &span)?; + Self::check_range_index(start_index, stop_index, value.len(), span)?; Ok(value.drain(start_index..stop_index).collect()) } } ResolvedAssigneeAccess::Tuple(index, span) => { if value.len() != 1 { - return Err(StatementError::array_assign_interior_index(span)); + return Err(StatementError::array_assign_interior_index(&span)); } match value.remove(0) { ConstrainedValue::Tuple(old) => { if index > old.len() { - Err(StatementError::tuple_assign_index_bounds(index, old.len(), span)) + Err(StatementError::tuple_assign_index_bounds(index, old.len(), &span)) } else { Ok(vec![&mut old[index]]) } } - _ => Err(StatementError::tuple_assign_index(span)), + _ => Err(StatementError::tuple_assign_index(&span)), } } ResolvedAssigneeAccess::Member(name) => { if value.len() != 1 { - return Err(StatementError::array_assign_interior_index(span.clone())); + return Err(StatementError::array_assign_interior_index(span)); } match value.remove(0) { ConstrainedValue::CircuitExpression(_variable, members) => { @@ -168,15 +160,12 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Some(member) => Ok(vec![&mut member.1]), None => { // Throw an error if the circuit variable does not exist in the circuit - Err(StatementError::undefined_circuit_variable( - name.to_string(), - span.to_owned(), - )) + Err(StatementError::undefined_circuit_variable(name.to_string(), span)) } } } // Throw an error if the circuit definition does not exist in the file - x => Err(StatementError::undefined_circuit(x.to_string(), span.to_owned())), + x => Err(StatementError::undefined_circuit(x.to_string(), span)), } } } diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index b7698b6109..f6d8f3b9fd 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -58,7 +58,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let inner_indicator = match self.enforce_expression(cs, statement.condition.get())? { ConstrainedValue::Boolean(resolved) => resolved, value => { - return Err(StatementError::conditional_boolean(value.to_string(), span)); + return Err(StatementError::conditional_boolean(value.to_string(), &span)); } }; @@ -70,11 +70,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { outer_indicator_string, inner_indicator_string ); let branch_1_indicator = Boolean::and( - &mut cs.ns(|| format!("branch 1 {} {}:{}", span.text, &span.line, &span.start)), + &mut cs.ns(|| format!("branch 1 {}:{}", &span.line_start, &span.col_start)), outer_indicator, &inner_indicator, ) - .map_err(|_| StatementError::indicator_calculation(branch_1_name, span.clone()))?; + .map_err(|_| StatementError::indicator_calculation(branch_1_name, &span))?; let mut results = vec![]; @@ -91,11 +91,11 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { outer_indicator_string, inner_indicator_string ); let branch_2_indicator = Boolean::and( - &mut cs.ns(|| format!("branch 2 {} {}:{}", span.text, &span.line, &span.start)), + &mut cs.ns(|| format!("branch 2 {}:{}", &span.line_start, &span.col_start)), &outer_indicator, &inner_indicator, ) - .map_err(|_| StatementError::indicator_calculation(branch_2_name, span.clone()))?; + .map_err(|_| StatementError::indicator_calculation(branch_2_name, &span))?; // Evaluate branch 2 let mut branch_2_result = match statement.next.get() { diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 96e53b9272..ca8e04d950 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -32,7 +32,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { return Err(StatementError::invalid_number_of_definitions( values.len(), variable_names.len(), - span.to_owned(), + span, )); } @@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { let values = match expression { // ConstrainedValue::Return(values) => values, ConstrainedValue::Tuple(values) => values, - value => return Err(StatementError::multiple_definition(value.to_string(), span)), + value => return Err(StatementError::multiple_definition(value.to_string(), &span)), }; self.enforce_multiple_definition(&statement.variables[..], values, &span) diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index 2a9f4c33c9..0dbd2a4916 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { // Evaluate statements and possibly return early let result = self.enforce_statement( - &mut cs.ns(|| format!("for loop iteration {} {}:{}", i, &span.line, &span.start)), + &mut cs.ns(|| format!("for loop iteration {} {}:{}", i, &span.line_start, &span.col_start)), indicator, statement.body.get(), )?; diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 786b4bf088..ab607b796e 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -79,17 +79,14 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } } _ => { - return Err(StatementError::unassigned( - statement.span.as_ref().map(|x| x.text.clone()).unwrap_or_default(), - statement.span.clone().unwrap_or_default(), - )); + return Err(StatementError::unassigned(&statement.span.clone().unwrap_or_default())); } } } Statement::Block(statement) => { let span = statement.span.clone().unwrap_or_default(); let result = self.evaluate_block( - &mut cs.ns(|| format!("block {}:{}", &span.line, &span.start)), + &mut cs.ns(|| format!("block {}:{}", &span.line_start, &span.col_start)), indicator, statement, )?; diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 28ccb53dfb..6512fd1e40 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -45,8 +45,7 @@ pub struct Address { impl Address { pub(crate) fn constant(address: String, span: &Span) -> Result { - let address = - AccountAddress::from_str(&address).map_err(|error| AddressError::account_error(error, span.to_owned()))?; + let address = AccountAddress::from_str(&address).map_err(|error| AddressError::account_error(error, span))?; let mut address_bytes = vec![]; address.write(&mut address_bytes).unwrap(); @@ -75,17 +74,17 @@ impl Address { if let InputValue::Address(string) = input { Some(string) } else { - return Err(AddressError::invalid_address(name.to_owned(), span.to_owned())); + return Err(AddressError::invalid_address(name.to_owned(), span)); } } None => None, }; let address = Address::alloc( - cs.ns(|| format!("`{}: address` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: address` {}:{}", name, span.line_start, span.col_start)), || address_value.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| AddressError::missing_address(span.to_owned()))?; + .map_err(|_| AddressError::missing_address(span))?; Ok(ConstrainedValue::Address(address)) } diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index 8caa9a8e3e..a8e6a9e3cb 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -35,10 +35,10 @@ pub(crate) fn allocate_bool>( span: &Span, ) -> Result { Boolean::alloc( - cs.ns(|| format!("`{}: bool` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: bool` {}:{}", name, span.line_start, span.col_start)), || option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| BooleanError::missing_boolean(format!("{}: bool", name), span.to_owned())) + .map_err(|_| BooleanError::missing_boolean(format!("{}: bool", name), span)) } pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( @@ -53,7 +53,7 @@ pub(crate) fn bool_from_input<'a, F: PrimeField, G: GroupType, CS: Constraint if let InputValue::Boolean(bool) = input { Some(bool) } else { - return Err(BooleanError::invalid_boolean(name.to_owned(), span.to_owned())); + return Err(BooleanError::invalid_boolean(name.to_owned(), span)); } } None => None, diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index db192bbad9..2152e7b379 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -57,10 +57,8 @@ impl FieldType { let number_info = number_string_typing(&string); let value = match number_info { - (number, neg) if neg => { - -F::from_str(&number).map_err(|_| FieldError::invalid_field(string, span.to_owned()))? - } - (number, _) => F::from_str(&number).map_err(|_| FieldError::invalid_field(string, span.to_owned()))?, + (number, neg) if neg => -F::from_str(&number).map_err(|_| FieldError::invalid_field(string, span))?, + (number, _) => F::from_str(&number).map_err(|_| FieldError::invalid_field(string, span))?, }; Ok(FieldType::Constant(value)) @@ -70,9 +68,7 @@ impl FieldType { match self { FieldType::Constant(field) => Ok(FieldType::Constant(field.neg())), FieldType::Allocated(field) => { - let result = field - .negate(cs) - .map_err(|e| FieldError::negate_operation(e, span.to_owned()))?; + let result = field.negate(cs).map_err(|e| FieldError::negate_operation(e, span))?; Ok(FieldType::Allocated(result)) } @@ -88,7 +84,7 @@ impl FieldType { (FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => { let result = self_value .add(cs, other_value) - .map_err(|e| FieldError::binary_operation("+".to_string(), e, span.to_owned()))?; + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?; Ok(FieldType::Allocated(result)) } @@ -97,7 +93,7 @@ impl FieldType { | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated( allocated_value .add_constant(cs, constant_value) - .map_err(|e| FieldError::binary_operation("+".to_string(), e, span.to_owned()))?, + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?, )), } } @@ -111,7 +107,7 @@ impl FieldType { (FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => { let result = self_value .sub(cs, other_value) - .map_err(|e| FieldError::binary_operation("-".to_string(), e, span.to_owned()))?; + .map_err(|e| FieldError::binary_operation("-".to_string(), e, span))?; Ok(FieldType::Allocated(result)) } @@ -120,7 +116,7 @@ impl FieldType { | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated( allocated_value .sub_constant(cs, constant_value) - .map_err(|e| FieldError::binary_operation("+".to_string(), e, span.to_owned()))?, + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?, )), } } @@ -134,7 +130,7 @@ impl FieldType { (FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => { let result = self_value .mul(cs, other_value) - .map_err(|e| FieldError::binary_operation("*".to_string(), e, span.to_owned()))?; + .map_err(|e| FieldError::binary_operation("*".to_string(), e, span))?; Ok(FieldType::Allocated(result)) } @@ -143,7 +139,7 @@ impl FieldType { | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated( allocated_value .mul_by_constant(cs, constant_value) - .map_err(|e| FieldError::binary_operation("*".to_string(), e, span.to_owned()))?, + .map_err(|e| FieldError::binary_operation("*".to_string(), e, span))?, )), } } @@ -153,14 +149,14 @@ impl FieldType { FieldType::Constant(constant) => { let constant_inverse = constant .inverse() - .ok_or_else(|| FieldError::no_inverse(constant.to_string(), span.to_owned()))?; + .ok_or_else(|| FieldError::no_inverse(constant.to_string(), span))?; FieldType::Constant(constant_inverse) } FieldType::Allocated(allocated) => { let allocated_inverse = allocated .inverse(&mut cs) - .map_err(|e| FieldError::binary_operation("+".to_string(), e, span.to_owned()))?; + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?; FieldType::Allocated(allocated_inverse) } diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index c5a55bfda0..a0119faaf9 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -37,19 +37,19 @@ pub(crate) fn allocate_field>( match number_info { (number, neg) if neg => FieldType::alloc( - cs.ns(|| format!("`{}: field` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: field` {}:{}", name, span.line_start, span.col_start)), || Some(number).ok_or(SynthesisError::AssignmentMissing), ) .map(|value| value.negate(cs, span)) - .map_err(|_| FieldError::missing_field(format!("{}: field", name), span.to_owned()))?, + .map_err(|_| FieldError::missing_field(format!("{}: field", name), span))?, (number, _) => FieldType::alloc( - cs.ns(|| format!("`{}: field` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: field` {}:{}", name, span.line_start, span.col_start)), || Some(number).ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| FieldError::missing_field(format!("{}: field", name), span.to_owned())), + .map_err(|_| FieldError::missing_field(format!("{}: field", name), span)), } } - None => Err(FieldError::missing_field(format!("{}: field", name), span.to_owned())), + None => Err(FieldError::missing_field(format!("{}: field", name), span)), } } @@ -65,7 +65,7 @@ pub(crate) fn field_from_input<'a, F: PrimeField, G: GroupType, CS: Constrain if let InputValue::Field(string) = input { Some(string) } else { - return Err(FieldError::invalid_field(input.to_string(), span.to_owned())); + return Err(FieldError::invalid_field(input.to_string(), span)); } } None => None, diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 32e6c90edc..772ee90eea 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -30,10 +30,10 @@ pub(crate) fn allocate_group, CS: ConstraintSyste span: &Span, ) -> Result { G::alloc( - cs.ns(|| format!("`{}: group` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: group` {}:{}", name, span.line_start, span.col_start)), || option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| GroupError::missing_group(format!("{}: group", name), span.to_owned())) + .map_err(|_| GroupError::missing_group(format!("{}: group", name), span)) } pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( @@ -48,7 +48,7 @@ pub(crate) fn group_from_input<'a, F: PrimeField, G: GroupType, CS: Constrain if let InputValue::Group(string) = input { Some(string) } else { - return Err(GroupError::invalid_group(input.to_string(), span.to_owned())); + return Err(GroupError::invalid_group(input.to_string(), span)); } } None => None, diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index b9176f90f3..a69d771bb8 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -59,9 +59,9 @@ impl GroupType for EdwardsGroupType { } fn to_allocated>(&self, mut cs: CS, span: &Span) -> Result { - self.allocated(cs.ns(|| format!("allocate affine point {}:{}", span.line, span.start))) + self.allocated(cs.ns(|| format!("allocate affine point {}:{}", span.line_start, span.col_start))) .map(|ebg| EdwardsGroupType::Allocated(Box::new(ebg))) - .map_err(|error| GroupError::synthesis_error(error, span.to_owned())) + .map_err(|error| GroupError::synthesis_error(error, span)) } fn negate>(&self, cs: CS, span: &Span) -> Result { @@ -69,7 +69,7 @@ impl GroupType for EdwardsGroupType { EdwardsGroupType::Constant(group) => Ok(EdwardsGroupType::Constant(group.neg())), EdwardsGroupType::Allocated(group) => { let result = , Fq>>::negate(group, cs) - .map_err(|e| GroupError::negate_operation(e, span.to_owned()))?; + .map_err(|e| GroupError::negate_operation(e, span))?; Ok(EdwardsGroupType::Allocated(Box::new(result))) } @@ -88,7 +88,7 @@ impl GroupType for EdwardsGroupType { cs, other_value, ) - .map_err(|e| GroupError::binary_operation("+".to_string(), e, span.to_owned()))?; + .map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?; Ok(EdwardsGroupType::Allocated(Box::new(result))) } @@ -98,7 +98,7 @@ impl GroupType for EdwardsGroupType { Ok(EdwardsGroupType::Allocated(Box::new( allocated_value .add_constant(cs, constant_value) - .map_err(|e| GroupError::binary_operation("+".to_string(), e, span.to_owned()))?, + .map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?, ))) } } @@ -116,7 +116,7 @@ impl GroupType for EdwardsGroupType { cs, other_value, ) - .map_err(|e| GroupError::binary_operation("-".to_string(), e, span.to_owned()))?; + .map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?; Ok(EdwardsGroupType::Allocated(Box::new(result))) } @@ -126,7 +126,7 @@ impl GroupType for EdwardsGroupType { Ok(EdwardsGroupType::Allocated(Box::new( allocated_value .sub_constant(cs, constant_value) - .map_err(|e| GroupError::binary_operation("-".to_string(), e, span.to_owned()))?, + .map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?, ))) } } @@ -149,10 +149,8 @@ impl EdwardsGroupType { } else { let one = edwards_affine_one(); let number_value = match number_info { - (number, neg) if neg => { - -Fp256::from_str(&number).map_err(|_| GroupError::n_group(number, span.clone()))? - } - (number, _) => Fp256::from_str(&number).map_err(|_| GroupError::n_group(number, span.clone()))?, + (number, neg) if neg => -Fp256::from_str(&number).map_err(|_| GroupError::n_group(number, span))?, + (number, _) => Fp256::from_str(&number).map_err(|_| GroupError::n_group(number, span))?, }; let result: EdwardsAffine = one.mul(&number_value); @@ -203,7 +201,7 @@ impl EdwardsGroupType { Self::edwards_affine_from_y_str(number_string_typing(&y_string), span, None, span) } // Invalid - (x, y) => Err(GroupError::invalid_group(format!("({}, {})", x, y), span.clone())), + (x, y) => Err(GroupError::invalid_group(format!("({}, {})", x, y), span)), } } @@ -214,14 +212,14 @@ impl EdwardsGroupType { element_span: &Span, ) -> Result { let x = match x_info { - (x_str, neg) if neg => -Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str, x_span.clone()))?, - (x_str, _) => Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str, x_span.clone()))?, + (x_str, neg) if neg => -Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str, x_span))?, + (x_str, _) => Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str, x_span))?, }; match greatest { // Sign provided Some(greatest) => { - EdwardsAffine::from_x_coordinate(x, greatest).ok_or_else(|| GroupError::x_recover(element_span.clone())) + EdwardsAffine::from_x_coordinate(x, greatest).ok_or_else(|| GroupError::x_recover(element_span)) } // Sign inferred None => { @@ -236,7 +234,7 @@ impl EdwardsGroupType { } // Otherwise return error. - Err(GroupError::x_recover(element_span.clone())) + Err(GroupError::x_recover(element_span)) } } } @@ -248,14 +246,14 @@ impl EdwardsGroupType { element_span: &Span, ) -> Result { let y = match y_info { - (y_str, neg) if neg => -Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str, y_span.clone()))?, - (y_str, _) => Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str, y_span.clone()))?, + (y_str, neg) if neg => -Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str, y_span))?, + (y_str, _) => Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str, y_span))?, }; match greatest { // Sign provided Some(greatest) => { - EdwardsAffine::from_y_coordinate(y, greatest).ok_or_else(|| GroupError::y_recover(element_span.clone())) + EdwardsAffine::from_y_coordinate(y, greatest).ok_or_else(|| GroupError::y_recover(element_span)) } // Sign inferred None => { @@ -270,7 +268,7 @@ impl EdwardsGroupType { } // Otherwise return error. - Err(GroupError::y_recover(element_span.clone())) + Err(GroupError::y_recover(element_span)) } } } @@ -284,16 +282,16 @@ impl EdwardsGroupType { ) -> Result { let x = match x_info { (x_str, neg) if neg => { - -Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str.to_string(), x_span.clone()))? + -Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str.to_string(), x_span))? } - (x_str, _) => Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str.to_string(), x_span.clone()))?, + (x_str, _) => Fq::from_str(&x_str).map_err(|_| GroupError::x_invalid(x_str.to_string(), x_span))?, }; let y = match y_info { (y_str, neg) if neg => { - -Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str.to_string(), y_span.clone()))? + -Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str.to_string(), y_span))? } - (y_str, _) => Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str.to_string(), y_span.clone()))?, + (y_str, _) => Fq::from_str(&y_str).map_err(|_| GroupError::y_invalid(y_str.to_string(), y_span))?, }; let element = EdwardsAffine::new(x, y); @@ -301,7 +299,7 @@ impl EdwardsGroupType { if element.is_on_curve() { Ok(element) } else { - Err(GroupError::not_on_curve(element.to_string(), element_span.clone())) + Err(GroupError::not_on_curve(element.to_string(), element_span)) } } diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 51b2a7c848..513106d8a4 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -93,6 +93,26 @@ impl Integer { match_integer!(integer => integer.get_bits()) } + // pub fn get_bits_typed(&self) -> (Vec, IntegerType) { + // let integer = self; + // (match_integer!(integer => integer.to_bits_le()), self.get_type()) + // } + + // pub fn from_bits_typed(type_: &IntegerType, bits: &[Boolean]) -> Integer { + // match type_ { + // IntegerType::U8 => Integer::U8(UInt8::from_bits_le(bits)), + // IntegerType::U16 => Integer::U16(UInt16::from_bits_le(bits)), + // IntegerType::U32 => Integer::U32(UInt32::from_bits_le(bits)), + // IntegerType::U64 => Integer::U64(UInt64::from_bits_le(bits)), + // IntegerType::U128 => Integer::U128(UInt128::from_bits_le(bits)), + // IntegerType::I8 => Integer::I8(Int8::from_bits_le(bits)), + // IntegerType::I16 => Integer::I16(Int16::from_bits_le(bits)), + // IntegerType::I32 => Integer::I32(Int32::from_bits_le(bits)), + // IntegerType::I64 => Integer::I64(Int64::from_bits_le(bits)), + // IntegerType::I128 => Integer::I128(Int128::from_bits_le(bits)), + // } + // } + pub fn get_value(&self) -> Option { let integer = self; match_integer!(integer => integer.get_value()) @@ -102,10 +122,10 @@ impl Integer { let unsigned_integer = self; let value_option: Option = match_unsigned_integer!(unsigned_integer => unsigned_integer.get_value()); - let value = value_option.ok_or_else(|| IntegerError::invalid_index(span.to_owned()))?; + let value = value_option.ok_or_else(|| IntegerError::invalid_index(span))?; let value_usize = value .parse::() - .map_err(|_| IntegerError::invalid_integer(value, span.to_owned()))?; + .map_err(|_| IntegerError::invalid_integer(value, span))?; Ok(value_usize) } @@ -136,70 +156,71 @@ impl Integer { IntegerType::U8 => { let u8_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); - let u8_result = UInt8::alloc(cs.ns(|| format!("`{}: u8` {}:{}", name, span.line, span.start)), || { - u8_option.ok_or(SynthesisError::AssignmentMissing) - }) - .map_err(|_| IntegerError::missing_integer(format!("{}: u8", name), span.to_owned()))?; + let u8_result = UInt8::alloc( + cs.ns(|| format!("`{}: u8` {}:{}", name, span.line_start, span.col_start)), + || u8_option.ok_or(SynthesisError::AssignmentMissing), + ) + .map_err(|_| IntegerError::missing_integer(format!("{}: u8", name), span))?; Integer::U8(u8_result) } IntegerType::U16 => { let u16_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let u16_result = UInt16::alloc( - cs.ns(|| format!("`{}: u16` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: u16` {}:{}", name, span.line_start, span.col_start)), || u16_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: u16", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: u16", name), span))?; Integer::U16(u16_result) } IntegerType::U32 => { let u32_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let u32_result = UInt32::alloc( - cs.ns(|| format!("`{}: u32` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: u32` {}:{}", name, span.line_start, span.col_start)), || u32_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: u32", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: u32", name), span))?; Integer::U32(u32_result) } IntegerType::U64 => { let u64_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let u64_result = UInt64::alloc( - cs.ns(|| format!("`{}: u64` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: u64` {}:{}", name, span.line_start, span.col_start)), || u64_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: u64", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: u64", name), span))?; Integer::U64(u64_result) } IntegerType::U128 => { let u128_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let u128_result = UInt128::alloc( - cs.ns(|| format!("`{}: u128` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: u128` {}:{}", name, span.line_start, span.col_start)), || u128_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: u128", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: u128", name), span))?; Integer::U128(u128_result) } @@ -207,69 +228,70 @@ impl Integer { IntegerType::I8 => { let i8_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); - let i8_result = Int8::alloc(cs.ns(|| format!("`{}: i8` {}:{}", name, span.line, span.start)), || { - i8_option.ok_or(SynthesisError::AssignmentMissing) - }) - .map_err(|_| IntegerError::missing_integer(format!("{}: i8", name), span.to_owned()))?; + let i8_result = Int8::alloc( + cs.ns(|| format!("`{}: i8` {}:{}", name, span.line_start, span.col_start)), + || i8_option.ok_or(SynthesisError::AssignmentMissing), + ) + .map_err(|_| IntegerError::missing_integer(format!("{}: i8", name), span))?; Integer::I8(i8_result) } IntegerType::I16 => { let i16_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let i16_result = Int16::alloc( - cs.ns(|| format!("`{}: i16` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: i16` {}:{}", name, span.line_start, span.col_start)), || i16_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: i16", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: i16", name), span))?; Integer::I16(i16_result) } IntegerType::I32 => { let i32_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let i32_result = Int32::alloc( - cs.ns(|| format!("`{}: i32` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: i32` {}:{}", name, span.line_start, span.col_start)), || i32_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: i32", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: i32", name), span))?; Integer::I32(i32_result) } IntegerType::I64 => { let i64_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let i64_result = Int64::alloc( - cs.ns(|| format!("`{}: i64` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: i64` {}:{}", name, span.line_start, span.col_start)), || i64_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: i64", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: i64", name), span))?; Integer::I64(i64_result) } IntegerType::I128 => { let i128_option = option.map(|s| { s.parse::() - .map_err(|_| IntegerError::invalid_integer(s, span.to_owned())) + .map_err(|_| IntegerError::invalid_integer(s, span)) .unwrap() }); let i128_result = Int128::alloc( - cs.ns(|| format!("`{}: i128` {}:{}", name, span.line, span.start)), + cs.ns(|| format!("`{}: i128` {}:{}", name, span.line_start, span.col_start)), || i128_option.ok_or(SynthesisError::AssignmentMissing), ) - .map_err(|_| IntegerError::missing_integer(format!("{}: i128", name), span.to_owned()))?; + .map_err(|_| IntegerError::missing_integer(format!("{}: i128", name), span))?; Integer::I128(i128_result) } @@ -289,7 +311,7 @@ impl Integer { if let InputValue::Integer(_type_, number) = input { Some(number) } else { - return Err(IntegerError::invalid_integer(input.to_string(), span.to_owned())); + return Err(IntegerError::invalid_integer(input.to_string(), span)); } } None => None, @@ -303,13 +325,13 @@ impl Integer { cs: &mut CS, span: &Span, ) -> Result { - let unique_namespace = format!("enforce -{} {}:{}", self, span.line, span.start); + let unique_namespace = format!("enforce -{} {}:{}", self, span.line_start, span.col_start); let a = self; let result = match_signed_integer!(a, span => a.neg(cs.ns(|| unique_namespace))); - result.ok_or_else(|| IntegerError::negate_operation(span.to_owned())) + result.ok_or_else(|| IntegerError::negate_operation(span)) } pub fn add>( @@ -318,14 +340,14 @@ impl Integer { other: Self, span: &Span, ) -> Result { - let unique_namespace = format!("enforce {} + {} {}:{}", self, other, span.line, span.start); + let unique_namespace = format!("enforce {} + {} {}:{}", self, other, span.line_start, span.col_start); let a = self; let b = other; let result = match_integers_span!((a, b), span => a.add(cs.ns(|| unique_namespace), &b)); - result.ok_or_else(|| IntegerError::binary_operation("+".to_string(), span.to_owned())) + result.ok_or_else(|| IntegerError::binary_operation("+".to_string(), span)) } pub fn sub>( @@ -334,14 +356,14 @@ impl Integer { other: Self, span: &Span, ) -> Result { - let unique_namespace = format!("enforce {} - {} {}:{}", self, other, span.line, span.start); + let unique_namespace = format!("enforce {} - {} {}:{}", self, other, span.line_start, span.col_start); let a = self; let b = other; let result = match_integers_span!((a, b), span => a.sub(cs.ns(|| unique_namespace), &b)); - result.ok_or_else(|| IntegerError::binary_operation("-".to_string(), span.to_owned())) + result.ok_or_else(|| IntegerError::binary_operation("-".to_string(), span)) } pub fn mul>( @@ -350,14 +372,14 @@ impl Integer { other: Self, span: &Span, ) -> Result { - let unique_namespace = format!("enforce {} * {} {}:{}", self, other, span.line, span.start); + let unique_namespace = format!("enforce {} * {} {}:{}", self, other, span.line_start, span.col_start); let a = self; let b = other; let result = match_integers_span!((a, b), span => a.mul(cs.ns(|| unique_namespace), &b)); - result.ok_or_else(|| IntegerError::binary_operation("*".to_string(), span.to_owned())) + result.ok_or_else(|| IntegerError::binary_operation("*".to_string(), span)) } pub fn div>( @@ -366,14 +388,14 @@ impl Integer { other: Self, span: &Span, ) -> Result { - let unique_namespace = format!("enforce {} ÷ {} {}:{}", self, other, span.line, span.start); + let unique_namespace = format!("enforce {} ÷ {} {}:{}", self, other, span.line_start, span.col_start); let a = self; let b = other; let result = match_integers_span!((a, b), span => a.div(cs.ns(|| unique_namespace), &b)); - result.ok_or_else(|| IntegerError::binary_operation("÷".to_string(), span.to_owned())) + result.ok_or_else(|| IntegerError::binary_operation("÷".to_string(), span)) } pub fn pow>( @@ -382,14 +404,14 @@ impl Integer { other: Self, span: &Span, ) -> Result { - let unique_namespace = format!("enforce {} ** {} {}:{}", self, other, span.line, span.start); + let unique_namespace = format!("enforce {} ** {} {}:{}", self, other, span.line_start, span.col_start); let a = self; let b = other; let result = match_integers_span!((a, b), span => a.pow(cs.ns(|| unique_namespace), &b)); - result.ok_or_else(|| IntegerError::binary_operation("**".to_string(), span.to_owned())) + result.ok_or_else(|| IntegerError::binary_operation("**".to_string(), span)) } } diff --git a/compiler/src/value/integer/macros.rs b/compiler/src/value/integer/macros.rs index cb6eb81f8c..a9e7e9b9b8 100644 --- a/compiler/src/value/integer/macros.rs +++ b/compiler/src/value/integer/macros.rs @@ -84,21 +84,11 @@ macro_rules! match_unsigned_integer { macro_rules! match_signed_integer { ($integer: ident, $span: ident => $expression: expr) => { match $integer { - Integer::I8($integer) => Some(Integer::I8( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - Integer::I16($integer) => Some(Integer::I16( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - Integer::I32($integer) => Some(Integer::I32( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - Integer::I64($integer) => Some(Integer::I64( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - Integer::I128($integer) => Some(Integer::I128( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), + Integer::I8($integer) => Some(Integer::I8($expression.map_err(|e| IntegerError::signed(e, $span))?)), + Integer::I16($integer) => Some(Integer::I16($expression.map_err(|e| IntegerError::signed(e, $span))?)), + Integer::I32($integer) => Some(Integer::I32($expression.map_err(|e| IntegerError::signed(e, $span))?)), + Integer::I64($integer) => Some(Integer::I64($expression.map_err(|e| IntegerError::signed(e, $span))?)), + Integer::I128($integer) => Some(Integer::I128($expression.map_err(|e| IntegerError::signed(e, $span))?)), _ => None, } @@ -129,37 +119,37 @@ macro_rules! match_integers { macro_rules! match_integers_span { (($a: ident, $b: ident), $span: ident => $expression:expr) => { match ($a, $b) { - (Integer::U8($a), Integer::U8($b)) => Some(Integer::U8( - $expression.map_err(|e| IntegerError::synthesis(e, $span.to_owned()))?, - )), + (Integer::U8($a), Integer::U8($b)) => { + Some(Integer::U8($expression.map_err(|e| IntegerError::synthesis(e, $span))?)) + } (Integer::U16($a), Integer::U16($b)) => Some(Integer::U16( - $expression.map_err(|e| IntegerError::synthesis(e, $span.to_owned()))?, + $expression.map_err(|e| IntegerError::synthesis(e, $span))?, )), (Integer::U32($a), Integer::U32($b)) => Some(Integer::U32( - $expression.map_err(|e| IntegerError::synthesis(e, $span.to_owned()))?, + $expression.map_err(|e| IntegerError::synthesis(e, $span))?, )), (Integer::U64($a), Integer::U64($b)) => Some(Integer::U64( - $expression.map_err(|e| IntegerError::synthesis(e, $span.to_owned()))?, + $expression.map_err(|e| IntegerError::synthesis(e, $span))?, )), (Integer::U128($a), Integer::U128($b)) => Some(Integer::U128( - $expression.map_err(|e| IntegerError::synthesis(e, $span.to_owned()))?, + $expression.map_err(|e| IntegerError::synthesis(e, $span))?, )), - (Integer::I8($a), Integer::I8($b)) => Some(Integer::I8( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - (Integer::I16($a), Integer::I16($b)) => Some(Integer::I16( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - (Integer::I32($a), Integer::I32($b)) => Some(Integer::I32( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - (Integer::I64($a), Integer::I64($b)) => Some(Integer::I64( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), - (Integer::I128($a), Integer::I128($b)) => Some(Integer::I128( - $expression.map_err(|e| IntegerError::signed(e, $span.to_owned()))?, - )), + (Integer::I8($a), Integer::I8($b)) => { + Some(Integer::I8($expression.map_err(|e| IntegerError::signed(e, $span))?)) + } + (Integer::I16($a), Integer::I16($b)) => { + Some(Integer::I16($expression.map_err(|e| IntegerError::signed(e, $span))?)) + } + (Integer::I32($a), Integer::I32($b)) => { + Some(Integer::I32($expression.map_err(|e| IntegerError::signed(e, $span))?)) + } + (Integer::I64($a), Integer::I64($b)) => { + Some(Integer::I64($expression.map_err(|e| IntegerError::signed(e, $span))?)) + } + (Integer::I128($a), Integer::I128($b)) => { + Some(Integer::I128($expression.map_err(|e| IntegerError::signed(e, $span))?)) + } (_, _) => None, } }; diff --git a/compiler/tests/group/mod.rs b/compiler/tests/group/mod.rs index d7fca2a4cd..f40cad73f6 100644 --- a/compiler/tests/group/mod.rs +++ b/compiler/tests/group/mod.rs @@ -39,8 +39,8 @@ pub fn group_element_to_input_value(g: EdwardsAffine) -> GroupValue { }; GroupValue::Tuple(GroupTuple { - x: GroupCoordinate::Number(x, fake_span.clone()), - y: GroupCoordinate::Number(y, fake_span.clone()), + x: GroupCoordinate::Number(x, fake_span), + y: GroupCoordinate::Number(y, fake_span), span: fake_span, }) } diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index ded55960bb..f99527b1c6 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -33,6 +33,23 @@ fn test_let_mut() { assert_satisfied(program); } +#[test] +fn test_cond_mut() { + let program_string = r#" + function main() { + let mut x = 100i8; + if false { + x = 1i8; + x *= 100i8; + } + console.assert(x == 100); + } + "#; + let program = parse_program(program_string).unwrap(); + + assert_satisfied(program); +} + #[test] fn test_let_mut_nested() { let program_string = include_str!("let_mut_nested.leo"); diff --git a/compiler/tests/syntax/mod.rs b/compiler/tests/syntax/mod.rs index 2fb1a100ea..009835c15d 100644 --- a/compiler/tests/syntax/mod.rs +++ b/compiler/tests/syntax/mod.rs @@ -16,7 +16,6 @@ use crate::{expect_asg_error, parse_input, parse_program}; use leo_compiler::errors::CompilerError; -use leo_grammar::ParserError; use leo_input::InputParserError; pub mod identifiers; @@ -28,7 +27,7 @@ fn test_semicolon() { let error = parse_program(program_string).err().unwrap(); match error { - CompilerError::ParserError(ParserError::SyntaxError(_)) => {} + CompilerError::SyntaxError(_) => {} _ => panic!("test_semicolon failed the wrong expected error, should be a ParserError"), } } diff --git a/grammar/LICENSE.md b/grammar/LICENSE.md deleted file mode 100644 index b95c626e2a..0000000000 --- a/grammar/LICENSE.md +++ /dev/null @@ -1,596 +0,0 @@ -GNU General Public License -========================== - -Version 3, 29 June 2007 - -Copyright © 2007 Free Software Foundation, Inc. <> - -Everyone is permitted to copy and distribute verbatim copies of this license -document, but changing it is not allowed. - -## Preamble - -The GNU General Public License is a free, copyleft license for software and other -kinds of works. - -The licenses for most software and other practical works are designed to take away -your freedom to share and change the works. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change all versions of a -program--to make sure it remains free software for all its users. We, the Free -Software Foundation, use the GNU General Public License for most of our software; it -applies also to any other work released this way by its authors. You can apply it to -your programs, too. - -When we speak of free software, we are referring to freedom, not price. Our General -Public Licenses are designed to make sure that you have the freedom to distribute -copies of free software (and charge for them if you wish), that you receive source -code or can get it if you want it, that you can change the software or use pieces of -it in new free programs, and that you know you can do these things. - -To protect your rights, we need to prevent others from denying you these rights or -asking you to surrender the rights. Therefore, you have certain responsibilities if -you distribute copies of the software, or if you modify it: responsibilities to -respect the freedom of others. - -For example, if you distribute copies of such a program, whether gratis or for a fee, -you must pass on to the recipients the same freedoms that you received. You must make -sure that they, too, receive or can get the source code. And you must show them these -terms so they know their rights. - -Developers that use the GNU GPL protect your rights with two steps: **(1)** assert -copyright on the software, and **(2)** offer you this License giving you legal permission -to copy, distribute and/or modify it. - -For the developers' and authors' protection, the GPL clearly explains that there is -no warranty for this free software. For both users' and authors' sake, the GPL -requires that modified versions be marked as changed, so that their problems will not -be attributed erroneously to authors of previous versions. - -Some devices are designed to deny users access to install or run modified versions of -the software inside them, although the manufacturer can do so. This is fundamentally -incompatible with the aim of protecting users' freedom to change the software. The -systematic pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we have designed -this version of the GPL to prohibit the practice for those products. If such problems -arise substantially in other domains, we stand ready to extend this provision to -those domains in future versions of the GPL, as needed to protect the freedom of -users. - -Finally, every program is threatened constantly by software patents. States should -not allow patents to restrict development and use of software on general-purpose -computers, but in those that do, we wish to avoid the special danger that patents -applied to a free program could make it effectively proprietary. To prevent this, the -GPL assures that patents cannot be used to render the program non-free. - -The precise terms and conditions for copying, distribution and modification follow. - -## TERMS AND CONDITIONS - -### 0. Definitions - -“This License” refers to version 3 of the GNU General Public License. - -“Copyright” also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - -“The Program” refers to any copyrightable work licensed under this -License. Each licensee is addressed as “you”. “Licensees” and -“recipients” may be individuals or organizations. - -To “modify” a work means to copy from or adapt all or part of the work in -a fashion requiring copyright permission, other than the making of an exact copy. The -resulting work is called a “modified version” of the earlier work or a -work “based on” the earlier work. - -A “covered work” means either the unmodified Program or a work based on -the Program. - -To “propagate” a work means to do anything with it that, without -permission, would make you directly or secondarily liable for infringement under -applicable copyright law, except executing it on a computer or modifying a private -copy. Propagation includes copying, distribution (with or without modification), -making available to the public, and in some countries other activities as well. - -To “convey” a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through a computer -network, with no transfer of a copy, is not conveying. - -An interactive user interface displays “Appropriate Legal Notices” to the -extent that it includes a convenient and prominently visible feature that **(1)** -displays an appropriate copyright notice, and **(2)** tells the user that there is no -warranty for the work (except to the extent that warranties are provided), that -licensees may convey the work under this License, and how to view a copy of this -License. If the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - -### 1. Source Code - -The “source code” for a work means the preferred form of the work for -making modifications to it. “Object code” means any non-source form of a -work. - -A “Standard Interface” means an interface that either is an official -standard defined by a recognized standards body, or, in the case of interfaces -specified for a particular programming language, one that is widely used among -developers working in that language. - -The “System Libraries” of an executable work include anything, other than -the work as a whole, that **(a)** is included in the normal form of packaging a Major -Component, but which is not part of that Major Component, and **(b)** serves only to -enable use of the work with that Major Component, or to implement a Standard -Interface for which an implementation is available to the public in source code form. -A “Major Component”, in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system (if any) on which -the executable work runs, or a compiler used to produce the work, or an object code -interpreter used to run it. - -The “Corresponding Source” for a work in object code form means all the -source code needed to generate, install, and (for an executable work) run the object -code and to modify the work, including scripts to control those activities. However, -it does not include the work's System Libraries, or general-purpose tools or -generally available free programs which are used unmodified in performing those -activities but which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for the work, and -the source code for shared libraries and dynamically linked subprograms that the work -is specifically designed to require, such as by intimate data communication or -control flow between those subprograms and other parts of the work. - -The Corresponding Source need not include anything that users can regenerate -automatically from other parts of the Corresponding Source. - -The Corresponding Source for a work in source code form is that same work. - -### 2. Basic Permissions - -All rights granted under this License are granted for the term of copyright on the -Program, and are irrevocable provided the stated conditions are met. This License -explicitly affirms your unlimited permission to run the unmodified Program. The -output from running a covered work is covered by this License only if the output, -given its content, constitutes a covered work. This License acknowledges your rights -of fair use or other equivalent, as provided by copyright law. - -You may make, run and propagate covered works that you do not convey, without -conditions so long as your license otherwise remains in force. You may convey covered -works to others for the sole purpose of having them make modifications exclusively -for you, or provide you with facilities for running those works, provided that you -comply with the terms of this License in conveying all material for which you do not -control copyright. Those thus making or running the covered works for you must do so -exclusively on your behalf, under your direction and control, on terms that prohibit -them from making any copies of your copyrighted material outside their relationship -with you. - -Conveying under any other circumstances is permitted solely under the conditions -stated below. Sublicensing is not allowed; section 10 makes it unnecessary. - -### 3. Protecting Users' Legal Rights From Anti-Circumvention Law - -No covered work shall be deemed part of an effective technological measure under any -applicable law fulfilling obligations under article 11 of the WIPO copyright treaty -adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention -of such measures. - -When you convey a covered work, you waive any legal power to forbid circumvention of -technological measures to the extent such circumvention is effected by exercising -rights under this License with respect to the covered work, and you disclaim any -intention to limit operation or modification of the work as a means of enforcing, -against the work's users, your or third parties' legal rights to forbid circumvention -of technological measures. - -### 4. Conveying Verbatim Copies - -You may convey verbatim copies of the Program's source code as you receive it, in any -medium, provided that you conspicuously and appropriately publish on each copy an -appropriate copyright notice; keep intact all notices stating that this License and -any non-permissive terms added in accord with section 7 apply to the code; keep -intact all notices of the absence of any warranty; and give all recipients a copy of -this License along with the Program. - -You may charge any price or no price for each copy that you convey, and you may offer -support or warranty protection for a fee. - -### 5. Conveying Modified Source Versions - -You may convey a work based on the Program, or the modifications to produce it from -the Program, in the form of source code under the terms of section 4, provided that -you also meet all of these conditions: - -* **a)** The work must carry prominent notices stating that you modified it, and giving a -relevant date. -* **b)** The work must carry prominent notices stating that it is released under this -License and any conditions added under section 7. This requirement modifies the -requirement in section 4 to “keep intact all notices”. -* **c)** You must license the entire work, as a whole, under this License to anyone who -comes into possession of a copy. This License will therefore apply, along with any -applicable section 7 additional terms, to the whole of the work, and all its parts, -regardless of how they are packaged. This License gives no permission to license the -work in any other way, but it does not invalidate such permission if you have -separately received it. -* **d)** If the work has interactive user interfaces, each must display Appropriate Legal -Notices; however, if the Program has interactive interfaces that do not display -Appropriate Legal Notices, your work need not make them do so. - -A compilation of a covered work with other separate and independent works, which are -not by their nature extensions of the covered work, and which are not combined with -it such as to form a larger program, in or on a volume of a storage or distribution -medium, is called an “aggregate” if the compilation and its resulting -copyright are not used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work in an aggregate -does not cause this License to apply to the other parts of the aggregate. - -### 6. Conveying Non-Source Forms - -You may convey a covered work in object code form under the terms of sections 4 and -5, provided that you also convey the machine-readable Corresponding Source under the -terms of this License, in one of these ways: - -* **a)** Convey the object code in, or embodied in, a physical product (including a -physical distribution medium), accompanied by the Corresponding Source fixed on a -durable physical medium customarily used for software interchange. -* **b)** Convey the object code in, or embodied in, a physical product (including a -physical distribution medium), accompanied by a written offer, valid for at least -three years and valid for as long as you offer spare parts or customer support for -that product model, to give anyone who possesses the object code either **(1)** a copy of -the Corresponding Source for all the software in the product that is covered by this -License, on a durable physical medium customarily used for software interchange, for -a price no more than your reasonable cost of physically performing this conveying of -source, or **(2)** access to copy the Corresponding Source from a network server at no -charge. -* **c)** Convey individual copies of the object code with a copy of the written offer to -provide the Corresponding Source. This alternative is allowed only occasionally and -noncommercially, and only if you received the object code with such an offer, in -accord with subsection 6b. -* **d)** Convey the object code by offering access from a designated place (gratis or for -a charge), and offer equivalent access to the Corresponding Source in the same way -through the same place at no further charge. You need not require recipients to copy -the Corresponding Source along with the object code. If the place to copy the object -code is a network server, the Corresponding Source may be on a different server -(operated by you or a third party) that supports equivalent copying facilities, -provided you maintain clear directions next to the object code saying where to find -the Corresponding Source. Regardless of what server hosts the Corresponding Source, -you remain obligated to ensure that it is available for as long as needed to satisfy -these requirements. -* **e)** Convey the object code using peer-to-peer transmission, provided you inform -other peers where the object code and Corresponding Source of the work are being -offered to the general public at no charge under subsection 6d. - -A separable portion of the object code, whose source code is excluded from the -Corresponding Source as a System Library, need not be included in conveying the -object code work. - -A “User Product” is either **(1)** a “consumer product”, which -means any tangible personal property which is normally used for personal, family, or -household purposes, or **(2)** anything designed or sold for incorporation into a -dwelling. In determining whether a product is a consumer product, doubtful cases -shall be resolved in favor of coverage. For a particular product received by a -particular user, “normally used” refers to a typical or common use of -that class of product, regardless of the status of the particular user or of the way -in which the particular user actually uses, or expects or is expected to use, the -product. A product is a consumer product regardless of whether the product has -substantial commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - -“Installation Information” for a User Product means any methods, -procedures, authorization keys, or other information required to install and execute -modified versions of a covered work in that User Product from a modified version of -its Corresponding Source. The information must suffice to ensure that the continued -functioning of the modified object code is in no case prevented or interfered with -solely because modification has been made. - -If you convey an object code work under this section in, or with, or specifically for -use in, a User Product, and the conveying occurs as part of a transaction in which -the right of possession and use of the User Product is transferred to the recipient -in perpetuity or for a fixed term (regardless of how the transaction is -characterized), the Corresponding Source conveyed under this section must be -accompanied by the Installation Information. But this requirement does not apply if -neither you nor any third party retains the ability to install modified object code -on the User Product (for example, the work has been installed in ROM). - -The requirement to provide Installation Information does not include a requirement to -continue to provide support service, warranty, or updates for a work that has been -modified or installed by the recipient, or for the User Product in which it has been -modified or installed. Access to a network may be denied when the modification itself -materially and adversely affects the operation of the network or violates the rules -and protocols for communication across the network. - -Corresponding Source conveyed, and Installation Information provided, in accord with -this section must be in a format that is publicly documented (and with an -implementation available to the public in source code form), and must require no -special password or key for unpacking, reading or copying. - -### 7. Additional Terms - -“Additional permissions” are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. Additional -permissions that are applicable to the entire Program shall be treated as though they -were included in this License, to the extent that they are valid under applicable -law. If additional permissions apply only to part of the Program, that part may be -used separately under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - -When you convey a copy of a covered work, you may at your option remove any -additional permissions from that copy, or from any part of it. (Additional -permissions may be written to require their own removal in certain cases when you -modify the work.) You may place additional permissions on material, added by you to a -covered work, for which you have or can give appropriate copyright permission. - -Notwithstanding any other provision of this License, for material you add to a -covered work, you may (if authorized by the copyright holders of that material) -supplement the terms of this License with terms: - -* **a)** Disclaiming warranty or limiting liability differently from the terms of -sections 15 and 16 of this License; or -* **b)** Requiring preservation of specified reasonable legal notices or author -attributions in that material or in the Appropriate Legal Notices displayed by works -containing it; or -* **c)** Prohibiting misrepresentation of the origin of that material, or requiring that -modified versions of such material be marked in reasonable ways as different from the -original version; or -* **d)** Limiting the use for publicity purposes of names of licensors or authors of the -material; or -* **e)** Declining to grant rights under trademark law for use of some trade names, -trademarks, or service marks; or -* **f)** Requiring indemnification of licensors and authors of that material by anyone -who conveys the material (or modified versions of it) with contractual assumptions of -liability to the recipient, for any liability that these contractual assumptions -directly impose on those licensors and authors. - -All other non-permissive additional terms are considered “further -restrictions” within the meaning of section 10. If the Program as you received -it, or any part of it, contains a notice stating that it is governed by this License -along with a term that is a further restriction, you may remove that term. If a -license document contains a further restriction but permits relicensing or conveying -under this License, you may add to a covered work material governed by the terms of -that license document, provided that the further restriction does not survive such -relicensing or conveying. - -If you add terms to a covered work in accord with this section, you must place, in -the relevant source files, a statement of the additional terms that apply to those -files, or a notice indicating where to find the applicable terms. - -Additional terms, permissive or non-permissive, may be stated in the form of a -separately written license, or stated as exceptions; the above requirements apply -either way. - -### 8. Termination - -You may not propagate or modify a covered work except as expressly provided under -this License. Any attempt otherwise to propagate or modify it is void, and will -automatically terminate your rights under this License (including any patent licenses -granted under the third paragraph of section 11). - -However, if you cease all violation of this License, then your license from a -particular copyright holder is reinstated **(a)** provisionally, unless and until the -copyright holder explicitly and finally terminates your license, and **(b)** permanently, -if the copyright holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - -Moreover, your license from a particular copyright holder is reinstated permanently -if the copyright holder notifies you of the violation by some reasonable means, this -is the first time you have received notice of violation of this License (for any -work) from that copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - -Termination of your rights under this section does not terminate the licenses of -parties who have received copies or rights from you under this License. If your -rights have been terminated and not permanently reinstated, you do not qualify to -receive new licenses for the same material under section 10. - -### 9. Acceptance Not Required for Having Copies - -You are not required to accept this License in order to receive or run a copy of the -Program. Ancillary propagation of a covered work occurring solely as a consequence of -using peer-to-peer transmission to receive a copy likewise does not require -acceptance. However, nothing other than this License grants you permission to -propagate or modify any covered work. These actions infringe copyright if you do not -accept this License. Therefore, by modifying or propagating a covered work, you -indicate your acceptance of this License to do so. - -### 10. Automatic Licensing of Downstream Recipients - -Each time you convey a covered work, the recipient automatically receives a license -from the original licensors, to run, modify and propagate that work, subject to this -License. You are not responsible for enforcing compliance by third parties with this -License. - -An “entity transaction” is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an organization, or -merging organizations. If propagation of a covered work results from an entity -transaction, each party to that transaction who receives a copy of the work also -receives whatever licenses to the work the party's predecessor in interest had or -could give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if the predecessor -has it or can get it with reasonable efforts. - -You may not impose any further restrictions on the exercise of the rights granted or -affirmed under this License. For example, you may not impose a license fee, royalty, -or other charge for exercise of rights granted under this License, and you may not -initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging -that any patent claim is infringed by making, using, selling, offering for sale, or -importing the Program or any portion of it. - -### 11. Patents - -A “contributor” is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The work thus -licensed is called the contributor's “contributor version”. - -A contributor's “essential patent claims” are all patent claims owned or -controlled by the contributor, whether already acquired or hereafter acquired, that -would be infringed by some manner, permitted by this License, of making, using, or -selling its contributor version, but do not include claims that would be infringed -only as a consequence of further modification of the contributor version. For -purposes of this definition, “control” includes the right to grant patent -sublicenses in a manner consistent with the requirements of this License. - -Each contributor grants you a non-exclusive, worldwide, royalty-free patent license -under the contributor's essential patent claims, to make, use, sell, offer for sale, -import and otherwise run, modify and propagate the contents of its contributor -version. - -In the following three paragraphs, a “patent license” is any express -agreement or commitment, however denominated, not to enforce a patent (such as an -express permission to practice a patent or covenant not to sue for patent -infringement). To “grant” such a patent license to a party means to make -such an agreement or commitment not to enforce a patent against the party. - -If you convey a covered work, knowingly relying on a patent license, and the -Corresponding Source of the work is not available for anyone to copy, free of charge -and under the terms of this License, through a publicly available network server or -other readily accessible means, then you must either **(1)** cause the Corresponding -Source to be so available, or **(2)** arrange to deprive yourself of the benefit of the -patent license for this particular work, or **(3)** arrange, in a manner consistent with -the requirements of this License, to extend the patent license to downstream -recipients. “Knowingly relying” means you have actual knowledge that, but -for the patent license, your conveying the covered work in a country, or your -recipient's use of the covered work in a country, would infringe one or more -identifiable patents in that country that you have reason to believe are valid. - -If, pursuant to or in connection with a single transaction or arrangement, you -convey, or propagate by procuring conveyance of, a covered work, and grant a patent -license to some of the parties receiving the covered work authorizing them to use, -propagate, modify or convey a specific copy of the covered work, then the patent -license you grant is automatically extended to all recipients of the covered work and -works based on it. - -A patent license is “discriminatory” if it does not include within the -scope of its coverage, prohibits the exercise of, or is conditioned on the -non-exercise of one or more of the rights that are specifically granted under this -License. You may not convey a covered work if you are a party to an arrangement with -a third party that is in the business of distributing software, under which you make -payment to the third party based on the extent of your activity of conveying the -work, and under which the third party grants, to any of the parties who would receive -the covered work from you, a discriminatory patent license **(a)** in connection with -copies of the covered work conveyed by you (or copies made from those copies), or **(b)** -primarily for and in connection with specific products or compilations that contain -the covered work, unless you entered into that arrangement, or that patent license -was granted, prior to 28 March 2007. - -Nothing in this License shall be construed as excluding or limiting any implied -license or other defenses to infringement that may otherwise be available to you -under applicable patent law. - -### 12. No Surrender of Others' Freedom - -If conditions are imposed on you (whether by court order, agreement or otherwise) -that contradict the conditions of this License, they do not excuse you from the -conditions of this License. If you cannot convey a covered work so as to satisfy -simultaneously your obligations under this License and any other pertinent -obligations, then as a consequence you may not convey it at all. For example, if you -agree to terms that obligate you to collect a royalty for further conveying from -those to whom you convey the Program, the only way you could satisfy both those terms -and this License would be to refrain entirely from conveying the Program. - -### 13. Use with the GNU Affero General Public License - -Notwithstanding any other provision of this License, you have permission to link or -combine any covered work with a work licensed under version 3 of the GNU Affero -General Public License into a single combined work, and to convey the resulting work. -The terms of this License will continue to apply to the part which is the covered -work, but the special requirements of the GNU Affero General Public License, section -13, concerning interaction through a network will apply to the combination as such. - -### 14. Revised Versions of this License - -The Free Software Foundation may publish revised and/or new versions of the GNU -General Public License from time to time. Such new versions will be similar in spirit -to the present version, but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Program specifies that -a certain numbered version of the GNU General Public License “or any later -version” applies to it, you have the option of following the terms and -conditions either of that numbered version or of any later version published by the -Free Software Foundation. If the Program does not specify a version number of the GNU -General Public License, you may choose any version ever published by the Free -Software Foundation. - -If the Program specifies that a proxy can decide which future versions of the GNU -General Public License can be used, that proxy's public statement of acceptance of a -version permanently authorizes you to choose that version for the Program. - -Later license versions may give you additional or different permissions. However, no -additional obligations are imposed on any author or copyright holder as a result of -your choosing to follow a later version. - -### 15. Disclaimer of Warranty - -THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER -EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE -QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE -DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - -### 16. Limitation of Liability - -IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY -COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS -PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, -INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE -OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE -WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - -### 17. Interpretation of Sections 15 and 16 - -If the disclaimer of warranty and limitation of liability provided above cannot be -given local legal effect according to their terms, reviewing courts shall apply local -law that most closely approximates an absolute waiver of all civil liability in -connection with the Program, unless a warranty or assumption of liability accompanies -a copy of the Program in return for a fee. - -_END OF TERMS AND CONDITIONS_ - -## How to Apply These Terms to Your New Programs - -If you develop a new program, and you want it to be of the greatest possible use to -the public, the best way to achieve this is to make it free software which everyone -can redistribute and change under these terms. - -To do so, attach the following notices to the program. It is safest to attach them -to the start of each source file to most effectively state the exclusion of warranty; -and each file should have at least the “copyright” line and a pointer to -where the full notice is found. - - - Copyright (C) - - This program 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. - - This program 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 this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - -If the program does terminal interaction, make it output a short notice like this -when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type 'show c' for details. - -The hypothetical commands `show w` and `show c` should show the appropriate parts of -the General Public License. Of course, your program's commands might be different; -for a GUI interface, you would use an “about box”. - -You should also get your employer (if you work as a programmer) or school, if any, to -sign a “copyright disclaimer” for the program, if necessary. For more -information on this, and how to apply and follow the GNU GPL, see -<>. - -The GNU General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may consider it -more useful to permit linking proprietary applications with the library. If this is -what you want to do, use the GNU Lesser General Public License instead of this -License. But first, please read -<>. diff --git a/grammar/README.md b/grammar/README.md deleted file mode 100644 index 1fd44dbf0d..0000000000 --- a/grammar/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# leo-grammar - -[![Crates.io](https://img.shields.io/crates/v/leo-grammar.svg?color=neon)](https://crates.io/crates/leo-grammar) -[![Authors](https://img.shields.io/badge/authors-Aleo-orange.svg)](../AUTHORS) -[![License](https://img.shields.io/badge/License-GPLv3-blue.svg)](./LICENSE.md) - -## Command-line instructions - -To generate an AST of the Leo program and save it as a JSON file , run: -``` -leo_grammar {PATH/TO/INPUT_FILENAME}.leo {PATH/TO/OUTPUT_DIRECTORY (optional)} -``` -If no output directory is provided, then the program will store the JSON file in the local working directory. diff --git a/grammar/benches/grammar.rs b/grammar/benches/grammar.rs deleted file mode 100644 index ec24d5edb7..0000000000 --- a/grammar/benches/grammar.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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::Grammar; - -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use std::path::Path; - -fn leo_grammar<'ast>(filepath: &'ast Path, program_string: &'ast str) { - let result = Grammar::<'ast>::new(filepath, program_string).unwrap(); - black_box(result); -} - -fn criterion_benchmark(c: &mut Criterion) { - let filepath = Path::new("./main.leo").to_path_buf(); - let program_string = include_str!("./main.leo"); - - c.bench_function("Grammar::new", |b| b.iter(|| leo_grammar(&filepath, program_string))); -} - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/grammar/benches/main.leo b/grammar/benches/main.leo deleted file mode 100644 index aafe79bcce..0000000000 --- a/grammar/benches/main.leo +++ /dev/null @@ -1,26 +0,0 @@ -circuit PedersenHash { - parameters: [group; 256], - - // Instantiates a Pedersen hash circuit - function new(self, parameters: [group; 256]) -> Self { - return Self { parameters: parameters } - } - - function hash(bits: [bool; 256]) -> group { - let mut digest: group = 0; - for i in 0..256 { - if bits[i] { - digest += self.parameters[i]; - } - } - return digest - } -} - -// The 'pedersen-hash' main function. -function main() -> group { - let parameters = [1group; 256]; - let pedersen = PedersenHash::new(parameters); - let hash_input: [bool; 256] = [true; 256]; - return pedersen.hash(hash_input) -} diff --git a/grammar/src/access/access.rs b/grammar/src/access/access.rs deleted file mode 100644 index 1c33808692..0000000000 --- a/grammar/src/access/access.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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::{access::*, ast::Rule}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access))] -pub enum Access<'ast> { - Array(ArrayAccess<'ast>), - Tuple(TupleAccess<'ast>), - Call(CallAccess<'ast>), - Object(MemberAccess<'ast>), - StaticObject(StaticMemberAccess<'ast>), -} diff --git a/grammar/src/access/array_access.rs b/grammar/src/access/array_access.rs deleted file mode 100644 index fe98590ce9..0000000000 --- a/grammar/src/access/array_access.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, common::RangeOrExpression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access_array))] -pub struct ArrayAccess<'ast> { - pub expression: RangeOrExpression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/access/assignee_access.rs b/grammar/src/access/assignee_access.rs deleted file mode 100644 index 880ad65255..0000000000 --- a/grammar/src/access/assignee_access.rs +++ /dev/null @@ -1,42 +0,0 @@ -// 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::{ - access::{ArrayAccess, MemberAccess, TupleAccess}, - ast::Rule, -}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access_assignee))] -pub enum AssigneeAccess<'ast> { - Array(ArrayAccess<'ast>), - Tuple(TupleAccess<'ast>), - Member(MemberAccess<'ast>), -} - -impl<'ast> fmt::Display for AssigneeAccess<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - AssigneeAccess::Array(ref array) => write!(f, "[{}]", array.expression), - AssigneeAccess::Tuple(ref tuple) => write!(f, ".{}", tuple.number), - AssigneeAccess::Member(ref member) => write!(f, ".{}", member.identifier), - } - } -} diff --git a/grammar/src/access/call_access.rs b/grammar/src/access/call_access.rs deleted file mode 100644 index 398c05a3f9..0000000000 --- a/grammar/src/access/call_access.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access_call))] -pub struct CallAccess<'ast> { - pub expressions: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/access/member_access.rs b/grammar/src/access/member_access.rs deleted file mode 100644 index a3e2e9e030..0000000000 --- a/grammar/src/access/member_access.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, common::Identifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access_member))] -pub struct MemberAccess<'ast> { - pub identifier: Identifier<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/access/mod.rs b/grammar/src/access/mod.rs deleted file mode 100644 index 927ebc16cb..0000000000 --- a/grammar/src/access/mod.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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 . - -#![allow(clippy::module_inception)] - -pub mod access; -pub use access::*; - -pub mod self_access; -pub use self_access::*; - -pub mod array_access; -pub use array_access::*; - -pub mod assignee_access; -pub use assignee_access::*; - -pub mod call_access; -pub use call_access::*; - -pub mod member_access; -pub use member_access::*; - -pub mod static_member_access; -pub use static_member_access::*; - -pub mod tuple_access; -pub use tuple_access::*; diff --git a/grammar/src/access/self_access.rs b/grammar/src/access/self_access.rs deleted file mode 100644 index 4c4c171835..0000000000 --- a/grammar/src/access/self_access.rs +++ /dev/null @@ -1,27 +0,0 @@ -// 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::{access::*, ast::Rule}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::self_access))] -pub enum SelfAccess<'ast> { - Object(MemberAccess<'ast>), - StaticObject(StaticMemberAccess<'ast>), -} diff --git a/grammar/src/access/static_member_access.rs b/grammar/src/access/static_member_access.rs deleted file mode 100644 index 7452d3e804..0000000000 --- a/grammar/src/access/static_member_access.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, common::Identifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access_static_member))] -pub struct StaticMemberAccess<'ast> { - pub identifier: Identifier<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/access/tuple_access.rs b/grammar/src/access/tuple_access.rs deleted file mode 100644 index 952e6a426f..0000000000 --- a/grammar/src/access/tuple_access.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, values::PositiveNumber, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::access_tuple))] -pub struct TupleAccess<'ast> { - pub number: PositiveNumber<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/annotations/annotation_arguments.rs b/grammar/src/annotations/annotation_arguments.rs deleted file mode 100644 index bf58a2c358..0000000000 --- a/grammar/src/annotations/annotation_arguments.rs +++ /dev/null @@ -1,43 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::annotation_arguments))] -pub struct AnnotationArguments<'ast> { - pub arguments: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::annotation_argument))] -pub struct AnnotationArgument<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/annotations/annotation_name.rs b/grammar/src/annotations/annotation_name.rs deleted file mode 100644 index d7cb1c12c9..0000000000 --- a/grammar/src/annotations/annotation_name.rs +++ /dev/null @@ -1,44 +0,0 @@ -// 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, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::annotation_name))] -pub enum AnnotationName<'ast> { - Context(Context<'ast>), - Test(Test<'ast>), -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::context))] -pub struct Context<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::test))] -pub struct Test<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/annotations/annotation_symbol.rs b/grammar/src/annotations/annotation_symbol.rs deleted file mode 100644 index 16f042be92..0000000000 --- a/grammar/src/annotations/annotation_symbol.rs +++ /dev/null @@ -1,29 +0,0 @@ -// 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, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::annotation_symbol))] -pub struct AnnotationSymbol<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/annotations/annotations.rs b/grammar/src/annotations/annotations.rs deleted file mode 100644 index 045eb3a47e..0000000000 --- a/grammar/src/annotations/annotations.rs +++ /dev/null @@ -1,36 +0,0 @@ -// 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::{ - annotations::{AnnotationArguments, AnnotationName, AnnotationSymbol}, - ast::Rule, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::annotation))] -pub struct Annotation<'ast> { - pub symbol: AnnotationSymbol<'ast>, - pub name: AnnotationName<'ast>, - pub arguments: Option>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/annotations/mod.rs b/grammar/src/annotations/mod.rs deleted file mode 100644 index 1da61336ed..0000000000 --- a/grammar/src/annotations/mod.rs +++ /dev/null @@ -1,29 +0,0 @@ -// 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 . - -#![allow(clippy::module_inception)] - -pub mod annotations; -pub use annotations::*; - -pub mod annotation_symbol; -pub use annotation_symbol::*; - -pub mod annotation_name; -pub use annotation_name::*; - -pub mod annotation_arguments; -pub use annotation_arguments::*; diff --git a/grammar/src/ast.rs b/grammar/src/ast.rs deleted file mode 100644 index 87da0a1967..0000000000 --- a/grammar/src/ast.rs +++ /dev/null @@ -1,176 +0,0 @@ -// 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 . - -//! Abstract syntax tree (ast) representation from leo.pest. -use crate::{ - common::Identifier, - expressions::{ - ArrayInitializerExpression, - ArrayInlineExpression, - CircuitInlineExpression, - Expression, - PostfixExpression, - SelfPostfixExpression, - TernaryExpression, - UnaryExpression, - }, - operations::{BinaryOperation, UnaryOperation}, - values::Value, -}; - -use crate::expressions::TupleExpression; -use from_pest::{ConversionError, FromPest, Void}; -use pest::{ - error::Error, - iterators::{Pair, Pairs}, - prec_climber::{Assoc, Operator, PrecClimber}, - Parser, - Span, -}; - -#[derive(Parser)] -#[grammar = "leo.pest"] -pub struct LanguageParser; - -pub fn parse(program_string: &str) -> Result, Error> { - LanguageParser::parse(Rule::file, program_string) -} - -pub(crate) fn span_into_string(span: Span) -> String { - span.as_str().to_string() -} - -lazy_static! { - static ref PRECEDENCE_CLIMBER: PrecClimber = precedence_climber(); -} - -// Expressions - -fn precedence_climber() -> PrecClimber { - PrecClimber::new(vec![ - Operator::new(Rule::operation_or, Assoc::Left), - Operator::new(Rule::operation_and, Assoc::Left), - Operator::new(Rule::operation_eq, Assoc::Left) - | Operator::new(Rule::operation_ne, Assoc::Left) - | Operator::new(Rule::operation_ge, Assoc::Left) - | Operator::new(Rule::operation_gt, Assoc::Left) - | Operator::new(Rule::operation_le, Assoc::Left) - | Operator::new(Rule::operation_lt, Assoc::Left), - Operator::new(Rule::operation_add, Assoc::Left) | Operator::new(Rule::operation_sub, Assoc::Left), - Operator::new(Rule::operation_mul, Assoc::Left) | Operator::new(Rule::operation_div, Assoc::Left), - Operator::new(Rule::operation_pow, Assoc::Left), - ]) -} - -fn parse_term(pair: Pair) -> Expression { - match pair.as_rule() { - Rule::expression_term => { - let clone = pair.clone(); - let next = clone.into_inner().next().unwrap(); - match next.as_rule() { - Rule::expression => Expression::from_pest(&mut pair.into_inner()).unwrap(), // Parenthesis case - Rule::expression_tuple => { - Expression::Tuple(TupleExpression::from_pest(&mut pair.into_inner()).unwrap()) - } - Rule::expression_array_inline => { - Expression::ArrayInline(ArrayInlineExpression::from_pest(&mut pair.into_inner()).unwrap()) - } - Rule::expression_array_initializer => Expression::ArrayInitializer(Box::new( - ArrayInitializerExpression::from_pest(&mut pair.into_inner()).unwrap(), - )), - Rule::expression_circuit_inline => { - Expression::CircuitInline(CircuitInlineExpression::from_pest(&mut pair.into_inner()).unwrap()) - } - Rule::expression_conditional => { - Expression::Ternary(Box::new(TernaryExpression::from_pest(&mut pair.into_inner()).unwrap())) - } - Rule::expression_unary => { - // The following is necessary to match with the unary operator and its unary expression - let span = next.as_span(); - let mut inner = next.into_inner(); - let operation = match inner.next().unwrap().as_rule() { - Rule::operation_unary => { - UnaryOperation::from_pest(&mut pair.into_inner().next().unwrap().into_inner()).unwrap() - } - rule => unreachable!("`expression_unary` should yield `operation_unary`, found {:#?}", rule), - }; - let expression = parse_term(inner.next().unwrap()); - Expression::Unary(Box::new(UnaryExpression { - operation, - expression, - span, - })) - } - Rule::expression_postfix => { - Expression::Postfix(PostfixExpression::from_pest(&mut pair.into_inner()).unwrap()) - } - Rule::self_expression_postfix => { - Expression::SelfPostfix(SelfPostfixExpression::from_pest(&mut pair.into_inner()).unwrap()) - } - Rule::value => Expression::Value(Value::from_pest(&mut pair.into_inner()).unwrap()), - Rule::identifier => Expression::Identifier(Identifier::from_pest(&mut pair.into_inner()).unwrap()), - rule => unreachable!( - "`term` should contain one of ['value', 'identifier', 'expression', 'expression_not', 'expression_increment', 'expression_decrement'], found {:#?}", - rule - ), - } - } - rule => unreachable!( - "`parse_expression_term` should be invoked on `Rule::expression_term`, found {:#?}", - rule - ), - } -} - -fn binary_expression<'ast>(lhs: Expression<'ast>, pair: Pair<'ast, Rule>, rhs: Expression<'ast>) -> Expression<'ast> { - let (start, _) = lhs.span().clone().split(); - let (_, end) = rhs.span().clone().split(); - let span = start.span(&end); - - match pair.as_rule() { - Rule::operation_or => Expression::binary(BinaryOperation::Or, lhs, rhs, span), - Rule::operation_and => Expression::binary(BinaryOperation::And, lhs, rhs, span), - Rule::operation_eq => Expression::binary(BinaryOperation::Eq, lhs, rhs, span), - Rule::operation_ne => Expression::binary(BinaryOperation::Ne, lhs, rhs, span), - Rule::operation_ge => Expression::binary(BinaryOperation::Ge, lhs, rhs, span), - Rule::operation_gt => Expression::binary(BinaryOperation::Gt, lhs, rhs, span), - Rule::operation_le => Expression::binary(BinaryOperation::Le, lhs, rhs, span), - Rule::operation_lt => Expression::binary(BinaryOperation::Lt, lhs, rhs, span), - Rule::operation_add => Expression::binary(BinaryOperation::Add, lhs, rhs, span), - Rule::operation_sub => Expression::binary(BinaryOperation::Sub, lhs, rhs, span), - Rule::operation_mul => Expression::binary(BinaryOperation::Mul, lhs, rhs, span), - Rule::operation_div => Expression::binary(BinaryOperation::Div, lhs, rhs, span), - Rule::operation_pow => Expression::binary(BinaryOperation::Pow, lhs, rhs, span), - _ => unreachable!(), - } -} - -impl<'ast> FromPest<'ast> for Expression<'ast> { - type FatalError = Void; - type Rule = Rule; - - fn from_pest(pest: &mut Pairs<'ast, Rule>) -> Result> { - let pair = pest.peek().ok_or(::from_pest::ConversionError::NoMatch)?; - match pair.as_rule() { - Rule::expression => { - // advance the iterator - pest.next(); - Ok(PRECEDENCE_CLIMBER.climb(pair.into_inner(), parse_term, binary_expression)) - } - _ => Err(ConversionError::NoMatch), - } - } -} diff --git a/grammar/src/circuits/circuit.rs b/grammar/src/circuits/circuit.rs deleted file mode 100644 index a704df6962..0000000000 --- a/grammar/src/circuits/circuit.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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::CircuitMember, common::Identifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit))] -pub struct Circuit<'ast> { - pub identifier: Identifier<'ast>, - pub members: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/circuits/circuit_implied_variable.rs b/grammar/src/circuits/circuit_implied_variable.rs deleted file mode 100644 index eeb9aee4bb..0000000000 --- a/grammar/src/circuits/circuit_implied_variable.rs +++ /dev/null @@ -1,27 +0,0 @@ -// 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/circuit_member.rs b/grammar/src/circuits/circuit_member.rs deleted file mode 100644 index 6ce1c822b8..0000000000 --- a/grammar/src/circuits/circuit_member.rs +++ /dev/null @@ -1,27 +0,0 @@ -// 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::CircuitVariableDefinition, functions::Function}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit_member))] -pub enum CircuitMember<'ast> { - CircuitVariableDefinition(CircuitVariableDefinition<'ast>), - CircuitFunction(Function<'ast>), -} diff --git a/grammar/src/circuits/circuit_variable.rs b/grammar/src/circuits/circuit_variable.rs deleted file mode 100644 index 30c35bbb0a..0000000000 --- a/grammar/src/circuits/circuit_variable.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, common::Identifier, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit_variable))] -pub struct CircuitVariable<'ast> { - pub identifier: Identifier<'ast>, - pub expression: Expression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/circuits/circuit_variable_definition.rs b/grammar/src/circuits/circuit_variable_definition.rs deleted file mode 100644 index cef9933bc6..0000000000 --- a/grammar/src/circuits/circuit_variable_definition.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, common::Identifier, types::Type, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit_variable_definition))] -pub struct CircuitVariableDefinition<'ast> { - pub identifier: Identifier<'ast>, - pub type_: Type<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/circuits/mod.rs b/grammar/src/circuits/mod.rs deleted file mode 100644 index 7b9a25eed6..0000000000 --- a/grammar/src/circuits/mod.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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 circuit; -pub use circuit::*; - -pub mod circuit_implied_variable; -pub use circuit_implied_variable::*; - -pub mod circuit_variable; -pub use circuit_variable::*; - -pub mod circuit_variable_definition; -pub use circuit_variable_definition::*; - -pub mod circuit_member; -pub use circuit_member::*; diff --git a/grammar/src/common/assignee.rs b/grammar/src/common/assignee.rs deleted file mode 100644 index 066fe1b0dd..0000000000 --- a/grammar/src/common/assignee.rs +++ /dev/null @@ -1,45 +0,0 @@ -// 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::{access::AssigneeAccess, ast::Rule, common::SelfKeywordOrIdentifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::assignee))] -pub struct Assignee<'ast> { - pub name: SelfKeywordOrIdentifier<'ast>, - pub accesses: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for Assignee<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.name)?; - for (i, access) in self.accesses.iter().enumerate() { - write!(f, "{}", access)?; - if i < self.accesses.len() - 1 { - write!(f, ", ")?; - } - } - write!(f, "") - } -} diff --git a/grammar/src/common/declare.rs b/grammar/src/common/declare.rs deleted file mode 100644 index c5a77ecacb..0000000000 --- a/grammar/src/common/declare.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::declare))] -pub enum Declare { - Const(Const), - Let(Let), -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::const_))] -pub struct Const {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::let_))] -pub struct Let {} diff --git a/grammar/src/common/eoi.rs b/grammar/src/common/eoi.rs deleted file mode 100644 index b37cf4f230..0000000000 --- a/grammar/src/common/eoi.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize, Deserialize)] -#[pest_ast(rule(Rule::EOI))] -pub struct EOI; diff --git a/grammar/src/common/identifier.rs b/grammar/src/common/identifier.rs deleted file mode 100644 index 0406e51336..0000000000 --- a/grammar/src/common/identifier.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::identifier))] -pub struct Identifier<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for Identifier<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} diff --git a/grammar/src/common/keyword_or_identifier.rs b/grammar/src/common/keyword_or_identifier.rs deleted file mode 100644 index 5ab05f5dad..0000000000 --- a/grammar/src/common/keyword_or_identifier.rs +++ /dev/null @@ -1,39 +0,0 @@ -// 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, common::Identifier, functions::InputKeyword, types::SelfType}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::keyword_or_identifier))] -pub enum KeywordOrIdentifier<'ast> { - SelfType(SelfType<'ast>), - Input(InputKeyword<'ast>), - Identifier(Identifier<'ast>), -} - -impl<'ast> fmt::Display for KeywordOrIdentifier<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - KeywordOrIdentifier::SelfType(self_type) => write!(f, "{}", self_type), - KeywordOrIdentifier::Input(input_keyword) => write!(f, "{}", input_keyword), - KeywordOrIdentifier::Identifier(name) => write!(f, "{}", name), - } - } -} diff --git a/grammar/src/common/line_end.rs b/grammar/src/common/line_end.rs deleted file mode 100644 index bfbc27948a..0000000000 --- a/grammar/src/common/line_end.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::LINE_END))] -pub struct LineEnd; - -impl fmt::Display for LineEnd { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, ";") - } -} diff --git a/grammar/src/common/mod.rs b/grammar/src/common/mod.rs deleted file mode 100644 index d72b2ea578..0000000000 --- a/grammar/src/common/mod.rs +++ /dev/null @@ -1,66 +0,0 @@ -// 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 assignee; -pub use assignee::*; - -pub mod declare; -pub use declare::*; - -pub mod eoi; -pub use eoi::*; - -pub mod identifier; -pub use identifier::*; - -pub mod keyword_or_identifier; -pub use keyword_or_identifier::*; - -pub mod line_end; -pub use line_end::*; - -pub mod mutable; -pub use mutable::*; - -pub mod mut_self_keyword; -pub use mut_self_keyword::*; - -pub mod range; -pub use range::*; - -pub mod range_or_expression; -pub use range_or_expression::*; - -pub mod self_keyword; -pub use self_keyword::*; - -pub mod self_keyword_or_identifier; -pub use self_keyword_or_identifier::*; - -pub mod spread; -pub use spread::*; - -pub mod spread_or_expression; -pub use spread_or_expression::*; - -pub mod static_; -pub use static_::*; - -pub mod variables; -pub use variables::*; - -pub mod variable_name; -pub use variable_name::*; diff --git a/grammar/src/common/mut_self_keyword.rs b/grammar/src/common/mut_self_keyword.rs deleted file mode 100644 index 1ddc0cfa57..0000000000 --- a/grammar/src/common/mut_self_keyword.rs +++ /dev/null @@ -1,42 +0,0 @@ -// 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, - common::{Mutable, SelfKeyword}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::mut_self_keyword))] -pub struct MutSelfKeyword<'ast> { - pub mutable: Mutable, - pub self_keyword: SelfKeyword<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for MutSelfKeyword<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "mut {}", self.self_keyword) - } -} diff --git a/grammar/src/common/mutable.rs b/grammar/src/common/mutable.rs deleted file mode 100644 index 283ec9eae1..0000000000 --- a/grammar/src/common/mutable.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::mutable))] -pub struct Mutable {} diff --git a/grammar/src/common/range.rs b/grammar/src/common/range.rs deleted file mode 100644 index cdb1f923f5..0000000000 --- a/grammar/src/common/range.rs +++ /dev/null @@ -1,36 +0,0 @@ -// 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, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::range_operator))] -pub struct RangeOperator {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::range))] -pub struct Range<'ast> { - pub from: Option>, - pub operator: RangeOperator, - pub to: Option>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/common/range_or_expression.rs b/grammar/src/common/range_or_expression.rs deleted file mode 100644 index 2b7ae2eb68..0000000000 --- a/grammar/src/common/range_or_expression.rs +++ /dev/null @@ -1,50 +0,0 @@ -// 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, common::Range, expressions::Expression}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::range_or_expression))] -pub enum RangeOrExpression<'ast> { - Range(Range<'ast>), - Expression(Expression<'ast>), -} - -impl<'ast> fmt::Display for RangeOrExpression<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - RangeOrExpression::Expression(ref expression) => write!(f, "{}", expression), - RangeOrExpression::Range(ref range) => write!( - f, - "{}..{}", - range - .from - .as_ref() - .map(|v| v.to_string()) - .unwrap_or_else(|| "".to_string()), - range - .to - .as_ref() - .map(|v| v.to_string()) - .unwrap_or_else(|| "".to_string()), - ), - } - } -} diff --git a/grammar/src/common/self_keyword.rs b/grammar/src/common/self_keyword.rs deleted file mode 100644 index 60721a7fab..0000000000 --- a/grammar/src/common/self_keyword.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::self_keyword))] -pub struct SelfKeyword<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub keyword: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for SelfKeyword<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.keyword) - } -} diff --git a/grammar/src/common/self_keyword_or_identifier.rs b/grammar/src/common/self_keyword_or_identifier.rs deleted file mode 100644 index 83e27901eb..0000000000 --- a/grammar/src/common/self_keyword_or_identifier.rs +++ /dev/null @@ -1,40 +0,0 @@ -// 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, - common::{Identifier, SelfKeyword}, -}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::self_keyword_or_identifier))] -pub enum SelfKeywordOrIdentifier<'ast> { - SelfKeyword(SelfKeyword<'ast>), - Identifier(Identifier<'ast>), -} - -impl<'ast> fmt::Display for SelfKeywordOrIdentifier<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - SelfKeywordOrIdentifier::SelfKeyword(self_keyword) => write!(f, "{}", self_keyword), - SelfKeywordOrIdentifier::Identifier(identifier) => write!(f, "{}", identifier), - } - } -} diff --git a/grammar/src/common/static_.rs b/grammar/src/common/static_.rs deleted file mode 100644 index 82ee9edfd1..0000000000 --- a/grammar/src/common/static_.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::static_))] -pub struct Static {} diff --git a/grammar/src/common/variable_name.rs b/grammar/src/common/variable_name.rs deleted file mode 100644 index f9c6fe2e28..0000000000 --- a/grammar/src/common/variable_name.rs +++ /dev/null @@ -1,46 +0,0 @@ -// 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, - common::{Identifier, Mutable}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::variable_name))] -pub struct VariableName<'ast> { - pub mutable: Option, - pub identifier: Identifier<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for VariableName<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if let Some(ref _mutable) = self.mutable { - write!(f, "mut ")?; - } - - write!(f, "{}", self.identifier) - } -} diff --git a/grammar/src/common/variables.rs b/grammar/src/common/variables.rs deleted file mode 100644 index 939107fd7a..0000000000 --- a/grammar/src/common/variables.rs +++ /dev/null @@ -1,52 +0,0 @@ -// 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, common::VariableName, types::Type, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::variables))] -pub struct Variables<'ast> { - pub names: Vec>, - pub type_: Option>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for Variables<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - if self.names.len() == 1 { - // mut a - write!(f, "{}", self.names[0])?; - } else { - // (a, mut b) - let names = self.names.iter().map(|x| x.to_string()).collect::>().join(","); - - write!(f, "({})", names)?; - } - - if self.type_.is_some() { - write!(f, ": {}", self.type_.as_ref().unwrap())?; - } - - write!(f, "") - } -} diff --git a/grammar/src/console/console_assert.rs b/grammar/src/console/console_assert.rs deleted file mode 100644 index 681f10dfc9..0000000000 --- a/grammar/src/console/console_assert.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_assert))] -pub struct ConsoleAssert<'ast> { - pub expression: Expression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ConsoleAssert<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "assert({})", self.expression) - } -} diff --git a/grammar/src/console/console_error.rs b/grammar/src/console/console_error.rs deleted file mode 100644 index 8155c8d75f..0000000000 --- a/grammar/src/console/console_error.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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, console::FormattedString, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_error))] -pub struct ConsoleError<'ast> { - pub string: FormattedString<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ConsoleError<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "error({})", self.string) - } -} diff --git a/grammar/src/console/console_function.rs b/grammar/src/console/console_function.rs deleted file mode 100644 index b2cb97a418..0000000000 --- a/grammar/src/console/console_function.rs +++ /dev/null @@ -1,44 +0,0 @@ -// 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, - console::{ConsoleAssert, ConsoleDebug, ConsoleError, ConsoleLog}, -}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_function))] -pub enum ConsoleFunction<'ast> { - Assert(ConsoleAssert<'ast>), - Debug(ConsoleDebug<'ast>), - Error(ConsoleError<'ast>), - Log(ConsoleLog<'ast>), -} - -impl<'ast> fmt::Display for ConsoleFunction<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - ConsoleFunction::Assert(assert) => write!(f, "{}", assert), - ConsoleFunction::Debug(debug) => write!(f, "{}", debug), - ConsoleFunction::Error(error) => write!(f, "{}", error), - ConsoleFunction::Log(log) => write!(f, "{}", log), - } - } -} diff --git a/grammar/src/console/console_function_call.rs b/grammar/src/console/console_function_call.rs deleted file mode 100644 index 18183927e9..0000000000 --- a/grammar/src/console/console_function_call.rs +++ /dev/null @@ -1,44 +0,0 @@ -// 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, - common::LineEnd, - console::{ConsoleFunction, ConsoleKeyword}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_function_call))] -pub struct ConsoleFunctionCall<'ast> { - pub keyword: ConsoleKeyword<'ast>, - pub function: ConsoleFunction<'ast>, - pub line_end: LineEnd, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ConsoleFunctionCall<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "console.{};", self.function) - } -} diff --git a/grammar/src/console/console_keyword.rs b/grammar/src/console/console_keyword.rs deleted file mode 100644 index b9f98355ed..0000000000 --- a/grammar/src/console/console_keyword.rs +++ /dev/null @@ -1,29 +0,0 @@ -// 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, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_keyword))] -pub struct ConsoleKeyword<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/console/console_log.rs b/grammar/src/console/console_log.rs deleted file mode 100644 index 06e6f457f0..0000000000 --- a/grammar/src/console/console_log.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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, console::FormattedString, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::console_log))] -pub struct ConsoleLog<'ast> { - pub string: FormattedString<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ConsoleLog<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "log({})", self.string) - } -} diff --git a/grammar/src/console/formatted_container.rs b/grammar/src/console/formatted_container.rs deleted file mode 100644 index 2943280b52..0000000000 --- a/grammar/src/console/formatted_container.rs +++ /dev/null @@ -1,36 +0,0 @@ -// 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, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::formatted_container))] -pub struct FormattedContainer<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for FormattedContainer<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{{}}") - } -} diff --git a/grammar/src/console/formatted_string.rs b/grammar/src/console/formatted_string.rs deleted file mode 100644 index f0e80d3209..0000000000 --- a/grammar/src/console/formatted_string.rs +++ /dev/null @@ -1,45 +0,0 @@ -// 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::{span_into_string, Rule}, - console::FormattedContainer, - expressions::Expression, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::formatted_string))] -pub struct FormattedString<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub string: String, - pub containers: Vec>, - pub parameters: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for FormattedString<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.string) - } -} diff --git a/grammar/src/console/mod.rs b/grammar/src/console/mod.rs deleted file mode 100644 index 30bd4481ab..0000000000 --- a/grammar/src/console/mod.rs +++ /dev/null @@ -1,42 +0,0 @@ -// 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 console_assert; -pub use console_assert::*; - -pub mod console_debug; -pub use console_debug::*; - -pub mod console_error; -pub use console_error::*; - -pub mod console_function; -pub use console_function::*; - -pub mod console_function_call; -pub use console_function_call::*; - -pub mod console_keyword; -pub use console_keyword::*; - -pub mod console_log; -pub use console_log::*; - -pub mod formatted_container; -pub use formatted_container::*; - -pub mod formatted_string; -pub use formatted_string::*; diff --git a/grammar/src/definitions/annotated_definition.rs b/grammar/src/definitions/annotated_definition.rs deleted file mode 100644 index 2bb3bf2d77..0000000000 --- a/grammar/src/definitions/annotated_definition.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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::{annotations::Annotation, ast::Rule, definitions::Definition, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::definition_annotated))] -pub struct AnnotatedDefinition<'ast> { - pub annotation: Annotation<'ast>, - pub definition: Box>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/definitions/definition.rs b/grammar/src/definitions/definition.rs deleted file mode 100644 index 7fd46ef7f5..0000000000 --- a/grammar/src/definitions/definition.rs +++ /dev/null @@ -1,36 +0,0 @@ -// 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::Circuit, - definitions::{AnnotatedDefinition, Deprecated}, - functions::Function, - imports::Import, -}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::definition))] -pub enum Definition<'ast> { - Annotated(AnnotatedDefinition<'ast>), - Import(Import<'ast>), - Circuit(Circuit<'ast>), - Function(Function<'ast>), - Deprecated(Deprecated<'ast>), -} diff --git a/grammar/src/definitions/deprecated.rs b/grammar/src/definitions/deprecated.rs deleted file mode 100644 index 5c8d514113..0000000000 --- a/grammar/src/definitions/deprecated.rs +++ /dev/null @@ -1,26 +0,0 @@ -// 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, functions::TestFunction}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::deprecated))] -pub enum Deprecated<'ast> { - TestFunction(TestFunction<'ast>), -} diff --git a/grammar/src/definitions/mod.rs b/grammar/src/definitions/mod.rs deleted file mode 100644 index b1f44725ff..0000000000 --- a/grammar/src/definitions/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 annotated_definition; -pub use annotated_definition::*; - -pub mod definition; -pub use definition::*; - -pub mod deprecated; -pub use deprecated::*; diff --git a/grammar/src/errors/parser.rs b/grammar/src/errors/parser.rs deleted file mode 100644 index 6f831d0ec2..0000000000 --- a/grammar/src/errors/parser.rs +++ /dev/null @@ -1,64 +0,0 @@ -// 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, errors::SyntaxError}; - -use pest::error::Error; -use std::path::{Path, PathBuf}; - -#[derive(Debug, Error)] -pub enum ParserError { - #[error("{}: {}", _0, _1)] - Crate(&'static str, String), - - #[error("Cannot read from the provided file path - {:?}", _0)] - FileReadError(PathBuf), - - #[error("{}", _0)] - IoError(#[from] std::io::Error), - - #[error("{}", _0)] - JsonError(#[from] serde_json::error::Error), - - #[error("{}", _0)] - SyntaxError(#[from] SyntaxError), - - #[error("Unable to construct program abstract syntax tree")] - SyntaxTreeError, -} - -impl ParserError { - pub fn set_path(&mut self, path: &Path) { - if let ParserError::SyntaxError(error) = self { - let new_error: Error = match error { - SyntaxError::Error(error) => { - let new_error = error.clone(); - new_error.with_path(path.to_str().unwrap()) - } - }; - - tracing::error!("{}", new_error); - - *error = SyntaxError::Error(new_error); - } - } -} - -impl From> for ParserError { - fn from(error: Error) -> Self { - ParserError::SyntaxError(SyntaxError::from(error)) - } -} diff --git a/grammar/src/errors/syntax.rs b/grammar/src/errors/syntax.rs deleted file mode 100644 index 9f8f98b81b..0000000000 --- a/grammar/src/errors/syntax.rs +++ /dev/null @@ -1,64 +0,0 @@ -// 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; - -use pest::error::Error; - -#[derive(Debug, Error)] -pub enum SyntaxError { - #[error("aborting due to syntax error")] - Error(Error), -} - -impl From> for SyntaxError { - fn from(mut error: Error) -> Self { - error = error.renamed_rules(|rule| match *rule { - Rule::LINE_END => "`;`".to_owned(), - Rule::type_integer => "`u32`".to_owned(), - Rule::type_field => "`field`".to_owned(), - Rule::type_group => "`group`".to_owned(), - Rule::address => "an aleo address: `aleo1...`".to_owned(), - Rule::file => "an import, circuit, or function".to_owned(), - Rule::identifier => "a variable name".to_owned(), - Rule::type_ => "a type".to_owned(), - Rule::access => "`.`, `::`, `()`".to_owned(), - - Rule::operation_and => "`&&`".to_owned(), - Rule::operation_or => "`||`".to_owned(), - Rule::operation_eq => "`==`".to_owned(), - Rule::operation_ne => "`!=`".to_owned(), - Rule::operation_ge => "`>=`".to_owned(), - Rule::operation_gt => "`>`".to_owned(), - Rule::operation_le => "`<=`".to_owned(), - Rule::operation_lt => "`<`".to_owned(), - Rule::operation_add => "`+`".to_owned(), - Rule::operation_sub => "`-`".to_owned(), - Rule::operation_mul => "`*`".to_owned(), - Rule::operation_div => "`/`".to_owned(), - Rule::operation_pow => "`**`".to_owned(), - - Rule::package => "package. Check package and import names for errors.".to_owned(), - Rule::package_name => { - "package name. Please use lowercase letters, numbers, and dashes `-` only.".to_owned() - } - - rule => format!("{:?}", rule), - }); - - SyntaxError::Error(error) - } -} diff --git a/grammar/src/expressions/array_initializer_expression.rs b/grammar/src/expressions/array_initializer_expression.rs deleted file mode 100644 index c2a73e0d09..0000000000 --- a/grammar/src/expressions/array_initializer_expression.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, expressions::Expression, types::ArrayDimensions, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_array_initializer))] -pub struct ArrayInitializerExpression<'ast> { - pub expression: Expression<'ast>, - pub dimensions: ArrayDimensions<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/array_inline_expression.rs b/grammar/src/expressions/array_inline_expression.rs deleted file mode 100644 index 5b3f4b7810..0000000000 --- a/grammar/src/expressions/array_inline_expression.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, common::SpreadOrExpression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_array_inline))] -pub struct ArrayInlineExpression<'ast> { - pub expressions: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/binary_expression.rs b/grammar/src/expressions/binary_expression.rs deleted file mode 100644 index 1086121d5b..0000000000 --- a/grammar/src/expressions/binary_expression.rs +++ /dev/null @@ -1,29 +0,0 @@ -// 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::{expressions::Expression, operations::BinaryOperation, SpanDef}; - -use pest::Span; -use serde::Serialize; - -#[derive(Clone, Debug, PartialEq, Serialize)] -pub struct BinaryExpression<'ast> { - pub operation: BinaryOperation, - pub left: Expression<'ast>, - pub right: Expression<'ast>, - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/circuit_inline_expression.rs b/grammar/src/expressions/circuit_inline_expression.rs deleted file mode 100644 index 6a51792bae..0000000000 --- a/grammar/src/expressions/circuit_inline_expression.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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::CircuitImpliedVariable, common::Identifier, types::SelfType, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_circuit_inline))] -pub struct CircuitInlineExpression<'ast> { - pub name: CircuitName<'ast>, - pub members: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::circuit_name))] -pub enum CircuitName<'ast> { - SelfType(SelfType<'ast>), - Identifier(Identifier<'ast>), -} diff --git a/grammar/src/expressions/expression.rs b/grammar/src/expressions/expression.rs deleted file mode 100644 index 7d71761a5c..0000000000 --- a/grammar/src/expressions/expression.rs +++ /dev/null @@ -1,114 +0,0 @@ -// 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::{common::Identifier, expressions::*, operations::BinaryOperation, values::Value}; - -use pest::Span; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, PartialEq, Serialize)] -pub enum Expression<'ast> { - Value(Value<'ast>), - Identifier(Identifier<'ast>), - Unary(Box>), - Binary(Box>), - Ternary(Box>), - ArrayInline(ArrayInlineExpression<'ast>), - ArrayInitializer(Box>), - CircuitInline(CircuitInlineExpression<'ast>), - Postfix(PostfixExpression<'ast>), - SelfPostfix(SelfPostfixExpression<'ast>), - Tuple(TupleExpression<'ast>), -} - -impl<'ast> Expression<'ast> { - pub fn binary( - operation: BinaryOperation, - left: Expression<'ast>, - right: Expression<'ast>, - span: Span<'ast>, - ) -> Self { - Expression::Binary(Box::new(BinaryExpression { - operation, - left, - right, - span, - })) - } - - pub fn ternary( - first: Expression<'ast>, - second: Expression<'ast>, - third: Expression<'ast>, - span: Span<'ast>, - ) -> Self { - Expression::Ternary(Box::new(TernaryExpression { - first, - second, - third, - span, - })) - } - - pub fn span(&self) -> &Span<'ast> { - match self { - Expression::Value(expression) => &expression.span(), - Expression::Identifier(expression) => &expression.span, - Expression::Unary(expression) => &expression.span, - Expression::Binary(expression) => &expression.span, - Expression::Ternary(expression) => &expression.span, - Expression::ArrayInline(expression) => &expression.span, - Expression::ArrayInitializer(expression) => &expression.span, - Expression::CircuitInline(expression) => &expression.span, - Expression::Postfix(expression) => &expression.span, - Expression::SelfPostfix(expression) => &expression.span, - Expression::Tuple(expression) => &expression.span, - } - } -} - -impl<'ast> fmt::Display for Expression<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Expression::Value(ref expression) => write!(f, "{}", expression), - Expression::Identifier(ref expression) => write!(f, "{}", expression), - Expression::Unary(ref expression) => write!(f, "{}", expression), - Expression::Binary(ref expression) => write!(f, "{} == {}", expression.left, expression.right), - Expression::Ternary(ref expression) => write!( - f, - "if {} ? {} : {}", - expression.first, expression.second, expression.third - ), - Expression::ArrayInline(ref expression) => { - for (i, spread_or_expression) in expression.expressions.iter().enumerate() { - write!(f, "{}", spread_or_expression)?; - if i < expression.expressions.len() - 1 { - write!(f, ", ")?; - } - } - write!(f, "") - } - Expression::ArrayInitializer(ref expression) => { - write!(f, "[{} ; ({})]", expression.expression, expression.dimensions) - } - Expression::CircuitInline(ref expression) => write!(f, "{}", expression.span.as_str()), - Expression::Postfix(ref expression) => write!(f, "{}", expression.span.as_str()), - Expression::SelfPostfix(ref expression) => write!(f, "{}", expression.span.as_str()), - Expression::Tuple(ref expression) => write!(f, "{}", expression.span.as_str()), - } - } -} diff --git a/grammar/src/expressions/mod.rs b/grammar/src/expressions/mod.rs deleted file mode 100644 index 6eb2e47eda..0000000000 --- a/grammar/src/expressions/mod.rs +++ /dev/null @@ -1,45 +0,0 @@ -// 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 array_initializer_expression; -pub use array_initializer_expression::*; - -pub mod array_inline_expression; -pub use array_inline_expression::*; - -pub mod binary_expression; -pub use binary_expression::*; - -pub mod circuit_inline_expression; -pub use circuit_inline_expression::*; - -pub mod expression; -pub use expression::*; - -pub mod unary_expression; -pub use unary_expression::*; - -pub mod postfix_expression; -pub use postfix_expression::*; - -pub mod self_postfix_expression; -pub use self_postfix_expression::*; - -pub mod ternary_expression; -pub use ternary_expression::*; - -pub mod tuple_expression; -pub use tuple_expression::*; diff --git a/grammar/src/expressions/postfix_expression.rs b/grammar/src/expressions/postfix_expression.rs deleted file mode 100644 index 923de16161..0000000000 --- a/grammar/src/expressions/postfix_expression.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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::{access::Access, ast::Rule, common::KeywordOrIdentifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_postfix))] -pub struct PostfixExpression<'ast> { - pub name: KeywordOrIdentifier<'ast>, - pub accesses: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/self_postfix_expression.rs b/grammar/src/expressions/self_postfix_expression.rs deleted file mode 100644 index 21017bda2d..0000000000 --- a/grammar/src/expressions/self_postfix_expression.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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::{ - access::{Access, SelfAccess}, - ast::Rule, - common::SelfKeyword, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::self_expression_postfix))] -pub struct SelfPostfixExpression<'ast> { - pub name: SelfKeyword<'ast>, - pub self_access: SelfAccess<'ast>, - pub accesses: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/ternary_expression.rs b/grammar/src/expressions/ternary_expression.rs deleted file mode 100644 index 163750bd61..0000000000 --- a/grammar/src/expressions/ternary_expression.rs +++ /dev/null @@ -1,32 +0,0 @@ -// 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, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_conditional))] -pub struct TernaryExpression<'ast> { - pub first: Expression<'ast>, - pub second: Expression<'ast>, - pub third: Expression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/tuple_expression.rs b/grammar/src/expressions/tuple_expression.rs deleted file mode 100644 index 16b8727fe9..0000000000 --- a/grammar/src/expressions/tuple_expression.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_tuple))] -pub struct TupleExpression<'ast> { - pub expressions: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/expressions/unary_expression.rs b/grammar/src/expressions/unary_expression.rs deleted file mode 100644 index b2d50fb4c4..0000000000 --- a/grammar/src/expressions/unary_expression.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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, expressions::Expression, operations::UnaryOperation, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::expression_unary))] -pub struct UnaryExpression<'ast> { - pub operation: UnaryOperation, - pub expression: Expression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for UnaryExpression<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}", self.operation, self.expression) - } -} diff --git a/grammar/src/files/file.rs b/grammar/src/files/file.rs deleted file mode 100644 index 6d1bc2fea3..0000000000 --- a/grammar/src/files/file.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, common::EOI, definitions::Definition, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::file))] -pub struct File<'ast> { - pub definitions: Vec>, - pub eoi: EOI, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/files/mod.rs b/grammar/src/files/mod.rs deleted file mode 100644 index da089614bf..0000000000 --- a/grammar/src/files/mod.rs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 file; -pub use file::*; diff --git a/grammar/src/functions/function.rs b/grammar/src/functions/function.rs deleted file mode 100644 index cd342b34bf..0000000000 --- a/grammar/src/functions/function.rs +++ /dev/null @@ -1,33 +0,0 @@ -// 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, common::Identifier, functions::input::Input, statements::Block, types::Type, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::function))] -pub struct Function<'ast> { - pub identifier: Identifier<'ast>, - pub parameters: Vec>, - pub returns: Option>, - pub block: Block<'ast>, - #[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 deleted file mode 100644 index 3cac32b798..0000000000 --- a/grammar/src/functions/input/function_input.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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, - common::{Const, Identifier, Mutable}, - types::Type, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -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>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/functions/input/input.rs b/grammar/src/functions/input/input.rs deleted file mode 100644 index 9b2ef22ab7..0000000000 --- a/grammar/src/functions/input/input.rs +++ /dev/null @@ -1,33 +0,0 @@ -// 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, - common::{MutSelfKeyword, SelfKeyword}, - functions::{FunctionInput, InputKeyword}, -}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::input))] -pub enum Input<'ast> { - InputKeyword(InputKeyword<'ast>), - SelfKeyword(SelfKeyword<'ast>), - MutSelfKeyword(MutSelfKeyword<'ast>), - FunctionInput(FunctionInput<'ast>), -} diff --git a/grammar/src/functions/input/input_keyword.rs b/grammar/src/functions/input/input_keyword.rs deleted file mode 100644 index 5032ae4436..0000000000 --- a/grammar/src/functions/input/input_keyword.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::input_keyword))] -pub struct InputKeyword<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub keyword: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for InputKeyword<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.keyword) - } -} diff --git a/grammar/src/functions/input/mod.rs b/grammar/src/functions/input/mod.rs deleted file mode 100644 index d75e262d32..0000000000 --- a/grammar/src/functions/input/mod.rs +++ /dev/null @@ -1,26 +0,0 @@ -// 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 . - -#![allow(clippy::module_inception)] - -pub mod function_input; -pub use function_input::*; - -pub mod input; -pub use input::*; - -pub mod input_keyword; -pub use input_keyword::*; diff --git a/grammar/src/functions/mod.rs b/grammar/src/functions/mod.rs deleted file mode 100644 index f16e3448d2..0000000000 --- a/grammar/src/functions/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 function; -pub use function::*; - -pub mod input; -pub use input::*; - -pub mod test_function; -pub use test_function::*; diff --git a/grammar/src/functions/test_function.rs b/grammar/src/functions/test_function.rs deleted file mode 100644 index 1e28efc53c..0000000000 --- a/grammar/src/functions/test_function.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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, functions::Function, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::test_function))] -pub struct TestFunction<'ast> { - pub function: Function<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> From> for TestFunction<'ast> { - fn from(function: Function<'ast>) -> Self { - let span = function.span.clone(); - TestFunction { function, span } - } -} diff --git a/grammar/src/imports/import.rs b/grammar/src/imports/import.rs deleted file mode 100644 index 1b62df80f3..0000000000 --- a/grammar/src/imports/import.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, common::LineEnd, imports::PackageOrPackages, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::import))] -pub struct Import<'ast> { - pub package_or_packages: PackageOrPackages<'ast>, - pub line_end: LineEnd, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/imports/import_symbol.rs b/grammar/src/imports/import_symbol.rs deleted file mode 100644 index 3643406618..0000000000 --- a/grammar/src/imports/import_symbol.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, common::Identifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::import_symbol))] -pub struct ImportSymbol<'ast> { - pub value: Identifier<'ast>, - pub alias: Option>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/imports/package.rs b/grammar/src/imports/package.rs deleted file mode 100644 index 0b3f1a0ecb..0000000000 --- a/grammar/src/imports/package.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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, - imports::{PackageAccess, PackageName}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::package))] -pub struct Package<'ast> { - pub name: PackageName<'ast>, - pub access: PackageAccess<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/imports/package_access.rs b/grammar/src/imports/package_access.rs deleted file mode 100644 index 7d172bd545..0000000000 --- a/grammar/src/imports/package_access.rs +++ /dev/null @@ -1,32 +0,0 @@ -// 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, - imports::{ImportSymbol, Package, Packages, Star}, -}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::package_access))] -pub enum PackageAccess<'ast> { - Star(Star<'ast>), - SubPackage(Box>), - Symbol(ImportSymbol<'ast>), - Multiple(Packages<'ast>), -} diff --git a/grammar/src/imports/package_name.rs b/grammar/src/imports/package_name.rs deleted file mode 100644 index a2e400460e..0000000000 --- a/grammar/src/imports/package_name.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::package_name))] -pub struct PackageName<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for PackageName<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} diff --git a/grammar/src/imports/package_or_packages.rs b/grammar/src/imports/package_or_packages.rs deleted file mode 100644 index 3cd0324480..0000000000 --- a/grammar/src/imports/package_or_packages.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, - imports::{Package, Packages}, -}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::package_or_packages))] -pub enum PackageOrPackages<'ast> { - Package(Package<'ast>), - Packages(Packages<'ast>), -} diff --git a/grammar/src/imports/packages.rs b/grammar/src/imports/packages.rs deleted file mode 100644 index 32003ffb16..0000000000 --- a/grammar/src/imports/packages.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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, - imports::{PackageAccess, PackageName}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::packages))] -pub struct Packages<'ast> { - pub name: PackageName<'ast>, - pub accesses: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/imports/star.rs b/grammar/src/imports/star.rs deleted file mode 100644 index 29cb6b6e35..0000000000 --- a/grammar/src/imports/star.rs +++ /dev/null @@ -1,29 +0,0 @@ -// 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, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::star))] -pub struct Star<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/leo.pest b/grammar/src/leo.pest deleted file mode 100644 index 4a5fbdde2e..0000000000 --- a/grammar/src/leo.pest +++ /dev/null @@ -1,560 +0,0 @@ -/// Common - -// Declared in common/assignee.rs -assignee = { self_keyword_or_identifier ~ access_assignee* } - -// Declared in files/file.rs -file = { SOI ~ definition* ~ EOI } - -// Declared in definitions/definition.rs -definition = { - definition_annotated - | import - | circuit - | function - | deprecated -} - -// Declared in definitions/deprecated.rs -deprecated = { - test_function -} - -// Declared in definitions/annotated_definition.rs -definition_annotated = { annotation ~ definition} - -// Declared in common/identifier.rs -identifier = @{ ((!protected_name ~ ASCII_ALPHA) | (protected_name ~ (ASCII_ALPHANUMERIC | "_"))) ~ (ASCII_ALPHANUMERIC | "_")* } -protected_name = { - "as" - | "circuit" - | "const" - | "console" - | "else" - | "for" - | "function" - | "if" - | "import" - | input_keyword - | "in" - | "let" - | "mut" - | "return" - | self_keyword - | "static" - | "string" - | "test" - | type_data - | type_self - | value_boolean -} - -// Declared in common/self_keyword.rs -self_keyword = { "self" } - -// Declared in common/mut_self_keyword.rs -mut_self_keyword = { mutable ~ self_keyword } - -// Declared in common/self_keyword_or_identifier.rs -self_keyword_or_identifier = { - self_keyword - | identifier -} - -// Declared in common/keyword_or_identifier.rs -keyword_or_identifier = { - input_keyword - | type_self - | identifier -} - -// Declared in common/line_end.rs -LINE_END = { ";" } - -// Declared in common/mutable.rs -mutable = { "mut " } - -// Declared in common/range.rs -range_operator = { ".." } -range = { expression? ~ range_operator ~ expression? } - -// Declared in common/range_or_expression.rs -range_or_expression = { range | expression } - -// Declared in common/spread.rs -spread = { "..." ~ expression } - -// Declared in common/spread_or_expression.rs -spread_or_expression = { spread | expression } - -// Declared in common/static_.rs -static_ = { "static " } - -// Declared in common/variable_name.rs - -variable_name = {mutable? ~ identifier} -variable_name_tuple = _{"(" ~ variable_name ~ ("," ~ variable_name)+ ~ ")"} - -// Declared in common/variables.rs -variables = { ( variable_name_tuple | variable_name ) ~ (":" ~ type_ )? } - -// Declared in common/declare.rs -declare = { let_ | const_ } -const_ = { "const " } -let_ = { "let " } - -/// Operations - -// Declared in operations/unary_operation.rs -operation_unary = { - operation_not - | operation_negate -} -operation_not = { "!" } -operation_negate = { "-" } - -// Declared in operations/binary_operation.rs -operation_and = { "&&" } -operation_or = { "||" } -operation_eq = { "==" } -operation_ne = { "!=" } -operation_ge = { ">=" } -operation_gt = { ">" } -operation_le = { "<=" } -operation_lt = { "<" } -operation_add = { "+" } -operation_sub = { "-" } -operation_mul = { "*" } -operation_div = { "/" } -operation_pow = { "**" } - -operation_compare = _{ - operation_eq | operation_ne | - operation_ge | operation_gt | - operation_le | operation_lt -} -operation_binary = _{ - operation_compare | operation_and | operation_or | - operation_add | operation_sub | operation_pow | operation_mul | operation_div -} - -// Declared in operations/assign_operation.rs -operation_assign = { - assign | operation_add_assign | operation_sub_assign | - operation_mul_assign | operation_div_assign | operation_pow_assign -} -assign = { "=" } -operation_add_assign = { "+=" } -operation_sub_assign = { "-=" } -operation_mul_assign = { "*=" } -operation_div_assign = { "/=" } -operation_pow_assign = { "**=" } - -/// Types - -// Declared in types/type_.rs -type_ = { type_self | type_tuple | type_array | type_data | type_circuit } - -// Declared in types/integer_type.rs -type_integer = { - type_integer_signed - | type_integer_unsigned -} - -// Declared in types/unsigned_integer_type.rs -type_u8 = { "u8" } -type_u16 = { "u16" } -type_u32 = { "u32" } -type_u64 = { "u64" } -type_u128 = { "u128" } - -type_integer_unsigned = { - type_u8 - | type_u16 - | type_u32 - | type_u64 - | type_u128 -} - -// Declared in types/signed_integer_type.rs -type_i8 = { "i8" } -type_i16 = { "i16" } -type_i32 = { "i32" } -type_i64 = { "i64" } -type_i128 = { "i128" } - -type_integer_signed = { - type_i8 - | type_i16 - | type_i32 - | type_i64 - | type_i128 -} - -// Declared in types/field_type.rs -type_field = { "field" } - -// Declared in types/group_type.rs -type_group = { "group" } - -// Declared in types/boolean_type.rs -type_boolean = { "bool" } - -// Declared in types/address_type.rs -type_address = { "address" } - -// Declared in types/data_type.rs -type_data = { - type_address - | type_boolean - | type_field - | type_group - | type_integer -} - -// Declared in types/self_type.rs -type_self = { "Self" } - -// Declared in types/self_type.rs -type_circuit = { identifier } - -// Declared in types/array_type.rs -type_array = { "[" ~ type_ ~ ";" ~ array_dimensions ~ "]" } - -// Declared in types/array_dimensions.rs -array_dimensions = { - dimension_single - | dimension_multiple -} - -// Declared in types/array_dimensions.rs -dimension_single = { - number_positive -} - -// Declared in types/array_dimensions.rs -dimension_multiple = { "(" ~ number_positive ~ ("," ~ number_positive)* ~ ")"} - -type_tuple = { "(" ~ (type_ ~ ("," ~ type_)+ ~ ","?)? ~ ")" } - -/// Values - -// Declared in values/value.rs -value = { - value_address - | value_boolean - | value_field - | value_group - | value_integer - | value_number // must be last as a catch all -} - -// Declared in values/number_value.rs -value_number = { number_negative | number_positive } - -// Declared in values/number_negative.rs -number_negative = @{ "-" ~ ASCII_DIGIT+ } - -// Declared in values/number_positive.rs -number_positive = @{ ASCII_DIGIT+ } - -// Declared in values/integer_value.rs -value_integer = { value_integer_signed | value_integer_unsigned} - -// Declared in values/signed_integer_value.rs -value_integer_signed = ${ value_number ~ type_integer_signed } - -// Declared in values/unsigned_integer_value.rs -value_integer_unsigned = ${ number_positive ~ type_integer_unsigned } - -// Declared in values/boolean_value.rs -value_boolean = { "true" | "false" } - -// Declared in values/field_value.rs -value_field = ${ value_number ~ type_field } - -// Declared in values/group_value.rs -value_group = ${ group_single_or_tuple ~ type_group } -group_single_or_tuple = {value_number | group_tuple} -group_tuple = !{"(" ~ group_coordinate ~ "," ~ group_coordinate ~ ")"} - -// Declared in values/group_coordinate.rs -group_coordinate = { - value_number - | sign_high - | sign_low - | inferred -} - -sign_high = @{"+"} -sign_low = @{"-"} -inferred = @{"_"} - -// Declared in values/address.rs -address = @{ "aleo1" ~ (LOWERCASE_LETTER | ASCII_DIGIT){58} } - -// Declared in values/address_value.rs -value_address = ${ type_address ~ "(" ~ address ~ ")" } - -/// Access - -// Declared in access/access.rs -access = { access_array | access_tuple | access_call | access_member | access_static_member } - -// Declared in access/self_access.rs -self_access = { access_member | access_static_member } - -// Declared in access/array_access.rs -access_array = !{ "[" ~ range_or_expression ~ "]" } - -// Declared in access/tuple_access.rs -access_tuple = ${ "." ~ number_positive } - -// Declared in access/assignee_access.rs -access_assignee = { access_array | access_tuple | access_member } - -// Declared in access/call_access.rs -access_call = !{ "(" ~ (expression ~ ("," ~ expression)*)? ~ ")" } - -// Declared in access/member_access.rs -access_member = ${ "." ~ identifier } - -// Declared in access/static_member_access.rs -access_static_member = ${ "::" ~ identifier } - -/// Circuits - -// Declared in circuits/circuit_definition.rs -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_ ~ ","?} - -// Declared in circuits/circuit_member.rs -circuit_member = { function | circuit_variable_definition} - -/// Conditionals - -expression_conditional = { "if " ~ expression ~ "? " ~ expression ~ ": " ~ expression} - -/// Expressions - -expression_term = { - value - | ("(" ~ expression ~ ")") - | expression_tuple - | expression_conditional - | expression_array_initializer - | expression_array_inline - | expression_circuit_inline - | expression_unary - | self_expression_postfix - | expression_postfix - | identifier -} - - -// Declared in expressions/expression.rs -expression = { expression_term ~ (operation_binary ~ expression_term)* } - -// Declared in expressions/expression_tuple.rs -expression_tuple = { "(" ~ (expression ~ ("," ~ expression)+)? ~ ")" } - -// Declared in expressions/array_initializer_expression.rs -expression_array_initializer = { "[" ~ expression ~ ";" ~ array_dimensions ~ "]" } - -// Declared in expressions/array_inline_expression.rs -expression_array_inline = { "[" ~ inline_array_inner ~ "]"} -inline_array_inner = _{(spread_or_expression ~ ("," ~ spread_or_expression)*)?} - -// Declared in expressions/circuit_inline_expression.rs -expression_circuit_inline = { circuit_name ~ "{" ~ circuit_variable_list ~ "}" } - -// Declared in expressions/circuit_inline_expression.rs -circuit_name = { - type_self - | identifier -} - -// Declared in expressions/circuit_inline_expression.rs -circuit_variable_list = _{ (circuit_implied_variable ~ ("," ~ circuit_implied_variable)*)? ~ ","? } - -// Declared in expressions/unary_expression.rs -expression_unary = { operation_unary ~ expression_term } - -// Declared in expressions/postfix_expression.rs -expression_postfix = ${ keyword_or_identifier ~ access+ } - -// Declared in expressions/self_postfix_expression.rs -self_expression_postfix = ${ self_keyword ~ self_access ~ access* } - -/// Statements - -// Declared in statements/statement.rs -statement = { - (statement_return - | statement_conditional - | statement_for - | console_function_call - | statement_definition - | statement_assign - | statement_expression - | block - ) -} - - -// Declared in statements/assign_statement.rs -statement_assign = { assignee ~ operation_assign ~ expression ~ LINE_END } - -block = { "{" ~ statement* ~ "}" } - -// Declared in statements/conditional_statement.rs -statement_conditional = {"if " ~ expression ~ block ~ ("else " ~ conditional_nested_or_end_statement)?} -conditional_nested_or_end_statement = { statement_conditional | block } - -// Declared in statements/definition_statement.rs -statement_definition = { declare ~ variables ~ "=" ~ expression ~ LINE_END} - -// Declared in statements/expression_statement.rs -statement_expression = { expression ~ LINE_END } - -// Decalred in functions/test_function.rs -test_function = { "test" ~ function } - -// Declared in statements/for_statement.rs -statement_for = { "for " ~ identifier ~ "in " ~ expression ~ ".." ~ expression ~ block } - -// Declared in statements/return_statement.rs -statement_return = { "return " ~ expression} - -/// Functions - -// Declared in functions/function.rs -function = { "function " ~ identifier ~ input_tuple ~ ("->" ~ type_)? ~ block } - -// Declared in functions/input/function_input.rs -function_input = { const_? ~ mutable? ~ identifier ~ ":" ~ type_ } - -// Declared in functions/input/input_keyword.rs -input_keyword = { "input" } - -// Declared in functions/input/input.rs -input = { - input_keyword - | self_keyword - | mut_self_keyword - | function_input -} -input_tuple = _{ "(" ~ (input ~ ("," ~ input)* ~ ","?)? ~ ")"} - - -/// Imports - -// Declared in imports/import.rs -import = { "import " ~ package_or_packages ~ LINE_END} - -// Declared in imports/package_name.rs -package_name = @{ (ASCII_ALPHA_LOWER | ASCII_DIGIT)+ ~ ( "-" ~ (ASCII_ALPHA_LOWER | ASCII_DIGIT)+)* } - -// Declared in imports/package_or_packages.rs -package_or_packages = { - packages - | package -} -// Declared in imports/package.rs -package = { package_name ~ "." ~ package_access } -// Declared in imports/packages.rs -packages = { package_name ~ "." ~ multiple_package_access } - -// Declared in imports/package_access -package_access = { - star - | packages - | package // subpackage - | import_symbol -} - -multiple_package_access = _{ "(" ~ package_access ~ ("," ~ package_access)* ~ ","? ~ ")"} - -// Declared in imports/star.rs -star = {"*"} - -// Declared in imports/import_symbol.rs -import_symbol = { identifier ~ ("as " ~ identifier)? } - -/// Utilities - -COMMENT = _{ ("/*" ~ (!"*/" ~ ANY)* ~ "*/") | ("//" ~ (!NEWLINE ~ ANY)*) } -WHITESPACE = _{ (" " | "\t" | NEWLINE) ~ (NEWLINE)* } // pest implicit whitespace keyword - -/// Console Functions - -// Declared in console/console_function_call.rs -console_function_call = ${console_keyword ~ "." ~ console_function ~ LINE_END} - -// Declared in console/console_keyword.rs -console_keyword = {"console"} - -// Declared in console/console_function.rs -console_function = { - console_assert - | console_debug - | console_error - | console_log -} - -// Declared in console/console_assert.rs -console_assert = !{"assert(" ~ expression ~ ")"} - -// Declared in console/console_debug.rs -console_debug = !{"debug(" ~ formatted_string? ~ ")"} - -// Declared in console/console_error.rs -console_error = !{"error(" ~ formatted_string? ~ ")"} - -// Declared in console/console_log.rs -console_log = !{"log(" ~ formatted_string? ~ ")"} - -// Declared in console/formatted_string.rs -formatted_string = { - "\"" - ~ (!"\"" ~ (formatted_container | ANY))* - ~ "\"" - ~ ("," ~ expression)* -} - -// Declared in console/formatted_container.rs -formatted_container = { "{" ~ "}"} - -/// Annotations - -// Declared in annotations/annotation.rs -annotation = ${annotation_symbol ~ annotation_name ~ annotation_arguments? } - -// Declared in annotations/annotation_symbol.rs -annotation_symbol = ${"@"} - -// Declared in annotations/annotation_name.rs -annotation_name = { - context // deprecated - | test -} - -// Declared in annotations/annotation_name.rs -context = {"context"} -test = {"test"} - -// Declared in annotations/annotation_argument.rs -annotation_arguments = !{"(" ~ annotation_argument ~ ("," ~ annotation_argument)* ~ ","? ~ NEWLINE* ~ ")"} - -annotation_argument = @{ (ASCII_ALPHANUMERIC | "_")+ } diff --git a/grammar/src/lib.rs b/grammar/src/lib.rs deleted file mode 100644 index 2f9e0fac02..0000000000 --- a/grammar/src/lib.rs +++ /dev/null @@ -1,110 +0,0 @@ -// 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 . - -//! The pest abstract syntax tree (ast) for a Leo program. -//! -//! This module contains the [`Grammar`] type, a wrapper around the [`File`] type in this module. -//! The [`Grammar`] type is the datatype generated by the pest parser using grammar from `leo.pest`. -//! The [`Grammar`] type is intended to be parsed into a [`Ast`]. It should not be parsed by -//! any other pass of the compiler. -#[macro_use] -extern crate lazy_static; -#[macro_use] -extern crate pest_derive; -#[macro_use] -extern crate thiserror; - -pub mod ast; - -pub mod access; -pub mod annotations; -pub mod circuits; -pub mod common; -pub mod console; -pub mod definitions; -pub mod expressions; -pub mod files; -pub mod functions; -pub mod imports; -pub mod operations; -pub mod statements; -pub mod types; -pub mod values; - -pub mod errors; -pub use errors::*; - -pub(crate) mod span; -pub(crate) use span::*; - -use from_pest::FromPest; -use std::{fs, path::Path}; - -/// -/// 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 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()))?); - - // Parse the file using leo.pest - let file = &mut ast::parse(&program_string) - .map_err(|error| ParserError::from(error.with_path(file_path.to_str().unwrap())))?; - - // Builds the abstract syntax tree using pest derivation. - let ast = files::File::<'ast>::from_pest(file).map_err(|_| ParserError::SyntaxTreeError)?; - tracing::debug!("{:#?}", ast); - - Ok(Self { 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/main.rs b/grammar/src/main.rs deleted file mode 100644 index ae9259084c..0000000000 --- a/grammar/src/main.rs +++ /dev/null @@ -1,68 +0,0 @@ -// 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::{Grammar, ParserError}; -use std::{env, fs, path::Path}; - -fn to_grammar(filepath: &Path) -> Result { - // Loads the Leo code as a string from the given file path. - let program_filepath = filepath.to_path_buf(); - let program_string = Grammar::load_file(&program_filepath)?; - - // Parses the Leo file and constructs an abstract syntax tree. - let ast = Grammar::new(&program_filepath, &program_string)?; - - // Serializes the abstract syntax tree into JSON format. - let serialized_ast = Grammar::to_json_string(&ast)?; - - Ok(serialized_ast) -} - -fn main() -> Result<(), ParserError> { - // Parse the command-line arguments as strings. - let cli_arguments = env::args().collect::>(); - - // Check that the correct number of command-line arguments were passed in. - if cli_arguments.len() < 2 || cli_arguments.len() > 3 { - eprintln!("Warning - an invalid number of command-line arguments were provided."); - println!( - "\nCommand-line usage:\n\n\tleo_grammar {{PATH/TO/INPUT_FILENAME}}.leo {{PATH/TO/OUTPUT_DIRECTORY (optional)}}\n" - ); - return Ok(()); // Exit innocently - } - - // Construct the input filepath. - let input_filepath = Path::new(&cli_arguments[1]); - - // Construct the serialized abstract syntax tree. - let serialized_ast = to_grammar(&input_filepath)?; - println!("{}", serialized_ast); - - // Determine the output directory. - let output_directory = match cli_arguments.len() == 3 { - true => format!( - "{}/{}.json", - cli_arguments[2], - input_filepath.file_stem().unwrap().to_str().unwrap() - ), - false => format!("./{}.json", input_filepath.file_stem().unwrap().to_str().unwrap()), - }; - - // Write the serialized abstract syntax tree to the output directory. - fs::write(Path::new(&output_directory), serialized_ast)?; - - Ok(()) -} diff --git a/grammar/src/operations/assign_operation.rs b/grammar/src/operations/assign_operation.rs deleted file mode 100644 index 49ea705c3f..0000000000 --- a/grammar/src/operations/assign_operation.rs +++ /dev/null @@ -1,55 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_assign))] -pub enum AssignOperation { - Assign(Assign), - AddAssign(AddAssign), - SubAssign(SubAssign), - MulAssign(MulAssign), - DivAssign(DivAssign), - PowAssign(PowAssign), -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::assign))] -pub struct Assign {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_add_assign))] -pub struct AddAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_sub_assign))] -pub struct SubAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_mul_assign))] -pub struct MulAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_div_assign))] -pub struct DivAssign {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_pow_assign))] -pub struct PowAssign {} diff --git a/grammar/src/operations/binary_operation.rs b/grammar/src/operations/binary_operation.rs deleted file mode 100644 index c6d0290c80..0000000000 --- a/grammar/src/operations/binary_operation.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_binary))] -pub enum BinaryOperation { - Or, - And, - Eq, - Ne, - Ge, - Gt, - Le, - Lt, - Add, - Sub, - Mul, - Div, - Pow, -} diff --git a/grammar/src/operations/mod.rs b/grammar/src/operations/mod.rs deleted file mode 100644 index 60772f4b04..0000000000 --- a/grammar/src/operations/mod.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 assign_operation; -pub use assign_operation::*; - -pub mod binary_operation; -pub use binary_operation::*; - -pub mod unary_operation; -pub use unary_operation::*; diff --git a/grammar/src/operations/unary_operation.rs b/grammar/src/operations/unary_operation.rs deleted file mode 100644 index f261fe7533..0000000000 --- a/grammar/src/operations/unary_operation.rs +++ /dev/null @@ -1,45 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_unary))] -pub enum UnaryOperation { - Negate(Negate), - Not(Not), -} - -impl fmt::Display for UnaryOperation { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - UnaryOperation::Negate(_) => write!(f, "-"), - UnaryOperation::Not(_) => write!(f, "!"), - } - } -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_not))] -pub struct Not {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::operation_negate))] -pub struct Negate {} diff --git a/grammar/src/span.rs b/grammar/src/span.rs deleted file mode 100644 index f7c0eae89d..0000000000 --- a/grammar/src/span.rs +++ /dev/null @@ -1,69 +0,0 @@ -// 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 pest::Span; -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, Deserialize)] -#[serde(remote = "Span")] -pub(crate) struct SpanDef<'i> { - /// # Attention - /// - /// This getter only returns a subset of the input. - /// Namely, it returns `self.input[self.start..self.end]`. - /// This means you can only accurate serialize (and not deserialize). - #[serde(getter = "Span::as_str")] - input: &'i str, - /// # Safety - /// - /// Must be a valid character boundary index into `input`. - #[serde(getter = "Span::start")] - start: usize, - /// # Safety - /// - /// Must be a valid character boundary index into `input`. - #[serde(getter = "Span::end")] - end: usize, -} - -// Provide a conversion to construct the remote type. -impl<'i> From> for Span<'i> { - fn from(def: SpanDef) -> Span { - Span::new(def.input, def.start, def.end).unwrap() - } -} - -#[test] -fn test_span_def() { - // Wrapper serializable JSON struct - #[derive(Serialize)] - struct Element<'ast> { - #[serde(with = "SpanDef")] - span: Span<'ast>, - } - - // Starting value - let span = Span::new("hello world", 1, 5).unwrap(); - let element = Element { span }; - - // Attempt to serialize span to string. - let output = serde_json::to_string(&element).unwrap(); - - let expected_output = "{\"span\":{\"input\":\"ello\",\"start\":1,\"end\":5}}"; - assert_eq!(expected_output, output); -} diff --git a/grammar/src/statements/assign_statement.rs b/grammar/src/statements/assign_statement.rs deleted file mode 100644 index 5325fd7b17..0000000000 --- a/grammar/src/statements/assign_statement.rs +++ /dev/null @@ -1,46 +0,0 @@ -// 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, - common::{Assignee, LineEnd}, - expressions::Expression, - operations::AssignOperation, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement_assign))] -pub struct AssignStatement<'ast> { - pub assignee: Assignee<'ast>, - pub assign: AssignOperation, - pub expression: Expression<'ast>, - pub line_end: LineEnd, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for AssignStatement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} = {};", self.assignee, self.expression) - } -} diff --git a/grammar/src/statements/block.rs b/grammar/src/statements/block.rs deleted file mode 100644 index bbbfe41ff7..0000000000 --- a/grammar/src/statements/block.rs +++ /dev/null @@ -1,45 +0,0 @@ -// 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, statements::Statement, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::block))] -pub struct Block<'ast> { - pub statements: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for Block<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - writeln!(f, "{{")?; - if self.statements.is_empty() { - writeln!(f, "\t")?; - } else { - self.statements - .iter() - .try_for_each(|statement| writeln!(f, "\t{}", statement))?; - } - write!(f, "}}") - } -} diff --git a/grammar/src/statements/conditional_nested_or_end_statement.rs b/grammar/src/statements/conditional_nested_or_end_statement.rs deleted file mode 100644 index 3bab38d701..0000000000 --- a/grammar/src/statements/conditional_nested_or_end_statement.rs +++ /dev/null @@ -1,40 +0,0 @@ -// 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, - statements::{Block, ConditionalStatement}, -}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::conditional_nested_or_end_statement))] -pub enum ConditionalNestedOrEndStatement<'ast> { - Nested(Box>), - End(Block<'ast>), -} - -impl<'ast> fmt::Display for ConditionalNestedOrEndStatement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - ConditionalNestedOrEndStatement::Nested(ref nested) => write!(f, "else {}", nested), - ConditionalNestedOrEndStatement::End(ref block) => write!(f, "else {}", block), - } - } -} diff --git a/grammar/src/statements/conditional_statement.rs b/grammar/src/statements/conditional_statement.rs deleted file mode 100644 index 2e6861f98b..0000000000 --- a/grammar/src/statements/conditional_statement.rs +++ /dev/null @@ -1,48 +0,0 @@ -// 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, - expressions::Expression, - statements::{Block, ConditionalNestedOrEndStatement}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement_conditional))] -pub struct ConditionalStatement<'ast> { - pub condition: Expression<'ast>, - pub block: Block<'ast>, - pub next: Option>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ConditionalStatement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "if ({}) {}", self.condition, self.block)?; - self.next - .as_ref() - .map(|n_or_e| write!(f, " {}", n_or_e)) - .unwrap_or_else(|| write!(f, "")) - } -} diff --git a/grammar/src/statements/definition_statement.rs b/grammar/src/statements/definition_statement.rs deleted file mode 100644 index c1db3c212d..0000000000 --- a/grammar/src/statements/definition_statement.rs +++ /dev/null @@ -1,45 +0,0 @@ -// 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, - common::{Declare, LineEnd, Variables}, - expressions::Expression, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement_definition))] -pub struct DefinitionStatement<'ast> { - pub declare: Declare, - pub variables: Variables<'ast>, - pub expression: Expression<'ast>, - pub line_end: LineEnd, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for DefinitionStatement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "let {} = {};", self.variables, self.expression) - } -} diff --git a/grammar/src/statements/expression_statement.rs b/grammar/src/statements/expression_statement.rs deleted file mode 100644 index bbef3f3568..0000000000 --- a/grammar/src/statements/expression_statement.rs +++ /dev/null @@ -1,31 +0,0 @@ -// 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, common::LineEnd, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement_expression))] -pub struct ExpressionStatement<'ast> { - pub expression: Expression<'ast>, - pub line_end: LineEnd, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/statements/for_statement.rs b/grammar/src/statements/for_statement.rs deleted file mode 100644 index c1be00e303..0000000000 --- a/grammar/src/statements/for_statement.rs +++ /dev/null @@ -1,40 +0,0 @@ -// 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, common::Identifier, expressions::Expression, statements::Block, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement_for))] -pub struct ForStatement<'ast> { - pub index: Identifier<'ast>, - pub start: Expression<'ast>, - pub stop: Expression<'ast>, - pub block: Block<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ForStatement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "for {} in {}..{} {}", self.index, self.start, self.stop, self.block) - } -} diff --git a/grammar/src/statements/mod.rs b/grammar/src/statements/mod.rs deleted file mode 100644 index b6ec4c1136..0000000000 --- a/grammar/src/statements/mod.rs +++ /dev/null @@ -1,42 +0,0 @@ -// 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 assign_statement; -pub use assign_statement::*; - -pub mod conditional_statement; -pub use conditional_statement::*; - -pub mod conditional_nested_or_end_statement; -pub use conditional_nested_or_end_statement::*; - -pub mod definition_statement; -pub use definition_statement::*; - -pub mod expression_statement; -pub use expression_statement::*; - -pub mod for_statement; -pub use for_statement::*; - -pub mod return_statement; -pub use return_statement::*; - -pub mod statement; -pub use statement::*; - -pub mod block; -pub use block::*; diff --git a/grammar/src/statements/return_statement.rs b/grammar/src/statements/return_statement.rs deleted file mode 100644 index 11d6b4ddcb..0000000000 --- a/grammar/src/statements/return_statement.rs +++ /dev/null @@ -1,37 +0,0 @@ -// 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, expressions::Expression, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement_return))] -pub struct ReturnStatement<'ast> { - pub expression: Expression<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for ReturnStatement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "return {}", self.expression) - } -} diff --git a/grammar/src/statements/statement.rs b/grammar/src/statements/statement.rs deleted file mode 100644 index d01c5d072e..0000000000 --- a/grammar/src/statements/statement.rs +++ /dev/null @@ -1,49 +0,0 @@ -// 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, console::ConsoleFunctionCall, statements::*}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::statement))] -pub enum Statement<'ast> { - Return(ReturnStatement<'ast>), - Definition(DefinitionStatement<'ast>), - Assign(AssignStatement<'ast>), - Conditional(ConditionalStatement<'ast>), - Iteration(ForStatement<'ast>), - Console(ConsoleFunctionCall<'ast>), - Expression(ExpressionStatement<'ast>), - Block(Block<'ast>), -} - -impl<'ast> fmt::Display for Statement<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Statement::Return(ref statement) => write!(f, "{}", statement), - Statement::Definition(ref statement) => write!(f, "{}", statement), - Statement::Assign(ref statement) => write!(f, "{}", statement), - Statement::Conditional(ref statement) => write!(f, "{}", statement), - Statement::Iteration(ref statement) => write!(f, "{}", statement), - Statement::Console(ref statement) => write!(f, "{}", statement), - Statement::Expression(ref statement) => write!(f, "{}", statement.expression), - Statement::Block(ref block) => write!(f, "{}", block), - } - } -} diff --git a/grammar/src/types/address_type.rs b/grammar/src/types/address_type.rs deleted file mode 100644 index 5c55367b1a..0000000000 --- a/grammar/src/types/address_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_address))] -pub struct AddressType {} diff --git a/grammar/src/types/array_dimensions.rs b/grammar/src/types/array_dimensions.rs deleted file mode 100644 index eb0aa89b1c..0000000000 --- a/grammar/src/types/array_dimensions.rs +++ /dev/null @@ -1,55 +0,0 @@ -// 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, values::PositiveNumber, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::array_dimensions))] -pub enum ArrayDimensions<'ast> { - Single(Single<'ast>), - Multiple(Multiple<'ast>), -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::dimension_single))] -pub struct Single<'ast> { - pub number: PositiveNumber<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::dimension_multiple))] -pub struct Multiple<'ast> { - pub numbers: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> std::fmt::Display for ArrayDimensions<'ast> { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - match *self { - ArrayDimensions::Single(ref single) => write!(f, "{}", single.number), - ArrayDimensions::Multiple(ref multiple) => write!(f, "{:?}", multiple.numbers), - } - } -} diff --git a/grammar/src/types/array_type.rs b/grammar/src/types/array_type.rs deleted file mode 100644 index a91b08558b..0000000000 --- a/grammar/src/types/array_type.rs +++ /dev/null @@ -1,35 +0,0 @@ -// 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, - types::{ArrayDimensions, Type}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_array))] -pub struct ArrayType<'ast> { - pub type_: Box>, - pub dimensions: ArrayDimensions<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/types/boolean_type.rs b/grammar/src/types/boolean_type.rs deleted file mode 100644 index f5502067c7..0000000000 --- a/grammar/src/types/boolean_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_boolean))] -pub struct BooleanType {} diff --git a/grammar/src/types/circuit_type.rs b/grammar/src/types/circuit_type.rs deleted file mode 100644 index c0156e100a..0000000000 --- a/grammar/src/types/circuit_type.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, common::Identifier, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_circuit))] -pub struct CircuitType<'ast> { - pub identifier: Identifier<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/types/data_type.rs b/grammar/src/types/data_type.rs deleted file mode 100644 index 78143384a5..0000000000 --- a/grammar/src/types/data_type.rs +++ /dev/null @@ -1,33 +0,0 @@ -// 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, - types::{AddressType, BooleanType, FieldType, GroupType, IntegerType}, -}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_data))] -pub enum DataType { - Address(AddressType), - Boolean(BooleanType), - Field(FieldType), - Group(GroupType), - Integer(IntegerType), -} diff --git a/grammar/src/types/field_type.rs b/grammar/src/types/field_type.rs deleted file mode 100644 index 6a5215e9cb..0000000000 --- a/grammar/src/types/field_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_field))] -pub struct FieldType {} diff --git a/grammar/src/types/group_type.rs b/grammar/src/types/group_type.rs deleted file mode 100644 index c1fe720dcd..0000000000 --- a/grammar/src/types/group_type.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_group))] -pub struct GroupType {} diff --git a/grammar/src/types/integer_type.rs b/grammar/src/types/integer_type.rs deleted file mode 100644 index 729ac0fcc4..0000000000 --- a/grammar/src/types/integer_type.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, - types::{SignedIntegerType, UnsignedIntegerType}, -}; - -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_integer))] -pub enum IntegerType { - Signed(SignedIntegerType), - Unsigned(UnsignedIntegerType), -} diff --git a/grammar/src/types/mod.rs b/grammar/src/types/mod.rs deleted file mode 100644 index 20da13b6db..0000000000 --- a/grammar/src/types/mod.rs +++ /dev/null @@ -1,57 +0,0 @@ -// 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_type; -pub use address_type::*; - -pub mod array_dimensions; -pub use array_dimensions::*; - -pub mod array_type; -pub use array_type::*; - -pub mod boolean_type; -pub use boolean_type::*; - -pub mod circuit_type; -pub use circuit_type::*; - -pub mod data_type; -pub use data_type::*; - -pub mod field_type; -pub use field_type::*; - -pub mod group_type; -pub use group_type::*; - -pub mod integer_type; -pub use integer_type::*; - -pub mod self_type; -pub use self_type::*; - -pub mod signed_integer_type; -pub use signed_integer_type::*; - -pub mod tuple_type; -pub use tuple_type::*; - -pub mod type_; -pub use type_::*; - -pub mod unsigned_integer_type; -pub use unsigned_integer_type::*; diff --git a/grammar/src/types/self_type.rs b/grammar/src/types/self_type.rs deleted file mode 100644 index e3fb6bd072..0000000000 --- a/grammar/src/types/self_type.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_self))] -pub struct SelfType<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub keyword: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for SelfType<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.keyword) - } -} diff --git a/grammar/src/types/signed_integer_type.rs b/grammar/src/types/signed_integer_type.rs deleted file mode 100644 index f615ffd747..0000000000 --- a/grammar/src/types/signed_integer_type.rs +++ /dev/null @@ -1,63 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_integer_signed))] -pub enum SignedIntegerType { - I8Type(I8Type), - I16Type(I16Type), - I32Type(I32Type), - I64Type(I64Type), - I128Type(I128Type), -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_i8))] -pub struct I8Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_i16))] -pub struct I16Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_i32))] -pub struct I32Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_i64))] -pub struct I64Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_i128))] -pub struct I128Type {} - -impl fmt::Display for SignedIntegerType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - SignedIntegerType::I8Type(_) => write!(f, "i8"), - SignedIntegerType::I16Type(_) => write!(f, "i16"), - SignedIntegerType::I32Type(_) => write!(f, "i32"), - SignedIntegerType::I64Type(_) => write!(f, "i64"), - SignedIntegerType::I128Type(_) => write!(f, "i128"), - } - } -} diff --git a/grammar/src/types/tuple_type.rs b/grammar/src/types/tuple_type.rs deleted file mode 100644 index 57f39c9261..0000000000 --- a/grammar/src/types/tuple_type.rs +++ /dev/null @@ -1,30 +0,0 @@ -// 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, types::Type, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_tuple))] -pub struct TupleType<'ast> { - pub types: Vec>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/types/type_.rs b/grammar/src/types/type_.rs deleted file mode 100644 index d020a7ef07..0000000000 --- a/grammar/src/types/type_.rs +++ /dev/null @@ -1,43 +0,0 @@ -// 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, types::*}; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_))] -pub enum Type<'ast> { - Basic(DataType), - Array(ArrayType<'ast>), - Tuple(TupleType<'ast>), - Circuit(CircuitType<'ast>), - SelfType(SelfType<'ast>), -} - -impl<'ast> fmt::Display for Type<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Type::Basic(ref _type) => write!(f, "basic"), - Type::Array(ref _type) => write!(f, "array"), - Type::Tuple(ref _type) => write!(f, "tuple"), - Type::Circuit(ref _type) => write!(f, "struct"), - Type::SelfType(ref type_) => write!(f, "{}", type_.keyword), - } - } -} diff --git a/grammar/src/types/unsigned_integer_type.rs b/grammar/src/types/unsigned_integer_type.rs deleted file mode 100644 index 734737604c..0000000000 --- a/grammar/src/types/unsigned_integer_type.rs +++ /dev/null @@ -1,63 +0,0 @@ -// 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; - -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_integer_unsigned))] -pub enum UnsignedIntegerType { - U8Type(U8Type), - U16Type(U16Type), - U32Type(U32Type), - U64Type(U64Type), - U128Type(U128Type), -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_u8))] -pub struct U8Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_u16))] -pub struct U16Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_u32))] -pub struct U32Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_u64))] -pub struct U64Type {} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::type_u128))] -pub struct U128Type {} - -impl fmt::Display for UnsignedIntegerType { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - UnsignedIntegerType::U8Type(_) => write!(f, "u8"), - UnsignedIntegerType::U16Type(_) => write!(f, "u16"), - UnsignedIntegerType::U32Type(_) => write!(f, "u32"), - UnsignedIntegerType::U64Type(_) => write!(f, "u64"), - UnsignedIntegerType::U128Type(_) => write!(f, "u128"), - } - } -} diff --git a/grammar/src/values/address.rs b/grammar/src/values/address.rs deleted file mode 100644 index e1e815a6e7..0000000000 --- a/grammar/src/values/address.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::address))] -pub struct Address<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for Address<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} diff --git a/grammar/src/values/address_value.rs b/grammar/src/values/address_value.rs deleted file mode 100644 index decf47431e..0000000000 --- a/grammar/src/values/address_value.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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, types::AddressType, values::address::Address, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_address))] -pub struct AddressValue<'ast> { - pub _type: AddressType, - pub address: Address<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for AddressValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.address) - } -} diff --git a/grammar/src/values/boolean_value.rs b/grammar/src/values/boolean_value.rs deleted file mode 100644 index 9e26d369f9..0000000000 --- a/grammar/src/values/boolean_value.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_boolean))] -pub struct BooleanValue<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for BooleanValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} diff --git a/grammar/src/values/field_value.rs b/grammar/src/values/field_value.rs deleted file mode 100644 index fad986b83e..0000000000 --- a/grammar/src/values/field_value.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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, types::FieldType, values::NumberValue, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_field))] -pub struct FieldValue<'ast> { - pub number: NumberValue<'ast>, - pub _type: FieldType, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for FieldValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.number) - } -} diff --git a/grammar/src/values/group_coordinate.rs b/grammar/src/values/group_coordinate.rs deleted file mode 100644 index 4f12c477d4..0000000000 --- a/grammar/src/values/group_coordinate.rs +++ /dev/null @@ -1,77 +0,0 @@ -// 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, values::NumberValue, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::group_coordinate))] -pub enum GroupCoordinate<'ast> { - Number(NumberValue<'ast>), - SignHigh(SignHigh<'ast>), - SignLow(SignLow<'ast>), - Inferred(Inferred<'ast>), -} - -impl<'ast> GroupCoordinate<'ast> { - pub fn span(&self) -> &Span<'ast> { - match self { - GroupCoordinate::Number(number) => &number.span(), - GroupCoordinate::SignHigh(sign_high) => &sign_high.span, - GroupCoordinate::SignLow(sign_low) => &sign_low.span, - GroupCoordinate::Inferred(inferred) => &inferred.span, - } - } -} - -impl<'ast> fmt::Display for GroupCoordinate<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - GroupCoordinate::Number(number) => write!(f, "{}", number), - GroupCoordinate::SignHigh(_) => write!(f, "+"), - GroupCoordinate::SignLow(_) => write!(f, "-"), - GroupCoordinate::Inferred(_) => write!(f, "_"), - } - } -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::sign_high))] -pub struct SignHigh<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::sign_low))] -pub struct SignLow<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::inferred))] -pub struct Inferred<'ast> { - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} diff --git a/grammar/src/values/group_value.rs b/grammar/src/values/group_value.rs deleted file mode 100644 index 56ab231908..0000000000 --- a/grammar/src/values/group_value.rs +++ /dev/null @@ -1,75 +0,0 @@ -// 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, - types::GroupType, - values::{GroupCoordinate, NumberValue}, - SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_group))] -pub struct GroupValue<'ast> { - pub value: GroupRepresentation<'ast>, - pub type_: GroupType, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for GroupValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::group_single_or_tuple))] -pub enum GroupRepresentation<'ast> { - Single(NumberValue<'ast>), - Tuple(GroupTuple<'ast>), -} - -impl<'ast> fmt::Display for GroupRepresentation<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - GroupRepresentation::Single(number) => write!(f, "{}", number), - GroupRepresentation::Tuple(tuple) => write!(f, "{}", tuple), - } - } -} - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::group_tuple))] -pub struct GroupTuple<'ast> { - pub x: GroupCoordinate<'ast>, - pub y: GroupCoordinate<'ast>, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for GroupTuple<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "({}, {})", self.x, self.y) - } -} diff --git a/grammar/src/values/integer_value.rs b/grammar/src/values/integer_value.rs deleted file mode 100644 index 64c0ebd640..0000000000 --- a/grammar/src/values/integer_value.rs +++ /dev/null @@ -1,50 +0,0 @@ -// 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, - values::{SignedIntegerValue, UnsignedIntegerValue}, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_integer))] -pub enum IntegerValue<'ast> { - Signed(SignedIntegerValue<'ast>), - Unsigned(UnsignedIntegerValue<'ast>), -} - -impl<'ast> IntegerValue<'ast> { - pub fn span(&self) -> &Span<'ast> { - match self { - IntegerValue::Signed(integer) => &integer.span, - IntegerValue::Unsigned(integer) => &integer.span, - } - } -} - -impl<'ast> fmt::Display for IntegerValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - IntegerValue::Signed(integer) => write!(f, "{}", integer), - IntegerValue::Unsigned(integer) => write!(f, "{}", integer), - } - } -} diff --git a/grammar/src/values/mod.rs b/grammar/src/values/mod.rs deleted file mode 100644 index 8fd2211392..0000000000 --- a/grammar/src/values/mod.rs +++ /dev/null @@ -1,54 +0,0 @@ -// 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 use address_value::*; - -pub mod address_value; -pub use address_value::*; - -pub mod boolean_value; -pub use boolean_value::*; - -pub mod field_value; -pub use field_value::*; - -pub mod group_coordinate; -pub use group_coordinate::*; - -pub mod group_value; -pub use group_value::*; - -pub mod integer_value; -pub use integer_value::*; - -pub mod number_value; -pub use number_value::*; - -pub mod positive_number; -pub use positive_number::*; - -pub mod negative_number; -pub use negative_number::*; - -pub mod signed_integer_value; -pub use signed_integer_value::*; - -pub mod unsigned_integer_value; -pub use unsigned_integer_value::*; - -pub mod value; -pub use value::*; diff --git a/grammar/src/values/negative_number.rs b/grammar/src/values/negative_number.rs deleted file mode 100644 index 5cd52eaef0..0000000000 --- a/grammar/src/values/negative_number.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - span::SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::number_negative))] -pub struct NegativeNumber<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for NegativeNumber<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} diff --git a/grammar/src/values/number_value.rs b/grammar/src/values/number_value.rs deleted file mode 100644 index 1d090c7528..0000000000 --- a/grammar/src/values/number_value.rs +++ /dev/null @@ -1,50 +0,0 @@ -// 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, - values::{NegativeNumber, PositiveNumber}, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_number))] -pub enum NumberValue<'ast> { - Negative(NegativeNumber<'ast>), - Positive(PositiveNumber<'ast>), -} - -impl<'ast> NumberValue<'ast> { - pub fn span(&self) -> &Span<'ast> { - match self { - NumberValue::Negative(number) => &number.span, - NumberValue::Positive(number) => &number.span, - } - } -} - -impl<'ast> fmt::Display for NumberValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match self { - NumberValue::Negative(number) => write!(f, "{}", number), - NumberValue::Positive(number) => write!(f, "{}", number), - } - } -} diff --git a/grammar/src/values/positive_number.rs b/grammar/src/values/positive_number.rs deleted file mode 100644 index 8fd522836f..0000000000 --- a/grammar/src/values/positive_number.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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::{span_into_string, Rule}, - span::SpanDef, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::number_positive))] -pub struct PositiveNumber<'ast> { - #[pest_ast(outer(with(span_into_string)))] - pub value: String, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for PositiveNumber<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self.value) - } -} diff --git a/grammar/src/values/signed_integer_value.rs b/grammar/src/values/signed_integer_value.rs deleted file mode 100644 index 5c49a0ebf1..0000000000 --- a/grammar/src/values/signed_integer_value.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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, types::SignedIntegerType, values::NumberValue, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_integer_signed))] -pub struct SignedIntegerValue<'ast> { - pub number: NumberValue<'ast>, - pub type_: SignedIntegerType, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for SignedIntegerValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}", self.number, self.type_) - } -} diff --git a/grammar/src/values/unsigned_integer_value.rs b/grammar/src/values/unsigned_integer_value.rs deleted file mode 100644 index 9b85ae8eea..0000000000 --- a/grammar/src/values/unsigned_integer_value.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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, types::UnsignedIntegerType, values::PositiveNumber, SpanDef}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value_integer_unsigned))] -pub struct UnsignedIntegerValue<'ast> { - pub number: PositiveNumber<'ast>, - pub type_: UnsignedIntegerType, - #[pest_ast(outer())] - #[serde(with = "SpanDef")] - pub span: Span<'ast>, -} - -impl<'ast> fmt::Display for UnsignedIntegerValue<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}{}", self.number, self.type_) - } -} diff --git a/grammar/src/values/value.rs b/grammar/src/values/value.rs deleted file mode 100644 index 2d92362c28..0000000000 --- a/grammar/src/values/value.rs +++ /dev/null @@ -1,62 +0,0 @@ -// 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, - values::{AddressValue, BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue}, -}; - -use pest::Span; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; - -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::value))] -pub enum Value<'ast> { - Address(AddressValue<'ast>), - Boolean(BooleanValue<'ast>), - Field(FieldValue<'ast>), - Group(GroupValue<'ast>), - Implicit(NumberValue<'ast>), - Integer(IntegerValue<'ast>), -} - -impl<'ast> Value<'ast> { - pub fn span(&self) -> &Span<'ast> { - match self { - Value::Address(value) => &value.span, - Value::Boolean(value) => &value.span, - Value::Field(value) => &value.span, - Value::Group(value) => &value.span, - Value::Implicit(value) => &value.span(), - Value::Integer(value) => &value.span(), - } - } -} - -impl<'ast> fmt::Display for Value<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Value::Address(ref value) => write!(f, "{}", value), - Value::Boolean(ref value) => write!(f, "{}", value), - Value::Field(ref value) => write!(f, "{}", value), - Value::Group(ref value) => write!(f, "{}", value), - Value::Implicit(ref value) => write!(f, "{}", value), - Value::Integer(ref value) => write!(f, "{}", value), - } - } -} diff --git a/grammar/tests/annotated.rs b/grammar/tests/annotated.rs deleted file mode 100644 index 32ac106dba..0000000000 --- a/grammar/tests/annotated.rs +++ /dev/null @@ -1,43 +0,0 @@ -// 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_annotation_no_context_test() { - parses_to! { - parser: LanguageParser, - input: "@test", - rule: Rule::annotation, - tokens: [ - annotation(0, 5, [annotation_symbol(0, 1, []), annotation_name(1, 5, [test(1, 5, [])])]) - ] - } -} - -#[test] -fn test_annotation_context_test() { - parses_to! { - parser: LanguageParser, - input: "@test(custom)", - rule: Rule::annotation, - tokens: [ - annotation(0, 13, [annotation_symbol(0, 1, []), annotation_name(1, 5, [test(1, 5, [])]), annotation_arguments(5, 13, [annotation_argument(6, 12, [])])]) - ] - } -} diff --git a/grammar/tests/circuits.rs b/grammar/tests/circuits.rs deleted file mode 100644 index 33c77151ca..0000000000 --- a/grammar/tests/circuits.rs +++ /dev/null @@ -1,116 +0,0 @@ -// 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/deprecated.rs b/grammar/tests/deprecated.rs deleted file mode 100644 index 5ff8f94cb0..0000000000 --- a/grammar/tests/deprecated.rs +++ /dev/null @@ -1,56 +0,0 @@ -// 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_deprecated_test_function() { - parses_to! { - parser: LanguageParser, - input: r#"test function old() { - return () -}"#, - rule: Rule::deprecated, - tokens: [ - deprecated(0, 37, [ - test_function(0, 37, [ - function(5, 37, [ - identifier(14, 17, []), - block(20, 37, [ - statement(26, 36, [ - statement_return(26, 36, [expression(33, 36, [expression_term(33, 35, [expression_tuple(33, 35, [])])])]) - ]) - ]) - ]) - ]) - ]) - ] - } -} - -#[test] -fn test_deprecated_context_function() { - parses_to! { - parser: LanguageParser, - input: "@context(custom)", - rule: Rule::annotation, - tokens: [ - annotation(0, 16, [annotation_symbol(0, 1, []), annotation_name(1, 8, [context(1, 8, [])]), annotation_arguments(8, 16, [annotation_argument(9, 15, [])])]) - ] - } -} diff --git a/grammar/tests/display.rs b/grammar/tests/display.rs deleted file mode 100644 index 38aaf42a70..0000000000 --- a/grammar/tests/display.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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 from_pest::FromPest; -use leo_grammar::{ - ast::{LanguageParser, Rule}, - statements::ConditionalStatement, -}; - -use pest::*; - -#[test] -fn conditional_statement_display() { - let input = r#"if (true) { - -} else { - -}"#; - let conditional_statement = - ConditionalStatement::from_pest(&mut LanguageParser::parse(Rule::statement_conditional, input).unwrap()) - .unwrap(); - let displayed = format!("{}", conditional_statement); - - assert_eq!(input, displayed); -} diff --git a/grammar/tests/expression.rs b/grammar/tests/expression.rs deleted file mode 100644 index 589c16bcee..0000000000 --- a/grammar/tests/expression.rs +++ /dev/null @@ -1,55 +0,0 @@ -// 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 redundant_parens() { - parses_to! { - parser: LanguageParser, - input: "(true)", - rule: Rule::expression, - tokens: [ - expression(0, 6, [ - expression_term(0, 6, [expression(1, 5, [expression_term(1, 5, [value(1, 5, [value_boolean(1, 5, [])])])])]) - ]) - ] - } -} - -#[test] -fn multiple_redundant_parens() { - parses_to! { - parser: LanguageParser, - input: "(((true)))", - rule: Rule::expression, - tokens: [ - expression(0, 10, [ - expression_term(0, 10, [ - expression(1, 9, [expression_term(1, 9, [ - expression(2, 8, [expression_term(2, 8, [ - expression(3, 7, [expression_term(3, 7, [ - value(3, 7, [value_boolean(3, 7, [])]) - ])]) - ])]) - ])]) - ]) - ]) - ] - } -} diff --git a/grammar/tests/function.rs b/grammar/tests/function.rs deleted file mode 100644 index 4bc1de7bf7..0000000000 --- a/grammar/tests/function.rs +++ /dev/null @@ -1,135 +0,0 @@ -// 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 call_wo_args() { - parses_to! { - parser: LanguageParser, - input: "x()", - rule: Rule::expression_postfix, - tokens: [ - expression_postfix(0, 3, [ - keyword_or_identifier(0, 1, [identifier(0, 1, [])]), - access(1, 3, [access_call(1, 3, [])]) - ]) - ] - } -} - -#[test] -fn call_with_arg() { - parses_to! { - parser: LanguageParser, - input: "x(true)", - rule: Rule::expression_postfix, - tokens: [ - expression_postfix(0, 7, [ - keyword_or_identifier(0, 1, [identifier(0, 1, [])]), - access(1, 7, [access_call(1, 7, [ - expression(2, 6, [expression_term(2, 6, [value(2, 6, [value_boolean(2, 6, [])])])]) - ])]) - ]) - ] - } -} - -#[test] -fn call_with_2_args() { - parses_to! { - parser: LanguageParser, - input: "x(true, false)", - rule: Rule::expression_postfix, - tokens: [ - expression_postfix(0, 14, [ - keyword_or_identifier(0, 1, [identifier(0, 1, [])]), - access(1, 14, [access_call(1, 14, [ - expression(2, 6, [expression_term(2, 6, [value(2, 6, [value_boolean(2, 6, [])])])]), - expression(8, 13, [expression_term(8, 13, [value(8, 13, [value_boolean(8, 13, [])])])]) - ])]) - ]) - ] - } -} - -#[test] -fn empty_def() { - parses_to! { - parser: LanguageParser, - input: "function x() {}", - rule: Rule::function, - tokens: [ - function(0, 15, [identifier(9, 10, []), block(13, 15, [])]) - ] - } -} - -#[test] -fn returning_unit_type() { - parses_to! { - parser: LanguageParser, - input: "function x() -> () {}", - rule: Rule::function, - tokens: [ - function(0, 21, [identifier(9, 10, []), type_(16, 18, [type_tuple(16, 18, [])]), block(19, 21, [])]) - ] - } -} - -#[test] -fn returning_unit_value() { - parses_to! { - parser: LanguageParser, - input: "function x() { return () }", - rule: Rule::function, - tokens: [ - function(0, 26, [identifier(9, 10, []), block(13, 26, [ - statement(15, 25, [ - statement_return(15, 25, [expression(22, 25, [expression_term(22, 24, [expression_tuple(22, 24, [])])])]) - ]) - ])]) - ] - } -} - -#[test] -fn id_def() { - parses_to! { - parser: LanguageParser, - input: "function id(x: u8) -> u8 { return x }", - rule: Rule::function, - tokens: [ - function(0, 37, [ - identifier(9, 11, []), - input(12, 17, [ - function_input(12, 17, [ - identifier(12, 13, []), - type_(15, 17, [type_data(15, 17, [type_integer(15, 17, [type_integer_unsigned(15, 17, [type_u8(15, 17, [])])])])]) - ]) - ]), - type_(22, 24, [type_data(22, 24, [type_integer(22, 24, [type_integer_unsigned(22, 24, [type_u8(22, 24, [])])])])]), - block(25, 37, [ - statement(27, 36, [statement_return(27, 36, [ - expression(34, 36, [expression_term(34, 35, [identifier(34, 35, [])])]) - ])]) - ]), - ]) - ] - } -} diff --git a/grammar/tests/imports.rs b/grammar/tests/imports.rs deleted file mode 100644 index 8ddd874e3d..0000000000 --- a/grammar/tests/imports.rs +++ /dev/null @@ -1,91 +0,0 @@ -// 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_or_packages(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_or_packages(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_or_packages(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/grammar/tests/leo-samples/multiline.leo b/grammar/tests/leo-samples/multiline.leo deleted file mode 100644 index 24eb4e5154..0000000000 --- a/grammar/tests/leo-samples/multiline.leo +++ /dev/null @@ -1,54 +0,0 @@ -// adding multiline support for Leo -// all the code in this file should compile just fine - -circuit BipBop { - bip - : - u32, - - bop - : u32, - - blup : - u32, - - function gimme_five() -> Self { - return Self { - bip: 1, - bop: 2, - blup: 3 - } - } - - function main() -> ( - u32 - , - u64 - ) { - return ( - 100 - , - 1000 - ) - } -} - -function main() -> ( - u32 - , - u64 -) { - let - a - : u32 - = 100 - ; - - let b : ( - u32, - u64 - ) = BipBop::gimme_five().main(); - - console.assert(true); -} - diff --git a/grammar/tests/mod.rs b/grammar/tests/mod.rs deleted file mode 100644 index 6b53d18df3..0000000000 --- a/grammar/tests/mod.rs +++ /dev/null @@ -1,21 +0,0 @@ -// 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 display; -mod expression; -mod function; -mod serialization; -mod tuple; diff --git a/grammar/tests/multiline.rs b/grammar/tests/multiline.rs deleted file mode 100644 index 2c3fca1706..0000000000 --- a/grammar/tests/multiline.rs +++ /dev/null @@ -1,24 +0,0 @@ -// 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 multiline() { - let multiline_sample = include_str!("leo-samples/multiline.leo"); - LanguageParser::parse(Rule::file, multiline_sample).expect("Can't parse multiline expression"); -} diff --git a/grammar/tests/self.rs b/grammar/tests/self.rs deleted file mode 100644 index 8157639e42..0000000000 --- a/grammar/tests/self.rs +++ /dev/null @@ -1,50 +0,0 @@ -// 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 self_call() { - parses_to! { - parser: LanguageParser, - input: "self.hello()", - rule: Rule::self_expression_postfix, - tokens: [ - self_expression_postfix(0, 12, [ - self_keyword(0, 4, []), - self_access(4, 10, [access_member(4, 10, [identifier(5, 10, [])])]), - access(10, 12, [access_call(10, 12, [])]) - ]) - ] - } -} - -#[test] -fn self_static() { - parses_to! { - parser: LanguageParser, - input: "self::hello()", - rule: Rule::self_expression_postfix, - tokens: [ - self_expression_postfix(0, 13, [ - self_keyword(0, 4, []), - self_access(4, 11, [access_static_member(4, 11, [identifier(6, 11, [])])]), - access(11, 13, [access_call(11, 13, [])]) - ]) - ] - } -} diff --git a/grammar/tests/serialization/expected_ast.json b/grammar/tests/serialization/expected_ast.json deleted file mode 100644 index cbbcf20a69..0000000000 --- a/grammar/tests/serialization/expected_ast.json +++ /dev/null @@ -1,85 +0,0 @@ -{ - "definitions": [ - { - "Function": { - "identifier": { - "value": "main", - "span": { - "input": "main", - "start": 9, - "end": 13 - } - }, - "parameters": [], - "returns": null, - "block": { - "statements": [ - { - "Return": { - "expression": { - "Binary": { - "operation": "Add", - "left": { - "Value": { - "Implicit": { - "Positive": { - "value": "1", - "span": { - "input": "1", - "start": 29, - "end": 30 - } - } - } - } - }, - "right": { - "Value": { - "Implicit": { - "Positive": { - "value": "1", - "span": { - "input": "1", - "start": 33, - "end": 34 - } - } - } - } - }, - "span": { - "input": "1 + 1", - "start": 29, - "end": 34 - } - } - }, - "span": { - "input": "return 1 + 1", - "start": 22, - "end": 34 - } - } - } - ], - "span": { - "input": "{\n return 1 + 1\n}", - "start": 16, - "end": 36 - } - }, - "span": { - "input": "function main() {\n return 1 + 1\n}", - "start": 0, - "end": 36 - } - } - } - ], - "eoi": null, - "span": { - "input": "function main() {\n return 1 + 1\n}\n", - "start": 0, - "end": 37 - } -} \ No newline at end of file diff --git a/grammar/tests/serialization/json.rs b/grammar/tests/serialization/json.rs deleted file mode 100644 index e940b4e764..0000000000 --- a/grammar/tests/serialization/json.rs +++ /dev/null @@ -1,38 +0,0 @@ -// 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 . - -#[test] -#[cfg(not(feature = "ci_skip"))] -fn test_serialize() { - use leo_grammar::Grammar; - use std::path::PathBuf; - - let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - program_filepath.push("tests/serialization/main.leo"); - - let expected = include_str!("./expected_ast.json"); - - // Loads the Leo code as a string from the given file path. - let program_string = Grammar::load_file(&program_filepath).unwrap(); - - // Parses the Leo file and constructs an abstract syntax tree. - let ast = Grammar::new(&program_filepath, &program_string).unwrap(); - - // Serializes the abstract syntax tree into JSON format. - let serialized_ast = Grammar::to_json_string(&ast).unwrap(); - - assert_eq!(expected, serialized_ast); -} diff --git a/grammar/tests/serialization/main.leo b/grammar/tests/serialization/main.leo deleted file mode 100644 index ef22115243..0000000000 --- a/grammar/tests/serialization/main.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - return 1 + 1 -} diff --git a/grammar/tests/serialization/mod.rs b/grammar/tests/serialization/mod.rs deleted file mode 100644 index 5096607ede..0000000000 --- a/grammar/tests/serialization/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -// 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 json; diff --git a/grammar/tests/tuple.rs b/grammar/tests/tuple.rs deleted file mode 100644 index 1408d5c0d8..0000000000 --- a/grammar/tests/tuple.rs +++ /dev/null @@ -1,107 +0,0 @@ -// 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 implicitly_typed() { - parses_to! { - parser: LanguageParser, - input: "(true, false)", - rule: Rule::expression_tuple, - tokens: [ - expression_tuple(0, 13, [ - expression(1, 5, [expression_term(1, 5, [value(1, 5, [value_boolean(1, 5, [])])])]), - expression(7, 12, [expression_term(7, 12, [value(7, 12, [value_boolean(7, 12, [])])])]) - ]) - ] - } -} - -#[test] -fn explicitly_typed() { - parses_to! { - parser: LanguageParser, - input: "let tup: (bool, bool) = (true, false);", - rule: Rule::statement_definition, - tokens: [ - statement_definition(0, 38, [ - declare(0, 4, [let_(0, 4, [])]), - variables(4, 21, [ - variable_name(4, 7, [identifier(4, 7, [])]), - type_(9, 21, [type_tuple(9, 21, [ - type_(10, 14, [type_data(10, 14, [type_boolean(10, 14, [])])]), - type_(16, 20, [type_data(16, 20, [type_boolean(16, 20, [])])]), - ])]) - ]), - expression(24, 37, [expression_term(24, 37, [expression_tuple(24, 37, [ - expression(25, 29, [expression_term(25, 29, [value(25, 29, [value_boolean(25, 29, [])])])]), - expression(31, 36, [expression_term(31, 36, [value(31, 36, [value_boolean(31, 36, [])])])]), - ])])]), - LINE_END(37, 38, []) - ]) - ] - } -} - -#[test] -fn access() { - parses_to! { - parser: LanguageParser, - input: "x.0", - rule: Rule::expression_postfix, - tokens: [ - expression_postfix(0, 3, [ - keyword_or_identifier(0, 1, [identifier(0, 1, [])]), - access(1, 3, [access_tuple(1, 3, [number_positive(2, 3, [])])]) - ]) - ] - } -} - -#[test] -fn implicit_unit() { - parses_to! { - parser: LanguageParser, - input: "()", - rule: Rule::expression_tuple, - tokens: [ - expression_tuple(0, 2, []) - ] - } -} - -#[test] -fn explicit_unit() { - parses_to! { - parser: LanguageParser, - input: "let x: () = ();", - rule: Rule::statement_definition, - tokens: [ - statement_definition(0, 15, [ - declare(0, 4, [let_(0, 4, [])]), - variables(4, 9, [ - variable_name(4, 5, [identifier(4, 5, [])]), - type_(7, 9, [type_tuple(7, 9, [])]) - ]), - expression(12, 14, [expression_term(12, 14, [expression_tuple(12, 14, [])])]), - LINE_END(14, 15, []) - ]) - ] - } -} diff --git a/imports/Cargo.toml b/imports/Cargo.toml index f7a53f98fc..c7e143d0a1 100644 --- a/imports/Cargo.toml +++ b/imports/Cargo.toml @@ -21,14 +21,14 @@ edition = "2018" path = "../ast" version = "1.2.3" -[dependencies.leo-grammar] -path = "../grammar" -version = "1.2.3" - [dependencies.leo-asg] path = "../asg" version = "1.2.3" +[dependencies.leo-parser] +path = "../parser" +version = "1.2.3" + [dependencies.indexmap] version = "1.6.1" features = [ "serde-1" ] diff --git a/imports/src/errors/import_parser.rs b/imports/src/errors/import_parser.rs index f3d901560c..1272d7e1e5 100644 --- a/imports/src/errors/import_parser.rs +++ b/imports/src/errors/import_parser.rs @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . use leo_asg::AsgConvertError; -use leo_ast::{AstError, DeprecatedError, Error as FormattedError, Identifier, Span}; -use leo_grammar::ParserError; +use leo_ast::{FormattedError, Identifier, LeoError, Span}; +use leo_parser::{DeprecatedError, SyntaxError}; use std::{io, path::Path}; @@ -28,44 +28,60 @@ pub enum ImportParserError { Error(#[from] FormattedError), #[error("{}", _0)] - ParserError(#[from] ParserError), + SyntaxError(#[from] SyntaxError), #[error("{}", _0)] AsgConvertError(#[from] AsgConvertError), } +impl LeoError for ImportParserError { + fn get_path(&self) -> Option<&str> { + match self { + ImportParserError::Error(error) => error.get_path(), + ImportParserError::SyntaxError(error) => error.get_path(), + ImportParserError::AsgConvertError(error) => error.get_path(), + ImportParserError::DeprecatedError(error) => error.get_path(), + } + } + + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + ImportParserError::Error(error) => error.set_path(path, contents), + ImportParserError::SyntaxError(error) => error.set_path(path, contents), + ImportParserError::AsgConvertError(error) => error.set_path(path, contents), + ImportParserError::DeprecatedError(error) => error.set_path(path, contents), + } + } +} + impl Into for ImportParserError { fn into(self) -> AsgConvertError { match self { ImportParserError::Error(x) => AsgConvertError::ImportError(x), - ImportParserError::ParserError(x) => x.into(), - ImportParserError::DeprecatedError(x) => AsgConvertError::AstError(AstError::DeprecatedError(x)), + ImportParserError::SyntaxError(x) => x.into(), + ImportParserError::DeprecatedError(x) => AsgConvertError::SyntaxError(SyntaxError::DeprecatedError(x)), ImportParserError::AsgConvertError(x) => x, } } } impl ImportParserError { - fn new_from_span(message: String, span: Span) -> Self { + fn new_from_span(message: String, span: &Span) -> Self { ImportParserError::Error(FormattedError::new_from_span(message, span)) } - fn new_from_span_with_path(message: String, span: Span, path: &Path) -> Self { - ImportParserError::Error(FormattedError::new_from_span_with_path(message, span, path)) - } - /// /// An imported package has the same name as an imported core_package. /// pub fn conflicting_imports(identifier: Identifier) -> Self { let message = format!("conflicting imports found for `{}`.", identifier.name); - Self::new_from_span(message, identifier.span) + Self::new_from_span(message, &identifier.span) } pub fn recursive_imports(package: &str, span: &Span) -> Self { let message = format!("recursive imports for `{}`.", package); - Self::new_from_span(message, span.clone()) + Self::new_from_span(message, span) } /// @@ -74,13 +90,13 @@ impl ImportParserError { pub fn duplicate_core_package(identifier: Identifier) -> Self { let message = format!("Duplicate core_package import `{}`.", identifier.name); - Self::new_from_span(message, identifier.span) + Self::new_from_span(message, &identifier.span) } /// /// Failed to convert a file path into an os string. /// - pub fn convert_os_string(span: Span) -> Self { + pub fn convert_os_string(span: &Span) -> Self { let message = "Failed to convert file string name, maybe an illegal character?".to_string(); Self::new_from_span(message, span) @@ -90,30 +106,28 @@ impl ImportParserError { /// Failed to find the directory of the current file. /// pub fn current_directory_error(error: io::Error) -> Self { - let span = Span { - text: "".to_string(), - line: 0, - start: 0, - end: 0, - }; let message = format!("Compilation failed trying to find current directory - {:?}.", error); - Self::new_from_span(message, span) + Self::new_from_span(message, &Span::default()) } /// /// Failed to open or get the name of a directory. /// - pub fn directory_error(error: io::Error, span: Span, path: &Path) -> Self { - let message = format!("Compilation failed due to directory error - {:?}.", error); + pub fn directory_error(error: io::Error, span: &Span, path: &Path) -> Self { + let message = format!( + "Compilation failed due to directory error @ '{}' - {:?}.", + path.to_str().unwrap_or_default(), + error + ); - Self::new_from_span_with_path(message, span, path) + Self::new_from_span(message, span) } /// /// Failed to import all symbols at a package path. /// - pub fn star(path: &Path, span: Span) -> Self { + pub fn star(path: &Path, span: &Span) -> Self { let message = format!("Cannot import `*` from path `{:?}`.", path); Self::new_from_span(message, span) @@ -122,11 +136,8 @@ impl ImportParserError { /// /// Failed to find a library file for the current package. /// - pub fn expected_lib_file(entry: String, span: Span) -> Self { - let message = format!( - "Expected library file`{}` when looking for symbol `{}`.", - entry, span.text - ); + pub fn expected_lib_file(entry: String, span: &Span) -> Self { + let message = format!("Expected library file `{}`.", entry,); Self::new_from_span(message, span) } @@ -140,6 +151,12 @@ impl ImportParserError { identifier.name ); - Self::new_from_span(message, identifier.span) + Self::new_from_span(message, &identifier.span) + } + + pub fn io_error(span: &Span, path: &str, error: std::io::Error) -> Self { + let message = format!("cannot read imported file '{}': {:?}", path, error,); + + Self::new_from_span(message, span) } } diff --git a/imports/src/parser/parse_package.rs b/imports/src/parser/parse_package.rs index 3acd05e41b..546fc7df63 100644 --- a/imports/src/parser/parse_package.rs +++ b/imports/src/parser/parse_package.rs @@ -81,9 +81,9 @@ impl<'a> ImportParser<'a> { // Get a vector of all packages in the source directory. let entries = fs::read_dir(path) - .map_err(|error| ImportParserError::directory_error(error, span.clone(), &error_path))? + .map_err(|error| ImportParserError::directory_error(error, span, &error_path))? .collect::, std::io::Error>>() - .map_err(|error| ImportParserError::directory_error(error, span.clone(), &error_path))?; + .map_err(|error| ImportParserError::directory_error(error, span, &error_path))?; // Check if the imported package name is in the source directory. let matched_source_entry = entries.into_iter().find(|entry| { @@ -98,9 +98,9 @@ impl<'a> ImportParser<'a> { if imports_directory.exists() { // Get a vector of all packages in the imports directory. let entries = fs::read_dir(imports_directory) - .map_err(|error| ImportParserError::directory_error(error, span.clone(), &error_path))? + .map_err(|error| ImportParserError::directory_error(error, span, &error_path))? .collect::, std::io::Error>>() - .map_err(|error| ImportParserError::directory_error(error, span.clone(), &error_path))?; + .map_err(|error| ImportParserError::directory_error(error, span, &error_path))?; // Check if the imported package name is in the imports directory. let matched_import_entry = entries @@ -111,13 +111,13 @@ impl<'a> ImportParser<'a> { match (matched_source_entry, matched_import_entry) { (Some(_), Some(_)) => Err(ImportParserError::conflicting_imports(Identifier::new_with_span( package_name, - span, + span.clone(), ))), (Some(source_entry), None) => self.parse_package_access(context, &source_entry, &segments[1..], span), (None, Some(import_entry)) => self.parse_package_access(context, &import_entry, &segments[1..], span), (None, None) => Err(ImportParserError::unknown_package(Identifier::new_with_span( package_name, - span, + span.clone(), ))), } } else { @@ -126,7 +126,7 @@ impl<'a> ImportParser<'a> { Some(source_entry) => self.parse_package_access(context, &source_entry, &segments[1..], span), None => Err(ImportParserError::unknown_package(Identifier::new_with_span( package_name, - span, + span.clone(), ))), } } diff --git a/imports/src/parser/parse_symbol.rs b/imports/src/parser/parse_symbol.rs index 9b02656d75..e37e89a9f2 100644 --- a/imports/src/parser/parse_symbol.rs +++ b/imports/src/parser/parse_symbol.rs @@ -16,7 +16,6 @@ use crate::{errors::ImportParserError, ImportParser}; use leo_ast::{Program, Span}; -use leo_grammar::Grammar; use std::fs::DirEntry; @@ -32,11 +31,11 @@ impl<'a> ImportParser<'a> { // Get the package file type. let file_type = package .file_type() - .map_err(|error| ImportParserError::directory_error(error, span.clone(), &package.path()))?; + .map_err(|error| ImportParserError::directory_error(error, span, &package.path()))?; let file_name = package .file_name() .into_string() - .map_err(|_| ImportParserError::convert_os_string(span.clone()))?; + .map_err(|_| ImportParserError::convert_os_string(span))?; let mut file_path = package.path(); if file_type.is_dir() { @@ -45,16 +44,18 @@ impl<'a> ImportParser<'a> { if !file_path.exists() { return Err(ImportParserError::expected_lib_file( format!("{:?}", file_path.as_path()), - span.clone(), + span, )); } } - // Build the package abstract syntax tree. - let program_string = &Grammar::load_file(&file_path)?; - let ast = &Grammar::new(&file_path, &program_string)?; + let file_path_str = file_path.to_str().unwrap_or_default(); - // Build the package Leo syntax tree from the package abstract syntax tree. - Ok(Program::from(&file_name, ast.as_repr())?) + // Build the package abstract syntax tree. + let program_string = + &std::fs::read_to_string(&file_path).map_err(|x| ImportParserError::io_error(span, file_path_str, x))?; + let mut ast = leo_parser::parse(&file_path_str, &program_string)?; + ast.name = file_name; + Ok(ast) } } diff --git a/input/src/errors/parser.rs b/input/src/errors/parser.rs index 71bdbee253..e45cb94741 100644 --- a/input/src/errors/parser.rs +++ b/input/src/errors/parser.rs @@ -28,11 +28,7 @@ use pest::{ error::{Error, ErrorVariant}, Span, }; -use std::{ - num::ParseIntError, - path::{Path, PathBuf}, - str::ParseBoolError, -}; +use std::{num::ParseIntError, path::PathBuf, str::ParseBoolError}; #[derive(Debug, Error)] pub enum InputParserError { @@ -56,12 +52,12 @@ pub enum InputParserError { } impl InputParserError { - pub fn set_path(&mut self, path: &Path) { + pub fn set_path(&mut self, path: &str, _content: &[String]) { if let InputParserError::SyntaxError(error) = self { let new_error: Error = match error { InputSyntaxError::Error(error) => { let new_error = error.clone(); - new_error.with_path(path.to_str().unwrap()) + new_error.with_path(path) } }; @@ -71,13 +67,17 @@ impl InputParserError { } } - fn new_from_span(message: String, span: Span) -> Self { - let error = Error::new_from_span(ErrorVariant::CustomError { message }, span); + pub fn get_path(&self) -> Option<&str> { + None + } + + fn new_from_span(message: String, span: &Span) -> Self { + let error = Error::new_from_span(ErrorVariant::CustomError { message }, span.to_owned()); InputParserError::SyntaxError(InputSyntaxError::from(error)) } - pub fn array_index(actual: String, span: Span) -> Self { + pub fn array_index(actual: String, span: &Span) -> Self { let message = format!("Expected constant number for array index, found `{}`", actual); Self::new_from_span(message, span) @@ -86,27 +86,26 @@ impl InputParserError { pub fn implicit_type(data_type: DataType, implicit: NumberValue) -> Self { let message = format!("expected `{}`, found `{}`", data_type, implicit); - Self::new_from_span(message, implicit.span().clone()) + Self::new_from_span(message, implicit.span()) } pub fn implicit_group(number: NumberValue) -> Self { let message = format!("group coordinates should be in (x, y)group format, found `{}`", number); - Self::new_from_span(message, number.span().clone()) + Self::new_from_span(message, number.span()) } pub fn data_type_mismatch(data_type: DataType, value: Value) -> Self { let message = format!("expected data type `{}`, found `{}`", data_type, value); - let span = value.span().to_owned(); - Self::new_from_span(message, span) + Self::new_from_span(message, value.span()) } pub fn expression_type_mismatch(type_: Type, expression: Expression) -> Self { let message = format!("expected expression type `{}`, found `{}`", type_, expression); let span = expression.span().to_owned(); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } pub fn array_inline_length(number: usize, array: ArrayInlineExpression) -> Self { @@ -117,10 +116,10 @@ impl InputParserError { ); let span = array.span.to_owned(); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } - pub fn array_init_length(expected: Vec, actual: Vec, span: Span) -> Self { + pub fn array_init_length(expected: Vec, actual: Vec, span: &Span) -> Self { let message = format!( "expected an array with a fixed size of {:?} elements, found one with {:?} elements", expected, actual @@ -133,21 +132,21 @@ impl InputParserError { let message = format!("the section header `{}` is not valid in an input `.in` file", header); let span = header.span(); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } pub fn public_section(header: Header) -> Self { let message = format!("the section header `{}` is not a public section", header); let span = header.span(); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } pub fn private_section(header: Header) -> Self { let message = format!("the section header `{}` is not a private section", header); let span = header.span(); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } pub fn table(table: Table) -> Self { @@ -156,16 +155,16 @@ impl InputParserError { table ); - Self::new_from_span(message, table.span) + Self::new_from_span(message, &table.span) } - pub fn tuple_length(expected: usize, actual: usize, span: Span) -> Self { + pub fn tuple_length(expected: usize, actual: usize, span: &Span) -> Self { let message = format!( "expected a tuple with {} elements, found a tuple with {} elements", expected, actual ); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } pub fn section(header: Header) -> Self { @@ -175,7 +174,7 @@ impl InputParserError { ); let span = header.span(); - Self::new_from_span(message, span) + Self::new_from_span(message, &span) } } diff --git a/grammar/Cargo.toml b/parser/Cargo.toml similarity index 74% rename from grammar/Cargo.toml rename to parser/Cargo.toml index 6f123a6d50..1a3a25e7d5 100644 --- a/grammar/Cargo.toml +++ b/parser/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "leo-grammar" +name = "leo-parser" version = "1.2.3" authors = [ "The Aleo Team " ] description = "AST generated by pest from the Leo grammar rules" @@ -17,30 +17,18 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "GPL-3.0" edition = "2018" -[[bin]] -name = "leo_grammar" -path = "src/main.rs" - [[bench]] -name = "grammar" -path = "benches/grammar.rs" +name = "leo_ast" +path = "benches/leo_ast.rs" harness = false -[dependencies.from-pest] -version = "0.3.1" +[dependencies.leo-ast] +path = "../ast" +version = "1.2.3" [dependencies.lazy_static] version = "1.3.0" -[dependencies.pest] -version = "2.0" - -[dependencies.pest-ast] -version = "0.3.3" - -[dependencies.pest_derive] -version = "2.0" - [dependencies.serde] version = "1.0" features = [ "derive" ] @@ -57,6 +45,9 @@ version = "0.1" [dev-dependencies.criterion] version = "0.3" +[dependencies.indexmap] +version = "1.6" + [features] default = [ ] ci_skip = [ ] diff --git a/ast/benches/big_circuit.leo b/parser/benches/big_circuit.leo similarity index 100% rename from ast/benches/big_circuit.leo rename to parser/benches/big_circuit.leo diff --git a/ast/benches/big_if_else.leo b/parser/benches/big_if_else.leo similarity index 100% rename from ast/benches/big_if_else.leo rename to parser/benches/big_if_else.leo diff --git a/ast/benches/big_ternary.leo b/parser/benches/big_ternary.leo similarity index 100% rename from ast/benches/big_ternary.leo rename to parser/benches/big_ternary.leo diff --git a/ast/benches/leo_ast.rs b/parser/benches/leo_ast.rs similarity index 54% rename from ast/benches/leo_ast.rs rename to parser/benches/leo_ast.rs index d5420b0543..0777665e0d 100644 --- a/ast/benches/leo_ast.rs +++ b/parser/benches/leo_ast.rs @@ -14,70 +14,56 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Ast; -use leo_grammar::Grammar; - use criterion::{criterion_group, criterion_main, Criterion}; -use std::{path::Path, time::Duration}; - -fn ast(ast: &Grammar) -> Ast { - Ast::new("leo_tree", &ast).unwrap() -} +use std::time::Duration; fn bench_big_if_else(c: &mut Criterion) { - let filepath = Path::new("./big_if_else.leo").to_path_buf(); let program_string = include_str!("./big_if_else.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./big_if_else.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::big_if_else", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::big_if_else", |b| b.iter(|| &ast)); } fn bench_big_ternary(c: &mut Criterion) { - let filepath = Path::new("./big_ternary.leo").to_path_buf(); let program_string = include_str!("./big_ternary.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./big_ternary.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::big_ternary", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::big_ternary", |b| b.iter(|| &ast)); } fn bench_big_circuit(c: &mut Criterion) { - let filepath = Path::new("./big_circuit.leo").to_path_buf(); let program_string = include_str!("./big_circuit.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./big_circuit.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::big_circuit", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::big_circuit", |b| b.iter(|| &ast)); } fn bench_long_expr(c: &mut Criterion) { - let filepath = Path::new("./long_expr.leo").to_path_buf(); let program_string = include_str!("./long_expr.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./long_expr.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::long_expr", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::long_expr", |b| b.iter(|| &ast)); } fn bench_long_array(c: &mut Criterion) { - let filepath = Path::new("./long_array.leo").to_path_buf(); let program_string = include_str!("./long_array.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./long_array.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::long_array", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::long_array", |b| b.iter(|| &ast)); } fn bench_many_foos(c: &mut Criterion) { - let filepath = Path::new("./many_foos.leo").to_path_buf(); let program_string = include_str!("./many_foos.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./many_foos.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::many_foos", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::many_foos", |b| b.iter(|| &ast)); } fn bench_many_assigns(c: &mut Criterion) { - let filepath = Path::new("./many_assigns.leo").to_path_buf(); let program_string = include_str!("./many_assigns.leo"); - let grammar = Grammar::new(&filepath, program_string).unwrap(); + let ast = leo_parser::parse_ast("./many_assigns.leo", program_string).expect("failed to parse benchmark"); - c.bench_function("Ast::many_assigns", |b| b.iter(|| ast(&grammar))); + c.bench_function("Ast::many_assigns", |b| b.iter(|| &ast)); } criterion_group!( diff --git a/ast/benches/long_array.leo b/parser/benches/long_array.leo similarity index 100% rename from ast/benches/long_array.leo rename to parser/benches/long_array.leo diff --git a/ast/benches/long_expr.leo b/parser/benches/long_expr.leo similarity index 100% rename from ast/benches/long_expr.leo rename to parser/benches/long_expr.leo diff --git a/ast/benches/many_assigns.leo b/parser/benches/many_assigns.leo similarity index 100% rename from ast/benches/many_assigns.leo rename to parser/benches/many_assigns.leo diff --git a/ast/benches/many_foos.leo b/parser/benches/many_foos.leo similarity index 100% rename from ast/benches/many_foos.leo rename to parser/benches/many_foos.leo diff --git a/parser/src/context.rs b/parser/src/context.rs new file mode 100644 index 0000000000..b213755c02 --- /dev/null +++ b/parser/src/context.rs @@ -0,0 +1,271 @@ +// 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 std::unimplemented; + +use crate::{tokenizer::*, SyntaxError, SyntaxResult, Token, KEYWORD_TOKENS}; +use leo_ast::*; + +pub struct ParserContext { + inner: Vec, + end_span: Span, + // true if parsing an expression for an if statement -- means circuit inits are not legal + pub(crate) fuzzy_struct_state: bool, +} + +impl Iterator for ParserContext { + type Item = SpannedToken; + + fn next(&mut self) -> Option { + self.inner.pop() + } +} + +impl ParserContext { + pub fn new(mut tokens: Vec) -> Self { + tokens.reverse(); + // todo: performance optimization here: drain filter + tokens = tokens + .into_iter() + .filter(|x| !matches!(x.token, Token::CommentLine(_) | Token::CommentBlock(_))) + .collect(); + ParserContext { + end_span: tokens.last().map(|x| x.span.clone()).unwrap_or_default(), + inner: tokens, + fuzzy_struct_state: false, + } + } + + pub fn eof(&self) -> SyntaxError { + SyntaxError::unexpected_eof(&self.end_span) + } + + pub fn peek(&self) -> SyntaxResult<&SpannedToken> { + self.inner.last().ok_or_else(|| self.eof()) + } + + pub fn peek_oneof(&self, token: &[Token]) -> SyntaxResult<&SpannedToken> { + if let Some(spanned_token) = self.inner.last() { + if token.iter().any(|x| x == &spanned_token.token) { + return Ok(spanned_token); + } else { + return Err(SyntaxError::unexpected( + &spanned_token.token, + token, + &spanned_token.span, + )); + } + } else { + Err(self.eof()) + } + } + + pub fn has_next(&self) -> bool { + !self.inner.is_empty() + } + + pub fn eat(&mut self, token: Token) -> Option { + if let Some(SpannedToken { token: inner, .. }) = self.inner.last() { + if &token == inner { + return self.inner.pop(); + } + } + None + } + + pub fn backtrack(&mut self, token: SpannedToken) { + self.inner.push(token); + } + + pub fn eat_ident(&mut self) -> Option { + if let Some(SpannedToken { + token: Token::Ident(_), .. + }) = self.inner.last() + { + let token = self.inner.pop().unwrap(); + if let SpannedToken { + token: Token::Ident(name), + span, + } = token + { + return Some(Identifier { name, span }); + } else { + unimplemented!() + } + } + None + } + + fn peek_group_coordinate(&self, i: &mut usize) -> Option { + let token = self.inner.get(*i)?; + *i -= 1; + Some(match &token.token { + Token::Add => GroupCoordinate::SignHigh, + Token::Minus => match self.inner.get(*i) { + Some(SpannedToken { + token: Token::Int(value), + span, + }) => { + *i -= 1; + GroupCoordinate::Number(format!("-{}", value), span.clone()) + } + _ => GroupCoordinate::SignLow, + }, + Token::Ident(x) if x == "_" => GroupCoordinate::Inferred, + Token::Int(value) => GroupCoordinate::Number(value.clone(), token.span.clone()), + _ => return None, + }) + } + + // kinda hacky, we're not LALR(1) for groups... + pub fn eat_group_partial(&mut self) -> Option<(GroupCoordinate, GroupCoordinate, Span)> { + let mut i = self.inner.len() - 1; + let start_span = self.inner.get(i)?.span.clone(); + let first = self.peek_group_coordinate(&mut i)?; + match self.inner.get(i) { + Some(SpannedToken { + token: Token::Comma, .. + }) => { + i -= 1; + } + _ => { + return None; + } + } + let second = self.peek_group_coordinate(&mut i)?; + match self.inner.get(i) { + Some(SpannedToken { + token: Token::RightParen, + .. + }) => { + i -= 1; + } + _ => { + return None; + } + } + let end_span; + match self.inner.get(i) { + Some(SpannedToken { + token: Token::Group, + span, + }) => { + end_span = span.clone(); + i -= 1; + } + _ => { + return None; + } + } + + self.inner.drain((i + 1)..); + Some((first, second, start_span + end_span)) + } + + pub fn eat_int(&mut self) -> Option<(PositiveNumber, Span)> { + if let Some(SpannedToken { + token: Token::Int(_), .. + }) = self.inner.last() + { + let token = self.inner.pop().unwrap(); + if let SpannedToken { + token: Token::Int(value), + span, + } = token + { + return Some((PositiveNumber { value }, span)); + } else { + unimplemented!() + } + } + None + } + + pub fn eat_any(&mut self, token: &[Token]) -> Option { + if let Some(SpannedToken { token: inner, .. }) = self.inner.last() { + if token.iter().any(|x| x == inner) { + return self.inner.pop(); + } + } + None + } + + pub fn expect(&mut self, token: Token) -> SyntaxResult { + if let Some(SpannedToken { token: inner, span }) = self.inner.last() { + if &token == inner { + Ok(self.inner.pop().unwrap().span) + } else { + Err(SyntaxError::unexpected(inner, &[token], span)) + } + } else { + Err(self.eof()) + } + } + + pub fn expect_oneof(&mut self, token: &[Token]) -> SyntaxResult { + if let Some(SpannedToken { token: inner, span }) = self.inner.last() { + if token.iter().any(|x| x == inner) { + Ok(self.inner.pop().unwrap()) + } else { + Err(SyntaxError::unexpected(inner, token, span)) + } + } else { + Err(self.eof()) + } + } + + pub fn expect_loose_ident(&mut self) -> SyntaxResult { + if let Some(token) = self.eat_any(KEYWORD_TOKENS) { + return Ok(Identifier { + name: token.token.to_string(), + span: token.span, + }); + } + if let Some((int, span)) = self.eat_int() { + return Ok(Identifier { name: int.value, span }); + } + self.expect_ident() + } + + pub fn expect_ident(&mut self) -> SyntaxResult { + if let Some(SpannedToken { token: inner, span }) = self.inner.last() { + if let Token::Ident(_) = inner { + let token = self.inner.pop().unwrap(); + if let SpannedToken { + token: Token::Ident(name), + span, + } = token + { + Ok(Identifier { name, span }) + } else { + unimplemented!() + } + } else { + Err(SyntaxError::unexpected_str(inner, "ident", span)) + } + } else { + Err(self.eof()) + } + } + + pub fn expect_any(&mut self) -> SyntaxResult { + if let Some(x) = self.inner.pop() { + Ok(x) + } else { + Err(self.eof()) + } + } +} diff --git a/ast/src/errors/deprecated.rs b/parser/src/errors/deprecated.rs similarity index 51% rename from ast/src/errors/deprecated.rs rename to parser/src/errors/deprecated.rs index c22419d3ee..496c3db306 100644 --- a/ast/src/errors/deprecated.rs +++ b/parser/src/errors/deprecated.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Error as FormattedError, Span}; -use leo_grammar::{annotations::AnnotationName, definitions::Deprecated}; - -use std::{convert::TryFrom, path::Path}; +use leo_ast::{FormattedError, LeoError, Span}; #[derive(Debug, Error)] pub enum DeprecatedError { @@ -26,38 +23,21 @@ pub enum DeprecatedError { } impl DeprecatedError { - pub fn set_path(&mut self, path: &Path) { - match self { - DeprecatedError::Error(error) => error.set_path(path), - } - } - - fn new_from_span(message: String, span: Span) -> Self { + fn new_from_span(message: String, span: &Span) -> Self { DeprecatedError::Error(FormattedError::new_from_span(message, span)) } } -impl<'ast> From> for DeprecatedError { - fn from(deprecated: Deprecated<'ast>) -> Self { - match deprecated { - Deprecated::TestFunction(test_function) => DeprecatedError::new_from_span( - "\"test function...\" is deprecated. Did you mean @test annotation?".to_string(), - Span::from(test_function.span.clone()), - ), +impl LeoError for DeprecatedError { + fn get_path(&self) -> Option<&str> { + match self { + DeprecatedError::Error(error) => error.get_path(), } } -} -impl<'ast> TryFrom> for DeprecatedError { - type Error = bool; - - fn try_from(annotation_name: AnnotationName<'ast>) -> Result { - match annotation_name { - AnnotationName::Context(context) => Ok(DeprecatedError::new_from_span( - "\"@context(...)\" is deprecated. Did you mean @test annotation?".to_string(), - Span::from(context.span.clone()), - )), - _ => Err(false), + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + DeprecatedError::Error(error) => error.set_path(path, contents), } } } @@ -65,6 +45,16 @@ impl<'ast> TryFrom> for DeprecatedError { impl DeprecatedError { pub fn const_statement(span: &Span) -> Self { let message = "const _ = ... is deprecated. Did you mean let?".to_string(); - Self::new_from_span(message, span.clone()) + Self::new_from_span(message, span) + } + + pub fn test_function(span: &Span) -> Self { + let message = "\"test function...\" is deprecated. Did you mean @test annotation?".to_string(); + Self::new_from_span(message, span) + } + + pub fn context_annotation(span: &Span) -> Self { + let message = "\"@context(...)\" is deprecated. Did you mean @test annotation?".to_string(); + Self::new_from_span(message, span) } } diff --git a/grammar/src/errors/mod.rs b/parser/src/errors/mod.rs similarity index 90% rename from grammar/src/errors/mod.rs rename to parser/src/errors/mod.rs index 9a69051aaa..6138a74a98 100644 --- a/grammar/src/errors/mod.rs +++ b/parser/src/errors/mod.rs @@ -14,8 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -pub mod parser; -pub use parser::*; +pub mod token; +pub use token::*; pub mod syntax; pub use syntax::*; + +pub mod deprecated; +pub use deprecated::*; diff --git a/parser/src/errors/syntax.rs b/parser/src/errors/syntax.rs new file mode 100644 index 0000000000..c453625d94 --- /dev/null +++ b/parser/src/errors/syntax.rs @@ -0,0 +1,108 @@ +// 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_ast::{FormattedError, LeoError, Span}; + +use crate::{DeprecatedError, Token, TokenError}; + +#[derive(Debug, Error)] +pub enum SyntaxError { + #[error("{}", _0)] + Error(#[from] FormattedError), + + #[error("{}", _0)] + TokenError(#[from] TokenError), + + #[error("{}", _0)] + DeprecatedError(#[from] DeprecatedError), +} + +impl LeoError for SyntaxError { + fn get_path(&self) -> Option<&str> { + match self { + SyntaxError::Error(error) => error.get_path(), + SyntaxError::TokenError(error) => error.get_path(), + SyntaxError::DeprecatedError(error) => error.get_path(), + } + } + + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + SyntaxError::Error(error) => error.set_path(path, contents), + SyntaxError::TokenError(error) => error.set_path(path, contents), + SyntaxError::DeprecatedError(error) => error.set_path(path, contents), + } + } +} + +impl SyntaxError { + fn new_from_span(message: String, span: &Span) -> Self { + SyntaxError::Error(FormattedError::new_from_span(message, span)) + } + + pub fn unexpected_eof(span: &Span) -> Self { + Self::new_from_span("unexpected EOF".to_string(), span) + } + + pub fn unexpected(got: &Token, expected: &[Token], span: &Span) -> Self { + Self::new_from_span( + format!( + "expected {} -- got '{}'", + expected + .iter() + .map(|x| format!("'{}'", x)) + .collect::>() + .join(", "), + got.to_string() + ), + span, + ) + } + + pub fn unexpected_ident(got: &str, expected: &[&str], span: &Span) -> Self { + Self::new_from_span( + format!( + "expected identifier {} -- got '{}'", + expected + .iter() + .map(|x| format!("'{}'", x)) + .collect::>() + .join(", "), + got + ), + span, + ) + } + + pub fn unexpected_str(got: &Token, expected: &str, span: &Span) -> Self { + Self::new_from_span(format!("expected '{}', got '{}'", expected, got.to_string()), span) + } + + pub fn spread_in_array_init(span: &Span) -> Self { + Self::new_from_span("illegal spread in array initializer".to_string(), span) + } + + pub fn invalid_assignment_target(span: &Span) -> Self { + Self::new_from_span("invalid assignment target".to_string(), span) + } + + pub fn invalid_package_name(span: &Span) -> Self { + Self::new_from_span( + "package names must be lowercase alphanumeric ascii with underscores and singular dashes".to_string(), + span, + ) + } +} diff --git a/parser/src/errors/token.rs b/parser/src/errors/token.rs new file mode 100644 index 0000000000..3a439646a7 --- /dev/null +++ b/parser/src/errors/token.rs @@ -0,0 +1,51 @@ +// 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_ast::{FormattedError, LeoError, Span}; + +#[derive(Debug, Error)] +pub enum TokenError { + #[error("{}", _0)] + Error(#[from] FormattedError), +} + +impl LeoError for TokenError { + fn get_path(&self) -> Option<&str> { + match self { + TokenError::Error(error) => error.get_path(), + } + } + + fn set_path(&mut self, path: &str, contents: &[String]) { + match self { + TokenError::Error(error) => error.set_path(path, contents), + } + } +} + +impl TokenError { + fn new_from_span(message: String, span: &Span) -> Self { + TokenError::Error(FormattedError::new_from_span(message, span)) + } + + pub fn unexpected_token(token: &str, span: &Span) -> Self { + TokenError::new_from_span(format!("unexpected token: '{}'", token), span) + } + + pub fn invalid_address_lit(token: &str, span: &Span) -> Self { + TokenError::new_from_span(format!("invalid address literal: '{}'", token), span) + } +} diff --git a/grammar/src/imports/mod.rs b/parser/src/lib.rs similarity index 64% rename from grammar/src/imports/mod.rs rename to parser/src/lib.rs index 7665e520c5..21b56c9a47 100644 --- a/grammar/src/imports/mod.rs +++ b/parser/src/lib.rs @@ -14,26 +14,28 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -pub mod import; -pub use import::*; +#[macro_use] +extern crate thiserror; -pub mod import_symbol; -pub use import_symbol::*; +pub mod tokenizer; +use leo_ast::Ast; +pub use tokenizer::*; -pub mod package; -pub use package::*; +pub mod token; +pub use token::*; -pub mod packages; -pub use packages::*; +pub mod errors; +pub use errors::*; -pub mod package_or_packages; -pub use package_or_packages::*; +pub mod parser; +pub use parser::*; -pub mod package_access; -pub use package_access::*; +pub mod context; +pub use context::*; -pub mod package_name; -pub use package_name::*; +#[cfg(test)] +mod test; -pub mod star; -pub use star::*; +pub fn parse_ast, Y: AsRef>(path: T, source: Y) -> SyntaxResult { + Ok(Ast::new(parser::parse(path.as_ref(), source.as_ref())?)) +} diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs new file mode 100644 index 0000000000..68f1a18278 --- /dev/null +++ b/parser/src/parser/expression.rs @@ -0,0 +1,577 @@ +// 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::*; + +const INT_TYPES: &[Token] = &[ + Token::I8, + Token::I16, + Token::I32, + Token::I64, + Token::I128, + Token::U8, + Token::U16, + Token::U32, + Token::U64, + Token::U128, + Token::Field, + Token::Group, +]; + +impl ParserContext { + pub fn parse_expression(&mut self) -> SyntaxResult { + let prior_fuzzy_state = self.fuzzy_struct_state; + self.fuzzy_struct_state = false; + let result = self.parse_expression_fuzzy(); + self.fuzzy_struct_state = prior_fuzzy_state; + result + } + + pub fn parse_expression_fuzzy(&mut self) -> SyntaxResult { + let if_token = self.eat(Token::If); + let mut expr = self.parse_or_expression()?; + if self.eat(Token::Question).is_some() { + let if_true = self.parse_expression()?; + self.expect(Token::Colon)?; + let if_false = self.parse_expression_fuzzy()?; + expr = Expression::Ternary(TernaryExpression { + span: expr.span() + if_false.span(), + condition: Box::new(expr), + if_true: Box::new(if_true), + if_false: Box::new(if_false), + }); + } else if if_token.is_some() { + let peeked = self.peek()?; + return Err(SyntaxError::unexpected(&peeked.token, &[Token::Question], &peeked.span)); + } + Ok(expr) + } + + pub fn parse_or_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_and_expression()?; + while self.eat(Token::Or).is_some() { + let right = self.parse_and_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: BinaryOperation::Or, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_and_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_bit_or_expression()?; + while self.eat(Token::And).is_some() { + let right = self.parse_bit_or_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: BinaryOperation::And, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_bit_or_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_bit_xor_expression()?; + while self.eat(Token::BitOr).is_some() { + let right = self.parse_bit_xor_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: BinaryOperation::BitOr, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_bit_xor_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_bit_and_expression()?; + while self.eat(Token::BitXor).is_some() { + let right = self.parse_bit_and_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: BinaryOperation::BitXor, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_bit_and_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_eq_expression()?; + while self.eat(Token::BitAnd).is_some() { + let right = self.parse_eq_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: BinaryOperation::BitAnd, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_eq_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_rel_expression()?; + while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) { + let right = self.parse_rel_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: match op { + Token::Eq => BinaryOperation::Eq, + Token::NotEq => BinaryOperation::Ne, + _ => unimplemented!(), + }, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_rel_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_shift_expression()?; + while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Lt, Token::LtEq, Token::Gt, Token::GtEq]) + { + let right = self.parse_shift_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: match op { + Token::Lt => BinaryOperation::Lt, + Token::LtEq => BinaryOperation::Le, + Token::Gt => BinaryOperation::Gt, + Token::GtEq => BinaryOperation::Ge, + _ => unimplemented!(), + }, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_shift_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_add_expression()?; + while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Shl, Token::Shr, Token::ShrSigned]) { + let right = self.parse_add_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: match op { + Token::Shl => BinaryOperation::Shl, + Token::Shr => BinaryOperation::Shr, + Token::ShrSigned => BinaryOperation::ShrSigned, + _ => unimplemented!(), + }, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_add_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_multiply_expression()?; + while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Add, Token::Minus]) { + let right = self.parse_multiply_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: match op { + Token::Add => BinaryOperation::Add, + Token::Minus => BinaryOperation::Sub, + _ => unimplemented!(), + }, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_multiply_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_exp_expression()?; + while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Mul, Token::Div, Token::Mod]) { + let right = self.parse_exp_expression()?; + expr = Expression::Binary(BinaryExpression { + span: expr.span() + right.span(), + op: match op { + Token::Mul => BinaryOperation::Mul, + Token::Div => BinaryOperation::Div, + Token::Mod => BinaryOperation::Mod, + _ => unimplemented!(), + }, + left: Box::new(expr), + right: Box::new(right), + }) + } + Ok(expr) + } + + pub fn parse_exp_expression(&mut self) -> SyntaxResult { + let mut exprs = vec![]; + exprs.push(self.parse_cast_expression()?); + while self.eat(Token::Exp).is_some() { + exprs.push(self.parse_cast_expression()?); + } + let mut expr = exprs.remove(exprs.len() - 1); + while !exprs.is_empty() { + let sub_expr = exprs.remove(exprs.len() - 1); + expr = Expression::Binary(BinaryExpression { + span: expr.span() + sub_expr.span(), + op: BinaryOperation::Pow, + left: Box::new(sub_expr), + right: Box::new(expr), + }) + } + Ok(expr) + } + + pub fn parse_cast_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_unary_expression()?; + while self.eat(Token::As).is_some() { + let (type_, type_span) = self.parse_type()?; + expr = Expression::Cast(CastExpression { + span: expr.span() + &type_span, + inner: Box::new(expr), + target_type: type_, + }) + } + Ok(expr) + } + + pub fn parse_unary_expression(&mut self) -> SyntaxResult { + let mut ops = vec![]; + while let Some(token) = self.eat_any(&[Token::Not, Token::Minus, Token::BitNot]) { + ops.push(token); + } + let mut inner = self.parse_access_expression()?; + for op in ops.into_iter().rev() { + inner = Expression::Unary(UnaryExpression { + span: &op.span + inner.span(), + op: match op.token { + Token::Not => UnaryOperation::Not, + Token::Minus => UnaryOperation::Negate, + Token::BitNot => UnaryOperation::BitNot, + _ => unimplemented!(), + }, + inner: Box::new(inner), + }); + } + Ok(inner) + } + + pub fn parse_access_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_primary_expression()?; + while let Some(token) = self.eat_any(&[Token::LeftSquare, Token::Dot, Token::LeftParen, Token::DoubleColon]) { + match token.token { + Token::LeftSquare => { + if self.eat(Token::DotDot).is_some() { + let right = if self.peek()?.token != Token::RightSquare { + Some(Box::new(self.parse_expression()?)) + } else { + None + }; + + let end = self.expect(Token::RightSquare)?; + expr = Expression::ArrayRangeAccess(ArrayRangeAccessExpression { + span: expr.span() + &end, + array: Box::new(expr), + left: None, + right, + }); + continue; + } + + let left = self.parse_expression()?; + if self.eat(Token::DotDot).is_some() { + let right = if self.peek()?.token != Token::RightSquare { + Some(Box::new(self.parse_expression()?)) + } else { + None + }; + + let end = self.expect(Token::RightSquare)?; + expr = Expression::ArrayRangeAccess(ArrayRangeAccessExpression { + span: expr.span() + &end, + array: Box::new(expr), + left: Some(Box::new(left)), + right, + }); + } else { + let end = self.expect(Token::RightSquare)?; + expr = Expression::ArrayAccess(ArrayAccessExpression { + span: expr.span() + &end, + array: Box::new(expr), + index: Box::new(left), + }); + } + } + Token::Dot => { + if let Some(ident) = self.eat_ident() { + expr = Expression::CircuitMemberAccess(CircuitMemberAccessExpression { + span: expr.span() + &ident.span, + circuit: Box::new(expr), + name: ident, + }); + } else if let Some((num, span)) = self.eat_int() { + expr = Expression::TupleAccess(TupleAccessExpression { + span: expr.span() + &span, + tuple: Box::new(expr), + index: num, + }); + } else { + let next = self.peek()?; + return Err(SyntaxError::unexpected_str(&next.token, "int or ident", &next.span)); + } + } + Token::LeftParen => { + let mut arguments = vec![]; + let end_span; + loop { + let end = self.eat(Token::RightParen); + if let Some(end) = end { + end_span = end.span; + break; + } + arguments.push(self.parse_expression()?); + if self.eat(Token::Comma).is_none() { + end_span = self.expect(Token::RightParen)?; + break; + } + } + expr = Expression::Call(CallExpression { + span: expr.span() + &end_span, + function: Box::new(expr), + arguments, + }); + } + Token::DoubleColon => { + let ident = self.expect_ident()?; + expr = Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { + span: expr.span() + &ident.span, + circuit: Box::new(expr), + name: ident, + }); + } + _ => unimplemented!(), + } + } + Ok(expr) + } + + pub fn parse_spread_or_expression(&mut self) -> SyntaxResult { + Ok(if self.eat(Token::DotDotDot).is_some() { + SpreadOrExpression::Spread(self.parse_expression()?) + } else { + SpreadOrExpression::Expression(self.parse_expression()?) + }) + } + + pub fn parse_circuit_init(&mut self, ident: Identifier) -> SyntaxResult { + self.expect(Token::LeftCurly)?; + let mut members = vec![]; + let end_span; + loop { + if let Some(end) = self.eat(Token::RightCurly) { + end_span = end.span; + break; + } + let name = self.expect_ident()?; + if self.eat(Token::Colon).is_some() { + let expression = self.parse_expression()?; + members.push(CircuitImpliedVariableDefinition { + identifier: name, + expression: Some(expression), + }); + } else { + members.push(CircuitImpliedVariableDefinition { + identifier: name.clone(), + expression: None, + }); + } + if self.eat(Token::Comma).is_none() { + end_span = self.expect(Token::RightCurly)?; + break; + } + } + Ok(Expression::CircuitInit(CircuitInitExpression { + span: &ident.span + &end_span, + name: ident, + members, + })) + } + + pub fn parse_primary_expression(&mut self) -> SyntaxResult { + let SpannedToken { token, span } = self.expect_any()?; + Ok(match token { + Token::Int(value) => { + let type_ = self.eat_any(INT_TYPES); + match type_ { + Some(SpannedToken { + token: Token::Field, + span: type_span, + }) => Expression::Value(ValueExpression::Field(value, span + type_span)), + Some(SpannedToken { + token: Token::Group, + span: type_span, + }) => Expression::Value(ValueExpression::Group(Box::new(GroupValue::Single( + value, + span + type_span, + )))), + Some(SpannedToken { token, span: type_span }) => Expression::Value(ValueExpression::Integer( + Self::token_to_int_type(token).expect("unknown int type token"), + value, + span + type_span, + )), + None => Expression::Value(ValueExpression::Implicit(value, span)), + } + } + Token::True => Expression::Value(ValueExpression::Boolean("true".to_string(), span)), + Token::False => Expression::Value(ValueExpression::Boolean("false".to_string(), span)), + Token::AddressLit(value) => Expression::Value(ValueExpression::Address(value, span)), + Token::Address => { + self.expect(Token::LeftParen)?; + let value = self.expect_any()?; + let value = if let SpannedToken { + token: Token::AddressLit(value), + .. + } = value + { + value + } else { + return Err(SyntaxError::unexpected_str(&value.token, "address", &value.span)); + }; + + let end = self.expect(Token::RightParen)?; + Expression::Value(ValueExpression::Address(value, span + end)) + } + Token::LeftParen => { + if let Some((left, right, span)) = self.eat_group_partial() { + return Ok(Expression::Value(ValueExpression::Group(Box::new(GroupValue::Tuple( + GroupTuple { + span, + x: left, + y: right, + }, + ))))); + } + let mut args = vec![]; + let end_span; + loop { + let end = self.eat(Token::RightParen); + if let Some(end) = end { + end_span = end.span; + break; + } + let expr = self.parse_expression()?; + args.push(expr); + if self.eat(Token::Comma).is_none() { + end_span = self.expect(Token::RightParen)?; + break; + } + } + if args.len() == 1 { + args.remove(0) + } else { + Expression::TupleInit(TupleInitExpression { + span: span + end_span, + elements: args, + }) + } + } + Token::LeftSquare => { + if let Some(end) = self.eat(Token::RightSquare) { + return Ok(Expression::ArrayInline(ArrayInlineExpression { + elements: vec![], + span: span + end.span, + })); + } + let first = self.parse_spread_or_expression()?; + if self.eat(Token::Semicolon).is_some() { + let dimensions = self.parse_array_dimensions()?; + let end = self.expect(Token::RightSquare)?; + let first = match first { + SpreadOrExpression::Spread(first) => { + let span = &span + first.span(); + return Err(SyntaxError::spread_in_array_init(&span)); + } + SpreadOrExpression::Expression(x) => x, + }; + Expression::ArrayInit(ArrayInitExpression { + span: span + end, + element: Box::new(first), + dimensions, + }) + } else { + let end_span; + let mut elements = vec![first]; + loop { + if let Some(token) = self.eat(Token::RightSquare) { + end_span = token.span; + break; + } + if elements.len() == 1 { + self.expect(Token::Comma)?; + } + elements.push(self.parse_spread_or_expression()?); + if self.eat(Token::Comma).is_none() { + end_span = self.expect(Token::RightSquare)?; + break; + } + } + Expression::ArrayInline(ArrayInlineExpression { + elements, + span: span + end_span, + }) + } + } + Token::Ident(name) => { + let ident = Identifier { name, span }; + if !self.fuzzy_struct_state && self.peek()?.token == Token::LeftCurly { + self.parse_circuit_init(ident)? + } else { + Expression::Identifier(ident) + } + } + Token::BigSelf => { + let ident = Identifier { + name: token.to_string(), + span, + }; + if !self.fuzzy_struct_state && self.peek()?.token == Token::LeftCurly { + self.parse_circuit_init(ident)? + } else { + Expression::Identifier(ident) + } + } + Token::Input | Token::LittleSelf => { + let ident = Identifier { + name: token.to_string(), + span, + }; + Expression::Identifier(ident) + } + token => { + return Err(SyntaxError::unexpected_str(&token, "expression", &span)); + } + }) + } +} diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs new file mode 100644 index 0000000000..efd50d8d15 --- /dev/null +++ b/parser/src/parser/file.rs @@ -0,0 +1,317 @@ +// 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::KEYWORD_TOKENS; + +use super::*; + +impl ParserContext { + pub fn parse_program(&mut self) -> SyntaxResult { + let mut imports = vec![]; + let mut circuits = IndexMap::new(); + let mut functions = IndexMap::new(); + // let mut tests = IndexMap::new(); + + while self.has_next() { + let token = self.peek()?; + match &token.token { + Token::Import => { + imports.push(self.parse_import()?); + } + Token::Circuit => { + let (id, circuit) = self.parse_circuit()?; + circuits.insert(id, circuit); + } + Token::Function | Token::At => { + let (id, function) = self.parse_function()?; + functions.insert(id, function); + } + Token::Ident(ident) if ident == "test" => { + return Err(SyntaxError::DeprecatedError(DeprecatedError::test_function( + &token.span, + ))); + // self.expect(Token::Test)?; + // let (id, function) = self.parse_function()?; + // tests.insert(id, TestFunction { + // function, + // input_file: None, + // }); + } + _ => { + return Err(SyntaxError::unexpected( + &token.token, + &[ + Token::Import, + Token::Circuit, + Token::Function, + Token::Ident("test".to_string()), + Token::At, + ], + &token.span, + )); + } + } + } + Ok(Program { + name: String::new(), + expected_input: vec![], + imports, + circuits, + functions, + }) + } + + pub fn parse_annotation(&mut self) -> SyntaxResult { + let start = self.expect(Token::At)?; + let name = self.expect_ident()?; + if name.name == "context" { + return Err(SyntaxError::DeprecatedError(DeprecatedError::context_annotation( + &name.span, + ))); + } + let end_span; + let arguments = if self.eat(Token::LeftParen).is_some() { + let mut args = vec![]; + loop { + if let Some(end) = self.eat(Token::RightParen) { + end_span = end.span; + break; + } + if let Some(ident) = self.eat_ident() { + args.push(ident.name); + } else if let Some((int, _)) = self.eat_int() { + args.push(int.value); + } else { + let token = self.peek()?; + return Err(SyntaxError::unexpected_str(&token.token, "ident or int", &token.span)); + } + if self.eat(Token::Comma).is_none() { + end_span = self.expect(Token::RightParen)?; + break; + } + } + args + } else { + end_span = name.span.clone(); + vec![] + }; + Ok(Annotation { + name, + arguments, + span: start + end_span, + }) + } + + pub fn parse_package_accesses(&mut self) -> SyntaxResult> { + let mut out = vec![]; + self.expect(Token::LeftParen)?; + while self.eat(Token::RightParen).is_none() { + let access = self.parse_package_access()?; + out.push(access); + if self.eat(Token::Comma).is_none() { + self.expect(Token::RightParen)?; + break; + } + } + Ok(out) + } + + pub fn parse_package_access(&mut self) -> SyntaxResult { + if let Some(SpannedToken { span, .. }) = self.eat(Token::Mul) { + Ok(PackageAccess::Star(span)) + } else { + let name = self.expect_ident()?; + if self.peek()?.token == Token::Dot { + self.backtrack(SpannedToken { + token: Token::Ident(name.name), + span: name.span, + }); + Ok(match self.parse_package_or_packages()? { + PackageOrPackages::Package(p) => PackageAccess::SubPackage(Box::new(p)), + PackageOrPackages::Packages(p) => PackageAccess::Multiple(p), + }) + } else if self.eat(Token::As).is_some() { + let alias = self.expect_ident()?; + Ok(PackageAccess::Symbol(ImportSymbol { + span: &name.span + &alias.span, + symbol: name, + alias: Some(alias), + })) + } else { + Ok(PackageAccess::Symbol(ImportSymbol { + span: name.span.clone(), + symbol: name, + alias: None, + })) + } + } + } + + pub fn parse_package_name(&mut self) -> SyntaxResult { + let mut base = self.expect_loose_ident()?; + while let Some(token) = self.eat(Token::Minus) { + if token.span.line_start == base.span.line_stop && token.span.col_start == base.span.col_stop { + base.name += "-"; + base.span = base.span + token.span; + let next = self.expect_loose_ident()?; + base.name += &next.name; + base.span = base.span + next.span; + } else { + break; + } + } + if let Some(token) = KEYWORD_TOKENS.iter().find(|x| x.to_string() == base.name) { + return Err(SyntaxError::unexpected_str(token, "package name", &base.span)); + } + if !base + .name + .chars() + .all(|x| x.is_ascii_lowercase() || x.is_ascii_digit() || x == '-' || x == '_') + { + return Err(SyntaxError::invalid_package_name(&base.span)); + } + Ok(base) + } + + pub fn parse_package_or_packages(&mut self) -> SyntaxResult { + let package_name = self.parse_package_name()?; + self.expect(Token::Dot)?; + if self.peek()?.token == Token::LeftParen { + let accesses = self.parse_package_accesses()?; + Ok(PackageOrPackages::Packages(Packages { + span: &package_name.span + accesses.last().map(|x| x.span()).unwrap_or(&package_name.span), + name: package_name, + accesses, + })) + } else { + let access = self.parse_package_access()?; + Ok(PackageOrPackages::Package(Package { + span: &package_name.span + access.span(), + name: package_name, + access, + })) + } + } + + pub fn parse_import(&mut self) -> SyntaxResult { + self.expect(Token::Import)?; + let package_or_packages = self.parse_package_or_packages()?; + self.expect(Token::Semicolon)?; + Ok(ImportStatement { + span: package_or_packages.span().clone(), + package_or_packages, + }) + } + + pub fn parse_circuit_member(&mut self) -> SyntaxResult { + let peeked = &self.peek()?.token; + if peeked == &Token::Function || peeked == &Token::At { + let function = self.parse_function()?; + Ok(CircuitMember::CircuitFunction(function.1)) + } else { + // circuit variable + let name = self.expect_ident()?; + self.expect(Token::Colon)?; + let type_ = self.parse_type()?.0; + self.eat(Token::Comma); + Ok(CircuitMember::CircuitVariable(name, type_)) + } + } + + pub fn parse_circuit(&mut self) -> SyntaxResult<(Identifier, Circuit)> { + self.expect(Token::Circuit)?; + let name = self.expect_ident()?; + self.expect(Token::LeftCurly)?; + let mut members = vec![]; + while self.eat(Token::RightCurly).is_none() { + let member = self.parse_circuit_member()?; + members.push(member); + } + Ok((name.clone(), Circuit { + circuit_name: name, + members, + })) + } + + pub fn parse_function_input(&mut self) -> SyntaxResult { + if let Some(token) = self.eat(Token::Input) { + return Ok(FunctionInput::InputKeyword(InputKeyword { span: token.span })); + } + let const_ = self.eat(Token::Const); + let mutable = self.eat(Token::Mut); + let name = if let Some(token) = self.eat(Token::LittleSelf) { + Identifier { + name: token.token.to_string(), + span: token.span, + } + } else { + self.expect_ident()? + }; + if name.name == "self" { + if const_.is_some() { + //error + } + if let Some(mutable) = &mutable { + return Ok(FunctionInput::MutSelfKeyword(MutSelfKeyword { + span: &mutable.span + &name.span, + })); + } + return Ok(FunctionInput::SelfKeyword(SelfKeyword { span: name.span })); + } + self.expect(Token::Colon)?; + let type_ = self.parse_type()?.0; + Ok(FunctionInput::Variable(FunctionInputVariable { + const_: const_.is_some(), + mutable: mutable.is_some(), + type_, + span: name.span.clone(), + identifier: name, + })) + } + + pub fn parse_function(&mut self) -> SyntaxResult<(Identifier, Function)> { + let mut annotations = vec![]; + while self.peek()?.token == Token::At { + annotations.push(self.parse_annotation()?); + } + let start = self.expect(Token::Function)?; + let name = self.expect_ident()?; + self.expect(Token::LeftParen)?; + let mut inputs = vec![]; + while self.eat(Token::RightParen).is_none() { + let input = self.parse_function_input()?; + inputs.push(input); + if self.eat(Token::Comma).is_none() { + self.expect(Token::RightParen)?; + break; + } + } + let output = if self.eat(Token::Arrow).is_some() { + Some(self.parse_type()?.0) + } else { + None + }; + let block = self.parse_block()?; + Ok((name.clone(), Function { + annotations, + identifier: name, + input: inputs, + output, + span: start + block.span.clone(), + block, + })) + } +} diff --git a/grammar/src/common/spread_or_expression.rs b/parser/src/parser/mod.rs similarity index 54% rename from grammar/src/common/spread_or_expression.rs rename to parser/src/parser/mod.rs index cd4bbc21d6..7980dedd94 100644 --- a/grammar/src/common/spread_or_expression.rs +++ b/parser/src/parser/mod.rs @@ -14,24 +14,30 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Spread, expressions::Expression}; +use std::unimplemented; -use pest_ast::FromPest; -use serde::Serialize; -use std::fmt; +use crate::{tokenizer::*, DeprecatedError, ParserContext, SyntaxError, Token}; +use indexmap::IndexMap; +use leo_ast::*; -#[derive(Clone, Debug, FromPest, PartialEq, Serialize)] -#[pest_ast(rule(Rule::spread_or_expression))] -pub enum SpreadOrExpression<'ast> { - Spread(Spread<'ast>), - Expression(Expression<'ast>), -} +pub type SyntaxResult = Result; -impl<'ast> fmt::Display for SpreadOrExpression<'ast> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - SpreadOrExpression::Spread(ref spread) => write!(f, "{}", spread), - SpreadOrExpression::Expression(ref expression) => write!(f, "{}", expression), +mod expression; +mod file; +mod statement; +mod type_; + +pub fn parse(path: &str, script: &str) -> SyntaxResult { + let mut tokens = ParserContext::new(crate::tokenize(script, path)?); + + match tokens.parse_program() { + Ok(x) => Ok(x), + Err(mut e) => { + e.set_path( + path, + &script.lines().map(|x| x.to_string()).collect::>()[..], + ); + Err(e) } } } diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs new file mode 100644 index 0000000000..fede6a5eab --- /dev/null +++ b/parser/src/parser/statement.rs @@ -0,0 +1,310 @@ +// 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::*; + +const ASSIGN_TOKENS: &[Token] = &[ + Token::Assign, + Token::AddEq, + Token::MinusEq, + Token::MulEq, + Token::DivEq, + Token::ExpEq, + Token::BitAndEq, + Token::BitOrEq, + Token::BitXorEq, + Token::ShlEq, + Token::ShrEq, + Token::ShrSignedEq, + Token::ModEq, + Token::OrEq, + Token::AndEq, +]; + +impl ParserContext { + pub fn construct_assignee_access(expr: Expression, accesses: &mut Vec) -> SyntaxResult { + let identifier; + match expr { + Expression::CircuitMemberAccess(expr) => { + identifier = Self::construct_assignee_access(*expr.circuit, accesses)?; + accesses.push(AssigneeAccess::Member(expr.name)); + } + Expression::TupleAccess(expr) => { + identifier = Self::construct_assignee_access(*expr.tuple, accesses)?; + accesses.push(AssigneeAccess::Tuple(expr.index, expr.span)); + } + Expression::ArrayRangeAccess(expr) => { + identifier = Self::construct_assignee_access(*expr.array, accesses)?; + accesses.push(AssigneeAccess::ArrayRange( + expr.left.map(|x| *x), + expr.right.map(|x| *x), + )); + } + Expression::ArrayAccess(expr) => { + identifier = Self::construct_assignee_access(*expr.array, accesses)?; + accesses.push(AssigneeAccess::ArrayIndex(*expr.index)); + } + Expression::Identifier(id) => identifier = id, + _ => return Err(SyntaxError::invalid_assignment_target(expr.span())), + } + Ok(identifier) + } + + pub fn construct_assignee(expr: Expression) -> SyntaxResult { + let expr_span = expr.span().clone(); + let mut accesses = vec![]; + let identifier = Self::construct_assignee_access(expr, &mut accesses)?; + + Ok(Assignee { + span: expr_span, + identifier, + accesses, + }) + } + + pub fn parse_statement(&mut self) -> SyntaxResult { + match &self.peek()?.token { + Token::Return => Ok(Statement::Return(self.parse_return_statement()?)), + Token::If => Ok(Statement::Conditional(self.parse_conditional_statement()?)), + Token::For => Ok(Statement::Iteration(self.parse_for_statement()?)), + Token::Console => Ok(Statement::Console(self.parse_console_statement()?)), + Token::Let | Token::Const => Ok(Statement::Definition(self.parse_definition_statement()?)), + Token::LeftCurly => Ok(Statement::Block(self.parse_block()?)), + _ => { + let expr = self.parse_expression()?; + + if let Some(operator) = self.eat_any(ASSIGN_TOKENS) { + let value = self.parse_expression()?; + let assignee = Self::construct_assignee(expr)?; + self.expect(Token::Semicolon)?; + Ok(Statement::Assign(AssignStatement { + span: &assignee.span + value.span(), + assignee, + operation: match operator.token { + Token::Assign => AssignOperation::Assign, + Token::AddEq => AssignOperation::Add, + Token::MinusEq => AssignOperation::Sub, + Token::MulEq => AssignOperation::Mul, + Token::DivEq => AssignOperation::Div, + Token::ExpEq => AssignOperation::Pow, + Token::OrEq => AssignOperation::Or, + Token::AndEq => AssignOperation::And, + Token::BitOrEq => AssignOperation::BitOr, + Token::BitAndEq => AssignOperation::BitAnd, + Token::BitXorEq => AssignOperation::BitXor, + Token::ShrEq => AssignOperation::Shr, + Token::ShrSignedEq => AssignOperation::ShrSigned, + Token::ShlEq => AssignOperation::Shl, + Token::ModEq => AssignOperation::Mod, + _ => unimplemented!(), + }, + value, + })) + } else { + self.expect(Token::Semicolon)?; + Ok(Statement::Expression(ExpressionStatement { + span: expr.span().clone(), + expression: expr, + })) + } + } + } + } + + pub fn parse_block(&mut self) -> SyntaxResult { + let start = self.expect(Token::LeftCurly)?; + let mut statements = vec![]; + loop { + match self.eat(Token::RightCurly) { + None => { + statements.push(self.parse_statement()?); + } + Some(end) => { + return Ok(Block { + span: start + end.span, + statements, + }); + } + } + } + } + + pub fn parse_return_statement(&mut self) -> SyntaxResult { + let start = self.expect(Token::Return)?; + let expr = self.parse_expression()?; + self.eat(Token::Comma); + + Ok(ReturnStatement { + span: &start + expr.span(), + expression: expr, + }) + } + + pub fn parse_conditional_statement(&mut self) -> SyntaxResult { + let start = self.expect(Token::If)?; + self.fuzzy_struct_state = true; + let expr = self.parse_expression_fuzzy()?; + self.fuzzy_struct_state = false; + let body = self.parse_block()?; + let next = if self.eat(Token::Else).is_some() { + Some(Box::new(self.parse_statement()?)) + } else { + None + }; + + Ok(ConditionalStatement { + span: &start + next.as_ref().map(|x| x.span()).unwrap_or(&body.span), + condition: expr, + block: body, + next, + }) + } + + pub fn parse_for_statement(&mut self) -> SyntaxResult { + let start_span = self.expect(Token::For)?; + let ident = self.expect_ident()?; + self.expect(Token::In)?; + let start = self.parse_expression()?; + self.expect(Token::DotDot)?; + self.fuzzy_struct_state = true; + let stop = self.parse_expression_fuzzy()?; + self.fuzzy_struct_state = false; + let block = self.parse_block()?; + + Ok(IterationStatement { + span: start_span + block.span.clone(), + variable: ident, + start, + stop, + block, + }) + } + + pub fn parse_formatted_string(&mut self) -> SyntaxResult { + let start_span; + let parts = match self.expect_any()? { + SpannedToken { + token: Token::FormattedString(parts), + span, + } => { + start_span = span; + parts + } + SpannedToken { token, span } => return Err(SyntaxError::unexpected_str(&token, "formatted string", &span)), + }; + let mut parameters = vec![]; + while self.eat(Token::Comma).is_some() { + let param = self.parse_expression()?; + parameters.push(param); + } + + Ok(FormattedString { + parts: parts + .into_iter() + .map(|x| match x { + crate::FormattedStringPart::Const(value) => FormattedStringPart::Const(value), + crate::FormattedStringPart::Container => FormattedStringPart::Container, + }) + .collect(), + span: &start_span + parameters.last().map(|x| x.span()).unwrap_or(&start_span), + parameters, + }) + } + + pub fn parse_console_statement(&mut self) -> SyntaxResult { + let keyword = self.expect(Token::Console)?; + self.expect(Token::Dot)?; + let function = self.expect_ident()?; + self.expect(Token::LeftParen)?; + let function = match &*function.name { + "assert" => { + let expr = self.parse_expression()?; + ConsoleFunction::Assert(expr) + } + "debug" => ConsoleFunction::Debug(self.parse_formatted_string()?), + "error" => ConsoleFunction::Error(self.parse_formatted_string()?), + "log" => ConsoleFunction::Log(self.parse_formatted_string()?), + x => { + return Err(SyntaxError::unexpected_ident( + &x, + &["assert", "debug", "error", "log"], + &function.span, + )); + } + }; + self.expect(Token::RightParen)?; + self.expect(Token::Semicolon)?; + + Ok(ConsoleStatement { + span: &keyword + function.span(), + function, + }) + } + + pub fn parse_variable_name(&mut self) -> SyntaxResult { + let mutable = self.eat(Token::Mut); + let name = self.expect_ident()?; + Ok(VariableName { + span: mutable + .as_ref() + .map(|x| &x.span + &name.span) + .unwrap_or_else(|| name.span.clone()), + mutable: mutable.is_some(), + identifier: name, + }) + } + + pub fn parse_definition_statement(&mut self) -> SyntaxResult { + let declare = self.expect_oneof(&[Token::Let, Token::Const])?; + let mut variable_names = vec![]; + if self.eat(Token::LeftParen).is_some() { + variable_names.push(self.parse_variable_name()?); + while self.eat(Token::Comma).is_some() { + variable_names.push(self.parse_variable_name()?); + } + self.expect(Token::RightParen)?; + } else { + variable_names.push(self.parse_variable_name()?); + } + + let type_ = if self.eat(Token::Colon).is_some() { + Some(self.parse_type()?.0) + } else { + None + }; + + self.expect(Token::Assign)?; + let expr = self.parse_expression()?; + self.expect(Token::Semicolon)?; + + Ok(DefinitionStatement { + span: &declare.span + expr.span(), + declaration_type: match declare.token { + Token::Let => Declare::Let, + Token::Const => { + return Err(SyntaxError::DeprecatedError(DeprecatedError::const_statement( + &declare.span, + ))); + //Declare::Const + } + _ => unimplemented!(), + }, + variable_names, + type_, + value: expr, + }) + } +} diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs new file mode 100644 index 0000000000..97e71c2ead --- /dev/null +++ b/parser/src/parser/type_.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 super::*; + +const TYPE_TOKENS: &[Token] = &[ + Token::I8, + Token::I16, + Token::I32, + Token::I64, + Token::I128, + Token::U8, + Token::U16, + Token::U32, + Token::U64, + Token::U128, + Token::Field, + Token::Group, + Token::Address, + Token::Bool, +]; + +impl ParserContext { + pub fn token_to_int_type(token: Token) -> Option { + Some(match token { + Token::I8 => IntegerType::I8, + Token::I16 => IntegerType::I16, + Token::I32 => IntegerType::I32, + Token::I64 => IntegerType::I64, + Token::I128 => IntegerType::I128, + Token::U8 => IntegerType::U8, + Token::U16 => IntegerType::U16, + Token::U32 => IntegerType::U32, + Token::U64 => IntegerType::U64, + Token::U128 => IntegerType::U128, + _ => return None, + }) + } + + pub fn parse_array_dimensions(&mut self) -> SyntaxResult { + Ok(if let Some((int, _)) = self.eat_int() { + ArrayDimensions(vec![int]) + } else { + self.expect(Token::LeftParen)?; + let mut dimensions = vec![]; + loop { + if let Some((int, _)) = self.eat_int() { + dimensions.push(int); + } else { + let token = self.peek()?; + return Err(SyntaxError::unexpected_str(&token.token, "int", &token.span)); + } + if self.eat(Token::Comma).is_none() { + break; + } + } + self.expect(Token::RightParen)?; + ArrayDimensions(dimensions) + }) + } + + pub fn parse_type(&mut self) -> SyntaxResult<(Type, Span)> { + Ok(if let Some(token) = self.eat(Token::BigSelf) { + (Type::SelfType, token.span) + } else if let Some(ident) = self.eat_ident() { + let span = ident.span.clone(); + (Type::Circuit(ident), span) + } else if let Some(token) = self.eat(Token::LeftParen) { + let mut types = vec![]; + let end_span; + loop { + if let Some(end) = self.eat(Token::RightParen) { + end_span = end.span; + break; + } + types.push(self.parse_type()?.0); + if self.eat(Token::Comma).is_none() { + end_span = self.expect(Token::RightParen)?; + break; + } + } + (Type::Tuple(types), token.span + end_span) + } else if let Some(token) = self.eat(Token::LeftSquare) { + let (inner, _) = self.parse_type()?; + self.expect(Token::Semicolon)?; + let dimensions = self.parse_array_dimensions()?; + let end_span = self.expect(Token::RightSquare)?; + (Type::Array(Box::new(inner), dimensions), token.span + end_span) + } else { + let token = self.expect_oneof(TYPE_TOKENS)?; + ( + match token.token { + Token::Field => Type::Field, + Token::Group => Type::Group, + Token::Address => Type::Address, + Token::Bool => Type::Boolean, + x => Type::IntegerType(Self::token_to_int_type(x).expect("invalid int type")), + }, + token.span, + ) + }) + } +} diff --git a/parser/src/test.rs b/parser/src/test.rs new file mode 100644 index 0000000000..dc1f0888b9 --- /dev/null +++ b/parser/src/test.rs @@ -0,0 +1,99 @@ +// 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 std::{fs, path::Path}; + +use crate::SyntaxError; + +struct TestFailure { + path: String, + error: SyntaxError, +} + +pub fn find_tests>(path: T, out: &mut Vec<(String, String)>) { + for entry in fs::read_dir(path).expect("fail to read tests").into_iter() { + let entry = entry.expect("fail to read tests").path(); + if entry.is_dir() { + find_tests(entry.as_path(), out); + continue; + } else if entry.extension().map(|x| x.to_str()).flatten().unwrap_or_default() != "leo" { + continue; + } + let content = fs::read_to_string(entry.as_path()).expect("failed to read test"); + out.push((entry.as_path().to_str().unwrap_or_default().to_string(), content)); + } +} + +#[test] +pub fn parser_pass_tests() { + let mut pass = 0; + let mut fail = vec![]; + let mut tests = vec![]; + find_tests("../tests/pass/parse/", &mut tests); + for (path, content) in tests.into_iter() { + match crate::parse(&path, &content) { + Ok(_) => { + pass += 1; + } + Err(e) => { + fail.push(TestFailure { path, error: e }); + } + } + } + if fail.len() > 0 { + for (i, fail) in fail.iter().enumerate() { + println!( + "\n\n-----------------TEST #{} FAILED (and shouldn't have)-----------------", + i + 1 + ); + println!("File: {}", fail.path); + println!("{}", fail.error); + } + panic!("failed {}/{} tests", fail.len(), fail.len() + pass); + } else { + println!("passed {}/{} tests", pass, pass); + } +} + +#[test] +pub fn parser_fail_tests() { + let mut pass = 0; + let mut fail = vec![]; + let mut tests = vec![]; + find_tests("../tests/fail/parse/", &mut tests); + for (path, content) in tests.into_iter() { + match crate::parse(&path, &content) { + Ok(_) => { + fail.push(path); + } + Err(_e) => { + pass += 1; + } + } + } + if fail.len() > 0 { + for (i, fail) in fail.iter().enumerate() { + println!( + "\n\n-----------------TEST #{} PASSED (and shouldn't have)-----------------", + i + 1 + ); + println!("File: {}", fail); + } + panic!("failed {}/{} tests", fail.len(), fail.len() + pass); + } else { + println!("passed {}/{} tests", pass, pass); + } +} diff --git a/parser/src/token.rs b/parser/src/token.rs new file mode 100644 index 0000000000..b1124eeac4 --- /dev/null +++ b/parser/src/token.rs @@ -0,0 +1,280 @@ +// 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 std::fmt; + +#[derive(Clone, Debug, PartialEq)] +pub enum FormattedStringPart { + Const(String), + Container, +} + +impl fmt::Display for FormattedStringPart { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + FormattedStringPart::Const(c) => write!(f, "{}", c), + FormattedStringPart::Container => write!(f, "{{}}"), + } + } +} + +#[derive(Clone, Debug, PartialEq)] +pub enum Token { + FormattedString(Vec), + AddressLit(String), + Ident(String), + Int(String), + CommentLine(String), + CommentBlock(String), + Not, + NotEq, + And, + LeftParen, + RightParen, + Mul, + Exp, + ExpEq, + MulEq, + Add, + AddEq, + Comma, + Minus, + MinusEq, + Arrow, + Dot, + DotDot, + DotDotDot, + Div, + DivEq, + Colon, + DoubleColon, + Semicolon, + Lt, + LtEq, + Assign, + Eq, + Gt, + GtEq, + At, + LeftSquare, + RightSquare, + Address, + As, + Bool, + Circuit, + Const, + Else, + False, + Field, + For, + Function, + Group, + I128, + I64, + I32, + I16, + I8, + If, + Import, + In, + Input, + Let, + Mut, + Return, + Static, + Str, + True, + U128, + U64, + U32, + U16, + U8, + BigSelf, + LittleSelf, + Console, + LeftCurly, + RightCurly, + Or, + BitAnd, + BitAndEq, + BitOr, + BitOrEq, + BitXor, + BitXorEq, + BitNot, + Shl, + ShlEq, + Shr, + ShrEq, + ShrSigned, + ShrSignedEq, + Mod, + ModEq, + OrEq, + AndEq, + Question, +} + +pub const KEYWORD_TOKENS: &[Token] = &[ + Token::Address, + Token::As, + Token::Bool, + Token::Circuit, + Token::Const, + Token::Else, + Token::False, + Token::Field, + Token::For, + Token::Function, + Token::Group, + Token::I128, + Token::I64, + Token::I32, + Token::I16, + Token::I8, + Token::If, + Token::Import, + Token::In, + Token::Input, + Token::Let, + Token::Mut, + Token::Return, + Token::Static, + Token::Str, + Token::True, + Token::U128, + Token::U64, + Token::U32, + Token::U16, + Token::U8, + Token::BigSelf, + Token::LittleSelf, + Token::Console, +]; + +impl Token { + pub fn is_keyword(&self) -> bool { + KEYWORD_TOKENS.iter().any(|x| x == self) + } +} + +impl fmt::Display for Token { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + use Token::*; + match self { + FormattedString(parts) => { + // todo escapes + write!(f, "\"")?; + for part in parts.iter() { + part.fmt(f)?; + } + write!(f, "\"") + } + AddressLit(s) => write!(f, "{}", s), + Ident(s) => write!(f, "{}", s), + Int(s) => write!(f, "{}", s), + CommentLine(s) => writeln!(f, "//{}", s), + CommentBlock(s) => write!(f, "/*{}*/ ", s), + Not => write!(f, "!"), + NotEq => write!(f, "!="), + And => write!(f, "&&"), + LeftParen => write!(f, "("), + RightParen => write!(f, ")"), + Mul => write!(f, "*"), + Exp => write!(f, "**"), + ExpEq => write!(f, "**="), + MulEq => write!(f, "*="), + Add => write!(f, "+"), + AddEq => write!(f, "+="), + Comma => write!(f, ","), + Minus => write!(f, "-"), + MinusEq => write!(f, "-="), + Arrow => write!(f, "->"), + Dot => write!(f, "."), + DotDot => write!(f, ".."), + DotDotDot => write!(f, "..."), + Div => write!(f, "/"), + DivEq => write!(f, "/="), + Colon => write!(f, ":"), + DoubleColon => write!(f, "::"), + Semicolon => write!(f, ";"), + Lt => write!(f, "<"), + LtEq => write!(f, "<="), + Assign => write!(f, "="), + Eq => write!(f, "=="), + Gt => write!(f, ">"), + GtEq => write!(f, ">="), + At => write!(f, "@"), + LeftSquare => write!(f, "["), + RightSquare => write!(f, "]"), + Address => write!(f, "address"), + As => write!(f, "as"), + Bool => write!(f, "bool"), + Circuit => write!(f, "circuit"), + Const => write!(f, "const"), + Else => write!(f, "else"), + False => write!(f, "false"), + Field => write!(f, "field"), + For => write!(f, "for"), + Function => write!(f, "function"), + Group => write!(f, "group"), + I128 => write!(f, "i128"), + I64 => write!(f, "i64"), + I32 => write!(f, "i32"), + I16 => write!(f, "i16"), + I8 => write!(f, "i8"), + If => write!(f, "if"), + Import => write!(f, "import"), + In => write!(f, "in"), + Input => write!(f, "input"), + Let => write!(f, "let"), + Mut => write!(f, "mut"), + Return => write!(f, "return"), + Static => write!(f, "static"), + Str => write!(f, "string"), + True => write!(f, "true"), + U128 => write!(f, "u128"), + U64 => write!(f, "u64"), + U32 => write!(f, "u32"), + U16 => write!(f, "u16"), + U8 => write!(f, "u8"), + BigSelf => write!(f, "Self"), + LittleSelf => write!(f, "self"), + Console => write!(f, "console"), + LeftCurly => write!(f, "{{"), + RightCurly => write!(f, "}}"), + Or => write!(f, "||"), + BitAnd => write!(f, "&"), + BitAndEq => write!(f, "&="), + BitOr => write!(f, "|"), + BitOrEq => write!(f, "|="), + BitXor => write!(f, "^"), + BitXorEq => write!(f, "^="), + BitNot => write!(f, "~"), + Shl => write!(f, "<<"), + ShlEq => write!(f, "<<="), + Shr => write!(f, ">>"), + ShrEq => write!(f, ">>="), + ShrSigned => write!(f, ">>>"), + ShrSignedEq => write!(f, ">>>="), + Mod => write!(f, "%"), + ModEq => write!(f, "%="), + OrEq => write!(f, "||="), + AndEq => write!(f, "&&="), + Question => write!(f, "?"), + } + } +} diff --git a/parser/src/tokenizer.rs b/parser/src/tokenizer.rs new file mode 100644 index 0000000000..b7eb61deba --- /dev/null +++ b/parser/src/tokenizer.rs @@ -0,0 +1,557 @@ +// 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::{FormattedStringPart, Token, TokenError}; +use leo_ast::Span; +use std::{fmt, rc::Rc}; + +fn eat<'a>(input: &'a [u8], wanted: &str) -> Option<&'a [u8]> { + let wanted = wanted.as_bytes(); + if input.len() < wanted.len() { + return None; + } + if &input[0..wanted.len()] == wanted { + return Some(&input[wanted.len()..]); + } + None +} + +fn eat_identifier(input: &[u8]) -> Option<(&[u8], &[u8])> { + if input.is_empty() { + return None; + } + if !input[0].is_ascii_alphabetic() && input[0] != b'_' { + return None; + } + let mut i = 1usize; + while i < input.len() { + if !input[i].is_ascii_alphanumeric() && input[i] != b'_' { + break; + } + i += 1; + } + Some((&input[0..i], &input[i..])) +} + +impl Token { + fn gobble_int(input: &[u8]) -> (&[u8], Option) { + if input.is_empty() { + return (input, None); + } + if !input[0].is_ascii_digit() { + return (input, None); + } + let mut i = 1; + let mut is_hex = false; + while i < input.len() { + if i == 1 && input[0] == b'0' && input[i] == b'x' { + is_hex = true; + i += 1; + continue; + } + if is_hex { + if !input[i].is_ascii_hexdigit() { + break; + } + } else if !input[i].is_ascii_digit() { + break; + } + + i += 1; + } + ( + &input[i..], + Some(Token::Int(String::from_utf8(input[0..i].to_vec()).unwrap_or_default())), + ) + } + + fn gobble(input: &[u8]) -> (&[u8], Option) { + if input.len() == 0 { + return (input, None); + } + match input[0] { + x if x.is_ascii_whitespace() => return (&input[1..], None), + b'"' => { + let mut i = 1; + let mut in_escape = false; + let mut start = 1usize; + let mut segments = vec![]; + while i < input.len() { + if !in_escape { + if input[i] == b'"' { + break; + } + if input[i] == b'\\' { + in_escape = !in_escape; + } else if i < input.len() - 1 && input[i] == b'{' { + if i < input.len() - 2 && input[i + 1] == b'{' { + i += 2; + continue; + } else if input[i + 1] != b'}' { + i += 1; + continue; + } + if start < i { + segments.push(FormattedStringPart::Const( + String::from_utf8_lossy(&input[start..i]).to_string(), + )); + } + segments.push(FormattedStringPart::Container); + start = i + 2; + i = start; + continue; + } + } else { + in_escape = false; + } + i += 1; + } + if i == input.len() { + return (input, None); + } + if start < i { + segments.push(FormattedStringPart::Const( + String::from_utf8_lossy(&input[start..i]).to_string(), + )); + } + return (&input[(i + 1)..], Some(Token::FormattedString(segments))); + } + x if x.is_ascii_digit() => { + return Self::gobble_int(input); + } + b'!' => { + if let Some(input) = eat(input, "!=") { + return (input, Some(Token::NotEq)); + } + return (&input[1..], Some(Token::Not)); + } + b'?' => { + return (&input[1..], Some(Token::Question)); + } + b'&' => { + if let Some(input) = eat(input, "&&") { + if let Some(input) = eat(input, "=") { + return (input, Some(Token::AndEq)); + } + return (input, Some(Token::And)); + } else if let Some(input) = eat(input, "&=") { + return (input, Some(Token::BitAndEq)); + } + return (&input[1..], Some(Token::BitAnd)); + } + b'(' => return (&input[1..], Some(Token::LeftParen)), + b')' => return (&input[1..], Some(Token::RightParen)), + b'*' => { + if let Some(input) = eat(input, "**") { + if let Some(input) = eat(input, "=") { + return (input, Some(Token::ExpEq)); + } + return (input, Some(Token::Exp)); + } else if let Some(input) = eat(input, "*=") { + return (input, Some(Token::MulEq)); + } + return (&input[1..], Some(Token::Mul)); + } + b'+' => { + if let Some(input) = eat(input, "+=") { + return (input, Some(Token::AddEq)); + } + return (&input[1..], Some(Token::Add)); + } + b',' => return (&input[1..], Some(Token::Comma)), + b'-' => { + if let (followed_int, Some(Token::Int(token))) = Self::gobble_int(&input[1..]) { + return (followed_int, Some(Token::Int(format!("-{}", token)))); + } else if let Some(input) = eat(input, "->") { + return (input, Some(Token::Arrow)); + } else if let Some(input) = eat(input, "-=") { + return (input, Some(Token::MinusEq)); + } + return (&input[1..], Some(Token::Minus)); + } + b'.' => { + if let Some(input) = eat(input, "...") { + return (input, Some(Token::DotDotDot)); + } else if let Some(input) = eat(input, "..") { + return (input, Some(Token::DotDot)); + } + return (&input[1..], Some(Token::Dot)); + } + b'/' => { + if let Some(input) = eat(input, "//") { + let eol = input.iter().position(|x| *x == b'\n'); + let (input, comment) = if let Some(eol) = eol { + (&input[(eol + 1)..], &input[..eol]) + } else { + (&input[input.len()..input.len()], &input[..]) + }; + return ( + input, + Some(Token::CommentLine(String::from_utf8_lossy(comment).to_string())), + ); + } else if let Some(input) = eat(input, "/*") { + if input.is_empty() { + return (input, None); + } + let eol = input.windows(2).position(|x| x[0] == b'*' && x[1] == b'/'); + let (input, comment) = if let Some(eol) = eol { + (&input[(eol + 2)..], &input[..eol]) + } else { + (&input[input.len()..input.len()], &input[..]) + }; + return ( + input, + Some(Token::CommentBlock(String::from_utf8_lossy(comment).to_string())), + ); + } else if let Some(input) = eat(input, "/=") { + return (input, Some(Token::DivEq)); + } + return (&input[1..], Some(Token::Div)); + } + b':' => { + if let Some(input) = eat(input, "::") { + return (input, Some(Token::DoubleColon)); + } else { + return (&input[1..], Some(Token::Colon)); + } + } + b';' => return (&input[1..], Some(Token::Semicolon)), + b'<' => { + if let Some(input) = eat(input, "<=") { + return (input, Some(Token::LtEq)); + } else if let Some(input) = eat(input, "<<") { + if let Some(input) = eat(input, "=") { + return (input, Some(Token::ShlEq)); + } + return (input, Some(Token::Shl)); + } + return (&input[1..], Some(Token::Lt)); + } + b'>' => { + if let Some(input) = eat(input, ">=") { + return (input, Some(Token::GtEq)); + } else if let Some(input) = eat(input, ">>") { + if let Some(input) = eat(input, "=") { + return (input, Some(Token::ShrEq)); + } else if let Some(input) = eat(input, ">") { + if let Some(input) = eat(input, "=") { + return (input, Some(Token::ShrSignedEq)); + } + return (input, Some(Token::ShrSigned)); + } + return (input, Some(Token::Shr)); + } + return (&input[1..], Some(Token::Gt)); + } + b'=' => { + if let Some(input) = eat(input, "==") { + return (input, Some(Token::Eq)); + } + return (&input[1..], Some(Token::Assign)); + } + b'@' => return (&input[1..], Some(Token::At)), + b'[' => return (&input[1..], Some(Token::LeftSquare)), + b']' => return (&input[1..], Some(Token::RightSquare)), + b'{' => return (&input[1..], Some(Token::LeftCurly)), + b'}' => return (&input[1..], Some(Token::RightCurly)), + b'|' => { + if let Some(input) = eat(input, "||") { + if let Some(input) = eat(input, "=") { + return (input, Some(Token::OrEq)); + } + return (input, Some(Token::Or)); + } else if let Some(input) = eat(input, "|=") { + return (input, Some(Token::BitOrEq)); + } + return (&input[1..], Some(Token::BitOr)); + } + b'^' => { + if let Some(input) = eat(input, "^=") { + return (input, Some(Token::BitXorEq)); + } + return (&input[1..], Some(Token::BitXor)); + } + b'~' => return (&input[1..], Some(Token::BitNot)), + b'%' => { + if let Some(input) = eat(input, "%=") { + return (input, Some(Token::ModEq)); + } + return (&input[1..], Some(Token::Mod)); + } + _ => (), + } + if let Some((ident, input)) = eat_identifier(input) { + let ident = String::from_utf8_lossy(ident).to_string(); + return ( + input, + Some(match &*ident { + x if x.starts_with("aleo1") + && x.chars().skip(5).all(|x| x.is_ascii_lowercase() || x.is_ascii_digit()) => + { + Token::AddressLit(x.to_string()) + } + "address" => Token::Address, + "as" => Token::As, + "bool" => Token::Bool, + "circuit" => Token::Circuit, + "const" => Token::Const, + "else" => Token::Else, + "false" => Token::False, + "field" => Token::Field, + "for" => Token::For, + "function" => Token::Function, + "group" => Token::Group, + "i128" => Token::I128, + "i64" => Token::I64, + "i32" => Token::I32, + "i16" => Token::I16, + "i8" => Token::I8, + "if" => Token::If, + "import" => Token::Import, + "in" => Token::In, + "input" => Token::Input, + "let" => Token::Let, + "mut" => Token::Mut, + "return" => Token::Return, + "static" => Token::Static, + "string" => Token::Str, + "true" => Token::True, + "u128" => Token::U128, + "u64" => Token::U64, + "u32" => Token::U32, + "u16" => Token::U16, + "u8" => Token::U8, + "Self" => Token::BigSelf, + "self" => Token::LittleSelf, + "console" => Token::Console, + _ => Token::Ident(ident), + }), + ); + } + + (input, None) + } +} + +#[derive(Clone)] +pub struct SpannedToken { + pub token: Token, + pub span: Span, +} + +impl fmt::Display for SpannedToken { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "'{}' @ ", self.token.to_string().trim())?; + self.span.fmt(f) + } +} + +impl fmt::Debug for SpannedToken { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + ::fmt(self, f) + } +} + +fn validate_address(address: &str) -> bool { + // "aleo1" (LOWERCASE_LETTER | ASCII_DIGIT){58} + if !address.starts_with("aleo1") || address.len() != 63 { + return false; + } + address + .chars() + .skip(5) + .all(|x| x.is_ascii_lowercase() || x.is_ascii_digit()) +} + +pub fn tokenize(input: &str, path: &str) -> Result, TokenError> { + let path = Rc::new(path.to_string()); + let mut input = input.as_bytes(); + let mut tokens = vec![]; + let mut index = 0usize; + let mut line_no = 1usize; + let mut line_start = 0usize; + while !input.is_empty() { + match Token::gobble(input) { + (output, Some(token)) => { + let span = Span { + line_start: line_no, + line_stop: line_no, + col_start: index - line_start + 1, + col_stop: index - line_start + (input.len() - output.len()) + 1, + path: path.clone(), + }; + if let Token::AddressLit(address) = &token { + if !validate_address(address) { + return Err(TokenError::invalid_address_lit(address, &span)); + } + } + tokens.push(SpannedToken { token, span }); + index += input.len() - output.len(); + input = output; + } + (output, None) => { + if output.is_empty() { + break; + } else if output.len() == input.len() { + return Err(TokenError::unexpected_token( + &String::from_utf8_lossy(&[input[0]]), + &Span { + line_start: line_no, + line_stop: line_no, + col_start: index - line_start + 1, + col_stop: index - line_start + 2, + path, + }, + )); + } + index += input.len() - output.len(); + if input[0] == b'\n' { + line_no += 1; + line_start = index; + } + input = output; + } + } + } + Ok(tokens) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_tokenizer() { + let tokens = tokenize( + r#" + "test" + "test{}test" + "test{}" + "{}test" + "test{" + "test}" + "test{test" + "test}test" + "te{{}}" + aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 + test_ident + 12345 + address + as + bool + circuit + const + else + false + field + for + function + group + i128 + i64 + i32 + i16 + i8 + if + import + in + input + let + mut + return + static + string + test + true + u128 + u64 + u32 + u16 + u8 + self + Self + console + ! + != + && + ( + ) + * + ** + **= + *= + + + += + , + - + -= + -> + . + .. + ... + / + /= + : + :: + ; + < + <= + = + == + > + >= + @ + [ + ] + {{ + }} + || + & + &= + | + |= + ^ + ^= + ~ + << + <<= + >> + >>= + >>> + >>>= + % + %= + ||= + &&= + ? + // test + /* test */ + //"#, + "test_path", + ) + .unwrap(); + let mut output = String::new(); + for SpannedToken { token, .. } in tokens.iter() { + output += &format!("{} ", &token.to_string()); + } + assert_eq!( + output, + r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= ? // test + /* test */ // + "# + ); + } +} diff --git a/ast/tests/mod.rs b/parser/tests/mod.rs similarity index 100% rename from ast/tests/mod.rs rename to parser/tests/mod.rs diff --git a/ast/tests/serialization/deprecated_error.leo b/parser/tests/serialization/deprecated_error.leo similarity index 100% rename from ast/tests/serialization/deprecated_error.leo rename to parser/tests/serialization/deprecated_error.leo diff --git a/ast/tests/serialization/expected_leo_ast.json b/parser/tests/serialization/expected_leo_ast.json similarity index 100% rename from ast/tests/serialization/expected_leo_ast.json rename to parser/tests/serialization/expected_leo_ast.json diff --git a/ast/tests/serialization/json.rs b/parser/tests/serialization/json.rs similarity index 76% rename from ast/tests/serialization/json.rs rename to parser/tests/serialization/json.rs index 5a58ff12c5..a52634df78 100644 --- a/ast/tests/serialization/json.rs +++ b/parser/tests/serialization/json.rs @@ -14,22 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use leo_ast::Ast; #[cfg(not(feature = "ci_skip"))] use leo_ast::Program; -use leo_ast::{Ast, AstError}; -use leo_grammar::{Grammar, ParserError}; +use leo_parser::SyntaxError; use std::path::{Path, PathBuf}; -fn to_ast(program_filepath: &Path) -> Result { - // Loads the Leo code as a string from the given file path. - let program_string = Grammar::load_file(program_filepath)?; +fn to_ast(program_filepath: &Path) -> Result { + let program_string = std::fs::read_to_string(program_filepath).expect("failed to open test"); - // Parses the Leo file and constructs a grammar ast. - let ast = Grammar::new(&program_filepath, &program_string)?; - - // Parses the pest ast and constructs a Leo ast. - Ast::new("leo_tree", &ast) + // Parses the Leo file and constructs a leo ast. + leo_parser::parse_ast(&program_filepath.to_str().unwrap(), &program_string) } #[test] @@ -92,19 +88,6 @@ fn test_serialize_deserialize_serialize() { assert_eq!(serialized_ast, reserialized_ast); } -#[test] -fn test_file_read_error() { - let error_result = { - let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - program_filepath.push("tests/serialization/dne.leo"); - - to_ast(&program_filepath) - } - .map_err(|err| matches!(err, AstError::ParserError(x) if matches!(x, ParserError::FileReadError(_)))); - - assert!(error_result.err().unwrap()); -} - #[test] fn test_generic_parser_error() { let error_result = { @@ -113,7 +96,7 @@ fn test_generic_parser_error() { to_ast(&program_filepath) } - .map_err(|err| matches!(err, AstError::ParserError(_))); + .map_err(|err| matches!(err, SyntaxError::Error(_))); assert!(error_result.err().unwrap()); } diff --git a/ast/tests/serialization/main.leo b/parser/tests/serialization/main.leo similarity index 100% rename from ast/tests/serialization/main.leo rename to parser/tests/serialization/main.leo diff --git a/ast/tests/serialization/mod.rs b/parser/tests/serialization/mod.rs similarity index 100% rename from ast/tests/serialization/mod.rs rename to parser/tests/serialization/mod.rs diff --git a/ast/tests/serialization/parser_error.leo b/parser/tests/serialization/parser_error.leo similarity index 100% rename from ast/tests/serialization/parser_error.leo rename to parser/tests/serialization/parser_error.leo diff --git a/tests/fail/parse/address/empty.leo b/tests/fail/parse/address/empty.leo new file mode 100644 index 0000000000..e5c06d0def --- /dev/null +++ b/tests/fail/parse/address/empty.leo @@ -0,0 +1,3 @@ +function main() { + let owner = address(); +} \ No newline at end of file diff --git a/tests/fail/parse/address/invalid_length.leo b/tests/fail/parse/address/invalid_length.leo new file mode 100644 index 0000000000..c1b7f719be --- /dev/null +++ b/tests/fail/parse/address/invalid_length.leo @@ -0,0 +1,3 @@ +function main() { + let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88); +} \ No newline at end of file diff --git a/tests/fail/parse/address/invalid_prefix.leo b/tests/fail/parse/address/invalid_prefix.leo new file mode 100644 index 0000000000..81959d2fa6 --- /dev/null +++ b/tests/fail/parse/address/invalid_prefix.leo @@ -0,0 +1,3 @@ +function main() { + let public_key_string = address(zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); +} \ No newline at end of file diff --git a/tests/fail/parse/array/initializer_fail.leo b/tests/fail/parse/array/initializer_fail.leo new file mode 100644 index 0000000000..3b2e7785cc --- /dev/null +++ b/tests/fail/parse/array/initializer_fail.leo @@ -0,0 +1,3 @@ +function main(a: [u8; 3]) { + console.assert(a == [1u8; -3]); +} \ No newline at end of file diff --git a/tests/fail/parse/array/type_fail.leo b/tests/fail/parse/array/type_fail.leo new file mode 100644 index 0000000000..1402ceba4c --- /dev/null +++ b/tests/fail/parse/array/type_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: [u8; -2] = [0u32; 2]; +} \ No newline at end of file diff --git a/tests/fail/parse/circuits/self_circuit.leo b/tests/fail/parse/circuits/self_circuit.leo new file mode 100644 index 0000000000..5a1d6c63be --- /dev/null +++ b/tests/fail/parse/circuits/self_circuit.leo @@ -0,0 +1,9 @@ +circuit Foo { + static function new() -> Self { + return Self { } + } +} + +function main() { + let a = Foo::new(); +} \ No newline at end of file diff --git a/tests/fail/parse/console/log_fail.leo b/tests/fail/parse/console/log_fail.leo new file mode 100644 index 0000000000..dafa6bea8e --- /dev/null +++ b/tests/fail/parse/console/log_fail.leo @@ -0,0 +1,3 @@ +function main() { + console.log( hello ); +} \ No newline at end of file diff --git a/tests/fail/parse/import/names_a_dash.leo b/tests/fail/parse/import/names_a_dash.leo new file mode 100644 index 0000000000..ec136176b2 --- /dev/null +++ b/tests/fail/parse/import/names_a_dash.leo @@ -0,0 +1,3 @@ +import a-.foo; + +function main() {} \ No newline at end of file diff --git a/tests/fail/parse/import/names_dash_a.leo b/tests/fail/parse/import/names_dash_a.leo new file mode 100644 index 0000000000..95ccb7e4a5 --- /dev/null +++ b/tests/fail/parse/import/names_dash_a.leo @@ -0,0 +1,3 @@ +import -a.foo; + +function main() {} \ No newline at end of file diff --git a/tests/fail/parse/import/names_dollar.leo b/tests/fail/parse/import/names_dollar.leo new file mode 100644 index 0000000000..e4eaec3719 --- /dev/null +++ b/tests/fail/parse/import/names_dollar.leo @@ -0,0 +1,3 @@ +import money$.foo; + +function main() {} \ No newline at end of file diff --git a/tests/fail/parse/syntax/address_fail.leo b/tests/fail/parse/syntax/address_fail.leo new file mode 100644 index 0000000000..4eb12c7743 --- /dev/null +++ b/tests/fail/parse/syntax/address_fail.leo @@ -0,0 +1,3 @@ +function main() { + let address = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/console_fail.leo b/tests/fail/parse/syntax/console_fail.leo new file mode 100644 index 0000000000..6ee932a66b --- /dev/null +++ b/tests/fail/parse/syntax/console_fail.leo @@ -0,0 +1,3 @@ +function main() { + let console = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/field_fail.leo b/tests/fail/parse/syntax/field_fail.leo new file mode 100644 index 0000000000..a1f85dc6ea --- /dev/null +++ b/tests/fail/parse/syntax/field_fail.leo @@ -0,0 +1,3 @@ +function main() { + let field = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/group_fail.leo b/tests/fail/parse/syntax/group_fail.leo new file mode 100644 index 0000000000..322997ea50 --- /dev/null +++ b/tests/fail/parse/syntax/group_fail.leo @@ -0,0 +1,3 @@ +function main() { + let group = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/i8_fail.leo b/tests/fail/parse/syntax/i8_fail.leo new file mode 100644 index 0000000000..596a9056ab --- /dev/null +++ b/tests/fail/parse/syntax/i8_fail.leo @@ -0,0 +1,3 @@ +function main() { + let i8 = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/input_fail.leo b/tests/fail/parse/syntax/input_fail.leo new file mode 100644 index 0000000000..e1b466d6d4 --- /dev/null +++ b/tests/fail/parse/syntax/input_fail.leo @@ -0,0 +1,3 @@ +function main() { + let input = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/self_keyword_fail.leo b/tests/fail/parse/syntax/self_keyword_fail.leo new file mode 100644 index 0000000000..28b899ccd4 --- /dev/null +++ b/tests/fail/parse/syntax/self_keyword_fail.leo @@ -0,0 +1,3 @@ +function main() { + let Self = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/self_type_fail.leo b/tests/fail/parse/syntax/self_type_fail.leo new file mode 100644 index 0000000000..28b899ccd4 --- /dev/null +++ b/tests/fail/parse/syntax/self_type_fail.leo @@ -0,0 +1,3 @@ +function main() { + let Self = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/semicolon.leo b/tests/fail/parse/syntax/semicolon.leo new file mode 100644 index 0000000000..68cfa7cbe0 --- /dev/null +++ b/tests/fail/parse/syntax/semicolon.leo @@ -0,0 +1,3 @@ +function main() { + let a = 0 +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/true_fail.leo b/tests/fail/parse/syntax/true_fail.leo new file mode 100644 index 0000000000..4eb12c7743 --- /dev/null +++ b/tests/fail/parse/syntax/true_fail.leo @@ -0,0 +1,3 @@ +function main() { + let address = 0u32; +} \ No newline at end of file diff --git a/tests/fail/parse/syntax/u8_fail.leo b/tests/fail/parse/syntax/u8_fail.leo new file mode 100644 index 0000000000..77687f5ff2 --- /dev/null +++ b/tests/fail/parse/syntax/u8_fail.leo @@ -0,0 +1,3 @@ +function main() { + let u8 = 0u32; +} \ No newline at end of file diff --git a/tests/pass/parse/address/console_assert_fail.leo b/tests/pass/parse/address/console_assert_fail.leo new file mode 100644 index 0000000000..3e7a5f106d --- /dev/null +++ b/tests/pass/parse/address/console_assert_fail.leo @@ -0,0 +1,6 @@ +function main() { + let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9); + + console.assert(address_1 == address_2); +} \ No newline at end of file diff --git a/tests/pass/parse/address/console_assert_pass.leo b/tests/pass/parse/address/console_assert_pass.leo new file mode 100644 index 0000000000..60ea4a79cd --- /dev/null +++ b/tests/pass/parse/address/console_assert_pass.leo @@ -0,0 +1,6 @@ +function main() { + let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + + console.assert(address_1 == address_2); +} \ No newline at end of file diff --git a/tests/pass/parse/address/equal.leo b/tests/pass/parse/address/equal.leo new file mode 100644 index 0000000000..9012a8c49d --- /dev/null +++ b/tests/pass/parse/address/equal.leo @@ -0,0 +1,3 @@ +function main(a: address, b: address, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/address/implicit_invalid.leo b/tests/pass/parse/address/implicit_invalid.leo new file mode 100644 index 0000000000..6f8eba5114 --- /dev/null +++ b/tests/pass/parse/address/implicit_invalid.leo @@ -0,0 +1,3 @@ +function main() { + let public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +} \ No newline at end of file diff --git a/tests/pass/parse/address/implicit_valid.leo b/tests/pass/parse/address/implicit_valid.leo new file mode 100644 index 0000000000..df6ebf497d --- /dev/null +++ b/tests/pass/parse/address/implicit_valid.leo @@ -0,0 +1,3 @@ +function main() { + let public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +} \ No newline at end of file diff --git a/tests/pass/parse/address/input.leo b/tests/pass/parse/address/input.leo new file mode 100644 index 0000000000..795deac98b --- /dev/null +++ b/tests/pass/parse/address/input.leo @@ -0,0 +1,5 @@ +function main(owner: address) { + let sender = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + + console.assert(owner == sender); +} \ No newline at end of file diff --git a/tests/pass/parse/address/ternary.leo b/tests/pass/parse/address/ternary.leo new file mode 100644 index 0000000000..29ecccb918 --- /dev/null +++ b/tests/pass/parse/address/ternary.leo @@ -0,0 +1,8 @@ +function main(s: bool, c: address) { + let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); + + let r = if s? a: b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/address/valid.leo b/tests/pass/parse/address/valid.leo new file mode 100644 index 0000000000..f06aefdaa6 --- /dev/null +++ b/tests/pass/parse/address/valid.leo @@ -0,0 +1,3 @@ +function main() { + let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); +} \ No newline at end of file diff --git a/tests/pass/parse/array/initializer.leo b/tests/pass/parse/array/initializer.leo new file mode 100644 index 0000000000..51ac19f68f --- /dev/null +++ b/tests/pass/parse/array/initializer.leo @@ -0,0 +1,3 @@ +function main(a: [u8; 3]) { + console.assert(a == [1u8; 3]); +} \ No newline at end of file diff --git a/tests/pass/parse/array/initializer_input.leo b/tests/pass/parse/array/initializer_input.leo new file mode 100644 index 0000000000..4b886159dc --- /dev/null +++ b/tests/pass/parse/array/initializer_input.leo @@ -0,0 +1,3 @@ +function main(a: [u8; (3, 2)]) { + console.assert(a == [0u8; (3, 2)]); +} \ No newline at end of file diff --git a/tests/pass/parse/array/inline.leo b/tests/pass/parse/array/inline.leo new file mode 100644 index 0000000000..8c5c98ae50 --- /dev/null +++ b/tests/pass/parse/array/inline.leo @@ -0,0 +1,3 @@ +function main(a: [u8; 3]) { + console.assert(a == [1u8, 1u8, 1u8]); +} \ No newline at end of file diff --git a/tests/pass/parse/array/input_nested_3x2.leo b/tests/pass/parse/array/input_nested_3x2.leo new file mode 100644 index 0000000000..b7e59a5dc0 --- /dev/null +++ b/tests/pass/parse/array/input_nested_3x2.leo @@ -0,0 +1,3 @@ +function main(a: [u8; (3, 2)]) { + console.assert(a == [[0u8; 2]; 3]); +} diff --git a/tests/pass/parse/array/input_tuple_3x2.leo b/tests/pass/parse/array/input_tuple_3x2.leo new file mode 100644 index 0000000000..4c3c001f41 --- /dev/null +++ b/tests/pass/parse/array/input_tuple_3x2.leo @@ -0,0 +1,3 @@ +function main(a: [u8; (3, 2)]) { + console.assert(a == [0u8; (3, 2)]); +} diff --git a/tests/pass/parse/array/input_tuple_3x2_fail.leo b/tests/pass/parse/array/input_tuple_3x2_fail.leo new file mode 100644 index 0000000000..4c3c001f41 --- /dev/null +++ b/tests/pass/parse/array/input_tuple_3x2_fail.leo @@ -0,0 +1,3 @@ +function main(a: [u8; (3, 2)]) { + console.assert(a == [0u8; (3, 2)]); +} diff --git a/tests/pass/parse/array/multi_fail_initializer.leo b/tests/pass/parse/array/multi_fail_initializer.leo new file mode 100644 index 0000000000..258750b327 --- /dev/null +++ b/tests/pass/parse/array/multi_fail_initializer.leo @@ -0,0 +1,3 @@ +function main() { + let arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions +} \ No newline at end of file diff --git a/tests/pass/parse/array/multi_fail_inline.leo b/tests/pass/parse/array/multi_fail_inline.leo new file mode 100644 index 0000000000..50a06c09b2 --- /dev/null +++ b/tests/pass/parse/array/multi_fail_inline.leo @@ -0,0 +1,4 @@ +function main() { + let arr: [u8; (2, 2)] = [[1u8, 1u8], + [1u8]]; // incorrect dimensions +} \ No newline at end of file diff --git a/tests/pass/parse/array/multi_initializer.leo b/tests/pass/parse/array/multi_initializer.leo new file mode 100644 index 0000000000..7257999ddf --- /dev/null +++ b/tests/pass/parse/array/multi_initializer.leo @@ -0,0 +1,7 @@ +function main() { + let a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; + + let b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2]; + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/multi_initializer_fail.leo b/tests/pass/parse/array/multi_initializer_fail.leo new file mode 100644 index 0000000000..0bd76acffa --- /dev/null +++ b/tests/pass/parse/array/multi_initializer_fail.leo @@ -0,0 +1,3 @@ +function main() { + let arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions +} \ No newline at end of file diff --git a/tests/pass/parse/array/nested.leo b/tests/pass/parse/array/nested.leo new file mode 100644 index 0000000000..c557758b05 --- /dev/null +++ b/tests/pass/parse/array/nested.leo @@ -0,0 +1,4 @@ +function main () { + let x = [false; (2, 2)]; + let y: bool = x[0][0]; +} diff --git a/tests/pass/parse/array/nested_3x2_value.leo b/tests/pass/parse/array/nested_3x2_value.leo new file mode 100644 index 0000000000..b69ddffb89 --- /dev/null +++ b/tests/pass/parse/array/nested_3x2_value.leo @@ -0,0 +1,8 @@ +// Multidimensional array syntax in leo +function main() { + let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + + let b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/nested_3x2_value_fail.leo b/tests/pass/parse/array/nested_3x2_value_fail.leo new file mode 100644 index 0000000000..35c8478cd1 --- /dev/null +++ b/tests/pass/parse/array/nested_3x2_value_fail.leo @@ -0,0 +1,4 @@ +// Multidimensional array syntax in leo +function main() { + let a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) +} diff --git a/tests/pass/parse/array/registers.leo b/tests/pass/parse/array/registers.leo new file mode 100644 index 0000000000..fb8980868e --- /dev/null +++ b/tests/pass/parse/array/registers.leo @@ -0,0 +1,3 @@ +function main(input) -> [u8; 3] { + return input.registers.r +} \ No newline at end of file diff --git a/tests/pass/parse/array/slice.leo b/tests/pass/parse/array/slice.leo new file mode 100644 index 0000000000..296f5bd050 --- /dev/null +++ b/tests/pass/parse/array/slice.leo @@ -0,0 +1,6 @@ +// `{from}..{to}` copies the elements of one array into another exclusively +function main(a: [u8; 3]) { + let b = [1u8; 4]; + + console.assert(a == b[0..3]); +} diff --git a/tests/pass/parse/array/slice_lower.leo b/tests/pass/parse/array/slice_lower.leo new file mode 100644 index 0000000000..dd669830ea --- /dev/null +++ b/tests/pass/parse/array/slice_lower.leo @@ -0,0 +1,8 @@ +function main() { + let arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + let expected: [u32; 2] = [0, 1]; + + let actual = arr[..2]; // Should produce [0, 1] + + console.assert(expected == actual); +} \ No newline at end of file diff --git a/tests/pass/parse/array/spread.leo b/tests/pass/parse/array/spread.leo new file mode 100644 index 0000000000..962e92c923 --- /dev/null +++ b/tests/pass/parse/array/spread.leo @@ -0,0 +1,7 @@ +// A spread operator `...` copies the elements of one array into another +function main(a: [u8; 3]) { + let b = [1u8, 1u8]; + let c = [1u8, ...b]; + + console.assert(a == c); +} \ No newline at end of file diff --git a/tests/pass/parse/array/tuple_3x2_value.leo b/tests/pass/parse/array/tuple_3x2_value.leo new file mode 100644 index 0000000000..dc9128c51e --- /dev/null +++ b/tests/pass/parse/array/tuple_3x2_value.leo @@ -0,0 +1,8 @@ +// Multidimensional array syntax in leo +function main() { + let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + + let b: [u32; (3, 2)] = [0; (3, 2)]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/tuple_3x2_value_fail.leo b/tests/pass/parse/array/tuple_3x2_value_fail.leo new file mode 100644 index 0000000000..42e6f61500 --- /dev/null +++ b/tests/pass/parse/array/tuple_3x2_value_fail.leo @@ -0,0 +1,4 @@ +// Multidimensional array syntax in leo +function main() { + let a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) +} diff --git a/tests/pass/parse/array/type_input_3x2.leo b/tests/pass/parse/array/type_input_3x2.leo new file mode 100644 index 0000000000..40781415c1 --- /dev/null +++ b/tests/pass/parse/array/type_input_3x2.leo @@ -0,0 +1,5 @@ +function main(a: [[u8; 2]; 3]) { + let b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_input_4x3x2.leo b/tests/pass/parse/array/type_input_4x3x2.leo new file mode 100644 index 0000000000..bd75514904 --- /dev/null +++ b/tests/pass/parse/array/type_input_4x3x2.leo @@ -0,0 +1,8 @@ +function main(a: [[[u8; 2]; 3]; 4]) { + let b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_nested_3x2.leo b/tests/pass/parse/array/type_nested_value_nested_3x2.leo new file mode 100644 index 0000000000..341b9ead9c --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_nested_3x2.leo @@ -0,0 +1,7 @@ +function main() { + let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + + let b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_nested_3x2_fail.leo b/tests/pass/parse/array/type_nested_value_nested_3x2_fail.leo new file mode 100644 index 0000000000..4bd07f85db --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_nested_3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_nested_4x3x2.leo b/tests/pass/parse/array/type_nested_value_nested_4x3x2.leo new file mode 100644 index 0000000000..5ba24a381b --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_nested_4x3x2.leo @@ -0,0 +1,10 @@ +function main() { + let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline + + let b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_nested_4x3x2_fail.leo b/tests/pass/parse/array/type_nested_value_nested_4x3x2_fail.leo new file mode 100644 index 0000000000..6479004d68 --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_nested_4x3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_tuple_3x2.leo b/tests/pass/parse/array/type_nested_value_tuple_3x2.leo new file mode 100644 index 0000000000..c6fac9ec64 --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_tuple_3x2.leo @@ -0,0 +1,7 @@ +function main() { + let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + + let b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_tuple_3x2_fail.leo b/tests/pass/parse/array/type_nested_value_tuple_3x2_fail.leo new file mode 100644 index 0000000000..ba99b070c7 --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_tuple_3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_tuple_4x3x2.leo b/tests/pass/parse/array/type_nested_value_tuple_4x3x2.leo new file mode 100644 index 0000000000..9be45de408 --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_tuple_4x3x2.leo @@ -0,0 +1,10 @@ +function main() { + let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline + + let b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_nested_value_tuple_4x3x2_fail.leo b/tests/pass/parse/array/type_nested_value_tuple_4x3x2_fail.leo new file mode 100644 index 0000000000..95172bf329 --- /dev/null +++ b/tests/pass/parse/array/type_nested_value_tuple_4x3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_nested_3x2.leo b/tests/pass/parse/array/type_tuple_value_nested_3x2.leo new file mode 100644 index 0000000000..4e061c4309 --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_nested_3x2.leo @@ -0,0 +1,7 @@ +function main() { + let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + + let b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_nested_3x2_fail.leo b/tests/pass/parse/array/type_tuple_value_nested_3x2_fail.leo new file mode 100644 index 0000000000..9732cf26ef --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_nested_3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_nested_4x3x2.leo b/tests/pass/parse/array/type_tuple_value_nested_4x3x2.leo new file mode 100644 index 0000000000..d9dc698784 --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_nested_4x3x2.leo @@ -0,0 +1,10 @@ +function main() { + let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline + + let b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_nested_4x3x2_fail.leo b/tests/pass/parse/array/type_tuple_value_nested_4x3x2_fail.leo new file mode 100644 index 0000000000..b820c4d088 --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_nested_4x3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_tuple_3x2.leo b/tests/pass/parse/array/type_tuple_value_tuple_3x2.leo new file mode 100644 index 0000000000..b0693f7667 --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_tuple_3x2.leo @@ -0,0 +1,7 @@ +function main() { + let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + + let b: [u8; (3, 2)] = [0; (3, 2)]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_tuple_3x2_fail.leo b/tests/pass/parse/array/type_tuple_value_tuple_3x2_fail.leo new file mode 100644 index 0000000000..99487ccb7a --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_tuple_3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering) +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_tuple_4x3x2.leo b/tests/pass/parse/array/type_tuple_value_tuple_4x3x2.leo new file mode 100644 index 0000000000..cdc1bc961e --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_tuple_4x3x2.leo @@ -0,0 +1,10 @@ +function main() { + let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]]; // inline + + let b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer + + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/array/type_tuple_value_tuple_4x3x2_fail.leo b/tests/pass/parse/array/type_tuple_value_tuple_4x3x2_fail.leo new file mode 100644 index 0000000000..824fd90bc6 --- /dev/null +++ b/tests/pass/parse/array/type_tuple_value_tuple_4x3x2_fail.leo @@ -0,0 +1,3 @@ +function main() { + let b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order) +} \ No newline at end of file diff --git a/tests/pass/parse/array/variable_slice_fail.leo b/tests/pass/parse/array/variable_slice_fail.leo new file mode 100644 index 0000000000..edb04caacf --- /dev/null +++ b/tests/pass/parse/array/variable_slice_fail.leo @@ -0,0 +1,7 @@ +function main() { + let a = [1u8; 10]; + for i in 0..10 { + let x = a[i..10]; + console.debug("{}", x); + } +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/all.leo b/tests/pass/parse/boolean/all.leo new file mode 100644 index 0000000000..29a3815881 --- /dev/null +++ b/tests/pass/parse/boolean/all.leo @@ -0,0 +1,8 @@ +// !(true && (false || true)) +function main() { + let a = true; + let b = false || a; + let c = !(true && b); + + console.assert(c == false); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/assert_eq_input.leo b/tests/pass/parse/boolean/assert_eq_input.leo new file mode 100644 index 0000000000..8a796e5bbd --- /dev/null +++ b/tests/pass/parse/boolean/assert_eq_input.leo @@ -0,0 +1,3 @@ +function main(a: bool, b: bool) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/conditional_mut.leo b/tests/pass/parse/boolean/conditional_mut.leo new file mode 100644 index 0000000000..e6716cb05a --- /dev/null +++ b/tests/pass/parse/boolean/conditional_mut.leo @@ -0,0 +1,6 @@ +function main () { + let mut x = true; + if x { + let y = 0u8; + } +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/false_and_false.leo b/tests/pass/parse/boolean/false_and_false.leo new file mode 100644 index 0000000000..70e4b0797b --- /dev/null +++ b/tests/pass/parse/boolean/false_and_false.leo @@ -0,0 +1,5 @@ +function main() { + let a = false && false; + + console.assert(a == false); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/false_or_false.leo b/tests/pass/parse/boolean/false_or_false.leo new file mode 100644 index 0000000000..4ae820254e --- /dev/null +++ b/tests/pass/parse/boolean/false_or_false.leo @@ -0,0 +1,5 @@ +function main() { + let a = false || false; + + console.assert(a == false); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/not_false.leo b/tests/pass/parse/boolean/not_false.leo new file mode 100644 index 0000000000..796b616871 --- /dev/null +++ b/tests/pass/parse/boolean/not_false.leo @@ -0,0 +1,3 @@ +function main() { + console.assert(!false == true); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/not_mutable.leo b/tests/pass/parse/boolean/not_mutable.leo new file mode 100644 index 0000000000..91a6e5ff37 --- /dev/null +++ b/tests/pass/parse/boolean/not_mutable.leo @@ -0,0 +1,4 @@ +function main () { + let mut b = false; + let a = !b; +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/not_true.leo b/tests/pass/parse/boolean/not_true.leo new file mode 100644 index 0000000000..8c87dffabb --- /dev/null +++ b/tests/pass/parse/boolean/not_true.leo @@ -0,0 +1,3 @@ +function main() { + console.assert(!true == false); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/not_u32.leo b/tests/pass/parse/boolean/not_u32.leo new file mode 100644 index 0000000000..44491d785b --- /dev/null +++ b/tests/pass/parse/boolean/not_u32.leo @@ -0,0 +1,3 @@ +function main() -> bool { + console.assert(!1u32 == 0u32); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/output_register.leo b/tests/pass/parse/boolean/output_register.leo new file mode 100644 index 0000000000..fb01d41dbe --- /dev/null +++ b/tests/pass/parse/boolean/output_register.leo @@ -0,0 +1,3 @@ +function main(input) -> bool { + return input.registers.r +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/true_and_false.leo b/tests/pass/parse/boolean/true_and_false.leo new file mode 100644 index 0000000000..3c7c484603 --- /dev/null +++ b/tests/pass/parse/boolean/true_and_false.leo @@ -0,0 +1,5 @@ +function main() { + let a = true && false; + + console.assert(a == false); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/true_and_true.leo b/tests/pass/parse/boolean/true_and_true.leo new file mode 100644 index 0000000000..c378e50024 --- /dev/null +++ b/tests/pass/parse/boolean/true_and_true.leo @@ -0,0 +1,5 @@ +function main() { + let a = true && true; + + console.assert(a == true); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/true_and_u32.leo b/tests/pass/parse/boolean/true_and_u32.leo new file mode 100644 index 0000000000..e5b3a8c001 --- /dev/null +++ b/tests/pass/parse/boolean/true_and_u32.leo @@ -0,0 +1,3 @@ +function main() { + let a = true && 1u32; +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/true_or_false.leo b/tests/pass/parse/boolean/true_or_false.leo new file mode 100644 index 0000000000..d643a96aa1 --- /dev/null +++ b/tests/pass/parse/boolean/true_or_false.leo @@ -0,0 +1,5 @@ +function main() { + let a = true || false; + + console.assert(a == true); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/true_or_true.leo b/tests/pass/parse/boolean/true_or_true.leo new file mode 100644 index 0000000000..b8eaa91ff1 --- /dev/null +++ b/tests/pass/parse/boolean/true_or_true.leo @@ -0,0 +1,5 @@ +function main() { + let a = true || true; + + console.assert(a == true); +} \ No newline at end of file diff --git a/tests/pass/parse/boolean/true_or_u32.leo b/tests/pass/parse/boolean/true_or_u32.leo new file mode 100644 index 0000000000..500b5f7bf4 --- /dev/null +++ b/tests/pass/parse/boolean/true_or_u32.leo @@ -0,0 +1,3 @@ +function main() { + let a = true || 1u32; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/define_circuit_inside_circuit_function.leo b/tests/pass/parse/circuits/define_circuit_inside_circuit_function.leo new file mode 100644 index 0000000000..8c25c1e9d9 --- /dev/null +++ b/tests/pass/parse/circuits/define_circuit_inside_circuit_function.leo @@ -0,0 +1,13 @@ +circuit Foo { + a: u32, +} + +circuit Bar { + function bar() { + let f = Foo { a: 0u32 }; + } +} + +function main() { + let b = Bar::bar(); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/duplicate_name_context.leo b/tests/pass/parse/circuits/duplicate_name_context.leo new file mode 100644 index 0000000000..98ff42d8f0 --- /dev/null +++ b/tests/pass/parse/circuits/duplicate_name_context.leo @@ -0,0 +1,13 @@ +circuit Bar { + b2: u32 + + function add_five(z:u32) -> u32 { + return z+5u32 + } +} + +function main () { + let Bar = 66u32; + let k1 = Bar{ b2: 30u32 }; + let k2 = Bar::add_five(55u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/inline.leo b/tests/pass/parse/circuits/inline.leo new file mode 100644 index 0000000000..8e214c729a --- /dev/null +++ b/tests/pass/parse/circuits/inline.leo @@ -0,0 +1,7 @@ +circuit Foo { + x: u32 +} + +function main() { + let a = Foo { x: 1u32 }; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/inline_fail.leo b/tests/pass/parse/circuits/inline_fail.leo new file mode 100644 index 0000000000..52792a07e0 --- /dev/null +++ b/tests/pass/parse/circuits/inline_fail.leo @@ -0,0 +1,7 @@ +circuit Foo { + x: u32 +} + +function main() { + let a = Foo { y: 0u32 }; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/inline_member_fail.leo b/tests/pass/parse/circuits/inline_member_fail.leo new file mode 100644 index 0000000000..7f0b8f7889 --- /dev/null +++ b/tests/pass/parse/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/tests/pass/parse/circuits/inline_member_pass.leo b/tests/pass/parse/circuits/inline_member_pass.leo new file mode 100644 index 0000000000..5541a65638 --- /dev/null +++ b/tests/pass/parse/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/tests/pass/parse/circuits/inline_undefined.leo b/tests/pass/parse/circuits/inline_undefined.leo new file mode 100644 index 0000000000..af070e01e9 --- /dev/null +++ b/tests/pass/parse/circuits/inline_undefined.leo @@ -0,0 +1,3 @@ +function main() { + let a = Foo { }; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_function.leo b/tests/pass/parse/circuits/member_function.leo new file mode 100644 index 0000000000..e40603dffb --- /dev/null +++ b/tests/pass/parse/circuits/member_function.leo @@ -0,0 +1,13 @@ +circuit Foo { + x: u32, + + function echo(self) -> u32 { + return self.x + } +} + +function main() { + let a = Foo { x: 1u32 }; + + console.assert(a.echo() == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_function_fail.leo b/tests/pass/parse/circuits/member_function_fail.leo new file mode 100644 index 0000000000..224b79cbf4 --- /dev/null +++ b/tests/pass/parse/circuits/member_function_fail.leo @@ -0,0 +1,10 @@ +circuit Foo { + function echo(x: u32) -> u32 { + return x + } +} + +function main() { + let a = Foo { }; + let err = a.echoed(1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_function_invalid.leo b/tests/pass/parse/circuits/member_function_invalid.leo new file mode 100644 index 0000000000..bb834e9562 --- /dev/null +++ b/tests/pass/parse/circuits/member_function_invalid.leo @@ -0,0 +1,10 @@ +circuit Foo { + function echo(x: u32) -> u32 { + return x + } +} + +function main() { + let a = Foo { }; + let err = a.echo(1u32); // echo is a static function and must be accessed using `::` +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_function_nested.leo b/tests/pass/parse/circuits/member_function_nested.leo new file mode 100644 index 0000000000..9e07cc9acf --- /dev/null +++ b/tests/pass/parse/circuits/member_function_nested.leo @@ -0,0 +1,18 @@ +circuit Foo { + x: u32, + + function add_x(self, y: u32) -> u32 { + return self.x + y + } + + function call_add_x(self, y: u32) -> u32 { + return self.add_x(y) + } +} + +function main() { + let a = Foo { x: 1u32 }; + let b = a.add_x(1u32); + + console.assert(b == 2u32); +} diff --git a/tests/pass/parse/circuits/member_static_function.leo b/tests/pass/parse/circuits/member_static_function.leo new file mode 100644 index 0000000000..4bf51190f0 --- /dev/null +++ b/tests/pass/parse/circuits/member_static_function.leo @@ -0,0 +1,11 @@ +circuit Foo { + function echo(x: u32) -> u32 { + return x + } +} + +function main() { + let a = Foo::echo(1u32); + + console.assert(a == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_static_function_invalid.leo b/tests/pass/parse/circuits/member_static_function_invalid.leo new file mode 100644 index 0000000000..09fec386d9 --- /dev/null +++ b/tests/pass/parse/circuits/member_static_function_invalid.leo @@ -0,0 +1,9 @@ +circuit Foo { + function echo(x: u32) -> u32 { + return x + } +} + +function main() { + let err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::` +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_static_function_nested.leo b/tests/pass/parse/circuits/member_static_function_nested.leo new file mode 100644 index 0000000000..ef536e3f6e --- /dev/null +++ b/tests/pass/parse/circuits/member_static_function_nested.leo @@ -0,0 +1,15 @@ +circuit Foo { + function qux() {} + + function bar() { + Self::qux(); + } + + function baz() { + Self::bar(); + } +} + +function main() { + Foo::baz(); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_static_function_undefined.leo b/tests/pass/parse/circuits/member_static_function_undefined.leo new file mode 100644 index 0000000000..cf9f98c7b4 --- /dev/null +++ b/tests/pass/parse/circuits/member_static_function_undefined.leo @@ -0,0 +1,9 @@ +circuit Foo { + function echo(x: u32) -> u32 { + return x + } +} + +function main() { + let err = Foo::echoed(1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_variable.leo b/tests/pass/parse/circuits/member_variable.leo new file mode 100644 index 0000000000..0dd35f2aec --- /dev/null +++ b/tests/pass/parse/circuits/member_variable.leo @@ -0,0 +1,9 @@ +circuit Foo { + x: u32, +} + +function main() { + let a = Foo { x: 1u32 }; + + console.assert(a.x == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/member_variable_and_function.leo b/tests/pass/parse/circuits/member_variable_and_function.leo new file mode 100644 index 0000000000..074feab7b8 --- /dev/null +++ b/tests/pass/parse/circuits/member_variable_and_function.leo @@ -0,0 +1,15 @@ +circuit Foo { + foo: u32, + + function bar() -> u32 { + return 1u32 + } +} + +function main() { + let a = Foo { foo: 1 }; + + let b = a.foo + Foo::bar(); + + console.assert(b == 2u32); +} diff --git a/tests/pass/parse/circuits/member_variable_fail.leo b/tests/pass/parse/circuits/member_variable_fail.leo new file mode 100644 index 0000000000..5780704ea2 --- /dev/null +++ b/tests/pass/parse/circuits/member_variable_fail.leo @@ -0,0 +1,9 @@ +circuit Foo { + x: u32 +} + +function main() { + let a = Foo { x: 1u32 }; + + let err = a.y; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_function_fail.leo b/tests/pass/parse/circuits/mut_function_fail.leo new file mode 100644 index 0000000000..3469f97627 --- /dev/null +++ b/tests/pass/parse/circuits/mut_function_fail.leo @@ -0,0 +1,11 @@ +circuit Foo { + a: u8, + + function bar() {} +} + +function main() { + let mut f = Foo { a: 0u8 }; + + f.bar = 1u8; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_self_function_fail.leo b/tests/pass/parse/circuits/mut_self_function_fail.leo new file mode 100644 index 0000000000..8c9b99f6ae --- /dev/null +++ b/tests/pass/parse/circuits/mut_self_function_fail.leo @@ -0,0 +1,15 @@ +circuit Foo { + a: u8, + + function bar() {} + + function set_a(mut self, new: u8) { + self.bar = new; + } +} + +function main() { + let mut f = Foo { a: 0u8 }; + + f.set_a(1u8); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_self_static_function_fail.leo b/tests/pass/parse/circuits/mut_self_static_function_fail.leo new file mode 100644 index 0000000000..8c9b99f6ae --- /dev/null +++ b/tests/pass/parse/circuits/mut_self_static_function_fail.leo @@ -0,0 +1,15 @@ +circuit Foo { + a: u8, + + function bar() {} + + function set_a(mut self, new: u8) { + self.bar = new; + } +} + +function main() { + let mut f = Foo { a: 0u8 }; + + f.set_a(1u8); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_self_variable.leo b/tests/pass/parse/circuits/mut_self_variable.leo new file mode 100644 index 0000000000..f5a35ec754 --- /dev/null +++ b/tests/pass/parse/circuits/mut_self_variable.leo @@ -0,0 +1,22 @@ +circuit Foo { + a: u8, + + function set_a(mut self, new: u8) { + self.a = new; + console.assert(self.a == new); + } +} + +function main() { + let mut f = Foo { a: 0u8 }; + + console.assert(f.a == 0u8); + + f.set_a(1u8); + + console.assert(f.a == 1u8); + + f.set_a(2u8); + + console.assert(f.a == 2u8); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_self_variable_branch.leo b/tests/pass/parse/circuits/mut_self_variable_branch.leo new file mode 100644 index 0000000000..e47f9b85df --- /dev/null +++ b/tests/pass/parse/circuits/mut_self_variable_branch.leo @@ -0,0 +1,32 @@ +circuit Foo { + a: u8, + + function set_a(mut self, condition: bool, new: u8) { + if condition { + self.a = new; + console.assert(self.a == new); + } + } +} + +function main() { + let mut f = Foo { a: 0u8 }; + + console.assert(f.a == 0u8); + + f.set_a(false, 1u8); + + console.assert(f.a == 0u8); + + f.set_a(true, 1u8); + + console.assert(f.a == 1u8); + + f.set_a(false, 2u8); + + console.assert(f.a == 1u8); + + f.set_a(true, 2u8); + + console.assert(f.a == 2u8); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_self_variable_conditional.leo b/tests/pass/parse/circuits/mut_self_variable_conditional.leo new file mode 100644 index 0000000000..74345afcb4 --- /dev/null +++ b/tests/pass/parse/circuits/mut_self_variable_conditional.leo @@ -0,0 +1,15 @@ +function main() { + let mut f = Foo { a: 0u32 }; + + f.bar(); +} + +circuit Foo { + a: u32 + + function bar(mut self) { + if true { + self.a = 5u32; // Mutating a variable inside a conditional statement should work. + } + } +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_self_variable_fail.leo b/tests/pass/parse/circuits/mut_self_variable_fail.leo new file mode 100644 index 0000000000..fdbb556bca --- /dev/null +++ b/tests/pass/parse/circuits/mut_self_variable_fail.leo @@ -0,0 +1,13 @@ +circuit Foo { + a: u8, + + function set_a(self, new: u8) { + self.a = new; + } +} + +function main() { + let mut f = Foo { a: 0u8 }; + + f.set_a(1u8); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_static_function_fail.leo b/tests/pass/parse/circuits/mut_static_function_fail.leo new file mode 100644 index 0000000000..ed3092c656 --- /dev/null +++ b/tests/pass/parse/circuits/mut_static_function_fail.leo @@ -0,0 +1,9 @@ +circuit Foo { + function bar() {} +} + +function main() { + let mut f = Foo { a: 0u8 }; + + f.bar = 1u8; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_variable.leo b/tests/pass/parse/circuits/mut_variable.leo new file mode 100644 index 0000000000..243d7a2cf2 --- /dev/null +++ b/tests/pass/parse/circuits/mut_variable.leo @@ -0,0 +1,17 @@ +circuit Foo { + a: u8, +} + +function main() { + let mut f = Foo { a: 0u8 }; + + console.assert(f.a == 0u8); + + f.a = 1u8; + + console.assert(f.a == 1u8); + + f.a = 2u8; + + console.assert(f.a == 2u8); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/mut_variable_fail.leo b/tests/pass/parse/circuits/mut_variable_fail.leo new file mode 100644 index 0000000000..4d58150c95 --- /dev/null +++ b/tests/pass/parse/circuits/mut_variable_fail.leo @@ -0,0 +1,9 @@ +circuit Foo { + a: u8, +} + +function main() { + let f = Foo { a: 0u8 }; + + f.a = 1u8; +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/pedersen_mock.leo b/tests/pass/parse/circuits/pedersen_mock.leo new file mode 100644 index 0000000000..0b42c64a6e --- /dev/null +++ b/tests/pass/parse/circuits/pedersen_mock.leo @@ -0,0 +1,27 @@ +circuit PedersenHash { + parameters: [u32; 512] + + function new(parameters: [u32; 512]) -> Self { + return Self { parameters: parameters } + } + + function hash(self, bits: [bool; 512]) -> u32 { + let mut digest: u32 = 0; + for i in 0..512 { + let base = if bits[i] ? self.parameters[i] : 0u32; + digest += base; + } + return digest + } +} + +// The 'pedersen_hash' main function. +function main() { + let parameters = [0u32; 512]; + let pedersen = PedersenHash::new(parameters); + let hash_input: [bool; 512] = [true; 512]; + + let res = pedersen.hash(hash_input); + + console.assert(res == 0u32); +} diff --git a/tests/pass/parse/circuits/self_fail.leo b/tests/pass/parse/circuits/self_fail.leo new file mode 100644 index 0000000000..e4e878dc89 --- /dev/null +++ b/tests/pass/parse/circuits/self_fail.leo @@ -0,0 +1,3 @@ +function main() { + Self::main(); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/self_member.leo b/tests/pass/parse/circuits/self_member.leo new file mode 100644 index 0000000000..1bd978433d --- /dev/null +++ b/tests/pass/parse/circuits/self_member.leo @@ -0,0 +1,14 @@ +circuit Foo { + f: u32, + + function bar(self) -> u32 { + return self.f + } +} + +function main() { + let a = Foo { f: 1u32 }; + let b = a.bar(); + + console.assert(b == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/self_member_invalid.leo b/tests/pass/parse/circuits/self_member_invalid.leo new file mode 100644 index 0000000000..2e8b14f66c --- /dev/null +++ b/tests/pass/parse/circuits/self_member_invalid.leo @@ -0,0 +1,12 @@ +circuit Foo { + f: u32, + + function bar() -> u32 { + return f + } +} + +function main() -> u32 { + let foo = Foo { f: 1u32 }; + let err = foo.bar(); +} \ No newline at end of file diff --git a/tests/pass/parse/circuits/self_member_undefined.leo b/tests/pass/parse/circuits/self_member_undefined.leo new file mode 100644 index 0000000000..471ffb973c --- /dev/null +++ b/tests/pass/parse/circuits/self_member_undefined.leo @@ -0,0 +1,10 @@ +circuit Foo { + function bar() -> u32 { + return self.f + } +} + +function main() { + let foo = Foo { }; + let err = foo.bar(); +} \ No newline at end of file diff --git a/tests/pass/parse/compiler/main.leo b/tests/pass/parse/compiler/main.leo new file mode 100644 index 0000000000..f5ddfb4e7f --- /dev/null +++ b/tests/pass/parse/compiler/main.leo @@ -0,0 +1,3 @@ +function main() { + let a: u32 = 1 + 2; +} \ No newline at end of file diff --git a/tests/pass/parse/console/assert.leo b/tests/pass/parse/console/assert.leo new file mode 100644 index 0000000000..ba6be77256 --- /dev/null +++ b/tests/pass/parse/console/assert.leo @@ -0,0 +1,3 @@ +function main(a: bool) { + console.assert(a == true); +} \ No newline at end of file diff --git a/tests/pass/parse/console/conditional_assert.leo b/tests/pass/parse/console/conditional_assert.leo new file mode 100644 index 0000000000..f2c1591e9c --- /dev/null +++ b/tests/pass/parse/console/conditional_assert.leo @@ -0,0 +1,7 @@ +function main(a: bool) { + if a { + console.assert(a == true); + } else { + console.assert(a == false); + } +} \ No newline at end of file diff --git a/tests/pass/parse/console/debug.leo b/tests/pass/parse/console/debug.leo new file mode 100644 index 0000000000..54e6eb539f --- /dev/null +++ b/tests/pass/parse/console/debug.leo @@ -0,0 +1,3 @@ +function main() { + console.debug("hello debug"); +} \ No newline at end of file diff --git a/tests/pass/parse/console/error.leo b/tests/pass/parse/console/error.leo new file mode 100644 index 0000000000..86d13f8cee --- /dev/null +++ b/tests/pass/parse/console/error.leo @@ -0,0 +1,3 @@ +function main() { + console.error("hello error"); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log.leo b/tests/pass/parse/console/log.leo new file mode 100644 index 0000000000..a190ca4ba9 --- /dev/null +++ b/tests/pass/parse/console/log.leo @@ -0,0 +1,3 @@ +function main() { + console.log("hello world"); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_conditional.leo b/tests/pass/parse/console/log_conditional.leo new file mode 100644 index 0000000000..a9fdb6e698 --- /dev/null +++ b/tests/pass/parse/console/log_conditional.leo @@ -0,0 +1,6 @@ +// Conditionally add two u32 integers and log the result to the console. +function main(a: u32, b: u32) { + if a == b { + console.log("{}=={}",a,b); // This line should not fail. + } +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_input.leo b/tests/pass/parse/console/log_input.leo new file mode 100644 index 0000000000..c4fd0a8b12 --- /dev/null +++ b/tests/pass/parse/console/log_input.leo @@ -0,0 +1,3 @@ +function main(a: bool) { + console.log("a = {}", a); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_parameter.leo b/tests/pass/parse/console/log_parameter.leo new file mode 100644 index 0000000000..ebcb931a2b --- /dev/null +++ b/tests/pass/parse/console/log_parameter.leo @@ -0,0 +1,3 @@ +function main() { + console.log("{}", 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_parameter_fail_empty.leo b/tests/pass/parse/console/log_parameter_fail_empty.leo new file mode 100644 index 0000000000..81b42c0919 --- /dev/null +++ b/tests/pass/parse/console/log_parameter_fail_empty.leo @@ -0,0 +1,3 @@ +function main() { + console.log("{}"); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_parameter_fail_none.leo b/tests/pass/parse/console/log_parameter_fail_none.leo new file mode 100644 index 0000000000..c92fdfbb2d --- /dev/null +++ b/tests/pass/parse/console/log_parameter_fail_none.leo @@ -0,0 +1,3 @@ +function main() { + console.log("", 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_parameter_fail_unknown.leo b/tests/pass/parse/console/log_parameter_fail_unknown.leo new file mode 100644 index 0000000000..757f4c27c3 --- /dev/null +++ b/tests/pass/parse/console/log_parameter_fail_unknown.leo @@ -0,0 +1,3 @@ +function main() { + console.log("{}", a); +} \ No newline at end of file diff --git a/tests/pass/parse/console/log_parameter_many.leo b/tests/pass/parse/console/log_parameter_many.leo new file mode 100644 index 0000000000..60455ebbb0 --- /dev/null +++ b/tests/pass/parse/console/log_parameter_many.leo @@ -0,0 +1,3 @@ +function main() { + console.log("{} {}", 1u32, true); +} \ No newline at end of file diff --git a/tests/pass/parse/core/arguments_length_fail.leo b/tests/pass/parse/core/arguments_length_fail.leo new file mode 100644 index 0000000000..ccdd4c5af9 --- /dev/null +++ b/tests/pass/parse/core/arguments_length_fail.leo @@ -0,0 +1,9 @@ +import core.unstable.blake2s.Blake2s; + +function main() { + let seed: [u8; 32] = [0; 32]; + + let result = Blake2s::hash(seed); // function `hash` takes 2 arguments + + console.log("Result: {}", result); +} diff --git a/tests/pass/parse/core/arguments_type_fail.leo b/tests/pass/parse/core/arguments_type_fail.leo new file mode 100644 index 0000000000..13c7e9735e --- /dev/null +++ b/tests/pass/parse/core/arguments_type_fail.leo @@ -0,0 +1,10 @@ +import core.unstable.blake2s.Blake2s; + +function main() { + let seed: [u8; 32] = [0; 32]; + let message: [u16; 32] = [0; 32]; // message should be type [u8; 32] + + let result = Blake2s::hash(seed, message); + + console.log("Result: {}", result); +} diff --git a/tests/pass/parse/core/blake2s_input.leo b/tests/pass/parse/core/blake2s_input.leo new file mode 100644 index 0000000000..6044795c3d --- /dev/null +++ b/tests/pass/parse/core/blake2s_input.leo @@ -0,0 +1,5 @@ +import core.unstable.blake2s.Blake2s; + +function main(seed: [u8; 32], message: [u8; 32]) -> [u8; 32] { + return Blake2s::hash(seed, message) +} diff --git a/tests/pass/parse/core/blake2s_random.leo b/tests/pass/parse/core/blake2s_random.leo new file mode 100644 index 0000000000..72aef44932 --- /dev/null +++ b/tests/pass/parse/core/blake2s_random.leo @@ -0,0 +1,7 @@ +import core.unstable.blake2s.Blake2s; + +function main(seed: [u8; 32], message: [u8; 32], expected: [u8; 32]) { + let actual = Blake2s::hash(seed, message); + + console.assert(expected == actual); +} diff --git a/tests/pass/parse/core/core_circuit_invalid.leo b/tests/pass/parse/core/core_circuit_invalid.leo new file mode 100644 index 0000000000..4a42bda032 --- /dev/null +++ b/tests/pass/parse/core/core_circuit_invalid.leo @@ -0,0 +1,3 @@ +import core.unstable.blake2s.BadCircuit; // `BadCircuit` is not included in the blake2s package + +function main() {} diff --git a/tests/pass/parse/core/core_circuit_star_fail.leo b/tests/pass/parse/core/core_circuit_star_fail.leo new file mode 100644 index 0000000000..14b54b0d69 --- /dev/null +++ b/tests/pass/parse/core/core_circuit_star_fail.leo @@ -0,0 +1,3 @@ +import core.*; // You cannot import all dependencies from core at once + +function main() {} diff --git a/tests/pass/parse/core/core_package_invalid.leo b/tests/pass/parse/core/core_package_invalid.leo new file mode 100644 index 0000000000..7cbcf93ecc --- /dev/null +++ b/tests/pass/parse/core/core_package_invalid.leo @@ -0,0 +1,3 @@ +import core.bad_circuit; // `bad_circuit` is not a core package + +function main() {} diff --git a/tests/pass/parse/core/core_unstable_package_invalid.leo b/tests/pass/parse/core/core_unstable_package_invalid.leo new file mode 100644 index 0000000000..35e6c0d1ba --- /dev/null +++ b/tests/pass/parse/core/core_unstable_package_invalid.leo @@ -0,0 +1,3 @@ +import core.unstable.bad_circuit; // `bad_circuit` is not a core unstable package + +function main() {} diff --git a/tests/pass/parse/core/unstable_blake2s.leo b/tests/pass/parse/core/unstable_blake2s.leo new file mode 100644 index 0000000000..ca7db13892 --- /dev/null +++ b/tests/pass/parse/core/unstable_blake2s.leo @@ -0,0 +1,10 @@ +import core.unstable.blake2s.Blake2s; + +function main() { + let seed: [u8; 32] = [0; 32]; + let message: [u8; 32] = [0; 32]; + + let result = Blake2s::hash(seed, message); + + console.log("Result: {}", result); +} diff --git a/tests/pass/parse/definition/out_of_order.leo b/tests/pass/parse/definition/out_of_order.leo new file mode 100644 index 0000000000..69d46d0e74 --- /dev/null +++ b/tests/pass/parse/definition/out_of_order.leo @@ -0,0 +1,6 @@ +@test +function fake_test() {} + +function main() {} + +circuit Foo {} \ No newline at end of file diff --git a/tests/pass/parse/definition/out_of_order_with_import.leo b/tests/pass/parse/definition/out_of_order_with_import.leo new file mode 100644 index 0000000000..daf92fdecb --- /dev/null +++ b/tests/pass/parse/definition/out_of_order_with_import.leo @@ -0,0 +1,7 @@ +@test function fake_test() {} + +function main() {} + +import test_import.foo; + +circuit Foo {} \ No newline at end of file diff --git a/tests/pass/parse/field/add.leo b/tests/pass/parse/field/add.leo new file mode 100644 index 0000000000..8dc2c7df4e --- /dev/null +++ b/tests/pass/parse/field/add.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field, c: field) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/field/console_assert.leo b/tests/pass/parse/field/console_assert.leo new file mode 100644 index 0000000000..c7224bcea5 --- /dev/null +++ b/tests/pass/parse/field/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/field/div.leo b/tests/pass/parse/field/div.leo new file mode 100644 index 0000000000..028b06fad2 --- /dev/null +++ b/tests/pass/parse/field/div.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field, c: field) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/field/eq.leo b/tests/pass/parse/field/eq.leo new file mode 100644 index 0000000000..e64307d8de --- /dev/null +++ b/tests/pass/parse/field/eq.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/field/field.leo b/tests/pass/parse/field/field.leo new file mode 100644 index 0000000000..3f109881ad --- /dev/null +++ b/tests/pass/parse/field/field.leo @@ -0,0 +1,4 @@ +function main() { + let negOneField: field = -1field; + let oneField = 1field; +} \ No newline at end of file diff --git a/tests/pass/parse/field/mul.leo b/tests/pass/parse/field/mul.leo new file mode 100644 index 0000000000..7df7c83830 --- /dev/null +++ b/tests/pass/parse/field/mul.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field, c: field) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/field/negate.leo b/tests/pass/parse/field/negate.leo new file mode 100644 index 0000000000..94c730207a --- /dev/null +++ b/tests/pass/parse/field/negate.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/field/sub.leo b/tests/pass/parse/field/sub.leo new file mode 100644 index 0000000000..2c84b24647 --- /dev/null +++ b/tests/pass/parse/field/sub.leo @@ -0,0 +1,3 @@ +function main(a: field, b: field, c: field) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/field/ternary.leo b/tests/pass/parse/field/ternary.leo new file mode 100644 index 0000000000..49cd6a4e62 --- /dev/null +++ b/tests/pass/parse/field/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: field, b: field, c: field) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/function/array_input.leo b/tests/pass/parse/function/array_input.leo new file mode 100644 index 0000000000..a70483cae7 --- /dev/null +++ b/tests/pass/parse/function/array_input.leo @@ -0,0 +1,6 @@ +function foo(a: [u8; 1]) {} + +function main() { + let a: [u16; 1] = [1; 1]; + foo(a); +} \ No newline at end of file diff --git a/tests/pass/parse/function/array_params_direct_call.leo b/tests/pass/parse/function/array_params_direct_call.leo new file mode 100644 index 0000000000..9305b0958d --- /dev/null +++ b/tests/pass/parse/function/array_params_direct_call.leo @@ -0,0 +1,9 @@ +function do_nothing(arr: [u32; 2]) {} + +function main() { + let arr: [u32; 2] = [0; 2]; + + do_nothing(arr); + do_nothing([...arr]); + do_nothing(arr[1u32..]); +} \ No newline at end of file diff --git a/tests/pass/parse/function/conditional_return.leo b/tests/pass/parse/function/conditional_return.leo new file mode 100644 index 0000000000..7ecd0e625c --- /dev/null +++ b/tests/pass/parse/function/conditional_return.leo @@ -0,0 +1,7 @@ +function main(x: u8) -> u8 { + if x == 2u8 { + return 3u8 + } else { + return 4u8 + } +} \ No newline at end of file diff --git a/tests/pass/parse/function/empty.leo b/tests/pass/parse/function/empty.leo new file mode 100644 index 0000000000..f06c976158 --- /dev/null +++ b/tests/pass/parse/function/empty.leo @@ -0,0 +1,5 @@ +function empty() { } + +function main() { + empty(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/iteration.leo b/tests/pass/parse/function/iteration.leo new file mode 100644 index 0000000000..19af4dd9cf --- /dev/null +++ b/tests/pass/parse/function/iteration.leo @@ -0,0 +1,13 @@ +function one() -> u32 { + return 1u32 +} + +function main() { + let mut a = 0u32; + + for i in 0..10 { + a += one(); + } + + console.assert(a == 10u32); +} \ No newline at end of file diff --git a/tests/pass/parse/function/iteration_repeated.leo b/tests/pass/parse/function/iteration_repeated.leo new file mode 100644 index 0000000000..3694b3594a --- /dev/null +++ b/tests/pass/parse/function/iteration_repeated.leo @@ -0,0 +1,15 @@ +function iteration() -> u32 { + let mut a = 0u32; + + for i in 0..10 { + a += 1; + } + + return a +} + +function main() { + let total = iteration() + iteration(); + + console.assert(total == 20); +} \ No newline at end of file diff --git a/tests/pass/parse/function/multiple_returns.leo b/tests/pass/parse/function/multiple_returns.leo new file mode 100644 index 0000000000..ef00a4ef47 --- /dev/null +++ b/tests/pass/parse/function/multiple_returns.leo @@ -0,0 +1,10 @@ +function tuple() -> (bool, bool) { + return (true, false) +} + +function main() { + let (a, b) = tuple(); + + console.assert(a == true); + console.assert(b == false); +} \ No newline at end of file diff --git a/tests/pass/parse/function/multiple_returns_fail.leo b/tests/pass/parse/function/multiple_returns_fail.leo new file mode 100644 index 0000000000..d4a8b36eac --- /dev/null +++ b/tests/pass/parse/function/multiple_returns_fail.leo @@ -0,0 +1,7 @@ +function main () -> i8 { + if true { + return 1i8 //ignored + } + return 2i8 //ignored + return 3i8 //returns +} \ No newline at end of file diff --git a/tests/pass/parse/function/multiple_returns_fail_conditional.leo b/tests/pass/parse/function/multiple_returns_fail_conditional.leo new file mode 100644 index 0000000000..04ebb9e306 --- /dev/null +++ b/tests/pass/parse/function/multiple_returns_fail_conditional.leo @@ -0,0 +1,9 @@ +function main () -> u16 { + if false { + let a = 1u16; + let b = a + 1u16; + return b + } else if false { + return 0u16 + } +} \ No newline at end of file diff --git a/tests/pass/parse/function/multiple_returns_main.leo b/tests/pass/parse/function/multiple_returns_main.leo new file mode 100644 index 0000000000..0bc82e1e4b --- /dev/null +++ b/tests/pass/parse/function/multiple_returns_main.leo @@ -0,0 +1,3 @@ +function main(input) -> (bool, bool) { + return (input.registers.a, input.registers.b) +} \ No newline at end of file diff --git a/tests/pass/parse/function/newlines.leo b/tests/pass/parse/function/newlines.leo new file mode 100644 index 0000000000..8c703f81d3 --- /dev/null +++ b/tests/pass/parse/function/newlines.leo @@ -0,0 +1,9 @@ +function main( + a: u32, + b: u32, +) -> ( + u32, + u32, +) { + return (a, b) +} \ No newline at end of file diff --git a/tests/pass/parse/function/repeated.leo b/tests/pass/parse/function/repeated.leo new file mode 100644 index 0000000000..a2d04d55f9 --- /dev/null +++ b/tests/pass/parse/function/repeated.leo @@ -0,0 +1,9 @@ +function one() -> bool { + return true +} + +function main() { + let a = one() && one(); + + console.assert(a == true); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return.leo b/tests/pass/parse/function/return.leo new file mode 100644 index 0000000000..10c7138977 --- /dev/null +++ b/tests/pass/parse/function/return.leo @@ -0,0 +1,7 @@ +function one() -> u32 { + return 1u32 +} + +function main() { + console.assert(one() == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return_array_nested_fail.leo b/tests/pass/parse/function/return_array_nested_fail.leo new file mode 100644 index 0000000000..dca001d9cc --- /dev/null +++ b/tests/pass/parse/function/return_array_nested_fail.leo @@ -0,0 +1,7 @@ +function array_3x2_tuple() -> [[u8; 2]; 3] { + return [0u8; (2, 3)] // The correct 3x2 array tuple is `[0u8; (3, 2)]` +} + +function main() { + let b = array_3x2_tuple(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return_array_nested_pass.leo b/tests/pass/parse/function/return_array_nested_pass.leo new file mode 100644 index 0000000000..dda5b4342b --- /dev/null +++ b/tests/pass/parse/function/return_array_nested_pass.leo @@ -0,0 +1,12 @@ +function array_3x2_nested() -> [[u8; 2]; 3] { + return [[0u8; 2]; 3] +} + +function array_3x2_tuple() -> [[u8; 2]; 3] { + return [0u8; (3, 2)] +} + +function main() { + let a = array_3x2_nested(); + let b = array_3x2_tuple(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return_array_tuple_fail.leo b/tests/pass/parse/function/return_array_tuple_fail.leo new file mode 100644 index 0000000000..4b7377e327 --- /dev/null +++ b/tests/pass/parse/function/return_array_tuple_fail.leo @@ -0,0 +1,7 @@ +function array_3x2_nested() -> [u8; (3, 2)] { + return [[0u8; 3]; 2] // The correct 3x2 nested array is `[0u8; 2]; 3]` +} + +function main() { + let a = array_3x2_nested(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return_array_tuple_pass.leo b/tests/pass/parse/function/return_array_tuple_pass.leo new file mode 100644 index 0000000000..a700bcabad --- /dev/null +++ b/tests/pass/parse/function/return_array_tuple_pass.leo @@ -0,0 +1,12 @@ +function array_3x2_nested() -> [u8; (3, 2)] { + return [[0u8; 2]; 3] +} + +function array_3x2_tuple() -> [u8; (3, 2)] { + return [0u8; (3, 2)] +} + +function main() { + let a = array_3x2_nested(); + let b = array_3x2_tuple(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return_tuple.leo b/tests/pass/parse/function/return_tuple.leo new file mode 100644 index 0000000000..c459740a47 --- /dev/null +++ b/tests/pass/parse/function/return_tuple.leo @@ -0,0 +1,11 @@ +// Returns a tuple of tuples. +function tuples() -> ((u8, u8), u32) { + let a: (u8, u8) = (1, 2); + let b: u32 = 3; + + return (a, b) +} + +function main() { + let t = tuples(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/return_tuple_conditional.leo b/tests/pass/parse/function/return_tuple_conditional.leo new file mode 100644 index 0000000000..c63967f548 --- /dev/null +++ b/tests/pass/parse/function/return_tuple_conditional.leo @@ -0,0 +1,15 @@ +// Returns a tuple using a conditional "if" statement. +function tuple_conditional () -> ( + i64, + i64 +) { + if true { + return (1, 1) + } else { + return (2, 2) + } +} + +function main() { + let t = tuple_conditional(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/scope_fail.leo b/tests/pass/parse/function/scope_fail.leo new file mode 100644 index 0000000000..773c2479d7 --- /dev/null +++ b/tests/pass/parse/function/scope_fail.leo @@ -0,0 +1,8 @@ +function foo() -> field { + return myGlobal +} + +function main() { + let myGlobal = 42field; + let err = foo(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/undefined.leo b/tests/pass/parse/function/undefined.leo new file mode 100644 index 0000000000..e1db3b9f09 --- /dev/null +++ b/tests/pass/parse/function/undefined.leo @@ -0,0 +1,3 @@ +function main() { + my_function(); +} \ No newline at end of file diff --git a/tests/pass/parse/function/value_unchanged.leo b/tests/pass/parse/function/value_unchanged.leo new file mode 100644 index 0000000000..32dcfa62d6 --- /dev/null +++ b/tests/pass/parse/function/value_unchanged.leo @@ -0,0 +1,19 @@ +// Functions input in leo are pass-by-value. +// +// Program execution: +// line 15: variable `a` is defined with value `1`. +// line 16: value `1` is copied and passed into function `bad_mutate()`. +// line 10: variable `x` is defined with value `1`. +// line 11: variable `x` is set to value `0`. +// line 18: program returns the value of `a`. + +function bad_mutate(mut x: u32) { + x = 0; // <- does not change `a` +} + +function main() { + let a = 1u32; + bad_mutate(a); + + console.assert(a == 1u32); // <- value `a` is still `1u32` +} \ No newline at end of file diff --git a/tests/pass/parse/group/add.leo b/tests/pass/parse/group/add.leo new file mode 100644 index 0000000000..bb84df2d6c --- /dev/null +++ b/tests/pass/parse/group/add.leo @@ -0,0 +1,3 @@ +function main(a: group, b: group, c: group) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/group/assert_eq.leo b/tests/pass/parse/group/assert_eq.leo new file mode 100644 index 0000000000..3886a07bbf --- /dev/null +++ b/tests/pass/parse/group/assert_eq.leo @@ -0,0 +1,3 @@ +function main(a: group, b: group) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/group/both_sign_high.leo b/tests/pass/parse/group/both_sign_high.leo new file mode 100644 index 0000000000..a8217d6d40 --- /dev/null +++ b/tests/pass/parse/group/both_sign_high.leo @@ -0,0 +1,3 @@ +function main() { + let element = (+, +)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/both_sign_inferred.leo b/tests/pass/parse/group/both_sign_inferred.leo new file mode 100644 index 0000000000..b3b8b512c3 --- /dev/null +++ b/tests/pass/parse/group/both_sign_inferred.leo @@ -0,0 +1,3 @@ +function main() { + let element = (_, _)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/both_sign_low.leo b/tests/pass/parse/group/both_sign_low.leo new file mode 100644 index 0000000000..0519c6d17d --- /dev/null +++ b/tests/pass/parse/group/both_sign_low.leo @@ -0,0 +1,3 @@ +function main() { + let element = (-, -)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/eq.leo b/tests/pass/parse/group/eq.leo new file mode 100644 index 0000000000..89701d9c99 --- /dev/null +++ b/tests/pass/parse/group/eq.leo @@ -0,0 +1,3 @@ +function main(a: group, b: group, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/group/input.leo b/tests/pass/parse/group/input.leo new file mode 100644 index 0000000000..3886a07bbf --- /dev/null +++ b/tests/pass/parse/group/input.leo @@ -0,0 +1,3 @@ +function main(a: group, b: group) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/group/negate.leo b/tests/pass/parse/group/negate.leo new file mode 100644 index 0000000000..506d8d73ce --- /dev/null +++ b/tests/pass/parse/group/negate.leo @@ -0,0 +1,3 @@ +function main(a: group, b: group) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/group/one.leo b/tests/pass/parse/group/one.leo new file mode 100644 index 0000000000..7be0cbbc2c --- /dev/null +++ b/tests/pass/parse/group/one.leo @@ -0,0 +1,3 @@ +function main() { + let element = 1group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/point.leo b/tests/pass/parse/group/point.leo new file mode 100644 index 0000000000..85eeb53b7b --- /dev/null +++ b/tests/pass/parse/group/point.leo @@ -0,0 +1,3 @@ +function main() { + let point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/point_input.leo b/tests/pass/parse/group/point_input.leo new file mode 100644 index 0000000000..68d8c458a3 --- /dev/null +++ b/tests/pass/parse/group/point_input.leo @@ -0,0 +1,3 @@ +function main(a: group) { + let b = a; +} \ No newline at end of file diff --git a/tests/pass/parse/group/positive_and_negative.leo b/tests/pass/parse/group/positive_and_negative.leo new file mode 100644 index 0000000000..fdf9b892be --- /dev/null +++ b/tests/pass/parse/group/positive_and_negative.leo @@ -0,0 +1,10 @@ +function main() { + let pos_element = 1group; + let neg_element = -1group; + + let pair_x_pos = (1, _)group; + let pair_x_neg = (-1, _)group; + + let pair_y_pos = (_, 1)group; + let pair_y_neg = (_, -1)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/sub.leo b/tests/pass/parse/group/sub.leo new file mode 100644 index 0000000000..dfe82d8e31 --- /dev/null +++ b/tests/pass/parse/group/sub.leo @@ -0,0 +1,3 @@ +function main(a: group, b: group, c: group) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/group/ternary.leo b/tests/pass/parse/group/ternary.leo new file mode 100644 index 0000000000..b213bb1419 --- /dev/null +++ b/tests/pass/parse/group/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: group, b: group, c: group) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/group/x_and_y.leo b/tests/pass/parse/group/x_and_y.leo new file mode 100644 index 0000000000..1b64702db1 --- /dev/null +++ b/tests/pass/parse/group/x_and_y.leo @@ -0,0 +1,3 @@ +function main(element: group) { + let b = element; +} \ No newline at end of file diff --git a/tests/pass/parse/group/x_sign_high.leo b/tests/pass/parse/group/x_sign_high.leo new file mode 100644 index 0000000000..1b8d397d02 --- /dev/null +++ b/tests/pass/parse/group/x_sign_high.leo @@ -0,0 +1,3 @@ +function main() { + let element = (0, +)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/x_sign_inferred.leo b/tests/pass/parse/group/x_sign_inferred.leo new file mode 100644 index 0000000000..9e9622a4a4 --- /dev/null +++ b/tests/pass/parse/group/x_sign_inferred.leo @@ -0,0 +1,3 @@ +function main() { + let element = (0, _)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/x_sign_low.leo b/tests/pass/parse/group/x_sign_low.leo new file mode 100644 index 0000000000..a5058bda52 --- /dev/null +++ b/tests/pass/parse/group/x_sign_low.leo @@ -0,0 +1,3 @@ +function main() { + let element = (0, -)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/y_sign_high.leo b/tests/pass/parse/group/y_sign_high.leo new file mode 100644 index 0000000000..fe16883b39 --- /dev/null +++ b/tests/pass/parse/group/y_sign_high.leo @@ -0,0 +1,3 @@ +function main() { + let element = (+, 1)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/y_sign_inferred.leo b/tests/pass/parse/group/y_sign_inferred.leo new file mode 100644 index 0000000000..003c373cf2 --- /dev/null +++ b/tests/pass/parse/group/y_sign_inferred.leo @@ -0,0 +1,3 @@ +function main() { + let element = (_, 1)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/y_sign_low.leo b/tests/pass/parse/group/y_sign_low.leo new file mode 100644 index 0000000000..9e61bfd2bb --- /dev/null +++ b/tests/pass/parse/group/y_sign_low.leo @@ -0,0 +1,3 @@ +function main() { + let element = (-, 1)group; +} \ No newline at end of file diff --git a/tests/pass/parse/group/zero.leo b/tests/pass/parse/group/zero.leo new file mode 100644 index 0000000000..e2c0283c21 --- /dev/null +++ b/tests/pass/parse/group/zero.leo @@ -0,0 +1,3 @@ +function main() { + let element = 0group; +} \ No newline at end of file diff --git a/tests/pass/parse/import/a-9.leo b/tests/pass/parse/import/a-9.leo new file mode 100644 index 0000000000..8cd9f87f14 --- /dev/null +++ b/tests/pass/parse/import/a-9.leo @@ -0,0 +1 @@ +function bar() {} \ No newline at end of file diff --git a/tests/pass/parse/import/a0-f.leo b/tests/pass/parse/import/a0-f.leo new file mode 100644 index 0000000000..c99ad3b713 --- /dev/null +++ b/tests/pass/parse/import/a0-f.leo @@ -0,0 +1 @@ +function foo() {} \ No newline at end of file diff --git a/tests/pass/parse/import/alias.leo b/tests/pass/parse/import/alias.leo new file mode 100644 index 0000000000..f153b5a128 --- /dev/null +++ b/tests/pass/parse/import/alias.leo @@ -0,0 +1,5 @@ +import test-import.foo as bar; + +function main() { + console.assert(bar() == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/import/basic.leo b/tests/pass/parse/import/basic.leo new file mode 100644 index 0000000000..53d243efaa --- /dev/null +++ b/tests/pass/parse/import/basic.leo @@ -0,0 +1,5 @@ +import test-import.foo; + +function main() { + console.assert(foo() == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/import/bat.leo b/tests/pass/parse/import/bat.leo new file mode 100755 index 0000000000..a7d2fc83d4 --- /dev/null +++ b/tests/pass/parse/import/bat.leo @@ -0,0 +1,3 @@ +circuit Bat { + t: u32 +} \ No newline at end of file diff --git a/tests/pass/parse/import/baz.leo b/tests/pass/parse/import/baz.leo new file mode 100755 index 0000000000..1bb268a84c --- /dev/null +++ b/tests/pass/parse/import/baz.leo @@ -0,0 +1,7 @@ +circuit Baz { + z: u32 +} + +circuit Bazzar { + a: u32 +} \ No newline at end of file diff --git a/tests/pass/parse/import/hello-world.leo b/tests/pass/parse/import/hello-world.leo new file mode 100644 index 0000000000..2d96e74c4c --- /dev/null +++ b/tests/pass/parse/import/hello-world.leo @@ -0,0 +1 @@ +function hello() {} \ No newline at end of file diff --git a/tests/pass/parse/import/lib.leo b/tests/pass/parse/import/lib.leo new file mode 100755 index 0000000000..c169f5935e --- /dev/null +++ b/tests/pass/parse/import/lib.leo @@ -0,0 +1,3 @@ +circuit Bar { + r: u32 +} \ No newline at end of file diff --git a/tests/pass/parse/import/many_import.leo b/tests/pass/parse/import/many_import.leo new file mode 100644 index 0000000000..5e85f19778 --- /dev/null +++ b/tests/pass/parse/import/many_import.leo @@ -0,0 +1,26 @@ +import test-import.( // local import + Point, + foo, +); + +import bar.( // imports directory import + Bar, + baz.(Baz, Bazzar), + bat.bat.Bat, +); + +import car.Car; // imports directory import + +function main() { + let point = Point { x: 1u32, y: 1u32 }; + let foo = foo(); + + let bar = Bar { r: 1u32 }; + let baz = Baz { z: 1u32 }; + let bazzar = Bazzar { a: 1u32 }; + let bat = Bat { t: 1u32 }; + + let car = Car { c: 1u32 }; + + console.assert(car.c == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/import/many_import_star.leo b/tests/pass/parse/import/many_import_star.leo new file mode 100644 index 0000000000..5145d0d05d --- /dev/null +++ b/tests/pass/parse/import/many_import_star.leo @@ -0,0 +1,19 @@ +import test-import.*; // local import + +import bar.*; // imports directory import +import bar.baz.*; // imports directory import +import bar.bat.bat.*; // imports directory import +import car.*; // imports directory import + +function main() { + let point = Point { x: 1u32, y: 1u32 }; + let foo = foo(); + + let bar = Bar { r: 1u32 }; + let bat = Bat { t: 1u32 }; + let baz = Baz { z: 1u32 }; + + let car = Car { c: 1u32 }; + + console.assert(car.c == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/import/multiple.leo b/tests/pass/parse/import/multiple.leo new file mode 100644 index 0000000000..5c89aaee0c --- /dev/null +++ b/tests/pass/parse/import/multiple.leo @@ -0,0 +1,10 @@ +import test-import.( + Point, + foo +); + +function main() { + let a = Point { x: 1u32, y: 0u32 }; + + console.assert(a.x == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/import/names.leo b/tests/pass/parse/import/names.leo new file mode 100644 index 0000000000..d3ce50829a --- /dev/null +++ b/tests/pass/parse/import/names.leo @@ -0,0 +1,5 @@ +import a0-f.foo; +import a-9.bar; +import hello-world.hello; + +function main() {} \ No newline at end of file diff --git a/tests/pass/parse/import/names_underscore.leo b/tests/pass/parse/import/names_underscore.leo new file mode 100644 index 0000000000..c5822ebadd --- /dev/null +++ b/tests/pass/parse/import/names_underscore.leo @@ -0,0 +1,3 @@ +import hello_world.foo; + +function main() {} \ No newline at end of file diff --git a/tests/pass/parse/import/star.leo b/tests/pass/parse/import/star.leo new file mode 100644 index 0000000000..9cd817686f --- /dev/null +++ b/tests/pass/parse/import/star.leo @@ -0,0 +1,7 @@ +import test-import.*; + +function main() { + let a = Point { x: 1u32, y: 0u32 }; + + console.assert(foo() == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/import/star_fail.leo b/tests/pass/parse/import/star_fail.leo new file mode 100644 index 0000000000..47f2efeda7 --- /dev/null +++ b/tests/pass/parse/import/star_fail.leo @@ -0,0 +1,4 @@ +// importing `*` from a directory is illegal +import bar.bat.*; + +function main() {} \ No newline at end of file diff --git a/tests/pass/parse/import/test-import.leo b/tests/pass/parse/import/test-import.leo new file mode 100644 index 0000000000..6dd3e2c88a --- /dev/null +++ b/tests/pass/parse/import/test-import.leo @@ -0,0 +1,8 @@ +circuit Point { + x: u32 + y: u32 +} + +function foo() -> u32 { + return 1u32 +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/add.leo b/tests/pass/parse/integers/i128/add.leo new file mode 100644 index 0000000000..e35648f545 --- /dev/null +++ b/tests/pass/parse/integers/i128/add.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: i128) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/console_assert.leo b/tests/pass/parse/integers/i128/console_assert.leo new file mode 100644 index 0000000000..c89021f609 --- /dev/null +++ b/tests/pass/parse/integers/i128/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/div.leo b/tests/pass/parse/integers/i128/div.leo new file mode 100644 index 0000000000..ffaeae19a8 --- /dev/null +++ b/tests/pass/parse/integers/i128/div.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: i128) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/eq.leo b/tests/pass/parse/integers/i128/eq.leo new file mode 100644 index 0000000000..f4beddc8fc --- /dev/null +++ b/tests/pass/parse/integers/i128/eq.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/ge.leo b/tests/pass/parse/integers/i128/ge.leo new file mode 100644 index 0000000000..1fbbd68073 --- /dev/null +++ b/tests/pass/parse/integers/i128/ge.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/gt.leo b/tests/pass/parse/integers/i128/gt.leo new file mode 100644 index 0000000000..27849afbe8 --- /dev/null +++ b/tests/pass/parse/integers/i128/gt.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/input.leo b/tests/pass/parse/integers/i128/input.leo new file mode 100644 index 0000000000..c89021f609 --- /dev/null +++ b/tests/pass/parse/integers/i128/input.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/le.leo b/tests/pass/parse/integers/i128/le.leo new file mode 100644 index 0000000000..ea0c3c9e1d --- /dev/null +++ b/tests/pass/parse/integers/i128/le.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/lt.leo b/tests/pass/parse/integers/i128/lt.leo new file mode 100644 index 0000000000..bde4def85c --- /dev/null +++ b/tests/pass/parse/integers/i128/lt.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/max.leo b/tests/pass/parse/integers/i128/max.leo new file mode 100644 index 0000000000..46c0a32599 --- /dev/null +++ b/tests/pass/parse/integers/i128/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: i128 = 170141183460469231731687303715884105727; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/max_fail.leo b/tests/pass/parse/integers/i128/max_fail.leo new file mode 100644 index 0000000000..820eda8759 --- /dev/null +++ b/tests/pass/parse/integers/i128/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i128 = 170141183460469231731687303715884105728; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/min.leo b/tests/pass/parse/integers/i128/min.leo new file mode 100644 index 0000000000..5f32e5add5 --- /dev/null +++ b/tests/pass/parse/integers/i128/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: i128 = -170141183460469231731687303715884105728; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/min_fail.leo b/tests/pass/parse/integers/i128/min_fail.leo new file mode 100644 index 0000000000..9035444fa9 --- /dev/null +++ b/tests/pass/parse/integers/i128/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i128 = -170141183460469231731687303715884105729; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/mod.rs b/tests/pass/parse/integers/i128/mod.rs new file mode 100644 index 0000000000..e62e07260e --- /dev/null +++ b/tests/pass/parse/integers/i128/mod.rs @@ -0,0 +1,134 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{I128Type, IntegerType, SignedIntegerType}; + +test_int!( + TestI128, + i128, + IntegerType::Signed(SignedIntegerType::I128Type(I128Type {})), + Int128 +); + +#[test] +fn test_i128_min() { + TestI128::test_min(); +} + +#[test] +fn test_i128_min_fail() { + TestI128::test_min_fail(); +} + +#[test] +fn test_i128_max() { + TestI128::test_max(); +} + +#[test] +fn test_i128_max_fail() { + TestI128::test_max_fail(); +} + +#[test] +fn test_i128_neg() { + TestI128::test_negate(); +} + +#[test] +fn test_i128_neg_max_fail() { + TestI128::test_negate_min_fail(); +} + +#[test] +fn test_i128_neg_zero() { + TestI128::test_negate_zero(); +} + +#[test] +fn test_i128_add() { + TestI128::test_add(); +} + +#[test] +fn test_i128_sub() { + TestI128::test_sub(); +} + +#[test] +fn test_i128_mul() { + TestI128::test_mul(); +} + +#[test] +#[ignore] // takes several minutes +fn test_i128_div() { + TestI128::test_div(); +} + +#[test] +fn test_i128_pow() { + TestI128::test_pow(); +} + +#[test] +fn test_i128_eq() { + TestI128::test_eq(); +} + +#[test] +fn test_i128_ne() { + TestI128::test_ne(); +} + +#[test] +fn test_i128_ge() { + TestI128::test_ge(); +} + +#[test] +fn test_i128_gt() { + TestI128::test_gt(); +} + +#[test] +fn test_i128_le() { + TestI128::test_le(); +} + +#[test] +fn test_i128_lt() { + TestI128::test_lt(); +} + +#[test] +fn test_i128_assert_eq() { + TestI128::test_console_assert(); +} + +#[test] +fn test_i128_ternary() { + TestI128::test_ternary(); +} diff --git a/tests/pass/parse/integers/i128/mul.leo b/tests/pass/parse/integers/i128/mul.leo new file mode 100644 index 0000000000..25b902d53c --- /dev/null +++ b/tests/pass/parse/integers/i128/mul.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: i128) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/ne.leo b/tests/pass/parse/integers/i128/ne.leo new file mode 100644 index 0000000000..dae148b49c --- /dev/null +++ b/tests/pass/parse/integers/i128/ne.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/negate.leo b/tests/pass/parse/integers/i128/negate.leo new file mode 100644 index 0000000000..437ee06390 --- /dev/null +++ b/tests/pass/parse/integers/i128/negate.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/negate_min.leo b/tests/pass/parse/integers/i128/negate_min.leo new file mode 100644 index 0000000000..cfbd308362 --- /dev/null +++ b/tests/pass/parse/integers/i128/negate_min.leo @@ -0,0 +1,4 @@ +function main() { + let a: i128 = -170141183460469231731687303715884105728; + let b = -a; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/negate_zero.leo b/tests/pass/parse/integers/i128/negate_zero.leo new file mode 100644 index 0000000000..9fb0c11afe --- /dev/null +++ b/tests/pass/parse/integers/i128/negate_zero.leo @@ -0,0 +1,5 @@ +function main() { + let a = 0i128; + + console.assert(-a == 0i128); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/pow.leo b/tests/pass/parse/integers/i128/pow.leo new file mode 100644 index 0000000000..05536aad51 --- /dev/null +++ b/tests/pass/parse/integers/i128/pow.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: i128) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/sub.leo b/tests/pass/parse/integers/i128/sub.leo new file mode 100644 index 0000000000..3a723eec49 --- /dev/null +++ b/tests/pass/parse/integers/i128/sub.leo @@ -0,0 +1,3 @@ +function main(a: i128, b: i128, c: i128) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/ternary.leo b/tests/pass/parse/integers/i128/ternary.leo new file mode 100644 index 0000000000..5c2f199499 --- /dev/null +++ b/tests/pass/parse/integers/i128/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: i128, b: i128, c: i128) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/add.leo b/tests/pass/parse/integers/i16/add.leo new file mode 100644 index 0000000000..556ae65c3a --- /dev/null +++ b/tests/pass/parse/integers/i16/add.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: i16) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/console_assert.leo b/tests/pass/parse/integers/i16/console_assert.leo new file mode 100644 index 0000000000..3afb25b207 --- /dev/null +++ b/tests/pass/parse/integers/i16/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/div.leo b/tests/pass/parse/integers/i16/div.leo new file mode 100644 index 0000000000..6d0c8f4614 --- /dev/null +++ b/tests/pass/parse/integers/i16/div.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: i16) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/eq.leo b/tests/pass/parse/integers/i16/eq.leo new file mode 100644 index 0000000000..338e3e50f6 --- /dev/null +++ b/tests/pass/parse/integers/i16/eq.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/ge.leo b/tests/pass/parse/integers/i16/ge.leo new file mode 100644 index 0000000000..68a4d40bf8 --- /dev/null +++ b/tests/pass/parse/integers/i16/ge.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/gt.leo b/tests/pass/parse/integers/i16/gt.leo new file mode 100644 index 0000000000..75d9bfb612 --- /dev/null +++ b/tests/pass/parse/integers/i16/gt.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/input.leo b/tests/pass/parse/integers/i16/input.leo new file mode 100644 index 0000000000..3afb25b207 --- /dev/null +++ b/tests/pass/parse/integers/i16/input.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/le.leo b/tests/pass/parse/integers/i16/le.leo new file mode 100644 index 0000000000..ff112c7fbc --- /dev/null +++ b/tests/pass/parse/integers/i16/le.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/lt.leo b/tests/pass/parse/integers/i16/lt.leo new file mode 100644 index 0000000000..46c57aabe6 --- /dev/null +++ b/tests/pass/parse/integers/i16/lt.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/max.leo b/tests/pass/parse/integers/i16/max.leo new file mode 100644 index 0000000000..084fe4969a --- /dev/null +++ b/tests/pass/parse/integers/i16/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: i16 = 32767; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/max_fail.leo b/tests/pass/parse/integers/i16/max_fail.leo new file mode 100644 index 0000000000..8dd2b7f50a --- /dev/null +++ b/tests/pass/parse/integers/i16/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i16 = 32768; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/min.leo b/tests/pass/parse/integers/i16/min.leo new file mode 100644 index 0000000000..3331281fcf --- /dev/null +++ b/tests/pass/parse/integers/i16/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: i16 = -32768; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/min_fail.leo b/tests/pass/parse/integers/i16/min_fail.leo new file mode 100644 index 0000000000..380848381a --- /dev/null +++ b/tests/pass/parse/integers/i16/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i16 = -32769; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/mod.rs b/tests/pass/parse/integers/i16/mod.rs new file mode 100644 index 0000000000..49b45f5b3e --- /dev/null +++ b/tests/pass/parse/integers/i16/mod.rs @@ -0,0 +1,133 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{I16Type, IntegerType, SignedIntegerType}; + +test_int!( + TestI16, + i16, + IntegerType::Signed(SignedIntegerType::I16Type(I16Type {})), + Int16 +); + +#[test] +fn test_i16_min() { + TestI16::test_min(); +} + +#[test] +fn test_i16_min_fail() { + TestI16::test_min_fail(); +} + +#[test] +fn test_i16_max() { + TestI16::test_max(); +} + +#[test] +fn test_i16_max_fail() { + TestI16::test_max_fail(); +} + +#[test] +fn test_i16_neg() { + TestI16::test_negate(); +} + +#[test] +fn test_i16_neg_max_fail() { + TestI16::test_negate_min_fail(); +} + +#[test] +fn test_i16_neg_zero() { + TestI16::test_negate_zero(); +} + +#[test] +fn test_i16_add() { + TestI16::test_add(); +} + +#[test] +fn test_i16_sub() { + TestI16::test_sub(); +} + +#[test] +fn test_i16_mul() { + TestI16::test_mul(); +} + +#[test] +fn test_i16_div() { + TestI16::test_div(); +} + +#[test] +fn test_i16_pow() { + TestI16::test_pow(); +} + +#[test] +fn test_i16_eq() { + TestI16::test_eq(); +} + +#[test] +fn test_i16_ne() { + TestI16::test_ne(); +} + +#[test] +fn test_i16_ge() { + TestI16::test_ge(); +} + +#[test] +fn test_i16_gt() { + TestI16::test_gt(); +} + +#[test] +fn test_i16_le() { + TestI16::test_le(); +} + +#[test] +fn test_i16_lt() { + TestI16::test_lt(); +} + +#[test] +fn test_i16_console_assert() { + TestI16::test_console_assert(); +} + +#[test] +fn test_i16_ternary() { + TestI16::test_ternary(); +} diff --git a/tests/pass/parse/integers/i16/mul.leo b/tests/pass/parse/integers/i16/mul.leo new file mode 100644 index 0000000000..6fd19b703a --- /dev/null +++ b/tests/pass/parse/integers/i16/mul.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: i16) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/ne.leo b/tests/pass/parse/integers/i16/ne.leo new file mode 100644 index 0000000000..f0a9472678 --- /dev/null +++ b/tests/pass/parse/integers/i16/ne.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/negate.leo b/tests/pass/parse/integers/i16/negate.leo new file mode 100644 index 0000000000..1d2644dce7 --- /dev/null +++ b/tests/pass/parse/integers/i16/negate.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/negate_min.leo b/tests/pass/parse/integers/i16/negate_min.leo new file mode 100644 index 0000000000..2622f8d2a3 --- /dev/null +++ b/tests/pass/parse/integers/i16/negate_min.leo @@ -0,0 +1,4 @@ +function main() { + let a = -32768i16; + let b = -a; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/negate_zero.leo b/tests/pass/parse/integers/i16/negate_zero.leo new file mode 100644 index 0000000000..46340c3dc5 --- /dev/null +++ b/tests/pass/parse/integers/i16/negate_zero.leo @@ -0,0 +1,5 @@ +function main() { + let a = 0i16; + + console.assert(-a == 0i16); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/pow.leo b/tests/pass/parse/integers/i16/pow.leo new file mode 100644 index 0000000000..769d2d2fbb --- /dev/null +++ b/tests/pass/parse/integers/i16/pow.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: i16) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/sub.leo b/tests/pass/parse/integers/i16/sub.leo new file mode 100644 index 0000000000..e935935187 --- /dev/null +++ b/tests/pass/parse/integers/i16/sub.leo @@ -0,0 +1,3 @@ +function main(a: i16, b: i16, c: i16) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/ternary.leo b/tests/pass/parse/integers/i16/ternary.leo new file mode 100644 index 0000000000..ccf29bfd50 --- /dev/null +++ b/tests/pass/parse/integers/i16/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: i16, b: i16, c: i16) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/add.leo b/tests/pass/parse/integers/i32/add.leo new file mode 100644 index 0000000000..3d8fb1b1d2 --- /dev/null +++ b/tests/pass/parse/integers/i32/add.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: i32) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/console_assert.leo b/tests/pass/parse/integers/i32/console_assert.leo new file mode 100644 index 0000000000..a2d6980e9a --- /dev/null +++ b/tests/pass/parse/integers/i32/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/div.leo b/tests/pass/parse/integers/i32/div.leo new file mode 100644 index 0000000000..3189a354f0 --- /dev/null +++ b/tests/pass/parse/integers/i32/div.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: i32) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/eq.leo b/tests/pass/parse/integers/i32/eq.leo new file mode 100644 index 0000000000..bac7af0be0 --- /dev/null +++ b/tests/pass/parse/integers/i32/eq.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/ge.leo b/tests/pass/parse/integers/i32/ge.leo new file mode 100644 index 0000000000..362521fc82 --- /dev/null +++ b/tests/pass/parse/integers/i32/ge.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/gt.leo b/tests/pass/parse/integers/i32/gt.leo new file mode 100644 index 0000000000..63ddcaa85c --- /dev/null +++ b/tests/pass/parse/integers/i32/gt.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/input.leo b/tests/pass/parse/integers/i32/input.leo new file mode 100644 index 0000000000..a2d6980e9a --- /dev/null +++ b/tests/pass/parse/integers/i32/input.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/le.leo b/tests/pass/parse/integers/i32/le.leo new file mode 100644 index 0000000000..948c66b1fc --- /dev/null +++ b/tests/pass/parse/integers/i32/le.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/lt.leo b/tests/pass/parse/integers/i32/lt.leo new file mode 100644 index 0000000000..72a8fb0d53 --- /dev/null +++ b/tests/pass/parse/integers/i32/lt.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/max.leo b/tests/pass/parse/integers/i32/max.leo new file mode 100644 index 0000000000..a9c707eb7f --- /dev/null +++ b/tests/pass/parse/integers/i32/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: i32 = 2147483647; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/max_fail.leo b/tests/pass/parse/integers/i32/max_fail.leo new file mode 100644 index 0000000000..f3fd81815f --- /dev/null +++ b/tests/pass/parse/integers/i32/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i32 = 2147483648; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/min.leo b/tests/pass/parse/integers/i32/min.leo new file mode 100644 index 0000000000..a29d591029 --- /dev/null +++ b/tests/pass/parse/integers/i32/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: i32 = -2147483648; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/min_fail.leo b/tests/pass/parse/integers/i32/min_fail.leo new file mode 100644 index 0000000000..1462d207e9 --- /dev/null +++ b/tests/pass/parse/integers/i32/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i32 = -2147483649; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/mod.rs b/tests/pass/parse/integers/i32/mod.rs new file mode 100644 index 0000000000..ee9e25701a --- /dev/null +++ b/tests/pass/parse/integers/i32/mod.rs @@ -0,0 +1,133 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{I32Type, IntegerType, SignedIntegerType}; + +test_int!( + TestI32, + i32, + IntegerType::Signed(SignedIntegerType::I32Type(I32Type {})), + Int32 +); + +#[test] +fn test_i32_min() { + TestI32::test_min(); +} + +#[test] +fn test_i32_min_fail() { + TestI32::test_min_fail(); +} + +#[test] +fn test_i32_max() { + TestI32::test_max(); +} + +#[test] +fn test_i32_max_fail() { + TestI32::test_max_fail(); +} + +#[test] +fn test_i32_neg() { + TestI32::test_negate(); +} + +#[test] +fn test_i32_neg_max_fail() { + TestI32::test_negate_min_fail(); +} + +#[test] +fn test_i32_neg_zero() { + TestI32::test_negate_zero(); +} + +#[test] +fn test_i32_add() { + TestI32::test_add(); +} + +#[test] +fn test_i32_sub() { + TestI32::test_sub(); +} + +#[test] +fn test_i32_mul() { + TestI32::test_mul(); +} + +#[test] +fn test_i32_div() { + TestI32::test_div(); +} + +#[test] +fn test_i32_pow() { + TestI32::test_pow(); +} + +#[test] +fn test_i32_eq() { + TestI32::test_eq(); +} + +#[test] +fn test_i32_ne() { + TestI32::test_ne(); +} + +#[test] +fn test_i32_ge() { + TestI32::test_ge(); +} + +#[test] +fn test_i32_gt() { + TestI32::test_gt(); +} + +#[test] +fn test_i32_le() { + TestI32::test_le(); +} + +#[test] +fn test_i32_lt() { + TestI32::test_lt(); +} + +#[test] +fn test_i32_console_assert() { + TestI32::test_console_assert(); +} + +#[test] +fn test_i32_ternary() { + TestI32::test_ternary(); +} diff --git a/tests/pass/parse/integers/i32/mul.leo b/tests/pass/parse/integers/i32/mul.leo new file mode 100644 index 0000000000..50ba5b4128 --- /dev/null +++ b/tests/pass/parse/integers/i32/mul.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: i32) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/ne.leo b/tests/pass/parse/integers/i32/ne.leo new file mode 100644 index 0000000000..dcc1a185d1 --- /dev/null +++ b/tests/pass/parse/integers/i32/ne.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/negate.leo b/tests/pass/parse/integers/i32/negate.leo new file mode 100644 index 0000000000..eef94c934f --- /dev/null +++ b/tests/pass/parse/integers/i32/negate.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/negate_min.leo b/tests/pass/parse/integers/i32/negate_min.leo new file mode 100644 index 0000000000..b3c10064e1 --- /dev/null +++ b/tests/pass/parse/integers/i32/negate_min.leo @@ -0,0 +1,4 @@ +function main() { + let a = -2147483648i32; + let b = -a; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/negate_zero.leo b/tests/pass/parse/integers/i32/negate_zero.leo new file mode 100644 index 0000000000..5533f575a6 --- /dev/null +++ b/tests/pass/parse/integers/i32/negate_zero.leo @@ -0,0 +1,5 @@ +function main() { + let a = 0i32; + + console.assert(-a == 0i32); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/pow.leo b/tests/pass/parse/integers/i32/pow.leo new file mode 100644 index 0000000000..ebb131e30b --- /dev/null +++ b/tests/pass/parse/integers/i32/pow.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: i32) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/sub.leo b/tests/pass/parse/integers/i32/sub.leo new file mode 100644 index 0000000000..1f054a5ddf --- /dev/null +++ b/tests/pass/parse/integers/i32/sub.leo @@ -0,0 +1,3 @@ +function main(a: i32, b: i32, c: i32) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/ternary.leo b/tests/pass/parse/integers/i32/ternary.leo new file mode 100644 index 0000000000..3066547ae3 --- /dev/null +++ b/tests/pass/parse/integers/i32/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: i32, b: i32, c: i32) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/add.leo b/tests/pass/parse/integers/i64/add.leo new file mode 100644 index 0000000000..aefdbb178f --- /dev/null +++ b/tests/pass/parse/integers/i64/add.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: i64) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/console_assert.leo b/tests/pass/parse/integers/i64/console_assert.leo new file mode 100644 index 0000000000..ab9a5d6e91 --- /dev/null +++ b/tests/pass/parse/integers/i64/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/div.leo b/tests/pass/parse/integers/i64/div.leo new file mode 100644 index 0000000000..142e4ab801 --- /dev/null +++ b/tests/pass/parse/integers/i64/div.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: i64) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/eq.leo b/tests/pass/parse/integers/i64/eq.leo new file mode 100644 index 0000000000..86a234c834 --- /dev/null +++ b/tests/pass/parse/integers/i64/eq.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/ge.leo b/tests/pass/parse/integers/i64/ge.leo new file mode 100644 index 0000000000..e7b453c5dc --- /dev/null +++ b/tests/pass/parse/integers/i64/ge.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/gt.leo b/tests/pass/parse/integers/i64/gt.leo new file mode 100644 index 0000000000..9709bad012 --- /dev/null +++ b/tests/pass/parse/integers/i64/gt.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/input.leo b/tests/pass/parse/integers/i64/input.leo new file mode 100644 index 0000000000..ab9a5d6e91 --- /dev/null +++ b/tests/pass/parse/integers/i64/input.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/le.leo b/tests/pass/parse/integers/i64/le.leo new file mode 100644 index 0000000000..3e2cfcb711 --- /dev/null +++ b/tests/pass/parse/integers/i64/le.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/lt.leo b/tests/pass/parse/integers/i64/lt.leo new file mode 100644 index 0000000000..ef4e38eb76 --- /dev/null +++ b/tests/pass/parse/integers/i64/lt.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/max.leo b/tests/pass/parse/integers/i64/max.leo new file mode 100644 index 0000000000..e0d19881e6 --- /dev/null +++ b/tests/pass/parse/integers/i64/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: i64 = 9223372036854775807; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/max_fail.leo b/tests/pass/parse/integers/i64/max_fail.leo new file mode 100644 index 0000000000..3e6603e4be --- /dev/null +++ b/tests/pass/parse/integers/i64/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i64 = 9223372036854775808; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/min.leo b/tests/pass/parse/integers/i64/min.leo new file mode 100644 index 0000000000..d7e99a87f8 --- /dev/null +++ b/tests/pass/parse/integers/i64/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: i64 = -9223372036854775808; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/min_fail.leo b/tests/pass/parse/integers/i64/min_fail.leo new file mode 100644 index 0000000000..11e43646b0 --- /dev/null +++ b/tests/pass/parse/integers/i64/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i64 = -9223372036854775809; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/mod.rs b/tests/pass/parse/integers/i64/mod.rs new file mode 100644 index 0000000000..066ac9956f --- /dev/null +++ b/tests/pass/parse/integers/i64/mod.rs @@ -0,0 +1,134 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{I64Type, IntegerType, SignedIntegerType}; + +test_int!( + TestI64, + i64, + IntegerType::Signed(SignedIntegerType::I64Type(I64Type {})), + Int64 +); + +#[test] +fn test_i64_min() { + TestI64::test_min(); +} + +#[test] +fn test_i64_min_fail() { + TestI64::test_min_fail(); +} + +#[test] +fn test_i64_max() { + TestI64::test_max(); +} + +#[test] +fn test_i64_max_fail() { + TestI64::test_max_fail(); +} + +#[test] +fn test_i64_neg() { + TestI64::test_negate(); +} + +#[test] +fn test_i64_neg_max_fail() { + TestI64::test_negate_min_fail(); +} + +#[test] +fn test_i64_neg_zero() { + TestI64::test_negate_zero(); +} + +#[test] +fn test_i64_add() { + TestI64::test_add(); +} + +#[test] +fn test_i64_sub() { + TestI64::test_sub(); +} + +#[test] +fn test_i64_mul() { + TestI64::test_mul(); +} + +#[test] +#[ignore] // takes 2 minutes +fn test_i64_div() { + TestI64::test_div(); +} + +#[test] +fn test_i64_pow() { + TestI64::test_pow(); +} + +#[test] +fn test_i64_eq() { + TestI64::test_eq(); +} + +#[test] +fn test_i64_ne() { + TestI64::test_ne(); +} + +#[test] +fn test_i64_ge() { + TestI64::test_ge(); +} + +#[test] +fn test_i64_gt() { + TestI64::test_gt(); +} + +#[test] +fn test_i64_le() { + TestI64::test_le(); +} + +#[test] +fn test_i64_lt() { + TestI64::test_lt(); +} + +#[test] +fn test_i64_console_assert() { + TestI64::test_console_assert(); +} + +#[test] +fn test_i64_ternary() { + TestI64::test_ternary(); +} diff --git a/tests/pass/parse/integers/i64/mul.leo b/tests/pass/parse/integers/i64/mul.leo new file mode 100644 index 0000000000..a3b8bd1da5 --- /dev/null +++ b/tests/pass/parse/integers/i64/mul.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: i64) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/ne.leo b/tests/pass/parse/integers/i64/ne.leo new file mode 100644 index 0000000000..a2642bb479 --- /dev/null +++ b/tests/pass/parse/integers/i64/ne.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/negate.leo b/tests/pass/parse/integers/i64/negate.leo new file mode 100644 index 0000000000..fe0cdc4d97 --- /dev/null +++ b/tests/pass/parse/integers/i64/negate.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/negate_min.leo b/tests/pass/parse/integers/i64/negate_min.leo new file mode 100644 index 0000000000..4dd27778d0 --- /dev/null +++ b/tests/pass/parse/integers/i64/negate_min.leo @@ -0,0 +1,4 @@ +function main() { + let a: i64 = -9223372036854775808; + let b = -a; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/negate_zero.leo b/tests/pass/parse/integers/i64/negate_zero.leo new file mode 100644 index 0000000000..6badfe4dc7 --- /dev/null +++ b/tests/pass/parse/integers/i64/negate_zero.leo @@ -0,0 +1,5 @@ +function main() { + let a = 0i64; + + console.assert(-a == 0i64); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/pow.leo b/tests/pass/parse/integers/i64/pow.leo new file mode 100644 index 0000000000..dca2dace74 --- /dev/null +++ b/tests/pass/parse/integers/i64/pow.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: i64) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/sub.leo b/tests/pass/parse/integers/i64/sub.leo new file mode 100644 index 0000000000..4d335e504b --- /dev/null +++ b/tests/pass/parse/integers/i64/sub.leo @@ -0,0 +1,3 @@ +function main(a: i64, b: i64, c: i64) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/ternary.leo b/tests/pass/parse/integers/i64/ternary.leo new file mode 100644 index 0000000000..811c759bdf --- /dev/null +++ b/tests/pass/parse/integers/i64/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: i64, b: i64, c: i64) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/add.leo b/tests/pass/parse/integers/i8/add.leo new file mode 100644 index 0000000000..dd71bc7f53 --- /dev/null +++ b/tests/pass/parse/integers/i8/add.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: i8) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/console_assert.leo b/tests/pass/parse/integers/i8/console_assert.leo new file mode 100644 index 0000000000..1fc09cb57d --- /dev/null +++ b/tests/pass/parse/integers/i8/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/div.leo b/tests/pass/parse/integers/i8/div.leo new file mode 100644 index 0000000000..a80d8e6319 --- /dev/null +++ b/tests/pass/parse/integers/i8/div.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: i8) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/eq.leo b/tests/pass/parse/integers/i8/eq.leo new file mode 100644 index 0000000000..130cc64b89 --- /dev/null +++ b/tests/pass/parse/integers/i8/eq.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/ge.leo b/tests/pass/parse/integers/i8/ge.leo new file mode 100644 index 0000000000..3084692c0c --- /dev/null +++ b/tests/pass/parse/integers/i8/ge.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/gt.leo b/tests/pass/parse/integers/i8/gt.leo new file mode 100644 index 0000000000..d3913b8b24 --- /dev/null +++ b/tests/pass/parse/integers/i8/gt.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/input.leo b/tests/pass/parse/integers/i8/input.leo new file mode 100644 index 0000000000..1fc09cb57d --- /dev/null +++ b/tests/pass/parse/integers/i8/input.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/le.leo b/tests/pass/parse/integers/i8/le.leo new file mode 100644 index 0000000000..92e011f206 --- /dev/null +++ b/tests/pass/parse/integers/i8/le.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/lt.leo b/tests/pass/parse/integers/i8/lt.leo new file mode 100644 index 0000000000..eb34b7148e --- /dev/null +++ b/tests/pass/parse/integers/i8/lt.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/max.leo b/tests/pass/parse/integers/i8/max.leo new file mode 100644 index 0000000000..b51126da59 --- /dev/null +++ b/tests/pass/parse/integers/i8/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: i8 = 127; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/max_fail.leo b/tests/pass/parse/integers/i8/max_fail.leo new file mode 100644 index 0000000000..4892505915 --- /dev/null +++ b/tests/pass/parse/integers/i8/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i8 = 128; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/min.leo b/tests/pass/parse/integers/i8/min.leo new file mode 100644 index 0000000000..d3c1bff5e4 --- /dev/null +++ b/tests/pass/parse/integers/i8/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: i8 = -128; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/min_fail.leo b/tests/pass/parse/integers/i8/min_fail.leo new file mode 100644 index 0000000000..051468ea70 --- /dev/null +++ b/tests/pass/parse/integers/i8/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: i8 = -129; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/mod.rs b/tests/pass/parse/integers/i8/mod.rs new file mode 100644 index 0000000000..9133a72248 --- /dev/null +++ b/tests/pass/parse/integers/i8/mod.rs @@ -0,0 +1,133 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{I8Type, IntegerType, SignedIntegerType}; + +test_int!( + TestI8, + i8, + IntegerType::Signed(SignedIntegerType::I8Type(I8Type {})), + Int8 +); + +#[test] +fn test_i8_min() { + TestI8::test_min(); +} + +#[test] +fn test_i8_min_fail() { + TestI8::test_min_fail(); +} + +#[test] +fn test_i8_max() { + TestI8::test_max(); +} + +#[test] +fn test_i8_max_fail() { + TestI8::test_max_fail(); +} + +#[test] +fn test_i8_neg() { + TestI8::test_negate(); +} + +#[test] +fn test_i8_neg_max_fail() { + TestI8::test_negate_min_fail(); +} + +#[test] +fn test_i8_neg_zero() { + TestI8::test_negate_zero(); +} + +#[test] +fn test_i8_add() { + TestI8::test_add(); +} + +#[test] +fn test_i8_sub() { + TestI8::test_sub(); +} + +#[test] +fn test_i8_mul() { + TestI8::test_mul(); +} + +#[test] +fn test_i8_div() { + TestI8::test_div(); +} + +#[test] +fn test_i8_pow() { + TestI8::test_pow(); +} + +#[test] +fn test_i8_eq() { + TestI8::test_eq(); +} + +#[test] +fn test_i8_ne() { + TestI8::test_ne(); +} + +#[test] +fn test_i8_ge() { + TestI8::test_ge(); +} + +#[test] +fn test_i8_gt() { + TestI8::test_gt(); +} + +#[test] +fn test_i8_le() { + TestI8::test_le(); +} + +#[test] +fn test_i8_lt() { + TestI8::test_lt(); +} + +#[test] +fn test_i8_console_assert() { + TestI8::test_console_assert(); +} + +#[test] +fn test_i8_ternary() { + TestI8::test_ternary(); +} diff --git a/tests/pass/parse/integers/i8/mul.leo b/tests/pass/parse/integers/i8/mul.leo new file mode 100644 index 0000000000..34726fff92 --- /dev/null +++ b/tests/pass/parse/integers/i8/mul.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: i8) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/ne.leo b/tests/pass/parse/integers/i8/ne.leo new file mode 100644 index 0000000000..e5028d404a --- /dev/null +++ b/tests/pass/parse/integers/i8/ne.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/negate.leo b/tests/pass/parse/integers/i8/negate.leo new file mode 100644 index 0000000000..2a2266bc56 --- /dev/null +++ b/tests/pass/parse/integers/i8/negate.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8) { + console.assert(-a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/negate_min.leo b/tests/pass/parse/integers/i8/negate_min.leo new file mode 100644 index 0000000000..3959da615e --- /dev/null +++ b/tests/pass/parse/integers/i8/negate_min.leo @@ -0,0 +1,4 @@ +function main() { + let a = -128i8; + let b = -a; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/negate_zero.leo b/tests/pass/parse/integers/i8/negate_zero.leo new file mode 100644 index 0000000000..21fbbab675 --- /dev/null +++ b/tests/pass/parse/integers/i8/negate_zero.leo @@ -0,0 +1,5 @@ +function main() { + let a = 0i8; + + console.assert(-a == 0i8); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/pow.leo b/tests/pass/parse/integers/i8/pow.leo new file mode 100644 index 0000000000..18aeb44b46 --- /dev/null +++ b/tests/pass/parse/integers/i8/pow.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: i8) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/sub.leo b/tests/pass/parse/integers/i8/sub.leo new file mode 100644 index 0000000000..a795bed153 --- /dev/null +++ b/tests/pass/parse/integers/i8/sub.leo @@ -0,0 +1,3 @@ +function main(a: i8, b: i8, c: i8) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/ternary.leo b/tests/pass/parse/integers/i8/ternary.leo new file mode 100644 index 0000000000..de797c6e3b --- /dev/null +++ b/tests/pass/parse/integers/i8/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: i8, b: i8, c: i8) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/add.leo b/tests/pass/parse/integers/u128/add.leo new file mode 100644 index 0000000000..6b32042fd5 --- /dev/null +++ b/tests/pass/parse/integers/u128/add.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: u128) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/console_assert.leo b/tests/pass/parse/integers/u128/console_assert.leo new file mode 100644 index 0000000000..adab295385 --- /dev/null +++ b/tests/pass/parse/integers/u128/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/div.leo b/tests/pass/parse/integers/u128/div.leo new file mode 100644 index 0000000000..0d62054eca --- /dev/null +++ b/tests/pass/parse/integers/u128/div.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: u128) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/eq.leo b/tests/pass/parse/integers/u128/eq.leo new file mode 100644 index 0000000000..2c2acd923a --- /dev/null +++ b/tests/pass/parse/integers/u128/eq.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/ge.leo b/tests/pass/parse/integers/u128/ge.leo new file mode 100644 index 0000000000..bff7cd321b --- /dev/null +++ b/tests/pass/parse/integers/u128/ge.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/gt.leo b/tests/pass/parse/integers/u128/gt.leo new file mode 100644 index 0000000000..e8aec0faf2 --- /dev/null +++ b/tests/pass/parse/integers/u128/gt.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/input.leo b/tests/pass/parse/integers/u128/input.leo new file mode 100644 index 0000000000..adab295385 --- /dev/null +++ b/tests/pass/parse/integers/u128/input.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/le.leo b/tests/pass/parse/integers/u128/le.leo new file mode 100644 index 0000000000..c9e4609136 --- /dev/null +++ b/tests/pass/parse/integers/u128/le.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/lt.leo b/tests/pass/parse/integers/u128/lt.leo new file mode 100644 index 0000000000..b37057c895 --- /dev/null +++ b/tests/pass/parse/integers/u128/lt.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/max.leo b/tests/pass/parse/integers/u128/max.leo new file mode 100644 index 0000000000..6da59dd058 --- /dev/null +++ b/tests/pass/parse/integers/u128/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: u128 = 340282366920938463463374607431768211455; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/max_fail.leo b/tests/pass/parse/integers/u128/max_fail.leo new file mode 100644 index 0000000000..40cdf7d2bb --- /dev/null +++ b/tests/pass/parse/integers/u128/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u128 = 340282366920938463463374607431768211456; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/min.leo b/tests/pass/parse/integers/u128/min.leo new file mode 100644 index 0000000000..044bda9e1c --- /dev/null +++ b/tests/pass/parse/integers/u128/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: u128 = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/min_fail.leo b/tests/pass/parse/integers/u128/min_fail.leo new file mode 100644 index 0000000000..df2390c576 --- /dev/null +++ b/tests/pass/parse/integers/u128/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u128 = -1; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/mod.rs b/tests/pass/parse/integers/u128/mod.rs new file mode 100644 index 0000000000..2c110af0a5 --- /dev/null +++ b/tests/pass/parse/integers/u128/mod.rs @@ -0,0 +1,118 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{IntegerType, U128Type, UnsignedIntegerType}; + +test_uint!( + TestU128, + u128, + IntegerType::Unsigned(UnsignedIntegerType::U128Type(U128Type {})), + UInt128 +); + +#[test] +fn test_u128_min() { + TestU128::test_min(); +} + +#[test] +fn test_u128_min_fail() { + TestU128::test_min_fail(); +} + +#[test] +fn test_u128_max() { + TestU128::test_max(); +} + +#[test] +fn test_u128_max_fail() { + TestU128::test_max_fail(); +} + +#[test] +fn test_u128_add() { + TestU128::test_add(); +} + +#[test] +fn test_u128_sub() { + TestU128::test_sub(); +} + +#[test] +fn test_u128_mul() { + TestU128::test_mul(); +} + +#[test] +fn test_u128_div() { + TestU128::test_div(); +} + +#[test] +fn test_u128_pow() { + TestU128::test_pow(); +} + +#[test] +fn test_u128_eq() { + TestU128::test_eq(); +} + +#[test] +fn test_u128_ne() { + TestU128::test_ne(); +} + +#[test] +fn test_u128_ge() { + TestU128::test_ge(); +} + +#[test] +fn test_u128_gt() { + TestU128::test_gt(); +} + +#[test] +fn test_u128_le() { + TestU128::test_le(); +} + +#[test] +fn test_u128_lt() { + TestU128::test_lt(); +} + +#[test] +fn test_u128_console_assert() { + TestU128::test_console_assert(); +} + +#[test] +fn test_u128_ternary() { + TestU128::test_ternary(); +} diff --git a/tests/pass/parse/integers/u128/mul.leo b/tests/pass/parse/integers/u128/mul.leo new file mode 100644 index 0000000000..c7fdc1530c --- /dev/null +++ b/tests/pass/parse/integers/u128/mul.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: u128) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/ne.leo b/tests/pass/parse/integers/u128/ne.leo new file mode 100644 index 0000000000..da3467d01e --- /dev/null +++ b/tests/pass/parse/integers/u128/ne.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/pow.leo b/tests/pass/parse/integers/u128/pow.leo new file mode 100644 index 0000000000..27614bfa56 --- /dev/null +++ b/tests/pass/parse/integers/u128/pow.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: u128) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/sub.leo b/tests/pass/parse/integers/u128/sub.leo new file mode 100644 index 0000000000..2374413505 --- /dev/null +++ b/tests/pass/parse/integers/u128/sub.leo @@ -0,0 +1,3 @@ +function main(a: u128, b: u128, c: u128) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/ternary.leo b/tests/pass/parse/integers/u128/ternary.leo new file mode 100644 index 0000000000..48299fac66 --- /dev/null +++ b/tests/pass/parse/integers/u128/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: u128, b: u128, c: u128) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/add.leo b/tests/pass/parse/integers/u16/add.leo new file mode 100644 index 0000000000..f00701181b --- /dev/null +++ b/tests/pass/parse/integers/u16/add.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: u16) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/console_assert.leo b/tests/pass/parse/integers/u16/console_assert.leo new file mode 100644 index 0000000000..761f0639d0 --- /dev/null +++ b/tests/pass/parse/integers/u16/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/div.leo b/tests/pass/parse/integers/u16/div.leo new file mode 100644 index 0000000000..f1dd3fa463 --- /dev/null +++ b/tests/pass/parse/integers/u16/div.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: u16) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/eq.leo b/tests/pass/parse/integers/u16/eq.leo new file mode 100644 index 0000000000..a4b4e78b49 --- /dev/null +++ b/tests/pass/parse/integers/u16/eq.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/ge.leo b/tests/pass/parse/integers/u16/ge.leo new file mode 100644 index 0000000000..4b1da1b27b --- /dev/null +++ b/tests/pass/parse/integers/u16/ge.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/gt.leo b/tests/pass/parse/integers/u16/gt.leo new file mode 100644 index 0000000000..2c5ffbe8eb --- /dev/null +++ b/tests/pass/parse/integers/u16/gt.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/input.leo b/tests/pass/parse/integers/u16/input.leo new file mode 100644 index 0000000000..761f0639d0 --- /dev/null +++ b/tests/pass/parse/integers/u16/input.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/le.leo b/tests/pass/parse/integers/u16/le.leo new file mode 100644 index 0000000000..49713482d0 --- /dev/null +++ b/tests/pass/parse/integers/u16/le.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/lt.leo b/tests/pass/parse/integers/u16/lt.leo new file mode 100644 index 0000000000..dae1951231 --- /dev/null +++ b/tests/pass/parse/integers/u16/lt.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/max.leo b/tests/pass/parse/integers/u16/max.leo new file mode 100644 index 0000000000..a707df9af8 --- /dev/null +++ b/tests/pass/parse/integers/u16/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: u16 = 65535; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/max_fail.leo b/tests/pass/parse/integers/u16/max_fail.leo new file mode 100644 index 0000000000..68ff0481e0 --- /dev/null +++ b/tests/pass/parse/integers/u16/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u16 = 65536; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/min.leo b/tests/pass/parse/integers/u16/min.leo new file mode 100644 index 0000000000..ab1bd7db48 --- /dev/null +++ b/tests/pass/parse/integers/u16/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: u16 = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/min_fail.leo b/tests/pass/parse/integers/u16/min_fail.leo new file mode 100644 index 0000000000..99b7310362 --- /dev/null +++ b/tests/pass/parse/integers/u16/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u16 = -1; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/mod.rs b/tests/pass/parse/integers/u16/mod.rs new file mode 100644 index 0000000000..b4b202b9da --- /dev/null +++ b/tests/pass/parse/integers/u16/mod.rs @@ -0,0 +1,118 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{IntegerType, U16Type, UnsignedIntegerType}; + +test_uint!( + TestU16, + u16, + IntegerType::Unsigned(UnsignedIntegerType::U16Type(U16Type {})), + UInt16 +); + +#[test] +fn test_u16_min() { + TestU16::test_min(); +} + +#[test] +fn test_u16_min_fail() { + TestU16::test_min_fail(); +} + +#[test] +fn test_u16_max() { + TestU16::test_max(); +} + +#[test] +fn test_u16_max_fail() { + TestU16::test_max_fail(); +} + +#[test] +fn test_u16_add() { + TestU16::test_add(); +} + +#[test] +fn test_u16_sub() { + TestU16::test_sub(); +} + +#[test] +fn test_u16_mul() { + TestU16::test_mul(); +} + +#[test] +fn test_u16_div() { + TestU16::test_div(); +} + +#[test] +fn test_u16_pow() { + TestU16::test_pow(); +} + +#[test] +fn test_u16_eq() { + TestU16::test_eq(); +} + +#[test] +fn test_u16_ne() { + TestU16::test_ne(); +} + +#[test] +fn test_u16_ge() { + TestU16::test_ge(); +} + +#[test] +fn test_u16_gt() { + TestU16::test_gt(); +} + +#[test] +fn test_u16_le() { + TestU16::test_le(); +} + +#[test] +fn test_u16_lt() { + TestU16::test_lt(); +} + +#[test] +fn test_u16_console_assert() { + TestU16::test_console_assert(); +} + +#[test] +fn test_u16_ternary() { + TestU16::test_ternary(); +} diff --git a/tests/pass/parse/integers/u16/mul.leo b/tests/pass/parse/integers/u16/mul.leo new file mode 100644 index 0000000000..f2c6f0aac8 --- /dev/null +++ b/tests/pass/parse/integers/u16/mul.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: u16) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/ne.leo b/tests/pass/parse/integers/u16/ne.leo new file mode 100644 index 0000000000..e90a304cfe --- /dev/null +++ b/tests/pass/parse/integers/u16/ne.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/pow.leo b/tests/pass/parse/integers/u16/pow.leo new file mode 100644 index 0000000000..564c1c51fe --- /dev/null +++ b/tests/pass/parse/integers/u16/pow.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: u16) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/sub.leo b/tests/pass/parse/integers/u16/sub.leo new file mode 100644 index 0000000000..92aae9ac2c --- /dev/null +++ b/tests/pass/parse/integers/u16/sub.leo @@ -0,0 +1,3 @@ +function main(a: u16, b: u16, c: u16) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/ternary.leo b/tests/pass/parse/integers/u16/ternary.leo new file mode 100644 index 0000000000..2e2752a130 --- /dev/null +++ b/tests/pass/parse/integers/u16/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: u16, b: u16, c: u16) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/add.leo b/tests/pass/parse/integers/u32/add.leo new file mode 100644 index 0000000000..6f6a2454b4 --- /dev/null +++ b/tests/pass/parse/integers/u32/add.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: u32) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/console_assert.leo b/tests/pass/parse/integers/u32/console_assert.leo new file mode 100644 index 0000000000..32604eb3b8 --- /dev/null +++ b/tests/pass/parse/integers/u32/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/div.leo b/tests/pass/parse/integers/u32/div.leo new file mode 100644 index 0000000000..ed689bd408 --- /dev/null +++ b/tests/pass/parse/integers/u32/div.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: u32) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/eq.leo b/tests/pass/parse/integers/u32/eq.leo new file mode 100644 index 0000000000..ca427b3c42 --- /dev/null +++ b/tests/pass/parse/integers/u32/eq.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/ge.leo b/tests/pass/parse/integers/u32/ge.leo new file mode 100644 index 0000000000..35c1c71829 --- /dev/null +++ b/tests/pass/parse/integers/u32/ge.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/gt.leo b/tests/pass/parse/integers/u32/gt.leo new file mode 100644 index 0000000000..f76df415c4 --- /dev/null +++ b/tests/pass/parse/integers/u32/gt.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/input.leo b/tests/pass/parse/integers/u32/input.leo new file mode 100644 index 0000000000..32604eb3b8 --- /dev/null +++ b/tests/pass/parse/integers/u32/input.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/le.leo b/tests/pass/parse/integers/u32/le.leo new file mode 100644 index 0000000000..9a802f896d --- /dev/null +++ b/tests/pass/parse/integers/u32/le.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/lt.leo b/tests/pass/parse/integers/u32/lt.leo new file mode 100644 index 0000000000..73e5654470 --- /dev/null +++ b/tests/pass/parse/integers/u32/lt.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/max.leo b/tests/pass/parse/integers/u32/max.leo new file mode 100644 index 0000000000..2950164a08 --- /dev/null +++ b/tests/pass/parse/integers/u32/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: u32 = 4294967295; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/max_fail.leo b/tests/pass/parse/integers/u32/max_fail.leo new file mode 100644 index 0000000000..96c7e01657 --- /dev/null +++ b/tests/pass/parse/integers/u32/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u32 = 4294967296; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/min.leo b/tests/pass/parse/integers/u32/min.leo new file mode 100644 index 0000000000..0f1c080938 --- /dev/null +++ b/tests/pass/parse/integers/u32/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: u32 = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/min_fail.leo b/tests/pass/parse/integers/u32/min_fail.leo new file mode 100644 index 0000000000..a8d41c475a --- /dev/null +++ b/tests/pass/parse/integers/u32/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u32 = -1; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/mod.rs b/tests/pass/parse/integers/u32/mod.rs new file mode 100644 index 0000000000..920fc6ed5b --- /dev/null +++ b/tests/pass/parse/integers/u32/mod.rs @@ -0,0 +1,118 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType}; + +test_uint!( + TestU32, + u32, + IntegerType::Unsigned(UnsignedIntegerType::U32Type(U32Type {})), + UInt32 +); + +#[test] +fn test_u32_min() { + TestU32::test_min(); +} + +#[test] +fn test_u32_min_fail() { + TestU32::test_min_fail(); +} + +#[test] +fn test_u32_max() { + TestU32::test_max(); +} + +#[test] +fn test_u32_max_fail() { + TestU32::test_max_fail(); +} + +#[test] +fn test_u32_add() { + TestU32::test_add(); +} + +#[test] +fn test_u32_sub() { + TestU32::test_sub(); +} + +#[test] +fn test_u32_mul() { + TestU32::test_mul(); +} + +#[test] +fn test_u32_div() { + TestU32::test_div(); +} + +#[test] +fn test_u32_pow() { + TestU32::test_pow(); +} + +#[test] +fn test_u32_eq() { + TestU32::test_eq(); +} + +#[test] +fn test_u32_ne() { + TestU32::test_ne(); +} + +#[test] +fn test_u32_ge() { + TestU32::test_ge(); +} + +#[test] +fn test_u32_gt() { + TestU32::test_gt(); +} + +#[test] +fn test_u32_le() { + TestU32::test_le(); +} + +#[test] +fn test_u32_lt() { + TestU32::test_lt(); +} + +#[test] +fn test_u32_console_assert() { + TestU32::test_console_assert(); +} + +#[test] +fn test_u32_ternary() { + TestU32::test_ternary(); +} diff --git a/tests/pass/parse/integers/u32/mul.leo b/tests/pass/parse/integers/u32/mul.leo new file mode 100644 index 0000000000..a77a85477b --- /dev/null +++ b/tests/pass/parse/integers/u32/mul.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: u32) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/ne.leo b/tests/pass/parse/integers/u32/ne.leo new file mode 100644 index 0000000000..00ee1a9989 --- /dev/null +++ b/tests/pass/parse/integers/u32/ne.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/pow.leo b/tests/pass/parse/integers/u32/pow.leo new file mode 100644 index 0000000000..b82496ff77 --- /dev/null +++ b/tests/pass/parse/integers/u32/pow.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: u32) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/sub.leo b/tests/pass/parse/integers/u32/sub.leo new file mode 100644 index 0000000000..54480bd4bc --- /dev/null +++ b/tests/pass/parse/integers/u32/sub.leo @@ -0,0 +1,3 @@ +function main(a: u32, b: u32, c: u32) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/ternary.leo b/tests/pass/parse/integers/u32/ternary.leo new file mode 100644 index 0000000000..fde04ac4b8 --- /dev/null +++ b/tests/pass/parse/integers/u32/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: u32, b: u32, c: u32) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/add.leo b/tests/pass/parse/integers/u64/add.leo new file mode 100644 index 0000000000..28abe51201 --- /dev/null +++ b/tests/pass/parse/integers/u64/add.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: u64) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/console_assert.leo b/tests/pass/parse/integers/u64/console_assert.leo new file mode 100644 index 0000000000..ac1d6d40c3 --- /dev/null +++ b/tests/pass/parse/integers/u64/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/div.leo b/tests/pass/parse/integers/u64/div.leo new file mode 100644 index 0000000000..059da236bb --- /dev/null +++ b/tests/pass/parse/integers/u64/div.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: u64) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/eq.leo b/tests/pass/parse/integers/u64/eq.leo new file mode 100644 index 0000000000..990b2dad2d --- /dev/null +++ b/tests/pass/parse/integers/u64/eq.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/ge.leo b/tests/pass/parse/integers/u64/ge.leo new file mode 100644 index 0000000000..46ba36ceff --- /dev/null +++ b/tests/pass/parse/integers/u64/ge.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/gt.leo b/tests/pass/parse/integers/u64/gt.leo new file mode 100644 index 0000000000..7d3032c7f5 --- /dev/null +++ b/tests/pass/parse/integers/u64/gt.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/input.leo b/tests/pass/parse/integers/u64/input.leo new file mode 100644 index 0000000000..ac1d6d40c3 --- /dev/null +++ b/tests/pass/parse/integers/u64/input.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/le.leo b/tests/pass/parse/integers/u64/le.leo new file mode 100644 index 0000000000..625b38d2d9 --- /dev/null +++ b/tests/pass/parse/integers/u64/le.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/lt.leo b/tests/pass/parse/integers/u64/lt.leo new file mode 100644 index 0000000000..ed379f7341 --- /dev/null +++ b/tests/pass/parse/integers/u64/lt.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/max.leo b/tests/pass/parse/integers/u64/max.leo new file mode 100644 index 0000000000..985897c006 --- /dev/null +++ b/tests/pass/parse/integers/u64/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: u64 = 18446744073709551615; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/max_fail.leo b/tests/pass/parse/integers/u64/max_fail.leo new file mode 100644 index 0000000000..0ca3f13895 --- /dev/null +++ b/tests/pass/parse/integers/u64/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u64 = 18446744073709551616; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/min.leo b/tests/pass/parse/integers/u64/min.leo new file mode 100644 index 0000000000..aa9b72fc8a --- /dev/null +++ b/tests/pass/parse/integers/u64/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: u64 = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/min_fail.leo b/tests/pass/parse/integers/u64/min_fail.leo new file mode 100644 index 0000000000..81b90cc74a --- /dev/null +++ b/tests/pass/parse/integers/u64/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u64 = -1; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/mod.rs b/tests/pass/parse/integers/u64/mod.rs new file mode 100644 index 0000000000..ec86c868f1 --- /dev/null +++ b/tests/pass/parse/integers/u64/mod.rs @@ -0,0 +1,118 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{IntegerType, U64Type, UnsignedIntegerType}; + +test_uint!( + TestU64, + u64, + IntegerType::Unsigned(UnsignedIntegerType::U64Type(U64Type {})), + UInt64 +); + +#[test] +fn test_u64_min() { + TestU64::test_min(); +} + +#[test] +fn test_u64_min_fail() { + TestU64::test_min_fail(); +} + +#[test] +fn test_u64_max() { + TestU64::test_max(); +} + +#[test] +fn test_u64_max_fail() { + TestU64::test_max_fail(); +} + +#[test] +fn test_u64_add() { + TestU64::test_add(); +} + +#[test] +fn test_u64_sub() { + TestU64::test_sub(); +} + +#[test] +fn test_u64_mul() { + TestU64::test_mul(); +} + +#[test] +fn test_u64_div() { + TestU64::test_div(); +} + +#[test] +fn test_u64_pow() { + TestU64::test_pow(); +} + +#[test] +fn test_u64_eq() { + TestU64::test_eq(); +} + +#[test] +fn test_u64_ne() { + TestU64::test_ne(); +} + +#[test] +fn test_u64_ge() { + TestU64::test_ge(); +} + +#[test] +fn test_u64_gt() { + TestU64::test_gt(); +} + +#[test] +fn test_u64_le() { + TestU64::test_le(); +} + +#[test] +fn test_u64_lt() { + TestU64::test_lt(); +} + +#[test] +fn test_u64_console_assert() { + TestU64::test_console_assert(); +} + +#[test] +fn test_u64_ternary() { + TestU64::test_ternary(); +} diff --git a/tests/pass/parse/integers/u64/mul.leo b/tests/pass/parse/integers/u64/mul.leo new file mode 100644 index 0000000000..2633e6780c --- /dev/null +++ b/tests/pass/parse/integers/u64/mul.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: u64) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/ne.leo b/tests/pass/parse/integers/u64/ne.leo new file mode 100644 index 0000000000..e47acbb1de --- /dev/null +++ b/tests/pass/parse/integers/u64/ne.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/pow.leo b/tests/pass/parse/integers/u64/pow.leo new file mode 100644 index 0000000000..64f0694ed1 --- /dev/null +++ b/tests/pass/parse/integers/u64/pow.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: u64) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/sub.leo b/tests/pass/parse/integers/u64/sub.leo new file mode 100644 index 0000000000..9961f0f7b7 --- /dev/null +++ b/tests/pass/parse/integers/u64/sub.leo @@ -0,0 +1,3 @@ +function main(a: u64, b: u64, c: u64) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/ternary.leo b/tests/pass/parse/integers/u64/ternary.leo new file mode 100644 index 0000000000..315fd7400b --- /dev/null +++ b/tests/pass/parse/integers/u64/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: u64, b: u64, c: u64) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/add.leo b/tests/pass/parse/integers/u8/add.leo new file mode 100644 index 0000000000..1b40e304d2 --- /dev/null +++ b/tests/pass/parse/integers/u8/add.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: u8) { + console.assert(a + b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/console_assert.leo b/tests/pass/parse/integers/u8/console_assert.leo new file mode 100644 index 0000000000..4d99dc106c --- /dev/null +++ b/tests/pass/parse/integers/u8/console_assert.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/div.leo b/tests/pass/parse/integers/u8/div.leo new file mode 100644 index 0000000000..945aa94c30 --- /dev/null +++ b/tests/pass/parse/integers/u8/div.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: u8) { + console.assert(a / b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/eq.leo b/tests/pass/parse/integers/u8/eq.leo new file mode 100644 index 0000000000..c2a487b0e7 --- /dev/null +++ b/tests/pass/parse/integers/u8/eq.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: bool) { + console.assert(a == b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/ge.leo b/tests/pass/parse/integers/u8/ge.leo new file mode 100644 index 0000000000..d819422276 --- /dev/null +++ b/tests/pass/parse/integers/u8/ge.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: bool) { + console.assert(a >= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/gt.leo b/tests/pass/parse/integers/u8/gt.leo new file mode 100644 index 0000000000..87843f575f --- /dev/null +++ b/tests/pass/parse/integers/u8/gt.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: bool) { + console.assert(a > b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/input.leo b/tests/pass/parse/integers/u8/input.leo new file mode 100644 index 0000000000..4d99dc106c --- /dev/null +++ b/tests/pass/parse/integers/u8/input.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8) { + console.assert(a == b); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/le.leo b/tests/pass/parse/integers/u8/le.leo new file mode 100644 index 0000000000..2607b7f3d1 --- /dev/null +++ b/tests/pass/parse/integers/u8/le.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: bool) { + console.assert(a <= b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/lt.leo b/tests/pass/parse/integers/u8/lt.leo new file mode 100644 index 0000000000..7495d0fe37 --- /dev/null +++ b/tests/pass/parse/integers/u8/lt.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: bool) { + console.assert(a < b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/max.leo b/tests/pass/parse/integers/u8/max.leo new file mode 100644 index 0000000000..684bdfba10 --- /dev/null +++ b/tests/pass/parse/integers/u8/max.leo @@ -0,0 +1,3 @@ +function main() { + let a: u8 = 255; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/max_fail.leo b/tests/pass/parse/integers/u8/max_fail.leo new file mode 100644 index 0000000000..f2b870096d --- /dev/null +++ b/tests/pass/parse/integers/u8/max_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u8 = 256; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/min.leo b/tests/pass/parse/integers/u8/min.leo new file mode 100644 index 0000000000..a88e33c5a6 --- /dev/null +++ b/tests/pass/parse/integers/u8/min.leo @@ -0,0 +1,3 @@ +function main() { + let a: u8 = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/min_fail.leo b/tests/pass/parse/integers/u8/min_fail.leo new file mode 100644 index 0000000000..7b91dc6e1a --- /dev/null +++ b/tests/pass/parse/integers/u8/min_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a: u8 = -1; +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/mod.rs b/tests/pass/parse/integers/u8/mod.rs new file mode 100644 index 0000000000..a61e28246d --- /dev/null +++ b/tests/pass/parse/integers/u8/mod.rs @@ -0,0 +1,118 @@ +// 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::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; +use leo_ast::InputValue; +use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType}; + +test_uint!( + TestU8, + u8, + IntegerType::Unsigned(UnsignedIntegerType::U8Type(U8Type {})), + UInt8 +); + +#[test] +fn test_u8_min() { + TestU8::test_min(); +} + +#[test] +fn test_u8_min_fail() { + TestU8::test_min_fail(); +} + +#[test] +fn test_u8_max() { + TestU8::test_max(); +} + +#[test] +fn test_u8_max_fail() { + TestU8::test_max_fail(); +} + +#[test] +fn test_u8_add() { + TestU8::test_add(); +} + +#[test] +fn test_u8_sub() { + TestU8::test_sub(); +} + +#[test] +fn test_u8_mul() { + TestU8::test_mul(); +} + +#[test] +fn test_u8_div() { + TestU8::test_div(); +} + +#[test] +fn test_u8_pow() { + TestU8::test_pow(); +} + +#[test] +fn test_u8_eq() { + TestU8::test_eq(); +} + +#[test] +fn test_u8_ne() { + TestU8::test_ne(); +} + +#[test] +fn test_u8_ge() { + TestU8::test_ge(); +} + +#[test] +fn test_u8_gt() { + TestU8::test_gt(); +} + +#[test] +fn test_u8_le() { + TestU8::test_le(); +} + +#[test] +fn test_u8_lt() { + TestU8::test_lt(); +} + +#[test] +fn test_u8_console_assert() { + TestU8::test_console_assert(); +} + +#[test] +fn test_u8_ternary() { + TestU8::test_ternary(); +} diff --git a/tests/pass/parse/integers/u8/mul.leo b/tests/pass/parse/integers/u8/mul.leo new file mode 100644 index 0000000000..11acf4688b --- /dev/null +++ b/tests/pass/parse/integers/u8/mul.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: u8) { + console.assert(a * b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/ne.leo b/tests/pass/parse/integers/u8/ne.leo new file mode 100644 index 0000000000..e75194a2f2 --- /dev/null +++ b/tests/pass/parse/integers/u8/ne.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: bool) { + console.assert(a != b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/pow.leo b/tests/pass/parse/integers/u8/pow.leo new file mode 100644 index 0000000000..928ab73b0d --- /dev/null +++ b/tests/pass/parse/integers/u8/pow.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: u8) { + console.assert(a ** b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/sub.leo b/tests/pass/parse/integers/u8/sub.leo new file mode 100644 index 0000000000..1335409c29 --- /dev/null +++ b/tests/pass/parse/integers/u8/sub.leo @@ -0,0 +1,3 @@ +function main(a: u8, b: u8, c: u8) { + console.assert(a - b == c); +} \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/ternary.leo b/tests/pass/parse/integers/u8/ternary.leo new file mode 100644 index 0000000000..ce868a5ec9 --- /dev/null +++ b/tests/pass/parse/integers/u8/ternary.leo @@ -0,0 +1,5 @@ +function main(s: bool, a: u8, b: u8, c: u8) { + let r = if s ? a : b; + + console.assert(r == c); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/array.leo b/tests/pass/parse/mutability/array.leo new file mode 100644 index 0000000000..1d51c15271 --- /dev/null +++ b/tests/pass/parse/mutability/array.leo @@ -0,0 +1,5 @@ +// Arrays are immutable by default. +function main() { + let a = [1u32]; + a[0] = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/array_mut.leo b/tests/pass/parse/mutability/array_mut.leo new file mode 100644 index 0000000000..1b86bac80f --- /dev/null +++ b/tests/pass/parse/mutability/array_mut.leo @@ -0,0 +1,7 @@ +// Adding the `mut` keyword makes an array variable mutable. +function main() { + let mut a = [1u32]; + a[0] = 0; + + console.assert(a[0] == 0u32); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/array_splice_mut.leo b/tests/pass/parse/mutability/array_splice_mut.leo new file mode 100644 index 0000000000..57cc67e872 --- /dev/null +++ b/tests/pass/parse/mutability/array_splice_mut.leo @@ -0,0 +1,9 @@ +// Adding the `mut` keyword makes an array variable mutable. +function main() { + let mut a = [1u32, 2u32, 3u32]; + a[0u32..2u32] = [4u32, 5u32]; + + console.assert(a[0] == 4u32); + console.assert(a[1] == 5u32); + console.assert(a[2] == 3u32); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/array_tuple_mut.leo b/tests/pass/parse/mutability/array_tuple_mut.leo new file mode 100644 index 0000000000..e0096bd7ac --- /dev/null +++ b/tests/pass/parse/mutability/array_tuple_mut.leo @@ -0,0 +1,8 @@ +// Adding the `mut` keyword makes an array variable mutable. +function main() { + let mut a = [(1u32, 2u32)]; + a[0u32].1 = 3u32; + + console.assert(a[0u32].0 == 1u32); + console.assert(a[0u32].1 == 3u32); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/circuit.leo b/tests/pass/parse/mutability/circuit.leo new file mode 100644 index 0000000000..be1c568836 --- /dev/null +++ b/tests/pass/parse/mutability/circuit.leo @@ -0,0 +1,9 @@ +// Circuits are immutable by default. +circuit Foo { + x: u32 +} + +function main() { + let a = Foo { x: 1 }; + a.x = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/circuit_function_mut.leo b/tests/pass/parse/mutability/circuit_function_mut.leo new file mode 100644 index 0000000000..eba1d02c0e --- /dev/null +++ b/tests/pass/parse/mutability/circuit_function_mut.leo @@ -0,0 +1,9 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + function bar() {} +} + +function main() { + let mut a = Foo { x: 1 }; + a.bar = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/circuit_mut.leo b/tests/pass/parse/mutability/circuit_mut.leo new file mode 100644 index 0000000000..27bd6109b2 --- /dev/null +++ b/tests/pass/parse/mutability/circuit_mut.leo @@ -0,0 +1,11 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + x: u32 +} + +function main() { + let mut a = Foo { x: 1 }; + a.x = 0; + + console.assert(a.x == 0u32); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/circuit_static_function_mut.leo b/tests/pass/parse/mutability/circuit_static_function_mut.leo new file mode 100644 index 0000000000..eba1d02c0e --- /dev/null +++ b/tests/pass/parse/mutability/circuit_static_function_mut.leo @@ -0,0 +1,9 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + function bar() {} +} + +function main() { + let mut a = Foo { x: 1 }; + a.bar = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/circuit_variable_mut.leo b/tests/pass/parse/mutability/circuit_variable_mut.leo new file mode 100644 index 0000000000..27bd6109b2 --- /dev/null +++ b/tests/pass/parse/mutability/circuit_variable_mut.leo @@ -0,0 +1,11 @@ +// Adding the `mut` keyword makes a circuit variable mutable. +circuit Foo { + x: u32 +} + +function main() { + let mut a = Foo { x: 1 }; + a.x = 0; + + console.assert(a.x == 0u32); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/const.leo b/tests/pass/parse/mutability/const.leo new file mode 100644 index 0000000000..d2a3a6ac2b --- /dev/null +++ b/tests/pass/parse/mutability/const.leo @@ -0,0 +1,5 @@ +// Let variables are immutable by default. +function main() { + let a = 1u32; + a = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/function_input.leo b/tests/pass/parse/mutability/function_input.leo new file mode 100644 index 0000000000..1ef3ce1f02 --- /dev/null +++ b/tests/pass/parse/mutability/function_input.leo @@ -0,0 +1,4 @@ +// Function input are immutable by default. +function main(a: bool) { + a = false; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/function_input_mut.leo b/tests/pass/parse/mutability/function_input_mut.leo new file mode 100644 index 0000000000..2df24b227c --- /dev/null +++ b/tests/pass/parse/mutability/function_input_mut.leo @@ -0,0 +1,6 @@ +// Adding the `mut` keyword makes a function variable mutable. +function main(mut a: bool) { + a = true; + + console.assert(a == true); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/let.leo b/tests/pass/parse/mutability/let.leo new file mode 100644 index 0000000000..477e6b35f5 --- /dev/null +++ b/tests/pass/parse/mutability/let.leo @@ -0,0 +1,5 @@ +// Variables are immutable by default. +function main() { + let a = 1u32; + a = 0; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/let_mut.leo b/tests/pass/parse/mutability/let_mut.leo new file mode 100644 index 0000000000..5766d144d3 --- /dev/null +++ b/tests/pass/parse/mutability/let_mut.leo @@ -0,0 +1,7 @@ +// Adding the `mut` keyword makes a variable mutable. +function main() { + let mut a = 1u32; + a = 0; + + console.assert(a == 0u32); +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/let_mut_nested.leo b/tests/pass/parse/mutability/let_mut_nested.leo new file mode 100644 index 0000000000..27121f6e48 --- /dev/null +++ b/tests/pass/parse/mutability/let_mut_nested.leo @@ -0,0 +1,5 @@ +function main () { + let mut x = 2u8; + let mut y = x; + let z = y / 2u8; +} \ No newline at end of file diff --git a/tests/pass/parse/mutability/swap.leo b/tests/pass/parse/mutability/swap.leo new file mode 100644 index 0000000000..0a209149ee --- /dev/null +++ b/tests/pass/parse/mutability/swap.leo @@ -0,0 +1,20 @@ +// Swap two elements of an array. +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; + return a +} + +function main() { + let mut arr: [u32; 2] = [0, 1]; + let expected: [u32; 2] = [1, 0]; + + // Do swap. + let actual = swap(arr, 0, 1); + + // Check result. + for i in 0..2 { + console.assert(expected[i] == actual[i]); + } +} \ No newline at end of file diff --git a/tests/pass/parse/statements/assert.leo b/tests/pass/parse/statements/assert.leo new file mode 100644 index 0000000000..f3d20b461d --- /dev/null +++ b/tests/pass/parse/statements/assert.leo @@ -0,0 +1,7 @@ +function main(a: u32) { + if a == 1 { + console.assert(a == 1); + } else { + console.assert(a == 0); + } +} diff --git a/tests/pass/parse/statements/block.leo b/tests/pass/parse/statements/block.leo new file mode 100644 index 0000000000..8650808041 --- /dev/null +++ b/tests/pass/parse/statements/block.leo @@ -0,0 +1,9 @@ +function main() { + let mut x = 4u32; + + { + x = 5u32; + } + + console.assert(x == 5u32); +} \ No newline at end of file diff --git a/tests/pass/parse/statements/chain.leo b/tests/pass/parse/statements/chain.leo new file mode 100644 index 0000000000..dbc0e1f38c --- /dev/null +++ b/tests/pass/parse/statements/chain.leo @@ -0,0 +1,13 @@ +function main(a: u32, b: u32) { + let mut c = 0u32; + + if a == 1 { + c = 1; + } else if a == 2 { + c = 2; + } else { + c = 3; + } + + console.assert(c == b); +} \ No newline at end of file diff --git a/tests/pass/parse/statements/for_loop.leo b/tests/pass/parse/statements/for_loop.leo new file mode 100644 index 0000000000..060d27d965 --- /dev/null +++ b/tests/pass/parse/statements/for_loop.leo @@ -0,0 +1,13 @@ +function main(a: bool) { + let mut b = 0u32; + + if a { + for i in 0..4 { + b += i; + } + } + + let r: u32 = if a ? 6 : 0; + + console.assert(r == b); +} diff --git a/tests/pass/parse/statements/iteration_basic.leo b/tests/pass/parse/statements/iteration_basic.leo new file mode 100644 index 0000000000..103c9abb9e --- /dev/null +++ b/tests/pass/parse/statements/iteration_basic.leo @@ -0,0 +1,8 @@ +function main() { + let mut x = 4u32; + for i in 0..3 { + x -= 1; + } + + console.assert(x == 1u32); +} \ No newline at end of file diff --git a/tests/pass/parse/statements/multiple_returns.leo b/tests/pass/parse/statements/multiple_returns.leo new file mode 100644 index 0000000000..b8dd869b47 --- /dev/null +++ b/tests/pass/parse/statements/multiple_returns.leo @@ -0,0 +1,7 @@ +function main(input) -> u32 { + if input.registers.a == 0u32 { + return 0u32 + } else { + return 1u32 + } +} \ No newline at end of file diff --git a/tests/pass/parse/statements/mutate.leo b/tests/pass/parse/statements/mutate.leo new file mode 100644 index 0000000000..458d3d0d60 --- /dev/null +++ b/tests/pass/parse/statements/mutate.leo @@ -0,0 +1,15 @@ +function main(a: u32) { + let mut b = 5u32; + + if a == 1 { + b = 1; + } else { + b = 0; + } + + if a == 1 { + console.assert(b == 1); + } else { + console.assert(b == 0); + } +} diff --git a/tests/pass/parse/statements/nested.leo b/tests/pass/parse/statements/nested.leo new file mode 100644 index 0000000000..3596f889d1 --- /dev/null +++ b/tests/pass/parse/statements/nested.leo @@ -0,0 +1,12 @@ +function main(a: bool, b: bool, c: u32) { + let mut d = 0u32; + + if a { + d += 1; + if b { + d += 2; + } + } + + console.assert(d == c); +} \ No newline at end of file diff --git a/tests/pass/parse/statements/num_returns_fail.leo b/tests/pass/parse/statements/num_returns_fail.leo new file mode 100644 index 0000000000..14b2fe6ad0 --- /dev/null +++ b/tests/pass/parse/statements/num_returns_fail.leo @@ -0,0 +1,3 @@ +function main() -> (bool, bool) { + return true +} \ No newline at end of file diff --git a/tests/pass/parse/statements/ternary_basic.leo b/tests/pass/parse/statements/ternary_basic.leo new file mode 100644 index 0000000000..1f9c1f65a2 --- /dev/null +++ b/tests/pass/parse/statements/ternary_basic.leo @@ -0,0 +1,5 @@ +function main(a: bool, b: bool) { + let c = if a ? true : false; + + let d = c == b; +} \ No newline at end of file diff --git a/tests/pass/parse/syntax/compare_mismatched_types.leo b/tests/pass/parse/syntax/compare_mismatched_types.leo new file mode 100644 index 0000000000..8cf6327cb3 --- /dev/null +++ b/tests/pass/parse/syntax/compare_mismatched_types.leo @@ -0,0 +1,3 @@ +function main() { + let a = -5i8 > 342u32; +} \ No newline at end of file diff --git a/tests/pass/parse/syntax/undefined.leo b/tests/pass/parse/syntax/undefined.leo new file mode 100644 index 0000000000..856b07589a --- /dev/null +++ b/tests/pass/parse/syntax/undefined.leo @@ -0,0 +1,3 @@ +function main() -> bool { + return a +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/access.leo b/tests/pass/parse/tuples/access.leo new file mode 100644 index 0000000000..196e9d058c --- /dev/null +++ b/tests/pass/parse/tuples/access.leo @@ -0,0 +1,6 @@ +function main() { + let a = (true, false); + + console.assert(a.0 == true); + console.assert(a.1 == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/basic.leo b/tests/pass/parse/tuples/basic.leo new file mode 100644 index 0000000000..37c728611c --- /dev/null +++ b/tests/pass/parse/tuples/basic.leo @@ -0,0 +1,3 @@ +function main() { + let a = (true, false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/function.leo b/tests/pass/parse/tuples/function.leo new file mode 100644 index 0000000000..b318348813 --- /dev/null +++ b/tests/pass/parse/tuples/function.leo @@ -0,0 +1,10 @@ +function foo() -> (bool, bool) { + return (true, false) +} + +function main() { + let a = foo(); + + console.assert(a.0 == true); + console.assert(a.1 == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/function_multiple.leo b/tests/pass/parse/tuples/function_multiple.leo new file mode 100644 index 0000000000..39848377c6 --- /dev/null +++ b/tests/pass/parse/tuples/function_multiple.leo @@ -0,0 +1,10 @@ +function foo() -> (bool, bool) { + return (true, false) +} + +function main() { + let (a, b) = foo(); + + console.assert(a == true); + console.assert(b == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/function_typed.leo b/tests/pass/parse/tuples/function_typed.leo new file mode 100644 index 0000000000..8af2c907ca --- /dev/null +++ b/tests/pass/parse/tuples/function_typed.leo @@ -0,0 +1,10 @@ +function foo() -> (bool, bool) { + return (true, false) +} + +function main() { + let a: (bool, bool) = foo(); + + console.assert(a.0 == true); + console.assert(a.1 == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/input.leo b/tests/pass/parse/tuples/input.leo new file mode 100644 index 0000000000..f7672a3b03 --- /dev/null +++ b/tests/pass/parse/tuples/input.leo @@ -0,0 +1,3 @@ +function main(a: (bool, bool)) { + +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/multiple.leo b/tests/pass/parse/tuples/multiple.leo new file mode 100644 index 0000000000..b7627dad2a --- /dev/null +++ b/tests/pass/parse/tuples/multiple.leo @@ -0,0 +1,6 @@ +function main() { + let (a, b) = (true, false); + + console.assert(a == true); + console.assert(b == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/multiple_typed.leo b/tests/pass/parse/tuples/multiple_typed.leo new file mode 100644 index 0000000000..29fc7ef877 --- /dev/null +++ b/tests/pass/parse/tuples/multiple_typed.leo @@ -0,0 +1,6 @@ +function main() { + let (a, b): (bool, bool) = (true, false); + + console.assert(a == true); + console.assert(b == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/nested.leo b/tests/pass/parse/tuples/nested.leo new file mode 100644 index 0000000000..a9599b360c --- /dev/null +++ b/tests/pass/parse/tuples/nested.leo @@ -0,0 +1,4 @@ +function main() { + let a = (true, false); + let b = (true, a); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/nested_access.leo b/tests/pass/parse/tuples/nested_access.leo new file mode 100644 index 0000000000..5edba64e24 --- /dev/null +++ b/tests/pass/parse/tuples/nested_access.leo @@ -0,0 +1,8 @@ +function main() { + let a = (true, false); + let b = (true, a); + + console.assert(b.0 == true); + console.assert(b.1.0 == true); + console.assert(b.1.1 == false); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/nested_typed.leo b/tests/pass/parse/tuples/nested_typed.leo new file mode 100644 index 0000000000..2e68117a2b --- /dev/null +++ b/tests/pass/parse/tuples/nested_typed.leo @@ -0,0 +1,4 @@ +function main() { + let a = (true, false); + let b: (bool, (bool, bool)) = (true, a); +} \ No newline at end of file diff --git a/tests/pass/parse/tuples/typed.leo b/tests/pass/parse/tuples/typed.leo new file mode 100644 index 0000000000..8cd2ed79db --- /dev/null +++ b/tests/pass/parse/tuples/typed.leo @@ -0,0 +1,3 @@ +function main() { + let a: (bool, bool) = (true, false); +} \ No newline at end of file From 23416e96333bab51469a933f3f48ce7706c5e230 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:29:36 -0800 Subject: [PATCH 34/92] cargo update --- Cargo.lock | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc53565464..c87d7dd80f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -186,7 +186,7 @@ dependencies = [ "block-padding", "byte-tools", "byteorder", - "generic-array 0.12.3", + "generic-array 0.12.4", ] [[package]] @@ -575,7 +575,7 @@ version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" dependencies = [ - "generic-array 0.12.3", + "generic-array 0.12.4", ] [[package]] @@ -844,9 +844,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" dependencies = [ "typenum", ] @@ -955,9 +955,9 @@ dependencies = [ [[package]] name = "hex" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "http" @@ -1399,9 +1399,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.86" +version = "0.2.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" +checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" [[package]] name = "libloading" @@ -1718,9 +1718,9 @@ checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" [[package]] name = "once_cell" -version = "1.7.0" +version = "1.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10acf907b94fc1b1a152d08ef97e7759650268cf986bf127f387e602b02c7e5a" +checksum = "af8b08b04175473088b46763e51ee54da5f9a164bc162f615b91bc179dbf15a3" [[package]] name = "oorandom" @@ -1888,9 +1888,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.4" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" +checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" [[package]] name = "pin-utils" @@ -2396,9 +2396,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.63" +version = "1.0.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6" +checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" dependencies = [ "itoa", "ryu", @@ -2858,9 +2858,9 @@ dependencies = [ [[package]] name = "tinytemplate" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ada8616fad06a2d0c455adc530de4ef57605a8120cc65da9653e0e9623ca74" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" dependencies = [ "serde", "serde_json", @@ -3305,9 +3305,9 @@ dependencies = [ [[package]] name = "zip" -version = "0.5.10" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a8977234acab718eb2820494b2f96cbb16004c19dddf88b7445b27381450997" +checksum = "8264fcea9b7a036a4a5103d7153e988dbc2ebbafb34f68a3c2d404b6b82d74b6" dependencies = [ "byteorder", "bzip2", From c9f70800fdedba14b2320040777d2cfbb7527e13 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:33:21 -0800 Subject: [PATCH 35/92] Update .tomls to 0.2.0 --- .rusty-hook.toml | 2 +- Cargo.lock | 154 +++++++++++++++++------------------------ Cargo.toml | 16 ++--- compiler/Cargo.toml | 20 ++---- gadgets/Cargo.toml | 10 +-- state/Cargo.toml | 20 ++---- synthesizer/Cargo.toml | 10 +-- 7 files changed, 81 insertions(+), 151 deletions(-) diff --git a/.rusty-hook.toml b/.rusty-hook.toml index bcdbfd8fa4..21760cec6d 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,5 +1,5 @@ [hooks] -pre-commit = "cargo clippy && cargo +nightly fmt --all -- --check" +#pre-commit = "cargo clippy && cargo +nightly fmt --all -- --check" [logging] verbose = true diff --git a/Cargo.lock b/Cargo.lock index c87d7dd80f..f1014ea8a0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1243,9 +1243,7 @@ dependencies = [ "snarkvm-algorithms", "snarkvm-curves", "snarkvm-dpc", - "snarkvm-errors", "snarkvm-gadgets", - "snarkvm-models", "snarkvm-objects", "snarkvm-utilities", "thiserror", @@ -1260,8 +1258,6 @@ dependencies = [ "rand", "rand_core", "rand_xorshift", - "snarkvm-errors", - "snarkvm-models", "snarkvm-utilities", "thiserror", ] @@ -1335,9 +1331,7 @@ dependencies = [ "serde_json", "snarkvm-algorithms", "snarkvm-curves", - "snarkvm-errors", "snarkvm-gadgets", - "snarkvm-models", "snarkvm-utilities", "structopt", "thiserror", @@ -1377,8 +1371,6 @@ dependencies = [ "snarkvm-algorithms", "snarkvm-curves", "snarkvm-dpc", - "snarkvm-errors", - "snarkvm-models", "snarkvm-objects", "snarkvm-storage", "snarkvm-utilities", @@ -1393,8 +1385,6 @@ dependencies = [ "serde", "serde_json", "snarkvm-curves", - "snarkvm-errors", - "snarkvm-models", ] [[package]] @@ -2480,9 +2470,9 @@ checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" [[package]] name = "snarkvm-algorithms" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d3de956d0221ff897ebcc2a36e8a88482dee06acaebce67f7819c41be843a11" +checksum = "fbb6ec1d5757858ec54ccbb211c7366e601cb495e4d6c3f1a6dd16507834f2b0" dependencies = [ "blake2", "derivative", @@ -2493,33 +2483,35 @@ dependencies = [ "rayon", "sha2", "smallvec", - "snarkvm-errors", - "snarkvm-models", + "snarkvm-curves", + "snarkvm-fields", "snarkvm-profiler", + "snarkvm-r1cs", "snarkvm-utilities", + "thiserror", ] [[package]] name = "snarkvm-curves" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd45a9c60e9c81bbfc4568f8c7d4c3fd0b6dc7b75916086eb16795fc3ea854b2" +checksum = "fb783fb37b05716640c50fbc180758dd999e34837767dbe6170a961e89ae0098" dependencies = [ "derivative", "rand", "rand_xorshift", "rustc_version 0.3.3", "serde", - "snarkvm-errors", - "snarkvm-models", + "snarkvm-fields", "snarkvm-utilities", + "thiserror", ] [[package]] name = "snarkvm-derives" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b3339f816745870549adbcf7f5b1db3441c8d73377278fec9c7829a87ebdc07" +checksum = "f5055a2424bfceca62bee32ec1d7ce86149c7daf880dbc71eb0b6001ab20043f" dependencies = [ "proc-macro-crate", "proc-macro-error", @@ -2530,11 +2522,13 @@ dependencies = [ [[package]] name = "snarkvm-dpc" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d43c0c63eedf067284496e068527f2448ea3ecba1ba9c44d486c3fb66e04e2" +checksum = "e9837ffa247354b6e3590e5482e3e109afb70e6af9953b475cd1ccdcd0ca40e2" dependencies = [ "anyhow", + "base58", + "bech32", "blake2", "derivative", "hex", @@ -2542,75 +2536,56 @@ dependencies = [ "rand", "snarkvm-algorithms", "snarkvm-curves", - "snarkvm-errors", + "snarkvm-fields", "snarkvm-gadgets", - "snarkvm-models", "snarkvm-objects", "snarkvm-parameters", "snarkvm-profiler", + "snarkvm-r1cs", "snarkvm-utilities", + "thiserror", ] [[package]] -name = "snarkvm-errors" -version = "0.0.6" +name = "snarkvm-fields" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce13866aa05abf33972261ab9803b2f223bd5bee9e5336aac0618c2aa8249f24" +checksum = "4d23901c74a59ddee3792f00a1bbc7846f35900f087f0cb0731a42d7a8601f71" dependencies = [ - "base58", - "bech32", "bincode", - "curl", - "hex", + "derivative", + "rand", + "rand_xorshift", + "serde", + "snarkvm-utilities", "thiserror", ] [[package]] name = "snarkvm-gadgets" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f6de0307dba124bf510fdf52b870a9ba76ad3177b2b742f91c87ee39a038d8" +checksum = "03e586f5528c542e8ccc0d9036667f00956dcd03433ed35953ff345db18854ea" dependencies = [ "derivative", "digest 0.9.0", "itertools 0.10.0", "snarkvm-algorithms", "snarkvm-curves", - "snarkvm-errors", - "snarkvm-models", - "snarkvm-utilities", -] - -[[package]] -name = "snarkvm-models" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21afc37b95e310387d9a7ea25e439c7e5f444896a760e5f3893d4e6ef387d48c" -dependencies = [ - "anyhow", - "bincode", - "cfg-if 1.0.0", - "derivative", - "fxhash", - "indexmap", - "itertools 0.10.0", - "rand", - "rand_xorshift", - "serde", - "snarkvm-errors", + "snarkvm-fields", + "snarkvm-r1cs", "snarkvm-utilities", + "thiserror", ] [[package]] name = "snarkvm-objects" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "724332214a919a1c14f07c458c191319101cc3252319cf2f9e8f122fd2a5f5d5" +checksum = "58db14d80c9d5496badf4c0aec9c75e7c40dbcdd50480b924968c36a4211b4d5" dependencies = [ - "base58", - "bech32", + "anyhow", "chrono", - "derivative", "hex", "once_cell", "rand", @@ -2618,53 +2593,49 @@ dependencies = [ "sha2", "snarkvm-algorithms", "snarkvm-curves", - "snarkvm-errors", - "snarkvm-models", "snarkvm-utilities", + "thiserror", ] [[package]] name = "snarkvm-parameters" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e69a1db7cba8b07538943c0a9c547f515a4d726d8863dc1d40c5f9266a8af27" +checksum = "0ef0c06581616f1f7d8f993c8ab89f6f804bd2e2712b3db03f791edbfad340c8" dependencies = [ "curl", "hex", "snarkvm-algorithms", - "snarkvm-errors", - "snarkvm-models", - "snarkvm-polycommit", - "snarkvm-utilities", -] - -[[package]] -name = "snarkvm-polycommit" -version = "0.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1f29eab35b3214dee0847deae11ea3af13c42e3beefb8cf7c22ed567cf3a70e" -dependencies = [ - "derivative", - "digest 0.9.0", - "rand_core", - "snarkvm-algorithms", - "snarkvm-errors", - "snarkvm-models", - "snarkvm-profiler", "snarkvm-utilities", + "thiserror", ] [[package]] name = "snarkvm-profiler" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ce2100d7198526f11290d70d83a1bb6a1dd578f43821ceb544421ebd398312" +checksum = "cf2fd43f8abfc3e87f03fd13ea260d14133f4716fa99eaf1578799ae85676530" + +[[package]] +name = "snarkvm-r1cs" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f34179150793df4add4c8ee67929ea7a3606c272b4849d9cfc4df2779a49ac58" +dependencies = [ + "cfg-if 1.0.0", + "fxhash", + "indexmap", + "itertools 0.10.0", + "snarkvm-curves", + "snarkvm-fields", + "snarkvm-utilities", +] [[package]] name = "snarkvm-storage" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b57ef27e6b3073f4681332ac018158cea1f28c8a14e2187085e2c656f1641550" +checksum = "6b5602ba49e2cb2726931262e961a38a95955aa3bf1881c9e84b62f8176b3079" dependencies = [ "anyhow", "bincode", @@ -2674,8 +2645,7 @@ dependencies = [ "rocksdb", "serde", "snarkvm-algorithms", - "snarkvm-errors", - "snarkvm-models", + "snarkvm-dpc", "snarkvm-objects", "snarkvm-parameters", "snarkvm-utilities", @@ -2684,14 +2654,14 @@ dependencies = [ [[package]] name = "snarkvm-utilities" -version = "0.0.6" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "272b8758ef7fed8dc70cc01ecfd13e9add23edbabcaae1c5c7cfaca54d0fcae5" +checksum = "307edca1c7fe02a498933808b70feb73ae5d60f8dad2e9ecba3f9cd65569d6a4" dependencies = [ "bincode", "rand", "snarkvm-derives", - "snarkvm-errors", + "thiserror", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 84ef126ea8..d222296ea9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -72,27 +72,19 @@ path = "./synthesizer" version = "1.2.3" [dependencies.snarkvm-algorithms] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-curves] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-errors] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-models] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.6" +version = "0.2.0" [dependencies.anyhow] version = "1.0" diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 6e9b5c71d6..513038078e 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -50,31 +50,23 @@ path = "../asg" version = "1.2.3" [dependencies.snarkvm-curves] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-errors] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-gadgets] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-models] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-objects] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.6" +version = "0.2.0" [dependencies.bincode] version = "1.3" @@ -115,7 +107,7 @@ version = "0.3" default-features = false [dev-dependencies.snarkvm-algorithms] -version = "0.0.6" +version = "0.2.0" default-features = false [features] diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index b32f462072..656e88f827 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -17,16 +17,8 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "GPL-3.0" edition = "2018" -[dependencies.snarkvm-errors] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-models] -version = "0.0.6" -default-features = false - [dependencies.snarkvm-utilities] -version = "0.0.6" +version = "0.2.0" [dependencies.rand] version = "0.8" diff --git a/state/Cargo.toml b/state/Cargo.toml index 0482e51f8d..e162c8a004 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -26,31 +26,23 @@ path = "../ast" version = "1.2.3" [dependencies.snarkvm-algorithms] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-curves] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-dpc] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-errors] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-models] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-objects] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.snarkvm-utilities] -version = "0.0.6" +version = "0.2.0" [dependencies.indexmap] version = "1.6.1" @@ -66,7 +58,7 @@ version = "0.3" version = "1.0" [dev-dependencies.snarkvm-storage] -version = "0.0.6" +version = "0.2.0" [dev-dependencies.rand_core] version = "0.6.2" diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index a9e497988d..04dcbf0845 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -18,15 +18,7 @@ license = "GPL-3.0" edition = "2018" [dependencies.snarkvm-curves] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-errors] -version = "0.0.6" -default-features = false - -[dependencies.snarkvm-models] -version = "0.0.6" +version = "0.2.0" default-features = false [dependencies.num-bigint] From 4f50b44a63753fe309434bbdbe9ba3e2430a3840 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:33:51 -0800 Subject: [PATCH 36/92] itemize imports --- .rustfmt.toml | 2 +- asg/src/checks/return_path.rs | 18 ++--- asg/src/const_value.rs | 8 +- asg/src/context.rs | 3 +- asg/src/error/mod.rs | 3 +- asg/src/expression/array_access.rs | 11 ++- asg/src/expression/array_init.rs | 11 ++- asg/src/expression/array_inline.rs | 11 ++- asg/src/expression/array_range_access.rs | 11 ++- asg/src/expression/binary.rs | 14 +++- asg/src/expression/call.rs | 31 ++++---- asg/src/expression/circuit_access.rs | 28 ++++--- asg/src/expression/circuit_init.rs | 31 ++++---- asg/src/expression/constant.rs | 26 +++---- asg/src/expression/mod.rs | 9 ++- asg/src/expression/ternary.rs | 11 ++- asg/src/expression/tuple_access.rs | 11 ++- asg/src/expression/tuple_init.rs | 11 ++- asg/src/expression/unary.rs | 11 ++- asg/src/expression/variable_ref.rs | 30 ++++---- asg/src/import.rs | 5 +- asg/src/input.rs | 7 +- asg/src/lib.rs | 4 +- asg/src/node.rs | 22 +++--- asg/src/prelude.rs | 4 +- asg/src/program/circuit.rs | 8 +- asg/src/program/function.rs | 29 ++++---- asg/src/program/mod.rs | 15 +++- asg/src/reducer/monoidal_director.rs | 4 +- asg/src/reducer/monoidal_reducer.rs | 5 +- asg/src/reducer/visitor.rs | 4 +- asg/src/reducer/visitor_director.rs | 7 +- asg/src/scope.rs | 14 +++- asg/src/statement/assign.rs | 34 ++++----- asg/src/statement/block.rs | 8 +- asg/src/statement/conditional.rs | 11 ++- asg/src/statement/console.rs | 10 ++- asg/src/statement/definition.rs | 32 ++++---- asg/src/statement/expression.rs | 9 ++- asg/src/statement/iteration.rs | 27 ++++--- asg/src/statement/mod.rs | 7 +- asg/src/statement/return_.rs | 10 ++- asg/src/variable.rs | 4 +- asg/tests/pass/form_ast.rs | 3 +- asg/tests/pass/import/mod.rs | 5 +- ast/benches/leo_ast.rs | 7 +- ast/src/annotation.rs | 17 +++-- ast/src/circuits/circuit.rs | 6 +- .../circuit_implied_variable_definition.rs | 6 +- ast/src/circuits/circuit_member.rs | 14 ++-- .../circuits/circuit_variable_definition.rs | 6 +- ast/src/common/array_dimensions.rs | 3 +- ast/src/common/identifier.rs | 51 ++++++------- ast/src/common/input_keyword.rs | 6 +- ast/src/common/mut_self_keyword.rs | 6 +- ast/src/common/positive_number.rs | 3 +- ast/src/common/self_keyword.rs | 6 +- ast/src/common/span.rs | 6 +- ast/src/common/spread_or_expression.rs | 13 ++-- ast/src/errors/deprecated.rs | 9 ++- ast/src/errors/error.rs | 3 +- ast/src/expression/mod.rs | 73 +++++++++---------- ast/src/functions/function.rs | 10 ++- ast/src/functions/input/function_input.rs | 8 +- ast/src/functions/input/input_variable.rs | 10 ++- ast/src/functions/test_function.rs | 6 +- ast/src/groups/group_coordinate.rs | 27 +++---- ast/src/groups/group_value.rs | 22 +++--- ast/src/imports/import.rs | 6 +- ast/src/imports/import_symbol.rs | 6 +- ast/src/imports/package.rs | 7 +- ast/src/imports/package_access.rs | 8 +- ast/src/imports/package_or_packages.rs | 6 +- ast/src/imports/packages.rs | 7 +- ast/src/input/input.rs | 16 ++-- ast/src/input/input_value.rs | 26 +++++-- ast/src/input/parameters/parameter.rs | 4 +- ast/src/input/program_input/main_input.rs | 3 +- ast/src/input/program_input/program_input.rs | 11 +-- ast/src/input/program_input/registers.rs | 6 +- .../private_state/private_state.rs | 10 +-- .../program_state/private_state/record.rs | 6 +- .../program_state/private_state/state_leaf.rs | 6 +- ast/src/input/program_state/program_state.rs | 13 ++-- .../public_state/public_state.rs | 7 +- .../input/program_state/public_state/state.rs | 6 +- ast/src/main.rs | 7 +- ast/src/program.rs | 24 +++--- ast/src/statements/assign/assignee.rs | 17 +++-- ast/src/statements/assign/mod.rs | 7 +- ast/src/statements/block.rs | 7 +- ast/src/statements/conditional.rs | 12 ++- .../statements/console/console_function.rs | 18 ++--- .../statements/console/console_statement.rs | 7 +- .../statements/console/formatted_container.rs | 6 +- .../statements/console/formatted_string.rs | 8 +- ast/src/statements/definition/declare.rs | 3 +- ast/src/statements/definition/mod.rs | 8 +- .../statements/definition/variable_name.rs | 7 +- ast/src/statements/expression.rs | 7 +- ast/src/statements/iteration.rs | 9 ++- ast/src/statements/return_statement.rs | 7 +- ast/src/statements/statement.rs | 7 +- ast/src/types/integer_type.rs | 19 ++--- ast/src/types/type_.rs | 23 +++--- ast/tests/serialization/json.rs | 9 ++- compiler/src/compiler.rs | 44 ++++++----- compiler/src/console/assert.rs | 22 +++--- compiler/src/console/console.rs | 15 ++-- compiler/src/console/format.rs | 7 +- compiler/src/constraints/constraints.rs | 13 ++-- compiler/src/definition/definition.rs | 4 +- compiler/src/errors/compiler.rs | 8 +- compiler/src/errors/console.rs | 3 +- compiler/src/errors/expression.rs | 14 +++- compiler/src/errors/function.rs | 23 +++--- compiler/src/errors/import.rs | 5 +- compiler/src/errors/output_bytes.rs | 6 +- compiler/src/errors/output_file.rs | 3 +- compiler/src/errors/statement.rs | 10 ++- compiler/src/errors/value/address.rs | 6 +- compiler/src/errors/value/boolean.rs | 3 +- compiler/src/errors/value/field.rs | 3 +- compiler/src/errors/value/group.rs | 3 +- compiler/src/errors/value/integer.rs | 5 +- compiler/src/errors/value/value.rs | 9 ++- compiler/src/expression/arithmetic/add.rs | 7 +- compiler/src/expression/arithmetic/div.rs | 7 +- compiler/src/expression/arithmetic/mul.rs | 7 +- compiler/src/expression/arithmetic/negate.rs | 7 +- compiler/src/expression/arithmetic/pow.rs | 7 +- compiler/src/expression/arithmetic/sub.rs | 7 +- compiler/src/expression/array/access.rs | 11 ++- compiler/src/expression/array/array.rs | 11 ++- compiler/src/expression/array/index.rs | 11 ++- compiler/src/expression/binary/binary.rs | 8 +- compiler/src/expression/circuit/access.rs | 11 ++- compiler/src/expression/circuit/circuit.rs | 18 +++-- .../src/expression/conditional/conditional.rs | 15 ++-- compiler/src/expression/expression.rs | 34 +++++---- .../src/expression/function/core_circuit.rs | 12 ++- compiler/src/expression/function/function.rs | 12 ++- compiler/src/expression/logical/and.rs | 11 +-- compiler/src/expression/logical/not.rs | 4 +- compiler/src/expression/logical/or.rs | 11 +-- compiler/src/expression/relational/eq.rs | 16 ++-- compiler/src/expression/relational/ge.rs | 7 +- compiler/src/expression/relational/gt.rs | 7 +- compiler/src/expression/relational/le.rs | 7 +- compiler/src/expression/relational/lt.rs | 7 +- compiler/src/expression/tuple/access.rs | 11 ++- compiler/src/expression/tuple/tuple.rs | 8 +- .../expression/variable_ref/variable_ref.rs | 5 +- compiler/src/function/function.rs | 16 ++-- compiler/src/function/input/array.rs | 11 ++- compiler/src/function/input/input_keyword.rs | 17 ++++- compiler/src/function/input/input_section.rs | 17 ++++- .../src/function/input/main_function_input.rs | 28 ++++--- compiler/src/function/input/tuple.rs | 11 ++- compiler/src/function/main_function.rs | 12 ++- compiler/src/function/mut_target.rs | 33 ++++----- compiler/src/function/result/result.rs | 26 +++---- compiler/src/output/output_bytes.rs | 12 ++- compiler/src/output/output_file.rs | 11 ++- compiler/src/prelude/blake2s.rs | 21 +++--- compiler/src/prelude/mod.rs | 10 ++- compiler/src/program/program.rs | 3 +- compiler/src/statement/assign/assign.rs | 21 +++--- compiler/src/statement/assign/assignee.rs | 13 +++- compiler/src/statement/block/block.rs | 12 +-- .../src/statement/conditional/conditional.rs | 21 +++--- .../src/statement/definition/definition.rs | 12 ++- compiler/src/statement/iteration/iteration.rs | 25 +++---- compiler/src/statement/return_/return_.rs | 8 +- compiler/src/statement/statement.rs | 12 +-- compiler/src/value/address/address.rs | 34 +++++---- compiler/src/value/boolean/input.rs | 18 ++--- compiler/src/value/field/field_type.rs | 36 ++++----- compiler/src/value/field/input.rs | 16 ++-- compiler/src/value/group/group_type.rs | 29 ++++---- compiler/src/value/group/input.rs | 10 ++- .../src/value/group/targets/edwards_bls12.rs | 61 +++++++++------- compiler/src/value/integer/integer.rs | 39 +++++----- compiler/src/value/integer/macros.rs | 10 ++- compiler/src/value/value.rs | 23 +++--- compiler/tests/address/mod.rs | 6 +- compiler/tests/array/mod.rs | 16 ++-- compiler/tests/boolean/mod.rs | 16 ++-- compiler/tests/circuits/mod.rs | 4 +- compiler/tests/compiler/mod.rs | 6 +- compiler/tests/console/mod.rs | 14 ++-- compiler/tests/core/mod.rs | 4 +- .../core/packages/unstable/blake2s/mod.rs | 18 ++--- compiler/tests/definition/mod.rs | 4 +- compiler/tests/function/mod.rs | 6 +- compiler/tests/import/mod.rs | 6 +- .../tests/input_files/program_input/mod.rs | 5 +- .../program_input_and_program_state/mod.rs | 4 +- .../input_files/program_registers/mod.rs | 4 +- .../tests/input_files/program_state/mod.rs | 4 +- compiler/tests/integers/i128/mod.rs | 19 ++--- compiler/tests/integers/i16/mod.rs | 19 ++--- compiler/tests/integers/i32/mod.rs | 19 ++--- compiler/tests/integers/i64/mod.rs | 19 ++--- compiler/tests/integers/i8/mod.rs | 19 ++--- compiler/tests/integers/integer_tester.rs | 9 ++- compiler/tests/integers/u128/mod.rs | 18 ++--- compiler/tests/integers/u16/mod.rs | 18 ++--- compiler/tests/integers/u32/mod.rs | 18 ++--- compiler/tests/integers/u64/mod.rs | 18 ++--- compiler/tests/integers/u8/mod.rs | 18 ++--- compiler/tests/mod.rs | 23 +++--- compiler/tests/mutability/mod.rs | 5 +- compiler/tests/statements/conditional/mod.rs | 18 ++--- compiler/tests/statements/mod.rs | 5 +- compiler/tests/syntax/mod.rs | 4 +- compiler/tests/tuples/mod.rs | 3 +- gadgets/benches/integer_arithmetic.rs | 22 ++++-- gadgets/src/arithmetic/add.rs | 16 ++-- gadgets/src/arithmetic/div.rs | 3 +- gadgets/src/arithmetic/mul.rs | 3 +- gadgets/src/arithmetic/neg.rs | 7 +- gadgets/src/arithmetic/pow.rs | 3 +- gadgets/src/arithmetic/sub.rs | 3 +- gadgets/src/bits/adder.rs | 7 +- gadgets/src/bits/comparator.rs | 21 +++--- gadgets/src/bits/rca.rs | 11 +-- gadgets/src/signed_integer/arithmetic/add.rs | 38 +++++----- gadgets/src/signed_integer/arithmetic/div.rs | 42 +++++------ gadgets/src/signed_integer/arithmetic/mul.rs | 41 +++++------ gadgets/src/signed_integer/arithmetic/neg.rs | 7 +- gadgets/src/signed_integer/arithmetic/pow.rs | 31 ++++---- gadgets/src/signed_integer/arithmetic/sub.rs | 21 +++--- gadgets/src/signed_integer/relational/cmp.rs | 26 +++---- gadgets/src/signed_integer/relational/eq.rs | 18 +++-- gadgets/src/signed_integer/utilities/alloc.rs | 25 ++++--- gadgets/src/signed_integer/utilities/eq.rs | 11 +-- .../src/signed_integer/utilities/select.rs | 14 ++-- gadgets/tests/signed_integer/i128.rs | 17 +++-- gadgets/tests/signed_integer/i16.rs | 17 +++-- gadgets/tests/signed_integer/i32.rs | 17 +++-- gadgets/tests/signed_integer/i64.rs | 17 +++-- gadgets/tests/signed_integer/i8.rs | 17 +++-- grammar/benches/grammar.rs | 5 +- grammar/src/access/access.rs | 3 +- grammar/src/access/array_access.rs | 4 +- grammar/src/access/assignee_access.rs | 8 +- grammar/src/access/call_access.rs | 4 +- grammar/src/access/member_access.rs | 4 +- grammar/src/access/self_access.rs | 3 +- grammar/src/access/static_member_access.rs | 4 +- grammar/src/access/tuple_access.rs | 4 +- .../src/annotations/annotation_arguments.rs | 7 +- grammar/src/annotations/annotation_name.rs | 3 +- grammar/src/annotations/annotation_symbol.rs | 3 +- grammar/src/annotations/annotations.rs | 10 +-- grammar/src/ast.rs | 46 ++++++------ grammar/src/circuits/circuit.rs | 5 +- .../src/circuits/circuit_implied_variable.rs | 4 +- grammar/src/circuits/circuit_member.rs | 4 +- grammar/src/circuits/circuit_variable.rs | 5 +- .../circuits/circuit_variable_definition.rs | 5 +- grammar/src/common/assignee.rs | 5 +- grammar/src/common/eoi.rs | 3 +- grammar/src/common/identifier.rs | 7 +- grammar/src/common/keyword_or_identifier.rs | 5 +- grammar/src/common/mut_self_keyword.rs | 9 +-- grammar/src/common/range.rs | 4 +- grammar/src/common/range_or_expression.rs | 4 +- grammar/src/common/self_keyword.rs | 7 +- .../src/common/self_keyword_or_identifier.rs | 7 +- grammar/src/common/spread.rs | 4 +- grammar/src/common/spread_or_expression.rs | 4 +- grammar/src/common/variable_name.rs | 9 +-- grammar/src/common/variables.rs | 5 +- grammar/src/console/console_assert.rs | 4 +- grammar/src/console/console_debug.rs | 4 +- grammar/src/console/console_error.rs | 4 +- grammar/src/console/console_function.rs | 9 ++- grammar/src/console/console_function_call.rs | 11 ++- grammar/src/console/console_keyword.rs | 3 +- grammar/src/console/console_log.rs | 4 +- grammar/src/console/formatted_container.rs | 3 +- grammar/src/console/formatted_string.rs | 11 ++- .../src/definitions/annotated_definition.rs | 5 +- grammar/src/definitions/definition.rs | 13 ++-- grammar/src/definitions/deprecated.rs | 3 +- grammar/src/errors/parser.rs | 6 +- .../array_initializer_expression.rs | 5 +- .../expressions/array_inline_expression.rs | 4 +- grammar/src/expressions/binary_expression.rs | 4 +- .../expressions/circuit_inline_expression.rs | 6 +- grammar/src/expressions/expression.rs | 5 +- grammar/src/expressions/postfix_expression.rs | 5 +- .../expressions/self_postfix_expression.rs | 11 ++- grammar/src/expressions/ternary_expression.rs | 4 +- grammar/src/expressions/tuple_expression.rs | 4 +- grammar/src/expressions/unary_expression.rs | 5 +- grammar/src/files/file.rs | 5 +- grammar/src/functions/function.rs | 7 +- grammar/src/functions/input/function_input.rs | 12 +-- grammar/src/functions/input/input.rs | 10 +-- grammar/src/functions/input/input_keyword.rs | 7 +- grammar/src/functions/test_function.rs | 4 +- grammar/src/imports/import.rs | 5 +- grammar/src/imports/import_symbol.rs | 4 +- grammar/src/imports/package.rs | 9 +-- grammar/src/imports/package_access.rs | 9 ++- grammar/src/imports/package_name.rs | 7 +- grammar/src/imports/package_or_packages.rs | 7 +- grammar/src/imports/packages.rs | 9 +-- grammar/src/imports/star.rs | 3 +- grammar/src/lib.rs | 3 +- grammar/src/main.rs | 7 +- grammar/src/span.rs | 3 +- grammar/src/statements/assign_statement.rs | 13 ++-- grammar/src/statements/block.rs | 4 +- .../conditional_nested_or_end_statement.rs | 7 +- .../src/statements/conditional_statement.rs | 11 ++- .../src/statements/definition_statement.rs | 12 +-- .../src/statements/expression_statement.rs | 5 +- grammar/src/statements/for_statement.rs | 6 +- grammar/src/statements/return_statement.rs | 4 +- grammar/src/statements/statement.rs | 4 +- grammar/src/types/array_dimensions.rs | 4 +- grammar/src/types/array_type.rs | 9 +-- grammar/src/types/circuit_type.rs | 4 +- grammar/src/types/data_type.rs | 10 ++- grammar/src/types/integer_type.rs | 7 +- grammar/src/types/self_type.rs | 7 +- grammar/src/types/tuple_type.rs | 4 +- grammar/src/types/type_.rs | 3 +- grammar/src/values/address.rs | 7 +- grammar/src/values/address_value.rs | 5 +- grammar/src/values/boolean_value.rs | 7 +- grammar/src/values/field_value.rs | 5 +- grammar/src/values/group_coordinate.rs | 4 +- grammar/src/values/group_value.rs | 11 ++- grammar/src/values/integer_value.rs | 7 +- grammar/src/values/negative_number.rs | 7 +- grammar/src/values/number_value.rs | 7 +- grammar/src/values/positive_number.rs | 7 +- grammar/src/values/signed_integer_value.rs | 5 +- grammar/src/values/unsigned_integer_value.rs | 5 +- grammar/src/values/value.rs | 11 ++- grammar/tests/annotated.rs | 3 +- grammar/tests/circuits.rs | 3 +- grammar/tests/deprecated.rs | 3 +- grammar/tests/display.rs | 7 +- grammar/tests/expression.rs | 3 +- grammar/tests/function.rs | 3 +- grammar/tests/imports.rs | 3 +- grammar/tests/multiline.rs | 3 +- grammar/tests/self.rs | 3 +- grammar/tests/tuple.rs | 3 +- imports/src/errors/import_parser.rs | 9 ++- imports/src/parser/import_parser.rs | 9 ++- imports/src/parser/parse_package.rs | 12 ++- imports/src/parser/parse_symbol.rs | 6 +- input/src/ast.rs | 5 +- input/src/common/identifier.rs | 3 +- input/src/definitions/definition.rs | 5 +- input/src/errors/parser.rs | 35 +++++---- .../array_initializer_expression.rs | 4 +- .../expressions/array_inline_expression.rs | 3 +- input/src/expressions/expression.rs | 4 +- input/src/expressions/tuple_expression.rs | 3 +- input/src/files/file.rs | 4 +- input/src/files/table_or_section.rs | 4 +- input/src/lib.rs | 3 +- input/src/parameters/parameter.rs | 4 +- input/src/sections/header.rs | 12 +-- input/src/sections/section.rs | 4 +- input/src/tables/table.rs | 4 +- input/src/tables/visibility.rs | 7 +- input/src/types/array_dimensions.rs | 3 +- input/src/types/array_type.rs | 7 +- input/src/types/data_type.rs | 9 ++- input/src/types/integer_type.rs | 7 +- input/src/types/tuple_type.rs | 3 +- input/src/types/type_.rs | 3 +- input/src/values/address.rs | 3 +- input/src/values/address_typed.rs | 4 +- input/src/values/address_value.rs | 7 +- input/src/values/boolean_value.rs | 3 +- input/src/values/field_value.rs | 4 +- input/src/values/group_coordinate.rs | 3 +- input/src/values/group_value.rs | 9 +-- input/src/values/integer_value.rs | 7 +- input/src/values/negative_number.rs | 3 +- input/src/values/number_value.rs | 7 +- input/src/values/positive_number.rs | 3 +- input/src/values/signed_integer_value.rs | 4 +- input/src/values/unsigned_integer_value.rs | 4 +- input/src/values/value.rs | 10 ++- leo/api.rs | 13 ++-- leo/commands/build.rs | 31 +++++--- leo/commands/clean.rs | 9 ++- leo/commands/deploy.rs | 3 +- leo/commands/init.rs | 6 +- leo/commands/lint.rs | 3 +- leo/commands/mod.rs | 6 +- leo/commands/new.rs | 9 ++- leo/commands/package/add.rs | 18 +++-- leo/commands/package/clone.rs | 19 +++-- leo/commands/package/login.rs | 14 ++-- leo/commands/package/logout.rs | 4 +- leo/commands/package/publish.rs | 21 +++--- leo/commands/package/remove.rs | 3 +- leo/commands/prove.rs | 10 ++- leo/commands/run.rs | 9 ++- leo/commands/setup.rs | 25 ++++--- leo/commands/test.rs | 28 ++++--- leo/commands/update.rs | 8 +- leo/commands/watch.rs | 14 +++- leo/config.rs | 16 ++-- leo/context.rs | 7 +- leo/logger.rs | 14 ++-- leo/main.rs | 38 +++++----- leo/tests/mod.rs | 26 +++---- leo/updater.rs | 7 +- package/src/errors/imports/directory.rs | 4 +- package/src/errors/inputs/directory.rs | 7 +- package/src/errors/inputs/input.rs | 3 +- package/src/errors/inputs/state.rs | 3 +- package/src/errors/outputs/checksum.rs | 3 +- package/src/errors/outputs/circuit.rs | 3 +- package/src/errors/outputs/directory.rs | 4 +- package/src/errors/outputs/proof.rs | 3 +- package/src/errors/outputs/proving_key.rs | 3 +- .../src/errors/outputs/verification_key.rs | 3 +- package/src/errors/package.rs | 3 +- package/src/errors/root/zip.rs | 3 +- package/src/errors/source/directory.rs | 4 +- package/src/imports/directory.rs | 4 +- package/src/inputs/directory.rs | 11 ++- package/src/inputs/input.rs | 14 ++-- package/src/inputs/pairs.rs | 14 ++-- package/src/inputs/state.rs | 14 ++-- package/src/outputs/checksum.rs | 14 ++-- package/src/outputs/circuit.rs | 14 ++-- package/src/outputs/directory.rs | 4 +- package/src/outputs/proof.rs | 14 ++-- package/src/outputs/proving_key.rs | 14 ++-- package/src/outputs/verification_key.rs | 14 ++-- package/src/package.rs | 18 +++-- package/src/root/gitignore.rs | 5 +- package/src/root/manifest.rs | 16 ++-- package/src/root/readme.rs | 5 +- package/src/root/zip.rs | 45 ++++++------ package/src/source/directory.rs | 9 +-- package/src/source/library.rs | 8 +- package/src/source/main.rs | 8 +- package/tests/initialize/initialize.rs | 14 ++-- package/tests/manifest/manifest.rs | 15 ++-- package/tests/mod.rs | 13 ++-- state/src/errors/dpc_record_values.rs | 3 +- state/src/errors/local_data_commitment.rs | 7 +- state/src/errors/state_leaf_values.rs | 3 +- state/src/errors/state_values.rs | 3 +- .../local_data_commitment.rs | 24 +++--- .../state_leaf_values.rs | 5 +- .../src/local_data_commitment/state_values.rs | 5 +- .../record_commitment/dpc_record_values.rs | 6 +- .../record_commitment/record_commitment.rs | 14 ++-- state/src/utilities/input_value.rs | 3 +- .../test_verify_local_data_commitment.rs | 16 ++-- synthesizer/src/circuit_synthesizer.rs | 14 ++-- synthesizer/src/serialized_circuit.rs | 18 ++--- synthesizer/src/serialized_field.rs | 10 ++- synthesizer/src/serialized_index.rs | 3 +- 471 files changed, 2935 insertions(+), 2020 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 39028b1340..396becc016 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -10,7 +10,7 @@ use_try_shorthand = true # Nightly configurations imports_layout = "HorizontalVertical" license_template_path = ".resources/license_header" -imports_granularity = "Crate" +imports_granularity = "Item" overflow_delimited_expr = true reorder_impl_items = true version = "Two" diff --git a/asg/src/checks/return_path.rs b/asg/src/checks/return_path.rs index 8a21f0514e..b2366a17f8 100644 --- a/asg/src/checks/return_path.rs +++ b/asg/src/checks/return_path.rs @@ -14,16 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - statement::*, - BoolAnd, - Expression, - Monoid, - MonoidalReducerExpression, - MonoidalReducerStatement, - Node, - Span, -}; +use crate::statement::*; +use crate::BoolAnd; +use crate::Expression; +use crate::Monoid; +use crate::MonoidalReducerExpression; +use crate::MonoidalReducerStatement; +use crate::Node; +use crate::Span; pub struct ReturnPathReducer { pub errors: Vec<(Span, String)>, diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index bab4aa5b3b..fce4e43ad7 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, IntegerType, Span, Type}; +use crate::AsgConvertError; +use crate::IntegerType; +use crate::Span; +use crate::Type; use num_bigint::BigInt; -use std::{convert::TryInto, fmt}; +use std::convert::TryInto; +use std::fmt; /// Constant integer values in a program. #[derive(Clone, Debug, PartialEq)] diff --git a/asg/src/context.rs b/asg/src/context.rs index 7d27ee10c0..2a20124f4e 100644 --- a/asg/src/context.rs +++ b/asg/src/context.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{cell::Cell, unimplemented}; +use std::cell::Cell; +use std::unimplemented; use typed_arena::Arena; diff --git a/asg/src/error/mod.rs b/asg/src/error/mod.rs index 39e60735dc..47e7cf761e 100644 --- a/asg/src/error/mod.rs +++ b/asg/src/error/mod.rs @@ -17,7 +17,8 @@ //! Errors encountered when attempting to convert to an asg from an ast. use crate::Span; -use leo_ast::{AstError, Error as FormattedError}; +use leo_ast::AstError; +use leo_ast::Error as FormattedError; use leo_grammar::ParserError; #[derive(Debug, Error)] diff --git a/asg/src/expression/array_access.rs b/asg/src/expression/array_access.rs index 3bbbd7909d..93a373a354 100644 --- a/asg/src/expression/array_access.rs +++ b/asg/src/expression/array_access.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use leo_ast::IntegerType; use std::cell::Cell; diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index 063485b4c4..8bc8ee1fcd 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index 79f78386fa..2d6a97fd4b 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use leo_ast::SpreadOrExpression; use std::cell::Cell; diff --git a/asg/src/expression/array_range_access.rs b/asg/src/expression/array_range_access.rs index f070116aa0..1890245176 100644 --- a/asg/src/expression/array_range_access.rs +++ b/asg/src/expression/array_range_access.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use leo_ast::IntegerType; use std::cell::Cell; diff --git a/asg/src/expression/binary.rs b/asg/src/expression/binary.rs index 9322b1d587..2b3b24f2ae 100644 --- a/asg/src/expression/binary.rs +++ b/asg/src/expression/binary.rs @@ -14,8 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; -pub use leo_ast::{BinaryOperation, BinaryOperationClass}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; +pub use leo_ast::BinaryOperation; +pub use leo_ast::BinaryOperationClass; use std::cell::Cell; diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index 52572a4907..0de4cbee3c 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -14,22 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - CircuitMember, - ConstValue, - Expression, - ExpressionNode, - FromAst, - Function, - FunctionQualifier, - Node, - PartialType, - Scope, - Span, - Type, -}; -pub use leo_ast::{BinaryOperation, Node as AstNode}; +use crate::AsgConvertError; +use crate::CircuitMember; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Function; +use crate::FunctionQualifier; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; +pub use leo_ast::BinaryOperation; +pub use leo_ast::Node as AstNode; use std::cell::Cell; diff --git a/asg/src/expression/circuit_access.rs b/asg/src/expression/circuit_access.rs index 739579cabd..63b79671d4 100644 --- a/asg/src/expression/circuit_access.rs +++ b/asg/src/expression/circuit_access.rs @@ -14,21 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - Circuit, - CircuitMember, - ConstValue, - Expression, - ExpressionNode, - FromAst, - Identifier, - Node, - PartialType, - Scope, - Span, - Type, -}; +use crate::AsgConvertError; +use crate::Circuit; +use crate::CircuitMember; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Identifier; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/expression/circuit_init.rs b/asg/src/expression/circuit_init.rs index b7ec7a764b..10058661bf 100644 --- a/asg/src/expression/circuit_init.rs +++ b/asg/src/expression/circuit_init.rs @@ -14,23 +14,22 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - Circuit, - CircuitMember, - ConstValue, - Expression, - ExpressionNode, - FromAst, - Identifier, - Node, - PartialType, - Scope, - Span, - Type, -}; +use crate::AsgConvertError; +use crate::Circuit; +use crate::CircuitMember; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Identifier; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; -use indexmap::{IndexMap, IndexSet}; +use indexmap::IndexMap; +use indexmap::IndexSet; use std::cell::Cell; #[derive(Clone)] diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index ae2a1fdd13..1ab97a0588 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -14,20 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - ConstInt, - ConstValue, - Expression, - ExpressionNode, - FromAst, - GroupValue, - Node, - PartialType, - Scope, - Span, - Type, -}; +use crate::AsgConvertError; +use crate::ConstInt; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::GroupValue; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/expression/mod.rs b/asg/src/expression/mod.rs index 720bac0781..76cb49011f 100644 --- a/asg/src/expression/mod.rs +++ b/asg/src/expression/mod.rs @@ -62,7 +62,14 @@ pub use unary::*; mod variable_ref; pub use variable_ref::*; -use crate::{AsgConvertError, ConstValue, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; #[derive(Clone)] pub enum Expression<'a> { diff --git a/asg/src/expression/ternary.rs b/asg/src/expression/ternary.rs index 93d1a7df0f..76d7b962e7 100644 --- a/asg/src/expression/ternary.rs +++ b/asg/src/expression/ternary.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/expression/tuple_access.rs b/asg/src/expression/tuple_access.rs index 4886ff4aa6..a73f7093f6 100644 --- a/asg/src/expression/tuple_access.rs +++ b/asg/src/expression/tuple_access.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/expression/tuple_init.rs b/asg/src/expression/tuple_init.rs index 195b4fe4af..d2bd923807 100644 --- a/asg/src/expression/tuple_init.rs +++ b/asg/src/expression/tuple_init.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index 0e5078e71c..e71f2d3d45 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Type; pub use leo_ast::UnaryOperation; use std::cell::Cell; diff --git a/asg/src/expression/variable_ref.rs b/asg/src/expression/variable_ref.rs index d702caa295..15f69ee690 100644 --- a/asg/src/expression/variable_ref.rs +++ b/asg/src/expression/variable_ref.rs @@ -14,22 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - ConstValue, - Constant, - DefinitionStatement, - Expression, - ExpressionNode, - FromAst, - Node, - PartialType, - Scope, - Span, - Statement, - Type, - Variable, -}; +use crate::AsgConvertError; +use crate::ConstValue; +use crate::Constant; +use crate::DefinitionStatement; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; +use crate::Variable; use std::cell::Cell; diff --git a/asg/src/import.rs b/asg/src/import.rs index 4dc3c5ae43..1b95fc2fdd 100644 --- a/asg/src/import.rs +++ b/asg/src/import.rs @@ -18,7 +18,10 @@ use std::marker::PhantomData; -use crate::{AsgContext, AsgConvertError, Program, Span}; +use crate::AsgContext; +use crate::AsgConvertError; +use crate::Program; +use crate::Span; use indexmap::IndexMap; diff --git a/asg/src/input.rs b/asg/src/input.rs index f9af9c2851..ee4b5ea72d 100644 --- a/asg/src/input.rs +++ b/asg/src/input.rs @@ -14,7 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Circuit, CircuitMember, Identifier, Scope, Type, Variable}; +use crate::Circuit; +use crate::CircuitMember; +use crate::Identifier; +use crate::Scope; +use crate::Type; +use crate::Variable; use indexmap::IndexMap; use std::cell::RefCell; diff --git a/asg/src/lib.rs b/asg/src/lib.rs index ada569edeb..a611f6929f 100644 --- a/asg/src/lib.rs +++ b/asg/src/lib.rs @@ -74,7 +74,9 @@ pub use pass::*; pub mod context; pub use context::*; -pub use leo_ast::{Ast, Identifier, Span}; +pub use leo_ast::Ast; +pub use leo_ast::Identifier; +pub use leo_ast::Span; use std::path::Path; diff --git a/asg/src/node.rs b/asg/src/node.rs index 58b4b7709e..ae9ca44a68 100644 --- a/asg/src/node.rs +++ b/asg/src/node.rs @@ -14,18 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgContextInner, - AsgConvertError, - Circuit, - Expression, - Function, - PartialType, - Scope, - Span, - Statement, - Variable, -}; +use crate::AsgContextInner; +use crate::AsgConvertError; +use crate::Circuit; +use crate::Expression; +use crate::Function; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Variable; /// A node in the abstract semantic graph. pub trait Node { diff --git a/asg/src/prelude.rs b/asg/src/prelude.rs index e977fd137f..f8408f5cb9 100644 --- a/asg/src/prelude.rs +++ b/asg/src/prelude.rs @@ -16,7 +16,9 @@ // TODO (protryon): We should merge this with core -use crate::{AsgContext, AsgConvertError, Program}; +use crate::AsgContext; +use crate::AsgConvertError; +use crate::Program; // TODO (protryon): Make asg deep copy so we can cache resolved core modules // TODO (protryon): Figure out how to do headers without bogus returns diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index e44c8b8277..05b262bd8b 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -14,7 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, Function, Identifier, Node, Scope, Span, Type}; +use crate::AsgConvertError; +use crate::Function; +use crate::Identifier; +use crate::Node; +use crate::Scope; +use crate::Span; +use crate::Type; use indexmap::IndexMap; use std::cell::RefCell; diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 159d3ead3b..1a46063502 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -14,24 +14,23 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - BlockStatement, - Circuit, - FromAst, - Identifier, - MonoidalDirector, - ReturnPathReducer, - Scope, - Span, - Statement, - Type, - Variable, -}; +use crate::AsgConvertError; +use crate::BlockStatement; +use crate::Circuit; +use crate::FromAst; +use crate::Identifier; +use crate::MonoidalDirector; +use crate::ReturnPathReducer; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; +use crate::Variable; use indexmap::IndexMap; use leo_ast::FunctionInput; -use std::cell::{Cell, RefCell}; +use std::cell::Cell; +use std::cell::RefCell; #[derive(Clone, Copy, PartialEq)] pub enum FunctionQualifier { diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index cccadd08d3..70d3e39889 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -24,11 +24,20 @@ pub use circuit::*; mod function; pub use function::*; -use crate::{ArenaNode, AsgContext, AsgConvertError, ImportResolver, Input, Scope}; -use leo_ast::{Identifier, PackageAccess, PackageOrPackages, Span}; +use crate::ArenaNode; +use crate::AsgContext; +use crate::AsgConvertError; +use crate::ImportResolver; +use crate::Input; +use crate::Scope; +use leo_ast::Identifier; +use leo_ast::PackageAccess; +use leo_ast::PackageOrPackages; +use leo_ast::Span; use indexmap::IndexMap; -use std::cell::{Cell, RefCell}; +use std::cell::Cell; +use std::cell::RefCell; /// Stores the Leo program abstract semantic graph (ASG). #[derive(Clone)] diff --git a/asg/src/reducer/monoidal_director.rs b/asg/src/reducer/monoidal_director.rs index 40a55d4a30..539363a95d 100644 --- a/asg/src/reducer/monoidal_director.rs +++ b/asg/src/reducer/monoidal_director.rs @@ -15,7 +15,9 @@ // along with the Leo library. If not, see . use super::*; -use crate::{expression::*, program::*, statement::*}; +use crate::expression::*; +use crate::program::*; +use crate::statement::*; use std::marker::PhantomData; diff --git a/asg/src/reducer/monoidal_reducer.rs b/asg/src/reducer/monoidal_reducer.rs index ba7a177f5b..a126bc2807 100644 --- a/asg/src/reducer/monoidal_reducer.rs +++ b/asg/src/reducer/monoidal_reducer.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{expression::*, program::*, statement::*, Monoid}; +use crate::expression::*; +use crate::program::*; +use crate::statement::*; +use crate::Monoid; #[allow(unused_variables)] pub trait MonoidalReducerExpression<'a, T: Monoid> { diff --git a/asg/src/reducer/visitor.rs b/asg/src/reducer/visitor.rs index 415f3ed265..220d920c82 100644 --- a/asg/src/reducer/visitor.rs +++ b/asg/src/reducer/visitor.rs @@ -16,7 +16,9 @@ use std::cell::Cell; -use crate::{expression::*, program::*, statement::*}; +use crate::expression::*; +use crate::program::*; +use crate::statement::*; pub enum VisitResult { VisitChildren, diff --git a/asg/src/reducer/visitor_director.rs b/asg/src/reducer/visitor_director.rs index 4edc95d106..fd37311d76 100644 --- a/asg/src/reducer/visitor_director.rs +++ b/asg/src/reducer/visitor_director.rs @@ -15,9 +15,12 @@ // along with the Leo library. If not, see . use super::*; -use crate::{expression::*, program::*, statement::*}; +use crate::expression::*; +use crate::program::*; +use crate::statement::*; -use std::{cell::Cell, marker::PhantomData}; +use std::cell::Cell; +use std::marker::PhantomData; pub struct VisitorDirector<'a, R: ExpressionVisitor<'a>> { visitor: R, diff --git a/asg/src/scope.rs b/asg/src/scope.rs index c39506c043..7394d8d4c4 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -14,10 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ArenaNode, AsgContext, AsgConvertError, Circuit, Expression, Function, Input, Statement, Type, Variable}; +use crate::ArenaNode; +use crate::AsgContext; +use crate::AsgConvertError; +use crate::Circuit; +use crate::Expression; +use crate::Function; +use crate::Input; +use crate::Statement; +use crate::Type; +use crate::Variable; use indexmap::IndexMap; -use std::cell::{Cell, RefCell}; +use std::cell::Cell; +use std::cell::RefCell; /// An abstract data type that track the current bindings for variables, functions, and circuits. #[derive(Clone)] diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index 1eda9119ba..f00d419cbd 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -14,24 +14,22 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - CircuitMember, - ConstInt, - ConstValue, - Expression, - ExpressionNode, - FromAst, - Identifier, - IntegerType, - Node, - PartialType, - Scope, - Span, - Statement, - Type, - Variable, -}; +use crate::AsgConvertError; +use crate::CircuitMember; +use crate::ConstInt; +use crate::ConstValue; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::Identifier; +use crate::IntegerType; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; +use crate::Variable; pub use leo_ast::AssignOperation; use leo_ast::AssigneeAccess as AstAssigneeAccess; diff --git a/asg/src/statement/block.rs b/asg/src/statement/block.rs index 9a64fcdfb9..70bd668119 100644 --- a/asg/src/statement/block.rs +++ b/asg/src/statement/block.rs @@ -14,7 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span, Statement}; +use crate::AsgConvertError; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; use std::cell::Cell; diff --git a/asg/src/statement/conditional.rs b/asg/src/statement/conditional.rs index 6f0b5f09b7..5d2d4f30ca 100644 --- a/asg/src/statement/conditional.rs +++ b/asg/src/statement/conditional.rs @@ -14,7 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, BlockStatement, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; +use crate::AsgConvertError; +use crate::BlockStatement; +use crate::Expression; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; use std::cell::Cell; diff --git a/asg/src/statement/console.rs b/asg/src/statement/console.rs index fdcf2858e5..f72c172f1b 100644 --- a/asg/src/statement/console.rs +++ b/asg/src/statement/console.rs @@ -14,7 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; +use crate::AsgConvertError; +use crate::Expression; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; use leo_ast::ConsoleFunction as AstConsoleFunction; use std::cell::Cell; diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index a779454996..dab03e9b7a 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -14,23 +14,23 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - AsgConvertError, - Expression, - ExpressionNode, - FromAst, - InnerVariable, - Node, - PartialType, - Scope, - Span, - Statement, - Type, - Variable, -}; -use leo_ast::{AstError, DeprecatedError}; +use crate::AsgConvertError; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::InnerVariable; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; +use crate::Variable; +use leo_ast::AstError; +use leo_ast::DeprecatedError; -use std::cell::{Cell, RefCell}; +use std::cell::Cell; +use std::cell::RefCell; #[derive(Clone)] pub struct DefinitionStatement<'a> { diff --git a/asg/src/statement/expression.rs b/asg/src/statement/expression.rs index f00c55c488..e533f87bf3 100644 --- a/asg/src/statement/expression.rs +++ b/asg/src/statement/expression.rs @@ -14,7 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement}; +use crate::AsgConvertError; +use crate::Expression; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; use std::cell::Cell; diff --git a/asg/src/statement/iteration.rs b/asg/src/statement/iteration.rs index 26cfd2ba74..1a441befbd 100644 --- a/asg/src/statement/iteration.rs +++ b/asg/src/statement/iteration.rs @@ -16,21 +16,20 @@ use leo_ast::IntegerType; -use crate::{ - AsgConvertError, - Expression, - ExpressionNode, - FromAst, - InnerVariable, - Node, - PartialType, - Scope, - Span, - Statement, - Variable, -}; +use crate::AsgConvertError; +use crate::Expression; +use crate::ExpressionNode; +use crate::FromAst; +use crate::InnerVariable; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Variable; -use std::cell::{Cell, RefCell}; +use std::cell::Cell; +use std::cell::RefCell; #[derive(Clone)] pub struct IterationStatement<'a> { diff --git a/asg/src/statement/mod.rs b/asg/src/statement/mod.rs index bc924f2ae1..7757ba4d33 100644 --- a/asg/src/statement/mod.rs +++ b/asg/src/statement/mod.rs @@ -42,7 +42,12 @@ pub use iteration::*; mod return_; pub use return_::*; -use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span}; +use crate::AsgConvertError; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; #[derive(Clone)] pub enum Statement<'a> { diff --git a/asg/src/statement/return_.rs b/asg/src/statement/return_.rs index fb6b640390..eccf6f794f 100644 --- a/asg/src/statement/return_.rs +++ b/asg/src/statement/return_.rs @@ -14,7 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; +use crate::AsgConvertError; +use crate::Expression; +use crate::FromAst; +use crate::Node; +use crate::PartialType; +use crate::Scope; +use crate::Span; +use crate::Statement; +use crate::Type; use std::cell::Cell; #[derive(Clone)] diff --git a/asg/src/variable.rs b/asg/src/variable.rs index 831de1c63f..a38274c3e9 100644 --- a/asg/src/variable.rs +++ b/asg/src/variable.rs @@ -16,7 +16,9 @@ use std::cell::RefCell; -use crate::{Expression, Statement, Type}; +use crate::Expression; +use crate::Statement; +use crate::Type; use leo_ast::Identifier; /// Specifies how a program variable was declared. diff --git a/asg/tests/pass/form_ast.rs b/asg/tests/pass/form_ast.rs index d49cb8b970..471f938310 100644 --- a/asg/tests/pass/form_ast.rs +++ b/asg/tests/pass/form_ast.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{load_asg, make_test_context}; +use crate::load_asg; +use crate::make_test_context; use leo_ast::Ast; use leo_grammar::Grammar; diff --git a/asg/tests/pass/import/mod.rs b/asg/tests/pass/import/mod.rs index 870e4fe9ee..1c6008557e 100644 --- a/asg/tests/pass/import/mod.rs +++ b/asg/tests/pass/import/mod.rs @@ -14,7 +14,10 @@ // 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, make_test_context, mocked_resolver}; +use crate::load_asg; +use crate::load_asg_imports; +use crate::make_test_context; +use crate::mocked_resolver; #[test] fn test_basic() { diff --git a/ast/benches/leo_ast.rs b/ast/benches/leo_ast.rs index d5420b0543..16619f1971 100644 --- a/ast/benches/leo_ast.rs +++ b/ast/benches/leo_ast.rs @@ -17,8 +17,11 @@ use leo_ast::Ast; use leo_grammar::Grammar; -use criterion::{criterion_group, criterion_main, Criterion}; -use std::{path::Path, time::Duration}; +use criterion::criterion_group; +use criterion::criterion_main; +use criterion::Criterion; +use std::path::Path; +use std::time::Duration; fn ast(ast: &Grammar) -> Ast { Ast::new("leo_tree", &ast).unwrap() diff --git a/ast/src/annotation.rs b/ast/src/annotation.rs index 9ccc5e833d..f1c233c935 100644 --- a/ast/src/annotation.rs +++ b/ast/src/annotation.rs @@ -14,11 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Circuit, DeprecatedError, Function, FunctionInput, Identifier, ImportStatement, TestFunction}; -use leo_grammar::{ - annotations::{Annotation, AnnotationArguments, AnnotationName}, - definitions::{AnnotatedDefinition, Definition}, -}; +use crate::Circuit; +use crate::DeprecatedError; +use crate::Function; +use crate::FunctionInput; +use crate::Identifier; +use crate::ImportStatement; +use crate::TestFunction; +use leo_grammar::annotations::Annotation; +use leo_grammar::annotations::AnnotationArguments; +use leo_grammar::annotations::AnnotationName; +use leo_grammar::definitions::AnnotatedDefinition; +use leo_grammar::definitions::Definition; use std::convert::TryFrom; diff --git a/ast/src/circuits/circuit.rs b/ast/src/circuits/circuit.rs index 79c2280cfc..de9aa0e88e 100644 --- a/ast/src/circuits/circuit.rs +++ b/ast/src/circuits/circuit.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{CircuitMember, Identifier}; +use crate::CircuitMember; +use crate::Identifier; use leo_grammar::circuits::Circuit as GrammarCircuit; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/circuits/circuit_implied_variable_definition.rs b/ast/src/circuits/circuit_implied_variable_definition.rs index 963c153bec..f48ae39ceb 100644 --- a/ast/src/circuits/circuit_implied_variable_definition.rs +++ b/ast/src/circuits/circuit_implied_variable_definition.rs @@ -14,10 +14,12 @@ // 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 crate::Expression; +use crate::Identifier; use leo_grammar::circuits::CircuitImpliedVariable; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CircuitImpliedVariableDefinition { diff --git a/ast/src/circuits/circuit_member.rs b/ast/src/circuits/circuit_member.rs index 29b5777587..8661b825be 100644 --- a/ast/src/circuits/circuit_member.rs +++ b/ast/src/circuits/circuit_member.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Function, Identifier, Type}; -use leo_grammar::{ - circuits::{CircuitMember as GrammarCircuitMember, CircuitVariableDefinition as GrammarCircuitVariableDefinition}, - functions::Function as GrammarFunction, -}; +use crate::Function; +use crate::Identifier; +use crate::Type; +use leo_grammar::circuits::CircuitMember as GrammarCircuitMember; +use leo_grammar::circuits::CircuitVariableDefinition as GrammarCircuitVariableDefinition; +use leo_grammar::functions::Function as GrammarFunction; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/circuits/circuit_variable_definition.rs b/ast/src/circuits/circuit_variable_definition.rs index 6cd3484f88..f553161a3c 100644 --- a/ast/src/circuits/circuit_variable_definition.rs +++ b/ast/src/circuits/circuit_variable_definition.rs @@ -14,10 +14,12 @@ // 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 crate::Expression; +use crate::Identifier; use leo_grammar::circuits::CircuitVariable; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CircuitVariableDefinition { diff --git a/ast/src/common/array_dimensions.rs b/ast/src/common/array_dimensions.rs index a401475200..1aa523bf68 100644 --- a/ast/src/common/array_dimensions.rs +++ b/ast/src/common/array_dimensions.rs @@ -18,7 +18,8 @@ use crate::PositiveNumber; use leo_grammar::types::ArrayDimensions as GrammarArrayDimensions; use leo_input::types::ArrayDimensions as InputArrayDimensions; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// A vector of positive numbers that represent array dimensions. diff --git a/ast/src/common/identifier.rs b/ast/src/common/identifier.rs index c24f4a9d8e..6d5bb779d8 100644 --- a/ast/src/common/identifier.rs +++ b/ast/src/common/identifier.rs @@ -14,36 +14,33 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputKeyword, MutSelfKeyword, SelfKeyword, Span}; -use leo_grammar::{ - annotations::AnnotationArgument, - common::{ - Identifier as GrammarIdentifier, - KeywordOrIdentifier, - MutSelfKeyword as GrammarMutSelfKeyword, - SelfKeyword as GrammarSelfKeyword, - SelfKeywordOrIdentifier, - }, - expressions::CircuitName, - functions::InputKeyword as GrammarInputKeyword, - imports::PackageName as GrammarPackageName, - types::SelfType, -}; +use crate::InputKeyword; +use crate::MutSelfKeyword; +use crate::SelfKeyword; +use crate::Span; +use leo_grammar::annotations::AnnotationArgument; +use leo_grammar::common::Identifier as GrammarIdentifier; +use leo_grammar::common::KeywordOrIdentifier; +use leo_grammar::common::MutSelfKeyword as GrammarMutSelfKeyword; +use leo_grammar::common::SelfKeyword as GrammarSelfKeyword; +use leo_grammar::common::SelfKeywordOrIdentifier; +use leo_grammar::expressions::CircuitName; +use leo_grammar::functions::InputKeyword as GrammarInputKeyword; +use leo_grammar::imports::PackageName as GrammarPackageName; +use leo_grammar::types::SelfType; use leo_input::common::Identifier as InputIdentifier; use crate::Node; -use serde::{ - de::{self, Visitor}, - Deserialize, - Deserializer, - Serialize, - Serializer, -}; -use std::{ - collections::BTreeMap, - fmt, - hash::{Hash, Hasher}, -}; +use serde::de::Visitor; +use serde::de::{self}; +use serde::Deserialize; +use serde::Deserializer; +use serde::Serialize; +use serde::Serializer; +use std::collections::BTreeMap; +use std::fmt; +use std::hash::Hash; +use std::hash::Hasher; /// An identifier in the constrained program. /// diff --git a/ast/src/common/input_keyword.rs b/ast/src/common/input_keyword.rs index a6dd0d5e74..987237ff94 100644 --- a/ast/src/common/input_keyword.rs +++ b/ast/src/common/input_keyword.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::Node; +use crate::Span; use leo_grammar::functions::InputKeyword as GrammarInputKeyword; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// The `input` keyword can view program register, record, and state values. diff --git a/ast/src/common/mut_self_keyword.rs b/ast/src/common/mut_self_keyword.rs index 0d4bf62168..a65fa16bdb 100644 --- a/ast/src/common/mut_self_keyword.rs +++ b/ast/src/common/mut_self_keyword.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::Node; +use crate::Span; use leo_grammar::common::MutSelfKeyword as GrammarMutSelfKeyword; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// The `mut self` keyword can view and modify circuit values inside of a circuit function. diff --git a/ast/src/common/positive_number.rs b/ast/src/common/positive_number.rs index 667727b1b5..d7223c6cdb 100644 --- a/ast/src/common/positive_number.rs +++ b/ast/src/common/positive_number.rs @@ -17,7 +17,8 @@ use leo_grammar::values::PositiveNumber as GrammarPositiveNumber; use leo_input::values::PositiveNumber as InputPositiveNumber; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// A number string guaranteed to be positive by the pest grammar. diff --git a/ast/src/common/self_keyword.rs b/ast/src/common/self_keyword.rs index caa9e1b7f6..d491c5fd95 100644 --- a/ast/src/common/self_keyword.rs +++ b/ast/src/common/self_keyword.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::Node; +use crate::Span; use leo_grammar::common::SelfKeyword as GrammarSelfKeyword; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// The `self` keyword can view circuit values inside of a circuit function. diff --git a/ast/src/common/span.rs b/ast/src/common/span.rs index e6e7a70388..ff2ff0f795 100644 --- a/ast/src/common/span.rs +++ b/ast/src/common/span.rs @@ -15,8 +15,10 @@ // along with the Leo library. If not, see . use pest::Span as GrammarSpan; -use serde::{Deserialize, Serialize}; -use std::hash::{Hash, Hasher}; +use serde::Deserialize; +use serde::Serialize; +use std::hash::Hash; +use std::hash::Hasher; #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct Span { diff --git a/ast/src/common/spread_or_expression.rs b/ast/src/common/spread_or_expression.rs index 78f940a5af..345ed83bfd 100644 --- a/ast/src/common/spread_or_expression.rs +++ b/ast/src/common/spread_or_expression.rs @@ -14,13 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Node, Span}; -use leo_grammar::{ - common::SpreadOrExpression as GrammarSpreadOrExpression, - expressions::Expression as GrammarExpression, -}; +use crate::Expression; +use crate::Node; +use crate::Span; +use leo_grammar::common::SpreadOrExpression as GrammarSpreadOrExpression; +use leo_grammar::expressions::Expression as GrammarExpression; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Spread or expression diff --git a/ast/src/errors/deprecated.rs b/ast/src/errors/deprecated.rs index c22419d3ee..65ae83a9d5 100644 --- a/ast/src/errors/deprecated.rs +++ b/ast/src/errors/deprecated.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Error as FormattedError, Span}; -use leo_grammar::{annotations::AnnotationName, definitions::Deprecated}; +use crate::Error as FormattedError; +use crate::Span; +use leo_grammar::annotations::AnnotationName; +use leo_grammar::definitions::Deprecated; -use std::{convert::TryFrom, path::Path}; +use std::convert::TryFrom; +use std::path::Path; #[derive(Debug, Error)] pub enum DeprecatedError { diff --git a/ast/src/errors/error.rs b/ast/src/errors/error.rs index 103b0ea9cb..c0fbfce73d 100644 --- a/ast/src/errors/error.rs +++ b/ast/src/errors/error.rs @@ -16,7 +16,8 @@ use crate::Span; -use std::{fmt, path::Path}; +use std::fmt; +use std::path::Path; pub const INDENT: &str = " "; diff --git a/ast/src/expression/mod.rs b/ast/src/expression/mod.rs index fb4050f1f2..629a77b9a2 100644 --- a/ast/src/expression/mod.rs +++ b/ast/src/expression/mod.rs @@ -14,44 +14,43 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ArrayDimensions, - CircuitImpliedVariableDefinition, - GroupValue, - Identifier, - IntegerType, - PositiveNumber, - Span, - SpreadOrExpression, -}; -use leo_grammar::{ - access::{Access, AssigneeAccess, SelfAccess}, - common::{Assignee, Identifier as GrammarIdentifier, RangeOrExpression as GrammarRangeOrExpression}, - expressions::{ - ArrayInitializerExpression, - ArrayInlineExpression as GrammarArrayInlineExpression, - BinaryExpression as GrammarBinaryExpression, - CircuitInlineExpression, - Expression as GrammarExpression, - PostfixExpression, - SelfPostfixExpression, - TernaryExpression as GrammarTernaryExpression, - UnaryExpression as GrammarUnaryExpression, - }, - operations::{BinaryOperation as GrammarBinaryOperation, UnaryOperation as GrammarUnaryOperation}, - values::{ - AddressValue, - BooleanValue, - FieldValue, - GroupValue as GrammarGroupValue, - IntegerValue, - NumberValue as GrammarNumber, - Value, - }, -}; +use crate::ArrayDimensions; +use crate::CircuitImpliedVariableDefinition; +use crate::GroupValue; +use crate::Identifier; +use crate::IntegerType; +use crate::PositiveNumber; +use crate::Span; +use crate::SpreadOrExpression; +use leo_grammar::access::Access; +use leo_grammar::access::AssigneeAccess; +use leo_grammar::access::SelfAccess; +use leo_grammar::common::Assignee; +use leo_grammar::common::Identifier as GrammarIdentifier; +use leo_grammar::common::RangeOrExpression as GrammarRangeOrExpression; +use leo_grammar::expressions::ArrayInitializerExpression; +use leo_grammar::expressions::ArrayInlineExpression as GrammarArrayInlineExpression; +use leo_grammar::expressions::BinaryExpression as GrammarBinaryExpression; +use leo_grammar::expressions::CircuitInlineExpression; +use leo_grammar::expressions::Expression as GrammarExpression; +use leo_grammar::expressions::PostfixExpression; +use leo_grammar::expressions::SelfPostfixExpression; +use leo_grammar::expressions::TernaryExpression as GrammarTernaryExpression; +use leo_grammar::expressions::UnaryExpression as GrammarUnaryExpression; +use leo_grammar::operations::BinaryOperation as GrammarBinaryOperation; +use leo_grammar::operations::UnaryOperation as GrammarUnaryOperation; +use leo_grammar::values::AddressValue; +use leo_grammar::values::BooleanValue; +use leo_grammar::values::FieldValue; +use leo_grammar::values::GroupValue as GrammarGroupValue; +use leo_grammar::values::IntegerValue; +use leo_grammar::values::NumberValue as GrammarNumber; +use leo_grammar::values::Value; -use leo_grammar::{access::TupleAccess, expressions::TupleExpression}; -use serde::{Deserialize, Serialize}; +use leo_grammar::access::TupleAccess; +use leo_grammar::expressions::TupleExpression; +use serde::Deserialize; +use serde::Serialize; use std::fmt; use crate::Node; diff --git a/ast/src/functions/function.rs b/ast/src/functions/function.rs index e9cea0c8c3..65b05a09cc 100644 --- a/ast/src/functions/function.rs +++ b/ast/src/functions/function.rs @@ -14,10 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Block, FunctionInput, Identifier, Node, Span, Type}; +use crate::Block; +use crate::FunctionInput; +use crate::Identifier; +use crate::Node; +use crate::Span; +use crate::Type; use leo_grammar::functions::Function as GrammarFunction; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Serialize, Deserialize)] diff --git a/ast/src/functions/input/function_input.rs b/ast/src/functions/input/function_input.rs index 8cece828ad..f0c30b14d8 100644 --- a/ast/src/functions/input/function_input.rs +++ b/ast/src/functions/input/function_input.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Identifier, Node, Span, Type}; +use crate::Identifier; +use crate::Node; +use crate::Span; +use crate::Type; use leo_grammar::functions::FunctionInput as GrammarFunctionInput; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/functions/input/input_variable.rs b/ast/src/functions/input/input_variable.rs index ecab44a959..4acef0e2c5 100644 --- a/ast/src/functions/input/input_variable.rs +++ b/ast/src/functions/input/input_variable.rs @@ -14,10 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{FunctionInputVariable, InputKeyword, MutSelfKeyword, Node, SelfKeyword, Span}; +use crate::FunctionInputVariable; +use crate::InputKeyword; +use crate::MutSelfKeyword; +use crate::Node; +use crate::SelfKeyword; +use crate::Span; use leo_grammar::functions::input::Input as GrammarInput; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Enumerates the possible inputs to a function. diff --git a/ast/src/functions/test_function.rs b/ast/src/functions/test_function.rs index eb9f09a346..b349094c46 100644 --- a/ast/src/functions/test_function.rs +++ b/ast/src/functions/test_function.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Function, Identifier}; +use crate::Function; +use crate::Identifier; use leo_grammar::functions::TestFunction as GrammarTestFunction; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct TestFunction { diff --git a/ast/src/groups/group_coordinate.rs b/ast/src/groups/group_coordinate.rs index fd201856dd..675337a5d2 100644 --- a/ast/src/groups/group_coordinate.rs +++ b/ast/src/groups/group_coordinate.rs @@ -15,22 +15,19 @@ // along with the Leo library. If not, see . use crate::common::span::Span; -use leo_grammar::values::{ - GroupCoordinate as GrammarGroupCoordinate, - Inferred as GrammarInferred, - NumberValue as GrammarNumberValue, - SignHigh as GrammarSignHigh, - SignLow as GrammarSignLow, -}; -use leo_input::values::{ - GroupCoordinate as InputGroupCoordinate, - Inferred as InputInferred, - NumberValue as InputNumberValue, - SignHigh as InputSignHigh, - SignLow as InputSignLow, -}; +use leo_grammar::values::GroupCoordinate as GrammarGroupCoordinate; +use leo_grammar::values::Inferred as GrammarInferred; +use leo_grammar::values::NumberValue as GrammarNumberValue; +use leo_grammar::values::SignHigh as GrammarSignHigh; +use leo_grammar::values::SignLow as GrammarSignLow; +use leo_input::values::GroupCoordinate as InputGroupCoordinate; +use leo_input::values::Inferred as InputInferred; +use leo_input::values::NumberValue as InputNumberValue; +use leo_input::values::SignHigh as InputSignHigh; +use leo_input::values::SignLow as InputSignLow; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/groups/group_value.rs b/ast/src/groups/group_value.rs index 5e0c42113e..32872fb32d 100644 --- a/ast/src/groups/group_value.rs +++ b/ast/src/groups/group_value.rs @@ -14,19 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{common::span::Span, groups::GroupCoordinate}; -use leo_grammar::values::{ - GroupRepresentation as GrammarGroupRepresentation, - GroupTuple as GrammarGroupTuple, - GroupValue as GrammarGroupValue, -}; -use leo_input::values::{ - GroupRepresentation as InputGroupRepresentation, - GroupTuple as InputGroupTuple, - GroupValue as InputGroupValue, -}; +use crate::common::span::Span; +use crate::groups::GroupCoordinate; +use leo_grammar::values::GroupRepresentation as GrammarGroupRepresentation; +use leo_grammar::values::GroupTuple as GrammarGroupTuple; +use leo_grammar::values::GroupValue as GrammarGroupValue; +use leo_input::values::GroupRepresentation as InputGroupRepresentation; +use leo_input::values::GroupTuple as InputGroupTuple; +use leo_input::values::GroupValue as InputGroupValue; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/imports/import.rs b/ast/src/imports/import.rs index 246f61c3b1..8e0d02770f 100644 --- a/ast/src/imports/import.rs +++ b/ast/src/imports/import.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{PackageOrPackages, Span}; +use crate::PackageOrPackages; +use crate::Span; use leo_grammar::imports::Import as GrammarImport; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Represents an import statement in a Leo program. diff --git a/ast/src/imports/import_symbol.rs b/ast/src/imports/import_symbol.rs index 20d8650793..c447624023 100644 --- a/ast/src/imports/import_symbol.rs +++ b/ast/src/imports/import_symbol.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Identifier, Span}; +use crate::Identifier; +use crate::Span; use leo_grammar::imports::ImportSymbol as GrammarImportSymbol; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/package.rs b/ast/src/imports/package.rs index 091e72142d..fec57b1fa3 100644 --- a/ast/src/imports/package.rs +++ b/ast/src/imports/package.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{common::Identifier, PackageAccess, Span}; +use crate::common::Identifier; +use crate::PackageAccess; +use crate::Span; use leo_grammar::imports::Package as GrammarPackage; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/package_access.rs b/ast/src/imports/package_access.rs index b329cc6b82..ade92faed3 100644 --- a/ast/src/imports/package_access.rs +++ b/ast/src/imports/package_access.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ImportSymbol, Package, Packages, Span}; +use crate::ImportSymbol; +use crate::Package; +use crate::Packages; +use crate::Span; use leo_grammar::imports::PackageAccess as GrammarPackageAccess; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/package_or_packages.rs b/ast/src/imports/package_or_packages.rs index 2f1b9bc717..0be227fd26 100644 --- a/ast/src/imports/package_or_packages.rs +++ b/ast/src/imports/package_or_packages.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Package, Packages}; +use crate::Package; +use crate::Packages; use leo_grammar::imports::PackageOrPackages as GrammarPackageOrPackages; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/packages.rs b/ast/src/imports/packages.rs index fab9542716..420c401ef7 100644 --- a/ast/src/imports/packages.rs +++ b/ast/src/imports/packages.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{common::Identifier, PackageAccess, Span}; +use crate::common::Identifier; +use crate::PackageAccess; +use crate::Span; use leo_grammar::imports::Packages as GrammarPackages; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/input/input.rs b/ast/src/input/input.rs index ae201c2aec..a72577dc3a 100644 --- a/ast/src/input/input.rs +++ b/ast/src/input/input.rs @@ -14,11 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputValue, MainInput, ProgramInput, ProgramState, Record, Registers, State, StateLeaf}; -use leo_input::{ - files::{File, TableOrSection}, - InputParserError, -}; +use crate::InputValue; +use crate::MainInput; +use crate::ProgramInput; +use crate::ProgramState; +use crate::Record; +use crate::Registers; +use crate::State; +use crate::StateLeaf; +use leo_input::files::File; +use leo_input::files::TableOrSection; +use leo_input::InputParserError; #[derive(Clone, PartialEq, Eq)] pub struct Input { diff --git a/ast/src/input/input_value.rs b/ast/src/input/input_value.rs index 5d6fba2a9e..ffbd5ce4e4 100644 --- a/ast/src/input/input_value.rs +++ b/ast/src/input/input_value.rs @@ -14,13 +14,25 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ArrayDimensions, GroupValue}; -use leo_input::{ - errors::InputParserError, - expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression, TupleExpression}, - types::{ArrayType, DataType, IntegerType, TupleType, Type}, - values::{Address, AddressValue, BooleanValue, FieldValue, GroupValue as InputGroupValue, NumberValue, Value}, -}; +use crate::ArrayDimensions; +use crate::GroupValue; +use leo_input::errors::InputParserError; +use leo_input::expressions::ArrayInitializerExpression; +use leo_input::expressions::ArrayInlineExpression; +use leo_input::expressions::Expression; +use leo_input::expressions::TupleExpression; +use leo_input::types::ArrayType; +use leo_input::types::DataType; +use leo_input::types::IntegerType; +use leo_input::types::TupleType; +use leo_input::types::Type; +use leo_input::values::Address; +use leo_input::values::AddressValue; +use leo_input::values::BooleanValue; +use leo_input::values::FieldValue; +use leo_input::values::GroupValue as InputGroupValue; +use leo_input::values::NumberValue; +use leo_input::values::Value; use pest::Span; use std::fmt; diff --git a/ast/src/input/parameters/parameter.rs b/ast/src/input/parameters/parameter.rs index 7f275f2fea..4031d57795 100644 --- a/ast/src/input/parameters/parameter.rs +++ b/ast/src/input/parameters/parameter.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Identifier, Span, Type}; +use crate::Identifier; +use crate::Span; +use crate::Type; use leo_input::parameters::Parameter as GrammarParameter; #[derive(Clone, PartialEq, Eq, Hash)] diff --git a/ast/src/input/program_input/main_input.rs b/ast/src/input/program_input/main_input.rs index 7d1b496134..5683d3f161 100644 --- a/ast/src/input/program_input/main_input.rs +++ b/ast/src/input/program_input/main_input.rs @@ -15,7 +15,8 @@ // along with the Leo library. If not, see . use crate::InputValue; -use leo_input::{definitions::Definition, InputParserError}; +use leo_input::definitions::Definition; +use leo_input::InputParserError; use indexmap::IndexMap; diff --git a/ast/src/input/program_input/program_input.rs b/ast/src/input/program_input/program_input.rs index 42efab1a25..17e933f211 100644 --- a/ast/src/input/program_input/program_input.rs +++ b/ast/src/input/program_input/program_input.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputValue, MainInput, Registers}; -use leo_input::{ - sections::{Header, Section}, - InputParserError, -}; +use crate::InputValue; +use crate::MainInput; +use crate::Registers; +use leo_input::sections::Header; +use leo_input::sections::Section; +use leo_input::InputParserError; #[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramInput { diff --git a/ast/src/input/program_input/registers.rs b/ast/src/input/program_input/registers.rs index 21e25030e3..5478e5df3a 100644 --- a/ast/src/input/program_input/registers.rs +++ b/ast/src/input/program_input/registers.rs @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; +use crate::InputValue; +use crate::Parameter; +use leo_input::definitions::Definition; +use leo_input::InputParserError; use indexmap::IndexMap; diff --git a/ast/src/input/program_state/private_state/private_state.rs b/ast/src/input/program_state/private_state/private_state.rs index f7f1f9edc9..895674d711 100644 --- a/ast/src/input/program_state/private_state/private_state.rs +++ b/ast/src/input/program_state/private_state/private_state.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Record, StateLeaf}; -use leo_input::{ - sections::{Header, Section}, - InputParserError, -}; +use crate::Record; +use crate::StateLeaf; +use leo_input::sections::Header; +use leo_input::sections::Section; +use leo_input::InputParserError; #[derive(Clone, PartialEq, Eq, Default)] pub struct PrivateState { diff --git a/ast/src/input/program_state/private_state/record.rs b/ast/src/input/program_state/private_state/record.rs index 4cb71920aa..7439c57bd5 100644 --- a/ast/src/input/program_state/private_state/record.rs +++ b/ast/src/input/program_state/private_state/record.rs @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; +use crate::InputValue; +use crate::Parameter; +use leo_input::definitions::Definition; +use leo_input::InputParserError; use indexmap::IndexMap; diff --git a/ast/src/input/program_state/private_state/state_leaf.rs b/ast/src/input/program_state/private_state/state_leaf.rs index 8e9b0e231b..138d053b34 100644 --- a/ast/src/input/program_state/private_state/state_leaf.rs +++ b/ast/src/input/program_state/private_state/state_leaf.rs @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; +use crate::InputValue; +use crate::Parameter; +use leo_input::definitions::Definition; +use leo_input::InputParserError; use indexmap::IndexMap; diff --git a/ast/src/input/program_state/program_state.rs b/ast/src/input/program_state/program_state.rs index 04275d176c..693c88fdc5 100644 --- a/ast/src/input/program_state/program_state.rs +++ b/ast/src/input/program_state/program_state.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{PrivateState, PublicState, Record, State, StateLeaf}; -use leo_input::{ - tables::{Table, Visibility}, - InputParserError, -}; +use crate::PrivateState; +use crate::PublicState; +use crate::Record; +use crate::State; +use crate::StateLeaf; +use leo_input::tables::Table; +use leo_input::tables::Visibility; +use leo_input::InputParserError; #[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramState { diff --git a/ast/src/input/program_state/public_state/public_state.rs b/ast/src/input/program_state/public_state/public_state.rs index 995aa06759..7fe4acd2a2 100644 --- a/ast/src/input/program_state/public_state/public_state.rs +++ b/ast/src/input/program_state/public_state/public_state.rs @@ -15,10 +15,9 @@ // along with the Leo library. If not, see . use crate::State; -use leo_input::{ - sections::{Header, Section}, - InputParserError, -}; +use leo_input::sections::Header; +use leo_input::sections::Section; +use leo_input::InputParserError; #[derive(Clone, PartialEq, Eq, Default)] pub struct PublicState { diff --git a/ast/src/input/program_state/public_state/state.rs b/ast/src/input/program_state/public_state/state.rs index dda85ddf94..04d32b6db2 100644 --- a/ast/src/input/program_state/public_state/state.rs +++ b/ast/src/input/program_state/public_state/state.rs @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputValue, Parameter}; -use leo_input::{definitions::Definition, InputParserError}; +use crate::InputValue; +use crate::Parameter; +use leo_input::definitions::Definition; +use leo_input::InputParserError; use indexmap::IndexMap; diff --git a/ast/src/main.rs b/ast/src/main.rs index 02f627cc4a..19f34a4e50 100644 --- a/ast/src/main.rs +++ b/ast/src/main.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Ast, AstError}; +use leo_ast::Ast; +use leo_ast::AstError; use leo_grammar::Grammar; -use std::{env, fs, path::Path}; +use std::env; +use std::fs; +use std::path::Path; fn to_leo_tree(filepath: &Path) -> Result { // Loads the Leo code as a string from the given file path. diff --git a/ast/src/program.rs b/ast/src/program.rs index 531a6316bb..9a669f25f0 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -17,20 +17,20 @@ //! A Leo program consists of import, circuit, and function definitions. //! Each defined type consists of ast statements and expressions. -use crate::{ - load_annotation, - Circuit, - DeprecatedError, - Function, - FunctionInput, - Identifier, - ImportStatement, - TestFunction, -}; -use leo_grammar::{definitions::Definition, files::File}; +use crate::load_annotation; +use crate::Circuit; +use crate::DeprecatedError; +use crate::Function; +use crate::FunctionInput; +use crate::Identifier; +use crate::ImportStatement; +use crate::TestFunction; +use leo_grammar::definitions::Definition; +use leo_grammar::files::File; use indexmap::IndexMap; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Stores the Leo program abstract syntax tree. diff --git a/ast/src/statements/assign/assignee.rs b/ast/src/statements/assign/assignee.rs index e84cccf2a9..98dae1a57e 100644 --- a/ast/src/statements/assign/assignee.rs +++ b/ast/src/statements/assign/assignee.rs @@ -14,13 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Identifier, PositiveNumber, Span}; -use leo_grammar::{ - access::{ArrayAccess, AssigneeAccess as GrammarAssigneeAccess}, - common::{Assignee as GrammarAssignee, Range, RangeOrExpression}, -}; +use crate::Expression; +use crate::Identifier; +use crate::PositiveNumber; +use crate::Span; +use leo_grammar::access::ArrayAccess; +use leo_grammar::access::AssigneeAccess as GrammarAssigneeAccess; +use leo_grammar::common::Assignee as GrammarAssignee; +use leo_grammar::common::Range; +use leo_grammar::common::RangeOrExpression; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/assign/mod.rs b/ast/src/statements/assign/mod.rs index 947472d14c..fa729749d8 100644 --- a/ast/src/statements/assign/mod.rs +++ b/ast/src/statements/assign/mod.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Node, Span}; +use crate::Expression; +use crate::Node; +use crate::Span; pub use leo_grammar::operations::AssignOperation as GrammarAssignOperation; use leo_grammar::statements::AssignStatement as GrammarAssignStatement; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; mod assignee; diff --git a/ast/src/statements/block.rs b/ast/src/statements/block.rs index d6cb72f26f..db0ccc8028 100644 --- a/ast/src/statements/block.rs +++ b/ast/src/statements/block.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span, Statement}; +use crate::Node; +use crate::Span; +use crate::Statement; use leo_grammar::statements::Block as GrammarBlock; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/conditional.rs b/ast/src/statements/conditional.rs index cf836ef3ed..7ea09f39e3 100644 --- a/ast/src/statements/conditional.rs +++ b/ast/src/statements/conditional.rs @@ -14,10 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Block, Expression, Node, Span, Statement}; -use leo_grammar::statements::{ConditionalNestedOrEndStatement, ConditionalStatement as GrammarConditionalStatement}; +use crate::Block; +use crate::Expression; +use crate::Node; +use crate::Span; +use crate::Statement; +use leo_grammar::statements::ConditionalNestedOrEndStatement; +use leo_grammar::statements::ConditionalStatement as GrammarConditionalStatement; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/console/console_function.rs b/ast/src/statements/console/console_function.rs index 7e9f9892ca..6bbad1da57 100644 --- a/ast/src/statements/console/console_function.rs +++ b/ast/src/statements/console/console_function.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, FormattedString}; -use leo_grammar::console::{ - ConsoleAssert as GrammarConsoleAssert, - ConsoleDebug as GrammarConsoleDebug, - ConsoleError as GrammarConsoleError, - ConsoleFunction as GrammarConsoleFunction, - ConsoleLog as GrammarConsoleLog, -}; +use crate::Expression; +use crate::FormattedString; +use leo_grammar::console::ConsoleAssert as GrammarConsoleAssert; +use leo_grammar::console::ConsoleDebug as GrammarConsoleDebug; +use leo_grammar::console::ConsoleError as GrammarConsoleError; +use leo_grammar::console::ConsoleFunction as GrammarConsoleFunction; +use leo_grammar::console::ConsoleLog as GrammarConsoleLog; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/console/console_statement.rs b/ast/src/statements/console/console_statement.rs index ad837f42f5..d51b4d8670 100644 --- a/ast/src/statements/console/console_statement.rs +++ b/ast/src/statements/console/console_statement.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ConsoleFunction, Node, Span}; +use crate::ConsoleFunction; +use crate::Node; +use crate::Span; use leo_grammar::console::ConsoleFunctionCall as GrammarConsoleFunctionCall; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/console/formatted_container.rs b/ast/src/statements/console/formatted_container.rs index 4634aa4c4a..1c35df5981 100644 --- a/ast/src/statements/console/formatted_container.rs +++ b/ast/src/statements/console/formatted_container.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Node, Span}; +use crate::Node; +use crate::Span; use leo_grammar::console::FormattedContainer as GrammarFormattedContainer; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/console/formatted_string.rs b/ast/src/statements/console/formatted_string.rs index f96baa1fe1..e94f6175be 100644 --- a/ast/src/statements/console/formatted_string.rs +++ b/ast/src/statements/console/formatted_string.rs @@ -14,10 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, FormattedContainer, Node, Span}; +use crate::Expression; +use crate::FormattedContainer; +use crate::Node; +use crate::Span; use leo_grammar::console::FormattedString as GrammarFormattedString; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/definition/declare.rs b/ast/src/statements/definition/declare.rs index de00d5f210..799702fa28 100644 --- a/ast/src/statements/definition/declare.rs +++ b/ast/src/statements/definition/declare.rs @@ -16,7 +16,8 @@ use leo_grammar::common::Declare as GrammarDeclare; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/definition/mod.rs b/ast/src/statements/definition/mod.rs index 78ad5ea933..ac24a4a37b 100644 --- a/ast/src/statements/definition/mod.rs +++ b/ast/src/statements/definition/mod.rs @@ -14,9 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Node, Span, Type}; +use crate::Expression; +use crate::Node; +use crate::Span; +use crate::Type; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; mod variable_name; diff --git a/ast/src/statements/definition/variable_name.rs b/ast/src/statements/definition/variable_name.rs index 7384b8ee1d..fa27f9c20f 100644 --- a/ast/src/statements/definition/variable_name.rs +++ b/ast/src/statements/definition/variable_name.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Identifier, Node, Span}; +use crate::Identifier; +use crate::Node; +use crate::Span; use leo_grammar::common::VariableName as GrammarVariableName; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/expression.rs b/ast/src/statements/expression.rs index f9ff66313c..542da065ca 100644 --- a/ast/src/statements/expression.rs +++ b/ast/src/statements/expression.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Node, Span}; +use crate::Expression; +use crate::Node; +use crate::Span; use leo_grammar::statements::ExpressionStatement as GrammarExpressionStatement; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/iteration.rs b/ast/src/statements/iteration.rs index 70126ff8ad..74afb710fd 100644 --- a/ast/src/statements/iteration.rs +++ b/ast/src/statements/iteration.rs @@ -14,10 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Block, Expression, Identifier, Node, Span}; +use crate::Block; +use crate::Expression; +use crate::Identifier; +use crate::Node; +use crate::Span; use leo_grammar::statements::ForStatement; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/return_statement.rs b/ast/src/statements/return_statement.rs index e1279b09c2..6de10692fa 100644 --- a/ast/src/statements/return_statement.rs +++ b/ast/src/statements/return_statement.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Expression, Node, Span}; +use crate::Expression; +use crate::Node; +use crate::Span; use leo_grammar::statements::ReturnStatement as GrammarReturnStatement; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/statement.rs b/ast/src/statements/statement.rs index 31067093e7..f44b62a262 100644 --- a/ast/src/statements/statement.rs +++ b/ast/src/statements/statement.rs @@ -14,12 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ConditionalStatement, Node, Span}; +use crate::ConditionalStatement; +use crate::Node; +use crate::Span; use leo_grammar::statements::Statement as GrammarStatement; use super::*; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Program statement that defines some action (or expression) to be carried out. diff --git a/ast/src/types/integer_type.rs b/ast/src/types/integer_type.rs index 1ced1e76f7..d667fe7259 100644 --- a/ast/src/types/integer_type.rs +++ b/ast/src/types/integer_type.rs @@ -14,18 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::types::{ - IntegerType as GrammarIntegerType, - SignedIntegerType as GrammarSignedIntegerType, - UnsignedIntegerType as GrammarUnsignedIntegerType, -}; -use leo_input::types::{ - IntegerType as InputIntegerType, - SignedIntegerType as InputSignedIntegerType, - UnsignedIntegerType as InputUnsignedIntegerType, -}; +use leo_grammar::types::IntegerType as GrammarIntegerType; +use leo_grammar::types::SignedIntegerType as GrammarSignedIntegerType; +use leo_grammar::types::UnsignedIntegerType as GrammarUnsignedIntegerType; +use leo_input::types::IntegerType as InputIntegerType; +use leo_input::types::SignedIntegerType as InputSignedIntegerType; +use leo_input::types::UnsignedIntegerType as InputUnsignedIntegerType; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Explicit integer type diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index 1d20699c31..0ad451a8c4 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -14,16 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ArrayDimensions, Identifier, IntegerType}; -use leo_grammar::types::{ArrayType, CircuitType, DataType, TupleType, Type as GrammarType}; -use leo_input::types::{ - ArrayType as InputArrayType, - DataType as InputDataType, - TupleType as InputTupleType, - Type as InputType, -}; +use crate::ArrayDimensions; +use crate::Identifier; +use crate::IntegerType; +use leo_grammar::types::ArrayType; +use leo_grammar::types::CircuitType; +use leo_grammar::types::DataType; +use leo_grammar::types::TupleType; +use leo_grammar::types::Type as GrammarType; +use leo_input::types::ArrayType as InputArrayType; +use leo_input::types::DataType as InputDataType; +use leo_input::types::TupleType as InputTupleType; +use leo_input::types::Type as InputType; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use std::fmt; /// Explicit type used for defining a variable or expression type diff --git a/ast/tests/serialization/json.rs b/ast/tests/serialization/json.rs index 5a58ff12c5..4257cc9af3 100644 --- a/ast/tests/serialization/json.rs +++ b/ast/tests/serialization/json.rs @@ -14,12 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use leo_ast::Ast; +use leo_ast::AstError; #[cfg(not(feature = "ci_skip"))] use leo_ast::Program; -use leo_ast::{Ast, AstError}; -use leo_grammar::{Grammar, ParserError}; +use leo_grammar::Grammar; +use leo_grammar::ParserError; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; fn to_ast(program_filepath: &Path) -> Result { // Loads the Leo code as a string from the given file path. diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index ee2a11b170..ca4da8319a 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -16,35 +16,39 @@ //! Compiles a Leo program from a file path. -use crate::{ - constraints::{generate_constraints, generate_test_constraints}, - errors::CompilerError, - GroupType, - OutputBytes, - OutputFile, -}; +use crate::constraints::generate_constraints; +use crate::constraints::generate_test_constraints; +use crate::errors::CompilerError; +use crate::GroupType; +use crate::OutputBytes; +use crate::OutputFile; use leo_asg::Asg; -use leo_ast::{Ast, Input, MainInput, Program}; +use leo_ast::Ast; +use leo_ast::Input; +use leo_ast::MainInput; +use leo_ast::Program; use leo_grammar::Grammar; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use leo_state::verify_local_data_commitment; -use snarkvm_dpc::{base_dpc::instantiated::Components, SystemParameters}; +use snarkvm_dpc::base_dpc::instantiated::Components; +use snarkvm_dpc::SystemParameters; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::r1cs::{ConstraintSynthesizer, ConstraintSystem}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSynthesizer; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use sha2::{Digest, Sha256}; -use std::{ - fs, - marker::PhantomData, - path::{Path, PathBuf}, -}; +use sha2::Digest; +use sha2::Sha256; +use std::fs; +use std::marker::PhantomData; +use std::path::Path; +use std::path::PathBuf; -pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; +pub use leo_asg::new_context; +pub use leo_asg::AsgContext as Context; +pub use leo_asg::AsgContext; thread_local! { static THREAD_GLOBAL_CONTEXT: AsgContext<'static> = { diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index 9d47cd5afa..8e1e7b08d2 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -16,19 +16,17 @@ //! Enforces an assert equals statement in a compiled Leo program. -use crate::{ - errors::ConsoleError, - get_indicator_value, - program::ConstrainedProgram, - value::ConstrainedValue, - GroupType, -}; -use leo_asg::{Expression, Span}; +use crate::errors::ConsoleError; +use crate::get_indicator_value; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Span; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn evaluate_console_assert>( diff --git a/compiler/src/console/console.rs b/compiler/src/console/console.rs index 2603cd8db7..dd4b20461d 100644 --- a/compiler/src/console/console.rs +++ b/compiler/src/console/console.rs @@ -16,13 +16,16 @@ //! Evaluates a macro in a compiled Leo program. -use crate::{errors::ConsoleError, program::ConstrainedProgram, statement::get_indicator_value, GroupType}; -use leo_asg::{ConsoleFunction, ConsoleStatement}; +use crate::errors::ConsoleError; +use crate::program::ConstrainedProgram; +use crate::statement::get_indicator_value; +use crate::GroupType; +use leo_asg::ConsoleFunction; +use leo_asg::ConsoleStatement; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn evaluate_console_function_call>( diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index 048303a023..a01aca7a0a 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -16,10 +16,13 @@ //! Evaluates a formatted string in a compiled Leo program. -use crate::{errors::ConsoleError, program::ConstrainedProgram, GroupType}; +use crate::errors::ConsoleError; +use crate::program::ConstrainedProgram; +use crate::GroupType; use leo_asg::FormattedString; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn format>( diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 412d8e30cc..1faee8346a 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -16,16 +16,19 @@ //! Generates R1CS constraints for a compiled Leo program. -use crate::{errors::CompilerError, ConstrainedProgram, GroupType, OutputBytes, OutputFile}; +use crate::errors::CompilerError; +use crate::ConstrainedProgram; +use crate::GroupType; +use crate::OutputBytes; +use crate::OutputFile; use leo_asg::Asg; use leo_ast::Input; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; -use snarkvm_models::{ - curves::PrimeField, - gadgets::r1cs::{ConstraintSystem, TestConstraintSystem}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use std::path::Path; pub fn generate_constraints<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/definition/definition.rs b/compiler/src/definition/definition.rs index 75e225b135..1f440f1747 100644 --- a/compiler/src/definition/definition.rs +++ b/compiler/src/definition/definition.rs @@ -16,7 +16,9 @@ //! Stores all defined names in a compiled Leo program. -use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Variable; use snarkvm_models::curves::PrimeField; diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index c8e7b496a9..4fb6e9f09e 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; +use crate::errors::FunctionError; +use crate::errors::ImportError; +use crate::errors::OutputBytesError; +use crate::errors::OutputFileError; use leo_asg::AsgConvertError; use leo_ast::AstError; use leo_grammar::ParserError; @@ -23,7 +26,8 @@ use leo_input::InputParserError; use leo_state::LocalDataVerificationError; use bincode::Error as SerdeError; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum CompilerError { diff --git a/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index c68a0035dd..f16baf21c7 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -15,7 +15,8 @@ // along with the Leo library. If not, see . use crate::errors::ExpressionError; -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use std::path::Path; diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index 38d17fe2e3..3be7305635 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -14,8 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::{AddressError, BooleanError, FieldError, FunctionError, GroupError, IntegerError, ValueError}; -use leo_ast::{ArrayDimensions, Error as FormattedError, Identifier, PositiveNumber, Span}; +use crate::errors::AddressError; +use crate::errors::BooleanError; +use crate::errors::FieldError; +use crate::errors::FunctionError; +use crate::errors::GroupError; +use crate::errors::IntegerError; +use crate::errors::ValueError; +use leo_ast::ArrayDimensions; +use leo_ast::Error as FormattedError; +use leo_ast::Identifier; +use leo_ast::PositiveNumber; +use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/function.rs b/compiler/src/errors/function.rs index 5422761581..4c66df6de3 100644 --- a/compiler/src/errors/function.rs +++ b/compiler/src/errors/function.rs @@ -14,19 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::{ - AddressError, - BooleanError, - ExpressionError, - FieldError, - GroupError, - IntegerError, - OutputBytesError, - StatementError, - ValueError, -}; +use crate::errors::AddressError; +use crate::errors::BooleanError; +use crate::errors::ExpressionError; +use crate::errors::FieldError; +use crate::errors::GroupError; +use crate::errors::IntegerError; +use crate::errors::OutputBytesError; +use crate::errors::StatementError; +use crate::errors::ValueError; use leo_asg::AsgConvertError; -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use std::path::Path; diff --git a/compiler/src/errors/import.rs b/compiler/src/errors/import.rs index 74ee48cc83..325c2d3789 100644 --- a/compiler/src/errors/import.rs +++ b/compiler/src/errors/import.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Identifier, ImportSymbol, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Identifier; +use leo_ast::ImportSymbol; +use leo_ast::Span; #[derive(Debug, Error)] pub enum ImportError { diff --git a/compiler/src/errors/output_bytes.rs b/compiler/src/errors/output_bytes.rs index 71649b0910..d1cb4508e5 100644 --- a/compiler/src/errors/output_bytes.rs +++ b/compiler/src/errors/output_bytes.rs @@ -15,8 +15,10 @@ // along with the Leo library. If not, see . use crate::errors::ValueError; -use leo_asg::{AsgConvertError, Type}; -use leo_ast::{Error as FormattedError, Span}; +use leo_asg::AsgConvertError; +use leo_asg::Type; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use std::path::Path; diff --git a/compiler/src/errors/output_file.rs b/compiler/src/errors/output_file.rs index c8b18185d6..0d584ea0d3 100644 --- a/compiler/src/errors/output_file.rs +++ b/compiler/src/errors/output_file.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum OutputFileError { diff --git a/compiler/src/errors/statement.rs b/compiler/src/errors/statement.rs index d915d40dff..c35c2d155a 100644 --- a/compiler/src/errors/statement.rs +++ b/compiler/src/errors/statement.rs @@ -14,9 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::{AddressError, BooleanError, ConsoleError, ExpressionError, IntegerError, ValueError}; +use crate::errors::AddressError; +use crate::errors::BooleanError; +use crate::errors::ConsoleError; +use crate::errors::ExpressionError; +use crate::errors::IntegerError; +use crate::errors::ValueError; use leo_asg::Type; -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use std::path::Path; diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index aa5c769ffb..6cd7bee1bf 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; -use snarkvm_errors::{gadgets::SynthesisError, objects::account::AccountError}; +use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_errors::objects::account::AccountError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/errors/value/boolean.rs b/compiler/src/errors/value/boolean.rs index fd0a5d8470..ee17dbf182 100644 --- a/compiler/src/errors/value/boolean.rs +++ b/compiler/src/errors/value/boolean.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/value/field.rs b/compiler/src/errors/value/field.rs index 55509037eb..cc92bbc24c 100644 --- a/compiler/src/errors/value/field.rs +++ b/compiler/src/errors/value/field.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index 3de87b9b99..a241a6e641 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{Error as FormattedError, Span}; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index 43be823d92..ba8b18c928 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{error::Error as FormattedError, IntegerType, Span, Type}; +use leo_ast::error::Error as FormattedError; +use leo_ast::IntegerType; +use leo_ast::Span; +use leo_ast::Type; use leo_gadgets::errors::SignedIntegerError; use snarkvm_errors::gadgets::SynthesisError; diff --git a/compiler/src/errors/value/value.rs b/compiler/src/errors/value/value.rs index 66a7d50e83..cd478445c4 100644 --- a/compiler/src/errors/value/value.rs +++ b/compiler/src/errors/value/value.rs @@ -14,8 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::{AddressError, BooleanError, FieldError, GroupError, IntegerError}; -use leo_ast::{Error as FormattedError, Span}; +use crate::errors::AddressError; +use crate::errors::BooleanError; +use crate::errors::FieldError; +use crate::errors::GroupError; +use crate::errors::IntegerError; +use leo_ast::Error as FormattedError; +use leo_ast::Span; use std::path::Path; diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index e2edaa93c1..20f1e0375a 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -16,10 +16,13 @@ //! Enforces an arithmetic `+` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn enforce_add<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 1c8ea36f5d..d5f8df488c 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -16,10 +16,13 @@ //! Enforces an arithmetic `/` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn enforce_div<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index 0500ae7705..f8b4f643ae 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -16,10 +16,13 @@ //! Enforces an arithmetic `*` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn enforce_mul<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/negate.rs b/compiler/src/expression/arithmetic/negate.rs index 72891e9547..3886c4e17b 100644 --- a/compiler/src/expression/arithmetic/negate.rs +++ b/compiler/src/expression/arithmetic/negate.rs @@ -16,10 +16,13 @@ //! Enforces a unary negate `-` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn enforce_negate<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index 3df43fac76..f8a7a450d9 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -16,10 +16,13 @@ //! Enforces an arithmetic `**` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn enforce_pow<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index 1abac1547a..a5cd600dbc 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -16,10 +16,13 @@ //! Enforces an arithmetic `-` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn enforce_sub<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 8a9469ca7a..4f2e2f84f7 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -16,10 +16,15 @@ //! Enforces array access in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{Expression, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 04c60441b3..003d990e14 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -18,10 +18,15 @@ use std::cell::Cell; -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{Expression, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce array expressions diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index 4b6bb27c6e..af86fdc675 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -16,10 +16,15 @@ //! Enforces an array index expression in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{Expression, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn enforce_index>( diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index 0509ce90b8..0fd10c61ee 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -16,10 +16,14 @@ //! Enforces a binary expression in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Expression; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; type ConstrainedValuePair<'a, T, U> = (ConstrainedValue<'a, T, U>, ConstrainedValue<'a, T, U>); diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 09d3327ca1..c37960ed30 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -16,10 +16,15 @@ //! Enforces a circuit access expression in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{CircuitAccessExpression, Node}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::CircuitAccessExpression; +use leo_asg::Node; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index fba53cab5b..283cf6f79d 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -16,15 +16,17 @@ //! Enforces a circuit expression in a compiled Leo program. -use crate::{ - errors::ExpressionError, - program::ConstrainedProgram, - value::{ConstrainedCircuitMember, ConstrainedValue}, - GroupType, -}; -use leo_asg::{CircuitInitExpression, CircuitMember, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedCircuitMember; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::CircuitInitExpression; +use leo_asg::CircuitMember; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn enforce_circuit>( diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index aa515d5346..4e163f7075 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -16,13 +16,16 @@ //! Enforces a conditional expression in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{Expression, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Span; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::select::CondSelectGadget}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce ternary conditional expression diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index e399d090ae..f0279fa4e2 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -16,23 +16,25 @@ //! Enforce constraints on an expression in a compiled Leo program. -use crate::{ - arithmetic::*, - errors::ExpressionError, - logical::*, - program::ConstrainedProgram, - relational::*, - resolve_core_circuit, - value::{Address, ConstrainedValue, Integer}, - FieldType, - GroupType, -}; -use leo_asg::{expression::*, ConstValue, Expression, Node}; +use crate::arithmetic::*; +use crate::errors::ExpressionError; +use crate::logical::*; +use crate::program::ConstrainedProgram; +use crate::relational::*; +use crate::resolve_core_circuit; +use crate::value::Address; +use crate::value::ConstrainedValue; +use crate::value::Integer; +use crate::FieldType; +use crate::GroupType; +use leo_asg::expression::*; +use leo_asg::ConstValue; +use leo_asg::Expression; +use leo_asg::Node; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn enforce_expression>( diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 663973f4df..732f6c132e 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -16,11 +16,17 @@ use std::cell::Cell; -use crate::{program::ConstrainedProgram, value::ConstrainedValue, CoreCircuit, GroupType}; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::CoreCircuit; +use crate::GroupType; use crate::errors::ExpressionError; -use leo_asg::{Expression, Function, Span}; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use leo_asg::Expression; +use leo_asg::Function; +use leo_asg::Span; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Call a default core circuit function with arguments diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index ba1888c4c6..730920fc32 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -18,10 +18,16 @@ use std::cell::Cell; -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{Expression, Function, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Function; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 0d8ef3773d..0c27aaaab4 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -16,13 +16,14 @@ //! Enforces a logical `&&` operator in a resolved Leo program. -use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; +use crate::errors::BooleanError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/logical/not.rs b/compiler/src/expression/logical/not.rs index 84d16c5be8..6ab5d83021 100644 --- a/compiler/src/expression/logical/not.rs +++ b/compiler/src/expression/logical/not.rs @@ -16,7 +16,9 @@ //! Enforces a logical `!` operator in a resolved Leo program. -use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; +use crate::errors::BooleanError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; use snarkvm_models::curves::PrimeField; diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index ec1739d085..fe70594d91 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -16,13 +16,14 @@ //! Enforces a logical `||` operator in a resolved Leo program. -use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; +use crate::errors::BooleanError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; pub fn enforce_or<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 99dfe39e42..297de28a1e 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -16,16 +16,16 @@ //! Enforces a relational `==` operator in a resolved Leo program. -use crate::{enforce_and, errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::enforce_and; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, eq::EvaluateEqGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index 0788633554..e52e06808e 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -16,11 +16,14 @@ //! Enforces a relational `>=` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index 8590e17b6c..f946eb4759 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -16,11 +16,14 @@ //! Enforces a relational `>` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 38ba4ba6d1..21388b24f6 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -16,11 +16,14 @@ //! Enforces a relational `<=` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 5282f60335..34d772bc72 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -16,11 +16,14 @@ //! Enforces a relational `<` operator in a resolved Leo program. -use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::comparator::EvaluateLtGadget; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 1f219a4d9a..83e626101b 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -16,10 +16,15 @@ //! Enforces array access in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{Expression, Span}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::Expression; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/tuple/tuple.rs b/compiler/src/expression/tuple/tuple.rs index 4759d0fef1..27f716c029 100644 --- a/compiler/src/expression/tuple/tuple.rs +++ b/compiler/src/expression/tuple/tuple.rs @@ -18,10 +18,14 @@ use std::cell::Cell; -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Expression; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce tuple expressions diff --git a/compiler/src/expression/variable_ref/variable_ref.rs b/compiler/src/expression/variable_ref/variable_ref.rs index c120dc2da8..f8bf605056 100644 --- a/compiler/src/expression/variable_ref/variable_ref.rs +++ b/compiler/src/expression/variable_ref/variable_ref.rs @@ -16,7 +16,10 @@ //! Enforces an identifier expression in a compiled Leo program. -use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::ExpressionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::VariableRef; use snarkvm_models::curves::PrimeField; diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 23dcda03b2..bffcf28444 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -16,15 +16,19 @@ //! Enforces constraints on a function in a compiled Leo program. -use crate::{errors::FunctionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::FunctionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; -use leo_asg::{Expression, Function, FunctionQualifier}; +use leo_asg::Expression; +use leo_asg::Function; +use leo_asg::FunctionQualifier; use std::cell::Cell; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn enforce_function>( diff --git a/compiler/src/function/input/array.rs b/compiler/src/function/input/array.rs index ebf3bca676..4e887488a1 100644 --- a/compiler/src/function/input/array.rs +++ b/compiler/src/function/input/array.rs @@ -16,12 +16,17 @@ //! Allocates an array as a main function input parameter in a compiled Leo program. -use crate::{errors::FunctionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::FunctionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Type; -use leo_ast::{InputValue, Span}; +use leo_ast::InputValue; +use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_array>( diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index e7aaed9fd6..31a82dfb53 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -14,11 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType}; -use leo_asg::{Circuit, CircuitMember, Type}; -use leo_ast::{Identifier, Input, Span}; +use crate::errors::FunctionError; +use crate::ConstrainedCircuitMember; +use crate::ConstrainedProgram; +use crate::ConstrainedValue; +use crate::GroupType; +use leo_asg::Circuit; +use leo_asg::CircuitMember; +use leo_asg::Type; +use leo_ast::Identifier; +use leo_ast::Input; +use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub const RECORD_VARIABLE_NAME: &str = "record"; pub const REGISTERS_VARIABLE_NAME: &str = "registers"; diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index 65331a3172..767e205e89 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -14,11 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType}; -use leo_asg::{AsgConvertError, Circuit, CircuitMember}; -use leo_ast::{Identifier, InputValue, Parameter}; +use crate::errors::FunctionError; +use crate::ConstrainedCircuitMember; +use crate::ConstrainedProgram; +use crate::ConstrainedValue; +use crate::GroupType; +use leo_asg::AsgConvertError; +use leo_asg::Circuit; +use leo_asg::CircuitMember; +use leo_ast::Identifier; +use leo_ast::InputValue; +use leo_ast::Parameter; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; use indexmap::IndexMap; diff --git a/compiler/src/function/input/main_function_input.rs b/compiler/src/function/input/main_function_input.rs index b4e5d540a3..2262956132 100644 --- a/compiler/src/function/input/main_function_input.rs +++ b/compiler/src/function/input/main_function_input.rs @@ -16,23 +16,21 @@ //! Allocates a main function input parameter in a compiled Leo program. -use crate::{ - address::Address, - errors::FunctionError, - program::ConstrainedProgram, - value::{ - boolean::input::bool_from_input, - field::input::field_from_input, - group::input::group_from_input, - ConstrainedValue, - }, - GroupType, - Integer, -}; +use crate::address::Address; +use crate::errors::FunctionError; +use crate::program::ConstrainedProgram; +use crate::value::boolean::input::bool_from_input; +use crate::value::field::input::field_from_input; +use crate::value::group::input::group_from_input; +use crate::value::ConstrainedValue; +use crate::GroupType; +use crate::Integer; use leo_asg::Type; -use leo_ast::{InputValue, Span}; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use leo_ast::InputValue; +use leo_ast::Span; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_main_function_input>( diff --git a/compiler/src/function/input/tuple.rs b/compiler/src/function/input/tuple.rs index 0530a0790f..1bde04d614 100644 --- a/compiler/src/function/input/tuple.rs +++ b/compiler/src/function/input/tuple.rs @@ -16,12 +16,17 @@ //! Allocates an array as a main function input parameter in a compiled Leo program. -use crate::{errors::FunctionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::FunctionError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Type; -use leo_ast::{InputValue, Span}; +use leo_ast::InputValue; +use leo_ast::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_tuple>( diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 45f6b28733..6a4da1728b 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -16,13 +16,19 @@ //! Enforces constraints on the main function of a compiled Leo program. -use crate::{errors::FunctionError, program::ConstrainedProgram, GroupType, OutputBytes}; +use crate::errors::FunctionError; +use crate::program::ConstrainedProgram; +use crate::GroupType; +use crate::OutputBytes; -use leo_asg::{Expression, Function, FunctionQualifier}; +use leo_asg::Expression; +use leo_asg::Function; +use leo_asg::FunctionQualifier; use leo_ast::Input; use std::cell::Cell; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn enforce_main_function>( diff --git a/compiler/src/function/mut_target.rs b/compiler/src/function/mut_target.rs index dd2f1c6582..b381c470c5 100644 --- a/compiler/src/function/mut_target.rs +++ b/compiler/src/function/mut_target.rs @@ -16,25 +16,22 @@ //! Resolves assignees in a compiled Leo program. -use crate::{ - errors::StatementError, - program::ConstrainedProgram, - value::ConstrainedValue, - GroupType, - ResolvedAssigneeAccess, -}; -use leo_asg::{ - ArrayAccessExpression, - ArrayRangeAccessExpression, - CircuitAccessExpression, - Expression, - Node, - Span, - TupleAccessExpression, - Variable, -}; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use crate::ResolvedAssigneeAccess; +use leo_asg::ArrayAccessExpression; +use leo_asg::ArrayRangeAccessExpression; +use leo_asg::CircuitAccessExpression; +use leo_asg::Expression; +use leo_asg::Node; +use leo_asg::Span; +use leo_asg::TupleAccessExpression; +use leo_asg::Variable; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { fn prepare_mut_access>( diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 57d0ad0bc5..7d90bfa3c9 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -16,23 +16,19 @@ //! Enforces that one return value is produced in a compiled Leo program. -use crate::{ - errors::StatementError, - get_indicator_value, - program::ConstrainedProgram, - value::ConstrainedValue, - GroupType, -}; +use crate::errors::StatementError; +use crate::get_indicator_value; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; -use leo_asg::{Span, Type}; +use leo_asg::Span; +use leo_asg::Type; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, select::CondSelectGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index df59b28f25..8fb1fe9705 100644 --- a/compiler/src/output/output_bytes.rs +++ b/compiler/src/output/output_bytes.rs @@ -14,13 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::OutputBytesError, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME}; +use crate::errors::OutputBytesError; +use crate::ConstrainedValue; +use crate::GroupType; +use crate::REGISTERS_VARIABLE_NAME; use leo_asg::Program; -use leo_ast::{Parameter, Registers, Span}; +use leo_ast::Parameter; +use leo_ast::Registers; +use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; /// Serialized program return output. #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] diff --git a/compiler/src/output/output_file.rs b/compiler/src/output/output_file.rs index 53194fcd28..d2aced5cdd 100644 --- a/compiler/src/output/output_file.rs +++ b/compiler/src/output/output_file.rs @@ -18,12 +18,11 @@ use crate::errors::OutputFileError; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/"; pub static OUTPUT_FILE_EXTENSION: &str = ".out"; diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index 96e68b38c6..f20d41562c 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -15,17 +15,18 @@ // along with the Leo library. If not, see . use super::CoreCircuit; -use crate::{errors::ExpressionError, ConstrainedValue, GroupType, Integer}; -use leo_asg::{Function, Span}; +use crate::errors::ExpressionError; +use crate::ConstrainedValue; +use crate::GroupType; +use crate::Integer; +use leo_asg::Function; +use leo_asg::Span; use snarkvm_gadgets::algorithms::prf::Blake2sGadget; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - algorithms::PRFGadget, - r1cs::ConstraintSystem, - utilities::{uint::UInt8, ToBytesGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::algorithms::PRFGadget; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::uint::UInt8; +use snarkvm_models::gadgets::utilities::ToBytesGadget; pub struct Blake2s; diff --git a/compiler/src/prelude/mod.rs b/compiler/src/prelude/mod.rs index 0319f67957..be3a4b0f41 100644 --- a/compiler/src/prelude/mod.rs +++ b/compiler/src/prelude/mod.rs @@ -17,9 +17,13 @@ pub mod blake2s; pub use blake2s::*; -use crate::{errors::ExpressionError, ConstrainedValue, GroupType}; -use leo_asg::{Function, Span}; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use crate::errors::ExpressionError; +use crate::ConstrainedValue; +use crate::GroupType; +use leo_asg::Function; +use leo_asg::Span; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub trait CoreCircuit<'a, F: PrimeField, G: GroupType>: Send + Sync { fn call_function>( diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index d956e8a1a2..cec1daf7fc 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -16,7 +16,8 @@ //! An in memory store to keep track of defined names when constraining a Leo program. -use crate::{value::ConstrainedValue, GroupType}; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Program; use snarkvm_models::curves::PrimeField; diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 625dd7d2b6..987358a078 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -16,16 +16,19 @@ //! Enforces an assign statement in a compiled Leo program. -use crate::{arithmetic::*, errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{AssignOperation, AssignStatement, Span}; +use crate::arithmetic::*; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::AssignOperation; +use leo_asg::AssignStatement; +use leo_asg::Span; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, select::CondSelectGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/statement/assign/assignee.rs b/compiler/src/statement/assign/assignee.rs index 74bf99479f..97cb46de9c 100644 --- a/compiler/src/statement/assign/assignee.rs +++ b/compiler/src/statement/assign/assignee.rs @@ -16,10 +16,17 @@ //! Resolves assignees in a compiled Leo program. -use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::{AssignAccess, AssignStatement, Identifier, Span}; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_asg::AssignAccess; +use leo_asg::AssignStatement; +use leo_asg::Identifier; +use leo_asg::Span; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub(crate) enum ResolvedAssigneeAccess { ArrayRange(Option, Option), diff --git a/compiler/src/statement/block/block.rs b/compiler/src/statement/block/block.rs index b7171a69b6..416b7174fa 100644 --- a/compiler/src/statement/block/block.rs +++ b/compiler/src/statement/block/block.rs @@ -16,13 +16,15 @@ //! Enforces a branch of a conditional or iteration statement in a compiled Leo program. -use crate::{program::ConstrainedProgram, GroupType, IndicatorAndConstrainedValue, StatementResult}; +use crate::program::ConstrainedProgram; +use crate::GroupType; +use crate::IndicatorAndConstrainedValue; +use crate::StatementResult; use leo_asg::BlockStatement; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Evaluates a branch of one or more statements and returns a result in diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index b7698b6109..9443b741b9 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -16,20 +16,17 @@ //! Methods to enforce constraints on statements in a compiled Leo program. -use crate::{ - errors::StatementError, - program::ConstrainedProgram, - value::ConstrainedValue, - GroupType, - IndicatorAndConstrainedValue, - StatementResult, -}; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use crate::IndicatorAndConstrainedValue; +use crate::StatementResult; use leo_asg::ConditionalStatement; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; fn indicator_to_string(indicator: &Boolean) -> String { indicator diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 96e53b9272..0575151b0e 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -16,10 +16,16 @@ //! Enforces a definition statement in a compiled Leo program. -use crate::{errors::StatementError, program::ConstrainedProgram, ConstrainedValue, GroupType}; -use leo_asg::{DefinitionStatement, Span, Variable}; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::ConstrainedValue; +use crate::GroupType; +use leo_asg::DefinitionStatement; +use leo_asg::Span; +use leo_asg::Variable; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { fn enforce_multiple_definition( diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index 2a9f4c33c9..fa80246a55 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -16,23 +16,18 @@ //! Enforces an iteration statement in a compiled Leo program. -use crate::{ - program::ConstrainedProgram, - value::ConstrainedValue, - GroupType, - IndicatorAndConstrainedValue, - Integer, - StatementResult, -}; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; +use crate::IndicatorAndConstrainedValue; +use crate::Integer; +use crate::StatementResult; use leo_asg::IterationStatement; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, uint::UInt32}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::uint::UInt32; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/statement/return_/return_.rs b/compiler/src/statement/return_/return_.rs index ed2ec85385..a8bb525a02 100644 --- a/compiler/src/statement/return_/return_.rs +++ b/compiler/src/statement/return_/return_.rs @@ -16,10 +16,14 @@ //! Enforces a return statement in a compiled Leo program. -use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::ReturnStatement; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn enforce_return_statement>( diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 786b4bf088..6ffcf6d3f6 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -16,13 +16,15 @@ //! Enforces a statement in a compiled Leo program. -use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::errors::StatementError; +use crate::program::ConstrainedProgram; +use crate::value::ConstrainedValue; +use crate::GroupType; use leo_asg::Statement; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; pub type StatementResult = Result; pub type IndicatorAndConstrainedValue<'a, T, U> = (Boolean, ConstrainedValue<'a, T, U>); diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 28ccb53dfb..de9c5dea84 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -14,27 +14,29 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::AddressError, ConstrainedValue, GroupType}; -use leo_ast::{InputValue, Span}; +use crate::errors::AddressError; +use crate::ConstrainedValue; +use crate::GroupType; +use leo_ast::InputValue; +use leo_ast::Span; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::{Assignment, ConstraintSystem}, - utilities::{ - alloc::AllocGadget, - boolean::Boolean, - eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, - select::CondSelectGadget, - uint::{UInt, UInt8}, - }, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::Assignment; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_models::gadgets::utilities::eq::EqGadget; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_models::gadgets::utilities::uint::UInt; +use snarkvm_models::gadgets::utilities::uint::UInt8; use snarkvm_objects::account::AccountAddress; use snarkvm_utilities::ToBytes; -use std::{borrow::Borrow, str::FromStr}; +use std::borrow::Borrow; +use std::str::FromStr; /// A public address #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index 8caa9a8e3e..cc116b014d 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -16,17 +16,17 @@ //! Methods to enforce constraints on input boolean values in a resolved Leo program. -use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; -use leo_ast::{InputValue, Span}; +use crate::errors::BooleanError; +use crate::value::ConstrainedValue; +use crate::GroupType; +use leo_ast::InputValue; +use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{alloc::AllocGadget, boolean::Boolean}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; pub(crate) fn allocate_bool>( cs: &mut CS, diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index db192bbad9..ed794e1960 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -16,28 +16,28 @@ //! A data type that represents a field value -use crate::{errors::FieldError, number_string_typing}; +use crate::errors::FieldError; +use crate::number_string_typing; use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - curves::{AllocatedFp, FieldGadget, FpGadget}, - r1cs::ConstraintSystem, - utilities::{ - alloc::AllocGadget, - boolean::Boolean, - eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, - select::CondSelectGadget, - uint::UInt8, - ToBitsGadget, - ToBytesGadget, - }, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::curves::AllocatedFp; +use snarkvm_models::gadgets::curves::FieldGadget; +use snarkvm_models::gadgets::curves::FpGadget; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_models::gadgets::utilities::eq::EqGadget; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_models::gadgets::utilities::uint::UInt8; +use snarkvm_models::gadgets::utilities::ToBitsGadget; +use snarkvm_models::gadgets::utilities::ToBytesGadget; -use std::{borrow::Borrow, cmp::Ordering}; +use std::borrow::Borrow; +use std::cmp::Ordering; #[derive(Clone, Debug)] pub enum FieldType { diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index c5a55bfda0..b296daace1 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -16,14 +16,18 @@ //! Methods to enforce constraints on input field values in a compiled Leo program. -use crate::{errors::FieldError, number_string_typing, value::ConstrainedValue, FieldType, GroupType}; -use leo_ast::{InputValue, Span}; +use crate::errors::FieldError; +use crate::number_string_typing; +use crate::value::ConstrainedValue; +use crate::FieldType; +use crate::GroupType; +use leo_ast::InputValue; +use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{r1cs::ConstraintSystem, utilities::alloc::AllocGadget}, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; pub(crate) fn allocate_field>( cs: &mut CS, diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index 730f6540c0..74afa68c99 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -17,22 +17,21 @@ //! A data type that represents members in the group formed by the set of affine points on a curve. use crate::errors::GroupError; -use leo_asg::{GroupValue, Span}; +use leo_asg::GroupValue; +use leo_asg::Span; -use snarkvm_models::{ - curves::{Field, One}, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{ - alloc::AllocGadget, - eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, - select::CondSelectGadget, - ToBitsGadget, - ToBytesGadget, - }, - }, -}; -use std::fmt::{Debug, Display}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::One; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_models::gadgets::utilities::eq::EqGadget; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_models::gadgets::utilities::ToBitsGadget; +use snarkvm_models::gadgets::utilities::ToBytesGadget; +use std::fmt::Debug; +use std::fmt::Display; pub trait GroupType: Sized diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 32e6c90edc..1106c724d1 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -16,12 +16,16 @@ //! Methods to enforce constraints on input group values in a Leo program. -use crate::{errors::GroupError, ConstrainedValue, GroupType}; -use leo_asg::{GroupValue, Span}; +use crate::errors::GroupError; +use crate::ConstrainedValue; +use crate::GroupType; +use leo_asg::GroupValue; +use leo_asg::Span; use leo_ast::InputValue; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; pub(crate) fn allocate_group, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index b9176f90f3..799a860114 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -14,36 +14,43 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::GroupError, number_string_typing, GroupType}; -use leo_asg::{GroupCoordinate, GroupValue, Span}; +use crate::errors::GroupError; +use crate::number_string_typing; +use crate::GroupType; +use leo_asg::GroupCoordinate; +use leo_asg::GroupValue; +use leo_asg::Span; -use snarkvm_curves::{ - edwards_bls12::{EdwardsAffine, EdwardsParameters, Fq}, - templates::twisted_edwards_extended::GroupAffine, -}; +use snarkvm_curves::edwards_bls12::EdwardsAffine; +use snarkvm_curves::edwards_bls12::EdwardsParameters; +use snarkvm_curves::edwards_bls12::Fq; +use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; -use snarkvm_models::{ - curves::{AffineCurve, Fp256, One, TEModelParameters, Zero}, - gadgets::{ - curves::{AllocatedFp, FieldGadget, FpGadget, GroupGadget}, - r1cs::ConstraintSystem, - utilities::{ - alloc::AllocGadget, - boolean::Boolean, - eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, - select::CondSelectGadget, - uint::UInt8, - ToBitsGadget, - ToBytesGadget, - }, - }, -}; -use std::{ - borrow::Borrow, - ops::{Mul, Neg, Sub}, - str::FromStr, -}; +use snarkvm_models::curves::AffineCurve; +use snarkvm_models::curves::Fp256; +use snarkvm_models::curves::One; +use snarkvm_models::curves::TEModelParameters; +use snarkvm_models::curves::Zero; +use snarkvm_models::gadgets::curves::AllocatedFp; +use snarkvm_models::gadgets::curves::FieldGadget; +use snarkvm_models::gadgets::curves::FpGadget; +use snarkvm_models::gadgets::curves::GroupGadget; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_models::gadgets::utilities::eq::EqGadget; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_models::gadgets::utilities::uint::UInt8; +use snarkvm_models::gadgets::utilities::ToBitsGadget; +use snarkvm_models::gadgets::utilities::ToBytesGadget; +use std::borrow::Borrow; +use std::ops::Mul; +use std::ops::Neg; +use std::ops::Sub; +use std::str::FromStr; #[derive(Clone, Debug)] pub enum EdwardsGroupType { diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 51b2a7c848..e743709fd4 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -15,29 +15,28 @@ // along with the Leo library. If not, see . //! Conversion of integer declarations to constraints in Leo. -use crate::{errors::IntegerError, IntegerTrait}; -use leo_asg::{ConstInt, IntegerType, Span}; +use crate::errors::IntegerError; +use crate::IntegerTrait; +use leo_asg::ConstInt; +use leo_asg::IntegerType; +use leo_asg::Span; use leo_ast::InputValue; -use leo_gadgets::{ - arithmetic::*, - bits::comparator::{ComparatorGadget, EvaluateLtGadget}, - signed_integer::*, -}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::bits::comparator::ComparatorGadget; +use leo_gadgets::bits::comparator::EvaluateLtGadget; +use leo_gadgets::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::{Field, PrimeField}, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{ - alloc::AllocGadget, - boolean::Boolean, - eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, - select::CondSelectGadget, - uint::*, - }, - }, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_models::gadgets::utilities::eq::EqGadget; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_models::gadgets::utilities::uint::*; use std::fmt; /// An integer type enum wrapping the integer value. diff --git a/compiler/src/value/integer/macros.rs b/compiler/src/value/integer/macros.rs index cb6eb81f8c..8040fb5792 100644 --- a/compiler/src/value/integer/macros.rs +++ b/compiler/src/value/integer/macros.rs @@ -16,10 +16,12 @@ use leo_gadgets::signed_integer::*; -use snarkvm_models::gadgets::utilities::{ - boolean::Boolean, - uint::{UInt128, UInt16, UInt32, UInt64, UInt8}, -}; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::uint::UInt128; +use snarkvm_models::gadgets::utilities::uint::UInt16; +use snarkvm_models::gadgets::utilities::uint::UInt32; +use snarkvm_models::gadgets::utilities::uint::UInt64; +use snarkvm_models::gadgets::utilities::uint::UInt8; use std::fmt::Debug; pub trait IntegerTrait: Sized + Clone + Debug { diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 873440ad79..055116375f 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -16,17 +16,22 @@ //! The in memory stored value for a defined name in a compiled Leo program. -use crate::{errors::ValueError, Address, FieldType, GroupType, Integer}; -use leo_asg::{Circuit, Identifier, Span, Type}; +use crate::errors::ValueError; +use crate::Address; +use crate::FieldType; +use crate::GroupType; +use crate::Integer; +use leo_asg::Circuit; +use leo_asg::Identifier; +use leo_asg::Span; +use leo_asg::Type; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, eq::ConditionalEqGadget, select::CondSelectGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; use std::fmt; #[derive(Clone, PartialEq, Eq)] diff --git a/compiler/tests/address/mod.rs b/compiler/tests/address/mod.rs index b0193ffbdf..d673192650 100644 --- a/compiler/tests/address/mod.rs +++ b/compiler/tests/address/mod.rs @@ -14,7 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_asg_error, expect_compiler_error, generate_main_input, parse_program}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::parse_program; use leo_ast::InputValue; static TEST_ADDRESS_1: &str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8"; diff --git a/compiler/tests/array/mod.rs b/compiler/tests/array/mod.rs index fb01748d2f..6c41ce7c3d 100644 --- a/compiler/tests/array/mod.rs +++ b/compiler/tests/array/mod.rs @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - get_output, - parse_program, - parse_program_with_input, - EdwardsTestCompiler, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::get_output; +use crate::parse_program; +use crate::parse_program_with_input; +use crate::EdwardsTestCompiler; pub fn output_ones(program: EdwardsTestCompiler) { let expected = include_bytes!("output/registers_ones.out"); diff --git a/compiler/tests/boolean/mod.rs b/compiler/tests/boolean/mod.rs index 4051bf83d9..768920731c 100644 --- a/compiler/tests/boolean/mod.rs +++ b/compiler/tests/boolean/mod.rs @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - get_output, - parse_program, - parse_program_with_input, - EdwardsTestCompiler, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::get_output; +use crate::parse_program; +use crate::parse_program_with_input; +use crate::EdwardsTestCompiler; pub fn output_true(program: EdwardsTestCompiler) { let expected = include_bytes!("output/registers_true.out"); diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs index 3fe4b54955..1c57e896dc 100644 --- a/compiler/tests/circuits/mod.rs +++ b/compiler/tests/circuits/mod.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_asg_error, parse_program}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::parse_program; // Expressions diff --git a/compiler/tests/compiler/mod.rs b/compiler/tests/compiler/mod.rs index d07b11b69a..ec9b64bc53 100644 --- a/compiler/tests/compiler/mod.rs +++ b/compiler/tests/compiler/mod.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{get_output, EdwardsTestCompiler}; +use crate::get_output; +use crate::EdwardsTestCompiler; -use std::{env::current_dir, path::PathBuf}; +use std::env::current_dir; +use std::path::PathBuf; static MAIN_FILE_NAME: &str = "tests/compiler/main.leo"; diff --git a/compiler/tests/console/mod.rs b/compiler/tests/console/mod.rs index 62ff5bce6f..954918cb94 100644 --- a/compiler/tests/console/mod.rs +++ b/compiler/tests/console/mod.rs @@ -14,14 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - parse_program, - parse_program_with_input, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::parse_program; +use crate::parse_program_with_input; use leo_ast::InputValue; #[test] diff --git a/compiler/tests/core/mod.rs b/compiler/tests/core/mod.rs index c4a6bb48a5..598606fba7 100644 --- a/compiler/tests/core/mod.rs +++ b/compiler/tests/core/mod.rs @@ -16,7 +16,9 @@ pub mod packages; -use crate::{assert_satisfied, expect_asg_error, parse_program}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::parse_program; #[test] fn test_core_circuit_invalid() { diff --git a/compiler/tests/core/packages/unstable/blake2s/mod.rs b/compiler/tests/core/packages/unstable/blake2s/mod.rs index 98bffe41e2..94ce6b08ef 100644 --- a/compiler/tests/core/packages/unstable/blake2s/mod.rs +++ b/compiler/tests/core/packages/unstable/blake2s/mod.rs @@ -14,17 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - generate_main_input, - get_output, - parse_program, - parse_program_with_input, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::generate_main_input; +use crate::get_output; +use crate::parse_program; +use crate::parse_program_with_input; use leo_ast::InputValue; -use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType}; +use leo_input::types::IntegerType; +use leo_input::types::U8Type; +use leo_input::types::UnsignedIntegerType; use rand::Rng; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; diff --git a/compiler/tests/definition/mod.rs b/compiler/tests/definition/mod.rs index e5faf8b2de..b6d4f463c9 100644 --- a/compiler/tests/definition/mod.rs +++ b/compiler/tests/definition/mod.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, import::set_local_dir, parse_program}; +use crate::assert_satisfied; +use crate::import::set_local_dir; +use crate::parse_program; #[test] fn test_out_of_order() { diff --git a/compiler/tests/function/mod.rs b/compiler/tests/function/mod.rs index 6de6cd8153..c3a7f9654f 100644 --- a/compiler/tests/function/mod.rs +++ b/compiler/tests/function/mod.rs @@ -14,7 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_asg_error, get_output, parse_program, parse_program_with_input}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::get_output; +use crate::parse_program; +use crate::parse_program_with_input; #[test] fn test_conditional_return() { diff --git a/compiler/tests/import/mod.rs b/compiler/tests/import/mod.rs index 1a3440b577..fccae4c6c6 100644 --- a/compiler/tests/import/mod.rs +++ b/compiler/tests/import/mod.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, parse_program}; +use crate::assert_satisfied; +use crate::parse_program; -use std::env::{current_dir, set_current_dir}; +use std::env::current_dir; +use std::env::set_current_dir; static TEST_SOURCE_DIRECTORY: &str = "tests/import"; diff --git a/compiler/tests/input_files/program_input/mod.rs b/compiler/tests/input_files/program_input/mod.rs index 529a512fdb..c82135b381 100644 --- a/compiler/tests/input_files/program_input/mod.rs +++ b/compiler/tests/input_files/program_input/mod.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_compiler_error, parse_program_with_input, EdwardsTestCompiler}; +use crate::assert_satisfied; +use crate::expect_compiler_error; +use crate::parse_program_with_input; +use crate::EdwardsTestCompiler; use leo_compiler::errors::CompilerError; fn expect_fail(program: EdwardsTestCompiler) { diff --git a/compiler/tests/input_files/program_input_and_program_state/mod.rs b/compiler/tests/input_files/program_input_and_program_state/mod.rs index 25541030ab..14d433c07b 100644 --- a/compiler/tests/input_files/program_input_and_program_state/mod.rs +++ b/compiler/tests/input_files/program_input_and_program_state/mod.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, parse_input_and_state, parse_program_with_input_and_state}; +use crate::assert_satisfied; +use crate::parse_input_and_state; +use crate::parse_program_with_input_and_state; #[test] fn test_basic() { diff --git a/compiler/tests/input_files/program_registers/mod.rs b/compiler/tests/input_files/program_registers/mod.rs index b172c141e0..43565f75d6 100644 --- a/compiler/tests/input_files/program_registers/mod.rs +++ b/compiler/tests/input_files/program_registers/mod.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{expect_compiler_error, get_output, parse_program_with_input}; +use crate::expect_compiler_error; +use crate::get_output; +use crate::parse_program_with_input; #[test] fn test_registers_pass() { diff --git a/compiler/tests/input_files/program_state/mod.rs b/compiler/tests/input_files/program_state/mod.rs index c5959196f5..5a9c1ff24c 100644 --- a/compiler/tests/input_files/program_state/mod.rs +++ b/compiler/tests/input_files/program_state/mod.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, parse_program_with_state, parse_state}; +use crate::assert_satisfied; +use crate::parse_program_with_state; +use crate::parse_state; #[test] fn test_basic() { diff --git a/compiler/tests/integers/i128/mod.rs b/compiler/tests/integers/i128/mod.rs index e62e07260e..e1885f7ffe 100644 --- a/compiler/tests/integers/i128/mod.rs +++ b/compiler/tests/integers/i128/mod.rs @@ -14,16 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::{expect_computation_error, IntegerTester}, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::expect_computation_error; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{I128Type, IntegerType, SignedIntegerType}; +use leo_input::types::I128Type; +use leo_input::types::IntegerType; +use leo_input::types::SignedIntegerType; test_int!( TestI128, diff --git a/compiler/tests/integers/i16/mod.rs b/compiler/tests/integers/i16/mod.rs index 49b45f5b3e..57404f5a30 100644 --- a/compiler/tests/integers/i16/mod.rs +++ b/compiler/tests/integers/i16/mod.rs @@ -14,16 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::{expect_computation_error, IntegerTester}, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::expect_computation_error; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{I16Type, IntegerType, SignedIntegerType}; +use leo_input::types::I16Type; +use leo_input::types::IntegerType; +use leo_input::types::SignedIntegerType; test_int!( TestI16, diff --git a/compiler/tests/integers/i32/mod.rs b/compiler/tests/integers/i32/mod.rs index ee9e25701a..965c96573f 100644 --- a/compiler/tests/integers/i32/mod.rs +++ b/compiler/tests/integers/i32/mod.rs @@ -14,16 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::{expect_computation_error, IntegerTester}, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::expect_computation_error; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{I32Type, IntegerType, SignedIntegerType}; +use leo_input::types::I32Type; +use leo_input::types::IntegerType; +use leo_input::types::SignedIntegerType; test_int!( TestI32, diff --git a/compiler/tests/integers/i64/mod.rs b/compiler/tests/integers/i64/mod.rs index 066ac9956f..083f04368b 100644 --- a/compiler/tests/integers/i64/mod.rs +++ b/compiler/tests/integers/i64/mod.rs @@ -14,16 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::{expect_computation_error, IntegerTester}, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::expect_computation_error; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{I64Type, IntegerType, SignedIntegerType}; +use leo_input::types::I64Type; +use leo_input::types::IntegerType; +use leo_input::types::SignedIntegerType; test_int!( TestI64, diff --git a/compiler/tests/integers/i8/mod.rs b/compiler/tests/integers/i8/mod.rs index 9133a72248..f7b4e46446 100644 --- a/compiler/tests/integers/i8/mod.rs +++ b/compiler/tests/integers/i8/mod.rs @@ -14,16 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::{expect_computation_error, IntegerTester}, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::expect_computation_error; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{I8Type, IntegerType, SignedIntegerType}; +use leo_input::types::I8Type; +use leo_input::types::IntegerType; +use leo_input::types::SignedIntegerType; test_int!( TestI8, diff --git a/compiler/tests/integers/integer_tester.rs b/compiler/tests/integers/integer_tester.rs index 23085d5aac..bec296d6e2 100644 --- a/compiler/tests/integers/integer_tester.rs +++ b/compiler/tests/integers/integer_tester.rs @@ -14,8 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{expect_compiler_error, EdwardsTestCompiler}; -use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, IntegerError, StatementError}; +use crate::expect_compiler_error; +use crate::EdwardsTestCompiler; +use leo_compiler::errors::CompilerError; +use leo_compiler::errors::ExpressionError; +use leo_compiler::errors::FunctionError; +use leo_compiler::errors::IntegerError; +use leo_compiler::errors::StatementError; pub trait IntegerTester { /// Tests defining the smalled value that can be represented by the integer type diff --git a/compiler/tests/integers/u128/mod.rs b/compiler/tests/integers/u128/mod.rs index 2c110af0a5..db276cea75 100644 --- a/compiler/tests/integers/u128/mod.rs +++ b/compiler/tests/integers/u128/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::IntegerTester, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{IntegerType, U128Type, UnsignedIntegerType}; +use leo_input::types::IntegerType; +use leo_input::types::U128Type; +use leo_input::types::UnsignedIntegerType; test_uint!( TestU128, diff --git a/compiler/tests/integers/u16/mod.rs b/compiler/tests/integers/u16/mod.rs index b4b202b9da..68b66429cd 100644 --- a/compiler/tests/integers/u16/mod.rs +++ b/compiler/tests/integers/u16/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::IntegerTester, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{IntegerType, U16Type, UnsignedIntegerType}; +use leo_input::types::IntegerType; +use leo_input::types::U16Type; +use leo_input::types::UnsignedIntegerType; test_uint!( TestU16, diff --git a/compiler/tests/integers/u32/mod.rs b/compiler/tests/integers/u32/mod.rs index 920fc6ed5b..7a646f0720 100644 --- a/compiler/tests/integers/u32/mod.rs +++ b/compiler/tests/integers/u32/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::IntegerTester, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType}; +use leo_input::types::IntegerType; +use leo_input::types::U32Type; +use leo_input::types::UnsignedIntegerType; test_uint!( TestU32, diff --git a/compiler/tests/integers/u64/mod.rs b/compiler/tests/integers/u64/mod.rs index ec86c868f1..4a76455959 100644 --- a/compiler/tests/integers/u64/mod.rs +++ b/compiler/tests/integers/u64/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::IntegerTester, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{IntegerType, U64Type, UnsignedIntegerType}; +use leo_input::types::IntegerType; +use leo_input::types::U64Type; +use leo_input::types::UnsignedIntegerType; test_uint!( TestU64, diff --git a/compiler/tests/integers/u8/mod.rs b/compiler/tests/integers/u8/mod.rs index a61e28246d..d8ea4ade30 100644 --- a/compiler/tests/integers/u8/mod.rs +++ b/compiler/tests/integers/u8/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_asg_error, - expect_compiler_error, - generate_main_input, - integers::IntegerTester, - parse_program, -}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::integers::IntegerTester; +use crate::parse_program; use leo_ast::InputValue; -use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType}; +use leo_input::types::IntegerType; +use leo_input::types::U8Type; +use leo_input::types::UnsignedIntegerType; test_uint!( TestU8, diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index aa5cfda8b7..4c29394acf 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -36,16 +36,19 @@ pub mod statements; pub mod syntax; pub mod tuples; -use leo_asg::{new_alloc_context, new_context, AsgContext}; -use leo_ast::{InputValue, MainInput}; -use leo_compiler::{ - compiler::Compiler, - errors::CompilerError, - group::targets::edwards_bls12::EdwardsGroupType, - ConstrainedValue, - OutputBytes, -}; -use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType}; +use leo_asg::new_alloc_context; +use leo_asg::new_context; +use leo_asg::AsgContext; +use leo_ast::InputValue; +use leo_ast::MainInput; +use leo_compiler::compiler::Compiler; +use leo_compiler::errors::CompilerError; +use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; +use leo_compiler::ConstrainedValue; +use leo_compiler::OutputBytes; +use leo_input::types::IntegerType; +use leo_input::types::U32Type; +use leo_input::types::UnsignedIntegerType; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index ded55960bb..4583d007d1 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_asg_error, generate_main_input, parse_program}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::generate_main_input; +use crate::parse_program; use leo_ast::InputValue; #[test] diff --git a/compiler/tests/statements/conditional/mod.rs b/compiler/tests/statements/conditional/mod.rs index 040c8108dd..f3ea03a39f 100644 --- a/compiler/tests/statements/conditional/mod.rs +++ b/compiler/tests/statements/conditional/mod.rs @@ -14,16 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - assert_satisfied, - expect_compiler_error, - generate_main_input, - generate_test_input_u32, - get_output, - parse_program, - parse_program_with_input, - EdwardsTestCompiler, -}; +use crate::assert_satisfied; +use crate::expect_compiler_error; +use crate::generate_main_input; +use crate::generate_test_input_u32; +use crate::get_output; +use crate::parse_program; +use crate::parse_program_with_input; +use crate::EdwardsTestCompiler; use leo_ast::InputValue; #[test] diff --git a/compiler/tests/statements/mod.rs b/compiler/tests/statements/mod.rs index 3aeb3f858b..a200744c7b 100644 --- a/compiler/tests/statements/mod.rs +++ b/compiler/tests/statements/mod.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, expect_asg_error, generate_main_input, parse_program}; +use crate::assert_satisfied; +use crate::expect_asg_error; +use crate::generate_main_input; +use crate::parse_program; use leo_ast::InputValue; pub mod conditional; diff --git a/compiler/tests/syntax/mod.rs b/compiler/tests/syntax/mod.rs index 2fb1a100ea..684af5468d 100644 --- a/compiler/tests/syntax/mod.rs +++ b/compiler/tests/syntax/mod.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{expect_asg_error, parse_input, parse_program}; +use crate::expect_asg_error; +use crate::parse_input; +use crate::parse_program; use leo_compiler::errors::CompilerError; use leo_grammar::ParserError; use leo_input::InputParserError; diff --git a/compiler/tests/tuples/mod.rs b/compiler/tests/tuples/mod.rs index 67798288a6..3afece0f86 100644 --- a/compiler/tests/tuples/mod.rs +++ b/compiler/tests/tuples/mod.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{assert_satisfied, parse_program}; +use crate::assert_satisfied; +use crate::parse_program; #[test] fn test_tuple_basic() { diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index 306cdbeb8a..2288a270f5 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -14,18 +14,26 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int128, Int16, Int32, Int64, Int8}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::Int128; +use leo_gadgets::Int16; +use leo_gadgets::Int32; +use leo_gadgets::Int64; +use leo_gadgets::Int8; -use snarkvm_models::gadgets::{ - r1cs::{ConstraintSystem, Fr, TestConstraintSystem}, - utilities::alloc::AllocGadget, -}; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Fr; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use rand::{Rng, SeedableRng}; +use rand::Rng; +use rand::SeedableRng; use rand_xorshift::XorShiftRng; use std::i128; -use criterion::{criterion_group, criterion_main, Criterion}; +use criterion::criterion_group; +use criterion::criterion_main; +use criterion::Criterion; macro_rules! create_add_bench { ($bench_name:ident, $bench_id:expr, $foo_name:ident, $std_type:ty, $bit_type:ty) => { diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index 5b82a38794..69af7b2886 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -15,13 +15,15 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::{Field, PrimeField}, - gadgets::{ - r1cs::ConstraintSystem, - utilities::uint::{UInt, UInt128, UInt16, UInt32, UInt64, UInt8}, - }, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::uint::UInt; +use snarkvm_models::gadgets::utilities::uint::UInt128; +use snarkvm_models::gadgets::utilities::uint::UInt16; +use snarkvm_models::gadgets::utilities::uint::UInt32; +use snarkvm_models::gadgets::utilities::uint::UInt64; +use snarkvm_models::gadgets::utilities::uint::UInt8; /// Returns addition of `self` + `other` in the constraint system. pub trait Add diff --git a/gadgets/src/arithmetic/div.rs b/gadgets/src/arithmetic/div.rs index ce43241628..45893ddc75 100644 --- a/gadgets/src/arithmetic/div.rs +++ b/gadgets/src/arithmetic/div.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_models::{curves::Field, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns division of `self` / `other` in the constraint system. pub trait Div diff --git a/gadgets/src/arithmetic/mul.rs b/gadgets/src/arithmetic/mul.rs index d98cad6a26..ad3cd453d1 100644 --- a/gadgets/src/arithmetic/mul.rs +++ b/gadgets/src/arithmetic/mul.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_models::{curves::Field, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns multiplication of `self` * `other` in the constraint system. pub trait Mul diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index b9b9624188..005962e5b0 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -17,10 +17,9 @@ use crate::bits::RippleCarryAdder; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::Field, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; use std::iter; diff --git a/gadgets/src/arithmetic/pow.rs b/gadgets/src/arithmetic/pow.rs index c20ba7d0ae..b638519d49 100644 --- a/gadgets/src/arithmetic/pow.rs +++ b/gadgets/src/arithmetic/pow.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_models::{curves::Field, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns exponentiation of `self` ** `other` in the constraint system. pub trait Pow diff --git a/gadgets/src/arithmetic/sub.rs b/gadgets/src/arithmetic/sub.rs index f553816c3f..a795ad2601 100644 --- a/gadgets/src/arithmetic/sub.rs +++ b/gadgets/src/arithmetic/sub.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_models::{curves::Field, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns subtraction of `self` - `other` in the constraint system. pub trait Sub diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index dda2b909c2..f57fd5ea0e 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -15,10 +15,9 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::Field, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; /// Single bit binary adder with carry bit /// https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index d77001d18b..5e0163301b 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -15,17 +15,16 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::{Field, PrimeField}, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{ - boolean::Boolean, - select::CondSelectGadget, - uint::{UInt128, UInt16, UInt32, UInt64, UInt8}, - }, - }, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_models::gadgets::utilities::uint::UInt128; +use snarkvm_models::gadgets::utilities::uint::UInt16; +use snarkvm_models::gadgets::utilities::uint::UInt32; +use snarkvm_models::gadgets::utilities::uint::UInt64; +use snarkvm_models::gadgets::utilities::uint::UInt8; pub trait EvaluateLtGadget { fn less_than>(&self, cs: CS, other: &Self) -> Result; diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index 96c75b505c..2da9c1a77b 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -14,13 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{bits::FullAdder, signed_integer::*}; +use crate::bits::FullAdder; +use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::{Field, PrimeField}, - gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; /// Returns the bitwise sum of a n-bit number with carry bit pub trait RippleCarryAdder diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index 3c440a3add..8bab46e5d5 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -14,28 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::Add, - bits::RippleCarryAdder, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::arithmetic::Add; +use crate::bits::RippleCarryAdder; +use crate::errors::SignedIntegerError; +use crate::Int; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; -use snarkvm_models::{ - curves::{fp_parameters::FpParameters, PrimeField}, - gadgets::{ - r1cs::{Assignment, ConstraintSystem, LinearCombination}, - utilities::{ - alloc::AllocGadget, - boolean::{AllocatedBit, Boolean}, - }, - }, -}; +use snarkvm_models::curves::fp_parameters::FpParameters; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::Assignment; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::LinearCombination; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; +use snarkvm_models::gadgets::utilities::boolean::Boolean; macro_rules! add_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/div.rs b/gadgets/src/signed_integer/arithmetic/div.rs index e50ca1da76..b140a875d3 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -14,29 +14,25 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::{Add, Div, Neg, Sub}, - bits::ComparatorGadget, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{ - alloc::AllocGadget, - boolean::{AllocatedBit, Boolean}, - eq::EvaluateEqGadget, - select::CondSelectGadget, - }, - }, -}; +use crate::arithmetic::Add; +use crate::arithmetic::Div; +use crate::arithmetic::Neg; +use crate::arithmetic::Sub; +use crate::bits::ComparatorGadget; +use crate::errors::SignedIntegerError; +use crate::Int; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; macro_rules! div_int_impl { ($($gadget:ident),*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index 2c448492d9..fb30a68c82 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -14,28 +14,25 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::Mul, - bits::{RippleCarryAdder, SignExtend}, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; -use snarkvm_models::{ - curves::{FpParameters, PrimeField}, - gadgets::{ - r1cs::{Assignment, ConstraintSystem, LinearCombination}, - utilities::{ - alloc::AllocGadget, - boolean::{AllocatedBit, Boolean}, - select::CondSelectGadget, - }, - }, -}; +use crate::arithmetic::Mul; +use crate::bits::RippleCarryAdder; +use crate::bits::SignExtend; +use crate::errors::SignedIntegerError; +use crate::Int; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; +use snarkvm_models::curves::FpParameters; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::Assignment; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::LinearCombination; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; use std::iter; diff --git a/gadgets/src/signed_integer/arithmetic/neg.rs b/gadgets/src/signed_integer/arithmetic/neg.rs index fc0e14b332..39aa3f567f 100644 --- a/gadgets/src/signed_integer/arithmetic/neg.rs +++ b/gadgets/src/signed_integer/arithmetic/neg.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{arithmetic::Neg, errors::SignedIntegerError, signed_integer::*}; +use crate::arithmetic::Neg; +use crate::errors::SignedIntegerError; +use crate::signed_integer::*; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; macro_rules! neg_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/pow.rs b/gadgets/src/signed_integer/arithmetic/pow.rs index f8689783bd..fc59955472 100644 --- a/gadgets/src/signed_integer/arithmetic/pow.rs +++ b/gadgets/src/signed_integer/arithmetic/pow.rs @@ -14,24 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::{Mul, Pow}, - errors::SignedIntegerError, - Int, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::arithmetic::Mul; +use crate::arithmetic::Pow; +use crate::errors::SignedIntegerError; +use crate::Int; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{alloc::AllocGadget, boolean::Boolean, select::CondSelectGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; macro_rules! pow_int_impl { ($($gadget:ty)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/sub.rs b/gadgets/src/signed_integer/arithmetic/sub.rs index c13ec13048..95ab05f120 100644 --- a/gadgets/src/signed_integer/arithmetic/sub.rs +++ b/gadgets/src/signed_integer/arithmetic/sub.rs @@ -14,16 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - arithmetic::{Add, Neg, Sub}, - errors::SignedIntegerError, - Int128, - Int16, - Int32, - Int64, - Int8, -}; -use snarkvm_models::{curves::PrimeField, gadgets::r1cs::ConstraintSystem}; +use crate::arithmetic::Add; +use crate::arithmetic::Neg; +use crate::arithmetic::Sub; +use crate::errors::SignedIntegerError; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; macro_rules! sub_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/relational/cmp.rs b/gadgets/src/signed_integer/relational/cmp.rs index 5f5bd562a1..25b8c91e1c 100644 --- a/gadgets/src/signed_integer/relational/cmp.rs +++ b/gadgets/src/signed_integer/relational/cmp.rs @@ -14,23 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - bits::{ComparatorGadget, EvaluateLtGadget}, - Int128, - Int16, - Int32, - Int64, - Int8, -}; +use crate::bits::ComparatorGadget; +use crate::bits::EvaluateLtGadget; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, select::CondSelectGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; use std::cmp::Ordering; macro_rules! cmp_gadget_impl { diff --git a/gadgets/src/signed_integer/relational/eq.rs b/gadgets/src/signed_integer/relational/eq.rs index 11edf05678..eff476b8b6 100644 --- a/gadgets/src/signed_integer/relational/eq.rs +++ b/gadgets/src/signed_integer/relational/eq.rs @@ -14,16 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Int, Int128, Int16, Int32, Int64, Int8}; +use crate::Int; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, eq::EvaluateEqGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; macro_rules! eq_gadget_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/utilities/alloc.rs b/gadgets/src/signed_integer/utilities/alloc.rs index c031adf754..60b3184544 100644 --- a/gadgets/src/signed_integer/utilities/alloc.rs +++ b/gadgets/src/signed_integer/utilities/alloc.rs @@ -14,20 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{Int, Int128, Int16, Int32, Int64, Int8}; +use crate::Int; +use crate::Int128; +use crate::Int16; +use crate::Int32; +use crate::Int64; +use crate::Int8; -use core::{borrow::Borrow, iter}; +use core::borrow::Borrow; +use core::iter; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::Field, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{ - alloc::AllocGadget, - boolean::{AllocatedBit, Boolean}, - }, - }, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; +use snarkvm_models::gadgets::utilities::boolean::Boolean; fn create_value, I: IntoIterator>, F: Field, CS: ConstraintSystem>( cs: &mut CS, diff --git a/gadgets/src/signed_integer/utilities/eq.rs b/gadgets/src/signed_integer/utilities/eq.rs index 15dbc74306..572e8947fb 100644 --- a/gadgets/src/signed_integer/utilities/eq.rs +++ b/gadgets/src/signed_integer/utilities/eq.rs @@ -17,13 +17,10 @@ use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::ConstraintSystem, - utilities::{boolean::Boolean, eq::ConditionalEqGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; macro_rules! cond_eq_int_impl { ($($gadget: ident),*) => ($( diff --git a/gadgets/src/signed_integer/utilities/select.rs b/gadgets/src/signed_integer/utilities/select.rs index a2db10dffe..7193f10843 100644 --- a/gadgets/src/signed_integer/utilities/select.rs +++ b/gadgets/src/signed_integer/utilities/select.rs @@ -17,13 +17,13 @@ use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::PrimeField, - gadgets::{ - r1cs::{Assignment, ConstraintSystem}, - utilities::{alloc::AllocGadget, boolean::Boolean, eq::EqGadget, select::CondSelectGadget}, - }, -}; +use snarkvm_models::curves::PrimeField; +use snarkvm_models::gadgets::r1cs::Assignment; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_models::gadgets::utilities::eq::EqGadget; +use snarkvm_models::gadgets::utilities::select::CondSelectGadget; macro_rules! select_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index d9d29a5e2d..a9082a2992 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int128}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::Int128; -use snarkvm_models::{ - curves::{One, Zero}, - gadgets::{ - r1cs::{ConstraintSystem, Fr, TestConstraintSystem}, - utilities::{alloc::AllocGadget, boolean::Boolean}, - }, -}; +use snarkvm_models::curves::One; +use snarkvm_models::curves::Zero; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Fr; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index ff2341554a..fab35e9141 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int16}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::Int16; -use snarkvm_models::{ - curves::{One, Zero}, - gadgets::{ - r1cs::{ConstraintSystem, Fr, TestConstraintSystem}, - utilities::{alloc::AllocGadget, boolean::Boolean}, - }, -}; +use snarkvm_models::curves::One; +use snarkvm_models::curves::Zero; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Fr; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index 6407301654..aceaef8188 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int32}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::Int32; -use snarkvm_models::{ - curves::{One, Zero}, - gadgets::{ - r1cs::{ConstraintSystem, Fr, TestConstraintSystem}, - utilities::{alloc::AllocGadget, boolean::Boolean}, - }, -}; +use snarkvm_models::curves::One; +use snarkvm_models::curves::Zero; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Fr; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 03259c7ece..24067288ad 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int64}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::Int64; -use snarkvm_models::{ - curves::{One, Zero}, - gadgets::{ - r1cs::{ConstraintSystem, Fr, TestConstraintSystem}, - utilities::{alloc::AllocGadget, boolean::Boolean}, - }, -}; +use snarkvm_models::curves::One; +use snarkvm_models::curves::Zero; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Fr; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index d9d3923410..1702409aae 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -14,15 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::{arithmetic::*, Int8}; +use leo_gadgets::arithmetic::*; +use leo_gadgets::Int8; -use snarkvm_models::{ - curves::{One, Zero}, - gadgets::{ - r1cs::{ConstraintSystem, Fr, TestConstraintSystem}, - utilities::{alloc::AllocGadget, boolean::Boolean}, - }, -}; +use snarkvm_models::curves::One; +use snarkvm_models::curves::Zero; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Fr; +use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_models::gadgets::utilities::boolean::Boolean; use rand::Rng; use rand_core::SeedableRng; diff --git a/grammar/benches/grammar.rs b/grammar/benches/grammar.rs index ec24d5edb7..ed493c740a 100644 --- a/grammar/benches/grammar.rs +++ b/grammar/benches/grammar.rs @@ -16,7 +16,10 @@ use leo_grammar::Grammar; -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::black_box; +use criterion::criterion_group; +use criterion::criterion_main; +use criterion::Criterion; use std::path::Path; fn leo_grammar<'ast>(filepath: &'ast Path, program_string: &'ast str) { diff --git a/grammar/src/access/access.rs b/grammar/src/access/access.rs index 1c33808692..914e994783 100644 --- a/grammar/src/access/access.rs +++ b/grammar/src/access/access.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{access::*, ast::Rule}; +use crate::access::*; +use crate::ast::Rule; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/access/array_access.rs b/grammar/src/access/array_access.rs index fe98590ce9..3f99db6242 100644 --- a/grammar/src/access/array_access.rs +++ b/grammar/src/access/array_access.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::RangeOrExpression, SpanDef}; +use crate::ast::Rule; +use crate::common::RangeOrExpression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/assignee_access.rs b/grammar/src/access/assignee_access.rs index 880ad65255..26cd172fa1 100644 --- a/grammar/src/access/assignee_access.rs +++ b/grammar/src/access/assignee_access.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - access::{ArrayAccess, MemberAccess, TupleAccess}, - ast::Rule, -}; +use crate::access::ArrayAccess; +use crate::access::MemberAccess; +use crate::access::TupleAccess; +use crate::ast::Rule; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/access/call_access.rs b/grammar/src/access/call_access.rs index 398c05a3f9..dcfaefd692 100644 --- a/grammar/src/access/call_access.rs +++ b/grammar/src/access/call_access.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/member_access.rs b/grammar/src/access/member_access.rs index a3e2e9e030..45d05e18e7 100644 --- a/grammar/src/access/member_access.rs +++ b/grammar/src/access/member_access.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/self_access.rs b/grammar/src/access/self_access.rs index 4c4c171835..2fc38d50ae 100644 --- a/grammar/src/access/self_access.rs +++ b/grammar/src/access/self_access.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{access::*, ast::Rule}; +use crate::access::*; +use crate::ast::Rule; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/access/static_member_access.rs b/grammar/src/access/static_member_access.rs index 7452d3e804..dd195cabeb 100644 --- a/grammar/src/access/static_member_access.rs +++ b/grammar/src/access/static_member_access.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/tuple_access.rs b/grammar/src/access/tuple_access.rs index 952e6a426f..25631d6cfb 100644 --- a/grammar/src/access/tuple_access.rs +++ b/grammar/src/access/tuple_access.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, values::PositiveNumber, SpanDef}; +use crate::ast::Rule; +use crate::values::PositiveNumber; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotation_arguments.rs b/grammar/src/annotations/annotation_arguments.rs index bf58a2c358..9447b490c2 100644 --- a/grammar/src/annotations/annotation_arguments.rs +++ b/grammar/src/annotations/annotation_arguments.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotation_name.rs b/grammar/src/annotations/annotation_name.rs index d7cb1c12c9..ebda9440cd 100644 --- a/grammar/src/annotations/annotation_name.rs +++ b/grammar/src/annotations/annotation_name.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, SpanDef}; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotation_symbol.rs b/grammar/src/annotations/annotation_symbol.rs index 16f042be92..f555884ab7 100644 --- a/grammar/src/annotations/annotation_symbol.rs +++ b/grammar/src/annotations/annotation_symbol.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, SpanDef}; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotations.rs b/grammar/src/annotations/annotations.rs index 045eb3a47e..d84d105d60 100644 --- a/grammar/src/annotations/annotations.rs +++ b/grammar/src/annotations/annotations.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - annotations::{AnnotationArguments, AnnotationName, AnnotationSymbol}, - ast::Rule, - SpanDef, -}; +use crate::annotations::AnnotationArguments; +use crate::annotations::AnnotationName; +use crate::annotations::AnnotationSymbol; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/ast.rs b/grammar/src/ast.rs index 87da0a1967..b1c63f8f82 100644 --- a/grammar/src/ast.rs +++ b/grammar/src/ast.rs @@ -15,31 +15,31 @@ // along with the Leo library. If not, see . //! Abstract syntax tree (ast) representation from leo.pest. -use crate::{ - common::Identifier, - expressions::{ - ArrayInitializerExpression, - ArrayInlineExpression, - CircuitInlineExpression, - Expression, - PostfixExpression, - SelfPostfixExpression, - TernaryExpression, - UnaryExpression, - }, - operations::{BinaryOperation, UnaryOperation}, - values::Value, -}; +use crate::common::Identifier; +use crate::expressions::ArrayInitializerExpression; +use crate::expressions::ArrayInlineExpression; +use crate::expressions::CircuitInlineExpression; +use crate::expressions::Expression; +use crate::expressions::PostfixExpression; +use crate::expressions::SelfPostfixExpression; +use crate::expressions::TernaryExpression; +use crate::expressions::UnaryExpression; +use crate::operations::BinaryOperation; +use crate::operations::UnaryOperation; +use crate::values::Value; use crate::expressions::TupleExpression; -use from_pest::{ConversionError, FromPest, Void}; -use pest::{ - error::Error, - iterators::{Pair, Pairs}, - prec_climber::{Assoc, Operator, PrecClimber}, - Parser, - Span, -}; +use from_pest::ConversionError; +use from_pest::FromPest; +use from_pest::Void; +use pest::error::Error; +use pest::iterators::Pair; +use pest::iterators::Pairs; +use pest::prec_climber::Assoc; +use pest::prec_climber::Operator; +use pest::prec_climber::PrecClimber; +use pest::Parser; +use pest::Span; #[derive(Parser)] #[grammar = "leo.pest"] diff --git a/grammar/src/circuits/circuit.rs b/grammar/src/circuits/circuit.rs index a704df6962..e719a7605c 100644 --- a/grammar/src/circuits/circuit.rs +++ b/grammar/src/circuits/circuit.rs @@ -14,7 +14,10 @@ // 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::CircuitMember, common::Identifier, SpanDef}; +use crate::ast::Rule; +use crate::circuits::CircuitMember; +use crate::common::Identifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/circuits/circuit_implied_variable.rs b/grammar/src/circuits/circuit_implied_variable.rs index eeb9aee4bb..0f8111e549 100644 --- a/grammar/src/circuits/circuit_implied_variable.rs +++ b/grammar/src/circuits/circuit_implied_variable.rs @@ -14,7 +14,9 @@ // 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 crate::ast::Rule; +use crate::circuits::CircuitVariable; +use crate::common::Identifier; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/circuits/circuit_member.rs b/grammar/src/circuits/circuit_member.rs index 6ce1c822b8..f451a28ffd 100644 --- a/grammar/src/circuits/circuit_member.rs +++ b/grammar/src/circuits/circuit_member.rs @@ -14,7 +14,9 @@ // 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::CircuitVariableDefinition, functions::Function}; +use crate::ast::Rule; +use crate::circuits::CircuitVariableDefinition; +use crate::functions::Function; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/circuits/circuit_variable.rs b/grammar/src/circuits/circuit_variable.rs index 30c35bbb0a..099422b632 100644 --- a/grammar/src/circuits/circuit_variable.rs +++ b/grammar/src/circuits/circuit_variable.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/circuits/circuit_variable_definition.rs b/grammar/src/circuits/circuit_variable_definition.rs index cef9933bc6..e1da1f7bc6 100644 --- a/grammar/src/circuits/circuit_variable_definition.rs +++ b/grammar/src/circuits/circuit_variable_definition.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, types::Type, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::types::Type; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/assignee.rs b/grammar/src/common/assignee.rs index 066fe1b0dd..77d8038db5 100644 --- a/grammar/src/common/assignee.rs +++ b/grammar/src/common/assignee.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{access::AssigneeAccess, ast::Rule, common::SelfKeywordOrIdentifier, SpanDef}; +use crate::access::AssigneeAccess; +use crate::ast::Rule; +use crate::common::SelfKeywordOrIdentifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/eoi.rs b/grammar/src/common/eoi.rs index b37cf4f230..34d32d9ba0 100644 --- a/grammar/src/common/eoi.rs +++ b/grammar/src/common/eoi.rs @@ -17,7 +17,8 @@ use crate::ast::Rule; use pest_ast::FromPest; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; #[derive(Clone, Debug, FromPest, PartialEq, Serialize, Deserialize)] #[pest_ast(rule(Rule::EOI))] diff --git a/grammar/src/common/identifier.rs b/grammar/src/common/identifier.rs index 0406e51336..9326593bff 100644 --- a/grammar/src/common/identifier.rs +++ b/grammar/src/common/identifier.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/keyword_or_identifier.rs b/grammar/src/common/keyword_or_identifier.rs index 5ab05f5dad..71e28485fa 100644 --- a/grammar/src/common/keyword_or_identifier.rs +++ b/grammar/src/common/keyword_or_identifier.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, functions::InputKeyword, types::SelfType}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::functions::InputKeyword; +use crate::types::SelfType; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/mut_self_keyword.rs b/grammar/src/common/mut_self_keyword.rs index 1ddc0cfa57..9c0cb39ee3 100644 --- a/grammar/src/common/mut_self_keyword.rs +++ b/grammar/src/common/mut_self_keyword.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::{Mutable, SelfKeyword}, - SpanDef, -}; +use crate::ast::Rule; +use crate::common::Mutable; +use crate::common::SelfKeyword; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/range.rs b/grammar/src/common/range.rs index cdb1f923f5..9d5a26fdd1 100644 --- a/grammar/src/common/range.rs +++ b/grammar/src/common/range.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/range_or_expression.rs b/grammar/src/common/range_or_expression.rs index 2b7ae2eb68..c740ddf486 100644 --- a/grammar/src/common/range_or_expression.rs +++ b/grammar/src/common/range_or_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Range, expressions::Expression}; +use crate::ast::Rule; +use crate::common::Range; +use crate::expressions::Expression; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/self_keyword.rs b/grammar/src/common/self_keyword.rs index 60721a7fab..40ccedb74a 100644 --- a/grammar/src/common/self_keyword.rs +++ b/grammar/src/common/self_keyword.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/self_keyword_or_identifier.rs b/grammar/src/common/self_keyword_or_identifier.rs index 83e27901eb..0912a76f2d 100644 --- a/grammar/src/common/self_keyword_or_identifier.rs +++ b/grammar/src/common/self_keyword_or_identifier.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::{Identifier, SelfKeyword}, -}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::common::SelfKeyword; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/spread.rs b/grammar/src/common/spread.rs index c9dd266816..4dd09cf5ff 100644 --- a/grammar/src/common/spread.rs +++ b/grammar/src/common/spread.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/spread_or_expression.rs b/grammar/src/common/spread_or_expression.rs index cd4bbc21d6..859147cda0 100644 --- a/grammar/src/common/spread_or_expression.rs +++ b/grammar/src/common/spread_or_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Spread, expressions::Expression}; +use crate::ast::Rule; +use crate::common::Spread; +use crate::expressions::Expression; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/variable_name.rs b/grammar/src/common/variable_name.rs index f9c6fe2e28..a9c862f586 100644 --- a/grammar/src/common/variable_name.rs +++ b/grammar/src/common/variable_name.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::{Identifier, Mutable}, - SpanDef, -}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::common::Mutable; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/variables.rs b/grammar/src/common/variables.rs index 939107fd7a..6a7b7f4751 100644 --- a/grammar/src/common/variables.rs +++ b/grammar/src/common/variables.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::VariableName, types::Type, SpanDef}; +use crate::ast::Rule; +use crate::common::VariableName; +use crate::types::Type; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_assert.rs b/grammar/src/console/console_assert.rs index 681f10dfc9..d5ed36d0c2 100644 --- a/grammar/src/console/console_assert.rs +++ b/grammar/src/console/console_assert.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_debug.rs b/grammar/src/console/console_debug.rs index 81b463947e..61583f53a4 100644 --- a/grammar/src/console/console_debug.rs +++ b/grammar/src/console/console_debug.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, console::FormattedString, SpanDef}; +use crate::ast::Rule; +use crate::console::FormattedString; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_error.rs b/grammar/src/console/console_error.rs index 8155c8d75f..ce342c2896 100644 --- a/grammar/src/console/console_error.rs +++ b/grammar/src/console/console_error.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, console::FormattedString, SpanDef}; +use crate::ast::Rule; +use crate::console::FormattedString; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_function.rs b/grammar/src/console/console_function.rs index b2cb97a418..da32c2095b 100644 --- a/grammar/src/console/console_function.rs +++ b/grammar/src/console/console_function.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - console::{ConsoleAssert, ConsoleDebug, ConsoleError, ConsoleLog}, -}; +use crate::ast::Rule; +use crate::console::ConsoleAssert; +use crate::console::ConsoleDebug; +use crate::console::ConsoleError; +use crate::console::ConsoleLog; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/console/console_function_call.rs b/grammar/src/console/console_function_call.rs index 18183927e9..08d1455896 100644 --- a/grammar/src/console/console_function_call.rs +++ b/grammar/src/console/console_function_call.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::LineEnd, - console::{ConsoleFunction, ConsoleKeyword}, - SpanDef, -}; +use crate::ast::Rule; +use crate::common::LineEnd; +use crate::console::ConsoleFunction; +use crate::console::ConsoleKeyword; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_keyword.rs b/grammar/src/console/console_keyword.rs index b9f98355ed..952d83933f 100644 --- a/grammar/src/console/console_keyword.rs +++ b/grammar/src/console/console_keyword.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, SpanDef}; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_log.rs b/grammar/src/console/console_log.rs index 06e6f457f0..b4fa3d1069 100644 --- a/grammar/src/console/console_log.rs +++ b/grammar/src/console/console_log.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, console::FormattedString, SpanDef}; +use crate::ast::Rule; +use crate::console::FormattedString; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/formatted_container.rs b/grammar/src/console/formatted_container.rs index 2943280b52..cedcc96bea 100644 --- a/grammar/src/console/formatted_container.rs +++ b/grammar/src/console/formatted_container.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, SpanDef}; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/formatted_string.rs b/grammar/src/console/formatted_string.rs index f0e80d3209..adbdfbdffb 100644 --- a/grammar/src/console/formatted_string.rs +++ b/grammar/src/console/formatted_string.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - console::FormattedContainer, - expressions::Expression, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::console::FormattedContainer; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/definitions/annotated_definition.rs b/grammar/src/definitions/annotated_definition.rs index 2bb3bf2d77..70f56ff93f 100644 --- a/grammar/src/definitions/annotated_definition.rs +++ b/grammar/src/definitions/annotated_definition.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{annotations::Annotation, ast::Rule, definitions::Definition, SpanDef}; +use crate::annotations::Annotation; +use crate::ast::Rule; +use crate::definitions::Definition; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/definitions/definition.rs b/grammar/src/definitions/definition.rs index 7fd46ef7f5..d3a8e4a909 100644 --- a/grammar/src/definitions/definition.rs +++ b/grammar/src/definitions/definition.rs @@ -14,13 +14,12 @@ // 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::Circuit, - definitions::{AnnotatedDefinition, Deprecated}, - functions::Function, - imports::Import, -}; +use crate::ast::Rule; +use crate::circuits::Circuit; +use crate::definitions::AnnotatedDefinition; +use crate::definitions::Deprecated; +use crate::functions::Function; +use crate::imports::Import; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/definitions/deprecated.rs b/grammar/src/definitions/deprecated.rs index 5c8d514113..a8b4cd5e0f 100644 --- a/grammar/src/definitions/deprecated.rs +++ b/grammar/src/definitions/deprecated.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, functions::TestFunction}; +use crate::ast::Rule; +use crate::functions::TestFunction; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/errors/parser.rs b/grammar/src/errors/parser.rs index 6f831d0ec2..39f936f59a 100644 --- a/grammar/src/errors/parser.rs +++ b/grammar/src/errors/parser.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, errors::SyntaxError}; +use crate::ast::Rule; +use crate::errors::SyntaxError; use pest::error::Error; -use std::path::{Path, PathBuf}; +use std::path::Path; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum ParserError { diff --git a/grammar/src/expressions/array_initializer_expression.rs b/grammar/src/expressions/array_initializer_expression.rs index c2a73e0d09..a724e3ebd9 100644 --- a/grammar/src/expressions/array_initializer_expression.rs +++ b/grammar/src/expressions/array_initializer_expression.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, types::ArrayDimensions, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::types::ArrayDimensions; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/array_inline_expression.rs b/grammar/src/expressions/array_inline_expression.rs index 5b3f4b7810..53ad6b1a9f 100644 --- a/grammar/src/expressions/array_inline_expression.rs +++ b/grammar/src/expressions/array_inline_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::SpreadOrExpression, SpanDef}; +use crate::ast::Rule; +use crate::common::SpreadOrExpression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/binary_expression.rs b/grammar/src/expressions/binary_expression.rs index 1086121d5b..c61b3f5f47 100644 --- a/grammar/src/expressions/binary_expression.rs +++ b/grammar/src/expressions/binary_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{expressions::Expression, operations::BinaryOperation, SpanDef}; +use crate::expressions::Expression; +use crate::operations::BinaryOperation; +use crate::SpanDef; use pest::Span; use serde::Serialize; diff --git a/grammar/src/expressions/circuit_inline_expression.rs b/grammar/src/expressions/circuit_inline_expression.rs index 6a51792bae..f6dbe9d0fe 100644 --- a/grammar/src/expressions/circuit_inline_expression.rs +++ b/grammar/src/expressions/circuit_inline_expression.rs @@ -14,7 +14,11 @@ // 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::CircuitImpliedVariable, common::Identifier, types::SelfType, SpanDef}; +use crate::ast::Rule; +use crate::circuits::CircuitImpliedVariable; +use crate::common::Identifier; +use crate::types::SelfType; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/expression.rs b/grammar/src/expressions/expression.rs index 7d71761a5c..dd5d9fee92 100644 --- a/grammar/src/expressions/expression.rs +++ b/grammar/src/expressions/expression.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{common::Identifier, expressions::*, operations::BinaryOperation, values::Value}; +use crate::common::Identifier; +use crate::expressions::*; +use crate::operations::BinaryOperation; +use crate::values::Value; use pest::Span; use serde::Serialize; diff --git a/grammar/src/expressions/postfix_expression.rs b/grammar/src/expressions/postfix_expression.rs index 923de16161..7701984f26 100644 --- a/grammar/src/expressions/postfix_expression.rs +++ b/grammar/src/expressions/postfix_expression.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{access::Access, ast::Rule, common::KeywordOrIdentifier, SpanDef}; +use crate::access::Access; +use crate::ast::Rule; +use crate::common::KeywordOrIdentifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/self_postfix_expression.rs b/grammar/src/expressions/self_postfix_expression.rs index 21017bda2d..7c53e13912 100644 --- a/grammar/src/expressions/self_postfix_expression.rs +++ b/grammar/src/expressions/self_postfix_expression.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - access::{Access, SelfAccess}, - ast::Rule, - common::SelfKeyword, - SpanDef, -}; +use crate::access::Access; +use crate::access::SelfAccess; +use crate::ast::Rule; +use crate::common::SelfKeyword; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/ternary_expression.rs b/grammar/src/expressions/ternary_expression.rs index 163750bd61..59a31e8844 100644 --- a/grammar/src/expressions/ternary_expression.rs +++ b/grammar/src/expressions/ternary_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/tuple_expression.rs b/grammar/src/expressions/tuple_expression.rs index 16b8727fe9..b15428f080 100644 --- a/grammar/src/expressions/tuple_expression.rs +++ b/grammar/src/expressions/tuple_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/unary_expression.rs b/grammar/src/expressions/unary_expression.rs index b2d50fb4c4..c9e5ac74f9 100644 --- a/grammar/src/expressions/unary_expression.rs +++ b/grammar/src/expressions/unary_expression.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, operations::UnaryOperation, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::operations::UnaryOperation; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/files/file.rs b/grammar/src/files/file.rs index 6d1bc2fea3..25eafba04b 100644 --- a/grammar/src/files/file.rs +++ b/grammar/src/files/file.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::EOI, definitions::Definition, SpanDef}; +use crate::ast::Rule; +use crate::common::EOI; +use crate::definitions::Definition; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/function.rs b/grammar/src/functions/function.rs index cd342b34bf..1be25b8ac5 100644 --- a/grammar/src/functions/function.rs +++ b/grammar/src/functions/function.rs @@ -14,7 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, functions::input::Input, statements::Block, types::Type, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::functions::input::Input; +use crate::statements::Block; +use crate::types::Type; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/input/function_input.rs b/grammar/src/functions/input/function_input.rs index 3cac32b798..fbe85c730d 100644 --- a/grammar/src/functions/input/function_input.rs +++ b/grammar/src/functions/input/function_input.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 . -use crate::{ - ast::Rule, - common::{Const, Identifier, Mutable}, - types::Type, - SpanDef, -}; +use crate::ast::Rule; +use crate::common::Const; +use crate::common::Identifier; +use crate::common::Mutable; +use crate::types::Type; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/input/input.rs b/grammar/src/functions/input/input.rs index 9b2ef22ab7..cecc2ed01a 100644 --- a/grammar/src/functions/input/input.rs +++ b/grammar/src/functions/input/input.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::{MutSelfKeyword, SelfKeyword}, - functions::{FunctionInput, InputKeyword}, -}; +use crate::ast::Rule; +use crate::common::MutSelfKeyword; +use crate::common::SelfKeyword; +use crate::functions::FunctionInput; +use crate::functions::InputKeyword; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/functions/input/input_keyword.rs b/grammar/src/functions/input/input_keyword.rs index 5032ae4436..1a76c63512 100644 --- a/grammar/src/functions/input/input_keyword.rs +++ b/grammar/src/functions/input/input_keyword.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/test_function.rs b/grammar/src/functions/test_function.rs index 1e28efc53c..834df3f2a9 100644 --- a/grammar/src/functions/test_function.rs +++ b/grammar/src/functions/test_function.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, functions::Function, SpanDef}; +use crate::ast::Rule; +use crate::functions::Function; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/import.rs b/grammar/src/imports/import.rs index 1b62df80f3..2c72ebc50c 100644 --- a/grammar/src/imports/import.rs +++ b/grammar/src/imports/import.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::LineEnd, imports::PackageOrPackages, SpanDef}; +use crate::ast::Rule; +use crate::common::LineEnd; +use crate::imports::PackageOrPackages; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/import_symbol.rs b/grammar/src/imports/import_symbol.rs index 3643406618..c0d4304b66 100644 --- a/grammar/src/imports/import_symbol.rs +++ b/grammar/src/imports/import_symbol.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/package.rs b/grammar/src/imports/package.rs index 0b3f1a0ecb..caffcaa13b 100644 --- a/grammar/src/imports/package.rs +++ b/grammar/src/imports/package.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - imports::{PackageAccess, PackageName}, - SpanDef, -}; +use crate::ast::Rule; +use crate::imports::PackageAccess; +use crate::imports::PackageName; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/package_access.rs b/grammar/src/imports/package_access.rs index 7d172bd545..379520d6d4 100644 --- a/grammar/src/imports/package_access.rs +++ b/grammar/src/imports/package_access.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - imports::{ImportSymbol, Package, Packages, Star}, -}; +use crate::ast::Rule; +use crate::imports::ImportSymbol; +use crate::imports::Package; +use crate::imports::Packages; +use crate::imports::Star; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/imports/package_name.rs b/grammar/src/imports/package_name.rs index a2e400460e..efe48335f4 100644 --- a/grammar/src/imports/package_name.rs +++ b/grammar/src/imports/package_name.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/package_or_packages.rs b/grammar/src/imports/package_or_packages.rs index 3cd0324480..9f3cc1049e 100644 --- a/grammar/src/imports/package_or_packages.rs +++ b/grammar/src/imports/package_or_packages.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - imports::{Package, Packages}, -}; +use crate::ast::Rule; +use crate::imports::Package; +use crate::imports::Packages; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/imports/packages.rs b/grammar/src/imports/packages.rs index 32003ffb16..1cfa0f2a74 100644 --- a/grammar/src/imports/packages.rs +++ b/grammar/src/imports/packages.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - imports::{PackageAccess, PackageName}, - SpanDef, -}; +use crate::ast::Rule; +use crate::imports::PackageAccess; +use crate::imports::PackageName; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/star.rs b/grammar/src/imports/star.rs index 29cb6b6e35..fc646aefe1 100644 --- a/grammar/src/imports/star.rs +++ b/grammar/src/imports/star.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, SpanDef}; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/lib.rs b/grammar/src/lib.rs index 2f9e0fac02..850dc37ff2 100644 --- a/grammar/src/lib.rs +++ b/grammar/src/lib.rs @@ -51,7 +51,8 @@ pub(crate) mod span; pub(crate) use span::*; use from_pest::FromPest; -use std::{fs, path::Path}; +use std::fs; +use std::path::Path; /// /// The grammar of a Leo program, encoded as an abstract syntax tree (AST). diff --git a/grammar/src/main.rs b/grammar/src/main.rs index ae9259084c..30ba62d972 100644 --- a/grammar/src/main.rs +++ b/grammar/src/main.rs @@ -14,8 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::{Grammar, ParserError}; -use std::{env, fs, path::Path}; +use leo_grammar::Grammar; +use leo_grammar::ParserError; +use std::env; +use std::fs; +use std::path::Path; fn to_grammar(filepath: &Path) -> Result { // Loads the Leo code as a string from the given file path. diff --git a/grammar/src/span.rs b/grammar/src/span.rs index f7c0eae89d..ba1be46daf 100644 --- a/grammar/src/span.rs +++ b/grammar/src/span.rs @@ -15,7 +15,8 @@ // along with the Leo library. If not, see . use pest::Span; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::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. diff --git a/grammar/src/statements/assign_statement.rs b/grammar/src/statements/assign_statement.rs index 5325fd7b17..3bea311ab2 100644 --- a/grammar/src/statements/assign_statement.rs +++ b/grammar/src/statements/assign_statement.rs @@ -14,13 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::{Assignee, LineEnd}, - expressions::Expression, - operations::AssignOperation, - SpanDef, -}; +use crate::ast::Rule; +use crate::common::Assignee; +use crate::common::LineEnd; +use crate::expressions::Expression; +use crate::operations::AssignOperation; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/block.rs b/grammar/src/statements/block.rs index bbbfe41ff7..12b3d856bf 100644 --- a/grammar/src/statements/block.rs +++ b/grammar/src/statements/block.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, statements::Statement, SpanDef}; +use crate::ast::Rule; +use crate::statements::Statement; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/conditional_nested_or_end_statement.rs b/grammar/src/statements/conditional_nested_or_end_statement.rs index 3bab38d701..a6807f1286 100644 --- a/grammar/src/statements/conditional_nested_or_end_statement.rs +++ b/grammar/src/statements/conditional_nested_or_end_statement.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - statements::{Block, ConditionalStatement}, -}; +use crate::ast::Rule; +use crate::statements::Block; +use crate::statements::ConditionalStatement; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/statements/conditional_statement.rs b/grammar/src/statements/conditional_statement.rs index 2e6861f98b..3145712852 100644 --- a/grammar/src/statements/conditional_statement.rs +++ b/grammar/src/statements/conditional_statement.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - expressions::Expression, - statements::{Block, ConditionalNestedOrEndStatement}, - SpanDef, -}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::statements::Block; +use crate::statements::ConditionalNestedOrEndStatement; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/definition_statement.rs b/grammar/src/statements/definition_statement.rs index c1db3c212d..9b076d6a7c 100644 --- a/grammar/src/statements/definition_statement.rs +++ b/grammar/src/statements/definition_statement.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 . -use crate::{ - ast::Rule, - common::{Declare, LineEnd, Variables}, - expressions::Expression, - SpanDef, -}; +use crate::ast::Rule; +use crate::common::Declare; +use crate::common::LineEnd; +use crate::common::Variables; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/expression_statement.rs b/grammar/src/statements/expression_statement.rs index bbef3f3568..3b78a62b5f 100644 --- a/grammar/src/statements/expression_statement.rs +++ b/grammar/src/statements/expression_statement.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::LineEnd, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::common::LineEnd; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/for_statement.rs b/grammar/src/statements/for_statement.rs index c1be00e303..c14b868e36 100644 --- a/grammar/src/statements/for_statement.rs +++ b/grammar/src/statements/for_statement.rs @@ -14,7 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, expressions::Expression, statements::Block, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::expressions::Expression; +use crate::statements::Block; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/return_statement.rs b/grammar/src/statements/return_statement.rs index 11d6b4ddcb..22ce5597be 100644 --- a/grammar/src/statements/return_statement.rs +++ b/grammar/src/statements/return_statement.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, SpanDef}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/statement.rs b/grammar/src/statements/statement.rs index d01c5d072e..771477c8f4 100644 --- a/grammar/src/statements/statement.rs +++ b/grammar/src/statements/statement.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, console::ConsoleFunctionCall, statements::*}; +use crate::ast::Rule; +use crate::console::ConsoleFunctionCall; +use crate::statements::*; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/types/array_dimensions.rs b/grammar/src/types/array_dimensions.rs index eb0aa89b1c..45928210bb 100644 --- a/grammar/src/types/array_dimensions.rs +++ b/grammar/src/types/array_dimensions.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, values::PositiveNumber, SpanDef}; +use crate::ast::Rule; +use crate::values::PositiveNumber; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/array_type.rs b/grammar/src/types/array_type.rs index a91b08558b..33ca7f227e 100644 --- a/grammar/src/types/array_type.rs +++ b/grammar/src/types/array_type.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::{ArrayDimensions, Type}, - SpanDef, -}; +use crate::ast::Rule; +use crate::types::ArrayDimensions; +use crate::types::Type; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/circuit_type.rs b/grammar/src/types/circuit_type.rs index c0156e100a..586267544d 100644 --- a/grammar/src/types/circuit_type.rs +++ b/grammar/src/types/circuit_type.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, SpanDef}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/data_type.rs b/grammar/src/types/data_type.rs index 78143384a5..acb7a17fe0 100644 --- a/grammar/src/types/data_type.rs +++ b/grammar/src/types/data_type.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::{AddressType, BooleanType, FieldType, GroupType, IntegerType}, -}; +use crate::ast::Rule; +use crate::types::AddressType; +use crate::types::BooleanType; +use crate::types::FieldType; +use crate::types::GroupType; +use crate::types::IntegerType; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/types/integer_type.rs b/grammar/src/types/integer_type.rs index 729ac0fcc4..d9003fb402 100644 --- a/grammar/src/types/integer_type.rs +++ b/grammar/src/types/integer_type.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::{SignedIntegerType, UnsignedIntegerType}, -}; +use crate::ast::Rule; +use crate::types::SignedIntegerType; +use crate::types::UnsignedIntegerType; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/types/self_type.rs b/grammar/src/types/self_type.rs index e3fb6bd072..99949e41f7 100644 --- a/grammar/src/types/self_type.rs +++ b/grammar/src/types/self_type.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/tuple_type.rs b/grammar/src/types/tuple_type.rs index 57f39c9261..f2ff4a9e5f 100644 --- a/grammar/src/types/tuple_type.rs +++ b/grammar/src/types/tuple_type.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::Type, SpanDef}; +use crate::ast::Rule; +use crate::types::Type; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/type_.rs b/grammar/src/types/type_.rs index d020a7ef07..ec1e7a9da6 100644 --- a/grammar/src/types/type_.rs +++ b/grammar/src/types/type_.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::*}; +use crate::ast::Rule; +use crate::types::*; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/values/address.rs b/grammar/src/values/address.rs index e1e815a6e7..9c5372aa09 100644 --- a/grammar/src/values/address.rs +++ b/grammar/src/values/address.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/address_value.rs b/grammar/src/values/address_value.rs index decf47431e..2d7c67e8d5 100644 --- a/grammar/src/values/address_value.rs +++ b/grammar/src/values/address_value.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::AddressType, values::address::Address, SpanDef}; +use crate::ast::Rule; +use crate::types::AddressType; +use crate::values::address::Address; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/boolean_value.rs b/grammar/src/values/boolean_value.rs index 9e26d369f9..9a0219f655 100644 --- a/grammar/src/values/boolean_value.rs +++ b/grammar/src/values/boolean_value.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/field_value.rs b/grammar/src/values/field_value.rs index fad986b83e..dc7464bcbc 100644 --- a/grammar/src/values/field_value.rs +++ b/grammar/src/values/field_value.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::FieldType, values::NumberValue, SpanDef}; +use crate::ast::Rule; +use crate::types::FieldType; +use crate::values::NumberValue; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/group_coordinate.rs b/grammar/src/values/group_coordinate.rs index 4f12c477d4..da1861c79d 100644 --- a/grammar/src/values/group_coordinate.rs +++ b/grammar/src/values/group_coordinate.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, values::NumberValue, SpanDef}; +use crate::ast::Rule; +use crate::values::NumberValue; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/group_value.rs b/grammar/src/values/group_value.rs index 56ab231908..4b9c7cc3d7 100644 --- a/grammar/src/values/group_value.rs +++ b/grammar/src/values/group_value.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::GroupType, - values::{GroupCoordinate, NumberValue}, - SpanDef, -}; +use crate::ast::Rule; +use crate::types::GroupType; +use crate::values::GroupCoordinate; +use crate::values::NumberValue; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/integer_value.rs b/grammar/src/values/integer_value.rs index 64c0ebd640..49b00b6fc7 100644 --- a/grammar/src/values/integer_value.rs +++ b/grammar/src/values/integer_value.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{SignedIntegerValue, UnsignedIntegerValue}, -}; +use crate::ast::Rule; +use crate::values::SignedIntegerValue; +use crate::values::UnsignedIntegerValue; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/negative_number.rs b/grammar/src/values/negative_number.rs index 5cd52eaef0..b0fd99eb7f 100644 --- a/grammar/src/values/negative_number.rs +++ b/grammar/src/values/negative_number.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - span::SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::span::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/number_value.rs b/grammar/src/values/number_value.rs index 1d090c7528..e0c63164fc 100644 --- a/grammar/src/values/number_value.rs +++ b/grammar/src/values/number_value.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{NegativeNumber, PositiveNumber}, -}; +use crate::ast::Rule; +use crate::values::NegativeNumber; +use crate::values::PositiveNumber; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/positive_number.rs b/grammar/src/values/positive_number.rs index 8fd522836f..a432b099ce 100644 --- a/grammar/src/values/positive_number.rs +++ b/grammar/src/values/positive_number.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::{span_into_string, Rule}, - span::SpanDef, -}; +use crate::ast::span_into_string; +use crate::ast::Rule; +use crate::span::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/signed_integer_value.rs b/grammar/src/values/signed_integer_value.rs index 5c49a0ebf1..08e5884522 100644 --- a/grammar/src/values/signed_integer_value.rs +++ b/grammar/src/values/signed_integer_value.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::SignedIntegerType, values::NumberValue, SpanDef}; +use crate::ast::Rule; +use crate::types::SignedIntegerType; +use crate::values::NumberValue; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/unsigned_integer_value.rs b/grammar/src/values/unsigned_integer_value.rs index 9b85ae8eea..c17d541dcf 100644 --- a/grammar/src/values/unsigned_integer_value.rs +++ b/grammar/src/values/unsigned_integer_value.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::UnsignedIntegerType, values::PositiveNumber, SpanDef}; +use crate::ast::Rule; +use crate::types::UnsignedIntegerType; +use crate::values::PositiveNumber; +use crate::SpanDef; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/value.rs b/grammar/src/values/value.rs index 2d92362c28..0314286277 100644 --- a/grammar/src/values/value.rs +++ b/grammar/src/values/value.rs @@ -14,10 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{AddressValue, BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue}, -}; +use crate::ast::Rule; +use crate::values::AddressValue; +use crate::values::BooleanValue; +use crate::values::FieldValue; +use crate::values::GroupValue; +use crate::values::IntegerValue; +use crate::values::NumberValue; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/tests/annotated.rs b/grammar/tests/annotated.rs index 32ac106dba..0f31370018 100644 --- a/grammar/tests/annotated.rs +++ b/grammar/tests/annotated.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/grammar/tests/circuits.rs b/grammar/tests/circuits.rs index 33c77151ca..161c8ce467 100644 --- a/grammar/tests/circuits.rs +++ b/grammar/tests/circuits.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/grammar/tests/deprecated.rs b/grammar/tests/deprecated.rs index 5ff8f94cb0..e9090c4566 100644 --- a/grammar/tests/deprecated.rs +++ b/grammar/tests/deprecated.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/grammar/tests/display.rs b/grammar/tests/display.rs index 38aaf42a70..ff67f18d42 100644 --- a/grammar/tests/display.rs +++ b/grammar/tests/display.rs @@ -15,10 +15,9 @@ // along with the Leo library. If not, see . use from_pest::FromPest; -use leo_grammar::{ - ast::{LanguageParser, Rule}, - statements::ConditionalStatement, -}; +use leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; +use leo_grammar::statements::ConditionalStatement; use pest::*; diff --git a/grammar/tests/expression.rs b/grammar/tests/expression.rs index 589c16bcee..f728b95b0f 100644 --- a/grammar/tests/expression.rs +++ b/grammar/tests/expression.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/grammar/tests/function.rs b/grammar/tests/function.rs index 4bc1de7bf7..3b85e6e186 100644 --- a/grammar/tests/function.rs +++ b/grammar/tests/function.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/grammar/tests/imports.rs b/grammar/tests/imports.rs index 8ddd874e3d..94ceabcce8 100644 --- a/grammar/tests/imports.rs +++ b/grammar/tests/imports.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/grammar/tests/multiline.rs b/grammar/tests/multiline.rs index 2c3fca1706..d5d03b5ebb 100644 --- a/grammar/tests/multiline.rs +++ b/grammar/tests/multiline.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; #[test] diff --git a/grammar/tests/self.rs b/grammar/tests/self.rs index 8157639e42..4a5ccf05c9 100644 --- a/grammar/tests/self.rs +++ b/grammar/tests/self.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; #[test] diff --git a/grammar/tests/tuple.rs b/grammar/tests/tuple.rs index 1408d5c0d8..1a602e4f5e 100644 --- a/grammar/tests/tuple.rs +++ b/grammar/tests/tuple.rs @@ -14,7 +14,8 @@ // 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 leo_grammar::ast::LanguageParser; +use leo_grammar::ast::Rule; use pest::*; diff --git a/imports/src/errors/import_parser.rs b/imports/src/errors/import_parser.rs index f3d901560c..378af76230 100644 --- a/imports/src/errors/import_parser.rs +++ b/imports/src/errors/import_parser.rs @@ -14,10 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . use leo_asg::AsgConvertError; -use leo_ast::{AstError, DeprecatedError, Error as FormattedError, Identifier, Span}; +use leo_ast::AstError; +use leo_ast::DeprecatedError; +use leo_ast::Error as FormattedError; +use leo_ast::Identifier; +use leo_ast::Span; use leo_grammar::ParserError; -use std::{io, path::Path}; +use std::io; +use std::path::Path; #[derive(Debug, Error)] pub enum ImportParserError { diff --git a/imports/src/parser/import_parser.rs b/imports/src/parser/import_parser.rs index 300408cffb..2e803ac303 100644 --- a/imports/src/parser/import_parser.rs +++ b/imports/src/parser/import_parser.rs @@ -15,9 +15,14 @@ // along with the Leo library. If not, see . use crate::errors::ImportParserError; -use leo_asg::{AsgContext, AsgConvertError, ImportResolver, Program, Span}; +use leo_asg::AsgContext; +use leo_asg::AsgConvertError; +use leo_asg::ImportResolver; +use leo_asg::Program; +use leo_asg::Span; -use indexmap::{IndexMap, IndexSet}; +use indexmap::IndexMap; +use indexmap::IndexSet; use std::env::current_dir; /// Stores imported packages. diff --git a/imports/src/parser/parse_package.rs b/imports/src/parser/parse_package.rs index 3acd05e41b..44d20b0b35 100644 --- a/imports/src/parser/parse_package.rs +++ b/imports/src/parser/parse_package.rs @@ -14,10 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::ImportParserError, ImportParser}; -use leo_asg::{AsgContext, Identifier, Program, Span}; +use crate::errors::ImportParserError; +use crate::ImportParser; +use leo_asg::AsgContext; +use leo_asg::Identifier; +use leo_asg::Program; +use leo_asg::Span; -use std::{fs, fs::DirEntry, path::PathBuf}; +use std::fs; +use std::fs::DirEntry; +use std::path::PathBuf; static SOURCE_FILE_EXTENSION: &str = ".leo"; static SOURCE_DIRECTORY_NAME: &str = "src/"; diff --git a/imports/src/parser/parse_symbol.rs b/imports/src/parser/parse_symbol.rs index 9b02656d75..8cc27a706f 100644 --- a/imports/src/parser/parse_symbol.rs +++ b/imports/src/parser/parse_symbol.rs @@ -14,8 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::ImportParserError, ImportParser}; -use leo_ast::{Program, Span}; +use crate::errors::ImportParserError; +use crate::ImportParser; +use leo_ast::Program; +use leo_ast::Span; use leo_grammar::Grammar; use std::fs::DirEntry; diff --git a/input/src/ast.rs b/input/src/ast.rs index cfb3deef07..74176907b3 100644 --- a/input/src/ast.rs +++ b/input/src/ast.rs @@ -15,7 +15,10 @@ // along with the Leo library. If not, see . //! Abstract syntax tree (ast) representation from leo-input.pest. -use pest::{error::Error, iterators::Pairs, Parser, Span}; +use pest::error::Error; +use pest::iterators::Pairs; +use pest::Parser; +use pest::Span; #[derive(Parser)] #[grammar = "leo-input.pest"] diff --git a/input/src/common/identifier.rs b/input/src/common/identifier.rs index 606ac424ee..8af41c89ee 100644 --- a/input/src/common/identifier.rs +++ b/input/src/common/identifier.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::{span_into_string, Rule}; +use crate::ast::span_into_string; +use crate::ast::Rule; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/definitions/definition.rs b/input/src/definitions/definition.rs index c0c64bbe67..0f682e3628 100644 --- a/input/src/definitions/definition.rs +++ b/input/src/definitions/definition.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::LineEnd, expressions::Expression, parameters::Parameter}; +use crate::ast::Rule; +use crate::common::LineEnd; +use crate::expressions::Expression; +use crate::parameters::Parameter; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/errors/parser.rs b/input/src/errors/parser.rs index 71bdbee253..e67b4db760 100644 --- a/input/src/errors/parser.rs +++ b/input/src/errors/parser.rs @@ -14,25 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - errors::SyntaxError as InputSyntaxError, - expressions::{ArrayInlineExpression, Expression}, - sections::Header, - tables::Table, - types::{DataType, Type}, - values::{NumberValue, Value}, -}; +use crate::ast::Rule; +use crate::errors::SyntaxError as InputSyntaxError; +use crate::expressions::ArrayInlineExpression; +use crate::expressions::Expression; +use crate::sections::Header; +use crate::tables::Table; +use crate::types::DataType; +use crate::types::Type; +use crate::values::NumberValue; +use crate::values::Value; -use pest::{ - error::{Error, ErrorVariant}, - Span, -}; -use std::{ - num::ParseIntError, - path::{Path, PathBuf}, - str::ParseBoolError, -}; +use pest::error::Error; +use pest::error::ErrorVariant; +use pest::Span; +use std::num::ParseIntError; +use std::path::Path; +use std::path::PathBuf; +use std::str::ParseBoolError; #[derive(Debug, Error)] pub enum InputParserError { diff --git a/input/src/expressions/array_initializer_expression.rs b/input/src/expressions/array_initializer_expression.rs index 7870ac76ba..812ddd21e5 100644 --- a/input/src/expressions/array_initializer_expression.rs +++ b/input/src/expressions/array_initializer_expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression, types::ArrayDimensions}; +use crate::ast::Rule; +use crate::expressions::Expression; +use crate::types::ArrayDimensions; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/expressions/array_inline_expression.rs b/input/src/expressions/array_inline_expression.rs index 573085bc79..b961aa94ab 100644 --- a/input/src/expressions/array_inline_expression.rs +++ b/input/src/expressions/array_inline_expression.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression}; +use crate::ast::Rule; +use crate::expressions::Expression; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/expressions/expression.rs b/input/src/expressions/expression.rs index 4694307b58..ed2f5f8fec 100644 --- a/input/src/expressions/expression.rs +++ b/input/src/expressions/expression.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::*, values::Value}; +use crate::ast::Rule; +use crate::expressions::*; +use crate::values::Value; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/expressions/tuple_expression.rs b/input/src/expressions/tuple_expression.rs index 5cbb95dffb..4b831a6175 100644 --- a/input/src/expressions/tuple_expression.rs +++ b/input/src/expressions/tuple_expression.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, expressions::Expression}; +use crate::ast::Rule; +use crate::expressions::Expression; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/files/file.rs b/input/src/files/file.rs index 61142390b8..3caf037aeb 100644 --- a/input/src/files/file.rs +++ b/input/src/files/file.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::EOI, files::TableOrSection}; +use crate::ast::Rule; +use crate::common::EOI; +use crate::files::TableOrSection; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/files/table_or_section.rs b/input/src/files/table_or_section.rs index 93dd31dfc9..11fe801ac4 100644 --- a/input/src/files/table_or_section.rs +++ b/input/src/files/table_or_section.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, sections::Section, tables::Table}; +use crate::ast::Rule; +use crate::sections::Section; +use crate::tables::Table; use pest_ast::FromPest; diff --git a/input/src/lib.rs b/input/src/lib.rs index e2537eeeb1..9bdb8ead9f 100644 --- a/input/src/lib.rs +++ b/input/src/lib.rs @@ -34,7 +34,8 @@ pub mod types; pub mod values; use from_pest::FromPest; -use std::{fs, path::Path}; +use std::fs; +use std::path::Path; pub struct LeoInputParser; diff --git a/input/src/parameters/parameter.rs b/input/src/parameters/parameter.rs index 410ef775a9..10f76536e0 100644 --- a/input/src/parameters/parameter.rs +++ b/input/src/parameters/parameter.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, common::Identifier, types::Type}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::types::Type; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/sections/header.rs b/input/src/sections/header.rs index ca437c0a45..bae10df0e3 100644 --- a/input/src/sections/header.rs +++ b/input/src/sections/header.rs @@ -14,11 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - common::Identifier, - sections::{Main, Record, Registers, State, StateLeaf}, -}; +use crate::ast::Rule; +use crate::common::Identifier; +use crate::sections::Main; +use crate::sections::Record; +use crate::sections::Registers; +use crate::sections::State; +use crate::sections::StateLeaf; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/sections/section.rs b/input/src/sections/section.rs index e53a6331cd..a35ece07a5 100644 --- a/input/src/sections/section.rs +++ b/input/src/sections/section.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, definitions::Definition, sections::Header}; +use crate::ast::Rule; +use crate::definitions::Definition; +use crate::sections::Header; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/tables/table.rs b/input/src/tables/table.rs index 9ea777cbda..beb272c62f 100644 --- a/input/src/tables/table.rs +++ b/input/src/tables/table.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, sections::Section, tables::Visibility}; +use crate::ast::Rule; +use crate::sections::Section; +use crate::tables::Visibility; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/tables/visibility.rs b/input/src/tables/visibility.rs index 0abe3828ee..c3bd9586b8 100644 --- a/input/src/tables/visibility.rs +++ b/input/src/tables/visibility.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - tables::{Private, Public}, -}; +use crate::ast::Rule; +use crate::tables::Private; +use crate::tables::Public; use pest_ast::FromPest; use std::fmt; diff --git a/input/src/types/array_dimensions.rs b/input/src/types/array_dimensions.rs index 776ca0d899..b89ce0269d 100644 --- a/input/src/types/array_dimensions.rs +++ b/input/src/types/array_dimensions.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, values::PositiveNumber}; +use crate::ast::Rule; +use crate::values::PositiveNumber; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/types/array_type.rs b/input/src/types/array_type.rs index 0132228e0d..3b5700a960 100644 --- a/input/src/types/array_type.rs +++ b/input/src/types/array_type.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::{ArrayDimensions, Type}, -}; +use crate::ast::Rule; +use crate::types::ArrayDimensions; +use crate::types::Type; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/types/data_type.rs b/input/src/types/data_type.rs index ecb82e3bda..5f948718a2 100644 --- a/input/src/types/data_type.rs +++ b/input/src/types/data_type.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::{BooleanType, FieldType, GroupType, IntegerType}, -}; +use crate::ast::Rule; +use crate::types::BooleanType; +use crate::types::FieldType; +use crate::types::GroupType; +use crate::types::IntegerType; use crate::types::AddressType; use pest_ast::FromPest; diff --git a/input/src/types/integer_type.rs b/input/src/types/integer_type.rs index a66e28d079..d6a636c94f 100644 --- a/input/src/types/integer_type.rs +++ b/input/src/types/integer_type.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::{SignedIntegerType, UnsignedIntegerType}, -}; +use crate::ast::Rule; +use crate::types::SignedIntegerType; +use crate::types::UnsignedIntegerType; use pest_ast::FromPest; use std::fmt; diff --git a/input/src/types/tuple_type.rs b/input/src/types/tuple_type.rs index c5086c077a..c5a6aaa3e7 100644 --- a/input/src/types/tuple_type.rs +++ b/input/src/types/tuple_type.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::Type}; +use crate::ast::Rule; +use crate::types::Type; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/types/type_.rs b/input/src/types/type_.rs index 605f919f1d..23b2fb63f7 100644 --- a/input/src/types/type_.rs +++ b/input/src/types/type_.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::*}; +use crate::ast::Rule; +use crate::types::*; use pest_ast::FromPest; use std::fmt; diff --git a/input/src/values/address.rs b/input/src/values/address.rs index becdf5f31f..e3adbea7a8 100644 --- a/input/src/values/address.rs +++ b/input/src/values/address.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::{span_into_string, Rule}; +use crate::ast::span_into_string; +use crate::ast::Rule; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/address_typed.rs b/input/src/values/address_typed.rs index 17e678e86c..a353c51027 100644 --- a/input/src/values/address_typed.rs +++ b/input/src/values/address_typed.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::AddressType, values::address::Address}; +use crate::ast::Rule; +use crate::types::AddressType; +use crate::values::address::Address; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/address_value.rs b/input/src/values/address_value.rs index 6134c41278..9de8bfa0d8 100644 --- a/input/src/values/address_value.rs +++ b/input/src/values/address_value.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{Address, AddressTyped}, -}; +use crate::ast::Rule; +use crate::values::Address; +use crate::values::AddressTyped; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/boolean_value.rs b/input/src/values/boolean_value.rs index 769cddd049..fb7f026964 100644 --- a/input/src/values/boolean_value.rs +++ b/input/src/values/boolean_value.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::{span_into_string, Rule}; +use crate::ast::span_into_string; +use crate::ast::Rule; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/field_value.rs b/input/src/values/field_value.rs index f3bc21ebb4..49a4b95cee 100644 --- a/input/src/values/field_value.rs +++ b/input/src/values/field_value.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::FieldType, values::NumberValue}; +use crate::ast::Rule; +use crate::types::FieldType; +use crate::values::NumberValue; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/group_coordinate.rs b/input/src/values/group_coordinate.rs index 8a4882c39c..a5ed031861 100644 --- a/input/src/values/group_coordinate.rs +++ b/input/src/values/group_coordinate.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, values::NumberValue}; +use crate::ast::Rule; +use crate::values::NumberValue; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/group_value.rs b/input/src/values/group_value.rs index bc4c72eb17..c9b17d90e0 100644 --- a/input/src/values/group_value.rs +++ b/input/src/values/group_value.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - types::GroupType, - values::{GroupCoordinate, NumberValue}, -}; +use crate::ast::Rule; +use crate::types::GroupType; +use crate::values::GroupCoordinate; +use crate::values::NumberValue; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/integer_value.rs b/input/src/values/integer_value.rs index 9e1004a929..f866879ef4 100644 --- a/input/src/values/integer_value.rs +++ b/input/src/values/integer_value.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{SignedIntegerValue, UnsignedIntegerValue}, -}; +use crate::ast::Rule; +use crate::values::SignedIntegerValue; +use crate::values::UnsignedIntegerValue; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/negative_number.rs b/input/src/values/negative_number.rs index 704580fb9e..bd24cfff6b 100644 --- a/input/src/values/negative_number.rs +++ b/input/src/values/negative_number.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::{span_into_string, Rule}; +use crate::ast::span_into_string; +use crate::ast::Rule; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/number_value.rs b/input/src/values/number_value.rs index 2071dca1a3..6014c2488b 100644 --- a/input/src/values/number_value.rs +++ b/input/src/values/number_value.rs @@ -14,10 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{NegativeNumber, PositiveNumber}, -}; +use crate::ast::Rule; +use crate::values::NegativeNumber; +use crate::values::PositiveNumber; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/positive_number.rs b/input/src/values/positive_number.rs index 9ccf38cff2..6270e3614e 100644 --- a/input/src/values/positive_number.rs +++ b/input/src/values/positive_number.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::{span_into_string, Rule}; +use crate::ast::span_into_string; +use crate::ast::Rule; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/signed_integer_value.rs b/input/src/values/signed_integer_value.rs index acd4301c0e..153b6a95d4 100644 --- a/input/src/values/signed_integer_value.rs +++ b/input/src/values/signed_integer_value.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::SignedIntegerType, values::NumberValue}; +use crate::ast::Rule; +use crate::types::SignedIntegerType; +use crate::values::NumberValue; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/unsigned_integer_value.rs b/input/src/values/unsigned_integer_value.rs index 7b0193069c..22046a9a92 100644 --- a/input/src/values/unsigned_integer_value.rs +++ b/input/src/values/unsigned_integer_value.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ast::Rule, types::UnsignedIntegerType, values::PositiveNumber}; +use crate::ast::Rule; +use crate::types::UnsignedIntegerType; +use crate::values::PositiveNumber; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/value.rs b/input/src/values/value.rs index 214b705bb0..760dcee4fe 100644 --- a/input/src/values/value.rs +++ b/input/src/values/value.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - ast::Rule, - values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue}, -}; +use crate::ast::Rule; +use crate::values::BooleanValue; +use crate::values::FieldValue; +use crate::values::GroupValue; +use crate::values::IntegerValue; +use crate::values::NumberValue; use crate::values::AddressValue; use pest::Span; diff --git a/leo/api.rs b/leo/api.rs index 23e12b3578..244dd0aa05 100644 --- a/leo/api.rs +++ b/leo/api.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use anyhow::{anyhow, Error, Result}; -use reqwest::{ - blocking::{Client, Response}, - Method, - StatusCode, -}; +use anyhow::anyhow; +use anyhow::Error; +use anyhow::Result; +use reqwest::blocking::Client; +use reqwest::blocking::Response; +use reqwest::Method; +use reqwest::StatusCode; use serde::Serialize; /// Trait describes API Routes and Request bodies, struct which implements diff --git a/leo/commands/build.rs b/leo/commands/build.rs index c239eb57ca..52f8de4d58 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -14,20 +14,27 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; -use leo_compiler::{ - compiler::{thread_leaked_context, Compiler}, - group::targets::edwards_bls12::EdwardsGroupType, -}; -use leo_package::{ - inputs::*, - outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, - source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, -}; -use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit}; +use crate::commands::Command; +use crate::context::Context; +use leo_compiler::compiler::thread_leaked_context; +use leo_compiler::compiler::Compiler; +use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; +use leo_package::inputs::*; +use leo_package::outputs::ChecksumFile; +use leo_package::outputs::CircuitFile; +use leo_package::outputs::OutputsDirectory; +use leo_package::outputs::OUTPUTS_DIRECTORY_NAME; +use leo_package::source::LibraryFile; +use leo_package::source::MainFile; +use leo_package::source::LIBRARY_FILENAME; +use leo_package::source::MAIN_FILENAME; +use leo_package::source::SOURCE_DIRECTORY_NAME; +use leo_synthesizer::CircuitSynthesizer; +use leo_synthesizer::SerializedCircuit; use anyhow::Result; -use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq}; +use snarkvm_curves::bls12_377::Bls12_377; +use snarkvm_curves::edwards_bls12::Fq; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/clean.rs b/leo/commands/clean.rs index 0b39661f07..47bc2e1d1a 100644 --- a/leo/commands/clean.rs +++ b/leo/commands/clean.rs @@ -14,9 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use leo_compiler::OutputFile; -use leo_package::outputs::{ChecksumFile, CircuitFile, ProofFile, ProvingKeyFile, VerificationKeyFile}; +use leo_package::outputs::ChecksumFile; +use leo_package::outputs::CircuitFile; +use leo_package::outputs::ProofFile; +use leo_package::outputs::ProvingKeyFile; +use leo_package::outputs::VerificationKeyFile; use anyhow::Result; use structopt::StructOpt; diff --git a/leo/commands/deploy.rs b/leo/commands/deploy.rs index 06eff0c2e6..d3024ec902 100644 --- a/leo/commands/deploy.rs +++ b/leo/commands/deploy.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use anyhow::Result; use structopt::StructOpt; diff --git a/leo/commands/init.rs b/leo/commands/init.rs index 7c6b3e7745..a80d194965 100644 --- a/leo/commands/init.rs +++ b/leo/commands/init.rs @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use leo_package::LeoPackage; -use anyhow::{anyhow, Result}; +use anyhow::anyhow; +use anyhow::Result; use std::env::current_dir; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/lint.rs b/leo/commands/lint.rs index 3e60d7ec6e..9449d6f658 100644 --- a/leo/commands/lint.rs +++ b/leo/commands/lint.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use anyhow::Result; use structopt::StructOpt; diff --git a/leo/commands/mod.rs b/leo/commands/mod.rs index 47d5994575..bbaf2cbb60 100644 --- a/leo/commands/mod.rs +++ b/leo/commands/mod.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::context::{get_context, Context}; +use crate::context::get_context; +use crate::context::Context; use anyhow::Result; use std::time::Instant; @@ -52,7 +53,8 @@ pub mod test; pub use test::Test; pub mod update; -pub use update::{Automatic as UpdateAutomatic, Update}; +pub use update::Automatic as UpdateAutomatic; +pub use update::Update; pub mod watch; pub use watch::Watch; diff --git a/leo/commands/new.rs b/leo/commands/new.rs index a4da67c309..b311445070 100644 --- a/leo/commands/new.rs +++ b/leo/commands/new.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use leo_package::LeoPackage; -use anyhow::{anyhow, Result}; -use std::{env::current_dir, fs}; +use anyhow::anyhow; +use anyhow::Result; +use std::env::current_dir; +use std::fs; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/package/add.rs b/leo/commands/package/add.rs index ef1491f2f9..9543e7809a 100644 --- a/leo/commands/package/add.rs +++ b/leo/commands/package/add.rs @@ -14,14 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{api::Fetch, commands::Command, context::Context}; -use leo_package::imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME}; +use crate::api::Fetch; +use crate::commands::Command; +use crate::context::Context; +use leo_package::imports::ImportsDirectory; +use leo_package::imports::IMPORTS_DIRECTORY_NAME; -use anyhow::{anyhow, Result}; -use std::{ - fs::{create_dir_all, File}, - io::{Read, Write}, -}; +use anyhow::anyhow; +use anyhow::Result; +use std::fs::create_dir_all; +use std::fs::File; +use std::io::Read; +use std::io::Write; use structopt::StructOpt; use tracing::Span; diff --git a/leo/commands/package/clone.rs b/leo/commands/package/clone.rs index da28e74fe2..f4dfaf846a 100644 --- a/leo/commands/package/clone.rs +++ b/leo/commands/package/clone.rs @@ -14,15 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{api::Fetch, commands::Command, context::Context}; +use crate::api::Fetch; +use crate::commands::Command; +use crate::context::Context; -use anyhow::{anyhow, Result}; -use std::{ - borrow::Cow, - fs::{self, File}, - io::{Read, Write}, - path::Path, -}; +use anyhow::anyhow; +use anyhow::Result; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Read; +use std::io::Write; +use std::path::Path; use structopt::StructOpt; use tracing::Span; diff --git a/leo/commands/package/login.rs b/leo/commands/package/login.rs index 25425fccb0..83d81ac6c6 100644 --- a/leo/commands/package/login.rs +++ b/leo/commands/package/login.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - api::{Login as LoginRoute, Profile as ProfileRoute}, - commands::Command, - config::*, - context::Context, -}; +use crate::api::Login as LoginRoute; +use crate::api::Profile as ProfileRoute; +use crate::commands::Command; +use crate::config::*; +use crate::context::Context; -use anyhow::{anyhow, Result}; +use anyhow::anyhow; +use anyhow::Result; use std::collections::HashMap; use structopt::StructOpt; use tracing::Span; diff --git a/leo/commands/package/logout.rs b/leo/commands/package/logout.rs index 6bd76a2575..4bc38b8cad 100644 --- a/leo/commands/package/logout.rs +++ b/leo/commands/package/logout.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, config::remove_token, context::Context}; +use crate::commands::Command; +use crate::config::remove_token; +use crate::context::Context; use anyhow::Result; use std::io::ErrorKind; diff --git a/leo/commands/package/publish.rs b/leo/commands/package/publish.rs index 7b86763c67..382e9ad6c5 100644 --- a/leo/commands/package/publish.rs +++ b/leo/commands/package/publish.rs @@ -15,17 +15,18 @@ // along with the Leo library. If not, see . use super::build::Build; -use crate::{ - commands::Command, - context::{Context, PACKAGE_MANAGER_URL}, -}; -use leo_package::{outputs::OutputsDirectory, root::ZipFile}; +use crate::commands::Command; +use crate::context::Context; +use crate::context::PACKAGE_MANAGER_URL; +use leo_package::outputs::OutputsDirectory; +use leo_package::root::ZipFile; -use anyhow::{anyhow, Result}; -use reqwest::{ - blocking::{multipart::Form, Client}, - header::{HeaderMap, HeaderValue}, -}; +use anyhow::anyhow; +use anyhow::Result; +use reqwest::blocking::multipart::Form; +use reqwest::blocking::Client; +use reqwest::header::HeaderMap; +use reqwest::header::HeaderValue; use serde::Deserialize; use structopt::StructOpt; diff --git a/leo/commands/package/remove.rs b/leo/commands/package/remove.rs index f0df722146..5d88725cc9 100644 --- a/leo/commands/package/remove.rs +++ b/leo/commands/package/remove.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use leo_package::LeoPackage; use anyhow::Result; diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index dbe19b5777..dd2b4eae20 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -15,10 +15,14 @@ // along with the Leo library. If not, see . use super::setup::Setup; -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; use leo_package::outputs::ProofFile; -use snarkvm_algorithms::snark::groth16::{Groth16, PreparedVerifyingKey, Proof}; -use snarkvm_curves::bls12_377::{Bls12_377, Fr}; +use snarkvm_algorithms::snark::groth16::Groth16; +use snarkvm_algorithms::snark::groth16::PreparedVerifyingKey; +use snarkvm_algorithms::snark::groth16::Proof; +use snarkvm_curves::bls12_377::Bls12_377; +use snarkvm_curves::bls12_377::Fr; use snarkvm_models::algorithms::SNARK; use snarkvm_utilities::bytes::ToBytes; diff --git a/leo/commands/run.rs b/leo/commands/run.rs index b1bf652ed7..dbcda803ef 100644 --- a/leo/commands/run.rs +++ b/leo/commands/run.rs @@ -15,12 +15,15 @@ // along with the Leo library. If not, see . use super::prove::Prove; -use crate::{commands::Command, context::Context}; -use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; +use crate::commands::Command; +use crate::context::Context; +use leo_compiler::compiler::Compiler; +use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; use anyhow::Result; use snarkvm_algorithms::snark::groth16::Groth16; -use snarkvm_curves::bls12_377::{Bls12_377, Fr}; +use snarkvm_curves::bls12_377::Bls12_377; +use snarkvm_curves::bls12_377::Fr; use snarkvm_models::algorithms::SNARK; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index fad11bbe20..06489768fc 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -15,17 +15,24 @@ // along with the Leo library. If not, see . use super::build::Build; -use crate::{commands::Command, context::Context}; -use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; -use leo_package::{ - outputs::{ProvingKeyFile, VerificationKeyFile}, - source::{MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, -}; +use crate::commands::Command; +use crate::context::Context; +use leo_compiler::compiler::Compiler; +use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; +use leo_package::outputs::ProvingKeyFile; +use leo_package::outputs::VerificationKeyFile; +use leo_package::source::MAIN_FILENAME; +use leo_package::source::SOURCE_DIRECTORY_NAME; -use anyhow::{anyhow, Result}; +use anyhow::anyhow; +use anyhow::Result; use rand::thread_rng; -use snarkvm_algorithms::snark::groth16::{Groth16, Parameters, PreparedVerifyingKey, VerifyingKey}; -use snarkvm_curves::bls12_377::{Bls12_377, Fr}; +use snarkvm_algorithms::snark::groth16::Groth16; +use snarkvm_algorithms::snark::groth16::Parameters; +use snarkvm_algorithms::snark::groth16::PreparedVerifyingKey; +use snarkvm_algorithms::snark::groth16::VerifyingKey; +use snarkvm_curves::bls12_377::Bls12_377; +use snarkvm_curves::bls12_377::Fr; use snarkvm_models::algorithms::snark::SNARK; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/test.rs b/leo/commands/test.rs index f5de8672f2..a167af6e94 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -14,20 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, context::Context}; -use leo_compiler::{ - compiler::{thread_leaked_context, Compiler}, - group::targets::edwards_bls12::EdwardsGroupType, -}; -use leo_package::{ - inputs::*, - outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, - source::{MainFile, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, -}; +use crate::commands::Command; +use crate::context::Context; +use leo_compiler::compiler::thread_leaked_context; +use leo_compiler::compiler::Compiler; +use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; +use leo_package::inputs::*; +use leo_package::outputs::OutputsDirectory; +use leo_package::outputs::OUTPUTS_DIRECTORY_NAME; +use leo_package::source::MainFile; +use leo_package::source::MAIN_FILENAME; +use leo_package::source::SOURCE_DIRECTORY_NAME; -use anyhow::{anyhow, Result}; +use anyhow::anyhow; +use anyhow::Result; use snarkvm_curves::edwards_bls12::Fq; -use std::{convert::TryFrom, path::PathBuf, time::Instant}; +use std::convert::TryFrom; +use std::path::PathBuf; +use std::time::Instant; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/update.rs b/leo/commands/update.rs index f3027e5907..c643ec2b49 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -14,9 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{commands::Command, config::Config, context::Context, updater::Updater}; +use crate::commands::Command; +use crate::config::Config; +use crate::context::Context; +use crate::updater::Updater; -use anyhow::{anyhow, Result}; +use anyhow::anyhow; +use anyhow::Result; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/watch.rs b/leo/commands/watch.rs index 7a98b9604f..ef4f4bf80a 100644 --- a/leo/commands/watch.rs +++ b/leo/commands/watch.rs @@ -15,12 +15,18 @@ // along with the Leo library. If not, see . use super::build::Build; -use crate::{commands::Command, context::Context}; +use crate::commands::Command; +use crate::context::Context; -use std::{sync::mpsc::channel, time::Duration}; +use std::sync::mpsc::channel; +use std::time::Duration; -use anyhow::{anyhow, Result}; -use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; +use anyhow::anyhow; +use anyhow::Result; +use notify::watcher; +use notify::DebouncedEvent; +use notify::RecursiveMode; +use notify::Watcher; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/config.rs b/leo/config.rs index efc1ca4ed3..3b9373896a 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -14,17 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{ - fs::{self, create_dir_all, File}, - io, - io::prelude::*, - path::{Path, PathBuf}, -}; +use std::fs::create_dir_all; +use std::fs::File; +use std::fs::{self}; +use std::io; +use std::io::prelude::*; +use std::path::Path; +use std::path::PathBuf; use anyhow::Error; use dirs::home_dir; use lazy_static::lazy_static; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; pub const LEO_CREDENTIALS_FILE: &str = "credentials"; pub const LEO_CONFIG_FILE: &str = "config.toml"; diff --git a/leo/context.rs b/leo/context.rs index bddd54e5f2..04404fc2e5 100644 --- a/leo/context.rs +++ b/leo/context.rs @@ -14,11 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{api::Api, config}; +use crate::api::Api; +use crate::config; use leo_package::root::Manifest; use anyhow::Result; -use std::{convert::TryFrom, env::current_dir, path::PathBuf}; +use std::convert::TryFrom; +use std::env::current_dir; +use std::path::PathBuf; pub const PACKAGE_MANAGER_URL: &str = "https://api.aleo.pm/"; diff --git a/leo/logger.rs b/leo/logger.rs index a2f81bc4c1..69df6295b6 100644 --- a/leo/logger.rs +++ b/leo/logger.rs @@ -17,12 +17,14 @@ use std::fmt; use colored::Colorize; -use tracing::{event::Event, subscriber::Subscriber}; -use tracing_subscriber::{ - fmt::{format::*, time::*, FmtContext, FormattedFields}, - registry::LookupSpan, - FmtSubscriber, -}; +use tracing::event::Event; +use tracing::subscriber::Subscriber; +use tracing_subscriber::fmt::format::*; +use tracing_subscriber::fmt::time::*; +use tracing_subscriber::fmt::FmtContext; +use tracing_subscriber::fmt::FormattedFields; +use tracing_subscriber::registry::LookupSpan; +use tracing_subscriber::FmtSubscriber; #[derive(Debug, Clone)] pub struct Format { diff --git a/leo/main.rs b/leo/main.rs index a0d256230c..bf48db7525 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -21,26 +21,30 @@ pub mod context; pub mod logger; pub mod updater; -use commands::{ - package::{Add, Clone, Login, Logout, Publish, Remove}, - Build, - Clean, - Command, - Deploy, - Init, - Lint, - New, - Prove, - Run, - Setup, - Test, - Update, - Watch, -}; +use commands::package::Add; +use commands::package::Clone; +use commands::package::Login; +use commands::package::Logout; +use commands::package::Publish; +use commands::package::Remove; +use commands::Build; +use commands::Clean; +use commands::Command; +use commands::Deploy; +use commands::Init; +use commands::Lint; +use commands::New; +use commands::Prove; +use commands::Run; +use commands::Setup; +use commands::Test; +use commands::Update; +use commands::Watch; use anyhow::Error; use std::process::exit; -use structopt::{clap::AppSettings, StructOpt}; +use structopt::clap::AppSettings; +use structopt::StructOpt; /// CLI Arguments entry point - includes global parameters and subcommands #[derive(StructOpt, Debug)] diff --git a/leo/tests/mod.rs b/leo/tests/mod.rs index 7bc611f49d..90a44aa441 100644 --- a/leo/tests/mod.rs +++ b/leo/tests/mod.rs @@ -18,20 +18,18 @@ use std::path::PathBuf; use anyhow::Result; -use crate::{ - commands::{ - package::{Login, Logout}, - Build, - Command, - Prove, - Run, - Setup, - Test, - Update, - UpdateAutomatic, - }, - context::{create_context, Context}, -}; +use crate::commands::package::Login; +use crate::commands::package::Logout; +use crate::commands::Build; +use crate::commands::Command; +use crate::commands::Prove; +use crate::commands::Run; +use crate::commands::Setup; +use crate::commands::Test; +use crate::commands::Update; +use crate::commands::UpdateAutomatic; +use crate::context::create_context; +use crate::context::Context; /// Path to the only complex Leo program that we have /// - relative to source dir - where Cargo.toml is located diff --git a/leo/updater.rs b/leo/updater.rs index cc5c8972da..d9aa6cc58a 100644 --- a/leo/updater.rs +++ b/leo/updater.rs @@ -16,9 +16,12 @@ use crate::config::Config; -use anyhow::{anyhow, Result}; +use anyhow::anyhow; +use anyhow::Result; use colored::Colorize; -use self_update::{backends::github, version::bump_is_greater, Status}; +use self_update::backends::github; +use self_update::version::bump_is_greater; +use self_update::Status; pub struct Updater; diff --git a/package/src/errors/imports/directory.rs b/package/src/errors/imports/directory.rs index 05e6cfadf2..a3faddac08 100644 --- a/package/src/errors/imports/directory.rs +++ b/package/src/errors/imports/directory.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{ffi::OsString, fs::FileType, io}; +use std::ffi::OsString; +use std::fs::FileType; +use std::io; #[derive(Debug, Error)] pub enum ImportsDirectoryError { diff --git a/package/src/errors/inputs/directory.rs b/package/src/errors/inputs/directory.rs index ee93d8c6d6..efae1910d9 100644 --- a/package/src/errors/inputs/directory.rs +++ b/package/src/errors/inputs/directory.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{InputFileError, StateFileError}; +use crate::InputFileError; +use crate::StateFileError; -use std::{ffi::OsString, fs::FileType, io}; +use std::ffi::OsString; +use std::fs::FileType; +use std::io; #[derive(Debug, Error)] pub enum InputsDirectoryError { diff --git a/package/src/errors/inputs/input.rs b/package/src/errors/inputs/input.rs index 659fcf32a3..1d83a076ec 100644 --- a/package/src/errors/inputs/input.rs +++ b/package/src/errors/inputs/input.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum InputFileError { diff --git a/package/src/errors/inputs/state.rs b/package/src/errors/inputs/state.rs index 8d56253b46..44e89e242e 100644 --- a/package/src/errors/inputs/state.rs +++ b/package/src/errors/inputs/state.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum StateFileError { diff --git a/package/src/errors/outputs/checksum.rs b/package/src/errors/outputs/checksum.rs index e2a6bd4375..cc1e6b5ed7 100644 --- a/package/src/errors/outputs/checksum.rs +++ b/package/src/errors/outputs/checksum.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum ChecksumFileError { diff --git a/package/src/errors/outputs/circuit.rs b/package/src/errors/outputs/circuit.rs index ce006c88f2..dee36386f3 100644 --- a/package/src/errors/outputs/circuit.rs +++ b/package/src/errors/outputs/circuit.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum CircuitFileError { diff --git a/package/src/errors/outputs/directory.rs b/package/src/errors/outputs/directory.rs index 2e16be7e39..0c079335a6 100644 --- a/package/src/errors/outputs/directory.rs +++ b/package/src/errors/outputs/directory.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{ffi::OsString, fs::FileType, io}; +use std::ffi::OsString; +use std::fs::FileType; +use std::io; #[derive(Debug, Error)] pub enum OutputsDirectoryError { diff --git a/package/src/errors/outputs/proof.rs b/package/src/errors/outputs/proof.rs index 461a3ab259..e0080bc7dd 100644 --- a/package/src/errors/outputs/proof.rs +++ b/package/src/errors/outputs/proof.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum ProofFileError { diff --git a/package/src/errors/outputs/proving_key.rs b/package/src/errors/outputs/proving_key.rs index d78e62aec4..1d76fa4ce5 100644 --- a/package/src/errors/outputs/proving_key.rs +++ b/package/src/errors/outputs/proving_key.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum ProvingKeyFileError { diff --git a/package/src/errors/outputs/verification_key.rs b/package/src/errors/outputs/verification_key.rs index 51398e630c..6765946767 100644 --- a/package/src/errors/outputs/verification_key.rs +++ b/package/src/errors/outputs/verification_key.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; #[derive(Debug, Error)] pub enum VerificationKeyFileError { diff --git a/package/src/errors/package.rs b/package/src/errors/package.rs index f0a07ea1ee..ddb1f707cb 100644 --- a/package/src/errors/package.rs +++ b/package/src/errors/package.rs @@ -13,7 +13,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{ffi::OsString, io}; +use std::ffi::OsString; +use std::io; #[derive(Debug, Error)] pub enum PackageError { diff --git a/package/src/errors/root/zip.rs b/package/src/errors/root/zip.rs index e9a9c15b82..c89a3ac5bd 100644 --- a/package/src/errors/root/zip.rs +++ b/package/src/errors/root/zip.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{io, path::PathBuf}; +use std::io; +use std::path::PathBuf; use walkdir::Error as WalkDirError; use zip::result::ZipError; diff --git a/package/src/errors/source/directory.rs b/package/src/errors/source/directory.rs index 00d0629ec2..22ed510d24 100644 --- a/package/src/errors/source/directory.rs +++ b/package/src/errors/source/directory.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{ffi::OsString, fs::FileType, io}; +use std::ffi::OsString; +use std::fs::FileType; +use std::io; #[derive(Debug, Error)] pub enum SourceDirectoryError { diff --git a/package/src/imports/directory.rs b/package/src/imports/directory.rs index a1d7e850ea..c14194e9c3 100644 --- a/package/src/imports/directory.rs +++ b/package/src/imports/directory.rs @@ -16,7 +16,9 @@ use crate::errors::ImportsDirectoryError; -use std::{borrow::Cow, fs, path::Path}; +use std::borrow::Cow; +use std::fs; +use std::path::Path; pub static IMPORTS_DIRECTORY_NAME: &str = "imports/"; diff --git a/package/src/inputs/directory.rs b/package/src/inputs/directory.rs index 77b4701501..3d3e4988fd 100644 --- a/package/src/inputs/directory.rs +++ b/package/src/inputs/directory.rs @@ -16,12 +16,11 @@ use crate::errors::InputsDirectoryError; -use std::{ - borrow::Cow, - fs, - fs::ReadDir, - path::{Path, PathBuf}, -}; +use std::borrow::Cow; +use std::fs; +use std::fs::ReadDir; +use std::path::Path; +use std::path::PathBuf; pub static INPUTS_DIRECTORY_NAME: &str = "inputs/"; diff --git a/package/src/inputs/input.rs b/package/src/inputs/input.rs index 60365535c4..a48ba3cbba 100644 --- a/package/src/inputs/input.rs +++ b/package/src/inputs/input.rs @@ -16,15 +16,15 @@ //! The `program.in` file. -use crate::{errors::InputFileError, inputs::INPUTS_DIRECTORY_NAME}; +use crate::errors::InputFileError; +use crate::inputs::INPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static INPUT_FILE_EXTENSION: &str = ".in"; diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index 0d21e7c7f4..9533481c61 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -14,12 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - inputs::{InputFile, InputsDirectory, StateFile, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION}, - InputsDirectoryError, -}; +use crate::inputs::InputFile; +use crate::inputs::InputsDirectory; +use crate::inputs::StateFile; +use crate::inputs::INPUT_FILE_EXTENSION; +use crate::inputs::STATE_FILE_EXTENSION; +use crate::InputsDirectoryError; -use std::{collections::HashMap, convert::TryFrom, path::Path}; +use std::collections::HashMap; +use std::convert::TryFrom; +use std::path::Path; #[derive(Default)] pub struct InputPairs { diff --git a/package/src/inputs/state.rs b/package/src/inputs/state.rs index cba6d515c9..4dbfbbedf4 100644 --- a/package/src/inputs/state.rs +++ b/package/src/inputs/state.rs @@ -16,15 +16,15 @@ //! The `program.state` file. -use crate::{errors::StateFileError, inputs::INPUTS_DIRECTORY_NAME}; +use crate::errors::StateFileError; +use crate::inputs::INPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static STATE_FILE_EXTENSION: &str = ".state"; diff --git a/package/src/outputs/checksum.rs b/package/src/outputs/checksum.rs index cf2de78c96..d789cb5ce9 100644 --- a/package/src/outputs/checksum.rs +++ b/package/src/outputs/checksum.rs @@ -16,15 +16,15 @@ //! The build checksum file. -use crate::{errors::ChecksumFileError, outputs::OUTPUTS_DIRECTORY_NAME}; +use crate::errors::ChecksumFileError; +use crate::outputs::OUTPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static CHECKSUM_FILE_EXTENSION: &str = ".sum"; diff --git a/package/src/outputs/circuit.rs b/package/src/outputs/circuit.rs index 7de45f1fb3..3f9ec82a99 100644 --- a/package/src/outputs/circuit.rs +++ b/package/src/outputs/circuit.rs @@ -16,15 +16,15 @@ //! The serialized circuit output file. -use crate::{errors::CircuitFileError, outputs::OUTPUTS_DIRECTORY_NAME}; +use crate::errors::CircuitFileError; +use crate::outputs::OUTPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static CIRCUIT_FILE_EXTENSION: &str = ".json"; diff --git a/package/src/outputs/directory.rs b/package/src/outputs/directory.rs index e2557f343c..ec49dc8f9e 100644 --- a/package/src/outputs/directory.rs +++ b/package/src/outputs/directory.rs @@ -16,7 +16,9 @@ use crate::errors::OutputsDirectoryError; -use std::{borrow::Cow, fs, path::Path}; +use std::borrow::Cow; +use std::fs; +use std::path::Path; pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/"; diff --git a/package/src/outputs/proof.rs b/package/src/outputs/proof.rs index b1f2be7c4b..14f394af42 100644 --- a/package/src/outputs/proof.rs +++ b/package/src/outputs/proof.rs @@ -16,15 +16,15 @@ //! The proof file. -use crate::{errors::ProofFileError, outputs::OUTPUTS_DIRECTORY_NAME}; +use crate::errors::ProofFileError; +use crate::outputs::OUTPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static PROOF_FILE_EXTENSION: &str = ".proof"; diff --git a/package/src/outputs/proving_key.rs b/package/src/outputs/proving_key.rs index fa336714b7..cb76033eee 100644 --- a/package/src/outputs/proving_key.rs +++ b/package/src/outputs/proving_key.rs @@ -16,15 +16,15 @@ //! The proving key file. -use crate::{errors::ProvingKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME}; +use crate::errors::ProvingKeyFileError; +use crate::outputs::OUTPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static PROVING_KEY_FILE_EXTENSION: &str = ".lpk"; diff --git a/package/src/outputs/verification_key.rs b/package/src/outputs/verification_key.rs index d3499c7b05..c10b4de1b8 100644 --- a/package/src/outputs/verification_key.rs +++ b/package/src/outputs/verification_key.rs @@ -16,15 +16,15 @@ //! The verification key file. -use crate::{errors::VerificationKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME}; +use crate::errors::VerificationKeyFileError; +use crate::outputs::OUTPUTS_DIRECTORY_NAME; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::Write, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Write; +use std::path::Path; pub static VERIFICATION_KEY_FILE_EXTENSION: &str = ".lvk"; diff --git a/package/src/package.rs b/package/src/package.rs index f5c46e2696..4089da6d31 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -14,13 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{ - errors::PackageError, - imports::ImportsDirectory, - inputs::{InputFile, InputsDirectory, StateFile}, - root::{Gitignore, Manifest, README}, - source::{LibraryFile, MainFile, SourceDirectory}, -}; +use crate::errors::PackageError; +use crate::imports::ImportsDirectory; +use crate::inputs::InputFile; +use crate::inputs::InputsDirectory; +use crate::inputs::StateFile; +use crate::root::Gitignore; +use crate::root::Manifest; +use crate::root::README; +use crate::source::LibraryFile; +use crate::source::MainFile; +use crate::source::SourceDirectory; use serde::Deserialize; use std::path::Path; diff --git a/package/src/root/gitignore.rs b/package/src/root/gitignore.rs index 756c51be05..3cdba044d5 100644 --- a/package/src/root/gitignore.rs +++ b/package/src/root/gitignore.rs @@ -19,7 +19,10 @@ use crate::errors::GitignoreError; use serde::Deserialize; -use std::{borrow::Cow, fs::File, io::Write, path::Path}; +use std::borrow::Cow; +use std::fs::File; +use std::io::Write; +use std::path::Path; pub static GITIGNORE_FILENAME: &str = ".gitignore"; diff --git a/package/src/root/manifest.rs b/package/src/root/manifest.rs index 540749fcdc..44c9983efe 100644 --- a/package/src/root/manifest.rs +++ b/package/src/root/manifest.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{errors::ManifestError, package::Package}; +use crate::errors::ManifestError; +use crate::package::Package; use serde::Deserialize; -use std::{ - borrow::Cow, - convert::TryFrom, - fs::File, - io::{Read, Write}, - path::Path, -}; +use std::borrow::Cow; +use std::convert::TryFrom; +use std::fs::File; +use std::io::Read; +use std::io::Write; +use std::path::Path; pub const MANIFEST_FILENAME: &str = "Leo.toml"; diff --git a/package/src/root/readme.rs b/package/src/root/readme.rs index 468f5e58b9..700e068f3a 100644 --- a/package/src/root/readme.rs +++ b/package/src/root/readme.rs @@ -19,7 +19,10 @@ use crate::errors::READMEError; use serde::Deserialize; -use std::{borrow::Cow, fs::File, io::Write, path::Path}; +use std::borrow::Cow; +use std::fs::File; +use std::io::Write; +use std::path::Path; pub static README_FILENAME: &str = "README.md"; diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index ee09917dd0..e02671d2c8 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -16,31 +16,32 @@ //! The program package zip file. -use crate::{ - errors::ZipFileError, - imports::IMPORTS_DIRECTORY_NAME, - inputs::{INPUTS_DIRECTORY_NAME, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION}, - outputs::{ - CHECKSUM_FILE_EXTENSION, - CIRCUIT_FILE_EXTENSION, - OUTPUTS_DIRECTORY_NAME, - PROOF_FILE_EXTENSION, - PROVING_KEY_FILE_EXTENSION, - VERIFICATION_KEY_FILE_EXTENSION, - }, - root::{MANIFEST_FILENAME, README_FILENAME}, - source::{SOURCE_DIRECTORY_NAME, SOURCE_FILE_EXTENSION}, -}; +use crate::errors::ZipFileError; +use crate::imports::IMPORTS_DIRECTORY_NAME; +use crate::inputs::INPUTS_DIRECTORY_NAME; +use crate::inputs::INPUT_FILE_EXTENSION; +use crate::inputs::STATE_FILE_EXTENSION; +use crate::outputs::CHECKSUM_FILE_EXTENSION; +use crate::outputs::CIRCUIT_FILE_EXTENSION; +use crate::outputs::OUTPUTS_DIRECTORY_NAME; +use crate::outputs::PROOF_FILE_EXTENSION; +use crate::outputs::PROVING_KEY_FILE_EXTENSION; +use crate::outputs::VERIFICATION_KEY_FILE_EXTENSION; +use crate::root::MANIFEST_FILENAME; +use crate::root::README_FILENAME; +use crate::source::SOURCE_DIRECTORY_NAME; +use crate::source::SOURCE_FILE_EXTENSION; use serde::Deserialize; -use std::{ - borrow::Cow, - fs::{self, File}, - io::{Read, Write}, - path::Path, -}; +use std::borrow::Cow; +use std::fs::File; +use std::fs::{self}; +use std::io::Read; +use std::io::Write; +use std::path::Path; use walkdir::WalkDir; -use zip::write::{FileOptions, ZipWriter}; +use zip::write::FileOptions; +use zip::write::ZipWriter; pub static ZIP_FILE_EXTENSION: &str = ".zip"; diff --git a/package/src/source/directory.rs b/package/src/source/directory.rs index 5764f972df..15053337c6 100644 --- a/package/src/source/directory.rs +++ b/package/src/source/directory.rs @@ -16,11 +16,10 @@ use crate::errors::SourceDirectoryError; -use std::{ - borrow::Cow, - fs, - path::{Path, PathBuf}, -}; +use std::borrow::Cow; +use std::fs; +use std::path::Path; +use std::path::PathBuf; pub static SOURCE_DIRECTORY_NAME: &str = "src/"; diff --git a/package/src/source/library.rs b/package/src/source/library.rs index 90a5193b85..e33aa1b2b0 100644 --- a/package/src/source/library.rs +++ b/package/src/source/library.rs @@ -16,10 +16,14 @@ //! The `lib.leo` file. -use crate::{errors::LibraryFileError, source::directory::SOURCE_DIRECTORY_NAME}; +use crate::errors::LibraryFileError; +use crate::source::directory::SOURCE_DIRECTORY_NAME; use serde::Deserialize; -use std::{borrow::Cow, fs::File, io::Write, path::Path}; +use std::borrow::Cow; +use std::fs::File; +use std::io::Write; +use std::path::Path; pub static LIBRARY_FILENAME: &str = "lib.leo"; diff --git a/package/src/source/main.rs b/package/src/source/main.rs index 7ac8c4990d..6709be131b 100644 --- a/package/src/source/main.rs +++ b/package/src/source/main.rs @@ -16,10 +16,14 @@ //! The `main.leo` file. -use crate::{errors::MainFileError, source::directory::SOURCE_DIRECTORY_NAME}; +use crate::errors::MainFileError; +use crate::source::directory::SOURCE_DIRECTORY_NAME; use serde::Deserialize; -use std::{borrow::Cow, fs::File, io::Write, path::Path}; +use std::borrow::Cow; +use std::fs::File; +use std::io::Write; +use std::path::Path; pub static MAIN_FILENAME: &str = "main.leo"; diff --git a/package/tests/initialize/initialize.rs b/package/tests/initialize/initialize.rs index 5e1b98bde8..de255bf97c 100644 --- a/package/tests/initialize/initialize.rs +++ b/package/tests/initialize/initialize.rs @@ -15,12 +15,14 @@ // along with the Leo library. If not, see . use crate::test_dir; -use leo_package::{ - inputs::{InputFile, InputsDirectory, StateFile}, - package::Package, - root::Manifest, - source::{LibraryFile, MainFile, SourceDirectory}, -}; +use leo_package::inputs::InputFile; +use leo_package::inputs::InputsDirectory; +use leo_package::inputs::StateFile; +use leo_package::package::Package; +use leo_package::root::Manifest; +use leo_package::source::LibraryFile; +use leo_package::source::MainFile; +use leo_package::source::SourceDirectory; const TEST_PACKAGE_NAME: &str = "test-package"; diff --git a/package/tests/manifest/manifest.rs b/package/tests/manifest/manifest.rs index d58fce5150..070289d7c7 100644 --- a/package/tests/manifest/manifest.rs +++ b/package/tests/manifest/manifest.rs @@ -17,14 +17,15 @@ // Tests for package manifest use crate::test_dir; -use leo_package::root::{Manifest, MANIFEST_FILENAME}; +use leo_package::root::Manifest; +use leo_package::root::MANIFEST_FILENAME; -use std::{ - convert::TryFrom, - fs::File, - io::{Read, Write}, - path::{Path, PathBuf}, -}; +use std::convert::TryFrom; +use std::fs::File; +use std::io::Read; +use std::io::Write; +use std::path::Path; +use std::path::PathBuf; const OLD_MANIFEST_FORMAT: &str = r#"[package] name = "test-package" diff --git a/package/tests/mod.rs b/package/tests/mod.rs index 8f72a16b3e..da355df338 100644 --- a/package/tests/mod.rs +++ b/package/tests/mod.rs @@ -20,13 +20,12 @@ pub mod initialize; pub mod manifest; use lazy_static::lazy_static; -use std::{ - cell::RefCell, - env, - fs, - path::PathBuf, - sync::atomic::{AtomicUsize, Ordering}, -}; +use std::cell::RefCell; +use std::env; +use std::fs; +use std::path::PathBuf; +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; const PACKAGE_TEST_DIRECTORY: &str = "package-testing"; diff --git a/state/src/errors/dpc_record_values.rs b/state/src/errors/dpc_record_values.rs index e47ba1cdcd..13aec54ee3 100644 --- a/state/src/errors/dpc_record_values.rs +++ b/state/src/errors/dpc_record_values.rs @@ -18,7 +18,8 @@ use crate::InputValueError; use snarkvm_errors::objects::account::AccountError; -use std::{num::ParseIntError, str::ParseBoolError}; +use std::num::ParseIntError; +use std::str::ParseBoolError; #[derive(Debug, Error)] pub enum DPCRecordValuesError { diff --git a/state/src/errors/local_data_commitment.rs b/state/src/errors/local_data_commitment.rs index f2dd08aa13..7d110f6ab7 100644 --- a/state/src/errors/local_data_commitment.rs +++ b/state/src/errors/local_data_commitment.rs @@ -14,9 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{RecordVerificationError, StateLeafValuesError, StateValuesError}; +use crate::RecordVerificationError; +use crate::StateLeafValuesError; +use crate::StateValuesError; -use snarkvm_errors::algorithms::{CommitmentError, MerkleError}; +use snarkvm_errors::algorithms::CommitmentError; +use snarkvm_errors::algorithms::MerkleError; use std::io::Error as IOError; diff --git a/state/src/errors/state_leaf_values.rs b/state/src/errors/state_leaf_values.rs index 83b377178a..503aff91d2 100644 --- a/state/src/errors/state_leaf_values.rs +++ b/state/src/errors/state_leaf_values.rs @@ -16,7 +16,8 @@ use crate::InputValueError; -use std::{num::ParseIntError, str::ParseBoolError}; +use std::num::ParseIntError; +use std::str::ParseBoolError; #[derive(Debug, Error)] pub enum StateLeafValuesError { diff --git a/state/src/errors/state_values.rs b/state/src/errors/state_values.rs index 94af651517..9195833463 100644 --- a/state/src/errors/state_values.rs +++ b/state/src/errors/state_values.rs @@ -16,7 +16,8 @@ use crate::InputValueError; -use std::{num::ParseIntError, str::ParseBoolError}; +use std::num::ParseIntError; +use std::str::ParseBoolError; #[derive(Debug, Error)] pub enum StateValuesError { diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index 62d3d43e79..6d43d93dea 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -14,19 +14,23 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{verify_record_commitment, LocalDataVerificationError, StateLeafValues, StateValues}; +use crate::verify_record_commitment; +use crate::LocalDataVerificationError; +use crate::StateLeafValues; +use crate::StateValues; use leo_ast::Input as AstInput; use snarkvm_algorithms::commitment_tree::CommitmentMerklePath; -use snarkvm_dpc::base_dpc::{ - instantiated::{Components, LocalDataCRH, LocalDataCommitment}, - parameters::SystemParameters, -}; -use snarkvm_models::{ - algorithms::{CommitmentScheme, CRH}, - dpc::DPCComponents, -}; -use snarkvm_utilities::{bytes::ToBytes, to_bytes, FromBytes}; +use snarkvm_dpc::base_dpc::instantiated::Components; +use snarkvm_dpc::base_dpc::instantiated::LocalDataCRH; +use snarkvm_dpc::base_dpc::instantiated::LocalDataCommitment; +use snarkvm_dpc::base_dpc::parameters::SystemParameters; +use snarkvm_models::algorithms::CommitmentScheme; +use snarkvm_models::algorithms::CRH; +use snarkvm_models::dpc::DPCComponents; +use snarkvm_utilities::bytes::ToBytes; +use snarkvm_utilities::to_bytes; +use snarkvm_utilities::FromBytes; use std::convert::TryFrom; diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index 8c7148741d..89dc5de902 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{find_input, input_to_bytes, input_to_integer_string, StateLeafValuesError}; +use crate::find_input; +use crate::input_to_bytes; +use crate::input_to_integer_string; +use crate::StateLeafValuesError; use leo_ast::StateLeaf as AstStateLeaf; use std::convert::TryFrom; diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs index 0ba48af568..0a0777a5fb 100644 --- a/state/src/local_data_commitment/state_values.rs +++ b/state/src/local_data_commitment/state_values.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{find_input, input_to_bytes, input_to_integer_string, StateValuesError}; +use crate::find_input; +use crate::input_to_bytes; +use crate::input_to_integer_string; +use crate::StateValuesError; use leo_ast::State as AstState; use std::convert::TryFrom; diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index 55ea334b69..ee237135ef 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{utilities::*, DPCRecordValuesError}; +use crate::utilities::*; +use crate::DPCRecordValuesError; use leo_ast::Record as AstRecord; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_objects::AccountAddress; -use std::{convert::TryFrom, str::FromStr}; +use std::convert::TryFrom; +use std::str::FromStr; static SERIAL_NUMBER_PARAMETER_STRING: &str = "serial_number"; static OWNER_PARAMETER_STRING: &str = "owner"; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index 9dc8785227..17f419e055 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -14,15 +14,17 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{DPCRecordValues, RecordVerificationError}; +use crate::DPCRecordValues; +use crate::RecordVerificationError; use leo_ast::Record as AstRecord; -use snarkvm_dpc::base_dpc::{ - instantiated::{Components, RecordCommitment}, - parameters::SystemParameters, -}; +use snarkvm_dpc::base_dpc::instantiated::Components; +use snarkvm_dpc::base_dpc::instantiated::RecordCommitment; +use snarkvm_dpc::base_dpc::parameters::SystemParameters; use snarkvm_models::algorithms::CommitmentScheme; -use snarkvm_utilities::{bytes::ToBytes, to_bytes, FromBytes}; +use snarkvm_utilities::bytes::ToBytes; +use snarkvm_utilities::to_bytes; +use snarkvm_utilities::FromBytes; use std::convert::TryFrom; diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs index cdcf32feb1..792ff3820b 100644 --- a/state/src/utilities/input_value.rs +++ b/state/src/utilities/input_value.rs @@ -15,7 +15,8 @@ // along with the Leo library. If not, see . use crate::InputValueError; -use leo_ast::{InputValue, Parameter}; +use leo_ast::InputValue; +use leo_ast::Parameter; use indexmap::IndexMap; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index bf43267337..86db48197b 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -18,14 +18,16 @@ use leo_ast::Input; use leo_input::LeoInputParser; use leo_state::verify_local_data_commitment; -use snarkvm_dpc::base_dpc::{instantiated::*, record_payload::RecordPayload, DPC}; -use snarkvm_models::{ - algorithms::{CommitmentScheme, CRH}, - dpc::Record, - objects::AccountScheme, -}; +use snarkvm_dpc::base_dpc::instantiated::*; +use snarkvm_dpc::base_dpc::record_payload::RecordPayload; +use snarkvm_dpc::base_dpc::DPC; +use snarkvm_models::algorithms::CommitmentScheme; +use snarkvm_models::algorithms::CRH; +use snarkvm_models::dpc::Record; +use snarkvm_models::objects::AccountScheme; use snarkvm_objects::Account; -use snarkvm_utilities::{bytes::ToBytes, to_bytes}; +use snarkvm_utilities::bytes::ToBytes; +use snarkvm_utilities::to_bytes; use rand::Rng; use rand_core::SeedableRng; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 52eb228b24..d9cfdb4f42 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -15,13 +15,13 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::{ - curves::{Field, PairingEngine}, - gadgets::{ - r1cs::{ConstraintSystem, Index, LinearCombination, Variable}, - utilities::OptionalVec, - }, -}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::PairingEngine; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Index; +use snarkvm_models::gadgets::r1cs::LinearCombination; +use snarkvm_models::gadgets::r1cs::Variable; +use snarkvm_models::gadgets::utilities::OptionalVec; #[derive(Default)] pub struct Namespace { diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 4c53b48eb4..258b38e644 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -16,18 +16,18 @@ use std::convert::TryFrom; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_errors::curves::FieldError; -use snarkvm_models::{ - curves::PairingEngine, - gadgets::{ - r1cs::{ConstraintSystem, Index}, - utilities::OptionalVec, - }, -}; +use snarkvm_models::curves::PairingEngine; +use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_models::gadgets::r1cs::Index; +use snarkvm_models::gadgets::utilities::OptionalVec; -use crate::{CircuitSynthesizer, SerializedField, SerializedIndex}; +use crate::CircuitSynthesizer; +use crate::SerializedField; +use crate::SerializedIndex; #[derive(Serialize, Deserialize)] pub struct SerializedCircuit { diff --git a/synthesizer/src/serialized_field.rs b/synthesizer/src/serialized_field.rs index 8c75dbae7e..d70f5e489c 100644 --- a/synthesizer/src/serialized_field.rs +++ b/synthesizer/src/serialized_field.rs @@ -14,12 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{convert::TryFrom, str::FromStr}; +use std::convert::TryFrom; +use std::str::FromStr; use num_bigint::BigUint; -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use snarkvm_errors::curves::FieldError; -use snarkvm_models::curves::{Field, Fp256, Fp256Parameters}; +use snarkvm_models::curves::Field; +use snarkvm_models::curves::Fp256; +use snarkvm_models::curves::Fp256Parameters; #[derive(Serialize, Deserialize)] pub struct SerializedField(pub String); diff --git a/synthesizer/src/serialized_index.rs b/synthesizer/src/serialized_index.rs index ab42aeef0c..8efe13d5f1 100644 --- a/synthesizer/src/serialized_index.rs +++ b/synthesizer/src/serialized_index.rs @@ -14,7 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use serde::{Deserialize, Serialize}; +use serde::Deserialize; +use serde::Serialize; use snarkvm_models::gadgets::r1cs::Index; #[derive(Serialize, Deserialize)] From 05c6f43018474cd939eb95c92ca092df72ad18db Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:35:10 -0800 Subject: [PATCH 37/92] Update comm and crh traits --- .../local_data_commitment.rs | 4 ++-- state/src/record_commitment/record_commitment.rs | 2 +- state/tests/test_verify_local_data_commitment.rs | 16 +++++++--------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index 6d43d93dea..b8e1b9955a 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -21,12 +21,12 @@ use crate::StateValues; use leo_ast::Input as AstInput; use snarkvm_algorithms::commitment_tree::CommitmentMerklePath; +use snarkvm_algorithms::traits::CommitmentScheme; +use snarkvm_algorithms::traits::CRH; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_dpc::base_dpc::instantiated::LocalDataCRH; use snarkvm_dpc::base_dpc::instantiated::LocalDataCommitment; use snarkvm_dpc::base_dpc::parameters::SystemParameters; -use snarkvm_models::algorithms::CommitmentScheme; -use snarkvm_models::algorithms::CRH; use snarkvm_models::dpc::DPCComponents; use snarkvm_utilities::bytes::ToBytes; use snarkvm_utilities::to_bytes; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index 17f419e055..ecff6fd880 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -18,10 +18,10 @@ use crate::DPCRecordValues; use crate::RecordVerificationError; use leo_ast::Record as AstRecord; +use snarkvm_algorithms::traits::CommitmentScheme; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_dpc::base_dpc::instantiated::RecordCommitment; use snarkvm_dpc::base_dpc::parameters::SystemParameters; -use snarkvm_models::algorithms::CommitmentScheme; use snarkvm_utilities::bytes::ToBytes; use snarkvm_utilities::to_bytes; use snarkvm_utilities::FromBytes; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 86db48197b..6c2d19bcf5 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -18,11 +18,11 @@ use leo_ast::Input; use leo_input::LeoInputParser; use leo_state::verify_local_data_commitment; +use snarkvm_algorithms::traits::CommitmentScheme; +use snarkvm_algorithms::traits::CRH; use snarkvm_dpc::base_dpc::instantiated::*; use snarkvm_dpc::base_dpc::record_payload::RecordPayload; use snarkvm_dpc::base_dpc::DPC; -use snarkvm_models::algorithms::CommitmentScheme; -use snarkvm_models::algorithms::CRH; use snarkvm_models::dpc::Record; use snarkvm_models::objects::AccountScheme; use snarkvm_objects::Account; @@ -74,13 +74,11 @@ fn test_generate_values_from_dpc() { let noop_program_snark_pp = InstantiatedDPC::generate_noop_program_snark_parameters(&system_parameters, &mut rng).unwrap(); - let noop_program_id = to_bytes![ - ProgramVerificationKeyCRH::hash( - &system_parameters.program_verification_key_crh, - &to_bytes![noop_program_snark_pp.verification_key].unwrap() - ) - .unwrap() - ] + let noop_program_id = to_bytes![ProgramVerificationKeyCRH::hash( + &system_parameters.program_verification_key_crh, + &to_bytes![noop_program_snark_pp.verification_key].unwrap() + ) + .unwrap()] .unwrap(); let signature_parameters = &system_parameters.account_signature; From d2bef646be820d616712b1c2e5f41694b2ea04f9 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:35:36 -0800 Subject: [PATCH 38/92] Update dpc traits --- state/src/local_data_commitment/local_data_commitment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index b8e1b9955a..fd23158814 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -27,7 +27,7 @@ use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_dpc::base_dpc::instantiated::LocalDataCRH; use snarkvm_dpc::base_dpc::instantiated::LocalDataCommitment; use snarkvm_dpc::base_dpc::parameters::SystemParameters; -use snarkvm_models::dpc::DPCComponents; +use snarkvm_dpc::traits::DPCComponents; use snarkvm_utilities::bytes::ToBytes; use snarkvm_utilities::to_bytes; use snarkvm_utilities::FromBytes; From bfdf3c4dcad58eccd6cca1463f1f7983aa5d8f9d Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:36:29 -0800 Subject: [PATCH 39/92] Update field trait --- compiler/src/value/group/group_type.rs | 2 +- compiler/src/value/integer/integer.rs | 2 +- gadgets/src/arithmetic/neg.rs | 2 +- gadgets/src/arithmetic/sub.rs | 2 +- gadgets/src/bits/adder.rs | 2 +- gadgets/src/bits/comparator.rs | 2 +- gadgets/src/bits/rca.rs | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index 74afa68c99..e305f88c4d 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -20,7 +20,7 @@ use crate::errors::GroupError; use leo_asg::GroupValue; use leo_asg::Span; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::One; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::alloc::AllocGadget; diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index e743709fd4..3e016a78a1 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -27,7 +27,7 @@ use leo_gadgets::bits::comparator::EvaluateLtGadget; use leo_gadgets::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::alloc::AllocGadget; diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index 005962e5b0..fa82bcacf7 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -17,7 +17,7 @@ use crate::bits::RippleCarryAdder; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::boolean::Boolean; diff --git a/gadgets/src/arithmetic/sub.rs b/gadgets/src/arithmetic/sub.rs index a795ad2601..c4ddca14c0 100644 --- a/gadgets/src/arithmetic/sub.rs +++ b/gadgets/src/arithmetic/sub.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 snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns subtraction of `self` - `other` in the constraint system. diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index f57fd5ea0e..11d685f04e 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::boolean::Boolean; diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index 5e0163301b..7a13eb1568 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::boolean::Boolean; diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index 2da9c1a77b..ac3ff9ec6f 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -18,7 +18,7 @@ use crate::bits::FullAdder; use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::boolean::Boolean; From 400e3dd440fa273cdebd92ec55eb84456fbf67fa Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:36:54 -0800 Subject: [PATCH 40/92] Update r1cs traits --- compiler/src/expression/array/array.rs | 2 +- compiler/src/expression/logical/and.rs | 2 +- compiler/src/expression/relational/lt.rs | 2 +- compiler/src/function/input/input_section.rs | 2 +- compiler/src/value/boolean/input.rs | 2 +- compiler/src/value/group/input.rs | 2 +- gadgets/src/arithmetic/add.rs | 2 +- gadgets/src/arithmetic/div.rs | 2 +- gadgets/src/arithmetic/mul.rs | 2 +- gadgets/src/arithmetic/pow.rs | 2 +- gadgets/src/arithmetic/sub.rs | 2 +- gadgets/src/bits/comparator.rs | 2 +- gadgets/src/signed_integer/utilities/alloc.rs | 2 +- gadgets/tests/signed_integer/i64.rs | 2 +- synthesizer/src/circuit_synthesizer.rs | 2 +- synthesizer/src/serialized_field.rs | 2 +- 16 files changed, 16 insertions(+), 16 deletions(-) diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 003d990e14..9680213fe1 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -26,7 +26,7 @@ use leo_asg::Expression; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce array expressions diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 0c27aaaab4..49511a4cbc 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -22,8 +22,8 @@ use crate::GroupType; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 34d772bc72..c47f63c526 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -23,7 +23,7 @@ use leo_asg::Span; use leo_gadgets::bits::comparator::EvaluateLtGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index 767e205e89..45216ebafd 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -27,7 +27,7 @@ use leo_ast::InputValue; use leo_ast::Parameter; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; use indexmap::IndexMap; diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index cc116b014d..a22be403cf 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -24,9 +24,9 @@ use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::alloc::AllocGadget; use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; pub(crate) fn allocate_bool>( cs: &mut CS, diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 1106c724d1..18d1f91a3b 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -25,7 +25,7 @@ use leo_ast::InputValue; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub(crate) fn allocate_group, CS: ConstraintSystem>( cs: &mut CS, diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index 69af7b2886..c3e6b8304b 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::uint::UInt; diff --git a/gadgets/src/arithmetic/div.rs b/gadgets/src/arithmetic/div.rs index 45893ddc75..113f874d7e 100644 --- a/gadgets/src/arithmetic/div.rs +++ b/gadgets/src/arithmetic/div.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 snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns division of `self` / `other` in the constraint system. diff --git a/gadgets/src/arithmetic/mul.rs b/gadgets/src/arithmetic/mul.rs index ad3cd453d1..04ccf13dc0 100644 --- a/gadgets/src/arithmetic/mul.rs +++ b/gadgets/src/arithmetic/mul.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 snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns multiplication of `self` * `other` in the constraint system. diff --git a/gadgets/src/arithmetic/pow.rs b/gadgets/src/arithmetic/pow.rs index b638519d49..d405abc153 100644 --- a/gadgets/src/arithmetic/pow.rs +++ b/gadgets/src/arithmetic/pow.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 snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; /// Returns exponentiation of `self` ** `other` in the constraint system. diff --git a/gadgets/src/arithmetic/sub.rs b/gadgets/src/arithmetic/sub.rs index c4ddca14c0..ee66603526 100644 --- a/gadgets/src/arithmetic/sub.rs +++ b/gadgets/src/arithmetic/sub.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; /// Returns subtraction of `self` - `other` in the constraint system. pub trait Sub diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index 7a13eb1568..a60404aa73 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -17,7 +17,6 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::boolean::Boolean; use snarkvm_models::gadgets::utilities::select::CondSelectGadget; use snarkvm_models::gadgets::utilities::uint::UInt128; @@ -25,6 +24,7 @@ use snarkvm_models::gadgets::utilities::uint::UInt16; use snarkvm_models::gadgets::utilities::uint::UInt32; use snarkvm_models::gadgets::utilities::uint::UInt64; use snarkvm_models::gadgets::utilities::uint::UInt8; +use snarkvm_r1cs::ConstraintSystem; pub trait EvaluateLtGadget { fn less_than>(&self, cs: CS, other: &Self) -> Result; diff --git a/gadgets/src/signed_integer/utilities/alloc.rs b/gadgets/src/signed_integer/utilities/alloc.rs index 60b3184544..435f193bbd 100644 --- a/gadgets/src/signed_integer/utilities/alloc.rs +++ b/gadgets/src/signed_integer/utilities/alloc.rs @@ -24,7 +24,7 @@ use crate::Int8; use core::borrow::Borrow; use core::iter; use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::utilities::alloc::AllocGadget; use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 24067288ad..e3d0de1b35 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -19,11 +19,11 @@ use leo_gadgets::Int64; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_models::gadgets::utilities::alloc::AllocGadget; use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index d9cfdb4f42..28260e0d89 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_errors::gadgets::SynthesisError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::PairingEngine; use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Index; diff --git a/synthesizer/src/serialized_field.rs b/synthesizer/src/serialized_field.rs index d70f5e489c..3788f78c26 100644 --- a/synthesizer/src/serialized_field.rs +++ b/synthesizer/src/serialized_field.rs @@ -21,7 +21,7 @@ use num_bigint::BigUint; use serde::Deserialize; use serde::Serialize; use snarkvm_errors::curves::FieldError; -use snarkvm_models::curves::Field; +use snarkvm_fields::Field; use snarkvm_models::curves::Fp256; use snarkvm_models::curves::Fp256Parameters; From 3c4b8e9f68cfb795c0d12a7451039a4e596fc0b6 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:38:28 -0800 Subject: [PATCH 41/92] Update gadgets traits --- compiler/src/compiler.rs | 4 +-- compiler/src/console/assert.rs | 4 +-- compiler/src/console/console.rs | 4 +-- compiler/src/console/format.rs | 2 +- compiler/src/constraints/constraints.rs | 2 +- compiler/src/expression/arithmetic/add.rs | 2 +- compiler/src/expression/arithmetic/div.rs | 2 +- compiler/src/expression/arithmetic/mul.rs | 2 +- compiler/src/expression/arithmetic/negate.rs | 2 +- compiler/src/expression/arithmetic/pow.rs | 2 +- compiler/src/expression/arithmetic/sub.rs | 2 +- compiler/src/expression/array/access.rs | 2 +- compiler/src/expression/array/index.rs | 2 +- compiler/src/expression/binary/binary.rs | 2 +- compiler/src/expression/circuit/access.rs | 2 +- compiler/src/expression/circuit/circuit.rs | 2 +- .../src/expression/conditional/conditional.rs | 4 +-- compiler/src/expression/expression.rs | 4 +-- .../src/expression/function/core_circuit.rs | 2 +- compiler/src/expression/function/function.rs | 2 +- compiler/src/expression/logical/and.rs | 2 +- compiler/src/expression/logical/or.rs | 4 +-- compiler/src/expression/relational/eq.rs | 6 ++--- compiler/src/expression/relational/ge.rs | 2 +- compiler/src/expression/relational/gt.rs | 2 +- compiler/src/expression/relational/le.rs | 2 +- compiler/src/expression/tuple/access.rs | 2 +- compiler/src/expression/tuple/tuple.rs | 2 +- compiler/src/function/function.rs | 4 +-- compiler/src/function/input/array.rs | 2 +- compiler/src/function/input/input_keyword.rs | 2 +- .../src/function/input/main_function_input.rs | 2 +- compiler/src/function/input/tuple.rs | 2 +- compiler/src/function/main_function.rs | 2 +- compiler/src/function/mut_target.rs | 2 +- compiler/src/function/result/result.rs | 6 ++--- compiler/src/prelude/blake2s.rs | 6 ++--- compiler/src/prelude/mod.rs | 2 +- compiler/src/statement/assign/assign.rs | 6 ++--- compiler/src/statement/assign/assignee.rs | 2 +- compiler/src/statement/block/block.rs | 4 +-- .../src/statement/conditional/conditional.rs | 4 +-- .../src/statement/definition/definition.rs | 2 +- compiler/src/statement/iteration/iteration.rs | 6 ++--- compiler/src/statement/return_/return_.rs | 2 +- compiler/src/statement/statement.rs | 4 +-- compiler/src/value/address/address.rs | 24 ++++++++++------- compiler/src/value/boolean/input.rs | 4 +-- compiler/src/value/field/field_type.rs | 26 +++++++++++-------- compiler/src/value/field/input.rs | 4 +-- compiler/src/value/group/group_type.rs | 16 ++++++------ .../src/value/group/targets/edwards_bls12.rs | 26 +++++++++++-------- compiler/src/value/integer/integer.rs | 16 ++++++------ compiler/src/value/integer/macros.rs | 12 ++++----- compiler/src/value/value.rs | 8 +++--- gadgets/benches/integer_arithmetic.rs | 4 +-- gadgets/src/arithmetic/add.rs | 14 +++++----- gadgets/src/arithmetic/div.rs | 2 +- gadgets/src/arithmetic/mul.rs | 2 +- gadgets/src/arithmetic/neg.rs | 4 +-- gadgets/src/arithmetic/pow.rs | 2 +- gadgets/src/bits/adder.rs | 4 +-- gadgets/src/bits/comparator.rs | 14 +++++----- gadgets/src/bits/rca.rs | 4 +-- gadgets/src/bits/sign_extend.rs | 2 +- gadgets/src/signed_integer/arithmetic/add.rs | 8 +++--- gadgets/src/signed_integer/arithmetic/div.rs | 12 ++++----- gadgets/src/signed_integer/arithmetic/mul.rs | 10 +++---- gadgets/src/signed_integer/arithmetic/neg.rs | 2 +- gadgets/src/signed_integer/arithmetic/pow.rs | 8 +++--- gadgets/src/signed_integer/arithmetic/sub.rs | 2 +- gadgets/src/signed_integer/int_impl.rs | 2 +- gadgets/src/signed_integer/relational/cmp.rs | 6 ++--- gadgets/src/signed_integer/relational/eq.rs | 6 ++--- gadgets/src/signed_integer/utilities/alloc.rs | 8 +++--- gadgets/src/signed_integer/utilities/eq.rs | 6 ++--- .../src/signed_integer/utilities/select.rs | 10 +++---- gadgets/tests/signed_integer/i128.rs | 6 ++--- gadgets/tests/signed_integer/i16.rs | 6 ++--- gadgets/tests/signed_integer/i32.rs | 6 ++--- gadgets/tests/signed_integer/i64.rs | 4 +-- gadgets/tests/signed_integer/i8.rs | 6 ++--- leo/commands/build.rs | 2 +- synthesizer/src/circuit_synthesizer.rs | 4 +-- synthesizer/src/serialized_circuit.rs | 4 +-- 85 files changed, 225 insertions(+), 213 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index ca4da8319a..a4074714cb 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -36,8 +36,8 @@ use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_dpc::SystemParameters; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSynthesizer; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSynthesizer; +use snarkvm_r1cs::ConstraintSystem; use sha2::Digest; use sha2::Sha256; diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index 8e1e7b08d2..2690423c5d 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -24,9 +24,9 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn evaluate_console_assert>( diff --git a/compiler/src/console/console.rs b/compiler/src/console/console.rs index dd4b20461d..e9e13c8eb1 100644 --- a/compiler/src/console/console.rs +++ b/compiler/src/console/console.rs @@ -23,9 +23,9 @@ use crate::GroupType; use leo_asg::ConsoleFunction; use leo_asg::ConsoleStatement; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn evaluate_console_function_call>( diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index a01aca7a0a..95dd280707 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_asg::FormattedString; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn format>( diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 1faee8346a..58d30775e7 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -27,8 +27,8 @@ use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; use std::path::Path; pub fn generate_constraints<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index 20f1e0375a..ff699735e4 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_add<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index d5f8df488c..8828641699 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_div<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index f8b4f643ae..2bb9a98b30 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_mul<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/negate.rs b/compiler/src/expression/arithmetic/negate.rs index 3886c4e17b..00c8d7a720 100644 --- a/compiler/src/expression/arithmetic/negate.rs +++ b/compiler/src/expression/arithmetic/negate.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_negate<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index f8a7a450d9..aa343dfca1 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_pow<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index a5cd600dbc..8e3b4f783f 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_sub<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 4f2e2f84f7..0d19983a31 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -24,7 +24,7 @@ use leo_asg::Expression; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index af86fdc675..cfc4b6742a 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -24,7 +24,7 @@ use leo_asg::Expression; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn enforce_index>( diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index 0fd10c61ee..02c14a10e3 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::Expression; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; type ConstrainedValuePair<'a, T, U> = (ConstrainedValue<'a, T, U>, ConstrainedValue<'a, T, U>); diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index c37960ed30..1c3f411598 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -24,7 +24,7 @@ use leo_asg::CircuitAccessExpression; use leo_asg::Node; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index 283cf6f79d..b69096f534 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -26,7 +26,7 @@ use leo_asg::CircuitMember; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn enforce_circuit>( diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index 4e163f7075..9362359105 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -23,9 +23,9 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce ternary conditional expression diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index f0279fa4e2..15f491a934 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -32,9 +32,9 @@ use leo_asg::ConstValue; use leo_asg::Expression; use leo_asg::Node; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn enforce_expression>( diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 732f6c132e..d0069cccd1 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -26,7 +26,7 @@ use leo_asg::Expression; use leo_asg::Function; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Call a default core circuit function with arguments diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index 730920fc32..ce9a93db74 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -27,7 +27,7 @@ use leo_asg::Function; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 49511a4cbc..5a1058a24f 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -21,8 +21,8 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index fe70594d91..ef93b720c7 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -21,9 +21,9 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; pub fn enforce_or<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 297de28a1e..24882d13de 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -22,10 +22,10 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index e52e06808e..f1a7e0f2ba 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -23,7 +23,7 @@ use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index f946eb4759..756c5873ec 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -23,7 +23,7 @@ use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 21388b24f6..4a51742b59 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -23,7 +23,7 @@ use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 83e626101b..826cc03b7f 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -24,7 +24,7 @@ use leo_asg::Expression; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/expression/tuple/tuple.rs b/compiler/src/expression/tuple/tuple.rs index 27f716c029..4836a341b7 100644 --- a/compiler/src/expression/tuple/tuple.rs +++ b/compiler/src/expression/tuple/tuple.rs @@ -25,7 +25,7 @@ use crate::GroupType; use leo_asg::Expression; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce tuple expressions diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index bffcf28444..b0d9314096 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -26,9 +26,9 @@ use leo_asg::Function; use leo_asg::FunctionQualifier; use std::cell::Cell; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub(crate) fn enforce_function>( diff --git a/compiler/src/function/input/array.rs b/compiler/src/function/input/array.rs index 4e887488a1..fd47f63b61 100644 --- a/compiler/src/function/input/array.rs +++ b/compiler/src/function/input/array.rs @@ -26,7 +26,7 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_array>( diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index 31a82dfb53..5f6567795e 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -27,7 +27,7 @@ use leo_ast::Input; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub const RECORD_VARIABLE_NAME: &str = "record"; pub const REGISTERS_VARIABLE_NAME: &str = "registers"; diff --git a/compiler/src/function/input/main_function_input.rs b/compiler/src/function/input/main_function_input.rs index 2262956132..ae142567e7 100644 --- a/compiler/src/function/input/main_function_input.rs +++ b/compiler/src/function/input/main_function_input.rs @@ -30,7 +30,7 @@ use leo_asg::Type; use leo_ast::InputValue; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_main_function_input>( diff --git a/compiler/src/function/input/tuple.rs b/compiler/src/function/input/tuple.rs index 1bde04d614..31683f2053 100644 --- a/compiler/src/function/input/tuple.rs +++ b/compiler/src/function/input/tuple.rs @@ -26,7 +26,7 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn allocate_tuple>( diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 6a4da1728b..cf083034ea 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -28,7 +28,7 @@ use leo_ast::Input; use std::cell::Cell; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn enforce_main_function>( diff --git a/compiler/src/function/mut_target.rs b/compiler/src/function/mut_target.rs index b381c470c5..ce6cb83b82 100644 --- a/compiler/src/function/mut_target.rs +++ b/compiler/src/function/mut_target.rs @@ -31,7 +31,7 @@ use leo_asg::TupleAccessExpression; use leo_asg::Variable; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { fn prepare_mut_access>( diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 7d90bfa3c9..196893cf48 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -25,10 +25,10 @@ use crate::GroupType; use leo_asg::Span; use leo_asg::Type; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index f20d41562c..4bfd9b6b20 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -22,11 +22,11 @@ use crate::Integer; use leo_asg::Function; use leo_asg::Span; use snarkvm_gadgets::algorithms::prf::Blake2sGadget; +use snarkvm_gadgets::traits::uint::UInt8; +use snarkvm_gadgets::traits::ToBytesGadget; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::algorithms::PRFGadget; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::uint::UInt8; -use snarkvm_models::gadgets::utilities::ToBytesGadget; +use snarkvm_r1cs::ConstraintSystem; pub struct Blake2s; diff --git a/compiler/src/prelude/mod.rs b/compiler/src/prelude/mod.rs index be3a4b0f41..9b220d3120 100644 --- a/compiler/src/prelude/mod.rs +++ b/compiler/src/prelude/mod.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::Function; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub trait CoreCircuit<'a, F: PrimeField, G: GroupType>: Send + Sync { fn call_function>( diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 987358a078..24fde4ebf6 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -25,10 +25,10 @@ use leo_asg::AssignOperation; use leo_asg::AssignStatement; use leo_asg::Span; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/statement/assign/assignee.rs b/compiler/src/statement/assign/assignee.rs index 97cb46de9c..857025f779 100644 --- a/compiler/src/statement/assign/assignee.rs +++ b/compiler/src/statement/assign/assignee.rs @@ -26,7 +26,7 @@ use leo_asg::Identifier; use leo_asg::Span; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; pub(crate) enum ResolvedAssigneeAccess { ArrayRange(Option, Option), diff --git a/compiler/src/statement/block/block.rs b/compiler/src/statement/block/block.rs index 416b7174fa..a9c6dcf2b2 100644 --- a/compiler/src/statement/block/block.rs +++ b/compiler/src/statement/block/block.rs @@ -22,9 +22,9 @@ use crate::IndicatorAndConstrainedValue; use crate::StatementResult; use leo_asg::BlockStatement; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Evaluates a branch of one or more statements and returns a result in diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 9443b741b9..5681db3c0f 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -24,9 +24,9 @@ use crate::IndicatorAndConstrainedValue; use crate::StatementResult; use leo_asg::ConditionalStatement; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; fn indicator_to_string(indicator: &Boolean) -> String { indicator diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 0575151b0e..17cea104bd 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -25,7 +25,7 @@ use leo_asg::Span; use leo_asg::Variable; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { fn enforce_multiple_definition( diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index fa80246a55..03f9deb327 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -24,10 +24,10 @@ use crate::Integer; use crate::StatementResult; use leo_asg::IterationStatement; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::uint::UInt32; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::uint::UInt32; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { #[allow(clippy::too_many_arguments)] diff --git a/compiler/src/statement/return_/return_.rs b/compiler/src/statement/return_/return_.rs index a8bb525a02..8c81b50400 100644 --- a/compiler/src/statement/return_/return_.rs +++ b/compiler/src/statement/return_/return_.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::ReturnStatement; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn enforce_return_statement>( diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 6ffcf6d3f6..2a5d32eda9 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -22,9 +22,9 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Statement; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; pub type StatementResult = Result; pub type IndicatorAndConstrainedValue<'a, T, U> = (Boolean, ConstrainedValue<'a, T, U>); diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index de9c5dea84..9dee56382f 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -22,18 +22,18 @@ use leo_ast::Span; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::eq::EqGadget; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_gadgets::traits::uint::UInt; +use snarkvm_gadgets::traits::uint::UInt8; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; -use snarkvm_models::gadgets::utilities::eq::EqGadget; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::utilities::uint::UInt; -use snarkvm_models::gadgets::utilities::uint::UInt8; use snarkvm_objects::account::AccountAddress; +use snarkvm_r1cs::ConstraintSystem; use snarkvm_utilities::ToBytes; use std::borrow::Borrow; use std::str::FromStr; @@ -207,7 +207,11 @@ impl ConditionalEqGadget for Address { } fn cond_select_helper(first: &Address, second: &Address, cond: bool) -> Address { - if cond { first.clone() } else { second.clone() } + if cond { + first.clone() + } else { + second.clone() + } } impl CondSelectGadget for Address { diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index a22be403cf..9ea21bd5e3 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -23,9 +23,9 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; pub(crate) fn allocate_bool>( diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index ed794e1960..a7faf497f2 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -21,20 +21,20 @@ use crate::number_string_typing; use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::eq::EqGadget; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_gadgets::traits::uint::UInt8; +use snarkvm_gadgets::traits::ToBitsGadget; +use snarkvm_gadgets::traits::ToBytesGadget; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::curves::AllocatedFp; use snarkvm_models::gadgets::curves::FieldGadget; use snarkvm_models::gadgets::curves::FpGadget; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; -use snarkvm_models::gadgets::utilities::eq::EqGadget; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::utilities::uint::UInt8; -use snarkvm_models::gadgets::utilities::ToBitsGadget; -use snarkvm_models::gadgets::utilities::ToBytesGadget; +use snarkvm_r1cs::ConstraintSystem; use std::borrow::Borrow; use std::cmp::Ordering; @@ -293,7 +293,11 @@ impl CondSelectGadget for FieldType { second: &Self, ) -> Result { if let Boolean::Constant(cond) = *cond { - if cond { Ok(first.clone()) } else { Ok(second.clone()) } + if cond { + Ok(first.clone()) + } else { + Ok(second.clone()) + } } else { let first_gadget = first.allocated(&mut cs)?; let second_gadget = second.allocated(&mut cs)?; diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index b296daace1..e67222ed59 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -25,9 +25,9 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_r1cs::ConstraintSystem; pub(crate) fn allocate_field>( cs: &mut CS, diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index e305f88c4d..94a5a496a2 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -21,15 +21,15 @@ use leo_asg::GroupValue; use leo_asg::Span; use snarkvm_fields::Field; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::eq::EqGadget; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_gadgets::traits::ToBitsGadget; +use snarkvm_gadgets::traits::ToBytesGadget; use snarkvm_models::curves::One; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; -use snarkvm_models::gadgets::utilities::eq::EqGadget; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::utilities::ToBitsGadget; -use snarkvm_models::gadgets::utilities::ToBytesGadget; +use snarkvm_r1cs::ConstraintSystem; use std::fmt::Debug; use std::fmt::Display; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 799a860114..580d8d153d 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -27,6 +27,15 @@ use snarkvm_curves::edwards_bls12::Fq; use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::eq::EqGadget; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_gadgets::traits::uint::UInt8; +use snarkvm_gadgets::traits::ToBitsGadget; +use snarkvm_gadgets::traits::ToBytesGadget; use snarkvm_models::curves::AffineCurve; use snarkvm_models::curves::Fp256; use snarkvm_models::curves::One; @@ -36,16 +45,7 @@ use snarkvm_models::gadgets::curves::AllocatedFp; use snarkvm_models::gadgets::curves::FieldGadget; use snarkvm_models::gadgets::curves::FpGadget; use snarkvm_models::gadgets::curves::GroupGadget; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; -use snarkvm_models::gadgets::utilities::eq::EqGadget; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::utilities::uint::UInt8; -use snarkvm_models::gadgets::utilities::ToBitsGadget; -use snarkvm_models::gadgets::utilities::ToBytesGadget; +use snarkvm_r1cs::ConstraintSystem; use std::borrow::Borrow; use std::ops::Mul; use std::ops::Neg; @@ -488,7 +488,11 @@ impl CondSelectGadget for EdwardsGroupType { second: &Self, ) -> Result { if let Boolean::Constant(cond) = *cond { - if cond { Ok(first.clone()) } else { Ok(second.clone()) } + if cond { + Ok(first.clone()) + } else { + Ok(second.clone()) + } } else { let first_gadget = first.allocated(cs.ns(|| "first"))?; let second_gadget = second.allocated(cs.ns(|| "second"))?; diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 3e016a78a1..171de0eda2 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -28,15 +28,15 @@ use leo_gadgets::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::eq::EqGadget; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_gadgets::traits::uint::*; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; -use snarkvm_models::gadgets::utilities::eq::EqGadget; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::utilities::uint::*; +use snarkvm_r1cs::ConstraintSystem; use std::fmt; /// An integer type enum wrapping the integer value. diff --git a/compiler/src/value/integer/macros.rs b/compiler/src/value/integer/macros.rs index 8040fb5792..4d59bba6a7 100644 --- a/compiler/src/value/integer/macros.rs +++ b/compiler/src/value/integer/macros.rs @@ -16,12 +16,12 @@ use leo_gadgets::signed_integer::*; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::uint::UInt128; -use snarkvm_models::gadgets::utilities::uint::UInt16; -use snarkvm_models::gadgets::utilities::uint::UInt32; -use snarkvm_models::gadgets::utilities::uint::UInt64; -use snarkvm_models::gadgets::utilities::uint::UInt8; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::uint::UInt128; +use snarkvm_gadgets::traits::uint::UInt16; +use snarkvm_gadgets::traits::uint::UInt32; +use snarkvm_gadgets::traits::uint::UInt64; +use snarkvm_gadgets::traits::uint::UInt8; use std::fmt::Debug; pub trait IntegerTrait: Sized + Clone + Debug { diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 055116375f..b0b9c9e54d 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -27,11 +27,11 @@ use leo_asg::Span; use leo_asg::Type; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; use std::fmt; #[derive(Clone, PartialEq, Eq)] diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index 2288a270f5..826b8ff1c6 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -21,10 +21,10 @@ use leo_gadgets::Int32; use leo_gadgets::Int64; use leo_gadgets::Int8; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; +use snarkvm_r1cs::ConstraintSystem; use rand::Rng; use rand::SeedableRng; diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index c3e6b8304b..140a065c21 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -16,14 +16,14 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; +use snarkvm_gadgets::traits::uint::UInt; +use snarkvm_gadgets::traits::uint::UInt128; +use snarkvm_gadgets::traits::uint::UInt16; +use snarkvm_gadgets::traits::uint::UInt32; +use snarkvm_gadgets::traits::uint::UInt64; +use snarkvm_gadgets::traits::uint::UInt8; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::uint::UInt; -use snarkvm_models::gadgets::utilities::uint::UInt128; -use snarkvm_models::gadgets::utilities::uint::UInt16; -use snarkvm_models::gadgets::utilities::uint::UInt32; -use snarkvm_models::gadgets::utilities::uint::UInt64; -use snarkvm_models::gadgets::utilities::uint::UInt8; +use snarkvm_r1cs::ConstraintSystem; /// Returns addition of `self` + `other` in the constraint system. pub trait Add diff --git a/gadgets/src/arithmetic/div.rs b/gadgets/src/arithmetic/div.rs index 113f874d7e..ca1a93c899 100644 --- a/gadgets/src/arithmetic/div.rs +++ b/gadgets/src/arithmetic/div.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; /// Returns division of `self` / `other` in the constraint system. pub trait Div diff --git a/gadgets/src/arithmetic/mul.rs b/gadgets/src/arithmetic/mul.rs index 04ccf13dc0..e99b339d4a 100644 --- a/gadgets/src/arithmetic/mul.rs +++ b/gadgets/src/arithmetic/mul.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; /// Returns multiplication of `self` * `other` in the constraint system. pub trait Mul diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index fa82bcacf7..bdb18ff086 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -18,8 +18,8 @@ use crate::bits::RippleCarryAdder; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; use std::iter; diff --git a/gadgets/src/arithmetic/pow.rs b/gadgets/src/arithmetic/pow.rs index d405abc153..bb1e8427c9 100644 --- a/gadgets/src/arithmetic/pow.rs +++ b/gadgets/src/arithmetic/pow.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; /// Returns exponentiation of `self` ** `other` in the constraint system. pub trait Pow diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index 11d685f04e..5c4997a7b4 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -16,8 +16,8 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; /// Single bit binary adder with carry bit /// https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index a60404aa73..09ffb34382 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -16,14 +16,14 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_gadgets::traits::uint::UInt128; +use snarkvm_gadgets::traits::uint::UInt16; +use snarkvm_gadgets::traits::uint::UInt32; +use snarkvm_gadgets::traits::uint::UInt64; +use snarkvm_gadgets::traits::uint::UInt8; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::utilities::uint::UInt128; -use snarkvm_models::gadgets::utilities::uint::UInt16; -use snarkvm_models::gadgets::utilities::uint::UInt32; -use snarkvm_models::gadgets::utilities::uint::UInt64; -use snarkvm_models::gadgets::utilities::uint::UInt8; use snarkvm_r1cs::ConstraintSystem; pub trait EvaluateLtGadget { diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index ac3ff9ec6f..372d91760e 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -19,9 +19,9 @@ use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; /// Returns the bitwise sum of a n-bit number with carry bit pub trait RippleCarryAdder diff --git a/gadgets/src/bits/sign_extend.rs b/gadgets/src/bits/sign_extend.rs index a0ee439a45..0e11057328 100644 --- a/gadgets/src/bits/sign_extend.rs +++ b/gadgets/src/bits/sign_extend.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 snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::boolean::Boolean; use std::iter; diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index 8bab46e5d5..51eb1a7388 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -24,14 +24,14 @@ use crate::Int32; use crate::Int64; use crate::Int8; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::AllocatedBit; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::fp_parameters::FpParameters; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::LinearCombination; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; macro_rules! add_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/div.rs b/gadgets/src/signed_integer/arithmetic/div.rs index b140a875d3..13e56297e6 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -26,13 +26,13 @@ use crate::Int16; use crate::Int32; use crate::Int64; use crate::Int8; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::AllocatedBit; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; macro_rules! div_int_impl { ($($gadget:ident),*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index fb30a68c82..4b20d34a28 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -24,15 +24,15 @@ use crate::Int16; use crate::Int32; use crate::Int64; use crate::Int8; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::AllocatedBit; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::FpParameters; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::LinearCombination; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; use std::iter; diff --git a/gadgets/src/signed_integer/arithmetic/neg.rs b/gadgets/src/signed_integer/arithmetic/neg.rs index 39aa3f567f..2015a43966 100644 --- a/gadgets/src/signed_integer/arithmetic/neg.rs +++ b/gadgets/src/signed_integer/arithmetic/neg.rs @@ -19,7 +19,7 @@ use crate::errors::SignedIntegerError; use crate::signed_integer::*; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; macro_rules! neg_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/pow.rs b/gadgets/src/signed_integer/arithmetic/pow.rs index fc59955472..dc1f57cba9 100644 --- a/gadgets/src/signed_integer/arithmetic/pow.rs +++ b/gadgets/src/signed_integer/arithmetic/pow.rs @@ -24,11 +24,11 @@ use crate::Int32; use crate::Int64; use crate::Int8; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; macro_rules! pow_int_impl { ($($gadget:ty)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/sub.rs b/gadgets/src/signed_integer/arithmetic/sub.rs index 95ab05f120..45b669c3e0 100644 --- a/gadgets/src/signed_integer/arithmetic/sub.rs +++ b/gadgets/src/signed_integer/arithmetic/sub.rs @@ -24,7 +24,7 @@ use crate::Int32; use crate::Int64; use crate::Int8; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; macro_rules! sub_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/int_impl.rs b/gadgets/src/signed_integer/int_impl.rs index 005d207033..244942867b 100644 --- a/gadgets/src/signed_integer/int_impl.rs +++ b/gadgets/src/signed_integer/int_impl.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 snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::boolean::Boolean; use std::fmt::Debug; diff --git a/gadgets/src/signed_integer/relational/cmp.rs b/gadgets/src/signed_integer/relational/cmp.rs index 25b8c91e1c..f70d078bc0 100644 --- a/gadgets/src/signed_integer/relational/cmp.rs +++ b/gadgets/src/signed_integer/relational/cmp.rs @@ -23,10 +23,10 @@ use crate::Int64; use crate::Int8; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; use std::cmp::Ordering; macro_rules! cmp_gadget_impl { diff --git a/gadgets/src/signed_integer/relational/eq.rs b/gadgets/src/signed_integer/relational/eq.rs index eff476b8b6..d11767b4e7 100644 --- a/gadgets/src/signed_integer/relational/eq.rs +++ b/gadgets/src/signed_integer/relational/eq.rs @@ -22,10 +22,10 @@ use crate::Int64; use crate::Int8; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::EvaluateEqGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::EvaluateEqGadget; +use snarkvm_r1cs::ConstraintSystem; macro_rules! eq_gadget_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/utilities/alloc.rs b/gadgets/src/signed_integer/utilities/alloc.rs index 435f193bbd..24f73654b0 100644 --- a/gadgets/src/signed_integer/utilities/alloc.rs +++ b/gadgets/src/signed_integer/utilities/alloc.rs @@ -25,10 +25,10 @@ use core::borrow::Borrow; use core::iter; use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::AllocatedBit; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::AllocatedBit; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; fn create_value, I: IntoIterator>, F: Field, CS: ConstraintSystem>( cs: &mut CS, diff --git a/gadgets/src/signed_integer/utilities/eq.rs b/gadgets/src/signed_integer/utilities/eq.rs index 572e8947fb..006b6c1467 100644 --- a/gadgets/src/signed_integer/utilities/eq.rs +++ b/gadgets/src/signed_integer/utilities/eq.rs @@ -17,10 +17,10 @@ use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::ConditionalEqGadget; use snarkvm_models::curves::PrimeField; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::ConditionalEqGadget; +use snarkvm_r1cs::ConstraintSystem; macro_rules! cond_eq_int_impl { ($($gadget: ident),*) => ($( diff --git a/gadgets/src/signed_integer/utilities/select.rs b/gadgets/src/signed_integer/utilities/select.rs index 7193f10843..0df2b857d7 100644 --- a/gadgets/src/signed_integer/utilities/select.rs +++ b/gadgets/src/signed_integer/utilities/select.rs @@ -17,13 +17,13 @@ use crate::signed_integer::*; use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::eq::EqGadget; +use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; -use snarkvm_models::gadgets::utilities::eq::EqGadget; -use snarkvm_models::gadgets::utilities::select::CondSelectGadget; +use snarkvm_r1cs::ConstraintSystem; macro_rules! select_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index a9082a2992..b3ed0cf355 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -17,13 +17,13 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int128; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index fab35e9141..f9881c490b 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -17,13 +17,13 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int16; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index aceaef8188..34a569df5a 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -17,13 +17,13 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int32; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index e3d0de1b35..594d9917da 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -17,12 +17,12 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int64; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; use rand::Rng; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index 1702409aae..b1e76be6f9 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -17,13 +17,13 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int8; +use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; -use snarkvm_models::gadgets::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::utilities::boolean::Boolean; +use snarkvm_r1cs::ConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 52f8de4d58..31124d1b58 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -35,7 +35,7 @@ use leo_synthesizer::SerializedCircuit; use anyhow::Result; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::edwards_bls12::Fq; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; +use snarkvm_r1cs::ConstraintSystem; use structopt::StructOpt; use tracing::span::Span; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 28260e0d89..3a91f74797 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -16,12 +16,12 @@ use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; +use snarkvm_gadgets::traits::OptionalVec; use snarkvm_models::curves::PairingEngine; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Index; use snarkvm_models::gadgets::r1cs::LinearCombination; use snarkvm_models::gadgets::r1cs::Variable; -use snarkvm_models::gadgets::utilities::OptionalVec; +use snarkvm_r1cs::ConstraintSystem; #[derive(Default)] pub struct Namespace { diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 258b38e644..77001990af 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -20,10 +20,10 @@ use serde::Deserialize; use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_errors::curves::FieldError; +use snarkvm_gadgets::traits::OptionalVec; use snarkvm_models::curves::PairingEngine; -use snarkvm_models::gadgets::r1cs::ConstraintSystem; use snarkvm_models::gadgets::r1cs::Index; -use snarkvm_models::gadgets::utilities::OptionalVec; +use snarkvm_r1cs::ConstraintSystem; use crate::CircuitSynthesizer; use crate::SerializedField; From b95495bab3654e9d4040d6bf682a549ace1a6f5f Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:39:22 -0800 Subject: [PATCH 42/92] Update r1cs error --- compiler/src/errors/expression.rs | 2 +- compiler/src/errors/value/address.rs | 2 +- compiler/src/errors/value/group.rs | 2 +- compiler/src/value/boolean/input.rs | 2 +- compiler/src/value/group/input.rs | 2 +- compiler/src/value/group/targets/edwards_bls12.rs | 2 +- gadgets/src/arithmetic/neg.rs | 2 +- gadgets/src/bits/comparator.rs | 2 +- gadgets/src/signed_integer/utilities/eq.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index 3be7305635..e109e7fdb8 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -27,7 +27,7 @@ use leo_ast::Identifier; use leo_ast::PositiveNumber; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_r1cs::SynthesisError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index 6cd7bee1bf..f9f2b48646 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -17,8 +17,8 @@ use leo_ast::Error as FormattedError; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_errors::objects::account::AccountError; +use snarkvm_r1cs::SynthesisError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index a241a6e641..1bfa2c53f7 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -17,7 +17,7 @@ use leo_ast::Error as FormattedError; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_r1cs::SynthesisError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index 9ea21bd5e3..dbd1d6b824 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -22,11 +22,11 @@ use crate::GroupType; use leo_ast::InputValue; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; pub(crate) fn allocate_bool>( cs: &mut CS, diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 18d1f91a3b..04b6a204c9 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -23,9 +23,9 @@ use leo_asg::GroupValue; use leo_asg::Span; use leo_ast::InputValue; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; pub(crate) fn allocate_group, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 580d8d153d..287f5549da 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -25,7 +25,6 @@ use snarkvm_curves::edwards_bls12::EdwardsAffine; use snarkvm_curves::edwards_bls12::EdwardsParameters; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; @@ -46,6 +45,7 @@ use snarkvm_models::gadgets::curves::FieldGadget; use snarkvm_models::gadgets::curves::FpGadget; use snarkvm_models::gadgets::curves::GroupGadget; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use std::borrow::Borrow; use std::ops::Mul; use std::ops::Neg; diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index bdb18ff086..96ec6b87c7 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -16,10 +16,10 @@ use crate::bits::RippleCarryAdder; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use std::iter; diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index 09ffb34382..33cbbd86a6 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::select::CondSelectGadget; @@ -25,6 +24,7 @@ use snarkvm_gadgets::traits::uint::UInt64; use snarkvm_gadgets::traits::uint::UInt8; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; pub trait EvaluateLtGadget { fn less_than>(&self, cs: CS, other: &Self) -> Result; diff --git a/gadgets/src/signed_integer/utilities/eq.rs b/gadgets/src/signed_integer/utilities/eq.rs index 006b6c1467..600cb5a35c 100644 --- a/gadgets/src/signed_integer/utilities/eq.rs +++ b/gadgets/src/signed_integer/utilities/eq.rs @@ -16,11 +16,11 @@ use crate::signed_integer::*; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::ConditionalEqGadget; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; macro_rules! cond_eq_int_impl { ($($gadget: ident),*) => ($( From fc4bc537dd6a34052fb0c33cd40844111d62296b Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:39:56 -0800 Subject: [PATCH 43/92] Update primefield traits --- compiler/src/compiler.rs | 2 +- compiler/src/errors/value/boolean.rs | 2 +- compiler/src/errors/value/field.rs | 2 +- compiler/src/errors/value/integer.rs | 2 +- compiler/src/expression/array/array.rs | 2 +- compiler/src/expression/logical/and.rs | 2 +- compiler/src/expression/relational/lt.rs | 2 +- compiler/src/function/input/input_section.rs | 2 +- compiler/src/value/address/address.rs | 2 +- compiler/src/value/boolean/input.rs | 2 +- compiler/src/value/field/field_type.rs | 2 +- compiler/src/value/field/input.rs | 2 +- compiler/src/value/group/input.rs | 2 +- compiler/src/value/integer/integer.rs | 2 +- compiler/src/value/value.rs | 2 +- gadgets/src/arithmetic/add.rs | 2 +- gadgets/src/bits/adder.rs | 2 +- gadgets/src/bits/comparator.rs | 2 +- gadgets/src/bits/rca.rs | 2 +- gadgets/src/errors/signed_integer.rs | 2 +- gadgets/src/signed_integer/relational/cmp.rs | 2 +- gadgets/src/signed_integer/relational/eq.rs | 2 +- gadgets/src/signed_integer/utilities/alloc.rs | 2 +- gadgets/src/signed_integer/utilities/eq.rs | 2 +- gadgets/src/signed_integer/utilities/select.rs | 2 +- synthesizer/src/circuit_synthesizer.rs | 2 +- 26 files changed, 26 insertions(+), 26 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index a4074714cb..2b5a2b2330 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -34,10 +34,10 @@ use leo_state::verify_local_data_commitment; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_dpc::SystemParameters; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSynthesizer; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use sha2::Digest; use sha2::Sha256; diff --git a/compiler/src/errors/value/boolean.rs b/compiler/src/errors/value/boolean.rs index ee17dbf182..e6472dfaf1 100644 --- a/compiler/src/errors/value/boolean.rs +++ b/compiler/src/errors/value/boolean.rs @@ -17,7 +17,7 @@ use leo_ast::Error as FormattedError; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_r1cs::SynthesisError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/errors/value/field.rs b/compiler/src/errors/value/field.rs index cc92bbc24c..f1e2c2e152 100644 --- a/compiler/src/errors/value/field.rs +++ b/compiler/src/errors/value/field.rs @@ -17,7 +17,7 @@ use leo_ast::Error as FormattedError; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_r1cs::SynthesisError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index ba8b18c928..6aabfe6dd2 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -20,7 +20,7 @@ use leo_ast::Span; use leo_ast::Type; use leo_gadgets::errors::SignedIntegerError; -use snarkvm_errors::gadgets::SynthesisError; +use snarkvm_r1cs::SynthesisError; use std::path::Path; #[derive(Debug, Error)] diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 9680213fe1..d904356a49 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -25,7 +25,7 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 5a1058a24f..bc160d223e 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -21,8 +21,8 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; +use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index c47f63c526..19c98f63a2 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::comparator::EvaluateLtGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_lt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index 45216ebafd..0e7cdac513 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -26,7 +26,7 @@ use leo_ast::Identifier; use leo_ast::InputValue; use leo_ast::Parameter; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; use indexmap::IndexMap; diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 9dee56382f..675eed12d1 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -21,7 +21,6 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::ConditionalEqGadget; @@ -34,6 +33,7 @@ use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_objects::account::AccountAddress; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use snarkvm_utilities::ToBytes; use std::borrow::Borrow; use std::str::FromStr; diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index dbd1d6b824..8b21a431c7 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -22,9 +22,9 @@ use crate::GroupType; use leo_ast::InputValue; use leo_ast::Span; +use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index a7faf497f2..3dc62ec3cf 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -20,7 +20,6 @@ use crate::errors::FieldError; use crate::number_string_typing; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::ConditionalEqGadget; @@ -35,6 +34,7 @@ use snarkvm_models::gadgets::curves::AllocatedFp; use snarkvm_models::gadgets::curves::FieldGadget; use snarkvm_models::gadgets::curves::FpGadget; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use std::borrow::Borrow; use std::cmp::Ordering; diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index e67222ed59..0821cf69c0 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -24,10 +24,10 @@ use crate::GroupType; use leo_ast::InputValue; use leo_ast::Span; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; pub(crate) fn allocate_field>( cs: &mut CS, diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index 04b6a204c9..ff4f084e75 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -23,7 +23,7 @@ use leo_asg::GroupValue; use leo_asg::Span; use leo_ast::InputValue; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 171de0eda2..1343a1e5f7 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -26,7 +26,6 @@ use leo_gadgets::bits::comparator::ComparatorGadget; use leo_gadgets::bits::comparator::EvaluateLtGadget; use leo_gadgets::signed_integer::*; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; @@ -37,6 +36,7 @@ use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_gadgets::traits::uint::*; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use std::fmt; /// An integer type enum wrapping the integer value. diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index b0b9c9e54d..7effee0438 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -26,12 +26,12 @@ use leo_asg::Identifier; use leo_asg::Span; use leo_asg::Type; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::ConditionalEqGadget; use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use std::fmt; #[derive(Clone, PartialEq, Eq)] diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index 140a065c21..08b3c097b7 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::uint::UInt; use snarkvm_gadgets::traits::uint::UInt128; @@ -24,6 +23,7 @@ use snarkvm_gadgets::traits::uint::UInt64; use snarkvm_gadgets::traits::uint::UInt8; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; /// Returns addition of `self` + `other` in the constraint system. pub trait Add diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index 5c4997a7b4..0f16b68242 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; /// Single bit binary adder with carry bit /// https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index 33cbbd86a6..f223d38799 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -15,6 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; +use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_gadgets::traits::uint::UInt128; @@ -22,7 +23,6 @@ use snarkvm_gadgets::traits::uint::UInt16; use snarkvm_gadgets::traits::uint::UInt32; use snarkvm_gadgets::traits::uint::UInt64; use snarkvm_gadgets::traits::uint::UInt8; -use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index 372d91760e..594f96a033 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -17,11 +17,11 @@ use crate::bits::FullAdder; use crate::signed_integer::*; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; /// Returns the bitwise sum of a n-bit number with carry bit pub trait RippleCarryAdder diff --git a/gadgets/src/errors/signed_integer.rs b/gadgets/src/errors/signed_integer.rs index f7a900b741..8998531882 100644 --- a/gadgets/src/errors/signed_integer.rs +++ b/gadgets/src/errors/signed_integer.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 snarkvm_errors::gadgets::SynthesisError; +use snarkvm_r1cs::SynthesisError; #[derive(Debug, Error)] pub enum SignedIntegerError { diff --git a/gadgets/src/signed_integer/relational/cmp.rs b/gadgets/src/signed_integer/relational/cmp.rs index f70d078bc0..1c8c956d62 100644 --- a/gadgets/src/signed_integer/relational/cmp.rs +++ b/gadgets/src/signed_integer/relational/cmp.rs @@ -22,11 +22,11 @@ use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; use std::cmp::Ordering; macro_rules! cmp_gadget_impl { diff --git a/gadgets/src/signed_integer/relational/eq.rs b/gadgets/src/signed_integer/relational/eq.rs index d11767b4e7..6c8a4e8d19 100644 --- a/gadgets/src/signed_integer/relational/eq.rs +++ b/gadgets/src/signed_integer/relational/eq.rs @@ -21,11 +21,11 @@ use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::EvaluateEqGadget; use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; macro_rules! eq_gadget_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/utilities/alloc.rs b/gadgets/src/signed_integer/utilities/alloc.rs index 24f73654b0..84b6670887 100644 --- a/gadgets/src/signed_integer/utilities/alloc.rs +++ b/gadgets/src/signed_integer/utilities/alloc.rs @@ -23,12 +23,12 @@ use crate::Int8; use core::borrow::Borrow; use core::iter; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::AllocatedBit; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; fn create_value, I: IntoIterator>, F: Field, CS: ConstraintSystem>( cs: &mut CS, diff --git a/gadgets/src/signed_integer/utilities/eq.rs b/gadgets/src/signed_integer/utilities/eq.rs index 600cb5a35c..5b311ea946 100644 --- a/gadgets/src/signed_integer/utilities/eq.rs +++ b/gadgets/src/signed_integer/utilities/eq.rs @@ -16,9 +16,9 @@ use crate::signed_integer::*; +use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_models::curves::PrimeField; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/signed_integer/utilities/select.rs b/gadgets/src/signed_integer/utilities/select.rs index 0df2b857d7..6f0198e560 100644 --- a/gadgets/src/signed_integer/utilities/select.rs +++ b/gadgets/src/signed_integer/utilities/select.rs @@ -16,7 +16,6 @@ use crate::signed_integer::*; -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_gadgets::traits::alloc::AllocGadget; use snarkvm_gadgets::traits::boolean::Boolean; use snarkvm_gadgets::traits::eq::EqGadget; @@ -24,6 +23,7 @@ use snarkvm_gadgets::traits::select::CondSelectGadget; use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; macro_rules! select_int_impl { ($($gadget: ident)*) => ($( diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 3a91f74797..0316b91ce0 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_errors::gadgets::SynthesisError; use snarkvm_fields::Field; use snarkvm_gadgets::traits::OptionalVec; use snarkvm_models::curves::PairingEngine; @@ -22,6 +21,7 @@ use snarkvm_models::gadgets::r1cs::Index; use snarkvm_models::gadgets::r1cs::LinearCombination; use snarkvm_models::gadgets::r1cs::Variable; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::SynthesisError; #[derive(Default)] pub struct Namespace { From f3daba63dfc07dd4ac71622930b445dfc905ea82 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:41:33 -0800 Subject: [PATCH 44/92] Update gadgets traits --- compiler/src/compiler.rs | 2 +- compiler/src/console/assert.rs | 4 ++-- compiler/src/console/console.rs | 4 ++-- compiler/src/console/format.rs | 2 +- compiler/src/constraints/constraints.rs | 2 +- compiler/src/definition/definition.rs | 2 +- compiler/src/expression/arithmetic/add.rs | 2 +- compiler/src/expression/arithmetic/div.rs | 2 +- compiler/src/expression/arithmetic/mul.rs | 2 +- compiler/src/expression/arithmetic/negate.rs | 2 +- compiler/src/expression/arithmetic/pow.rs | 2 +- compiler/src/expression/arithmetic/sub.rs | 2 +- compiler/src/expression/array/access.rs | 2 +- compiler/src/expression/array/index.rs | 2 +- compiler/src/expression/binary/binary.rs | 2 +- compiler/src/expression/circuit/access.rs | 2 +- compiler/src/expression/circuit/circuit.rs | 2 +- .../src/expression/conditional/conditional.rs | 4 ++-- compiler/src/expression/expression.rs | 4 ++-- .../src/expression/function/core_circuit.rs | 2 +- compiler/src/expression/function/function.rs | 2 +- compiler/src/expression/logical/and.rs | 2 +- compiler/src/expression/logical/not.rs | 2 +- compiler/src/expression/logical/or.rs | 4 ++-- compiler/src/expression/relational/eq.rs | 6 +++--- compiler/src/expression/relational/ge.rs | 2 +- compiler/src/expression/relational/gt.rs | 2 +- compiler/src/expression/relational/le.rs | 2 +- compiler/src/expression/tuple/access.rs | 2 +- compiler/src/expression/tuple/tuple.rs | 2 +- .../expression/variable_ref/variable_ref.rs | 2 +- compiler/src/function/function.rs | 4 ++-- compiler/src/function/input/array.rs | 2 +- compiler/src/function/input/input_keyword.rs | 2 +- .../src/function/input/main_function_input.rs | 2 +- compiler/src/function/input/tuple.rs | 2 +- compiler/src/function/main_function.rs | 2 +- compiler/src/function/mut_target.rs | 2 +- compiler/src/function/result/result.rs | 6 +++--- compiler/src/output/output_bytes.rs | 2 +- compiler/src/prelude/blake2s.rs | 6 +++--- compiler/src/prelude/mod.rs | 2 +- compiler/src/program/program.rs | 2 +- compiler/src/statement/assign/assign.rs | 6 +++--- compiler/src/statement/assign/assignee.rs | 2 +- compiler/src/statement/block/block.rs | 4 ++-- .../src/statement/conditional/conditional.rs | 4 ++-- .../src/statement/definition/definition.rs | 2 +- compiler/src/statement/iteration/iteration.rs | 6 +++--- compiler/src/statement/return_/return_.rs | 2 +- compiler/src/statement/statement.rs | 4 ++-- compiler/src/value/address/address.rs | 18 ++++++++--------- compiler/src/value/boolean/input.rs | 4 ++-- compiler/src/value/field/field_type.rs | 20 +++++++++---------- compiler/src/value/field/input.rs | 4 ++-- compiler/src/value/group/group_type.rs | 14 ++++++------- .../src/value/group/targets/edwards_bls12.rs | 18 ++++++++--------- compiler/src/value/integer/integer.rs | 16 +++++++-------- compiler/src/value/integer/macros.rs | 12 +++++------ compiler/src/value/value.rs | 8 ++++---- gadgets/benches/integer_arithmetic.rs | 2 +- gadgets/src/arithmetic/add.rs | 14 ++++++------- gadgets/src/arithmetic/neg.rs | 2 +- gadgets/src/bits/adder.rs | 2 +- gadgets/src/bits/comparator.rs | 14 ++++++------- gadgets/src/bits/rca.rs | 4 ++-- gadgets/src/bits/sign_extend.rs | 2 +- gadgets/src/signed_integer/arithmetic/add.rs | 8 ++++---- gadgets/src/signed_integer/arithmetic/div.rs | 12 +++++------ gadgets/src/signed_integer/arithmetic/mul.rs | 10 +++++----- gadgets/src/signed_integer/arithmetic/neg.rs | 2 +- gadgets/src/signed_integer/arithmetic/pow.rs | 8 ++++---- gadgets/src/signed_integer/arithmetic/sub.rs | 2 +- gadgets/src/signed_integer/int_impl.rs | 2 +- gadgets/src/signed_integer/relational/cmp.rs | 6 +++--- gadgets/src/signed_integer/relational/eq.rs | 6 +++--- gadgets/src/signed_integer/utilities/alloc.rs | 6 +++--- gadgets/src/signed_integer/utilities/eq.rs | 4 ++-- .../src/signed_integer/utilities/select.rs | 10 +++++----- gadgets/tests/signed_integer/i128.rs | 4 ++-- gadgets/tests/signed_integer/i16.rs | 4 ++-- gadgets/tests/signed_integer/i32.rs | 4 ++-- gadgets/tests/signed_integer/i64.rs | 4 ++-- gadgets/tests/signed_integer/i8.rs | 4 ++-- synthesizer/src/circuit_synthesizer.rs | 2 +- synthesizer/src/serialized_circuit.rs | 2 +- 86 files changed, 197 insertions(+), 197 deletions(-) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 2b5a2b2330..55195e043e 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -34,7 +34,7 @@ use leo_state::verify_local_data_commitment; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_dpc::SystemParameters; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSynthesizer; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index 2690423c5d..deb4abf99c 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -24,8 +24,8 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/console/console.rs b/compiler/src/console/console.rs index e9e13c8eb1..d6765f7ae8 100644 --- a/compiler/src/console/console.rs +++ b/compiler/src/console/console.rs @@ -23,8 +23,8 @@ use crate::GroupType; use leo_asg::ConsoleFunction; use leo_asg::ConsoleStatement; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index 95dd280707..6154039232 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -21,7 +21,7 @@ use crate::program::ConstrainedProgram; use crate::GroupType; use leo_asg::FormattedString; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 58d30775e7..34795a7cdf 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -26,7 +26,7 @@ use leo_ast::Input; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; use std::path::Path; diff --git a/compiler/src/definition/definition.rs b/compiler/src/definition/definition.rs index 1f440f1747..a542b0e565 100644 --- a/compiler/src/definition/definition.rs +++ b/compiler/src/definition/definition.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Variable; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { pub fn store_definition(&mut self, variable: &Variable, value: ConstrainedValue<'a, F, G>) { diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index ff699735e4..4086114e4b 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_add<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 8828641699..b0fd7dc2b5 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_div<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index 2bb9a98b30..88204ff7e0 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_mul<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/arithmetic/negate.rs b/compiler/src/expression/arithmetic/negate.rs index 00c8d7a720..e4ad3dfadd 100644 --- a/compiler/src/expression/arithmetic/negate.rs +++ b/compiler/src/expression/arithmetic/negate.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_negate<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index aa343dfca1..3ec3db06a0 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_pow<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index 8e3b4f783f..8a12764a79 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_sub<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 0d19983a31..371a195e19 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index cfc4b6742a..fe281f85de 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index 02c14a10e3..2bab64f405 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -22,7 +22,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Expression; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; type ConstrainedValuePair<'a, T, U> = (ConstrainedValue<'a, T, U>, ConstrainedValue<'a, T, U>); diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 1c3f411598..047d8fb32c 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::CircuitAccessExpression; use leo_asg::Node; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index b69096f534..6e25db67a5 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -25,7 +25,7 @@ use leo_asg::CircuitInitExpression; use leo_asg::CircuitMember; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index 9362359105..572c7ec737 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -23,8 +23,8 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 15f491a934..46e7021ba1 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -32,8 +32,8 @@ use leo_asg::ConstValue; use leo_asg::Expression; use leo_asg::Node; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index d0069cccd1..0c8ffa808a 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -25,7 +25,7 @@ use crate::errors::ExpressionError; use leo_asg::Expression; use leo_asg::Function; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index ce9a93db74..5ef05dacb8 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -26,7 +26,7 @@ use leo_asg::Expression; use leo_asg::Function; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index bc160d223e..6243fb3698 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_asg::Span; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_and<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/logical/not.rs b/compiler/src/expression/logical/not.rs index 6ab5d83021..3e7022bd57 100644 --- a/compiler/src/expression/logical/not.rs +++ b/compiler/src/expression/logical/not.rs @@ -21,7 +21,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; pub fn evaluate_not<'a, F: PrimeField, G: GroupType>( value: ConstrainedValue<'a, F, G>, diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index ef93b720c7..d8e42df918 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -21,8 +21,8 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; pub fn enforce_or<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 24882d13de..29fb597390 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -22,9 +22,9 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Span; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index f1a7e0f2ba..faa4f7c69a 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_ge<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index 756c5873ec..b30a97553b 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_gt<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 4a51742b59..6c247048bc 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -22,7 +22,7 @@ use crate::GroupType; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_le<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 826cc03b7f..46d37d6a10 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -23,7 +23,7 @@ use crate::GroupType; use leo_asg::Expression; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/tuple/tuple.rs b/compiler/src/expression/tuple/tuple.rs index 4836a341b7..5ab7b4da88 100644 --- a/compiler/src/expression/tuple/tuple.rs +++ b/compiler/src/expression/tuple/tuple.rs @@ -24,7 +24,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Expression; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/expression/variable_ref/variable_ref.rs b/compiler/src/expression/variable_ref/variable_ref.rs index f8bf605056..076b3dee3a 100644 --- a/compiler/src/expression/variable_ref/variable_ref.rs +++ b/compiler/src/expression/variable_ref/variable_ref.rs @@ -22,7 +22,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::VariableRef; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { /// Enforce a variable expression by getting the resolved value diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index b0d9314096..98df36cb2e 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -26,8 +26,8 @@ use leo_asg::Function; use leo_asg::FunctionQualifier; use std::cell::Cell; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/function/input/array.rs b/compiler/src/function/input/array.rs index fd47f63b61..5e6d9fd976 100644 --- a/compiler/src/function/input/array.rs +++ b/compiler/src/function/input/array.rs @@ -25,7 +25,7 @@ use leo_asg::Type; use leo_ast::InputValue; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index 5f6567795e..ae5cd8386a 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -26,7 +26,7 @@ use leo_ast::Identifier; use leo_ast::Input; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub const RECORD_VARIABLE_NAME: &str = "record"; diff --git a/compiler/src/function/input/main_function_input.rs b/compiler/src/function/input/main_function_input.rs index ae142567e7..0ad5f707ad 100644 --- a/compiler/src/function/input/main_function_input.rs +++ b/compiler/src/function/input/main_function_input.rs @@ -29,7 +29,7 @@ use crate::Integer; use leo_asg::Type; use leo_ast::InputValue; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/function/input/tuple.rs b/compiler/src/function/input/tuple.rs index 31683f2053..3bb8587406 100644 --- a/compiler/src/function/input/tuple.rs +++ b/compiler/src/function/input/tuple.rs @@ -25,7 +25,7 @@ use leo_asg::Type; use leo_ast::InputValue; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index cf083034ea..86c601426d 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -27,7 +27,7 @@ use leo_asg::FunctionQualifier; use leo_ast::Input; use std::cell::Cell; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/function/mut_target.rs b/compiler/src/function/mut_target.rs index ce6cb83b82..1d7927ad2b 100644 --- a/compiler/src/function/mut_target.rs +++ b/compiler/src/function/mut_target.rs @@ -30,7 +30,7 @@ use leo_asg::Span; use leo_asg::TupleAccessExpression; use leo_asg::Variable; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 196893cf48..499af03122 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -25,9 +25,9 @@ use crate::GroupType; use leo_asg::Span; use leo_asg::Type; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index 8fb1fe9705..6e4fc29423 100644 --- a/compiler/src/output/output_bytes.rs +++ b/compiler/src/output/output_bytes.rs @@ -23,7 +23,7 @@ use leo_ast::Parameter; use leo_ast::Registers; use leo_ast::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use serde::Deserialize; use serde::Serialize; diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index 4bfd9b6b20..6a89d801f2 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -21,10 +21,10 @@ use crate::GroupType; use crate::Integer; use leo_asg::Function; use leo_asg::Span; +use snarkvm_fields::PrimeField; use snarkvm_gadgets::algorithms::prf::Blake2sGadget; -use snarkvm_gadgets::traits::uint::UInt8; -use snarkvm_gadgets::traits::ToBytesGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_gadgets::traits::utilities::uint::UInt8; +use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::gadgets::algorithms::PRFGadget; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/prelude/mod.rs b/compiler/src/prelude/mod.rs index 9b220d3120..70799088aa 100644 --- a/compiler/src/prelude/mod.rs +++ b/compiler/src/prelude/mod.rs @@ -22,7 +22,7 @@ use crate::ConstrainedValue; use crate::GroupType; use leo_asg::Function; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub trait CoreCircuit<'a, F: PrimeField, G: GroupType>: Send + Sync { diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index cec1daf7fc..329134643d 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -20,7 +20,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Program; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use indexmap::IndexMap; diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 24fde4ebf6..f738529c9f 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -25,9 +25,9 @@ use leo_asg::AssignOperation; use leo_asg::AssignStatement; use leo_asg::Span; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/assign/assignee.rs b/compiler/src/statement/assign/assignee.rs index 857025f779..598bc95d17 100644 --- a/compiler/src/statement/assign/assignee.rs +++ b/compiler/src/statement/assign/assignee.rs @@ -25,7 +25,7 @@ use leo_asg::AssignStatement; use leo_asg::Identifier; use leo_asg::Span; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; pub(crate) enum ResolvedAssigneeAccess { diff --git a/compiler/src/statement/block/block.rs b/compiler/src/statement/block/block.rs index a9c6dcf2b2..5c81c3b6d9 100644 --- a/compiler/src/statement/block/block.rs +++ b/compiler/src/statement/block/block.rs @@ -22,8 +22,8 @@ use crate::IndicatorAndConstrainedValue; use crate::StatementResult; use leo_asg::BlockStatement; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 5681db3c0f..22bfbdb7ae 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -24,8 +24,8 @@ use crate::IndicatorAndConstrainedValue; use crate::StatementResult; use leo_asg::ConditionalStatement; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; fn indicator_to_string(indicator: &Boolean) -> String { diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 17cea104bd..8199c80f8a 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -24,7 +24,7 @@ use leo_asg::DefinitionStatement; use leo_asg::Span; use leo_asg::Variable; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index 03f9deb327..c70b2690de 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -24,9 +24,9 @@ use crate::Integer; use crate::StatementResult; use leo_asg::IterationStatement; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::uint::UInt32; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::uint::UInt32; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/return_/return_.rs b/compiler/src/statement/return_/return_.rs index 8c81b50400..ae0172002d 100644 --- a/compiler/src/statement/return_/return_.rs +++ b/compiler/src/statement/return_/return_.rs @@ -22,7 +22,7 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::ReturnStatement; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 2a5d32eda9..e5eef59ec6 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -22,8 +22,8 @@ use crate::value::ConstrainedValue; use crate::GroupType; use leo_asg::Statement; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; pub type StatementResult = Result; diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 675eed12d1..84e0bcff12 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -21,15 +21,15 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::eq::EqGadget; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_gadgets::traits::uint::UInt; -use snarkvm_gadgets::traits::uint::UInt8; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::eq::EqGadget; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::uint::UInt; +use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_objects::account::AccountAddress; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index 8b21a431c7..7ab9ce591e 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -23,8 +23,8 @@ use leo_ast::InputValue; use leo_ast::Span; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index 3dc62ec3cf..6111ca27a2 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -20,16 +20,16 @@ use crate::errors::FieldError; use crate::number_string_typing; use leo_ast::Span; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::eq::EqGadget; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_gadgets::traits::uint::UInt8; -use snarkvm_gadgets::traits::ToBitsGadget; -use snarkvm_gadgets::traits::ToBytesGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::eq::EqGadget; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::uint::UInt8; +use snarkvm_gadgets::traits::utilities::ToBitsGadget; +use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::gadgets::curves::AllocatedFp; use snarkvm_models::gadgets::curves::FieldGadget; use snarkvm_models::gadgets::curves::FpGadget; diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index 0821cf69c0..299c2e1cc6 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -24,8 +24,8 @@ use crate::GroupType; use leo_ast::InputValue; use leo_ast::Span; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index 94a5a496a2..ef87679039 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -21,13 +21,13 @@ use leo_asg::GroupValue; use leo_asg::Span; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::eq::EqGadget; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_gadgets::traits::ToBitsGadget; -use snarkvm_gadgets::traits::ToBytesGadget; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::eq::EqGadget; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::ToBitsGadget; +use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::curves::One; use snarkvm_r1cs::ConstraintSystem; use std::fmt::Debug; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 287f5549da..9dc5b50689 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -26,15 +26,15 @@ use snarkvm_curves::edwards_bls12::EdwardsParameters; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::eq::EqGadget; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_gadgets::traits::uint::UInt8; -use snarkvm_gadgets::traits::ToBitsGadget; -use snarkvm_gadgets::traits::ToBytesGadget; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::eq::EqGadget; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::uint::UInt8; +use snarkvm_gadgets::traits::utilities::ToBitsGadget; +use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::curves::AffineCurve; use snarkvm_models::curves::Fp256; use snarkvm_models::curves::One; diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 1343a1e5f7..aadcad705f 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -27,14 +27,14 @@ use leo_gadgets::bits::comparator::EvaluateLtGadget; use leo_gadgets::signed_integer::*; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::eq::EqGadget; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_gadgets::traits::uint::*; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::eq::EqGadget; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::uint::*; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; use std::fmt; diff --git a/compiler/src/value/integer/macros.rs b/compiler/src/value/integer/macros.rs index 4d59bba6a7..e62ee6fcb5 100644 --- a/compiler/src/value/integer/macros.rs +++ b/compiler/src/value/integer/macros.rs @@ -16,12 +16,12 @@ use leo_gadgets::signed_integer::*; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::uint::UInt128; -use snarkvm_gadgets::traits::uint::UInt16; -use snarkvm_gadgets::traits::uint::UInt32; -use snarkvm_gadgets::traits::uint::UInt64; -use snarkvm_gadgets::traits::uint::UInt8; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::uint::UInt128; +use snarkvm_gadgets::traits::utilities::uint::UInt16; +use snarkvm_gadgets::traits::utilities::uint::UInt32; +use snarkvm_gadgets::traits::utilities::uint::UInt64; +use snarkvm_gadgets::traits::utilities::uint::UInt8; use std::fmt::Debug; pub trait IntegerTrait: Sized + Clone + Debug { diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 7effee0438..99cdbfffe8 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -26,10 +26,10 @@ use leo_asg::Identifier; use leo_asg::Span; use leo_asg::Type; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; use std::fmt; diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index 826b8ff1c6..1807cdf100 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -21,7 +21,7 @@ use leo_gadgets::Int32; use leo_gadgets::Int64; use leo_gadgets::Int8; -use snarkvm_gadgets::traits::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_models::gadgets::r1cs::Fr; use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index 08b3c097b7..d4ea613984 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -15,13 +15,13 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_gadgets::traits::uint::UInt; -use snarkvm_gadgets::traits::uint::UInt128; -use snarkvm_gadgets::traits::uint::UInt16; -use snarkvm_gadgets::traits::uint::UInt32; -use snarkvm_gadgets::traits::uint::UInt64; -use snarkvm_gadgets::traits::uint::UInt8; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::uint::UInt; +use snarkvm_gadgets::traits::utilities::uint::UInt128; +use snarkvm_gadgets::traits::utilities::uint::UInt16; +use snarkvm_gadgets::traits::utilities::uint::UInt32; +use snarkvm_gadgets::traits::utilities::uint::UInt64; +use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index 96ec6b87c7..62afbe45ea 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -17,7 +17,7 @@ use crate::bits::RippleCarryAdder; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index 0f16b68242..fdca3fe2ee 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index f223d38799..881dcd8434 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -16,13 +16,13 @@ use snarkvm_fields::Field; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_gadgets::traits::uint::UInt128; -use snarkvm_gadgets::traits::uint::UInt16; -use snarkvm_gadgets::traits::uint::UInt32; -use snarkvm_gadgets::traits::uint::UInt64; -use snarkvm_gadgets::traits::uint::UInt8; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::uint::UInt128; +use snarkvm_gadgets::traits::utilities::uint::UInt16; +use snarkvm_gadgets::traits::utilities::uint::UInt32; +use snarkvm_gadgets::traits::utilities::uint::UInt64; +use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index 594f96a033..1954ab5865 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -18,8 +18,8 @@ use crate::bits::FullAdder; use crate::signed_integer::*; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/bits/sign_extend.rs b/gadgets/src/bits/sign_extend.rs index 0e11057328..5fd6569334 100644 --- a/gadgets/src/bits/sign_extend.rs +++ b/gadgets/src/bits/sign_extend.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 snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use std::iter; diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index 51eb1a7388..541ee55f3d 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -24,11 +24,11 @@ use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::AllocatedBit; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::fp_parameters::FpParameters; -use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_models::gadgets::r1cs::LinearCombination; use snarkvm_r1cs::ConstraintSystem; diff --git a/gadgets/src/signed_integer/arithmetic/div.rs b/gadgets/src/signed_integer/arithmetic/div.rs index 13e56297e6..b0f93b21a3 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -26,12 +26,12 @@ use crate::Int16; use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::AllocatedBit; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; macro_rules! div_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index 4b20d34a28..155d235bbe 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -24,12 +24,12 @@ use crate::Int16; use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::AllocatedBit; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::select::CondSelectGadget; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_models::curves::FpParameters; -use snarkvm_models::curves::PrimeField; use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_models::gadgets::r1cs::LinearCombination; use snarkvm_r1cs::ConstraintSystem; diff --git a/gadgets/src/signed_integer/arithmetic/neg.rs b/gadgets/src/signed_integer/arithmetic/neg.rs index 2015a43966..28955cced5 100644 --- a/gadgets/src/signed_integer/arithmetic/neg.rs +++ b/gadgets/src/signed_integer/arithmetic/neg.rs @@ -18,7 +18,7 @@ use crate::arithmetic::Neg; use crate::errors::SignedIntegerError; use crate::signed_integer::*; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; macro_rules! neg_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/pow.rs b/gadgets/src/signed_integer/arithmetic/pow.rs index dc1f57cba9..7838fd7625 100644 --- a/gadgets/src/signed_integer/arithmetic/pow.rs +++ b/gadgets/src/signed_integer/arithmetic/pow.rs @@ -24,10 +24,10 @@ use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; macro_rules! pow_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/sub.rs b/gadgets/src/signed_integer/arithmetic/sub.rs index 45b669c3e0..77eebd25ca 100644 --- a/gadgets/src/signed_integer/arithmetic/sub.rs +++ b/gadgets/src/signed_integer/arithmetic/sub.rs @@ -23,7 +23,7 @@ use crate::Int16; use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; macro_rules! sub_int_impl { diff --git a/gadgets/src/signed_integer/int_impl.rs b/gadgets/src/signed_integer/int_impl.rs index 244942867b..211199871a 100644 --- a/gadgets/src/signed_integer/int_impl.rs +++ b/gadgets/src/signed_integer/int_impl.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 snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use std::fmt::Debug; diff --git a/gadgets/src/signed_integer/relational/cmp.rs b/gadgets/src/signed_integer/relational/cmp.rs index 1c8c956d62..167b729925 100644 --- a/gadgets/src/signed_integer/relational/cmp.rs +++ b/gadgets/src/signed_integer/relational/cmp.rs @@ -22,9 +22,9 @@ use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; use std::cmp::Ordering; diff --git a/gadgets/src/signed_integer/relational/eq.rs b/gadgets/src/signed_integer/relational/eq.rs index 6c8a4e8d19..d48330bdc4 100644 --- a/gadgets/src/signed_integer/relational/eq.rs +++ b/gadgets/src/signed_integer/relational/eq.rs @@ -21,9 +21,9 @@ use crate::Int32; use crate::Int64; use crate::Int8; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::EvaluateEqGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/signed_integer/utilities/alloc.rs b/gadgets/src/signed_integer/utilities/alloc.rs index 84b6670887..efc856637c 100644 --- a/gadgets/src/signed_integer/utilities/alloc.rs +++ b/gadgets/src/signed_integer/utilities/alloc.rs @@ -24,9 +24,9 @@ use crate::Int8; use core::borrow::Borrow; use core::iter; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::AllocatedBit; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/signed_integer/utilities/eq.rs b/gadgets/src/signed_integer/utilities/eq.rs index 5b311ea946..83a97a7daa 100644 --- a/gadgets/src/signed_integer/utilities/eq.rs +++ b/gadgets/src/signed_integer/utilities/eq.rs @@ -17,8 +17,8 @@ use crate::signed_integer::*; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::ConditionalEqGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/src/signed_integer/utilities/select.rs b/gadgets/src/signed_integer/utilities/select.rs index 6f0198e560..ea511f5054 100644 --- a/gadgets/src/signed_integer/utilities/select.rs +++ b/gadgets/src/signed_integer/utilities/select.rs @@ -16,11 +16,11 @@ use crate::signed_integer::*; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; -use snarkvm_gadgets::traits::eq::EqGadget; -use snarkvm_gadgets::traits::select::CondSelectGadget; -use snarkvm_models::curves::PrimeField; +use snarkvm_fields::PrimeField; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::eq::EqGadget; +use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index b3ed0cf355..f643538755 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -17,8 +17,8 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int128; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::r1cs::Fr; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index f9881c490b..89805d84ee 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -17,8 +17,8 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int16; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::r1cs::Fr; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index 34a569df5a..4fbd9bdace 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -17,8 +17,8 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int32; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::r1cs::Fr; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 594d9917da..2e083606f6 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -17,8 +17,8 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int64; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::r1cs::Fr; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index b1e76be6f9..7f513b5e59 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -17,8 +17,8 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int8; -use snarkvm_gadgets::traits::alloc::AllocGadget; -use snarkvm_gadgets::traits::boolean::Boolean; +use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; +use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::r1cs::Fr; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 0316b91ce0..d59b17db66 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use snarkvm_fields::Field; -use snarkvm_gadgets::traits::OptionalVec; +use snarkvm_gadgets::traits::utilities::OptionalVec; use snarkvm_models::curves::PairingEngine; use snarkvm_models::gadgets::r1cs::Index; use snarkvm_models::gadgets::r1cs::LinearCombination; diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 77001990af..cc8e688f48 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -20,7 +20,7 @@ use serde::Deserialize; use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_errors::curves::FieldError; -use snarkvm_gadgets::traits::OptionalVec; +use snarkvm_gadgets::traits::utilities::OptionalVec; use snarkvm_models::curves::PairingEngine; use snarkvm_models::gadgets::r1cs::Index; use snarkvm_r1cs::ConstraintSystem; From 78e8a3b4560893fc9e31deddcc457bc16e357cc7 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:42:14 -0800 Subject: [PATCH 45/92] Update curves traits --- synthesizer/src/circuit_synthesizer.rs | 2 +- synthesizer/src/serialized_circuit.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index d59b17db66..3cd19f972d 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -14,9 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use snarkvm_curves::traits::PairingEngine; use snarkvm_fields::Field; use snarkvm_gadgets::traits::utilities::OptionalVec; -use snarkvm_models::curves::PairingEngine; use snarkvm_models::gadgets::r1cs::Index; use snarkvm_models::gadgets::r1cs::LinearCombination; use snarkvm_models::gadgets::r1cs::Variable; diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index cc8e688f48..459617e837 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -19,9 +19,9 @@ use std::convert::TryFrom; use serde::Deserialize; use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; +use snarkvm_curves::traits::PairingEngine; use snarkvm_errors::curves::FieldError; use snarkvm_gadgets::traits::utilities::OptionalVec; -use snarkvm_models::curves::PairingEngine; use snarkvm_models::gadgets::r1cs::Index; use snarkvm_r1cs::ConstraintSystem; From 88e76c7fa3162c89c5c05aeefd1a4abcafd8c0c9 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:42:34 -0800 Subject: [PATCH 46/92] Adds fields dep --- Cargo.lock | 1 + synthesizer/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index f1014ea8a0..8773bb717d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1385,6 +1385,7 @@ dependencies = [ "serde", "serde_json", "snarkvm-curves", + "snarkvm-fields", ] [[package]] diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 04dcbf0845..72899f285d 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -21,6 +21,10 @@ edition = "2018" version = "0.2.0" default-features = false +[dependencies.snarkvm-fields] +version = "0.2.0" +default-features = false + [dependencies.num-bigint] version = "0.3" From 18a51cea168f57eda8738f16897ae7d4991f6b84 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:43:22 -0800 Subject: [PATCH 47/92] Adds fields dep --- Cargo.lock | 1 + gadgets/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 8773bb717d..50946b52aa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1258,6 +1258,7 @@ dependencies = [ "rand", "rand_core", "rand_xorshift", + "snarkvm-fields", "snarkvm-utilities", "thiserror", ] diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index 656e88f827..9b467cee0f 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -17,6 +17,10 @@ include = [ "Cargo.toml", "src", "README.md", "LICENSE.md" ] license = "GPL-3.0" edition = "2018" +[dependencies.snarkvm-fields] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-utilities] version = "0.2.0" From df4a2e0f4d6604b3b98677175da9eb4d96af554f Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:43:59 -0800 Subject: [PATCH 48/92] Adds r1cs dep --- Cargo.lock | 1 + gadgets/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 50946b52aa..b945bf5ca6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1259,6 +1259,7 @@ dependencies = [ "rand_core", "rand_xorshift", "snarkvm-fields", + "snarkvm-r1cs", "snarkvm-utilities", "thiserror", ] diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index 9b467cee0f..82087be70f 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -21,6 +21,10 @@ edition = "2018" version = "0.2.0" default-features = false +[dependencies.snarkvm-r1cs] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-utilities] version = "0.2.0" From 441edff36f35c61e6907c20510f0043f36c13069 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:44:36 -0800 Subject: [PATCH 49/92] Adds gadgets dep --- Cargo.lock | 1 + gadgets/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index b945bf5ca6..079b9f5d76 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1259,6 +1259,7 @@ dependencies = [ "rand_core", "rand_xorshift", "snarkvm-fields", + "snarkvm-gadgets", "snarkvm-r1cs", "snarkvm-utilities", "thiserror", diff --git a/gadgets/Cargo.toml b/gadgets/Cargo.toml index 82087be70f..5238eed768 100644 --- a/gadgets/Cargo.toml +++ b/gadgets/Cargo.toml @@ -21,6 +21,10 @@ edition = "2018" version = "0.2.0" default-features = false +[dependencies.snarkvm-gadgets] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-r1cs] version = "0.2.0" default-features = false From 24f5b168aaabf5d049e6202237ee45c80661df10 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:45:37 -0800 Subject: [PATCH 50/92] Updates r1cs traits --- compiler/src/constraints/constraints.rs | 2 +- compiler/src/value/address/address.rs | 2 +- compiler/tests/mod.rs | 2 +- gadgets/benches/integer_arithmetic.rs | 4 ++-- gadgets/src/signed_integer/arithmetic/add.rs | 4 ++-- gadgets/src/signed_integer/arithmetic/mul.rs | 4 ++-- gadgets/src/signed_integer/utilities/select.rs | 2 +- gadgets/tests/signed_integer/i128.rs | 4 ++-- gadgets/tests/signed_integer/i16.rs | 4 ++-- gadgets/tests/signed_integer/i32.rs | 4 ++-- gadgets/tests/signed_integer/i64.rs | 4 ++-- gadgets/tests/signed_integer/i8.rs | 4 ++-- synthesizer/src/circuit_synthesizer.rs | 6 +++--- synthesizer/src/serialized_circuit.rs | 2 +- synthesizer/src/serialized_index.rs | 2 +- 15 files changed, 25 insertions(+), 25 deletions(-) diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 34795a7cdf..5b02a313bb 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -27,8 +27,8 @@ use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use snarkvm_fields::PrimeField; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::TestConstraintSystem; use std::path::Path; pub fn generate_constraints<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 84e0bcff12..d3bd652887 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -30,8 +30,8 @@ use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_gadgets::traits::utilities::uint::UInt; use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_models::gadgets::r1cs::Assignment; use snarkvm_objects::account::AccountAddress; +use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; use snarkvm_utilities::ToBytes; diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 4c29394acf..1b7b3d47be 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -51,7 +51,7 @@ use leo_input::types::U32Type; use leo_input::types::UnsignedIntegerType; use snarkvm_curves::edwards_bls12::Fq; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; +use snarkvm_r1cs::TestConstraintSystem; use std::path::PathBuf; diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index 1807cdf100..f8d788daa0 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -22,9 +22,9 @@ use leo_gadgets::Int64; use leo_gadgets::Int8; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_models::gadgets::r1cs::Fr; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Fr; +use snarkvm_r1cs::TestConstraintSystem; use rand::Rng; use rand::SeedableRng; diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index 541ee55f3d..bcad949566 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -29,9 +29,9 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::fp_parameters::FpParameters; -use snarkvm_models::gadgets::r1cs::Assignment; -use snarkvm_models::gadgets::r1cs::LinearCombination; +use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::LinearCombination; macro_rules! add_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index 155d235bbe..03108f4b7f 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -30,9 +30,9 @@ use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_models::curves::FpParameters; -use snarkvm_models::gadgets::r1cs::Assignment; -use snarkvm_models::gadgets::r1cs::LinearCombination; +use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::LinearCombination; use std::iter; diff --git a/gadgets/src/signed_integer/utilities/select.rs b/gadgets/src/signed_integer/utilities/select.rs index ea511f5054..22482ee801 100644 --- a/gadgets/src/signed_integer/utilities/select.rs +++ b/gadgets/src/signed_integer/utilities/select.rs @@ -21,7 +21,7 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::EqGadget; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_models::gadgets::r1cs::Assignment; +use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index f643538755..3d15906c7b 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -21,9 +21,9 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::Fr; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Fr; +use snarkvm_r1cs::TestConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index 89805d84ee..068cc9d91d 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -21,9 +21,9 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::Fr; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Fr; +use snarkvm_r1cs::TestConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index 4fbd9bdace..436d7ddbc5 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -21,9 +21,9 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::Fr; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Fr; +use snarkvm_r1cs::TestConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 2e083606f6..87e142f676 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -21,9 +21,9 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::Fr; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Fr; +use snarkvm_r1cs::TestConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index 7f513b5e59..ccd55a0756 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -21,9 +21,9 @@ use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_models::curves::One; use snarkvm_models::curves::Zero; -use snarkvm_models::gadgets::r1cs::Fr; -use snarkvm_models::gadgets::r1cs::TestConstraintSystem; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Fr; +use snarkvm_r1cs::TestConstraintSystem; use rand::Rng; use rand_core::SeedableRng; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 3cd19f972d..b967670768 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -17,11 +17,11 @@ use snarkvm_curves::traits::PairingEngine; use snarkvm_fields::Field; use snarkvm_gadgets::traits::utilities::OptionalVec; -use snarkvm_models::gadgets::r1cs::Index; -use snarkvm_models::gadgets::r1cs::LinearCombination; -use snarkvm_models::gadgets::r1cs::Variable; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Index; +use snarkvm_r1cs::LinearCombination; use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::Variable; #[derive(Default)] pub struct Namespace { diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 459617e837..6ff18e15d1 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -22,8 +22,8 @@ use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::traits::PairingEngine; use snarkvm_errors::curves::FieldError; use snarkvm_gadgets::traits::utilities::OptionalVec; -use snarkvm_models::gadgets::r1cs::Index; use snarkvm_r1cs::ConstraintSystem; +use snarkvm_r1cs::Index; use crate::CircuitSynthesizer; use crate::SerializedField; diff --git a/synthesizer/src/serialized_index.rs b/synthesizer/src/serialized_index.rs index 8efe13d5f1..53fc644a1a 100644 --- a/synthesizer/src/serialized_index.rs +++ b/synthesizer/src/serialized_index.rs @@ -16,7 +16,7 @@ use serde::Deserialize; use serde::Serialize; -use snarkvm_models::gadgets::r1cs::Index; +use snarkvm_r1cs::Index; #[derive(Serialize, Deserialize)] pub enum SerializedIndex { From f65ad893603ec021a08674e9092b96053d1b7125 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:46:19 -0800 Subject: [PATCH 51/92] Update algo errors --- state/src/errors/local_data_commitment.rs | 4 ++-- state/src/errors/record_commitment.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/state/src/errors/local_data_commitment.rs b/state/src/errors/local_data_commitment.rs index 7d110f6ab7..d5fb0c5ee8 100644 --- a/state/src/errors/local_data_commitment.rs +++ b/state/src/errors/local_data_commitment.rs @@ -18,8 +18,8 @@ use crate::RecordVerificationError; use crate::StateLeafValuesError; use crate::StateValuesError; -use snarkvm_errors::algorithms::CommitmentError; -use snarkvm_errors::algorithms::MerkleError; +use snarkvm_algorithms::CommitmentError; +use snarkvm_algorithms::MerkleError; use std::io::Error as IOError; diff --git a/state/src/errors/record_commitment.rs b/state/src/errors/record_commitment.rs index a0205248ab..507c5bb48f 100644 --- a/state/src/errors/record_commitment.rs +++ b/state/src/errors/record_commitment.rs @@ -16,7 +16,7 @@ use crate::DPCRecordValuesError; -use snarkvm_errors::algorithms::CommitmentError; +use snarkvm_algorithms::CommitmentError; use std::io::Error as IOError; From 3421e891b6e2abf2802a262acfb242c4f49261b4 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:46:47 -0800 Subject: [PATCH 52/92] Adds r1cs dep --- Cargo.lock | 1 + synthesizer/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 079b9f5d76..267f19f1db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1389,6 +1389,7 @@ dependencies = [ "serde_json", "snarkvm-curves", "snarkvm-fields", + "snarkvm-r1cs", ] [[package]] diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 72899f285d..687398112e 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -25,6 +25,10 @@ default-features = false version = "0.2.0" default-features = false +[dependencies.snarkvm-r1cs] +version = "0.2.0" +default-features = false + [dependencies.num-bigint] version = "0.3" From ff4412d7d0c7bc921c2c235ceb02c41d2de9056b Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:47:32 -0800 Subject: [PATCH 53/92] Update curves errors --- synthesizer/src/serialized_circuit.rs | 2 +- synthesizer/src/serialized_field.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 6ff18e15d1..279556cba0 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -20,7 +20,7 @@ use serde::Deserialize; use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::traits::PairingEngine; -use snarkvm_errors::curves::FieldError; +use snarkvm_curves::FieldError; use snarkvm_gadgets::traits::utilities::OptionalVec; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Index; diff --git a/synthesizer/src/serialized_field.rs b/synthesizer/src/serialized_field.rs index 3788f78c26..0a43d37589 100644 --- a/synthesizer/src/serialized_field.rs +++ b/synthesizer/src/serialized_field.rs @@ -20,7 +20,7 @@ use std::str::FromStr; use num_bigint::BigUint; use serde::Deserialize; use serde::Serialize; -use snarkvm_errors::curves::FieldError; +use snarkvm_curves::FieldError; use snarkvm_fields::Field; use snarkvm_models::curves::Fp256; use snarkvm_models::curves::Fp256Parameters; From 187f738811cf27b9790a55ed0857462ef5e0ad59 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:48:01 -0800 Subject: [PATCH 54/92] Update fields errors --- synthesizer/src/serialized_circuit.rs | 2 +- synthesizer/src/serialized_field.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 279556cba0..08d3c40679 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -20,7 +20,7 @@ use serde::Deserialize; use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::traits::PairingEngine; -use snarkvm_curves::FieldError; +use snarkvm_fields::FieldError; use snarkvm_gadgets::traits::utilities::OptionalVec; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Index; diff --git a/synthesizer/src/serialized_field.rs b/synthesizer/src/serialized_field.rs index 0a43d37589..c0f020ca38 100644 --- a/synthesizer/src/serialized_field.rs +++ b/synthesizer/src/serialized_field.rs @@ -20,8 +20,8 @@ use std::str::FromStr; use num_bigint::BigUint; use serde::Deserialize; use serde::Serialize; -use snarkvm_curves::FieldError; use snarkvm_fields::Field; +use snarkvm_fields::FieldError; use snarkvm_models::curves::Fp256; use snarkvm_models::curves::Fp256Parameters; From d8e9edc941b596e1edd4fd97ea4a4bbfec7d2709 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:48:28 -0800 Subject: [PATCH 55/92] Update fields structs --- compiler/src/value/group/targets/edwards_bls12.rs | 2 +- gadgets/src/signed_integer/arithmetic/mul.rs | 2 +- synthesizer/src/serialized_field.rs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 9dc5b50689..5bb10df513 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -25,6 +25,7 @@ use snarkvm_curves::edwards_bls12::EdwardsAffine; use snarkvm_curves::edwards_bls12::EdwardsParameters; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; +use snarkvm_fields::Fp256; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; @@ -36,7 +37,6 @@ use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_gadgets::traits::utilities::ToBitsGadget; use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::curves::AffineCurve; -use snarkvm_models::curves::Fp256; use snarkvm_models::curves::One; use snarkvm_models::curves::TEModelParameters; use snarkvm_models::curves::Zero; diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index 03108f4b7f..4e0d3568a4 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -24,12 +24,12 @@ use crate::Int16; use crate::Int32; use crate::Int64; use crate::Int8; +use snarkvm_fields::FpParameters; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_models::curves::FpParameters; use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::LinearCombination; diff --git a/synthesizer/src/serialized_field.rs b/synthesizer/src/serialized_field.rs index c0f020ca38..504daa8403 100644 --- a/synthesizer/src/serialized_field.rs +++ b/synthesizer/src/serialized_field.rs @@ -22,8 +22,8 @@ use serde::Deserialize; use serde::Serialize; use snarkvm_fields::Field; use snarkvm_fields::FieldError; -use snarkvm_models::curves::Fp256; -use snarkvm_models::curves::Fp256Parameters; +use snarkvm_fields::Fp256; +use snarkvm_fields::Fp256Parameters; #[derive(Serialize, Deserialize)] pub struct SerializedField(pub String); From 4fec97083d73b3349683d3281e798433bbde0388 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:48:48 -0800 Subject: [PATCH 56/92] Adds gadgets dep --- Cargo.lock | 1 + synthesizer/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 267f19f1db..84a477cfbd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1389,6 +1389,7 @@ dependencies = [ "serde_json", "snarkvm-curves", "snarkvm-fields", + "snarkvm-gadgets", "snarkvm-r1cs", ] diff --git a/synthesizer/Cargo.toml b/synthesizer/Cargo.toml index 687398112e..6524788cfd 100644 --- a/synthesizer/Cargo.toml +++ b/synthesizer/Cargo.toml @@ -25,6 +25,10 @@ default-features = false version = "0.2.0" default-features = false +[dependencies.snarkvm-gadgets] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-r1cs] version = "0.2.0" default-features = false From 4e9576e58ddea41540d23d02c6e647e5134bdc27 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:49:47 -0800 Subject: [PATCH 57/92] Fix object errors --- compiler/src/errors/value/address.rs | 2 +- state/src/errors/dpc_record_values.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index f9f2b48646..b95c3da3ce 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -17,7 +17,7 @@ use leo_ast::Error as FormattedError; use leo_ast::Span; -use snarkvm_errors::objects::account::AccountError; +use snarkos_objects::errors::AccountError; use snarkvm_r1cs::SynthesisError; use std::path::Path; diff --git a/state/src/errors/dpc_record_values.rs b/state/src/errors/dpc_record_values.rs index 13aec54ee3..94f4340f14 100644 --- a/state/src/errors/dpc_record_values.rs +++ b/state/src/errors/dpc_record_values.rs @@ -16,7 +16,7 @@ use crate::InputValueError; -use snarkvm_errors::objects::account::AccountError; +use snarkos_objects::errors::AccountError; use std::num::ParseIntError; use std::str::ParseBoolError; From 1411107d2309f51f0f1fa36185b5da12bb025a14 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:50:26 -0800 Subject: [PATCH 58/92] Update fields traits --- gadgets/src/signed_integer/arithmetic/add.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index bcad949566..af2020c3ed 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -24,11 +24,11 @@ use crate::Int32; use crate::Int64; use crate::Int8; +use snarkvm_fields::fp_parameters::FpParameters; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_models::curves::fp_parameters::FpParameters; use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::LinearCombination; From 7b7c1bbef40f83ab7f0d376ada25f47cd41cb4b0 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:51:59 -0800 Subject: [PATCH 59/92] Remove object dept --- Cargo.lock | 1 - compiler/src/value/address/address.rs | 2 +- state/Cargo.toml | 4 ---- state/src/record_commitment/dpc_record_values.rs | 2 +- state/tests/test_verify_local_data_commitment.rs | 2 +- 5 files changed, 3 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84a477cfbd..777a712d04 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1374,7 +1374,6 @@ dependencies = [ "snarkvm-algorithms", "snarkvm-curves", "snarkvm-dpc", - "snarkvm-objects", "snarkvm-storage", "snarkvm-utilities", "thiserror", diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index d3bd652887..8dc60b3007 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -20,6 +20,7 @@ use crate::GroupType; use leo_ast::InputValue; use leo_ast::Span; +use snarkvm_dpc::account::AccountAddress; use snarkvm_dpc::base_dpc::instantiated::Components; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; @@ -30,7 +31,6 @@ use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_gadgets::traits::utilities::uint::UInt; use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_objects::account::AccountAddress; use snarkvm_r1cs::Assignment; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/state/Cargo.toml b/state/Cargo.toml index e162c8a004..8e7d0573cf 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -37,10 +37,6 @@ default-features = false version = "0.2.0" default-features = false -[dependencies.snarkvm-objects] -version = "0.2.0" -default-features = false - [dependencies.snarkvm-utilities] version = "0.2.0" diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index ee237135ef..ca217a11b3 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -19,7 +19,7 @@ use crate::DPCRecordValuesError; use leo_ast::Record as AstRecord; use snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_objects::AccountAddress; +use snarkvm_dpc::AccountAddress; use std::convert::TryFrom; use std::str::FromStr; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 6c2d19bcf5..ee52e8e0db 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -23,9 +23,9 @@ use snarkvm_algorithms::traits::CRH; use snarkvm_dpc::base_dpc::instantiated::*; use snarkvm_dpc::base_dpc::record_payload::RecordPayload; use snarkvm_dpc::base_dpc::DPC; +use snarkvm_dpc::Account; use snarkvm_models::dpc::Record; use snarkvm_models::objects::AccountScheme; -use snarkvm_objects::Account; use snarkvm_utilities::bytes::ToBytes; use snarkvm_utilities::to_bytes; From 1b0a6dbd699d372a27a7503df9d01307a4fae19c Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:52:54 -0800 Subject: [PATCH 60/92] Update fields traits --- compiler/src/value/group/targets/edwards_bls12.rs | 4 ++-- gadgets/tests/signed_integer/i128.rs | 4 ++-- gadgets/tests/signed_integer/i16.rs | 4 ++-- gadgets/tests/signed_integer/i32.rs | 4 ++-- gadgets/tests/signed_integer/i64.rs | 4 ++-- gadgets/tests/signed_integer/i8.rs | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 5bb10df513..2c97a3210c 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -26,6 +26,8 @@ use snarkvm_curves::edwards_bls12::EdwardsParameters; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; use snarkvm_fields::Fp256; +use snarkvm_fields::One; +use snarkvm_fields::Zero; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; @@ -37,9 +39,7 @@ use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_gadgets::traits::utilities::ToBitsGadget; use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::curves::AffineCurve; -use snarkvm_models::curves::One; use snarkvm_models::curves::TEModelParameters; -use snarkvm_models::curves::Zero; use snarkvm_models::gadgets::curves::AllocatedFp; use snarkvm_models::gadgets::curves::FieldGadget; use snarkvm_models::gadgets::curves::FpGadget; diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index 3d15906c7b..7c0d38a67f 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -17,10 +17,10 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int128; +use snarkvm_fields::One; +use snarkvm_fields::Zero; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_models::curves::One; -use snarkvm_models::curves::Zero; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Fr; use snarkvm_r1cs::TestConstraintSystem; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index 068cc9d91d..dc6eaee2fb 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -17,10 +17,10 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int16; +use snarkvm_fields::One; +use snarkvm_fields::Zero; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_models::curves::One; -use snarkvm_models::curves::Zero; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Fr; use snarkvm_r1cs::TestConstraintSystem; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index 436d7ddbc5..9170aa98d0 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -17,10 +17,10 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int32; +use snarkvm_fields::One; +use snarkvm_fields::Zero; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_models::curves::One; -use snarkvm_models::curves::Zero; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Fr; use snarkvm_r1cs::TestConstraintSystem; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 87e142f676..030cac373c 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -17,10 +17,10 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int64; +use snarkvm_fields::One; +use snarkvm_fields::Zero; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_models::curves::One; -use snarkvm_models::curves::Zero; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Fr; use snarkvm_r1cs::TestConstraintSystem; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index ccd55a0756..9a3aad4340 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -17,10 +17,10 @@ use leo_gadgets::arithmetic::*; use leo_gadgets::Int8; +use snarkvm_fields::One; +use snarkvm_fields::Zero; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_models::curves::One; -use snarkvm_models::curves::Zero; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Fr; use snarkvm_r1cs::TestConstraintSystem; From 4692a2b20ee1b1a0b152fb852169e4f70440faba Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:53:48 -0800 Subject: [PATCH 61/92] Update object errors --- compiler/src/errors/value/address.rs | 2 +- compiler/src/value/group/group_type.rs | 2 +- state/src/errors/dpc_record_values.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index b95c3da3ce..4cd9889c8f 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -17,7 +17,7 @@ use leo_ast::Error as FormattedError; use leo_ast::Span; -use snarkos_objects::errors::AccountError; +use snarkvm_dpc::AccountError; use snarkvm_r1cs::SynthesisError; use std::path::Path; diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index ef87679039..eb7969546e 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -21,6 +21,7 @@ use leo_asg::GroupValue; use leo_asg::Span; use snarkvm_fields::Field; +use snarkvm_fields::One; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; use snarkvm_gadgets::traits::utilities::eq::EqGadget; @@ -28,7 +29,6 @@ use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_gadgets::traits::utilities::ToBitsGadget; use snarkvm_gadgets::traits::utilities::ToBytesGadget; -use snarkvm_models::curves::One; use snarkvm_r1cs::ConstraintSystem; use std::fmt::Debug; use std::fmt::Display; diff --git a/state/src/errors/dpc_record_values.rs b/state/src/errors/dpc_record_values.rs index 94f4340f14..0f97cf7f91 100644 --- a/state/src/errors/dpc_record_values.rs +++ b/state/src/errors/dpc_record_values.rs @@ -16,7 +16,7 @@ use crate::InputValueError; -use snarkos_objects::errors::AccountError; +use snarkvm_dpc::AccountError; use std::num::ParseIntError; use std::str::ParseBoolError; From b029469ecae7cc441236ee89d9511d228579c611 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:54:21 -0800 Subject: [PATCH 62/92] Remove objects dep --- Cargo.lock | 1 - compiler/Cargo.toml | 4 ---- 2 files changed, 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 777a712d04..135b248d93 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1244,7 +1244,6 @@ dependencies = [ "snarkvm-curves", "snarkvm-dpc", "snarkvm-gadgets", - "snarkvm-objects", "snarkvm-utilities", "thiserror", "tracing", diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 513038078e..dfc9139c6f 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -61,10 +61,6 @@ default-features = false version = "0.2.0" default-features = false -[dependencies.snarkvm-objects] -version = "0.2.0" -default-features = false - [dependencies.snarkvm-utilities] version = "0.2.0" From e11ef69f7488b6957b51fcec99b15161f9e5f4d7 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:54:37 -0800 Subject: [PATCH 63/92] Add fields dep --- Cargo.lock | 1 + compiler/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 135b248d93..c41466d0cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1243,6 +1243,7 @@ dependencies = [ "snarkvm-algorithms", "snarkvm-curves", "snarkvm-dpc", + "snarkvm-fields", "snarkvm-gadgets", "snarkvm-utilities", "thiserror", diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index dfc9139c6f..3eb9458381 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -53,6 +53,10 @@ version = "1.2.3" version = "0.2.0" default-features = false +[dependencies.snarkvm-fields] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-dpc] version = "0.2.0" default-features = false From dadc57a148e145f7bbe4cd17383cd440b33e84fe Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:55:22 -0800 Subject: [PATCH 64/92] Add r1cs dep --- Cargo.lock | 1 + compiler/Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index c41466d0cb..708fdf7dd4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1245,6 +1245,7 @@ dependencies = [ "snarkvm-dpc", "snarkvm-fields", "snarkvm-gadgets", + "snarkvm-r1cs", "snarkvm-utilities", "thiserror", "tracing", diff --git a/compiler/Cargo.toml b/compiler/Cargo.toml index 3eb9458381..9f44f8b213 100644 --- a/compiler/Cargo.toml +++ b/compiler/Cargo.toml @@ -65,6 +65,10 @@ default-features = false version = "0.2.0" default-features = false +[dependencies.snarkvm-r1cs] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-utilities] version = "0.2.0" From 1c5ac21e9c4176e7e51847e4d77bbe88c89f5265 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:56:03 -0800 Subject: [PATCH 65/92] Update dpc structs --- state/tests/test_verify_local_data_commitment.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index ee52e8e0db..8b088a0950 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -24,7 +24,7 @@ use snarkvm_dpc::base_dpc::instantiated::*; use snarkvm_dpc::base_dpc::record_payload::RecordPayload; use snarkvm_dpc::base_dpc::DPC; use snarkvm_dpc::Account; -use snarkvm_models::dpc::Record; +use snarkvm_dpc::Record; use snarkvm_models::objects::AccountScheme; use snarkvm_utilities::bytes::ToBytes; use snarkvm_utilities::to_bytes; @@ -32,7 +32,7 @@ use snarkvm_utilities::to_bytes; use rand::Rng; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; -use snarkvm_models::dpc::DPCScheme; +use snarkvm_dpc::DPCScheme; use snarkvm_storage::Ledger; // TODO (Collin): Update input to reflect new parameter ordering. From bf43da5a84ed21a9162a680c6c73d7363bcfeaec Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:56:36 -0800 Subject: [PATCH 66/92] Update dpc structs --- state/tests/test_verify_local_data_commitment.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 8b088a0950..147650ffde 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -24,8 +24,8 @@ use snarkvm_dpc::base_dpc::instantiated::*; use snarkvm_dpc::base_dpc::record_payload::RecordPayload; use snarkvm_dpc::base_dpc::DPC; use snarkvm_dpc::Account; +use snarkvm_dpc::AccountScheme; use snarkvm_dpc::Record; -use snarkvm_models::objects::AccountScheme; use snarkvm_utilities::bytes::ToBytes; use snarkvm_utilities::to_bytes; From c03e1045f2c560dbfa3b03c9e0d6e5e0e181cd6f Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:57:20 -0800 Subject: [PATCH 67/92] Update gadgets traits --- compiler/src/prelude/blake2s.rs | 2 +- compiler/src/value/field/field_type.rs | 6 +++--- compiler/src/value/group/targets/edwards_bls12.rs | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index 6a89d801f2..0ed7ff9945 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -23,9 +23,9 @@ use leo_asg::Function; use leo_asg::Span; use snarkvm_fields::PrimeField; use snarkvm_gadgets::algorithms::prf::Blake2sGadget; +use snarkvm_gadgets::algorithms::PRFGadget; use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_gadgets::traits::utilities::ToBytesGadget; -use snarkvm_models::gadgets::algorithms::PRFGadget; use snarkvm_r1cs::ConstraintSystem; pub struct Blake2s; diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index 6111ca27a2..3423ba1634 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -21,6 +21,9 @@ use crate::number_string_typing; use leo_ast::Span; use snarkvm_fields::PrimeField; +use snarkvm_gadgets::curves::AllocatedFp; +use snarkvm_gadgets::curves::FieldGadget; +use snarkvm_gadgets::curves::FpGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; @@ -30,9 +33,6 @@ use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_gadgets::traits::utilities::ToBitsGadget; use snarkvm_gadgets::traits::utilities::ToBytesGadget; -use snarkvm_models::gadgets::curves::AllocatedFp; -use snarkvm_models::gadgets::curves::FieldGadget; -use snarkvm_models::gadgets::curves::FpGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 2c97a3210c..8a93a6db2b 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -29,6 +29,10 @@ use snarkvm_fields::Fp256; use snarkvm_fields::One; use snarkvm_fields::Zero; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; +use snarkvm_gadgets::curves::AllocatedFp; +use snarkvm_gadgets::curves::FieldGadget; +use snarkvm_gadgets::curves::FpGadget; +use snarkvm_gadgets::curves::GroupGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; @@ -40,10 +44,6 @@ use snarkvm_gadgets::traits::utilities::ToBitsGadget; use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_models::curves::AffineCurve; use snarkvm_models::curves::TEModelParameters; -use snarkvm_models::gadgets::curves::AllocatedFp; -use snarkvm_models::gadgets::curves::FieldGadget; -use snarkvm_models::gadgets::curves::FpGadget; -use snarkvm_models::gadgets::curves::GroupGadget; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; use std::borrow::Borrow; From 8690e35e955e0b3325f97c263b510053d93097c5 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:58:50 -0800 Subject: [PATCH 68/92] Update field structs --- compiler/src/value/field/field_type.rs | 6 +++--- compiler/src/value/group/targets/edwards_bls12.rs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index 3423ba1634..576515c3c6 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -21,9 +21,9 @@ use crate::number_string_typing; use leo_ast::Span; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::curves::AllocatedFp; -use snarkvm_gadgets::curves::FieldGadget; -use snarkvm_gadgets::curves::FpGadget; +use snarkvm_gadgets::fields::AllocatedFp; +use snarkvm_gadgets::fields::FieldGadget; +use snarkvm_gadgets::fields::FpGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 8a93a6db2b..a58740ab09 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -29,10 +29,10 @@ use snarkvm_fields::Fp256; use snarkvm_fields::One; use snarkvm_fields::Zero; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; -use snarkvm_gadgets::curves::AllocatedFp; -use snarkvm_gadgets::curves::FieldGadget; -use snarkvm_gadgets::curves::FpGadget; use snarkvm_gadgets::curves::GroupGadget; +use snarkvm_gadgets::fields::AllocatedFp; +use snarkvm_gadgets::fields::FieldGadget; +use snarkvm_gadgets::fields::FpGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; From 3bdf598431e582c104eec180d860bb7e0ab554ff Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 10:59:43 -0800 Subject: [PATCH 69/92] Update field and curves traits --- compiler/src/value/field/field_type.rs | 2 +- compiler/src/value/group/targets/edwards_bls12.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index 576515c3c6..a03e6e1bc4 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -22,8 +22,8 @@ use leo_ast::Span; use snarkvm_fields::PrimeField; use snarkvm_gadgets::fields::AllocatedFp; -use snarkvm_gadgets::fields::FieldGadget; use snarkvm_gadgets::fields::FpGadget; +use snarkvm_gadgets::traits::fields::FieldGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index a58740ab09..34d58ebb0c 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -29,10 +29,10 @@ use snarkvm_fields::Fp256; use snarkvm_fields::One; use snarkvm_fields::Zero; use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; -use snarkvm_gadgets::curves::GroupGadget; use snarkvm_gadgets::fields::AllocatedFp; -use snarkvm_gadgets::fields::FieldGadget; use snarkvm_gadgets::fields::FpGadget; +use snarkvm_gadgets::traits::curves::GroupGadget; +use snarkvm_gadgets::traits::fields::FieldGadget; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; use snarkvm_gadgets::traits::utilities::boolean::Boolean; use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; From 4650b5cd804a20db1b34332288a5e23a98aae0dc Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 11:01:00 -0800 Subject: [PATCH 70/92] Update gadget traits --- compiler/src/prelude/blake2s.rs | 2 +- synthesizer/src/circuit_synthesizer.rs | 2 +- synthesizer/src/serialized_circuit.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index 0ed7ff9945..ab21175a87 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -23,7 +23,7 @@ use leo_asg::Function; use leo_asg::Span; use snarkvm_fields::PrimeField; use snarkvm_gadgets::algorithms::prf::Blake2sGadget; -use snarkvm_gadgets::algorithms::PRFGadget; +use snarkvm_gadgets::traits::algorithms::PRFGadget; use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_gadgets::traits::utilities::ToBytesGadget; use snarkvm_r1cs::ConstraintSystem; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index b967670768..014a4401dd 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -16,10 +16,10 @@ use snarkvm_curves::traits::PairingEngine; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::utilities::OptionalVec; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Index; use snarkvm_r1cs::LinearCombination; +use snarkvm_r1cs::OptionalVec; use snarkvm_r1cs::SynthesisError; use snarkvm_r1cs::Variable; diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index 08d3c40679..ef09a9cce1 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -21,9 +21,9 @@ use serde::Serialize; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::traits::PairingEngine; use snarkvm_fields::FieldError; -use snarkvm_gadgets::traits::utilities::OptionalVec; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::Index; +use snarkvm_r1cs::OptionalVec; use crate::CircuitSynthesizer; use crate::SerializedField; From 1735038dee137c8f06d0ef1428ae171e3705b25c Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 11:02:31 -0800 Subject: [PATCH 71/92] Update algorithms, curves, and gadget traits --- compiler/src/value/group/targets/edwards_bls12.rs | 4 ++-- compiler/tests/core/packages/unstable/blake2s/mod.rs | 2 +- leo/commands/prove.rs | 2 +- leo/commands/run.rs | 2 +- leo/commands/setup.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 34d58ebb0c..66cc727cef 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -25,6 +25,8 @@ use snarkvm_curves::edwards_bls12::EdwardsAffine; use snarkvm_curves::edwards_bls12::EdwardsParameters; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; +use snarkvm_curves::AffineCurve; +use snarkvm_curves::TEModelParameters; use snarkvm_fields::Fp256; use snarkvm_fields::One; use snarkvm_fields::Zero; @@ -42,8 +44,6 @@ use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; use snarkvm_gadgets::traits::utilities::uint::UInt8; use snarkvm_gadgets::traits::utilities::ToBitsGadget; use snarkvm_gadgets::traits::utilities::ToBytesGadget; -use snarkvm_models::curves::AffineCurve; -use snarkvm_models::curves::TEModelParameters; use snarkvm_r1cs::ConstraintSystem; use snarkvm_r1cs::SynthesisError; use std::borrow::Borrow; diff --git a/compiler/tests/core/packages/unstable/blake2s/mod.rs b/compiler/tests/core/packages/unstable/blake2s/mod.rs index 94ce6b08ef..63e044a514 100644 --- a/compiler/tests/core/packages/unstable/blake2s/mod.rs +++ b/compiler/tests/core/packages/unstable/blake2s/mod.rs @@ -29,7 +29,7 @@ use rand::Rng; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; use snarkvm_algorithms::prf::blake2s::Blake2s as B2SPRF; -use snarkvm_models::algorithms::PRF; +use snarkvm_algorithms::traits::PRF; #[test] fn test_arguments_length_fail() { diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index dd2b4eae20..3072841b99 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -21,9 +21,9 @@ use leo_package::outputs::ProofFile; use snarkvm_algorithms::snark::groth16::Groth16; use snarkvm_algorithms::snark::groth16::PreparedVerifyingKey; use snarkvm_algorithms::snark::groth16::Proof; +use snarkvm_algorithms::traits::SNARK; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::bls12_377::Fr; -use snarkvm_models::algorithms::SNARK; use snarkvm_utilities::bytes::ToBytes; use anyhow::Result; diff --git a/leo/commands/run.rs b/leo/commands/run.rs index dbcda803ef..16e3f7f433 100644 --- a/leo/commands/run.rs +++ b/leo/commands/run.rs @@ -22,9 +22,9 @@ use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; use anyhow::Result; use snarkvm_algorithms::snark::groth16::Groth16; +use snarkvm_algorithms::traits::SNARK; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::bls12_377::Fr; -use snarkvm_models::algorithms::SNARK; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 06489768fc..c152033b43 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -31,9 +31,9 @@ use snarkvm_algorithms::snark::groth16::Groth16; use snarkvm_algorithms::snark::groth16::Parameters; use snarkvm_algorithms::snark::groth16::PreparedVerifyingKey; use snarkvm_algorithms::snark::groth16::VerifyingKey; +use snarkvm_algorithms::traits::snark::SNARK; use snarkvm_curves::bls12_377::Bls12_377; use snarkvm_curves::bls12_377::Fr; -use snarkvm_models::algorithms::snark::SNARK; use structopt::StructOpt; use tracing::span::Span; From 689dbad8fe0153e6735c219181eb7ecff6f04749 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 11:03:19 -0800 Subject: [PATCH 72/92] Adds r1cs dep --- Cargo.lock | 1 + Cargo.toml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 708fdf7dd4..881ab30a24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1336,6 +1336,7 @@ dependencies = [ "snarkvm-algorithms", "snarkvm-curves", "snarkvm-gadgets", + "snarkvm-r1cs", "snarkvm-utilities", "structopt", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index d222296ea9..1287459f14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -83,6 +83,10 @@ default-features = false version = "0.2.0" default-features = false +[dependencies.snarkvm-r1cs] +version = "0.2.0" +default-features = false + [dependencies.snarkvm-utilities] version = "0.2.0" From 869b6ddb336bd0adee6c0d9005256e01744aae96 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 4 Mar 2021 11:03:25 -0800 Subject: [PATCH 73/92] update tinytemplate --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc53565464..abd07dc676 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2858,9 +2858,9 @@ dependencies = [ [[package]] name = "tinytemplate" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ada8616fad06a2d0c455adc530de4ef57605a8120cc65da9653e0e9623ca74" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" dependencies = [ "serde", "serde_json", From 2e7b542b8b24dd3baa28e64e5c6e6e43a9829053 Mon Sep 17 00:00:00 2001 From: howardwu Date: Thu, 4 Mar 2021 11:09:24 -0800 Subject: [PATCH 74/92] Format and clean up, enable default on snarkvm_algorithms --- .rustfmt.toml | 2 +- .rusty-hook.toml | 2 +- Cargo.toml | 2 +- asg/src/checks/return_path.rs | 18 +++-- asg/src/const_value.rs | 8 +- asg/src/context.rs | 3 +- asg/src/error/mod.rs | 3 +- asg/src/expression/array_access.rs | 11 +-- asg/src/expression/array_init.rs | 11 +-- asg/src/expression/array_inline.rs | 11 +-- asg/src/expression/array_range_access.rs | 11 +-- asg/src/expression/binary.rs | 14 +--- asg/src/expression/call.rs | 31 ++++---- asg/src/expression/circuit_access.rs | 28 +++---- asg/src/expression/circuit_init.rs | 31 ++++---- asg/src/expression/constant.rs | 26 ++++--- asg/src/expression/mod.rs | 9 +-- asg/src/expression/ternary.rs | 11 +-- asg/src/expression/tuple_access.rs | 11 +-- asg/src/expression/tuple_init.rs | 11 +-- asg/src/expression/unary.rs | 11 +-- asg/src/expression/variable_ref.rs | 30 ++++---- asg/src/import.rs | 5 +- asg/src/input.rs | 7 +- asg/src/lib.rs | 4 +- asg/src/node.rs | 22 +++--- asg/src/prelude.rs | 4 +- asg/src/program/circuit.rs | 8 +- asg/src/program/function.rs | 29 ++++---- asg/src/program/mod.rs | 15 +--- asg/src/reducer/monoidal_director.rs | 4 +- asg/src/reducer/monoidal_reducer.rs | 5 +- asg/src/reducer/visitor.rs | 4 +- asg/src/reducer/visitor_director.rs | 7 +- asg/src/scope.rs | 14 +--- asg/src/statement/assign.rs | 34 +++++---- asg/src/statement/block.rs | 8 +- asg/src/statement/conditional.rs | 11 +-- asg/src/statement/console.rs | 10 +-- asg/src/statement/definition.rs | 32 ++++---- asg/src/statement/expression.rs | 9 +-- asg/src/statement/iteration.rs | 27 +++---- asg/src/statement/mod.rs | 7 +- asg/src/statement/return_.rs | 10 +-- asg/src/variable.rs | 4 +- asg/tests/pass/form_ast.rs | 3 +- asg/tests/pass/import/mod.rs | 5 +- ast/benches/leo_ast.rs | 7 +- ast/src/annotation.rs | 17 ++--- ast/src/circuits/circuit.rs | 6 +- .../circuit_implied_variable_definition.rs | 6 +- ast/src/circuits/circuit_member.rs | 14 ++-- .../circuits/circuit_variable_definition.rs | 6 +- ast/src/common/array_dimensions.rs | 3 +- ast/src/common/identifier.rs | 54 ++++++++------ ast/src/common/input_keyword.rs | 6 +- ast/src/common/mut_self_keyword.rs | 6 +- ast/src/common/positive_number.rs | 3 +- ast/src/common/self_keyword.rs | 6 +- ast/src/common/span.rs | 6 +- ast/src/common/spread_or_expression.rs | 13 ++-- ast/src/errors/deprecated.rs | 9 +-- ast/src/errors/error.rs | 3 +- ast/src/expression/mod.rs | 73 +++++++++--------- ast/src/functions/function.rs | 10 +-- ast/src/functions/input/function_input.rs | 8 +- ast/src/functions/input/input_variable.rs | 10 +-- ast/src/functions/test_function.rs | 6 +- ast/src/groups/group_coordinate.rs | 27 ++++--- ast/src/groups/group_value.rs | 22 +++--- ast/src/imports/import.rs | 6 +- ast/src/imports/import_symbol.rs | 6 +- ast/src/imports/package.rs | 7 +- ast/src/imports/package_access.rs | 8 +- ast/src/imports/package_or_packages.rs | 6 +- ast/src/imports/packages.rs | 7 +- ast/src/input/input.rs | 16 ++-- ast/src/input/input_value.rs | 26 ++----- ast/src/input/parameters/parameter.rs | 4 +- ast/src/input/program_input/main_input.rs | 3 +- ast/src/input/program_input/program_input.rs | 11 ++- ast/src/input/program_input/registers.rs | 6 +- .../private_state/private_state.rs | 10 +-- .../program_state/private_state/record.rs | 6 +- .../program_state/private_state/state_leaf.rs | 6 +- ast/src/input/program_state/program_state.rs | 13 ++-- .../public_state/public_state.rs | 7 +- .../input/program_state/public_state/state.rs | 6 +- ast/src/main.rs | 7 +- ast/src/program.rs | 24 +++--- ast/src/statements/assign/assignee.rs | 17 ++--- ast/src/statements/assign/mod.rs | 7 +- ast/src/statements/block.rs | 7 +- ast/src/statements/conditional.rs | 12 +-- .../statements/console/console_function.rs | 18 ++--- .../statements/console/console_statement.rs | 7 +- .../statements/console/formatted_container.rs | 6 +- .../statements/console/formatted_string.rs | 8 +- ast/src/statements/definition/declare.rs | 3 +- ast/src/statements/definition/mod.rs | 8 +- .../statements/definition/variable_name.rs | 7 +- ast/src/statements/expression.rs | 7 +- ast/src/statements/iteration.rs | 9 +-- ast/src/statements/return_statement.rs | 7 +- ast/src/statements/statement.rs | 7 +- ast/src/types/integer_type.rs | 19 +++-- ast/src/types/type_.rs | 23 +++--- ast/tests/serialization/json.rs | 9 +-- compiler/src/compiler.rs | 41 +++++----- compiler/src/console/assert.rs | 15 ++-- compiler/src/console/console.rs | 8 +- compiler/src/console/format.rs | 4 +- compiler/src/constraints/constraints.rs | 9 +-- compiler/src/definition/definition.rs | 4 +- compiler/src/errors/compiler.rs | 8 +- compiler/src/errors/console.rs | 3 +- compiler/src/errors/expression.rs | 14 +--- compiler/src/errors/function.rs | 23 +++--- compiler/src/errors/import.rs | 5 +- compiler/src/errors/output_bytes.rs | 6 +- compiler/src/errors/output_file.rs | 3 +- compiler/src/errors/statement.rs | 10 +-- compiler/src/errors/value/address.rs | 3 +- compiler/src/errors/value/boolean.rs | 3 +- compiler/src/errors/value/field.rs | 3 +- compiler/src/errors/value/group.rs | 3 +- compiler/src/errors/value/integer.rs | 5 +- compiler/src/errors/value/value.rs | 9 +-- compiler/src/expression/arithmetic/add.rs | 4 +- compiler/src/expression/arithmetic/div.rs | 4 +- compiler/src/expression/arithmetic/mul.rs | 4 +- compiler/src/expression/arithmetic/negate.rs | 4 +- compiler/src/expression/arithmetic/pow.rs | 4 +- compiler/src/expression/arithmetic/sub.rs | 4 +- compiler/src/expression/array/access.rs | 8 +- compiler/src/expression/array/array.rs | 8 +- compiler/src/expression/array/index.rs | 8 +- compiler/src/expression/binary/binary.rs | 5 +- compiler/src/expression/circuit/access.rs | 8 +- compiler/src/expression/circuit/circuit.rs | 15 ++-- .../src/expression/conditional/conditional.rs | 8 +- compiler/src/expression/expression.rs | 27 +++---- .../src/expression/function/core_circuit.rs | 9 +-- compiler/src/expression/function/function.rs | 9 +-- compiler/src/expression/logical/and.rs | 4 +- compiler/src/expression/logical/not.rs | 4 +- compiler/src/expression/logical/or.rs | 4 +- compiler/src/expression/relational/eq.rs | 8 +- compiler/src/expression/relational/ge.rs | 4 +- compiler/src/expression/relational/gt.rs | 4 +- compiler/src/expression/relational/le.rs | 4 +- compiler/src/expression/relational/lt.rs | 4 +- compiler/src/expression/tuple/access.rs | 8 +- compiler/src/expression/tuple/tuple.rs | 5 +- .../expression/variable_ref/variable_ref.rs | 5 +- compiler/src/function/function.rs | 9 +-- compiler/src/function/input/array.rs | 8 +- compiler/src/function/input/input_keyword.rs | 14 +--- compiler/src/function/input/input_section.rs | 14 +--- .../src/function/input/main_function_input.rs | 25 ++++--- compiler/src/function/input/tuple.rs | 8 +- compiler/src/function/main_function.rs | 9 +-- compiler/src/function/mut_target.rs | 30 ++++---- compiler/src/function/result/result.rs | 18 ++--- compiler/src/output/output_bytes.rs | 12 +-- compiler/src/output/output_file.rs | 14 ++-- compiler/src/prelude/blake2s.rs | 19 +++-- compiler/src/prelude/mod.rs | 7 +- compiler/src/program/program.rs | 3 +- compiler/src/statement/assign/assign.rs | 13 +--- compiler/src/statement/assign/assignee.rs | 10 +-- compiler/src/statement/block/block.rs | 5 +- .../src/statement/conditional/conditional.rs | 14 ++-- .../src/statement/definition/definition.rs | 9 +-- compiler/src/statement/iteration/iteration.rs | 17 +++-- compiler/src/statement/return_/return_.rs | 5 +- compiler/src/statement/statement.rs | 5 +- compiler/src/value/address/address.rs | 38 ++++------ compiler/src/value/boolean/input.rs | 13 +--- compiler/src/value/field/field_type.rs | 42 +++++------ compiler/src/value/field/input.rs | 12 +-- compiler/src/value/group/group_type.rs | 23 +++--- compiler/src/value/group/input.rs | 10 +-- .../src/value/group/targets/edwards_bls12.rs | 74 +++++++++---------- compiler/src/value/integer/integer.rs | 36 ++++----- compiler/src/value/integer/macros.rs | 10 +-- compiler/src/value/value.rs | 18 +---- compiler/tests/address/mod.rs | 6 +- compiler/tests/array/mod.rs | 16 ++-- compiler/tests/boolean/mod.rs | 16 ++-- compiler/tests/circuits/mod.rs | 4 +- compiler/tests/compiler/mod.rs | 6 +- compiler/tests/console/mod.rs | 14 ++-- compiler/tests/core/mod.rs | 4 +- .../core/packages/unstable/blake2s/mod.rs | 21 +++--- compiler/tests/definition/mod.rs | 4 +- compiler/tests/function/mod.rs | 6 +- compiler/tests/import/mod.rs | 6 +- .../tests/input_files/program_input/mod.rs | 5 +- .../program_input_and_program_state/mod.rs | 4 +- .../input_files/program_registers/mod.rs | 4 +- .../tests/input_files/program_state/mod.rs | 4 +- compiler/tests/integers/i128/mod.rs | 19 +++-- compiler/tests/integers/i16/mod.rs | 19 +++-- compiler/tests/integers/i32/mod.rs | 19 +++-- compiler/tests/integers/i64/mod.rs | 19 +++-- compiler/tests/integers/i8/mod.rs | 19 +++-- compiler/tests/integers/integer_tester.rs | 9 +-- compiler/tests/integers/u128/mod.rs | 18 ++--- compiler/tests/integers/u16/mod.rs | 18 ++--- compiler/tests/integers/u32/mod.rs | 18 ++--- compiler/tests/integers/u64/mod.rs | 18 ++--- compiler/tests/integers/u8/mod.rs | 18 ++--- compiler/tests/mod.rs | 23 +++--- compiler/tests/mutability/mod.rs | 5 +- compiler/tests/statements/conditional/mod.rs | 18 +++-- compiler/tests/statements/mod.rs | 5 +- compiler/tests/syntax/mod.rs | 4 +- compiler/tests/tuples/mod.rs | 3 +- gadgets/benches/integer_arithmetic.rs | 18 +---- gadgets/src/arithmetic/add.rs | 13 +--- gadgets/src/arithmetic/neg.rs | 3 +- gadgets/src/bits/adder.rs | 3 +- gadgets/src/bits/comparator.rs | 18 ++--- gadgets/src/bits/rca.rs | 9 +-- gadgets/src/signed_integer/arithmetic/add.rs | 34 ++++----- gadgets/src/signed_integer/arithmetic/div.rs | 34 ++++----- gadgets/src/signed_integer/arithmetic/mul.rs | 37 +++++----- gadgets/src/signed_integer/arithmetic/neg.rs | 4 +- gadgets/src/signed_integer/arithmetic/pow.rs | 23 +++--- gadgets/src/signed_integer/arithmetic/sub.rs | 18 ++--- gadgets/src/signed_integer/relational/cmp.rs | 21 +++--- gadgets/src/signed_integer/relational/eq.rs | 13 +--- gadgets/src/signed_integer/utilities/alloc.rs | 20 ++--- gadgets/src/signed_integer/utilities/eq.rs | 6 +- .../src/signed_integer/utilities/select.rs | 14 ++-- gadgets/tests/signed_integer/i128.rs | 13 +--- gadgets/tests/signed_integer/i16.rs | 13 +--- gadgets/tests/signed_integer/i32.rs | 13 +--- gadgets/tests/signed_integer/i64.rs | 13 +--- gadgets/tests/signed_integer/i8.rs | 13 +--- grammar/benches/grammar.rs | 5 +- grammar/src/access/access.rs | 3 +- grammar/src/access/array_access.rs | 4 +- grammar/src/access/assignee_access.rs | 8 +- grammar/src/access/call_access.rs | 4 +- grammar/src/access/member_access.rs | 4 +- grammar/src/access/self_access.rs | 3 +- grammar/src/access/static_member_access.rs | 4 +- grammar/src/access/tuple_access.rs | 4 +- .../src/annotations/annotation_arguments.rs | 7 +- grammar/src/annotations/annotation_name.rs | 3 +- grammar/src/annotations/annotation_symbol.rs | 3 +- grammar/src/annotations/annotations.rs | 10 +-- grammar/src/ast.rs | 46 ++++++------ grammar/src/circuits/circuit.rs | 5 +- .../src/circuits/circuit_implied_variable.rs | 4 +- grammar/src/circuits/circuit_member.rs | 4 +- grammar/src/circuits/circuit_variable.rs | 5 +- .../circuits/circuit_variable_definition.rs | 5 +- grammar/src/common/assignee.rs | 5 +- grammar/src/common/eoi.rs | 3 +- grammar/src/common/identifier.rs | 7 +- grammar/src/common/keyword_or_identifier.rs | 5 +- grammar/src/common/mut_self_keyword.rs | 9 ++- grammar/src/common/range.rs | 4 +- grammar/src/common/range_or_expression.rs | 4 +- grammar/src/common/self_keyword.rs | 7 +- .../src/common/self_keyword_or_identifier.rs | 7 +- grammar/src/common/spread.rs | 4 +- grammar/src/common/spread_or_expression.rs | 4 +- grammar/src/common/variable_name.rs | 9 ++- grammar/src/common/variables.rs | 5 +- grammar/src/console/console_assert.rs | 4 +- grammar/src/console/console_debug.rs | 4 +- grammar/src/console/console_error.rs | 4 +- grammar/src/console/console_function.rs | 9 +-- grammar/src/console/console_function_call.rs | 11 +-- grammar/src/console/console_keyword.rs | 3 +- grammar/src/console/console_log.rs | 4 +- grammar/src/console/formatted_container.rs | 3 +- grammar/src/console/formatted_string.rs | 11 +-- .../src/definitions/annotated_definition.rs | 5 +- grammar/src/definitions/definition.rs | 13 ++-- grammar/src/definitions/deprecated.rs | 3 +- grammar/src/errors/parser.rs | 6 +- .../array_initializer_expression.rs | 5 +- .../expressions/array_inline_expression.rs | 4 +- grammar/src/expressions/binary_expression.rs | 4 +- .../expressions/circuit_inline_expression.rs | 6 +- grammar/src/expressions/expression.rs | 5 +- grammar/src/expressions/postfix_expression.rs | 5 +- .../expressions/self_postfix_expression.rs | 11 +-- grammar/src/expressions/ternary_expression.rs | 4 +- grammar/src/expressions/tuple_expression.rs | 4 +- grammar/src/expressions/unary_expression.rs | 5 +- grammar/src/files/file.rs | 5 +- grammar/src/functions/function.rs | 7 +- grammar/src/functions/input/function_input.rs | 12 +-- grammar/src/functions/input/input.rs | 10 +-- grammar/src/functions/input/input_keyword.rs | 7 +- grammar/src/functions/test_function.rs | 4 +- grammar/src/imports/import.rs | 5 +- grammar/src/imports/import_symbol.rs | 4 +- grammar/src/imports/package.rs | 9 ++- grammar/src/imports/package_access.rs | 9 +-- grammar/src/imports/package_name.rs | 7 +- grammar/src/imports/package_or_packages.rs | 7 +- grammar/src/imports/packages.rs | 9 ++- grammar/src/imports/star.rs | 3 +- grammar/src/lib.rs | 3 +- grammar/src/main.rs | 7 +- grammar/src/span.rs | 3 +- grammar/src/statements/assign_statement.rs | 13 ++-- grammar/src/statements/block.rs | 4 +- .../conditional_nested_or_end_statement.rs | 7 +- .../src/statements/conditional_statement.rs | 11 +-- .../src/statements/definition_statement.rs | 12 +-- .../src/statements/expression_statement.rs | 5 +- grammar/src/statements/for_statement.rs | 6 +- grammar/src/statements/return_statement.rs | 4 +- grammar/src/statements/statement.rs | 4 +- grammar/src/types/array_dimensions.rs | 4 +- grammar/src/types/array_type.rs | 9 ++- grammar/src/types/circuit_type.rs | 4 +- grammar/src/types/data_type.rs | 10 +-- grammar/src/types/integer_type.rs | 7 +- grammar/src/types/self_type.rs | 7 +- grammar/src/types/tuple_type.rs | 4 +- grammar/src/types/type_.rs | 3 +- grammar/src/values/address.rs | 7 +- grammar/src/values/address_value.rs | 5 +- grammar/src/values/boolean_value.rs | 7 +- grammar/src/values/field_value.rs | 5 +- grammar/src/values/group_coordinate.rs | 4 +- grammar/src/values/group_value.rs | 11 +-- grammar/src/values/integer_value.rs | 7 +- grammar/src/values/negative_number.rs | 7 +- grammar/src/values/number_value.rs | 7 +- grammar/src/values/positive_number.rs | 7 +- grammar/src/values/signed_integer_value.rs | 5 +- grammar/src/values/unsigned_integer_value.rs | 5 +- grammar/src/values/value.rs | 11 +-- grammar/tests/annotated.rs | 3 +- grammar/tests/circuits.rs | 3 +- grammar/tests/deprecated.rs | 3 +- grammar/tests/display.rs | 7 +- grammar/tests/expression.rs | 3 +- grammar/tests/function.rs | 3 +- grammar/tests/imports.rs | 3 +- grammar/tests/multiline.rs | 3 +- grammar/tests/self.rs | 3 +- grammar/tests/tuple.rs | 3 +- imports/src/errors/import_parser.rs | 9 +-- imports/src/parser/import_parser.rs | 9 +-- imports/src/parser/parse_package.rs | 12 +-- imports/src/parser/parse_symbol.rs | 6 +- input/src/ast.rs | 5 +- input/src/common/identifier.rs | 3 +- input/src/definitions/definition.rs | 5 +- input/src/errors/parser.rs | 35 ++++----- .../array_initializer_expression.rs | 4 +- .../expressions/array_inline_expression.rs | 3 +- input/src/expressions/expression.rs | 4 +- input/src/expressions/tuple_expression.rs | 3 +- input/src/files/file.rs | 4 +- input/src/files/table_or_section.rs | 4 +- input/src/lib.rs | 3 +- input/src/parameters/parameter.rs | 4 +- input/src/sections/header.rs | 12 ++- input/src/sections/section.rs | 4 +- input/src/tables/table.rs | 4 +- input/src/tables/visibility.rs | 7 +- input/src/types/array_dimensions.rs | 3 +- input/src/types/array_type.rs | 7 +- input/src/types/data_type.rs | 9 +-- input/src/types/integer_type.rs | 7 +- input/src/types/tuple_type.rs | 3 +- input/src/types/type_.rs | 3 +- input/src/values/address.rs | 3 +- input/src/values/address_typed.rs | 4 +- input/src/values/address_value.rs | 7 +- input/src/values/boolean_value.rs | 3 +- input/src/values/field_value.rs | 4 +- input/src/values/group_coordinate.rs | 3 +- input/src/values/group_value.rs | 9 ++- input/src/values/integer_value.rs | 7 +- input/src/values/negative_number.rs | 3 +- input/src/values/number_value.rs | 7 +- input/src/values/positive_number.rs | 3 +- input/src/values/signed_integer_value.rs | 4 +- input/src/values/unsigned_integer_value.rs | 4 +- input/src/values/value.rs | 10 +-- leo/api.rs | 13 ++-- leo/commands/build.rs | 31 +++----- leo/commands/clean.rs | 9 +-- leo/commands/deploy.rs | 3 +- leo/commands/init.rs | 6 +- leo/commands/lint.rs | 3 +- leo/commands/mod.rs | 6 +- leo/commands/new.rs | 9 +-- leo/commands/package/add.rs | 18 ++--- leo/commands/package/clone.rs | 22 +++--- leo/commands/package/login.rs | 14 ++-- leo/commands/package/logout.rs | 4 +- leo/commands/package/publish.rs | 21 +++--- leo/commands/package/remove.rs | 3 +- leo/commands/prove.rs | 14 ++-- leo/commands/run.rs | 12 +-- leo/commands/setup.rs | 29 +++----- leo/commands/test.rs | 28 +++---- leo/commands/update.rs | 8 +- leo/commands/watch.rs | 14 +--- leo/config.rs | 20 ++--- leo/context.rs | 7 +- leo/logger.rs | 14 ++-- leo/main.rs | 38 +++++----- leo/tests/mod.rs | 26 ++++--- leo/updater.rs | 7 +- package/src/errors/imports/directory.rs | 4 +- package/src/errors/inputs/directory.rs | 7 +- package/src/errors/inputs/input.rs | 3 +- package/src/errors/inputs/state.rs | 3 +- package/src/errors/outputs/checksum.rs | 3 +- package/src/errors/outputs/circuit.rs | 3 +- package/src/errors/outputs/directory.rs | 4 +- package/src/errors/outputs/proof.rs | 3 +- package/src/errors/outputs/proving_key.rs | 3 +- .../src/errors/outputs/verification_key.rs | 3 +- package/src/errors/package.rs | 3 +- package/src/errors/root/zip.rs | 3 +- package/src/errors/source/directory.rs | 4 +- package/src/imports/directory.rs | 4 +- package/src/inputs/directory.rs | 11 +-- package/src/inputs/input.rs | 17 +++-- package/src/inputs/pairs.rs | 14 ++-- package/src/inputs/state.rs | 17 +++-- package/src/outputs/checksum.rs | 17 +++-- package/src/outputs/circuit.rs | 17 +++-- package/src/outputs/directory.rs | 4 +- package/src/outputs/proof.rs | 17 +++-- package/src/outputs/proving_key.rs | 17 +++-- package/src/outputs/verification_key.rs | 17 +++-- package/src/package.rs | 18 ++--- package/src/root/gitignore.rs | 5 +- package/src/root/manifest.rs | 16 ++-- package/src/root/readme.rs | 5 +- package/src/root/zip.rs | 48 ++++++------ package/src/source/directory.rs | 9 ++- package/src/source/library.rs | 8 +- package/src/source/main.rs | 8 +- package/tests/initialize/initialize.rs | 14 ++-- package/tests/manifest/manifest.rs | 15 ++-- package/tests/mod.rs | 13 ++-- state/Cargo.toml | 2 +- state/src/errors/dpc_record_values.rs | 3 +- state/src/errors/local_data_commitment.rs | 7 +- state/src/errors/state_leaf_values.rs | 3 +- state/src/errors/state_values.rs | 3 +- .../local_data_commitment.rs | 28 ++++--- .../state_leaf_values.rs | 5 +- .../src/local_data_commitment/state_values.rs | 5 +- .../record_commitment/dpc_record_values.rs | 9 +-- .../record_commitment/record_commitment.rs | 14 ++-- state/src/utilities/input_value.rs | 3 +- .../test_verify_local_data_commitment.rs | 30 ++++---- synthesizer/src/circuit_synthesizer.rs | 7 +- synthesizer/src/serialized_circuit.rs | 14 +--- synthesizer/src/serialized_field.rs | 11 +-- synthesizer/src/serialized_index.rs | 3 +- 470 files changed, 1862 insertions(+), 2849 deletions(-) diff --git a/.rustfmt.toml b/.rustfmt.toml index 396becc016..39028b1340 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -10,7 +10,7 @@ use_try_shorthand = true # Nightly configurations imports_layout = "HorizontalVertical" license_template_path = ".resources/license_header" -imports_granularity = "Item" +imports_granularity = "Crate" overflow_delimited_expr = true reorder_impl_items = true version = "Two" diff --git a/.rusty-hook.toml b/.rusty-hook.toml index 21760cec6d..bcdbfd8fa4 100644 --- a/.rusty-hook.toml +++ b/.rusty-hook.toml @@ -1,5 +1,5 @@ [hooks] -#pre-commit = "cargo clippy && cargo +nightly fmt --all -- --check" +pre-commit = "cargo clippy && cargo +nightly fmt --all -- --check" [logging] verbose = true diff --git a/Cargo.toml b/Cargo.toml index 1287459f14..6628e10f2f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -73,7 +73,7 @@ version = "1.2.3" [dependencies.snarkvm-algorithms] version = "0.2.0" -default-features = false +#default-features = false [dependencies.snarkvm-curves] version = "0.2.0" diff --git a/asg/src/checks/return_path.rs b/asg/src/checks/return_path.rs index b2366a17f8..8a21f0514e 100644 --- a/asg/src/checks/return_path.rs +++ b/asg/src/checks/return_path.rs @@ -14,14 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::statement::*; -use crate::BoolAnd; -use crate::Expression; -use crate::Monoid; -use crate::MonoidalReducerExpression; -use crate::MonoidalReducerStatement; -use crate::Node; -use crate::Span; +use crate::{ + statement::*, + BoolAnd, + Expression, + Monoid, + MonoidalReducerExpression, + MonoidalReducerStatement, + Node, + Span, +}; pub struct ReturnPathReducer { pub errors: Vec<(Span, String)>, diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index fce4e43ad7..bab4aa5b3b 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::IntegerType; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, IntegerType, Span, Type}; use num_bigint::BigInt; -use std::convert::TryInto; -use std::fmt; +use std::{convert::TryInto, fmt}; /// Constant integer values in a program. #[derive(Clone, Debug, PartialEq)] diff --git a/asg/src/context.rs b/asg/src/context.rs index 2a20124f4e..7d27ee10c0 100644 --- a/asg/src/context.rs +++ b/asg/src/context.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::cell::Cell; -use std::unimplemented; +use std::{cell::Cell, unimplemented}; use typed_arena::Arena; diff --git a/asg/src/error/mod.rs b/asg/src/error/mod.rs index 47e7cf761e..39e60735dc 100644 --- a/asg/src/error/mod.rs +++ b/asg/src/error/mod.rs @@ -17,8 +17,7 @@ //! Errors encountered when attempting to convert to an asg from an ast. use crate::Span; -use leo_ast::AstError; -use leo_ast::Error as FormattedError; +use leo_ast::{AstError, Error as FormattedError}; use leo_grammar::ParserError; #[derive(Debug, Error)] diff --git a/asg/src/expression/array_access.rs b/asg/src/expression/array_access.rs index 93a373a354..3bbbd7909d 100644 --- a/asg/src/expression/array_access.rs +++ b/asg/src/expression/array_access.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use leo_ast::IntegerType; use std::cell::Cell; diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index 8bc8ee1fcd..063485b4c4 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use std::cell::Cell; diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index 2d6a97fd4b..79f78386fa 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use leo_ast::SpreadOrExpression; use std::cell::Cell; diff --git a/asg/src/expression/array_range_access.rs b/asg/src/expression/array_range_access.rs index 1890245176..f070116aa0 100644 --- a/asg/src/expression/array_range_access.rs +++ b/asg/src/expression/array_range_access.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use leo_ast::IntegerType; use std::cell::Cell; diff --git a/asg/src/expression/binary.rs b/asg/src/expression/binary.rs index 2b3b24f2ae..9322b1d587 100644 --- a/asg/src/expression/binary.rs +++ b/asg/src/expression/binary.rs @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; -pub use leo_ast::BinaryOperation; -pub use leo_ast::BinaryOperationClass; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; +pub use leo_ast::{BinaryOperation, BinaryOperationClass}; use std::cell::Cell; diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index 0de4cbee3c..52572a4907 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -14,21 +14,22 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::CircuitMember; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Function; -use crate::FunctionQualifier; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; -pub use leo_ast::BinaryOperation; -pub use leo_ast::Node as AstNode; +use crate::{ + AsgConvertError, + CircuitMember, + ConstValue, + Expression, + ExpressionNode, + FromAst, + Function, + FunctionQualifier, + Node, + PartialType, + Scope, + Span, + Type, +}; +pub use leo_ast::{BinaryOperation, Node as AstNode}; use std::cell::Cell; diff --git a/asg/src/expression/circuit_access.rs b/asg/src/expression/circuit_access.rs index 63b79671d4..739579cabd 100644 --- a/asg/src/expression/circuit_access.rs +++ b/asg/src/expression/circuit_access.rs @@ -14,19 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Circuit; -use crate::CircuitMember; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Identifier; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{ + AsgConvertError, + Circuit, + CircuitMember, + ConstValue, + Expression, + ExpressionNode, + FromAst, + Identifier, + Node, + PartialType, + Scope, + Span, + Type, +}; use std::cell::Cell; diff --git a/asg/src/expression/circuit_init.rs b/asg/src/expression/circuit_init.rs index 10058661bf..b7ec7a764b 100644 --- a/asg/src/expression/circuit_init.rs +++ b/asg/src/expression/circuit_init.rs @@ -14,22 +14,23 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Circuit; -use crate::CircuitMember; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Identifier; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{ + AsgConvertError, + Circuit, + CircuitMember, + ConstValue, + Expression, + ExpressionNode, + FromAst, + Identifier, + Node, + PartialType, + Scope, + Span, + Type, +}; -use indexmap::IndexMap; -use indexmap::IndexSet; +use indexmap::{IndexMap, IndexSet}; use std::cell::Cell; #[derive(Clone)] diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index 1ab97a0588..ae2a1fdd13 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -14,18 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstInt; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::GroupValue; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{ + AsgConvertError, + ConstInt, + ConstValue, + Expression, + ExpressionNode, + FromAst, + GroupValue, + Node, + PartialType, + Scope, + Span, + Type, +}; use std::cell::Cell; diff --git a/asg/src/expression/mod.rs b/asg/src/expression/mod.rs index 76cb49011f..720bac0781 100644 --- a/asg/src/expression/mod.rs +++ b/asg/src/expression/mod.rs @@ -62,14 +62,7 @@ pub use unary::*; mod variable_ref; pub use variable_ref::*; -use crate::AsgConvertError; -use crate::ConstValue; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, FromAst, Node, PartialType, Scope, Span, Type}; #[derive(Clone)] pub enum Expression<'a> { diff --git a/asg/src/expression/ternary.rs b/asg/src/expression/ternary.rs index 76d7b962e7..93d1a7df0f 100644 --- a/asg/src/expression/ternary.rs +++ b/asg/src/expression/ternary.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use std::cell::Cell; diff --git a/asg/src/expression/tuple_access.rs b/asg/src/expression/tuple_access.rs index a73f7093f6..4886ff4aa6 100644 --- a/asg/src/expression/tuple_access.rs +++ b/asg/src/expression/tuple_access.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use std::cell::Cell; diff --git a/asg/src/expression/tuple_init.rs b/asg/src/expression/tuple_init.rs index d2bd923807..195b4fe4af 100644 --- a/asg/src/expression/tuple_init.rs +++ b/asg/src/expression/tuple_init.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; use std::cell::Cell; diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index e71f2d3d45..0e5078e71c 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, ConstValue, Expression, ExpressionNode, FromAst, Node, PartialType, Scope, Span, Type}; pub use leo_ast::UnaryOperation; use std::cell::Cell; diff --git a/asg/src/expression/variable_ref.rs b/asg/src/expression/variable_ref.rs index 15f69ee690..d702caa295 100644 --- a/asg/src/expression/variable_ref.rs +++ b/asg/src/expression/variable_ref.rs @@ -14,20 +14,22 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::ConstValue; -use crate::Constant; -use crate::DefinitionStatement; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; -use crate::Variable; +use crate::{ + AsgConvertError, + ConstValue, + Constant, + DefinitionStatement, + Expression, + ExpressionNode, + FromAst, + Node, + PartialType, + Scope, + Span, + Statement, + Type, + Variable, +}; use std::cell::Cell; diff --git a/asg/src/import.rs b/asg/src/import.rs index 1b95fc2fdd..4dc3c5ae43 100644 --- a/asg/src/import.rs +++ b/asg/src/import.rs @@ -18,10 +18,7 @@ use std::marker::PhantomData; -use crate::AsgContext; -use crate::AsgConvertError; -use crate::Program; -use crate::Span; +use crate::{AsgContext, AsgConvertError, Program, Span}; use indexmap::IndexMap; diff --git a/asg/src/input.rs b/asg/src/input.rs index ee4b5ea72d..f9af9c2851 100644 --- a/asg/src/input.rs +++ b/asg/src/input.rs @@ -14,12 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Circuit; -use crate::CircuitMember; -use crate::Identifier; -use crate::Scope; -use crate::Type; -use crate::Variable; +use crate::{Circuit, CircuitMember, Identifier, Scope, Type, Variable}; use indexmap::IndexMap; use std::cell::RefCell; diff --git a/asg/src/lib.rs b/asg/src/lib.rs index a611f6929f..ada569edeb 100644 --- a/asg/src/lib.rs +++ b/asg/src/lib.rs @@ -74,9 +74,7 @@ pub use pass::*; pub mod context; pub use context::*; -pub use leo_ast::Ast; -pub use leo_ast::Identifier; -pub use leo_ast::Span; +pub use leo_ast::{Ast, Identifier, Span}; use std::path::Path; diff --git a/asg/src/node.rs b/asg/src/node.rs index ae9ca44a68..58b4b7709e 100644 --- a/asg/src/node.rs +++ b/asg/src/node.rs @@ -14,16 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgContextInner; -use crate::AsgConvertError; -use crate::Circuit; -use crate::Expression; -use crate::Function; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Variable; +use crate::{ + AsgContextInner, + AsgConvertError, + Circuit, + Expression, + Function, + PartialType, + Scope, + Span, + Statement, + Variable, +}; /// A node in the abstract semantic graph. pub trait Node { diff --git a/asg/src/prelude.rs b/asg/src/prelude.rs index f8408f5cb9..e977fd137f 100644 --- a/asg/src/prelude.rs +++ b/asg/src/prelude.rs @@ -16,9 +16,7 @@ // TODO (protryon): We should merge this with core -use crate::AsgContext; -use crate::AsgConvertError; -use crate::Program; +use crate::{AsgContext, AsgConvertError, Program}; // TODO (protryon): Make asg deep copy so we can cache resolved core modules // TODO (protryon): Figure out how to do headers without bogus returns diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index 05b262bd8b..e44c8b8277 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Function; -use crate::Identifier; -use crate::Node; -use crate::Scope; -use crate::Span; -use crate::Type; +use crate::{AsgConvertError, Function, Identifier, Node, Scope, Span, Type}; use indexmap::IndexMap; use std::cell::RefCell; diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 1a46063502..159d3ead3b 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -14,23 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::BlockStatement; -use crate::Circuit; -use crate::FromAst; -use crate::Identifier; -use crate::MonoidalDirector; -use crate::ReturnPathReducer; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; -use crate::Variable; +use crate::{ + AsgConvertError, + BlockStatement, + Circuit, + FromAst, + Identifier, + MonoidalDirector, + ReturnPathReducer, + Scope, + Span, + Statement, + Type, + Variable, +}; use indexmap::IndexMap; use leo_ast::FunctionInput; -use std::cell::Cell; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; #[derive(Clone, Copy, PartialEq)] pub enum FunctionQualifier { diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 70d3e39889..cccadd08d3 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -24,20 +24,11 @@ pub use circuit::*; mod function; pub use function::*; -use crate::ArenaNode; -use crate::AsgContext; -use crate::AsgConvertError; -use crate::ImportResolver; -use crate::Input; -use crate::Scope; -use leo_ast::Identifier; -use leo_ast::PackageAccess; -use leo_ast::PackageOrPackages; -use leo_ast::Span; +use crate::{ArenaNode, AsgContext, AsgConvertError, ImportResolver, Input, Scope}; +use leo_ast::{Identifier, PackageAccess, PackageOrPackages, Span}; use indexmap::IndexMap; -use std::cell::Cell; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; /// Stores the Leo program abstract semantic graph (ASG). #[derive(Clone)] diff --git a/asg/src/reducer/monoidal_director.rs b/asg/src/reducer/monoidal_director.rs index 539363a95d..40a55d4a30 100644 --- a/asg/src/reducer/monoidal_director.rs +++ b/asg/src/reducer/monoidal_director.rs @@ -15,9 +15,7 @@ // along with the Leo library. If not, see . use super::*; -use crate::expression::*; -use crate::program::*; -use crate::statement::*; +use crate::{expression::*, program::*, statement::*}; use std::marker::PhantomData; diff --git a/asg/src/reducer/monoidal_reducer.rs b/asg/src/reducer/monoidal_reducer.rs index a126bc2807..ba7a177f5b 100644 --- a/asg/src/reducer/monoidal_reducer.rs +++ b/asg/src/reducer/monoidal_reducer.rs @@ -14,10 +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::*; -use crate::program::*; -use crate::statement::*; -use crate::Monoid; +use crate::{expression::*, program::*, statement::*, Monoid}; #[allow(unused_variables)] pub trait MonoidalReducerExpression<'a, T: Monoid> { diff --git a/asg/src/reducer/visitor.rs b/asg/src/reducer/visitor.rs index 220d920c82..415f3ed265 100644 --- a/asg/src/reducer/visitor.rs +++ b/asg/src/reducer/visitor.rs @@ -16,9 +16,7 @@ use std::cell::Cell; -use crate::expression::*; -use crate::program::*; -use crate::statement::*; +use crate::{expression::*, program::*, statement::*}; pub enum VisitResult { VisitChildren, diff --git a/asg/src/reducer/visitor_director.rs b/asg/src/reducer/visitor_director.rs index fd37311d76..4edc95d106 100644 --- a/asg/src/reducer/visitor_director.rs +++ b/asg/src/reducer/visitor_director.rs @@ -15,12 +15,9 @@ // along with the Leo library. If not, see . use super::*; -use crate::expression::*; -use crate::program::*; -use crate::statement::*; +use crate::{expression::*, program::*, statement::*}; -use std::cell::Cell; -use std::marker::PhantomData; +use std::{cell::Cell, marker::PhantomData}; pub struct VisitorDirector<'a, R: ExpressionVisitor<'a>> { visitor: R, diff --git a/asg/src/scope.rs b/asg/src/scope.rs index 7394d8d4c4..c39506c043 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -14,20 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ArenaNode; -use crate::AsgContext; -use crate::AsgConvertError; -use crate::Circuit; -use crate::Expression; -use crate::Function; -use crate::Input; -use crate::Statement; -use crate::Type; -use crate::Variable; +use crate::{ArenaNode, AsgContext, AsgConvertError, Circuit, Expression, Function, Input, Statement, Type, Variable}; use indexmap::IndexMap; -use std::cell::Cell; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; /// An abstract data type that track the current bindings for variables, functions, and circuits. #[derive(Clone)] diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index f00d419cbd..1eda9119ba 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -14,22 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::CircuitMember; -use crate::ConstInt; -use crate::ConstValue; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::Identifier; -use crate::IntegerType; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; -use crate::Variable; +use crate::{ + AsgConvertError, + CircuitMember, + ConstInt, + ConstValue, + Expression, + ExpressionNode, + FromAst, + Identifier, + IntegerType, + Node, + PartialType, + Scope, + Span, + Statement, + Type, + Variable, +}; pub use leo_ast::AssignOperation; use leo_ast::AssigneeAccess as AstAssigneeAccess; diff --git a/asg/src/statement/block.rs b/asg/src/statement/block.rs index 70bd668119..9a64fcdfb9 100644 --- a/asg/src/statement/block.rs +++ b/asg/src/statement/block.rs @@ -14,13 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; +use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span, Statement}; use std::cell::Cell; diff --git a/asg/src/statement/conditional.rs b/asg/src/statement/conditional.rs index 5d2d4f30ca..6f0b5f09b7 100644 --- a/asg/src/statement/conditional.rs +++ b/asg/src/statement/conditional.rs @@ -14,16 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::BlockStatement; -use crate::Expression; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; +use crate::{AsgConvertError, BlockStatement, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; use std::cell::Cell; diff --git a/asg/src/statement/console.rs b/asg/src/statement/console.rs index f72c172f1b..fdcf2858e5 100644 --- a/asg/src/statement/console.rs +++ b/asg/src/statement/console.rs @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Expression; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; +use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; use leo_ast::ConsoleFunction as AstConsoleFunction; use std::cell::Cell; diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index dab03e9b7a..a779454996 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -14,23 +14,23 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::InnerVariable; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; -use crate::Variable; -use leo_ast::AstError; -use leo_ast::DeprecatedError; +use crate::{ + AsgConvertError, + Expression, + ExpressionNode, + FromAst, + InnerVariable, + Node, + PartialType, + Scope, + Span, + Statement, + Type, + Variable, +}; +use leo_ast::{AstError, DeprecatedError}; -use std::cell::Cell; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; #[derive(Clone)] pub struct DefinitionStatement<'a> { diff --git a/asg/src/statement/expression.rs b/asg/src/statement/expression.rs index e533f87bf3..f00c55c488 100644 --- a/asg/src/statement/expression.rs +++ b/asg/src/statement/expression.rs @@ -14,14 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Expression; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; +use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement}; use std::cell::Cell; diff --git a/asg/src/statement/iteration.rs b/asg/src/statement/iteration.rs index 1a441befbd..26cfd2ba74 100644 --- a/asg/src/statement/iteration.rs +++ b/asg/src/statement/iteration.rs @@ -16,20 +16,21 @@ use leo_ast::IntegerType; -use crate::AsgConvertError; -use crate::Expression; -use crate::ExpressionNode; -use crate::FromAst; -use crate::InnerVariable; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Variable; +use crate::{ + AsgConvertError, + Expression, + ExpressionNode, + FromAst, + InnerVariable, + Node, + PartialType, + Scope, + Span, + Statement, + Variable, +}; -use std::cell::Cell; -use std::cell::RefCell; +use std::cell::{Cell, RefCell}; #[derive(Clone)] pub struct IterationStatement<'a> { diff --git a/asg/src/statement/mod.rs b/asg/src/statement/mod.rs index 7757ba4d33..bc924f2ae1 100644 --- a/asg/src/statement/mod.rs +++ b/asg/src/statement/mod.rs @@ -42,12 +42,7 @@ pub use iteration::*; mod return_; pub use return_::*; -use crate::AsgConvertError; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; +use crate::{AsgConvertError, FromAst, Node, PartialType, Scope, Span}; #[derive(Clone)] pub enum Statement<'a> { diff --git a/asg/src/statement/return_.rs b/asg/src/statement/return_.rs index eccf6f794f..fb6b640390 100644 --- a/asg/src/statement/return_.rs +++ b/asg/src/statement/return_.rs @@ -14,15 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::AsgConvertError; -use crate::Expression; -use crate::FromAst; -use crate::Node; -use crate::PartialType; -use crate::Scope; -use crate::Span; -use crate::Statement; -use crate::Type; +use crate::{AsgConvertError, Expression, FromAst, Node, PartialType, Scope, Span, Statement, Type}; use std::cell::Cell; #[derive(Clone)] diff --git a/asg/src/variable.rs b/asg/src/variable.rs index a38274c3e9..831de1c63f 100644 --- a/asg/src/variable.rs +++ b/asg/src/variable.rs @@ -16,9 +16,7 @@ use std::cell::RefCell; -use crate::Expression; -use crate::Statement; -use crate::Type; +use crate::{Expression, Statement, Type}; use leo_ast::Identifier; /// Specifies how a program variable was declared. diff --git a/asg/tests/pass/form_ast.rs b/asg/tests/pass/form_ast.rs index 471f938310..d49cb8b970 100644 --- a/asg/tests/pass/form_ast.rs +++ b/asg/tests/pass/form_ast.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::load_asg; -use crate::make_test_context; +use crate::{load_asg, make_test_context}; use leo_ast::Ast; use leo_grammar::Grammar; diff --git a/asg/tests/pass/import/mod.rs b/asg/tests/pass/import/mod.rs index 1c6008557e..870e4fe9ee 100644 --- a/asg/tests/pass/import/mod.rs +++ b/asg/tests/pass/import/mod.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::load_asg; -use crate::load_asg_imports; -use crate::make_test_context; -use crate::mocked_resolver; +use crate::{load_asg, load_asg_imports, make_test_context, mocked_resolver}; #[test] fn test_basic() { diff --git a/ast/benches/leo_ast.rs b/ast/benches/leo_ast.rs index 16619f1971..d5420b0543 100644 --- a/ast/benches/leo_ast.rs +++ b/ast/benches/leo_ast.rs @@ -17,11 +17,8 @@ use leo_ast::Ast; use leo_grammar::Grammar; -use criterion::criterion_group; -use criterion::criterion_main; -use criterion::Criterion; -use std::path::Path; -use std::time::Duration; +use criterion::{criterion_group, criterion_main, Criterion}; +use std::{path::Path, time::Duration}; fn ast(ast: &Grammar) -> Ast { Ast::new("leo_tree", &ast).unwrap() diff --git a/ast/src/annotation.rs b/ast/src/annotation.rs index f1c233c935..9ccc5e833d 100644 --- a/ast/src/annotation.rs +++ b/ast/src/annotation.rs @@ -14,18 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Circuit; -use crate::DeprecatedError; -use crate::Function; -use crate::FunctionInput; -use crate::Identifier; -use crate::ImportStatement; -use crate::TestFunction; -use leo_grammar::annotations::Annotation; -use leo_grammar::annotations::AnnotationArguments; -use leo_grammar::annotations::AnnotationName; -use leo_grammar::definitions::AnnotatedDefinition; -use leo_grammar::definitions::Definition; +use crate::{Circuit, DeprecatedError, Function, FunctionInput, Identifier, ImportStatement, TestFunction}; +use leo_grammar::{ + annotations::{Annotation, AnnotationArguments, AnnotationName}, + definitions::{AnnotatedDefinition, Definition}, +}; use std::convert::TryFrom; diff --git a/ast/src/circuits/circuit.rs b/ast/src/circuits/circuit.rs index de9aa0e88e..79c2280cfc 100644 --- a/ast/src/circuits/circuit.rs +++ b/ast/src/circuits/circuit.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::CircuitMember; -use crate::Identifier; +use crate::{CircuitMember, Identifier}; use leo_grammar::circuits::Circuit as GrammarCircuit; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/circuits/circuit_implied_variable_definition.rs b/ast/src/circuits/circuit_implied_variable_definition.rs index f48ae39ceb..963c153bec 100644 --- a/ast/src/circuits/circuit_implied_variable_definition.rs +++ b/ast/src/circuits/circuit_implied_variable_definition.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Identifier; +use crate::{Expression, Identifier}; use leo_grammar::circuits::CircuitImpliedVariable; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CircuitImpliedVariableDefinition { diff --git a/ast/src/circuits/circuit_member.rs b/ast/src/circuits/circuit_member.rs index 8661b825be..29b5777587 100644 --- a/ast/src/circuits/circuit_member.rs +++ b/ast/src/circuits/circuit_member.rs @@ -14,15 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Function; -use crate::Identifier; -use crate::Type; -use leo_grammar::circuits::CircuitMember as GrammarCircuitMember; -use leo_grammar::circuits::CircuitVariableDefinition as GrammarCircuitVariableDefinition; -use leo_grammar::functions::Function as GrammarFunction; +use crate::{Function, Identifier, Type}; +use leo_grammar::{ + circuits::{CircuitMember as GrammarCircuitMember, CircuitVariableDefinition as GrammarCircuitVariableDefinition}, + functions::Function as GrammarFunction, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/circuits/circuit_variable_definition.rs b/ast/src/circuits/circuit_variable_definition.rs index f553161a3c..6cd3484f88 100644 --- a/ast/src/circuits/circuit_variable_definition.rs +++ b/ast/src/circuits/circuit_variable_definition.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Identifier; +use crate::{Expression, Identifier}; use leo_grammar::circuits::CircuitVariable; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct CircuitVariableDefinition { diff --git a/ast/src/common/array_dimensions.rs b/ast/src/common/array_dimensions.rs index 1aa523bf68..a401475200 100644 --- a/ast/src/common/array_dimensions.rs +++ b/ast/src/common/array_dimensions.rs @@ -18,8 +18,7 @@ use crate::PositiveNumber; use leo_grammar::types::ArrayDimensions as GrammarArrayDimensions; use leo_input::types::ArrayDimensions as InputArrayDimensions; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// A vector of positive numbers that represent array dimensions. diff --git a/ast/src/common/identifier.rs b/ast/src/common/identifier.rs index 6d5bb779d8..cc9c544e99 100644 --- a/ast/src/common/identifier.rs +++ b/ast/src/common/identifier.rs @@ -14,33 +14,39 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputKeyword; -use crate::MutSelfKeyword; -use crate::SelfKeyword; -use crate::Span; -use leo_grammar::annotations::AnnotationArgument; -use leo_grammar::common::Identifier as GrammarIdentifier; -use leo_grammar::common::KeywordOrIdentifier; -use leo_grammar::common::MutSelfKeyword as GrammarMutSelfKeyword; -use leo_grammar::common::SelfKeyword as GrammarSelfKeyword; -use leo_grammar::common::SelfKeywordOrIdentifier; -use leo_grammar::expressions::CircuitName; -use leo_grammar::functions::InputKeyword as GrammarInputKeyword; -use leo_grammar::imports::PackageName as GrammarPackageName; -use leo_grammar::types::SelfType; +use crate::{InputKeyword, MutSelfKeyword, SelfKeyword, Span}; +use leo_grammar::{ + annotations::AnnotationArgument, + common::{ + Identifier as GrammarIdentifier, + KeywordOrIdentifier, + MutSelfKeyword as GrammarMutSelfKeyword, + SelfKeyword as GrammarSelfKeyword, + SelfKeywordOrIdentifier, + }, + expressions::CircuitName, + functions::InputKeyword as GrammarInputKeyword, + imports::PackageName as GrammarPackageName, + types::SelfType, +}; use leo_input::common::Identifier as InputIdentifier; use crate::Node; -use serde::de::Visitor; -use serde::de::{self}; -use serde::Deserialize; -use serde::Deserializer; -use serde::Serialize; -use serde::Serializer; -use std::collections::BTreeMap; -use std::fmt; -use std::hash::Hash; -use std::hash::Hasher; +use serde::{ + de::{ + Visitor, + {self}, + }, + Deserialize, + Deserializer, + Serialize, + Serializer, +}; +use std::{ + collections::BTreeMap, + fmt, + hash::{Hash, Hasher}, +}; /// An identifier in the constrained program. /// diff --git a/ast/src/common/input_keyword.rs b/ast/src/common/input_keyword.rs index 987237ff94..a6dd0d5e74 100644 --- a/ast/src/common/input_keyword.rs +++ b/ast/src/common/input_keyword.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Node; -use crate::Span; +use crate::{Node, Span}; use leo_grammar::functions::InputKeyword as GrammarInputKeyword; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// The `input` keyword can view program register, record, and state values. diff --git a/ast/src/common/mut_self_keyword.rs b/ast/src/common/mut_self_keyword.rs index a65fa16bdb..0d4bf62168 100644 --- a/ast/src/common/mut_self_keyword.rs +++ b/ast/src/common/mut_self_keyword.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Node; -use crate::Span; +use crate::{Node, Span}; use leo_grammar::common::MutSelfKeyword as GrammarMutSelfKeyword; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// The `mut self` keyword can view and modify circuit values inside of a circuit function. diff --git a/ast/src/common/positive_number.rs b/ast/src/common/positive_number.rs index d7223c6cdb..667727b1b5 100644 --- a/ast/src/common/positive_number.rs +++ b/ast/src/common/positive_number.rs @@ -17,8 +17,7 @@ use leo_grammar::values::PositiveNumber as GrammarPositiveNumber; use leo_input::values::PositiveNumber as InputPositiveNumber; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// A number string guaranteed to be positive by the pest grammar. diff --git a/ast/src/common/self_keyword.rs b/ast/src/common/self_keyword.rs index d491c5fd95..caa9e1b7f6 100644 --- a/ast/src/common/self_keyword.rs +++ b/ast/src/common/self_keyword.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Node; -use crate::Span; +use crate::{Node, Span}; use leo_grammar::common::SelfKeyword as GrammarSelfKeyword; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// The `self` keyword can view circuit values inside of a circuit function. diff --git a/ast/src/common/span.rs b/ast/src/common/span.rs index ff2ff0f795..e6e7a70388 100644 --- a/ast/src/common/span.rs +++ b/ast/src/common/span.rs @@ -15,10 +15,8 @@ // along with the Leo library. If not, see . use pest::Span as GrammarSpan; -use serde::Deserialize; -use serde::Serialize; -use std::hash::Hash; -use std::hash::Hasher; +use serde::{Deserialize, Serialize}; +use std::hash::{Hash, Hasher}; #[derive(Clone, Debug, Default, Serialize, Deserialize)] pub struct Span { diff --git a/ast/src/common/spread_or_expression.rs b/ast/src/common/spread_or_expression.rs index 345ed83bfd..78f940a5af 100644 --- a/ast/src/common/spread_or_expression.rs +++ b/ast/src/common/spread_or_expression.rs @@ -14,14 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Node; -use crate::Span; -use leo_grammar::common::SpreadOrExpression as GrammarSpreadOrExpression; -use leo_grammar::expressions::Expression as GrammarExpression; +use crate::{Expression, Node, Span}; +use leo_grammar::{ + common::SpreadOrExpression as GrammarSpreadOrExpression, + expressions::Expression as GrammarExpression, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Spread or expression diff --git a/ast/src/errors/deprecated.rs b/ast/src/errors/deprecated.rs index 65ae83a9d5..c22419d3ee 100644 --- a/ast/src/errors/deprecated.rs +++ b/ast/src/errors/deprecated.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Error as FormattedError; -use crate::Span; -use leo_grammar::annotations::AnnotationName; -use leo_grammar::definitions::Deprecated; +use crate::{Error as FormattedError, Span}; +use leo_grammar::{annotations::AnnotationName, definitions::Deprecated}; -use std::convert::TryFrom; -use std::path::Path; +use std::{convert::TryFrom, path::Path}; #[derive(Debug, Error)] pub enum DeprecatedError { diff --git a/ast/src/errors/error.rs b/ast/src/errors/error.rs index c0fbfce73d..103b0ea9cb 100644 --- a/ast/src/errors/error.rs +++ b/ast/src/errors/error.rs @@ -16,8 +16,7 @@ use crate::Span; -use std::fmt; -use std::path::Path; +use std::{fmt, path::Path}; pub const INDENT: &str = " "; diff --git a/ast/src/expression/mod.rs b/ast/src/expression/mod.rs index 629a77b9a2..fb4050f1f2 100644 --- a/ast/src/expression/mod.rs +++ b/ast/src/expression/mod.rs @@ -14,43 +14,44 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ArrayDimensions; -use crate::CircuitImpliedVariableDefinition; -use crate::GroupValue; -use crate::Identifier; -use crate::IntegerType; -use crate::PositiveNumber; -use crate::Span; -use crate::SpreadOrExpression; -use leo_grammar::access::Access; -use leo_grammar::access::AssigneeAccess; -use leo_grammar::access::SelfAccess; -use leo_grammar::common::Assignee; -use leo_grammar::common::Identifier as GrammarIdentifier; -use leo_grammar::common::RangeOrExpression as GrammarRangeOrExpression; -use leo_grammar::expressions::ArrayInitializerExpression; -use leo_grammar::expressions::ArrayInlineExpression as GrammarArrayInlineExpression; -use leo_grammar::expressions::BinaryExpression as GrammarBinaryExpression; -use leo_grammar::expressions::CircuitInlineExpression; -use leo_grammar::expressions::Expression as GrammarExpression; -use leo_grammar::expressions::PostfixExpression; -use leo_grammar::expressions::SelfPostfixExpression; -use leo_grammar::expressions::TernaryExpression as GrammarTernaryExpression; -use leo_grammar::expressions::UnaryExpression as GrammarUnaryExpression; -use leo_grammar::operations::BinaryOperation as GrammarBinaryOperation; -use leo_grammar::operations::UnaryOperation as GrammarUnaryOperation; -use leo_grammar::values::AddressValue; -use leo_grammar::values::BooleanValue; -use leo_grammar::values::FieldValue; -use leo_grammar::values::GroupValue as GrammarGroupValue; -use leo_grammar::values::IntegerValue; -use leo_grammar::values::NumberValue as GrammarNumber; -use leo_grammar::values::Value; +use crate::{ + ArrayDimensions, + CircuitImpliedVariableDefinition, + GroupValue, + Identifier, + IntegerType, + PositiveNumber, + Span, + SpreadOrExpression, +}; +use leo_grammar::{ + access::{Access, AssigneeAccess, SelfAccess}, + common::{Assignee, Identifier as GrammarIdentifier, RangeOrExpression as GrammarRangeOrExpression}, + expressions::{ + ArrayInitializerExpression, + ArrayInlineExpression as GrammarArrayInlineExpression, + BinaryExpression as GrammarBinaryExpression, + CircuitInlineExpression, + Expression as GrammarExpression, + PostfixExpression, + SelfPostfixExpression, + TernaryExpression as GrammarTernaryExpression, + UnaryExpression as GrammarUnaryExpression, + }, + operations::{BinaryOperation as GrammarBinaryOperation, UnaryOperation as GrammarUnaryOperation}, + values::{ + AddressValue, + BooleanValue, + FieldValue, + GroupValue as GrammarGroupValue, + IntegerValue, + NumberValue as GrammarNumber, + Value, + }, +}; -use leo_grammar::access::TupleAccess; -use leo_grammar::expressions::TupleExpression; -use serde::Deserialize; -use serde::Serialize; +use leo_grammar::{access::TupleAccess, expressions::TupleExpression}; +use serde::{Deserialize, Serialize}; use std::fmt; use crate::Node; diff --git a/ast/src/functions/function.rs b/ast/src/functions/function.rs index 65b05a09cc..e9cea0c8c3 100644 --- a/ast/src/functions/function.rs +++ b/ast/src/functions/function.rs @@ -14,16 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Block; -use crate::FunctionInput; -use crate::Identifier; -use crate::Node; -use crate::Span; -use crate::Type; +use crate::{Block, FunctionInput, Identifier, Node, Span, Type}; use leo_grammar::functions::Function as GrammarFunction; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Serialize, Deserialize)] diff --git a/ast/src/functions/input/function_input.rs b/ast/src/functions/input/function_input.rs index f0c30b14d8..8cece828ad 100644 --- a/ast/src/functions/input/function_input.rs +++ b/ast/src/functions/input/function_input.rs @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Identifier; -use crate::Node; -use crate::Span; -use crate::Type; +use crate::{Identifier, Node, Span, Type}; use leo_grammar::functions::FunctionInput as GrammarFunctionInput; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/functions/input/input_variable.rs b/ast/src/functions/input/input_variable.rs index 4acef0e2c5..ecab44a959 100644 --- a/ast/src/functions/input/input_variable.rs +++ b/ast/src/functions/input/input_variable.rs @@ -14,16 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::FunctionInputVariable; -use crate::InputKeyword; -use crate::MutSelfKeyword; -use crate::Node; -use crate::SelfKeyword; -use crate::Span; +use crate::{FunctionInputVariable, InputKeyword, MutSelfKeyword, Node, SelfKeyword, Span}; use leo_grammar::functions::input::Input as GrammarInput; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Enumerates the possible inputs to a function. diff --git a/ast/src/functions/test_function.rs b/ast/src/functions/test_function.rs index b349094c46..eb9f09a346 100644 --- a/ast/src/functions/test_function.rs +++ b/ast/src/functions/test_function.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Function; -use crate::Identifier; +use crate::{Function, Identifier}; use leo_grammar::functions::TestFunction as GrammarTestFunction; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct TestFunction { diff --git a/ast/src/groups/group_coordinate.rs b/ast/src/groups/group_coordinate.rs index 675337a5d2..fd201856dd 100644 --- a/ast/src/groups/group_coordinate.rs +++ b/ast/src/groups/group_coordinate.rs @@ -15,19 +15,22 @@ // along with the Leo library. If not, see . use crate::common::span::Span; -use leo_grammar::values::GroupCoordinate as GrammarGroupCoordinate; -use leo_grammar::values::Inferred as GrammarInferred; -use leo_grammar::values::NumberValue as GrammarNumberValue; -use leo_grammar::values::SignHigh as GrammarSignHigh; -use leo_grammar::values::SignLow as GrammarSignLow; -use leo_input::values::GroupCoordinate as InputGroupCoordinate; -use leo_input::values::Inferred as InputInferred; -use leo_input::values::NumberValue as InputNumberValue; -use leo_input::values::SignHigh as InputSignHigh; -use leo_input::values::SignLow as InputSignLow; +use leo_grammar::values::{ + GroupCoordinate as GrammarGroupCoordinate, + Inferred as GrammarInferred, + NumberValue as GrammarNumberValue, + SignHigh as GrammarSignHigh, + SignLow as GrammarSignLow, +}; +use leo_input::values::{ + GroupCoordinate as InputGroupCoordinate, + Inferred as InputInferred, + NumberValue as InputNumberValue, + SignHigh as InputSignHigh, + SignLow as InputSignLow, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/groups/group_value.rs b/ast/src/groups/group_value.rs index 32872fb32d..5e0c42113e 100644 --- a/ast/src/groups/group_value.rs +++ b/ast/src/groups/group_value.rs @@ -14,17 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::common::span::Span; -use crate::groups::GroupCoordinate; -use leo_grammar::values::GroupRepresentation as GrammarGroupRepresentation; -use leo_grammar::values::GroupTuple as GrammarGroupTuple; -use leo_grammar::values::GroupValue as GrammarGroupValue; -use leo_input::values::GroupRepresentation as InputGroupRepresentation; -use leo_input::values::GroupTuple as InputGroupTuple; -use leo_input::values::GroupValue as InputGroupValue; +use crate::{common::span::Span, groups::GroupCoordinate}; +use leo_grammar::values::{ + GroupRepresentation as GrammarGroupRepresentation, + GroupTuple as GrammarGroupTuple, + GroupValue as GrammarGroupValue, +}; +use leo_input::values::{ + GroupRepresentation as InputGroupRepresentation, + GroupTuple as InputGroupTuple, + GroupValue as InputGroupValue, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/imports/import.rs b/ast/src/imports/import.rs index 8e0d02770f..246f61c3b1 100644 --- a/ast/src/imports/import.rs +++ b/ast/src/imports/import.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::PackageOrPackages; -use crate::Span; +use crate::{PackageOrPackages, Span}; use leo_grammar::imports::Import as GrammarImport; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Represents an import statement in a Leo program. diff --git a/ast/src/imports/import_symbol.rs b/ast/src/imports/import_symbol.rs index c447624023..20d8650793 100644 --- a/ast/src/imports/import_symbol.rs +++ b/ast/src/imports/import_symbol.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Identifier; -use crate::Span; +use crate::{Identifier, Span}; use leo_grammar::imports::ImportSymbol as GrammarImportSymbol; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/package.rs b/ast/src/imports/package.rs index fec57b1fa3..091e72142d 100644 --- a/ast/src/imports/package.rs +++ b/ast/src/imports/package.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::common::Identifier; -use crate::PackageAccess; -use crate::Span; +use crate::{common::Identifier, PackageAccess, Span}; use leo_grammar::imports::Package as GrammarPackage; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/package_access.rs b/ast/src/imports/package_access.rs index ade92faed3..b329cc6b82 100644 --- a/ast/src/imports/package_access.rs +++ b/ast/src/imports/package_access.rs @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ImportSymbol; -use crate::Package; -use crate::Packages; -use crate::Span; +use crate::{ImportSymbol, Package, Packages, Span}; use leo_grammar::imports::PackageAccess as GrammarPackageAccess; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/package_or_packages.rs b/ast/src/imports/package_or_packages.rs index 0be227fd26..2f1b9bc717 100644 --- a/ast/src/imports/package_or_packages.rs +++ b/ast/src/imports/package_or_packages.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Package; -use crate::Packages; +use crate::{Package, Packages}; use leo_grammar::imports::PackageOrPackages as GrammarPackageOrPackages; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/imports/packages.rs b/ast/src/imports/packages.rs index 420c401ef7..fab9542716 100644 --- a/ast/src/imports/packages.rs +++ b/ast/src/imports/packages.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::common::Identifier; -use crate::PackageAccess; -use crate::Span; +use crate::{common::Identifier, PackageAccess, Span}; use leo_grammar::imports::Packages as GrammarPackages; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Eq, Hash, PartialEq, Serialize, Deserialize)] diff --git a/ast/src/input/input.rs b/ast/src/input/input.rs index a72577dc3a..ae201c2aec 100644 --- a/ast/src/input/input.rs +++ b/ast/src/input/input.rs @@ -14,17 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputValue; -use crate::MainInput; -use crate::ProgramInput; -use crate::ProgramState; -use crate::Record; -use crate::Registers; -use crate::State; -use crate::StateLeaf; -use leo_input::files::File; -use leo_input::files::TableOrSection; -use leo_input::InputParserError; +use crate::{InputValue, MainInput, ProgramInput, ProgramState, Record, Registers, State, StateLeaf}; +use leo_input::{ + files::{File, TableOrSection}, + InputParserError, +}; #[derive(Clone, PartialEq, Eq)] pub struct Input { diff --git a/ast/src/input/input_value.rs b/ast/src/input/input_value.rs index ffbd5ce4e4..5d6fba2a9e 100644 --- a/ast/src/input/input_value.rs +++ b/ast/src/input/input_value.rs @@ -14,25 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ArrayDimensions; -use crate::GroupValue; -use leo_input::errors::InputParserError; -use leo_input::expressions::ArrayInitializerExpression; -use leo_input::expressions::ArrayInlineExpression; -use leo_input::expressions::Expression; -use leo_input::expressions::TupleExpression; -use leo_input::types::ArrayType; -use leo_input::types::DataType; -use leo_input::types::IntegerType; -use leo_input::types::TupleType; -use leo_input::types::Type; -use leo_input::values::Address; -use leo_input::values::AddressValue; -use leo_input::values::BooleanValue; -use leo_input::values::FieldValue; -use leo_input::values::GroupValue as InputGroupValue; -use leo_input::values::NumberValue; -use leo_input::values::Value; +use crate::{ArrayDimensions, GroupValue}; +use leo_input::{ + errors::InputParserError, + expressions::{ArrayInitializerExpression, ArrayInlineExpression, Expression, TupleExpression}, + types::{ArrayType, DataType, IntegerType, TupleType, Type}, + values::{Address, AddressValue, BooleanValue, FieldValue, GroupValue as InputGroupValue, NumberValue, Value}, +}; use pest::Span; use std::fmt; diff --git a/ast/src/input/parameters/parameter.rs b/ast/src/input/parameters/parameter.rs index 4031d57795..7f275f2fea 100644 --- a/ast/src/input/parameters/parameter.rs +++ b/ast/src/input/parameters/parameter.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Identifier; -use crate::Span; -use crate::Type; +use crate::{Identifier, Span, Type}; use leo_input::parameters::Parameter as GrammarParameter; #[derive(Clone, PartialEq, Eq, Hash)] diff --git a/ast/src/input/program_input/main_input.rs b/ast/src/input/program_input/main_input.rs index 5683d3f161..7d1b496134 100644 --- a/ast/src/input/program_input/main_input.rs +++ b/ast/src/input/program_input/main_input.rs @@ -15,8 +15,7 @@ // along with the Leo library. If not, see . use crate::InputValue; -use leo_input::definitions::Definition; -use leo_input::InputParserError; +use leo_input::{definitions::Definition, InputParserError}; use indexmap::IndexMap; diff --git a/ast/src/input/program_input/program_input.rs b/ast/src/input/program_input/program_input.rs index 17e933f211..42efab1a25 100644 --- a/ast/src/input/program_input/program_input.rs +++ b/ast/src/input/program_input/program_input.rs @@ -14,12 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputValue; -use crate::MainInput; -use crate::Registers; -use leo_input::sections::Header; -use leo_input::sections::Section; -use leo_input::InputParserError; +use crate::{InputValue, MainInput, Registers}; +use leo_input::{ + sections::{Header, Section}, + InputParserError, +}; #[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramInput { diff --git a/ast/src/input/program_input/registers.rs b/ast/src/input/program_input/registers.rs index 5478e5df3a..21e25030e3 100644 --- a/ast/src/input/program_input/registers.rs +++ b/ast/src/input/program_input/registers.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputValue; -use crate::Parameter; -use leo_input::definitions::Definition; -use leo_input::InputParserError; +use crate::{InputValue, Parameter}; +use leo_input::{definitions::Definition, InputParserError}; use indexmap::IndexMap; diff --git a/ast/src/input/program_state/private_state/private_state.rs b/ast/src/input/program_state/private_state/private_state.rs index 895674d711..f7f1f9edc9 100644 --- a/ast/src/input/program_state/private_state/private_state.rs +++ b/ast/src/input/program_state/private_state/private_state.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Record; -use crate::StateLeaf; -use leo_input::sections::Header; -use leo_input::sections::Section; -use leo_input::InputParserError; +use crate::{Record, StateLeaf}; +use leo_input::{ + sections::{Header, Section}, + InputParserError, +}; #[derive(Clone, PartialEq, Eq, Default)] pub struct PrivateState { diff --git a/ast/src/input/program_state/private_state/record.rs b/ast/src/input/program_state/private_state/record.rs index 7439c57bd5..4cb71920aa 100644 --- a/ast/src/input/program_state/private_state/record.rs +++ b/ast/src/input/program_state/private_state/record.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputValue; -use crate::Parameter; -use leo_input::definitions::Definition; -use leo_input::InputParserError; +use crate::{InputValue, Parameter}; +use leo_input::{definitions::Definition, InputParserError}; use indexmap::IndexMap; diff --git a/ast/src/input/program_state/private_state/state_leaf.rs b/ast/src/input/program_state/private_state/state_leaf.rs index 138d053b34..8e9b0e231b 100644 --- a/ast/src/input/program_state/private_state/state_leaf.rs +++ b/ast/src/input/program_state/private_state/state_leaf.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputValue; -use crate::Parameter; -use leo_input::definitions::Definition; -use leo_input::InputParserError; +use crate::{InputValue, Parameter}; +use leo_input::{definitions::Definition, InputParserError}; use indexmap::IndexMap; diff --git a/ast/src/input/program_state/program_state.rs b/ast/src/input/program_state/program_state.rs index 693c88fdc5..04275d176c 100644 --- a/ast/src/input/program_state/program_state.rs +++ b/ast/src/input/program_state/program_state.rs @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::PrivateState; -use crate::PublicState; -use crate::Record; -use crate::State; -use crate::StateLeaf; -use leo_input::tables::Table; -use leo_input::tables::Visibility; -use leo_input::InputParserError; +use crate::{PrivateState, PublicState, Record, State, StateLeaf}; +use leo_input::{ + tables::{Table, Visibility}, + InputParserError, +}; #[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramState { diff --git a/ast/src/input/program_state/public_state/public_state.rs b/ast/src/input/program_state/public_state/public_state.rs index 7fe4acd2a2..995aa06759 100644 --- a/ast/src/input/program_state/public_state/public_state.rs +++ b/ast/src/input/program_state/public_state/public_state.rs @@ -15,9 +15,10 @@ // along with the Leo library. If not, see . use crate::State; -use leo_input::sections::Header; -use leo_input::sections::Section; -use leo_input::InputParserError; +use leo_input::{ + sections::{Header, Section}, + InputParserError, +}; #[derive(Clone, PartialEq, Eq, Default)] pub struct PublicState { diff --git a/ast/src/input/program_state/public_state/state.rs b/ast/src/input/program_state/public_state/state.rs index 04d32b6db2..dda85ddf94 100644 --- a/ast/src/input/program_state/public_state/state.rs +++ b/ast/src/input/program_state/public_state/state.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputValue; -use crate::Parameter; -use leo_input::definitions::Definition; -use leo_input::InputParserError; +use crate::{InputValue, Parameter}; +use leo_input::{definitions::Definition, InputParserError}; use indexmap::IndexMap; diff --git a/ast/src/main.rs b/ast/src/main.rs index 19f34a4e50..02f627cc4a 100644 --- a/ast/src/main.rs +++ b/ast/src/main.rs @@ -14,12 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Ast; -use leo_ast::AstError; +use leo_ast::{Ast, AstError}; use leo_grammar::Grammar; -use std::env; -use std::fs; -use std::path::Path; +use std::{env, fs, path::Path}; fn to_leo_tree(filepath: &Path) -> Result { // Loads the Leo code as a string from the given file path. diff --git a/ast/src/program.rs b/ast/src/program.rs index 9a669f25f0..531a6316bb 100644 --- a/ast/src/program.rs +++ b/ast/src/program.rs @@ -17,20 +17,20 @@ //! A Leo program consists of import, circuit, and function definitions. //! Each defined type consists of ast statements and expressions. -use crate::load_annotation; -use crate::Circuit; -use crate::DeprecatedError; -use crate::Function; -use crate::FunctionInput; -use crate::Identifier; -use crate::ImportStatement; -use crate::TestFunction; -use leo_grammar::definitions::Definition; -use leo_grammar::files::File; +use crate::{ + load_annotation, + Circuit, + DeprecatedError, + Function, + FunctionInput, + Identifier, + ImportStatement, + TestFunction, +}; +use leo_grammar::{definitions::Definition, files::File}; use indexmap::IndexMap; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Stores the Leo program abstract syntax tree. diff --git a/ast/src/statements/assign/assignee.rs b/ast/src/statements/assign/assignee.rs index 98dae1a57e..e84cccf2a9 100644 --- a/ast/src/statements/assign/assignee.rs +++ b/ast/src/statements/assign/assignee.rs @@ -14,18 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Identifier; -use crate::PositiveNumber; -use crate::Span; -use leo_grammar::access::ArrayAccess; -use leo_grammar::access::AssigneeAccess as GrammarAssigneeAccess; -use leo_grammar::common::Assignee as GrammarAssignee; -use leo_grammar::common::Range; -use leo_grammar::common::RangeOrExpression; +use crate::{Expression, Identifier, PositiveNumber, Span}; +use leo_grammar::{ + access::{ArrayAccess, AssigneeAccess as GrammarAssigneeAccess}, + common::{Assignee as GrammarAssignee, Range, RangeOrExpression}, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/assign/mod.rs b/ast/src/statements/assign/mod.rs index fa729749d8..947472d14c 100644 --- a/ast/src/statements/assign/mod.rs +++ b/ast/src/statements/assign/mod.rs @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Node; -use crate::Span; +use crate::{Expression, Node, Span}; pub use leo_grammar::operations::AssignOperation as GrammarAssignOperation; use leo_grammar::statements::AssignStatement as GrammarAssignStatement; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; mod assignee; diff --git a/ast/src/statements/block.rs b/ast/src/statements/block.rs index db0ccc8028..d6cb72f26f 100644 --- a/ast/src/statements/block.rs +++ b/ast/src/statements/block.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Node; -use crate::Span; -use crate::Statement; +use crate::{Node, Span, Statement}; use leo_grammar::statements::Block as GrammarBlock; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/conditional.rs b/ast/src/statements/conditional.rs index 7ea09f39e3..cf836ef3ed 100644 --- a/ast/src/statements/conditional.rs +++ b/ast/src/statements/conditional.rs @@ -14,16 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Block; -use crate::Expression; -use crate::Node; -use crate::Span; -use crate::Statement; -use leo_grammar::statements::ConditionalNestedOrEndStatement; -use leo_grammar::statements::ConditionalStatement as GrammarConditionalStatement; +use crate::{Block, Expression, Node, Span, Statement}; +use leo_grammar::statements::{ConditionalNestedOrEndStatement, ConditionalStatement as GrammarConditionalStatement}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/console/console_function.rs b/ast/src/statements/console/console_function.rs index 6bbad1da57..7e9f9892ca 100644 --- a/ast/src/statements/console/console_function.rs +++ b/ast/src/statements/console/console_function.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::FormattedString; -use leo_grammar::console::ConsoleAssert as GrammarConsoleAssert; -use leo_grammar::console::ConsoleDebug as GrammarConsoleDebug; -use leo_grammar::console::ConsoleError as GrammarConsoleError; -use leo_grammar::console::ConsoleFunction as GrammarConsoleFunction; -use leo_grammar::console::ConsoleLog as GrammarConsoleLog; +use crate::{Expression, FormattedString}; +use leo_grammar::console::{ + ConsoleAssert as GrammarConsoleAssert, + ConsoleDebug as GrammarConsoleDebug, + ConsoleError as GrammarConsoleError, + ConsoleFunction as GrammarConsoleFunction, + ConsoleLog as GrammarConsoleLog, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/console/console_statement.rs b/ast/src/statements/console/console_statement.rs index d51b4d8670..ad837f42f5 100644 --- a/ast/src/statements/console/console_statement.rs +++ b/ast/src/statements/console/console_statement.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ConsoleFunction; -use crate::Node; -use crate::Span; +use crate::{ConsoleFunction, Node, Span}; use leo_grammar::console::ConsoleFunctionCall as GrammarConsoleFunctionCall; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/console/formatted_container.rs b/ast/src/statements/console/formatted_container.rs index 1c35df5981..4634aa4c4a 100644 --- a/ast/src/statements/console/formatted_container.rs +++ b/ast/src/statements/console/formatted_container.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Node; -use crate::Span; +use crate::{Node, Span}; use leo_grammar::console::FormattedContainer as GrammarFormattedContainer; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/console/formatted_string.rs b/ast/src/statements/console/formatted_string.rs index e94f6175be..f96baa1fe1 100644 --- a/ast/src/statements/console/formatted_string.rs +++ b/ast/src/statements/console/formatted_string.rs @@ -14,14 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::FormattedContainer; -use crate::Node; -use crate::Span; +use crate::{Expression, FormattedContainer, Node, Span}; use leo_grammar::console::FormattedString as GrammarFormattedString; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/definition/declare.rs b/ast/src/statements/definition/declare.rs index 799702fa28..de00d5f210 100644 --- a/ast/src/statements/definition/declare.rs +++ b/ast/src/statements/definition/declare.rs @@ -16,8 +16,7 @@ use leo_grammar::common::Declare as GrammarDeclare; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/definition/mod.rs b/ast/src/statements/definition/mod.rs index ac24a4a37b..78ad5ea933 100644 --- a/ast/src/statements/definition/mod.rs +++ b/ast/src/statements/definition/mod.rs @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Node; -use crate::Span; -use crate::Type; +use crate::{Expression, Node, Span, Type}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; mod variable_name; diff --git a/ast/src/statements/definition/variable_name.rs b/ast/src/statements/definition/variable_name.rs index fa27f9c20f..7384b8ee1d 100644 --- a/ast/src/statements/definition/variable_name.rs +++ b/ast/src/statements/definition/variable_name.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Identifier; -use crate::Node; -use crate::Span; +use crate::{Identifier, Node, Span}; use leo_grammar::common::VariableName as GrammarVariableName; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] diff --git a/ast/src/statements/expression.rs b/ast/src/statements/expression.rs index 542da065ca..f9ff66313c 100644 --- a/ast/src/statements/expression.rs +++ b/ast/src/statements/expression.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Node; -use crate::Span; +use crate::{Expression, Node, Span}; use leo_grammar::statements::ExpressionStatement as GrammarExpressionStatement; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/iteration.rs b/ast/src/statements/iteration.rs index 74afb710fd..70126ff8ad 100644 --- a/ast/src/statements/iteration.rs +++ b/ast/src/statements/iteration.rs @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Block; -use crate::Expression; -use crate::Identifier; -use crate::Node; -use crate::Span; +use crate::{Block, Expression, Identifier, Node, Span}; use leo_grammar::statements::ForStatement; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/return_statement.rs b/ast/src/statements/return_statement.rs index 6de10692fa..e1279b09c2 100644 --- a/ast/src/statements/return_statement.rs +++ b/ast/src/statements/return_statement.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Expression; -use crate::Node; -use crate::Span; +use crate::{Expression, Node, Span}; use leo_grammar::statements::ReturnStatement as GrammarReturnStatement; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] diff --git a/ast/src/statements/statement.rs b/ast/src/statements/statement.rs index f44b62a262..31067093e7 100644 --- a/ast/src/statements/statement.rs +++ b/ast/src/statements/statement.rs @@ -14,15 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ConditionalStatement; -use crate::Node; -use crate::Span; +use crate::{ConditionalStatement, Node, Span}; use leo_grammar::statements::Statement as GrammarStatement; use super::*; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Program statement that defines some action (or expression) to be carried out. diff --git a/ast/src/types/integer_type.rs b/ast/src/types/integer_type.rs index d667fe7259..1ced1e76f7 100644 --- a/ast/src/types/integer_type.rs +++ b/ast/src/types/integer_type.rs @@ -14,15 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::types::IntegerType as GrammarIntegerType; -use leo_grammar::types::SignedIntegerType as GrammarSignedIntegerType; -use leo_grammar::types::UnsignedIntegerType as GrammarUnsignedIntegerType; -use leo_input::types::IntegerType as InputIntegerType; -use leo_input::types::SignedIntegerType as InputSignedIntegerType; -use leo_input::types::UnsignedIntegerType as InputUnsignedIntegerType; +use leo_grammar::types::{ + IntegerType as GrammarIntegerType, + SignedIntegerType as GrammarSignedIntegerType, + UnsignedIntegerType as GrammarUnsignedIntegerType, +}; +use leo_input::types::{ + IntegerType as InputIntegerType, + SignedIntegerType as InputSignedIntegerType, + UnsignedIntegerType as InputUnsignedIntegerType, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Explicit integer type diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index 0ad451a8c4..1d20699c31 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -14,21 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ArrayDimensions; -use crate::Identifier; -use crate::IntegerType; -use leo_grammar::types::ArrayType; -use leo_grammar::types::CircuitType; -use leo_grammar::types::DataType; -use leo_grammar::types::TupleType; -use leo_grammar::types::Type as GrammarType; -use leo_input::types::ArrayType as InputArrayType; -use leo_input::types::DataType as InputDataType; -use leo_input::types::TupleType as InputTupleType; -use leo_input::types::Type as InputType; +use crate::{ArrayDimensions, Identifier, IntegerType}; +use leo_grammar::types::{ArrayType, CircuitType, DataType, TupleType, Type as GrammarType}; +use leo_input::types::{ + ArrayType as InputArrayType, + DataType as InputDataType, + TupleType as InputTupleType, + Type as InputType, +}; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use std::fmt; /// Explicit type used for defining a variable or expression type diff --git a/ast/tests/serialization/json.rs b/ast/tests/serialization/json.rs index 4257cc9af3..5a58ff12c5 100644 --- a/ast/tests/serialization/json.rs +++ b/ast/tests/serialization/json.rs @@ -14,15 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Ast; -use leo_ast::AstError; #[cfg(not(feature = "ci_skip"))] use leo_ast::Program; -use leo_grammar::Grammar; -use leo_grammar::ParserError; +use leo_ast::{Ast, AstError}; +use leo_grammar::{Grammar, ParserError}; -use std::path::Path; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; fn to_ast(program_filepath: &Path) -> Result { // Loads the Leo code as a string from the given file path. diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 55195e043e..9410ca7100 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -16,39 +16,32 @@ //! Compiles a Leo program from a file path. -use crate::constraints::generate_constraints; -use crate::constraints::generate_test_constraints; -use crate::errors::CompilerError; -use crate::GroupType; -use crate::OutputBytes; -use crate::OutputFile; +use crate::{ + constraints::{generate_constraints, generate_test_constraints}, + errors::CompilerError, + GroupType, + OutputBytes, + OutputFile, +}; use leo_asg::Asg; -use leo_ast::Ast; -use leo_ast::Input; -use leo_ast::MainInput; -use leo_ast::Program; +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 snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_dpc::SystemParameters; +use snarkvm_dpc::{base_dpc::instantiated::Components, SystemParameters}; use snarkvm_fields::PrimeField; -use snarkvm_r1cs::ConstraintSynthesizer; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::{ConstraintSynthesizer, ConstraintSystem, SynthesisError}; -use sha2::Digest; -use sha2::Sha256; -use std::fs; -use std::marker::PhantomData; -use std::path::Path; -use std::path::PathBuf; +use sha2::{Digest, Sha256}; +use std::{ + fs, + marker::PhantomData, + path::{Path, PathBuf}, +}; -pub use leo_asg::new_context; -pub use leo_asg::AsgContext as Context; -pub use leo_asg::AsgContext; +pub use leo_asg::{new_context, AsgContext as Context, AsgContext}; thread_local! { static THREAD_GLOBAL_CONTEXT: AsgContext<'static> = { diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index deb4abf99c..cab7f1cf11 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -16,13 +16,14 @@ //! Enforces an assert equals statement in a compiled Leo program. -use crate::errors::ConsoleError; -use crate::get_indicator_value; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Span; +use crate::{ + errors::ConsoleError, + get_indicator_value, + program::ConstrainedProgram, + value::ConstrainedValue, + GroupType, +}; +use leo_asg::{Expression, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::boolean::Boolean; diff --git a/compiler/src/console/console.rs b/compiler/src/console/console.rs index d6765f7ae8..90c490aefc 100644 --- a/compiler/src/console/console.rs +++ b/compiler/src/console/console.rs @@ -16,12 +16,8 @@ //! Evaluates a macro in a compiled Leo program. -use crate::errors::ConsoleError; -use crate::program::ConstrainedProgram; -use crate::statement::get_indicator_value; -use crate::GroupType; -use leo_asg::ConsoleFunction; -use leo_asg::ConsoleStatement; +use crate::{errors::ConsoleError, program::ConstrainedProgram, statement::get_indicator_value, GroupType}; +use leo_asg::{ConsoleFunction, ConsoleStatement}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::boolean::Boolean; diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index 6154039232..2a20f389ac 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -16,9 +16,7 @@ //! Evaluates a formatted string in a compiled Leo program. -use crate::errors::ConsoleError; -use crate::program::ConstrainedProgram; -use crate::GroupType; +use crate::{errors::ConsoleError, program::ConstrainedProgram, GroupType}; use leo_asg::FormattedString; use snarkvm_fields::PrimeField; diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 5b02a313bb..a1d574cfba 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -16,19 +16,14 @@ //! Generates R1CS constraints for a compiled Leo program. -use crate::errors::CompilerError; -use crate::ConstrainedProgram; -use crate::GroupType; -use crate::OutputBytes; -use crate::OutputFile; +use crate::{errors::CompilerError, ConstrainedProgram, GroupType, OutputBytes, OutputFile}; use leo_asg::Asg; use leo_ast::Input; use leo_input::LeoInputParser; use leo_package::inputs::InputPairs; use snarkvm_fields::PrimeField; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_r1cs::{ConstraintSystem, TestConstraintSystem}; use std::path::Path; pub fn generate_constraints<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/definition/definition.rs b/compiler/src/definition/definition.rs index a542b0e565..5c36b80388 100644 --- a/compiler/src/definition/definition.rs +++ b/compiler/src/definition/definition.rs @@ -16,9 +16,7 @@ //! Stores all defined names in a compiled Leo program. -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Variable; use snarkvm_fields::PrimeField; diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index 4fb6e9f09e..c8e7b496a9 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::FunctionError; -use crate::errors::ImportError; -use crate::errors::OutputBytesError; -use crate::errors::OutputFileError; +use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; use leo_asg::AsgConvertError; use leo_ast::AstError; use leo_grammar::ParserError; @@ -26,8 +23,7 @@ use leo_input::InputParserError; use leo_state::LocalDataVerificationError; use bincode::Error as SerdeError; -use std::path::Path; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; #[derive(Debug, Error)] pub enum CompilerError { diff --git a/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index f16baf21c7..c68a0035dd 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -15,8 +15,7 @@ // along with the Leo library. If not, see . use crate::errors::ExpressionError; -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use std::path::Path; diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index e109e7fdb8..ac58aada16 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -14,18 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::AddressError; -use crate::errors::BooleanError; -use crate::errors::FieldError; -use crate::errors::FunctionError; -use crate::errors::GroupError; -use crate::errors::IntegerError; -use crate::errors::ValueError; -use leo_ast::ArrayDimensions; -use leo_ast::Error as FormattedError; -use leo_ast::Identifier; -use leo_ast::PositiveNumber; -use leo_ast::Span; +use crate::errors::{AddressError, BooleanError, FieldError, FunctionError, GroupError, IntegerError, ValueError}; +use leo_ast::{ArrayDimensions, Error as FormattedError, Identifier, PositiveNumber, Span}; use snarkvm_r1cs::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/function.rs b/compiler/src/errors/function.rs index 4c66df6de3..5422761581 100644 --- a/compiler/src/errors/function.rs +++ b/compiler/src/errors/function.rs @@ -14,18 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::AddressError; -use crate::errors::BooleanError; -use crate::errors::ExpressionError; -use crate::errors::FieldError; -use crate::errors::GroupError; -use crate::errors::IntegerError; -use crate::errors::OutputBytesError; -use crate::errors::StatementError; -use crate::errors::ValueError; +use crate::errors::{ + AddressError, + BooleanError, + ExpressionError, + FieldError, + GroupError, + IntegerError, + OutputBytesError, + StatementError, + ValueError, +}; use leo_asg::AsgConvertError; -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use std::path::Path; diff --git a/compiler/src/errors/import.rs b/compiler/src/errors/import.rs index 325c2d3789..74ee48cc83 100644 --- a/compiler/src/errors/import.rs +++ b/compiler/src/errors/import.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Error as FormattedError; -use leo_ast::Identifier; -use leo_ast::ImportSymbol; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Identifier, ImportSymbol, Span}; #[derive(Debug, Error)] pub enum ImportError { diff --git a/compiler/src/errors/output_bytes.rs b/compiler/src/errors/output_bytes.rs index d1cb4508e5..71649b0910 100644 --- a/compiler/src/errors/output_bytes.rs +++ b/compiler/src/errors/output_bytes.rs @@ -15,10 +15,8 @@ // along with the Leo library. If not, see . use crate::errors::ValueError; -use leo_asg::AsgConvertError; -use leo_asg::Type; -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_asg::{AsgConvertError, Type}; +use leo_ast::{Error as FormattedError, Span}; use std::path::Path; diff --git a/compiler/src/errors/output_file.rs b/compiler/src/errors/output_file.rs index 0d584ea0d3..c8b18185d6 100644 --- a/compiler/src/errors/output_file.rs +++ b/compiler/src/errors/output_file.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum OutputFileError { diff --git a/compiler/src/errors/statement.rs b/compiler/src/errors/statement.rs index c35c2d155a..d915d40dff 100644 --- a/compiler/src/errors/statement.rs +++ b/compiler/src/errors/statement.rs @@ -14,15 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::AddressError; -use crate::errors::BooleanError; -use crate::errors::ConsoleError; -use crate::errors::ExpressionError; -use crate::errors::IntegerError; -use crate::errors::ValueError; +use crate::errors::{AddressError, BooleanError, ConsoleError, ExpressionError, IntegerError, ValueError}; use leo_asg::Type; -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use std::path::Path; diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index 4cd9889c8f..a6dfdd840d 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use snarkvm_dpc::AccountError; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/errors/value/boolean.rs b/compiler/src/errors/value/boolean.rs index e6472dfaf1..7f7c264148 100644 --- a/compiler/src/errors/value/boolean.rs +++ b/compiler/src/errors/value/boolean.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use snarkvm_r1cs::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/value/field.rs b/compiler/src/errors/value/field.rs index f1e2c2e152..0a6766f3e1 100644 --- a/compiler/src/errors/value/field.rs +++ b/compiler/src/errors/value/field.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use snarkvm_r1cs::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index 1bfa2c53f7..e83d8af596 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use leo_ast::{Error as FormattedError, Span}; use snarkvm_r1cs::SynthesisError; use std::path::Path; diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index 6aabfe6dd2..bd8f44cad3 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::error::Error as FormattedError; -use leo_ast::IntegerType; -use leo_ast::Span; -use leo_ast::Type; +use leo_ast::{error::Error as FormattedError, IntegerType, Span, Type}; use leo_gadgets::errors::SignedIntegerError; use snarkvm_r1cs::SynthesisError; diff --git a/compiler/src/errors/value/value.rs b/compiler/src/errors/value/value.rs index cd478445c4..66a7d50e83 100644 --- a/compiler/src/errors/value/value.rs +++ b/compiler/src/errors/value/value.rs @@ -14,13 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::AddressError; -use crate::errors::BooleanError; -use crate::errors::FieldError; -use crate::errors::GroupError; -use crate::errors::IntegerError; -use leo_ast::Error as FormattedError; -use leo_ast::Span; +use crate::errors::{AddressError, BooleanError, FieldError, GroupError, IntegerError}; +use leo_ast::{Error as FormattedError, Span}; use std::path::Path; diff --git a/compiler/src/expression/arithmetic/add.rs b/compiler/src/expression/arithmetic/add.rs index 4086114e4b..67baf70950 100644 --- a/compiler/src/expression/arithmetic/add.rs +++ b/compiler/src/expression/arithmetic/add.rs @@ -16,9 +16,7 @@ //! Enforces an arithmetic `+` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_ast::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index b0fd7dc2b5..37fec2c641 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -16,9 +16,7 @@ //! Enforces an arithmetic `/` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_ast::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index 88204ff7e0..995ba21002 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -16,9 +16,7 @@ //! Enforces an arithmetic `*` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_ast::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/arithmetic/negate.rs b/compiler/src/expression/arithmetic/negate.rs index e4ad3dfadd..bee6106f34 100644 --- a/compiler/src/expression/arithmetic/negate.rs +++ b/compiler/src/expression/arithmetic/negate.rs @@ -16,9 +16,7 @@ //! Enforces a unary negate `-` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_ast::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/arithmetic/pow.rs b/compiler/src/expression/arithmetic/pow.rs index 3ec3db06a0..48230b49e6 100644 --- a/compiler/src/expression/arithmetic/pow.rs +++ b/compiler/src/expression/arithmetic/pow.rs @@ -16,9 +16,7 @@ //! Enforces an arithmetic `**` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_ast::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/arithmetic/sub.rs b/compiler/src/expression/arithmetic/sub.rs index 8a12764a79..a86c154956 100644 --- a/compiler/src/expression/arithmetic/sub.rs +++ b/compiler/src/expression/arithmetic/sub.rs @@ -16,9 +16,7 @@ //! Enforces an arithmetic `-` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_ast::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 371a195e19..363f552087 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -16,12 +16,8 @@ //! Enforces array access in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Span; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{Expression, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index d904356a49..0630bf0869 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -18,12 +18,8 @@ use std::cell::Cell; -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Span; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{Expression, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index fe281f85de..1b5dde5a67 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -16,12 +16,8 @@ //! Enforces an array index expression in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Span; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{Expression, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index 2bab64f405..d5b250d507 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -16,10 +16,7 @@ //! Enforces a binary expression in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 047d8fb32c..87e6ec7320 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -16,12 +16,8 @@ //! Enforces a circuit access expression in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::CircuitAccessExpression; -use leo_asg::Node; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{CircuitAccessExpression, Node}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index 6e25db67a5..7ad2eb7079 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -16,14 +16,13 @@ //! Enforces a circuit expression in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedCircuitMember; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::CircuitInitExpression; -use leo_asg::CircuitMember; -use leo_asg::Span; +use crate::{ + errors::ExpressionError, + program::ConstrainedProgram, + value::{ConstrainedCircuitMember, ConstrainedValue}, + GroupType, +}; +use leo_asg::{CircuitInitExpression, CircuitMember, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index 572c7ec737..0fab6b027b 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -16,12 +16,8 @@ //! Enforces a conditional expression in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Span; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{Expression, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 46e7021ba1..49eaf97a5b 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -16,21 +16,18 @@ //! Enforce constraints on an expression in a compiled Leo program. -use crate::arithmetic::*; -use crate::errors::ExpressionError; -use crate::logical::*; -use crate::program::ConstrainedProgram; -use crate::relational::*; -use crate::resolve_core_circuit; -use crate::value::Address; -use crate::value::ConstrainedValue; -use crate::value::Integer; -use crate::FieldType; -use crate::GroupType; -use leo_asg::expression::*; -use leo_asg::ConstValue; -use leo_asg::Expression; -use leo_asg::Node; +use crate::{ + arithmetic::*, + errors::ExpressionError, + logical::*, + program::ConstrainedProgram, + relational::*, + resolve_core_circuit, + value::{Address, ConstrainedValue, Integer}, + FieldType, + GroupType, +}; +use leo_asg::{expression::*, ConstValue, Expression, Node}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::boolean::Boolean; diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 0c8ffa808a..c1a467724d 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -16,15 +16,10 @@ use std::cell::Cell; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::CoreCircuit; -use crate::GroupType; +use crate::{program::ConstrainedProgram, value::ConstrainedValue, CoreCircuit, GroupType}; use crate::errors::ExpressionError; -use leo_asg::Expression; -use leo_asg::Function; -use leo_asg::Span; +use leo_asg::{Expression, Function, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index 5ef05dacb8..3276918328 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -18,13 +18,8 @@ use std::cell::Cell; -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Function; -use leo_asg::Span; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{Expression, Function, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 6243fb3698..623feb844c 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -16,9 +16,7 @@ //! Enforces a logical `&&` operator in a resolved Leo program. -use crate::errors::BooleanError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/logical/not.rs b/compiler/src/expression/logical/not.rs index 3e7022bd57..06556dc13f 100644 --- a/compiler/src/expression/logical/not.rs +++ b/compiler/src/expression/logical/not.rs @@ -16,9 +16,7 @@ //! Enforces a logical `!` operator in a resolved Leo program. -use crate::errors::BooleanError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index d8e42df918..b6e37fd459 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -16,9 +16,7 @@ //! Enforces a logical `||` operator in a resolved Leo program. -use crate::errors::BooleanError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/relational/eq.rs b/compiler/src/expression/relational/eq.rs index 29fb597390..325a35f466 100644 --- a/compiler/src/expression/relational/eq.rs +++ b/compiler/src/expression/relational/eq.rs @@ -16,15 +16,11 @@ //! Enforces a relational `==` operator in a resolved Leo program. -use crate::enforce_and; -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{enforce_and, errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, eq::EvaluateEqGadget}; use snarkvm_r1cs::ConstraintSystem; pub fn evaluate_eq<'a, F: PrimeField, G: GroupType, CS: ConstraintSystem>( diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index faa4f7c69a..18e44ff0c8 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -16,9 +16,7 @@ //! Enforces a relational `>=` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index b30a97553b..726d81da2a 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -16,9 +16,7 @@ //! Enforces a relational `>` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 6c247048bc..547aa519a1 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -16,9 +16,7 @@ //! Enforces a relational `<=` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use leo_gadgets::bits::ComparatorGadget; diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 19c98f63a2..a47f1f8735 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -16,9 +16,7 @@ //! Enforces a relational `<` operator in a resolved Leo program. -use crate::errors::ExpressionError; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, value::ConstrainedValue, GroupType}; use leo_asg::Span; use leo_gadgets::bits::comparator::EvaluateLtGadget; diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 46d37d6a10..40e5efe64e 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -16,12 +16,8 @@ //! Enforces array access in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::Expression; -use leo_asg::Span; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{Expression, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/expression/tuple/tuple.rs b/compiler/src/expression/tuple/tuple.rs index 5ab7b4da88..45ce92d86d 100644 --- a/compiler/src/expression/tuple/tuple.rs +++ b/compiler/src/expression/tuple/tuple.rs @@ -18,10 +18,7 @@ use std::cell::Cell; -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Expression; use snarkvm_fields::PrimeField; diff --git a/compiler/src/expression/variable_ref/variable_ref.rs b/compiler/src/expression/variable_ref/variable_ref.rs index 076b3dee3a..d2bef6e489 100644 --- a/compiler/src/expression/variable_ref/variable_ref.rs +++ b/compiler/src/expression/variable_ref/variable_ref.rs @@ -16,10 +16,7 @@ //! Enforces an identifier expression in a compiled Leo program. -use crate::errors::ExpressionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::ExpressionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::VariableRef; use snarkvm_fields::PrimeField; diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 98df36cb2e..840c3d5619 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -16,14 +16,9 @@ //! Enforces constraints on a function in a compiled Leo program. -use crate::errors::FunctionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::FunctionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; -use leo_asg::Expression; -use leo_asg::Function; -use leo_asg::FunctionQualifier; +use leo_asg::{Expression, Function, FunctionQualifier}; use std::cell::Cell; use snarkvm_fields::PrimeField; diff --git a/compiler/src/function/input/array.rs b/compiler/src/function/input/array.rs index 5e6d9fd976..dcb88e6422 100644 --- a/compiler/src/function/input/array.rs +++ b/compiler/src/function/input/array.rs @@ -16,14 +16,10 @@ //! Allocates an array as a main function input parameter in a compiled Leo program. -use crate::errors::FunctionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::FunctionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Type; -use leo_ast::InputValue; -use leo_ast::Span; +use leo_ast::{InputValue, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index ae5cd8386a..1a5dcd6e34 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -14,17 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::FunctionError; -use crate::ConstrainedCircuitMember; -use crate::ConstrainedProgram; -use crate::ConstrainedValue; -use crate::GroupType; -use leo_asg::Circuit; -use leo_asg::CircuitMember; -use leo_asg::Type; -use leo_ast::Identifier; -use leo_ast::Input; -use leo_ast::Span; +use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType}; +use leo_asg::{Circuit, CircuitMember, Type}; +use leo_ast::{Identifier, Input, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index 0e7cdac513..e188b82f3b 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -14,17 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::FunctionError; -use crate::ConstrainedCircuitMember; -use crate::ConstrainedProgram; -use crate::ConstrainedValue; -use crate::GroupType; -use leo_asg::AsgConvertError; -use leo_asg::Circuit; -use leo_asg::CircuitMember; -use leo_ast::Identifier; -use leo_ast::InputValue; -use leo_ast::Parameter; +use crate::{errors::FunctionError, ConstrainedCircuitMember, ConstrainedProgram, ConstrainedValue, GroupType}; +use leo_asg::{AsgConvertError, Circuit, CircuitMember}; +use leo_ast::{Identifier, InputValue, Parameter}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/function/input/main_function_input.rs b/compiler/src/function/input/main_function_input.rs index 0ad5f707ad..cbf9150a64 100644 --- a/compiler/src/function/input/main_function_input.rs +++ b/compiler/src/function/input/main_function_input.rs @@ -16,19 +16,22 @@ //! Allocates a main function input parameter in a compiled Leo program. -use crate::address::Address; -use crate::errors::FunctionError; -use crate::program::ConstrainedProgram; -use crate::value::boolean::input::bool_from_input; -use crate::value::field::input::field_from_input; -use crate::value::group::input::group_from_input; -use crate::value::ConstrainedValue; -use crate::GroupType; -use crate::Integer; +use crate::{ + address::Address, + errors::FunctionError, + program::ConstrainedProgram, + value::{ + boolean::input::bool_from_input, + field::input::field_from_input, + group::input::group_from_input, + ConstrainedValue, + }, + GroupType, + Integer, +}; use leo_asg::Type; -use leo_ast::InputValue; -use leo_ast::Span; +use leo_ast::{InputValue, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/function/input/tuple.rs b/compiler/src/function/input/tuple.rs index 3bb8587406..e83133e279 100644 --- a/compiler/src/function/input/tuple.rs +++ b/compiler/src/function/input/tuple.rs @@ -16,14 +16,10 @@ //! Allocates an array as a main function input parameter in a compiled Leo program. -use crate::errors::FunctionError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::FunctionError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Type; -use leo_ast::InputValue; -use leo_ast::Span; +use leo_ast::{InputValue, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 86c601426d..5ce77a009f 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -16,14 +16,9 @@ //! Enforces constraints on the main function of a compiled Leo program. -use crate::errors::FunctionError; -use crate::program::ConstrainedProgram; -use crate::GroupType; -use crate::OutputBytes; +use crate::{errors::FunctionError, program::ConstrainedProgram, GroupType, OutputBytes}; -use leo_asg::Expression; -use leo_asg::Function; -use leo_asg::FunctionQualifier; +use leo_asg::{Expression, Function, FunctionQualifier}; use leo_ast::Input; use std::cell::Cell; diff --git a/compiler/src/function/mut_target.rs b/compiler/src/function/mut_target.rs index 1d7927ad2b..00a7c17d6d 100644 --- a/compiler/src/function/mut_target.rs +++ b/compiler/src/function/mut_target.rs @@ -16,19 +16,23 @@ //! Resolves assignees in a compiled Leo program. -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use crate::ResolvedAssigneeAccess; -use leo_asg::ArrayAccessExpression; -use leo_asg::ArrayRangeAccessExpression; -use leo_asg::CircuitAccessExpression; -use leo_asg::Expression; -use leo_asg::Node; -use leo_asg::Span; -use leo_asg::TupleAccessExpression; -use leo_asg::Variable; +use crate::{ + errors::StatementError, + program::ConstrainedProgram, + value::ConstrainedValue, + GroupType, + ResolvedAssigneeAccess, +}; +use leo_asg::{ + ArrayAccessExpression, + ArrayRangeAccessExpression, + CircuitAccessExpression, + Expression, + Node, + Span, + TupleAccessExpression, + Variable, +}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 499af03122..29b6aed420 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -16,18 +16,18 @@ //! Enforces that one return value is produced in a compiled Leo program. -use crate::errors::StatementError; -use crate::get_indicator_value; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{ + errors::StatementError, + get_indicator_value, + program::ConstrainedProgram, + value::ConstrainedValue, + GroupType, +}; -use leo_asg::Span; -use leo_asg::Type; +use leo_asg::{Span, Type}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, select::CondSelectGadget}; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index 6e4fc29423..ecbaffe408 100644 --- a/compiler/src/output/output_bytes.rs +++ b/compiler/src/output/output_bytes.rs @@ -14,19 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::OutputBytesError; -use crate::ConstrainedValue; -use crate::GroupType; -use crate::REGISTERS_VARIABLE_NAME; +use crate::{errors::OutputBytesError, ConstrainedValue, GroupType, REGISTERS_VARIABLE_NAME}; use leo_asg::Program; -use leo_ast::Parameter; -use leo_ast::Registers; -use leo_ast::Span; +use leo_ast::{Parameter, Registers, Span}; use snarkvm_fields::PrimeField; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; /// Serialized program return output. #[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)] diff --git a/compiler/src/output/output_file.rs b/compiler/src/output/output_file.rs index d2aced5cdd..f9dd6eeda1 100644 --- a/compiler/src/output/output_file.rs +++ b/compiler/src/output/output_file.rs @@ -18,11 +18,15 @@ use crate::errors::OutputFileError; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/"; pub static OUTPUT_FILE_EXTENSION: &str = ".out"; diff --git a/compiler/src/prelude/blake2s.rs b/compiler/src/prelude/blake2s.rs index ab21175a87..c8659425ad 100644 --- a/compiler/src/prelude/blake2s.rs +++ b/compiler/src/prelude/blake2s.rs @@ -15,17 +15,16 @@ // along with the Leo library. If not, see . use super::CoreCircuit; -use crate::errors::ExpressionError; -use crate::ConstrainedValue; -use crate::GroupType; -use crate::Integer; -use leo_asg::Function; -use leo_asg::Span; +use crate::{errors::ExpressionError, ConstrainedValue, GroupType, Integer}; +use leo_asg::{Function, Span}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::algorithms::prf::Blake2sGadget; -use snarkvm_gadgets::traits::algorithms::PRFGadget; -use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_gadgets::traits::utilities::ToBytesGadget; +use snarkvm_gadgets::{ + algorithms::prf::Blake2sGadget, + traits::{ + algorithms::PRFGadget, + utilities::{uint::UInt8, ToBytesGadget}, + }, +}; use snarkvm_r1cs::ConstraintSystem; pub struct Blake2s; diff --git a/compiler/src/prelude/mod.rs b/compiler/src/prelude/mod.rs index 70799088aa..736308274b 100644 --- a/compiler/src/prelude/mod.rs +++ b/compiler/src/prelude/mod.rs @@ -17,11 +17,8 @@ pub mod blake2s; pub use blake2s::*; -use crate::errors::ExpressionError; -use crate::ConstrainedValue; -use crate::GroupType; -use leo_asg::Function; -use leo_asg::Span; +use crate::{errors::ExpressionError, ConstrainedValue, GroupType}; +use leo_asg::{Function, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index 329134643d..1110e9a7c0 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -16,8 +16,7 @@ //! An in memory store to keep track of defined names when constraining a Leo program. -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{value::ConstrainedValue, GroupType}; use leo_asg::Program; use snarkvm_fields::PrimeField; diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index f738529c9f..232d03d125 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -16,18 +16,11 @@ //! Enforces an assign statement in a compiled Leo program. -use crate::arithmetic::*; -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::AssignOperation; -use leo_asg::AssignStatement; -use leo_asg::Span; +use crate::{arithmetic::*, errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{AssignOperation, AssignStatement, Span}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, select::CondSelectGadget}; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/assign/assignee.rs b/compiler/src/statement/assign/assignee.rs index 598bc95d17..71e758688d 100644 --- a/compiler/src/statement/assign/assignee.rs +++ b/compiler/src/statement/assign/assignee.rs @@ -16,14 +16,8 @@ //! Resolves assignees in a compiled Leo program. -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_asg::AssignAccess; -use leo_asg::AssignStatement; -use leo_asg::Identifier; -use leo_asg::Span; +use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use leo_asg::{AssignAccess, AssignStatement, Identifier, Span}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/statement/block/block.rs b/compiler/src/statement/block/block.rs index 5c81c3b6d9..ed9d7577df 100644 --- a/compiler/src/statement/block/block.rs +++ b/compiler/src/statement/block/block.rs @@ -16,10 +16,7 @@ //! Enforces a branch of a conditional or iteration statement in a compiled Leo program. -use crate::program::ConstrainedProgram; -use crate::GroupType; -use crate::IndicatorAndConstrainedValue; -use crate::StatementResult; +use crate::{program::ConstrainedProgram, GroupType, IndicatorAndConstrainedValue, StatementResult}; use leo_asg::BlockStatement; use snarkvm_fields::PrimeField; diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 22bfbdb7ae..84368ed307 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -16,12 +16,14 @@ //! Methods to enforce constraints on statements in a compiled Leo program. -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use crate::IndicatorAndConstrainedValue; -use crate::StatementResult; +use crate::{ + errors::StatementError, + program::ConstrainedProgram, + value::ConstrainedValue, + GroupType, + IndicatorAndConstrainedValue, + StatementResult, +}; use leo_asg::ConditionalStatement; use snarkvm_fields::PrimeField; diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 8199c80f8a..a021b52ed1 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -16,13 +16,8 @@ //! Enforces a definition statement in a compiled Leo program. -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::ConstrainedValue; -use crate::GroupType; -use leo_asg::DefinitionStatement; -use leo_asg::Span; -use leo_asg::Variable; +use crate::{errors::StatementError, program::ConstrainedProgram, ConstrainedValue, GroupType}; +use leo_asg::{DefinitionStatement, Span, Variable}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index c70b2690de..a5fe0e8b30 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -16,17 +16,18 @@ //! Enforces an iteration statement in a compiled Leo program. -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; -use crate::IndicatorAndConstrainedValue; -use crate::Integer; -use crate::StatementResult; +use crate::{ + program::ConstrainedProgram, + value::ConstrainedValue, + GroupType, + IndicatorAndConstrainedValue, + Integer, + StatementResult, +}; use leo_asg::IterationStatement; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::uint::UInt32; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, uint::UInt32}; use snarkvm_r1cs::ConstraintSystem; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { diff --git a/compiler/src/statement/return_/return_.rs b/compiler/src/statement/return_/return_.rs index ae0172002d..91e23c9e04 100644 --- a/compiler/src/statement/return_/return_.rs +++ b/compiler/src/statement/return_/return_.rs @@ -16,10 +16,7 @@ //! Enforces a return statement in a compiled Leo program. -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::ReturnStatement; use snarkvm_fields::PrimeField; diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index e5eef59ec6..135c7932fd 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -16,10 +16,7 @@ //! Enforces a statement in a compiled Leo program. -use crate::errors::StatementError; -use crate::program::ConstrainedProgram; -use crate::value::ConstrainedValue; -use crate::GroupType; +use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; use leo_asg::Statement; use snarkvm_fields::PrimeField; diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 8dc60b3007..b7d9e013b2 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -14,29 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::AddressError; -use crate::ConstrainedValue; -use crate::GroupType; -use leo_ast::InputValue; -use leo_ast::Span; +use crate::{errors::AddressError, ConstrainedValue, GroupType}; +use leo_ast::{InputValue, Span}; -use snarkvm_dpc::account::AccountAddress; -use snarkvm_dpc::base_dpc::instantiated::Components; +use snarkvm_dpc::{account::AccountAddress, base_dpc::instantiated::Components}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::utilities::eq::EqGadget; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_gadgets::traits::utilities::uint::UInt; -use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_r1cs::Assignment; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::Boolean, + eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, + select::CondSelectGadget, + uint::{UInt, UInt8}, +}; +use snarkvm_r1cs::{Assignment, ConstraintSystem, SynthesisError}; use snarkvm_utilities::ToBytes; -use std::borrow::Borrow; -use std::str::FromStr; +use std::{borrow::Borrow, str::FromStr}; /// A public address #[derive(Clone, Debug, PartialEq, Eq)] @@ -207,11 +199,7 @@ impl ConditionalEqGadget for Address { } fn cond_select_helper(first: &Address, second: &Address, cond: bool) -> Address { - if cond { - first.clone() - } else { - second.clone() - } + if cond { first.clone() } else { second.clone() } } impl CondSelectGadget for Address { diff --git a/compiler/src/value/boolean/input.rs b/compiler/src/value/boolean/input.rs index 7ab9ce591e..e60cda1a68 100644 --- a/compiler/src/value/boolean/input.rs +++ b/compiler/src/value/boolean/input.rs @@ -16,17 +16,12 @@ //! Methods to enforce constraints on input boolean values in a resolved Leo program. -use crate::errors::BooleanError; -use crate::value::ConstrainedValue; -use crate::GroupType; -use leo_ast::InputValue; -use leo_ast::Span; +use crate::{errors::BooleanError, value::ConstrainedValue, GroupType}; +use leo_ast::{InputValue, Span}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; pub(crate) fn allocate_bool>( cs: &mut CS, diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index a03e6e1bc4..21819c6ed3 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -16,28 +16,28 @@ //! A data type that represents a field value -use crate::errors::FieldError; -use crate::number_string_typing; +use crate::{errors::FieldError, number_string_typing}; use leo_ast::Span; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::fields::AllocatedFp; -use snarkvm_gadgets::fields::FpGadget; -use snarkvm_gadgets::traits::fields::FieldGadget; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::utilities::eq::EqGadget; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_gadgets::traits::utilities::ToBitsGadget; -use snarkvm_gadgets::traits::utilities::ToBytesGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::{ + fields::{AllocatedFp, FpGadget}, + traits::{ + fields::FieldGadget, + utilities::{ + alloc::AllocGadget, + boolean::Boolean, + eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, + select::CondSelectGadget, + uint::UInt8, + ToBitsGadget, + ToBytesGadget, + }, + }, +}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; -use std::borrow::Borrow; -use std::cmp::Ordering; +use std::{borrow::Borrow, cmp::Ordering}; #[derive(Clone, Debug)] pub enum FieldType { @@ -293,11 +293,7 @@ impl CondSelectGadget for FieldType { second: &Self, ) -> Result { if let Boolean::Constant(cond) = *cond { - if cond { - Ok(first.clone()) - } else { - Ok(second.clone()) - } + if cond { Ok(first.clone()) } else { Ok(second.clone()) } } else { let first_gadget = first.allocated(&mut cs)?; let second_gadget = second.allocated(&mut cs)?; diff --git a/compiler/src/value/field/input.rs b/compiler/src/value/field/input.rs index 299c2e1cc6..4172fa23b0 100644 --- a/compiler/src/value/field/input.rs +++ b/compiler/src/value/field/input.rs @@ -16,18 +16,12 @@ //! Methods to enforce constraints on input field values in a compiled Leo program. -use crate::errors::FieldError; -use crate::number_string_typing; -use crate::value::ConstrainedValue; -use crate::FieldType; -use crate::GroupType; -use leo_ast::InputValue; -use leo_ast::Span; +use crate::{errors::FieldError, number_string_typing, value::ConstrainedValue, FieldType, GroupType}; +use leo_ast::{InputValue, Span}; use snarkvm_fields::PrimeField; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; pub(crate) fn allocate_field>( cs: &mut CS, diff --git a/compiler/src/value/group/group_type.rs b/compiler/src/value/group/group_type.rs index eb7969546e..8c822938ea 100644 --- a/compiler/src/value/group/group_type.rs +++ b/compiler/src/value/group/group_type.rs @@ -17,21 +17,18 @@ //! A data type that represents members in the group formed by the set of affine points on a curve. use crate::errors::GroupError; -use leo_asg::GroupValue; -use leo_asg::Span; +use leo_asg::{GroupValue, Span}; -use snarkvm_fields::Field; -use snarkvm_fields::One; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::utilities::eq::EqGadget; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_gadgets::traits::utilities::ToBitsGadget; -use snarkvm_gadgets::traits::utilities::ToBytesGadget; +use snarkvm_fields::{Field, One}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, + select::CondSelectGadget, + ToBitsGadget, + ToBytesGadget, +}; use snarkvm_r1cs::ConstraintSystem; -use std::fmt::Debug; -use std::fmt::Display; +use std::fmt::{Debug, Display}; pub trait GroupType: Sized diff --git a/compiler/src/value/group/input.rs b/compiler/src/value/group/input.rs index ff4f084e75..df56ff5564 100644 --- a/compiler/src/value/group/input.rs +++ b/compiler/src/value/group/input.rs @@ -16,16 +16,12 @@ //! Methods to enforce constraints on input group values in a Leo program. -use crate::errors::GroupError; -use crate::ConstrainedValue; -use crate::GroupType; -use leo_asg::GroupValue; -use leo_asg::Span; +use crate::{errors::GroupError, ConstrainedValue, GroupType}; +use leo_asg::{GroupValue, Span}; use leo_ast::InputValue; use snarkvm_fields::PrimeField; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; pub(crate) fn allocate_group, CS: ConstraintSystem>( cs: &mut CS, diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 66cc727cef..9c8cecb525 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -14,43 +14,39 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::GroupError; -use crate::number_string_typing; -use crate::GroupType; -use leo_asg::GroupCoordinate; -use leo_asg::GroupValue; -use leo_asg::Span; +use crate::{errors::GroupError, number_string_typing, GroupType}; +use leo_asg::{GroupCoordinate, GroupValue, Span}; -use snarkvm_curves::edwards_bls12::EdwardsAffine; -use snarkvm_curves::edwards_bls12::EdwardsParameters; -use snarkvm_curves::edwards_bls12::Fq; -use snarkvm_curves::templates::twisted_edwards_extended::GroupAffine; -use snarkvm_curves::AffineCurve; -use snarkvm_curves::TEModelParameters; -use snarkvm_fields::Fp256; -use snarkvm_fields::One; -use snarkvm_fields::Zero; -use snarkvm_gadgets::curves::edwards_bls12::EdwardsBlsGadget; -use snarkvm_gadgets::fields::AllocatedFp; -use snarkvm_gadgets::fields::FpGadget; -use snarkvm_gadgets::traits::curves::GroupGadget; -use snarkvm_gadgets::traits::fields::FieldGadget; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::utilities::eq::EqGadget; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_gadgets::traits::utilities::ToBitsGadget; -use snarkvm_gadgets::traits::utilities::ToBytesGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; -use std::borrow::Borrow; -use std::ops::Mul; -use std::ops::Neg; -use std::ops::Sub; -use std::str::FromStr; +use snarkvm_curves::{ + edwards_bls12::{EdwardsAffine, EdwardsParameters, Fq}, + templates::twisted_edwards_extended::GroupAffine, + AffineCurve, + TEModelParameters, +}; +use snarkvm_fields::{Fp256, One, Zero}; +use snarkvm_gadgets::{ + curves::edwards_bls12::EdwardsBlsGadget, + fields::{AllocatedFp, FpGadget}, + traits::{ + curves::GroupGadget, + fields::FieldGadget, + utilities::{ + alloc::AllocGadget, + boolean::Boolean, + eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, + select::CondSelectGadget, + uint::UInt8, + ToBitsGadget, + ToBytesGadget, + }, + }, +}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; +use std::{ + borrow::Borrow, + ops::{Mul, Neg, Sub}, + str::FromStr, +}; #[derive(Clone, Debug)] pub enum EdwardsGroupType { @@ -488,11 +484,7 @@ impl CondSelectGadget for EdwardsGroupType { second: &Self, ) -> Result { if let Boolean::Constant(cond) = *cond { - if cond { - Ok(first.clone()) - } else { - Ok(second.clone()) - } + if cond { Ok(first.clone()) } else { Ok(second.clone()) } } else { let first_gadget = first.allocated(cs.ns(|| "first"))?; let second_gadget = second.allocated(cs.ns(|| "second"))?; diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index aadcad705f..812aa457ef 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -15,28 +15,24 @@ // along with the Leo library. If not, see . //! Conversion of integer declarations to constraints in Leo. -use crate::errors::IntegerError; -use crate::IntegerTrait; -use leo_asg::ConstInt; -use leo_asg::IntegerType; -use leo_asg::Span; +use crate::{errors::IntegerError, IntegerTrait}; +use leo_asg::{ConstInt, IntegerType, Span}; use leo_ast::InputValue; -use leo_gadgets::arithmetic::*; -use leo_gadgets::bits::comparator::ComparatorGadget; -use leo_gadgets::bits::comparator::EvaluateLtGadget; -use leo_gadgets::signed_integer::*; +use leo_gadgets::{ + arithmetic::*, + bits::comparator::{ComparatorGadget, EvaluateLtGadget}, + signed_integer::*, +}; -use snarkvm_fields::Field; -use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::utilities::eq::EqGadget; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_gadgets::traits::utilities::uint::*; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_fields::{Field, PrimeField}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::Boolean, + eq::{ConditionalEqGadget, EqGadget, EvaluateEqGadget}, + select::CondSelectGadget, + uint::*, +}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; use std::fmt; /// An integer type enum wrapping the integer value. diff --git a/compiler/src/value/integer/macros.rs b/compiler/src/value/integer/macros.rs index e62ee6fcb5..13d0ad2b2a 100644 --- a/compiler/src/value/integer/macros.rs +++ b/compiler/src/value/integer/macros.rs @@ -16,12 +16,10 @@ use leo_gadgets::signed_integer::*; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::uint::UInt128; -use snarkvm_gadgets::traits::utilities::uint::UInt16; -use snarkvm_gadgets::traits::utilities::uint::UInt32; -use snarkvm_gadgets::traits::utilities::uint::UInt64; -use snarkvm_gadgets::traits::utilities::uint::UInt8; +use snarkvm_gadgets::traits::utilities::{ + boolean::Boolean, + uint::{UInt128, UInt16, UInt32, UInt64, UInt8}, +}; use std::fmt::Debug; pub trait IntegerTrait: Sized + Clone + Debug { diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 99cdbfffe8..78bb36846f 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -16,22 +16,12 @@ //! The in memory stored value for a defined name in a compiled Leo program. -use crate::errors::ValueError; -use crate::Address; -use crate::FieldType; -use crate::GroupType; -use crate::Integer; -use leo_asg::Circuit; -use leo_asg::Identifier; -use leo_asg::Span; -use leo_asg::Type; +use crate::{errors::ValueError, Address, FieldType, GroupType, Integer}; +use leo_asg::{Circuit, Identifier, Span, Type}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, eq::ConditionalEqGadget, select::CondSelectGadget}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; use std::fmt; #[derive(Clone, PartialEq, Eq)] diff --git a/compiler/tests/address/mod.rs b/compiler/tests/address/mod.rs index d673192650..b0193ffbdf 100644 --- a/compiler/tests/address/mod.rs +++ b/compiler/tests/address/mod.rs @@ -14,11 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::parse_program; +use crate::{assert_satisfied, expect_asg_error, expect_compiler_error, generate_main_input, parse_program}; use leo_ast::InputValue; static TEST_ADDRESS_1: &str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8"; diff --git a/compiler/tests/array/mod.rs b/compiler/tests/array/mod.rs index 6c41ce7c3d..fb01748d2f 100644 --- a/compiler/tests/array/mod.rs +++ b/compiler/tests/array/mod.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::get_output; -use crate::parse_program; -use crate::parse_program_with_input; -use crate::EdwardsTestCompiler; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + get_output, + parse_program, + parse_program_with_input, + EdwardsTestCompiler, +}; pub fn output_ones(program: EdwardsTestCompiler) { let expected = include_bytes!("output/registers_ones.out"); diff --git a/compiler/tests/boolean/mod.rs b/compiler/tests/boolean/mod.rs index 768920731c..4051bf83d9 100644 --- a/compiler/tests/boolean/mod.rs +++ b/compiler/tests/boolean/mod.rs @@ -14,13 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::get_output; -use crate::parse_program; -use crate::parse_program_with_input; -use crate::EdwardsTestCompiler; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + get_output, + parse_program, + parse_program_with_input, + EdwardsTestCompiler, +}; pub fn output_true(program: EdwardsTestCompiler) { let expected = include_bytes!("output/registers_true.out"); diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs index 1c57e896dc..3fe4b54955 100644 --- a/compiler/tests/circuits/mod.rs +++ b/compiler/tests/circuits/mod.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::parse_program; +use crate::{assert_satisfied, expect_asg_error, parse_program}; // Expressions diff --git a/compiler/tests/compiler/mod.rs b/compiler/tests/compiler/mod.rs index ec9b64bc53..d07b11b69a 100644 --- a/compiler/tests/compiler/mod.rs +++ b/compiler/tests/compiler/mod.rs @@ -14,11 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::get_output; -use crate::EdwardsTestCompiler; +use crate::{get_output, EdwardsTestCompiler}; -use std::env::current_dir; -use std::path::PathBuf; +use std::{env::current_dir, path::PathBuf}; static MAIN_FILE_NAME: &str = "tests/compiler/main.leo"; diff --git a/compiler/tests/console/mod.rs b/compiler/tests/console/mod.rs index 954918cb94..62ff5bce6f 100644 --- a/compiler/tests/console/mod.rs +++ b/compiler/tests/console/mod.rs @@ -14,12 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::parse_program; -use crate::parse_program_with_input; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + parse_program, + parse_program_with_input, +}; use leo_ast::InputValue; #[test] diff --git a/compiler/tests/core/mod.rs b/compiler/tests/core/mod.rs index 598606fba7..c4a6bb48a5 100644 --- a/compiler/tests/core/mod.rs +++ b/compiler/tests/core/mod.rs @@ -16,9 +16,7 @@ pub mod packages; -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::parse_program; +use crate::{assert_satisfied, expect_asg_error, parse_program}; #[test] fn test_core_circuit_invalid() { diff --git a/compiler/tests/core/packages/unstable/blake2s/mod.rs b/compiler/tests/core/packages/unstable/blake2s/mod.rs index 63e044a514..ce9a23b2f3 100644 --- a/compiler/tests/core/packages/unstable/blake2s/mod.rs +++ b/compiler/tests/core/packages/unstable/blake2s/mod.rs @@ -14,22 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::generate_main_input; -use crate::get_output; -use crate::parse_program; -use crate::parse_program_with_input; +use crate::{ + assert_satisfied, + expect_asg_error, + generate_main_input, + get_output, + parse_program, + parse_program_with_input, +}; use leo_ast::InputValue; -use leo_input::types::IntegerType; -use leo_input::types::U8Type; -use leo_input::types::UnsignedIntegerType; +use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType}; use rand::Rng; use rand_core::SeedableRng; use rand_xorshift::XorShiftRng; -use snarkvm_algorithms::prf::blake2s::Blake2s as B2SPRF; -use snarkvm_algorithms::traits::PRF; +use snarkvm_algorithms::{prf::blake2s::Blake2s as B2SPRF, traits::PRF}; #[test] fn test_arguments_length_fail() { diff --git a/compiler/tests/definition/mod.rs b/compiler/tests/definition/mod.rs index b6d4f463c9..e5faf8b2de 100644 --- a/compiler/tests/definition/mod.rs +++ b/compiler/tests/definition/mod.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::import::set_local_dir; -use crate::parse_program; +use crate::{assert_satisfied, import::set_local_dir, parse_program}; #[test] fn test_out_of_order() { diff --git a/compiler/tests/function/mod.rs b/compiler/tests/function/mod.rs index c3a7f9654f..6de6cd8153 100644 --- a/compiler/tests/function/mod.rs +++ b/compiler/tests/function/mod.rs @@ -14,11 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::get_output; -use crate::parse_program; -use crate::parse_program_with_input; +use crate::{assert_satisfied, expect_asg_error, get_output, parse_program, parse_program_with_input}; #[test] fn test_conditional_return() { diff --git a/compiler/tests/import/mod.rs b/compiler/tests/import/mod.rs index fccae4c6c6..1a3440b577 100644 --- a/compiler/tests/import/mod.rs +++ b/compiler/tests/import/mod.rs @@ -14,11 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::parse_program; +use crate::{assert_satisfied, parse_program}; -use std::env::current_dir; -use std::env::set_current_dir; +use std::env::{current_dir, set_current_dir}; static TEST_SOURCE_DIRECTORY: &str = "tests/import"; diff --git a/compiler/tests/input_files/program_input/mod.rs b/compiler/tests/input_files/program_input/mod.rs index c82135b381..529a512fdb 100644 --- a/compiler/tests/input_files/program_input/mod.rs +++ b/compiler/tests/input_files/program_input/mod.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_compiler_error; -use crate::parse_program_with_input; -use crate::EdwardsTestCompiler; +use crate::{assert_satisfied, expect_compiler_error, parse_program_with_input, EdwardsTestCompiler}; use leo_compiler::errors::CompilerError; fn expect_fail(program: EdwardsTestCompiler) { diff --git a/compiler/tests/input_files/program_input_and_program_state/mod.rs b/compiler/tests/input_files/program_input_and_program_state/mod.rs index 14d433c07b..25541030ab 100644 --- a/compiler/tests/input_files/program_input_and_program_state/mod.rs +++ b/compiler/tests/input_files/program_input_and_program_state/mod.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::parse_input_and_state; -use crate::parse_program_with_input_and_state; +use crate::{assert_satisfied, parse_input_and_state, parse_program_with_input_and_state}; #[test] fn test_basic() { diff --git a/compiler/tests/input_files/program_registers/mod.rs b/compiler/tests/input_files/program_registers/mod.rs index 43565f75d6..b172c141e0 100644 --- a/compiler/tests/input_files/program_registers/mod.rs +++ b/compiler/tests/input_files/program_registers/mod.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::expect_compiler_error; -use crate::get_output; -use crate::parse_program_with_input; +use crate::{expect_compiler_error, get_output, parse_program_with_input}; #[test] fn test_registers_pass() { diff --git a/compiler/tests/input_files/program_state/mod.rs b/compiler/tests/input_files/program_state/mod.rs index 5a9c1ff24c..c5959196f5 100644 --- a/compiler/tests/input_files/program_state/mod.rs +++ b/compiler/tests/input_files/program_state/mod.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::parse_program_with_state; -use crate::parse_state; +use crate::{assert_satisfied, parse_program_with_state, parse_state}; #[test] fn test_basic() { diff --git a/compiler/tests/integers/i128/mod.rs b/compiler/tests/integers/i128/mod.rs index e1885f7ffe..e62e07260e 100644 --- a/compiler/tests/integers/i128/mod.rs +++ b/compiler/tests/integers/i128/mod.rs @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::expect_computation_error; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::I128Type; -use leo_input::types::IntegerType; -use leo_input::types::SignedIntegerType; +use leo_input::types::{I128Type, IntegerType, SignedIntegerType}; test_int!( TestI128, diff --git a/compiler/tests/integers/i16/mod.rs b/compiler/tests/integers/i16/mod.rs index 57404f5a30..49b45f5b3e 100644 --- a/compiler/tests/integers/i16/mod.rs +++ b/compiler/tests/integers/i16/mod.rs @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::expect_computation_error; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::I16Type; -use leo_input::types::IntegerType; -use leo_input::types::SignedIntegerType; +use leo_input::types::{I16Type, IntegerType, SignedIntegerType}; test_int!( TestI16, diff --git a/compiler/tests/integers/i32/mod.rs b/compiler/tests/integers/i32/mod.rs index 965c96573f..ee9e25701a 100644 --- a/compiler/tests/integers/i32/mod.rs +++ b/compiler/tests/integers/i32/mod.rs @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::expect_computation_error; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::I32Type; -use leo_input::types::IntegerType; -use leo_input::types::SignedIntegerType; +use leo_input::types::{I32Type, IntegerType, SignedIntegerType}; test_int!( TestI32, diff --git a/compiler/tests/integers/i64/mod.rs b/compiler/tests/integers/i64/mod.rs index 083f04368b..066ac9956f 100644 --- a/compiler/tests/integers/i64/mod.rs +++ b/compiler/tests/integers/i64/mod.rs @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::expect_computation_error; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::I64Type; -use leo_input::types::IntegerType; -use leo_input::types::SignedIntegerType; +use leo_input::types::{I64Type, IntegerType, SignedIntegerType}; test_int!( TestI64, diff --git a/compiler/tests/integers/i8/mod.rs b/compiler/tests/integers/i8/mod.rs index f7b4e46446..9133a72248 100644 --- a/compiler/tests/integers/i8/mod.rs +++ b/compiler/tests/integers/i8/mod.rs @@ -14,17 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::expect_computation_error; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::{expect_computation_error, IntegerTester}, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::I8Type; -use leo_input::types::IntegerType; -use leo_input::types::SignedIntegerType; +use leo_input::types::{I8Type, IntegerType, SignedIntegerType}; test_int!( TestI8, diff --git a/compiler/tests/integers/integer_tester.rs b/compiler/tests/integers/integer_tester.rs index bec296d6e2..23085d5aac 100644 --- a/compiler/tests/integers/integer_tester.rs +++ b/compiler/tests/integers/integer_tester.rs @@ -14,13 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::expect_compiler_error; -use crate::EdwardsTestCompiler; -use leo_compiler::errors::CompilerError; -use leo_compiler::errors::ExpressionError; -use leo_compiler::errors::FunctionError; -use leo_compiler::errors::IntegerError; -use leo_compiler::errors::StatementError; +use crate::{expect_compiler_error, EdwardsTestCompiler}; +use leo_compiler::errors::{CompilerError, ExpressionError, FunctionError, IntegerError, StatementError}; pub trait IntegerTester { /// Tests defining the smalled value that can be represented by the integer type diff --git a/compiler/tests/integers/u128/mod.rs b/compiler/tests/integers/u128/mod.rs index db276cea75..2c110af0a5 100644 --- a/compiler/tests/integers/u128/mod.rs +++ b/compiler/tests/integers/u128/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::IntegerType; -use leo_input::types::U128Type; -use leo_input::types::UnsignedIntegerType; +use leo_input::types::{IntegerType, U128Type, UnsignedIntegerType}; test_uint!( TestU128, diff --git a/compiler/tests/integers/u16/mod.rs b/compiler/tests/integers/u16/mod.rs index 68b66429cd..b4b202b9da 100644 --- a/compiler/tests/integers/u16/mod.rs +++ b/compiler/tests/integers/u16/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::IntegerType; -use leo_input::types::U16Type; -use leo_input::types::UnsignedIntegerType; +use leo_input::types::{IntegerType, U16Type, UnsignedIntegerType}; test_uint!( TestU16, diff --git a/compiler/tests/integers/u32/mod.rs b/compiler/tests/integers/u32/mod.rs index 7a646f0720..920fc6ed5b 100644 --- a/compiler/tests/integers/u32/mod.rs +++ b/compiler/tests/integers/u32/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::IntegerType; -use leo_input::types::U32Type; -use leo_input::types::UnsignedIntegerType; +use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType}; test_uint!( TestU32, diff --git a/compiler/tests/integers/u64/mod.rs b/compiler/tests/integers/u64/mod.rs index 4a76455959..ec86c868f1 100644 --- a/compiler/tests/integers/u64/mod.rs +++ b/compiler/tests/integers/u64/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::IntegerType; -use leo_input::types::U64Type; -use leo_input::types::UnsignedIntegerType; +use leo_input::types::{IntegerType, U64Type, UnsignedIntegerType}; test_uint!( TestU64, diff --git a/compiler/tests/integers/u8/mod.rs b/compiler/tests/integers/u8/mod.rs index d8ea4ade30..a61e28246d 100644 --- a/compiler/tests/integers/u8/mod.rs +++ b/compiler/tests/integers/u8/mod.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::integers::IntegerTester; -use crate::parse_program; +use crate::{ + assert_satisfied, + expect_asg_error, + expect_compiler_error, + generate_main_input, + integers::IntegerTester, + parse_program, +}; use leo_ast::InputValue; -use leo_input::types::IntegerType; -use leo_input::types::U8Type; -use leo_input::types::UnsignedIntegerType; +use leo_input::types::{IntegerType, U8Type, UnsignedIntegerType}; test_uint!( TestU8, diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 1b7b3d47be..5b34767f43 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -36,19 +36,16 @@ pub mod statements; pub mod syntax; pub mod tuples; -use leo_asg::new_alloc_context; -use leo_asg::new_context; -use leo_asg::AsgContext; -use leo_ast::InputValue; -use leo_ast::MainInput; -use leo_compiler::compiler::Compiler; -use leo_compiler::errors::CompilerError; -use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; -use leo_compiler::ConstrainedValue; -use leo_compiler::OutputBytes; -use leo_input::types::IntegerType; -use leo_input::types::U32Type; -use leo_input::types::UnsignedIntegerType; +use leo_asg::{new_alloc_context, new_context, AsgContext}; +use leo_ast::{InputValue, MainInput}; +use leo_compiler::{ + compiler::Compiler, + errors::CompilerError, + group::targets::edwards_bls12::EdwardsGroupType, + ConstrainedValue, + OutputBytes, +}; +use leo_input::types::{IntegerType, U32Type, UnsignedIntegerType}; use snarkvm_curves::edwards_bls12::Fq; use snarkvm_r1cs::TestConstraintSystem; diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index 4583d007d1..ded55960bb 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::generate_main_input; -use crate::parse_program; +use crate::{assert_satisfied, expect_asg_error, generate_main_input, parse_program}; use leo_ast::InputValue; #[test] diff --git a/compiler/tests/statements/conditional/mod.rs b/compiler/tests/statements/conditional/mod.rs index f3ea03a39f..040c8108dd 100644 --- a/compiler/tests/statements/conditional/mod.rs +++ b/compiler/tests/statements/conditional/mod.rs @@ -14,14 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_compiler_error; -use crate::generate_main_input; -use crate::generate_test_input_u32; -use crate::get_output; -use crate::parse_program; -use crate::parse_program_with_input; -use crate::EdwardsTestCompiler; +use crate::{ + assert_satisfied, + expect_compiler_error, + generate_main_input, + generate_test_input_u32, + get_output, + parse_program, + parse_program_with_input, + EdwardsTestCompiler, +}; use leo_ast::InputValue; #[test] diff --git a/compiler/tests/statements/mod.rs b/compiler/tests/statements/mod.rs index a200744c7b..3aeb3f858b 100644 --- a/compiler/tests/statements/mod.rs +++ b/compiler/tests/statements/mod.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::expect_asg_error; -use crate::generate_main_input; -use crate::parse_program; +use crate::{assert_satisfied, expect_asg_error, generate_main_input, parse_program}; use leo_ast::InputValue; pub mod conditional; diff --git a/compiler/tests/syntax/mod.rs b/compiler/tests/syntax/mod.rs index 684af5468d..2fb1a100ea 100644 --- a/compiler/tests/syntax/mod.rs +++ b/compiler/tests/syntax/mod.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::expect_asg_error; -use crate::parse_input; -use crate::parse_program; +use crate::{expect_asg_error, parse_input, parse_program}; use leo_compiler::errors::CompilerError; use leo_grammar::ParserError; use leo_input::InputParserError; diff --git a/compiler/tests/tuples/mod.rs b/compiler/tests/tuples/mod.rs index 3afece0f86..67798288a6 100644 --- a/compiler/tests/tuples/mod.rs +++ b/compiler/tests/tuples/mod.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::assert_satisfied; -use crate::parse_program; +use crate::{assert_satisfied, parse_program}; #[test] fn test_tuple_basic() { diff --git a/gadgets/benches/integer_arithmetic.rs b/gadgets/benches/integer_arithmetic.rs index f8d788daa0..a75546d7e4 100644 --- a/gadgets/benches/integer_arithmetic.rs +++ b/gadgets/benches/integer_arithmetic.rs @@ -14,26 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::arithmetic::*; -use leo_gadgets::Int128; -use leo_gadgets::Int16; -use leo_gadgets::Int32; -use leo_gadgets::Int64; -use leo_gadgets::Int8; +use leo_gadgets::{arithmetic::*, Int128, Int16, Int32, Int64, Int8}; use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Fr; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; -use rand::Rng; -use rand::SeedableRng; +use rand::{Rng, SeedableRng}; use rand_xorshift::XorShiftRng; use std::i128; -use criterion::criterion_group; -use criterion::criterion_main; -use criterion::Criterion; +use criterion::{criterion_group, criterion_main, Criterion}; macro_rules! create_add_bench { ($bench_name:ident, $bench_id:expr, $foo_name:ident, $std_type:ty, $bit_type:ty) => { diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index d4ea613984..eada6b2c3b 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -14,16 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_fields::Field; -use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::uint::UInt; -use snarkvm_gadgets::traits::utilities::uint::UInt128; -use snarkvm_gadgets::traits::utilities::uint::UInt16; -use snarkvm_gadgets::traits::utilities::uint::UInt32; -use snarkvm_gadgets::traits::utilities::uint::UInt64; -use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_fields::{Field, PrimeField}; +use snarkvm_gadgets::traits::utilities::uint::{UInt, UInt128, UInt16, UInt32, UInt64, UInt8}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; /// Returns addition of `self` + `other` in the constraint system. pub trait Add diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index 62afbe45ea..170014950a 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -18,8 +18,7 @@ use crate::bits::RippleCarryAdder; use snarkvm_fields::Field; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; use std::iter; diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index fdca3fe2ee..9ebc028a7e 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -16,8 +16,7 @@ use snarkvm_fields::Field; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; /// Single bit binary adder with carry bit /// https://en.wikipedia.org/wiki/Adder_(electronics)#Full_adder diff --git a/gadgets/src/bits/comparator.rs b/gadgets/src/bits/comparator.rs index 881dcd8434..ef0a6fc5ad 100644 --- a/gadgets/src/bits/comparator.rs +++ b/gadgets/src/bits/comparator.rs @@ -14,17 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use snarkvm_fields::Field; -use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_gadgets::traits::utilities::uint::UInt128; -use snarkvm_gadgets::traits::utilities::uint::UInt16; -use snarkvm_gadgets::traits::utilities::uint::UInt32; -use snarkvm_gadgets::traits::utilities::uint::UInt64; -use snarkvm_gadgets::traits::utilities::uint::UInt8; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_fields::{Field, PrimeField}; +use snarkvm_gadgets::traits::utilities::{ + boolean::Boolean, + select::CondSelectGadget, + uint::{UInt128, UInt16, UInt32, UInt64, UInt8}, +}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; pub trait EvaluateLtGadget { fn less_than>(&self, cs: CS, other: &Self) -> Result; diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index 1954ab5865..270e7d2415 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::bits::FullAdder; -use crate::signed_integer::*; +use crate::{bits::FullAdder, signed_integer::*}; -use snarkvm_fields::Field; -use snarkvm_fields::PrimeField; +use snarkvm_fields::{Field, PrimeField}; use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; /// Returns the bitwise sum of a n-bit number with carry bit pub trait RippleCarryAdder diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index af2020c3ed..be7ae00cea 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -14,24 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::arithmetic::Add; -use crate::bits::RippleCarryAdder; -use crate::errors::SignedIntegerError; -use crate::Int; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{ + arithmetic::Add, + bits::RippleCarryAdder, + errors::SignedIntegerError, + Int, + Int128, + Int16, + Int32, + Int64, + Int8, +}; -use snarkvm_fields::fp_parameters::FpParameters; -use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::Assignment; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::LinearCombination; +use snarkvm_fields::{fp_parameters::FpParameters, PrimeField}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::{AllocatedBit, Boolean}, +}; +use snarkvm_r1cs::{Assignment, ConstraintSystem, LinearCombination}; macro_rules! add_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/arithmetic/div.rs b/gadgets/src/signed_integer/arithmetic/div.rs index b0f93b21a3..6f93029abc 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -14,24 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::arithmetic::Add; -use crate::arithmetic::Div; -use crate::arithmetic::Neg; -use crate::arithmetic::Sub; -use crate::bits::ComparatorGadget; -use crate::errors::SignedIntegerError; -use crate::Int; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{ + arithmetic::{Add, Div, Neg, Sub}, + bits::ComparatorGadget, + errors::SignedIntegerError, + Int, + Int128, + Int16, + Int32, + Int64, + Int8, +}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::{AllocatedBit, Boolean}, + eq::EvaluateEqGadget, + select::CondSelectGadget, +}; use snarkvm_r1cs::ConstraintSystem; macro_rules! div_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index 4e0d3568a4..fb6b792715 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -14,25 +14,24 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::arithmetic::Mul; -use crate::bits::RippleCarryAdder; -use crate::bits::SignExtend; -use crate::errors::SignedIntegerError; -use crate::Int; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; -use snarkvm_fields::FpParameters; -use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_r1cs::Assignment; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::LinearCombination; +use crate::{ + arithmetic::Mul, + bits::{RippleCarryAdder, SignExtend}, + errors::SignedIntegerError, + Int, + Int128, + Int16, + Int32, + Int64, + Int8, +}; +use snarkvm_fields::{FpParameters, PrimeField}; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::{AllocatedBit, Boolean}, + select::CondSelectGadget, +}; +use snarkvm_r1cs::{Assignment, ConstraintSystem, LinearCombination}; use std::iter; diff --git a/gadgets/src/signed_integer/arithmetic/neg.rs b/gadgets/src/signed_integer/arithmetic/neg.rs index 28955cced5..3f802878bf 100644 --- a/gadgets/src/signed_integer/arithmetic/neg.rs +++ b/gadgets/src/signed_integer/arithmetic/neg.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::arithmetic::Neg; -use crate::errors::SignedIntegerError; -use crate::signed_integer::*; +use crate::{arithmetic::Neg, errors::SignedIntegerError, signed_integer::*}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/gadgets/src/signed_integer/arithmetic/pow.rs b/gadgets/src/signed_integer/arithmetic/pow.rs index 7838fd7625..3f6467978f 100644 --- a/gadgets/src/signed_integer/arithmetic/pow.rs +++ b/gadgets/src/signed_integer/arithmetic/pow.rs @@ -14,20 +14,19 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::arithmetic::Mul; -use crate::arithmetic::Pow; -use crate::errors::SignedIntegerError; -use crate::Int; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{ + arithmetic::{Mul, Pow}, + errors::SignedIntegerError, + Int, + Int128, + Int16, + Int32, + Int64, + Int8, +}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean, select::CondSelectGadget}; use snarkvm_r1cs::ConstraintSystem; macro_rules! pow_int_impl { diff --git a/gadgets/src/signed_integer/arithmetic/sub.rs b/gadgets/src/signed_integer/arithmetic/sub.rs index 77eebd25ca..fc3ae9a539 100644 --- a/gadgets/src/signed_integer/arithmetic/sub.rs +++ b/gadgets/src/signed_integer/arithmetic/sub.rs @@ -14,15 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::arithmetic::Add; -use crate::arithmetic::Neg; -use crate::arithmetic::Sub; -use crate::errors::SignedIntegerError; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{ + arithmetic::{Add, Neg, Sub}, + errors::SignedIntegerError, + Int128, + Int16, + Int32, + Int64, + Int8, +}; use snarkvm_fields::PrimeField; use snarkvm_r1cs::ConstraintSystem; diff --git a/gadgets/src/signed_integer/relational/cmp.rs b/gadgets/src/signed_integer/relational/cmp.rs index 167b729925..07b2537748 100644 --- a/gadgets/src/signed_integer/relational/cmp.rs +++ b/gadgets/src/signed_integer/relational/cmp.rs @@ -14,19 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::bits::ComparatorGadget; -use crate::bits::EvaluateLtGadget; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{ + bits::{ComparatorGadget, EvaluateLtGadget}, + Int128, + Int16, + Int32, + Int64, + Int8, +}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, select::CondSelectGadget}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; use std::cmp::Ordering; macro_rules! cmp_gadget_impl { diff --git a/gadgets/src/signed_integer/relational/eq.rs b/gadgets/src/signed_integer/relational/eq.rs index d48330bdc4..0cc1dcf792 100644 --- a/gadgets/src/signed_integer/relational/eq.rs +++ b/gadgets/src/signed_integer/relational/eq.rs @@ -14,18 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Int; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{Int, Int128, Int16, Int32, Int64, Int8}; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::EvaluateEqGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, eq::EvaluateEqGadget}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; macro_rules! eq_gadget_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/src/signed_integer/utilities/alloc.rs b/gadgets/src/signed_integer/utilities/alloc.rs index efc856637c..154b12f48c 100644 --- a/gadgets/src/signed_integer/utilities/alloc.rs +++ b/gadgets/src/signed_integer/utilities/alloc.rs @@ -14,21 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::Int; -use crate::Int128; -use crate::Int16; -use crate::Int32; -use crate::Int64; -use crate::Int8; +use crate::{Int, Int128, Int16, Int32, Int64, Int8}; -use core::borrow::Borrow; -use core::iter; +use core::{borrow::Borrow, iter}; use snarkvm_fields::Field; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::AllocatedBit; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::{AllocatedBit, Boolean}, +}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; fn create_value, I: IntoIterator>, F: Field, CS: ConstraintSystem>( cs: &mut CS, diff --git a/gadgets/src/signed_integer/utilities/eq.rs b/gadgets/src/signed_integer/utilities/eq.rs index 83a97a7daa..d3d9066f9c 100644 --- a/gadgets/src/signed_integer/utilities/eq.rs +++ b/gadgets/src/signed_integer/utilities/eq.rs @@ -17,10 +17,8 @@ use crate::signed_integer::*; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::ConditionalEqGadget; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{boolean::Boolean, eq::ConditionalEqGadget}; +use snarkvm_r1cs::{ConstraintSystem, SynthesisError}; macro_rules! cond_eq_int_impl { ($($gadget: ident),*) => ($( diff --git a/gadgets/src/signed_integer/utilities/select.rs b/gadgets/src/signed_integer/utilities/select.rs index 22482ee801..8cbcede327 100644 --- a/gadgets/src/signed_integer/utilities/select.rs +++ b/gadgets/src/signed_integer/utilities/select.rs @@ -17,13 +17,13 @@ use crate::signed_integer::*; use snarkvm_fields::PrimeField; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_gadgets::traits::utilities::eq::EqGadget; -use snarkvm_gadgets::traits::utilities::select::CondSelectGadget; -use snarkvm_r1cs::Assignment; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::SynthesisError; +use snarkvm_gadgets::traits::utilities::{ + alloc::AllocGadget, + boolean::Boolean, + eq::EqGadget, + select::CondSelectGadget, +}; +use snarkvm_r1cs::{Assignment, ConstraintSystem, SynthesisError}; macro_rules! select_int_impl { ($($gadget: ident)*) => ($( diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index 7c0d38a67f..9efa1f4c7a 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::arithmetic::*; -use leo_gadgets::Int128; +use leo_gadgets::{arithmetic::*, Int128}; -use snarkvm_fields::One; -use snarkvm_fields::Zero; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Fr; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_fields::{One, Zero}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index dc6eaee2fb..c6e5af960b 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::arithmetic::*; -use leo_gadgets::Int16; +use leo_gadgets::{arithmetic::*, Int16}; -use snarkvm_fields::One; -use snarkvm_fields::Zero; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Fr; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_fields::{One, Zero}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index 9170aa98d0..fb9fee1c94 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::arithmetic::*; -use leo_gadgets::Int32; +use leo_gadgets::{arithmetic::*, Int32}; -use snarkvm_fields::One; -use snarkvm_fields::Zero; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Fr; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_fields::{One, Zero}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 030cac373c..2aee9111c5 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::arithmetic::*; -use leo_gadgets::Int64; +use leo_gadgets::{arithmetic::*, Int64}; -use snarkvm_fields::One; -use snarkvm_fields::Zero; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Fr; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_fields::{One, Zero}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; use rand_core::SeedableRng; diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index 9a3aad4340..b8eaef23ed 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_gadgets::arithmetic::*; -use leo_gadgets::Int8; +use leo_gadgets::{arithmetic::*, Int8}; -use snarkvm_fields::One; -use snarkvm_fields::Zero; -use snarkvm_gadgets::traits::utilities::alloc::AllocGadget; -use snarkvm_gadgets::traits::utilities::boolean::Boolean; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Fr; -use snarkvm_r1cs::TestConstraintSystem; +use snarkvm_fields::{One, Zero}; +use snarkvm_gadgets::traits::utilities::{alloc::AllocGadget, boolean::Boolean}; +use snarkvm_r1cs::{ConstraintSystem, Fr, TestConstraintSystem}; use rand::Rng; use rand_core::SeedableRng; diff --git a/grammar/benches/grammar.rs b/grammar/benches/grammar.rs index ed493c740a..ec24d5edb7 100644 --- a/grammar/benches/grammar.rs +++ b/grammar/benches/grammar.rs @@ -16,10 +16,7 @@ use leo_grammar::Grammar; -use criterion::black_box; -use criterion::criterion_group; -use criterion::criterion_main; -use criterion::Criterion; +use criterion::{black_box, criterion_group, criterion_main, Criterion}; use std::path::Path; fn leo_grammar<'ast>(filepath: &'ast Path, program_string: &'ast str) { diff --git a/grammar/src/access/access.rs b/grammar/src/access/access.rs index 914e994783..1c33808692 100644 --- a/grammar/src/access/access.rs +++ b/grammar/src/access/access.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::access::*; -use crate::ast::Rule; +use crate::{access::*, ast::Rule}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/access/array_access.rs b/grammar/src/access/array_access.rs index 3f99db6242..fe98590ce9 100644 --- a/grammar/src/access/array_access.rs +++ b/grammar/src/access/array_access.rs @@ -14,9 +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; -use crate::common::RangeOrExpression; -use crate::SpanDef; +use crate::{ast::Rule, common::RangeOrExpression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/assignee_access.rs b/grammar/src/access/assignee_access.rs index 26cd172fa1..880ad65255 100644 --- a/grammar/src/access/assignee_access.rs +++ b/grammar/src/access/assignee_access.rs @@ -14,10 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::access::ArrayAccess; -use crate::access::MemberAccess; -use crate::access::TupleAccess; -use crate::ast::Rule; +use crate::{ + access::{ArrayAccess, MemberAccess, TupleAccess}, + ast::Rule, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/access/call_access.rs b/grammar/src/access/call_access.rs index dcfaefd692..398c05a3f9 100644 --- a/grammar/src/access/call_access.rs +++ b/grammar/src/access/call_access.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/member_access.rs b/grammar/src/access/member_access.rs index 45d05e18e7..a3e2e9e030 100644 --- a/grammar/src/access/member_access.rs +++ b/grammar/src/access/member_access.rs @@ -14,9 +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; -use crate::common::Identifier; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/self_access.rs b/grammar/src/access/self_access.rs index 2fc38d50ae..4c4c171835 100644 --- a/grammar/src/access/self_access.rs +++ b/grammar/src/access/self_access.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::access::*; -use crate::ast::Rule; +use crate::{access::*, ast::Rule}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/access/static_member_access.rs b/grammar/src/access/static_member_access.rs index dd195cabeb..7452d3e804 100644 --- a/grammar/src/access/static_member_access.rs +++ b/grammar/src/access/static_member_access.rs @@ -14,9 +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; -use crate::common::Identifier; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/access/tuple_access.rs b/grammar/src/access/tuple_access.rs index 25631d6cfb..952e6a426f 100644 --- a/grammar/src/access/tuple_access.rs +++ b/grammar/src/access/tuple_access.rs @@ -14,9 +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; -use crate::values::PositiveNumber; -use crate::SpanDef; +use crate::{ast::Rule, values::PositiveNumber, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotation_arguments.rs b/grammar/src/annotations/annotation_arguments.rs index 9447b490c2..bf58a2c358 100644 --- a/grammar/src/annotations/annotation_arguments.rs +++ b/grammar/src/annotations/annotation_arguments.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotation_name.rs b/grammar/src/annotations/annotation_name.rs index ebda9440cd..d7cb1c12c9 100644 --- a/grammar/src/annotations/annotation_name.rs +++ b/grammar/src/annotations/annotation_name.rs @@ -14,8 +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; -use crate::SpanDef; +use crate::{ast::Rule, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotation_symbol.rs b/grammar/src/annotations/annotation_symbol.rs index f555884ab7..16f042be92 100644 --- a/grammar/src/annotations/annotation_symbol.rs +++ b/grammar/src/annotations/annotation_symbol.rs @@ -14,8 +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; -use crate::SpanDef; +use crate::{ast::Rule, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/annotations/annotations.rs b/grammar/src/annotations/annotations.rs index d84d105d60..045eb3a47e 100644 --- a/grammar/src/annotations/annotations.rs +++ b/grammar/src/annotations/annotations.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::annotations::AnnotationArguments; -use crate::annotations::AnnotationName; -use crate::annotations::AnnotationSymbol; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + annotations::{AnnotationArguments, AnnotationName, AnnotationSymbol}, + ast::Rule, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/ast.rs b/grammar/src/ast.rs index b1c63f8f82..87da0a1967 100644 --- a/grammar/src/ast.rs +++ b/grammar/src/ast.rs @@ -15,31 +15,31 @@ // along with the Leo library. If not, see . //! Abstract syntax tree (ast) representation from leo.pest. -use crate::common::Identifier; -use crate::expressions::ArrayInitializerExpression; -use crate::expressions::ArrayInlineExpression; -use crate::expressions::CircuitInlineExpression; -use crate::expressions::Expression; -use crate::expressions::PostfixExpression; -use crate::expressions::SelfPostfixExpression; -use crate::expressions::TernaryExpression; -use crate::expressions::UnaryExpression; -use crate::operations::BinaryOperation; -use crate::operations::UnaryOperation; -use crate::values::Value; +use crate::{ + common::Identifier, + expressions::{ + ArrayInitializerExpression, + ArrayInlineExpression, + CircuitInlineExpression, + Expression, + PostfixExpression, + SelfPostfixExpression, + TernaryExpression, + UnaryExpression, + }, + operations::{BinaryOperation, UnaryOperation}, + values::Value, +}; use crate::expressions::TupleExpression; -use from_pest::ConversionError; -use from_pest::FromPest; -use from_pest::Void; -use pest::error::Error; -use pest::iterators::Pair; -use pest::iterators::Pairs; -use pest::prec_climber::Assoc; -use pest::prec_climber::Operator; -use pest::prec_climber::PrecClimber; -use pest::Parser; -use pest::Span; +use from_pest::{ConversionError, FromPest, Void}; +use pest::{ + error::Error, + iterators::{Pair, Pairs}, + prec_climber::{Assoc, Operator, PrecClimber}, + Parser, + Span, +}; #[derive(Parser)] #[grammar = "leo.pest"] diff --git a/grammar/src/circuits/circuit.rs b/grammar/src/circuits/circuit.rs index e719a7605c..a704df6962 100644 --- a/grammar/src/circuits/circuit.rs +++ b/grammar/src/circuits/circuit.rs @@ -14,10 +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; -use crate::circuits::CircuitMember; -use crate::common::Identifier; -use crate::SpanDef; +use crate::{ast::Rule, circuits::CircuitMember, common::Identifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/circuits/circuit_implied_variable.rs b/grammar/src/circuits/circuit_implied_variable.rs index 0f8111e549..eeb9aee4bb 100644 --- a/grammar/src/circuits/circuit_implied_variable.rs +++ b/grammar/src/circuits/circuit_implied_variable.rs @@ -14,9 +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; -use crate::circuits::CircuitVariable; -use crate::common::Identifier; +use crate::{ast::Rule, circuits::CircuitVariable, common::Identifier}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/circuits/circuit_member.rs b/grammar/src/circuits/circuit_member.rs index f451a28ffd..6ce1c822b8 100644 --- a/grammar/src/circuits/circuit_member.rs +++ b/grammar/src/circuits/circuit_member.rs @@ -14,9 +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; -use crate::circuits::CircuitVariableDefinition; -use crate::functions::Function; +use crate::{ast::Rule, circuits::CircuitVariableDefinition, functions::Function}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/circuits/circuit_variable.rs b/grammar/src/circuits/circuit_variable.rs index 099422b632..30c35bbb0a 100644 --- a/grammar/src/circuits/circuit_variable.rs +++ b/grammar/src/circuits/circuit_variable.rs @@ -14,10 +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; -use crate::common::Identifier; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/circuits/circuit_variable_definition.rs b/grammar/src/circuits/circuit_variable_definition.rs index e1da1f7bc6..cef9933bc6 100644 --- a/grammar/src/circuits/circuit_variable_definition.rs +++ b/grammar/src/circuits/circuit_variable_definition.rs @@ -14,10 +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; -use crate::common::Identifier; -use crate::types::Type; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, types::Type, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/assignee.rs b/grammar/src/common/assignee.rs index 77d8038db5..066fe1b0dd 100644 --- a/grammar/src/common/assignee.rs +++ b/grammar/src/common/assignee.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::access::AssigneeAccess; -use crate::ast::Rule; -use crate::common::SelfKeywordOrIdentifier; -use crate::SpanDef; +use crate::{access::AssigneeAccess, ast::Rule, common::SelfKeywordOrIdentifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/eoi.rs b/grammar/src/common/eoi.rs index 34d32d9ba0..b37cf4f230 100644 --- a/grammar/src/common/eoi.rs +++ b/grammar/src/common/eoi.rs @@ -17,8 +17,7 @@ use crate::ast::Rule; use pest_ast::FromPest; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, FromPest, PartialEq, Serialize, Deserialize)] #[pest_ast(rule(Rule::EOI))] diff --git a/grammar/src/common/identifier.rs b/grammar/src/common/identifier.rs index 9326593bff..0406e51336 100644 --- a/grammar/src/common/identifier.rs +++ b/grammar/src/common/identifier.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/keyword_or_identifier.rs b/grammar/src/common/keyword_or_identifier.rs index 71e28485fa..5ab05f5dad 100644 --- a/grammar/src/common/keyword_or_identifier.rs +++ b/grammar/src/common/keyword_or_identifier.rs @@ -14,10 +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; -use crate::common::Identifier; -use crate::functions::InputKeyword; -use crate::types::SelfType; +use crate::{ast::Rule, common::Identifier, functions::InputKeyword, types::SelfType}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/mut_self_keyword.rs b/grammar/src/common/mut_self_keyword.rs index 9c0cb39ee3..1ddc0cfa57 100644 --- a/grammar/src/common/mut_self_keyword.rs +++ b/grammar/src/common/mut_self_keyword.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::Mutable; -use crate::common::SelfKeyword; -use crate::SpanDef; +use crate::{ + ast::Rule, + common::{Mutable, SelfKeyword}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/range.rs b/grammar/src/common/range.rs index 9d5a26fdd1..cdb1f923f5 100644 --- a/grammar/src/common/range.rs +++ b/grammar/src/common/range.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/range_or_expression.rs b/grammar/src/common/range_or_expression.rs index c740ddf486..2b7ae2eb68 100644 --- a/grammar/src/common/range_or_expression.rs +++ b/grammar/src/common/range_or_expression.rs @@ -14,9 +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; -use crate::common::Range; -use crate::expressions::Expression; +use crate::{ast::Rule, common::Range, expressions::Expression}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/self_keyword.rs b/grammar/src/common/self_keyword.rs index 40ccedb74a..60721a7fab 100644 --- a/grammar/src/common/self_keyword.rs +++ b/grammar/src/common/self_keyword.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/self_keyword_or_identifier.rs b/grammar/src/common/self_keyword_or_identifier.rs index 0912a76f2d..83e27901eb 100644 --- a/grammar/src/common/self_keyword_or_identifier.rs +++ b/grammar/src/common/self_keyword_or_identifier.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::Identifier; -use crate::common::SelfKeyword; +use crate::{ + ast::Rule, + common::{Identifier, SelfKeyword}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/spread.rs b/grammar/src/common/spread.rs index 4dd09cf5ff..c9dd266816 100644 --- a/grammar/src/common/spread.rs +++ b/grammar/src/common/spread.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/spread_or_expression.rs b/grammar/src/common/spread_or_expression.rs index 859147cda0..cd4bbc21d6 100644 --- a/grammar/src/common/spread_or_expression.rs +++ b/grammar/src/common/spread_or_expression.rs @@ -14,9 +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; -use crate::common::Spread; -use crate::expressions::Expression; +use crate::{ast::Rule, common::Spread, expressions::Expression}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/common/variable_name.rs b/grammar/src/common/variable_name.rs index a9c862f586..f9c6fe2e28 100644 --- a/grammar/src/common/variable_name.rs +++ b/grammar/src/common/variable_name.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::Identifier; -use crate::common::Mutable; -use crate::SpanDef; +use crate::{ + ast::Rule, + common::{Identifier, Mutable}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/common/variables.rs b/grammar/src/common/variables.rs index 6a7b7f4751..939107fd7a 100644 --- a/grammar/src/common/variables.rs +++ b/grammar/src/common/variables.rs @@ -14,10 +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; -use crate::common::VariableName; -use crate::types::Type; -use crate::SpanDef; +use crate::{ast::Rule, common::VariableName, types::Type, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_assert.rs b/grammar/src/console/console_assert.rs index d5ed36d0c2..681f10dfc9 100644 --- a/grammar/src/console/console_assert.rs +++ b/grammar/src/console/console_assert.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_debug.rs b/grammar/src/console/console_debug.rs index 61583f53a4..81b463947e 100644 --- a/grammar/src/console/console_debug.rs +++ b/grammar/src/console/console_debug.rs @@ -14,9 +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; -use crate::console::FormattedString; -use crate::SpanDef; +use crate::{ast::Rule, console::FormattedString, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_error.rs b/grammar/src/console/console_error.rs index ce342c2896..8155c8d75f 100644 --- a/grammar/src/console/console_error.rs +++ b/grammar/src/console/console_error.rs @@ -14,9 +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; -use crate::console::FormattedString; -use crate::SpanDef; +use crate::{ast::Rule, console::FormattedString, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_function.rs b/grammar/src/console/console_function.rs index da32c2095b..b2cb97a418 100644 --- a/grammar/src/console/console_function.rs +++ b/grammar/src/console/console_function.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::console::ConsoleAssert; -use crate::console::ConsoleDebug; -use crate::console::ConsoleError; -use crate::console::ConsoleLog; +use crate::{ + ast::Rule, + console::{ConsoleAssert, ConsoleDebug, ConsoleError, ConsoleLog}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/console/console_function_call.rs b/grammar/src/console/console_function_call.rs index 08d1455896..18183927e9 100644 --- a/grammar/src/console/console_function_call.rs +++ b/grammar/src/console/console_function_call.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::LineEnd; -use crate::console::ConsoleFunction; -use crate::console::ConsoleKeyword; -use crate::SpanDef; +use crate::{ + ast::Rule, + common::LineEnd, + console::{ConsoleFunction, ConsoleKeyword}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_keyword.rs b/grammar/src/console/console_keyword.rs index 952d83933f..b9f98355ed 100644 --- a/grammar/src/console/console_keyword.rs +++ b/grammar/src/console/console_keyword.rs @@ -14,8 +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; -use crate::SpanDef; +use crate::{ast::Rule, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/console_log.rs b/grammar/src/console/console_log.rs index b4fa3d1069..06e6f457f0 100644 --- a/grammar/src/console/console_log.rs +++ b/grammar/src/console/console_log.rs @@ -14,9 +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; -use crate::console::FormattedString; -use crate::SpanDef; +use crate::{ast::Rule, console::FormattedString, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/formatted_container.rs b/grammar/src/console/formatted_container.rs index cedcc96bea..2943280b52 100644 --- a/grammar/src/console/formatted_container.rs +++ b/grammar/src/console/formatted_container.rs @@ -14,8 +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; -use crate::SpanDef; +use crate::{ast::Rule, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/console/formatted_string.rs b/grammar/src/console/formatted_string.rs index adbdfbdffb..f0e80d3209 100644 --- a/grammar/src/console/formatted_string.rs +++ b/grammar/src/console/formatted_string.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::console::FormattedContainer; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + console::FormattedContainer, + expressions::Expression, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/definitions/annotated_definition.rs b/grammar/src/definitions/annotated_definition.rs index 70f56ff93f..2bb3bf2d77 100644 --- a/grammar/src/definitions/annotated_definition.rs +++ b/grammar/src/definitions/annotated_definition.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::annotations::Annotation; -use crate::ast::Rule; -use crate::definitions::Definition; -use crate::SpanDef; +use crate::{annotations::Annotation, ast::Rule, definitions::Definition, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/definitions/definition.rs b/grammar/src/definitions/definition.rs index d3a8e4a909..7fd46ef7f5 100644 --- a/grammar/src/definitions/definition.rs +++ b/grammar/src/definitions/definition.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::circuits::Circuit; -use crate::definitions::AnnotatedDefinition; -use crate::definitions::Deprecated; -use crate::functions::Function; -use crate::imports::Import; +use crate::{ + ast::Rule, + circuits::Circuit, + definitions::{AnnotatedDefinition, Deprecated}, + functions::Function, + imports::Import, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/definitions/deprecated.rs b/grammar/src/definitions/deprecated.rs index a8b4cd5e0f..5c8d514113 100644 --- a/grammar/src/definitions/deprecated.rs +++ b/grammar/src/definitions/deprecated.rs @@ -14,8 +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; -use crate::functions::TestFunction; +use crate::{ast::Rule, functions::TestFunction}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/errors/parser.rs b/grammar/src/errors/parser.rs index 39f936f59a..6f831d0ec2 100644 --- a/grammar/src/errors/parser.rs +++ b/grammar/src/errors/parser.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::errors::SyntaxError; +use crate::{ast::Rule, errors::SyntaxError}; use pest::error::Error; -use std::path::Path; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; #[derive(Debug, Error)] pub enum ParserError { diff --git a/grammar/src/expressions/array_initializer_expression.rs b/grammar/src/expressions/array_initializer_expression.rs index a724e3ebd9..c2a73e0d09 100644 --- a/grammar/src/expressions/array_initializer_expression.rs +++ b/grammar/src/expressions/array_initializer_expression.rs @@ -14,10 +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; -use crate::expressions::Expression; -use crate::types::ArrayDimensions; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, types::ArrayDimensions, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/array_inline_expression.rs b/grammar/src/expressions/array_inline_expression.rs index 53ad6b1a9f..5b3f4b7810 100644 --- a/grammar/src/expressions/array_inline_expression.rs +++ b/grammar/src/expressions/array_inline_expression.rs @@ -14,9 +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; -use crate::common::SpreadOrExpression; -use crate::SpanDef; +use crate::{ast::Rule, common::SpreadOrExpression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/binary_expression.rs b/grammar/src/expressions/binary_expression.rs index c61b3f5f47..1086121d5b 100644 --- a/grammar/src/expressions/binary_expression.rs +++ b/grammar/src/expressions/binary_expression.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::expressions::Expression; -use crate::operations::BinaryOperation; -use crate::SpanDef; +use crate::{expressions::Expression, operations::BinaryOperation, SpanDef}; use pest::Span; use serde::Serialize; diff --git a/grammar/src/expressions/circuit_inline_expression.rs b/grammar/src/expressions/circuit_inline_expression.rs index f6dbe9d0fe..6a51792bae 100644 --- a/grammar/src/expressions/circuit_inline_expression.rs +++ b/grammar/src/expressions/circuit_inline_expression.rs @@ -14,11 +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; -use crate::circuits::CircuitImpliedVariable; -use crate::common::Identifier; -use crate::types::SelfType; -use crate::SpanDef; +use crate::{ast::Rule, circuits::CircuitImpliedVariable, common::Identifier, types::SelfType, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/expression.rs b/grammar/src/expressions/expression.rs index dd5d9fee92..7d71761a5c 100644 --- a/grammar/src/expressions/expression.rs +++ b/grammar/src/expressions/expression.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::common::Identifier; -use crate::expressions::*; -use crate::operations::BinaryOperation; -use crate::values::Value; +use crate::{common::Identifier, expressions::*, operations::BinaryOperation, values::Value}; use pest::Span; use serde::Serialize; diff --git a/grammar/src/expressions/postfix_expression.rs b/grammar/src/expressions/postfix_expression.rs index 7701984f26..923de16161 100644 --- a/grammar/src/expressions/postfix_expression.rs +++ b/grammar/src/expressions/postfix_expression.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::access::Access; -use crate::ast::Rule; -use crate::common::KeywordOrIdentifier; -use crate::SpanDef; +use crate::{access::Access, ast::Rule, common::KeywordOrIdentifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/self_postfix_expression.rs b/grammar/src/expressions/self_postfix_expression.rs index 7c53e13912..21017bda2d 100644 --- a/grammar/src/expressions/self_postfix_expression.rs +++ b/grammar/src/expressions/self_postfix_expression.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::access::Access; -use crate::access::SelfAccess; -use crate::ast::Rule; -use crate::common::SelfKeyword; -use crate::SpanDef; +use crate::{ + access::{Access, SelfAccess}, + ast::Rule, + common::SelfKeyword, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/ternary_expression.rs b/grammar/src/expressions/ternary_expression.rs index 59a31e8844..163750bd61 100644 --- a/grammar/src/expressions/ternary_expression.rs +++ b/grammar/src/expressions/ternary_expression.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/tuple_expression.rs b/grammar/src/expressions/tuple_expression.rs index b15428f080..16b8727fe9 100644 --- a/grammar/src/expressions/tuple_expression.rs +++ b/grammar/src/expressions/tuple_expression.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/expressions/unary_expression.rs b/grammar/src/expressions/unary_expression.rs index c9e5ac74f9..b2d50fb4c4 100644 --- a/grammar/src/expressions/unary_expression.rs +++ b/grammar/src/expressions/unary_expression.rs @@ -14,10 +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; -use crate::expressions::Expression; -use crate::operations::UnaryOperation; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, operations::UnaryOperation, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/files/file.rs b/grammar/src/files/file.rs index 25eafba04b..6d1bc2fea3 100644 --- a/grammar/src/files/file.rs +++ b/grammar/src/files/file.rs @@ -14,10 +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; -use crate::common::EOI; -use crate::definitions::Definition; -use crate::SpanDef; +use crate::{ast::Rule, common::EOI, definitions::Definition, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/function.rs b/grammar/src/functions/function.rs index 1be25b8ac5..cd342b34bf 100644 --- a/grammar/src/functions/function.rs +++ b/grammar/src/functions/function.rs @@ -14,12 +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; -use crate::common::Identifier; -use crate::functions::input::Input; -use crate::statements::Block; -use crate::types::Type; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, functions::input::Input, statements::Block, types::Type, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/input/function_input.rs b/grammar/src/functions/input/function_input.rs index fbe85c730d..3cac32b798 100644 --- a/grammar/src/functions/input/function_input.rs +++ b/grammar/src/functions/input/function_input.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 . -use crate::ast::Rule; -use crate::common::Const; -use crate::common::Identifier; -use crate::common::Mutable; -use crate::types::Type; -use crate::SpanDef; +use crate::{ + ast::Rule, + common::{Const, Identifier, Mutable}, + types::Type, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/input/input.rs b/grammar/src/functions/input/input.rs index cecc2ed01a..9b2ef22ab7 100644 --- a/grammar/src/functions/input/input.rs +++ b/grammar/src/functions/input/input.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::MutSelfKeyword; -use crate::common::SelfKeyword; -use crate::functions::FunctionInput; -use crate::functions::InputKeyword; +use crate::{ + ast::Rule, + common::{MutSelfKeyword, SelfKeyword}, + functions::{FunctionInput, InputKeyword}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/functions/input/input_keyword.rs b/grammar/src/functions/input/input_keyword.rs index 1a76c63512..5032ae4436 100644 --- a/grammar/src/functions/input/input_keyword.rs +++ b/grammar/src/functions/input/input_keyword.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/functions/test_function.rs b/grammar/src/functions/test_function.rs index 834df3f2a9..1e28efc53c 100644 --- a/grammar/src/functions/test_function.rs +++ b/grammar/src/functions/test_function.rs @@ -14,9 +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; -use crate::functions::Function; -use crate::SpanDef; +use crate::{ast::Rule, functions::Function, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/import.rs b/grammar/src/imports/import.rs index 2c72ebc50c..1b62df80f3 100644 --- a/grammar/src/imports/import.rs +++ b/grammar/src/imports/import.rs @@ -14,10 +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; -use crate::common::LineEnd; -use crate::imports::PackageOrPackages; -use crate::SpanDef; +use crate::{ast::Rule, common::LineEnd, imports::PackageOrPackages, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/import_symbol.rs b/grammar/src/imports/import_symbol.rs index c0d4304b66..3643406618 100644 --- a/grammar/src/imports/import_symbol.rs +++ b/grammar/src/imports/import_symbol.rs @@ -14,9 +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; -use crate::common::Identifier; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/package.rs b/grammar/src/imports/package.rs index caffcaa13b..0b3f1a0ecb 100644 --- a/grammar/src/imports/package.rs +++ b/grammar/src/imports/package.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::imports::PackageAccess; -use crate::imports::PackageName; -use crate::SpanDef; +use crate::{ + ast::Rule, + imports::{PackageAccess, PackageName}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/package_access.rs b/grammar/src/imports/package_access.rs index 379520d6d4..7d172bd545 100644 --- a/grammar/src/imports/package_access.rs +++ b/grammar/src/imports/package_access.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::imports::ImportSymbol; -use crate::imports::Package; -use crate::imports::Packages; -use crate::imports::Star; +use crate::{ + ast::Rule, + imports::{ImportSymbol, Package, Packages, Star}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/imports/package_name.rs b/grammar/src/imports/package_name.rs index efe48335f4..a2e400460e 100644 --- a/grammar/src/imports/package_name.rs +++ b/grammar/src/imports/package_name.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/package_or_packages.rs b/grammar/src/imports/package_or_packages.rs index 9f3cc1049e..3cd0324480 100644 --- a/grammar/src/imports/package_or_packages.rs +++ b/grammar/src/imports/package_or_packages.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::imports::Package; -use crate::imports::Packages; +use crate::{ + ast::Rule, + imports::{Package, Packages}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/imports/packages.rs b/grammar/src/imports/packages.rs index 1cfa0f2a74..32003ffb16 100644 --- a/grammar/src/imports/packages.rs +++ b/grammar/src/imports/packages.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::imports::PackageAccess; -use crate::imports::PackageName; -use crate::SpanDef; +use crate::{ + ast::Rule, + imports::{PackageAccess, PackageName}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/imports/star.rs b/grammar/src/imports/star.rs index fc646aefe1..29cb6b6e35 100644 --- a/grammar/src/imports/star.rs +++ b/grammar/src/imports/star.rs @@ -14,8 +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; -use crate::SpanDef; +use crate::{ast::Rule, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/lib.rs b/grammar/src/lib.rs index 850dc37ff2..2f9e0fac02 100644 --- a/grammar/src/lib.rs +++ b/grammar/src/lib.rs @@ -51,8 +51,7 @@ pub(crate) mod span; pub(crate) use span::*; use from_pest::FromPest; -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; /// /// The grammar of a Leo program, encoded as an abstract syntax tree (AST). diff --git a/grammar/src/main.rs b/grammar/src/main.rs index 30ba62d972..ae9259084c 100644 --- a/grammar/src/main.rs +++ b/grammar/src/main.rs @@ -14,11 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_grammar::Grammar; -use leo_grammar::ParserError; -use std::env; -use std::fs; -use std::path::Path; +use leo_grammar::{Grammar, ParserError}; +use std::{env, fs, path::Path}; fn to_grammar(filepath: &Path) -> Result { // Loads the Leo code as a string from the given file path. diff --git a/grammar/src/span.rs b/grammar/src/span.rs index ba1be46daf..f7c0eae89d 100644 --- a/grammar/src/span.rs +++ b/grammar/src/span.rs @@ -15,8 +15,7 @@ // along with the Leo library. If not, see . use pest::Span; -use serde::Deserialize; -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. diff --git a/grammar/src/statements/assign_statement.rs b/grammar/src/statements/assign_statement.rs index 3bea311ab2..5325fd7b17 100644 --- a/grammar/src/statements/assign_statement.rs +++ b/grammar/src/statements/assign_statement.rs @@ -14,12 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::Assignee; -use crate::common::LineEnd; -use crate::expressions::Expression; -use crate::operations::AssignOperation; -use crate::SpanDef; +use crate::{ + ast::Rule, + common::{Assignee, LineEnd}, + expressions::Expression, + operations::AssignOperation, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/block.rs b/grammar/src/statements/block.rs index 12b3d856bf..bbbfe41ff7 100644 --- a/grammar/src/statements/block.rs +++ b/grammar/src/statements/block.rs @@ -14,9 +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; -use crate::statements::Statement; -use crate::SpanDef; +use crate::{ast::Rule, statements::Statement, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/conditional_nested_or_end_statement.rs b/grammar/src/statements/conditional_nested_or_end_statement.rs index a6807f1286..3bab38d701 100644 --- a/grammar/src/statements/conditional_nested_or_end_statement.rs +++ b/grammar/src/statements/conditional_nested_or_end_statement.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::statements::Block; -use crate::statements::ConditionalStatement; +use crate::{ + ast::Rule, + statements::{Block, ConditionalStatement}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/statements/conditional_statement.rs b/grammar/src/statements/conditional_statement.rs index 3145712852..2e6861f98b 100644 --- a/grammar/src/statements/conditional_statement.rs +++ b/grammar/src/statements/conditional_statement.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::expressions::Expression; -use crate::statements::Block; -use crate::statements::ConditionalNestedOrEndStatement; -use crate::SpanDef; +use crate::{ + ast::Rule, + expressions::Expression, + statements::{Block, ConditionalNestedOrEndStatement}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/definition_statement.rs b/grammar/src/statements/definition_statement.rs index 9b076d6a7c..c1db3c212d 100644 --- a/grammar/src/statements/definition_statement.rs +++ b/grammar/src/statements/definition_statement.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 . -use crate::ast::Rule; -use crate::common::Declare; -use crate::common::LineEnd; -use crate::common::Variables; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ + ast::Rule, + common::{Declare, LineEnd, Variables}, + expressions::Expression, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/expression_statement.rs b/grammar/src/statements/expression_statement.rs index 3b78a62b5f..bbef3f3568 100644 --- a/grammar/src/statements/expression_statement.rs +++ b/grammar/src/statements/expression_statement.rs @@ -14,10 +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; -use crate::common::LineEnd; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, common::LineEnd, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/for_statement.rs b/grammar/src/statements/for_statement.rs index c14b868e36..c1be00e303 100644 --- a/grammar/src/statements/for_statement.rs +++ b/grammar/src/statements/for_statement.rs @@ -14,11 +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; -use crate::common::Identifier; -use crate::expressions::Expression; -use crate::statements::Block; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, expressions::Expression, statements::Block, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/return_statement.rs b/grammar/src/statements/return_statement.rs index 22ce5597be..11d6b4ddcb 100644 --- a/grammar/src/statements/return_statement.rs +++ b/grammar/src/statements/return_statement.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::SpanDef; +use crate::{ast::Rule, expressions::Expression, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/statements/statement.rs b/grammar/src/statements/statement.rs index 771477c8f4..d01c5d072e 100644 --- a/grammar/src/statements/statement.rs +++ b/grammar/src/statements/statement.rs @@ -14,9 +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; -use crate::console::ConsoleFunctionCall; -use crate::statements::*; +use crate::{ast::Rule, console::ConsoleFunctionCall, statements::*}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/types/array_dimensions.rs b/grammar/src/types/array_dimensions.rs index 45928210bb..eb0aa89b1c 100644 --- a/grammar/src/types/array_dimensions.rs +++ b/grammar/src/types/array_dimensions.rs @@ -14,9 +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; -use crate::values::PositiveNumber; -use crate::SpanDef; +use crate::{ast::Rule, values::PositiveNumber, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/array_type.rs b/grammar/src/types/array_type.rs index 33ca7f227e..a91b08558b 100644 --- a/grammar/src/types/array_type.rs +++ b/grammar/src/types/array_type.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::ArrayDimensions; -use crate::types::Type; -use crate::SpanDef; +use crate::{ + ast::Rule, + types::{ArrayDimensions, Type}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/circuit_type.rs b/grammar/src/types/circuit_type.rs index 586267544d..c0156e100a 100644 --- a/grammar/src/types/circuit_type.rs +++ b/grammar/src/types/circuit_type.rs @@ -14,9 +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; -use crate::common::Identifier; -use crate::SpanDef; +use crate::{ast::Rule, common::Identifier, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/data_type.rs b/grammar/src/types/data_type.rs index acb7a17fe0..78143384a5 100644 --- a/grammar/src/types/data_type.rs +++ b/grammar/src/types/data_type.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::AddressType; -use crate::types::BooleanType; -use crate::types::FieldType; -use crate::types::GroupType; -use crate::types::IntegerType; +use crate::{ + ast::Rule, + types::{AddressType, BooleanType, FieldType, GroupType, IntegerType}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/types/integer_type.rs b/grammar/src/types/integer_type.rs index d9003fb402..729ac0fcc4 100644 --- a/grammar/src/types/integer_type.rs +++ b/grammar/src/types/integer_type.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::SignedIntegerType; -use crate::types::UnsignedIntegerType; +use crate::{ + ast::Rule, + types::{SignedIntegerType, UnsignedIntegerType}, +}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/types/self_type.rs b/grammar/src/types/self_type.rs index 99949e41f7..e3fb6bd072 100644 --- a/grammar/src/types/self_type.rs +++ b/grammar/src/types/self_type.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/tuple_type.rs b/grammar/src/types/tuple_type.rs index f2ff4a9e5f..57f39c9261 100644 --- a/grammar/src/types/tuple_type.rs +++ b/grammar/src/types/tuple_type.rs @@ -14,9 +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; -use crate::types::Type; -use crate::SpanDef; +use crate::{ast::Rule, types::Type, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/types/type_.rs b/grammar/src/types/type_.rs index ec1e7a9da6..d020a7ef07 100644 --- a/grammar/src/types/type_.rs +++ b/grammar/src/types/type_.rs @@ -14,8 +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; -use crate::types::*; +use crate::{ast::Rule, types::*}; use pest_ast::FromPest; use serde::Serialize; diff --git a/grammar/src/values/address.rs b/grammar/src/values/address.rs index 9c5372aa09..e1e815a6e7 100644 --- a/grammar/src/values/address.rs +++ b/grammar/src/values/address.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/address_value.rs b/grammar/src/values/address_value.rs index 2d7c67e8d5..decf47431e 100644 --- a/grammar/src/values/address_value.rs +++ b/grammar/src/values/address_value.rs @@ -14,10 +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; -use crate::types::AddressType; -use crate::values::address::Address; -use crate::SpanDef; +use crate::{ast::Rule, types::AddressType, values::address::Address, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/boolean_value.rs b/grammar/src/values/boolean_value.rs index 9a0219f655..9e26d369f9 100644 --- a/grammar/src/values/boolean_value.rs +++ b/grammar/src/values/boolean_value.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/field_value.rs b/grammar/src/values/field_value.rs index dc7464bcbc..fad986b83e 100644 --- a/grammar/src/values/field_value.rs +++ b/grammar/src/values/field_value.rs @@ -14,10 +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; -use crate::types::FieldType; -use crate::values::NumberValue; -use crate::SpanDef; +use crate::{ast::Rule, types::FieldType, values::NumberValue, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/group_coordinate.rs b/grammar/src/values/group_coordinate.rs index da1861c79d..4f12c477d4 100644 --- a/grammar/src/values/group_coordinate.rs +++ b/grammar/src/values/group_coordinate.rs @@ -14,9 +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; -use crate::values::NumberValue; -use crate::SpanDef; +use crate::{ast::Rule, values::NumberValue, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/group_value.rs b/grammar/src/values/group_value.rs index 4b9c7cc3d7..56ab231908 100644 --- a/grammar/src/values/group_value.rs +++ b/grammar/src/values/group_value.rs @@ -14,11 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::GroupType; -use crate::values::GroupCoordinate; -use crate::values::NumberValue; -use crate::SpanDef; +use crate::{ + ast::Rule, + types::GroupType, + values::{GroupCoordinate, NumberValue}, + SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/integer_value.rs b/grammar/src/values/integer_value.rs index 49b00b6fc7..64c0ebd640 100644 --- a/grammar/src/values/integer_value.rs +++ b/grammar/src/values/integer_value.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::SignedIntegerValue; -use crate::values::UnsignedIntegerValue; +use crate::{ + ast::Rule, + values::{SignedIntegerValue, UnsignedIntegerValue}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/negative_number.rs b/grammar/src/values/negative_number.rs index b0fd99eb7f..5cd52eaef0 100644 --- a/grammar/src/values/negative_number.rs +++ b/grammar/src/values/negative_number.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::span::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + span::SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/number_value.rs b/grammar/src/values/number_value.rs index e0c63164fc..1d090c7528 100644 --- a/grammar/src/values/number_value.rs +++ b/grammar/src/values/number_value.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::NegativeNumber; -use crate::values::PositiveNumber; +use crate::{ + ast::Rule, + values::{NegativeNumber, PositiveNumber}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/positive_number.rs b/grammar/src/values/positive_number.rs index a432b099ce..8fd522836f 100644 --- a/grammar/src/values/positive_number.rs +++ b/grammar/src/values/positive_number.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::span_into_string; -use crate::ast::Rule; -use crate::span::SpanDef; +use crate::{ + ast::{span_into_string, Rule}, + span::SpanDef, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/signed_integer_value.rs b/grammar/src/values/signed_integer_value.rs index 08e5884522..5c49a0ebf1 100644 --- a/grammar/src/values/signed_integer_value.rs +++ b/grammar/src/values/signed_integer_value.rs @@ -14,10 +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; -use crate::types::SignedIntegerType; -use crate::values::NumberValue; -use crate::SpanDef; +use crate::{ast::Rule, types::SignedIntegerType, values::NumberValue, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/unsigned_integer_value.rs b/grammar/src/values/unsigned_integer_value.rs index c17d541dcf..9b85ae8eea 100644 --- a/grammar/src/values/unsigned_integer_value.rs +++ b/grammar/src/values/unsigned_integer_value.rs @@ -14,10 +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; -use crate::types::UnsignedIntegerType; -use crate::values::PositiveNumber; -use crate::SpanDef; +use crate::{ast::Rule, types::UnsignedIntegerType, values::PositiveNumber, SpanDef}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/src/values/value.rs b/grammar/src/values/value.rs index 0314286277..2d92362c28 100644 --- a/grammar/src/values/value.rs +++ b/grammar/src/values/value.rs @@ -14,13 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::AddressValue; -use crate::values::BooleanValue; -use crate::values::FieldValue; -use crate::values::GroupValue; -use crate::values::IntegerValue; -use crate::values::NumberValue; +use crate::{ + ast::Rule, + values::{AddressValue, BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/grammar/tests/annotated.rs b/grammar/tests/annotated.rs index 0f31370018..32ac106dba 100644 --- a/grammar/tests/annotated.rs +++ b/grammar/tests/annotated.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/grammar/tests/circuits.rs b/grammar/tests/circuits.rs index 161c8ce467..33c77151ca 100644 --- a/grammar/tests/circuits.rs +++ b/grammar/tests/circuits.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/grammar/tests/deprecated.rs b/grammar/tests/deprecated.rs index e9090c4566..5ff8f94cb0 100644 --- a/grammar/tests/deprecated.rs +++ b/grammar/tests/deprecated.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/grammar/tests/display.rs b/grammar/tests/display.rs index ff67f18d42..38aaf42a70 100644 --- a/grammar/tests/display.rs +++ b/grammar/tests/display.rs @@ -15,9 +15,10 @@ // along with the Leo library. If not, see . use from_pest::FromPest; -use leo_grammar::ast::LanguageParser; -use leo_grammar::ast::Rule; -use leo_grammar::statements::ConditionalStatement; +use leo_grammar::{ + ast::{LanguageParser, Rule}, + statements::ConditionalStatement, +}; use pest::*; diff --git a/grammar/tests/expression.rs b/grammar/tests/expression.rs index f728b95b0f..589c16bcee 100644 --- a/grammar/tests/expression.rs +++ b/grammar/tests/expression.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/grammar/tests/function.rs b/grammar/tests/function.rs index 3b85e6e186..4bc1de7bf7 100644 --- a/grammar/tests/function.rs +++ b/grammar/tests/function.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/grammar/tests/imports.rs b/grammar/tests/imports.rs index 94ceabcce8..8ddd874e3d 100644 --- a/grammar/tests/imports.rs +++ b/grammar/tests/imports.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/grammar/tests/multiline.rs b/grammar/tests/multiline.rs index d5d03b5ebb..2c3fca1706 100644 --- a/grammar/tests/multiline.rs +++ b/grammar/tests/multiline.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; #[test] diff --git a/grammar/tests/self.rs b/grammar/tests/self.rs index 4a5ccf05c9..8157639e42 100644 --- a/grammar/tests/self.rs +++ b/grammar/tests/self.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; #[test] diff --git a/grammar/tests/tuple.rs b/grammar/tests/tuple.rs index 1a602e4f5e..1408d5c0d8 100644 --- a/grammar/tests/tuple.rs +++ b/grammar/tests/tuple.rs @@ -14,8 +14,7 @@ // 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; -use leo_grammar::ast::Rule; +use leo_grammar::ast::{LanguageParser, Rule}; use pest::*; diff --git a/imports/src/errors/import_parser.rs b/imports/src/errors/import_parser.rs index 378af76230..f3d901560c 100644 --- a/imports/src/errors/import_parser.rs +++ b/imports/src/errors/import_parser.rs @@ -14,15 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . use leo_asg::AsgConvertError; -use leo_ast::AstError; -use leo_ast::DeprecatedError; -use leo_ast::Error as FormattedError; -use leo_ast::Identifier; -use leo_ast::Span; +use leo_ast::{AstError, DeprecatedError, Error as FormattedError, Identifier, Span}; use leo_grammar::ParserError; -use std::io; -use std::path::Path; +use std::{io, path::Path}; #[derive(Debug, Error)] pub enum ImportParserError { diff --git a/imports/src/parser/import_parser.rs b/imports/src/parser/import_parser.rs index 2e803ac303..300408cffb 100644 --- a/imports/src/parser/import_parser.rs +++ b/imports/src/parser/import_parser.rs @@ -15,14 +15,9 @@ // along with the Leo library. If not, see . use crate::errors::ImportParserError; -use leo_asg::AsgContext; -use leo_asg::AsgConvertError; -use leo_asg::ImportResolver; -use leo_asg::Program; -use leo_asg::Span; +use leo_asg::{AsgContext, AsgConvertError, ImportResolver, Program, Span}; -use indexmap::IndexMap; -use indexmap::IndexSet; +use indexmap::{IndexMap, IndexSet}; use std::env::current_dir; /// Stores imported packages. diff --git a/imports/src/parser/parse_package.rs b/imports/src/parser/parse_package.rs index 44d20b0b35..3acd05e41b 100644 --- a/imports/src/parser/parse_package.rs +++ b/imports/src/parser/parse_package.rs @@ -14,16 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::ImportParserError; -use crate::ImportParser; -use leo_asg::AsgContext; -use leo_asg::Identifier; -use leo_asg::Program; -use leo_asg::Span; +use crate::{errors::ImportParserError, ImportParser}; +use leo_asg::{AsgContext, Identifier, Program, Span}; -use std::fs; -use std::fs::DirEntry; -use std::path::PathBuf; +use std::{fs, fs::DirEntry, path::PathBuf}; static SOURCE_FILE_EXTENSION: &str = ".leo"; static SOURCE_DIRECTORY_NAME: &str = "src/"; diff --git a/imports/src/parser/parse_symbol.rs b/imports/src/parser/parse_symbol.rs index 8cc27a706f..9b02656d75 100644 --- a/imports/src/parser/parse_symbol.rs +++ b/imports/src/parser/parse_symbol.rs @@ -14,10 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::ImportParserError; -use crate::ImportParser; -use leo_ast::Program; -use leo_ast::Span; +use crate::{errors::ImportParserError, ImportParser}; +use leo_ast::{Program, Span}; use leo_grammar::Grammar; use std::fs::DirEntry; diff --git a/input/src/ast.rs b/input/src/ast.rs index 74176907b3..cfb3deef07 100644 --- a/input/src/ast.rs +++ b/input/src/ast.rs @@ -15,10 +15,7 @@ // along with the Leo library. If not, see . //! Abstract syntax tree (ast) representation from leo-input.pest. -use pest::error::Error; -use pest::iterators::Pairs; -use pest::Parser; -use pest::Span; +use pest::{error::Error, iterators::Pairs, Parser, Span}; #[derive(Parser)] #[grammar = "leo-input.pest"] diff --git a/input/src/common/identifier.rs b/input/src/common/identifier.rs index 8af41c89ee..606ac424ee 100644 --- a/input/src/common/identifier.rs +++ b/input/src/common/identifier.rs @@ -14,8 +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::span_into_string; -use crate::ast::Rule; +use crate::ast::{span_into_string, Rule}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/definitions/definition.rs b/input/src/definitions/definition.rs index 0f682e3628..c0c64bbe67 100644 --- a/input/src/definitions/definition.rs +++ b/input/src/definitions/definition.rs @@ -14,10 +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; -use crate::common::LineEnd; -use crate::expressions::Expression; -use crate::parameters::Parameter; +use crate::{ast::Rule, common::LineEnd, expressions::Expression, parameters::Parameter}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/errors/parser.rs b/input/src/errors/parser.rs index e67b4db760..71bdbee253 100644 --- a/input/src/errors/parser.rs +++ b/input/src/errors/parser.rs @@ -14,24 +14,25 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::errors::SyntaxError as InputSyntaxError; -use crate::expressions::ArrayInlineExpression; -use crate::expressions::Expression; -use crate::sections::Header; -use crate::tables::Table; -use crate::types::DataType; -use crate::types::Type; -use crate::values::NumberValue; -use crate::values::Value; +use crate::{ + ast::Rule, + errors::SyntaxError as InputSyntaxError, + expressions::{ArrayInlineExpression, Expression}, + sections::Header, + tables::Table, + types::{DataType, Type}, + values::{NumberValue, Value}, +}; -use pest::error::Error; -use pest::error::ErrorVariant; -use pest::Span; -use std::num::ParseIntError; -use std::path::Path; -use std::path::PathBuf; -use std::str::ParseBoolError; +use pest::{ + error::{Error, ErrorVariant}, + Span, +}; +use std::{ + num::ParseIntError, + path::{Path, PathBuf}, + str::ParseBoolError, +}; #[derive(Debug, Error)] pub enum InputParserError { diff --git a/input/src/expressions/array_initializer_expression.rs b/input/src/expressions/array_initializer_expression.rs index 812ddd21e5..7870ac76ba 100644 --- a/input/src/expressions/array_initializer_expression.rs +++ b/input/src/expressions/array_initializer_expression.rs @@ -14,9 +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; -use crate::expressions::Expression; -use crate::types::ArrayDimensions; +use crate::{ast::Rule, expressions::Expression, types::ArrayDimensions}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/expressions/array_inline_expression.rs b/input/src/expressions/array_inline_expression.rs index b961aa94ab..573085bc79 100644 --- a/input/src/expressions/array_inline_expression.rs +++ b/input/src/expressions/array_inline_expression.rs @@ -14,8 +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; -use crate::expressions::Expression; +use crate::{ast::Rule, expressions::Expression}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/expressions/expression.rs b/input/src/expressions/expression.rs index ed2f5f8fec..4694307b58 100644 --- a/input/src/expressions/expression.rs +++ b/input/src/expressions/expression.rs @@ -14,9 +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; -use crate::expressions::*; -use crate::values::Value; +use crate::{ast::Rule, expressions::*, values::Value}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/expressions/tuple_expression.rs b/input/src/expressions/tuple_expression.rs index 4b831a6175..5cbb95dffb 100644 --- a/input/src/expressions/tuple_expression.rs +++ b/input/src/expressions/tuple_expression.rs @@ -14,8 +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; -use crate::expressions::Expression; +use crate::{ast::Rule, expressions::Expression}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/files/file.rs b/input/src/files/file.rs index 3caf037aeb..61142390b8 100644 --- a/input/src/files/file.rs +++ b/input/src/files/file.rs @@ -14,9 +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; -use crate::common::EOI; -use crate::files::TableOrSection; +use crate::{ast::Rule, common::EOI, files::TableOrSection}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/files/table_or_section.rs b/input/src/files/table_or_section.rs index 11fe801ac4..93dd31dfc9 100644 --- a/input/src/files/table_or_section.rs +++ b/input/src/files/table_or_section.rs @@ -14,9 +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; -use crate::sections::Section; -use crate::tables::Table; +use crate::{ast::Rule, sections::Section, tables::Table}; use pest_ast::FromPest; diff --git a/input/src/lib.rs b/input/src/lib.rs index 9bdb8ead9f..e2537eeeb1 100644 --- a/input/src/lib.rs +++ b/input/src/lib.rs @@ -34,8 +34,7 @@ pub mod types; pub mod values; use from_pest::FromPest; -use std::fs; -use std::path::Path; +use std::{fs, path::Path}; pub struct LeoInputParser; diff --git a/input/src/parameters/parameter.rs b/input/src/parameters/parameter.rs index 10f76536e0..410ef775a9 100644 --- a/input/src/parameters/parameter.rs +++ b/input/src/parameters/parameter.rs @@ -14,9 +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; -use crate::common::Identifier; -use crate::types::Type; +use crate::{ast::Rule, common::Identifier, types::Type}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/sections/header.rs b/input/src/sections/header.rs index bae10df0e3..ca437c0a45 100644 --- a/input/src/sections/header.rs +++ b/input/src/sections/header.rs @@ -14,13 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::common::Identifier; -use crate::sections::Main; -use crate::sections::Record; -use crate::sections::Registers; -use crate::sections::State; -use crate::sections::StateLeaf; +use crate::{ + ast::Rule, + common::Identifier, + sections::{Main, Record, Registers, State, StateLeaf}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/sections/section.rs b/input/src/sections/section.rs index a35ece07a5..e53a6331cd 100644 --- a/input/src/sections/section.rs +++ b/input/src/sections/section.rs @@ -14,9 +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; -use crate::definitions::Definition; -use crate::sections::Header; +use crate::{ast::Rule, definitions::Definition, sections::Header}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/tables/table.rs b/input/src/tables/table.rs index beb272c62f..9ea777cbda 100644 --- a/input/src/tables/table.rs +++ b/input/src/tables/table.rs @@ -14,9 +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; -use crate::sections::Section; -use crate::tables::Visibility; +use crate::{ast::Rule, sections::Section, tables::Visibility}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/tables/visibility.rs b/input/src/tables/visibility.rs index c3bd9586b8..0abe3828ee 100644 --- a/input/src/tables/visibility.rs +++ b/input/src/tables/visibility.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::tables::Private; -use crate::tables::Public; +use crate::{ + ast::Rule, + tables::{Private, Public}, +}; use pest_ast::FromPest; use std::fmt; diff --git a/input/src/types/array_dimensions.rs b/input/src/types/array_dimensions.rs index b89ce0269d..776ca0d899 100644 --- a/input/src/types/array_dimensions.rs +++ b/input/src/types/array_dimensions.rs @@ -14,8 +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; -use crate::values::PositiveNumber; +use crate::{ast::Rule, values::PositiveNumber}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/types/array_type.rs b/input/src/types/array_type.rs index 3b5700a960..0132228e0d 100644 --- a/input/src/types/array_type.rs +++ b/input/src/types/array_type.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::ArrayDimensions; -use crate::types::Type; +use crate::{ + ast::Rule, + types::{ArrayDimensions, Type}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/types/data_type.rs b/input/src/types/data_type.rs index 5f948718a2..ecb82e3bda 100644 --- a/input/src/types/data_type.rs +++ b/input/src/types/data_type.rs @@ -14,11 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::BooleanType; -use crate::types::FieldType; -use crate::types::GroupType; -use crate::types::IntegerType; +use crate::{ + ast::Rule, + types::{BooleanType, FieldType, GroupType, IntegerType}, +}; use crate::types::AddressType; use pest_ast::FromPest; diff --git a/input/src/types/integer_type.rs b/input/src/types/integer_type.rs index d6a636c94f..a66e28d079 100644 --- a/input/src/types/integer_type.rs +++ b/input/src/types/integer_type.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::SignedIntegerType; -use crate::types::UnsignedIntegerType; +use crate::{ + ast::Rule, + types::{SignedIntegerType, UnsignedIntegerType}, +}; use pest_ast::FromPest; use std::fmt; diff --git a/input/src/types/tuple_type.rs b/input/src/types/tuple_type.rs index c5a6aaa3e7..c5086c077a 100644 --- a/input/src/types/tuple_type.rs +++ b/input/src/types/tuple_type.rs @@ -14,8 +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; -use crate::types::Type; +use crate::{ast::Rule, types::Type}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/types/type_.rs b/input/src/types/type_.rs index 23b2fb63f7..605f919f1d 100644 --- a/input/src/types/type_.rs +++ b/input/src/types/type_.rs @@ -14,8 +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; -use crate::types::*; +use crate::{ast::Rule, types::*}; use pest_ast::FromPest; use std::fmt; diff --git a/input/src/values/address.rs b/input/src/values/address.rs index e3adbea7a8..becdf5f31f 100644 --- a/input/src/values/address.rs +++ b/input/src/values/address.rs @@ -14,8 +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::span_into_string; -use crate::ast::Rule; +use crate::ast::{span_into_string, Rule}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/address_typed.rs b/input/src/values/address_typed.rs index a353c51027..17e678e86c 100644 --- a/input/src/values/address_typed.rs +++ b/input/src/values/address_typed.rs @@ -14,9 +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; -use crate::types::AddressType; -use crate::values::address::Address; +use crate::{ast::Rule, types::AddressType, values::address::Address}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/address_value.rs b/input/src/values/address_value.rs index 9de8bfa0d8..6134c41278 100644 --- a/input/src/values/address_value.rs +++ b/input/src/values/address_value.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::Address; -use crate::values::AddressTyped; +use crate::{ + ast::Rule, + values::{Address, AddressTyped}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/boolean_value.rs b/input/src/values/boolean_value.rs index fb7f026964..769cddd049 100644 --- a/input/src/values/boolean_value.rs +++ b/input/src/values/boolean_value.rs @@ -14,8 +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::span_into_string; -use crate::ast::Rule; +use crate::ast::{span_into_string, Rule}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/field_value.rs b/input/src/values/field_value.rs index 49a4b95cee..f3bc21ebb4 100644 --- a/input/src/values/field_value.rs +++ b/input/src/values/field_value.rs @@ -14,9 +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; -use crate::types::FieldType; -use crate::values::NumberValue; +use crate::{ast::Rule, types::FieldType, values::NumberValue}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/group_coordinate.rs b/input/src/values/group_coordinate.rs index a5ed031861..8a4882c39c 100644 --- a/input/src/values/group_coordinate.rs +++ b/input/src/values/group_coordinate.rs @@ -14,8 +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; -use crate::values::NumberValue; +use crate::{ast::Rule, values::NumberValue}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/group_value.rs b/input/src/values/group_value.rs index c9b17d90e0..bc4c72eb17 100644 --- a/input/src/values/group_value.rs +++ b/input/src/values/group_value.rs @@ -14,10 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::types::GroupType; -use crate::values::GroupCoordinate; -use crate::values::NumberValue; +use crate::{ + ast::Rule, + types::GroupType, + values::{GroupCoordinate, NumberValue}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/integer_value.rs b/input/src/values/integer_value.rs index f866879ef4..9e1004a929 100644 --- a/input/src/values/integer_value.rs +++ b/input/src/values/integer_value.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::SignedIntegerValue; -use crate::values::UnsignedIntegerValue; +use crate::{ + ast::Rule, + values::{SignedIntegerValue, UnsignedIntegerValue}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/negative_number.rs b/input/src/values/negative_number.rs index bd24cfff6b..704580fb9e 100644 --- a/input/src/values/negative_number.rs +++ b/input/src/values/negative_number.rs @@ -14,8 +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::span_into_string; -use crate::ast::Rule; +use crate::ast::{span_into_string, Rule}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/number_value.rs b/input/src/values/number_value.rs index 6014c2488b..2071dca1a3 100644 --- a/input/src/values/number_value.rs +++ b/input/src/values/number_value.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::NegativeNumber; -use crate::values::PositiveNumber; +use crate::{ + ast::Rule, + values::{NegativeNumber, PositiveNumber}, +}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/positive_number.rs b/input/src/values/positive_number.rs index 6270e3614e..9ccf38cff2 100644 --- a/input/src/values/positive_number.rs +++ b/input/src/values/positive_number.rs @@ -14,8 +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::span_into_string; -use crate::ast::Rule; +use crate::ast::{span_into_string, Rule}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/signed_integer_value.rs b/input/src/values/signed_integer_value.rs index 153b6a95d4..acd4301c0e 100644 --- a/input/src/values/signed_integer_value.rs +++ b/input/src/values/signed_integer_value.rs @@ -14,9 +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; -use crate::types::SignedIntegerType; -use crate::values::NumberValue; +use crate::{ast::Rule, types::SignedIntegerType, values::NumberValue}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/unsigned_integer_value.rs b/input/src/values/unsigned_integer_value.rs index 22046a9a92..7b0193069c 100644 --- a/input/src/values/unsigned_integer_value.rs +++ b/input/src/values/unsigned_integer_value.rs @@ -14,9 +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; -use crate::types::UnsignedIntegerType; -use crate::values::PositiveNumber; +use crate::{ast::Rule, types::UnsignedIntegerType, values::PositiveNumber}; use pest::Span; use pest_ast::FromPest; diff --git a/input/src/values/value.rs b/input/src/values/value.rs index 760dcee4fe..214b705bb0 100644 --- a/input/src/values/value.rs +++ b/input/src/values/value.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::ast::Rule; -use crate::values::BooleanValue; -use crate::values::FieldValue; -use crate::values::GroupValue; -use crate::values::IntegerValue; -use crate::values::NumberValue; +use crate::{ + ast::Rule, + values::{BooleanValue, FieldValue, GroupValue, IntegerValue, NumberValue}, +}; use crate::values::AddressValue; use pest::Span; diff --git a/leo/api.rs b/leo/api.rs index 244dd0aa05..23e12b3578 100644 --- a/leo/api.rs +++ b/leo/api.rs @@ -14,13 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use anyhow::anyhow; -use anyhow::Error; -use anyhow::Result; -use reqwest::blocking::Client; -use reqwest::blocking::Response; -use reqwest::Method; -use reqwest::StatusCode; +use anyhow::{anyhow, Error, Result}; +use reqwest::{ + blocking::{Client, Response}, + Method, + StatusCode, +}; use serde::Serialize; /// Trait describes API Routes and Request bodies, struct which implements diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 31124d1b58..5f47cd1a6b 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -14,27 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; -use leo_compiler::compiler::thread_leaked_context; -use leo_compiler::compiler::Compiler; -use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; -use leo_package::inputs::*; -use leo_package::outputs::ChecksumFile; -use leo_package::outputs::CircuitFile; -use leo_package::outputs::OutputsDirectory; -use leo_package::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_package::source::LibraryFile; -use leo_package::source::MainFile; -use leo_package::source::LIBRARY_FILENAME; -use leo_package::source::MAIN_FILENAME; -use leo_package::source::SOURCE_DIRECTORY_NAME; -use leo_synthesizer::CircuitSynthesizer; -use leo_synthesizer::SerializedCircuit; +use crate::{commands::Command, context::Context}; +use leo_compiler::{ + compiler::{thread_leaked_context, Compiler}, + group::targets::edwards_bls12::EdwardsGroupType, +}; +use leo_package::{ + inputs::*, + outputs::{ChecksumFile, CircuitFile, OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, + source::{LibraryFile, MainFile, LIBRARY_FILENAME, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, +}; +use leo_synthesizer::{CircuitSynthesizer, SerializedCircuit}; use anyhow::Result; -use snarkvm_curves::bls12_377::Bls12_377; -use snarkvm_curves::edwards_bls12::Fq; +use snarkvm_curves::{bls12_377::Bls12_377, edwards_bls12::Fq}; use snarkvm_r1cs::ConstraintSystem; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/clean.rs b/leo/commands/clean.rs index 47bc2e1d1a..0b39661f07 100644 --- a/leo/commands/clean.rs +++ b/leo/commands/clean.rs @@ -14,14 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use leo_compiler::OutputFile; -use leo_package::outputs::ChecksumFile; -use leo_package::outputs::CircuitFile; -use leo_package::outputs::ProofFile; -use leo_package::outputs::ProvingKeyFile; -use leo_package::outputs::VerificationKeyFile; +use leo_package::outputs::{ChecksumFile, CircuitFile, ProofFile, ProvingKeyFile, VerificationKeyFile}; use anyhow::Result; use structopt::StructOpt; diff --git a/leo/commands/deploy.rs b/leo/commands/deploy.rs index d3024ec902..06eff0c2e6 100644 --- a/leo/commands/deploy.rs +++ b/leo/commands/deploy.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use anyhow::Result; use structopt::StructOpt; diff --git a/leo/commands/init.rs b/leo/commands/init.rs index a80d194965..7c6b3e7745 100644 --- a/leo/commands/init.rs +++ b/leo/commands/init.rs @@ -14,12 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use leo_package::LeoPackage; -use anyhow::anyhow; -use anyhow::Result; +use anyhow::{anyhow, Result}; use std::env::current_dir; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/lint.rs b/leo/commands/lint.rs index 9449d6f658..3e60d7ec6e 100644 --- a/leo/commands/lint.rs +++ b/leo/commands/lint.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use anyhow::Result; use structopt::StructOpt; diff --git a/leo/commands/mod.rs b/leo/commands/mod.rs index bbaf2cbb60..47d5994575 100644 --- a/leo/commands/mod.rs +++ b/leo/commands/mod.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::context::get_context; -use crate::context::Context; +use crate::context::{get_context, Context}; use anyhow::Result; use std::time::Instant; @@ -53,8 +52,7 @@ pub mod test; pub use test::Test; pub mod update; -pub use update::Automatic as UpdateAutomatic; -pub use update::Update; +pub use update::{Automatic as UpdateAutomatic, Update}; pub mod watch; pub use watch::Watch; diff --git a/leo/commands/new.rs b/leo/commands/new.rs index b311445070..a4da67c309 100644 --- a/leo/commands/new.rs +++ b/leo/commands/new.rs @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use leo_package::LeoPackage; -use anyhow::anyhow; -use anyhow::Result; -use std::env::current_dir; -use std::fs; +use anyhow::{anyhow, Result}; +use std::{env::current_dir, fs}; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/package/add.rs b/leo/commands/package/add.rs index 9543e7809a..ef1491f2f9 100644 --- a/leo/commands/package/add.rs +++ b/leo/commands/package/add.rs @@ -14,18 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::api::Fetch; -use crate::commands::Command; -use crate::context::Context; -use leo_package::imports::ImportsDirectory; -use leo_package::imports::IMPORTS_DIRECTORY_NAME; +use crate::{api::Fetch, commands::Command, context::Context}; +use leo_package::imports::{ImportsDirectory, IMPORTS_DIRECTORY_NAME}; -use anyhow::anyhow; -use anyhow::Result; -use std::fs::create_dir_all; -use std::fs::File; -use std::io::Read; -use std::io::Write; +use anyhow::{anyhow, Result}; +use std::{ + fs::{create_dir_all, File}, + io::{Read, Write}, +}; use structopt::StructOpt; use tracing::Span; diff --git a/leo/commands/package/clone.rs b/leo/commands/package/clone.rs index f4dfaf846a..5b5e6acdcf 100644 --- a/leo/commands/package/clone.rs +++ b/leo/commands/package/clone.rs @@ -14,18 +14,18 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::api::Fetch; -use crate::commands::Command; -use crate::context::Context; +use crate::{api::Fetch, commands::Command, context::Context}; -use anyhow::anyhow; -use anyhow::Result; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Read; -use std::io::Write; -use std::path::Path; +use anyhow::{anyhow, Result}; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::{Read, Write}, + path::Path, +}; use structopt::StructOpt; use tracing::Span; diff --git a/leo/commands/package/login.rs b/leo/commands/package/login.rs index 83d81ac6c6..25425fccb0 100644 --- a/leo/commands/package/login.rs +++ b/leo/commands/package/login.rs @@ -14,14 +14,14 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::api::Login as LoginRoute; -use crate::api::Profile as ProfileRoute; -use crate::commands::Command; -use crate::config::*; -use crate::context::Context; +use crate::{ + api::{Login as LoginRoute, Profile as ProfileRoute}, + commands::Command, + config::*, + context::Context, +}; -use anyhow::anyhow; -use anyhow::Result; +use anyhow::{anyhow, Result}; use std::collections::HashMap; use structopt::StructOpt; use tracing::Span; diff --git a/leo/commands/package/logout.rs b/leo/commands/package/logout.rs index 4bc38b8cad..6bd76a2575 100644 --- a/leo/commands/package/logout.rs +++ b/leo/commands/package/logout.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::config::remove_token; -use crate::context::Context; +use crate::{commands::Command, config::remove_token, context::Context}; use anyhow::Result; use std::io::ErrorKind; diff --git a/leo/commands/package/publish.rs b/leo/commands/package/publish.rs index 382e9ad6c5..7b86763c67 100644 --- a/leo/commands/package/publish.rs +++ b/leo/commands/package/publish.rs @@ -15,18 +15,17 @@ // along with the Leo library. If not, see . use super::build::Build; -use crate::commands::Command; -use crate::context::Context; -use crate::context::PACKAGE_MANAGER_URL; -use leo_package::outputs::OutputsDirectory; -use leo_package::root::ZipFile; +use crate::{ + commands::Command, + context::{Context, PACKAGE_MANAGER_URL}, +}; +use leo_package::{outputs::OutputsDirectory, root::ZipFile}; -use anyhow::anyhow; -use anyhow::Result; -use reqwest::blocking::multipart::Form; -use reqwest::blocking::Client; -use reqwest::header::HeaderMap; -use reqwest::header::HeaderValue; +use anyhow::{anyhow, Result}; +use reqwest::{ + blocking::{multipart::Form, Client}, + header::{HeaderMap, HeaderValue}, +}; use serde::Deserialize; use structopt::StructOpt; diff --git a/leo/commands/package/remove.rs b/leo/commands/package/remove.rs index 5d88725cc9..f0df722146 100644 --- a/leo/commands/package/remove.rs +++ b/leo/commands/package/remove.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use leo_package::LeoPackage; use anyhow::Result; diff --git a/leo/commands/prove.rs b/leo/commands/prove.rs index 3072841b99..da99c84aed 100644 --- a/leo/commands/prove.rs +++ b/leo/commands/prove.rs @@ -15,15 +15,13 @@ // along with the Leo library. If not, see . use super::setup::Setup; -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; use leo_package::outputs::ProofFile; -use snarkvm_algorithms::snark::groth16::Groth16; -use snarkvm_algorithms::snark::groth16::PreparedVerifyingKey; -use snarkvm_algorithms::snark::groth16::Proof; -use snarkvm_algorithms::traits::SNARK; -use snarkvm_curves::bls12_377::Bls12_377; -use snarkvm_curves::bls12_377::Fr; +use snarkvm_algorithms::{ + snark::groth16::{Groth16, PreparedVerifyingKey, Proof}, + traits::SNARK, +}; +use snarkvm_curves::bls12_377::{Bls12_377, Fr}; use snarkvm_utilities::bytes::ToBytes; use anyhow::Result; diff --git a/leo/commands/run.rs b/leo/commands/run.rs index 16e3f7f433..eeec6fc02d 100644 --- a/leo/commands/run.rs +++ b/leo/commands/run.rs @@ -15,16 +15,12 @@ // along with the Leo library. If not, see . use super::prove::Prove; -use crate::commands::Command; -use crate::context::Context; -use leo_compiler::compiler::Compiler; -use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; +use crate::{commands::Command, context::Context}; +use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; use anyhow::Result; -use snarkvm_algorithms::snark::groth16::Groth16; -use snarkvm_algorithms::traits::SNARK; -use snarkvm_curves::bls12_377::Bls12_377; -use snarkvm_curves::bls12_377::Fr; +use snarkvm_algorithms::{snark::groth16::Groth16, traits::SNARK}; +use snarkvm_curves::bls12_377::{Bls12_377, Fr}; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index c152033b43..5f76d88dd0 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -15,25 +15,20 @@ // along with the Leo library. If not, see . use super::build::Build; -use crate::commands::Command; -use crate::context::Context; -use leo_compiler::compiler::Compiler; -use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; -use leo_package::outputs::ProvingKeyFile; -use leo_package::outputs::VerificationKeyFile; -use leo_package::source::MAIN_FILENAME; -use leo_package::source::SOURCE_DIRECTORY_NAME; +use crate::{commands::Command, context::Context}; +use leo_compiler::{compiler::Compiler, group::targets::edwards_bls12::EdwardsGroupType}; +use leo_package::{ + outputs::{ProvingKeyFile, VerificationKeyFile}, + source::{MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, +}; -use anyhow::anyhow; -use anyhow::Result; +use anyhow::{anyhow, Result}; use rand::thread_rng; -use snarkvm_algorithms::snark::groth16::Groth16; -use snarkvm_algorithms::snark::groth16::Parameters; -use snarkvm_algorithms::snark::groth16::PreparedVerifyingKey; -use snarkvm_algorithms::snark::groth16::VerifyingKey; -use snarkvm_algorithms::traits::snark::SNARK; -use snarkvm_curves::bls12_377::Bls12_377; -use snarkvm_curves::bls12_377::Fr; +use snarkvm_algorithms::{ + snark::groth16::{Groth16, Parameters, PreparedVerifyingKey, VerifyingKey}, + traits::snark::SNARK, +}; +use snarkvm_curves::bls12_377::{Bls12_377, Fr}; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/test.rs b/leo/commands/test.rs index a167af6e94..f5de8672f2 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -14,24 +14,20 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::context::Context; -use leo_compiler::compiler::thread_leaked_context; -use leo_compiler::compiler::Compiler; -use leo_compiler::group::targets::edwards_bls12::EdwardsGroupType; -use leo_package::inputs::*; -use leo_package::outputs::OutputsDirectory; -use leo_package::outputs::OUTPUTS_DIRECTORY_NAME; -use leo_package::source::MainFile; -use leo_package::source::MAIN_FILENAME; -use leo_package::source::SOURCE_DIRECTORY_NAME; +use crate::{commands::Command, context::Context}; +use leo_compiler::{ + compiler::{thread_leaked_context, Compiler}, + group::targets::edwards_bls12::EdwardsGroupType, +}; +use leo_package::{ + inputs::*, + outputs::{OutputsDirectory, OUTPUTS_DIRECTORY_NAME}, + source::{MainFile, MAIN_FILENAME, SOURCE_DIRECTORY_NAME}, +}; -use anyhow::anyhow; -use anyhow::Result; +use anyhow::{anyhow, Result}; use snarkvm_curves::edwards_bls12::Fq; -use std::convert::TryFrom; -use std::path::PathBuf; -use std::time::Instant; +use std::{convert::TryFrom, path::PathBuf, time::Instant}; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/update.rs b/leo/commands/update.rs index c643ec2b49..f3027e5907 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -14,13 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::commands::Command; -use crate::config::Config; -use crate::context::Context; -use crate::updater::Updater; +use crate::{commands::Command, config::Config, context::Context, updater::Updater}; -use anyhow::anyhow; -use anyhow::Result; +use anyhow::{anyhow, Result}; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/commands/watch.rs b/leo/commands/watch.rs index ef4f4bf80a..7a98b9604f 100644 --- a/leo/commands/watch.rs +++ b/leo/commands/watch.rs @@ -15,18 +15,12 @@ // along with the Leo library. If not, see . use super::build::Build; -use crate::commands::Command; -use crate::context::Context; +use crate::{commands::Command, context::Context}; -use std::sync::mpsc::channel; -use std::time::Duration; +use std::{sync::mpsc::channel, time::Duration}; -use anyhow::anyhow; -use anyhow::Result; -use notify::watcher; -use notify::DebouncedEvent; -use notify::RecursiveMode; -use notify::Watcher; +use anyhow::{anyhow, Result}; +use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher}; use structopt::StructOpt; use tracing::span::Span; diff --git a/leo/config.rs b/leo/config.rs index 3b9373896a..11de847b70 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -14,19 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::fs::create_dir_all; -use std::fs::File; -use std::fs::{self}; -use std::io; -use std::io::prelude::*; -use std::path::Path; -use std::path::PathBuf; +use std::{ + fs::{ + create_dir_all, + File, + {self}, + }, + io, + io::prelude::*, + path::{Path, PathBuf}, +}; use anyhow::Error; use dirs::home_dir; use lazy_static::lazy_static; -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; pub const LEO_CREDENTIALS_FILE: &str = "credentials"; pub const LEO_CONFIG_FILE: &str = "config.toml"; diff --git a/leo/context.rs b/leo/context.rs index 04404fc2e5..bddd54e5f2 100644 --- a/leo/context.rs +++ b/leo/context.rs @@ -14,14 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::api::Api; -use crate::config; +use crate::{api::Api, config}; use leo_package::root::Manifest; use anyhow::Result; -use std::convert::TryFrom; -use std::env::current_dir; -use std::path::PathBuf; +use std::{convert::TryFrom, env::current_dir, path::PathBuf}; pub const PACKAGE_MANAGER_URL: &str = "https://api.aleo.pm/"; diff --git a/leo/logger.rs b/leo/logger.rs index 69df6295b6..a2f81bc4c1 100644 --- a/leo/logger.rs +++ b/leo/logger.rs @@ -17,14 +17,12 @@ use std::fmt; use colored::Colorize; -use tracing::event::Event; -use tracing::subscriber::Subscriber; -use tracing_subscriber::fmt::format::*; -use tracing_subscriber::fmt::time::*; -use tracing_subscriber::fmt::FmtContext; -use tracing_subscriber::fmt::FormattedFields; -use tracing_subscriber::registry::LookupSpan; -use tracing_subscriber::FmtSubscriber; +use tracing::{event::Event, subscriber::Subscriber}; +use tracing_subscriber::{ + fmt::{format::*, time::*, FmtContext, FormattedFields}, + registry::LookupSpan, + FmtSubscriber, +}; #[derive(Debug, Clone)] pub struct Format { diff --git a/leo/main.rs b/leo/main.rs index bf48db7525..a0d256230c 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -21,30 +21,26 @@ pub mod context; pub mod logger; pub mod updater; -use commands::package::Add; -use commands::package::Clone; -use commands::package::Login; -use commands::package::Logout; -use commands::package::Publish; -use commands::package::Remove; -use commands::Build; -use commands::Clean; -use commands::Command; -use commands::Deploy; -use commands::Init; -use commands::Lint; -use commands::New; -use commands::Prove; -use commands::Run; -use commands::Setup; -use commands::Test; -use commands::Update; -use commands::Watch; +use commands::{ + package::{Add, Clone, Login, Logout, Publish, Remove}, + Build, + Clean, + Command, + Deploy, + Init, + Lint, + New, + Prove, + Run, + Setup, + Test, + Update, + Watch, +}; use anyhow::Error; use std::process::exit; -use structopt::clap::AppSettings; -use structopt::StructOpt; +use structopt::{clap::AppSettings, StructOpt}; /// CLI Arguments entry point - includes global parameters and subcommands #[derive(StructOpt, Debug)] diff --git a/leo/tests/mod.rs b/leo/tests/mod.rs index 90a44aa441..7bc611f49d 100644 --- a/leo/tests/mod.rs +++ b/leo/tests/mod.rs @@ -18,18 +18,20 @@ use std::path::PathBuf; use anyhow::Result; -use crate::commands::package::Login; -use crate::commands::package::Logout; -use crate::commands::Build; -use crate::commands::Command; -use crate::commands::Prove; -use crate::commands::Run; -use crate::commands::Setup; -use crate::commands::Test; -use crate::commands::Update; -use crate::commands::UpdateAutomatic; -use crate::context::create_context; -use crate::context::Context; +use crate::{ + commands::{ + package::{Login, Logout}, + Build, + Command, + Prove, + Run, + Setup, + Test, + Update, + UpdateAutomatic, + }, + context::{create_context, Context}, +}; /// Path to the only complex Leo program that we have /// - relative to source dir - where Cargo.toml is located diff --git a/leo/updater.rs b/leo/updater.rs index d9aa6cc58a..cc5c8972da 100644 --- a/leo/updater.rs +++ b/leo/updater.rs @@ -16,12 +16,9 @@ use crate::config::Config; -use anyhow::anyhow; -use anyhow::Result; +use anyhow::{anyhow, Result}; use colored::Colorize; -use self_update::backends::github; -use self_update::version::bump_is_greater; -use self_update::Status; +use self_update::{backends::github, version::bump_is_greater, Status}; pub struct Updater; diff --git a/package/src/errors/imports/directory.rs b/package/src/errors/imports/directory.rs index a3faddac08..05e6cfadf2 100644 --- a/package/src/errors/imports/directory.rs +++ b/package/src/errors/imports/directory.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::ffi::OsString; -use std::fs::FileType; -use std::io; +use std::{ffi::OsString, fs::FileType, io}; #[derive(Debug, Error)] pub enum ImportsDirectoryError { diff --git a/package/src/errors/inputs/directory.rs b/package/src/errors/inputs/directory.rs index efae1910d9..ee93d8c6d6 100644 --- a/package/src/errors/inputs/directory.rs +++ b/package/src/errors/inputs/directory.rs @@ -14,12 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::InputFileError; -use crate::StateFileError; +use crate::{InputFileError, StateFileError}; -use std::ffi::OsString; -use std::fs::FileType; -use std::io; +use std::{ffi::OsString, fs::FileType, io}; #[derive(Debug, Error)] pub enum InputsDirectoryError { diff --git a/package/src/errors/inputs/input.rs b/package/src/errors/inputs/input.rs index 1d83a076ec..659fcf32a3 100644 --- a/package/src/errors/inputs/input.rs +++ b/package/src/errors/inputs/input.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum InputFileError { diff --git a/package/src/errors/inputs/state.rs b/package/src/errors/inputs/state.rs index 44e89e242e..8d56253b46 100644 --- a/package/src/errors/inputs/state.rs +++ b/package/src/errors/inputs/state.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum StateFileError { diff --git a/package/src/errors/outputs/checksum.rs b/package/src/errors/outputs/checksum.rs index cc1e6b5ed7..e2a6bd4375 100644 --- a/package/src/errors/outputs/checksum.rs +++ b/package/src/errors/outputs/checksum.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum ChecksumFileError { diff --git a/package/src/errors/outputs/circuit.rs b/package/src/errors/outputs/circuit.rs index dee36386f3..ce006c88f2 100644 --- a/package/src/errors/outputs/circuit.rs +++ b/package/src/errors/outputs/circuit.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum CircuitFileError { diff --git a/package/src/errors/outputs/directory.rs b/package/src/errors/outputs/directory.rs index 0c079335a6..2e16be7e39 100644 --- a/package/src/errors/outputs/directory.rs +++ b/package/src/errors/outputs/directory.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::ffi::OsString; -use std::fs::FileType; -use std::io; +use std::{ffi::OsString, fs::FileType, io}; #[derive(Debug, Error)] pub enum OutputsDirectoryError { diff --git a/package/src/errors/outputs/proof.rs b/package/src/errors/outputs/proof.rs index e0080bc7dd..461a3ab259 100644 --- a/package/src/errors/outputs/proof.rs +++ b/package/src/errors/outputs/proof.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum ProofFileError { diff --git a/package/src/errors/outputs/proving_key.rs b/package/src/errors/outputs/proving_key.rs index 1d76fa4ce5..d78e62aec4 100644 --- a/package/src/errors/outputs/proving_key.rs +++ b/package/src/errors/outputs/proving_key.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum ProvingKeyFileError { diff --git a/package/src/errors/outputs/verification_key.rs b/package/src/errors/outputs/verification_key.rs index 6765946767..51398e630c 100644 --- a/package/src/errors/outputs/verification_key.rs +++ b/package/src/errors/outputs/verification_key.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; #[derive(Debug, Error)] pub enum VerificationKeyFileError { diff --git a/package/src/errors/package.rs b/package/src/errors/package.rs index ddb1f707cb..f0a07ea1ee 100644 --- a/package/src/errors/package.rs +++ b/package/src/errors/package.rs @@ -13,8 +13,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::ffi::OsString; -use std::io; +use std::{ffi::OsString, io}; #[derive(Debug, Error)] pub enum PackageError { diff --git a/package/src/errors/root/zip.rs b/package/src/errors/root/zip.rs index c89a3ac5bd..e9a9c15b82 100644 --- a/package/src/errors/root/zip.rs +++ b/package/src/errors/root/zip.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::io; -use std::path::PathBuf; +use std::{io, path::PathBuf}; use walkdir::Error as WalkDirError; use zip::result::ZipError; diff --git a/package/src/errors/source/directory.rs b/package/src/errors/source/directory.rs index 22ed510d24..00d0629ec2 100644 --- a/package/src/errors/source/directory.rs +++ b/package/src/errors/source/directory.rs @@ -14,9 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::ffi::OsString; -use std::fs::FileType; -use std::io; +use std::{ffi::OsString, fs::FileType, io}; #[derive(Debug, Error)] pub enum SourceDirectoryError { diff --git a/package/src/imports/directory.rs b/package/src/imports/directory.rs index c14194e9c3..a1d7e850ea 100644 --- a/package/src/imports/directory.rs +++ b/package/src/imports/directory.rs @@ -16,9 +16,7 @@ use crate::errors::ImportsDirectoryError; -use std::borrow::Cow; -use std::fs; -use std::path::Path; +use std::{borrow::Cow, fs, path::Path}; pub static IMPORTS_DIRECTORY_NAME: &str = "imports/"; diff --git a/package/src/inputs/directory.rs b/package/src/inputs/directory.rs index 3d3e4988fd..77b4701501 100644 --- a/package/src/inputs/directory.rs +++ b/package/src/inputs/directory.rs @@ -16,11 +16,12 @@ use crate::errors::InputsDirectoryError; -use std::borrow::Cow; -use std::fs; -use std::fs::ReadDir; -use std::path::Path; -use std::path::PathBuf; +use std::{ + borrow::Cow, + fs, + fs::ReadDir, + path::{Path, PathBuf}, +}; pub static INPUTS_DIRECTORY_NAME: &str = "inputs/"; diff --git a/package/src/inputs/input.rs b/package/src/inputs/input.rs index a48ba3cbba..3e01cbbe5d 100644 --- a/package/src/inputs/input.rs +++ b/package/src/inputs/input.rs @@ -16,15 +16,18 @@ //! The `program.in` file. -use crate::errors::InputFileError; -use crate::inputs::INPUTS_DIRECTORY_NAME; +use crate::{errors::InputFileError, inputs::INPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static INPUT_FILE_EXTENSION: &str = ".in"; diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index 9533481c61..0d21e7c7f4 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -14,16 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::inputs::InputFile; -use crate::inputs::InputsDirectory; -use crate::inputs::StateFile; -use crate::inputs::INPUT_FILE_EXTENSION; -use crate::inputs::STATE_FILE_EXTENSION; -use crate::InputsDirectoryError; +use crate::{ + inputs::{InputFile, InputsDirectory, StateFile, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION}, + InputsDirectoryError, +}; -use std::collections::HashMap; -use std::convert::TryFrom; -use std::path::Path; +use std::{collections::HashMap, convert::TryFrom, path::Path}; #[derive(Default)] pub struct InputPairs { diff --git a/package/src/inputs/state.rs b/package/src/inputs/state.rs index 4dbfbbedf4..7bda80ceb7 100644 --- a/package/src/inputs/state.rs +++ b/package/src/inputs/state.rs @@ -16,15 +16,18 @@ //! The `program.state` file. -use crate::errors::StateFileError; -use crate::inputs::INPUTS_DIRECTORY_NAME; +use crate::{errors::StateFileError, inputs::INPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static STATE_FILE_EXTENSION: &str = ".state"; diff --git a/package/src/outputs/checksum.rs b/package/src/outputs/checksum.rs index d789cb5ce9..9352429973 100644 --- a/package/src/outputs/checksum.rs +++ b/package/src/outputs/checksum.rs @@ -16,15 +16,18 @@ //! The build checksum file. -use crate::errors::ChecksumFileError; -use crate::outputs::OUTPUTS_DIRECTORY_NAME; +use crate::{errors::ChecksumFileError, outputs::OUTPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static CHECKSUM_FILE_EXTENSION: &str = ".sum"; diff --git a/package/src/outputs/circuit.rs b/package/src/outputs/circuit.rs index 3f9ec82a99..d9d0e8cced 100644 --- a/package/src/outputs/circuit.rs +++ b/package/src/outputs/circuit.rs @@ -16,15 +16,18 @@ //! The serialized circuit output file. -use crate::errors::CircuitFileError; -use crate::outputs::OUTPUTS_DIRECTORY_NAME; +use crate::{errors::CircuitFileError, outputs::OUTPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static CIRCUIT_FILE_EXTENSION: &str = ".json"; diff --git a/package/src/outputs/directory.rs b/package/src/outputs/directory.rs index ec49dc8f9e..e2557f343c 100644 --- a/package/src/outputs/directory.rs +++ b/package/src/outputs/directory.rs @@ -16,9 +16,7 @@ use crate::errors::OutputsDirectoryError; -use std::borrow::Cow; -use std::fs; -use std::path::Path; +use std::{borrow::Cow, fs, path::Path}; pub static OUTPUTS_DIRECTORY_NAME: &str = "outputs/"; diff --git a/package/src/outputs/proof.rs b/package/src/outputs/proof.rs index 14f394af42..815d6048be 100644 --- a/package/src/outputs/proof.rs +++ b/package/src/outputs/proof.rs @@ -16,15 +16,18 @@ //! The proof file. -use crate::errors::ProofFileError; -use crate::outputs::OUTPUTS_DIRECTORY_NAME; +use crate::{errors::ProofFileError, outputs::OUTPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static PROOF_FILE_EXTENSION: &str = ".proof"; diff --git a/package/src/outputs/proving_key.rs b/package/src/outputs/proving_key.rs index cb76033eee..7e2d938bd7 100644 --- a/package/src/outputs/proving_key.rs +++ b/package/src/outputs/proving_key.rs @@ -16,15 +16,18 @@ //! The proving key file. -use crate::errors::ProvingKeyFileError; -use crate::outputs::OUTPUTS_DIRECTORY_NAME; +use crate::{errors::ProvingKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static PROVING_KEY_FILE_EXTENSION: &str = ".lpk"; diff --git a/package/src/outputs/verification_key.rs b/package/src/outputs/verification_key.rs index c10b4de1b8..6f7fca8797 100644 --- a/package/src/outputs/verification_key.rs +++ b/package/src/outputs/verification_key.rs @@ -16,15 +16,18 @@ //! The verification key file. -use crate::errors::VerificationKeyFileError; -use crate::outputs::OUTPUTS_DIRECTORY_NAME; +use crate::{errors::VerificationKeyFileError, outputs::OUTPUTS_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::Write, + path::Path, +}; pub static VERIFICATION_KEY_FILE_EXTENSION: &str = ".lvk"; diff --git a/package/src/package.rs b/package/src/package.rs index 4089da6d31..f5c46e2696 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -14,17 +14,13 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::PackageError; -use crate::imports::ImportsDirectory; -use crate::inputs::InputFile; -use crate::inputs::InputsDirectory; -use crate::inputs::StateFile; -use crate::root::Gitignore; -use crate::root::Manifest; -use crate::root::README; -use crate::source::LibraryFile; -use crate::source::MainFile; -use crate::source::SourceDirectory; +use crate::{ + errors::PackageError, + imports::ImportsDirectory, + inputs::{InputFile, InputsDirectory, StateFile}, + root::{Gitignore, Manifest, README}, + source::{LibraryFile, MainFile, SourceDirectory}, +}; use serde::Deserialize; use std::path::Path; diff --git a/package/src/root/gitignore.rs b/package/src/root/gitignore.rs index 3cdba044d5..756c51be05 100644 --- a/package/src/root/gitignore.rs +++ b/package/src/root/gitignore.rs @@ -19,10 +19,7 @@ use crate::errors::GitignoreError; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::io::Write; -use std::path::Path; +use std::{borrow::Cow, fs::File, io::Write, path::Path}; pub static GITIGNORE_FILENAME: &str = ".gitignore"; diff --git a/package/src/root/manifest.rs b/package/src/root/manifest.rs index 44c9983efe..540749fcdc 100644 --- a/package/src/root/manifest.rs +++ b/package/src/root/manifest.rs @@ -14,16 +14,16 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::errors::ManifestError; -use crate::package::Package; +use crate::{errors::ManifestError, package::Package}; use serde::Deserialize; -use std::borrow::Cow; -use std::convert::TryFrom; -use std::fs::File; -use std::io::Read; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + convert::TryFrom, + fs::File, + io::{Read, Write}, + path::Path, +}; pub const MANIFEST_FILENAME: &str = "Leo.toml"; diff --git a/package/src/root/readme.rs b/package/src/root/readme.rs index 700e068f3a..468f5e58b9 100644 --- a/package/src/root/readme.rs +++ b/package/src/root/readme.rs @@ -19,10 +19,7 @@ use crate::errors::READMEError; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::io::Write; -use std::path::Path; +use std::{borrow::Cow, fs::File, io::Write, path::Path}; pub static README_FILENAME: &str = "README.md"; diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index e02671d2c8..46426b9d3e 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -16,32 +16,34 @@ //! The program package zip file. -use crate::errors::ZipFileError; -use crate::imports::IMPORTS_DIRECTORY_NAME; -use crate::inputs::INPUTS_DIRECTORY_NAME; -use crate::inputs::INPUT_FILE_EXTENSION; -use crate::inputs::STATE_FILE_EXTENSION; -use crate::outputs::CHECKSUM_FILE_EXTENSION; -use crate::outputs::CIRCUIT_FILE_EXTENSION; -use crate::outputs::OUTPUTS_DIRECTORY_NAME; -use crate::outputs::PROOF_FILE_EXTENSION; -use crate::outputs::PROVING_KEY_FILE_EXTENSION; -use crate::outputs::VERIFICATION_KEY_FILE_EXTENSION; -use crate::root::MANIFEST_FILENAME; -use crate::root::README_FILENAME; -use crate::source::SOURCE_DIRECTORY_NAME; -use crate::source::SOURCE_FILE_EXTENSION; +use crate::{ + errors::ZipFileError, + imports::IMPORTS_DIRECTORY_NAME, + inputs::{INPUTS_DIRECTORY_NAME, INPUT_FILE_EXTENSION, STATE_FILE_EXTENSION}, + outputs::{ + CHECKSUM_FILE_EXTENSION, + CIRCUIT_FILE_EXTENSION, + OUTPUTS_DIRECTORY_NAME, + PROOF_FILE_EXTENSION, + PROVING_KEY_FILE_EXTENSION, + VERIFICATION_KEY_FILE_EXTENSION, + }, + root::{MANIFEST_FILENAME, README_FILENAME}, + source::{SOURCE_DIRECTORY_NAME, SOURCE_FILE_EXTENSION}, +}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::fs::{self}; -use std::io::Read; -use std::io::Write; -use std::path::Path; +use std::{ + borrow::Cow, + fs::{ + File, + {self}, + }, + io::{Read, Write}, + path::Path, +}; use walkdir::WalkDir; -use zip::write::FileOptions; -use zip::write::ZipWriter; +use zip::write::{FileOptions, ZipWriter}; pub static ZIP_FILE_EXTENSION: &str = ".zip"; diff --git a/package/src/source/directory.rs b/package/src/source/directory.rs index 15053337c6..5764f972df 100644 --- a/package/src/source/directory.rs +++ b/package/src/source/directory.rs @@ -16,10 +16,11 @@ use crate::errors::SourceDirectoryError; -use std::borrow::Cow; -use std::fs; -use std::path::Path; -use std::path::PathBuf; +use std::{ + borrow::Cow, + fs, + path::{Path, PathBuf}, +}; pub static SOURCE_DIRECTORY_NAME: &str = "src/"; diff --git a/package/src/source/library.rs b/package/src/source/library.rs index e33aa1b2b0..90a5193b85 100644 --- a/package/src/source/library.rs +++ b/package/src/source/library.rs @@ -16,14 +16,10 @@ //! The `lib.leo` file. -use crate::errors::LibraryFileError; -use crate::source::directory::SOURCE_DIRECTORY_NAME; +use crate::{errors::LibraryFileError, source::directory::SOURCE_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::io::Write; -use std::path::Path; +use std::{borrow::Cow, fs::File, io::Write, path::Path}; pub static LIBRARY_FILENAME: &str = "lib.leo"; diff --git a/package/src/source/main.rs b/package/src/source/main.rs index 6709be131b..7ac8c4990d 100644 --- a/package/src/source/main.rs +++ b/package/src/source/main.rs @@ -16,14 +16,10 @@ //! The `main.leo` file. -use crate::errors::MainFileError; -use crate::source::directory::SOURCE_DIRECTORY_NAME; +use crate::{errors::MainFileError, source::directory::SOURCE_DIRECTORY_NAME}; use serde::Deserialize; -use std::borrow::Cow; -use std::fs::File; -use std::io::Write; -use std::path::Path; +use std::{borrow::Cow, fs::File, io::Write, path::Path}; pub static MAIN_FILENAME: &str = "main.leo"; diff --git a/package/tests/initialize/initialize.rs b/package/tests/initialize/initialize.rs index de255bf97c..5e1b98bde8 100644 --- a/package/tests/initialize/initialize.rs +++ b/package/tests/initialize/initialize.rs @@ -15,14 +15,12 @@ // along with the Leo library. If not, see . use crate::test_dir; -use leo_package::inputs::InputFile; -use leo_package::inputs::InputsDirectory; -use leo_package::inputs::StateFile; -use leo_package::package::Package; -use leo_package::root::Manifest; -use leo_package::source::LibraryFile; -use leo_package::source::MainFile; -use leo_package::source::SourceDirectory; +use leo_package::{ + inputs::{InputFile, InputsDirectory, StateFile}, + package::Package, + root::Manifest, + source::{LibraryFile, MainFile, SourceDirectory}, +}; const TEST_PACKAGE_NAME: &str = "test-package"; diff --git a/package/tests/manifest/manifest.rs b/package/tests/manifest/manifest.rs index 070289d7c7..d58fce5150 100644 --- a/package/tests/manifest/manifest.rs +++ b/package/tests/manifest/manifest.rs @@ -17,15 +17,14 @@ // Tests for package manifest use crate::test_dir; -use leo_package::root::Manifest; -use leo_package::root::MANIFEST_FILENAME; +use leo_package::root::{Manifest, MANIFEST_FILENAME}; -use std::convert::TryFrom; -use std::fs::File; -use std::io::Read; -use std::io::Write; -use std::path::Path; -use std::path::PathBuf; +use std::{ + convert::TryFrom, + fs::File, + io::{Read, Write}, + path::{Path, PathBuf}, +}; const OLD_MANIFEST_FORMAT: &str = r#"[package] name = "test-package" diff --git a/package/tests/mod.rs b/package/tests/mod.rs index da355df338..8f72a16b3e 100644 --- a/package/tests/mod.rs +++ b/package/tests/mod.rs @@ -20,12 +20,13 @@ pub mod initialize; pub mod manifest; use lazy_static::lazy_static; -use std::cell::RefCell; -use std::env; -use std::fs; -use std::path::PathBuf; -use std::sync::atomic::AtomicUsize; -use std::sync::atomic::Ordering; +use std::{ + cell::RefCell, + env, + fs, + path::PathBuf, + sync::atomic::{AtomicUsize, Ordering}, +}; const PACKAGE_TEST_DIRECTORY: &str = "package-testing"; diff --git a/state/Cargo.toml b/state/Cargo.toml index 8e7d0573cf..72b7c71b02 100644 --- a/state/Cargo.toml +++ b/state/Cargo.toml @@ -27,7 +27,7 @@ version = "1.2.3" [dependencies.snarkvm-algorithms] version = "0.2.0" -default-features = false +#default-features = false [dependencies.snarkvm-curves] version = "0.2.0" diff --git a/state/src/errors/dpc_record_values.rs b/state/src/errors/dpc_record_values.rs index 0f97cf7f91..437666bfea 100644 --- a/state/src/errors/dpc_record_values.rs +++ b/state/src/errors/dpc_record_values.rs @@ -18,8 +18,7 @@ use crate::InputValueError; use snarkvm_dpc::AccountError; -use std::num::ParseIntError; -use std::str::ParseBoolError; +use std::{num::ParseIntError, str::ParseBoolError}; #[derive(Debug, Error)] pub enum DPCRecordValuesError { diff --git a/state/src/errors/local_data_commitment.rs b/state/src/errors/local_data_commitment.rs index d5fb0c5ee8..a0f8465983 100644 --- a/state/src/errors/local_data_commitment.rs +++ b/state/src/errors/local_data_commitment.rs @@ -14,12 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::RecordVerificationError; -use crate::StateLeafValuesError; -use crate::StateValuesError; +use crate::{RecordVerificationError, StateLeafValuesError, StateValuesError}; -use snarkvm_algorithms::CommitmentError; -use snarkvm_algorithms::MerkleError; +use snarkvm_algorithms::{CommitmentError, MerkleError}; use std::io::Error as IOError; diff --git a/state/src/errors/state_leaf_values.rs b/state/src/errors/state_leaf_values.rs index 503aff91d2..83b377178a 100644 --- a/state/src/errors/state_leaf_values.rs +++ b/state/src/errors/state_leaf_values.rs @@ -16,8 +16,7 @@ use crate::InputValueError; -use std::num::ParseIntError; -use std::str::ParseBoolError; +use std::{num::ParseIntError, str::ParseBoolError}; #[derive(Debug, Error)] pub enum StateLeafValuesError { diff --git a/state/src/errors/state_values.rs b/state/src/errors/state_values.rs index 9195833463..94af651517 100644 --- a/state/src/errors/state_values.rs +++ b/state/src/errors/state_values.rs @@ -16,8 +16,7 @@ use crate::InputValueError; -use std::num::ParseIntError; -use std::str::ParseBoolError; +use std::{num::ParseIntError, str::ParseBoolError}; #[derive(Debug, Error)] pub enum StateValuesError { diff --git a/state/src/local_data_commitment/local_data_commitment.rs b/state/src/local_data_commitment/local_data_commitment.rs index fd23158814..9576603447 100644 --- a/state/src/local_data_commitment/local_data_commitment.rs +++ b/state/src/local_data_commitment/local_data_commitment.rs @@ -14,23 +14,21 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::verify_record_commitment; -use crate::LocalDataVerificationError; -use crate::StateLeafValues; -use crate::StateValues; +use crate::{verify_record_commitment, LocalDataVerificationError, StateLeafValues, StateValues}; use leo_ast::Input as AstInput; -use snarkvm_algorithms::commitment_tree::CommitmentMerklePath; -use snarkvm_algorithms::traits::CommitmentScheme; -use snarkvm_algorithms::traits::CRH; -use snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_dpc::base_dpc::instantiated::LocalDataCRH; -use snarkvm_dpc::base_dpc::instantiated::LocalDataCommitment; -use snarkvm_dpc::base_dpc::parameters::SystemParameters; -use snarkvm_dpc::traits::DPCComponents; -use snarkvm_utilities::bytes::ToBytes; -use snarkvm_utilities::to_bytes; -use snarkvm_utilities::FromBytes; +use snarkvm_algorithms::{ + commitment_tree::CommitmentMerklePath, + traits::{CommitmentScheme, CRH}, +}; +use snarkvm_dpc::{ + base_dpc::{ + instantiated::{Components, LocalDataCRH, LocalDataCommitment}, + parameters::SystemParameters, + }, + traits::DPCComponents, +}; +use snarkvm_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; diff --git a/state/src/local_data_commitment/state_leaf_values.rs b/state/src/local_data_commitment/state_leaf_values.rs index 89dc5de902..8c7148741d 100644 --- a/state/src/local_data_commitment/state_leaf_values.rs +++ b/state/src/local_data_commitment/state_leaf_values.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::find_input; -use crate::input_to_bytes; -use crate::input_to_integer_string; -use crate::StateLeafValuesError; +use crate::{find_input, input_to_bytes, input_to_integer_string, StateLeafValuesError}; use leo_ast::StateLeaf as AstStateLeaf; use std::convert::TryFrom; diff --git a/state/src/local_data_commitment/state_values.rs b/state/src/local_data_commitment/state_values.rs index 0a0777a5fb..0ba48af568 100644 --- a/state/src/local_data_commitment/state_values.rs +++ b/state/src/local_data_commitment/state_values.rs @@ -14,10 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::find_input; -use crate::input_to_bytes; -use crate::input_to_integer_string; -use crate::StateValuesError; +use crate::{find_input, input_to_bytes, input_to_integer_string, StateValuesError}; use leo_ast::State as AstState; use std::convert::TryFrom; diff --git a/state/src/record_commitment/dpc_record_values.rs b/state/src/record_commitment/dpc_record_values.rs index ca217a11b3..9c6ccc05b6 100644 --- a/state/src/record_commitment/dpc_record_values.rs +++ b/state/src/record_commitment/dpc_record_values.rs @@ -14,15 +14,12 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::utilities::*; -use crate::DPCRecordValuesError; +use crate::{utilities::*, DPCRecordValuesError}; use leo_ast::Record as AstRecord; -use snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_dpc::AccountAddress; +use snarkvm_dpc::{base_dpc::instantiated::Components, AccountAddress}; -use std::convert::TryFrom; -use std::str::FromStr; +use std::{convert::TryFrom, str::FromStr}; static SERIAL_NUMBER_PARAMETER_STRING: &str = "serial_number"; static OWNER_PARAMETER_STRING: &str = "owner"; diff --git a/state/src/record_commitment/record_commitment.rs b/state/src/record_commitment/record_commitment.rs index ecff6fd880..02ff4b977f 100644 --- a/state/src/record_commitment/record_commitment.rs +++ b/state/src/record_commitment/record_commitment.rs @@ -14,17 +14,15 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::DPCRecordValues; -use crate::RecordVerificationError; +use crate::{DPCRecordValues, RecordVerificationError}; use leo_ast::Record as AstRecord; use snarkvm_algorithms::traits::CommitmentScheme; -use snarkvm_dpc::base_dpc::instantiated::Components; -use snarkvm_dpc::base_dpc::instantiated::RecordCommitment; -use snarkvm_dpc::base_dpc::parameters::SystemParameters; -use snarkvm_utilities::bytes::ToBytes; -use snarkvm_utilities::to_bytes; -use snarkvm_utilities::FromBytes; +use snarkvm_dpc::base_dpc::{ + instantiated::{Components, RecordCommitment}, + parameters::SystemParameters, +}; +use snarkvm_utilities::{bytes::ToBytes, to_bytes, FromBytes}; use std::convert::TryFrom; diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs index 792ff3820b..cdcf32feb1 100644 --- a/state/src/utilities/input_value.rs +++ b/state/src/utilities/input_value.rs @@ -15,8 +15,7 @@ // along with the Leo library. If not, see . use crate::InputValueError; -use leo_ast::InputValue; -use leo_ast::Parameter; +use leo_ast::{InputValue, Parameter}; use indexmap::IndexMap; diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 147650ffde..f0a8e6b431 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -18,16 +18,14 @@ use leo_ast::Input; use leo_input::LeoInputParser; use leo_state::verify_local_data_commitment; -use snarkvm_algorithms::traits::CommitmentScheme; -use snarkvm_algorithms::traits::CRH; -use snarkvm_dpc::base_dpc::instantiated::*; -use snarkvm_dpc::base_dpc::record_payload::RecordPayload; -use snarkvm_dpc::base_dpc::DPC; -use snarkvm_dpc::Account; -use snarkvm_dpc::AccountScheme; -use snarkvm_dpc::Record; -use snarkvm_utilities::bytes::ToBytes; -use snarkvm_utilities::to_bytes; +use snarkvm_algorithms::traits::{CommitmentScheme, CRH}; +use snarkvm_dpc::{ + base_dpc::{instantiated::*, record_payload::RecordPayload, DPC}, + Account, + AccountScheme, + Record, +}; +use snarkvm_utilities::{bytes::ToBytes, to_bytes}; use rand::Rng; use rand_core::SeedableRng; @@ -74,11 +72,13 @@ fn test_generate_values_from_dpc() { let noop_program_snark_pp = InstantiatedDPC::generate_noop_program_snark_parameters(&system_parameters, &mut rng).unwrap(); - let noop_program_id = to_bytes![ProgramVerificationKeyCRH::hash( - &system_parameters.program_verification_key_crh, - &to_bytes![noop_program_snark_pp.verification_key].unwrap() - ) - .unwrap()] + let noop_program_id = to_bytes![ + ProgramVerificationKeyCRH::hash( + &system_parameters.program_verification_key_crh, + &to_bytes![noop_program_snark_pp.verification_key].unwrap() + ) + .unwrap() + ] .unwrap(); let signature_parameters = &system_parameters.account_signature; diff --git a/synthesizer/src/circuit_synthesizer.rs b/synthesizer/src/circuit_synthesizer.rs index 014a4401dd..356f97d15a 100644 --- a/synthesizer/src/circuit_synthesizer.rs +++ b/synthesizer/src/circuit_synthesizer.rs @@ -16,12 +16,7 @@ use snarkvm_curves::traits::PairingEngine; use snarkvm_fields::Field; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Index; -use snarkvm_r1cs::LinearCombination; -use snarkvm_r1cs::OptionalVec; -use snarkvm_r1cs::SynthesisError; -use snarkvm_r1cs::Variable; +use snarkvm_r1cs::{ConstraintSystem, Index, LinearCombination, OptionalVec, SynthesisError, Variable}; #[derive(Default)] pub struct Namespace { diff --git a/synthesizer/src/serialized_circuit.rs b/synthesizer/src/serialized_circuit.rs index ef09a9cce1..4f20704b2c 100644 --- a/synthesizer/src/serialized_circuit.rs +++ b/synthesizer/src/serialized_circuit.rs @@ -16,18 +16,12 @@ use std::convert::TryFrom; -use serde::Deserialize; -use serde::Serialize; -use snarkvm_curves::bls12_377::Bls12_377; -use snarkvm_curves::traits::PairingEngine; +use serde::{Deserialize, Serialize}; +use snarkvm_curves::{bls12_377::Bls12_377, traits::PairingEngine}; use snarkvm_fields::FieldError; -use snarkvm_r1cs::ConstraintSystem; -use snarkvm_r1cs::Index; -use snarkvm_r1cs::OptionalVec; +use snarkvm_r1cs::{ConstraintSystem, Index, OptionalVec}; -use crate::CircuitSynthesizer; -use crate::SerializedField; -use crate::SerializedIndex; +use crate::{CircuitSynthesizer, SerializedField, SerializedIndex}; #[derive(Serialize, Deserialize)] pub struct SerializedCircuit { diff --git a/synthesizer/src/serialized_field.rs b/synthesizer/src/serialized_field.rs index 504daa8403..acb25e0ce2 100644 --- a/synthesizer/src/serialized_field.rs +++ b/synthesizer/src/serialized_field.rs @@ -14,16 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::convert::TryFrom; -use std::str::FromStr; +use std::{convert::TryFrom, str::FromStr}; use num_bigint::BigUint; -use serde::Deserialize; -use serde::Serialize; -use snarkvm_fields::Field; -use snarkvm_fields::FieldError; -use snarkvm_fields::Fp256; -use snarkvm_fields::Fp256Parameters; +use serde::{Deserialize, Serialize}; +use snarkvm_fields::{Field, FieldError, Fp256, Fp256Parameters}; #[derive(Serialize, Deserialize)] pub struct SerializedField(pub String); diff --git a/synthesizer/src/serialized_index.rs b/synthesizer/src/serialized_index.rs index 53fc644a1a..2d7c879881 100644 --- a/synthesizer/src/serialized_index.rs +++ b/synthesizer/src/serialized_index.rs @@ -14,8 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use serde::Deserialize; -use serde::Serialize; +use serde::{Deserialize, Serialize}; use snarkvm_r1cs::Index; #[derive(Serialize, Deserialize)] From b5fbb9c2175a3e46df713b127a35d30bc17c712a Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 4 Mar 2021 12:08:55 -0800 Subject: [PATCH 75/92] cargo clippy --- parser/src/context.rs | 6 +++--- parser/src/test.rs | 4 ++-- parser/src/tokenizer.rs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/parser/src/context.rs b/parser/src/context.rs index b213755c02..355fbe4737 100644 --- a/parser/src/context.rs +++ b/parser/src/context.rs @@ -60,13 +60,13 @@ impl ParserContext { pub fn peek_oneof(&self, token: &[Token]) -> SyntaxResult<&SpannedToken> { if let Some(spanned_token) = self.inner.last() { if token.iter().any(|x| x == &spanned_token.token) { - return Ok(spanned_token); + Ok(spanned_token) } else { - return Err(SyntaxError::unexpected( + Err(SyntaxError::unexpected( &spanned_token.token, token, &spanned_token.span, - )); + )) } } else { Err(self.eof()) diff --git a/parser/src/test.rs b/parser/src/test.rs index dc1f0888b9..1014d83e85 100644 --- a/parser/src/test.rs +++ b/parser/src/test.rs @@ -53,7 +53,7 @@ pub fn parser_pass_tests() { } } } - if fail.len() > 0 { + if !fail.is_empty() { for (i, fail) in fail.iter().enumerate() { println!( "\n\n-----------------TEST #{} FAILED (and shouldn't have)-----------------", @@ -84,7 +84,7 @@ pub fn parser_fail_tests() { } } } - if fail.len() > 0 { + if !fail.is_empty() { for (i, fail) in fail.iter().enumerate() { println!( "\n\n-----------------TEST #{} PASSED (and shouldn't have)-----------------", diff --git a/parser/src/tokenizer.rs b/parser/src/tokenizer.rs index b7eb61deba..2285227d5c 100644 --- a/parser/src/tokenizer.rs +++ b/parser/src/tokenizer.rs @@ -79,7 +79,7 @@ impl Token { } fn gobble(input: &[u8]) -> (&[u8], Option) { - if input.len() == 0 { + if input.is_empty() { return (input, None); } match input[0] { From d7d84c0ea7234e6136fb4740ecc5edfbf1368a85 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 4 Mar 2021 15:58:00 -0800 Subject: [PATCH 76/92] fix test build issues. parser errors on dash + number names --- asg/tests/mod.rs | 7 +------ asg/tests/pass/form_ast.rs | 22 +++++++--------------- parser/src/parser/context.rs | 30 +++++++++++++++--------------- parser/src/parser/file.rs | 9 +++++++++ parser/src/tokenizer/mod.rs | 3 ++- 5 files changed, 34 insertions(+), 37 deletions(-) diff --git a/asg/tests/mod.rs b/asg/tests/mod.rs index 03ae443dc1..01d12530cc 100644 --- a/asg/tests/mod.rs +++ b/asg/tests/mod.rs @@ -15,16 +15,12 @@ // along with the Leo library. If not, see . use leo_asg::*; -use leo_ast::Ast; use leo_parser::parse_ast; -use std::path::Path; - mod fail; mod pass; const TESTING_FILEPATH: &str = "input.leo"; -const TESTING_PROGRAM_NAME: &str = "test_program"; fn load_asg(program_string: &str) -> Result, AsgConvertError> { load_asg_imports(make_test_context(), program_string, &mut NullImportResolver) @@ -35,8 +31,7 @@ fn load_asg_imports<'a, T: ImportResolver<'a>>( program_string: &str, imports: &mut T, ) -> Result, AsgConvertError> { - // let grammar = Grammar::new(Path::new(&TESTING_FILEPATH), program_string)?; - let ast = Ast::new(TESTING_PROGRAM_NAME, &grammar)?; + let ast = parse_ast(&TESTING_FILEPATH, program_string)?; InternalProgram::new(context, &ast.as_repr(), imports) } diff --git a/asg/tests/pass/form_ast.rs b/asg/tests/pass/form_ast.rs index d49cb8b970..c59e055c1e 100644 --- a/asg/tests/pass/form_ast.rs +++ b/asg/tests/pass/form_ast.rs @@ -15,10 +15,7 @@ // along with the Leo library. If not, see . use crate::{load_asg, make_test_context}; -use leo_ast::Ast; -use leo_grammar::Grammar; - -use std::path::Path; +use leo_parser::parse_ast; #[test] fn test_basic() { @@ -56,6 +53,7 @@ fn test_function_rename() { #[test] fn test_imports() { + let import_name = "test-import".to_string(); let context = make_test_context(); let mut imports = crate::mocked_resolver(&context); let test_import = r#" @@ -70,7 +68,7 @@ fn test_imports() { "#; imports .packages - .insert("test-import".to_string(), load_asg(test_import).unwrap()); + .insert(import_name.clone(), load_asg(test_import).unwrap()); let program_string = r#" import test-import.foo; @@ -79,17 +77,11 @@ fn test_imports() { } "#; - let test_import_grammar = Grammar::new(Path::new("test-import.leo"), test_import).unwrap(); - println!( - "{}", - serde_json::to_string(Ast::new("test-import", &test_import_grammar).unwrap().as_repr()).unwrap() - ); + let test_import_ast = parse_ast(&import_name, test_import).unwrap(); + println!("{}", serde_json::to_string(test_import_ast.as_repr()).unwrap()); - let test_grammar = Grammar::new(Path::new("test.leo"), program_string).unwrap(); - println!( - "{}", - serde_json::to_string(Ast::new("test", &test_grammar).unwrap().as_repr()).unwrap() - ); + let test_ast = parse_ast("test.leo", program_string).unwrap(); + println!("{}", serde_json::to_string(test_ast.as_repr()).unwrap()); let asg = crate::load_asg_imports(&context, program_string, &mut imports).unwrap(); let reformed_ast = leo_asg::reform_ast(&asg); diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index 355fbe4737..a6b5908406 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -57,21 +57,21 @@ impl ParserContext { self.inner.last().ok_or_else(|| self.eof()) } - pub fn peek_oneof(&self, token: &[Token]) -> SyntaxResult<&SpannedToken> { - if let Some(spanned_token) = self.inner.last() { - if token.iter().any(|x| x == &spanned_token.token) { - Ok(spanned_token) - } else { - Err(SyntaxError::unexpected( - &spanned_token.token, - token, - &spanned_token.span, - )) - } - } else { - Err(self.eof()) - } - } + // pub fn peek_oneof(&self, token: &[Token]) -> SyntaxResult<&SpannedToken> { + // if let Some(spanned_token) = self.inner.last() { + // if token.iter().any(|x| x == &spanned_token.token) { + // Ok(spanned_token) + // } else { + // Err(SyntaxError::unexpected( + // &spanned_token.token, + // token, + // &spanned_token.span, + // )) + // } + // } else { + // Err(self.eof()) + // } + // } pub fn has_next(&self) -> bool { !self.inner.is_empty() diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index efd50d8d15..7334ef4700 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -161,7 +161,10 @@ impl ParserContext { } pub fn parse_package_name(&mut self) -> SyntaxResult { + // Build the package name, starting with valid characters up to a dash `-` (Token::Minus). let mut base = self.expect_loose_ident()?; + + // Build the rest of the package name including dashes. while let Some(token) = self.eat(Token::Minus) { if token.span.line_start == base.span.line_stop && token.span.col_start == base.span.col_stop { base.name += "-"; @@ -173,9 +176,13 @@ impl ParserContext { break; } } + + // Return an error if the package name contains a keyword. if let Some(token) = KEYWORD_TOKENS.iter().find(|x| x.to_string() == base.name) { return Err(SyntaxError::unexpected_str(token, "package name", &base.span)); } + + // Return an error if the package name contains invalid characters. if !base .name .chars() @@ -183,6 +190,8 @@ impl ParserContext { { return Err(SyntaxError::invalid_package_name(&base.span)); } + + // Return the package name. Ok(base) } diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index f4cb840a96..aeafbb3dfc 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -16,7 +16,8 @@ //! The tokenizer to convert Leo code text into tokens. //! -//! This module contains the [`tokenize()`] method. +//! This module contains the [`tokenize()`] method which breaks down string text into tokens, +//! separated by whitespace. pub(crate) mod token; pub(crate) use self::token::*; From ed41a55c477350228b8941b8b3692b15053091e5 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 4 Mar 2021 16:47:41 -0800 Subject: [PATCH 77/92] add comments to context --- parser/src/parser/context.rs | 119 +++++++++++++++----- parser/src/parser/expression.rs | 2 +- parser/src/parser/file.rs | 6 +- parser/src/parser/mod.rs | 2 +- parser/src/parser/type_.rs | 2 +- parser/src/tokenizer/mod.rs | 6 +- parser/src/tokenizer/tokenizer.rs | 181 ------------------------------ 7 files changed, 97 insertions(+), 221 deletions(-) diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index a6b5908406..5fe63ce4a0 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -19,8 +19,10 @@ use std::unimplemented; use crate::{tokenizer::*, SyntaxError, SyntaxResult, Token, KEYWORD_TOKENS}; use leo_ast::*; +/// Stores a program in tokenized format plus additional context. +/// May be converted into a [`Program`] AST by parsing all tokens. pub struct ParserContext { - inner: Vec, + tokens: Vec, end_span: Span, // true if parsing an expression for an if statement -- means circuit inits are not legal pub(crate) fuzzy_struct_state: bool, @@ -30,11 +32,14 @@ impl Iterator for ParserContext { type Item = SpannedToken; fn next(&mut self) -> Option { - self.inner.pop() + self.tokens.pop() } } impl ParserContext { + /// + /// Returns a new [`ParserContext`] type given a vector of tokens. + /// pub fn new(mut tokens: Vec) -> Self { tokens.reverse(); // todo: performance optimization here: drain filter @@ -44,17 +49,23 @@ impl ParserContext { .collect(); ParserContext { end_span: tokens.last().map(|x| x.span.clone()).unwrap_or_default(), - inner: tokens, + tokens, fuzzy_struct_state: false, } } + /// + /// Returns an unexpected end of function [`SyntaxError`]. + /// pub fn eof(&self) -> SyntaxError { SyntaxError::unexpected_eof(&self.end_span) } + /// + /// Returns a reference to the next token or error if it does not exist. + /// pub fn peek(&self) -> SyntaxResult<&SpannedToken> { - self.inner.last().ok_or_else(|| self.eof()) + self.tokens.last().ok_or_else(|| self.eof()) } // pub fn peek_oneof(&self, token: &[Token]) -> SyntaxResult<&SpannedToken> { @@ -73,29 +84,43 @@ impl ParserContext { // } // } + /// + /// Returns true if the next token exists. + /// pub fn has_next(&self) -> bool { - !self.inner.is_empty() + !self.tokens.is_empty() } + /// + /// Removes the next token if it exists and returns it, or [None] if + /// the next token does not exist. + /// pub fn eat(&mut self, token: Token) -> Option { - if let Some(SpannedToken { token: inner, .. }) = self.inner.last() { + if let Some(SpannedToken { token: inner, .. }) = self.tokens.last() { if &token == inner { - return self.inner.pop(); + return self.tokens.pop(); } } None } + /// + /// Appends a token to the back of the vector. + /// pub fn backtrack(&mut self, token: SpannedToken) { - self.inner.push(token); + self.tokens.push(token); } - pub fn eat_ident(&mut self) -> Option { + /// + /// Removes the next token if it is a [`Token::Ident(_)`] and returns it, or [None] if + /// the next token is not a [`Token::Ident(_)`] or if the next token does not exist. + /// + pub fn eat_identifier(&mut self) -> Option { if let Some(SpannedToken { token: Token::Ident(_), .. - }) = self.inner.last() + }) = self.tokens.last() { - let token = self.inner.pop().unwrap(); + let token = self.tokens.pop().unwrap(); if let SpannedToken { token: Token::Ident(name), span, @@ -109,12 +134,16 @@ impl ParserContext { None } + /// + /// Returns a reference to the next token if it is a [`GroupCoordinate`], or [None] if + /// the next token is not a [`GroupCoordinate`]. + /// fn peek_group_coordinate(&self, i: &mut usize) -> Option { - let token = self.inner.get(*i)?; + let token = self.tokens.get(*i)?; *i -= 1; Some(match &token.token { Token::Add => GroupCoordinate::SignHigh, - Token::Minus => match self.inner.get(*i) { + Token::Minus => match self.tokens.get(*i) { Some(SpannedToken { token: Token::Int(value), span, @@ -130,12 +159,16 @@ impl ParserContext { }) } + /// + /// Removes the next two tokens if they are a pair of [`GroupCoordinate`] and returns them, + /// or [None] if the next token is not a [`GroupCoordinate`]. + /// // kinda hacky, we're not LALR(1) for groups... pub fn eat_group_partial(&mut self) -> Option<(GroupCoordinate, GroupCoordinate, Span)> { - let mut i = self.inner.len() - 1; - let start_span = self.inner.get(i)?.span.clone(); + let mut i = self.tokens.len() - 1; + let start_span = self.tokens.get(i)?.span.clone(); let first = self.peek_group_coordinate(&mut i)?; - match self.inner.get(i) { + match self.tokens.get(i) { Some(SpannedToken { token: Token::Comma, .. }) => { @@ -146,7 +179,7 @@ impl ParserContext { } } let second = self.peek_group_coordinate(&mut i)?; - match self.inner.get(i) { + match self.tokens.get(i) { Some(SpannedToken { token: Token::RightParen, .. @@ -158,7 +191,7 @@ impl ParserContext { } } let end_span; - match self.inner.get(i) { + match self.tokens.get(i) { Some(SpannedToken { token: Token::Group, span, @@ -171,16 +204,20 @@ impl ParserContext { } } - self.inner.drain((i + 1)..); + self.tokens.drain((i + 1)..); Some((first, second, start_span + end_span)) } + /// + /// Removes the next token if it is a [`Token::Int(_)`] and returns it, or [None] if + /// the next token is not a [`Token::Int(_)`] or if the next token does not exist. + /// pub fn eat_int(&mut self) -> Option<(PositiveNumber, Span)> { if let Some(SpannedToken { token: Token::Int(_), .. - }) = self.inner.last() + }) = self.tokens.last() { - let token = self.inner.pop().unwrap(); + let token = self.tokens.pop().unwrap(); if let SpannedToken { token: Token::Int(value), span, @@ -194,19 +231,26 @@ impl ParserContext { None } + /// + /// Removes the next token if it exists and returns it, or [None] if + /// the next token does not exist. + /// pub fn eat_any(&mut self, token: &[Token]) -> Option { - if let Some(SpannedToken { token: inner, .. }) = self.inner.last() { + if let Some(SpannedToken { token: inner, .. }) = self.tokens.last() { if token.iter().any(|x| x == inner) { - return self.inner.pop(); + return self.tokens.pop(); } } None } + /// + /// Returns the span of the next token if it is equal to the given [`Token`], or error. + /// pub fn expect(&mut self, token: Token) -> SyntaxResult { - if let Some(SpannedToken { token: inner, span }) = self.inner.last() { + if let Some(SpannedToken { token: inner, span }) = self.tokens.last() { if &token == inner { - Ok(self.inner.pop().unwrap().span) + Ok(self.tokens.pop().unwrap().span) } else { Err(SyntaxError::unexpected(inner, &[token], span)) } @@ -215,10 +259,13 @@ impl ParserContext { } } + /// + /// Returns the span of the next token if it is equal to one of the given [`Token`]s, or error. + /// pub fn expect_oneof(&mut self, token: &[Token]) -> SyntaxResult { - if let Some(SpannedToken { token: inner, span }) = self.inner.last() { + if let Some(SpannedToken { token: inner, span }) = self.tokens.last() { if token.iter().any(|x| x == inner) { - Ok(self.inner.pop().unwrap()) + Ok(self.tokens.pop().unwrap()) } else { Err(SyntaxError::unexpected(inner, token, span)) } @@ -227,7 +274,11 @@ impl ParserContext { } } - pub fn expect_loose_ident(&mut self) -> SyntaxResult { + /// + /// Returns the [`Identifier`] of the next token if it is a keyword, + /// [`Token::Int(_)`], or an [`Identifier`], or error. + /// + pub fn expect_loose_identifier(&mut self) -> SyntaxResult { if let Some(token) = self.eat_any(KEYWORD_TOKENS) { return Ok(Identifier { name: token.token.to_string(), @@ -240,10 +291,13 @@ impl ParserContext { self.expect_ident() } + /// + /// Returns the [`Identifier`] of the next token if it is an [`Identifier`], or error. + /// pub fn expect_ident(&mut self) -> SyntaxResult { - if let Some(SpannedToken { token: inner, span }) = self.inner.last() { + if let Some(SpannedToken { token: inner, span }) = self.tokens.last() { if let Token::Ident(_) = inner { - let token = self.inner.pop().unwrap(); + let token = self.tokens.pop().unwrap(); if let SpannedToken { token: Token::Ident(name), span, @@ -261,8 +315,11 @@ impl ParserContext { } } + /// + /// Returns the next token if it exists or return end of function. + /// pub fn expect_any(&mut self) -> SyntaxResult { - if let Some(x) = self.inner.pop() { + if let Some(x) = self.tokens.pop() { Ok(x) } else { Err(self.eof()) diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 68f1a18278..68f7ce59a4 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -325,7 +325,7 @@ impl ParserContext { } } Token::Dot => { - if let Some(ident) = self.eat_ident() { + if let Some(ident) = self.eat_identifier() { expr = Expression::CircuitMemberAccess(CircuitMemberAccessExpression { span: expr.span() + &ident.span, circuit: Box::new(expr), diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 7334ef4700..bf8ec248d3 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -90,7 +90,7 @@ impl ParserContext { end_span = end.span; break; } - if let Some(ident) = self.eat_ident() { + if let Some(ident) = self.eat_identifier() { args.push(ident.name); } else if let Some((int, _)) = self.eat_int() { args.push(int.value); @@ -162,14 +162,14 @@ impl ParserContext { pub fn parse_package_name(&mut self) -> SyntaxResult { // Build the package name, starting with valid characters up to a dash `-` (Token::Minus). - let mut base = self.expect_loose_ident()?; + let mut base = self.expect_loose_identifier()?; // Build the rest of the package name including dashes. while let Some(token) = self.eat(Token::Minus) { if token.span.line_start == base.span.line_stop && token.span.col_start == base.span.col_stop { base.name += "-"; base.span = base.span + token.span; - let next = self.expect_loose_ident()?; + let next = self.expect_loose_identifier()?; base.name += &next.name; base.span = base.span + next.span; } else { diff --git a/parser/src/parser/mod.rs b/parser/src/parser/mod.rs index 5c6e8b7997..0801bf4cf4 100644 --- a/parser/src/parser/mod.rs +++ b/parser/src/parser/mod.rs @@ -37,7 +37,7 @@ pub type SyntaxResult = Result; /// Creates a new program from a given file path and source code text. pub fn parse(path: &str, source: &str) -> SyntaxResult { - let mut tokens = ParserContext::new(crate::tokenize(source, path)?); + let mut tokens = ParserContext::new(crate::tokenize(path, source)?); match tokens.parse_program() { Ok(x) => Ok(x), diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index 97e71c2ead..ef75ce5b07 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -75,7 +75,7 @@ impl ParserContext { pub fn parse_type(&mut self) -> SyntaxResult<(Type, Span)> { Ok(if let Some(token) = self.eat(Token::BigSelf) { (Type::SelfType, token.span) - } else if let Some(ident) = self.eat_ident() { + } else if let Some(ident) = self.eat_identifier() { let span = ident.span.clone(); (Type::Circuit(ident), span) } else if let Some(token) = self.eat(Token::LeftParen) { diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index aeafbb3dfc..72fe7e3f8f 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -31,9 +31,9 @@ use leo_ast::Span; use std::rc::Rc; /// Creates a new vector of spanned tokens from a given file path and source code text. -pub(crate) fn tokenize(input: &str, path: &str) -> Result, TokenError> { +pub(crate) fn tokenize(path: &str, source: &str) -> Result, TokenError> { let path = Rc::new(path.to_string()); - let mut input = input.as_bytes(); + let mut input = source.as_bytes(); let mut tokens = vec![]; let mut index = 0usize; let mut line_no = 1usize; @@ -91,6 +91,7 @@ mod tests { #[test] fn test_tokenizer() { let tokens = tokenize( + "test_path", r#" "test" "test{}test" @@ -195,7 +196,6 @@ mod tests { // test /* test */ //"#, - "test_path", ) .unwrap(); let mut output = String::new(); diff --git a/parser/src/tokenizer/tokenizer.rs b/parser/src/tokenizer/tokenizer.rs index 44b321702a..7c8b8bd972 100644 --- a/parser/src/tokenizer/tokenizer.rs +++ b/parser/src/tokenizer/tokenizer.rs @@ -376,184 +376,3 @@ pub(crate) fn validate_address(address: &str) -> bool { .skip(5) .all(|x| x.is_ascii_lowercase() || x.is_ascii_digit()) } -// -// /// Creates a new vector of spanned tokens from a given file path and source code text. -// pub(crate) fn tokenize(input: &str, path: &str) -> Result, TokenError> { -// let path = Rc::new(path.to_string()); -// let mut input = input.as_bytes(); -// let mut tokens = vec![]; -// let mut index = 0usize; -// let mut line_no = 1usize; -// let mut line_start = 0usize; -// while !input.is_empty() { -// match Token::gobble(input) { -// (output, Some(token)) => { -// let span = Span { -// line_start: line_no, -// line_stop: line_no, -// col_start: index - line_start + 1, -// col_stop: index - line_start + (input.len() - output.len()) + 1, -// path: path.clone(), -// }; -// if let Token::AddressLit(address) = &token { -// if !validate_address(address) { -// return Err(TokenError::invalid_address_lit(address, &span)); -// } -// } -// tokens.push(SpannedToken { token, span }); -// index += input.len() - output.len(); -// input = output; -// } -// (output, None) => { -// if output.is_empty() { -// break; -// } else if output.len() == input.len() { -// return Err(TokenError::unexpected_token( -// &String::from_utf8_lossy(&[input[0]]), -// &Span { -// line_start: line_no, -// line_stop: line_no, -// col_start: index - line_start + 1, -// col_stop: index - line_start + 2, -// path, -// }, -// )); -// } -// index += input.len() - output.len(); -// if input[0] == b'\n' { -// line_no += 1; -// line_start = index; -// } -// input = output; -// } -// } -// } -// Ok(tokens) -// } -// -// #[cfg(test)] -// mod tests { -// use super::*; -// -// #[test] -// fn test_tokenizer() { -// let tokens = tokenize( -// r#" -// "test" -// "test{}test" -// "test{}" -// "{}test" -// "test{" -// "test}" -// "test{test" -// "test}test" -// "te{{}}" -// aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 -// test_ident -// 12345 -// address -// as -// bool -// circuit -// const -// else -// false -// field -// for -// function -// group -// i128 -// i64 -// i32 -// i16 -// i8 -// if -// import -// in -// input -// let -// mut -// return -// static -// string -// test -// true -// u128 -// u64 -// u32 -// u16 -// u8 -// self -// Self -// console -// ! -// != -// && -// ( -// ) -// * -// ** -// **= -// *= -// + -// += -// , -// - -// -= -// -> -// . -// .. -// ... -// / -// /= -// : -// :: -// ; -// < -// <= -// = -// == -// > -// >= -// @ -// [ -// ] -// {{ -// }} -// || -// & -// &= -// | -// |= -// ^ -// ^= -// ~ -// << -// <<= -// >> -// >>= -// >>> -// >>>= -// % -// %= -// ||= -// &&= -// ? -// // test -// /* test */ -// //"#, -// "test_path", -// ) -// .unwrap(); -// let mut output = String::new(); -// for SpannedToken { token, .. } in tokens.iter() { -// output += &format!("{} ", &token.to_string()); -// } -// assert_eq!( -// output, -// r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= ? // test -// /* test */ // -// "# -// ); -// } -// } From e492950106851b005a51bf9499a6db795040b168 Mon Sep 17 00:00:00 2001 From: Protryon Date: Fri, 5 Mar 2021 09:15:37 -0800 Subject: [PATCH 78/92] fix package names --- parser/src/parser/file.rs | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index bf8ec248d3..c7c087add0 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -162,18 +162,35 @@ impl ParserContext { pub fn parse_package_name(&mut self) -> SyntaxResult { // Build the package name, starting with valid characters up to a dash `-` (Token::Minus). - let mut base = self.expect_loose_identifier()?; + let mut base = self.expect_loose_ident()?; // Build the rest of the package name including dashes. - while let Some(token) = self.eat(Token::Minus) { - if token.span.line_start == base.span.line_stop && token.span.col_start == base.span.col_stop { - base.name += "-"; - base.span = base.span + token.span; - let next = self.expect_loose_identifier()?; - base.name += &next.name; - base.span = base.span + next.span; - } else { - break; + loop { + match &self.peek()?.token { + Token::Minus => { + let span = self.expect(Token::Minus)?; + base.name += "-"; + base.span = base.span + span; + let next = self.expect_loose_ident()?; + base.name += &next.name; + base.span = base.span + next.span; + }, + Token::Int(_) => { + let (num, span) = self.eat_int().unwrap(); + base.name += &num.value; + base.span = base.span + span; + }, + Token::Ident(_) => { + let next = self.expect_ident()?; + base.name += &next.name; + base.span = base.span + next.span; + }, + x if KEYWORD_TOKENS.contains(&x) => { + let next = self.expect_loose_ident()?; + base.name += &next.name; + base.span = base.span + next.span; + }, + _ => break, } } From d14a3a666b01f796567dbe7e5a33586d8388b738 Mon Sep 17 00:00:00 2001 From: Protryon Date: Fri, 5 Mar 2021 09:19:26 -0800 Subject: [PATCH 79/92] format --- parser/src/parser/file.rs | 18 +++++++++--------- .../src/tokenizer/{tokenizer.rs => lexer.rs} | 0 parser/src/tokenizer/mod.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) rename parser/src/tokenizer/{tokenizer.rs => lexer.rs} (100%) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index c7c087add0..970e34570e 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -162,7 +162,7 @@ impl ParserContext { pub fn parse_package_name(&mut self) -> SyntaxResult { // Build the package name, starting with valid characters up to a dash `-` (Token::Minus). - let mut base = self.expect_loose_ident()?; + let mut base = self.expect_loose_identifier()?; // Build the rest of the package name including dashes. loop { @@ -171,25 +171,25 @@ impl ParserContext { let span = self.expect(Token::Minus)?; base.name += "-"; base.span = base.span + span; - let next = self.expect_loose_ident()?; + let next = self.expect_loose_identifier()?; base.name += &next.name; - base.span = base.span + next.span; - }, + base.span = base.span + next.span; + } Token::Int(_) => { let (num, span) = self.eat_int().unwrap(); base.name += &num.value; base.span = base.span + span; - }, + } Token::Ident(_) => { let next = self.expect_ident()?; base.name += &next.name; base.span = base.span + next.span; - }, + } x if KEYWORD_TOKENS.contains(&x) => { - let next = self.expect_loose_ident()?; + let next = self.expect_loose_identifier()?; base.name += &next.name; - base.span = base.span + next.span; - }, + base.span = base.span + next.span; + } _ => break, } } diff --git a/parser/src/tokenizer/tokenizer.rs b/parser/src/tokenizer/lexer.rs similarity index 100% rename from parser/src/tokenizer/tokenizer.rs rename to parser/src/tokenizer/lexer.rs diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index 72fe7e3f8f..4da08ed84d 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -22,8 +22,8 @@ pub(crate) mod token; pub(crate) use self::token::*; -pub(crate) mod tokenizer; -pub(crate) use self::tokenizer::*; +pub(crate) mod lexer; +pub(crate) use self::lexer::*; use crate::TokenError; use leo_ast::Span; From f86e03f4b7d5ee07a0775f08d022ef86809c03a0 Mon Sep 17 00:00:00 2001 From: Protryon Date: Fri, 5 Mar 2021 09:53:06 -0800 Subject: [PATCH 80/92] fix spans for comments --- parser/src/tokenizer/lexer.rs | 11 +++---- parser/src/tokenizer/mod.rs | 54 ++++++++++++++++++++++++++++++++--- parser/src/tokenizer/token.rs | 9 +++--- 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 7c8b8bd972..5540857ce0 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -16,6 +16,7 @@ use crate::tokenizer::{FormattedStringPart, Token}; use leo_ast::Span; +use serde::{Deserialize, Serialize}; use std::fmt; @@ -192,7 +193,7 @@ impl Token { return (&input[1..], Some(Token::Dot)); } b'/' => { - if let Some(input) = eat(input, "//") { + if eat(input, "//").is_some() { let eol = input.iter().position(|x| *x == b'\n'); let (input, comment) = if let Some(eol) = eol { (&input[(eol + 1)..], &input[..eol]) @@ -203,13 +204,13 @@ impl Token { input, Some(Token::CommentLine(String::from_utf8_lossy(comment).to_string())), ); - } else if let Some(input) = eat(input, "/*") { + } else if eat(input, "/*").is_some() { if input.is_empty() { return (input, None); } - let eol = input.windows(2).position(|x| x[0] == b'*' && x[1] == b'/'); + let eol = input.windows(2).skip(2).position(|x| x[0] == b'*' && x[1] == b'/'); let (input, comment) = if let Some(eol) = eol { - (&input[(eol + 2)..], &input[..eol]) + (&input[(eol + 4)..], &input[..eol + 4]) } else { (&input[input.len()..input.len()], &input[..]) }; @@ -347,7 +348,7 @@ impl Token { } } -#[derive(Clone)] +#[derive(Clone, Serialize, Deserialize)] pub struct SpannedToken { pub token: Token, pub span: Span, diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index 4da08ed84d..e302920584 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -41,17 +41,34 @@ pub(crate) fn tokenize(path: &str, source: &str) -> Result, To while !input.is_empty() { match Token::gobble(input) { (output, Some(token)) => { - let span = Span { + let mut span = Span { line_start: line_no, line_stop: line_no, col_start: index - line_start + 1, col_stop: index - line_start + (input.len() - output.len()) + 1, path: path.clone(), }; - if let Token::AddressLit(address) = &token { - if !validate_address(address) { - return Err(TokenError::invalid_address_lit(address, &span)); + match &token { + Token::CommentLine(_) => { + line_no += 1; + line_start = index + (input.len() - output.len()); } + Token::CommentBlock(block) => { + let line_ct = block.chars().filter(|x| *x == '\n').count(); + line_no += line_ct; + if line_ct > 0 { + let last_line_index = block.rfind('\n').unwrap(); + line_start = index + last_line_index + 1; + span.col_stop = index + (input.len() - output.len()) - line_start + 1; + } + span.line_stop = line_no; + } + Token::AddressLit(address) => { + if !validate_address(address) { + return Err(TokenError::invalid_address_lit(address, &span)); + } + } + _ => (), } tokens.push(SpannedToken { token, span }); index += input.len() - output.len(); @@ -209,4 +226,33 @@ mod tests { "# ); } + + #[test] + fn test_spans() { + let raw = r#" + test + // test + test + /* test */ + test + /* test + test */ + test + "#; + let tokens = tokenize("test_path", raw).unwrap(); + let mut line_indicies = vec![0]; + for (i, c) in raw.chars().enumerate() { + if c == '\n' { + line_indicies.push(i + 1); + } + } + for token in tokens.iter() { + let token_raw = token.token.to_string(); + let start = line_indicies.get(token.span.line_start - 1).unwrap(); + let stop = line_indicies.get(token.span.line_stop - 1).unwrap(); + let original = &raw[*start + token.span.col_start - 1..*stop + token.span.col_stop - 1]; + assert_eq!(original, &token_raw); + } + println!("{}", serde_json::to_string_pretty(&tokens).unwrap()); + } } diff --git a/parser/src/tokenizer/token.rs b/parser/src/tokenizer/token.rs index b1124eeac4..f1323eca59 100644 --- a/parser/src/tokenizer/token.rs +++ b/parser/src/tokenizer/token.rs @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum FormattedStringPart { Const(String), Container, @@ -31,7 +32,7 @@ impl fmt::Display for FormattedStringPart { } } -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Token { FormattedString(Vec), AddressLit(String), @@ -186,8 +187,8 @@ impl fmt::Display for Token { AddressLit(s) => write!(f, "{}", s), Ident(s) => write!(f, "{}", s), Int(s) => write!(f, "{}", s), - CommentLine(s) => writeln!(f, "//{}", s), - CommentBlock(s) => write!(f, "/*{}*/ ", s), + CommentLine(s) => writeln!(f, "{}", s), + CommentBlock(s) => write!(f, "{}", s), Not => write!(f, "!"), NotEq => write!(f, "!="), And => write!(f, "&&"), From 4fada913fb8367507f985072e1fffd533b7217f1 Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 5 Mar 2021 14:09:14 -0800 Subject: [PATCH 81/92] add comments to parser expression --- parser/src/parser/context.rs | 1 - parser/src/parser/expression.rs | 137 ++++++++++++++++++++++++++++++-- 2 files changed, 131 insertions(+), 7 deletions(-) diff --git a/parser/src/parser/context.rs b/parser/src/parser/context.rs index 5fe63ce4a0..1c3f41f53e 100644 --- a/parser/src/parser/context.rs +++ b/parser/src/parser/context.rs @@ -163,7 +163,6 @@ impl ParserContext { /// Removes the next two tokens if they are a pair of [`GroupCoordinate`] and returns them, /// or [None] if the next token is not a [`GroupCoordinate`]. /// - // kinda hacky, we're not LALR(1) for groups... pub fn eat_group_partial(&mut self) -> Option<(GroupCoordinate, GroupCoordinate, Span)> { let mut i = self.tokens.len() - 1; let start_span = self.tokens.get(i)?.span.clone(); diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 68f7ce59a4..299368b5c3 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -32,17 +32,40 @@ const INT_TYPES: &[Token] = &[ ]; impl ParserContext { + /// + /// Returns an [`Expression`] AST node if the next token is an expression. + /// Includes circuit init expressions. + /// pub fn parse_expression(&mut self) -> SyntaxResult { + // Store current parser state. let prior_fuzzy_state = self.fuzzy_struct_state; + + // Allow circuit init expressions. self.fuzzy_struct_state = false; + + // Parse expression. let result = self.parse_expression_fuzzy(); + + // Restore prior parser state. self.fuzzy_struct_state = prior_fuzzy_state; + result } + /// + /// Returns an [`Expression`] AST node if the next tokens represent + /// a ternary expression. May or may not include circuit init expressions. + /// + /// Otherwise, tries to parse the next token using [`parse_or_expression`]. + /// pub fn parse_expression_fuzzy(&mut self) -> SyntaxResult { + // Check if we are parsing a ternary expression. let if_token = self.eat(Token::If); + + // Try to parse the next expression. Try BinaryOperation::Or. let mut expr = self.parse_or_expression()?; + + // Parse the rest of the ternary expression. if self.eat(Token::Question).is_some() { let if_true = self.parse_expression()?; self.expect(Token::Colon)?; @@ -60,6 +83,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent + /// a binary or expression. + /// + /// Otherwise, tries to parse the next token using [`parse_and_expression`]. + /// pub fn parse_or_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_and_expression()?; while self.eat(Token::Or).is_some() { @@ -74,6 +103,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary and expression. + /// + /// Otherwise, tries to parse the next token using [`parse_bit_or_expression`]. + /// pub fn parse_and_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_bit_or_expression()?; while self.eat(Token::And).is_some() { @@ -88,6 +123,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary bitwise or expression. + /// + /// Otherwise, tries to parse the next token using [`parse_bit_xor_expression`]. + /// pub fn parse_bit_or_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_bit_xor_expression()?; while self.eat(Token::BitOr).is_some() { @@ -102,6 +143,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary bitwise xor expression. + /// + /// Otherwise, tries to parse the next token using [`parse_bit_and_expression`]. + /// pub fn parse_bit_xor_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_bit_and_expression()?; while self.eat(Token::BitXor).is_some() { @@ -116,6 +163,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary bitwise and expression. + /// + /// Otherwise, tries to parse the next token using [`parse_eq_expression`]. + /// pub fn parse_bit_and_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_eq_expression()?; while self.eat(Token::BitAnd).is_some() { @@ -130,6 +183,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary equals or not equals expression. + /// + /// Otherwise, tries to parse the next token using [`parse_rel_expression`]. + /// pub fn parse_eq_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_rel_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Eq, Token::NotEq]) { @@ -148,6 +207,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary relational expression: less than, less than or equals, greater than, greater than or equals. + /// + /// Otherwise, tries to parse the next token using [`parse_shift_expression`]. + /// pub fn parse_rel_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_shift_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Lt, Token::LtEq, Token::Gt, Token::GtEq]) @@ -169,10 +234,16 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary shift expression. + /// + /// Otherwise, tries to parse the next token using [`parse_add_sub_expression`]. + /// pub fn parse_shift_expression(&mut self) -> SyntaxResult { - let mut expr = self.parse_add_expression()?; + let mut expr = self.parse_add_sub_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Shl, Token::Shr, Token::ShrSigned]) { - let right = self.parse_add_expression()?; + let right = self.parse_add_sub_expression()?; expr = Expression::Binary(BinaryExpression { span: expr.span() + right.span(), op: match op { @@ -188,10 +259,16 @@ impl ParserContext { Ok(expr) } - pub fn parse_add_expression(&mut self) -> SyntaxResult { - let mut expr = self.parse_multiply_expression()?; + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary addition or subtraction expression. + /// + /// Otherwise, tries to parse the next token using [`parse_mul_div_pow_expression`]. + /// + pub fn parse_add_sub_expression(&mut self) -> SyntaxResult { + let mut expr = self.parse_mul_div_mod_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Add, Token::Minus]) { - let right = self.parse_multiply_expression()?; + let right = self.parse_mul_div_mod_expression()?; expr = Expression::Binary(BinaryExpression { span: expr.span() + right.span(), op: match op { @@ -206,7 +283,13 @@ impl ParserContext { Ok(expr) } - pub fn parse_multiply_expression(&mut self) -> SyntaxResult { + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary multiplication, division, or modulus expression. + /// + /// Otherwise, tries to parse the next token using [`parse_exp_expression`]. + /// + pub fn parse_mul_div_mod_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_exp_expression()?; while let Some(SpannedToken { token: op, .. }) = self.eat_any(&[Token::Mul, Token::Div, Token::Mod]) { let right = self.parse_exp_expression()?; @@ -225,6 +308,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// binary exponentiation expression. + /// + /// Otherwise, tries to parse the next token using [`parse_cast_expression`]. + /// pub fn parse_exp_expression(&mut self) -> SyntaxResult { let mut exprs = vec![]; exprs.push(self.parse_cast_expression()?); @@ -244,6 +333,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// type cast expression. + /// + /// Otherwise, tries to parse the next token using [`parse_unary_expression`]. + /// pub fn parse_cast_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_unary_expression()?; while self.eat(Token::As).is_some() { @@ -257,6 +352,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent a + /// unary not, negate, or bitwise not expression. + /// + /// Otherwise, tries to parse the next token using [`parse_access_expression`]. + /// pub fn parse_unary_expression(&mut self) -> SyntaxResult { let mut ops = vec![]; while let Some(token) = self.eat_any(&[Token::Not, Token::Minus, Token::BitNot]) { @@ -278,6 +379,12 @@ impl ParserContext { Ok(inner) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent an + /// array access, circuit member access, function call, or static function call expression. + /// + /// Otherwise, tries to parse the next token using [`parse_primary_expression`]. + /// pub fn parse_access_expression(&mut self) -> SyntaxResult { let mut expr = self.parse_primary_expression()?; while let Some(token) = self.eat_any(&[Token::LeftSquare, Token::Dot, Token::LeftParen, Token::DoubleColon]) { @@ -377,6 +484,12 @@ impl ParserContext { Ok(expr) } + /// + /// Returns a [`SpreadOrExpression`] AST node if the next tokens represent an + /// spread or expression. + /// + /// This method should only be called in the context of an array access expression. + /// pub fn parse_spread_or_expression(&mut self) -> SyntaxResult { Ok(if self.eat(Token::DotDotDot).is_some() { SpreadOrExpression::Spread(self.parse_expression()?) @@ -385,6 +498,10 @@ impl ParserContext { }) } + /// + /// Returns an [`Expression`] AST node if the next tokens represent an + /// circuit initialization expression. + /// pub fn parse_circuit_init(&mut self, ident: Identifier) -> SyntaxResult { self.expect(Token::LeftCurly)?; let mut members = vec![]; @@ -419,6 +536,14 @@ impl ParserContext { })) } + /// + /// Returns an [`Expression`] AST node if the next token is a primary expression: + /// - Scalar types: field, group, unsigned integer, signed integer, boolean, address + /// - Aggregate types: array, tuple + /// - Identifiers: variables, keywords + /// + /// Returns an expression error if the token cannot be matched. + /// pub fn parse_primary_expression(&mut self) -> SyntaxResult { let SpannedToken { token, span } = self.expect_any()?; Ok(match token { From 01e2a13170ef790bf8dc907b8de6633a551cc98e Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 5 Mar 2021 14:26:59 -0800 Subject: [PATCH 82/92] add comments to parser file --- parser/src/parser/file.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 970e34570e..a5d0649edd 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -19,6 +19,9 @@ use crate::KEYWORD_TOKENS; use super::*; impl ParserContext { + /// + /// Returns a [`Program`] AST if all tokens can be consumed and represent a valid Leo program. + /// pub fn parse_program(&mut self) -> SyntaxResult { let mut imports = vec![]; let mut circuits = IndexMap::new(); @@ -74,6 +77,9 @@ impl ParserContext { }) } + /// + /// Returns an [`Annotation`] AST node if the next tokens represent a supported annotation. + /// pub fn parse_annotation(&mut self) -> SyntaxResult { let start = self.expect(Token::At)?; let name = self.expect_ident()?; @@ -115,6 +121,10 @@ impl ParserContext { }) } + /// + /// Returns a vector of [`PackageAccess`] AST nodes if the next tokens represent package access + /// expressions within an import statement. + /// pub fn parse_package_accesses(&mut self) -> SyntaxResult> { let mut out = vec![]; self.expect(Token::LeftParen)?; @@ -129,6 +139,10 @@ impl ParserContext { Ok(out) } + /// + /// Returns a [`PackageAccess`] AST node if the next tokens represent a package access expression + /// within an import statement. + /// pub fn parse_package_access(&mut self) -> SyntaxResult { if let Some(SpannedToken { span, .. }) = self.eat(Token::Mul) { Ok(PackageAccess::Star(span)) @@ -160,6 +174,9 @@ impl ParserContext { } } + /// + /// Returns an [`Identifier`] AST node if the next tokens represent a valid package name. + /// pub fn parse_package_name(&mut self) -> SyntaxResult { // Build the package name, starting with valid characters up to a dash `-` (Token::Minus). let mut base = self.expect_loose_identifier()?; @@ -212,6 +229,10 @@ impl ParserContext { Ok(base) } + /// + /// Returns a [`PackageOrPackages`] AST node if the next tokens represent a valid package import + /// with accesses. + /// pub fn parse_package_or_packages(&mut self) -> SyntaxResult { let package_name = self.parse_package_name()?; self.expect(Token::Dot)?; @@ -232,6 +253,9 @@ impl ParserContext { } } + /// + /// Returns a [`ImportStatement`] AST node if the next tokens represent an import statement. + /// pub fn parse_import(&mut self) -> SyntaxResult { self.expect(Token::Import)?; let package_or_packages = self.parse_package_or_packages()?; @@ -242,6 +266,10 @@ impl ParserContext { }) } + /// + /// Returns a [`CircuitMember`] AST node if the next tokens represent a circuit member variable + /// or circuit member function. + /// pub fn parse_circuit_member(&mut self) -> SyntaxResult { let peeked = &self.peek()?.token; if peeked == &Token::Function || peeked == &Token::At { @@ -257,6 +285,10 @@ impl ParserContext { } } + /// + /// Returns a [`(Identifier, Circuit)`] tuple of AST nodes if the next tokens represent a + /// circuit name and definition statement. + /// pub fn parse_circuit(&mut self) -> SyntaxResult<(Identifier, Circuit)> { self.expect(Token::Circuit)?; let name = self.expect_ident()?; @@ -272,6 +304,9 @@ impl ParserContext { })) } + /// + /// Returns a [`FunctionInput`] AST node if the next tokens represent a function parameter. + /// pub fn parse_function_input(&mut self) -> SyntaxResult { if let Some(token) = self.eat(Token::Input) { return Ok(FunctionInput::InputKeyword(InputKeyword { span: token.span })); @@ -308,6 +343,10 @@ impl ParserContext { })) } + /// + /// Returns an [`(Identifier, Function)`] AST node if the next tokens represent a function name + /// and function definition. + /// pub fn parse_function(&mut self) -> SyntaxResult<(Identifier, Function)> { let mut annotations = vec![]; while self.peek()?.token == Token::At { From 7caf53bb315704869461b31f689105d13bec5a90 Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 5 Mar 2021 14:38:40 -0800 Subject: [PATCH 83/92] add comments to parser statements --- parser/src/parser/file.rs | 2 +- parser/src/parser/statement.rs | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index a5d0649edd..36dca63852 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -286,7 +286,7 @@ impl ParserContext { } /// - /// Returns a [`(Identifier, Circuit)`] tuple of AST nodes if the next tokens represent a + /// Returns an [`(Identifier, Circuit)`] tuple of AST nodes if the next tokens represent a /// circuit name and definition statement. /// pub fn parse_circuit(&mut self) -> SyntaxResult<(Identifier, Circuit)> { diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index fede6a5eab..c01190fa0b 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -35,6 +35,10 @@ const ASSIGN_TOKENS: &[Token] = &[ ]; impl ParserContext { + /// + /// Returns an [`Identifier`] AST node if the given [`Expression`] AST node evaluates to an + /// identifier access. The access is stored in the given accesses. + /// pub fn construct_assignee_access(expr: Expression, accesses: &mut Vec) -> SyntaxResult { let identifier; match expr { @@ -63,6 +67,9 @@ impl ParserContext { Ok(identifier) } + /// + /// Returns an [`Assignee`] AST node from the given [`Expression`] AST node with accesses. + /// pub fn construct_assignee(expr: Expression) -> SyntaxResult { let expr_span = expr.span().clone(); let mut accesses = vec![]; @@ -75,6 +82,9 @@ impl ParserContext { }) } + /// + /// Returns a [`Statement`] AST node if the next tokens represent a statement. + /// pub fn parse_statement(&mut self) -> SyntaxResult { match &self.peek()?.token { Token::Return => Ok(Statement::Return(self.parse_return_statement()?)), @@ -124,6 +134,9 @@ impl ParserContext { } } + /// + /// Returns a [`Block`] AST node if the next tokens represent a block of statements. + /// pub fn parse_block(&mut self) -> SyntaxResult { let start = self.expect(Token::LeftCurly)?; let mut statements = vec![]; @@ -142,6 +155,9 @@ impl ParserContext { } } + /// + /// Returns a [`ReturnStatement`] AST node if the next tokens represent a return statement. + /// pub fn parse_return_statement(&mut self) -> SyntaxResult { let start = self.expect(Token::Return)?; let expr = self.parse_expression()?; @@ -153,6 +169,9 @@ impl ParserContext { }) } + /// + /// Returns a [`ConditionalStatement`] AST node if the next tokens represent a conditional statement. + /// pub fn parse_conditional_statement(&mut self) -> SyntaxResult { let start = self.expect(Token::If)?; self.fuzzy_struct_state = true; @@ -173,6 +192,9 @@ impl ParserContext { }) } + /// + /// Returns an [`IterationStatement`] AST node if the next tokens represent an iteration statement. + /// pub fn parse_for_statement(&mut self) -> SyntaxResult { let start_span = self.expect(Token::For)?; let ident = self.expect_ident()?; @@ -193,6 +215,9 @@ impl ParserContext { }) } + /// + /// Returns a [`FormattedString`] AST node if the next tokens represent a formatted string. + /// pub fn parse_formatted_string(&mut self) -> SyntaxResult { let start_span; let parts = match self.expect_any()? { @@ -224,6 +249,9 @@ impl ParserContext { }) } + /// + /// Returns a [`ConsoleStatement`] AST node if the next tokens represent a console statement. + /// pub fn parse_console_statement(&mut self) -> SyntaxResult { let keyword = self.expect(Token::Console)?; self.expect(Token::Dot)?; @@ -254,6 +282,10 @@ impl ParserContext { }) } + /// + /// Returns a [`VariableName`] AST node if the next tokens represent a variable name with + /// valid keywords. + /// pub fn parse_variable_name(&mut self) -> SyntaxResult { let mutable = self.eat(Token::Mut); let name = self.expect_ident()?; @@ -267,6 +299,9 @@ impl ParserContext { }) } + /// + /// Returns a [`DefinitionStatement`] AST node if the next tokens represent a definition statement. + /// pub fn parse_definition_statement(&mut self) -> SyntaxResult { let declare = self.expect_oneof(&[Token::Let, Token::Const])?; let mut variable_names = vec![]; From ef91489829f499ff8bc3ec680c00195a41e4e8ac Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 5 Mar 2021 14:43:27 -0800 Subject: [PATCH 84/92] add comments to parser types --- parser/src/parser/type_.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index ef75ce5b07..cac76bbd3c 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -34,6 +34,9 @@ const TYPE_TOKENS: &[Token] = &[ ]; impl ParserContext { + /// + /// Returns a [`IntegerType`] AST node if the given token is a supported integer type, or [`None`]. + /// pub fn token_to_int_type(token: Token) -> Option { Some(match token { Token::I8 => IntegerType::I8, @@ -50,6 +53,9 @@ impl ParserContext { }) } + /// + /// Returns an [`ArrayDimensions`] AST node if the next tokens represent dimensions for an array type. + /// pub fn parse_array_dimensions(&mut self) -> SyntaxResult { Ok(if let Some((int, _)) = self.eat_int() { ArrayDimensions(vec![int]) @@ -72,6 +78,10 @@ impl ParserContext { }) } + /// + /// Returns a [`(Type, Span)`] tuple of AST nodes if the next token represents a type. Also + /// returns the span of the parsed token. + /// pub fn parse_type(&mut self) -> SyntaxResult<(Type, Span)> { Ok(if let Some(token) = self.eat(Token::BigSelf) { (Type::SelfType, token.span) From 76afaf6167514aef55714bc836cdefadc63d3e76 Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 5 Mar 2021 15:01:43 -0800 Subject: [PATCH 85/92] add comments to parser tokenizer --- parser/src/tokenizer/lexer.rs | 22 +++++++++++++++++++++- parser/src/tokenizer/mod.rs | 2 +- parser/src/tokenizer/token.rs | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 5540857ce0..3a6d91c1e1 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -20,6 +20,10 @@ use serde::{Deserialize, Serialize}; use std::fmt; +/// +/// Returns a reference to bytes from the given input if the given string is equal to the bytes, +/// otherwise returns [`None`]. +/// fn eat<'a>(input: &'a [u8], wanted: &str) -> Option<&'a [u8]> { let wanted = wanted.as_bytes(); if input.len() < wanted.len() { @@ -31,6 +35,10 @@ fn eat<'a>(input: &'a [u8], wanted: &str) -> Option<&'a [u8]> { None } +/// +/// Returns a reference to the bytes of an identifier and the remaining bytes from the given input. +/// Returns [`None`] if the bytes do not represent an identifier. +/// fn eat_identifier(input: &[u8]) -> Option<(&[u8], &[u8])> { if input.is_empty() { return None; @@ -49,6 +57,10 @@ fn eat_identifier(input: &[u8]) -> Option<(&[u8], &[u8])> { } impl Token { + /// + /// Returns a reference to the remaining bytes and the bytes of a number from the given input. + /// Returns [`None`] if the bytes do not represent a number. + /// fn gobble_int(input: &[u8]) -> (&[u8], Option) { if input.is_empty() { return (input, None); @@ -80,6 +92,10 @@ impl Token { ) } + /// + /// Returns a reference to the remaining bytes and the bytes of a [`Token`] from the given input. + /// Returns [`None`] if the bytes do not represent a token. + /// pub(crate) fn gobble(input: &[u8]) -> (&[u8], Option) { if input.is_empty() { return (input, None); @@ -367,7 +383,11 @@ impl fmt::Debug for SpannedToken { } } -pub(crate) fn validate_address(address: &str) -> bool { +/// +/// Returns true if the given string looks like Aleo address. +/// This method DOES NOT check if the address is valid on-chain. +/// +pub(crate) fn check_address(address: &str) -> bool { // "aleo1" (LOWERCASE_LETTER | ASCII_DIGIT){58} if !address.starts_with("aleo1") || address.len() != 63 { return false; diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index e302920584..40b90b5ca2 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -64,7 +64,7 @@ pub(crate) fn tokenize(path: &str, source: &str) -> Result, To span.line_stop = line_no; } Token::AddressLit(address) => { - if !validate_address(address) { + if !check_address(address) { return Err(TokenError::invalid_address_lit(address, &span)); } } diff --git a/parser/src/tokenizer/token.rs b/parser/src/tokenizer/token.rs index f1323eca59..18604d64db 100644 --- a/parser/src/tokenizer/token.rs +++ b/parser/src/tokenizer/token.rs @@ -17,6 +17,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; +/// Parts of a formatted string for logging to the console. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum FormattedStringPart { Const(String), @@ -32,6 +33,7 @@ impl fmt::Display for FormattedStringPart { } } +/// Represents all valid Leo syntax tokens. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] pub enum Token { FormattedString(Vec), @@ -129,6 +131,7 @@ pub enum Token { Question, } +/// Represents all valid Leo keyword tokens. pub const KEYWORD_TOKENS: &[Token] = &[ Token::Address, Token::As, @@ -167,6 +170,9 @@ pub const KEYWORD_TOKENS: &[Token] = &[ ]; impl Token { + /// + /// Returns `true` if the `self` token equals a Leo keyword. + /// pub fn is_keyword(&self) -> bool { KEYWORD_TOKENS.iter().any(|x| x == self) } From 7cc331f2199173dfcec34dd4e34f83b10ae0beb6 Mon Sep 17 00:00:00 2001 From: collin Date: Fri, 5 Mar 2021 16:11:39 -0800 Subject: [PATCH 86/92] fix formatting error --- ast/src/errors/error.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ast/src/errors/error.rs b/ast/src/errors/error.rs index 28b7d48f72..1f029866aa 100644 --- a/ast/src/errors/error.rs +++ b/ast/src/errors/error.rs @@ -110,7 +110,7 @@ impl fmt::Display for FormattedError { write!( f, - "{indent }--> {path}{line_start}:{start}\n\ + "{indent }--> {path} {line_start}:{start}\n\ {indent } |\n", indent = INDENT, path = path, @@ -132,7 +132,7 @@ impl fmt::Display for FormattedError { write!( f, - "{indent } | {underline}\n\ + "{indent } | {underline}\n\ {indent } |\n\ {indent } = {message}", indent = INDENT, From f5187fc872d104bddb7ef3d46a072628183bdea0 Mon Sep 17 00:00:00 2001 From: Protryon Date: Sun, 7 Mar 2021 06:27:42 -0800 Subject: [PATCH 87/92] fix some failing tests --- asg/src/const_value.rs | 65 ++++++++++++++--- asg/src/error/mod.rs | 8 +++ asg/src/expression/unary.rs | 20 ++++-- ast/src/common/span.rs | 2 +- ast/src/types/integer_type.rs | 10 +++ compiler/tests/mutability/mod.rs | 17 ----- parser/src/tokenizer/lexer.rs | 4 +- parser/src/tokenizer/mod.rs | 2 +- .../tests/serialization/expected_leo_ast.json | 72 ++++++++++--------- 9 files changed, 129 insertions(+), 71 deletions(-) diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index f093a65559..2316604925 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -186,7 +186,7 @@ macro_rules! const_int_bimap { impl ConstInt { const_int_op!(raw_value, String, x, format!("{}", x)); - const_int_map!(value_negate, x, x.checked_neg()?); + const_int_map!(value_negate, x, x.overflowing_neg().0); const_int_map!(value_bit_negate, x, !x); @@ -267,18 +267,61 @@ impl ConstInt { Type::Integer(self.get_int_type()) } + fn parse_signed(int_type: &IntegerType, raw: u128) -> Option { + Some(match int_type { + IntegerType::I8 => ConstInt::I8(raw.try_into().ok()?), + IntegerType::I16 => ConstInt::I16(raw.try_into().ok()?), + IntegerType::I32 => ConstInt::I32(raw.try_into().ok()?), + IntegerType::I64 => ConstInt::I64(raw.try_into().ok()?), + IntegerType::I128 => ConstInt::I128(raw.try_into().ok()?), + _ => panic!("illegal type passed to parse_signed"), + }) + } + pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result { + let raw: u128 = value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?; Ok(match int_type { - IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + // IntegerType::I8 => ConstInt::I8(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), + // IntegerType::I16 => ConstInt::I16(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), + // IntegerType::I32 => ConstInt::I32(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), + // IntegerType::I64 => ConstInt::I64(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), + // IntegerType::I128 => ConstInt::I128(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), + IntegerType::U8 => ConstInt::U8( + raw.try_into() + .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, + ), + IntegerType::U16 => ConstInt::U16( + raw.try_into() + .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, + ), + IntegerType::U32 => ConstInt::U32( + raw.try_into() + .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, + ), + IntegerType::U64 => ConstInt::U64( + raw.try_into() + .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, + ), + IntegerType::U128 => ConstInt::U128( + raw.try_into() + .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, + ), + signed_type => { + if let Some(parsed) = Self::parse_signed(signed_type, raw) { + parsed + } else if let Some(_parsed) = Self::parse_signed(signed_type, raw - 1) { + match int_type { + IntegerType::I8 => ConstInt::I8(raw as i8), + IntegerType::I16 => ConstInt::I16(raw as i16), + IntegerType::I32 => ConstInt::I32(raw as i32), + IntegerType::I64 => ConstInt::I64(raw as i64), + IntegerType::I128 => ConstInt::I128(raw as i128), + _ => panic!("illegal type passed to parse_signed"), + } + } else { + return Err(AsgConvertError::overflowed_const_int(&value, span)); + } + } }) } } diff --git a/asg/src/error/mod.rs b/asg/src/error/mod.rs index 74f7f3944e..1cb3ef346e 100644 --- a/asg/src/error/mod.rs +++ b/asg/src/error/mod.rs @@ -244,6 +244,14 @@ impl AsgConvertError { Self::new_from_span(format!("failed to parse int value '{}'", value), span) } + pub fn overflowed_const_int(value: &str, span: &Span) -> Self { + Self::new_from_span(format!("const int value is overflowed for type '{}'", value), span) + } + + pub fn unsigned_negation(span: &Span) -> Self { + Self::new_from_span("cannot negate unsigned integer".to_string(), span) + } + pub fn immutable_assignment(name: &str, span: &Span) -> Self { Self::new_from_span(format!("illegal assignment to immutable variable '{}'", name), span) } diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index fa8ac8474a..4ccc7662a6 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -126,15 +126,25 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { } }, }; + let expr = <&Expression<'a>>::from_ast(scope, &*value.inner, expected_type.map(Into::into))?; + + if matches!(value.op, UnaryOperation::Negate) { + let is_expr_unsigned = expr + .get_type() + .map(|x| match x { + Type::Integer(x) => !x.is_signed(), + _ => false, + }) + .unwrap_or(false); + if is_expr_unsigned { + return Err(AsgConvertError::unsigned_negation(&value.span)); + } + } Ok(UnaryExpression { parent: Cell::new(None), span: Some(value.span.clone()), operation: value.op.clone(), - inner: Cell::new(<&Expression<'a>>::from_ast( - scope, - &*value.inner, - expected_type.map(Into::into), - )?), + inner: Cell::new(expr), }) } } diff --git a/ast/src/common/span.rs b/ast/src/common/span.rs index ab6c3607c3..33879b364f 100644 --- a/ast/src/common/span.rs +++ b/ast/src/common/span.rs @@ -76,7 +76,7 @@ impl std::ops::Add for Span { col_stop: self.col_stop.max(other.col_stop), path: self.path, } - } else if self.line_start < other.line_start { + } else if self.line_start < other.line_stop { Span { line_start: self.line_start, line_stop: other.line_stop, diff --git a/ast/src/types/integer_type.rs b/ast/src/types/integer_type.rs index 36cd47d27b..2319c51769 100644 --- a/ast/src/types/integer_type.rs +++ b/ast/src/types/integer_type.rs @@ -39,6 +39,16 @@ pub enum IntegerType { I128, } +impl IntegerType { + pub fn is_signed(&self) -> bool { + use IntegerType::*; + match self { + I8 | I16 | I32 | I64 | I128 => true, + _ => false, + } + } +} + impl From for IntegerType { fn from(integer_type: InputIntegerType) -> Self { match integer_type { diff --git a/compiler/tests/mutability/mod.rs b/compiler/tests/mutability/mod.rs index f99527b1c6..ded55960bb 100644 --- a/compiler/tests/mutability/mod.rs +++ b/compiler/tests/mutability/mod.rs @@ -33,23 +33,6 @@ fn test_let_mut() { assert_satisfied(program); } -#[test] -fn test_cond_mut() { - let program_string = r#" - function main() { - let mut x = 100i8; - if false { - x = 1i8; - x *= 100i8; - } - console.assert(x == 100); - } - "#; - let program = parse_program(program_string).unwrap(); - - assert_satisfied(program); -} - #[test] fn test_let_mut_nested() { let program_string = include_str!("let_mut_nested.leo"); diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 5540857ce0..e85d2fb2be 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -175,9 +175,7 @@ impl Token { } b',' => return (&input[1..], Some(Token::Comma)), b'-' => { - if let (followed_int, Some(Token::Int(token))) = Self::gobble_int(&input[1..]) { - return (followed_int, Some(Token::Int(format!("-{}", token)))); - } else if let Some(input) = eat(input, "->") { + if let Some(input) = eat(input, "->") { return (input, Some(Token::Arrow)); } else if let Some(input) = eat(input, "-=") { return (input, Some(Token::MinusEq)); diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index e302920584..ad4cb531a8 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -222,7 +222,7 @@ mod tests { assert_eq!( output, r#""test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address as bool circuit const else false field for function group i128 i64 i32 i16 i8 if import in input let mut return static string test true u128 u64 u32 u16 u8 self Self console ! != && ( ) * ** **= *= + += , - -= -> . .. ... / /= : :: ; < <= = == > >= @ [ ] { { } } || & &= | |= ^ ^= ~ << <<= >> >>= >>> >>>= % %= ||= &&= ? // test - /* test */ // + /* test */ // "# ); } diff --git a/parser/tests/serialization/expected_leo_ast.json b/parser/tests/serialization/expected_leo_ast.json index 6227b135e6..ae0cb3ad55 100644 --- a/parser/tests/serialization/expected_leo_ast.json +++ b/parser/tests/serialization/expected_leo_ast.json @@ -1,14 +1,15 @@ { - "name": "leo_tree", + "name": "", "expected_input": [], "imports": [], "circuits": {}, "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}": { - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"text\\\":\\\" function main() {\\\",\\\"line\\\":1,\\\"start\\\":10,\\\"end\\\":14}\"}", + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"/home/p/aleo/leo/parser/tests/serialization/main.leo\\\"}\"}": { + "annotations": [], + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"/home/p/aleo/leo/parser/tests/serialization/main.leo\\\"}\"}", "input": [], "output": null, - "block" : { + "block": { "statements": [ { "Return": { @@ -19,59 +20,64 @@ "Implicit": [ "1", { - "text": " return 1 + 1", - "line": 2, - "start": 12, - "end": 13 + "line_start": 2, + "line_stop": 2, + "col_start": 12, + "col_stop": 13, + "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" } ] } }, - "op": "Add", "right": { "Value": { "Implicit": [ "1", { - "text": " return 1 + 1", - "line": 2, - "start": 16, - "end": 17 + "line_start": 2, + "line_stop": 2, + "col_start": 16, + "col_stop": 17, + "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" } ] } }, + "op": "Add", "span": { - "text": " return 1 + 1", - "line": 2, - "start": 12, - "end": 17 + "line_start": 2, + "line_stop": 2, + "col_start": 12, + "col_stop": 17, + "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" } } }, - "span" : { - "text": " return 1 + 1", - "line": 2, - "start": 5, - "end": 17 + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 5, + "col_stop": 17, + "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" } } } ], - "span" : { - "text": " return 1 + 1", - "line": 2, - "start": 5, - "end": 17 + "span": { + "line_start": 1, + "line_stop": 3, + "col_start": 17, + "col_stop": 2, + "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" } }, "span": { - "text": " function main() {", - "line": 1, - "start": 1, - "end": 1 + "line_start": 1, + "line_stop": 3, + "col_start": 1, + "col_stop": 2, + "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" } } - }, - "tests": {} + } } \ No newline at end of file From a6bf66f864970761a8fcae5af28bf1237da2cb4a Mon Sep 17 00:00:00 2001 From: Protryon Date: Sun, 7 Mar 2021 06:48:02 -0800 Subject: [PATCH 88/92] fix tests --- asg/src/const_value.rs | 65 ++++++--------------------------- asg/src/error/mod.rs | 4 -- ast/src/common/span.rs | 1 + ast/src/types/integer_type.rs | 5 +-- parser/src/parser/expression.rs | 23 +++++++++--- 5 files changed, 30 insertions(+), 68 deletions(-) diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index 2316604925..f093a65559 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -186,7 +186,7 @@ macro_rules! const_int_bimap { impl ConstInt { const_int_op!(raw_value, String, x, format!("{}", x)); - const_int_map!(value_negate, x, x.overflowing_neg().0); + const_int_map!(value_negate, x, x.checked_neg()?); const_int_map!(value_bit_negate, x, !x); @@ -267,61 +267,18 @@ impl ConstInt { Type::Integer(self.get_int_type()) } - fn parse_signed(int_type: &IntegerType, raw: u128) -> Option { - Some(match int_type { - IntegerType::I8 => ConstInt::I8(raw.try_into().ok()?), - IntegerType::I16 => ConstInt::I16(raw.try_into().ok()?), - IntegerType::I32 => ConstInt::I32(raw.try_into().ok()?), - IntegerType::I64 => ConstInt::I64(raw.try_into().ok()?), - IntegerType::I128 => ConstInt::I128(raw.try_into().ok()?), - _ => panic!("illegal type passed to parse_signed"), - }) - } - pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result { - let raw: u128 = value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?; Ok(match int_type { - // IntegerType::I8 => ConstInt::I8(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), - // IntegerType::I16 => ConstInt::I16(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), - // IntegerType::I32 => ConstInt::I32(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), - // IntegerType::I64 => ConstInt::I64(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), - // IntegerType::I128 => ConstInt::I128(raw.try_into().map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?), - IntegerType::U8 => ConstInt::U8( - raw.try_into() - .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, - ), - IntegerType::U16 => ConstInt::U16( - raw.try_into() - .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, - ), - IntegerType::U32 => ConstInt::U32( - raw.try_into() - .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, - ), - IntegerType::U64 => ConstInt::U64( - raw.try_into() - .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, - ), - IntegerType::U128 => ConstInt::U128( - raw.try_into() - .map_err(|_| AsgConvertError::overflowed_const_int(&value, span))?, - ), - signed_type => { - if let Some(parsed) = Self::parse_signed(signed_type, raw) { - parsed - } else if let Some(_parsed) = Self::parse_signed(signed_type, raw - 1) { - match int_type { - IntegerType::I8 => ConstInt::I8(raw as i8), - IntegerType::I16 => ConstInt::I16(raw as i16), - IntegerType::I32 => ConstInt::I32(raw as i32), - IntegerType::I64 => ConstInt::I64(raw as i64), - IntegerType::I128 => ConstInt::I128(raw as i128), - _ => panic!("illegal type passed to parse_signed"), - } - } else { - return Err(AsgConvertError::overflowed_const_int(&value, span)); - } - } + IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), }) } } diff --git a/asg/src/error/mod.rs b/asg/src/error/mod.rs index 1cb3ef346e..87040a58fa 100644 --- a/asg/src/error/mod.rs +++ b/asg/src/error/mod.rs @@ -244,10 +244,6 @@ impl AsgConvertError { Self::new_from_span(format!("failed to parse int value '{}'", value), span) } - pub fn overflowed_const_int(value: &str, span: &Span) -> Self { - Self::new_from_span(format!("const int value is overflowed for type '{}'", value), span) - } - pub fn unsigned_negation(span: &Span) -> Self { Self::new_from_span("cannot negate unsigned integer".to_string(), span) } diff --git a/ast/src/common/span.rs b/ast/src/common/span.rs index 33879b364f..1f672f9889 100644 --- a/ast/src/common/span.rs +++ b/ast/src/common/span.rs @@ -67,6 +67,7 @@ impl std::ops::Add for &Span { impl std::ops::Add for Span { type Output = Self; + #[allow(clippy::comparison_chain)] fn add(self, other: Self) -> Self { if self.line_start == other.line_stop { Span { diff --git a/ast/src/types/integer_type.rs b/ast/src/types/integer_type.rs index 2319c51769..579ca2c6c0 100644 --- a/ast/src/types/integer_type.rs +++ b/ast/src/types/integer_type.rs @@ -42,10 +42,7 @@ pub enum IntegerType { impl IntegerType { pub fn is_signed(&self) -> bool { use IntegerType::*; - match self { - I8 | I16 | I32 | I64 | I128 => true, - _ => false, - } + matches!(self, I8 | I16 | I32 | I64 | I128) } } diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 299368b5c3..257cb30852 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -365,14 +365,25 @@ impl ParserContext { } let mut inner = self.parse_access_expression()?; for op in ops.into_iter().rev() { + let operation = match op.token { + Token::Not => UnaryOperation::Not, + Token::Minus => UnaryOperation::Negate, + Token::BitNot => UnaryOperation::BitNot, + _ => unimplemented!(), + }; + // hack for const signed integer overflow issues + if matches!(operation, UnaryOperation::Negate) { + if let Expression::Value(ValueExpression::Integer(type_, value, span)) = inner { + inner = Expression::Value(ValueExpression::Integer(type_, format!("-{}", value), &op.span + &span)); + continue; + } else if let Expression::Value(ValueExpression::Implicit(value, span)) = inner { + inner = Expression::Value(ValueExpression::Implicit(format!("-{}", value), &op.span + &span)); + continue; + } + } inner = Expression::Unary(UnaryExpression { span: &op.span + inner.span(), - op: match op.token { - Token::Not => UnaryOperation::Not, - Token::Minus => UnaryOperation::Negate, - Token::BitNot => UnaryOperation::BitNot, - _ => unimplemented!(), - }, + op: operation, inner: Box::new(inner), }); } From b60affc40b8b44214f5b5dca0b984a85d4097cb8 Mon Sep 17 00:00:00 2001 From: Protryon Date: Sun, 7 Mar 2021 07:20:08 -0800 Subject: [PATCH 89/92] fix ci test --- parser/tests/serialization/expected_leo_ast.json | 16 ++++++++-------- parser/tests/serialization/json.rs | 12 ++++-------- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/parser/tests/serialization/expected_leo_ast.json b/parser/tests/serialization/expected_leo_ast.json index ae0cb3ad55..9535cdd016 100644 --- a/parser/tests/serialization/expected_leo_ast.json +++ b/parser/tests/serialization/expected_leo_ast.json @@ -4,9 +4,9 @@ "imports": [], "circuits": {}, "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"/home/p/aleo/leo/parser/tests/serialization/main.leo\\\"}\"}": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"./tests/serialization/main.leo\\\"}\"}": { "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"/home/p/aleo/leo/parser/tests/serialization/main.leo\\\"}\"}", + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"./tests/serialization/main.leo\\\"}\"}", "input": [], "output": null, "block": { @@ -24,7 +24,7 @@ "line_stop": 2, "col_start": 12, "col_stop": 13, - "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" + "path": "./tests/serialization/main.leo" } ] } @@ -38,7 +38,7 @@ "line_stop": 2, "col_start": 16, "col_stop": 17, - "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" + "path": "./tests/serialization/main.leo" } ] } @@ -49,7 +49,7 @@ "line_stop": 2, "col_start": 12, "col_stop": 17, - "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" + "path": "./tests/serialization/main.leo" } } }, @@ -58,7 +58,7 @@ "line_stop": 2, "col_start": 5, "col_stop": 17, - "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" + "path": "./tests/serialization/main.leo" } } } @@ -68,7 +68,7 @@ "line_stop": 3, "col_start": 17, "col_stop": 2, - "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" + "path": "./tests/serialization/main.leo" } }, "span": { @@ -76,7 +76,7 @@ "line_stop": 3, "col_start": 1, "col_stop": 2, - "path": "/home/p/aleo/leo/parser/tests/serialization/main.leo" + "path": "./tests/serialization/main.leo" } } } diff --git a/parser/tests/serialization/json.rs b/parser/tests/serialization/json.rs index a52634df78..cf1c01f66b 100644 --- a/parser/tests/serialization/json.rs +++ b/parser/tests/serialization/json.rs @@ -33,8 +33,7 @@ fn to_ast(program_filepath: &Path) -> Result { fn test_serialize() { // Construct an ast from the given test file. let ast = { - let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - program_filepath.push("tests/serialization/main.leo"); + let program_filepath = PathBuf::from("./tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -53,8 +52,7 @@ fn test_serialize() { fn test_deserialize() { // Load the expected ast. let expected_ast = { - let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - program_filepath.push("tests/serialization/main.leo"); + let program_filepath = PathBuf::from("./tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -70,8 +68,7 @@ fn test_deserialize() { fn test_serialize_deserialize_serialize() { // Construct an ast from the given test file. let ast = { - let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - program_filepath.push("tests/serialization/main.leo"); + let program_filepath = PathBuf::from("./tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -91,8 +88,7 @@ fn test_serialize_deserialize_serialize() { #[test] fn test_generic_parser_error() { let error_result = { - let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); - program_filepath.push("tests/serialization/parser_error.leo"); + let program_filepath = PathBuf::from("./tests/serialization/parser_error.leo"); to_ast(&program_filepath) } From 2a616eb13d0a301ed4c377e8025c5f281bbf153d Mon Sep 17 00:00:00 2001 From: Protryon Date: Sun, 7 Mar 2021 10:17:33 -0800 Subject: [PATCH 90/92] absolute path for parser tests --- parser/src/test.rs | 13 ++++++++++--- parser/tests/serialization/expected_leo_ast.json | 16 ++++++++-------- parser/tests/serialization/json.rs | 14 +++++++++----- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/parser/src/test.rs b/parser/src/test.rs index 1014d83e85..ad123ca63d 100644 --- a/parser/src/test.rs +++ b/parser/src/test.rs @@ -14,7 +14,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use std::{fs, path::Path}; +use std::{ + fs, + path::{Path, PathBuf}, +}; use crate::SyntaxError; @@ -42,7 +45,9 @@ pub fn parser_pass_tests() { let mut pass = 0; let mut fail = vec![]; let mut tests = vec![]; - find_tests("../tests/pass/parse/", &mut tests); + let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + test_dir.push("../tests/pass/parse/"); + find_tests(&test_dir, &mut tests); for (path, content) in tests.into_iter() { match crate::parse(&path, &content) { Ok(_) => { @@ -73,7 +78,9 @@ pub fn parser_fail_tests() { let mut pass = 0; let mut fail = vec![]; let mut tests = vec![]; - find_tests("../tests/fail/parse/", &mut tests); + let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + test_dir.push("../tests/fail/parse/"); + find_tests(&test_dir, &mut tests); for (path, content) in tests.into_iter() { match crate::parse(&path, &content) { Ok(_) => { diff --git a/parser/tests/serialization/expected_leo_ast.json b/parser/tests/serialization/expected_leo_ast.json index 9535cdd016..cedf6db8a0 100644 --- a/parser/tests/serialization/expected_leo_ast.json +++ b/parser/tests/serialization/expected_leo_ast.json @@ -4,9 +4,9 @@ "imports": [], "circuits": {}, "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"./tests/serialization/main.leo\\\"}\"}": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"test\\\"}\"}": { "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"./tests/serialization/main.leo\\\"}\"}", + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"test\\\"}\"}", "input": [], "output": null, "block": { @@ -24,7 +24,7 @@ "line_stop": 2, "col_start": 12, "col_stop": 13, - "path": "./tests/serialization/main.leo" + "path": "test" } ] } @@ -38,7 +38,7 @@ "line_stop": 2, "col_start": 16, "col_stop": 17, - "path": "./tests/serialization/main.leo" + "path": "test" } ] } @@ -49,7 +49,7 @@ "line_stop": 2, "col_start": 12, "col_stop": 17, - "path": "./tests/serialization/main.leo" + "path": "test" } } }, @@ -58,7 +58,7 @@ "line_stop": 2, "col_start": 5, "col_stop": 17, - "path": "./tests/serialization/main.leo" + "path": "test" } } } @@ -68,7 +68,7 @@ "line_stop": 3, "col_start": 17, "col_stop": 2, - "path": "./tests/serialization/main.leo" + "path": "test" } }, "span": { @@ -76,7 +76,7 @@ "line_stop": 3, "col_start": 1, "col_stop": 2, - "path": "./tests/serialization/main.leo" + "path": "test" } } } diff --git a/parser/tests/serialization/json.rs b/parser/tests/serialization/json.rs index cf1c01f66b..9e62f65072 100644 --- a/parser/tests/serialization/json.rs +++ b/parser/tests/serialization/json.rs @@ -25,7 +25,7 @@ fn to_ast(program_filepath: &Path) -> Result { let program_string = std::fs::read_to_string(program_filepath).expect("failed to open test"); // Parses the Leo file and constructs a leo ast. - leo_parser::parse_ast(&program_filepath.to_str().unwrap(), &program_string) + leo_parser::parse_ast("test", &program_string) } #[test] @@ -33,7 +33,8 @@ fn to_ast(program_filepath: &Path) -> Result { fn test_serialize() { // Construct an ast from the given test file. let ast = { - let program_filepath = PathBuf::from("./tests/serialization/main.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -52,7 +53,8 @@ fn test_serialize() { fn test_deserialize() { // Load the expected ast. let expected_ast = { - let program_filepath = PathBuf::from("./tests/serialization/main.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -68,7 +70,8 @@ fn test_deserialize() { fn test_serialize_deserialize_serialize() { // Construct an ast from the given test file. let ast = { - let program_filepath = PathBuf::from("./tests/serialization/main.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/main.leo"); to_ast(&program_filepath).unwrap() }; @@ -88,7 +91,8 @@ fn test_serialize_deserialize_serialize() { #[test] fn test_generic_parser_error() { let error_result = { - let program_filepath = PathBuf::from("./tests/serialization/parser_error.leo"); + let mut program_filepath = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + program_filepath.push("tests/serialization/parser_error.leo"); to_ast(&program_filepath) } From 9252534122edb68dbbfe4d0a9be6f15323d17a8e Mon Sep 17 00:00:00 2001 From: howardwu Date: Sun, 7 Mar 2021 12:31:40 -0800 Subject: [PATCH 91/92] Update README --- .resources/banner.png | Bin 29489 -> 0 bytes README.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 .resources/banner.png diff --git a/.resources/banner.png b/.resources/banner.png deleted file mode 100644 index e1f5b724e6b89e44a14f54b62d6496fbca248639..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 29489 zcmd42cT^K?8#g#~K@deLQf&x=6s1Z>dhfl7h}6)FbcBbZG)0l#I|z{$dH@kndJjDm z=_Mc}lo0X_KJUJJ&Ys;rzCC-s{c?`UU?!Q&J@?9NkrB^?K?pQ1>LHLBy}Svc%qOI)ciPajehh_kOIfji8niR6BE zSAmnvmdUKcH=frNF8s1P#JcK~S@*(JC{ypvz9Q_`|9%qtwvv4%^~nkIgAJIlgLjvg zh-TVG;-K@Wpz@~h!2?-rAnWEwDDSbQMFA4^aW7~AYWT6i2%eA?(uPD~aX3HSwVz=m zY^OiZeQ_t1Bip43GZI*;nsLHrm#dFy0|~%$076R(chd9oF$3cp8&(C*3#-`|M{RAv zyE7r!qGunfZyR4v@l_i@nK>Ta6n12La`_Qp(eT6dD;MiW=i2K(x6N6Z zyE)CHhSEi#;#V%D9shj~LtN#@B@}`VKsGPVP=|<~)32U$*s=pItrff*XttnxQ|--E ze|PPN>o@FQY#q1M`*cv_t$*)~w^@Flx)&nt%X=c^kNbO?DdoEPR;?E+ZEaZ7oDJx$ zfbd1O%MXWAJXN51VOfQb|L@;vXB#cPkG}AIU1S8(4%q^23Pb)LhD&vejn?euVkB`p z7MXqVPvH*rzsJ|l>q7aV!j{-BI`<3b=s79~zP;#>KKt2niV~x5IlDph_v1-hGwAH| z6O0q$Vpb%d{$T~dbz;2M_4B{)Y9G)QxcDL7&e1rP^;N)% zy3fw|NUZ1~_8VmeO*1oTFWL-^#af3I6&1f0A3GcD(9gZAyfIRj>xAT(ck=E)i%Lkm zOzn`ZR02vo%Iwm<@REmMEcVu6>yhC;TI)4RC3XO{7gR|2F+~U~L&I__&N$ACQbgiR z#mV_A^-Nc%@Q22iEZA%M@~PhQiYPdy-e_oh{T*?81xhP~{RAN=+%qx3Q!6*LL#-uK znY&{Uu-FmBb2H-#!qjY!8a_!pt4YQo>J%lOK>YT!e9hEm<(|0D(JB8_Z{aQkS=Co2 zdrQ6hMuUsJnJX1K=DSlq_Q$U>du{vdnOTu2s={at3O?bKiL%Pw)=>$Kk0-4j(E2`u*?p#C;lQybN#FL zJZ@=d>+7gH@p92W3kUf_^Vh{so1oxW$O=BJ2iOoC*ex6*$E+!(A(FYR&x$@(=;ac>8S}LK77Y#JHW)fO%BUk__5We+=Xk8?bTyHx>!hS6 zU-NNr&)UuO#4iz2M1ys^sOl)kkL0(#5-IKMP5y6fx4*xz%^{&$N3K zwzRF;_#1ogPpnv_)R2jM&lBl82&p={pXWoLr36CEsyRwxgLdq0J$4E?^1i4u`i?Mn zat&$O2x#VmMBsj(rw(INDWl0~a4!g~`_9RHs2Olfg2D&iG+D;wV3+K3mP@ov#3}p)wxF{D=ynJJR!9@ zDonAPJ;Nb2BWaTz6vD8vDWxY~U>#WETNs1kZn+3sDSP^(=UGfie-rcE7!tep0f7}W zl6xy$&aKy_DOL%uq-E)|?=5rPiq<2XLgEb0JS}>1y84e&2Ac~X#-8@j6R6MI#h2u@ zoh!B_Q`Bc%tsPlXFyD$CzbG8r3u`I8a6!!WtsZ75ytnw8cDx>J79p*NEq+8$S-LLm zTT%e4`NLXIk|kB+^8OI@XC`~AM%CaUuqGvR&r%v8Zrk`&k2}0t+Ly^u{e{J^kY4UMJG(owkphst+#Q3QIh@6XE(j)WyW@8YH8JFPff`0 zvDscYe>REeKS_y?j~v6TJDjxjCEjHhPbo!J)dQ|UAnU! z((oN03>22OAns|y<0z?-Cuzlh3XL0+(sR6+I7hHxn?jNE+HCiu?f{6EGB zwcfdO?&Go81c&Q~e8&496Z+Go@fN@sVo^uSHZ7tD3vt zu9mmtQ~b3OXD&TqDHywR;90?G(}@4GnKe5JUeSqZzm+Blu7scpqfz?LpO{1>T`Vj( zI!{mF@wQceV8!bO#XZ#-{ts6;9R#%%i{-4cXAg^ZSE2I-P0h1%L6c^AREy;o0wBq(bnWK-+5S}ZksFZ%b~1Hg(#uY&|!_= zx_V6Fh7U%ph=2`_=J30Xbh7x-cM>w2}`|FAZai>K^w@fx~K(a)C3L;^z|@l z2Q#KKM*6IcUnMDaEcqCK=rK%FV@x!(|Ebq7{A>RB4fGa)enJWTf-m3u-irXE$}4@p zlEWjRgb|J#F|DLUY6zF%1{+)l$>T0gk@1{9T#Bqs8C{#Okmb` z+brenvl8t0ZRW^Z8k*)R&lY-M)!D2-E~5BoA>&-wy;9Zcl>~1SsgP~cl-H){GNqlO zQd`Q|>Fnsb?rUEYl1E;5v1OF(TyF$JBm~}cnJwk-+9N&a)2;+KgyH_wsqQ*QmwSvJ zINO{57UE1WtKHWV0CXku+YMOm^3Oq6lh93-9}P6R6Y{ppxprCb+!|P3 zSjgB4pwyPugeKZ-yB2&FZICke+@Le5{L$=f-kqD~=1tGamkt!%v=BiW*K@EgR}`1+ zy$FFsj(W*r(%Q)TdI%u6gh=H;p)QW*T}&@GJE7ovWw5IoT6(yS!&95ku%nWH0hyx@ zBhMm8boJeg@AS^Z?Iex|fOcJ4dieYL;E!>!vBp{`6KGN;*O}M# z4+v6`LKkH#uS3__v(o*5f^uwu_l~$sK4C7zOvG$961`N%DJRQ5GVeW#Aw^sPKFfKV z%E`4(mzZE2znrZ;6cXmGwo%Hara@ojXs!J728-bc6aEGMhE;99!1E2yPcs)EL3A|OQQ7#{mX$je6C0`okdIwV1k38R{@ ztcpYr=Jc9!!x9hdka>QT_=K^!Ux0D z)wSQK%s6pn8p8f$i5_m z?>M7wSKP;heM|`I)OL$4P7|2O*U!YXhf^B`%9P^7gSH~xHH|C1Tp8}bP0myo{YD+3 zEou$Q5vkm>VeM@}+iOgg(8#CK_>9ud6%dQvP70H^hcrra>SghsimOJ?2d|H&tHxGc zxl{I@>;21)Hg$tX$geOZgc_Q_?!DCveCZxF z@XN4_S*6Fk_*C1TZP}UrB&X@?lyKd3=R)rB(~p&&$r1!*vb$mF+`h^{PMN*Eap_%t zqIe^Dwx8xzqOc^EUd>Z+B38oy#6fK2^k##PZ?<5z;A7p+C+LZ>72lFln9wFND@w(& z#K8!mGTX4}ewdrF^nnsjrmb2k#?#jSRbEn3MAOEz)v8RSFPG%K1q5n*D*ZXLX_p^i z!Kv+vM(ZTsz1^F+^)zsIt@kDkP{Ku_+pKx(ny&XvZ=Z#^d$;v;WXw0#yjpn-_Vt8x z#l+j3D-{mk8&+64)g!BFcOnPWIkhK~U8yCGlo?{VIT07$ewr>DQ;Ca)mgw z+YNDQ$UjxZ!1zr2VvaYf)XUEM6E&v6f)N#I7;;XfVD(RG@8l&(c3$^gj*e;BV@5{$ zh$M)x8B2MWB5eyRS)O7fMx&z*wcw?kQYHH7_v63ywEYP?VeN}d8VnJUQCX1yVf#)r-OntC^@snhwhF-C zBK^Oh5dXhw3+?A1RmPBe7QkTL!Pu4Zue_PCdOUVk7$lAGAB`1`-R@x9*_Ye>>f463 z+uf~43Ii!uU7jdq&9siq%uH(e@4Btun1$OUHyYZTUD7YejrK2mgPwFM#q^QCBKsHb ztW&(xF{&S)VYOg0$6kfJdG$jK!}9I2{^wK+3GtAloaTpuaP(Bsf?$c3)Y_wj-uU&3 z6yn-Lu)P^H!SA~n2zhh#$$I%UXFy%qmea1DTu{)7!0N=&27}9$8BY+$bcz<0W4riC zD+Ei;T-6e0C?QTr=Up=q`oJM?852h{NlCliw^6K5*z!~@Mbw3E5xZyA{7k;KSO4XU z&`tc_6|V2CvK{Z!Z_-L_?)$ggQtKES)^-KU_5u_K=@6QpY3kPJ^!CmC`hHuk1ApoX zHHK&m6d*)gW^_L$k@B-}K^4P(C!>D2x>Ret{Q?b8U)=}Ur3SHY9^g8$<-LH>nRT{o zymx+{wNMk;SZ>_NSH5S)G&$e!tm&f5?zV0T^OV zTKU~I90Nem`z;w)X4nMvrZi~#y|vxU@CBFjs+$~OiS2VeNd14RddJEtmKAB1Kr_Sk%;vk_c5#k5+g3fg zzjUmQy)RCC4IDDX1T2a9Gc~nN#rxjh3KLOl{h(J`o_>aEG~w~%2#|ZLie$I=(WDcD z9v;#M&sldT(!rx8bGkt06s#EPuS$cW74v>O&Mu<-`;nGaha2B}bL_aY6^Tv?zMHFb zMMf&DsZ}|dBUHpt=7bZ9h!7W+nT5S#%bQ7ePgnDyPn{e-Vof`r2icp{uSHg;{IT)x z7JGn+BB!-dtutZ@KMt(DnP$XGjS?aG)ihMLc{Y3@FNs(hVvV;d^`v7pqMq&N%l1kT zp|`&}pq~q~sg=w|yjy0ks|tk0+*b`Qt-%=Y&nG7$evWq0ks0-Pb(4pFTv~b*V)y3N z7BbaomaEQUUJ2G(1*7XhK%@j_Et;cSi+sop$ zWJ1yK>DH#7&=joAQ;}La@o`)KA3rU-8j@ZmEpM$Vf3H_3WNUJ{I0hA&)-Ao)?a1Nv z(n@hQ^z#d0Jwr*4z8mO0|7XE^wZ7-hhuuTWT*HIurMkPp*{jit%}3}ifnE{D%~j8U z!gw2V_xN%fu@&Ob$b`>LkB+j+pZnag|EeYQwNvTsMJh}4Ls&VAG5B|SWa0^yZ_Q zu{?{m6E!O9X_PAyM=^Rqed7#)o0#x^>Kt?O6|r1|N$RBzlHAyAu~q%S03S5D@VZ-v z4N{L`xzdMZqQ{K|pFURdf_r6m=@^zu7H{@R&6XA}Kdq3X2QSa~uX~|gYrZjDrGuKj zho9=SyHoFV!UBirC;3yIlWvuOH6}Vz(Pj4R%^PNeVHf0qyfNp}+NRVM`bG+_b4Nyt z+@SYs6I^cb+@3pnxn1AKe>OmS8SUH6bDI=9BZ86>7~jv8<(_(9?d(oTOp)3eG#}yL zco17w{)+3k?wZWS2kYL8MvXCo1hyclmg4(5%cF>Add*5>1)p1vPXD^z zuDGjU0@8W92s)R3+8%#{%4aHo@~t@qPY2q?-Q71ceO+H;j62H1?&xS=D9ILXH!oKR zyJrd9*~}}5W4tl(VG7_cN)sbn{32#%YBm{3p7*w+!_8fau(DBW*G7_8>#BmT)&1-l zPYt!?f5teLGu9RpYlvkY4DJY~x`~L!U$PEuTn5L#?4x~7VC6p@v3*YIe=8pI-}c$i z1@s$3AaNj0eF?IeFRf{Hf5{4X2A<^PfIbh&Dis*t^-p51#+l~7p^R+Ob7x#{xBDilC&k`s0*lw!18VYYqazn(f1rEV!H649dfpU{Kb8%t? zWQT#AYOrfkptfhy(o~?HRzw1wj6igz|Lee+N%(0btDg`BI6nr>9bGJS1W%HSirCqa zWI)3R-20HKqpbw~EO^I{NZT)-CFmk@(W(LZHuWw+sBz{q@9$tAdB|L}+1H!IO#xp3 z`=N#!eLDAQpdm_rj|2l5y3!$F(@TOpO0=H-7(QU@&KlF5vsC1fqrYfaIvW#!k z3toJ!-J`DcEJnnx=5tlM*Ef*F*2^*4FCbAySo$uT88E$zz`tRkDDt#AKl zG#XUfE?4-9-Sdba>#q2sdC4@Pu+Nc7GdTGGiGrfG4QuJ3WQ2q*v5L)`0 zl9EtU#Jf+I;F;6vKWc%YnZTEiV;a*V?(I!YT8zE)LSOQFOUtnes2=UvujGSf!fFx3 zfJ%->TP|FRaxaj5hlz=P8Z;KvYp>pOv;r-X7)%HA_)K;8HI_N6eaX7*J+oHW%W%ZG zkE1*m4bphB;|^L+TQlryC+e3m&ud#ReFeXa+yK*cXm0RFTT&>fqfD2n3Z94-JpgES z)MRB5G;{oof%6#?su5eD{7xU}ip5y?i2kh1lSoGH)c>t9kD41D(PD>p>t)b7xxl$6YAeJ8x%B=Z|Oj)vb zZ)DfHt`D_($nCR@pxBgKS7_(Tx3 zt#i(0upq@&p?(9R(6R!bDE~K}M0e{V%WYv0mWsxF|oHMkNnm?5Q8n;iVmu+sd=Dyl?s*-1KSZeIamTD53pZkez;r`EJ? z&f3FY^s^ax(T;e+PVhmS@u8l&P3OJC)kOiVsHE;J4jeLN=8Fr3EtW}QSFhBj zF#Sm;=F^5YfNe!x>!SI#B?^PZQ^g(Dwd(#NVT(%zC3YsdEz}Gd(4X~E_RChiDC|?8 zk+@nWD@9_E&+q6hH4;mT$FvMsReSkaN2dV05dDy57qg@QsleJBsa+b7Cjn(ys*)==5Cs6ajw2QM6Gj2Q9{EZ#qsBO zbn(g@!uQuTU)FcFWsz&T@8a{JyHrUj;V7GQx&BkKQ2E=eth^`wu=kP6$479+N{2CV zOIPe?@rb(tLQYbvFrwOdN7H%^0e%M9rq^B|XED_(*Ta-Jn1Qg_$;{!r6nr>jq|fVf zAUysNdFVe|yU)yy*7gmq{OZ;)+rhDw)N~F7PX~^{KwW~V(qVC%bnB7MFUOB;*#tFo zH1EUd1Y_g#`3mXew=my~b#s5eyNHBesF4CCQWVt`JZJ0vvhb{@VXjuYk0&5(tv02{ zGV17Jx~^IA1*zeCqf+&Skd5=r?T#o`VMOmUJ5`Aj`}-T_4){PGN|V8L$7_vOiER5D z5$;~kMA|@W#nN66aV|sYM0p}sbcj4$nBky&m+y>3Eco{Y?+%JTjPx%5fScQsu7xt= zd<}U%vj<~$>j&r!NZG7fw<2>7nr@4bkVj85IxMB3Rv2C%>b>ssh;-icpQ}a-SaQw% zx4<8MVL5~0qV()us+9o1>mIe@iyu-a9n{1V8oh8#9dx$4ht-!gwp?n=pD0ct@*y>` zBs}}t7EHAm6SuW4>c3)O$DK2l9PFck_+DMq)#0Z`kIQVuUYlZaHHWF@AL=S?uFa17&Y6Hv1WK>XXL@DV-P*BJ0$@?tFleKI&{OZ+IpqCr*wAhPM!4k ziQiWr>sEZc=D*-ysJq`_cRa{6DXqJY64U1OW|qF`TwXJV9IFzfw$uwQ-@W+buCDU8 zp~ROiWnE+3rD#`nG$NJsQ;wl_dfS;>ZdB2{{c7SX(=9s=wLSNKN=x$M+utrm`x_*{ z8us_04A2q$RmA^)QN9148qoip1|MohdD%JjG&Iz{R#|_X7#}ybLb7jfx7h>yv;Q{O zYyVL!{!cl@fQVfLB$M^(YpN+z3}B0rnwXsY2N@NmMA_cYPXfrOl>G*)AQHsn#>};? zMTKgVK&a~Yj0YYBcA(&DweM}DAF_40y+xO%rRtLL%=_M4wj9~<>}6*m-hji7Bcev`drH?~1gR>T+DtqjIIHmw4?XV~R z%8hqP$kWtVNhlbnVL?4NtB9fQr4_fWQnLpMa`OIb0vZ1sGWlN#)h?&F_DA^f{N2OC z^6i34`52TvbNu=LXDD8=7C{MU9C?XB>V$;8+-9y_TDs9W*Zu7BbV6UbB?8*l8zI}T zog6G~k|utv-1`L5s!%E_3n6ul9{0}t?Fu2$_|2p5`*m=546J@76ttP1Ccj?E07b^j z=uGD>l`Yit_}wQ1cgQ#h>tKs5JWi&}7Xf!XBeq$=V*X5`ONz6{4xAM^alh4seGWd z3|XsTQUherjg>=e{uWp4h7ULY_#F^jOuUVP-G&#|&aC;o6G&K3B}FQ8-_a(eV0=eovL;8!P%Z z%(EUrgJ3*|&-mv%Ou576%X0Z9(yJu+JkL72V@DV0>8-W2*zKJ8;$o}{p?6z zPE~o*O>5!X6E9^|Tj8(x?k$B&xg&lsJAgfwLom$r$?Pe@vMQ2P`uIpscJ=}c%`EvG zq5Z$@Qn4$sz7tL$paNNGZChV)3-Zzo_0KIjh1+t^-bE;C-ToO}oy9BA1pp5; zLXZmU9badp8uNM3C{e<-h8Yq^4#!u{%{_~}PbW_?UMb2B`*W4L{LFP`6XiSLeErN2 zA$}l^cEQwSKu+z;yWN=!r!F2D`&Q`N)$}!dV@Uq14SKAX#KtzH_dS)62<&vKr2myZ zW%#izz@F1-5T>*CgxSZ7az)Bc55l+YkfjMS05{9{wWnC^L3d`>gJw+E(%}8C0su%0 z?HB5{g|hVV>-9GkUm8<$SNgogXgG^2ARG_~VVh?2Bl&dw1wT;%s zPJ0Bzn_vp?#hE#uVZ~6uVs2C?EShnvt=>T`#eSb>(C00k2Wzx7fgp=o-8yK+pcJ|$ zE+%|xKh)5z99oz8K$ou>UF}P{DSl#KzQ)>v4MV|incbOJa?VZpHjFMlTrIyZmfQ!5 zm&JfRXFQz@r-DdD0xgXYzNrY-9U!dTnNd6Z0%QwcZnx09HnJFVe_VH6$!pXC!ae9& zw8X_2X=VSjCGnAOkaM8{7nKsXFisxv&PBJKJ_{^;GPXKqR#zuz(^bzvo+hrbY#;Am z6|q&8TOkH3SzcK>h*d1|@{gW)AYG&r2m=+(st3pB9)B3x*Va~HV79`g;e$7g)J=2! zc}gAL7{bF9rR=sP(X#7P4F~SUa$d_)c1_lTRtlc4^!FXaduKrZYdI*T#T9H+U7~qG zdas%H-(5naBo0UVb)S22ac;q4=X<6N72YU`xbMC>5=`Syn2pqL@DN&-K8gKA9J=w` z#nF@*lNjUQI}!TzXwgNOQ`EHtO1-{lwb8t>dzzRb;H!UKP>`46s(yt-`xANQOZcMQ zn1{(9^83@6r*O-m{9$?xc+5MNe_@)N!0VPPcffrBAO-s`)B*nI!U>=n2efDCnVH#a zdd+N&UhT|gXF1PsdiCl@WR#M#{f6TSs(3~GC-gBG6m89lq9V$?TfM8^*3B6&Y&MLlg5~Sjiey;tt=Dh*TUgy*1C68uP?Hw zmI;E=pN2+^U0}a0r}C9oQPn55mZ=kS?j!d%&P+65xAKV9 zm3rRpPZ0svMK0%MC`Vje%+6(rMwnl{P>@_nMsC!D;Lyw>6X|fpU1zZk?6b}1uiNVC zU9}X3?ho-XSh9|?hnzk6W$UvddjkWxNe#H>1_y{ z^MqdyAo?r9i-ms#ZU zGKuC{;#Dc1dv3Zy3r2vn*SY_wsgY0@8xh)ow$YM3fCF(Z-{s^=xl00}IOncHv@yhy zPThPUxK>ToabSq@W9KmUh{z`hdqt`To-6zk7rh|8_4Sc``9F;pB5DMf?REe4S29f% zgfzFta$jABIF02x?-2p*LYF^4{S%=LiPOX=k%h9H9BxW#F!w=dk!h{bNmxYThQHWN z=0gxnPyyz{%0fx&8fxWyCUNOrDw>agj5FAmsjp^%Q_J4@ z<72H>m8~b_M*7znqZt#+p&L4Cz~b}7F#Jzr=+Qe94MO{=5b#Lms)YP3K)YAO{h~jt zab?*-6^AsEq(M=;?7(p8mWidLdREG;wlQx|DnBLnta1V zp7Scay43xZK0!YmOv$L}@3ZOLmNGlsGZ-{H{Dyy-_YrtZd1di+X{!a71EbHEXRNjb zKHp%s*_ri?5`SixDFb)tA_!fD9A}uNkBvzzN);OuC<_>E9j}+?#5^sd^dl@w_RnSN z`IM?s@JC|LZn8YXU^-3Tnn+Apj38P`F4neX2$FPju6Zta3dWb{_CjoLP8Jl1l@WzJ z*FbR3jSGfUG$PmHI;}rV30!&bR#AYxie4-`>_9ZY^E;Z%@pTC9?X+NeK3{0TJ5ND7 z&qEJaz4G2u^W<4x15J)r%51gEp9o6ySK(Q|%%3EKx_VMz$Q=RuN-ARPhhL|2pu|6k z2>Au*Cs$c+^zdkMjlob;wxCA!E$Aq|5EIij{sM)Uu{bFV0V8_CfgsK|i21}AYxUm2 zf;O(OJ6X)VfPO)B!!rR=Vh#B%W+G7kq?4XdUm&6(~V z7{fwtg!~G__map(Fc)OJzI0#2;0vcRShzvUn=JtXZ-9D8HUwRX6+lTMb=M6$i%sF0oX|8~RJV+@4k#J)0S>c3IUMNI-kmJ)yF!5OHK;J+_ z61R~tbD(CcHjT_S`H3)$Vd*6ikYoP$813s4Ug!&7KMJWB7XfAA6K0Z}SMOpR0Qbj5 z#XUS{S^iZ)SYBw4c;5CcAk^dUNrkQ@x%k&!9r65V7mmu^6v!maS;EIQ41;O$T zCbB?C#EO27WxRj_El_;o04YTL(``X3M#e43!$4}g?6^|;G{?n&TQcS`4+#M-woBIg zNAL}EWToZFwBVvUb}KIHS5>+Lp*0uFlZwG?H88oO1N5aafZxnX{dez^9UT_1(^;jr(UBcHV@B#i- zb<+jJ@|iufSWvsa96%!?(gA1M|GrE0@CXy*=ow}qE(uI&ZFfN4+=xqK|f7KK%bmYP+@Z}LPwQ{hOt8zYdv?!0ZXASY)8raBpd z$wEsh6SOgd<6c=xY?FQxp#<&BGU9<};};7c>{#;E$($MUoCJeCB`2_k%9zWv=iO+& z0w^jGeUv4HG-m_VXWLN%1Vu9lqFOCm2Dp=FVVHrA2q6sfDoEuG+&h(>`fwcx#`1DC zGVG_ixCF>SwUz(p@ylB*zTNwS*=^q0uTlES$cZ%q#mje8T%7F{AD?}DVNP=@vFGi% zI1&#x+T?I2>5mO-zKn#bZKt_$rO@r|?1?!9g!_p0=KEZLwkk(!kxeOrR&BoCAJWw= z7_l5f1=$XN(5?Vd3#FF2o*?G2_gREFnTB-T>owu4Y8|rDo?G&7_W9aI*yyfFamq*q z@0`9{4B4p@TIw>~OeoaV1%s2tot{OD21xJ6>0fw-5fmi&YP%s#zS)>rFcdmt1X?Nr z#ajRLXoI;_eX;EF-^JUnLl_)qJZZvS@$(CS!k8UIR))TUC?EDJU^sYwf5ZP!_8?|C z#x+pV2AaK{xnWSLKf}fX%|ns(91aU$2gtf;&z!R%%P$WUY9VZ(fV)l(ko4?k5&kx( z2=f{PW0vM`o(Jk^FC_Xt*_1!I@?drb)bE=#UHZgA=xb4)MZXoQhLDqcKFtFI+^U#r zPCcVvUXrlYo$&bGtVPTH)H|bg+YJ+4K4?6sJpX_=R6ss(2F4!WLJ%f{qFQ4h2DWbWybuO;A#1i~Iu87O2 z6X)HM;K;=N&>6zA{pk3{nEd^Y7@hN_mAO-~BF&q?8Iji~&XU7Rmytj4B`K(1%hvT&6wavVo>8M4M}s&Ft)3pG zI(CkL7G7URGmI=h>%bRLrtmZksV4RC?(CKN=C+1cZFLO>45FA$l~_IX!AHn&$9=w$llv$GbA2BJzQ@7z9c3!x&mwY9P2NJV)J z7kl*GLG(OrgJj%J$@ExIy1lcVBBlY9bR04HB5mBK8XWqjK4hesZciQ8)&q?-htYMF zW&#e;W9{uP8bq_5Omix=U+eYM&30n)hA=^cwNw@QrAtpv&DoR;C<__)EV97p4~0cS zR5&6KlTo^CQRiRLRR~&}M6c8LO1n)%B%fr;`VD>9{q>Y6IN%!!V#&&SJiTZ$<-}{D zR+Bo{K9}R61_^6`(HhOlU<+PMuX|Tw^2G`%G#s>NN0j_3jMq*^);VCMKlZgrIDlT2 z3&r)3!uZ98(m)Hk2PWw0Szih3N)1}8f3%nn-5_UTMSt^ujH;s_^6hm#^e@tGZ;5U4 zj8#T#dC)VBkWXyI6VX~$DS1xhFKN#3Rg}$a=H`uF7v&L6(IRP}m{m2R=gn&nWu_}A z*5xEhcy+em8`V#rK~~k zBxN6GjFz6ef&rU(v&+yP;)bx}SSg~3QSsn+&y!OZ>MgjchKC@T$}4u~Kc$+D+#BlX zIxDG5PwW||`B;wo`Dr3OuffDODRv#luA`7EL=f7G&1$@J^2Xu))?4Zu?|7t2qx9w42>LS!J?idHoOb_AOQ)~o z`67~MBKaGPMzk!?E{}Y=d&`Q`1m`g{{Y_xZSGN-lnwS7U`<^&dy6kt|axEXRbHu4; zOG)t>Mm)J&j6x=6=PX!kvv_Xxf7 zry(9!l|Pi~Dh1U8WYF$smuROfg7t0bixGM%DyusG%mGrXn9)Y#SWTz<&W94OE{1c9 zJ4t+^B%~O9W=|w^kb#nP8j4QRukxkwxmA04`uq5hL#xN=PBsQ0=U-Fa4 z1vC8fRVX6 zzAid_$ZpK;Y50f8?A)IJ|Vdh^6T2t{RW#-+nVS>i81OUd#k-{~!7*SQAv21^&0qqi5`mw5{q)plo( zK$k*~X-{Cc3to;1SBMPeSfnOA-=^5hmv4VF%ytnVL7tNhZBs+)+2H3Bly+LPFA4@i zwxN^&fBk=Cju(!+G=O_7;dPQ6skMS_lvME1GpOX)S-NYRXK7;r3B&Quf`j{*-^Px_ zOE8iB{vlC!*7COpqD3(kb>13Z--i59LE-sapPJP=cqD|3Z%bzZ-?DFK){?dx6W$T} z!g&R*yCOY{44S=&(!x~^V4<;~2h|8Z0s5RYfS%_^;De|lfxIAd5DHEttmlqVZ{EWt za30VcGm@WH`wK2<3!j_x)WTqsqnp#X^o*kmB*yHu??w7SXz=5bY(bJmyGkv}!w|a@ z{F}Txc3v_k$kuKDlbM$O?CBxg0tXeq@B80Vt)u}c&Ij8ts?HrH{ys@pw5g8<;;-1- zm(&Ls@g_i&oBA5@r{kT$;LTf+zV>N9EqsvzD+~DX#KVpVT&{2A>3aWxRvZV>f(hB3 zW8Z~T((7@A-`slJjqfe43kQ$7_^k|q#}hfYT#`jOIZi7!2|aYNjuB^|5ELctB&#U7 zZ6P-rRXzPpNi6S&yjUizJ5oV*vF+y`#PWs{%Il4}u%ru|vvC*%ere&j?|(R+7JhPDY+u^MwxtBF=lmYmHD%_DRJxb zDJ`86X))Ht;;?q9bCU!DO8EB2(EJr7L_*=k2r3~SXNJQ4Mg$KiB8_ZH*-k>rNPxw) z0Z{bTrlacfZB@1^)YYn`>pSFO4EpHRw72IeIC0OQ`Athb@_UK&ncw3Dtq5owJE0eB7ez}I)x(bKc|7_R_w!{|GB)?#$531d)N2q zBxjHd&c(t~tZee753hc*OuMq0uP(!tbm+om7u$XkU_E*#>5xqmGloB)2WR=;Z(DrG zdF4{&<|!p5C55bXp9K6CI(x3ipJ?y;4W-&7>fVQS3Djsk^Yg^gE-H26^j6vgFhdzP z2%dFb(OtpQUu?^P!}+4}9$3!XHFOhdhq_Q}TqOA83QN1r`!xcDFTtpfC98;N@}m=! zo5Y#*J?#X#v#a;9zJw=L&u}&>Z{6PGf9&JWhZwYIVv9TsNgAv(Wq@|(=iu58b=cSn zexjoSkSx^PK35WUnMq7}5Sp+kEeKym8uPWqQLiQ#UL*uBWy-(R@E1baJX9o&Z7o_1 zSwP}j34parrVgm#;Nc(o%DuPBGtJMFmm z9f9xuT|x2!_4tfl^6?#i-wP{T(*N--{h^6KxgoTox0r~t>L5V&+x!zU`o%G?P)7@f zeF1SFKgqRxJd!q@0WK|d6!M1=cy<*RhmTw(J{h@BfHZmR_9q2zcCj;bIqvf>U1D@%$hd(G$!O(t@9Q3EbQ!RewOx z9rEnV?*e}qGTYL2$|Tn^e$5qPVj~2ao>Y4#GmF4`m3e%&nzWr_^)h*2-{PTBBA*HspFAss$h;2MyiVn=sx-YQ5gkoJv^L3#o;Q0 zgNL$qF#`DY+j4<05?jpx%hdc4ajEQ#5ikWBM-}sZ_vn(+eO^>PTQMRqdM!bcW4zA> zr#JkmMHcY`lu_@Hk8i+n@rAEAsonYzSFqs@DkCQk?)Zv7MKbi04)E?#fM zpEB*e4*6B$G7-J|JfN7CHGTV$ADa6$5wY(6ZJMsV@8bampSl*s)3BMhmE@Oy*mu4Np%c%!VyA5RDs-nMa>7{tQ4izdHdJ0YddCBWQn;){0X zqR=A{pAAmShfeYizdt);Dz|M~m^$jTSW+gHOPN?7{b{QmPk>7v z0PWw3LnQ8Ams}p&$-DtHT3nRQ+2Ki$$U|uTYzw}34sY&wvm_|Ta@&V`EKHCxge$HC zRWPjO&pTdRlx2yBOB|O=N52*|zIxT+Xo{@42KD=Z&1-k^WOjp*qzz z!ka0s$SNmI;)|QX%;!`%d~;zWo@-|`yS4=RL+jZJQJwe9c5xqa0;!<4mRj0vDorIwZq&m_5 zCgY3o;r{7cqc(3(i*hn!VE_ALpA(d$;fqM^yl9=sV;jy!^q>-=`65YLpr5ybOuy{DCJPA*c8+K3wq{4rZW7a^_*rXC1#&mH z0*d|fm&X(a+5}ygPK`zY{WJI3m&nEh zEdpD<_~zInL=FKIQONSGRBwhG4iOzy+Uqwi;O+%szNQC$0ajS0SW?cvFZ;DXg=GBf zKO>jT*sJed4MRZ%bHXtfSJ%S8shDM2d%GFKdhrH*>xP5ylcr7a49npnL5ASC_Wo@+)YLaE5v`;0ofBPs~h1#Hunwn6tTL!G1} zqEmhsX(G+;S6f@jpgbmP>)t*vs5?@N1tCzs) zX=Rw5vZ`BOlIJ!{W+Kw)Q(7Yd||$J1EA?qx&W8{lJn9R8Dgl0_j;;P1$)LzG8zUl^grzE{#g?{dJJHrXG$0 z58ep<7dd*naq*ZJtwX?MW8hl~6S^h6#&8+!8GX_z_=FlhmhT-Rx7dL<(eO>s?veg> zjB4SUtyNy7zgBo?M>{&n&lL!mmB`9Ktq$NQCOCg`GAv{_yNCxa9P(J+(Dj7^jW3t( z_;**jo;sa5F&*1#b!{MEh_jzO*}BX-w=Kt{vc?@b8l+|o&E8FsyZe)6K@W(Rv6=~Y zMC4-X1yivV8&{GG7#+E~hUj37mHBv0N{^+sMz7+LNO7Pb6lAClE4k;lst@9LRTFTZ}H;xo@2n^NG=1R7J;&hH98MdLCu3M-9Uy>J<#XC52^T1Wk* zm0stqLLsqr%Fz_pd@TC+z531SRS<}rPMIF1aWlVZacb6Wsz{5;72&3)UP0!V&U&WJ zS2&M3@+)1Be@;8qAbX-H(1=UmiQVE#=#}{oi$ekT%(Js`O4)_`AnE7X)-AN<5S*tw zl@%?3Q_$d}Rt?yJ2!QXePg-~p!;5|tXVdHab>5J$?kC~5=V6FQuT{m8dnbB_Yp>Y| zhKeEwE^;@)ZDJMT3^JCla@j9bumu{(|IX18K`RQrbJz_Ywx&Jbr=F%3I`QPq#d4`k zZn=l1jcS|i^^WUa31WX9WXBkY8AkSX(en2}qzE-T8v|nm&yc^!@TDqbS4>X^>mLGI z`Q8Y%HK2tBeSqQdwfK243}_~_&3QAy_wrB(^{Ywf1BtmoU)A6r00adbWkgr1qGn-gVbah{Cp2?$$ z?1r=VKdOTU;*SWF4J-89)It*lo+J5$L%+l#PAY&wB$LWCTI1elHiAO#nh5)eyIjt^ z_SpO9Wh~`rk&H|aV}&t|UJcuO^}mOm`0vLXLsSCme+I!A<@71c$QT9>zCslJONO*p zs}qRbz66mk-rdiQHYMQ3JopD#bM9}dq|~^mBY{Rx6gc$+XcGhNhP@1>uDKAn6Az3= z5t)lfi&)3zr04W=XU-g5EVGE9EoANc=BCTo!*}xBr1%*U z|9+&PxwW-PB6B|X(xpq6?06n}Bg!iBR^8n!Ps@6tq8i!w8%mKL84Qd=MUjnC66oM~ zJa}H1WYBP#6Oh;X&!>98#Eg0B!4BJ!k(1ziq9M;YThF2**YEy1LNbq|ujB6oUez23 zm#zQ^hw!C5Wn`3p5;ECQW8kuj!@gWzeK1Pl^0im07=c22?*!d_oeY8_Ipe`n+&o;& zY~?dW9@P~6#N`dXs?SRVH&cDqcUbow(>{`K#?lu*rh(<2K4qWzA6e-(goXphRCzaA zt9+>~yDxnbQBdS<(>PejaN%%OO1if;Yi0nWh&)~4v_=!mUV z<39G~3`@RgnOkO^85y<1r50soAH9rOdO%hRB%A-mUwm*?!p!qFA7u|x!BG9!4&O{K z{iC=q{aoZf`DZYQJ@`n&FfZKC)9}9E)7)ay^!#+|-txYnAiH&Qk$Fo%o@%<;W_$Cs zzud5`$K_TZbGMY*{gV$g-e3X%tEMIKiD;lbLEw#NJ`GCwxaj)FRu`JTO}QF*3sLlA z)|Am|&9+oMOuWb{G%@?E8}kW}aIjM{?RzvXS8KI7G$?JKFYn9FueZS-xS7h!$ZmJE zu5cV`%id;xaRZjnz`cXMT;czv&7Om45_w%EtIw~C%lB^~;Qhcle0$!$z5niL*a47l zF3$L7_#KunW$WBRq9WGpNZe!%A3?KX7kjyK`A?(;V$-PN6bs$h1(9=U(MQNV9*G~5 zTUV+Wjw=*j{YbO}#lXigpVf|=&*PY|dPrT-0Le0+7 z{Oo9d&HX@Xv+vuEh_1xop;2}zr_5QMlW%5Sem;1Q~XqwAgtd;}&+%ru-c zXYB2G|Ll#rvLkc2a5mwS=ci7{P(DG|aU;n2kF1 z(4TJ5?m@#mMY%aAo77*9-KjOVTl%Yfl0CEYjVN0^Sx&hWo3lKEa%PeE32)76A9P@w zXgXTKpVn(KsTg;~bYgLkE#Ydp2QY@H^Gci8xFS)Z6+IvtBkvIebIYapQ^++kj!9ao zQAcT6&JUG5RO75v-8H*#vgO1XqD17pR8IyH8+bovHJzZDB8tC~J~5XW_`|^=u@^BB&lLTob8g5|TIQN9v4N37+4%Wr_cbFEI32sY;U>?+o*6`` z3YCZ5jU3Lw?uzBmI4IXnnfVg2%Wos`>%^8Fqn|!Sk$~i&sEV(+phHtKeu_^SC36TqF1g4 zkXn9dOclhX#5({21TGq;1|_3?Py;M#o6lYb2Z~=S|4CKlbTxPx?;i$RaJ9!Sox<6cV9+szp92?KqP}D~&X))t^Y_~$ z=U#?CK{S+esrbo$V@>-T05jzp{MPKAce#0cw79D*-RwDCnaTo? zGqb>+DHy7=kGv2dj@Hd`pnzc)j~xO1l+du4;r%Q>`x_lJJ;2VOUB$iBqwaSXj4$t4 z?Nm1YYxwh>)|VYGkONQ3MCOZ)EB!K--Vt_;a~PY4=mm517_Le` zXd%nk`bm8z;%MmbZoh2_y2$373Fp4&0ivd{%HLNk`Af`zlF`i$~2oxML+!*-Sb-6krUi}>! ztzxqUZ=ighcN}V~G&#|e1j0lfs(CH*nXf+?@R^HJdW3pIsDnDEKg|qS`U6511AA=5D4yqP%|DWi6O;lp`&U~@EuB|;%DL{! z+^dy~2?Sa~QT@c5J3W_vX4|r{Q7bpJrs$r7@OVm)HpOaDs_WTk+JVtl(}e>B_q022 zgZpN&6hf!Tre-SYCn!|!VZ1|Zn)X)7l)`(WJ}R7Z2UL<{cwUN)NK2u#U_UhE0l{BqY? zE2Awcuc!F)E`RbezwTF`c`Vw!Ck}4F_4m+P-4xKh!z^dNsB9$82(cCQ{;ZlSxng!I zL3q>n{-{g=H^JLbH$bHDo;tq2ad|-g9>59}b^#leadbF*w$z z8R`vKpfh6_)4=)<>&(7gnKl$n{Is^z(P2auA*L-Yn3jQk;^+Lp5pc0i&6D!Ixg9_D zi$<3*eFLMZBF6A)pE_h<;7>pBIN6ET*%b5f+PE@VAuWsma5GwKllIzh$4Od-Q^qC*E^3e zqmHeVcq%1XV?Ed-LXEy>ke5%8Hn*R}w7w9_E1@;29TMG=JB4D5v+m;Q&hOm8f8nd~ zabVWQ0z10rQ%_Jg&%tKj#w^`5p0OObgy-=Od5qYA?;a@+H1uP{uiSF62S4yy|F5#+cCF)eXPb2>|?6?r>c{Y1;s)5Z7RS3=5v z*H+X{HSivf1rWv+AN?fy>bg}A`t-uuQM=o#-p5H@j^63Xbh-37xQM{6N~WeSkPB0TfSC^Z)p%$`UW+EOovJfb zUh>3w4b_@lyLcrtRe_I9BPGW&WpPx7R#QIn#dUHm&m)-JMstgZc2KbP^%P0#sF}`e zLEMyxp975wn^yR9o4ax0PRvhDL}mcR3a7zQ;i6wzOJkkC`OLz%I^l0$4ehYcl~$i5 zJF(DYN)O1X#ZFU;=SmC)Z27I7qY*o$)O6R{ zNg7A(?_-ek3O>XT2S&@(o<265Qy?T#h`SrBRRI4A?+V$Hu2fOrtnd%A%Z1L|KC-@L z=n?!&hjx_`wALY!RJ%J)qZFkNeK;#VB=L#e_82iIw*?hk1pT|9DCNCF_a+<}?tP?p zk`d;Mg~-cY!N}y;2~)2F2zd!I{rqPU$6vBK+GGUW(-kvU;dBuBv@xCW5X-K-3avvY zfZcFK;b;x7H8!MaH-4kxNNtWlbla~;0~`U=4Q>*&tsZY;80!Z{}t&H8rhQ8xxW2V7_Du<=7XJPHE)Z1yhKB@_<# zx0w<5*wK)`)0TZDK_F&hVYVdH6Ztr}qvVfY1-Y4nXFC>IGkpH`JN?k#yN#0c&L1Rh zm5$D>bofFMiU*R8qq;;3L~_qD=A&c<2@9>`Yud&9{8hA2%(0N=0}AE*9NVttg&Sz& zyt_H_Pg*v;=+DwGd2}s#mL%J4og!-yelqYmUR6CWq<^SzfsgqTTS^QY1Xu##Ls;QxONUW{%NLl|PK5$?w1!cT| z6GvbKH$WrE$k*L*D$d`K)URaokGt>=u=RKeHJHp*m#0q!wy{g@+E{d3i?}tWo2a%! z>+LRoIF4qhI}^uLAB}98_u6zZ@CQ((RCfB^%J}}QU??HPHYfvxzX41j)(ozK6BaYU z4kt~=X_-+I?enlElBvaeOsoK3-eQokxBS|CW!CgJHFwY_?|z1RUP*UXaIb3yv`Aw$ zTJ1ANho71SPCzIH#}^DxsFF|BJiRwld(oI+3jZA(0dRYWU<@k6O%QHdDo2(iQpAr1 zEptY_OmL~x9?xDa0o{{>?4eGe0AU+Ko~`42Xacev=Xg^ysVj7Xp*t=Axu z@FKUGxWd?Rq|LV_Qnt-E%TRGIKmi*7-559&V7+BN9_3?~qzq^@XeLK<(+wJtU5X=- zp9Q~3z1=8j8-Gl7?FHM>qfj}cXg%xpq*qP4iS}LYV(%g9W=0d#wLGrxVdyuYF@3J^ z>X^||>e9D$&_}*!RYJUc?Y@u_@vC$CWvEy)9-w_Z>ufzTzd%pQ|3o$dDg)a|#pFU` zXS@X7sN!mH1^LzoCiTG8B^jdw)5xl&l~1=`7Bt97%=f4;I@#5$ZcM71ULOqW22FEe zYkms~C>xK4_@Ohxly%#qBsl^jd9I?7n&hfuD6wl~sET9EhQGL<^R5YvY!Z8!`Dgzs zN7b$$-*Cu`u_wX7!6D-HtD_A`Yg^0FT*OL(-N)`R>G#1Yau7o^2D-=UgbOt6n9Gl9 zs2;?$Jcy{?B)Mr5hlwv< z{BU0U3sro(T%LAb)Q7~I++Y-(emvRH!FEg2amViN>lCK2jXYE73k!L0$Z6@G^`!!K z_eSR#nw#3RsJXd5HtrI*?k~)A-9~m>IeuJ~K~#O1Y*iQPt1A66-$bi z#jqKz1@095>D>N}T;#gK4({_@3azqTj+%VnZ2h2|;pFyag?Uu1oauJW1?*HwR6Uoq z1t7~QnmP@sNsl|7DaTm2+(O4=4jKM2CE!s?It#G7h%O5Q6yDz)`G9oxaZ$?LJvN9b zhhw&!fX)%e)8jsDVHKZ4@`8@H7XpoIA54;_Kb1?3hF~z9~t%v_k;hsjM>F z*_{Q^ujULtPgq|!bw5X)KytZtIUwXMSc}}xCs=)8tiVTjF%N@jH#h74Pg6 zk`goTE6WT8r+|!IoJW&`eW1kW`o*&G)VnUfbEPVdGfmbW;dj>=Fu9P=1o23V8_U#q za0$k$-d+LUsFbw$`TgOi2gNj>>-E7`P9pPbCVX0XmU{H-ZphlN+@Na(W5~_C_0GnD z9P)p{nIH{bi?K}QG+pGXHjn9DV(3W-(=h+*Z9r-VZv;DBZ_U{~(hNo%r_^vm72 z?VfgnpC*(ST^O>y0dG|@VAhV3~O4`o(Q9j<5_2<=jU4O_lI@j%VlMeVZ zKip-%GKJZOsyzM_((N=`&#!OYOr%{&wL7z0MIT2%Ehx9SaS9?7MfUhteWRnHD^OBb?n( zFm%LtjYa=uQ9A=f)A`3-_dN9a!QoNE^k>K54}5)x@#wRgTs*x4i#@DWmu9R*;y^6$ zga-Tq)Q&45swEm!;l8>ET0KeCLZ@NhK-E&%zFHgpyYP$Xdv!Xh(o0E*UG!ZO2DcB8 zNwh|mNL7!4#Z)Gt_aAn$ZwCd=+W@L)5fD^wqxcq;9{_}lG(;vqICl`ZR!+n1Z-)Wk zqf6qg#@BnS&J`p3N`M%0j7F$DKwhylJjHZ`R0K{zc=|UDzSu1AVP8W+A87tx-lkws z>66=)!{LXGM>O6%c_DCIOsCsKRk_e^waiZEB}^n2YyD*2ouBY!z70s8T<{SKKGxss zh(Gj(u@42-YHxN)=`vH7E{ zV2!Jo4Q`8b6uC+03WmE=1F;{KneBGo%hZ3t00H|L}d z8rN<4-tk)?ZGVj&jQ)0qX|Aqo>zoh-9F3GD*(clL?=OlJn4v_Z$vT>%rAFNHviI}l z`ZMC_Bnm7cqkdv4v9?shv(fELEvJFiS%Nz|k6(Q1IGwmcqMdfGn z8&5V{whdBDW!BA?QKV^kq8uHu%Ifv#ywBHB95-$O$A=BoMQdgS#87g;(-?tK8>IPe z))1SHCGH#x89(7Uwd-bRn{RnZ*M&Z1?^J!)Le)U90(1{_jgIP|#+aToOef_b|=~F<3^(uY1vOG(FBC?}9ey(RlwGHBlS3v-rnt{vmYUR`90iUNu{u-+DZMiU3rhxtF12a_F3n z8gK1d8l_vj*fi#m*q)om&>0;6v%It9=xM2V$?PvBbQgnDFp&?c+WT!-jFd}eGRT=& zED5g-SAU^*7)-<6x{Z_nIfCy`AnUG9=#%D#m>PuWIzQw5C}t3C#{c@4KQoOK-o*Pa zq!40uTDOh)moxcoX&v#q_bYs0cf;(lA}1LGb6}V>*Z8Zp^>Zn7Y2H&TN^(7xTy#`z zd+c{V0&cK?4d)M)ODs(Zxp{u?&0em)-L(i^Tl$|7_|iaC6LqKbBxE&{KMuA&q!vt? zGj;KO_VusD>yEv5L;gf{oZnQF+v=j?cXsg2wZ@B~vPI`Z>cZn;4~MrAi$`}!(XVd) z^Iq>mQ1JMp&k z#w+&1=-(rzpP5Oz2m7`W!*Xrfp? - +

The Leo Programming Language

From a4f2101aaf967baffcb6532d165079cc1d739fcd Mon Sep 17 00:00:00 2001 From: Protryon Date: Mon, 8 Mar 2021 14:45:38 -0800 Subject: [PATCH 92/92] remove if from ternary expression --- asg/tests/pass/address/ternary.leo | 2 +- asg/tests/pass/circuits/pedersen_mock.leo | 2 +- asg/tests/pass/field/ternary.leo | 2 +- asg/tests/pass/group/ternary.leo | 2 +- asg/tests/pass/integers/i128/ternary.leo | 2 +- asg/tests/pass/integers/i16/ternary.leo | 2 +- asg/tests/pass/integers/i32/ternary.leo | 2 +- asg/tests/pass/integers/i64/ternary.leo | 2 +- asg/tests/pass/integers/i8/ternary.leo | 2 +- asg/tests/pass/integers/u128/ternary.leo | 2 +- asg/tests/pass/integers/u16/ternary.leo | 2 +- asg/tests/pass/integers/u32/ternary.leo | 2 +- asg/tests/pass/integers/u64/ternary.leo | 2 +- asg/tests/pass/integers/u8/ternary.leo | 2 +- asg/tests/pass/statements/conditional/for_loop.leo | 2 +- asg/tests/pass/statements/ternary_basic.leo | 2 +- compiler/tests/address/ternary.leo | 2 +- compiler/tests/circuits/pedersen_mock.leo | 2 +- compiler/tests/field/ternary.leo | 2 +- compiler/tests/group/ternary.leo | 2 +- compiler/tests/integers/i128/ternary.leo | 2 +- compiler/tests/integers/i16/ternary.leo | 2 +- compiler/tests/integers/i32/ternary.leo | 2 +- compiler/tests/integers/i64/ternary.leo | 2 +- compiler/tests/integers/i8/ternary.leo | 2 +- compiler/tests/integers/u128/ternary.leo | 2 +- compiler/tests/integers/u16/ternary.leo | 2 +- compiler/tests/integers/u32/ternary.leo | 2 +- compiler/tests/integers/u64/ternary.leo | 2 +- compiler/tests/integers/u8/ternary.leo | 2 +- compiler/tests/statements/conditional/for_loop.leo | 2 +- compiler/tests/statements/ternary_basic.leo | 2 +- parser/src/parser/expression.rs | 6 ------ tests/pass/parse/address/ternary.leo | 2 +- tests/pass/parse/circuits/pedersen_mock.leo | 2 +- tests/pass/parse/field/ternary.leo | 2 +- tests/pass/parse/group/ternary.leo | 2 +- tests/pass/parse/integers/i128/ternary.leo | 2 +- tests/pass/parse/integers/i16/ternary.leo | 2 +- tests/pass/parse/integers/i32/ternary.leo | 2 +- tests/pass/parse/integers/i64/ternary.leo | 2 +- tests/pass/parse/integers/i8/ternary.leo | 2 +- tests/pass/parse/integers/u128/ternary.leo | 2 +- tests/pass/parse/integers/u16/ternary.leo | 2 +- tests/pass/parse/integers/u32/ternary.leo | 2 +- tests/pass/parse/integers/u64/ternary.leo | 2 +- tests/pass/parse/integers/u8/ternary.leo | 2 +- tests/pass/parse/statements/for_loop.leo | 2 +- tests/pass/parse/statements/ternary_basic.leo | 2 +- 49 files changed, 48 insertions(+), 54 deletions(-) diff --git a/asg/tests/pass/address/ternary.leo b/asg/tests/pass/address/ternary.leo index 29ecccb918..bdd88b9d92 100644 --- a/asg/tests/pass/address/ternary.leo +++ b/asg/tests/pass/address/ternary.leo @@ -2,7 +2,7 @@ function main(s: bool, c: address) { let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); - let r = if s? a: b; + let r = s? a: b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/pedersen_mock.leo b/asg/tests/pass/circuits/pedersen_mock.leo index 0b42c64a6e..559ebb7614 100644 --- a/asg/tests/pass/circuits/pedersen_mock.leo +++ b/asg/tests/pass/circuits/pedersen_mock.leo @@ -8,7 +8,7 @@ circuit PedersenHash { function hash(self, bits: [bool; 512]) -> u32 { let mut digest: u32 = 0; for i in 0..512 { - let base = if bits[i] ? self.parameters[i] : 0u32; + let base = bits[i] ? self.parameters[i] : 0u32; digest += base; } return digest diff --git a/asg/tests/pass/field/ternary.leo b/asg/tests/pass/field/ternary.leo index 49cd6a4e62..f193ad82a3 100644 --- a/asg/tests/pass/field/ternary.leo +++ b/asg/tests/pass/field/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: field, b: field, c: field) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/group/ternary.leo b/asg/tests/pass/group/ternary.leo index b213bb1419..fb69b74521 100644 --- a/asg/tests/pass/group/ternary.leo +++ b/asg/tests/pass/group/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: group, b: group, c: group) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i128/ternary.leo b/asg/tests/pass/integers/i128/ternary.leo index 5c2f199499..a923c428e6 100644 --- a/asg/tests/pass/integers/i128/ternary.leo +++ b/asg/tests/pass/integers/i128/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i128, b: i128, c: i128) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i16/ternary.leo b/asg/tests/pass/integers/i16/ternary.leo index ccf29bfd50..4586b87bb4 100644 --- a/asg/tests/pass/integers/i16/ternary.leo +++ b/asg/tests/pass/integers/i16/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i16, b: i16, c: i16) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i32/ternary.leo b/asg/tests/pass/integers/i32/ternary.leo index 3066547ae3..7927c2998b 100644 --- a/asg/tests/pass/integers/i32/ternary.leo +++ b/asg/tests/pass/integers/i32/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i32, b: i32, c: i32) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i64/ternary.leo b/asg/tests/pass/integers/i64/ternary.leo index 811c759bdf..1a2d03a77f 100644 --- a/asg/tests/pass/integers/i64/ternary.leo +++ b/asg/tests/pass/integers/i64/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i64, b: i64, c: i64) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i8/ternary.leo b/asg/tests/pass/integers/i8/ternary.leo index de797c6e3b..e1ec1943c9 100644 --- a/asg/tests/pass/integers/i8/ternary.leo +++ b/asg/tests/pass/integers/i8/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i8, b: i8, c: i8) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u128/ternary.leo b/asg/tests/pass/integers/u128/ternary.leo index 48299fac66..22e2e67058 100644 --- a/asg/tests/pass/integers/u128/ternary.leo +++ b/asg/tests/pass/integers/u128/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u128, b: u128, c: u128) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u16/ternary.leo b/asg/tests/pass/integers/u16/ternary.leo index 2e2752a130..11d836570d 100644 --- a/asg/tests/pass/integers/u16/ternary.leo +++ b/asg/tests/pass/integers/u16/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u16, b: u16, c: u16) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u32/ternary.leo b/asg/tests/pass/integers/u32/ternary.leo index fde04ac4b8..3c96a7236c 100644 --- a/asg/tests/pass/integers/u32/ternary.leo +++ b/asg/tests/pass/integers/u32/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u32, b: u32, c: u32) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u64/ternary.leo b/asg/tests/pass/integers/u64/ternary.leo index 315fd7400b..4c4ddd8e0c 100644 --- a/asg/tests/pass/integers/u64/ternary.leo +++ b/asg/tests/pass/integers/u64/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u64, b: u64, c: u64) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u8/ternary.leo b/asg/tests/pass/integers/u8/ternary.leo index ce868a5ec9..1b436aa054 100644 --- a/asg/tests/pass/integers/u8/ternary.leo +++ b/asg/tests/pass/integers/u8/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u8, b: u8, c: u8) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/statements/conditional/for_loop.leo b/asg/tests/pass/statements/conditional/for_loop.leo index 060d27d965..2dca076858 100644 --- a/asg/tests/pass/statements/conditional/for_loop.leo +++ b/asg/tests/pass/statements/conditional/for_loop.leo @@ -7,7 +7,7 @@ function main(a: bool) { } } - let r: u32 = if a ? 6 : 0; + let r: u32 = a ? 6 : 0; console.assert(r == b); } diff --git a/asg/tests/pass/statements/ternary_basic.leo b/asg/tests/pass/statements/ternary_basic.leo index 1f9c1f65a2..675b681fa9 100644 --- a/asg/tests/pass/statements/ternary_basic.leo +++ b/asg/tests/pass/statements/ternary_basic.leo @@ -1,5 +1,5 @@ function main(a: bool, b: bool) { - let c = if a ? true : false; + let c = a ? true : false; let d = c == b; } \ No newline at end of file diff --git a/compiler/tests/address/ternary.leo b/compiler/tests/address/ternary.leo index 29ecccb918..bdd88b9d92 100644 --- a/compiler/tests/address/ternary.leo +++ b/compiler/tests/address/ternary.leo @@ -2,7 +2,7 @@ function main(s: bool, c: address) { let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); - let r = if s? a: b; + let r = s? a: b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/circuits/pedersen_mock.leo b/compiler/tests/circuits/pedersen_mock.leo index 0b42c64a6e..559ebb7614 100644 --- a/compiler/tests/circuits/pedersen_mock.leo +++ b/compiler/tests/circuits/pedersen_mock.leo @@ -8,7 +8,7 @@ circuit PedersenHash { function hash(self, bits: [bool; 512]) -> u32 { let mut digest: u32 = 0; for i in 0..512 { - let base = if bits[i] ? self.parameters[i] : 0u32; + let base = bits[i] ? self.parameters[i] : 0u32; digest += base; } return digest diff --git a/compiler/tests/field/ternary.leo b/compiler/tests/field/ternary.leo index 49cd6a4e62..f193ad82a3 100644 --- a/compiler/tests/field/ternary.leo +++ b/compiler/tests/field/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: field, b: field, c: field) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/group/ternary.leo b/compiler/tests/group/ternary.leo index b213bb1419..fb69b74521 100644 --- a/compiler/tests/group/ternary.leo +++ b/compiler/tests/group/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: group, b: group, c: group) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/ternary.leo b/compiler/tests/integers/i128/ternary.leo index 5c2f199499..a923c428e6 100644 --- a/compiler/tests/integers/i128/ternary.leo +++ b/compiler/tests/integers/i128/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i128, b: i128, c: i128) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/ternary.leo b/compiler/tests/integers/i16/ternary.leo index ccf29bfd50..4586b87bb4 100644 --- a/compiler/tests/integers/i16/ternary.leo +++ b/compiler/tests/integers/i16/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i16, b: i16, c: i16) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/ternary.leo b/compiler/tests/integers/i32/ternary.leo index 3066547ae3..7927c2998b 100644 --- a/compiler/tests/integers/i32/ternary.leo +++ b/compiler/tests/integers/i32/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i32, b: i32, c: i32) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/ternary.leo b/compiler/tests/integers/i64/ternary.leo index 811c759bdf..1a2d03a77f 100644 --- a/compiler/tests/integers/i64/ternary.leo +++ b/compiler/tests/integers/i64/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i64, b: i64, c: i64) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/ternary.leo b/compiler/tests/integers/i8/ternary.leo index de797c6e3b..e1ec1943c9 100644 --- a/compiler/tests/integers/i8/ternary.leo +++ b/compiler/tests/integers/i8/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i8, b: i8, c: i8) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u128/ternary.leo b/compiler/tests/integers/u128/ternary.leo index 48299fac66..22e2e67058 100644 --- a/compiler/tests/integers/u128/ternary.leo +++ b/compiler/tests/integers/u128/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u128, b: u128, c: u128) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u16/ternary.leo b/compiler/tests/integers/u16/ternary.leo index 2e2752a130..11d836570d 100644 --- a/compiler/tests/integers/u16/ternary.leo +++ b/compiler/tests/integers/u16/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u16, b: u16, c: u16) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u32/ternary.leo b/compiler/tests/integers/u32/ternary.leo index fde04ac4b8..3c96a7236c 100644 --- a/compiler/tests/integers/u32/ternary.leo +++ b/compiler/tests/integers/u32/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u32, b: u32, c: u32) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u64/ternary.leo b/compiler/tests/integers/u64/ternary.leo index 315fd7400b..4c4ddd8e0c 100644 --- a/compiler/tests/integers/u64/ternary.leo +++ b/compiler/tests/integers/u64/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u64, b: u64, c: u64) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u8/ternary.leo b/compiler/tests/integers/u8/ternary.leo index ce868a5ec9..1b436aa054 100644 --- a/compiler/tests/integers/u8/ternary.leo +++ b/compiler/tests/integers/u8/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u8, b: u8, c: u8) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/statements/conditional/for_loop.leo b/compiler/tests/statements/conditional/for_loop.leo index 060d27d965..2dca076858 100644 --- a/compiler/tests/statements/conditional/for_loop.leo +++ b/compiler/tests/statements/conditional/for_loop.leo @@ -7,7 +7,7 @@ function main(a: bool) { } } - let r: u32 = if a ? 6 : 0; + let r: u32 = a ? 6 : 0; console.assert(r == b); } diff --git a/compiler/tests/statements/ternary_basic.leo b/compiler/tests/statements/ternary_basic.leo index 1f9c1f65a2..675b681fa9 100644 --- a/compiler/tests/statements/ternary_basic.leo +++ b/compiler/tests/statements/ternary_basic.leo @@ -1,5 +1,5 @@ function main(a: bool, b: bool) { - let c = if a ? true : false; + let c = a ? true : false; let d = c == b; } \ No newline at end of file diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 257cb30852..ec4df7c2cd 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -59,9 +59,6 @@ impl ParserContext { /// Otherwise, tries to parse the next token using [`parse_or_expression`]. /// pub fn parse_expression_fuzzy(&mut self) -> SyntaxResult { - // Check if we are parsing a ternary expression. - let if_token = self.eat(Token::If); - // Try to parse the next expression. Try BinaryOperation::Or. let mut expr = self.parse_or_expression()?; @@ -76,9 +73,6 @@ impl ParserContext { if_true: Box::new(if_true), if_false: Box::new(if_false), }); - } else if if_token.is_some() { - let peeked = self.peek()?; - return Err(SyntaxError::unexpected(&peeked.token, &[Token::Question], &peeked.span)); } Ok(expr) } diff --git a/tests/pass/parse/address/ternary.leo b/tests/pass/parse/address/ternary.leo index 29ecccb918..bdd88b9d92 100644 --- a/tests/pass/parse/address/ternary.leo +++ b/tests/pass/parse/address/ternary.leo @@ -2,7 +2,7 @@ function main(s: bool, c: address) { let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); - let r = if s? a: b; + let r = s? a: b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/circuits/pedersen_mock.leo b/tests/pass/parse/circuits/pedersen_mock.leo index 0b42c64a6e..559ebb7614 100644 --- a/tests/pass/parse/circuits/pedersen_mock.leo +++ b/tests/pass/parse/circuits/pedersen_mock.leo @@ -8,7 +8,7 @@ circuit PedersenHash { function hash(self, bits: [bool; 512]) -> u32 { let mut digest: u32 = 0; for i in 0..512 { - let base = if bits[i] ? self.parameters[i] : 0u32; + let base = bits[i] ? self.parameters[i] : 0u32; digest += base; } return digest diff --git a/tests/pass/parse/field/ternary.leo b/tests/pass/parse/field/ternary.leo index 49cd6a4e62..f193ad82a3 100644 --- a/tests/pass/parse/field/ternary.leo +++ b/tests/pass/parse/field/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: field, b: field, c: field) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/group/ternary.leo b/tests/pass/parse/group/ternary.leo index b213bb1419..fb69b74521 100644 --- a/tests/pass/parse/group/ternary.leo +++ b/tests/pass/parse/group/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: group, b: group, c: group) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/ternary.leo b/tests/pass/parse/integers/i128/ternary.leo index 5c2f199499..a923c428e6 100644 --- a/tests/pass/parse/integers/i128/ternary.leo +++ b/tests/pass/parse/integers/i128/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i128, b: i128, c: i128) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/i16/ternary.leo b/tests/pass/parse/integers/i16/ternary.leo index ccf29bfd50..4586b87bb4 100644 --- a/tests/pass/parse/integers/i16/ternary.leo +++ b/tests/pass/parse/integers/i16/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i16, b: i16, c: i16) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/i32/ternary.leo b/tests/pass/parse/integers/i32/ternary.leo index 3066547ae3..7927c2998b 100644 --- a/tests/pass/parse/integers/i32/ternary.leo +++ b/tests/pass/parse/integers/i32/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i32, b: i32, c: i32) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/i64/ternary.leo b/tests/pass/parse/integers/i64/ternary.leo index 811c759bdf..1a2d03a77f 100644 --- a/tests/pass/parse/integers/i64/ternary.leo +++ b/tests/pass/parse/integers/i64/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i64, b: i64, c: i64) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/i8/ternary.leo b/tests/pass/parse/integers/i8/ternary.leo index de797c6e3b..e1ec1943c9 100644 --- a/tests/pass/parse/integers/i8/ternary.leo +++ b/tests/pass/parse/integers/i8/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: i8, b: i8, c: i8) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/u128/ternary.leo b/tests/pass/parse/integers/u128/ternary.leo index 48299fac66..22e2e67058 100644 --- a/tests/pass/parse/integers/u128/ternary.leo +++ b/tests/pass/parse/integers/u128/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u128, b: u128, c: u128) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/u16/ternary.leo b/tests/pass/parse/integers/u16/ternary.leo index 2e2752a130..11d836570d 100644 --- a/tests/pass/parse/integers/u16/ternary.leo +++ b/tests/pass/parse/integers/u16/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u16, b: u16, c: u16) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/u32/ternary.leo b/tests/pass/parse/integers/u32/ternary.leo index fde04ac4b8..3c96a7236c 100644 --- a/tests/pass/parse/integers/u32/ternary.leo +++ b/tests/pass/parse/integers/u32/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u32, b: u32, c: u32) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/u64/ternary.leo b/tests/pass/parse/integers/u64/ternary.leo index 315fd7400b..4c4ddd8e0c 100644 --- a/tests/pass/parse/integers/u64/ternary.leo +++ b/tests/pass/parse/integers/u64/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u64, b: u64, c: u64) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/integers/u8/ternary.leo b/tests/pass/parse/integers/u8/ternary.leo index ce868a5ec9..1b436aa054 100644 --- a/tests/pass/parse/integers/u8/ternary.leo +++ b/tests/pass/parse/integers/u8/ternary.leo @@ -1,5 +1,5 @@ function main(s: bool, a: u8, b: u8, c: u8) { - let r = if s ? a : b; + let r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/tests/pass/parse/statements/for_loop.leo b/tests/pass/parse/statements/for_loop.leo index 060d27d965..2dca076858 100644 --- a/tests/pass/parse/statements/for_loop.leo +++ b/tests/pass/parse/statements/for_loop.leo @@ -7,7 +7,7 @@ function main(a: bool) { } } - let r: u32 = if a ? 6 : 0; + let r: u32 = a ? 6 : 0; console.assert(r == b); } diff --git a/tests/pass/parse/statements/ternary_basic.leo b/tests/pass/parse/statements/ternary_basic.leo index 1f9c1f65a2..675b681fa9 100644 --- a/tests/pass/parse/statements/ternary_basic.leo +++ b/tests/pass/parse/statements/ternary_basic.leo @@ -1,5 +1,5 @@ function main(a: bool, b: bool) { - let c = if a ? true : false; + let c = a ? true : false; let d = c == b; } \ No newline at end of file