From af5a708f8c6ca222fe52e0b26a0e15811177bcc5 Mon Sep 17 00:00:00 2001 From: gluax Date: Tue, 9 Mar 2021 15:56:35 -0500 Subject: [PATCH 01/40] reconstruction --- Cargo.lock | 87 ++-- ast/src/lib.rs | 3 + ast/src/reducer/mod.rs | 33 ++ ast/src/reducer/monoid.rs | 68 +++ ast/src/reducer/monoidal_director.rs | 450 ++++++++++++++++++ ast/src/reducer/monoidal_reducer.rs | 317 +++++++++++++ ast/src/reducer/reconstructing_director.rs | 518 +++++++++++++++++++++ ast/src/reducer/reconstructing_reducer.rs | 204 ++++++++ 8 files changed, 1642 insertions(+), 38 deletions(-) create mode 100644 ast/src/reducer/mod.rs create mode 100644 ast/src/reducer/monoid.rs create mode 100644 ast/src/reducer/monoidal_director.rs create mode 100644 ast/src/reducer/monoidal_reducer.rs create mode 100644 ast/src/reducer/reconstructing_director.rs create mode 100644 ast/src/reducer/reconstructing_reducer.rs diff --git a/Cargo.lock b/Cargo.lock index 881ab30a24..f9877705d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,9 +11,9 @@ dependencies = [ [[package]] name = "adler" -version = "1.0.2" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" +checksum = "bedc89c5c7b5550ffb9372eb5c5ffc7f9f705cc3f4a128bd4669b9745f555093" [[package]] name = "adler32" @@ -186,7 +186,7 @@ dependencies = [ "block-padding", "byte-tools", "byteorder", - "generic-array 0.12.4", + "generic-array 0.12.3", ] [[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.4", + "generic-array 0.12.3", ] [[package]] @@ -844,9 +844,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.4" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" dependencies = [ "typenum", ] @@ -906,9 +906,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d832b01df74254fe364568d6ddc294443f61cbec82816b60904303af87efae78" +checksum = "6b67e66362108efccd8ac053abafc8b7a8d86a37e6e48fc4f6f7485eb5e9e6a5" dependencies = [ "bytes", "fnv", @@ -921,6 +921,7 @@ dependencies = [ "tokio", "tokio-util", "tracing", + "tracing-futures", ] [[package]] @@ -1160,9 +1161,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.48" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc9f84f9b115ce7843d60706df1422a916680bfdfcbdb0447c5614ff9d7e4d78" +checksum = "5cfb73131c35423a367daf8cbd24100af0d077668c8c2943f0e7dd775fef0f65" dependencies = [ "wasm-bindgen", ] @@ -1396,9 +1397,9 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.87" +version = "0.2.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "265d751d31d6780a3f956bb5b8022feba2d94eeee5a84ba64f4212eedca42213" +checksum = "b7282d924be3275cec7f6756ff4121987bc6481325397dde6ba3e7802b1a8b1c" [[package]] name = "libloading" @@ -1885,9 +1886,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.6" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc0e1f259c92177c30a4c9d177246edd0a3568b25756a977d0632cf8fa37e905" +checksum = "439697af366c49a6d0a010c56a0d97685bc140ce0d377b13a2ea2aa42d64a827" [[package]] name = "pin-utils" @@ -2289,9 +2290,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dfd318104249865096c8da1dfabf09ddbb6d0330ea176812a62ec75e40c4166" +checksum = "c6af1b6204f89cf0069736daf8b852573e3bc34898eee600e95d3dd855c12e81" dependencies = [ "bitflags", "core-foundation", @@ -2302,9 +2303,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.1.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dee48cdde5ed250b0d3252818f646e174ab414036edb884dde62d80a3ac6082d" +checksum = "31531d257baab426203cf81c5ce1b0b55159dda7ed602ac81b582ccd62265741" dependencies = [ "core-foundation-sys", "libc", @@ -2393,9 +2394,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.64" +version = "1.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79" +checksum = "43535db9747a4ba938c0ce0a98cc631a46ebf943c9e1d604e091df6007620bf6" dependencies = [ "itoa", "ryu", @@ -2835,9 +2836,9 @@ dependencies = [ [[package]] name = "tinytemplate" -version = "1.2.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +checksum = "a2ada8616fad06a2d0c455adc530de4ef57605a8120cc65da9653e0e9623ca74" dependencies = [ "serde", "serde_json", @@ -2944,6 +2945,16 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "pin-project", + "tracing", +] + [[package]] name = "tracing-log" version = "0.1.2" @@ -3133,9 +3144,9 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasm-bindgen" -version = "0.2.71" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ee1280240b7c461d6a0071313e08f34a60b0365f14260362e5a2b17d1d31aa7" +checksum = "55c0f7123de74f0dab9b7d00fd614e7b19349cd1e2f5252bbe9b1754b59433be" dependencies = [ "cfg-if 1.0.0", "serde", @@ -3145,9 +3156,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.71" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b7d8b6942b8bb3a9b0e73fc79b98095a27de6fa247615e59d096754a3bc2aa8" +checksum = "7bc45447f0d4573f3d65720f636bbcc3dd6ce920ed704670118650bcd47764c7" dependencies = [ "bumpalo", "lazy_static", @@ -3160,9 +3171,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.21" +version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e67a5806118af01f0d9045915676b22aaebecf4178ae7021bc171dab0b897ab" +checksum = "3de431a2910c86679c34283a33f66f4e4abd7e0aec27b6669060148872aadf94" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -3172,9 +3183,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.71" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5ac38da8ef716661f0f36c0d8320b89028efe10c7c0afde65baffb496ce0d3b" +checksum = "3b8853882eef39593ad4174dd26fc9865a64e84026d223f63bb2c42affcbba2c" dependencies = [ "quote 1.0.9", "wasm-bindgen-macro-support", @@ -3182,9 +3193,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.71" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc053ec74d454df287b9374ee8abb36ffd5acb95ba87da3ba5b7d3fe20eb401e" +checksum = "4133b5e7f2a531fa413b3a1695e925038a05a71cf67e87dafa295cb645a01385" dependencies = [ "proc-macro2 1.0.24", "quote 1.0.9", @@ -3195,15 +3206,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.71" +version = "0.2.70" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d6f8ec44822dd71f5f221a5847fb34acd9060535c1211b70a05844c0f6383b1" +checksum = "dd4945e4943ae02d15c13962b38a5b1e81eadd4b71214eee75af64a4d6a4fd64" [[package]] name = "web-sys" -version = "0.3.48" +version = "0.3.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec600b26223b2948cedfde2a0aa6756dcf1fef616f43d7b3097aaf53a6c4d92b" +checksum = "c40dc691fc48003eba817c38da7113c15698142da971298003cac3ef175680b3" dependencies = [ "js-sys", "wasm-bindgen", @@ -3282,9 +3293,9 @@ dependencies = [ [[package]] name = "zip" -version = "0.5.11" +version = "0.5.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8264fcea9b7a036a4a5103d7153e988dbc2ebbafb34f68a3c2d404b6b82d74b6" +checksum = "5a8977234acab718eb2820494b2f96cbb16004c19dddf88b7445b27381450997" dependencies = [ "byteorder", "bzip2", diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 51fd09e848..3d06462030 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -52,6 +52,9 @@ pub use self::input::*; pub mod program; pub use self::program::*; +pub mod reducer; +pub use self::reducer::*; + pub mod statements; pub use self::statements::*; diff --git a/ast/src/reducer/mod.rs b/ast/src/reducer/mod.rs new file mode 100644 index 0000000000..c73c85d895 --- /dev/null +++ b/ast/src/reducer/mod.rs @@ -0,0 +1,33 @@ +// 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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +mod monoid; +pub use monoid::*; + +mod monoidal_director; +pub use monoidal_director::*; + +mod monoidal_reducer; +pub use monoidal_reducer::*; + +mod reconstructing_reducer; +pub use reconstructing_reducer::*; + +mod reconstructing_director; +pub use reconstructing_director::*; diff --git a/ast/src/reducer/monoid.rs b/ast/src/reducer/monoid.rs new file mode 100644 index 0000000000..e2f6e2ac70 --- /dev/null +++ b/ast/src/reducer/monoid.rs @@ -0,0 +1,68 @@ +// 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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +pub trait Monoid: Default { + fn append(self, other: Self) -> Self; + + fn append_all(self, others: impl Iterator) -> Self { + let mut current = self; + for item in others { + current = current.append(item); + } + current + } + + fn append_option(self, other: Option) -> Self { + match other { + None => self, + Some(other) => self.append(other), + } + } +} + +pub struct VecAppend(Vec); + +impl Default for VecAppend { + fn default() -> Self { + Self(vec![]) + } +} + +impl Monoid for VecAppend { + fn append(mut self, other: Self) -> Self { + self.0.extend(other.0); + VecAppend(self.0) + } + + fn append_all(mut self, others: impl Iterator) -> Self { + let all: Vec> = others.map(|x| x.0).collect(); + let total_size = all.iter().fold(0, |acc, v| acc + v.len()); + self.0.reserve(total_size); + for item in all.into_iter() { + self.0.extend(item); + } + self + } +} + +impl Into> for VecAppend { + fn into(self) -> Vec { + self.0 + } +} diff --git a/ast/src/reducer/monoidal_director.rs b/ast/src/reducer/monoidal_director.rs new file mode 100644 index 0000000000..4b5353cc6f --- /dev/null +++ b/ast/src/reducer/monoidal_director.rs @@ -0,0 +1,450 @@ +// 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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +use crate::{ + reducer::*, + AssigneeAccess, + Circuit, + CircuitMember, + ConditionalStatement, + ConsoleFunction, + Expression, + Function, + FunctionInput, + FunctionInputVariable, + GroupCoordinate, + GroupValue, + Identifier, + ImportStatement, + IntegerType, + Monoid, + PackageOrPackages, + Program, + SpreadOrExpression, + Statement, + TestFunction, + Type, + ValueExpression, + VariableName, +}; +use std::marker::PhantomData; + +pub struct MonoidalDirector> { + reducer: R, + _monoid: PhantomData, +} + +impl> MonoidalDirector { + pub fn new(reducer: R) -> Self { + Self { + reducer, + _monoid: PhantomData, + } + } + + pub fn reduce_program(&mut self, program: &Program) -> T { + let inputs = program + .expected_input + .iter() + .map(|x| self.reduce_function_input(x)) + .collect(); + let imports = program + .imports + .iter() + .map(|x| self.reduce_import_statement(x)) + .collect(); + let circuits = program + .circuits + .iter() + .map(|(identifier, circuit)| { + ( + identifier.name.clone(), + (self.reduce_identifier(identifier), self.reduce_circuit(circuit)), + ) + }) + .collect(); + let functions = program + .functions + .iter() + .map(|(identifier, function)| { + ( + identifier.name.clone(), + (self.reduce_identifier(identifier), self.reduce_function(function)), + ) + }) + .collect(); + let test_functions = program + .tests + .iter() + .map(|(identifier, test_function)| { + ( + identifier.name.clone(), + ( + self.reduce_identifier(identifier), + self.reduce_test_function(test_function), + ), + ) + }) + .collect(); + + self.reducer + .reduce_program(program, inputs, imports, circuits, functions, test_functions) + } + + pub fn reduce_function_input(&mut self, input: &FunctionInput) -> T { + let item = match input { + FunctionInput::InputKeyword(_) => FunctionInputItem::InputKeyword, + FunctionInput::SelfKeyword(_) => FunctionInputItem::SelfKeyword, + FunctionInput::MutSelfKeyword(_) => FunctionInputItem::MutSelfKeyword, + FunctionInput::Variable(function_input_variable) => { + FunctionInputItem::Variable(self.reduce_function_input_variable(function_input_variable)) + } + }; + + self.reducer.reduce_function_input(input, item) + } + + pub fn reduce_import_statement(&mut self, import: &ImportStatement) -> T { + let package = self.reduce_package(&import.package_or_packages); + + self.reducer.reduce_import_statement(import, package) + } + + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> T { + let circuit_name = self.reduce_identifier(&circuit.circuit_name); + let members = circuit.members.iter().map(|x| self.reduce_circuit_member(x)).collect(); + + self.reducer.reduce_circuit(circuit, circuit_name, members) + } + + pub fn reduce_function(&mut self, function: &Function) -> T { + let identifier = self.reduce_identifier(&function.identifier); + let input = function.input.iter().map(|x| self.reduce_function_input(x)).collect(); + let output = function.output.as_ref().map(|x| self.reduce_type(x)); + let statements = function + .block + .statements + .iter() + .map(|x| self.reduce_statement(x)) + .collect(); + + self.reducer + .reduce_function(function, identifier, input, output, statements) + } + + pub fn reduce_test_function(&mut self, test_function: &TestFunction) -> T { + let function = self.reduce_function(&test_function.function); + let input_file = test_function.input_file.as_ref().map(|x| self.reduce_identifier(x)); + + self.reducer.reduce_test_function(test_function, function, input_file) + } + + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> T { + self.reducer.reduce_identifier(identifier) + } + + pub fn reduce_integer_type(&mut self, integer_type: &IntegerType) -> T { + self.reducer.reduce_integer_type(integer_type) + } + + pub fn reduce_function_input_variable(&mut self, function_input_variable: &FunctionInputVariable) -> T { + let identifier = self.reduce_identifier(&function_input_variable.identifier); + let type_ = self.reduce_type(&function_input_variable.type_); + + self.reducer + .reduce_function_input_variable(function_input_variable, identifier, type_) + } + + pub fn reduce_type(&mut self, type_: &Type) -> T { + let items = match type_ { + Type::Array(type_, _) => TypeMonoidItems::Array(self.reduce_type(type_)), + Type::Tuple(types) => TypeMonoidItems::Tuple(types.iter().map(|x| self.reduce_type(x)).collect()), + Type::Circuit(identifier) => TypeMonoidItems::Identifier(self.reduce_identifier(identifier)), + _ => TypeMonoidItems::None, + }; + + self.reducer.reduce_type(type_, items) + } + + pub fn reduce_package(&mut self, package_or_packages: &PackageOrPackages) -> T { + match package_or_packages { + PackageOrPackages::Package(package) => { + let name = self.reduce_identifier(&package.name); + + self.reducer.reduce_package(package, name) + } + PackageOrPackages::Packages(packages) => { + let name = self.reduce_identifier(&packages.name); + + self.reducer.reduce_packages(packages, name) + } + } + } + + pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> T { + let items = match circuit_member { + CircuitMember::CircuitVariable(identifier, type_) => CircuitMemberMonoidItems::Variable { + identifier: self.reduce_identifier(identifier), + type_: self.reduce_type(type_), + }, + CircuitMember::CircuitFunction(function) => { + CircuitMemberMonoidItems::Function(self.reduce_function(function)) + } + }; + + self.reducer.reduce_circuit_member(circuit_member, items) + } + + pub fn reduce_statement(&mut self, statement: &Statement) -> T { + let items = match statement { + Statement::Return(ret) => StatementMonoidItems::Return(self.reduce_expression(&ret.expression)), + Statement::Definition(definition) => StatementMonoidItems::Definition { + variables: self.reduce_variable_names(&definition.variable_names), + expression: self.reduce_expression(&definition.value), + }, + Statement::Assign(assign) => StatementMonoidItems::Assign { + assignee: self.reduce_identifier(&assign.assignee.identifier), + assignee_accesses: assign + .assignee + .accesses + .iter() + .map(|x| self.reduce_assignee_access(x)) + .collect(), + expression: self.reduce_expression(&assign.value), + }, + Statement::Conditional(conditional) => { + StatementMonoidItems::Conditional(self.reduce_conditional_statement(conditional)) + } + Statement::Iteration(iteration) => StatementMonoidItems::Iteration { + identifier: self.reduce_identifier(&iteration.variable), + start: self.reduce_expression(&iteration.start), + stop: self.reduce_expression(&iteration.stop), + statements: iteration + .block + .statements + .iter() + .map(|x| self.reduce_statement(x)) + .collect(), + }, + Statement::Console(console) => match &console.function { + ConsoleFunction::Assert(expression) => { + StatementMonoidItems::ConsoleAssert(self.reduce_expression(expression)) + } + ConsoleFunction::Debug(formatted_string) + | ConsoleFunction::Error(formatted_string) + | ConsoleFunction::Log(formatted_string) => StatementMonoidItems::ConsoleFormat( + formatted_string + .parameters + .iter() + .map(|parameter| self.reduce_expression(¶meter)) + .collect(), + ), + }, + Statement::Expression(statement) => { + StatementMonoidItems::Expression(self.reduce_expression(&statement.expression)) + } + Statement::Block(block) => StatementMonoidItems::Statements( + block + .statements + .iter() + .map(|statement| self.reduce_statement(statement)) + .collect(), + ), + }; + + self.reducer.reduce_statement(statement, items) + } + + pub fn reduce_assignee_access(&mut self, assignee_access: &AssigneeAccess) -> T { + let item = match assignee_access { + AssigneeAccess::ArrayRange(start, stop) => { + let start_item = start.as_ref().map(|x| self.reduce_expression(x)); + let stop_item = stop.as_ref().map(|x| self.reduce_expression(x)); + AssigneeAccessItem::Array(RangeItem::Range(start_item, stop_item)) + } + AssigneeAccess::ArrayIndex(expression) => { + AssigneeAccessItem::Array(RangeItem::Index(self.reduce_expression(expression))) + } + AssigneeAccess::Tuple(_, _) => AssigneeAccessItem::Tuple, + AssigneeAccess::Member(identifier) => { + let identifier = self.reduce_identifier(identifier); + AssigneeAccessItem::Member(identifier) + } + }; + + self.reducer.reduce_assignee_access(assignee_access, item) + } + + pub fn reduce_conditional_statement(&mut self, statement: &ConditionalStatement) -> T { + let condition = self.reduce_expression(&statement.condition); + let statements = statement + .block + .statements + .iter() + .map(|x| self.reduce_statement(x)) + .collect(); + let next = statement.next.as_ref().map(|x| self.reduce_statement(x)); + + self.reducer + .reduce_conditional_statement(statement, condition, statements, next) + } + + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> T { + let identifier = self.reduce_identifier(&variable_name.identifier); + + self.reducer.reduce_variable_name(variable_name, identifier) + } + + pub fn reduce_variable_names(&mut self, variable_names: &[VariableName]) -> T { + let names = variable_names + .iter() + .map(|variable_name| self.reduce_variable_name(variable_name)) + .collect(); + + self.reducer.reduce_variable_names(names) + } + + pub fn reduce_group_coordinate(&mut self, group_coordinate: &GroupCoordinate) -> T { + self.reducer.reduce_group_coordinate(group_coordinate) + } + + pub fn reduce_value_expression(&mut self, value_expression: &ValueExpression) -> T { + let item = match value_expression { + ValueExpression::Address(_, _) => ValueExpressionMonoidItems::Address, + ValueExpression::Boolean(_, _) => ValueExpressionMonoidItems::Boolean, + ValueExpression::Field(_, _) => ValueExpressionMonoidItems::Field, + ValueExpression::Group(group_value) => match group_value.as_ref() { + GroupValue::Single(_, _) => ValueExpressionMonoidItems::GroupSingle, + GroupValue::Tuple(tuple) => { + let x = self.reduce_group_coordinate(&tuple.x); + let y = self.reduce_group_coordinate(&tuple.y); + ValueExpressionMonoidItems::GroupTuple(x, y) + } + }, + ValueExpression::Implicit(_, _) => ValueExpressionMonoidItems::Implicit, + ValueExpression::Integer(integer_type, _, _) => { + ValueExpressionMonoidItems::Integer(self.reduce_integer_type(integer_type)) + } + }; + + self.reducer.reduce_value_expression(value_expression, item) + } + + pub fn reduce_expression(&mut self, expression: &Expression) -> T { + let items = match expression { + Expression::Identifier(identifier) => ExpressionMonoidItems::Unary(self.reduce_identifier(identifier)), + Expression::Value(value) => ExpressionMonoidItems::Value(self.reduce_value_expression(value)), + Expression::Binary(binary) => { + let left = self.reduce_expression(&binary.left); + let right = self.reduce_expression(&binary.right); + ExpressionMonoidItems::Binary(left, right) + } + Expression::Unary(unary) => ExpressionMonoidItems::Unary(self.reduce_expression(&unary.inner)), + Expression::Ternary(ternary) => { + let condition = self.reduce_expression(&ternary.condition); + let left = self.reduce_expression(&ternary.if_true); + let right = self.reduce_expression(&ternary.if_false); + ExpressionMonoidItems::Triary(condition, left, right) + } + Expression::ArrayInline(array_inline) => ExpressionMonoidItems::Var( + array_inline + .elements + .iter() + .map(|x| match x { + SpreadOrExpression::Expression(expression) | SpreadOrExpression::Spread(expression) => { + self.reduce_expression(expression) + } + }) + .collect(), + ), + Expression::ArrayInit(array_init) => { + let element = self.reduce_expression(&array_init.element); + ExpressionMonoidItems::Unary(element) + } + Expression::ArrayAccess(array_access) => { + let array = self.reduce_expression(&array_access.array); + let index = self.reduce_expression(&array_access.index); + ExpressionMonoidItems::ArrayAccess(array, index) + } + Expression::ArrayRangeAccess(array_range_access) => { + let array = self.reduce_expression(&array_range_access.array); + + match (array_range_access.left.as_ref(), array_range_access.right.as_ref()) { + (Some(left_expression), Some(right_expression)) => { + let left = self.reduce_expression(&left_expression); + let right = self.reduce_expression(&right_expression); + ExpressionMonoidItems::Triary(array, left, right) + } + (Some(left_expression), None) => { + let left = self.reduce_expression(&left_expression); + ExpressionMonoidItems::Binary(array, left) + } + (None, Some(right_expression)) => { + let right = self.reduce_expression(&right_expression); + ExpressionMonoidItems::Binary(array, right) + } + (None, None) => ExpressionMonoidItems::Unary(array), + } + } + Expression::TupleInit(tuple_init) => { + let element_items = tuple_init.elements.iter().map(|x| self.reduce_expression(x)).collect(); + ExpressionMonoidItems::Var(element_items) + } + Expression::TupleAccess(tuple_access) => { + let tuple_access = self.reduce_expression(&tuple_access.tuple); + ExpressionMonoidItems::Unary(tuple_access) + } + + Expression::CircuitInit(circuit_init) => { + let defined_circuit_name_item = self.reduce_identifier(&circuit_init.name); + let members = circuit_init + .members + .iter() + .map(|definition| { + let definition_identifier = self.reduce_identifier(&definition.identifier); + let definition_expression = self.reduce_expression(&definition.expression); + (definition_identifier, definition_expression) + }) + .collect(); + + ExpressionMonoidItems::Circuit(defined_circuit_name_item, members) + } + Expression::CircuitMemberAccess(circuit_member_access) => { + let declared_circuit_name = self.reduce_expression(&circuit_member_access.circuit); + let circuit_member_name = self.reduce_identifier(&circuit_member_access.name); + + ExpressionMonoidItems::Binary(declared_circuit_name, circuit_member_name) + } + Expression::CircuitStaticFunctionAccess(circuit_static_func_access) => { + let declared_circuit_name = self.reduce_expression(&circuit_static_func_access.circuit); + let circuit_static_function_name = self.reduce_identifier(&circuit_static_func_access.name); + + ExpressionMonoidItems::Binary(declared_circuit_name, circuit_static_function_name) + } + + Expression::Call(call) => { + let function = self.reduce_expression(&call.function); + let function_arguments = call.arguments.iter().map(|x| self.reduce_expression(x)).collect(); + + ExpressionMonoidItems::FunctionCall(function, function_arguments) + } + }; + self.reducer.reduce_expression(expression, items) + } +} diff --git a/ast/src/reducer/monoidal_reducer.rs b/ast/src/reducer/monoidal_reducer.rs new file mode 100644 index 0000000000..470dd34eb2 --- /dev/null +++ b/ast/src/reducer/monoidal_reducer.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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +use crate::{ + AssigneeAccess, + Circuit, + CircuitMember, + ConditionalStatement, + Expression, + Function, + FunctionInput, + FunctionInputVariable, + GroupCoordinate, + Identifier, + ImportStatement, + IntegerType, + Monoid, + Package, + Packages, + Program, + Statement, + TestFunction, + Type, + ValueExpression, + VariableName, +}; +use indexmap::IndexMap; + +pub enum TypeMonoidItems { + None, + Tuple(Vec), + Array(T), + Identifier(T), +} + +pub enum CircuitMemberMonoidItems { + Variable { identifier: T, type_: T }, + Function(T), +} + +pub enum StatementMonoidItems { + Return(T), + Definition { + variables: T, + expression: T, + }, + Assign { + assignee: T, + assignee_accesses: Vec, + expression: T, + }, + Conditional(T), + Iteration { + identifier: T, + start: T, + stop: T, + statements: Vec, + }, + ConsoleAssert(T), + ConsoleFormat(Vec), + Expression(T), + Statements(Vec), +} + +pub enum AssigneeAccessItem { + Array(RangeItem), + Tuple, + Member(T), +} + +pub enum RangeItem { + Range(Option, Option), + Index(T), +} + +pub enum ExpressionMonoidItems { + Empty, + Unary(T), + Binary(T, T), + Triary(T, T, T), + FunctionCall(T, Vec), + ArrayAccess(T, T), + Circuit(T, Vec<(T, T)>), + Var(Vec), + Value(T), +} + +pub enum ConditionStatementNextItem { + Nested(T), + End(Vec), +} + +pub enum FunctionInputItem { + InputKeyword, + SelfKeyword, + MutSelfKeyword, + Variable(T), +} + +pub enum ValueExpressionMonoidItems { + Address, + Boolean, + Field, + GroupSingle, + GroupTuple(T, T), + Implicit, + Integer(T), +} + +#[allow(unused_variables)] +pub trait MonoidalReducer { + fn reduce_program( + &mut self, + program: &Program, + expected_input: Vec, + imports: Vec, + circuits: IndexMap, + functions: IndexMap, + tests: IndexMap, + ) -> T { + let mut items = T::default() + .append_all(expected_input.into_iter()) + .append_all(imports.into_iter()); + + for (_, (identifier, value)) in circuits.into_iter() { + items = items.append(identifier).append(value); + } + for (_, (identifier, value)) in functions.into_iter() { + items = items.append(identifier).append(value); + } + for (_, (identifier, value)) in tests.into_iter() { + items = items.append(identifier).append(value); + } + items + } + + fn reduce_function_input(&mut self, input: &FunctionInput, item: FunctionInputItem) -> T { + match item { + FunctionInputItem::InputKeyword | FunctionInputItem::SelfKeyword | FunctionInputItem::MutSelfKeyword => { + T::default() + } + FunctionInputItem::Variable(variable) => variable, + } + } + + fn reduce_import_statement(&mut self, import: &ImportStatement, package: T) -> T { + package + } + + fn reduce_circuit(&mut self, circuit: &Circuit, circuit_name: T, members: Vec) -> T { + circuit_name.append_all(members.into_iter()) + } + + fn reduce_function( + &mut self, + function: &Function, + identifier: T, + input: Vec, + output: Option, + statements: Vec, + ) -> T { + identifier + .append_all(input.into_iter()) + .append_option(output) + .append_all(statements.into_iter()) + } + + fn reduce_test_function(&mut self, test_function: &TestFunction, function: T, input_file: Option) -> T { + function.append_option(input_file) + } + + fn reduce_identifier(&mut self, identifier: &Identifier) -> T { + T::default() + } + + fn reduce_integer_type(&mut self, integer_type: &IntegerType) -> T { + T::default() + } + + fn reduce_function_input_variable( + &mut self, + function_input_variable: &FunctionInputVariable, + identifier: T, + type_: T, + ) -> T { + identifier.append(type_) + } + + fn reduce_type(&mut self, type_: &Type, items: TypeMonoidItems) -> T { + match items { + TypeMonoidItems::Tuple(items) => T::default().append_all(items.into_iter()), + TypeMonoidItems::Array(item) => item, + TypeMonoidItems::Identifier(item) => item, + TypeMonoidItems::None => T::default(), + } + } + + fn reduce_packages(&mut self, packages: &Packages, name: T) -> T { + name + } + + fn reduce_package(&mut self, package: &Package, name: T) -> T { + name + } + + fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember, items: CircuitMemberMonoidItems) -> T { + match items { + CircuitMemberMonoidItems::Variable { identifier, type_ } => identifier.append(type_), + CircuitMemberMonoidItems::Function(identifier) => identifier, + } + } + + fn reduce_statement(&mut self, statement: &Statement, items: StatementMonoidItems) -> T { + match items { + StatementMonoidItems::Return(expression) => expression, + StatementMonoidItems::Definition { variables, expression } => variables.append(expression), + StatementMonoidItems::Assign { + assignee, + assignee_accesses, + expression, + } => assignee.append_all(assignee_accesses.into_iter()).append(expression), + StatementMonoidItems::Conditional(conditional) => conditional, + StatementMonoidItems::Iteration { + identifier, + start, + stop, + statements, + } => identifier.append(start).append(stop).append_all(statements.into_iter()), + StatementMonoidItems::ConsoleAssert(expression) => expression, + StatementMonoidItems::ConsoleFormat(parameters) => T::default().append_all(parameters.into_iter()), + StatementMonoidItems::Expression(expression) => expression, + StatementMonoidItems::Statements(statements) => T::default().append_all(statements.into_iter()), + } + } + + fn reduce_assignee_access(&mut self, assignee_access: &AssigneeAccess, item: AssigneeAccessItem) -> T { + match item { + AssigneeAccessItem::Array(assignee) => match assignee { + RangeItem::Index(index) => index, + RangeItem::Range(start, stop) => T::default().append_option(start).append_option(stop), + }, + AssigneeAccessItem::Tuple => T::default(), + AssigneeAccessItem::Member(identifier) => identifier, + } + } + + fn reduce_conditional_statement( + &mut self, + statement: &ConditionalStatement, + condition: T, + statements: Vec, + next: Option, + ) -> T { + condition.append_all(statements.into_iter()).append_option(next) + } + + fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: T) -> T { + identifier + } + + fn reduce_variable_names(&mut self, names: Vec) -> T { + T::default().append_all(names.into_iter()) + } + + fn reduce_group_coordinate(&mut self, group_coordinate: &GroupCoordinate) -> T { + T::default() + } + + fn reduce_value_expression( + &mut self, + value_expression: &ValueExpression, + value: ValueExpressionMonoidItems, + ) -> T { + match value { + ValueExpressionMonoidItems::GroupTuple(x, y) => x.append(y), + ValueExpressionMonoidItems::Integer(integer_type) => integer_type, + _ => T::default(), + } + } + + // please be careful matching on array access/range expressions, they can be ExpressionMonoidItems::BiTriary or ExpressionMonoidItems::Binary + fn reduce_expression(&mut self, expression: &Expression, items: ExpressionMonoidItems) -> T { + match items { + ExpressionMonoidItems::Empty => T::default(), + ExpressionMonoidItems::Unary(expression) => expression, + ExpressionMonoidItems::Binary(left, right) => left.append(right), + ExpressionMonoidItems::Triary(left, center, right) => left.append(center).append(right), + ExpressionMonoidItems::ArrayAccess(identifier, index) => identifier.append(index), + ExpressionMonoidItems::FunctionCall(identifier, arguments) => identifier.append_all(arguments.into_iter()), + ExpressionMonoidItems::Circuit(identifier, arguments) => { + let mut out = identifier; + for (key, value) in arguments.into_iter() { + out = out.append(key).append(value); + } + out + } + ExpressionMonoidItems::Var(items) => T::default().append_all(items.into_iter()), + ExpressionMonoidItems::Value(value) => value, + } + } +} diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs new file mode 100644 index 0000000000..f195b991dc --- /dev/null +++ b/ast/src/reducer/reconstructing_director.rs @@ -0,0 +1,518 @@ +// 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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +use crate::{ + ArrayAccessExpression, + ArrayInitExpression, + ArrayInlineExpression, + ArrayRangeAccessExpression, + AssignStatement, + Assignee, + AssigneeAccess, + BinaryExpression, + Block, + CallExpression, + Circuit, + CircuitImpliedVariableDefinition, + CircuitInitExpression, + CircuitMember, + CircuitMemberAccessExpression, + CircuitStaticFunctionAccessExpression, + ConditionalStatement, + ConsoleFunction, + ConsoleStatement, + DefinitionStatement, + Expression, + ExpressionStatement, + FormattedString, + Function, + FunctionInput, + FunctionInputVariable, + Identifier, + ImportStatement, + IterationStatement, + PackageOrPackages, + Program, + ReconstructingReducer, + ReturnStatement, + SpreadOrExpression, + Statement, + TernaryExpression, + TestFunction, + TupleAccessExpression, + TupleInitExpression, + Type, + UnaryExpression, + VariableName, +}; + +pub struct ReconstructingDirector { + reducer: R, +} + +impl ReconstructingDirector { + pub fn new(reducer: R) -> Self { + Self { reducer } + } + + pub fn reduce_program(&mut self, program: &Program) -> Program { + let inputs = program + .expected_input + .iter() + .filter_map(|x| self.reduce_function_input(x)) + .collect(); + let imports = program + .imports + .iter() + .filter_map(|x| self.reduce_import_statement(x)) + .collect(); + let circuits = program + .circuits + .iter() + .filter_map(|(identifier, circuit)| { + Some((self.reduce_identifier(identifier), self.reduce_circuit(circuit)?)) + }) + .collect(); + let functions = program + .functions + .iter() + .filter_map(|(identifier, function)| { + Some((self.reduce_identifier(identifier), self.reduce_function(function)?)) + }) + .collect(); + let test_functions = program + .tests + .iter() + .filter_map(|(identifier, test_function)| { + Some(( + self.reduce_identifier(identifier), + self.reduce_test_function(test_function)?, + )) + }) + .collect(); + + self.reducer + .reduce_program(program, inputs, imports, circuits, functions, test_functions) + } + + pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Option { + let item = match input { + FunctionInput::InputKeyword(input_keyword) => FunctionInput::InputKeyword(input_keyword.clone()), + FunctionInput::SelfKeyword(self_keyword) => FunctionInput::SelfKeyword(self_keyword.clone()), + FunctionInput::MutSelfKeyword(mut_self_keyword) => FunctionInput::MutSelfKeyword(mut_self_keyword.clone()), + FunctionInput::Variable(function_input_variable) => { + FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)) + } + }; + + self.reducer.reduce_function_input(input, item) + } + + pub fn reduce_import_statement(&mut self, import: &ImportStatement) -> Option { + let package = self.reduce_package(&import.package_or_packages); + + self.reducer.reduce_import_statement(import, package) + } + + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Option { + let circuit_name = self.reduce_identifier(&circuit.circuit_name); + let members = circuit + .members + .iter() + .filter_map(|x| self.reduce_circuit_member(x)) + .collect(); + + self.reducer.reduce_circuit(circuit, circuit_name, members) + } + + pub fn reduce_function(&mut self, function: &Function) -> Option { + let identifier = self.reduce_identifier(&function.identifier); + let input = function + .input + .iter() + .filter_map(|x| self.reduce_function_input(x)) + .collect(); + let output = function.output.as_ref().map(|x| self.reduce_type(x)); + let block = Block { + statements: function + .block + .statements + .iter() + .map(|x| self.reduce_statement(x)) + .collect(), + span: function.block.span.clone(), + }; + + self.reducer.reduce_function(function, identifier, input, output, block) + } + + pub fn reduce_test_function(&mut self, test_function: &TestFunction) -> Option { + let function = self.reduce_function(&test_function.function); + let input_file = test_function.input_file.as_ref().map(|x| self.reduce_identifier(x)); + + self.reducer.reduce_test_function(test_function, function?, input_file) + } + + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { + self.reducer.reduce_identifier(identifier) + } + + pub fn reduce_function_input_variable( + &mut self, + function_input_variable: &FunctionInputVariable, + ) -> FunctionInputVariable { + let identifier = self.reduce_identifier(&function_input_variable.identifier); + let type_ = self.reduce_type(&function_input_variable.type_); + + self.reducer + .reduce_function_input_variable(function_input_variable, identifier, type_) + } + + pub fn reduce_type(&mut self, type_: &Type) -> Type { + let items = match type_ { + // Data type wrappers + Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_)), dimensions.clone()), + Type::Tuple(types) => Type::Tuple(types.iter().map(|x| self.reduce_type(x)).collect()), + Type::Circuit(identifier) => Type::Circuit(self.reduce_identifier(identifier)), + _ => type_.clone(), + }; + + self.reducer.reduce_type(type_, items) + } + + pub fn reduce_package(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { + self.reducer.reduce_package(package_or_packages) + } + + pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Option { + let items = match circuit_member { + CircuitMember::CircuitVariable(identifier, type_) => { + CircuitMember::CircuitVariable(self.reduce_identifier(identifier), self.reduce_type(type_)) + } + CircuitMember::CircuitFunction(function) => CircuitMember::CircuitFunction(self.reduce_function(function)?), + }; + + self.reducer.reduce_circuit_member(circuit_member, items) + } + + pub fn reduce_statement(&mut self, statement: &Statement) -> Statement { + let items = match statement { + Statement::Return(return_statement) => Statement::Return(ReturnStatement { + expression: self.reduce_expression(&return_statement.expression), + span: return_statement.span.clone(), + }), + Statement::Definition(definition) => { + Statement::Definition(DefinitionStatement { + declaration_type: definition.declaration_type.clone(), + variable_names: definition + .variable_names + .iter() + .map(|variable_name| self.reduce_variable_name(variable_name)) + .collect(), + type_: Some(self.reduce_type(&definition.type_.as_ref().unwrap())), // TODO fix + value: self.reduce_expression(&definition.value), + span: definition.span.clone(), + }) + } + Statement::Assign(assign) => Statement::Assign(AssignStatement { + operation: assign.operation.clone(), + assignee: Assignee { + identifier: self.reduce_identifier(&assign.assignee.identifier), + accesses: assign + .assignee + .accesses + .iter() + .filter_map(|x| self.reduce_assignee_access(x)) + .collect(), + span: assign.assignee.span.clone(), + }, + value: self.reduce_expression(&assign.value), + span: assign.span.clone(), + }), + Statement::Conditional(conditional) => { + Statement::Conditional(self.reduce_conditional_statement(conditional)) + } + Statement::Iteration(iteration) => { + Statement::Iteration(IterationStatement { + variable: self.reduce_identifier(&iteration.variable), + start: self.reduce_expression(&iteration.start), + stop: self.reduce_expression(&iteration.stop), + block: Block { + statements: iteration + .block + .statements + .iter() + .map(|statement| self.reduce_statement(statement)) + .collect(), + span: iteration.block.span.clone(), + }, // TODO reduce block that isn't in a statement + span: iteration.span.clone(), + }) + } + Statement::Console(console_function_call) => { + let function = match &console_function_call.function { + ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)), + ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { + let formatted = FormattedString { + string: format.string.clone(), + containers: format.containers.clone(), + parameters: format + .parameters + .iter() + .map(|parameter| self.reduce_expression(¶meter)) + .collect(), + span: format.span.clone(), + }; + match &console_function_call.function { + ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted), + ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), + ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted), + _ => unimplemented!(), // impossible + } + } + }; + Statement::Console(ConsoleStatement { + function, + span: console_function_call.span.clone(), + }) + } + Statement::Expression(expression) => Statement::Expression(ExpressionStatement { + expression: self.reduce_expression(&expression.expression), + span: expression.span.clone(), + }), + Statement::Block(block) => Statement::Block(Block { + statements: block + .statements + .iter() + .map(|statement| self.reduce_statement(statement)) + .collect(), + span: block.span.clone(), + }), + }; + + self.reducer.reduce_statement(statement, items) + } + + pub fn reduce_assignee_access(&mut self, assignee_access: &AssigneeAccess) -> Option { + let item = match assignee_access { + AssigneeAccess::ArrayRange(start, stop) => { + let start_item = start.as_ref().map(|x| self.reduce_expression(x)); + let stop_item = stop.as_ref().map(|x| self.reduce_expression(x)); + AssigneeAccess::ArrayRange(start_item, stop_item) + } + AssigneeAccess::ArrayIndex(expression) => AssigneeAccess::ArrayIndex(self.reduce_expression(&expression)), + AssigneeAccess::Tuple(number, span) => AssigneeAccess::Tuple(number.clone(), span.clone()), + AssigneeAccess::Member(identifier) => { + let identifier = self.reduce_identifier(identifier); + AssigneeAccess::Member(identifier) + } + }; + + self.reducer.reduce_assignee_access(assignee_access, item) + } + + pub fn reduce_conditional_statement(&mut self, statement: &ConditionalStatement) -> ConditionalStatement { + let condition = self.reduce_expression(&statement.condition); + let statements = Block { + statements: statement + .block + .statements + .iter() + .map(|x| self.reduce_statement(x)) + .collect(), + span: statement.block.span.clone(), + }; + let next = statement.next.as_ref().map(|x| self.reduce_statement(x)); + + self.reducer + .reduce_conditional_statement(statement, condition, statements, next) + } + + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> VariableName { + let identifier = self.reduce_identifier(&variable_name.identifier); + + self.reducer.reduce_variable_name(variable_name, identifier) + } + + pub fn reduce_expression(&mut self, expression: &Expression) -> Expression { + let items = match expression { + Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)), + // Expression::Value(value) => Expression::Value(self.reduce_expression(value.)) + Expression::Binary(binary) => { + let left = Box::new(self.reduce_expression(&binary.left)); + let right = Box::new(self.reduce_expression(&binary.right)); + + Expression::Binary(BinaryExpression { + left, + right, + op: binary.op.clone(), + span: binary.span.clone(), + }) + } + Expression::Unary(unary) => { + let inner = Box::new(self.reduce_expression(&unary.inner)); + + Expression::Unary(UnaryExpression { + inner, + op: unary.op.clone(), + span: unary.span.clone(), + }) + } + Expression::Ternary(ternary) => { + let condition = Box::new(self.reduce_expression(&ternary.condition)); + let if_true = Box::new(self.reduce_expression(&ternary.if_true)); + let if_false = Box::new(self.reduce_expression(&ternary.if_false)); + + Expression::Ternary(TernaryExpression { + condition, + if_true, + if_false, + span: ternary.span.clone(), + }) + } + + Expression::ArrayInline(array_inline) => { + let elements = array_inline + .elements + .iter() + .map(|x| match x { + SpreadOrExpression::Expression(expression) => { + SpreadOrExpression::Expression(self.reduce_expression(expression)) + } + SpreadOrExpression::Spread(expression) => { + SpreadOrExpression::Spread(self.reduce_expression(expression)) + } + }) + .collect(); + + Expression::ArrayInline(ArrayInlineExpression { + elements, + span: array_inline.span.clone(), + }) + } + Expression::ArrayInit(array_init) => { + let element = Box::new(self.reduce_expression(&array_init.element)); + + Expression::ArrayInit(ArrayInitExpression { + element, + dimensions: array_init.dimensions.clone(), + span: array_init.span.clone(), + }) + } + Expression::ArrayAccess(array_access) => { + let array = Box::new(self.reduce_expression(&array_access.array)); + let index = Box::new(self.reduce_expression(&array_access.index)); + Expression::ArrayAccess(ArrayAccessExpression { + array, + index, + span: array_access.span.clone(), + }) + } + Expression::ArrayRangeAccess(array_range_access) => { + let array = Box::new(self.reduce_expression(&array_range_access.array)); + let left = array_range_access + .left + .as_ref() + .map(|left| Box::new(self.reduce_expression(&left))); + let right = array_range_access + .right + .as_ref() + .map(|right| Box::new(self.reduce_expression(&right))); + + Expression::ArrayRangeAccess(ArrayRangeAccessExpression { + array, + left, + right, + span: array_range_access.span.clone(), + }) + } + + Expression::TupleInit(tuple_init) => { + let elements = tuple_init.elements.iter().map(|x| self.reduce_expression(x)).collect(); + + Expression::TupleInit(TupleInitExpression { + elements, + span: tuple_init.span.clone(), + }) + } + Expression::TupleAccess(tuple_access) => { + let tuple = Box::new(self.reduce_expression(&tuple_access.tuple)); + + Expression::TupleAccess(TupleAccessExpression { + tuple, + index: tuple_access.index.clone(), + span: tuple_access.span.clone(), + }) + } + Expression::CircuitInit(circuit_init) => { + let name = self.reduce_identifier(&circuit_init.name); + let members = circuit_init + .members + .iter() + .map(|definition| { + let identifier = self.reduce_identifier(&definition.identifier); + let expression = self.reduce_expression(&definition.expression); + + CircuitImpliedVariableDefinition { identifier, expression } + }) + .collect(); + + Expression::CircuitInit(CircuitInitExpression { + name, + members, + span: circuit_init.span.clone(), + }) + } + Expression::CircuitMemberAccess(circuit_member_access) => { + let circuit = Box::new(self.reduce_expression(&circuit_member_access.circuit)); + let name = self.reduce_identifier(&circuit_member_access.name); + + Expression::CircuitMemberAccess(CircuitMemberAccessExpression { + circuit, + name, + span: circuit_member_access.span.clone(), + }) + } + Expression::CircuitStaticFunctionAccess(circuit_static_func_access) => { + let circuit = Box::new(self.reduce_expression(&circuit_static_func_access.circuit)); + let name = self.reduce_identifier(&circuit_static_func_access.name); + + Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { + circuit, + name, + span: circuit_static_func_access.span.clone(), + }) + } + Expression::Call(call) => { + let function = Box::new(self.reduce_expression(&call.function)); + let arguments = call.arguments.iter().map(|x| self.reduce_expression(x)).collect(); + + Expression::Call(CallExpression { + function, + arguments, + span: call.span.clone(), + }) + } + + x => x.clone(), // leaf nodes we dont reconstruct + }; + + self.reducer.reduce_expression(expression, items) + } +} diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs new file mode 100644 index 0000000000..6db147b04f --- /dev/null +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -0,0 +1,204 @@ +// 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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +use crate::{ + AssigneeAccess, + Block, + Circuit, + CircuitMember, + ConditionalStatement, + Expression, + Function, + FunctionInput, + FunctionInputVariable, + Identifier, + ImportStatement, + Package, + PackageOrPackages, + Packages, + Program, + Statement, + TestFunction, + Type, + VariableName, +}; +use indexmap::IndexMap; + +#[allow(unused_variables)] +#[allow(clippy::redundant_closure)] // Clippy bug line 188 +pub trait ReconstructingReducer { + // ciruits/functions/tests map identifier -> (identifier_item, value_item) + fn reduce_program( + &mut self, + program: &Program, + expected_input: Vec, + imports: Vec, + circuits: IndexMap, + functions: IndexMap, + tests: IndexMap, + ) -> Program { + Program { + name: program.name.clone(), + expected_input, + imports, + circuits, + functions, + tests, + } + } + + fn reduce_function_input(&mut self, input: &FunctionInput, item: FunctionInput) -> Option { + Some(item) + } + + fn reduce_import_statement( + &mut self, + import: &ImportStatement, + package_or_packages: PackageOrPackages, + ) -> Option { + Some(ImportStatement { + package_or_packages, + span: import.span.clone(), + }) + } + + fn reduce_circuit( + &mut self, + circuit: &Circuit, + circuit_name: Identifier, + members: Vec, + ) -> Option { + Some(Circuit { circuit_name, members }) + } + + fn reduce_function( + &mut self, + function: &Function, + identifier: Identifier, + input: Vec, + output: Option, + block: Block, + ) -> Option { + Some(Function { + identifier, + input, + output, + block, + span: function.span.clone(), + }) + } + + fn reduce_test_function( + &mut self, + test_function: &TestFunction, + function: Function, + input_file: Option, + ) -> Option { + Some(TestFunction { function, input_file }) + } + + fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { + identifier.clone() + } + + fn reduce_function_input_variable( + &mut self, + function_input_variable: &FunctionInputVariable, + identifier: Identifier, + type_: Type, + ) -> FunctionInputVariable { + FunctionInputVariable { + identifier, + const_: function_input_variable.const_, + mutable: function_input_variable.mutable, + type_, + span: function_input_variable.span.clone(), + } + } + + fn reduce_type(&mut self, type_: &Type, items: Type) -> Type { + items + } + + fn reduce_package(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { + match package_or_packages { + PackageOrPackages::Package(package) => { + let name = self.reduce_identifier(&package.name); + + PackageOrPackages::Package(Package { + name, + access: package.access.clone(), + span: package.span.clone(), + }) + } + PackageOrPackages::Packages(packages) => { + let name = self.reduce_identifier(&packages.name); + + PackageOrPackages::Packages(Packages { + name, + accesses: packages.accesses.clone(), + span: packages.span.clone(), + }) + } + } + } + + fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember, items: CircuitMember) -> Option { + Some(items) + } + + fn reduce_statement(&mut self, statement: &Statement, items: Statement) -> Statement { + items + } + + fn reduce_assignee_access( + &mut self, + assignee_access: &AssigneeAccess, + item: AssigneeAccess, + ) -> Option { + Some(item) + } + + fn reduce_conditional_statement( + &mut self, + statement: &ConditionalStatement, + condition: Expression, + block: Block, + next: Option, + ) -> ConditionalStatement { + ConditionalStatement { + condition, + block, + next: next.map(|item| Box::new(item)), + span: statement.span.clone(), + } + } + + fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> VariableName { + VariableName { + mutable: variable_name.mutable, + identifier, + span: variable_name.span.clone(), + } + } + + fn reduce_expression(&mut self, expression: &Expression, items: Expression) -> Expression { + items + } +} From 51c20ff07fa652d4d1cacb59af25b3500b609f32 Mon Sep 17 00:00:00 2001 From: gluax Date: Tue, 9 Mar 2021 18:46:45 -0500 Subject: [PATCH 02/40] fix some reducer bugs, still more to implement/make function better --- ast/src/reducer/canonicalization.rs | 36 ++++++++++++++++++++++ ast/src/reducer/mod.rs | 3 ++ ast/src/reducer/monoidal_director.rs | 6 ++-- ast/src/reducer/monoidal_reducer.rs | 3 +- ast/src/reducer/reconstructing_director.rs | 27 ++++++++-------- 5 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 ast/src/reducer/canonicalization.rs diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs new file mode 100644 index 0000000000..cd64e19faa --- /dev/null +++ b/ast/src/reducer/canonicalization.rs @@ -0,0 +1,36 @@ +// 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 . + +//! This module contains the reducer which iterates through ast nodes - converting them into +//! asg nodes and saving relevant information. + +use crate::{reducer::ReconstructingReducer, Identifier}; + +pub struct Canonicalizer; + +impl Canonicalizer { + fn is_self(&self, identifier: &Identifier) -> bool { + match identifier.name.as_str() { + "Self" | "self" => true, + _ => false, + } + } +} + +impl ReconstructingReducer for Canonicalizer { + // TODO in reduce_circuit -> turn SelfKeyword and SelfType to Circuit Name + // and replace self with Circuit Name +} diff --git a/ast/src/reducer/mod.rs b/ast/src/reducer/mod.rs index c73c85d895..ae9e09287e 100644 --- a/ast/src/reducer/mod.rs +++ b/ast/src/reducer/mod.rs @@ -17,6 +17,9 @@ //! This module contains the reducer which iterates through ast nodes - converting them into //! asg nodes and saving relevant information. +mod canonicalization; +pub use canonicalization::*; + mod monoid; pub use monoid::*; diff --git a/ast/src/reducer/monoidal_director.rs b/ast/src/reducer/monoidal_director.rs index f4443ec870..fa7408aa79 100644 --- a/ast/src/reducer/monoidal_director.rs +++ b/ast/src/reducer/monoidal_director.rs @@ -397,7 +397,8 @@ impl> MonoidalDirector { .iter() .map(|definition| { let definition_identifier = self.reduce_identifier(&definition.identifier); - let definition_expression = definition.expression.as_ref().map(|expr| self.reduce_expression(&expr)); + let definition_expression = + definition.expression.as_ref().map(|expr| self.reduce_expression(&expr)); (definition_identifier, definition_expression) }) .collect(); @@ -422,10 +423,9 @@ impl> MonoidalDirector { let function_arguments = call.arguments.iter().map(|x| self.reduce_expression(x)).collect(); ExpressionMonoidItems::FunctionCall(function, function_arguments) - }, + } // TODO casts? - _ => ExpressionMonoidItems::Empty, }; self.reducer.reduce_expression(expression, items) diff --git a/ast/src/reducer/monoidal_reducer.rs b/ast/src/reducer/monoidal_reducer.rs index 334da3de40..dc47e16ec8 100644 --- a/ast/src/reducer/monoidal_reducer.rs +++ b/ast/src/reducer/monoidal_reducer.rs @@ -300,12 +300,11 @@ pub trait MonoidalReducer { match value { Some(val) => { out = out.append(key).append(val); - }, + } None => { out = out.append(key); } } - } out } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 1447144775..a9fdb85148 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -149,7 +149,8 @@ impl ReconstructingDirector { span: function.block.span.clone(), }; - self.reducer.reduce_function(function, annotations, identifier, input, output, block) + self.reducer + .reduce_function(function, annotations, identifier, input, output, block) } pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { @@ -200,19 +201,17 @@ impl ReconstructingDirector { expression: self.reduce_expression(&return_statement.expression), span: return_statement.span.clone(), }), - Statement::Definition(definition) => { - Statement::Definition(DefinitionStatement { - declaration_type: definition.declaration_type.clone(), - variable_names: definition - .variable_names - .iter() - .map(|variable_name| self.reduce_variable_name(variable_name)) - .collect(), - type_: Some(self.reduce_type(&definition.type_.as_ref().unwrap())), // TODO fix - value: self.reduce_expression(&definition.value), - span: definition.span.clone(), - }) - } + Statement::Definition(definition) => Statement::Definition(DefinitionStatement { + declaration_type: definition.declaration_type.clone(), + variable_names: definition + .variable_names + .iter() + .map(|variable_name| self.reduce_variable_name(variable_name)) + .collect(), + type_: definition.type_.as_ref().map(|inner| self.reduce_type(&inner)), + value: self.reduce_expression(&definition.value), + span: definition.span.clone(), + }), Statement::Assign(assign) => Statement::Assign(AssignStatement { operation: assign.operation.clone(), assignee: Assignee { From 9f126613d0c0e30f56c961a9fc25230b27b2fe8a Mon Sep 17 00:00:00 2001 From: gluax Date: Wed, 10 Mar 2021 12:11:54 -0500 Subject: [PATCH 03/40] Self words replaced, still need to error for self/Self outside circuits --- HEAD | 0 ast/src/reducer/canonicalization.rs | 112 +++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 HEAD diff --git a/HEAD b/HEAD new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index cd64e19faa..8c4eb23ecf 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -17,20 +17,124 @@ //! This module contains the reducer which iterates through ast nodes - converting them into //! asg nodes and saving relevant information. -use crate::{reducer::ReconstructingReducer, Identifier}; +use crate::{ + reducer::ReconstructingReducer, + Circuit, + CircuitMember, + Function, + FunctionInput, + FunctionInputVariable, + Identifier, + Type, +}; pub struct Canonicalizer; impl Canonicalizer { fn is_self(&self, identifier: &Identifier) -> bool { match identifier.name.as_str() { - "Self" | "self" => true, + "Self" => true, _ => false, } } + + fn is_self_keyword(&self, function_inputs: &Vec) -> bool { + for function_input in function_inputs { + match function_input { + FunctionInput::SelfKeyword(_) => return true, + _ => {} + } + } + + false + } + + fn is_self_type(&self, type_option: Option<&Type>) -> bool { + match type_option { + Some(type_) => match type_ { + Type::SelfType => true, + _ => false, + }, + None => false, + } + } + + fn canonicalize_function_input(&self, function_input: &FunctionInput, circuit_name: &Identifier) -> FunctionInput { + match function_input { + FunctionInput::SelfKeyword(self_keyword) => { + return FunctionInput::Variable(FunctionInputVariable { + identifier: circuit_name.clone(), + const_: false, + mutable: false, + type_: Type::Circuit(circuit_name.clone()), + span: self_keyword.span.clone(), + }); + } + FunctionInput::MutSelfKeyword(mut_self_keyword) => { + return FunctionInput::Variable(FunctionInputVariable { + identifier: circuit_name.clone(), + const_: false, + mutable: true, + type_: Type::Circuit(circuit_name.clone()), + span: mut_self_keyword.span.clone(), + }); + } + _ => {} + } + + function_input.clone() + } + + fn canonicalize_circuit_member(&self, circuit_member: &CircuitMember, circuit_name: &Identifier) -> CircuitMember { + match circuit_member { + CircuitMember::CircuitVariable(_, _) => {} + CircuitMember::CircuitFunction(function) => { + let mut input = function.input.clone(); + let mut output = function.output.clone(); + + if self.is_self_keyword(&input) { + input = input + .iter() + .map(|function_input| self.canonicalize_function_input(function_input, circuit_name)) + .collect(); + } + + if self.is_self_type(output.as_ref()) { + output = Some(Type::Circuit(circuit_name.clone())); + } + + return CircuitMember::CircuitFunction(Function { + annotations: function.annotations.clone(), + identifier: function.identifier.clone(), + input, + output, + block: function.block.clone(), + span: function.span.clone(), + }); + } + } + + circuit_member.clone() + } } impl ReconstructingReducer for Canonicalizer { - // TODO in reduce_circuit -> turn SelfKeyword and SelfType to Circuit Name - // and replace self with Circuit Name + fn reduce_circuit( + &mut self, + _: &Circuit, + circuit_name: Identifier, + members: Vec, + ) -> Option { + let new_circuit = Circuit { + circuit_name: circuit_name.clone(), + members: members + .iter() + .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) + .collect(), + }; + + Some(new_circuit) + } + + // TODO make all self/Self outside of circuit error out } From 8e0ebd386acbba3c5fcaf991c81a7461d0a9f5c4 Mon Sep 17 00:00:00 2001 From: gluax Date: Wed, 10 Mar 2021 12:22:56 -0500 Subject: [PATCH 04/40] comment out replacing of self in circuit function input... not sure --- ast/src/reducer/canonicalization.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 8c4eb23ecf..2976c01d5f 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -89,15 +89,16 @@ impl Canonicalizer { match circuit_member { CircuitMember::CircuitVariable(_, _) => {} CircuitMember::CircuitFunction(function) => { - let mut input = function.input.clone(); + let input = function.input.clone(); let mut output = function.output.clone(); - if self.is_self_keyword(&input) { - input = input - .iter() - .map(|function_input| self.canonicalize_function_input(function_input, circuit_name)) - .collect(); - } + // probably shouldn't do this its self not Self + // if self.is_self_keyword(&input) { + // input = input + // .iter() + // .map(|function_input| self.canonicalize_function_input(function_input, circuit_name)) + // .collect(); + // } if self.is_self_type(output.as_ref()) { output = Some(Type::Circuit(circuit_name.clone())); From 476307fffc1424c9d245fc8f3e1ff218b7e5ee3a Mon Sep 17 00:00:00 2001 From: gluax Date: Wed, 10 Mar 2021 13:27:06 -0500 Subject: [PATCH 05/40] there could be more instances where expressions might need to be matched --- ast/src/reducer/canonicalization.rs | 128 ++++++++++++++++++++++++---- 1 file changed, 110 insertions(+), 18 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 2976c01d5f..c8aa3a4843 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -19,30 +19,36 @@ use crate::{ reducer::ReconstructingReducer, + Block, + CallExpression, Circuit, + CircuitInitExpression, CircuitMember, + CircuitMemberAccessExpression, + CircuitStaticFunctionAccessExpression, + DefinitionStatement, + Expression, + ExpressionStatement, Function, FunctionInput, FunctionInputVariable, Identifier, + ReturnStatement, + Statement, Type, }; pub struct Canonicalizer; impl Canonicalizer { - fn is_self(&self, identifier: &Identifier) -> bool { - match identifier.name.as_str() { - "Self" => true, - _ => false, - } + fn _is_self(&self, identifier: &Identifier) -> bool { + matches!(identifier.name.as_str(), "Self") } - fn is_self_keyword(&self, function_inputs: &Vec) -> bool { + fn _is_self_keyword(&self, function_inputs: &[FunctionInput]) -> bool { for function_input in function_inputs { - match function_input { - FunctionInput::SelfKeyword(_) => return true, - _ => {} + if let FunctionInput::SelfKeyword(_) = function_input { + return true; } } @@ -50,16 +56,10 @@ impl Canonicalizer { } fn is_self_type(&self, type_option: Option<&Type>) -> bool { - match type_option { - Some(type_) => match type_ { - Type::SelfType => true, - _ => false, - }, - None => false, - } + matches!(type_option, Some(Type::SelfType)) } - fn canonicalize_function_input(&self, function_input: &FunctionInput, circuit_name: &Identifier) -> FunctionInput { + fn _canonicalize_function_input(&self, function_input: &FunctionInput, circuit_name: &Identifier) -> FunctionInput { match function_input { FunctionInput::SelfKeyword(self_keyword) => { return FunctionInput::Variable(FunctionInputVariable { @@ -85,12 +85,104 @@ impl Canonicalizer { function_input.clone() } + fn canonicalize_expression(&self, expression: &Expression, circuit_name: &Identifier) -> Expression { + match expression { + Expression::CircuitInit(circuit_init) => { + return Expression::CircuitInit(CircuitInitExpression { + name: circuit_name.clone(), + members: circuit_init.members.clone(), + span: circuit_init.span.clone(), + }); + } + Expression::CircuitMemberAccess(circuit_member_access) => { + return Expression::CircuitMemberAccess(CircuitMemberAccessExpression { + circuit: Box::new(self.canonicalize_expression(&circuit_member_access.circuit, circuit_name)), + name: circuit_member_access.name.clone(), + span: circuit_member_access.span.clone(), + }); + } + Expression::CircuitStaticFunctionAccess(circuit_static_func_access) => { + return Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { + circuit: Box::new(self.canonicalize_expression(&circuit_static_func_access.circuit, circuit_name)), + name: circuit_static_func_access.name.clone(), + span: circuit_static_func_access.span.clone(), + }); + } + Expression::Call(call) => { + return Expression::Call(CallExpression { + function: Box::new(self.canonicalize_expression(&call.function, circuit_name)), + arguments: call.arguments.clone(), + span: call.span.clone(), + }); + } + _ => {} + } + + expression.clone() + } + + fn canonicalize_statement(&self, statement: &Statement, circuit_name: &Identifier) -> Statement { + // What Statements could have Self appear + + match statement { + Statement::Return(return_statement) => { + return Statement::Return(ReturnStatement { + expression: self.canonicalize_expression(&return_statement.expression, circuit_name), + span: return_statement.span.clone(), + }); + } + Statement::Definition(definition) => { + let mut type_ = definition.type_.clone(); + + if self.is_self_type(type_.as_ref()) { + type_ = Some(Type::Circuit(circuit_name.clone())); + } + + return Statement::Definition(DefinitionStatement { + declaration_type: definition.declaration_type.clone(), + variable_names: definition.variable_names.clone(), + type_, + value: self.canonicalize_expression(&definition.value, circuit_name), + span: definition.span.clone(), + }); + } + Statement::Expression(expression) => { + return Statement::Expression(ExpressionStatement { + expression: self.canonicalize_expression(&expression.expression, circuit_name), + span: expression.span.clone(), + }); + } + Statement::Block(block) => { + return Statement::Block(Block { + statements: block + .statements + .iter() + .map(|block_statement| self.canonicalize_statement(&block_statement, circuit_name)) + .collect(), + span: block.span.clone(), + }); + } + _ => {} + } + + statement.clone() + } + fn canonicalize_circuit_member(&self, circuit_member: &CircuitMember, circuit_name: &Identifier) -> CircuitMember { match circuit_member { CircuitMember::CircuitVariable(_, _) => {} CircuitMember::CircuitFunction(function) => { let input = function.input.clone(); let mut output = function.output.clone(); + let block = Block { + statements: function + .block + .statements + .iter() + .map(|statement| self.canonicalize_statement(statement, circuit_name)) + .collect(), + span: function.block.span.clone(), + }; // probably shouldn't do this its self not Self // if self.is_self_keyword(&input) { @@ -109,7 +201,7 @@ impl Canonicalizer { identifier: function.identifier.clone(), input, output, - block: function.block.clone(), + block, span: function.span.clone(), }); } From 250c8ce5ec9976d4ef05ad783ef5b3290be2c90a Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 14:32:20 -0500 Subject: [PATCH 06/40] reducer clean up --- ast/src/reducer/canonicalization.rs | 57 +- ast/src/reducer/mod.rs | 12 - ast/src/reducer/monoid.rs | 68 -- ast/src/reducer/monoidal_director.rs | 433 ----------- ast/src/reducer/monoidal_reducer.rs | 315 -------- ast/src/reducer/reconstructing_director.rs | 866 +++++++++++---------- ast/src/reducer/reconstructing_reducer.rs | 537 +++++++++---- 7 files changed, 855 insertions(+), 1433 deletions(-) delete mode 100644 ast/src/reducer/monoid.rs delete mode 100644 ast/src/reducer/monoidal_director.rs delete mode 100644 ast/src/reducer/monoidal_reducer.rs diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index c8aa3a4843..bab7238090 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -14,29 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//! This module contains the reducer which iterates through ast nodes - converting them into -//! asg nodes and saving relevant information. - -use crate::{ - reducer::ReconstructingReducer, - Block, - CallExpression, - Circuit, - CircuitInitExpression, - CircuitMember, - CircuitMemberAccessExpression, - CircuitStaticFunctionAccessExpression, - DefinitionStatement, - Expression, - ExpressionStatement, - Function, - FunctionInput, - FunctionInputVariable, - Identifier, - ReturnStatement, - Statement, - Type, -}; +use crate::*; pub struct Canonicalizer; @@ -45,16 +23,6 @@ impl Canonicalizer { matches!(identifier.name.as_str(), "Self") } - fn _is_self_keyword(&self, function_inputs: &[FunctionInput]) -> bool { - for function_input in function_inputs { - if let FunctionInput::SelfKeyword(_) = function_input { - return true; - } - } - - false - } - fn is_self_type(&self, type_option: Option<&Type>) -> bool { matches!(type_option, Some(Type::SelfType)) } @@ -184,14 +152,6 @@ impl Canonicalizer { span: function.block.span.clone(), }; - // probably shouldn't do this its self not Self - // if self.is_self_keyword(&input) { - // input = input - // .iter() - // .map(|function_input| self.canonicalize_function_input(function_input, circuit_name)) - // .collect(); - // } - if self.is_self_type(output.as_ref()) { output = Some(Type::Circuit(circuit_name.clone())); } @@ -212,22 +172,15 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_circuit( - &mut self, - _: &Circuit, - circuit_name: Identifier, - members: Vec, - ) -> Option { - let new_circuit = Circuit { + fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { + Circuit { circuit_name: circuit_name.clone(), members: members .iter() .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) .collect(), - }; - - Some(new_circuit) + } } - // TODO make all self/Self outside of circuit error out + // fn reduce_program(program: &Program, expected_input: Vec, imports: Vec, circuits: IndexMap, functions: IndexMap) } diff --git a/ast/src/reducer/mod.rs b/ast/src/reducer/mod.rs index ae9e09287e..144997d8e1 100644 --- a/ast/src/reducer/mod.rs +++ b/ast/src/reducer/mod.rs @@ -14,21 +14,9 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//! This module contains the reducer which iterates through ast nodes - converting them into -//! asg nodes and saving relevant information. - mod canonicalization; pub use canonicalization::*; -mod monoid; -pub use monoid::*; - -mod monoidal_director; -pub use monoidal_director::*; - -mod monoidal_reducer; -pub use monoidal_reducer::*; - mod reconstructing_reducer; pub use reconstructing_reducer::*; diff --git a/ast/src/reducer/monoid.rs b/ast/src/reducer/monoid.rs deleted file mode 100644 index e2f6e2ac70..0000000000 --- a/ast/src/reducer/monoid.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 . - -//! This module contains the reducer which iterates through ast nodes - converting them into -//! asg nodes and saving relevant information. - -pub trait Monoid: Default { - fn append(self, other: Self) -> Self; - - fn append_all(self, others: impl Iterator) -> Self { - let mut current = self; - for item in others { - current = current.append(item); - } - current - } - - fn append_option(self, other: Option) -> Self { - match other { - None => self, - Some(other) => self.append(other), - } - } -} - -pub struct VecAppend(Vec); - -impl Default for VecAppend { - fn default() -> Self { - Self(vec![]) - } -} - -impl Monoid for VecAppend { - fn append(mut self, other: Self) -> Self { - self.0.extend(other.0); - VecAppend(self.0) - } - - fn append_all(mut self, others: impl Iterator) -> Self { - let all: Vec> = others.map(|x| x.0).collect(); - let total_size = all.iter().fold(0, |acc, v| acc + v.len()); - self.0.reserve(total_size); - for item in all.into_iter() { - self.0.extend(item); - } - self - } -} - -impl Into> for VecAppend { - fn into(self) -> Vec { - self.0 - } -} diff --git a/ast/src/reducer/monoidal_director.rs b/ast/src/reducer/monoidal_director.rs deleted file mode 100644 index fa7408aa79..0000000000 --- a/ast/src/reducer/monoidal_director.rs +++ /dev/null @@ -1,433 +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 . - -//! This module contains the reducer which iterates through ast nodes - converting them into -//! asg nodes and saving relevant information. - -use crate::{ - reducer::*, - AssigneeAccess, - Circuit, - CircuitMember, - ConditionalStatement, - ConsoleFunction, - Expression, - Function, - FunctionInput, - FunctionInputVariable, - GroupCoordinate, - GroupValue, - Identifier, - ImportStatement, - IntegerType, - Monoid, - PackageOrPackages, - Program, - SpreadOrExpression, - Statement, - Type, - ValueExpression, - VariableName, -}; -use std::marker::PhantomData; - -pub struct MonoidalDirector> { - reducer: R, - _monoid: PhantomData, -} - -impl> MonoidalDirector { - pub fn new(reducer: R) -> Self { - Self { - reducer, - _monoid: PhantomData, - } - } - - pub fn reduce_program(&mut self, program: &Program) -> T { - let inputs = program - .expected_input - .iter() - .map(|x| self.reduce_function_input(x)) - .collect(); - let imports = program - .imports - .iter() - .map(|x| self.reduce_import_statement(x)) - .collect(); - let circuits = program - .circuits - .iter() - .map(|(identifier, circuit)| { - ( - identifier.name.clone(), - (self.reduce_identifier(identifier), self.reduce_circuit(circuit)), - ) - }) - .collect(); - let functions = program - .functions - .iter() - .map(|(identifier, function)| { - ( - identifier.name.clone(), - (self.reduce_identifier(identifier), self.reduce_function(function)), - ) - }) - .collect(); - - self.reducer - .reduce_program(program, inputs, imports, circuits, functions) - } - - pub fn reduce_function_input(&mut self, input: &FunctionInput) -> T { - let item = match input { - FunctionInput::InputKeyword(_) => FunctionInputItem::InputKeyword, - FunctionInput::SelfKeyword(_) => FunctionInputItem::SelfKeyword, - FunctionInput::MutSelfKeyword(_) => FunctionInputItem::MutSelfKeyword, - FunctionInput::Variable(function_input_variable) => { - FunctionInputItem::Variable(self.reduce_function_input_variable(function_input_variable)) - } - }; - - self.reducer.reduce_function_input(input, item) - } - - pub fn reduce_import_statement(&mut self, import: &ImportStatement) -> T { - let package = self.reduce_package(&import.package_or_packages); - - self.reducer.reduce_import_statement(import, package) - } - - pub fn reduce_circuit(&mut self, circuit: &Circuit) -> T { - let circuit_name = self.reduce_identifier(&circuit.circuit_name); - let members = circuit.members.iter().map(|x| self.reduce_circuit_member(x)).collect(); - - self.reducer.reduce_circuit(circuit, circuit_name, members) - } - - pub fn reduce_function(&mut self, function: &Function) -> T { - let identifier = self.reduce_identifier(&function.identifier); - let input = function.input.iter().map(|x| self.reduce_function_input(x)).collect(); - let output = function.output.as_ref().map(|x| self.reduce_type(x)); - let statements = function - .block - .statements - .iter() - .map(|x| self.reduce_statement(x)) - .collect(); - - self.reducer - .reduce_function(function, identifier, input, output, statements) - } - - pub fn reduce_identifier(&mut self, identifier: &Identifier) -> T { - self.reducer.reduce_identifier(identifier) - } - - pub fn reduce_integer_type(&mut self, integer_type: &IntegerType) -> T { - self.reducer.reduce_integer_type(integer_type) - } - - pub fn reduce_function_input_variable(&mut self, function_input_variable: &FunctionInputVariable) -> T { - let identifier = self.reduce_identifier(&function_input_variable.identifier); - let type_ = self.reduce_type(&function_input_variable.type_); - - self.reducer - .reduce_function_input_variable(function_input_variable, identifier, type_) - } - - pub fn reduce_type(&mut self, type_: &Type) -> T { - let items = match type_ { - Type::Array(type_, _) => TypeMonoidItems::Array(self.reduce_type(type_)), - Type::Tuple(types) => TypeMonoidItems::Tuple(types.iter().map(|x| self.reduce_type(x)).collect()), - Type::Circuit(identifier) => TypeMonoidItems::Identifier(self.reduce_identifier(identifier)), - _ => TypeMonoidItems::None, - }; - - self.reducer.reduce_type(type_, items) - } - - pub fn reduce_package(&mut self, package_or_packages: &PackageOrPackages) -> T { - match package_or_packages { - PackageOrPackages::Package(package) => { - let name = self.reduce_identifier(&package.name); - - self.reducer.reduce_package(package, name) - } - PackageOrPackages::Packages(packages) => { - let name = self.reduce_identifier(&packages.name); - - self.reducer.reduce_packages(packages, name) - } - } - } - - pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> T { - let items = match circuit_member { - CircuitMember::CircuitVariable(identifier, type_) => CircuitMemberMonoidItems::Variable { - identifier: self.reduce_identifier(identifier), - type_: self.reduce_type(type_), - }, - CircuitMember::CircuitFunction(function) => { - CircuitMemberMonoidItems::Function(self.reduce_function(function)) - } - }; - - self.reducer.reduce_circuit_member(circuit_member, items) - } - - pub fn reduce_statement(&mut self, statement: &Statement) -> T { - let items = match statement { - Statement::Return(ret) => StatementMonoidItems::Return(self.reduce_expression(&ret.expression)), - Statement::Definition(definition) => StatementMonoidItems::Definition { - variables: self.reduce_variable_names(&definition.variable_names), - expression: self.reduce_expression(&definition.value), - }, - Statement::Assign(assign) => StatementMonoidItems::Assign { - assignee: self.reduce_identifier(&assign.assignee.identifier), - assignee_accesses: assign - .assignee - .accesses - .iter() - .map(|x| self.reduce_assignee_access(x)) - .collect(), - expression: self.reduce_expression(&assign.value), - }, - Statement::Conditional(conditional) => { - StatementMonoidItems::Conditional(self.reduce_conditional_statement(conditional)) - } - Statement::Iteration(iteration) => StatementMonoidItems::Iteration { - identifier: self.reduce_identifier(&iteration.variable), - start: self.reduce_expression(&iteration.start), - stop: self.reduce_expression(&iteration.stop), - statements: iteration - .block - .statements - .iter() - .map(|x| self.reduce_statement(x)) - .collect(), - }, - Statement::Console(console) => match &console.function { - ConsoleFunction::Assert(expression) => { - StatementMonoidItems::ConsoleAssert(self.reduce_expression(expression)) - } - ConsoleFunction::Debug(formatted_string) - | ConsoleFunction::Error(formatted_string) - | ConsoleFunction::Log(formatted_string) => StatementMonoidItems::ConsoleFormat( - formatted_string - .parameters - .iter() - .map(|parameter| self.reduce_expression(¶meter)) - .collect(), - ), - }, - Statement::Expression(statement) => { - StatementMonoidItems::Expression(self.reduce_expression(&statement.expression)) - } - Statement::Block(block) => StatementMonoidItems::Statements( - block - .statements - .iter() - .map(|statement| self.reduce_statement(statement)) - .collect(), - ), - }; - - self.reducer.reduce_statement(statement, items) - } - - pub fn reduce_assignee_access(&mut self, assignee_access: &AssigneeAccess) -> T { - let item = match assignee_access { - AssigneeAccess::ArrayRange(start, stop) => { - let start_item = start.as_ref().map(|x| self.reduce_expression(x)); - let stop_item = stop.as_ref().map(|x| self.reduce_expression(x)); - AssigneeAccessItem::Array(RangeItem::Range(start_item, stop_item)) - } - AssigneeAccess::ArrayIndex(expression) => { - AssigneeAccessItem::Array(RangeItem::Index(self.reduce_expression(expression))) - } - AssigneeAccess::Tuple(_, _) => AssigneeAccessItem::Tuple, - AssigneeAccess::Member(identifier) => { - let identifier = self.reduce_identifier(identifier); - AssigneeAccessItem::Member(identifier) - } - }; - - self.reducer.reduce_assignee_access(assignee_access, item) - } - - pub fn reduce_conditional_statement(&mut self, statement: &ConditionalStatement) -> T { - let condition = self.reduce_expression(&statement.condition); - let statements = statement - .block - .statements - .iter() - .map(|x| self.reduce_statement(x)) - .collect(); - let next = statement.next.as_ref().map(|x| self.reduce_statement(x)); - - self.reducer - .reduce_conditional_statement(statement, condition, statements, next) - } - - pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> T { - let identifier = self.reduce_identifier(&variable_name.identifier); - - self.reducer.reduce_variable_name(variable_name, identifier) - } - - pub fn reduce_variable_names(&mut self, variable_names: &[VariableName]) -> T { - let names = variable_names - .iter() - .map(|variable_name| self.reduce_variable_name(variable_name)) - .collect(); - - self.reducer.reduce_variable_names(names) - } - - pub fn reduce_group_coordinate(&mut self, group_coordinate: &GroupCoordinate) -> T { - self.reducer.reduce_group_coordinate(group_coordinate) - } - - pub fn reduce_value_expression(&mut self, value_expression: &ValueExpression) -> T { - let item = match value_expression { - ValueExpression::Address(_, _) => ValueExpressionMonoidItems::Address, - ValueExpression::Boolean(_, _) => ValueExpressionMonoidItems::Boolean, - ValueExpression::Field(_, _) => ValueExpressionMonoidItems::Field, - ValueExpression::Group(group_value) => match group_value.as_ref() { - GroupValue::Single(_, _) => ValueExpressionMonoidItems::GroupSingle, - GroupValue::Tuple(tuple) => { - let x = self.reduce_group_coordinate(&tuple.x); - let y = self.reduce_group_coordinate(&tuple.y); - ValueExpressionMonoidItems::GroupTuple(x, y) - } - }, - ValueExpression::Implicit(_, _) => ValueExpressionMonoidItems::Implicit, - ValueExpression::Integer(integer_type, _, _) => { - ValueExpressionMonoidItems::Integer(self.reduce_integer_type(integer_type)) - } - }; - - self.reducer.reduce_value_expression(value_expression, item) - } - - pub fn reduce_expression(&mut self, expression: &Expression) -> T { - let items = match expression { - Expression::Identifier(identifier) => ExpressionMonoidItems::Unary(self.reduce_identifier(identifier)), - Expression::Value(value) => ExpressionMonoidItems::Value(self.reduce_value_expression(value)), - Expression::Binary(binary) => { - let left = self.reduce_expression(&binary.left); - let right = self.reduce_expression(&binary.right); - ExpressionMonoidItems::Binary(left, right) - } - Expression::Unary(unary) => ExpressionMonoidItems::Unary(self.reduce_expression(&unary.inner)), - Expression::Ternary(ternary) => { - let condition = self.reduce_expression(&ternary.condition); - let left = self.reduce_expression(&ternary.if_true); - let right = self.reduce_expression(&ternary.if_false); - ExpressionMonoidItems::Triary(condition, left, right) - } - Expression::ArrayInline(array_inline) => ExpressionMonoidItems::Var( - array_inline - .elements - .iter() - .map(|x| match x { - SpreadOrExpression::Expression(expression) | SpreadOrExpression::Spread(expression) => { - self.reduce_expression(expression) - } - }) - .collect(), - ), - Expression::ArrayInit(array_init) => { - let element = self.reduce_expression(&array_init.element); - ExpressionMonoidItems::Unary(element) - } - Expression::ArrayAccess(array_access) => { - let array = self.reduce_expression(&array_access.array); - let index = self.reduce_expression(&array_access.index); - ExpressionMonoidItems::ArrayAccess(array, index) - } - Expression::ArrayRangeAccess(array_range_access) => { - let array = self.reduce_expression(&array_range_access.array); - - match (array_range_access.left.as_ref(), array_range_access.right.as_ref()) { - (Some(left_expression), Some(right_expression)) => { - let left = self.reduce_expression(&left_expression); - let right = self.reduce_expression(&right_expression); - ExpressionMonoidItems::Triary(array, left, right) - } - (Some(left_expression), None) => { - let left = self.reduce_expression(&left_expression); - ExpressionMonoidItems::Binary(array, left) - } - (None, Some(right_expression)) => { - let right = self.reduce_expression(&right_expression); - ExpressionMonoidItems::Binary(array, right) - } - (None, None) => ExpressionMonoidItems::Unary(array), - } - } - Expression::TupleInit(tuple_init) => { - let element_items = tuple_init.elements.iter().map(|x| self.reduce_expression(x)).collect(); - ExpressionMonoidItems::Var(element_items) - } - Expression::TupleAccess(tuple_access) => { - let tuple_access = self.reduce_expression(&tuple_access.tuple); - ExpressionMonoidItems::Unary(tuple_access) - } - - Expression::CircuitInit(circuit_init) => { - let defined_circuit_name_item = self.reduce_identifier(&circuit_init.name); - let members = circuit_init - .members - .iter() - .map(|definition| { - let definition_identifier = self.reduce_identifier(&definition.identifier); - let definition_expression = - definition.expression.as_ref().map(|expr| self.reduce_expression(&expr)); - (definition_identifier, definition_expression) - }) - .collect(); - - ExpressionMonoidItems::Circuit(defined_circuit_name_item, members) - } - Expression::CircuitMemberAccess(circuit_member_access) => { - let declared_circuit_name = self.reduce_expression(&circuit_member_access.circuit); - let circuit_member_name = self.reduce_identifier(&circuit_member_access.name); - - ExpressionMonoidItems::Binary(declared_circuit_name, circuit_member_name) - } - Expression::CircuitStaticFunctionAccess(circuit_static_func_access) => { - let declared_circuit_name = self.reduce_expression(&circuit_static_func_access.circuit); - let circuit_static_function_name = self.reduce_identifier(&circuit_static_func_access.name); - - ExpressionMonoidItems::Binary(declared_circuit_name, circuit_static_function_name) - } - - Expression::Call(call) => { - let function = self.reduce_expression(&call.function); - let function_arguments = call.arguments.iter().map(|x| self.reduce_expression(x)).collect(); - - ExpressionMonoidItems::FunctionCall(function, function_arguments) - } - - // TODO casts? - _ => ExpressionMonoidItems::Empty, - }; - self.reducer.reduce_expression(expression, items) - } -} diff --git a/ast/src/reducer/monoidal_reducer.rs b/ast/src/reducer/monoidal_reducer.rs deleted file mode 100644 index dc47e16ec8..0000000000 --- a/ast/src/reducer/monoidal_reducer.rs +++ /dev/null @@ -1,315 +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 . - -//! This module contains the reducer which iterates through ast nodes - converting them into -//! asg nodes and saving relevant information. - -use crate::{ - AssigneeAccess, - Circuit, - CircuitMember, - ConditionalStatement, - Expression, - Function, - FunctionInput, - FunctionInputVariable, - GroupCoordinate, - Identifier, - ImportStatement, - IntegerType, - Monoid, - Package, - Packages, - Program, - Statement, - Type, - ValueExpression, - VariableName, -}; -use indexmap::IndexMap; - -pub enum TypeMonoidItems { - None, - Tuple(Vec), - Array(T), - Identifier(T), -} - -pub enum CircuitMemberMonoidItems { - Variable { identifier: T, type_: T }, - Function(T), -} - -pub enum StatementMonoidItems { - Return(T), - Definition { - variables: T, - expression: T, - }, - Assign { - assignee: T, - assignee_accesses: Vec, - expression: T, - }, - Conditional(T), - Iteration { - identifier: T, - start: T, - stop: T, - statements: Vec, - }, - ConsoleAssert(T), - ConsoleFormat(Vec), - Expression(T), - Statements(Vec), -} - -pub enum AssigneeAccessItem { - Array(RangeItem), - Tuple, - Member(T), -} - -pub enum RangeItem { - Range(Option, Option), - Index(T), -} - -pub enum ExpressionMonoidItems { - Empty, - Unary(T), - Binary(T, T), - Triary(T, T, T), - FunctionCall(T, Vec), - ArrayAccess(T, T), - Circuit(T, Vec<(T, Option)>), - Var(Vec), - Value(T), -} - -pub enum ConditionStatementNextItem { - Nested(T), - End(Vec), -} - -pub enum FunctionInputItem { - InputKeyword, - SelfKeyword, - MutSelfKeyword, - Variable(T), -} - -pub enum ValueExpressionMonoidItems { - Address, - Boolean, - Field, - GroupSingle, - GroupTuple(T, T), - Implicit, - Integer(T), -} - -#[allow(unused_variables)] -pub trait MonoidalReducer { - fn reduce_program( - &mut self, - program: &Program, - expected_input: Vec, - imports: Vec, - circuits: IndexMap, - functions: IndexMap, - ) -> T { - let mut items = T::default() - .append_all(expected_input.into_iter()) - .append_all(imports.into_iter()); - - for (_, (identifier, value)) in circuits.into_iter() { - items = items.append(identifier).append(value); - } - for (_, (identifier, value)) in functions.into_iter() { - items = items.append(identifier).append(value); - } - items - } - - fn reduce_function_input(&mut self, input: &FunctionInput, item: FunctionInputItem) -> T { - match item { - FunctionInputItem::InputKeyword | FunctionInputItem::SelfKeyword | FunctionInputItem::MutSelfKeyword => { - T::default() - } - FunctionInputItem::Variable(variable) => variable, - } - } - - fn reduce_import_statement(&mut self, import: &ImportStatement, package: T) -> T { - package - } - - fn reduce_circuit(&mut self, circuit: &Circuit, circuit_name: T, members: Vec) -> T { - circuit_name.append_all(members.into_iter()) - } - - fn reduce_function( - &mut self, - function: &Function, - identifier: T, - input: Vec, - output: Option, - statements: Vec, - ) -> T { - identifier - .append_all(input.into_iter()) - .append_option(output) - .append_all(statements.into_iter()) - } - - fn reduce_identifier(&mut self, identifier: &Identifier) -> T { - T::default() - } - - fn reduce_integer_type(&mut self, integer_type: &IntegerType) -> T { - T::default() - } - - fn reduce_function_input_variable( - &mut self, - function_input_variable: &FunctionInputVariable, - identifier: T, - type_: T, - ) -> T { - identifier.append(type_) - } - - fn reduce_type(&mut self, type_: &Type, items: TypeMonoidItems) -> T { - match items { - TypeMonoidItems::Tuple(items) => T::default().append_all(items.into_iter()), - TypeMonoidItems::Array(item) => item, - TypeMonoidItems::Identifier(item) => item, - TypeMonoidItems::None => T::default(), - } - } - - fn reduce_packages(&mut self, packages: &Packages, name: T) -> T { - name - } - - fn reduce_package(&mut self, package: &Package, name: T) -> T { - name - } - - fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember, items: CircuitMemberMonoidItems) -> T { - match items { - CircuitMemberMonoidItems::Variable { identifier, type_ } => identifier.append(type_), - CircuitMemberMonoidItems::Function(identifier) => identifier, - } - } - - fn reduce_statement(&mut self, statement: &Statement, items: StatementMonoidItems) -> T { - match items { - StatementMonoidItems::Return(expression) => expression, - StatementMonoidItems::Definition { variables, expression } => variables.append(expression), - StatementMonoidItems::Assign { - assignee, - assignee_accesses, - expression, - } => assignee.append_all(assignee_accesses.into_iter()).append(expression), - StatementMonoidItems::Conditional(conditional) => conditional, - StatementMonoidItems::Iteration { - identifier, - start, - stop, - statements, - } => identifier.append(start).append(stop).append_all(statements.into_iter()), - StatementMonoidItems::ConsoleAssert(expression) => expression, - StatementMonoidItems::ConsoleFormat(parameters) => T::default().append_all(parameters.into_iter()), - StatementMonoidItems::Expression(expression) => expression, - StatementMonoidItems::Statements(statements) => T::default().append_all(statements.into_iter()), - } - } - - fn reduce_assignee_access(&mut self, assignee_access: &AssigneeAccess, item: AssigneeAccessItem) -> T { - match item { - AssigneeAccessItem::Array(assignee) => match assignee { - RangeItem::Index(index) => index, - RangeItem::Range(start, stop) => T::default().append_option(start).append_option(stop), - }, - AssigneeAccessItem::Tuple => T::default(), - AssigneeAccessItem::Member(identifier) => identifier, - } - } - - fn reduce_conditional_statement( - &mut self, - statement: &ConditionalStatement, - condition: T, - statements: Vec, - next: Option, - ) -> T { - condition.append_all(statements.into_iter()).append_option(next) - } - - fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: T) -> T { - identifier - } - - fn reduce_variable_names(&mut self, names: Vec) -> T { - T::default().append_all(names.into_iter()) - } - - fn reduce_group_coordinate(&mut self, group_coordinate: &GroupCoordinate) -> T { - T::default() - } - - fn reduce_value_expression( - &mut self, - value_expression: &ValueExpression, - value: ValueExpressionMonoidItems, - ) -> T { - match value { - ValueExpressionMonoidItems::GroupTuple(x, y) => x.append(y), - ValueExpressionMonoidItems::Integer(integer_type) => integer_type, - _ => T::default(), - } - } - - // please be careful matching on array access/range expressions, they can be ExpressionMonoidItems::BiTriary or ExpressionMonoidItems::Binary - fn reduce_expression(&mut self, expression: &Expression, items: ExpressionMonoidItems) -> T { - match items { - ExpressionMonoidItems::Empty => T::default(), - ExpressionMonoidItems::Unary(expression) => expression, - ExpressionMonoidItems::Binary(left, right) => left.append(right), - ExpressionMonoidItems::Triary(left, center, right) => left.append(center).append(right), - ExpressionMonoidItems::ArrayAccess(identifier, index) => identifier.append(index), - ExpressionMonoidItems::FunctionCall(identifier, arguments) => identifier.append_all(arguments.into_iter()), - ExpressionMonoidItems::Circuit(identifier, arguments) => { - let mut out = identifier; - for (key, value) in arguments.into_iter() { - match value { - Some(val) => { - out = out.append(key).append(val); - } - None => { - out = out.append(key); - } - } - } - out - } - ExpressionMonoidItems::Var(items) => T::default().append_all(items.into_iter()), - ExpressionMonoidItems::Value(value) => value, - } - } -} diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index a9fdb85148..5503448c5a 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -17,49 +17,7 @@ //! This module contains the reducer which iterates through ast nodes - converting them into //! asg nodes and saving relevant information. -use crate::{ - ArrayAccessExpression, - ArrayInitExpression, - ArrayInlineExpression, - ArrayRangeAccessExpression, - AssignStatement, - Assignee, - AssigneeAccess, - BinaryExpression, - Block, - CallExpression, - Circuit, - CircuitImpliedVariableDefinition, - CircuitInitExpression, - CircuitMember, - CircuitMemberAccessExpression, - CircuitStaticFunctionAccessExpression, - ConditionalStatement, - ConsoleFunction, - ConsoleStatement, - DefinitionStatement, - Expression, - ExpressionStatement, - FormattedString, - Function, - FunctionInput, - FunctionInputVariable, - Identifier, - ImportStatement, - IterationStatement, - PackageOrPackages, - Program, - ReconstructingReducer, - ReturnStatement, - SpreadOrExpression, - Statement, - TernaryExpression, - TupleAccessExpression, - TupleInitExpression, - Type, - UnaryExpression, - VariableName, -}; +use crate::*; pub struct ReconstructingDirector { reducer: R, @@ -70,430 +28,496 @@ impl ReconstructingDirector { Self { reducer } } + pub fn reduce_type(&mut self, type_: &Type) -> Type { + let new = match type_ { + // Data type wrappers + Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_)), dimensions.clone()), + Type::Tuple(types) => Type::Tuple(types.iter().map(|type_| self.reduce_type(type_)).collect()), + Type::Circuit(identifier) => Type::Circuit(self.reduce_identifier(identifier)), + _ => type_.clone(), + }; + + self.reducer.reduce_type(type_, new) + } + + // Expressions + pub fn reduce_expression(&mut self, expression: &Expression) -> Expression { + let new = match expression { + Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)), + Expression::Value(value) => Expression::Value(self.reduce_value(&value)), + Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary)), + Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary)), + Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary)), + Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast)), + + Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(&array_inline)), + Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(&array_init)), + Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(&array_access)), + Expression::ArrayRangeAccess(array_range_access) => { + Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access)) + } + + Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(&tuple_init)), + Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(&tuple_access)), + + Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(&circuit_init)), + Expression::CircuitMemberAccess(circuit_member_access) => { + Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access)) + } + Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => { + Expression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(&circuit_static_fn_access)) + } + + Expression::Call(call) => Expression::Call(self.reduce_call(&call)), + }; + + self.reducer.reduce_expression(expression, new) + } + + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { + self.reducer.reduce_identifier(identifier, identifier.span.clone()) + } + + pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> GroupTuple { + self.reducer.reduce_group_tuple(group_tuple, group_tuple.span.clone()) + } + + pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> GroupValue { + let new = match group_value { + GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)), + _ => group_value.clone(), + }; + + self.reducer.reduce_group_value(group_value, new) + } + + pub fn reduce_value(&mut self, value: &ValueExpression) -> ValueExpression { + let new = match value { + ValueExpression::Group(group_value) => { + ValueExpression::Group(Box::new(self.reduce_group_value(&group_value))) + } + _ => value.clone(), + }; + + self.reducer.reduce_value(value, new) + } + + pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> BinaryExpression { + let left = self.reduce_expression(&binary.left); + let right = self.reduce_expression(&binary.right); + + self.reducer + .reduce_binary(binary, left, right, binary.op.clone(), binary.span.clone()) + } + + pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> UnaryExpression { + let inner = self.reduce_expression(&unary.inner); + + self.reducer + .reduce_unary(unary, inner, unary.op.clone(), unary.span.clone()) + } + + pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> TernaryExpression { + let condition = self.reduce_expression(&ternary.condition); + let if_true = self.reduce_expression(&ternary.if_true); + let if_false = self.reduce_expression(&ternary.if_false); + + self.reducer + .reduce_ternary(ternary, condition, if_true, if_false, ternary.span.clone()) + } + + pub fn reduce_cast(&mut self, cast: &CastExpression) -> CastExpression { + let inner = self.reduce_expression(&cast.inner); + let target_type = cast.target_type.clone(); // TODO reduce + + self.reducer.reduce_cast(cast, inner, target_type, cast.span.clone()) + } + + pub fn reduce_array_inline(&mut self, array_inline: &ArrayInlineExpression) -> ArrayInlineExpression { + let elements = array_inline + .elements + .iter() + .map(|element| match element { + SpreadOrExpression::Expression(expression) => { + SpreadOrExpression::Expression(self.reduce_expression(expression)) + } + SpreadOrExpression::Spread(expression) => { + SpreadOrExpression::Spread(self.reduce_expression(expression)) + } + }) + .collect(); + + self.reducer + .reduce_array_inline(array_inline, elements, array_inline.span.clone()) + } + + pub fn reduce_array_init(&mut self, array_init: &ArrayInitExpression) -> ArrayInitExpression { + let element = self.reduce_expression(&array_init.element); + + self.reducer + .reduce_array_init(array_init, element, array_init.span.clone()) + } + + pub fn reduce_array_access(&mut self, array_access: &ArrayAccessExpression) -> ArrayAccessExpression { + let array = self.reduce_expression(&array_access.array); + let index = self.reduce_expression(&array_access.index); + + self.reducer + .reduce_array_access(array_access, array, index, array_access.span.clone()) + } + + pub fn reduce_array_range_access( + &mut self, + array_range_access: &ArrayRangeAccessExpression, + ) -> ArrayRangeAccessExpression { + let array = self.reduce_expression(&array_range_access.array); + let left = array_range_access + .left + .as_ref() + .map(|left| self.reduce_expression(left)); + let right = array_range_access + .right + .as_ref() + .map(|right| self.reduce_expression(right)); + + self.reducer + .reduce_array_range_access(array_range_access, array, left, right, array_range_access.span.clone()) + } + + pub fn reduce_tuple_init(&mut self, tuple_init: &TupleInitExpression) -> TupleInitExpression { + let elements = tuple_init + .elements + .iter() + .map(|expr| self.reduce_expression(expr)) + .collect(); + + self.reducer + .reduce_tuple_init(tuple_init, elements, tuple_init.span.clone()) + } + + pub fn reduce_tuple_access(&mut self, tuple_access: &TupleAccessExpression) -> TupleAccessExpression { + let tuple = self.reduce_expression(&tuple_access.tuple); + + self.reducer + .reduce_tuple_access(tuple_access, tuple, tuple_access.span.clone()) + } + + pub fn reduce_circuit_init(&mut self, circuit_init: &CircuitInitExpression) -> CircuitInitExpression { + let name = self.reduce_identifier(&circuit_init.name); + let members = circuit_init + .members + .iter() + .map(|definition| { + let identifier = self.reduce_identifier(&definition.identifier); + let expression = definition.expression.as_ref().map(|expr| self.reduce_expression(expr)); + + CircuitImpliedVariableDefinition { identifier, expression } + }) + .collect(); + + self.reducer + .reduce_circuit_init(circuit_init, name, members, circuit_init.span.clone()) + } + + pub fn reduce_circuit_member_access( + &mut self, + circuit_member_access: &CircuitMemberAccessExpression, + ) -> CircuitMemberAccessExpression { + let circuit = self.reduce_expression(&circuit_member_access.circuit); + let name = self.reduce_identifier(&circuit_member_access.name); + + self.reducer.reduce_circuit_member_access( + circuit_member_access, + circuit, + name, + circuit_member_access.span.clone(), + ) + } + + pub fn reduce_circuit_static_fn_access( + &mut self, + circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, + ) -> CircuitStaticFunctionAccessExpression { + let circuit = self.reduce_expression(&circuit_static_fn_access.circuit); + let name = self.reduce_identifier(&circuit_static_fn_access.name); + + self.reducer.reduce_circuit_static_fn_access( + circuit_static_fn_access, + circuit, + name, + circuit_static_fn_access.span.clone(), + ) + } + + pub fn reduce_call(&mut self, call: &CallExpression) -> CallExpression { + let function = self.reduce_expression(&call.function); + let arguments = call.arguments.iter().map(|expr| self.reduce_expression(expr)).collect(); + + self.reducer.reduce_call(call, function, arguments, call.span.clone()) + } + + // Statements + pub fn reduce_statement(&mut self, statement: &Statement) -> Statement { + let new = match statement { + Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)), + Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)), + Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)), + Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(&conditional)), + Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration)), + Statement::Console(console) => Statement::Console(self.reduce_console(&console)), + Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)), + Statement::Block(block) => Statement::Block(self.reduce_block(&block)), + }; + + self.reducer.reduce_statement(statement, new) + } + + pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> ReturnStatement { + let expression = self.reduce_expression(&return_statement.expression); + + self.reducer + .reduce_return(return_statement, expression, return_statement.span.clone()) + } + + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> VariableName { + let identifier = self.reduce_identifier(&variable_name.identifier); + + self.reducer + .reduce_variable_name(variable_name, identifier, variable_name.span.clone()) + } + + pub fn reduce_definition(&mut self, definition: &DefinitionStatement) -> DefinitionStatement { + let variable_names = definition + .variable_names + .iter() + .map(|variable_name| self.reduce_variable_name(variable_name)) + .collect(); + let type_ = definition.type_.as_ref().map(|inner| self.reduce_type(inner)); + let value = self.reduce_expression(&definition.value); + + self.reducer + .reduce_definition(definition, variable_names, type_, value, definition.span.clone()) + } + + pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> AssigneeAccess { + let new = match access { + AssigneeAccess::ArrayRange(left, right) => AssigneeAccess::ArrayRange( + left.as_ref().map(|expr| self.reduce_expression(expr)), + right.as_ref().map(|expr| self.reduce_expression(expr)), + ), + AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(&index)), + AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)), + _ => access.clone(), + }; + + self.reducer.reduce_assignee_access(access, new) + } + + pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Assignee { + let identifier = self.reduce_identifier(&assignee.identifier); + let accesses = assignee + .accesses + .iter() + .map(|access| self.reduce_assignee_access(access)) + .collect(); + + self.reducer + .reduce_assignee(assignee, identifier, accesses, assignee.span.clone()) + } + + pub fn reduce_assign(&mut self, assign: &AssignStatement) -> AssignStatement { + let assignee = self.reduce_assignee(&assign.assignee); + let value = self.reduce_expression(&assign.value); + + self.reducer.reduce_assign(assign, assignee, value, assign.span.clone()) + } + + pub fn reduce_conditional(&mut self, conditional: &ConditionalStatement) -> ConditionalStatement { + let condition = self.reduce_expression(&conditional.condition); + let block = self.reduce_block(&conditional.block); + let next = conditional + .next + .as_ref() + .map(|condition| self.reduce_statement(condition)); + + self.reducer + .reduce_conditional(conditional, condition, block, next, conditional.span.clone()) + } + + pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> IterationStatement { + let variable = self.reduce_identifier(&iteration.variable); + let start = self.reduce_expression(&iteration.start); + let stop = self.reduce_expression(&iteration.stop); + let block = self.reduce_block(&iteration.block); + + self.reducer + .reduce_iteration(iteration, variable, start, stop, block, iteration.span.clone()) + } + + pub fn reduce_console(&mut self, console_function_call: &ConsoleStatement) -> ConsoleStatement { + let function = match &console_function_call.function { + ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)), + ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { + let formatted = FormattedString { + parts: format.parts.clone(), + parameters: format + .parameters + .iter() + .map(|parameter| self.reduce_expression(parameter)) + .collect(), + span: format.span.clone(), + }; + match &console_function_call.function { + ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted), + ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), + ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted), + _ => unimplemented!(), // impossible + } + } + }; + + self.reducer + .reduce_console(console_function_call, function, console_function_call.span.clone()) + } + + pub fn reduce_expression_statement(&mut self, expression: &ExpressionStatement) -> ExpressionStatement { + let inner_expression = self.reduce_expression(&expression.expression); + self.reducer + .reduce_expression_statement(expression, inner_expression, expression.span.clone()) + } + + pub fn reduce_block(&mut self, block: &Block) -> Block { + let statements = block + .statements + .iter() + .map(|statement| self.reduce_statement(statement)) + .collect(); + + self.reducer.reduce_block(block, statements, block.span.clone()) + } + + // Program pub fn reduce_program(&mut self, program: &Program) -> Program { let inputs = program .expected_input .iter() - .filter_map(|x| self.reduce_function_input(x)) + .map(|input| self.reduce_function_input(input)) .collect(); let imports = program .imports .iter() - .filter_map(|x| self.reduce_import_statement(x)) + .map(|import| self.reduce_import(import)) .collect(); let circuits = program .circuits .iter() - .filter_map(|(identifier, circuit)| { - Some((self.reduce_identifier(identifier), self.reduce_circuit(circuit)?)) - }) + .map(|(identifier, circuit)| (self.reduce_identifier(identifier), self.reduce_circuit(circuit))) .collect(); let functions = program .functions .iter() - .filter_map(|(identifier, function)| { - Some((self.reduce_identifier(identifier), self.reduce_function(function)?)) - }) + .map(|(identifier, function)| (self.reduce_identifier(identifier), self.reduce_function(function))) .collect(); self.reducer .reduce_program(program, inputs, imports, circuits, functions) } - pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Option { - let item = match input { - FunctionInput::InputKeyword(input_keyword) => FunctionInput::InputKeyword(input_keyword.clone()), - FunctionInput::SelfKeyword(self_keyword) => FunctionInput::SelfKeyword(self_keyword.clone()), - FunctionInput::MutSelfKeyword(mut_self_keyword) => FunctionInput::MutSelfKeyword(mut_self_keyword.clone()), + pub fn reduce_function_input_variable(&mut self, variable: &FunctionInputVariable) -> FunctionInputVariable { + let identifier = self.reduce_identifier(&variable.identifier); + let type_ = self.reduce_type(&variable.type_); + + self.reducer + .reduce_function_input_variable(variable, identifier, type_, variable.span.clone()) + } + + pub fn reduce_function_input(&mut self, input: &FunctionInput) -> FunctionInput { + let new = match input { FunctionInput::Variable(function_input_variable) => { FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)) } + _ => input.clone(), }; - self.reducer.reduce_function_input(input, item) + self.reducer.reduce_function_input(input, new) } - pub fn reduce_import_statement(&mut self, import: &ImportStatement) -> Option { - let package = self.reduce_package(&import.package_or_packages); + pub fn reduce_package_or_packages(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { + let new = match package_or_packages { + PackageOrPackages::Package(package) => PackageOrPackages::Package(Package { + name: self.reduce_identifier(&package.name), + access: package.access.clone(), + span: package.span.clone(), + }), + PackageOrPackages::Packages(packages) => PackageOrPackages::Packages(Packages { + name: self.reduce_identifier(&packages.name), + accesses: packages.accesses.clone(), + span: packages.span.clone(), + }), + }; - self.reducer.reduce_import_statement(import, package) + self.reducer.reduce_package_or_packages(package_or_packages, new) } - pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Option { + pub fn reduce_import(&mut self, import: &ImportStatement) -> ImportStatement { + let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages); + + self.reducer + .reduce_import(import, package_or_packages, import.span.clone()) + } + + pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> CircuitMember { + let new = match circuit_member { + CircuitMember::CircuitVariable(identifier, type_) => { + CircuitMember::CircuitVariable(self.reduce_identifier(&identifier), self.reduce_type(&type_)) + } + CircuitMember::CircuitFunction(function) => CircuitMember::CircuitFunction(self.reduce_function(&function)), + }; + + self.reducer.reduce_circuit_member(circuit_member, new) + } + + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Circuit { let circuit_name = self.reduce_identifier(&circuit.circuit_name); let members = circuit .members .iter() - .filter_map(|x| self.reduce_circuit_member(x)) + .map(|member| self.reduce_circuit_member(member)) .collect(); self.reducer.reduce_circuit(circuit, circuit_name, members) } - pub fn reduce_function(&mut self, function: &Function) -> Option { + fn reduce_annotation(&mut self, annotation: &Annotation) -> Annotation { + let name = self.reduce_identifier(&annotation.name); + + self.reducer + .reduce_annotation(annotation, annotation.span.clone(), name) + } + + pub fn reduce_function(&mut self, function: &Function) -> Function { let identifier = self.reduce_identifier(&function.identifier); - let annotations = function.annotations.clone(); // TODO reduce + let annotations = function + .annotations + .iter() + .map(|annotation| self.reduce_annotation(annotation)) + .collect(); let input = function .input .iter() - .filter_map(|x| self.reduce_function_input(x)) + .map(|input| self.reduce_function_input(input)) .collect(); - let output = function.output.as_ref().map(|x| self.reduce_type(x)); - let block = Block { - statements: function - .block - .statements - .iter() - .map(|x| self.reduce_statement(x)) - .collect(), - span: function.block.span.clone(), - }; + let output = function.output.as_ref().map(|output| self.reduce_type(output)); + let block = self.reduce_block(&function.block); - self.reducer - .reduce_function(function, annotations, identifier, input, output, block) - } - - pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { - self.reducer.reduce_identifier(identifier) - } - - pub fn reduce_function_input_variable( - &mut self, - function_input_variable: &FunctionInputVariable, - ) -> FunctionInputVariable { - let identifier = self.reduce_identifier(&function_input_variable.identifier); - let type_ = self.reduce_type(&function_input_variable.type_); - - self.reducer - .reduce_function_input_variable(function_input_variable, identifier, type_) - } - - pub fn reduce_type(&mut self, type_: &Type) -> Type { - let items = match type_ { - // Data type wrappers - Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_)), dimensions.clone()), - Type::Tuple(types) => Type::Tuple(types.iter().map(|x| self.reduce_type(x)).collect()), - Type::Circuit(identifier) => Type::Circuit(self.reduce_identifier(identifier)), - _ => type_.clone(), - }; - - self.reducer.reduce_type(type_, items) - } - - pub fn reduce_package(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { - self.reducer.reduce_package(package_or_packages) - } - - pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Option { - let items = match circuit_member { - CircuitMember::CircuitVariable(identifier, type_) => { - CircuitMember::CircuitVariable(self.reduce_identifier(identifier), self.reduce_type(type_)) - } - CircuitMember::CircuitFunction(function) => CircuitMember::CircuitFunction(self.reduce_function(function)?), - }; - - self.reducer.reduce_circuit_member(circuit_member, items) - } - - pub fn reduce_statement(&mut self, statement: &Statement) -> Statement { - let items = match statement { - Statement::Return(return_statement) => Statement::Return(ReturnStatement { - expression: self.reduce_expression(&return_statement.expression), - span: return_statement.span.clone(), - }), - Statement::Definition(definition) => Statement::Definition(DefinitionStatement { - declaration_type: definition.declaration_type.clone(), - variable_names: definition - .variable_names - .iter() - .map(|variable_name| self.reduce_variable_name(variable_name)) - .collect(), - type_: definition.type_.as_ref().map(|inner| self.reduce_type(&inner)), - value: self.reduce_expression(&definition.value), - span: definition.span.clone(), - }), - Statement::Assign(assign) => Statement::Assign(AssignStatement { - operation: assign.operation.clone(), - assignee: Assignee { - identifier: self.reduce_identifier(&assign.assignee.identifier), - accesses: assign - .assignee - .accesses - .iter() - .filter_map(|x| self.reduce_assignee_access(x)) - .collect(), - span: assign.assignee.span.clone(), - }, - value: self.reduce_expression(&assign.value), - span: assign.span.clone(), - }), - Statement::Conditional(conditional) => { - Statement::Conditional(self.reduce_conditional_statement(conditional)) - } - Statement::Iteration(iteration) => { - Statement::Iteration(IterationStatement { - variable: self.reduce_identifier(&iteration.variable), - start: self.reduce_expression(&iteration.start), - stop: self.reduce_expression(&iteration.stop), - block: Block { - statements: iteration - .block - .statements - .iter() - .map(|statement| self.reduce_statement(statement)) - .collect(), - span: iteration.block.span.clone(), - }, // TODO reduce block that isn't in a statement - span: iteration.span.clone(), - }) - } - Statement::Console(console_function_call) => { - let function = match &console_function_call.function { - ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)), - ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { - let formatted = FormattedString { - parts: format.parts.clone(), - parameters: format - .parameters - .iter() - .map(|parameter| self.reduce_expression(¶meter)) - .collect(), - span: format.span.clone(), - }; - match &console_function_call.function { - ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted), - ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), - ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted), - _ => unimplemented!(), // impossible - } - } - }; - Statement::Console(ConsoleStatement { - function, - span: console_function_call.span.clone(), - }) - } - Statement::Expression(expression) => Statement::Expression(ExpressionStatement { - expression: self.reduce_expression(&expression.expression), - span: expression.span.clone(), - }), - Statement::Block(block) => Statement::Block(Block { - statements: block - .statements - .iter() - .map(|statement| self.reduce_statement(statement)) - .collect(), - span: block.span.clone(), - }), - }; - - self.reducer.reduce_statement(statement, items) - } - - pub fn reduce_assignee_access(&mut self, assignee_access: &AssigneeAccess) -> Option { - let item = match assignee_access { - AssigneeAccess::ArrayRange(start, stop) => { - let start_item = start.as_ref().map(|x| self.reduce_expression(x)); - let stop_item = stop.as_ref().map(|x| self.reduce_expression(x)); - AssigneeAccess::ArrayRange(start_item, stop_item) - } - AssigneeAccess::ArrayIndex(expression) => AssigneeAccess::ArrayIndex(self.reduce_expression(&expression)), - AssigneeAccess::Tuple(number, span) => AssigneeAccess::Tuple(number.clone(), span.clone()), - AssigneeAccess::Member(identifier) => { - let identifier = self.reduce_identifier(identifier); - AssigneeAccess::Member(identifier) - } - }; - - self.reducer.reduce_assignee_access(assignee_access, item) - } - - pub fn reduce_conditional_statement(&mut self, statement: &ConditionalStatement) -> ConditionalStatement { - let condition = self.reduce_expression(&statement.condition); - let statements = Block { - statements: statement - .block - .statements - .iter() - .map(|x| self.reduce_statement(x)) - .collect(), - span: statement.block.span.clone(), - }; - let next = statement.next.as_ref().map(|x| self.reduce_statement(x)); - - self.reducer - .reduce_conditional_statement(statement, condition, statements, next) - } - - pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> VariableName { - let identifier = self.reduce_identifier(&variable_name.identifier); - - self.reducer.reduce_variable_name(variable_name, identifier) - } - - pub fn reduce_expression(&mut self, expression: &Expression) -> Expression { - let items = match expression { - Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)), - // Expression::Value(value) => Expression::Value(self.reduce_expression(value.)) - Expression::Binary(binary) => { - let left = Box::new(self.reduce_expression(&binary.left)); - let right = Box::new(self.reduce_expression(&binary.right)); - - Expression::Binary(BinaryExpression { - left, - right, - op: binary.op.clone(), - span: binary.span.clone(), - }) - } - Expression::Unary(unary) => { - let inner = Box::new(self.reduce_expression(&unary.inner)); - - Expression::Unary(UnaryExpression { - inner, - op: unary.op.clone(), - span: unary.span.clone(), - }) - } - Expression::Ternary(ternary) => { - let condition = Box::new(self.reduce_expression(&ternary.condition)); - let if_true = Box::new(self.reduce_expression(&ternary.if_true)); - let if_false = Box::new(self.reduce_expression(&ternary.if_false)); - - Expression::Ternary(TernaryExpression { - condition, - if_true, - if_false, - span: ternary.span.clone(), - }) - } - - Expression::ArrayInline(array_inline) => { - let elements = array_inline - .elements - .iter() - .map(|x| match x { - SpreadOrExpression::Expression(expression) => { - SpreadOrExpression::Expression(self.reduce_expression(expression)) - } - SpreadOrExpression::Spread(expression) => { - SpreadOrExpression::Spread(self.reduce_expression(expression)) - } - }) - .collect(); - - Expression::ArrayInline(ArrayInlineExpression { - elements, - span: array_inline.span.clone(), - }) - } - Expression::ArrayInit(array_init) => { - let element = Box::new(self.reduce_expression(&array_init.element)); - - Expression::ArrayInit(ArrayInitExpression { - element, - dimensions: array_init.dimensions.clone(), - span: array_init.span.clone(), - }) - } - Expression::ArrayAccess(array_access) => { - let array = Box::new(self.reduce_expression(&array_access.array)); - let index = Box::new(self.reduce_expression(&array_access.index)); - Expression::ArrayAccess(ArrayAccessExpression { - array, - index, - span: array_access.span.clone(), - }) - } - Expression::ArrayRangeAccess(array_range_access) => { - let array = Box::new(self.reduce_expression(&array_range_access.array)); - let left = array_range_access - .left - .as_ref() - .map(|left| Box::new(self.reduce_expression(&left))); - let right = array_range_access - .right - .as_ref() - .map(|right| Box::new(self.reduce_expression(&right))); - - Expression::ArrayRangeAccess(ArrayRangeAccessExpression { - array, - left, - right, - span: array_range_access.span.clone(), - }) - } - - Expression::TupleInit(tuple_init) => { - let elements = tuple_init.elements.iter().map(|x| self.reduce_expression(x)).collect(); - - Expression::TupleInit(TupleInitExpression { - elements, - span: tuple_init.span.clone(), - }) - } - Expression::TupleAccess(tuple_access) => { - let tuple = Box::new(self.reduce_expression(&tuple_access.tuple)); - - Expression::TupleAccess(TupleAccessExpression { - tuple, - index: tuple_access.index.clone(), - span: tuple_access.span.clone(), - }) - } - Expression::CircuitInit(circuit_init) => { - let name = self.reduce_identifier(&circuit_init.name); - let members = circuit_init - .members - .iter() - .map(|definition| { - let identifier = self.reduce_identifier(&definition.identifier); - let expression = definition.expression.as_ref().map(|expr| self.reduce_expression(&expr)); - - CircuitImpliedVariableDefinition { identifier, expression } - }) - .collect(); - - Expression::CircuitInit(CircuitInitExpression { - name, - members, - span: circuit_init.span.clone(), - }) - } - Expression::CircuitMemberAccess(circuit_member_access) => { - let circuit = Box::new(self.reduce_expression(&circuit_member_access.circuit)); - let name = self.reduce_identifier(&circuit_member_access.name); - - Expression::CircuitMemberAccess(CircuitMemberAccessExpression { - circuit, - name, - span: circuit_member_access.span.clone(), - }) - } - Expression::CircuitStaticFunctionAccess(circuit_static_func_access) => { - let circuit = Box::new(self.reduce_expression(&circuit_static_func_access.circuit)); - let name = self.reduce_identifier(&circuit_static_func_access.name); - - Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { - circuit, - name, - span: circuit_static_func_access.span.clone(), - }) - } - Expression::Call(call) => { - let function = Box::new(self.reduce_expression(&call.function)); - let arguments = call.arguments.iter().map(|x| self.reduce_expression(x)).collect(); - - Expression::Call(CallExpression { - function, - arguments, - span: call.span.clone(), - }) - } - - x => x.clone(), // leaf nodes we dont reconstruct - }; - - self.reducer.reduce_expression(expression, items) + self.reducer.reduce_function( + function, + identifier, + annotations, + input, + output, + block, + function.span.clone(), + ) } } diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 472ddcecbd..ce9cbd1e49 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -14,36 +14,364 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -//! This module contains the reducer which iterates through ast nodes - converting them into -//! asg nodes and saving relevant information. - -use crate::{ - Annotation, - AssigneeAccess, - Block, - Circuit, - CircuitMember, - ConditionalStatement, - Expression, - Function, - FunctionInput, - FunctionInputVariable, - Identifier, - ImportStatement, - Package, - PackageOrPackages, - Packages, - Program, - Statement, - Type, - VariableName, -}; +use crate::*; use indexmap::IndexMap; -#[allow(unused_variables)] -#[allow(clippy::redundant_closure)] // Clippy bug line 188 +// Needed to fix clippy bug. +#[allow(clippy::redudant_closure)] pub trait ReconstructingReducer { - // ciruits/functions/tests map identifier -> (identifier_item, value_item) + fn reduce_type(&mut self, _type_: &Type, new: Type) -> Type { + new + } + + // Expressions + fn reduce_expression(&mut self, _expression: &Expression, new: Expression) -> Expression { + new + } + + fn reduce_identifier(&mut self, identifier: &Identifier, span: Span) -> Identifier { + Identifier { + name: identifier.name.clone(), + span, + } + } + + fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple, span: Span) -> GroupTuple { + GroupTuple { + x: group_tuple.x.clone(), + y: group_tuple.y.clone(), + span, + } + } + + fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> GroupValue { + new + } + + fn reduce_value(&mut self, _value: &ValueExpression, new: ValueExpression) -> ValueExpression { + new + } + + fn reduce_binary( + &mut self, + _binary: &BinaryExpression, + left: Expression, + right: Expression, + op: BinaryOperation, + span: Span, + ) -> BinaryExpression { + BinaryExpression { + left: Box::new(left), + right: Box::new(right), + op, + span, + } + } + + fn reduce_unary( + &mut self, + _unary: &UnaryExpression, + inner: Expression, + op: UnaryOperation, + span: Span, + ) -> UnaryExpression { + UnaryExpression { + inner: Box::new(inner), + op, + span, + } + } + + fn reduce_ternary( + &mut self, + _ternary: &TernaryExpression, + condition: Expression, + if_true: Expression, + if_false: Expression, + span: Span, + ) -> TernaryExpression { + TernaryExpression { + condition: Box::new(condition), + if_true: Box::new(if_true), + if_false: Box::new(if_false), + span, + } + } + + fn reduce_cast( + &mut self, + _cast: &CastExpression, + inner: Expression, + target_type: Type, + span: Span, + ) -> CastExpression { + CastExpression { + inner: Box::new(inner), + target_type, + span, + } + } + + fn reduce_array_inline( + &mut self, + _array_inline: &ArrayInlineExpression, + elements: Vec, + span: Span, + ) -> ArrayInlineExpression { + ArrayInlineExpression { elements, span } + } + + fn reduce_array_init( + &mut self, + array_init: &ArrayInitExpression, + element: Expression, + span: Span, + ) -> ArrayInitExpression { + ArrayInitExpression { + element: Box::new(element), + dimensions: array_init.dimensions.clone(), + span, + } + } + + fn reduce_array_access( + &mut self, + _array_access: &ArrayAccessExpression, + array: Expression, + index: Expression, + span: Span, + ) -> ArrayAccessExpression { + ArrayAccessExpression { + array: Box::new(array), + index: Box::new(index), + span, + } + } + + fn reduce_array_range_access( + &mut self, + _array_rage_access: &ArrayRangeAccessExpression, + array: Expression, + left: Option, + right: Option, + span: Span, + ) -> ArrayRangeAccessExpression { + ArrayRangeAccessExpression { + array: Box::new(array), + left: left.map(|expr| Box::new(expr)), + right: right.map(|expr| Box::new(expr)), + span, + } + } + + fn reduce_tuple_init( + &mut self, + _tuple_init: &TupleInitExpression, + elements: Vec, + span: Span, + ) -> TupleInitExpression { + TupleInitExpression { elements, span } + } + + fn reduce_tuple_access( + &mut self, + tuple_access: &TupleAccessExpression, + tuple: Expression, + span: Span, + ) -> TupleAccessExpression { + TupleAccessExpression { + tuple: Box::new(tuple), + index: tuple_access.index.clone(), + span, + } + } + + fn reduce_circuit_init( + &mut self, + _circuit_init: &CircuitInitExpression, + name: Identifier, + members: Vec, + span: Span, + ) -> CircuitInitExpression { + CircuitInitExpression { name, members, span } + } + + fn reduce_circuit_member_access( + &mut self, + _circuit_member_access: &CircuitMemberAccessExpression, + circuit: Expression, + name: Identifier, + span: Span, + ) -> CircuitMemberAccessExpression { + CircuitMemberAccessExpression { + circuit: Box::new(circuit), + name, + span, + } + } + + fn reduce_circuit_static_fn_access( + &mut self, + _circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, + circuit: Expression, + name: Identifier, + span: Span, + ) -> CircuitStaticFunctionAccessExpression { + CircuitStaticFunctionAccessExpression { + circuit: Box::new(circuit), + name, + span, + } + } + + fn reduce_call( + &mut self, + _call: &CallExpression, + function: Expression, + arguments: Vec, + span: Span, + ) -> CallExpression { + CallExpression { + function: Box::new(function), + arguments, + span, + } + } + + // Statements + fn reduce_statement(&mut self, _statement: &Statement, new: Statement) -> Statement { + new + } + + fn reduce_return( + &mut self, + _return_statement: &ReturnStatement, + expression: Expression, + span: Span, + ) -> ReturnStatement { + ReturnStatement { expression, span } + } + + fn reduce_variable_name( + &mut self, + variable_name: &VariableName, + identifier: Identifier, + span: Span, + ) -> VariableName { + VariableName { + mutable: variable_name.mutable.clone(), + identifier, + span, + } + } + + fn reduce_definition( + &mut self, + definition: &DefinitionStatement, + variable_names: Vec, + type_: Option, + value: Expression, + span: Span, + ) -> DefinitionStatement { + DefinitionStatement { + declaration_type: definition.declaration_type.clone(), + variable_names, + type_, + value, + span, + } + } + + fn reduce_assignee_access(&mut self, _access: &AssigneeAccess, new: AssigneeAccess) -> AssigneeAccess { + new + } + + fn reduce_assignee( + &mut self, + _assignee: &Assignee, + identifier: Identifier, + accesses: Vec, + span: Span, + ) -> Assignee { + Assignee { + identifier, + accesses, + span, + } + } + + fn reduce_assign( + &mut self, + assign: &AssignStatement, + assignee: Assignee, + value: Expression, + span: Span, + ) -> AssignStatement { + AssignStatement { + operation: assign.operation.clone(), + assignee, + value, + span, + } + } + + fn reduce_conditional( + &mut self, + _conditional: &ConditionalStatement, + condition: Expression, + block: Block, + statement: Option, + span: Span, + ) -> ConditionalStatement { + ConditionalStatement { + condition, + block, + next: statement.map(|statement| Box::new(statement)), + span, + } + } + + fn reduce_iteration( + &mut self, + _iteration: &IterationStatement, + variable: Identifier, + start: Expression, + stop: Expression, + block: Block, + span: Span, + ) -> IterationStatement { + IterationStatement { + variable, + start, + stop, + block, + span, + } + } + + fn reduce_console( + &mut self, + _console: &ConsoleStatement, + function: ConsoleFunction, + span: Span, + ) -> ConsoleStatement { + ConsoleStatement { function, span } + } + + fn reduce_expression_statement( + &mut self, + _expression_statement: &ExpressionStatement, + expression: Expression, + span: Span, + ) -> ExpressionStatement { + ExpressionStatement { expression, span } + } + + fn reduce_block(&mut self, _block: &Block, statements: Vec, span: Span) -> Block { + Block { statements, span } + } + + // Program fn reduce_program( &mut self, program: &Program, @@ -61,135 +389,80 @@ pub trait ReconstructingReducer { } } - fn reduce_function_input(&mut self, input: &FunctionInput, item: FunctionInput) -> Option { - Some(item) - } - - fn reduce_import_statement( - &mut self, - import: &ImportStatement, - package_or_packages: PackageOrPackages, - ) -> Option { - Some(ImportStatement { - package_or_packages, - span: import.span.clone(), - }) - } - - fn reduce_circuit( - &mut self, - circuit: &Circuit, - circuit_name: Identifier, - members: Vec, - ) -> Option { - Some(Circuit { circuit_name, members }) - } - - fn reduce_function( - &mut self, - function: &Function, - annotations: Vec, - identifier: Identifier, - input: Vec, - output: Option, - block: Block, - ) -> Option { - Some(Function { - annotations, - identifier, - input, - output, - block, - span: function.span.clone(), - }) - } - - fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { - identifier.clone() - } - fn reduce_function_input_variable( &mut self, - function_input_variable: &FunctionInputVariable, + variable: &FunctionInputVariable, identifier: Identifier, type_: Type, + span: Span, ) -> FunctionInputVariable { FunctionInputVariable { identifier, - const_: function_input_variable.const_, - mutable: function_input_variable.mutable, + const_: variable.const_.clone(), + mutable: variable.mutable, type_, - span: function_input_variable.span.clone(), + span, } } - fn reduce_type(&mut self, type_: &Type, items: Type) -> Type { - items + fn reduce_function_input(&mut self, _input: &FunctionInput, new: FunctionInput) -> FunctionInput { + new } - fn reduce_package(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { - match package_or_packages { - PackageOrPackages::Package(package) => { - let name = self.reduce_identifier(&package.name); + fn reduce_package_or_packages( + &mut self, + _package_or_packages: &PackageOrPackages, + new: PackageOrPackages, + ) -> PackageOrPackages { + new + } - PackageOrPackages::Package(Package { - name, - access: package.access.clone(), - span: package.span.clone(), - }) - } - PackageOrPackages::Packages(packages) => { - let name = self.reduce_identifier(&packages.name); - - PackageOrPackages::Packages(Packages { - name, - accesses: packages.accesses.clone(), - span: packages.span.clone(), - }) - } + fn reduce_import( + &mut self, + _import: &ImportStatement, + package_or_packages: PackageOrPackages, + span: Span, + ) -> ImportStatement { + ImportStatement { + package_or_packages, + span, } } - fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember, items: CircuitMember) -> Option { - Some(items) + fn reduce_circuit_member(&mut self, _circuit_member: &CircuitMember, new: CircuitMember) -> CircuitMember { + new } - fn reduce_statement(&mut self, statement: &Statement, items: Statement) -> Statement { - items + fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { + Circuit { circuit_name, members } } - fn reduce_assignee_access( + fn reduce_annotation(&mut self, annotation: &Annotation, span: Span, name: Identifier) -> Annotation { + Annotation { + span, + name, + arguments: annotation.arguments.clone(), + } + } + + #[allow(clippy::too_many_arguments)] + fn reduce_function( &mut self, - assignee_access: &AssigneeAccess, - item: AssigneeAccess, - ) -> Option { - Some(item) - } - - fn reduce_conditional_statement( - &mut self, - statement: &ConditionalStatement, - condition: Expression, + _function: &Function, + identifier: Identifier, + annotations: Vec, + input: Vec, + output: Option, block: Block, - next: Option, - ) -> ConditionalStatement { - ConditionalStatement { - condition, - block, - next: next.map(|item| Box::new(item)), - span: statement.span.clone(), - } - } - - fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> VariableName { - VariableName { - mutable: variable_name.mutable, + span: Span, + ) -> Function { + Function { identifier, - span: variable_name.span.clone(), + annotations, + input, + output, + block, + span, } } - - fn reduce_expression(&mut self, expression: &Expression, items: Expression) -> Expression { - items - } } From e302f839ed3a82d1b1f054df0fe3b8eee5b34eae Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 14:34:20 -0500 Subject: [PATCH 07/40] fix spelling --- ast/src/reducer/reconstructing_reducer.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index ce9cbd1e49..363f6e58fd 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -18,7 +18,7 @@ use crate::*; use indexmap::IndexMap; // Needed to fix clippy bug. -#[allow(clippy::redudant_closure)] +#[allow(clippy::redundant_closure)] pub trait ReconstructingReducer { fn reduce_type(&mut self, _type_: &Type, new: Type) -> Type { new @@ -259,7 +259,7 @@ pub trait ReconstructingReducer { span: Span, ) -> VariableName { VariableName { - mutable: variable_name.mutable.clone(), + mutable: variable_name.mutable, identifier, span, } @@ -398,7 +398,7 @@ pub trait ReconstructingReducer { ) -> FunctionInputVariable { FunctionInputVariable { identifier, - const_: variable.const_.clone(), + const_: variable.const_, mutable: variable.mutable, type_, span, From 4185f6f6d21d3f7b375b340c55066d76bce19987 Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 16:19:07 -0500 Subject: [PATCH 08/40] array types and expressions expanded --- ast/src/reducer/canonicalization.rs | 81 ++++++++- ast/src/reducer/reconstructing_director.rs | 101 ++++------- ast/src/reducer/reconstructing_reducer.rs | 198 ++++++++------------- 3 files changed, 185 insertions(+), 195 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index bab7238090..a7b3131206 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -15,6 +15,7 @@ // along with the Leo library. If not, see . use crate::*; +use indexmap::IndexMap; pub struct Canonicalizer; @@ -172,15 +173,79 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { - Circuit { - circuit_name: circuit_name.clone(), - members: members - .iter() - .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) - .collect(), + fn reduce_type(&mut self, _type_: &Type, new: Type) -> Type { + match new { + Type::Array(_, mut dimensions) => { + // TODO need to throw errors in all these. + // Throw error if dimensions is empty. + let mut next = Type::Array( + Box::new(Type::Group), + ArrayDimensions(vec![dimensions.remove_last().unwrap()]), + ); + let mut array = next.clone(); + loop { + if dimensions.is_empty() { + break; + } + + array = Type::Array(Box::new(next), ArrayDimensions(vec![dimensions.remove_last().unwrap()])); + next = array.clone(); + } + + array + } + _ => new.clone(), } } - // fn reduce_program(program: &Program, expected_input: Vec, imports: Vec, circuits: IndexMap, functions: IndexMap) + fn reduce_array_init(&mut self, array_init: &ArrayInitExpression, element: Expression) -> ArrayInitExpression { + // TODO ERROR HERE if len is 0 + let element = Box::new(element); + + if array_init.dimensions.0.len() == 1 { + return ArrayInitExpression { + element, + dimensions: array_init.dimensions.clone(), + span: array_init.span.clone(), + }; + } + + let mut dimensions = array_init.dimensions.clone(); + + let mut next = Expression::ArrayInit(ArrayInitExpression { + element, + dimensions: ArrayDimensions(vec![dimensions.remove_last().unwrap()]), + span: array_init.span.clone(), + }); + + let mut outer_element = Box::new(next.clone()); + for (index, dimension) in dimensions.0.iter().rev().enumerate() { + if index == dimensions.0.len() - 1 { + break; + } + + next = Expression::ArrayInit(ArrayInitExpression { + element: outer_element, + dimensions: ArrayDimensions(vec![dimension.clone()]), + span: array_init.span.clone(), + }); + outer_element = Box::new(next.clone()); + } + + ArrayInitExpression { + element: outer_element, + dimensions: ArrayDimensions(vec![dimensions.remove_first().unwrap()]), + span: array_init.span.clone(), + } + } + + // fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { + // Circuit { + // circuit_name: circuit_name.clone(), + // members: members + // .iter() + // .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) + // .collect(), + // } + // } } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 5503448c5a..ebc1986e41 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -75,11 +75,11 @@ impl ReconstructingDirector { } pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { - self.reducer.reduce_identifier(identifier, identifier.span.clone()) + self.reducer.reduce_identifier(identifier) } pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> GroupTuple { - self.reducer.reduce_group_tuple(group_tuple, group_tuple.span.clone()) + self.reducer.reduce_group_tuple(group_tuple) } pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> GroupValue { @@ -106,15 +106,13 @@ impl ReconstructingDirector { let left = self.reduce_expression(&binary.left); let right = self.reduce_expression(&binary.right); - self.reducer - .reduce_binary(binary, left, right, binary.op.clone(), binary.span.clone()) + self.reducer.reduce_binary(binary, left, right, binary.op.clone()) } pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> UnaryExpression { let inner = self.reduce_expression(&unary.inner); - self.reducer - .reduce_unary(unary, inner, unary.op.clone(), unary.span.clone()) + self.reducer.reduce_unary(unary, inner, unary.op.clone()) } pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> TernaryExpression { @@ -122,15 +120,14 @@ impl ReconstructingDirector { let if_true = self.reduce_expression(&ternary.if_true); let if_false = self.reduce_expression(&ternary.if_false); - self.reducer - .reduce_ternary(ternary, condition, if_true, if_false, ternary.span.clone()) + self.reducer.reduce_ternary(ternary, condition, if_true, if_false) } pub fn reduce_cast(&mut self, cast: &CastExpression) -> CastExpression { let inner = self.reduce_expression(&cast.inner); let target_type = cast.target_type.clone(); // TODO reduce - self.reducer.reduce_cast(cast, inner, target_type, cast.span.clone()) + self.reducer.reduce_cast(cast, inner, target_type) } pub fn reduce_array_inline(&mut self, array_inline: &ArrayInlineExpression) -> ArrayInlineExpression { @@ -147,23 +144,20 @@ impl ReconstructingDirector { }) .collect(); - self.reducer - .reduce_array_inline(array_inline, elements, array_inline.span.clone()) + self.reducer.reduce_array_inline(array_inline, elements) } pub fn reduce_array_init(&mut self, array_init: &ArrayInitExpression) -> ArrayInitExpression { let element = self.reduce_expression(&array_init.element); - self.reducer - .reduce_array_init(array_init, element, array_init.span.clone()) + self.reducer.reduce_array_init(array_init, element) } pub fn reduce_array_access(&mut self, array_access: &ArrayAccessExpression) -> ArrayAccessExpression { let array = self.reduce_expression(&array_access.array); let index = self.reduce_expression(&array_access.index); - self.reducer - .reduce_array_access(array_access, array, index, array_access.span.clone()) + self.reducer.reduce_array_access(array_access, array, index) } pub fn reduce_array_range_access( @@ -181,7 +175,7 @@ impl ReconstructingDirector { .map(|right| self.reduce_expression(right)); self.reducer - .reduce_array_range_access(array_range_access, array, left, right, array_range_access.span.clone()) + .reduce_array_range_access(array_range_access, array, left, right) } pub fn reduce_tuple_init(&mut self, tuple_init: &TupleInitExpression) -> TupleInitExpression { @@ -191,15 +185,13 @@ impl ReconstructingDirector { .map(|expr| self.reduce_expression(expr)) .collect(); - self.reducer - .reduce_tuple_init(tuple_init, elements, tuple_init.span.clone()) + self.reducer.reduce_tuple_init(tuple_init, elements) } pub fn reduce_tuple_access(&mut self, tuple_access: &TupleAccessExpression) -> TupleAccessExpression { let tuple = self.reduce_expression(&tuple_access.tuple); - self.reducer - .reduce_tuple_access(tuple_access, tuple, tuple_access.span.clone()) + self.reducer.reduce_tuple_access(tuple_access, tuple) } pub fn reduce_circuit_init(&mut self, circuit_init: &CircuitInitExpression) -> CircuitInitExpression { @@ -215,8 +207,7 @@ impl ReconstructingDirector { }) .collect(); - self.reducer - .reduce_circuit_init(circuit_init, name, members, circuit_init.span.clone()) + self.reducer.reduce_circuit_init(circuit_init, name, members) } pub fn reduce_circuit_member_access( @@ -226,12 +217,8 @@ impl ReconstructingDirector { let circuit = self.reduce_expression(&circuit_member_access.circuit); let name = self.reduce_identifier(&circuit_member_access.name); - self.reducer.reduce_circuit_member_access( - circuit_member_access, - circuit, - name, - circuit_member_access.span.clone(), - ) + self.reducer + .reduce_circuit_member_access(circuit_member_access, circuit, name) } pub fn reduce_circuit_static_fn_access( @@ -241,19 +228,15 @@ impl ReconstructingDirector { let circuit = self.reduce_expression(&circuit_static_fn_access.circuit); let name = self.reduce_identifier(&circuit_static_fn_access.name); - self.reducer.reduce_circuit_static_fn_access( - circuit_static_fn_access, - circuit, - name, - circuit_static_fn_access.span.clone(), - ) + self.reducer + .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name) } pub fn reduce_call(&mut self, call: &CallExpression) -> CallExpression { let function = self.reduce_expression(&call.function); let arguments = call.arguments.iter().map(|expr| self.reduce_expression(expr)).collect(); - self.reducer.reduce_call(call, function, arguments, call.span.clone()) + self.reducer.reduce_call(call, function, arguments) } // Statements @@ -275,15 +258,13 @@ impl ReconstructingDirector { pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> ReturnStatement { let expression = self.reduce_expression(&return_statement.expression); - self.reducer - .reduce_return(return_statement, expression, return_statement.span.clone()) + self.reducer.reduce_return(return_statement, expression) } pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> VariableName { let identifier = self.reduce_identifier(&variable_name.identifier); - self.reducer - .reduce_variable_name(variable_name, identifier, variable_name.span.clone()) + self.reducer.reduce_variable_name(variable_name, identifier) } pub fn reduce_definition(&mut self, definition: &DefinitionStatement) -> DefinitionStatement { @@ -295,8 +276,7 @@ impl ReconstructingDirector { let type_ = definition.type_.as_ref().map(|inner| self.reduce_type(inner)); let value = self.reduce_expression(&definition.value); - self.reducer - .reduce_definition(definition, variable_names, type_, value, definition.span.clone()) + self.reducer.reduce_definition(definition, variable_names, type_, value) } pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> AssigneeAccess { @@ -321,15 +301,14 @@ impl ReconstructingDirector { .map(|access| self.reduce_assignee_access(access)) .collect(); - self.reducer - .reduce_assignee(assignee, identifier, accesses, assignee.span.clone()) + self.reducer.reduce_assignee(assignee, identifier, accesses) } pub fn reduce_assign(&mut self, assign: &AssignStatement) -> AssignStatement { let assignee = self.reduce_assignee(&assign.assignee); let value = self.reduce_expression(&assign.value); - self.reducer.reduce_assign(assign, assignee, value, assign.span.clone()) + self.reducer.reduce_assign(assign, assignee, value) } pub fn reduce_conditional(&mut self, conditional: &ConditionalStatement) -> ConditionalStatement { @@ -340,8 +319,7 @@ impl ReconstructingDirector { .as_ref() .map(|condition| self.reduce_statement(condition)); - self.reducer - .reduce_conditional(conditional, condition, block, next, conditional.span.clone()) + self.reducer.reduce_conditional(conditional, condition, block, next) } pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> IterationStatement { @@ -350,8 +328,7 @@ impl ReconstructingDirector { let stop = self.reduce_expression(&iteration.stop); let block = self.reduce_block(&iteration.block); - self.reducer - .reduce_iteration(iteration, variable, start, stop, block, iteration.span.clone()) + self.reducer.reduce_iteration(iteration, variable, start, stop, block) } pub fn reduce_console(&mut self, console_function_call: &ConsoleStatement) -> ConsoleStatement { @@ -376,14 +353,12 @@ impl ReconstructingDirector { } }; - self.reducer - .reduce_console(console_function_call, function, console_function_call.span.clone()) + self.reducer.reduce_console(console_function_call, function) } pub fn reduce_expression_statement(&mut self, expression: &ExpressionStatement) -> ExpressionStatement { let inner_expression = self.reduce_expression(&expression.expression); - self.reducer - .reduce_expression_statement(expression, inner_expression, expression.span.clone()) + self.reducer.reduce_expression_statement(expression, inner_expression) } pub fn reduce_block(&mut self, block: &Block) -> Block { @@ -393,7 +368,7 @@ impl ReconstructingDirector { .map(|statement| self.reduce_statement(statement)) .collect(); - self.reducer.reduce_block(block, statements, block.span.clone()) + self.reducer.reduce_block(block, statements) } // Program @@ -427,8 +402,7 @@ impl ReconstructingDirector { let identifier = self.reduce_identifier(&variable.identifier); let type_ = self.reduce_type(&variable.type_); - self.reducer - .reduce_function_input_variable(variable, identifier, type_, variable.span.clone()) + self.reducer.reduce_function_input_variable(variable, identifier, type_) } pub fn reduce_function_input(&mut self, input: &FunctionInput) -> FunctionInput { @@ -462,8 +436,7 @@ impl ReconstructingDirector { pub fn reduce_import(&mut self, import: &ImportStatement) -> ImportStatement { let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages); - self.reducer - .reduce_import(import, package_or_packages, import.span.clone()) + self.reducer.reduce_import(import, package_or_packages) } pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> CircuitMember { @@ -491,8 +464,7 @@ impl ReconstructingDirector { fn reduce_annotation(&mut self, annotation: &Annotation) -> Annotation { let name = self.reduce_identifier(&annotation.name); - self.reducer - .reduce_annotation(annotation, annotation.span.clone(), name) + self.reducer.reduce_annotation(annotation, name) } pub fn reduce_function(&mut self, function: &Function) -> Function { @@ -510,14 +482,7 @@ impl ReconstructingDirector { let output = function.output.as_ref().map(|output| self.reduce_type(output)); let block = self.reduce_block(&function.block); - self.reducer.reduce_function( - function, - identifier, - annotations, - input, - output, - block, - function.span.clone(), - ) + self.reducer + .reduce_function(function, identifier, annotations, input, output, block) } } diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 363f6e58fd..12059804ba 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -29,18 +29,18 @@ pub trait ReconstructingReducer { new } - fn reduce_identifier(&mut self, identifier: &Identifier, span: Span) -> Identifier { + fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { Identifier { name: identifier.name.clone(), - span, + span: identifier.span.clone(), } } - fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple, span: Span) -> GroupTuple { + fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> GroupTuple { GroupTuple { x: group_tuple.x.clone(), y: group_tuple.y.clone(), - span, + span: group_tuple.span.clone(), } } @@ -54,187 +54,169 @@ pub trait ReconstructingReducer { fn reduce_binary( &mut self, - _binary: &BinaryExpression, + binary: &BinaryExpression, left: Expression, right: Expression, op: BinaryOperation, - span: Span, ) -> BinaryExpression { BinaryExpression { left: Box::new(left), right: Box::new(right), op, - span, + span: binary.span.clone(), } } - fn reduce_unary( - &mut self, - _unary: &UnaryExpression, - inner: Expression, - op: UnaryOperation, - span: Span, - ) -> UnaryExpression { + fn reduce_unary(&mut self, unary: &UnaryExpression, inner: Expression, op: UnaryOperation) -> UnaryExpression { UnaryExpression { inner: Box::new(inner), op, - span, + span: unary.span.clone(), } } fn reduce_ternary( &mut self, - _ternary: &TernaryExpression, + ternary: &TernaryExpression, condition: Expression, if_true: Expression, if_false: Expression, - span: Span, ) -> TernaryExpression { TernaryExpression { condition: Box::new(condition), if_true: Box::new(if_true), if_false: Box::new(if_false), - span, + span: ternary.span.clone(), } } - fn reduce_cast( - &mut self, - _cast: &CastExpression, - inner: Expression, - target_type: Type, - span: Span, - ) -> CastExpression { + fn reduce_cast(&mut self, cast: &CastExpression, inner: Expression, target_type: Type) -> CastExpression { CastExpression { inner: Box::new(inner), target_type, - span, + span: cast.span.clone(), } } fn reduce_array_inline( &mut self, - _array_inline: &ArrayInlineExpression, + array_inline: &ArrayInlineExpression, elements: Vec, - span: Span, ) -> ArrayInlineExpression { - ArrayInlineExpression { elements, span } + ArrayInlineExpression { + elements, + span: array_inline.span.clone(), + } } - fn reduce_array_init( - &mut self, - array_init: &ArrayInitExpression, - element: Expression, - span: Span, - ) -> ArrayInitExpression { + fn reduce_array_init(&mut self, array_init: &ArrayInitExpression, element: Expression) -> ArrayInitExpression { ArrayInitExpression { element: Box::new(element), dimensions: array_init.dimensions.clone(), - span, + span: array_init.span.clone(), } } fn reduce_array_access( &mut self, - _array_access: &ArrayAccessExpression, + array_access: &ArrayAccessExpression, array: Expression, index: Expression, - span: Span, ) -> ArrayAccessExpression { ArrayAccessExpression { array: Box::new(array), index: Box::new(index), - span, + span: array_access.span.clone(), } } fn reduce_array_range_access( &mut self, - _array_rage_access: &ArrayRangeAccessExpression, + array_rage_access: &ArrayRangeAccessExpression, array: Expression, left: Option, right: Option, - span: Span, ) -> ArrayRangeAccessExpression { ArrayRangeAccessExpression { array: Box::new(array), left: left.map(|expr| Box::new(expr)), right: right.map(|expr| Box::new(expr)), - span, + span: array_rage_access.span.clone(), } } fn reduce_tuple_init( &mut self, - _tuple_init: &TupleInitExpression, + tuple_init: &TupleInitExpression, elements: Vec, - span: Span, ) -> TupleInitExpression { - TupleInitExpression { elements, span } + TupleInitExpression { + elements, + span: tuple_init.span.clone(), + } } fn reduce_tuple_access( &mut self, tuple_access: &TupleAccessExpression, tuple: Expression, - span: Span, ) -> TupleAccessExpression { TupleAccessExpression { tuple: Box::new(tuple), index: tuple_access.index.clone(), - span, + span: tuple_access.span.clone(), } } fn reduce_circuit_init( &mut self, - _circuit_init: &CircuitInitExpression, + circuit_init: &CircuitInitExpression, name: Identifier, members: Vec, - span: Span, ) -> CircuitInitExpression { - CircuitInitExpression { name, members, span } + CircuitInitExpression { + name, + members, + span: circuit_init.span.clone(), + } } fn reduce_circuit_member_access( &mut self, - _circuit_member_access: &CircuitMemberAccessExpression, + circuit_member_access: &CircuitMemberAccessExpression, circuit: Expression, name: Identifier, - span: Span, ) -> CircuitMemberAccessExpression { CircuitMemberAccessExpression { circuit: Box::new(circuit), name, - span, + span: circuit_member_access.span.clone(), } } fn reduce_circuit_static_fn_access( &mut self, - _circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, + circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, circuit: Expression, name: Identifier, - span: Span, ) -> CircuitStaticFunctionAccessExpression { CircuitStaticFunctionAccessExpression { circuit: Box::new(circuit), name, - span, + span: circuit_static_fn_access.span.clone(), } } fn reduce_call( &mut self, - _call: &CallExpression, + call: &CallExpression, function: Expression, arguments: Vec, - span: Span, ) -> CallExpression { CallExpression { function: Box::new(function), arguments, - span, + span: call.span.clone(), } } @@ -243,25 +225,18 @@ pub trait ReconstructingReducer { new } - fn reduce_return( - &mut self, - _return_statement: &ReturnStatement, - expression: Expression, - span: Span, - ) -> ReturnStatement { - ReturnStatement { expression, span } + fn reduce_return(&mut self, return_statement: &ReturnStatement, expression: Expression) -> ReturnStatement { + ReturnStatement { + expression, + span: return_statement.span.clone(), + } } - fn reduce_variable_name( - &mut self, - variable_name: &VariableName, - identifier: Identifier, - span: Span, - ) -> VariableName { + fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> VariableName { VariableName { mutable: variable_name.mutable, identifier, - span, + span: variable_name.span.clone(), } } @@ -271,14 +246,13 @@ pub trait ReconstructingReducer { variable_names: Vec, type_: Option, value: Expression, - span: Span, ) -> DefinitionStatement { DefinitionStatement { declaration_type: definition.declaration_type.clone(), variable_names, type_, value, - span, + span: definition.span.clone(), } } @@ -288,87 +262,81 @@ pub trait ReconstructingReducer { fn reduce_assignee( &mut self, - _assignee: &Assignee, + assignee: &Assignee, identifier: Identifier, accesses: Vec, - span: Span, ) -> Assignee { Assignee { identifier, accesses, - span, + span: assignee.span.clone(), } } - fn reduce_assign( - &mut self, - assign: &AssignStatement, - assignee: Assignee, - value: Expression, - span: Span, - ) -> AssignStatement { + fn reduce_assign(&mut self, assign: &AssignStatement, assignee: Assignee, value: Expression) -> AssignStatement { AssignStatement { operation: assign.operation.clone(), assignee, value, - span, + span: assign.span.clone(), } } fn reduce_conditional( &mut self, - _conditional: &ConditionalStatement, + conditional: &ConditionalStatement, condition: Expression, block: Block, statement: Option, - span: Span, ) -> ConditionalStatement { ConditionalStatement { condition, block, next: statement.map(|statement| Box::new(statement)), - span, + span: conditional.span.clone(), } } fn reduce_iteration( &mut self, - _iteration: &IterationStatement, + iteration: &IterationStatement, variable: Identifier, start: Expression, stop: Expression, block: Block, - span: Span, ) -> IterationStatement { IterationStatement { variable, start, stop, block, - span, + span: iteration.span.clone(), } } - fn reduce_console( - &mut self, - _console: &ConsoleStatement, - function: ConsoleFunction, - span: Span, - ) -> ConsoleStatement { - ConsoleStatement { function, span } + fn reduce_console(&mut self, console: &ConsoleStatement, function: ConsoleFunction) -> ConsoleStatement { + ConsoleStatement { + function, + span: console.span.clone(), + } } fn reduce_expression_statement( &mut self, - _expression_statement: &ExpressionStatement, + expression_statement: &ExpressionStatement, expression: Expression, - span: Span, ) -> ExpressionStatement { - ExpressionStatement { expression, span } + ExpressionStatement { + expression, + span: expression_statement.span.clone(), + } } - fn reduce_block(&mut self, _block: &Block, statements: Vec, span: Span) -> Block { - Block { statements, span } + fn reduce_block(&mut self, block: &Block, statements: Vec) -> Block { + Block { + statements, + span: block.span.clone(), + } } // Program @@ -394,14 +362,13 @@ pub trait ReconstructingReducer { variable: &FunctionInputVariable, identifier: Identifier, type_: Type, - span: Span, ) -> FunctionInputVariable { FunctionInputVariable { identifier, const_: variable.const_, mutable: variable.mutable, type_, - span, + span: variable.span.clone(), } } @@ -417,15 +384,10 @@ pub trait ReconstructingReducer { new } - fn reduce_import( - &mut self, - _import: &ImportStatement, - package_or_packages: PackageOrPackages, - span: Span, - ) -> ImportStatement { + fn reduce_import(&mut self, import: &ImportStatement, package_or_packages: PackageOrPackages) -> ImportStatement { ImportStatement { package_or_packages, - span, + span: import.span.clone(), } } @@ -437,24 +399,22 @@ pub trait ReconstructingReducer { Circuit { circuit_name, members } } - fn reduce_annotation(&mut self, annotation: &Annotation, span: Span, name: Identifier) -> Annotation { + fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Annotation { Annotation { - span, + span: annotation.span.clone(), name, arguments: annotation.arguments.clone(), } } - #[allow(clippy::too_many_arguments)] fn reduce_function( &mut self, - _function: &Function, + function: &Function, identifier: Identifier, annotations: Vec, input: Vec, output: Option, block: Block, - span: Span, ) -> Function { Function { identifier, @@ -462,7 +422,7 @@ pub trait ReconstructingReducer { input, output, block, - span, + span: function.span.clone(), } } } From 02e5f57eedeca9ddee15129d9d75295f2a68a92a Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 16:47:57 -0500 Subject: [PATCH 09/40] compound assignments --- ast/src/reducer/canonicalization.rs | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index a7b3131206..91b1f5ff6a 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -239,6 +239,47 @@ impl ReconstructingReducer for Canonicalizer { } } + fn reduce_assign(&mut self, assign: &AssignStatement, assignee: Assignee, value: Expression) -> AssignStatement { + match value { + Expression::Value(value) => { + let left = Box::new(Expression::Identifier(assignee.identifier.clone())); + let right = Box::new(Expression::Value(value)); + let op = match assign.operation { + AssignOperation::Assign => BinaryOperation::Eq, + AssignOperation::Add => BinaryOperation::Add, + AssignOperation::Sub => BinaryOperation::Sub, + AssignOperation::Mul => BinaryOperation::Mul, + AssignOperation::Div => BinaryOperation::Div, + AssignOperation::Pow => BinaryOperation::Pow, + AssignOperation::Or => BinaryOperation::Or, + AssignOperation::And => BinaryOperation::And, + AssignOperation::BitOr => BinaryOperation::BitOr, + AssignOperation::BitAnd => BinaryOperation::BitAnd, + AssignOperation::BitXor => BinaryOperation::BitXor, + AssignOperation::Shr => BinaryOperation::Shr, + AssignOperation::ShrSigned => BinaryOperation::ShrSigned, + AssignOperation::Shl => BinaryOperation::Shl, + AssignOperation::Mod => BinaryOperation::Mod, + }; + + let value = Expression::Binary(BinaryExpression { + left, + right, + op, + span: assign.span.clone(), + }); + + AssignStatement { + operation: assign.operation.clone(), + assignee, + value, + span: assign.span.clone(), + } + } + _ => assign.clone(), + } + } + // fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { // Circuit { // circuit_name: circuit_name.clone(), From 04f62cdd8c512829e7959a0b8fb67eed8e7cc507 Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 16:59:08 -0500 Subject: [PATCH 10/40] missing function output types --- ast/src/reducer/canonicalization.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 91b1f5ff6a..6359d6ed44 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -280,6 +280,30 @@ impl ReconstructingReducer for Canonicalizer { } } + fn reduce_function( + &mut self, + function: &Function, + identifier: Identifier, + annotations: Vec, + input: Vec, + output: Option, + block: Block, + ) -> Function { + let new_output = match output { + None => Some(Type::Tuple(vec![])), + _ => output.clone(), + }; + + Function { + identifier, + annotations, + input, + output: new_output, + block, + span: function.span.clone(), + } + } + // fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { // Circuit { // circuit_name: circuit_name.clone(), From 88166a64f95d72399a438107d66bd348116c2f63 Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 18:29:53 -0500 Subject: [PATCH 11/40] error on Self outside of cicuits --- ast/src/reducer/canonicalization.rs | 67 +++++--------- ast/src/reducer/reconstructing_director.rs | 101 +++++++++++++-------- ast/src/reducer/reconstructing_reducer.rs | 19 +++- 3 files changed, 103 insertions(+), 84 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 6359d6ed44..4ddbf0e232 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -15,45 +15,15 @@ // along with the Leo library. If not, see . use crate::*; -use indexmap::IndexMap; +// use indexmap::IndexMap; pub struct Canonicalizer; impl Canonicalizer { - fn _is_self(&self, identifier: &Identifier) -> bool { - matches!(identifier.name.as_str(), "Self") - } - fn is_self_type(&self, type_option: Option<&Type>) -> bool { matches!(type_option, Some(Type::SelfType)) } - fn _canonicalize_function_input(&self, function_input: &FunctionInput, circuit_name: &Identifier) -> FunctionInput { - match function_input { - FunctionInput::SelfKeyword(self_keyword) => { - return FunctionInput::Variable(FunctionInputVariable { - identifier: circuit_name.clone(), - const_: false, - mutable: false, - type_: Type::Circuit(circuit_name.clone()), - span: self_keyword.span.clone(), - }); - } - FunctionInput::MutSelfKeyword(mut_self_keyword) => { - return FunctionInput::Variable(FunctionInputVariable { - identifier: circuit_name.clone(), - const_: false, - mutable: true, - type_: Type::Circuit(circuit_name.clone()), - span: mut_self_keyword.span.clone(), - }); - } - _ => {} - } - - function_input.clone() - } - fn canonicalize_expression(&self, expression: &Expression, circuit_name: &Identifier) -> Expression { match expression { Expression::CircuitInit(circuit_init) => { @@ -173,11 +143,15 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_type(&mut self, _type_: &Type, new: Type) -> Type { + fn reduce_type(&mut self, _type_: &Type, new: Type, in_circuit: bool) -> Type { match new { Type::Array(_, mut dimensions) => { // TODO need to throw errors in all these. // Throw error if dimensions is empty. + // if array_init.dimensions.0.len() == 0 { + + // } + let mut next = Type::Array( Box::new(Type::Group), ArrayDimensions(vec![dimensions.remove_last().unwrap()]), @@ -194,12 +168,20 @@ impl ReconstructingReducer for Canonicalizer { array } + Type::SelfType if !in_circuit => { + println!("Brrr bad Self"); + new.clone() + } _ => new.clone(), } } fn reduce_array_init(&mut self, array_init: &ArrayInitExpression, element: Expression) -> ArrayInitExpression { // TODO ERROR HERE if len is 0 + // if array_init.dimensions.0.len() == 0 { + + // } + let element = Box::new(element); if array_init.dimensions.0.len() == 1 { @@ -288,10 +270,11 @@ impl ReconstructingReducer for Canonicalizer { input: Vec, output: Option, block: Block, + _in_circuit: bool, ) -> Function { let new_output = match output { None => Some(Type::Tuple(vec![])), - _ => output.clone(), + _ => output, }; Function { @@ -304,13 +287,13 @@ impl ReconstructingReducer for Canonicalizer { } } - // fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { - // Circuit { - // circuit_name: circuit_name.clone(), - // members: members - // .iter() - // .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) - // .collect(), - // } - // } + fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { + Circuit { + circuit_name: circuit_name.clone(), + members: members + .iter() + .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) + .collect(), + } + } } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index ebc1986e41..102e7e3dfc 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -28,16 +28,18 @@ impl ReconstructingDirector { Self { reducer } } - pub fn reduce_type(&mut self, type_: &Type) -> Type { + pub fn reduce_type(&mut self, type_: &Type, in_circuit: bool) -> Type { let new = match type_ { // Data type wrappers - Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_)), dimensions.clone()), - Type::Tuple(types) => Type::Tuple(types.iter().map(|type_| self.reduce_type(type_)).collect()), + Type::Array(type_, dimensions) => { + Type::Array(Box::new(self.reduce_type(type_, in_circuit)), dimensions.clone()) + } + Type::Tuple(types) => Type::Tuple(types.iter().map(|type_| self.reduce_type(type_, in_circuit)).collect()), Type::Circuit(identifier) => Type::Circuit(self.reduce_identifier(identifier)), _ => type_.clone(), }; - self.reducer.reduce_type(type_, new) + self.reducer.reduce_type(type_, new, in_circuit) } // Expressions @@ -240,19 +242,21 @@ impl ReconstructingDirector { } // Statements - pub fn reduce_statement(&mut self, statement: &Statement) -> Statement { + pub fn reduce_statement(&mut self, statement: &Statement, in_circuit: bool) -> Statement { let new = match statement { Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)), - Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)), + Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition, in_circuit)), Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)), - Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(&conditional)), - Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration)), + Statement::Conditional(conditional) => { + Statement::Conditional(self.reduce_conditional(&conditional, in_circuit)) + } + Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration, in_circuit)), Statement::Console(console) => Statement::Console(self.reduce_console(&console)), Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)), - Statement::Block(block) => Statement::Block(self.reduce_block(&block)), + Statement::Block(block) => Statement::Block(self.reduce_block(&block, in_circuit)), }; - self.reducer.reduce_statement(statement, new) + self.reducer.reduce_statement(statement, new, in_circuit) } pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> ReturnStatement { @@ -267,16 +271,20 @@ impl ReconstructingDirector { self.reducer.reduce_variable_name(variable_name, identifier) } - pub fn reduce_definition(&mut self, definition: &DefinitionStatement) -> DefinitionStatement { + pub fn reduce_definition(&mut self, definition: &DefinitionStatement, in_circuit: bool) -> DefinitionStatement { let variable_names = definition .variable_names .iter() .map(|variable_name| self.reduce_variable_name(variable_name)) .collect(); - let type_ = definition.type_.as_ref().map(|inner| self.reduce_type(inner)); + let type_ = definition + .type_ + .as_ref() + .map(|inner| self.reduce_type(inner, in_circuit)); let value = self.reduce_expression(&definition.value); - self.reducer.reduce_definition(definition, variable_names, type_, value) + self.reducer + .reduce_definition(definition, variable_names, type_, value, in_circuit) } pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> AssigneeAccess { @@ -311,24 +319,26 @@ impl ReconstructingDirector { self.reducer.reduce_assign(assign, assignee, value) } - pub fn reduce_conditional(&mut self, conditional: &ConditionalStatement) -> ConditionalStatement { + pub fn reduce_conditional(&mut self, conditional: &ConditionalStatement, in_circuit: bool) -> ConditionalStatement { let condition = self.reduce_expression(&conditional.condition); - let block = self.reduce_block(&conditional.block); + let block = self.reduce_block(&conditional.block, in_circuit); let next = conditional .next .as_ref() - .map(|condition| self.reduce_statement(condition)); + .map(|condition| self.reduce_statement(condition, in_circuit)); - self.reducer.reduce_conditional(conditional, condition, block, next) + self.reducer + .reduce_conditional(conditional, condition, block, next, in_circuit) } - pub fn reduce_iteration(&mut self, iteration: &IterationStatement) -> IterationStatement { + pub fn reduce_iteration(&mut self, iteration: &IterationStatement, in_circuit: bool) -> IterationStatement { let variable = self.reduce_identifier(&iteration.variable); let start = self.reduce_expression(&iteration.start); let stop = self.reduce_expression(&iteration.stop); - let block = self.reduce_block(&iteration.block); + let block = self.reduce_block(&iteration.block, in_circuit); - self.reducer.reduce_iteration(iteration, variable, start, stop, block) + self.reducer + .reduce_iteration(iteration, variable, start, stop, block, in_circuit) } pub fn reduce_console(&mut self, console_function_call: &ConsoleStatement) -> ConsoleStatement { @@ -361,14 +371,14 @@ impl ReconstructingDirector { self.reducer.reduce_expression_statement(expression, inner_expression) } - pub fn reduce_block(&mut self, block: &Block) -> Block { + pub fn reduce_block(&mut self, block: &Block, in_circuit: bool) -> Block { let statements = block .statements .iter() - .map(|statement| self.reduce_statement(statement)) + .map(|statement| self.reduce_statement(statement, in_circuit)) .collect(); - self.reducer.reduce_block(block, statements) + self.reducer.reduce_block(block, statements, in_circuit) } // Program @@ -376,7 +386,7 @@ impl ReconstructingDirector { let inputs = program .expected_input .iter() - .map(|input| self.reduce_function_input(input)) + .map(|input| self.reduce_function_input(input, false)) .collect(); let imports = program .imports @@ -391,29 +401,39 @@ impl ReconstructingDirector { let functions = program .functions .iter() - .map(|(identifier, function)| (self.reduce_identifier(identifier), self.reduce_function(function))) + .map(|(identifier, function)| { + ( + self.reduce_identifier(identifier), + self.reduce_function(function, false), + ) + }) .collect(); self.reducer .reduce_program(program, inputs, imports, circuits, functions) } - pub fn reduce_function_input_variable(&mut self, variable: &FunctionInputVariable) -> FunctionInputVariable { + pub fn reduce_function_input_variable( + &mut self, + variable: &FunctionInputVariable, + in_circuit: bool, + ) -> FunctionInputVariable { let identifier = self.reduce_identifier(&variable.identifier); - let type_ = self.reduce_type(&variable.type_); + let type_ = self.reduce_type(&variable.type_, in_circuit); - self.reducer.reduce_function_input_variable(variable, identifier, type_) + self.reducer + .reduce_function_input_variable(variable, identifier, type_, in_circuit) } - pub fn reduce_function_input(&mut self, input: &FunctionInput) -> FunctionInput { + pub fn reduce_function_input(&mut self, input: &FunctionInput, in_circuit: bool) -> FunctionInput { let new = match input { FunctionInput::Variable(function_input_variable) => { - FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)) + FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable, in_circuit)) } _ => input.clone(), }; - self.reducer.reduce_function_input(input, new) + self.reducer.reduce_function_input(input, new, in_circuit) } pub fn reduce_package_or_packages(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { @@ -442,9 +462,11 @@ impl ReconstructingDirector { pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> CircuitMember { let new = match circuit_member { CircuitMember::CircuitVariable(identifier, type_) => { - CircuitMember::CircuitVariable(self.reduce_identifier(&identifier), self.reduce_type(&type_)) + CircuitMember::CircuitVariable(self.reduce_identifier(&identifier), self.reduce_type(&type_, true)) + } + CircuitMember::CircuitFunction(function) => { + CircuitMember::CircuitFunction(self.reduce_function(&function, true)) } - CircuitMember::CircuitFunction(function) => CircuitMember::CircuitFunction(self.reduce_function(&function)), }; self.reducer.reduce_circuit_member(circuit_member, new) @@ -467,7 +489,7 @@ impl ReconstructingDirector { self.reducer.reduce_annotation(annotation, name) } - pub fn reduce_function(&mut self, function: &Function) -> Function { + pub fn reduce_function(&mut self, function: &Function, in_circuit: bool) -> Function { let identifier = self.reduce_identifier(&function.identifier); let annotations = function .annotations @@ -477,12 +499,15 @@ impl ReconstructingDirector { let input = function .input .iter() - .map(|input| self.reduce_function_input(input)) + .map(|input| self.reduce_function_input(input, false)) .collect(); - let output = function.output.as_ref().map(|output| self.reduce_type(output)); - let block = self.reduce_block(&function.block); + let output = function + .output + .as_ref() + .map(|output| self.reduce_type(output, in_circuit)); + let block = self.reduce_block(&function.block, false); self.reducer - .reduce_function(function, identifier, annotations, input, output, block) + .reduce_function(function, identifier, annotations, input, output, block, in_circuit) } } diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 12059804ba..2cc4945449 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -20,7 +20,7 @@ use indexmap::IndexMap; // Needed to fix clippy bug. #[allow(clippy::redundant_closure)] pub trait ReconstructingReducer { - fn reduce_type(&mut self, _type_: &Type, new: Type) -> Type { + fn reduce_type(&mut self, _type_: &Type, new: Type, _in_circuit: bool) -> Type { new } @@ -221,7 +221,7 @@ pub trait ReconstructingReducer { } // Statements - fn reduce_statement(&mut self, _statement: &Statement, new: Statement) -> Statement { + fn reduce_statement(&mut self, _statement: &Statement, new: Statement, _in_circuit: bool) -> Statement { new } @@ -246,6 +246,7 @@ pub trait ReconstructingReducer { variable_names: Vec, type_: Option, value: Expression, + _in_circuit: bool, ) -> DefinitionStatement { DefinitionStatement { declaration_type: definition.declaration_type.clone(), @@ -288,6 +289,7 @@ pub trait ReconstructingReducer { condition: Expression, block: Block, statement: Option, + _in_circuit: bool, ) -> ConditionalStatement { ConditionalStatement { condition, @@ -304,6 +306,7 @@ pub trait ReconstructingReducer { start: Expression, stop: Expression, block: Block, + _in_circuit: bool, ) -> IterationStatement { IterationStatement { variable, @@ -332,7 +335,7 @@ pub trait ReconstructingReducer { } } - fn reduce_block(&mut self, block: &Block, statements: Vec) -> Block { + fn reduce_block(&mut self, block: &Block, statements: Vec, _in_circuit: bool) -> Block { Block { statements, span: block.span.clone(), @@ -362,6 +365,7 @@ pub trait ReconstructingReducer { variable: &FunctionInputVariable, identifier: Identifier, type_: Type, + _in_circuit: bool, ) -> FunctionInputVariable { FunctionInputVariable { identifier, @@ -372,7 +376,12 @@ pub trait ReconstructingReducer { } } - fn reduce_function_input(&mut self, _input: &FunctionInput, new: FunctionInput) -> FunctionInput { + fn reduce_function_input( + &mut self, + _input: &FunctionInput, + new: FunctionInput, + _in_circuit: bool, + ) -> FunctionInput { new } @@ -407,6 +416,7 @@ pub trait ReconstructingReducer { } } + #[allow(clippy::too_many_arguments)] fn reduce_function( &mut self, function: &Function, @@ -415,6 +425,7 @@ pub trait ReconstructingReducer { input: Vec, output: Option, block: Block, + _in_circuit: bool, ) -> Function { Function { identifier, From 3a1c29e3b2d986ee5158aea4331f8279b1bd096c Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 12 Mar 2021 20:41:49 -0500 Subject: [PATCH 12/40] ready to return real errors, fixed Self outside circuit bugs --- Cargo.lock | 1 + ast/Cargo.toml | 3 + ast/src/lib.rs | 7 + ast/src/reducer/canonicalization.rs | 56 +- ast/src/reducer/reconstructing_director.rs | 598 ++++++++++++--------- ast/src/reducer/reconstructing_reducer.rs | 302 +++++++---- 6 files changed, 586 insertions(+), 381 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 58b0d5dade..fd2e0d86d5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1209,6 +1209,7 @@ dependencies = [ name = "leo-ast" version = "1.2.3" dependencies = [ + "anyhow", "criterion", "indexmap", "leo-input", diff --git a/ast/Cargo.toml b/ast/Cargo.toml index 3ec4548606..28a2b8e277 100644 --- a/ast/Cargo.toml +++ b/ast/Cargo.toml @@ -35,6 +35,9 @@ features = ["derive", "rc"] [dependencies.serde_json] version = "1.0" +[dependencies.anyhow] +version = "1.0" + [dependencies.thiserror] version = "1.0" diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 078fda8de0..6800701560 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -61,6 +61,8 @@ pub use self::types::*; mod node; pub use node::*; +use anyhow::Result; + /// The abstract syntax tree (AST) for a Leo program. /// /// The [`Ast`] type represents a Leo program as a series of recursive data types. @@ -78,6 +80,11 @@ impl Ast { Self { ast: program } } + pub fn canonicalize(&mut self) -> Result<()> { + self.ast = ReconstructingDirector::new(Canonicalizer).reduce_program(self.as_repr())?; + Ok(()) + } + /// Returns a reference to the inner program AST representation. pub fn as_repr(&self) -> &Program { &self.ast diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 4ddbf0e232..9dde3a1886 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::*; -// use indexmap::IndexMap; +use anyhow::Result; pub struct Canonicalizer; @@ -143,7 +143,7 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_type(&mut self, _type_: &Type, new: Type, in_circuit: bool) -> Type { + fn reduce_type(&mut self, _type_: &Type, new: Type, in_circuit: bool) -> Result { match new { Type::Array(_, mut dimensions) => { // TODO need to throw errors in all these. @@ -166,17 +166,22 @@ impl ReconstructingReducer for Canonicalizer { next = array.clone(); } - array + Ok(array) } Type::SelfType if !in_circuit => { println!("Brrr bad Self"); - new.clone() + Ok(new.clone()) } - _ => new.clone(), + _ => Ok(new.clone()), } } - fn reduce_array_init(&mut self, array_init: &ArrayInitExpression, element: Expression) -> ArrayInitExpression { + fn reduce_array_init( + &mut self, + array_init: &ArrayInitExpression, + element: Expression, + _in_circuit: bool, + ) -> Result { // TODO ERROR HERE if len is 0 // if array_init.dimensions.0.len() == 0 { @@ -185,11 +190,11 @@ impl ReconstructingReducer for Canonicalizer { let element = Box::new(element); if array_init.dimensions.0.len() == 1 { - return ArrayInitExpression { + return Ok(ArrayInitExpression { element, dimensions: array_init.dimensions.clone(), span: array_init.span.clone(), - }; + }); } let mut dimensions = array_init.dimensions.clone(); @@ -214,14 +219,20 @@ impl ReconstructingReducer for Canonicalizer { outer_element = Box::new(next.clone()); } - ArrayInitExpression { + Ok(ArrayInitExpression { element: outer_element, dimensions: ArrayDimensions(vec![dimensions.remove_first().unwrap()]), span: array_init.span.clone(), - } + }) } - fn reduce_assign(&mut self, assign: &AssignStatement, assignee: Assignee, value: Expression) -> AssignStatement { + fn reduce_assign( + &mut self, + assign: &AssignStatement, + assignee: Assignee, + value: Expression, + _in_circuit: bool, + ) -> Result { match value { Expression::Value(value) => { let left = Box::new(Expression::Identifier(assignee.identifier.clone())); @@ -251,14 +262,14 @@ impl ReconstructingReducer for Canonicalizer { span: assign.span.clone(), }); - AssignStatement { + Ok(AssignStatement { operation: assign.operation.clone(), assignee, value, span: assign.span.clone(), - } + }) } - _ => assign.clone(), + _ => Ok(assign.clone()), } } @@ -271,29 +282,34 @@ impl ReconstructingReducer for Canonicalizer { output: Option, block: Block, _in_circuit: bool, - ) -> Function { + ) -> Result { let new_output = match output { None => Some(Type::Tuple(vec![])), _ => output, }; - Function { + Ok(Function { identifier, annotations, input, output: new_output, block, span: function.span.clone(), - } + }) } - fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { - Circuit { + fn reduce_circuit( + &mut self, + _circuit: &Circuit, + circuit_name: Identifier, + members: Vec, + ) -> Result { + Ok(Circuit { circuit_name: circuit_name.clone(), members: members .iter() .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) .collect(), - } + }) } } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 102e7e3dfc..3ba7f7de91 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -18,6 +18,8 @@ //! asg nodes and saving relevant information. use crate::*; +use anyhow::Result; +use indexmap::IndexMap; pub struct ReconstructingDirector { reducer: R, @@ -28,14 +30,20 @@ impl ReconstructingDirector { Self { reducer } } - pub fn reduce_type(&mut self, type_: &Type, in_circuit: bool) -> Type { + pub fn reduce_type(&mut self, type_: &Type, in_circuit: bool) -> Result { let new = match type_ { - // Data type wrappers Type::Array(type_, dimensions) => { - Type::Array(Box::new(self.reduce_type(type_, in_circuit)), dimensions.clone()) + Type::Array(Box::new(self.reduce_type(type_, in_circuit)?), dimensions.clone()) } - Type::Tuple(types) => Type::Tuple(types.iter().map(|type_| self.reduce_type(type_, in_circuit)).collect()), - Type::Circuit(identifier) => Type::Circuit(self.reduce_identifier(identifier)), + Type::Tuple(types) => { + let mut reduced_types = vec![]; + for type_ in types.iter() { + reduced_types.push(self.reduce_type(type_, in_circuit)?); + } + + Type::Tuple(reduced_types) + } + Type::Circuit(identifier) => Type::Circuit(self.reduce_identifier(identifier)?), _ => type_.clone(), }; @@ -43,60 +51,74 @@ impl ReconstructingDirector { } // Expressions - pub fn reduce_expression(&mut self, expression: &Expression) -> Expression { + pub fn reduce_expression(&mut self, expression: &Expression, in_circuit: bool) -> Result { let new = match expression { - Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)), - Expression::Value(value) => Expression::Value(self.reduce_value(&value)), - Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary)), - Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary)), - Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary)), - Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast)), + Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?), + Expression::Value(value) => Expression::Value(self.reduce_value(&value)?), + Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary, in_circuit)?), + Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary, in_circuit)?), + Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary, in_circuit)?), + Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast, in_circuit)?), - Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(&array_inline)), - Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(&array_init)), - Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(&array_access)), + Expression::ArrayInline(array_inline) => { + Expression::ArrayInline(self.reduce_array_inline(&array_inline, in_circuit)?) + } + Expression::ArrayInit(array_init) => { + Expression::ArrayInit(self.reduce_array_init(&array_init, in_circuit)?) + } + Expression::ArrayAccess(array_access) => { + Expression::ArrayAccess(self.reduce_array_access(&array_access, in_circuit)?) + } Expression::ArrayRangeAccess(array_range_access) => { - Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access)) + Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access, in_circuit)?) } - Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(&tuple_init)), - Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(&tuple_access)), + Expression::TupleInit(tuple_init) => { + Expression::TupleInit(self.reduce_tuple_init(&tuple_init, in_circuit)?) + } + Expression::TupleAccess(tuple_access) => { + Expression::TupleAccess(self.reduce_tuple_access(&tuple_access, in_circuit)?) + } - Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(&circuit_init)), + Expression::CircuitInit(circuit_init) => { + Expression::CircuitInit(self.reduce_circuit_init(&circuit_init, in_circuit)?) + } Expression::CircuitMemberAccess(circuit_member_access) => { - Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access)) + Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access, in_circuit)?) } Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => { - Expression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(&circuit_static_fn_access)) + Expression::CircuitStaticFunctionAccess( + self.reduce_circuit_static_fn_access(&circuit_static_fn_access, in_circuit)?, + ) } - Expression::Call(call) => Expression::Call(self.reduce_call(&call)), + Expression::Call(call) => Expression::Call(self.reduce_call(&call, in_circuit)?), }; - self.reducer.reduce_expression(expression, new) + self.reducer.reduce_expression(expression, new, in_circuit) } - pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { self.reducer.reduce_identifier(identifier) } - pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> GroupTuple { + pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { self.reducer.reduce_group_tuple(group_tuple) } - pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> GroupValue { + pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { let new = match group_value { - GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)), + GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?), _ => group_value.clone(), }; self.reducer.reduce_group_value(group_value, new) } - pub fn reduce_value(&mut self, value: &ValueExpression) -> ValueExpression { + pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { let new = match value { ValueExpression::Group(group_value) => { - ValueExpression::Group(Box::new(self.reduce_group_value(&group_value))) + ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)) } _ => value.clone(), }; @@ -104,256 +126,333 @@ impl ReconstructingDirector { self.reducer.reduce_value(value, new) } - pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> BinaryExpression { - let left = self.reduce_expression(&binary.left); - let right = self.reduce_expression(&binary.right); + pub fn reduce_binary(&mut self, binary: &BinaryExpression, in_circuit: bool) -> Result { + let left = self.reduce_expression(&binary.left, in_circuit)?; + let right = self.reduce_expression(&binary.right, in_circuit)?; - self.reducer.reduce_binary(binary, left, right, binary.op.clone()) + self.reducer + .reduce_binary(binary, left, right, binary.op.clone(), in_circuit) } - pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> UnaryExpression { - let inner = self.reduce_expression(&unary.inner); + pub fn reduce_unary(&mut self, unary: &UnaryExpression, in_circuit: bool) -> Result { + let inner = self.reduce_expression(&unary.inner, in_circuit)?; - self.reducer.reduce_unary(unary, inner, unary.op.clone()) + self.reducer.reduce_unary(unary, inner, unary.op.clone(), in_circuit) } - pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> TernaryExpression { - let condition = self.reduce_expression(&ternary.condition); - let if_true = self.reduce_expression(&ternary.if_true); - let if_false = self.reduce_expression(&ternary.if_false); + pub fn reduce_ternary(&mut self, ternary: &TernaryExpression, in_circuit: bool) -> Result { + let condition = self.reduce_expression(&ternary.condition, in_circuit)?; + let if_true = self.reduce_expression(&ternary.if_true, in_circuit)?; + let if_false = self.reduce_expression(&ternary.if_false, in_circuit)?; - self.reducer.reduce_ternary(ternary, condition, if_true, if_false) + self.reducer + .reduce_ternary(ternary, condition, if_true, if_false, in_circuit) } - pub fn reduce_cast(&mut self, cast: &CastExpression) -> CastExpression { - let inner = self.reduce_expression(&cast.inner); - let target_type = cast.target_type.clone(); // TODO reduce + pub fn reduce_cast(&mut self, cast: &CastExpression, in_circuit: bool) -> Result { + let inner = self.reduce_expression(&cast.inner, in_circuit)?; + let target_type = self.reduce_type(&cast.target_type, in_circuit)?; - self.reducer.reduce_cast(cast, inner, target_type) + self.reducer.reduce_cast(cast, inner, target_type, in_circuit) } - pub fn reduce_array_inline(&mut self, array_inline: &ArrayInlineExpression) -> ArrayInlineExpression { - let elements = array_inline - .elements - .iter() - .map(|element| match element { + pub fn reduce_array_inline( + &mut self, + array_inline: &ArrayInlineExpression, + in_circuit: bool, + ) -> Result { + let mut elements = vec![]; + for element in array_inline.elements.iter() { + let reduced_element = match element { SpreadOrExpression::Expression(expression) => { - SpreadOrExpression::Expression(self.reduce_expression(expression)) + SpreadOrExpression::Expression(self.reduce_expression(expression, in_circuit)?) } SpreadOrExpression::Spread(expression) => { - SpreadOrExpression::Spread(self.reduce_expression(expression)) + SpreadOrExpression::Spread(self.reduce_expression(expression, in_circuit)?) } - }) - .collect(); + }; - self.reducer.reduce_array_inline(array_inline, elements) + elements.push(reduced_element); + } + + self.reducer.reduce_array_inline(array_inline, elements, in_circuit) } - pub fn reduce_array_init(&mut self, array_init: &ArrayInitExpression) -> ArrayInitExpression { - let element = self.reduce_expression(&array_init.element); + pub fn reduce_array_init( + &mut self, + array_init: &ArrayInitExpression, + in_circuit: bool, + ) -> Result { + let element = self.reduce_expression(&array_init.element, in_circuit)?; - self.reducer.reduce_array_init(array_init, element) + self.reducer.reduce_array_init(array_init, element, in_circuit) } - pub fn reduce_array_access(&mut self, array_access: &ArrayAccessExpression) -> ArrayAccessExpression { - let array = self.reduce_expression(&array_access.array); - let index = self.reduce_expression(&array_access.index); + pub fn reduce_array_access( + &mut self, + array_access: &ArrayAccessExpression, + in_circuit: bool, + ) -> Result { + let array = self.reduce_expression(&array_access.array, in_circuit)?; + let index = self.reduce_expression(&array_access.index, in_circuit)?; - self.reducer.reduce_array_access(array_access, array, index) + self.reducer.reduce_array_access(array_access, array, index, in_circuit) } pub fn reduce_array_range_access( &mut self, array_range_access: &ArrayRangeAccessExpression, - ) -> ArrayRangeAccessExpression { - let array = self.reduce_expression(&array_range_access.array); - let left = array_range_access - .left - .as_ref() - .map(|left| self.reduce_expression(left)); - let right = array_range_access - .right - .as_ref() - .map(|right| self.reduce_expression(right)); + in_circuit: bool, + ) -> Result { + let array = self.reduce_expression(&array_range_access.array, in_circuit)?; + let left = match array_range_access.left.as_ref() { + Some(left) => Some(self.reduce_expression(left, in_circuit)?), + None => None, + }; + let right = match array_range_access.right.as_ref() { + Some(right) => Some(self.reduce_expression(right, in_circuit)?), + None => None, + }; self.reducer - .reduce_array_range_access(array_range_access, array, left, right) + .reduce_array_range_access(array_range_access, array, left, right, in_circuit) } - pub fn reduce_tuple_init(&mut self, tuple_init: &TupleInitExpression) -> TupleInitExpression { - let elements = tuple_init - .elements - .iter() - .map(|expr| self.reduce_expression(expr)) - .collect(); + pub fn reduce_tuple_init( + &mut self, + tuple_init: &TupleInitExpression, + in_circuit: bool, + ) -> Result { + let mut elements = vec![]; + for element in tuple_init.elements.iter() { + elements.push(self.reduce_expression(element, in_circuit)?); + } - self.reducer.reduce_tuple_init(tuple_init, elements) + self.reducer.reduce_tuple_init(tuple_init, elements, in_circuit) } - pub fn reduce_tuple_access(&mut self, tuple_access: &TupleAccessExpression) -> TupleAccessExpression { - let tuple = self.reduce_expression(&tuple_access.tuple); + pub fn reduce_tuple_access( + &mut self, + tuple_access: &TupleAccessExpression, + in_circuit: bool, + ) -> Result { + let tuple = self.reduce_expression(&tuple_access.tuple, in_circuit)?; - self.reducer.reduce_tuple_access(tuple_access, tuple) + self.reducer.reduce_tuple_access(tuple_access, tuple, in_circuit) } - pub fn reduce_circuit_init(&mut self, circuit_init: &CircuitInitExpression) -> CircuitInitExpression { - let name = self.reduce_identifier(&circuit_init.name); - let members = circuit_init - .members - .iter() - .map(|definition| { - let identifier = self.reduce_identifier(&definition.identifier); - let expression = definition.expression.as_ref().map(|expr| self.reduce_expression(expr)); + pub fn reduce_circuit_implied_variable_definition( + &mut self, + variable: &CircuitImpliedVariableDefinition, + in_circuit: bool, + ) -> Result { + let identifier = self.reduce_identifier(&variable.identifier)?; + let expression = match variable.expression.as_ref() { + Some(expr) => Some(self.reduce_expression(expr, in_circuit)?), + None => None, + }; - CircuitImpliedVariableDefinition { identifier, expression } - }) - .collect(); + self.reducer + .reduce_circuit_implied_variable_definition(variable, identifier, expression, in_circuit) + } - self.reducer.reduce_circuit_init(circuit_init, name, members) + pub fn reduce_circuit_init( + &mut self, + circuit_init: &CircuitInitExpression, + in_circuit: bool, + ) -> Result { + let name = self.reduce_identifier(&circuit_init.name)?; + + let mut members = vec![]; + for member in circuit_init.members.iter() { + members.push(self.reduce_circuit_implied_variable_definition(member, in_circuit)?); + } + + self.reducer + .reduce_circuit_init(circuit_init, name, members, in_circuit) } pub fn reduce_circuit_member_access( &mut self, circuit_member_access: &CircuitMemberAccessExpression, - ) -> CircuitMemberAccessExpression { - let circuit = self.reduce_expression(&circuit_member_access.circuit); - let name = self.reduce_identifier(&circuit_member_access.name); + in_circuit: bool, + ) -> Result { + let circuit = self.reduce_expression(&circuit_member_access.circuit, in_circuit)?; + let name = self.reduce_identifier(&circuit_member_access.name)?; self.reducer - .reduce_circuit_member_access(circuit_member_access, circuit, name) + .reduce_circuit_member_access(circuit_member_access, circuit, name, in_circuit) } pub fn reduce_circuit_static_fn_access( &mut self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, - ) -> CircuitStaticFunctionAccessExpression { - let circuit = self.reduce_expression(&circuit_static_fn_access.circuit); - let name = self.reduce_identifier(&circuit_static_fn_access.name); + in_circuit: bool, + ) -> Result { + let circuit = self.reduce_expression(&circuit_static_fn_access.circuit, in_circuit)?; + let name = self.reduce_identifier(&circuit_static_fn_access.name)?; self.reducer - .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name) + .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name, in_circuit) } - pub fn reduce_call(&mut self, call: &CallExpression) -> CallExpression { - let function = self.reduce_expression(&call.function); - let arguments = call.arguments.iter().map(|expr| self.reduce_expression(expr)).collect(); + pub fn reduce_call(&mut self, call: &CallExpression, in_circuit: bool) -> Result { + let function = self.reduce_expression(&call.function, in_circuit)?; - self.reducer.reduce_call(call, function, arguments) + let mut arguments = vec![]; + for argument in call.arguments.iter() { + arguments.push(self.reduce_expression(argument, in_circuit)?); + } + + self.reducer.reduce_call(call, function, arguments, in_circuit) } // Statements - pub fn reduce_statement(&mut self, statement: &Statement, in_circuit: bool) -> Statement { + pub fn reduce_statement(&mut self, statement: &Statement, in_circuit: bool) -> Result { let new = match statement { - Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)), - Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition, in_circuit)), - Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)), - Statement::Conditional(conditional) => { - Statement::Conditional(self.reduce_conditional(&conditional, in_circuit)) + Statement::Return(return_statement) => { + Statement::Return(self.reduce_return(&return_statement, in_circuit)?) } - Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration, in_circuit)), - Statement::Console(console) => Statement::Console(self.reduce_console(&console)), - Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)), - Statement::Block(block) => Statement::Block(self.reduce_block(&block, in_circuit)), + Statement::Definition(definition) => { + Statement::Definition(self.reduce_definition(&definition, in_circuit)?) + } + Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign, in_circuit)?), + Statement::Conditional(conditional) => { + Statement::Conditional(self.reduce_conditional(&conditional, in_circuit)?) + } + Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration, in_circuit)?), + Statement::Console(console) => Statement::Console(self.reduce_console(&console, in_circuit)?), + Statement::Expression(expression) => { + Statement::Expression(self.reduce_expression_statement(&expression, in_circuit)?) + } + Statement::Block(block) => Statement::Block(self.reduce_block(&block, in_circuit)?), }; self.reducer.reduce_statement(statement, new, in_circuit) } - pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> ReturnStatement { - let expression = self.reduce_expression(&return_statement.expression); + pub fn reduce_return(&mut self, return_statement: &ReturnStatement, in_circuit: bool) -> Result { + let expression = self.reduce_expression(&return_statement.expression, in_circuit)?; - self.reducer.reduce_return(return_statement, expression) + self.reducer.reduce_return(return_statement, expression, in_circuit) } - pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> VariableName { - let identifier = self.reduce_identifier(&variable_name.identifier); + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { + let identifier = self.reduce_identifier(&variable_name.identifier)?; self.reducer.reduce_variable_name(variable_name, identifier) } - pub fn reduce_definition(&mut self, definition: &DefinitionStatement, in_circuit: bool) -> DefinitionStatement { - let variable_names = definition - .variable_names - .iter() - .map(|variable_name| self.reduce_variable_name(variable_name)) - .collect(); - let type_ = definition - .type_ - .as_ref() - .map(|inner| self.reduce_type(inner, in_circuit)); - let value = self.reduce_expression(&definition.value); + pub fn reduce_definition( + &mut self, + definition: &DefinitionStatement, + in_circuit: bool, + ) -> Result { + let mut variable_names = vec![]; + for variable_name in definition.variable_names.iter() { + variable_names.push(self.reduce_variable_name(variable_name)?); + } + + let type_ = match definition.type_.as_ref() { + Some(inner) => Some(self.reduce_type(inner, in_circuit)?), + None => None, + }; + + let value = self.reduce_expression(&definition.value, in_circuit)?; self.reducer .reduce_definition(definition, variable_names, type_, value, in_circuit) } - pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> AssigneeAccess { + pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess, in_circuit: bool) -> Result { let new = match access { - AssigneeAccess::ArrayRange(left, right) => AssigneeAccess::ArrayRange( - left.as_ref().map(|expr| self.reduce_expression(expr)), - right.as_ref().map(|expr| self.reduce_expression(expr)), - ), - AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(&index)), - AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)), + AssigneeAccess::ArrayRange(left, right) => { + let left = match left.as_ref() { + Some(left) => Some(self.reduce_expression(left, in_circuit)?), + None => None, + }; + let right = match right.as_ref() { + Some(right) => Some(self.reduce_expression(right, in_circuit)?), + None => None, + }; + + AssigneeAccess::ArrayRange(left, right) + } + AssigneeAccess::ArrayIndex(index) => { + AssigneeAccess::ArrayIndex(self.reduce_expression(&index, in_circuit)?) + } + AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)?), _ => access.clone(), }; - self.reducer.reduce_assignee_access(access, new) + self.reducer.reduce_assignee_access(access, new, in_circuit) } - pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Assignee { - let identifier = self.reduce_identifier(&assignee.identifier); - let accesses = assignee - .accesses - .iter() - .map(|access| self.reduce_assignee_access(access)) - .collect(); + pub fn reduce_assignee(&mut self, assignee: &Assignee, in_circuit: bool) -> Result { + let identifier = self.reduce_identifier(&assignee.identifier)?; - self.reducer.reduce_assignee(assignee, identifier, accesses) + let mut accesses = vec![]; + for access in assignee.accesses.iter() { + accesses.push(self.reduce_assignee_access(access, in_circuit)?); + } + + self.reducer.reduce_assignee(assignee, identifier, accesses, in_circuit) } - pub fn reduce_assign(&mut self, assign: &AssignStatement) -> AssignStatement { - let assignee = self.reduce_assignee(&assign.assignee); - let value = self.reduce_expression(&assign.value); + pub fn reduce_assign(&mut self, assign: &AssignStatement, in_circuit: bool) -> Result { + let assignee = self.reduce_assignee(&assign.assignee, in_circuit)?; + let value = self.reduce_expression(&assign.value, in_circuit)?; - self.reducer.reduce_assign(assign, assignee, value) + self.reducer.reduce_assign(assign, assignee, value, in_circuit) } - pub fn reduce_conditional(&mut self, conditional: &ConditionalStatement, in_circuit: bool) -> ConditionalStatement { - let condition = self.reduce_expression(&conditional.condition); - let block = self.reduce_block(&conditional.block, in_circuit); - let next = conditional - .next - .as_ref() - .map(|condition| self.reduce_statement(condition, in_circuit)); + pub fn reduce_conditional( + &mut self, + conditional: &ConditionalStatement, + in_circuit: bool, + ) -> Result { + let condition = self.reduce_expression(&conditional.condition, in_circuit)?; + let block = self.reduce_block(&conditional.block, in_circuit)?; + let next = match conditional.next.as_ref() { + Some(condition) => Some(self.reduce_statement(condition, in_circuit)?), + None => None, + }; self.reducer .reduce_conditional(conditional, condition, block, next, in_circuit) } - pub fn reduce_iteration(&mut self, iteration: &IterationStatement, in_circuit: bool) -> IterationStatement { - let variable = self.reduce_identifier(&iteration.variable); - let start = self.reduce_expression(&iteration.start); - let stop = self.reduce_expression(&iteration.stop); - let block = self.reduce_block(&iteration.block, in_circuit); + pub fn reduce_iteration(&mut self, iteration: &IterationStatement, in_circuit: bool) -> Result { + let variable = self.reduce_identifier(&iteration.variable)?; + let start = self.reduce_expression(&iteration.start, in_circuit)?; + let stop = self.reduce_expression(&iteration.stop, in_circuit)?; + let block = self.reduce_block(&iteration.block, in_circuit)?; self.reducer .reduce_iteration(iteration, variable, start, stop, block, in_circuit) } - pub fn reduce_console(&mut self, console_function_call: &ConsoleStatement) -> ConsoleStatement { + pub fn reduce_console( + &mut self, + console_function_call: &ConsoleStatement, + in_circuit: bool, + ) -> Result { let function = match &console_function_call.function { - ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)), + ConsoleFunction::Assert(expression) => { + ConsoleFunction::Assert(self.reduce_expression(expression, in_circuit)?) + } ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { + let mut parameters = vec![]; + for parameter in format.parameters.iter() { + parameters.push(self.reduce_expression(parameter, in_circuit)?); + } + let formatted = FormattedString { parts: format.parts.clone(), - parameters: format - .parameters - .iter() - .map(|parameter| self.reduce_expression(parameter)) - .collect(), + parameters, span: format.span.clone(), }; + match &console_function_call.function { ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted), ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), @@ -363,51 +462,52 @@ impl ReconstructingDirector { } }; - self.reducer.reduce_console(console_function_call, function) + self.reducer.reduce_console(console_function_call, function, in_circuit) } - pub fn reduce_expression_statement(&mut self, expression: &ExpressionStatement) -> ExpressionStatement { - let inner_expression = self.reduce_expression(&expression.expression); - self.reducer.reduce_expression_statement(expression, inner_expression) + pub fn reduce_expression_statement( + &mut self, + expression: &ExpressionStatement, + in_circuit: bool, + ) -> Result { + let inner_expression = self.reduce_expression(&expression.expression, in_circuit)?; + self.reducer + .reduce_expression_statement(expression, inner_expression, in_circuit) } - pub fn reduce_block(&mut self, block: &Block, in_circuit: bool) -> Block { - let statements = block - .statements - .iter() - .map(|statement| self.reduce_statement(statement, in_circuit)) - .collect(); + pub fn reduce_block(&mut self, block: &Block, in_circuit: bool) -> Result { + let mut statements = vec![]; + for statement in block.statements.iter() { + statements.push(self.reduce_statement(statement, in_circuit)?); + } self.reducer.reduce_block(block, statements, in_circuit) } // Program - pub fn reduce_program(&mut self, program: &Program) -> Program { - let inputs = program - .expected_input - .iter() - .map(|input| self.reduce_function_input(input, false)) - .collect(); - let imports = program - .imports - .iter() - .map(|import| self.reduce_import(import)) - .collect(); - let circuits = program - .circuits - .iter() - .map(|(identifier, circuit)| (self.reduce_identifier(identifier), self.reduce_circuit(circuit))) - .collect(); - let functions = program - .functions - .iter() - .map(|(identifier, function)| { - ( - self.reduce_identifier(identifier), - self.reduce_function(function, false), - ) - }) - .collect(); + pub fn reduce_program(&mut self, program: &Program) -> Result { + let mut inputs = vec![]; + for input in program.expected_input.iter() { + inputs.push(self.reduce_function_input(input, false)?); + } + + let mut imports = vec![]; + for import in program.imports.iter() { + imports.push(self.reduce_import(import)?); + } + + let mut circuits = IndexMap::new(); + for (identifier, circuit) in program.circuits.iter() { + circuits.insert(self.reduce_identifier(identifier)?, self.reduce_circuit(circuit)?); + } + + let mut functions = IndexMap::new(); + for (identifier, function) in program.functions.iter() { + functions.insert( + self.reduce_identifier(identifier)?, + self.reduce_function(function, false)?, + ); + } self.reducer .reduce_program(program, inputs, imports, circuits, functions) @@ -417,18 +517,18 @@ impl ReconstructingDirector { &mut self, variable: &FunctionInputVariable, in_circuit: bool, - ) -> FunctionInputVariable { - let identifier = self.reduce_identifier(&variable.identifier); - let type_ = self.reduce_type(&variable.type_, in_circuit); + ) -> Result { + let identifier = self.reduce_identifier(&variable.identifier)?; + let type_ = self.reduce_type(&variable.type_, in_circuit)?; self.reducer .reduce_function_input_variable(variable, identifier, type_, in_circuit) } - pub fn reduce_function_input(&mut self, input: &FunctionInput, in_circuit: bool) -> FunctionInput { + pub fn reduce_function_input(&mut self, input: &FunctionInput, in_circuit: bool) -> Result { let new = match input { FunctionInput::Variable(function_input_variable) => { - FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable, in_circuit)) + FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable, in_circuit)?) } _ => input.clone(), }; @@ -436,15 +536,15 @@ impl ReconstructingDirector { self.reducer.reduce_function_input(input, new, in_circuit) } - pub fn reduce_package_or_packages(&mut self, package_or_packages: &PackageOrPackages) -> PackageOrPackages { + pub fn reduce_package_or_packages(&mut self, package_or_packages: &PackageOrPackages) -> Result { let new = match package_or_packages { PackageOrPackages::Package(package) => PackageOrPackages::Package(Package { - name: self.reduce_identifier(&package.name), + name: self.reduce_identifier(&package.name)?, access: package.access.clone(), span: package.span.clone(), }), PackageOrPackages::Packages(packages) => PackageOrPackages::Packages(Packages { - name: self.reduce_identifier(&packages.name), + name: self.reduce_identifier(&packages.name)?, accesses: packages.accesses.clone(), span: packages.span.clone(), }), @@ -453,61 +553,63 @@ impl ReconstructingDirector { self.reducer.reduce_package_or_packages(package_or_packages, new) } - pub fn reduce_import(&mut self, import: &ImportStatement) -> ImportStatement { - let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages); + pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { + let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?; self.reducer.reduce_import(import, package_or_packages) } - pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> CircuitMember { + pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result { let new = match circuit_member { CircuitMember::CircuitVariable(identifier, type_) => { - CircuitMember::CircuitVariable(self.reduce_identifier(&identifier), self.reduce_type(&type_, true)) + CircuitMember::CircuitVariable(self.reduce_identifier(&identifier)?, self.reduce_type(&type_, true)?) } CircuitMember::CircuitFunction(function) => { - CircuitMember::CircuitFunction(self.reduce_function(&function, true)) + CircuitMember::CircuitFunction(self.reduce_function(&function, true)?) } }; self.reducer.reduce_circuit_member(circuit_member, new) } - pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Circuit { - let circuit_name = self.reduce_identifier(&circuit.circuit_name); - let members = circuit - .members - .iter() - .map(|member| self.reduce_circuit_member(member)) - .collect(); + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { + let circuit_name = self.reduce_identifier(&circuit.circuit_name)?; + + let mut members = vec![]; + for member in circuit.members.iter() { + members.push(self.reduce_circuit_member(member)?); + } self.reducer.reduce_circuit(circuit, circuit_name, members) } - fn reduce_annotation(&mut self, annotation: &Annotation) -> Annotation { - let name = self.reduce_identifier(&annotation.name); + fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { + let name = self.reduce_identifier(&annotation.name)?; self.reducer.reduce_annotation(annotation, name) } - pub fn reduce_function(&mut self, function: &Function, in_circuit: bool) -> Function { - let identifier = self.reduce_identifier(&function.identifier); - let annotations = function - .annotations - .iter() - .map(|annotation| self.reduce_annotation(annotation)) - .collect(); - let input = function - .input - .iter() - .map(|input| self.reduce_function_input(input, false)) - .collect(); - let output = function - .output - .as_ref() - .map(|output| self.reduce_type(output, in_circuit)); - let block = self.reduce_block(&function.block, false); + pub fn reduce_function(&mut self, function: &Function, in_circuit: bool) -> Result { + let identifier = self.reduce_identifier(&function.identifier)?; + + let mut annotations = vec![]; + for annotation in function.annotations.iter() { + annotations.push(self.reduce_annotation(annotation)?); + } + + let mut inputs = vec![]; + for input in function.input.iter() { + inputs.push(self.reduce_function_input(input, false)?); + } + + let output = match function.output.as_ref() { + Some(type_) => Some(self.reduce_type(type_, in_circuit)?), + None => None, + }; + + let block = self.reduce_block(&function.block, false)?; self.reducer - .reduce_function(function, identifier, annotations, input, output, block, in_circuit) + .reduce_function(function, identifier, annotations, inputs, output, block, in_circuit) } } diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 2cc4945449..be5b39aeac 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -15,41 +15,47 @@ // along with the Leo library. If not, see . use crate::*; +use anyhow::Result; use indexmap::IndexMap; // Needed to fix clippy bug. #[allow(clippy::redundant_closure)] pub trait ReconstructingReducer { - fn reduce_type(&mut self, _type_: &Type, new: Type, _in_circuit: bool) -> Type { - new + fn reduce_type(&mut self, _type_: &Type, new: Type, _in_circuit: bool) -> Result { + Ok(new) } // Expressions - fn reduce_expression(&mut self, _expression: &Expression, new: Expression) -> Expression { - new + fn reduce_expression( + &mut self, + _expression: &Expression, + new: Expression, + _in_circuit: bool, + ) -> Result { + Ok(new) } - fn reduce_identifier(&mut self, identifier: &Identifier) -> Identifier { - Identifier { + fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + Ok(Identifier { name: identifier.name.clone(), span: identifier.span.clone(), - } + }) } - fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> GroupTuple { - GroupTuple { + fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + Ok(GroupTuple { x: group_tuple.x.clone(), y: group_tuple.y.clone(), span: group_tuple.span.clone(), - } + }) } - fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> GroupValue { - new + fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> Result { + Ok(new) } - fn reduce_value(&mut self, _value: &ValueExpression, new: ValueExpression) -> ValueExpression { - new + fn reduce_value(&mut self, _value: &ValueExpression, new: ValueExpression) -> Result { + Ok(new) } fn reduce_binary( @@ -58,21 +64,28 @@ pub trait ReconstructingReducer { left: Expression, right: Expression, op: BinaryOperation, - ) -> BinaryExpression { - BinaryExpression { + _in_circuit: bool, + ) -> Result { + Ok(BinaryExpression { left: Box::new(left), right: Box::new(right), op, span: binary.span.clone(), - } + }) } - fn reduce_unary(&mut self, unary: &UnaryExpression, inner: Expression, op: UnaryOperation) -> UnaryExpression { - UnaryExpression { + fn reduce_unary( + &mut self, + unary: &UnaryExpression, + inner: Expression, + op: UnaryOperation, + _in_circuit: bool, + ) -> Result { + Ok(UnaryExpression { inner: Box::new(inner), op, span: unary.span.clone(), - } + }) } fn reduce_ternary( @@ -81,40 +94,53 @@ pub trait ReconstructingReducer { condition: Expression, if_true: Expression, if_false: Expression, - ) -> TernaryExpression { - TernaryExpression { + _in_circuit: bool, + ) -> Result { + Ok(TernaryExpression { condition: Box::new(condition), if_true: Box::new(if_true), if_false: Box::new(if_false), span: ternary.span.clone(), - } + }) } - fn reduce_cast(&mut self, cast: &CastExpression, inner: Expression, target_type: Type) -> CastExpression { - CastExpression { + fn reduce_cast( + &mut self, + cast: &CastExpression, + inner: Expression, + target_type: Type, + _in_circuit: bool, + ) -> Result { + Ok(CastExpression { inner: Box::new(inner), target_type, span: cast.span.clone(), - } + }) } fn reduce_array_inline( &mut self, array_inline: &ArrayInlineExpression, elements: Vec, - ) -> ArrayInlineExpression { - ArrayInlineExpression { + _in_circuit: bool, + ) -> Result { + Ok(ArrayInlineExpression { elements, span: array_inline.span.clone(), - } + }) } - fn reduce_array_init(&mut self, array_init: &ArrayInitExpression, element: Expression) -> ArrayInitExpression { - ArrayInitExpression { + fn reduce_array_init( + &mut self, + array_init: &ArrayInitExpression, + element: Expression, + _in_circuit: bool, + ) -> Result { + Ok(ArrayInitExpression { element: Box::new(element), dimensions: array_init.dimensions.clone(), span: array_init.span.clone(), - } + }) } fn reduce_array_access( @@ -122,12 +148,13 @@ pub trait ReconstructingReducer { array_access: &ArrayAccessExpression, array: Expression, index: Expression, - ) -> ArrayAccessExpression { - ArrayAccessExpression { + _in_circuit: bool, + ) -> Result { + Ok(ArrayAccessExpression { array: Box::new(array), index: Box::new(index), span: array_access.span.clone(), - } + }) } fn reduce_array_range_access( @@ -136,36 +163,49 @@ pub trait ReconstructingReducer { array: Expression, left: Option, right: Option, - ) -> ArrayRangeAccessExpression { - ArrayRangeAccessExpression { + _in_circuit: bool, + ) -> Result { + Ok(ArrayRangeAccessExpression { array: Box::new(array), left: left.map(|expr| Box::new(expr)), right: right.map(|expr| Box::new(expr)), span: array_rage_access.span.clone(), - } + }) } fn reduce_tuple_init( &mut self, tuple_init: &TupleInitExpression, elements: Vec, - ) -> TupleInitExpression { - TupleInitExpression { + _in_circuit: bool, + ) -> Result { + Ok(TupleInitExpression { elements, span: tuple_init.span.clone(), - } + }) } fn reduce_tuple_access( &mut self, tuple_access: &TupleAccessExpression, tuple: Expression, - ) -> TupleAccessExpression { - TupleAccessExpression { + _in_circuit: bool, + ) -> Result { + Ok(TupleAccessExpression { tuple: Box::new(tuple), index: tuple_access.index.clone(), span: tuple_access.span.clone(), - } + }) + } + + fn reduce_circuit_implied_variable_definition( + &mut self, + _variable: &CircuitImpliedVariableDefinition, + identifier: Identifier, + expression: Option, + _in_circuit: bool, + ) -> Result { + Ok(CircuitImpliedVariableDefinition { identifier, expression }) } fn reduce_circuit_init( @@ -173,12 +213,13 @@ pub trait ReconstructingReducer { circuit_init: &CircuitInitExpression, name: Identifier, members: Vec, - ) -> CircuitInitExpression { - CircuitInitExpression { + _in_circuit: bool, + ) -> Result { + Ok(CircuitInitExpression { name, members, span: circuit_init.span.clone(), - } + }) } fn reduce_circuit_member_access( @@ -186,12 +227,13 @@ pub trait ReconstructingReducer { circuit_member_access: &CircuitMemberAccessExpression, circuit: Expression, name: Identifier, - ) -> CircuitMemberAccessExpression { - CircuitMemberAccessExpression { + _in_circuit: bool, + ) -> Result { + Ok(CircuitMemberAccessExpression { circuit: Box::new(circuit), name, span: circuit_member_access.span.clone(), - } + }) } fn reduce_circuit_static_fn_access( @@ -199,12 +241,13 @@ pub trait ReconstructingReducer { circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, circuit: Expression, name: Identifier, - ) -> CircuitStaticFunctionAccessExpression { - CircuitStaticFunctionAccessExpression { + _in_circuit: bool, + ) -> Result { + Ok(CircuitStaticFunctionAccessExpression { circuit: Box::new(circuit), name, span: circuit_static_fn_access.span.clone(), - } + }) } fn reduce_call( @@ -212,32 +255,38 @@ pub trait ReconstructingReducer { call: &CallExpression, function: Expression, arguments: Vec, - ) -> CallExpression { - CallExpression { + _in_circuit: bool, + ) -> Result { + Ok(CallExpression { function: Box::new(function), arguments, span: call.span.clone(), - } + }) } // Statements - fn reduce_statement(&mut self, _statement: &Statement, new: Statement, _in_circuit: bool) -> Statement { - new + fn reduce_statement(&mut self, _statement: &Statement, new: Statement, _in_circuit: bool) -> Result { + Ok(new) } - fn reduce_return(&mut self, return_statement: &ReturnStatement, expression: Expression) -> ReturnStatement { - ReturnStatement { + fn reduce_return( + &mut self, + return_statement: &ReturnStatement, + expression: Expression, + _in_circuit: bool, + ) -> Result { + Ok(ReturnStatement { expression, span: return_statement.span.clone(), - } + }) } - fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> VariableName { - VariableName { + fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> Result { + Ok(VariableName { mutable: variable_name.mutable, identifier, span: variable_name.span.clone(), - } + }) } fn reduce_definition( @@ -247,18 +296,23 @@ pub trait ReconstructingReducer { type_: Option, value: Expression, _in_circuit: bool, - ) -> DefinitionStatement { - DefinitionStatement { + ) -> Result { + Ok(DefinitionStatement { declaration_type: definition.declaration_type.clone(), variable_names, type_, value, span: definition.span.clone(), - } + }) } - fn reduce_assignee_access(&mut self, _access: &AssigneeAccess, new: AssigneeAccess) -> AssigneeAccess { - new + fn reduce_assignee_access( + &mut self, + _access: &AssigneeAccess, + new: AssigneeAccess, + _in_circuit: bool, + ) -> Result { + Ok(new) } fn reduce_assignee( @@ -266,21 +320,28 @@ pub trait ReconstructingReducer { assignee: &Assignee, identifier: Identifier, accesses: Vec, - ) -> Assignee { - Assignee { + _in_circuit: bool, + ) -> Result { + Ok(Assignee { identifier, accesses, span: assignee.span.clone(), - } + }) } - fn reduce_assign(&mut self, assign: &AssignStatement, assignee: Assignee, value: Expression) -> AssignStatement { - AssignStatement { + fn reduce_assign( + &mut self, + assign: &AssignStatement, + assignee: Assignee, + value: Expression, + _in_circuit: bool, + ) -> Result { + Ok(AssignStatement { operation: assign.operation.clone(), assignee, value, span: assign.span.clone(), - } + }) } fn reduce_conditional( @@ -290,13 +351,13 @@ pub trait ReconstructingReducer { block: Block, statement: Option, _in_circuit: bool, - ) -> ConditionalStatement { - ConditionalStatement { + ) -> Result { + Ok(ConditionalStatement { condition, block, next: statement.map(|statement| Box::new(statement)), span: conditional.span.clone(), - } + }) } fn reduce_iteration( @@ -307,39 +368,45 @@ pub trait ReconstructingReducer { stop: Expression, block: Block, _in_circuit: bool, - ) -> IterationStatement { - IterationStatement { + ) -> Result { + Ok(IterationStatement { variable, start, stop, block, span: iteration.span.clone(), - } + }) } - fn reduce_console(&mut self, console: &ConsoleStatement, function: ConsoleFunction) -> ConsoleStatement { - ConsoleStatement { + fn reduce_console( + &mut self, + console: &ConsoleStatement, + function: ConsoleFunction, + _in_circuit: bool, + ) -> Result { + Ok(ConsoleStatement { function, span: console.span.clone(), - } + }) } fn reduce_expression_statement( &mut self, expression_statement: &ExpressionStatement, expression: Expression, - ) -> ExpressionStatement { - ExpressionStatement { + _in_circuit: bool, + ) -> Result { + Ok(ExpressionStatement { expression, span: expression_statement.span.clone(), - } + }) } - fn reduce_block(&mut self, block: &Block, statements: Vec, _in_circuit: bool) -> Block { - Block { + fn reduce_block(&mut self, block: &Block, statements: Vec, _in_circuit: bool) -> Result { + Ok(Block { statements, span: block.span.clone(), - } + }) } // Program @@ -350,14 +417,14 @@ pub trait ReconstructingReducer { imports: Vec, circuits: IndexMap, functions: IndexMap, - ) -> Program { - Program { + ) -> Result { + Ok(Program { name: program.name.clone(), expected_input, imports, circuits, functions, - } + }) } fn reduce_function_input_variable( @@ -366,14 +433,14 @@ pub trait ReconstructingReducer { identifier: Identifier, type_: Type, _in_circuit: bool, - ) -> FunctionInputVariable { - FunctionInputVariable { + ) -> Result { + Ok(FunctionInputVariable { identifier, const_: variable.const_, mutable: variable.mutable, type_, span: variable.span.clone(), - } + }) } fn reduce_function_input( @@ -381,39 +448,48 @@ pub trait ReconstructingReducer { _input: &FunctionInput, new: FunctionInput, _in_circuit: bool, - ) -> FunctionInput { - new + ) -> Result { + Ok(new) } fn reduce_package_or_packages( &mut self, _package_or_packages: &PackageOrPackages, new: PackageOrPackages, - ) -> PackageOrPackages { - new + ) -> Result { + Ok(new) } - fn reduce_import(&mut self, import: &ImportStatement, package_or_packages: PackageOrPackages) -> ImportStatement { - ImportStatement { + fn reduce_import( + &mut self, + import: &ImportStatement, + package_or_packages: PackageOrPackages, + ) -> Result { + Ok(ImportStatement { package_or_packages, span: import.span.clone(), - } + }) } - fn reduce_circuit_member(&mut self, _circuit_member: &CircuitMember, new: CircuitMember) -> CircuitMember { - new + fn reduce_circuit_member(&mut self, _circuit_member: &CircuitMember, new: CircuitMember) -> Result { + Ok(new) } - fn reduce_circuit(&mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec) -> Circuit { - Circuit { circuit_name, members } + fn reduce_circuit( + &mut self, + _circuit: &Circuit, + circuit_name: Identifier, + members: Vec, + ) -> Result { + Ok(Circuit { circuit_name, members }) } - fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Annotation { - Annotation { + fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Result { + Ok(Annotation { span: annotation.span.clone(), name, arguments: annotation.arguments.clone(), - } + }) } #[allow(clippy::too_many_arguments)] @@ -426,14 +502,14 @@ pub trait ReconstructingReducer { output: Option, block: Block, _in_circuit: bool, - ) -> Function { - Function { + ) -> Result { + Ok(Function { identifier, annotations, input, output, block, span: function.span.clone(), - } + }) } } From ac135426380d80266e2ae72d899be7089ac8e57d Mon Sep 17 00:00:00 2001 From: gluax Date: Mon, 15 Mar 2021 13:37:23 -0400 Subject: [PATCH 13/40] Proper Errors --- ast/src/lib.rs | 8 +- ast/src/reducer/canonicalization.rs | 37 +++-- ast/src/reducer/errors.rs | 41 ++++++ ast/src/reducer/mod.rs | 3 + ast/src/reducer/reconstructing_director.rs | 160 ++++++++++++++------- ast/src/reducer/reconstructing_reducer.rs | 121 ++++++++++------ compiler/src/compiler.rs | 3 +- compiler/src/errors/compiler.rs | 5 +- 8 files changed, 258 insertions(+), 120 deletions(-) create mode 100644 ast/src/reducer/errors.rs diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 6800701560..65bbc74f95 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -19,6 +19,10 @@ //! 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 +65,6 @@ pub use self::types::*; mod node; pub use node::*; -use anyhow::Result; - /// The abstract syntax tree (AST) for a Leo program. /// /// The [`Ast`] type represents a Leo program as a series of recursive data types. @@ -80,7 +82,7 @@ impl Ast { Self { ast: program } } - pub fn canonicalize(&mut self) -> Result<()> { + pub fn canonicalize(&mut self) -> Result<(), CanonicalizeError> { self.ast = ReconstructingDirector::new(Canonicalizer).reduce_program(self.as_repr())?; Ok(()) } diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 9dde3a1886..69f2a36032 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -15,7 +15,6 @@ // along with the Leo library. If not, see . use crate::*; -use anyhow::Result; pub struct Canonicalizer; @@ -143,14 +142,18 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_type(&mut self, _type_: &Type, new: Type, in_circuit: bool) -> Result { + fn reduce_type( + &mut self, + _type_: &Type, + new: Type, + in_circuit: bool, + span: &Span, + ) -> Result { match new { Type::Array(_, mut dimensions) => { - // TODO need to throw errors in all these. - // Throw error if dimensions is empty. - // if array_init.dimensions.0.len() == 0 { - - // } + if dimensions.0.len() == 0 { + return Err(CanonicalizeError::invalid_array_dimension_size(span).into()); + } let mut next = Type::Array( Box::new(Type::Group), @@ -168,10 +171,7 @@ impl ReconstructingReducer for Canonicalizer { Ok(array) } - Type::SelfType if !in_circuit => { - println!("Brrr bad Self"); - Ok(new.clone()) - } + Type::SelfType if !in_circuit => Err(CanonicalizeError::big_self_outside_of_circuit(span)), _ => Ok(new.clone()), } } @@ -181,11 +181,10 @@ impl ReconstructingReducer for Canonicalizer { array_init: &ArrayInitExpression, element: Expression, _in_circuit: bool, - ) -> Result { - // TODO ERROR HERE if len is 0 - // if array_init.dimensions.0.len() == 0 { - - // } + ) -> Result { + if array_init.dimensions.0.len() == 0 { + return Err(CanonicalizeError::invalid_array_dimension_size(&array_init.span)); + } let element = Box::new(element); @@ -232,7 +231,7 @@ impl ReconstructingReducer for Canonicalizer { assignee: Assignee, value: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { match value { Expression::Value(value) => { let left = Box::new(Expression::Identifier(assignee.identifier.clone())); @@ -282,7 +281,7 @@ impl ReconstructingReducer for Canonicalizer { output: Option, block: Block, _in_circuit: bool, - ) -> Result { + ) -> Result { let new_output = match output { None => Some(Type::Tuple(vec![])), _ => output, @@ -303,7 +302,7 @@ impl ReconstructingReducer for Canonicalizer { _circuit: &Circuit, circuit_name: Identifier, members: Vec, - ) -> Result { + ) -> Result { Ok(Circuit { circuit_name: circuit_name.clone(), members: members diff --git a/ast/src/reducer/errors.rs b/ast/src/reducer/errors.rs new file mode 100644 index 0000000000..0ed9d40942 --- /dev/null +++ b/ast/src/reducer/errors.rs @@ -0,0 +1,41 @@ +// Copyright (C) 2019-2021 Aleo Systems Inc. +// This file is part of the Leo library. + +// The Leo library is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// The Leo library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with the Leo library. If not, see . + +use crate::{FormattedError, Span}; + +#[derive(Debug, Error)] +pub enum CanonicalizeError { + #[error("{}", _0)] + Error(#[from] FormattedError), +} + +impl CanonicalizeError { + fn new_from_span(message: String, span: &Span) -> Self { + CanonicalizeError::Error(FormattedError::new_from_span(message, span)) + } + + pub fn big_self_outside_of_circuit(span: &Span) -> Self { + let message = "cannot call keyword `Self` outside of a circuit function".to_string(); + + Self::new_from_span(message, span) + } + + pub fn invalid_array_dimension_size(span: &Span) -> Self { + let message = "recieved dimension size of 0, expected it to be 1 or larger.".to_string(); + + Self::new_from_span(message, span) + } +} diff --git a/ast/src/reducer/mod.rs b/ast/src/reducer/mod.rs index 144997d8e1..d5d4d52982 100644 --- a/ast/src/reducer/mod.rs +++ b/ast/src/reducer/mod.rs @@ -17,6 +17,9 @@ mod canonicalization; pub use canonicalization::*; +mod errors; +pub use errors::*; + mod reconstructing_reducer; pub use reconstructing_reducer::*; diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 3ba7f7de91..52a40f3281 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -18,7 +18,6 @@ //! asg nodes and saving relevant information. use crate::*; -use anyhow::Result; use indexmap::IndexMap; pub struct ReconstructingDirector { @@ -30,15 +29,15 @@ impl ReconstructingDirector { Self { reducer } } - pub fn reduce_type(&mut self, type_: &Type, in_circuit: bool) -> Result { + pub fn reduce_type(&mut self, type_: &Type, in_circuit: bool, span: &Span) -> Result { let new = match type_ { Type::Array(type_, dimensions) => { - Type::Array(Box::new(self.reduce_type(type_, in_circuit)?), dimensions.clone()) + Type::Array(Box::new(self.reduce_type(type_, in_circuit, span)?), dimensions.clone()) } Type::Tuple(types) => { let mut reduced_types = vec![]; for type_ in types.iter() { - reduced_types.push(self.reduce_type(type_, in_circuit)?); + reduced_types.push(self.reduce_type(type_, in_circuit, span)?); } Type::Tuple(reduced_types) @@ -47,11 +46,15 @@ impl ReconstructingDirector { _ => type_.clone(), }; - self.reducer.reduce_type(type_, new, in_circuit) + self.reducer.reduce_type(type_, new, in_circuit, span) } // Expressions - pub fn reduce_expression(&mut self, expression: &Expression, in_circuit: bool) -> Result { + pub fn reduce_expression( + &mut self, + expression: &Expression, + in_circuit: bool, + ) -> Result { let new = match expression { Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?), Expression::Value(value) => Expression::Value(self.reduce_value(&value)?), @@ -98,15 +101,15 @@ impl ReconstructingDirector { self.reducer.reduce_expression(expression, new, in_circuit) } - pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { self.reducer.reduce_identifier(identifier) } - pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { self.reducer.reduce_group_tuple(group_tuple) } - pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { + pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { let new = match group_value { GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?), _ => group_value.clone(), @@ -115,7 +118,7 @@ impl ReconstructingDirector { self.reducer.reduce_group_value(group_value, new) } - pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { + pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { let new = match value { ValueExpression::Group(group_value) => { ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)) @@ -126,7 +129,11 @@ impl ReconstructingDirector { self.reducer.reduce_value(value, new) } - pub fn reduce_binary(&mut self, binary: &BinaryExpression, in_circuit: bool) -> Result { + pub fn reduce_binary( + &mut self, + binary: &BinaryExpression, + in_circuit: bool, + ) -> Result { let left = self.reduce_expression(&binary.left, in_circuit)?; let right = self.reduce_expression(&binary.right, in_circuit)?; @@ -134,13 +141,21 @@ impl ReconstructingDirector { .reduce_binary(binary, left, right, binary.op.clone(), in_circuit) } - pub fn reduce_unary(&mut self, unary: &UnaryExpression, in_circuit: bool) -> Result { + pub fn reduce_unary( + &mut self, + unary: &UnaryExpression, + in_circuit: bool, + ) -> Result { let inner = self.reduce_expression(&unary.inner, in_circuit)?; self.reducer.reduce_unary(unary, inner, unary.op.clone(), in_circuit) } - pub fn reduce_ternary(&mut self, ternary: &TernaryExpression, in_circuit: bool) -> Result { + pub fn reduce_ternary( + &mut self, + ternary: &TernaryExpression, + in_circuit: bool, + ) -> Result { let condition = self.reduce_expression(&ternary.condition, in_circuit)?; let if_true = self.reduce_expression(&ternary.if_true, in_circuit)?; let if_false = self.reduce_expression(&ternary.if_false, in_circuit)?; @@ -149,9 +164,13 @@ impl ReconstructingDirector { .reduce_ternary(ternary, condition, if_true, if_false, in_circuit) } - pub fn reduce_cast(&mut self, cast: &CastExpression, in_circuit: bool) -> Result { + pub fn reduce_cast( + &mut self, + cast: &CastExpression, + in_circuit: bool, + ) -> Result { let inner = self.reduce_expression(&cast.inner, in_circuit)?; - let target_type = self.reduce_type(&cast.target_type, in_circuit)?; + let target_type = self.reduce_type(&cast.target_type, in_circuit, &cast.span)?; self.reducer.reduce_cast(cast, inner, target_type, in_circuit) } @@ -160,7 +179,7 @@ impl ReconstructingDirector { &mut self, array_inline: &ArrayInlineExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let mut elements = vec![]; for element in array_inline.elements.iter() { let reduced_element = match element { @@ -182,7 +201,7 @@ impl ReconstructingDirector { &mut self, array_init: &ArrayInitExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let element = self.reduce_expression(&array_init.element, in_circuit)?; self.reducer.reduce_array_init(array_init, element, in_circuit) @@ -192,7 +211,7 @@ impl ReconstructingDirector { &mut self, array_access: &ArrayAccessExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let array = self.reduce_expression(&array_access.array, in_circuit)?; let index = self.reduce_expression(&array_access.index, in_circuit)?; @@ -203,7 +222,7 @@ impl ReconstructingDirector { &mut self, array_range_access: &ArrayRangeAccessExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let array = self.reduce_expression(&array_range_access.array, in_circuit)?; let left = match array_range_access.left.as_ref() { Some(left) => Some(self.reduce_expression(left, in_circuit)?), @@ -222,7 +241,7 @@ impl ReconstructingDirector { &mut self, tuple_init: &TupleInitExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let mut elements = vec![]; for element in tuple_init.elements.iter() { elements.push(self.reduce_expression(element, in_circuit)?); @@ -235,7 +254,7 @@ impl ReconstructingDirector { &mut self, tuple_access: &TupleAccessExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let tuple = self.reduce_expression(&tuple_access.tuple, in_circuit)?; self.reducer.reduce_tuple_access(tuple_access, tuple, in_circuit) @@ -245,7 +264,7 @@ impl ReconstructingDirector { &mut self, variable: &CircuitImpliedVariableDefinition, in_circuit: bool, - ) -> Result { + ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; let expression = match variable.expression.as_ref() { Some(expr) => Some(self.reduce_expression(expr, in_circuit)?), @@ -260,7 +279,7 @@ impl ReconstructingDirector { &mut self, circuit_init: &CircuitInitExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let name = self.reduce_identifier(&circuit_init.name)?; let mut members = vec![]; @@ -276,7 +295,7 @@ impl ReconstructingDirector { &mut self, circuit_member_access: &CircuitMemberAccessExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let circuit = self.reduce_expression(&circuit_member_access.circuit, in_circuit)?; let name = self.reduce_identifier(&circuit_member_access.name)?; @@ -288,7 +307,7 @@ impl ReconstructingDirector { &mut self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, in_circuit: bool, - ) -> Result { + ) -> Result { let circuit = self.reduce_expression(&circuit_static_fn_access.circuit, in_circuit)?; let name = self.reduce_identifier(&circuit_static_fn_access.name)?; @@ -296,7 +315,11 @@ impl ReconstructingDirector { .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name, in_circuit) } - pub fn reduce_call(&mut self, call: &CallExpression, in_circuit: bool) -> Result { + pub fn reduce_call( + &mut self, + call: &CallExpression, + in_circuit: bool, + ) -> Result { let function = self.reduce_expression(&call.function, in_circuit)?; let mut arguments = vec![]; @@ -308,7 +331,11 @@ impl ReconstructingDirector { } // Statements - pub fn reduce_statement(&mut self, statement: &Statement, in_circuit: bool) -> Result { + pub fn reduce_statement( + &mut self, + statement: &Statement, + in_circuit: bool, + ) -> Result { let new = match statement { Statement::Return(return_statement) => { Statement::Return(self.reduce_return(&return_statement, in_circuit)?) @@ -331,13 +358,17 @@ impl ReconstructingDirector { self.reducer.reduce_statement(statement, new, in_circuit) } - pub fn reduce_return(&mut self, return_statement: &ReturnStatement, in_circuit: bool) -> Result { + pub fn reduce_return( + &mut self, + return_statement: &ReturnStatement, + in_circuit: bool, + ) -> Result { let expression = self.reduce_expression(&return_statement.expression, in_circuit)?; self.reducer.reduce_return(return_statement, expression, in_circuit) } - pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { let identifier = self.reduce_identifier(&variable_name.identifier)?; self.reducer.reduce_variable_name(variable_name, identifier) @@ -347,14 +378,14 @@ impl ReconstructingDirector { &mut self, definition: &DefinitionStatement, in_circuit: bool, - ) -> Result { + ) -> Result { let mut variable_names = vec![]; for variable_name in definition.variable_names.iter() { variable_names.push(self.reduce_variable_name(variable_name)?); } let type_ = match definition.type_.as_ref() { - Some(inner) => Some(self.reduce_type(inner, in_circuit)?), + Some(inner) => Some(self.reduce_type(inner, in_circuit, &definition.span)?), None => None, }; @@ -364,7 +395,11 @@ impl ReconstructingDirector { .reduce_definition(definition, variable_names, type_, value, in_circuit) } - pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess, in_circuit: bool) -> Result { + pub fn reduce_assignee_access( + &mut self, + access: &AssigneeAccess, + in_circuit: bool, + ) -> Result { let new = match access { AssigneeAccess::ArrayRange(left, right) => { let left = match left.as_ref() { @@ -388,7 +423,7 @@ impl ReconstructingDirector { self.reducer.reduce_assignee_access(access, new, in_circuit) } - pub fn reduce_assignee(&mut self, assignee: &Assignee, in_circuit: bool) -> Result { + pub fn reduce_assignee(&mut self, assignee: &Assignee, in_circuit: bool) -> Result { let identifier = self.reduce_identifier(&assignee.identifier)?; let mut accesses = vec![]; @@ -399,7 +434,11 @@ impl ReconstructingDirector { self.reducer.reduce_assignee(assignee, identifier, accesses, in_circuit) } - pub fn reduce_assign(&mut self, assign: &AssignStatement, in_circuit: bool) -> Result { + pub fn reduce_assign( + &mut self, + assign: &AssignStatement, + in_circuit: bool, + ) -> Result { let assignee = self.reduce_assignee(&assign.assignee, in_circuit)?; let value = self.reduce_expression(&assign.value, in_circuit)?; @@ -410,7 +449,7 @@ impl ReconstructingDirector { &mut self, conditional: &ConditionalStatement, in_circuit: bool, - ) -> Result { + ) -> Result { let condition = self.reduce_expression(&conditional.condition, in_circuit)?; let block = self.reduce_block(&conditional.block, in_circuit)?; let next = match conditional.next.as_ref() { @@ -422,7 +461,11 @@ impl ReconstructingDirector { .reduce_conditional(conditional, condition, block, next, in_circuit) } - pub fn reduce_iteration(&mut self, iteration: &IterationStatement, in_circuit: bool) -> Result { + pub fn reduce_iteration( + &mut self, + iteration: &IterationStatement, + in_circuit: bool, + ) -> Result { let variable = self.reduce_identifier(&iteration.variable)?; let start = self.reduce_expression(&iteration.start, in_circuit)?; let stop = self.reduce_expression(&iteration.stop, in_circuit)?; @@ -436,7 +479,7 @@ impl ReconstructingDirector { &mut self, console_function_call: &ConsoleStatement, in_circuit: bool, - ) -> Result { + ) -> Result { let function = match &console_function_call.function { ConsoleFunction::Assert(expression) => { ConsoleFunction::Assert(self.reduce_expression(expression, in_circuit)?) @@ -469,13 +512,13 @@ impl ReconstructingDirector { &mut self, expression: &ExpressionStatement, in_circuit: bool, - ) -> Result { + ) -> Result { let inner_expression = self.reduce_expression(&expression.expression, in_circuit)?; self.reducer .reduce_expression_statement(expression, inner_expression, in_circuit) } - pub fn reduce_block(&mut self, block: &Block, in_circuit: bool) -> Result { + pub fn reduce_block(&mut self, block: &Block, in_circuit: bool) -> Result { let mut statements = vec![]; for statement in block.statements.iter() { statements.push(self.reduce_statement(statement, in_circuit)?); @@ -485,7 +528,7 @@ impl ReconstructingDirector { } // Program - pub fn reduce_program(&mut self, program: &Program) -> Result { + pub fn reduce_program(&mut self, program: &Program) -> Result { let mut inputs = vec![]; for input in program.expected_input.iter() { inputs.push(self.reduce_function_input(input, false)?); @@ -517,15 +560,19 @@ impl ReconstructingDirector { &mut self, variable: &FunctionInputVariable, in_circuit: bool, - ) -> Result { + ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; - let type_ = self.reduce_type(&variable.type_, in_circuit)?; + let type_ = self.reduce_type(&variable.type_, in_circuit, &variable.span)?; self.reducer .reduce_function_input_variable(variable, identifier, type_, in_circuit) } - pub fn reduce_function_input(&mut self, input: &FunctionInput, in_circuit: bool) -> Result { + pub fn reduce_function_input( + &mut self, + input: &FunctionInput, + in_circuit: bool, + ) -> Result { let new = match input { FunctionInput::Variable(function_input_variable) => { FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable, in_circuit)?) @@ -536,7 +583,10 @@ impl ReconstructingDirector { self.reducer.reduce_function_input(input, new, in_circuit) } - pub fn reduce_package_or_packages(&mut self, package_or_packages: &PackageOrPackages) -> Result { + pub fn reduce_package_or_packages( + &mut self, + package_or_packages: &PackageOrPackages, + ) -> Result { let new = match package_or_packages { PackageOrPackages::Package(package) => PackageOrPackages::Package(Package { name: self.reduce_identifier(&package.name)?, @@ -553,17 +603,21 @@ impl ReconstructingDirector { self.reducer.reduce_package_or_packages(package_or_packages, new) } - pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { + pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?; self.reducer.reduce_import(import, package_or_packages) } - pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result { + pub fn reduce_circuit_member( + &mut self, + circuit_member: &CircuitMember, + ) -> Result { let new = match circuit_member { - CircuitMember::CircuitVariable(identifier, type_) => { - CircuitMember::CircuitVariable(self.reduce_identifier(&identifier)?, self.reduce_type(&type_, true)?) - } + CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable( + self.reduce_identifier(&identifier)?, + self.reduce_type(&type_, true, &identifier.span)?, + ), CircuitMember::CircuitFunction(function) => { CircuitMember::CircuitFunction(self.reduce_function(&function, true)?) } @@ -572,7 +626,7 @@ impl ReconstructingDirector { self.reducer.reduce_circuit_member(circuit_member, new) } - pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { let circuit_name = self.reduce_identifier(&circuit.circuit_name)?; let mut members = vec![]; @@ -583,13 +637,13 @@ impl ReconstructingDirector { self.reducer.reduce_circuit(circuit, circuit_name, members) } - fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { + fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { let name = self.reduce_identifier(&annotation.name)?; self.reducer.reduce_annotation(annotation, name) } - pub fn reduce_function(&mut self, function: &Function, in_circuit: bool) -> Result { + pub fn reduce_function(&mut self, function: &Function, in_circuit: bool) -> Result { let identifier = self.reduce_identifier(&function.identifier)?; let mut annotations = vec![]; @@ -603,7 +657,7 @@ impl ReconstructingDirector { } let output = match function.output.as_ref() { - Some(type_) => Some(self.reduce_type(type_, in_circuit)?), + Some(type_) => Some(self.reduce_type(type_, in_circuit, &function.span)?), None => None, }; diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index be5b39aeac..a06e350481 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -15,13 +15,18 @@ // along with the Leo library. If not, see . use crate::*; -use anyhow::Result; use indexmap::IndexMap; // Needed to fix clippy bug. #[allow(clippy::redundant_closure)] pub trait ReconstructingReducer { - fn reduce_type(&mut self, _type_: &Type, new: Type, _in_circuit: bool) -> Result { + fn reduce_type( + &mut self, + _type_: &Type, + new: Type, + _in_circuit: bool, + _span: &Span, + ) -> Result { Ok(new) } @@ -31,18 +36,18 @@ pub trait ReconstructingReducer { _expression: &Expression, new: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(new) } - fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { Ok(Identifier { name: identifier.name.clone(), span: identifier.span.clone(), }) } - fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { Ok(GroupTuple { x: group_tuple.x.clone(), y: group_tuple.y.clone(), @@ -50,11 +55,19 @@ pub trait ReconstructingReducer { }) } - fn reduce_group_value(&mut self, _group_value: &GroupValue, new: GroupValue) -> Result { + fn reduce_group_value( + &mut self, + _group_value: &GroupValue, + new: GroupValue, + ) -> Result { Ok(new) } - fn reduce_value(&mut self, _value: &ValueExpression, new: ValueExpression) -> Result { + fn reduce_value( + &mut self, + _value: &ValueExpression, + new: ValueExpression, + ) -> Result { Ok(new) } @@ -65,7 +78,7 @@ pub trait ReconstructingReducer { right: Expression, op: BinaryOperation, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(BinaryExpression { left: Box::new(left), right: Box::new(right), @@ -80,7 +93,7 @@ pub trait ReconstructingReducer { inner: Expression, op: UnaryOperation, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(UnaryExpression { inner: Box::new(inner), op, @@ -95,7 +108,7 @@ pub trait ReconstructingReducer { if_true: Expression, if_false: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(TernaryExpression { condition: Box::new(condition), if_true: Box::new(if_true), @@ -110,7 +123,7 @@ pub trait ReconstructingReducer { inner: Expression, target_type: Type, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(CastExpression { inner: Box::new(inner), target_type, @@ -123,7 +136,7 @@ pub trait ReconstructingReducer { array_inline: &ArrayInlineExpression, elements: Vec, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ArrayInlineExpression { elements, span: array_inline.span.clone(), @@ -135,7 +148,7 @@ pub trait ReconstructingReducer { array_init: &ArrayInitExpression, element: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ArrayInitExpression { element: Box::new(element), dimensions: array_init.dimensions.clone(), @@ -149,7 +162,7 @@ pub trait ReconstructingReducer { array: Expression, index: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ArrayAccessExpression { array: Box::new(array), index: Box::new(index), @@ -164,7 +177,7 @@ pub trait ReconstructingReducer { left: Option, right: Option, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ArrayRangeAccessExpression { array: Box::new(array), left: left.map(|expr| Box::new(expr)), @@ -178,7 +191,7 @@ pub trait ReconstructingReducer { tuple_init: &TupleInitExpression, elements: Vec, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(TupleInitExpression { elements, span: tuple_init.span.clone(), @@ -190,7 +203,7 @@ pub trait ReconstructingReducer { tuple_access: &TupleAccessExpression, tuple: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(TupleAccessExpression { tuple: Box::new(tuple), index: tuple_access.index.clone(), @@ -204,7 +217,7 @@ pub trait ReconstructingReducer { identifier: Identifier, expression: Option, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(CircuitImpliedVariableDefinition { identifier, expression }) } @@ -214,7 +227,7 @@ pub trait ReconstructingReducer { name: Identifier, members: Vec, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(CircuitInitExpression { name, members, @@ -228,7 +241,7 @@ pub trait ReconstructingReducer { circuit: Expression, name: Identifier, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(CircuitMemberAccessExpression { circuit: Box::new(circuit), name, @@ -242,7 +255,7 @@ pub trait ReconstructingReducer { circuit: Expression, name: Identifier, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(CircuitStaticFunctionAccessExpression { circuit: Box::new(circuit), name, @@ -256,7 +269,7 @@ pub trait ReconstructingReducer { function: Expression, arguments: Vec, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(CallExpression { function: Box::new(function), arguments, @@ -265,7 +278,12 @@ pub trait ReconstructingReducer { } // Statements - fn reduce_statement(&mut self, _statement: &Statement, new: Statement, _in_circuit: bool) -> Result { + fn reduce_statement( + &mut self, + _statement: &Statement, + new: Statement, + _in_circuit: bool, + ) -> Result { Ok(new) } @@ -274,14 +292,18 @@ pub trait ReconstructingReducer { return_statement: &ReturnStatement, expression: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ReturnStatement { expression, span: return_statement.span.clone(), }) } - fn reduce_variable_name(&mut self, variable_name: &VariableName, identifier: Identifier) -> Result { + fn reduce_variable_name( + &mut self, + variable_name: &VariableName, + identifier: Identifier, + ) -> Result { Ok(VariableName { mutable: variable_name.mutable, identifier, @@ -296,7 +318,7 @@ pub trait ReconstructingReducer { type_: Option, value: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(DefinitionStatement { declaration_type: definition.declaration_type.clone(), variable_names, @@ -311,7 +333,7 @@ pub trait ReconstructingReducer { _access: &AssigneeAccess, new: AssigneeAccess, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(new) } @@ -321,7 +343,7 @@ pub trait ReconstructingReducer { identifier: Identifier, accesses: Vec, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(Assignee { identifier, accesses, @@ -335,7 +357,7 @@ pub trait ReconstructingReducer { assignee: Assignee, value: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(AssignStatement { operation: assign.operation.clone(), assignee, @@ -351,7 +373,7 @@ pub trait ReconstructingReducer { block: Block, statement: Option, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ConditionalStatement { condition, block, @@ -368,7 +390,7 @@ pub trait ReconstructingReducer { stop: Expression, block: Block, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(IterationStatement { variable, start, @@ -383,7 +405,7 @@ pub trait ReconstructingReducer { console: &ConsoleStatement, function: ConsoleFunction, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ConsoleStatement { function, span: console.span.clone(), @@ -395,14 +417,19 @@ pub trait ReconstructingReducer { expression_statement: &ExpressionStatement, expression: Expression, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(ExpressionStatement { expression, span: expression_statement.span.clone(), }) } - fn reduce_block(&mut self, block: &Block, statements: Vec, _in_circuit: bool) -> Result { + fn reduce_block( + &mut self, + block: &Block, + statements: Vec, + _in_circuit: bool, + ) -> Result { Ok(Block { statements, span: block.span.clone(), @@ -417,7 +444,7 @@ pub trait ReconstructingReducer { imports: Vec, circuits: IndexMap, functions: IndexMap, - ) -> Result { + ) -> Result { Ok(Program { name: program.name.clone(), expected_input, @@ -433,7 +460,7 @@ pub trait ReconstructingReducer { identifier: Identifier, type_: Type, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(FunctionInputVariable { identifier, const_: variable.const_, @@ -448,7 +475,7 @@ pub trait ReconstructingReducer { _input: &FunctionInput, new: FunctionInput, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(new) } @@ -456,7 +483,7 @@ pub trait ReconstructingReducer { &mut self, _package_or_packages: &PackageOrPackages, new: PackageOrPackages, - ) -> Result { + ) -> Result { Ok(new) } @@ -464,14 +491,18 @@ pub trait ReconstructingReducer { &mut self, import: &ImportStatement, package_or_packages: PackageOrPackages, - ) -> Result { + ) -> Result { Ok(ImportStatement { package_or_packages, span: import.span.clone(), }) } - fn reduce_circuit_member(&mut self, _circuit_member: &CircuitMember, new: CircuitMember) -> Result { + fn reduce_circuit_member( + &mut self, + _circuit_member: &CircuitMember, + new: CircuitMember, + ) -> Result { Ok(new) } @@ -480,11 +511,15 @@ pub trait ReconstructingReducer { _circuit: &Circuit, circuit_name: Identifier, members: Vec, - ) -> Result { + ) -> Result { Ok(Circuit { circuit_name, members }) } - fn reduce_annotation(&mut self, annotation: &Annotation, name: Identifier) -> Result { + fn reduce_annotation( + &mut self, + annotation: &Annotation, + name: Identifier, + ) -> Result { Ok(Annotation { span: annotation.span.clone(), name, @@ -502,7 +537,7 @@ pub trait ReconstructingReducer { output: Option, block: Block, _in_circuit: bool, - ) -> Result { + ) -> Result { Ok(Function { identifier, annotations, diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index c5f2a3b880..afb89c8515 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -232,7 +232,8 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { Rc::new(lines), ); - let ast = parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?; + let mut ast = parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?; + ast.canonicalize()?; // Store the main program file. self.program = ast.into_repr(); diff --git a/compiler/src/errors/compiler.rs b/compiler/src/errors/compiler.rs index 23a99a96f2..d721ec2df6 100644 --- a/compiler/src/errors/compiler.rs +++ b/compiler/src/errors/compiler.rs @@ -16,7 +16,7 @@ use crate::errors::{FunctionError, ImportError, OutputBytesError, OutputFileError}; use leo_asg::AsgConvertError; -use leo_ast::LeoError; +use leo_ast::{CanonicalizeError, LeoError}; use leo_imports::ImportParserError; use leo_input::InputParserError; use leo_parser::SyntaxError; @@ -71,6 +71,9 @@ pub enum CompilerError { #[error("{}", _0)] AsgConvertError(#[from] AsgConvertError), + + #[error("{}", _0)] + CanonicalizeError(#[from] CanonicalizeError), } impl LeoError for CompilerError { From b83d6e9b05d9458f6549fb03804a624efffc4da6 Mon Sep 17 00:00:00 2001 From: gluax Date: Tue, 16 Mar 2021 13:15:10 -0400 Subject: [PATCH 14/40] error fixes, Self replacements extended --- ast/src/reducer/canonicalization.rs | 324 +++++++++++++++++---- ast/src/reducer/reconstructing_director.rs | 99 +++---- ast/src/reducer/reconstructing_reducer.rs | 92 +++--- 3 files changed, 359 insertions(+), 156 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 860eb6eef3..e80701089e 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -18,6 +18,9 @@ use crate::*; pub struct Canonicalizer; +// TODO fix function input array. +// TODO fix test 0 size array. + impl Canonicalizer { fn is_self_type(&self, type_option: Option<&Type>) -> bool { matches!(type_option, Some(Type::SelfType)) @@ -25,6 +28,137 @@ impl Canonicalizer { fn canonicalize_expression(&self, expression: &Expression, circuit_name: &Identifier) -> Expression { match expression { + Expression::Unary(unary) => { + let inner = Box::new(self.canonicalize_expression(&unary.inner, circuit_name)); + + return Expression::Unary(UnaryExpression { + inner, + op: unary.op.clone(), + span: unary.span.clone(), + }); + } + Expression::Binary(binary) => { + let left = Box::new(self.canonicalize_expression(&binary.left, circuit_name)); + let right = Box::new(self.canonicalize_expression(&binary.right, circuit_name)); + + return Expression::Binary(BinaryExpression { + left, + right, + op: binary.op.clone(), + span: binary.span.clone(), + }); + } + Expression::Ternary(ternary) => { + let condition = Box::new(self.canonicalize_expression(&ternary.condition, circuit_name)); + let if_true = Box::new(self.canonicalize_expression(&ternary.if_true, circuit_name)); + let if_false = Box::new(self.canonicalize_expression(&ternary.if_false, circuit_name)); + + return Expression::Ternary(TernaryExpression { + condition, + if_true, + if_false, + span: ternary.span.clone(), + }); + } + + Expression::Cast(cast) => { + let inner = Box::new(self.canonicalize_expression(&cast.inner, circuit_name)); + let mut target_type = cast.target_type.clone(); + + if matches!(target_type, Type::SelfType) { + target_type = Type::Circuit(circuit_name.clone()); + } + + return Expression::Cast(CastExpression { + inner, + target_type, + span: cast.span.clone(), + }); + } + + Expression::ArrayInline(array_inline) => { + let elements = array_inline + .elements + .iter() + .map(|element| match element { + SpreadOrExpression::Expression(expression) => { + SpreadOrExpression::Expression(self.canonicalize_expression(expression, circuit_name)) + } + SpreadOrExpression::Spread(expression) => { + SpreadOrExpression::Spread(self.canonicalize_expression(expression, circuit_name)) + } + }) + .collect(); + + return Expression::ArrayInline(ArrayInlineExpression { + elements, + span: array_inline.span.clone(), + }); + } + + Expression::ArrayInit(array_init) => { + let element = Box::new(self.canonicalize_expression(&array_init.element, circuit_name)); + + return Expression::ArrayInit(ArrayInitExpression { + dimensions: array_init.dimensions.clone(), + element, + span: array_init.span.clone(), + }); + } + + Expression::ArrayAccess(array_access) => { + let array = Box::new(self.canonicalize_expression(&array_access.array, circuit_name)); + let index = Box::new(self.canonicalize_expression(&array_access.index, circuit_name)); + + return Expression::ArrayAccess(ArrayAccessExpression { + array, + index, + span: array_access.span.clone(), + }); + } + + Expression::ArrayRangeAccess(array_range_access) => { + let array = Box::new(self.canonicalize_expression(&array_range_access.array, circuit_name)); + let left = array_range_access + .left + .as_ref() + .map(|left| Box::new(self.canonicalize_expression(left, circuit_name))); + let right = array_range_access + .right + .as_ref() + .map(|right| Box::new(self.canonicalize_expression(right, circuit_name))); + + return Expression::ArrayRangeAccess(ArrayRangeAccessExpression { + array, + left, + right, + span: array_range_access.span.clone(), + }); + } + + Expression::TupleInit(tuple_init) => { + let elements = tuple_init + .elements + .iter() + .map(|element| self.canonicalize_expression(element, circuit_name)) + .collect(); + + return Expression::TupleInit(TupleInitExpression { + elements, + span: tuple_init.span.clone(), + }); + } + + Expression::TupleAccess(tuple_access) => { + let tuple = Box::new(self.canonicalize_expression(&tuple_access.tuple, circuit_name)); + + return Expression::TupleAccess(TupleAccessExpression { + tuple, + index: tuple_access.index.clone(), + span: tuple_access.span.clone(), + }); + } + Expression::CircuitInit(circuit_init) => { return Expression::CircuitInit(CircuitInitExpression { name: circuit_name.clone(), @@ -59,51 +193,156 @@ impl Canonicalizer { expression.clone() } - fn canonicalize_statement(&self, statement: &Statement, circuit_name: &Identifier) -> Statement { - // What Statements could have Self appear + fn canonicalize_assignee_access(&self, access: &AssigneeAccess, circuit_name: &Identifier) -> AssigneeAccess { + match access { + AssigneeAccess::ArrayRange(left, right) => { + let left = match left.as_ref() { + Some(left) => Some(self.canonicalize_expression(left, circuit_name)), + None => None, + }; + let right = match right.as_ref() { + Some(right) => Some(self.canonicalize_expression(right, circuit_name)), + None => None, + }; + AssigneeAccess::ArrayRange(left, right) + } + AssigneeAccess::ArrayIndex(index) => { + AssigneeAccess::ArrayIndex(self.canonicalize_expression(&index, circuit_name)) + } + _ => access.clone(), + } + } + + fn canonicalize_assignee(&self, assignee: &Assignee, circuit_name: &Identifier) -> Assignee { + let accesses = assignee + .accesses + .iter() + .map(|access| self.canonicalize_assignee_access(access, circuit_name)) + .collect(); + + Assignee { + identifier: assignee.identifier.clone(), + accesses, + span: assignee.span.clone(), + } + } + + fn canonicalize_block(&self, block: &Block, circuit_name: &Identifier) -> Block { + let statements = block + .statements + .iter() + .map(|block_statement| self.canonicalize_statement(&block_statement, circuit_name)) + .collect(); + + Block { + statements, + span: block.span.clone(), + } + } + + fn canonicalize_statement(&self, statement: &Statement, circuit_name: &Identifier) -> Statement { match statement { Statement::Return(return_statement) => { - return Statement::Return(ReturnStatement { - expression: self.canonicalize_expression(&return_statement.expression, circuit_name), + let expression = self.canonicalize_expression(&return_statement.expression, circuit_name); + Statement::Return(ReturnStatement { + expression, span: return_statement.span.clone(), - }); + }) } Statement::Definition(definition) => { + let value = self.canonicalize_expression(&definition.value, circuit_name); let mut type_ = definition.type_.clone(); if self.is_self_type(type_.as_ref()) { type_ = Some(Type::Circuit(circuit_name.clone())); } - return Statement::Definition(DefinitionStatement { + Statement::Definition(DefinitionStatement { declaration_type: definition.declaration_type.clone(), variable_names: definition.variable_names.clone(), type_, - value: self.canonicalize_expression(&definition.value, circuit_name), + value, span: definition.span.clone(), - }); + }) } - Statement::Expression(expression) => { - return Statement::Expression(ExpressionStatement { - expression: self.canonicalize_expression(&expression.expression, circuit_name), - span: expression.span.clone(), - }); - } - Statement::Block(block) => { - return Statement::Block(Block { - statements: block - .statements - .iter() - .map(|block_statement| self.canonicalize_statement(&block_statement, circuit_name)) - .collect(), - span: block.span.clone(), - }); - } - _ => {} - } + Statement::Assign(assign) => { + let assignee = self.canonicalize_assignee(&assign.assignee, circuit_name); + let value = self.canonicalize_expression(&assign.value, circuit_name); - statement.clone() + Statement::Assign(AssignStatement { + assignee, + value, + operation: assign.operation.clone(), + span: assign.span.clone(), + }) + } + Statement::Conditional(conditional) => { + let condition = self.canonicalize_expression(&conditional.condition, circuit_name); + let block = self.canonicalize_block(&conditional.block, circuit_name); + let next = match conditional.next.as_ref() { + Some(condition) => Some(Box::new(self.canonicalize_statement(condition, circuit_name))), + None => None, + }; + + Statement::Conditional(ConditionalStatement { + condition, + block, + next, + span: conditional.span.clone(), + }) + } + Statement::Iteration(iteration) => { + let start = self.canonicalize_expression(&iteration.start, circuit_name); + let stop = self.canonicalize_expression(&iteration.stop, circuit_name); + let block = self.canonicalize_block(&iteration.block, circuit_name); + + Statement::Iteration(IterationStatement { + variable: iteration.variable.clone(), + start, + stop, + block, + span: iteration.span.clone(), + }) + } + Statement::Console(console_function_call) => { + let function = match &console_function_call.function { + ConsoleFunction::Assert(expression) => { + ConsoleFunction::Assert(self.canonicalize_expression(expression, circuit_name)) + } + ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { + let parameters = format + .parameters + .iter() + .map(|parameter| self.canonicalize_expression(parameter, circuit_name)) + .collect(); + + let formatted = FormattedString { + parts: format.parts.clone(), + parameters, + span: format.span.clone(), + }; + + match &console_function_call.function { + ConsoleFunction::Debug(_) => ConsoleFunction::Debug(formatted), + ConsoleFunction::Error(_) => ConsoleFunction::Error(formatted), + ConsoleFunction::Log(_) => ConsoleFunction::Log(formatted), + _ => unimplemented!(), // impossible + } + } + }; + + Statement::Console(ConsoleStatement { + function, + span: console_function_call.span.clone(), + }) + } + Statement::Expression(expression) => Statement::Expression(ExpressionStatement { + expression: self.canonicalize_expression(&expression.expression, circuit_name), + span: expression.span.clone(), + }), + Statement::Block(block) => Statement::Block(self.canonicalize_block(block, circuit_name)), + } } fn canonicalize_circuit_member(&self, circuit_member: &CircuitMember, circuit_name: &Identifier) -> CircuitMember { @@ -112,15 +351,7 @@ impl Canonicalizer { CircuitMember::CircuitFunction(function) => { let input = function.input.clone(); let mut output = function.output.clone(); - let block = Block { - statements: function - .block - .statements - .iter() - .map(|statement| self.canonicalize_statement(statement, circuit_name)) - .collect(), - span: function.block.span.clone(), - }; + let block = self.canonicalize_block(&function.block, circuit_name); if self.is_self_type(output.as_ref()) { output = Some(Type::Circuit(circuit_name.clone())); @@ -142,16 +373,10 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_type( - &mut self, - _type_: &Type, - new: Type, - in_circuit: bool, - span: &Span, - ) -> Result { + fn reduce_type(&self, _type_: &Type, new: Type, in_circuit: bool, span: &Span) -> Result { match new { Type::Array(_, mut dimensions) => { - if dimensions.0.is_empty() { + if dimensions.is_zero() { return Err(CanonicalizeError::invalid_array_dimension_size(span)); } @@ -160,6 +385,7 @@ impl ReconstructingReducer for Canonicalizer { ArrayDimensions(vec![dimensions.remove_last().unwrap()]), ); let mut array = next.clone(); + loop { if dimensions.is_empty() { break; @@ -177,12 +403,12 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_array_init( - &mut self, + &self, array_init: &ArrayInitExpression, element: Expression, _in_circuit: bool, ) -> Result { - if array_init.dimensions.0.is_empty() { + if array_init.dimensions.is_zero() { return Err(CanonicalizeError::invalid_array_dimension_size(&array_init.span)); } @@ -226,7 +452,7 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_assign( - &mut self, + &self, assign: &AssignStatement, assignee: Assignee, value: Expression, @@ -273,7 +499,7 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_function( - &mut self, + &self, function: &Function, identifier: Identifier, annotations: Vec, @@ -298,7 +524,7 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_circuit( - &mut self, + &self, _circuit: &Circuit, circuit_name: Identifier, members: Vec, diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 52a40f3281..ab71c7b030 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -29,7 +29,7 @@ impl ReconstructingDirector { Self { reducer } } - pub fn reduce_type(&mut self, type_: &Type, in_circuit: bool, span: &Span) -> Result { + pub fn reduce_type(&self, type_: &Type, in_circuit: bool, span: &Span) -> Result { let new = match type_ { Type::Array(type_, dimensions) => { Type::Array(Box::new(self.reduce_type(type_, in_circuit, span)?), dimensions.clone()) @@ -51,7 +51,7 @@ impl ReconstructingDirector { // Expressions pub fn reduce_expression( - &mut self, + &self, expression: &Expression, in_circuit: bool, ) -> Result { @@ -101,15 +101,15 @@ impl ReconstructingDirector { self.reducer.reduce_expression(expression, new, in_circuit) } - pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + pub fn reduce_identifier(&self, identifier: &Identifier) -> Result { self.reducer.reduce_identifier(identifier) } - pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + pub fn reduce_group_tuple(&self, group_tuple: &GroupTuple) -> Result { self.reducer.reduce_group_tuple(group_tuple) } - pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { + pub fn reduce_group_value(&self, group_value: &GroupValue) -> Result { let new = match group_value { GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?), _ => group_value.clone(), @@ -118,7 +118,7 @@ impl ReconstructingDirector { self.reducer.reduce_group_value(group_value, new) } - pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { + pub fn reduce_value(&self, value: &ValueExpression) -> Result { let new = match value { ValueExpression::Group(group_value) => { ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)) @@ -130,7 +130,7 @@ impl ReconstructingDirector { } pub fn reduce_binary( - &mut self, + &self, binary: &BinaryExpression, in_circuit: bool, ) -> Result { @@ -142,7 +142,7 @@ impl ReconstructingDirector { } pub fn reduce_unary( - &mut self, + &self, unary: &UnaryExpression, in_circuit: bool, ) -> Result { @@ -152,7 +152,7 @@ impl ReconstructingDirector { } pub fn reduce_ternary( - &mut self, + &self, ternary: &TernaryExpression, in_circuit: bool, ) -> Result { @@ -164,11 +164,7 @@ impl ReconstructingDirector { .reduce_ternary(ternary, condition, if_true, if_false, in_circuit) } - pub fn reduce_cast( - &mut self, - cast: &CastExpression, - in_circuit: bool, - ) -> Result { + pub fn reduce_cast(&self, cast: &CastExpression, in_circuit: bool) -> Result { let inner = self.reduce_expression(&cast.inner, in_circuit)?; let target_type = self.reduce_type(&cast.target_type, in_circuit, &cast.span)?; @@ -176,7 +172,7 @@ impl ReconstructingDirector { } pub fn reduce_array_inline( - &mut self, + &self, array_inline: &ArrayInlineExpression, in_circuit: bool, ) -> Result { @@ -198,7 +194,7 @@ impl ReconstructingDirector { } pub fn reduce_array_init( - &mut self, + &self, array_init: &ArrayInitExpression, in_circuit: bool, ) -> Result { @@ -208,7 +204,7 @@ impl ReconstructingDirector { } pub fn reduce_array_access( - &mut self, + &self, array_access: &ArrayAccessExpression, in_circuit: bool, ) -> Result { @@ -219,7 +215,7 @@ impl ReconstructingDirector { } pub fn reduce_array_range_access( - &mut self, + &self, array_range_access: &ArrayRangeAccessExpression, in_circuit: bool, ) -> Result { @@ -238,7 +234,7 @@ impl ReconstructingDirector { } pub fn reduce_tuple_init( - &mut self, + &self, tuple_init: &TupleInitExpression, in_circuit: bool, ) -> Result { @@ -251,7 +247,7 @@ impl ReconstructingDirector { } pub fn reduce_tuple_access( - &mut self, + &self, tuple_access: &TupleAccessExpression, in_circuit: bool, ) -> Result { @@ -261,7 +257,7 @@ impl ReconstructingDirector { } pub fn reduce_circuit_implied_variable_definition( - &mut self, + &self, variable: &CircuitImpliedVariableDefinition, in_circuit: bool, ) -> Result { @@ -276,7 +272,7 @@ impl ReconstructingDirector { } pub fn reduce_circuit_init( - &mut self, + &self, circuit_init: &CircuitInitExpression, in_circuit: bool, ) -> Result { @@ -292,7 +288,7 @@ impl ReconstructingDirector { } pub fn reduce_circuit_member_access( - &mut self, + &self, circuit_member_access: &CircuitMemberAccessExpression, in_circuit: bool, ) -> Result { @@ -304,7 +300,7 @@ impl ReconstructingDirector { } pub fn reduce_circuit_static_fn_access( - &mut self, + &self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, in_circuit: bool, ) -> Result { @@ -315,11 +311,7 @@ impl ReconstructingDirector { .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name, in_circuit) } - pub fn reduce_call( - &mut self, - call: &CallExpression, - in_circuit: bool, - ) -> Result { + pub fn reduce_call(&self, call: &CallExpression, in_circuit: bool) -> Result { let function = self.reduce_expression(&call.function, in_circuit)?; let mut arguments = vec![]; @@ -331,11 +323,7 @@ impl ReconstructingDirector { } // Statements - pub fn reduce_statement( - &mut self, - statement: &Statement, - in_circuit: bool, - ) -> Result { + pub fn reduce_statement(&self, statement: &Statement, in_circuit: bool) -> Result { let new = match statement { Statement::Return(return_statement) => { Statement::Return(self.reduce_return(&return_statement, in_circuit)?) @@ -359,7 +347,7 @@ impl ReconstructingDirector { } pub fn reduce_return( - &mut self, + &self, return_statement: &ReturnStatement, in_circuit: bool, ) -> Result { @@ -368,14 +356,14 @@ impl ReconstructingDirector { self.reducer.reduce_return(return_statement, expression, in_circuit) } - pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { + pub fn reduce_variable_name(&self, variable_name: &VariableName) -> Result { let identifier = self.reduce_identifier(&variable_name.identifier)?; self.reducer.reduce_variable_name(variable_name, identifier) } pub fn reduce_definition( - &mut self, + &self, definition: &DefinitionStatement, in_circuit: bool, ) -> Result { @@ -396,7 +384,7 @@ impl ReconstructingDirector { } pub fn reduce_assignee_access( - &mut self, + &self, access: &AssigneeAccess, in_circuit: bool, ) -> Result { @@ -423,7 +411,7 @@ impl ReconstructingDirector { self.reducer.reduce_assignee_access(access, new, in_circuit) } - pub fn reduce_assignee(&mut self, assignee: &Assignee, in_circuit: bool) -> Result { + pub fn reduce_assignee(&self, assignee: &Assignee, in_circuit: bool) -> Result { let identifier = self.reduce_identifier(&assignee.identifier)?; let mut accesses = vec![]; @@ -435,7 +423,7 @@ impl ReconstructingDirector { } pub fn reduce_assign( - &mut self, + &self, assign: &AssignStatement, in_circuit: bool, ) -> Result { @@ -446,7 +434,7 @@ impl ReconstructingDirector { } pub fn reduce_conditional( - &mut self, + &self, conditional: &ConditionalStatement, in_circuit: bool, ) -> Result { @@ -462,7 +450,7 @@ impl ReconstructingDirector { } pub fn reduce_iteration( - &mut self, + &self, iteration: &IterationStatement, in_circuit: bool, ) -> Result { @@ -476,7 +464,7 @@ impl ReconstructingDirector { } pub fn reduce_console( - &mut self, + &self, console_function_call: &ConsoleStatement, in_circuit: bool, ) -> Result { @@ -509,7 +497,7 @@ impl ReconstructingDirector { } pub fn reduce_expression_statement( - &mut self, + &self, expression: &ExpressionStatement, in_circuit: bool, ) -> Result { @@ -518,7 +506,7 @@ impl ReconstructingDirector { .reduce_expression_statement(expression, inner_expression, in_circuit) } - pub fn reduce_block(&mut self, block: &Block, in_circuit: bool) -> Result { + pub fn reduce_block(&self, block: &Block, in_circuit: bool) -> Result { let mut statements = vec![]; for statement in block.statements.iter() { statements.push(self.reduce_statement(statement, in_circuit)?); @@ -528,7 +516,7 @@ impl ReconstructingDirector { } // Program - pub fn reduce_program(&mut self, program: &Program) -> Result { + pub fn reduce_program(&self, program: &Program) -> Result { let mut inputs = vec![]; for input in program.expected_input.iter() { inputs.push(self.reduce_function_input(input, false)?); @@ -557,7 +545,7 @@ impl ReconstructingDirector { } pub fn reduce_function_input_variable( - &mut self, + &self, variable: &FunctionInputVariable, in_circuit: bool, ) -> Result { @@ -569,7 +557,7 @@ impl ReconstructingDirector { } pub fn reduce_function_input( - &mut self, + &self, input: &FunctionInput, in_circuit: bool, ) -> Result { @@ -584,7 +572,7 @@ impl ReconstructingDirector { } pub fn reduce_package_or_packages( - &mut self, + &self, package_or_packages: &PackageOrPackages, ) -> Result { let new = match package_or_packages { @@ -603,16 +591,13 @@ impl ReconstructingDirector { self.reducer.reduce_package_or_packages(package_or_packages, new) } - pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { + pub fn reduce_import(&self, import: &ImportStatement) -> Result { let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?; self.reducer.reduce_import(import, package_or_packages) } - pub fn reduce_circuit_member( - &mut self, - circuit_member: &CircuitMember, - ) -> Result { + pub fn reduce_circuit_member(&self, circuit_member: &CircuitMember) -> Result { let new = match circuit_member { CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable( self.reduce_identifier(&identifier)?, @@ -626,7 +611,7 @@ impl ReconstructingDirector { self.reducer.reduce_circuit_member(circuit_member, new) } - pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { + pub fn reduce_circuit(&self, circuit: &Circuit) -> Result { let circuit_name = self.reduce_identifier(&circuit.circuit_name)?; let mut members = vec![]; @@ -637,13 +622,13 @@ impl ReconstructingDirector { self.reducer.reduce_circuit(circuit, circuit_name, members) } - fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { + fn reduce_annotation(&self, annotation: &Annotation) -> Result { let name = self.reduce_identifier(&annotation.name)?; self.reducer.reduce_annotation(annotation, name) } - pub fn reduce_function(&mut self, function: &Function, in_circuit: bool) -> Result { + pub fn reduce_function(&self, function: &Function, in_circuit: bool) -> Result { let identifier = self.reduce_identifier(&function.identifier)?; let mut annotations = vec![]; diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index a06e350481..784d2c917c 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -21,7 +21,7 @@ use indexmap::IndexMap; #[allow(clippy::redundant_closure)] pub trait ReconstructingReducer { fn reduce_type( - &mut self, + &self, _type_: &Type, new: Type, _in_circuit: bool, @@ -32,7 +32,7 @@ pub trait ReconstructingReducer { // Expressions fn reduce_expression( - &mut self, + &self, _expression: &Expression, new: Expression, _in_circuit: bool, @@ -40,14 +40,14 @@ pub trait ReconstructingReducer { Ok(new) } - fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { + fn reduce_identifier(&self, identifier: &Identifier) -> Result { Ok(Identifier { name: identifier.name.clone(), span: identifier.span.clone(), }) } - fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { + fn reduce_group_tuple(&self, group_tuple: &GroupTuple) -> Result { Ok(GroupTuple { x: group_tuple.x.clone(), y: group_tuple.y.clone(), @@ -55,16 +55,12 @@ pub trait ReconstructingReducer { }) } - fn reduce_group_value( - &mut self, - _group_value: &GroupValue, - new: GroupValue, - ) -> Result { + fn reduce_group_value(&self, _group_value: &GroupValue, new: GroupValue) -> Result { Ok(new) } fn reduce_value( - &mut self, + &self, _value: &ValueExpression, new: ValueExpression, ) -> Result { @@ -72,7 +68,7 @@ pub trait ReconstructingReducer { } fn reduce_binary( - &mut self, + &self, binary: &BinaryExpression, left: Expression, right: Expression, @@ -88,7 +84,7 @@ pub trait ReconstructingReducer { } fn reduce_unary( - &mut self, + &self, unary: &UnaryExpression, inner: Expression, op: UnaryOperation, @@ -102,7 +98,7 @@ pub trait ReconstructingReducer { } fn reduce_ternary( - &mut self, + &self, ternary: &TernaryExpression, condition: Expression, if_true: Expression, @@ -118,7 +114,7 @@ pub trait ReconstructingReducer { } fn reduce_cast( - &mut self, + &self, cast: &CastExpression, inner: Expression, target_type: Type, @@ -132,7 +128,7 @@ pub trait ReconstructingReducer { } fn reduce_array_inline( - &mut self, + &self, array_inline: &ArrayInlineExpression, elements: Vec, _in_circuit: bool, @@ -144,7 +140,7 @@ pub trait ReconstructingReducer { } fn reduce_array_init( - &mut self, + &self, array_init: &ArrayInitExpression, element: Expression, _in_circuit: bool, @@ -157,7 +153,7 @@ pub trait ReconstructingReducer { } fn reduce_array_access( - &mut self, + &self, array_access: &ArrayAccessExpression, array: Expression, index: Expression, @@ -171,7 +167,7 @@ pub trait ReconstructingReducer { } fn reduce_array_range_access( - &mut self, + &self, array_rage_access: &ArrayRangeAccessExpression, array: Expression, left: Option, @@ -187,7 +183,7 @@ pub trait ReconstructingReducer { } fn reduce_tuple_init( - &mut self, + &self, tuple_init: &TupleInitExpression, elements: Vec, _in_circuit: bool, @@ -199,7 +195,7 @@ pub trait ReconstructingReducer { } fn reduce_tuple_access( - &mut self, + &self, tuple_access: &TupleAccessExpression, tuple: Expression, _in_circuit: bool, @@ -212,7 +208,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_implied_variable_definition( - &mut self, + &self, _variable: &CircuitImpliedVariableDefinition, identifier: Identifier, expression: Option, @@ -222,7 +218,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_init( - &mut self, + &self, circuit_init: &CircuitInitExpression, name: Identifier, members: Vec, @@ -236,7 +232,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_member_access( - &mut self, + &self, circuit_member_access: &CircuitMemberAccessExpression, circuit: Expression, name: Identifier, @@ -250,7 +246,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_static_fn_access( - &mut self, + &self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, circuit: Expression, name: Identifier, @@ -264,7 +260,7 @@ pub trait ReconstructingReducer { } fn reduce_call( - &mut self, + &self, call: &CallExpression, function: Expression, arguments: Vec, @@ -279,7 +275,7 @@ pub trait ReconstructingReducer { // Statements fn reduce_statement( - &mut self, + &self, _statement: &Statement, new: Statement, _in_circuit: bool, @@ -288,7 +284,7 @@ pub trait ReconstructingReducer { } fn reduce_return( - &mut self, + &self, return_statement: &ReturnStatement, expression: Expression, _in_circuit: bool, @@ -300,7 +296,7 @@ pub trait ReconstructingReducer { } fn reduce_variable_name( - &mut self, + &self, variable_name: &VariableName, identifier: Identifier, ) -> Result { @@ -312,7 +308,7 @@ pub trait ReconstructingReducer { } fn reduce_definition( - &mut self, + &self, definition: &DefinitionStatement, variable_names: Vec, type_: Option, @@ -329,7 +325,7 @@ pub trait ReconstructingReducer { } fn reduce_assignee_access( - &mut self, + &self, _access: &AssigneeAccess, new: AssigneeAccess, _in_circuit: bool, @@ -338,7 +334,7 @@ pub trait ReconstructingReducer { } fn reduce_assignee( - &mut self, + &self, assignee: &Assignee, identifier: Identifier, accesses: Vec, @@ -352,7 +348,7 @@ pub trait ReconstructingReducer { } fn reduce_assign( - &mut self, + &self, assign: &AssignStatement, assignee: Assignee, value: Expression, @@ -367,7 +363,7 @@ pub trait ReconstructingReducer { } fn reduce_conditional( - &mut self, + &self, conditional: &ConditionalStatement, condition: Expression, block: Block, @@ -383,7 +379,7 @@ pub trait ReconstructingReducer { } fn reduce_iteration( - &mut self, + &self, iteration: &IterationStatement, variable: Identifier, start: Expression, @@ -401,7 +397,7 @@ pub trait ReconstructingReducer { } fn reduce_console( - &mut self, + &self, console: &ConsoleStatement, function: ConsoleFunction, _in_circuit: bool, @@ -413,7 +409,7 @@ pub trait ReconstructingReducer { } fn reduce_expression_statement( - &mut self, + &self, expression_statement: &ExpressionStatement, expression: Expression, _in_circuit: bool, @@ -425,7 +421,7 @@ pub trait ReconstructingReducer { } fn reduce_block( - &mut self, + &self, block: &Block, statements: Vec, _in_circuit: bool, @@ -438,7 +434,7 @@ pub trait ReconstructingReducer { // Program fn reduce_program( - &mut self, + &self, program: &Program, expected_input: Vec, imports: Vec, @@ -455,7 +451,7 @@ pub trait ReconstructingReducer { } fn reduce_function_input_variable( - &mut self, + &self, variable: &FunctionInputVariable, identifier: Identifier, type_: Type, @@ -471,7 +467,7 @@ pub trait ReconstructingReducer { } fn reduce_function_input( - &mut self, + &self, _input: &FunctionInput, new: FunctionInput, _in_circuit: bool, @@ -480,7 +476,7 @@ pub trait ReconstructingReducer { } fn reduce_package_or_packages( - &mut self, + &self, _package_or_packages: &PackageOrPackages, new: PackageOrPackages, ) -> Result { @@ -488,7 +484,7 @@ pub trait ReconstructingReducer { } fn reduce_import( - &mut self, + &self, import: &ImportStatement, package_or_packages: PackageOrPackages, ) -> Result { @@ -499,7 +495,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_member( - &mut self, + &self, _circuit_member: &CircuitMember, new: CircuitMember, ) -> Result { @@ -507,7 +503,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit( - &mut self, + &self, _circuit: &Circuit, circuit_name: Identifier, members: Vec, @@ -515,11 +511,7 @@ pub trait ReconstructingReducer { Ok(Circuit { circuit_name, members }) } - fn reduce_annotation( - &mut self, - annotation: &Annotation, - name: Identifier, - ) -> Result { + fn reduce_annotation(&self, annotation: &Annotation, name: Identifier) -> Result { Ok(Annotation { span: annotation.span.clone(), name, @@ -529,7 +521,7 @@ pub trait ReconstructingReducer { #[allow(clippy::too_many_arguments)] fn reduce_function( - &mut self, + &self, function: &Function, identifier: Identifier, annotations: Vec, From dceb8a9744c3264c7f2a88d5c5424a6db69fd67b Mon Sep 17 00:00:00 2001 From: gluax Date: Wed, 17 Mar 2021 14:33:04 -0400 Subject: [PATCH 15/40] fix Self inside of circuit giving an error, tests --- ast/src/reducer/canonicalization.rs | 5 +- ast/src/reducer/reconstructing_director.rs | 4 +- .../canonicalization/array_expansion.json | 338 ++++++++++++++++++ .../canonicalization/array_expansion.leo | 7 + .../canonicalization/array_size_zero_fail.leo | 3 + .../big_self_in_circuit_replacement.json | 206 +++++++++++ .../big_self_in_circuit_replacement.leo | 15 + .../big_self_outside_circuit_fail.leo | 15 + .../canonicalization/compound_assignment.json | 128 +++++++ .../canonicalization/compound_assignment.leo | 4 + .../canonicalization/input/array_expansion.in | 2 + compiler/tests/canonicalization/mod.rs | 89 +++++ compiler/tests/mod.rs | 2 + 13 files changed, 812 insertions(+), 6 deletions(-) create mode 100644 compiler/tests/canonicalization/array_expansion.json create mode 100644 compiler/tests/canonicalization/array_expansion.leo create mode 100644 compiler/tests/canonicalization/array_size_zero_fail.leo create mode 100644 compiler/tests/canonicalization/big_self_in_circuit_replacement.json create mode 100644 compiler/tests/canonicalization/big_self_in_circuit_replacement.leo create mode 100644 compiler/tests/canonicalization/big_self_outside_circuit_fail.leo create mode 100644 compiler/tests/canonicalization/compound_assignment.json create mode 100644 compiler/tests/canonicalization/compound_assignment.leo create mode 100644 compiler/tests/canonicalization/input/array_expansion.in create mode 100644 compiler/tests/canonicalization/mod.rs diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 398b61ad11..06178ecfea 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -18,9 +18,6 @@ use crate::*; pub struct Canonicalizer; -// TODO fix function input array. -// TODO fix test 0 size array. - impl Canonicalizer { fn is_self_type(&self, type_option: Option<&Type>) -> bool { matches!(type_option, Some(Type::SelfType)) @@ -161,7 +158,7 @@ impl Canonicalizer { Expression::CircuitInit(circuit_init) => { let mut name = circuit_init.name.clone(); - if circuit_name.name == *"Self" { + if name.name == *"Self" { name = circuit_name.clone(); } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index ab71c7b030..06aa1f4501 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -638,7 +638,7 @@ impl ReconstructingDirector { let mut inputs = vec![]; for input in function.input.iter() { - inputs.push(self.reduce_function_input(input, false)?); + inputs.push(self.reduce_function_input(input, in_circuit)?); } let output = match function.output.as_ref() { @@ -646,7 +646,7 @@ impl ReconstructingDirector { None => None, }; - let block = self.reduce_block(&function.block, false)?; + let block = self.reduce_block(&function.block, in_circuit)?; self.reducer .reduce_function(function, identifier, annotations, inputs, output, block, in_circuit) diff --git a/compiler/tests/canonicalization/array_expansion.json b/compiler/tests/canonicalization/array_expansion.json new file mode 100644 index 0000000000..4d321c1e68 --- /dev/null +++ b/compiler/tests/canonicalization/array_expansion.json @@ -0,0 +1,338 @@ +{ + "name": "", + "expected_input": [], + "imports": [], + "circuits": {}, + "functions": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}": { + "annotations": [], + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}", + "input": [ + { + "Variable": { + "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":15,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\"}\"}", + "const_": false, + "mutable": false, + "type_": { + "Array": [ + { + "Array": [ + "Group", + [ + { + "value": "1" + } + ] + ] + }, + [ + { + "value": "2" + } + ] + ] + }, + "span": { + "line_start": 1, + "line_stop": 1, + "col_start": 15, + "col_stop": 16, + "path": "" + } + } + } + ], + "output": { + "Tuple": [] + }, + "block": { + "statements": [ + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": false, + "identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 7, + "col_stop": 8, + "path": "" + } + } + ], + "type_": null, + "value": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "Value": { + "Boolean": [ + "true", + { + "line_start": 2, + "line_stop": 2, + "col_start": 12, + "col_stop": 16, + "path": "" + } + ] + } + }, + "dimensions": [ + { + "value": "2" + } + ], + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 11, + "col_stop": 34, + "path": "" + } + } + }, + "dimensions": [ + { + "value": "3" + } + ], + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 11, + "col_stop": 34, + "path": "" + } + } + }, + "dimensions": [ + { + "value": "4" + } + ], + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 11, + "col_stop": 34, + "path": "" + } + } + }, + "dimensions": [ + { + "value": "5" + } + ], + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 11, + "col_stop": 34, + "path": "" + } + } + }, + "dimensions": [ + { + "value": "6" + } + ], + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 11, + "col_stop": 34, + "path": "" + } + } + }, + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 3, + "col_stop": 34, + "path": "" + } + } + }, + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": false, + "identifier": "{\"name\":\"c\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 7, + "col_stop": 8, + "path": "" + } + } + ], + "type_": { + "Array": [ + { + "Array": [ + { + "IntegerType": "U32" + }, + [ + { + "value": "2" + } + ] + ] + }, + [ + { + "value": "1" + } + ] + ] + }, + "value": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "Value": { + "Integer": [ + "U32", + "0", + { + "line_start": 3, + "line_stop": 3, + "col_start": 27, + "col_stop": 31, + "path": "" + } + ] + } + }, + "dimensions": [ + { + "value": "2" + } + ], + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 26, + "col_stop": 40, + "path": "" + } + } + }, + "dimensions": [ + { + "value": "1" + } + ], + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 26, + "col_stop": 40, + "path": "" + } + } + }, + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 3, + "col_stop": 40, + "path": "" + } + } + }, + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": false, + "identifier": "{\"name\":\"d\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 4, + "line_stop": 4, + "col_start": 7, + "col_stop": 8, + "path": "" + } + } + ], + "type_": null, + "value": { + "ArrayInit": { + "element": { + "Value": { + "Integer": [ + "I8", + "0", + { + "line_start": 4, + "line_stop": 4, + "col_start": 12, + "col_stop": 15, + "path": "" + } + ] + } + }, + "dimensions": [ + { + "value": "1" + } + ], + "span": { + "line_start": 4, + "line_stop": 4, + "col_start": 11, + "col_stop": 21, + "path": "" + } + } + }, + "span": { + "line_start": 4, + "line_stop": 4, + "col_start": 3, + "col_stop": 21, + "path": "" + } + } + } + ], + "span": { + "line_start": 1, + "line_stop": 5, + "col_start": 35, + "col_stop": 2, + "path": "" + } + }, + "span": { + "line_start": 1, + "line_stop": 5, + "col_start": 1, + "col_stop": 2, + "path": "" + } + } + } +} diff --git a/compiler/tests/canonicalization/array_expansion.leo b/compiler/tests/canonicalization/array_expansion.leo new file mode 100644 index 0000000000..c83d9ce2c4 --- /dev/null +++ b/compiler/tests/canonicalization/array_expansion.leo @@ -0,0 +1,7 @@ +function main(a: [group; (2, 1)]) { + let b = [true; (6, 5, 4, 3, 2)]; + let c: [u32; (1, 2)] = [0u32; (1, 2)]; + let d = [0i8; (1)]; + // let d = [true; 0]; + // let e = [true; (0)]; +} \ No newline at end of file diff --git a/compiler/tests/canonicalization/array_size_zero_fail.leo b/compiler/tests/canonicalization/array_size_zero_fail.leo new file mode 100644 index 0000000000..b90563dc4d --- /dev/null +++ b/compiler/tests/canonicalization/array_size_zero_fail.leo @@ -0,0 +1,3 @@ +function main() { + let a = [true; (0)]; +} \ No newline at end of file diff --git a/compiler/tests/canonicalization/big_self_in_circuit_replacement.json b/compiler/tests/canonicalization/big_self_in_circuit_replacement.json new file mode 100644 index 0000000000..eb63d86b86 --- /dev/null +++ b/compiler/tests/canonicalization/big_self_in_circuit_replacement.json @@ -0,0 +1,206 @@ +{ + "name": "", + "expected_input": [], + "imports": [], + "circuits": { + "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}": { + "circuit_name": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}", + "members": [ + { + "CircuitVariable": [ + "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\"}\"}", + { + "IntegerType": "U32" + } + ] + }, + { + "CircuitFunction": { + "annotations": [], + "identifier": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":12,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\"}\"}", + "input": [], + "output": { + "Circuit": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}" + }, + "block": { + "statements": [ + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": false, + "identifier": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 5, + "line_stop": 5, + "col_start": 9, + "col_stop": 12, + "path": "" + } + } + ], + "type_": { + "Circuit": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}" + }, + "value": { + "CircuitInit": { + "name": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}", + "members": [ + { + "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\"}\"}", + "expression": { + "Value": { + "Integer": [ + "U32", + "1", + { + "line_start": 6, + "line_stop": 6, + "col_start": 10, + "col_stop": 14, + "path": "" + } + ] + } + } + } + ], + "span": { + "line_start": 5, + "line_stop": 7, + "col_start": 21, + "col_stop": 6, + "path": "" + } + } + }, + "span": { + "line_start": 5, + "line_stop": 7, + "col_start": 5, + "col_stop": 6, + "path": "" + } + } + }, + { + "Return": { + "expression": { + "Identifier": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":12,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\"}\"}" + }, + "span": { + "line_start": 9, + "line_stop": 9, + "col_start": 5, + "col_stop": 15, + "path": "" + } + } + } + ], + "span": { + "line_start": 4, + "line_stop": 10, + "col_start": 26, + "col_stop": 4, + "path": "" + } + }, + "span": { + "line_start": 4, + "line_stop": 10, + "col_start": 3, + "col_stop": 4, + "path": "" + } + } + } + ] + } + }, + "functions": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}": { + "annotations": [], + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}", + "input": [], + "output": { + "Tuple": [] + }, + "block": { + "statements": [ + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": false, + "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":7,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 14, + "line_stop": 14, + "col_start": 7, + "col_stop": 10, + "path": "" + } + } + ], + "type_": { + "Circuit": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":12,\\\"col_stop\\\":15,\\\"path\\\":\\\"\\\"}\"}" + }, + "value": { + "Call": { + "function": { + "CircuitStaticFunctionAccess": { + "circuit": { + "Identifier": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":18,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\"}\"}" + }, + "name": "{\"name\":\"new\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":23,\\\"col_stop\\\":26,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 14, + "line_stop": 14, + "col_start": 18, + "col_stop": 26, + "path": "" + } + } + }, + "arguments": [], + "span": { + "line_start": 14, + "line_stop": 14, + "col_start": 18, + "col_stop": 28, + "path": "" + } + } + }, + "span": { + "line_start": 14, + "line_stop": 14, + "col_start": 3, + "col_stop": 28, + "path": "" + } + } + } + ], + "span": { + "line_start": 13, + "line_stop": 15, + "col_start": 17, + "col_stop": 2, + "path": "" + } + }, + "span": { + "line_start": 13, + "line_stop": 15, + "col_start": 1, + "col_stop": 2, + "path": "" + } + } + } + } + \ No newline at end of file diff --git a/compiler/tests/canonicalization/big_self_in_circuit_replacement.leo b/compiler/tests/canonicalization/big_self_in_circuit_replacement.leo new file mode 100644 index 0000000000..f8b2657a70 --- /dev/null +++ b/compiler/tests/canonicalization/big_self_in_circuit_replacement.leo @@ -0,0 +1,15 @@ +circuit Foo { + x: u32 + + function new() -> Self { + let new: Self = Self { + x: 1u32 + }; + + return new + } +} + +function main() { + let foo: Foo = Foo::new(); +} \ No newline at end of file diff --git a/compiler/tests/canonicalization/big_self_outside_circuit_fail.leo b/compiler/tests/canonicalization/big_self_outside_circuit_fail.leo new file mode 100644 index 0000000000..d1f30e8470 --- /dev/null +++ b/compiler/tests/canonicalization/big_self_outside_circuit_fail.leo @@ -0,0 +1,15 @@ +circuit Foo { + x: u32 + + function new() -> Self { + let new: Self = Self { + x: 1u32 + }; + + return new + } +} + +function main() { + let foo: Self = Foo::new(); +} \ No newline at end of file diff --git a/compiler/tests/canonicalization/compound_assignment.json b/compiler/tests/canonicalization/compound_assignment.json new file mode 100644 index 0000000000..fda6fb09cf --- /dev/null +++ b/compiler/tests/canonicalization/compound_assignment.json @@ -0,0 +1,128 @@ +{ + "name": "", + "expected_input": [], + "imports": [], + "circuits": {}, + "functions": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}": { + "annotations": [], + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\"}\"}", + "input": [], + "output": { + "Tuple": [] + }, + "block": { + "statements": [ + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": true, + "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":11,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\"}\"}", + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 7, + "col_stop": 12, + "path": "" + } + } + ], + "type_": null, + "value": { + "Value": { + "Integer": [ + "U32", + "10", + { + "line_start": 2, + "line_stop": 2, + "col_start": 15, + "col_stop": 20, + "path": "" + } + ] + } + }, + "span": { + "line_start": 2, + "line_stop": 2, + "col_start": 3, + "col_stop": 20, + "path": "" + } + } + }, + { + "Assign": { + "operation": "Assign", + "assignee": { + "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\"}\"}", + "accesses": [], + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 3, + "col_stop": 4, + "path": "" + } + }, + "value": { + "Binary": { + "left": { + "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\"}\"}" + }, + "right": { + "Value": { + "Implicit": [ + "20", + { + "line_start": 3, + "line_stop": 3, + "col_start": 8, + "col_stop": 10, + "path": "" + } + ] + } + }, + "op": "Add", + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 3, + "col_stop": 10, + "path": "" + } + } + }, + "span": { + "line_start": 3, + "line_stop": 3, + "col_start": 3, + "col_stop": 10, + "path": "" + } + } + } + ], + "span": { + "line_start": 1, + "line_stop": 4, + "col_start": 17, + "col_stop": 2, + "path": "" + } + }, + "span": { + "line_start": 1, + "line_stop": 4, + "col_start": 1, + "col_stop": 2, + "path": "" + } + } + } + } + \ No newline at end of file diff --git a/compiler/tests/canonicalization/compound_assignment.leo b/compiler/tests/canonicalization/compound_assignment.leo new file mode 100644 index 0000000000..f17d8762ff --- /dev/null +++ b/compiler/tests/canonicalization/compound_assignment.leo @@ -0,0 +1,4 @@ +function main() { + let mut x = 10u32; + x += 20; +} \ No newline at end of file diff --git a/compiler/tests/canonicalization/input/array_expansion.in b/compiler/tests/canonicalization/input/array_expansion.in new file mode 100644 index 0000000000..072fb7677c --- /dev/null +++ b/compiler/tests/canonicalization/input/array_expansion.in @@ -0,0 +1,2 @@ +[main] +a: [group; (2, 1)] = [1group; (2, 1)]; \ No newline at end of file diff --git a/compiler/tests/canonicalization/mod.rs b/compiler/tests/canonicalization/mod.rs new file mode 100644 index 0000000000..fd2db5da3f --- /dev/null +++ b/compiler/tests/canonicalization/mod.rs @@ -0,0 +1,89 @@ +// 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, parse_program, parse_program_with_input}; +use leo_ast::Ast; +use leo_parser::parser; + +pub fn parse_program_ast(file_string: &str) -> Ast { + const TEST_PROGRAM_PATH: &str = ""; + let test_program_file_path = std::path::PathBuf::from(TEST_PROGRAM_PATH); + + let mut ast = Ast::new( + parser::parse(test_program_file_path.to_str().expect("unwrap fail"), &file_string) + .expect("Failed to parse file."), + ); + ast.canonicalize().expect("Failed to canonicalize program."); + + ast +} + +#[test] +fn test_big_self_in_circuit_replacement() { + // Check program is valid. + let program_string = include_str!("big_self_in_circuit_replacement.leo"); + let program = parse_program(program_string).unwrap(); + assert_satisfied(program); + + // Check we get expected ast. + let ast = parse_program_ast(program_string); + let expected_json = include_str!("big_self_in_circuit_replacement.json"); + let expected_ast: Ast = Ast::from_json_string(expected_json).expect("Unable to parse json."); + + assert_eq!(expected_ast, ast); +} + +#[test] +fn test_big_self_outside_circuit_fail() { + // Check program is invalid. + let program_string = include_str!("big_self_outside_circuit_fail.leo"); + let program = parse_program(program_string); + assert!(program.is_err()); +} + +#[test] +fn test_array_expansion() { + let program_string = include_str!("array_expansion.leo"); + let input_string = include_str!("input/array_expansion.in"); + let program = parse_program_with_input(program_string, input_string).unwrap(); + assert_satisfied(program); + + let ast = parse_program_ast(program_string); + let expected_json = include_str!("array_expansion.json"); + let expected_ast: Ast = Ast::from_json_string(expected_json).expect("Unable to parse json."); + + assert_eq!(expected_ast, ast); +} + +#[test] +fn test_array_size_zero_fail() { + let program_string = include_str!("array_size_zero_fail.leo"); + let program = parse_program(program_string); + assert!(program.is_err()); +} + +#[test] +fn test_compound_assignment() { + let program_string = include_str!("compound_assignment.leo"); + let program = parse_program(program_string).unwrap(); + assert_satisfied(program); + + let ast = parse_program_ast(program_string); + let expected_json = include_str!("compound_assignment.json"); + let expected_ast: Ast = Ast::from_json_string(expected_json).expect("Unable to parse json."); + + assert_eq!(expected_ast, ast); +} diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index bacbde0ddb..96069ffe54 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -15,11 +15,13 @@ // along with the Leo library. If not, see . // allow the use of EdwardsTestCompiler::parse_program_from_string for tests + #![allow(deprecated)] pub mod address; pub mod array; pub mod boolean; +pub mod canonicalization; pub mod circuits; pub mod compiler; pub mod console; From e2817f9b8db4f33d56432dd45c369651b5305952 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Wed, 17 Mar 2021 17:58:21 -0400 Subject: [PATCH 16/40] Delete HEAD Not sure when I accidentally made this --- HEAD | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 HEAD diff --git a/HEAD b/HEAD deleted file mode 100644 index e69de29bb2..0000000000 From 0e9bff8419ac9b15f78921cdfe7fd6a7a3b3b3e9 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Wed, 17 Mar 2021 18:00:02 -0400 Subject: [PATCH 17/40] Delete test.report Delete debug file --- test.report | 1163 --------------------------------------------------- 1 file changed, 1163 deletions(-) delete mode 100644 test.report diff --git a/test.report b/test.report deleted file mode 100644 index b04880500d..0000000000 --- a/test.report +++ /dev/null @@ -1,1163 +0,0 @@ - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.01s - - -running 410 tests -test fail::array::test_initializer_fail ... ok -test fail::array::test_input_nested_3x2_fail ... ok -test fail::array::test_type_fail ... ok -test fail::address::test_implicit_invalid ... ok -test fail::array::test_multi_initializer_fail ... ok -test fail::array::test_multi_fail_initializer ... ok -test fail::array::test_multi_inline_fail ... ok -test fail::array::test_type_nested_value_nested_3x2_fail ... ok -test fail::array::test_nested_3x2_value_fail ... ok -test fail::array::test_input_tuple_3x2_fail ... ok -test fail::array::test_type_nested_value_nested_4x3x2_fail ... ok -test fail::array::test_tuple_3x2_value_fail ... ok -test fail::array::test_type_nested_value_tuple_4x3x2_fail ... ok -test fail::array::test_type_nested_value_tuple_3x2_fail ... ok -test fail::array::test_type_tuple_value_tuple_3x2_fail ... ok -test fail::array::test_type_tuple_value_nested_4x3x2_fail ... ok -test fail::array::test_type_tuple_value_nested_3x2_fail ... ok -test fail::array::test_type_tuple_value_tuple_3x2_swap_fail ... ok -test fail::boolean::test_not_u32 ... ok -test fail::boolean::test_true_or_u32 ... ok -test fail::boolean::test_true_and_u32 ... ok -test fail::array::test_type_tuple_value_nested_3x2_swap_fail ... ok -test fail::array::test_type_tuple_value_tuple_4x3x2_fail ... ok -test fail::circuits::test_inline_undefined ... ok -test fail::circuits::test_member_static_function_invalid ... ok -test fail::circuits::test_inline_fail ... ok -test fail::circuits::test_member_function_invalid ... ok -test fail::circuits::test_member_function_fail ... ok -test fail::circuits::test_member_static_function_undefined ... ok -test fail::circuits::test_mutate_function_fail ... ok -test fail::circuits::test_member_variable_fail ... ok -test fail::circuits::test_self_fail ... ok -test fail::circuits::test_mut_member_function_fail ... ok -test fail::circuits::test_mutate_static_function_fail ... ok -test fail::circuits::test_mutate_variable_fail ... ok -test fail::circuits::test_mutate_self_function_fail ... ok -test fail::console::test_log_fail ... ok -test fail::circuits::test_mutate_self_variable_fail ... ok -test fail::console::test_log_parameter_fail_empty ... ok -test fail::console::test_log_parameter_fail_none ... ok -test fail::circuits::test_self_member_invalid ... ok -test fail::core::test_core_circuit_invalid ... ok -test fail::core::test_core_circuit_star_fail ... ok -test fail::core::test_core_package_invalid ... ok -test fail::console::test_log_parameter_fail_unknown ... ok -test fail::circuits::test_self_member_undefined ... ok -test fail::function::test_multiple_returns_fail ... ok -test fail::function::test_multiple_returns_input_ambiguous ... ok -test fail::function::test_array_input ... ok -test fail::function::test_multiple_returns_fail_conditional ... ok -test fail::integers::i128::test_i128_max_fail ... ok -test fail::function::test_scope_fail ... ok -test fail::function::test_undefined ... ok -test fail::function::test_return_array_tuple_fail ... ok -test fail::integers::i128::test_i128_min_fail ... ok -test fail::function::test_return_array_nested_fail ... ok -test fail::integers::i16::test_i16_min_fail ... ok -test fail::integers::i32::test_i32_max_fail ... ok -test fail::integers::i32::test_i32_min_fail ... ok -test fail::integers::i64::test_i64_max_fail ... ok -test fail::integers::i16::test_i16_max_fail ... ok -test fail::circuits::test_mutate_self_static_function_fail ... ok -test fail::integers::i64::test_i64_min_fail ... ok -test fail::integers::i8::test_i8_min_fail ... ok -test fail::integers::u128::test_u128_min_fail ... ok -test fail::integers::u16::test_u16_max_fail ... ok -test fail::core::test_core_unstable_package_invalid ... ok -test fail::integers::i8::test_i8_max_fail ... ok -test fail::integers::u16::test_u16_min_fail ... ok -test fail::integers::u32::test_u32_min_fail ... ok -test fail::integers::u128::test_u128_max_fail ... ok -test fail::integers::u64::test_u64_min_fail ... ok -test fail::integers::u8::test_u8_max_fail ... ok -test fail::integers::u32::test_u32_max_fail ... ok -test fail::integers::u64::test_u64_max_fail ... ok -test fail::mutability::test_circuit ... ok -test fail::integers::u8::test_u8_min_fail ... ok -test fail::mutability::test_array ... ok -test fail::mutability::test_circuit_static_function_mut ... ok -test fail::mutability::test_const_fail ... ok -test fail::mutability::test_function_input ... ok -test fail::statements::test_const_declaration_fail ... ok -test fail::mutability::test_circuit_function_mut ... ok -test fail::statements::test_num_returns_fail ... ok -test pass::address::test_implicit_valid ... ok -test pass::address::test_equal ... ok -test pass::address::test_console_assert_pass ... ok -test fail::mutability::test_let ... ok -test pass::address::test_valid ... ok -test pass::array::test_initializer ... ok -test pass::address::test_ternary ... ok -test pass::array::test_inline ... ok -test pass::array::test_index_u8 ... ok -test pass::array::test_input_tuple_3x2 ... ok -test pass::array::test_initializer_input ... ok -test pass::array::test_implicit ... ok -test pass::array::test_input_nested_3x2 ... ok -test pass::array::test_input_type_nested_value_nested_3x2 ... ok -test pass::array::test_input_type_nested_value_tuple_3x2 ... ok -test pass::array::test_input_type_tuple_value_tuple_3x2 ... ok -test pass::array::test_input_type_tuple_value_nested_3x2 ... ok -test pass::array::test_input_type_nested_value_nested_4x3x2 ... ok -test pass::array::test_multi_initializer ... ok -test pass::array::test_registers ... ok -test pass::array::test_nested_3x2_value ... ok -test pass::array::test_input_type_tuple_value_tuple_4x3x2 ... ok -test pass::array::test_input_type_nested_value_tuple_4x3x2 ... ok -test pass::array::test_input_type_tuple_value_nested_4x3x2 ... ok -test pass::array::test_slice_i8 ... ok -test pass::array::test_spread ... ok -test pass::array::test_slice ... ok -test pass::array::test_slice_lower ... ok -test pass::array::test_type_nested_value_nested_3x2 ... ok -test pass::array::test_tuple_3x2_value ... ok -test pass::array::test_type_tuple_value_nested_3x2 ... ok -test pass::array::test_type_nested_value_tuple_3x2 ... ok -test pass::array::test_type_tuple_value_tuple_3x2 ... ok -test pass::array::test_type_nested_value_tuple_4x3x2 ... ok -test pass::array::test_type_nested_value_nested_4x3x2 ... ok -test pass::boolean::test_input_pass ... ok -test pass::boolean::test_false_and_false ... ok -test pass::boolean::test_false_or_false ... ok -test pass::boolean::test_not_false ... ok -test pass::boolean::test_all ... ok -test pass::boolean::test_not_mutable ... ok -test pass::boolean::test_registers ... ok -test pass::boolean::test_true_and_true ... ok -test pass::boolean::test_not_true ... ok -test pass::boolean::test_true_or_false ... ok -test pass::boolean::test_true_or_true ... ok -test pass::array::test_type_tuple_value_nested_4x3x2 ... ok -test pass::array::test_type_tuple_value_tuple_4x3x2 ... ok -test pass::circuits::test_circuit_explicit_define ... ok -test pass::circuits::test_member_variable ... ok -test pass::circuits::test_member_function ... ok -test pass::circuits::test_member_static_function ... ok -test pass::circuits::test_member_static_function_nested ... ok -test pass::circuits::test_define_circuit_inside_circuit_function ... ok -test pass::circuits::test_inline ... ok -test pass::boolean::test_true_and_false ... ok -test pass::circuits::test_member_variable_and_function ... ok -test pass::circuits::test_member_function_nested ... ok -test pass::circuits::test_mut_member_function ... ok -test pass::circuits::test_mutate_variable ... ok -test pass::circuits::test_mutate_self_variable_conditional ... ok -test pass::console::test_debug ... ok -test pass::console::test_error ... ok -test pass::console::test_log ... ok -test pass::console::test_conditional_assert ... ok -test pass::circuits::test_pedersen_mock ... ok -test pass::circuits::test_self_member_pass ... ok -test pass::console::test_assert ... ok -test pass::console::test_log_parameter_many ... ok -test pass::circuits::test_mutate_self_variable ... ok -test pass::console::test_log_parameter ... ok -test pass::console::test_log_input ... ok -test pass::definition::test_out_of_order ... ok -test pass::field::test_console_assert_pass ... ok -test pass::field::test_div ... ok -test pass::field::test_add ... ok -test pass::field::test_eq ... ok -test pass::field::test_negate ... ok -test pass::field::test_mul ... ok -test pass::core::test_blake2s_random ... ok -test pass::field::test_sub ... ok -test pass::core::test_unstable_blake2s ... ok -test pass::field::test_ternary ... ok -test pass::core::test_blake2s_input ... ok -test pass::function::test_array_input ... ok -test pass::form_ast::test_function_rename ... ok -test pass::function::test_empty ... ok -test pass::function::test_const_args ... ok -test pass::function::test_const_args_fail ... ok -test pass::function::test_iteration ... ok -test pass::function::test_const_args_used ... ok -test pass::form_ast::test_basic ... ok -test pass::function::test_multiple_returns ... ok -test pass::function::test_iteration_repeated ... ok -test pass::function::test_multiple_returns_main ... ok -test pass::function::test_repeated_function_call ... ok -test pass::function::test_return_array_tuple_pass ... ok -test pass::function::test_return ... ok -test pass::function::test_return_tuple ... ok -test pass::function::test_return_array_nested_pass ... ok -test pass::function::test_newlines ... ok -test pass::function::test_undefined ... ok -test pass::group::test_add_explicit ... ok -test pass::group::test_add ... ok -test pass::group::test_console_assert_pass ... ok -test pass::function::test_value_unchanged ... ok -test pass::field::test_add_explicit ... ok -test pass::form_ast::test_imports ... ok -test pass::group::test_eq ... ok -test pass::group::test_implicit ... ok -test pass::function::test_return_tuple_conditional ... ok -test pass::group::test_one ... ok -test pass::group::test_point_input ... ok -test pass::group::test_negate ... ok -test pass::group::test_point ... ok -test pass::group::test_input ... ok -test pass::group::test_sub ... ok -test pass::group::test_ternary ... ok -test pass::group::test_x_sign_high ... ok -test pass::group::test_x_sign_inferred ... ok -test pass::group::test_x_sign_low ... ok -test pass::group::test_y_sign_high ... ok -test pass::group::test_y_sign_low ... ok -test pass::group::test_zero ... ok -test pass::group::test_y_sign_inferred ... ok -test pass::import::test_multiple ... ok -test pass::import::test_alias ... ok -test pass::input_files::program_input::test_input_multiple ... ok -test pass::import::test_basic ... ok -test pass::import::test_name ... ok -test pass::input_files::program_input::test_input_pass ... ok -test pass::input_files::program_state::test_access_state ... ok -test pass::import::test_star ... ok -test pass::integers::i128::test_i128_div ... ignored -test pass::input_files::program_input_and_program_state::test_access ... ok -test pass::input_files::program_state::test_access_all ... ok -test pass::integers::i128::test_i128_add ... ok -test pass::import::test_many_import ... ok -test pass::integers::i128::test_i128_max ... ok -test pass::integers::i128::test_i128_assert_eq ... ok -test pass::integers::i128::test_i128_gt ... ok -test pass::integers::i128::test_i128_lt ... ok -test pass::integers::i128::test_i128_eq ... ok -test pass::integers::i128::test_i128_le ... ok -test pass::integers::i128::test_i128_min ... ok -test pass::integers::i128::test_i128_ge ... ok -test pass::integers::i128::test_i128_neg ... ok -test pass::integers::i128::test_i128_neg_zero ... ok -test pass::integers::i128::test_i128_ne ... ok -test pass::integers::i128::test_i128_pow ... ok -test pass::integers::i128::test_i128_mul ... ok -test pass::integers::i16::test_i16_console_assert ... ok -test pass::import::test_many_import_star ... ok -test pass::integers::i16::test_i16_add ... ok -test pass::integers::i16::test_i16_div ... ok -test pass::integers::i16::test_i16_eq ... ok -test pass::integers::i128::test_i128_sub ... ok -test pass::integers::i128::test_i128_ternary ... ok -test pass::integers::i16::test_i16_lt ... ok -test pass::integers::i16::test_i16_ge ... ok -test pass::integers::i16::test_i16_max ... ok -test pass::integers::i16::test_i16_gt ... ok -test pass::integers::i16::test_i16_min ... ok -test pass::integers::i16::test_i16_ne ... ok -test pass::integers::i16::test_i16_le ... ok -test pass::integers::i16::test_i16_mul ... ok -test pass::integers::i16::test_i16_pow ... ok -test pass::integers::i32::test_i32_console_assert ... ok -test pass::integers::i16::test_i16_neg ... ok -test pass::integers::i16::test_i16_neg_zero ... ok -test pass::integers::i16::test_i16_sub ... ok -test pass::integers::i16::test_i16_ternary ... ok -test pass::integers::i32::test_i32_add ... ok -test pass::integers::i32::test_i32_div ... ok -test pass::integers::i32::test_i32_eq ... ok -test pass::integers::i32::test_i32_max ... ok -test pass::integers::i32::test_i32_gt ... ok -test pass::integers::i32::test_i32_ge ... ok -test pass::integers::i32::test_i32_lt ... ok -test pass::integers::i32::test_i32_le ... ok -test pass::integers::i32::test_i32_min ... ok -test pass::integers::i32::test_i32_neg ... ok -test pass::integers::i32::test_i32_mul ... ok -test pass::integers::i64::test_i64_div ... ignored -test pass::integers::i32::test_i32_neg_zero ... ok -test pass::integers::i32::test_i32_pow ... ok -test pass::integers::i32::test_i32_ternary ... ok -test pass::integers::i32::test_i32_ne ... ok -test pass::integers::i64::test_i64_add ... ok -test pass::integers::i32::test_i32_sub ... ok -test pass::integers::i64::test_i64_console_assert ... ok -test pass::integers::i64::test_i64_eq ... ok -test pass::integers::i64::test_i64_gt ... ok -test pass::integers::i64::test_i64_ge ... ok -test pass::integers::i64::test_i64_max ... ok -test pass::integers::i64::test_i64_le ... ok -test pass::integers::i64::test_i64_mul ... ok -test pass::integers::i64::test_i64_lt ... ok -test pass::integers::i64::test_i64_min ... ok -test pass::integers::i64::test_i64_ne ... ok -test pass::integers::i64::test_i64_pow ... ok -test pass::integers::i64::test_i64_neg ... ok -test pass::integers::i64::test_i64_neg_zero ... ok -test pass::integers::i8::test_i8_add ... ok -test pass::integers::i64::test_i64_sub ... ok -test pass::integers::i64::test_i64_ternary ... ok -test pass::integers::i8::test_i8_eq ... ok -test pass::integers::i8::test_i8_console_assert ... ok -test pass::integers::i8::test_i8_max ... ok -test pass::integers::i8::test_i8_ge ... ok -test pass::integers::i8::test_i8_gt ... ok -test pass::integers::i8::test_i8_div ... ok -test pass::integers::i8::test_i8_le ... ok -test pass::integers::i8::test_i8_lt ... ok -test pass::integers::i8::test_i8_min ... ok -test pass::integers::i8::test_i8_ne ... ok -test pass::integers::i8::test_i8_neg ... ok -test pass::integers::i8::test_i8_pow ... ok -test pass::integers::i8::test_i8_neg_zero ... ok -test pass::integers::i8::test_i8_mul ... ok -test pass::integers::u128::test_u128_add ... ok -test pass::integers::i8::test_i8_sub ... ok -test pass::integers::i8::test_i8_ternary ... ok -test pass::integers::u128::test_u128_le ... ok -test pass::integers::u128::test_u128_ge ... ok -test pass::integers::u128::test_u128_eq ... ok -test pass::integers::u128::test_u128_console_assert ... ok -test pass::integers::u128::test_u128_max ... ok -test pass::integers::u128::test_u128_div ... ok -test pass::integers::u128::test_u128_lt ... ok -test pass::integers::u128::test_u128_gt ... ok -test pass::integers::u128::test_u128_min ... ok -test pass::integers::u128::test_u128_ne ... ok -test pass::integers::u128::test_u128_mul ... ok -test pass::integers::u128::test_u128_sub ... ok -test pass::integers::u16::test_u16_add ... ok -test pass::integers::u128::test_u128_pow ... ok -test pass::integers::u128::test_u128_ternary ... ok -test pass::integers::u16::test_u16_console_assert ... ok -test pass::integers::u16::test_u16_ge ... ok -test pass::integers::u16::test_u16_div ... ok -test pass::integers::u16::test_u16_eq ... ok -test pass::integers::u16::test_u16_lt ... ok -test pass::integers::u16::test_u16_le ... ok -test pass::integers::u16::test_u16_gt ... ok -test pass::integers::u16::test_u16_max ... ok -test pass::integers::u16::test_u16_min ... ok -test pass::integers::u16::test_u16_sub ... ok -test pass::integers::u16::test_u16_ternary ... ok -test pass::integers::u16::test_u16_ne ... ok -test pass::integers::u16::test_u16_pow ... ok -test pass::integers::u32::test_u32_console_assert ... ok -test pass::integers::u16::test_u16_mul ... ok -test pass::integers::u32::test_u32_div ... ok -test pass::integers::u32::test_u32_le ... ok -test pass::integers::u32::test_u32_eq ... ok -test pass::integers::u32::test_u32_gt ... ok -test pass::integers::u32::test_u32_lt ... ok -test pass::integers::u32::test_u32_max ... ok -test pass::integers::u32::test_u32_ge ... ok -test pass::integers::u32::test_u32_min ... ok -test pass::integers::u32::test_u32_add ... ok -test pass::integers::u32::test_u32_mul ... ok -test pass::integers::u32::test_u32_pow ... ok -test pass::integers::u32::test_u32_ne ... ok -test pass::integers::u64::test_u64_console_assert ... ok -test pass::integers::u32::test_u32_sub ... ok -test pass::integers::u64::test_u64_div ... ok -test pass::integers::u64::test_u64_add ... ok -test pass::integers::u32::test_u32_ternary ... ok -test pass::integers::u64::test_u64_eq ... ok -test pass::integers::u64::test_u64_max ... ok -test pass::integers::u64::test_u64_le ... ok -test pass::integers::u64::test_u64_gt ... ok -test pass::integers::u64::test_u64_ge ... ok -test pass::integers::u64::test_u64_lt ... ok -test pass::integers::u64::test_u64_min ... ok -test pass::integers::u64::test_u64_ne ... ok -test pass::integers::u64::test_u64_sub ... ok -test pass::integers::u64::test_u64_mul ... ok -test pass::integers::u64::test_u64_ternary ... ok -test pass::integers::u64::test_u64_pow ... ok -test pass::integers::u8::test_u8_add ... ok -test pass::integers::u8::test_u8_console_assert ... ok -test pass::integers::u8::test_u8_ge ... ok -test pass::integers::u8::test_u8_eq ... ok -test pass::integers::u8::test_u8_gt ... ok -test pass::integers::u8::test_u8_le ... ok -test pass::integers::u8::test_u8_div ... ok -test pass::integers::u8::test_u8_lt ... ok -test pass::integers::u8::test_u8_min ... ok -test pass::integers::u8::test_u8_mul ... ok -test pass::integers::u8::test_u8_max ... ok -test pass::integers::u8::test_u8_ne ... ok -test pass::integers::u8::test_u8_pow ... ok -test pass::integers::u8::test_u8_ternary ... ok -test pass::integers::u8::test_u8_sub ... ok -test pass::mutability::test_array_mut ... ok -test pass::mutability::test_function_input_mut ... ok -test pass::mutability::test_circuit_variable_mut ... ok -test pass::mutability::test_let_mut ... ok -test pass::mutability::test_array_splice_mut ... ok -test pass::mutability::test_array_tuple_mut ... ok -test pass::mutability::test_let_mut_nested ... ok -test pass::mutability::test_circuit_mut ... ok -test pass::statements::conditional::test_assert ... ok -test pass::statements::conditional::test_for_loop ... ok -test pass::statements::conditional::test_chain ... ok -test pass::mutability::test_swap ... ok -test pass::statements::conditional::test_multiple_returns ... ok -test pass::statements::test_block ... ok -test pass::statements::conditional::test_nested ... ok -test pass::statements::test_iteration_basic ... ok -test pass::tuples::test_function ... ok -test pass::statements::conditional::test_mutate ... ok -test pass::statements::test_ternary_basic ... ok -test pass::tuples::test_multiple ... ok -test pass::tuples::test_nested ... ok -test pass::tuples::test_nested_typed ... ok -test pass::tuples::test_multiple_typed ... ok -test pass::tuples::test_function_multiple ... ok -test pass::tuples::test_function_typed ... ok -test pass::tuples::test_tuple_basic ... ok -test pass::tuples::test_tuple_typed ... ok -test pass::tuples::test_nested_access ... ok -test pass::tuples::test_tuple_access ... ok - -test result: ok. 408 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.07s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 1 test -test errors::error::test_error ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 435 tests -test address::test_invalid_length ... ok -test address::test_invalid_prefix ... ok -test address::test_empty ... ok -test address::test_implicit_invalid ... ok -test array::test_initializer_fail ... ok -test address::test_implicit_valid ... ok -test address::test_console_assert_fail ... ok -test array::test_initializer_input_fail ... ok -test array::test_inline_fail ... ok -test address::test_valid ... ok -test array::test_input_nested_3x2_fail ... ok -test array::test_inline ... ok -test array::test_initializer ... ok -test array::test_input_tuple_3x2_fail ... ok -test address::test_console_assert_pass ... ok -test array::test_initializer_input ... ok -test array::test_input_type_nested_value_nested_3x2_fail ... ok -test array::test_input_tuple_3x2 ... ok -test array::test_input_type_nested_value_tuple_3x2_fail ... ok -test array::test_input_type_nested_value_nested_4x3x2_fail ... ok -test array::test_input_nested_3x2 ... ok -test array::test_input_type_nested_value_nested_3x2 ... ok -test array::test_input_type_tuple_value_nested_3x2_fail ... ok -test array::test_input_type_nested_value_tuple_4x3x2_fail ... ok -test array::test_input_type_tuple_value_nested_4x3x2_fail ... ok -test array::test_input_type_nested_value_tuple_3x2 ... ok -test array::test_input_type_tuple_value_nested_3x2 ... ok -test array::test_input_type_tuple_value_tuple_3x2 ... ok -test array::test_input_type_tuple_value_tuple_4x3x2_fail ... ok -test array::test_multi_fail_initializer ... ok -test array::test_input_type_tuple_value_tuple_3x2_fail ... ok -test array::test_multi_initializer_fail ... ok -test array::test_input_type_nested_value_tuple_4x3x2 ... ok -test array::test_nested ... ok -test array::test_multi_initializer ... ok -test array::test_multi_inline_fail ... ok -test array::test_nested_3x2_value_fail ... ok -test array::test_nested_3x2_value ... ok -test array::test_input_type_nested_value_nested_4x3x2 ... ok -test array::test_registers ... ok -test array::test_slice_lower ... ok -test array::test_spread ... ok -test array::test_slice ... ok -test array::test_type_fail ... ok -test array::test_type_nested_value_nested_3x2_fail ... ok -test array::test_tuple_3x2_value ... ok -test array::test_type_nested_value_nested_4x3x2_fail ... ok -test array::test_type_nested_value_nested_3x2 ... ok -test array::test_type_nested_value_tuple_3x2_fail ... ok -test array::test_tuple_3x2_value_fail ... ok -test array::test_type_nested_value_tuple_4x3x2_fail ... ok -test array::test_type_nested_value_tuple_3x2 ... ok -test array::test_type_tuple_value_nested_3x2_fail ... ok -test array::test_input_type_tuple_value_nested_4x3x2 ... ok -test array::test_type_tuple_value_nested_3x2 ... ok -test array::test_type_tuple_value_nested_4x3x2_fail ... ok -test array::test_type_tuple_value_tuple_3x2_fail ... ok -test array::test_type_nested_value_nested_4x3x2 ... ok -test array::test_type_tuple_value_tuple_4x3x2_fail ... ok -test array::test_variable_slice_fail ... ok -test array::test_type_nested_value_tuple_4x3x2 ... ok -test boolean::test_all ... ok -test array::test_type_tuple_value_tuple_3x2 ... ok -test boolean::test_false_and_false ... ok -test boolean::test_false_or_false ... ok -test boolean::test_input_fail ... ok -test boolean::test_input_pass ... ok -test boolean::test_not_false ... ok -test boolean::test_not_true ... ok -test boolean::test_not_mutable ... ok -test boolean::test_not_u32 ... ok -test boolean::test_true_and_false ... ok -test boolean::test_true_and_true ... ok -test boolean::test_true_and_u32 ... ok -test array::test_type_tuple_value_nested_4x3x2 ... ok -test boolean::test_true_or_false ... ok -test boolean::test_true_or_u32 ... ok -test boolean::test_conditional_mut ... ok -test boolean::test_true_or_true ... ok -test circuits::test_inline ... ok -test circuits::test_define_circuit_inside_circuit_function ... ok -test circuits::test_inline_fail ... ok -test boolean::test_registers ... ok -test array::test_type_tuple_value_tuple_4x3x2 ... ok -test circuits::test_duplicate_name_context ... ok -test circuits::test_inline_member_pass ... ok -test circuits::test_inline_undefined ... ok -test circuits::test_member_function_invalid ... ok -test circuits::test_member_function ... ok -test circuits::test_member_function_fail ... ok -test circuits::test_member_static_function_invalid ... ok -test circuits::test_member_static_function_undefined ... ok -test circuits::test_member_static_function_nested ... ok -test array::test_input_type_tuple_value_tuple_4x3x2 ... ok -test circuits::test_member_function_nested ... ok -test circuits::test_member_variable_fail ... ok -test circuits::test_mutate_function_fail ... ok -test circuits::test_member_variable ... ok -test circuits::test_member_variable_and_function ... ok -test circuits::test_mutate_self_function_fail ... ok -test circuits::test_mutate_self_static_function_fail ... ok -test circuits::test_mutate_self_variable_conditional ... FAILED -test circuits::test_inline_member_fail ... ok -test circuits::test_mutate_self_variable_fail ... ok -test circuits::test_mutate_static_function_fail ... ok -test circuits::test_mutate_variable ... FAILED -test circuits::test_mutate_self_variable ... ok -test circuits::test_self_fail ... ok -test circuits::test_self_member_invalid ... ok -test circuits::test_self_member_undefined ... ok -test compiler::test_parse_program_from_string ... ignored -test circuits::test_member_static_function ... ok -test circuits::test_mutate_self_variable_branch ... ok -test circuits::test_self_member_pass ... ok -test console::test_assert ... ok -test console::test_debug ... ok -test circuits::test_mutate_variable_fail ... ok -test console::test_log ... ok -test console::test_error ... ok -test console::test_log_fail ... ok -test console::test_conditional_assert ... ok -test console::test_log_parameter ... ok -test console::test_log_parameter_fail_none ... ok -test console::test_log_parameter_many ... ok -test console::test_log_parameter_fail_empty ... ok -test console::test_log_input ... ok -test console::test_log_parameter_fail_unknown ... ok -test core::packages::unstable::blake2s::test_arguments_length_fail ... ok -test core::test_core_circuit_invalid ... ok -test core::test_core_circuit_star_fail ... ok -test core::packages::unstable::blake2s::test_arguments_type_fail ... ok -test core::test_core_unstable_package_invalid ... ok -test core::test_core_package_invalid ... ok -test definition::test_out_of_order ... ok -test definition::test_out_of_order_with_import ... ignored -test function::test_array_input ... ok -test console::test_log_conditional ... ok -test function::test_conditional_return ... ok -test function::test_array_params_direct_call ... ok -test function::test_empty ... ok -test function::test_iteration_repeated ... FAILED -test function::test_iteration ... ok -test function::test_multiple_returns ... ok -test function::test_multiple_returns_fail ... ok -test function::test_multiple_returns_main ... ok -test function::test_newlines ... ok -test function::test_repeated_function_call ... ok -test function::test_return ... ok -test function::test_multiple_returns_fail_conditional ... ok -test function::test_return_array_nested_fail ... ok -test function::test_return_array_nested_pass ... ok -test function::test_return_array_tuple_fail ... ok -test function::test_return_array_tuple_pass ... ok -test function::test_return_tuple ... ok -test function::test_return_tuple_conditional ... ok -test function::test_undefined ... ok -test function::test_scope_fail ... ok -test import::test_alias ... ignored -test import::test_basic ... ignored -test import::test_many_import ... ignored -test import::test_many_import_star ... ignored -test import::test_multiple ... ignored -test import::test_names_fail_1 ... ignored -test import::test_names_fail_2 ... ignored -test import::test_names_fail_3 ... ignored -test import::test_names_fail_4 ... ignored -test import::test_names_pass ... ignored -test import::test_star ... ignored -test import::test_star_fail ... ignored -test function::test_value_unchanged ... FAILED -test input_files::program_input::test_field_input ... ok -test address::test_equal ... ok -test input_files::program_input::test_input_array_fail ... ok -test input_files::program_input::test_input_fail_name ... ok -test input_files::program_input::test_input_fail_type ... ok -test input_files::program_input::test_group_input ... ok -test input_files::program_input::test_input_array_dimensions_mismatch ... ok -test input_files::program_input::test_input_pass ... ok -test input_files::program_input::test_input_multiple ... ok -test input_files::program_input_and_program_state::test_basic ... ok -test input_files::program_input::test_input_multi_dimension_array ... ok -test input_files::program_registers::test_registers_array ... ok -test input_files::program_registers::test_registers_fail ... ok -test input_files::program_registers::test_registers_pass ... ok -test input_files::program_input_and_program_state::test_full ... ok -test input_files::program_input_and_program_state::test_access ... ok -test input_files::program_state::test_basic ... ok -test input_files::program_state::test_section_invalid ... ok -test input_files::program_state::test_section_undefined ... ok -test input_files::program_state::test_access_all ... ok -test input_files::program_state::test_visibility_fail ... ok -test input_files::program_state::test_token_withdraw ... ok -test input_files::program_state::test_access_state ... ok -test integers::i128::test_i128_div ... ignored -test core::test_unstable_blake2s_sanity ... ok -test address::test_ternary ... ok -test circuits::test_pedersen_mock ... ok -test integers::i128::test_i128_assert_eq ... ok -test integers::i128::test_i128_eq ... ok -test integers::i128::test_i128_max ... ok -test integers::i128::test_i128_max_fail ... ok -test integers::i128::test_i128_min ... ok -test integers::i128::test_i128_min_fail ... ok -test integers::i128::test_i128_mul ... ok -test integers::i128::test_i128_add ... ok -test integers::i128::test_i128_gt ... ok -test integers::i128::test_i128_ge ... ok -test integers::i128::test_i128_neg_zero ... ok -test integers::i128::test_i128_neg_max_fail ... ok -test integers::i128::test_i128_pow ... ok -test integers::i128::test_i128_ne ... ok -test integers::i128::test_i128_neg ... ok -test integers::i128::test_i128_le ... ok -test integers::i16::test_i16_console_assert ... ok -test integers::i16::test_i16_add ... ok -test integers::i128::test_i128_ternary ... ok -test integers::i16::test_i16_eq ... ok -test core::packages::unstable::blake2s::test_blake2s_input ... ok -test core::packages::unstable::blake2s::test_blake2s_random ... ok -test integers::i16::test_i16_max ... ok -test integers::i16::test_i16_max_fail ... ok -test integers::i16::test_i16_min ... ok -test integers::i16::test_i16_ge ... ok -test integers::i16::test_i16_mul ... ok -test integers::i16::test_i16_min_fail ... ok -test integers::i16::test_i16_le ... ok -test integers::i16::test_i16_gt ... ok -test integers::i16::test_i16_neg_max_fail ... ok -test integers::i16::test_i16_pow ... ok -test integers::i16::test_i16_neg_zero ... ok -test integers::i16::test_i16_neg ... ok -test integers::i16::test_i16_ternary ... ok -test integers::i16::test_i16_ne ... ok -test integers::i16::test_i16_lt ... ok -test integers::i16::test_i16_sub ... ok -test integers::i128::test_i128_lt ... ok -test integers::i32::test_i32_console_assert ... ok -test integers::i32::test_i32_add ... ok -test integers::i32::test_i32_eq ... ok -test integers::i32::test_i32_max ... ok -test integers::i32::test_i32_max_fail ... ok -test integers::i32::test_i32_min ... ok -test integers::i32::test_i32_min_fail ... ok -test integers::i32::test_i32_mul ... ok -test integers::i32::test_i32_ne ... ok -test integers::i32::test_i32_ge ... ok -test integers::i32::test_i32_neg_max_fail ... ok -test integers::i32::test_i32_neg_zero ... ok -test integers::i32::test_i32_pow ... ok -test integers::i32::test_i32_gt ... ok -test integers::i32::test_i32_le ... ok -test integers::i32::test_i32_lt ... ok -test integers::i128::test_i128_sub ... ok -test integers::i64::test_i64_div ... ignored -test integers::i32::test_i32_ternary ... ok -test integers::i32::test_i32_neg ... ok -test integers::i32::test_i32_sub ... ok -test integers::i64::test_i64_add ... ok -test integers::i64::test_i64_console_assert ... ok -test integers::i64::test_i64_max ... ok -test integers::i64::test_i64_max_fail ... ok -test integers::i64::test_i64_min ... ok -test integers::i64::test_i64_min_fail ... ok -test integers::i64::test_i64_mul ... ok -test integers::i64::test_i64_eq ... ok -test integers::i64::test_i64_gt ... ok -test integers::i64::test_i64_ge ... ok -test integers::i64::test_i64_neg_zero ... ok -test integers::i64::test_i64_pow ... ok -test integers::i64::test_i64_neg_max_fail ... ok -test integers::i64::test_i64_ne ... ok -test integers::i64::test_i64_neg ... ok -test integers::i8::test_i8_console_assert ... ok -test integers::i8::test_i8_add ... ok -test integers::i64::test_i64_ternary ... ok -test integers::i64::test_i64_le ... ok -test integers::i8::test_i8_eq ... ok -test integers::i8::test_i8_ge ... ok -test integers::i8::test_i8_gt ... ok -test integers::i8::test_i8_max ... ok -test integers::i64::test_i64_lt ... ok -test integers::i8::test_i8_max_fail ... ok -test integers::i8::test_i8_min ... ok -test integers::i8::test_i8_min_fail ... ok -test integers::i8::test_i8_le ... ok -test integers::i8::test_i8_mul ... ok -test integers::i8::test_i8_neg_max_fail ... ok -test integers::i8::test_i8_neg_zero ... ok -test integers::i8::test_i8_lt ... ok -test integers::i8::test_i8_pow ... ok -test integers::i8::test_i8_ternary ... ok -test integers::i8::test_i8_neg ... ok -test integers::i8::test_i8_ne ... ok -test integers::i8::test_i8_sub ... ok -test integers::i64::test_i64_sub ... ok -test integers::u128::test_u128_add ... ok -test integers::u128::test_u128_console_assert ... ok -test integers::u128::test_u128_eq ... ok -test integers::i8::test_i8_div ... ok -test integers::u128::test_u128_max ... ok -test integers::u128::test_u128_max_fail ... ok -test integers::u128::test_u128_min ... ok -test integers::u128::test_u128_min_fail ... ok -test integers::u128::test_u128_mul ... ok -test integers::u128::test_u128_ge ... ok -test integers::u128::test_u128_pow ... ok -test integers::u128::test_u128_gt ... ok -test integers::u128::test_u128_ternary ... ok -test integers::u16::test_u16_add ... ok -test integers::u16::test_u16_console_assert ... ok -test integers::u128::test_u128_sub ... ok -test integers::u16::test_u16_eq ... ok -test integers::u128::test_u128_ne ... ok -test integers::u128::test_u128_lt ... ok -test integers::u128::test_u128_le ... ok -test integers::u16::test_u16_ge ... ok -test integers::u16::test_u16_max ... ok -test integers::u16::test_u16_max_fail ... ok -test integers::u16::test_u16_min ... ok -test integers::u16::test_u16_min_fail ... ok -test integers::u16::test_u16_mul ... ok -test integers::u16::test_u16_ne ... ok -test integers::u16::test_u16_gt ... ok -test integers::u16::test_u16_pow ... ok -test integers::u16::test_u16_le ... ok -test integers::u16::test_u16_ternary ... ok -test integers::u16::test_u16_lt ... ok -test integers::u16::test_u16_sub ... ok -test integers::u32::test_u32_add ... ok -test integers::u16::test_u16_div ... ok -test integers::u32::test_u32_console_assert ... ok -test integers::u32::test_u32_eq ... ok -test integers::u32::test_u32_ge ... ok -test integers::u32::test_u32_max ... ok -test integers::u32::test_u32_max_fail ... ok -test integers::u32::test_u32_min ... ok -test integers::u32::test_u32_min_fail ... ok -test integers::u32::test_u32_mul ... ok -test integers::u32::test_u32_gt ... ok -test integers::u32::test_u32_pow ... ok -test integers::u32::test_u32_le ... ok -test integers::u32::test_u32_lt ... ok -test integers::u32::test_u32_ternary ... ok -test integers::u32::test_u32_sub ... ok -test integers::u32::test_u32_ne ... ok -test integers::u64::test_u64_add ... ok -test integers::u64::test_u64_console_assert ... ok -test integers::u64::test_u64_eq ... ok -test integers::u64::test_u64_ge ... ok -test integers::u64::test_u64_gt ... ok -test integers::u64::test_u64_max ... ok -test integers::u64::test_u64_max_fail ... ok -test integers::u64::test_u64_min ... ok -test integers::u64::test_u64_min_fail ... ok -test integers::u64::test_u64_mul ... ok -test integers::u64::test_u64_le ... ok -test integers::u64::test_u64_pow ... ok -test integers::i16::test_i16_div ... ok -test integers::u64::test_u64_ternary ... ok -test integers::u64::test_u64_sub ... ok -test integers::u8::test_u8_add ... ok -test integers::u8::test_u8_console_assert ... ok -test integers::u64::test_u64_ne ... ok -test integers::u8::test_u8_eq ... ok -test integers::u8::test_u8_ge ... ok -test integers::u8::test_u8_gt ... ok -test integers::u64::test_u64_lt ... ok -test integers::u8::test_u8_max ... ok -test integers::u8::test_u8_max_fail ... ok -test integers::u8::test_u8_min ... ok -test integers::u8::test_u8_div ... ok -test integers::u8::test_u8_min_fail ... ok -test integers::u8::test_u8_mul ... ok -test integers::u8::test_u8_pow ... ok -test integers::u8::test_u8_sub ... ok -test integers::u8::test_u8_ternary ... ok -test mutability::test_array ... ok -test mutability::test_array_mut ... FAILED -test mutability::test_array_splice_mut ... ok -test mutability::test_array_tuple_mut ... FAILED -test mutability::test_circuit ... ok -test mutability::test_circuit_function_mut ... ok -test mutability::test_circuit_mut ... FAILED -test mutability::test_circuit_static_function_mut ... ok -test mutability::test_circuit_variable_mut ... FAILED -test mutability::test_const_fail ... ok -test mutability::test_function_input ... ok -test mutability::test_function_input_mut ... ok -test mutability::test_let ... ok -test mutability::test_let_mut ... FAILED -test mutability::test_let_mut_nested ... ok -test mutability::test_swap ... ok -test integers::u8::test_u8_ne ... ok -test statements::conditional::test_chain ... FAILED -test integers::u8::test_u8_le ... ok -test integers::u8::test_u8_lt ... ok -test statements::conditional::test_assert ... ok -test statements::conditional::test_mutate ... FAILED -test statements::conditional::test_nested ... FAILED -test statements::test_block ... FAILED -test statements::test_iteration_input ... ok -test statements::test_iteration_basic ... ok -test statements::conditional::test_multiple_returns ... ok -test syntax::identifiers::test_address_name_fail ... ok -test statements::test_num_returns_fail ... ok -test syntax::identifiers::test_console_name_fail ... ok -test statements::test_ternary_basic ... ok -test syntax::identifiers::test_i8_name_fail ... ok -test syntax::identifiers::test_field_name_fail ... ok -test syntax::identifiers::test_input_name_fail ... ok -test syntax::identifiers::test_self_keyword_name_fail ... ok -test syntax::identifiers::test_group_name_fail ... ok -test syntax::identifiers::test_self_type_name_fail ... ok -test syntax::identifiers::test_u8_name_fail ... ok -test syntax::input_syntax_error ... ok -test syntax::test_semicolon ... ignored -test syntax::test_compare_mismatched_types ... ok -test syntax::identifiers::test_true_name_fail ... ok -test syntax::test_undefined ... ok -test tuples::test_function ... ok -test tuples::test_function_typed ... ok -test tuples::test_function_multiple ... ok -test tuples::test_multiple ... ok -test tuples::test_nested_access ... ok -test tuples::test_nested_typed ... ok -test tuples::test_multiple_typed ... ok -test tuples::test_tuple_access ... ok -test tuples::test_nested ... ok -test tuples::test_tuple_basic ... ok -test tuples::test_tuple_typed ... ok -test statements::conditional::test_for_loop ... ok -test integers::u32::test_u32_div ... ok -test integers::u64::test_u64_div ... ok -test integers::i32::test_i32_div ... ok -test integers::u128::test_u128_div ... ok - -failures: - ----- circuits::test_mutate_self_variable_conditional stdout ---- -thread 'circuits::test_mutate_self_variable_conditional' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 12, line_stop: 12, start: 13, end: 26, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/circuits/mod.rs:164:49 -note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace - ----- circuits::test_mutate_variable stdout ---- -thread 'circuits::test_mutate_variable' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 10, line_stop: 10, start: 5, end: 14, text: None, message: "unexpected type, expected: \'u8\', received: \'bool\'" }))', compiler/tests/circuits/mod.rs:204:49 - ----- function::test_iteration_repeated stdout ---- -thread 'function::test_iteration_repeated' panicked at 'tried to create object at existing path: block 11:17/function call iteration 12:17/block 1:29/for loop iteration 0 4:5/block 4:20/enforce 0 + 1 5:9', /home/gluax/.cargo/registry/src/github.com-1ecc6299db9ec823/snarkvm-r1cs-0.2.0/src/test_constraint_system.rs:282:17 - ----- function::test_value_unchanged stdout ---- -thread 'function::test_value_unchanged' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 11, line_stop: 11, start: 5, end: 10, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/function/mod.rs:142:49 - ----- mutability::test_array_mut stdout ---- -thread 'mutability::test_array_mut' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 4, line_stop: 4, start: 5, end: 13, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/mutability/mod.rs:63:49 - ----- mutability::test_array_tuple_mut stdout ---- -thread 'mutability::test_array_tuple_mut' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 4, line_stop: 4, start: 5, end: 21, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/mutability/mod.rs:71:40 - ----- mutability::test_circuit_mut stdout ---- -thread 'mutability::test_circuit_mut' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 8, line_stop: 8, start: 5, end: 12, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/mutability/mod.rs:95:49 - ----- mutability::test_circuit_variable_mut stdout ---- -thread 'mutability::test_circuit_variable_mut' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 8, line_stop: 8, start: 5, end: 12, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/mutability/mod.rs:103:49 - ----- mutability::test_let_mut stdout ---- -thread 'mutability::test_let_mut' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 4, line_stop: 4, start: 5, end: 10, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/mutability/mod.rs:31:49 - ----- statements::conditional::test_chain stdout ---- -thread 'statements::conditional::test_chain' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 5, line_stop: 5, start: 9, end: 14, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/statements/conditional/mod.rs:110:57 - ----- statements::conditional::test_mutate stdout ---- -thread 'statements::conditional::test_mutate' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 5, line_stop: 5, start: 9, end: 14, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/statements/conditional/mod.rs:64:60 - ----- statements::conditional::test_nested stdout ---- -thread 'statements::conditional::test_nested' panicked at 'tried to create object at existing path: block 1:41/block 4:10/enforce 0 + 1 5:9', /home/gluax/.cargo/registry/src/github.com-1ecc6299db9ec823/snarkvm-r1cs-0.2.0/src/test_constraint_system.rs:282:17 - ----- statements::test_block stdout ---- -thread 'statements::test_block' panicked at 'called `Result::unwrap()` on an `Err` value: AsgConvertError(Error(FormattedError { path: None, line_start: 5, line_stop: 5, start: 9, end: 17, text: None, message: "unexpected type, expected: \'u32\', received: \'bool\'" }))', compiler/tests/statements/mod.rs:71:40 - - -failures: - circuits::test_mutate_self_variable_conditional - circuits::test_mutate_variable - function::test_iteration_repeated - function::test_value_unchanged - mutability::test_array_mut - mutability::test_array_tuple_mut - mutability::test_circuit_mut - mutability::test_circuit_variable_mut - mutability::test_let_mut - statements::conditional::test_chain - statements::conditional::test_mutate - statements::conditional::test_nested - statements::test_block - -test result: FAILED. 405 passed; 13 failed; 17 ignored; 0 measured; 0 filtered out; finished in 32.91s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 53 tests -test signed_integer::i128::test_int128_add_constants ... ok -test signed_integer::i128::test_int128_sub_constants ... ok -test signed_integer::i128::test_int128_add ... ok -test signed_integer::i16::test_int16_add_constants ... ok -test signed_integer::i16::test_int16_constant_and_alloc ... ok -test signed_integer::i128::test_int128_constant_and_alloc ... ok -test signed_integer::i128::test_int128_sub ... ok -test signed_integer::i16::test_int16_add ... ok -test signed_integer::i16::test_int16_div ... ok -test signed_integer::i16::test_int16_div_constants ... ok -test signed_integer::i16::test_int16_mul_constants ... ok -test signed_integer::i128::test_int128_div_constants ... ok -test signed_integer::i128::test_int128_mul_constants ... ok -test signed_integer::i16::test_int16_sub_constants ... ok -test signed_integer::i32::test_int32_add_constants ... ok -test signed_integer::i32::test_int32_constant_and_alloc ... ok -test signed_integer::i16::test_int16_sub ... ok -test signed_integer::i16::test_int16_pow_constants ... ok -test signed_integer::i32::test_int32_div_constants ... ok -test signed_integer::i16::test_int16_mul ... ok -test signed_integer::i32::test_int32_pow ... ignored -test signed_integer::i32::test_int32_pow_constants ... ignored -test signed_integer::i32::test_int32_add ... ok -test signed_integer::i32::test_int32_mul_constants ... ok -test signed_integer::i32::test_int32_sub_constants ... ok -test signed_integer::i64::test_int64_add_constants ... ok -test signed_integer::i16::test_int16_pow ... ok -test signed_integer::i128::test_int128_div ... test signed_integer::i128::test_int128_div has been running for over 60 seconds -test signed_integer::i128::test_int128_mul ... test signed_integer::i128::test_int128_mul has been running for over 60 seconds -test signed_integer::i64::test_int64_constant_and_alloc ... ok -test signed_integer::i32::test_int32_div ... ok -test signed_integer::i64::test_int64_div_constants ... ok -test signed_integer::i32::test_int32_mul ... ok -test signed_integer::i64::test_int64_pow ... ignored -test signed_integer::i64::test_int64_pow_constants ... ignored -test signed_integer::i32::test_int32_sub ... ok -test signed_integer::i64::test_int64_mul_constants ... ok -test signed_integer::i64::test_int64_sub_constants ... ok -test signed_integer::i8::test_int8_add_constants ... ok -test signed_integer::i8::test_int8_constant_and_alloc ... ok -test signed_integer::i8::test_int8_add ... ok -test signed_integer::i8::test_int8_div_constants ... ok -test signed_integer::i64::test_int64_add ... ok -test signed_integer::i128::test_int128_mul ... ok -test signed_integer::i8::test_int8_mul_constants ... ok -test signed_integer::i8::test_int8_mul ... ok -test signed_integer::i64::test_int64_div ... ok -test signed_integer::i8::test_int8_sub_constants ... ok -test signed_integer::i8::test_int8_sub ... ok -test signed_integer::i8::test_int8_div ... ok -test signed_integer::i128::test_int128_div ... ok -test signed_integer::i8::test_int8_pow ... ok -test signed_integer::i64::test_int64_mul ... ok -test signed_integer::i8::test_int8_pow_constants ... ok -test signed_integer::i64::test_int64_sub ... ok - -test result: ok. 49 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 121.63s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 8 tests -test tests::test_logout ... ok -test tests::test_pedersen_hash ... ok -test tests::build_pedersen_hash ... ok -test tests::login_incorrect_credentials_or_token ... ok -test tests::setup_pedersen_hash ... ok -test tests::leo_update_and_update_automatic ... ok -test tests::run_pedersen_hash ... ok -test tests::prove_pedersen_hash ... ok - -test result: ok. 8 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 1.38s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 1 test -test package::tests::test_is_package_name_valid ... ok - -test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 11 tests -test initialize::initialize::initialize_fails_with_invalid_package_names ... ignored -test manifest::manifest::test_manifest_no_refactors ... ignored -test manifest::manifest::test_manifest_refactor_project ... ignored -test manifest::manifest::test_manifest_refactor_remote ... ignored -test initialize::initialize::initialize_fails_with_existing_library_file ... ok -test initialize::initialize::initialize_fails_with_existing_main_file ... ok -test initialize::initialize::initialize_fails_with_existing_input_file ... ok -test initialize::initialize::initialize_fails_with_existing_state_file ... ok -test initialize::initialize::initialize_fails_with_existing_manifest ... ok -test initialize::initialize::initialize_valid_package ... ok -test manifest::manifest::test_manifest_refactors ... ok - -test result: ok. 7 passed; 0 failed; 4 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 4 tests -test tokenizer::tests::test_spans ... ok -test tokenizer::tests::test_tokenizer ... ok -test test::parser_fail_tests ... ok -test test::parser_pass_tests ... ok - -test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s - - -running 4 tests -test serialization::json::test_generic_parser_error ... ok -test serialization::json::test_deserialize ... ok -test serialization::json::test_serialize ... ok -test serialization::json::test_serialize_deserialize_serialize ... ok - -test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 3 tests -test test_verify_local_data_commitment::test_generate_values_from_dpc ... ignored -test test_verify_local_data_commitment::test_verify_local_data_commitment_from_file ... ignored -test test_verify_record_commitment::test_verify_record_from_file ... ignored - -test result: ok. 0 passed; 0 failed; 3 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 2 tests -test test_generate_values_from_dpc ... ignored -test test_verify_local_data_commitment_from_file ... ignored - -test result: ok. 0 passed; 0 failed; 2 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 1 test -test test_verify_record_from_file ... ignored - -test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - - -running 0 tests - -test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s - From b50919085b9700d43b884d803e278bd40307aa06 Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 18 Mar 2021 15:19:07 -0400 Subject: [PATCH 18/40] deprecate let mut, undeprecate const, let is now mutable by default --- HEAD | 0 asg/tests/fail/address/implicit_invalid.leo | 2 +- .../fail/array/multi_fail_initializer.leo | 2 +- asg/tests/fail/array/multi_fail_inline.leo | 2 +- .../fail/array/multi_initializer_fail.leo | 2 +- .../fail/array/nested_3x2_value_fail.leo | 2 +- asg/tests/fail/array/tuple_3x2_value_fail.leo | 2 +- asg/tests/fail/array/type_fail.leo | 2 +- .../type_nested_value_nested_3x2_fail.leo | 2 +- .../type_nested_value_nested_4x3x2_fail.leo | 2 +- .../type_nested_value_tuple_3x2_fail.leo | 2 +- .../type_nested_value_tuple_4x3x2_fail.leo | 2 +- .../type_tuple_value_nested_3x2_fail.leo | 2 +- .../type_tuple_value_nested_3x2_swap_fail.leo | 4 +- .../type_tuple_value_nested_4x3x2_fail.leo | 2 +- .../array/type_tuple_value_tuple_3x2_fail.leo | 2 +- .../type_tuple_value_tuple_3x2_swap_fail.leo | 4 +- .../type_tuple_value_tuple_4x3x2_fail.leo | 2 +- asg/tests/fail/boolean/true_and_u32.leo | 2 +- asg/tests/fail/boolean/true_or_u32.leo | 2 +- asg/tests/fail/circuits/inline_fail.leo | 2 +- asg/tests/fail/circuits/inline_undefined.leo | 2 +- .../fail/circuits/member_function_fail.leo | 4 +- .../fail/circuits/member_function_invalid.leo | 4 +- .../member_static_function_invalid.leo | 2 +- .../member_static_function_undefined.leo | 2 +- .../fail/circuits/member_variable_fail.leo | 4 +- asg/tests/fail/circuits/mod.rs | 2 +- asg/tests/fail/circuits/mut_function_fail.leo | 2 +- .../fail/circuits/mut_self_function_fail.leo | 2 +- .../mut_self_static_function_fail.leo | 2 +- .../fail/circuits/mut_self_variable_fail.leo | 2 +- .../circuits/mut_static_function_fail.leo | 2 +- asg/tests/fail/circuits/mut_variable_fail.leo | 2 +- .../fail/circuits/self_member_invalid.leo | 4 +- .../fail/circuits/self_member_undefined.leo | 4 +- asg/tests/fail/function/array_input.leo | 2 +- .../multiple_returns_fail_conditional.leo | 4 +- .../function/return_array_nested_fail.leo | 2 +- .../fail/function/return_array_tuple_fail.leo | 2 +- asg/tests/fail/function/scope_fail.leo | 4 +- asg/tests/fail/group/both_sign_high.leo | 2 +- asg/tests/fail/group/both_sign_inferred.leo | 2 +- asg/tests/fail/group/both_sign_low.leo | 2 +- asg/tests/fail/integers/i128/max_fail.leo | 2 +- asg/tests/fail/integers/i128/min_fail.leo | 2 +- asg/tests/fail/integers/i128/negate_min.leo | 4 +- asg/tests/fail/integers/i16/max_fail.leo | 2 +- asg/tests/fail/integers/i16/min_fail.leo | 2 +- asg/tests/fail/integers/i16/negate_min.leo | 4 +- asg/tests/fail/integers/i32/max_fail.leo | 2 +- asg/tests/fail/integers/i32/min_fail.leo | 2 +- asg/tests/fail/integers/i32/negate_min.leo | 4 +- asg/tests/fail/integers/i64/max_fail.leo | 2 +- asg/tests/fail/integers/i64/min_fail.leo | 2 +- asg/tests/fail/integers/i64/negate_min.leo | 4 +- asg/tests/fail/integers/i8/max_fail.leo | 2 +- asg/tests/fail/integers/i8/min_fail.leo | 2 +- asg/tests/fail/integers/i8/negate_min.leo | 4 +- asg/tests/fail/integers/u128/max_fail.leo | 2 +- asg/tests/fail/integers/u128/min_fail.leo | 2 +- asg/tests/fail/integers/u16/max_fail.leo | 2 +- asg/tests/fail/integers/u16/min_fail.leo | 2 +- asg/tests/fail/integers/u32/max_fail.leo | 2 +- asg/tests/fail/integers/u32/min_fail.leo | 2 +- asg/tests/fail/integers/u64/max_fail.leo | 2 +- asg/tests/fail/integers/u64/min_fail.leo | 2 +- asg/tests/fail/integers/u8/max_fail.leo | 2 +- asg/tests/fail/integers/u8/min_fail.leo | 2 +- asg/tests/fail/mutability/array.leo | 2 +- asg/tests/fail/mutability/circuit.leo | 2 +- .../fail/mutability/circuit_function_mut.leo | 2 +- .../circuit_static_function_mut.leo | 2 +- asg/tests/fail/mutability/const.leo | 2 +- asg/tests/fail/mutability/let.leo | 2 +- .../statements/const_declaration_fail.leo | 3 - .../statements/let_mut_declaration_fail.leo | 3 + asg/tests/fail/statements/mod.rs | 4 +- .../pass/address/console_assert_pass.leo | 4 +- asg/tests/pass/address/implicit_invalid.leo | 2 +- asg/tests/pass/address/implicit_valid.leo | 2 +- asg/tests/pass/address/input.leo | 2 +- asg/tests/pass/address/ternary.leo | 6 +- asg/tests/pass/address/valid.leo | 2 +- asg/tests/pass/array/implicit.leo | 8 +- asg/tests/pass/array/index_u8.leo | 4 +- asg/tests/pass/array/multi_initializer.leo | 4 +- asg/tests/pass/array/nested_3x2_value.leo | 4 +- asg/tests/pass/array/slice.leo | 2 +- asg/tests/pass/array/slice_i8.leo | 2 +- asg/tests/pass/array/slice_lower.leo | 6 +- asg/tests/pass/array/spread.leo | 4 +- asg/tests/pass/array/tuple_3x2_value.leo | 4 +- asg/tests/pass/array/type_input_3x2.leo | 2 +- asg/tests/pass/array/type_input_4x3x2.leo | 2 +- .../array/type_nested_value_nested_3x2.leo | 4 +- .../array/type_nested_value_nested_4x3x2.leo | 4 +- .../array/type_nested_value_tuple_3x2.leo | 4 +- .../array/type_nested_value_tuple_4x3x2.leo | 4 +- .../array/type_tuple_value_nested_3x2.leo | 4 +- .../array/type_tuple_value_nested_4x3x2.leo | 4 +- .../pass/array/type_tuple_value_tuple_3x2.leo | 4 +- .../array/type_tuple_value_tuple_4x3x2.leo | 4 +- asg/tests/pass/boolean/all.leo | 6 +- asg/tests/pass/boolean/false_and_false.leo | 2 +- asg/tests/pass/boolean/false_or_false.leo | 2 +- asg/tests/pass/boolean/not_mutable.leo | 4 +- asg/tests/pass/boolean/true_and_false.leo | 2 +- asg/tests/pass/boolean/true_and_true.leo | 2 +- asg/tests/pass/boolean/true_or_false.leo | 2 +- asg/tests/pass/boolean/true_or_true.leo | 2 +- ...define_circuit_inside_circuit_function.leo | 4 +- asg/tests/pass/circuits/inline.leo | 2 +- asg/tests/pass/circuits/member_function.leo | 2 +- .../pass/circuits/member_function_nested.leo | 4 +- .../pass/circuits/member_static_function.leo | 2 +- asg/tests/pass/circuits/member_variable.leo | 2 +- .../circuits/member_variable_and_function.leo | 4 +- asg/tests/pass/circuits/mod.rs | 2 +- asg/tests/pass/circuits/mut_self_variable.leo | 2 +- .../mut_self_variable_conditional.leo | 2 +- asg/tests/pass/circuits/mut_variable.leo | 2 +- asg/tests/pass/circuits/pedersen_mock.leo | 12 +- asg/tests/pass/circuits/self_circuit.leo | 2 +- asg/tests/pass/circuits/self_member.leo | 4 +- asg/tests/pass/core/blake2s_random.leo | 2 +- asg/tests/pass/core/unstable_blake2s.leo | 6 +- asg/tests/pass/field/ternary.leo | 2 +- asg/tests/pass/form_ast.rs | 4 +- asg/tests/pass/function/array_input.leo | 2 +- asg/tests/pass/function/iteration.leo | 2 +- .../pass/function/iteration_repeated.leo | 4 +- asg/tests/pass/function/mod.rs | 10 +- asg/tests/pass/function/multiple_returns.leo | 2 +- asg/tests/pass/function/repeated.leo | 2 +- .../function/return_array_nested_pass.leo | 4 +- .../pass/function/return_array_tuple_pass.leo | 4 +- asg/tests/pass/function/return_tuple.leo | 6 +- .../function/return_tuple_conditional.leo | 2 +- asg/tests/pass/function/value_unchanged.leo | 2 +- asg/tests/pass/group/both_sign_high.leo | 2 +- asg/tests/pass/group/both_sign_inferred.leo | 2 +- asg/tests/pass/group/both_sign_low.leo | 2 +- asg/tests/pass/group/one.leo | 2 +- asg/tests/pass/group/point.leo | 2 +- asg/tests/pass/group/point_input.leo | 2 +- asg/tests/pass/group/ternary.leo | 2 +- asg/tests/pass/group/x_and_y.leo | 2 +- asg/tests/pass/group/x_sign_high.leo | 2 +- asg/tests/pass/group/x_sign_inferred.leo | 2 +- asg/tests/pass/group/x_sign_low.leo | 2 +- asg/tests/pass/group/y_sign_high.leo | 2 +- asg/tests/pass/group/y_sign_inferred.leo | 2 +- asg/tests/pass/group/y_sign_low.leo | 2 +- asg/tests/pass/group/zero.leo | 2 +- asg/tests/pass/import/many_import.leo | 14 +- asg/tests/pass/import/many_import_star.leo | 12 +- asg/tests/pass/import/multiple.leo | 2 +- asg/tests/pass/import/star.leo | 2 +- .../input_files/program_state/access_all.leo | 2 +- asg/tests/pass/integers/i128/max.leo | 2 +- asg/tests/pass/integers/i128/min.leo | 2 +- asg/tests/pass/integers/i128/negate_zero.leo | 2 +- asg/tests/pass/integers/i128/ternary.leo | 2 +- asg/tests/pass/integers/i16/max.leo | 2 +- asg/tests/pass/integers/i16/min.leo | 2 +- asg/tests/pass/integers/i16/negate_zero.leo | 2 +- asg/tests/pass/integers/i16/ternary.leo | 2 +- asg/tests/pass/integers/i32/max.leo | 2 +- asg/tests/pass/integers/i32/min.leo | 2 +- asg/tests/pass/integers/i32/negate_zero.leo | 2 +- asg/tests/pass/integers/i32/ternary.leo | 2 +- asg/tests/pass/integers/i64/max.leo | 2 +- asg/tests/pass/integers/i64/min.leo | 2 +- asg/tests/pass/integers/i64/negate_zero.leo | 2 +- asg/tests/pass/integers/i64/ternary.leo | 2 +- asg/tests/pass/integers/i8/max.leo | 2 +- asg/tests/pass/integers/i8/min.leo | 2 +- asg/tests/pass/integers/i8/negate_zero.leo | 2 +- asg/tests/pass/integers/i8/ternary.leo | 2 +- asg/tests/pass/integers/u128/max.leo | 2 +- asg/tests/pass/integers/u128/min.leo | 2 +- asg/tests/pass/integers/u128/ternary.leo | 2 +- asg/tests/pass/integers/u16/max.leo | 2 +- asg/tests/pass/integers/u16/min.leo | 2 +- asg/tests/pass/integers/u16/ternary.leo | 2 +- asg/tests/pass/integers/u32/max.leo | 2 +- asg/tests/pass/integers/u32/min.leo | 2 +- asg/tests/pass/integers/u32/ternary.leo | 2 +- asg/tests/pass/integers/u64/max.leo | 2 +- asg/tests/pass/integers/u64/min.leo | 2 +- asg/tests/pass/integers/u64/ternary.leo | 2 +- asg/tests/pass/integers/u8/max.leo | 2 +- asg/tests/pass/integers/u8/min.leo | 2 +- asg/tests/pass/integers/u8/ternary.leo | 2 +- asg/tests/pass/mutability/array_mut.leo | 2 +- .../pass/mutability/array_splice_mut.leo | 2 +- asg/tests/pass/mutability/array_tuple_mut.leo | 2 +- asg/tests/pass/mutability/circuit_mut.leo | 2 +- .../pass/mutability/circuit_variable_mut.leo | 2 +- asg/tests/pass/mutability/let_mut.leo | 2 +- asg/tests/pass/mutability/let_mut_nested.leo | 6 +- asg/tests/pass/mutability/swap.leo | 8 +- asg/tests/pass/statements/block.leo | 2 +- .../pass/statements/conditional/chain.leo | 2 +- .../pass/statements/conditional/for_loop.leo | 4 +- .../pass/statements/conditional/mutate.leo | 2 +- .../pass/statements/conditional/nested.leo | 2 +- asg/tests/pass/statements/iteration_basic.leo | 2 +- asg/tests/pass/statements/ternary_basic.leo | 4 +- asg/tests/pass/tuples/access.leo | 2 +- asg/tests/pass/tuples/basic.leo | 2 +- asg/tests/pass/tuples/function.leo | 2 +- asg/tests/pass/tuples/function_multiple.leo | 2 +- asg/tests/pass/tuples/function_typed.leo | 2 +- asg/tests/pass/tuples/multiple.leo | 2 +- asg/tests/pass/tuples/multiple_typed.leo | 2 +- asg/tests/pass/tuples/nested.leo | 4 +- asg/tests/pass/tuples/nested_access.leo | 4 +- asg/tests/pass/tuples/nested_typed.leo | 4 +- asg/tests/pass/tuples/typed.leo | 2 +- .../tests/address/console_assert_fail.leo | 4 +- .../tests/address/console_assert_pass.leo | 4 +- compiler/tests/address/empty.leo | 2 +- compiler/tests/address/implicit_invalid.leo | 2 +- compiler/tests/address/implicit_valid.leo | 2 +- compiler/tests/address/input.leo | 2 +- compiler/tests/address/invalid_length.leo | 2 +- compiler/tests/address/invalid_prefix.leo | 2 +- compiler/tests/address/ternary.leo | 6 +- compiler/tests/address/valid.leo | 2 +- compiler/tests/array/input/inline_fail.leo | 2 +- .../tests/array/multi_fail_initializer.leo | 2 +- compiler/tests/array/multi_fail_inline.leo | 2 +- compiler/tests/array/multi_initializer.leo | 4 +- .../tests/array/multi_initializer_fail.leo | 2 +- compiler/tests/array/nested.leo | 4 +- compiler/tests/array/nested_3x2_value.leo | 4 +- .../tests/array/nested_3x2_value_fail.leo | 2 +- compiler/tests/array/slice.leo | 2 +- compiler/tests/array/slice_lower.leo | 6 +- compiler/tests/array/spread.leo | 4 +- compiler/tests/array/tuple_3x2_value.leo | 4 +- compiler/tests/array/tuple_3x2_value_fail.leo | 2 +- compiler/tests/array/type_fail.leo | 2 +- compiler/tests/array/type_input_3x2.leo | 2 +- compiler/tests/array/type_input_4x3x2.leo | 2 +- .../array/type_nested_value_nested_3x2.leo | 4 +- .../type_nested_value_nested_3x2_fail.leo | 2 +- .../array/type_nested_value_nested_4x3x2.leo | 4 +- .../type_nested_value_nested_4x3x2_fail.leo | 2 +- .../array/type_nested_value_tuple_3x2.leo | 4 +- .../type_nested_value_tuple_3x2_fail.leo | 2 +- .../array/type_nested_value_tuple_4x3x2.leo | 4 +- .../type_nested_value_tuple_4x3x2_fail.leo | 2 +- .../array/type_tuple_value_nested_3x2.leo | 4 +- .../type_tuple_value_nested_3x2_fail.leo | 2 +- .../array/type_tuple_value_nested_4x3x2.leo | 4 +- .../type_tuple_value_nested_4x3x2_fail.leo | 2 +- .../array/type_tuple_value_tuple_3x2.leo | 4 +- .../array/type_tuple_value_tuple_3x2_fail.leo | 2 +- .../array/type_tuple_value_tuple_4x3x2.leo | 4 +- .../type_tuple_value_tuple_4x3x2_fail.leo | 2 +- compiler/tests/array/variable_slice_fail.leo | 4 +- compiler/tests/boolean/all.leo | 6 +- compiler/tests/boolean/conditional_mut.leo | 4 +- compiler/tests/boolean/false_and_false.leo | 2 +- compiler/tests/boolean/false_or_false.leo | 2 +- compiler/tests/boolean/not_mutable.leo | 4 +- compiler/tests/boolean/true_and_false.leo | 2 +- compiler/tests/boolean/true_and_true.leo | 2 +- compiler/tests/boolean/true_and_u32.leo | 2 +- compiler/tests/boolean/true_or_false.leo | 2 +- compiler/tests/boolean/true_or_true.leo | 2 +- compiler/tests/boolean/true_or_u32.leo | 2 +- ...define_circuit_inside_circuit_function.leo | 4 +- .../tests/circuits/duplicate_name_context.leo | 6 +- compiler/tests/circuits/inline.leo | 2 +- compiler/tests/circuits/inline_fail.leo | 2 +- .../tests/circuits/inline_member_fail.leo | 4 +- .../tests/circuits/inline_member_pass.leo | 6 +- compiler/tests/circuits/inline_undefined.leo | 2 +- compiler/tests/circuits/member_function.leo | 2 +- .../tests/circuits/member_function_fail.leo | 4 +- .../circuits/member_function_invalid.leo | 4 +- .../tests/circuits/member_function_nested.leo | 4 +- .../tests/circuits/member_static_function.leo | 2 +- .../member_static_function_invalid.leo | 2 +- .../member_static_function_undefined.leo | 2 +- compiler/tests/circuits/member_variable.leo | 2 +- .../circuits/member_variable_and_function.leo | 4 +- .../tests/circuits/member_variable_fail.leo | 4 +- compiler/tests/circuits/mut_function_fail.leo | 2 +- .../tests/circuits/mut_self_function_fail.leo | 2 +- .../mut_self_static_function_fail.leo | 2 +- compiler/tests/circuits/mut_self_variable.leo | 2 +- .../circuits/mut_self_variable_branch.leo | 2 +- .../mut_self_variable_conditional.leo | 2 +- .../tests/circuits/mut_self_variable_fail.leo | 2 +- .../circuits/mut_static_function_fail.leo | 2 +- compiler/tests/circuits/mut_variable.leo | 2 +- compiler/tests/circuits/mut_variable_fail.leo | 2 +- compiler/tests/circuits/pedersen_mock.leo | 12 +- compiler/tests/circuits/self_circuit.leo | 2 +- compiler/tests/circuits/self_member.leo | 4 +- .../tests/circuits/self_member_invalid.leo | 4 +- .../tests/circuits/self_member_undefined.leo | 4 +- compiler/tests/compiler/main.leo | 2 +- .../blake2s/arguments_length_fail.leo | 4 +- .../unstable/blake2s/arguments_type_fail.leo | 6 +- .../unstable/blake2s/blake2s_random.leo | 2 +- compiler/tests/core/unstable_blake2s.leo | 6 +- compiler/tests/field/field.leo | 4 +- compiler/tests/field/ternary.leo | 2 +- compiler/tests/function/array_input.leo | 2 +- .../function/array_params_direct_call.leo | 2 +- compiler/tests/function/iteration.leo | 2 +- .../tests/function/iteration_repeated.leo | 4 +- compiler/tests/function/multiple_returns.leo | 2 +- .../multiple_returns_fail_conditional.leo | 4 +- compiler/tests/function/repeated.leo | 2 +- .../function/return_array_nested_fail.leo | 2 +- .../function/return_array_nested_pass.leo | 4 +- .../function/return_array_tuple_fail.leo | 2 +- .../function/return_array_tuple_pass.leo | 4 +- compiler/tests/function/return_tuple.leo | 6 +- .../function/return_tuple_conditional.leo | 2 +- compiler/tests/function/scope_fail.leo | 4 +- compiler/tests/function/value_unchanged.leo | 2 +- compiler/tests/group/both_sign_high.leo | 2 +- compiler/tests/group/both_sign_inferred.leo | 2 +- compiler/tests/group/both_sign_low.leo | 2 +- compiler/tests/group/one.leo | 2 +- compiler/tests/group/point.leo | 2 +- compiler/tests/group/point_input.leo | 2 +- .../tests/group/positive_and_negative.leo | 12 +- compiler/tests/group/ternary.leo | 2 +- compiler/tests/group/x_and_y.leo | 2 +- compiler/tests/group/x_sign_high.leo | 2 +- compiler/tests/group/x_sign_inferred.leo | 2 +- compiler/tests/group/x_sign_low.leo | 2 +- compiler/tests/group/y_sign_high.leo | 2 +- compiler/tests/group/y_sign_inferred.leo | 2 +- compiler/tests/group/y_sign_low.leo | 2 +- compiler/tests/group/zero.leo | 2 +- compiler/tests/import/many_import.leo | 14 +- compiler/tests/import/many_import_star.leo | 12 +- compiler/tests/import/multiple.leo | 2 +- compiler/tests/import/star.leo | 2 +- .../main_multi_dimension_array.leo | 2 +- .../input_files/program_state/access_all.leo | 2 +- compiler/tests/integers/i128/max.leo | 2 +- compiler/tests/integers/i128/max_fail.leo | 2 +- compiler/tests/integers/i128/min.leo | 2 +- compiler/tests/integers/i128/min_fail.leo | 2 +- compiler/tests/integers/i128/negate_min.leo | 4 +- compiler/tests/integers/i128/negate_zero.leo | 2 +- compiler/tests/integers/i128/ternary.leo | 2 +- compiler/tests/integers/i16/max.leo | 2 +- compiler/tests/integers/i16/max_fail.leo | 2 +- compiler/tests/integers/i16/min.leo | 2 +- compiler/tests/integers/i16/min_fail.leo | 2 +- compiler/tests/integers/i16/negate_min.leo | 4 +- compiler/tests/integers/i16/negate_zero.leo | 2 +- compiler/tests/integers/i16/ternary.leo | 2 +- compiler/tests/integers/i32/max.leo | 2 +- compiler/tests/integers/i32/max_fail.leo | 2 +- compiler/tests/integers/i32/min.leo | 2 +- compiler/tests/integers/i32/min_fail.leo | 2 +- compiler/tests/integers/i32/negate_min.leo | 4 +- compiler/tests/integers/i32/negate_zero.leo | 2 +- compiler/tests/integers/i32/ternary.leo | 2 +- compiler/tests/integers/i64/max.leo | 2 +- compiler/tests/integers/i64/max_fail.leo | 2 +- compiler/tests/integers/i64/min.leo | 2 +- compiler/tests/integers/i64/min_fail.leo | 2 +- compiler/tests/integers/i64/negate_min.leo | 4 +- compiler/tests/integers/i64/negate_zero.leo | 2 +- compiler/tests/integers/i64/ternary.leo | 2 +- compiler/tests/integers/i8/max.leo | 2 +- compiler/tests/integers/i8/max_fail.leo | 2 +- compiler/tests/integers/i8/min.leo | 2 +- compiler/tests/integers/i8/min_fail.leo | 2 +- compiler/tests/integers/i8/negate_min.leo | 4 +- compiler/tests/integers/i8/negate_zero.leo | 2 +- compiler/tests/integers/i8/ternary.leo | 2 +- compiler/tests/integers/u128/max.leo | 2 +- compiler/tests/integers/u128/max_fail.leo | 2 +- compiler/tests/integers/u128/min.leo | 2 +- compiler/tests/integers/u128/min_fail.leo | 2 +- compiler/tests/integers/u128/ternary.leo | 2 +- compiler/tests/integers/u16/max.leo | 2 +- compiler/tests/integers/u16/max_fail.leo | 2 +- compiler/tests/integers/u16/min.leo | 2 +- compiler/tests/integers/u16/min_fail.leo | 2 +- compiler/tests/integers/u16/ternary.leo | 2 +- compiler/tests/integers/u32/max.leo | 2 +- compiler/tests/integers/u32/max_fail.leo | 2 +- compiler/tests/integers/u32/min.leo | 2 +- compiler/tests/integers/u32/min_fail.leo | 2 +- compiler/tests/integers/u32/ternary.leo | 2 +- compiler/tests/integers/u64/max.leo | 2 +- compiler/tests/integers/u64/max_fail.leo | 2 +- compiler/tests/integers/u64/min.leo | 2 +- compiler/tests/integers/u64/min_fail.leo | 2 +- compiler/tests/integers/u64/ternary.leo | 2 +- compiler/tests/integers/u8/max.leo | 2 +- compiler/tests/integers/u8/max_fail.leo | 2 +- compiler/tests/integers/u8/min.leo | 2 +- compiler/tests/integers/u8/min_fail.leo | 2 +- compiler/tests/integers/u8/ternary.leo | 2 +- compiler/tests/mutability/array.leo | 2 +- compiler/tests/mutability/array_mut.leo | 2 +- .../tests/mutability/array_splice_mut.leo | 2 +- compiler/tests/mutability/array_tuple_mut.leo | 2 +- compiler/tests/mutability/circuit.leo | 2 +- .../tests/mutability/circuit_function_mut.leo | 2 +- compiler/tests/mutability/circuit_mut.leo | 2 +- .../circuit_static_function_mut.leo | 2 +- .../tests/mutability/circuit_variable_mut.leo | 2 +- compiler/tests/mutability/const.leo | 2 +- compiler/tests/mutability/let.leo | 2 +- compiler/tests/mutability/let_mut.leo | 2 +- compiler/tests/mutability/let_mut_nested.leo | 6 +- compiler/tests/mutability/swap.leo | 8 +- compiler/tests/statements/block.leo | 2 +- .../tests/statements/conditional/chain.leo | 2 +- .../tests/statements/conditional/for_loop.leo | 4 +- .../tests/statements/conditional/mutate.leo | 2 +- .../tests/statements/conditional/nested.leo | 2 +- compiler/tests/statements/iteration_basic.leo | 2 +- compiler/tests/statements/ternary_basic.leo | 4 +- .../tests/syntax/compare_mismatched_types.leo | 2 +- .../tests/syntax/identifiers/address_fail.leo | 2 +- .../tests/syntax/identifiers/console_fail.leo | 2 +- .../tests/syntax/identifiers/field_fail.leo | 2 +- .../tests/syntax/identifiers/group_fail.leo | 2 +- compiler/tests/syntax/identifiers/i8_fail.leo | 2 +- .../tests/syntax/identifiers/input_fail.leo | 2 +- .../syntax/identifiers/self_keyword_fail.leo | 2 +- .../syntax/identifiers/self_type_fail.leo | 2 +- .../tests/syntax/identifiers/true_fail.leo | 2 +- compiler/tests/syntax/identifiers/u8_fail.leo | 2 +- compiler/tests/syntax/semicolon.leo | 2 +- compiler/tests/tuples/access.leo | 2 +- compiler/tests/tuples/basic.leo | 2 +- compiler/tests/tuples/function.leo | 2 +- compiler/tests/tuples/function_multiple.leo | 2 +- compiler/tests/tuples/function_typed.leo | 2 +- compiler/tests/tuples/multiple.leo | 2 +- compiler/tests/tuples/multiple_typed.leo | 2 +- compiler/tests/tuples/nested.leo | 4 +- compiler/tests/tuples/nested_access.leo | 4 +- compiler/tests/tuples/nested_typed.leo | 4 +- compiler/tests/tuples/typed.leo | 2 +- examples/hello-world/src/main.leo | 2 +- examples/pedersen-hash/src/main.leo | 8 +- parser/benches/big_circuit.leo | 4 +- parser/benches/big_if_else.leo | 2 +- parser/benches/big_ternary.leo | 2 +- parser/benches/long_array.leo | 4 +- parser/benches/long_expr.leo | 10 +- parser/benches/many_assigns.leo | 768 +++++++++--------- parser/src/errors/deprecated.rs | 4 +- parser/src/parser/statement.rs | 29 +- tests/fail/parse/address/empty.leo | 2 +- tests/fail/parse/address/invalid_length.leo | 2 +- tests/fail/parse/address/invalid_prefix.leo | 2 +- tests/fail/parse/array/type_fail.leo | 2 +- tests/fail/parse/circuits/self_circuit.leo | 2 +- tests/fail/parse/syntax/address_fail.leo | 2 +- tests/fail/parse/syntax/console_fail.leo | 2 +- tests/fail/parse/syntax/field_fail.leo | 2 +- tests/fail/parse/syntax/group_fail.leo | 2 +- tests/fail/parse/syntax/i8_fail.leo | 2 +- tests/fail/parse/syntax/input_fail.leo | 2 +- tests/fail/parse/syntax/self_keyword_fail.leo | 2 +- tests/fail/parse/syntax/self_type_fail.leo | 2 +- tests/fail/parse/syntax/semicolon.leo | 2 +- tests/fail/parse/syntax/true_fail.leo | 2 +- tests/fail/parse/syntax/u8_fail.leo | 2 +- .../parse/address/console_assert_fail.leo | 4 +- .../parse/address/console_assert_pass.leo | 4 +- tests/pass/parse/address/implicit_invalid.leo | 2 +- tests/pass/parse/address/implicit_valid.leo | 2 +- tests/pass/parse/address/input.leo | 2 +- tests/pass/parse/address/ternary.leo | 6 +- tests/pass/parse/address/valid.leo | 2 +- .../parse/array/multi_fail_initializer.leo | 2 +- tests/pass/parse/array/multi_fail_inline.leo | 2 +- tests/pass/parse/array/multi_initializer.leo | 4 +- .../parse/array/multi_initializer_fail.leo | 2 +- tests/pass/parse/array/nested.leo | 4 +- tests/pass/parse/array/nested_3x2_value.leo | 4 +- .../parse/array/nested_3x2_value_fail.leo | 2 +- tests/pass/parse/array/slice.leo | 2 +- tests/pass/parse/array/slice_lower.leo | 6 +- tests/pass/parse/array/spread.leo | 4 +- tests/pass/parse/array/tuple_3x2_value.leo | 4 +- .../pass/parse/array/tuple_3x2_value_fail.leo | 2 +- tests/pass/parse/array/type_input_3x2.leo | 2 +- tests/pass/parse/array/type_input_4x3x2.leo | 2 +- .../array/type_nested_value_nested_3x2.leo | 4 +- .../type_nested_value_nested_3x2_fail.leo | 2 +- .../array/type_nested_value_nested_4x3x2.leo | 4 +- .../type_nested_value_nested_4x3x2_fail.leo | 2 +- .../array/type_nested_value_tuple_3x2.leo | 4 +- .../type_nested_value_tuple_3x2_fail.leo | 2 +- .../array/type_nested_value_tuple_4x3x2.leo | 4 +- .../type_nested_value_tuple_4x3x2_fail.leo | 2 +- .../array/type_tuple_value_nested_3x2.leo | 4 +- .../type_tuple_value_nested_3x2_fail.leo | 2 +- .../array/type_tuple_value_nested_4x3x2.leo | 4 +- .../type_tuple_value_nested_4x3x2_fail.leo | 2 +- .../array/type_tuple_value_tuple_3x2.leo | 4 +- .../array/type_tuple_value_tuple_3x2_fail.leo | 2 +- .../array/type_tuple_value_tuple_4x3x2.leo | 4 +- .../type_tuple_value_tuple_4x3x2_fail.leo | 2 +- .../pass/parse/array/variable_slice_fail.leo | 4 +- tests/pass/parse/boolean/all.leo | 6 +- tests/pass/parse/boolean/conditional_mut.leo | 4 +- tests/pass/parse/boolean/false_and_false.leo | 2 +- tests/pass/parse/boolean/false_or_false.leo | 2 +- tests/pass/parse/boolean/not_mutable.leo | 4 +- tests/pass/parse/boolean/true_and_false.leo | 2 +- tests/pass/parse/boolean/true_and_true.leo | 2 +- tests/pass/parse/boolean/true_and_u32.leo | 2 +- tests/pass/parse/boolean/true_or_false.leo | 2 +- tests/pass/parse/boolean/true_or_true.leo | 2 +- tests/pass/parse/boolean/true_or_u32.leo | 2 +- ...define_circuit_inside_circuit_function.leo | 4 +- .../parse/circuits/duplicate_name_context.leo | 6 +- tests/pass/parse/circuits/inline.leo | 2 +- tests/pass/parse/circuits/inline_fail.leo | 2 +- .../parse/circuits/inline_member_fail.leo | 4 +- .../parse/circuits/inline_member_pass.leo | 6 +- .../pass/parse/circuits/inline_undefined.leo | 2 +- tests/pass/parse/circuits/member_function.leo | 2 +- .../parse/circuits/member_function_fail.leo | 4 +- .../circuits/member_function_invalid.leo | 4 +- .../parse/circuits/member_function_nested.leo | 4 +- .../parse/circuits/member_static_function.leo | 2 +- .../member_static_function_invalid.leo | 2 +- .../member_static_function_undefined.leo | 2 +- tests/pass/parse/circuits/member_variable.leo | 2 +- .../circuits/member_variable_and_function.leo | 4 +- .../parse/circuits/member_variable_fail.leo | 4 +- .../pass/parse/circuits/mut_function_fail.leo | 2 +- .../parse/circuits/mut_self_function_fail.leo | 2 +- .../mut_self_static_function_fail.leo | 2 +- .../pass/parse/circuits/mut_self_variable.leo | 2 +- .../circuits/mut_self_variable_branch.leo | 2 +- .../mut_self_variable_conditional.leo | 2 +- .../parse/circuits/mut_self_variable_fail.leo | 2 +- .../circuits/mut_static_function_fail.leo | 2 +- tests/pass/parse/circuits/mut_variable.leo | 2 +- .../pass/parse/circuits/mut_variable_fail.leo | 2 +- tests/pass/parse/circuits/pedersen_mock.leo | 12 +- tests/pass/parse/circuits/self_member.leo | 4 +- .../parse/circuits/self_member_invalid.leo | 4 +- .../parse/circuits/self_member_undefined.leo | 4 +- tests/pass/parse/compiler/main.leo | 2 +- .../pass/parse/core/arguments_length_fail.leo | 4 +- tests/pass/parse/core/arguments_type_fail.leo | 6 +- tests/pass/parse/core/blake2s_random.leo | 2 +- tests/pass/parse/core/unstable_blake2s.leo | 6 +- tests/pass/parse/field/field.leo | 4 +- tests/pass/parse/field/ternary.leo | 2 +- tests/pass/parse/function/array_input.leo | 2 +- .../function/array_params_direct_call.leo | 2 +- tests/pass/parse/function/iteration.leo | 2 +- .../parse/function/iteration_repeated.leo | 4 +- .../pass/parse/function/multiple_returns.leo | 2 +- .../multiple_returns_fail_conditional.leo | 4 +- tests/pass/parse/function/repeated.leo | 2 +- .../function/return_array_nested_fail.leo | 2 +- .../function/return_array_nested_pass.leo | 4 +- .../function/return_array_tuple_fail.leo | 2 +- .../function/return_array_tuple_pass.leo | 4 +- tests/pass/parse/function/return_tuple.leo | 6 +- .../function/return_tuple_conditional.leo | 2 +- tests/pass/parse/function/scope_fail.leo | 4 +- tests/pass/parse/function/value_unchanged.leo | 2 +- tests/pass/parse/group/both_sign_high.leo | 2 +- tests/pass/parse/group/both_sign_inferred.leo | 2 +- tests/pass/parse/group/both_sign_low.leo | 2 +- tests/pass/parse/group/one.leo | 2 +- tests/pass/parse/group/point.leo | 2 +- tests/pass/parse/group/point_input.leo | 2 +- .../parse/group/positive_and_negative.leo | 12 +- tests/pass/parse/group/ternary.leo | 2 +- tests/pass/parse/group/x_and_y.leo | 2 +- tests/pass/parse/group/x_sign_high.leo | 2 +- tests/pass/parse/group/x_sign_inferred.leo | 2 +- tests/pass/parse/group/x_sign_low.leo | 2 +- tests/pass/parse/group/y_sign_high.leo | 2 +- tests/pass/parse/group/y_sign_inferred.leo | 2 +- tests/pass/parse/group/y_sign_low.leo | 2 +- tests/pass/parse/group/zero.leo | 2 +- tests/pass/parse/import/many_import.leo | 14 +- tests/pass/parse/import/many_import_star.leo | 12 +- tests/pass/parse/import/multiple.leo | 2 +- tests/pass/parse/import/star.leo | 2 +- tests/pass/parse/integers/i128/max.leo | 2 +- tests/pass/parse/integers/i128/max_fail.leo | 2 +- tests/pass/parse/integers/i128/min.leo | 2 +- tests/pass/parse/integers/i128/min_fail.leo | 2 +- tests/pass/parse/integers/i128/negate_min.leo | 4 +- .../pass/parse/integers/i128/negate_zero.leo | 2 +- tests/pass/parse/integers/i128/ternary.leo | 2 +- tests/pass/parse/integers/i16/max.leo | 2 +- tests/pass/parse/integers/i16/max_fail.leo | 2 +- tests/pass/parse/integers/i16/min.leo | 2 +- tests/pass/parse/integers/i16/min_fail.leo | 2 +- tests/pass/parse/integers/i16/negate_min.leo | 4 +- tests/pass/parse/integers/i16/negate_zero.leo | 2 +- tests/pass/parse/integers/i16/ternary.leo | 2 +- tests/pass/parse/integers/i32/max.leo | 2 +- tests/pass/parse/integers/i32/max_fail.leo | 2 +- tests/pass/parse/integers/i32/min.leo | 2 +- tests/pass/parse/integers/i32/min_fail.leo | 2 +- tests/pass/parse/integers/i32/negate_min.leo | 4 +- tests/pass/parse/integers/i32/negate_zero.leo | 2 +- tests/pass/parse/integers/i32/ternary.leo | 2 +- tests/pass/parse/integers/i64/max.leo | 2 +- tests/pass/parse/integers/i64/max_fail.leo | 2 +- tests/pass/parse/integers/i64/min.leo | 2 +- tests/pass/parse/integers/i64/min_fail.leo | 2 +- tests/pass/parse/integers/i64/negate_min.leo | 4 +- tests/pass/parse/integers/i64/negate_zero.leo | 2 +- tests/pass/parse/integers/i64/ternary.leo | 2 +- tests/pass/parse/integers/i8/max.leo | 2 +- tests/pass/parse/integers/i8/max_fail.leo | 2 +- tests/pass/parse/integers/i8/min.leo | 2 +- tests/pass/parse/integers/i8/min_fail.leo | 2 +- tests/pass/parse/integers/i8/negate_min.leo | 4 +- tests/pass/parse/integers/i8/negate_zero.leo | 2 +- tests/pass/parse/integers/i8/ternary.leo | 2 +- tests/pass/parse/integers/u128/max.leo | 2 +- tests/pass/parse/integers/u128/max_fail.leo | 2 +- tests/pass/parse/integers/u128/min.leo | 2 +- tests/pass/parse/integers/u128/min_fail.leo | 2 +- tests/pass/parse/integers/u128/ternary.leo | 2 +- tests/pass/parse/integers/u16/max.leo | 2 +- tests/pass/parse/integers/u16/max_fail.leo | 2 +- tests/pass/parse/integers/u16/min.leo | 2 +- tests/pass/parse/integers/u16/min_fail.leo | 2 +- tests/pass/parse/integers/u16/ternary.leo | 2 +- tests/pass/parse/integers/u32/max.leo | 2 +- tests/pass/parse/integers/u32/max_fail.leo | 2 +- tests/pass/parse/integers/u32/min.leo | 2 +- tests/pass/parse/integers/u32/min_fail.leo | 2 +- tests/pass/parse/integers/u32/ternary.leo | 2 +- tests/pass/parse/integers/u64/max.leo | 2 +- tests/pass/parse/integers/u64/max_fail.leo | 2 +- tests/pass/parse/integers/u64/min.leo | 2 +- tests/pass/parse/integers/u64/min_fail.leo | 2 +- tests/pass/parse/integers/u64/ternary.leo | 2 +- tests/pass/parse/integers/u8/max.leo | 2 +- tests/pass/parse/integers/u8/max_fail.leo | 2 +- tests/pass/parse/integers/u8/min.leo | 2 +- tests/pass/parse/integers/u8/min_fail.leo | 2 +- tests/pass/parse/integers/u8/ternary.leo | 2 +- tests/pass/parse/mutability/array.leo | 2 +- tests/pass/parse/mutability/array_mut.leo | 2 +- .../parse/mutability/array_splice_mut.leo | 2 +- .../pass/parse/mutability/array_tuple_mut.leo | 2 +- tests/pass/parse/mutability/circuit.leo | 2 +- .../parse/mutability/circuit_function_mut.leo | 2 +- tests/pass/parse/mutability/circuit_mut.leo | 2 +- .../circuit_static_function_mut.leo | 2 +- .../parse/mutability/circuit_variable_mut.leo | 2 +- tests/pass/parse/mutability/const.leo | 2 +- tests/pass/parse/mutability/let.leo | 2 +- tests/pass/parse/mutability/let_mut.leo | 2 +- .../pass/parse/mutability/let_mut_nested.leo | 6 +- tests/pass/parse/mutability/swap.leo | 8 +- tests/pass/parse/statements/block.leo | 2 +- tests/pass/parse/statements/chain.leo | 2 +- tests/pass/parse/statements/for_loop.leo | 4 +- .../pass/parse/statements/iteration_basic.leo | 2 +- tests/pass/parse/statements/mutate.leo | 2 +- tests/pass/parse/statements/nested.leo | 2 +- tests/pass/parse/statements/ternary_basic.leo | 4 +- .../parse/syntax/compare_mismatched_types.leo | 2 +- tests/pass/parse/tuples/access.leo | 2 +- tests/pass/parse/tuples/basic.leo | 2 +- tests/pass/parse/tuples/function.leo | 2 +- tests/pass/parse/tuples/function_multiple.leo | 2 +- tests/pass/parse/tuples/function_typed.leo | 2 +- tests/pass/parse/tuples/multiple.leo | 2 +- tests/pass/parse/tuples/multiple_typed.leo | 2 +- tests/pass/parse/tuples/nested.leo | 4 +- tests/pass/parse/tuples/nested_access.leo | 4 +- tests/pass/parse/tuples/nested_typed.leo | 4 +- tests/pass/parse/tuples/typed.leo | 2 +- 696 files changed, 1356 insertions(+), 1359 deletions(-) create mode 100644 HEAD delete mode 100644 asg/tests/fail/statements/const_declaration_fail.leo create mode 100644 asg/tests/fail/statements/let_mut_declaration_fail.leo diff --git a/HEAD b/HEAD new file mode 100644 index 0000000000..e69de29bb2 diff --git a/asg/tests/fail/address/implicit_invalid.leo b/asg/tests/fail/address/implicit_invalid.leo index 6f8eba5114..aadc38a6d8 100644 --- a/asg/tests/fail/address/implicit_invalid.leo +++ b/asg/tests/fail/address/implicit_invalid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; } \ No newline at end of file diff --git a/asg/tests/fail/array/multi_fail_initializer.leo b/asg/tests/fail/array/multi_fail_initializer.leo index 258750b327..be1ab315bd 100644 --- a/asg/tests/fail/array/multi_fail_initializer.leo +++ b/asg/tests/fail/array/multi_fail_initializer.leo @@ -1,3 +1,3 @@ function main() { - let arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions + const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions } \ No newline at end of file diff --git a/asg/tests/fail/array/multi_fail_inline.leo b/asg/tests/fail/array/multi_fail_inline.leo index 50a06c09b2..49c9296798 100644 --- a/asg/tests/fail/array/multi_fail_inline.leo +++ b/asg/tests/fail/array/multi_fail_inline.leo @@ -1,4 +1,4 @@ function main() { - let arr: [u8; (2, 2)] = [[1u8, 1u8], + const arr: [u8; (2, 2)] = [[1u8, 1u8], [1u8]]; // incorrect dimensions } \ No newline at end of file diff --git a/asg/tests/fail/array/multi_initializer_fail.leo b/asg/tests/fail/array/multi_initializer_fail.leo index 0bd76acffa..e38a8fdaee 100644 --- a/asg/tests/fail/array/multi_initializer_fail.leo +++ b/asg/tests/fail/array/multi_initializer_fail.leo @@ -1,3 +1,3 @@ function main() { - let arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions + const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions } \ No newline at end of file diff --git a/asg/tests/fail/array/nested_3x2_value_fail.leo b/asg/tests/fail/array/nested_3x2_value_fail.leo index 35c8478cd1..a187a51991 100644 --- a/asg/tests/fail/array/nested_3x2_value_fail.leo +++ b/asg/tests/fail/array/nested_3x2_value_fail.leo @@ -1,4 +1,4 @@ // Multidimensional array syntax in leo function main() { - let a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) + const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) } diff --git a/asg/tests/fail/array/tuple_3x2_value_fail.leo b/asg/tests/fail/array/tuple_3x2_value_fail.leo index 42e6f61500..78593ab696 100644 --- a/asg/tests/fail/array/tuple_3x2_value_fail.leo +++ b/asg/tests/fail/array/tuple_3x2_value_fail.leo @@ -1,4 +1,4 @@ // Multidimensional array syntax in leo function main() { - let a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) + const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) } diff --git a/asg/tests/fail/array/type_fail.leo b/asg/tests/fail/array/type_fail.leo index 1402ceba4c..356bba976a 100644 --- a/asg/tests/fail/array/type_fail.leo +++ b/asg/tests/fail/array/type_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: [u8; -2] = [0u32; 2]; + const a: [u8; -2] = [0u32; 2]; } \ No newline at end of file diff --git a/asg/tests/fail/array/type_nested_value_nested_3x2_fail.leo b/asg/tests/fail/array/type_nested_value_nested_3x2_fail.leo index 4bd07f85db..56c8916fb0 100644 --- a/asg/tests/fail/array/type_nested_value_nested_3x2_fail.leo +++ b/asg/tests/fail/array/type_nested_value_nested_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) + const b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_nested_value_nested_4x3x2_fail.leo b/asg/tests/fail/array/type_nested_value_nested_4x3x2_fail.leo index 6479004d68..480327a91d 100644 --- a/asg/tests/fail/array/type_nested_value_nested_4x3x2_fail.leo +++ b/asg/tests/fail/array/type_nested_value_nested_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) + const b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_nested_value_tuple_3x2_fail.leo b/asg/tests/fail/array/type_nested_value_tuple_3x2_fail.leo index ba99b070c7..3bfb559615 100644 --- a/asg/tests/fail/array/type_nested_value_tuple_3x2_fail.leo +++ b/asg/tests/fail/array/type_nested_value_tuple_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) + const b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_nested_value_tuple_4x3x2_fail.leo b/asg/tests/fail/array/type_nested_value_tuple_4x3x2_fail.leo index 95172bf329..ce1219a37b 100644 --- a/asg/tests/fail/array/type_nested_value_tuple_4x3x2_fail.leo +++ b/asg/tests/fail/array/type_nested_value_tuple_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering) + const b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_tuple_value_nested_3x2_fail.leo b/asg/tests/fail/array/type_tuple_value_nested_3x2_fail.leo index 9732cf26ef..e84f025a9f 100644 --- a/asg/tests/fail/array/type_tuple_value_nested_3x2_fail.leo +++ b/asg/tests/fail/array/type_tuple_value_nested_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering) + const b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_tuple_value_nested_3x2_swap_fail.leo b/asg/tests/fail/array/type_tuple_value_nested_3x2_swap_fail.leo index 6edfa83847..0b960c6b44 100644 --- a/asg/tests/fail/array/type_tuple_value_nested_3x2_swap_fail.leo +++ b/asg/tests/fail/array/type_tuple_value_nested_3x2_swap_fail.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (2, 3)] = [[0; 3]; 2]; // initializer + const b: [u8; (2, 3)] = [[0; 3]; 2]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/fail/array/type_tuple_value_nested_4x3x2_fail.leo b/asg/tests/fail/array/type_tuple_value_nested_4x3x2_fail.leo index b820c4d088..cbb7ccbf76 100644 --- a/asg/tests/fail/array/type_tuple_value_nested_4x3x2_fail.leo +++ b/asg/tests/fail/array/type_tuple_value_nested_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) + const b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_tuple_value_tuple_3x2_fail.leo b/asg/tests/fail/array/type_tuple_value_tuple_3x2_fail.leo index 99487ccb7a..884a75db9d 100644 --- a/asg/tests/fail/array/type_tuple_value_tuple_3x2_fail.leo +++ b/asg/tests/fail/array/type_tuple_value_tuple_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering) + const b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/asg/tests/fail/array/type_tuple_value_tuple_3x2_swap_fail.leo b/asg/tests/fail/array/type_tuple_value_tuple_3x2_swap_fail.leo index 40f1ca9933..d742a544a7 100644 --- a/asg/tests/fail/array/type_tuple_value_tuple_3x2_swap_fail.leo +++ b/asg/tests/fail/array/type_tuple_value_tuple_3x2_swap_fail.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (2, 3)] = [0; (2, 3)]; // initializer + const b: [u8; (2, 3)] = [0; (2, 3)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/fail/array/type_tuple_value_tuple_4x3x2_fail.leo b/asg/tests/fail/array/type_tuple_value_tuple_4x3x2_fail.leo index 824fd90bc6..31e2a5e552 100644 --- a/asg/tests/fail/array/type_tuple_value_tuple_4x3x2_fail.leo +++ b/asg/tests/fail/array/type_tuple_value_tuple_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order) + const b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order) } \ No newline at end of file diff --git a/asg/tests/fail/boolean/true_and_u32.leo b/asg/tests/fail/boolean/true_and_u32.leo index e5b3a8c001..ad3ead9040 100644 --- a/asg/tests/fail/boolean/true_and_u32.leo +++ b/asg/tests/fail/boolean/true_and_u32.leo @@ -1,3 +1,3 @@ function main() { - let a = true && 1u32; + const a = true && 1u32; } \ No newline at end of file diff --git a/asg/tests/fail/boolean/true_or_u32.leo b/asg/tests/fail/boolean/true_or_u32.leo index 500b5f7bf4..38dab727b9 100644 --- a/asg/tests/fail/boolean/true_or_u32.leo +++ b/asg/tests/fail/boolean/true_or_u32.leo @@ -1,3 +1,3 @@ function main() { - let a = true || 1u32; + const a = true || 1u32; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/inline_fail.leo b/asg/tests/fail/circuits/inline_fail.leo index 52792a07e0..01597005fb 100644 --- a/asg/tests/fail/circuits/inline_fail.leo +++ b/asg/tests/fail/circuits/inline_fail.leo @@ -3,5 +3,5 @@ circuit Foo { } function main() { - let a = Foo { y: 0u32 }; + const a = Foo { y: 0u32 }; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/inline_undefined.leo b/asg/tests/fail/circuits/inline_undefined.leo index af070e01e9..40c4cf722c 100644 --- a/asg/tests/fail/circuits/inline_undefined.leo +++ b/asg/tests/fail/circuits/inline_undefined.leo @@ -1,3 +1,3 @@ function main() { - let a = Foo { }; + const a = Foo { }; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/member_function_fail.leo b/asg/tests/fail/circuits/member_function_fail.leo index 224b79cbf4..5a1c4100c5 100644 --- a/asg/tests/fail/circuits/member_function_fail.leo +++ b/asg/tests/fail/circuits/member_function_fail.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let a = Foo { }; - let err = a.echoed(1u32); + const a = Foo { }; + const err = a.echoed(1u32); } \ No newline at end of file diff --git a/asg/tests/fail/circuits/member_function_invalid.leo b/asg/tests/fail/circuits/member_function_invalid.leo index bb834e9562..aa689eb976 100644 --- a/asg/tests/fail/circuits/member_function_invalid.leo +++ b/asg/tests/fail/circuits/member_function_invalid.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let a = Foo { }; - let err = a.echo(1u32); // echo is a static function and must be accessed using `::` + const a = Foo { }; + const err = a.echo(1u32); // echo is a static function and must be accessed using `::` } \ No newline at end of file diff --git a/asg/tests/fail/circuits/member_static_function_invalid.leo b/asg/tests/fail/circuits/member_static_function_invalid.leo index 09fec386d9..7829b4b430 100644 --- a/asg/tests/fail/circuits/member_static_function_invalid.leo +++ b/asg/tests/fail/circuits/member_static_function_invalid.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::` + const err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::` } \ No newline at end of file diff --git a/asg/tests/fail/circuits/member_static_function_undefined.leo b/asg/tests/fail/circuits/member_static_function_undefined.leo index cf9f98c7b4..ece1d00963 100644 --- a/asg/tests/fail/circuits/member_static_function_undefined.leo +++ b/asg/tests/fail/circuits/member_static_function_undefined.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let err = Foo::echoed(1u32); + const err = Foo::echoed(1u32); } \ No newline at end of file diff --git a/asg/tests/fail/circuits/member_variable_fail.leo b/asg/tests/fail/circuits/member_variable_fail.leo index 5780704ea2..fdf42068d5 100644 --- a/asg/tests/fail/circuits/member_variable_fail.leo +++ b/asg/tests/fail/circuits/member_variable_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; - let err = a.y; + const err = a.y; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/mod.rs b/asg/tests/fail/circuits/mod.rs index f88d9ec42d..38f1824755 100644 --- a/asg/tests/fail/circuits/mod.rs +++ b/asg/tests/fail/circuits/mod.rs @@ -60,7 +60,7 @@ fn test_mut_member_function_fail() { } function main() { - let a = Foo { }; + const a = Foo { }; console.assert(a.echo(1u32) == 1u32); }"#; diff --git a/asg/tests/fail/circuits/mut_function_fail.leo b/asg/tests/fail/circuits/mut_function_fail.leo index 3469f97627..1b87e2bfb1 100644 --- a/asg/tests/fail/circuits/mut_function_fail.leo +++ b/asg/tests/fail/circuits/mut_function_fail.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.bar = 1u8; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/mut_self_function_fail.leo b/asg/tests/fail/circuits/mut_self_function_fail.leo index 8c9b99f6ae..58c8088ba1 100644 --- a/asg/tests/fail/circuits/mut_self_function_fail.leo +++ b/asg/tests/fail/circuits/mut_self_function_fail.leo @@ -9,7 +9,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.set_a(1u8); } \ No newline at end of file diff --git a/asg/tests/fail/circuits/mut_self_static_function_fail.leo b/asg/tests/fail/circuits/mut_self_static_function_fail.leo index 8c9b99f6ae..58c8088ba1 100644 --- a/asg/tests/fail/circuits/mut_self_static_function_fail.leo +++ b/asg/tests/fail/circuits/mut_self_static_function_fail.leo @@ -9,7 +9,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.set_a(1u8); } \ No newline at end of file diff --git a/asg/tests/fail/circuits/mut_self_variable_fail.leo b/asg/tests/fail/circuits/mut_self_variable_fail.leo index fdbb556bca..4db62a4d3e 100644 --- a/asg/tests/fail/circuits/mut_self_variable_fail.leo +++ b/asg/tests/fail/circuits/mut_self_variable_fail.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.set_a(1u8); } \ No newline at end of file diff --git a/asg/tests/fail/circuits/mut_static_function_fail.leo b/asg/tests/fail/circuits/mut_static_function_fail.leo index ed3092c656..fd873bd17b 100644 --- a/asg/tests/fail/circuits/mut_static_function_fail.leo +++ b/asg/tests/fail/circuits/mut_static_function_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.bar = 1u8; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/mut_variable_fail.leo b/asg/tests/fail/circuits/mut_variable_fail.leo index 4d58150c95..7ba4193074 100644 --- a/asg/tests/fail/circuits/mut_variable_fail.leo +++ b/asg/tests/fail/circuits/mut_variable_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let f = Foo { a: 0u8 }; + const f = Foo { a: 0u8 }; f.a = 1u8; } \ No newline at end of file diff --git a/asg/tests/fail/circuits/self_member_invalid.leo b/asg/tests/fail/circuits/self_member_invalid.leo index 2e8b14f66c..163499d619 100644 --- a/asg/tests/fail/circuits/self_member_invalid.leo +++ b/asg/tests/fail/circuits/self_member_invalid.leo @@ -7,6 +7,6 @@ circuit Foo { } function main() -> u32 { - let foo = Foo { f: 1u32 }; - let err = foo.bar(); + const foo = Foo { f: 1u32 }; + const err = foo.bar(); } \ No newline at end of file diff --git a/asg/tests/fail/circuits/self_member_undefined.leo b/asg/tests/fail/circuits/self_member_undefined.leo index 471ffb973c..05a40905d7 100644 --- a/asg/tests/fail/circuits/self_member_undefined.leo +++ b/asg/tests/fail/circuits/self_member_undefined.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let foo = Foo { }; - let err = foo.bar(); + const foo = Foo { }; + const err = foo.bar(); } \ No newline at end of file diff --git a/asg/tests/fail/function/array_input.leo b/asg/tests/fail/function/array_input.leo index a70483cae7..899c0e4af6 100644 --- a/asg/tests/fail/function/array_input.leo +++ b/asg/tests/fail/function/array_input.leo @@ -1,6 +1,6 @@ function foo(a: [u8; 1]) {} function main() { - let a: [u16; 1] = [1; 1]; + const a: [u16; 1] = [1; 1]; foo(a); } \ No newline at end of file diff --git a/asg/tests/fail/function/multiple_returns_fail_conditional.leo b/asg/tests/fail/function/multiple_returns_fail_conditional.leo index 04ebb9e306..227fe5ce12 100644 --- a/asg/tests/fail/function/multiple_returns_fail_conditional.leo +++ b/asg/tests/fail/function/multiple_returns_fail_conditional.leo @@ -1,7 +1,7 @@ function main () -> u16 { if false { - let a = 1u16; - let b = a + 1u16; + const a = 1u16; + const b = a + 1u16; return b } else if false { return 0u16 diff --git a/asg/tests/fail/function/return_array_nested_fail.leo b/asg/tests/fail/function/return_array_nested_fail.leo index dca001d9cc..8eca684b8a 100644 --- a/asg/tests/fail/function/return_array_nested_fail.leo +++ b/asg/tests/fail/function/return_array_nested_fail.leo @@ -3,5 +3,5 @@ function array_3x2_tuple() -> [[u8; 2]; 3] { } function main() { - let b = array_3x2_tuple(); + const b = array_3x2_tuple(); } \ No newline at end of file diff --git a/asg/tests/fail/function/return_array_tuple_fail.leo b/asg/tests/fail/function/return_array_tuple_fail.leo index 4b7377e327..c960456ac1 100644 --- a/asg/tests/fail/function/return_array_tuple_fail.leo +++ b/asg/tests/fail/function/return_array_tuple_fail.leo @@ -3,5 +3,5 @@ function array_3x2_nested() -> [u8; (3, 2)] { } function main() { - let a = array_3x2_nested(); + const a = array_3x2_nested(); } \ No newline at end of file diff --git a/asg/tests/fail/function/scope_fail.leo b/asg/tests/fail/function/scope_fail.leo index 773c2479d7..6f1d390541 100644 --- a/asg/tests/fail/function/scope_fail.leo +++ b/asg/tests/fail/function/scope_fail.leo @@ -3,6 +3,6 @@ function foo() -> field { } function main() { - let myGlobal = 42field; - let err = foo(); + const myGlobal = 42field; + const err = foo(); } \ No newline at end of file diff --git a/asg/tests/fail/group/both_sign_high.leo b/asg/tests/fail/group/both_sign_high.leo index a8217d6d40..4c93573e1e 100644 --- a/asg/tests/fail/group/both_sign_high.leo +++ b/asg/tests/fail/group/both_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, +)group; + const element = (+, +)group; } \ No newline at end of file diff --git a/asg/tests/fail/group/both_sign_inferred.leo b/asg/tests/fail/group/both_sign_inferred.leo index b3b8b512c3..0bbd360ba0 100644 --- a/asg/tests/fail/group/both_sign_inferred.leo +++ b/asg/tests/fail/group/both_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, _)group; + const element = (_, _)group; } \ No newline at end of file diff --git a/asg/tests/fail/group/both_sign_low.leo b/asg/tests/fail/group/both_sign_low.leo index 0519c6d17d..1cb4f46c55 100644 --- a/asg/tests/fail/group/both_sign_low.leo +++ b/asg/tests/fail/group/both_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, -)group; + const element = (-, -)group; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i128/max_fail.leo b/asg/tests/fail/integers/i128/max_fail.leo index 820eda8759..a9a46afd7f 100644 --- a/asg/tests/fail/integers/i128/max_fail.leo +++ b/asg/tests/fail/integers/i128/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = 170141183460469231731687303715884105728; + const a: i128 = 170141183460469231731687303715884105728; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i128/min_fail.leo b/asg/tests/fail/integers/i128/min_fail.leo index 9035444fa9..918f0e439d 100644 --- a/asg/tests/fail/integers/i128/min_fail.leo +++ b/asg/tests/fail/integers/i128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = -170141183460469231731687303715884105729; + const a: i128 = -170141183460469231731687303715884105729; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i128/negate_min.leo b/asg/tests/fail/integers/i128/negate_min.leo index cfbd308362..c9de272960 100644 --- a/asg/tests/fail/integers/i128/negate_min.leo +++ b/asg/tests/fail/integers/i128/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a: i128 = -170141183460469231731687303715884105728; - let b = -a; + const a: i128 = -170141183460469231731687303715884105728; + const b = -a; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i16/max_fail.leo b/asg/tests/fail/integers/i16/max_fail.leo index 8dd2b7f50a..209bcc6518 100644 --- a/asg/tests/fail/integers/i16/max_fail.leo +++ b/asg/tests/fail/integers/i16/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = 32768; + const a: i16 = 32768; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i16/min_fail.leo b/asg/tests/fail/integers/i16/min_fail.leo index 380848381a..13d7c8b7f2 100644 --- a/asg/tests/fail/integers/i16/min_fail.leo +++ b/asg/tests/fail/integers/i16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = -32769; + const a: i16 = -32769; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i16/negate_min.leo b/asg/tests/fail/integers/i16/negate_min.leo index 2622f8d2a3..d52a356396 100644 --- a/asg/tests/fail/integers/i16/negate_min.leo +++ b/asg/tests/fail/integers/i16/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -32768i16; - let b = -a; + const a = -32768i16; + const b = -a; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i32/max_fail.leo b/asg/tests/fail/integers/i32/max_fail.leo index f3fd81815f..af2877ff5e 100644 --- a/asg/tests/fail/integers/i32/max_fail.leo +++ b/asg/tests/fail/integers/i32/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = 2147483648; + const a: i32 = 2147483648; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i32/min_fail.leo b/asg/tests/fail/integers/i32/min_fail.leo index 1462d207e9..11a683b087 100644 --- a/asg/tests/fail/integers/i32/min_fail.leo +++ b/asg/tests/fail/integers/i32/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = -2147483649; + const a: i32 = -2147483649; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i32/negate_min.leo b/asg/tests/fail/integers/i32/negate_min.leo index b3c10064e1..a96455d57a 100644 --- a/asg/tests/fail/integers/i32/negate_min.leo +++ b/asg/tests/fail/integers/i32/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -2147483648i32; - let b = -a; + const a = -2147483648i32; + const b = -a; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i64/max_fail.leo b/asg/tests/fail/integers/i64/max_fail.leo index 3e6603e4be..362b794a2c 100644 --- a/asg/tests/fail/integers/i64/max_fail.leo +++ b/asg/tests/fail/integers/i64/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = 9223372036854775808; + const a: i64 = 9223372036854775808; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i64/min_fail.leo b/asg/tests/fail/integers/i64/min_fail.leo index 11e43646b0..bb260ecc3f 100644 --- a/asg/tests/fail/integers/i64/min_fail.leo +++ b/asg/tests/fail/integers/i64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = -9223372036854775809; + const a: i64 = -9223372036854775809; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i64/negate_min.leo b/asg/tests/fail/integers/i64/negate_min.leo index 4dd27778d0..daf694491b 100644 --- a/asg/tests/fail/integers/i64/negate_min.leo +++ b/asg/tests/fail/integers/i64/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a: i64 = -9223372036854775808; - let b = -a; + const a: i64 = -9223372036854775808; + const b = -a; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i8/max_fail.leo b/asg/tests/fail/integers/i8/max_fail.leo index 4892505915..9e1956024a 100644 --- a/asg/tests/fail/integers/i8/max_fail.leo +++ b/asg/tests/fail/integers/i8/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = 128; + const a: i8 = 128; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i8/min_fail.leo b/asg/tests/fail/integers/i8/min_fail.leo index 051468ea70..41170e9b93 100644 --- a/asg/tests/fail/integers/i8/min_fail.leo +++ b/asg/tests/fail/integers/i8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = -129; + const a: i8 = -129; } \ No newline at end of file diff --git a/asg/tests/fail/integers/i8/negate_min.leo b/asg/tests/fail/integers/i8/negate_min.leo index 3959da615e..7f664a1b78 100644 --- a/asg/tests/fail/integers/i8/negate_min.leo +++ b/asg/tests/fail/integers/i8/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -128i8; - let b = -a; + const a = -128i8; + const b = -a; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u128/max_fail.leo b/asg/tests/fail/integers/u128/max_fail.leo index 40cdf7d2bb..f51c967925 100644 --- a/asg/tests/fail/integers/u128/max_fail.leo +++ b/asg/tests/fail/integers/u128/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 340282366920938463463374607431768211456; + const a: u128 = 340282366920938463463374607431768211456; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u128/min_fail.leo b/asg/tests/fail/integers/u128/min_fail.leo index df2390c576..b0d17191ff 100644 --- a/asg/tests/fail/integers/u128/min_fail.leo +++ b/asg/tests/fail/integers/u128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = -1; + const a: u128 = -1; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u16/max_fail.leo b/asg/tests/fail/integers/u16/max_fail.leo index 68ff0481e0..bb703210e3 100644 --- a/asg/tests/fail/integers/u16/max_fail.leo +++ b/asg/tests/fail/integers/u16/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 65536; + const a: u16 = 65536; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u16/min_fail.leo b/asg/tests/fail/integers/u16/min_fail.leo index 99b7310362..0c61dd7ddf 100644 --- a/asg/tests/fail/integers/u16/min_fail.leo +++ b/asg/tests/fail/integers/u16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = -1; + const a: u16 = -1; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u32/max_fail.leo b/asg/tests/fail/integers/u32/max_fail.leo index 96c7e01657..6b1631876e 100644 --- a/asg/tests/fail/integers/u32/max_fail.leo +++ b/asg/tests/fail/integers/u32/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 4294967296; + const a: u32 = 4294967296; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u32/min_fail.leo b/asg/tests/fail/integers/u32/min_fail.leo index a8d41c475a..c3e3f33225 100644 --- a/asg/tests/fail/integers/u32/min_fail.leo +++ b/asg/tests/fail/integers/u32/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + const a: u32 = -1; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u64/max_fail.leo b/asg/tests/fail/integers/u64/max_fail.leo index 0ca3f13895..d606c83585 100644 --- a/asg/tests/fail/integers/u64/max_fail.leo +++ b/asg/tests/fail/integers/u64/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 18446744073709551616; + const a: u64 = 18446744073709551616; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u64/min_fail.leo b/asg/tests/fail/integers/u64/min_fail.leo index 81b90cc74a..e58f1897e6 100644 --- a/asg/tests/fail/integers/u64/min_fail.leo +++ b/asg/tests/fail/integers/u64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = -1; + const a: u64 = -1; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u8/max_fail.leo b/asg/tests/fail/integers/u8/max_fail.leo index f2b870096d..01bb544601 100644 --- a/asg/tests/fail/integers/u8/max_fail.leo +++ b/asg/tests/fail/integers/u8/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 256; + const a: u8 = 256; } \ No newline at end of file diff --git a/asg/tests/fail/integers/u8/min_fail.leo b/asg/tests/fail/integers/u8/min_fail.leo index 7b91dc6e1a..3cd8d46de7 100644 --- a/asg/tests/fail/integers/u8/min_fail.leo +++ b/asg/tests/fail/integers/u8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = -1; + const a: u8 = -1; } \ No newline at end of file diff --git a/asg/tests/fail/mutability/array.leo b/asg/tests/fail/mutability/array.leo index 1d51c15271..ea63baaad2 100644 --- a/asg/tests/fail/mutability/array.leo +++ b/asg/tests/fail/mutability/array.leo @@ -1,5 +1,5 @@ // Arrays are immutable by default. function main() { - let a = [1u32]; + const a = [1u32]; a[0] = 0; } \ No newline at end of file diff --git a/asg/tests/fail/mutability/circuit.leo b/asg/tests/fail/mutability/circuit.leo index be1c568836..508595ef16 100644 --- a/asg/tests/fail/mutability/circuit.leo +++ b/asg/tests/fail/mutability/circuit.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let a = Foo { x: 1 }; + const a = Foo { x: 1 }; a.x = 0; } \ No newline at end of file diff --git a/asg/tests/fail/mutability/circuit_function_mut.leo b/asg/tests/fail/mutability/circuit_function_mut.leo index eba1d02c0e..c1bc941c94 100644 --- a/asg/tests/fail/mutability/circuit_function_mut.leo +++ b/asg/tests/fail/mutability/circuit_function_mut.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.bar = 0; } \ No newline at end of file diff --git a/asg/tests/fail/mutability/circuit_static_function_mut.leo b/asg/tests/fail/mutability/circuit_static_function_mut.leo index eba1d02c0e..c1bc941c94 100644 --- a/asg/tests/fail/mutability/circuit_static_function_mut.leo +++ b/asg/tests/fail/mutability/circuit_static_function_mut.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.bar = 0; } \ No newline at end of file diff --git a/asg/tests/fail/mutability/const.leo b/asg/tests/fail/mutability/const.leo index d2a3a6ac2b..6201e7c5af 100644 --- a/asg/tests/fail/mutability/const.leo +++ b/asg/tests/fail/mutability/const.leo @@ -1,5 +1,5 @@ // Let variables are immutable by default. function main() { - let a = 1u32; + const a = 1u32; a = 0; } \ No newline at end of file diff --git a/asg/tests/fail/mutability/let.leo b/asg/tests/fail/mutability/let.leo index 477e6b35f5..105730adb7 100644 --- a/asg/tests/fail/mutability/let.leo +++ b/asg/tests/fail/mutability/let.leo @@ -1,5 +1,5 @@ // Variables are immutable by default. function main() { - let a = 1u32; + const a = 1u32; a = 0; } \ No newline at end of file diff --git a/asg/tests/fail/statements/const_declaration_fail.leo b/asg/tests/fail/statements/const_declaration_fail.leo deleted file mode 100644 index 1c7afb178a..0000000000 --- a/asg/tests/fail/statements/const_declaration_fail.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - const x = 1u32; -} \ No newline at end of file diff --git a/asg/tests/fail/statements/let_mut_declaration_fail.leo b/asg/tests/fail/statements/let_mut_declaration_fail.leo new file mode 100644 index 0000000000..ea80a7bc0d --- /dev/null +++ b/asg/tests/fail/statements/let_mut_declaration_fail.leo @@ -0,0 +1,3 @@ +function main() { + let mut x = 1u32; +} \ No newline at end of file diff --git a/asg/tests/fail/statements/mod.rs b/asg/tests/fail/statements/mod.rs index 6f6c3021dd..106af9dfe7 100644 --- a/asg/tests/fail/statements/mod.rs +++ b/asg/tests/fail/statements/mod.rs @@ -23,7 +23,7 @@ fn test_num_returns_fail() { } #[test] -fn test_const_declaration_fail() { - let program_string = include_str!("const_declaration_fail.leo"); +fn test_let_mut_declaration_fail() { + let program_string = include_str!("let_mut_declaration_fail.leo"); load_asg(program_string).err().unwrap(); } diff --git a/asg/tests/pass/address/console_assert_pass.leo b/asg/tests/pass/address/console_assert_pass.leo index 60ea4a79cd..f17d7d8c05 100644 --- a/asg/tests/pass/address/console_assert_pass.leo +++ b/asg/tests/pass/address/console_assert_pass.leo @@ -1,6 +1,6 @@ function main() { - let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); console.assert(address_1 == address_2); } \ No newline at end of file diff --git a/asg/tests/pass/address/implicit_invalid.leo b/asg/tests/pass/address/implicit_invalid.leo index 6f8eba5114..aadc38a6d8 100644 --- a/asg/tests/pass/address/implicit_invalid.leo +++ b/asg/tests/pass/address/implicit_invalid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; } \ No newline at end of file diff --git a/asg/tests/pass/address/implicit_valid.leo b/asg/tests/pass/address/implicit_valid.leo index df6ebf497d..75bcbaa8a1 100644 --- a/asg/tests/pass/address/implicit_valid.leo +++ b/asg/tests/pass/address/implicit_valid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; } \ No newline at end of file diff --git a/asg/tests/pass/address/input.leo b/asg/tests/pass/address/input.leo index 795deac98b..29519f0334 100644 --- a/asg/tests/pass/address/input.leo +++ b/asg/tests/pass/address/input.leo @@ -1,5 +1,5 @@ function main(owner: address) { - let sender = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const sender = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); console.assert(owner == sender); } \ No newline at end of file diff --git a/asg/tests/pass/address/ternary.leo b/asg/tests/pass/address/ternary.leo index bdd88b9d92..dc87153d2d 100644 --- a/asg/tests/pass/address/ternary.leo +++ b/asg/tests/pass/address/ternary.leo @@ -1,8 +1,8 @@ function main(s: bool, c: address) { - let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); + const a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); - let r = s? a: b; + const r = s? a: b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/address/valid.leo b/asg/tests/pass/address/valid.leo index f06aefdaa6..18f1682526 100644 --- a/asg/tests/pass/address/valid.leo +++ b/asg/tests/pass/address/valid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); } \ No newline at end of file diff --git a/asg/tests/pass/array/implicit.leo b/asg/tests/pass/array/implicit.leo index a7077c8389..cfb4281e35 100644 --- a/asg/tests/pass/array/implicit.leo +++ b/asg/tests/pass/array/implicit.leo @@ -1,6 +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]; + const a = [1u8, 2u8, 3u8, 4]; + const b = [1u8, 2u8, 3, 4u8]; + const c = [1u8, 2, 3u8, 4u8]; + const d = [1, 2u8, 3u8, 4u8]; } \ No newline at end of file diff --git a/asg/tests/pass/array/index_u8.leo b/asg/tests/pass/array/index_u8.leo index 7ad1c6a9ea..24d52ba82e 100644 --- a/asg/tests/pass/array/index_u8.leo +++ b/asg/tests/pass/array/index_u8.leo @@ -1,5 +1,5 @@ function main() { - let x = 0u8; - let a = [0u8; 4]; + const x = 0u8; + const a = [0u8; 4]; console.assert(a[x] == 0); } diff --git a/asg/tests/pass/array/multi_initializer.leo b/asg/tests/pass/array/multi_initializer.leo index 7257999ddf..6133542ef0 100644 --- a/asg/tests/pass/array/multi_initializer.leo +++ b/asg/tests/pass/array/multi_initializer.leo @@ -1,7 +1,7 @@ function main() { - let a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; + const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; - let b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2]; + const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2]; console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/nested_3x2_value.leo b/asg/tests/pass/array/nested_3x2_value.leo index b69ddffb89..c5f64c997e 100644 --- a/asg/tests/pass/array/nested_3x2_value.leo +++ b/asg/tests/pass/array/nested_3x2_value.leo @@ -1,8 +1,8 @@ // Multidimensional array syntax in leo function main() { - let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline - let b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer + const b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/slice.leo b/asg/tests/pass/array/slice.leo index 296f5bd050..9ff83dbbb8 100644 --- a/asg/tests/pass/array/slice.leo +++ b/asg/tests/pass/array/slice.leo @@ -1,6 +1,6 @@ // `{from}..{to}` copies the elements of one array into another exclusively function main(a: [u8; 3]) { - let b = [1u8; 4]; + const b = [1u8; 4]; console.assert(a == b[0..3]); } diff --git a/asg/tests/pass/array/slice_i8.leo b/asg/tests/pass/array/slice_i8.leo index bc3d884cc6..18f090e6f0 100644 --- a/asg/tests/pass/array/slice_i8.leo +++ b/asg/tests/pass/array/slice_i8.leo @@ -1,6 +1,6 @@ // `{from}..{to}` copies the elements of one array into another exclusively function main(a: [u8; 3]) { - let b = [1u8; 4]; + const b = [1u8; 4]; console.assert(a == b[0u8..3i8]); } diff --git a/asg/tests/pass/array/slice_lower.leo b/asg/tests/pass/array/slice_lower.leo index dd669830ea..0af6fbd937 100644 --- a/asg/tests/pass/array/slice_lower.leo +++ b/asg/tests/pass/array/slice_lower.leo @@ -1,8 +1,8 @@ function main() { - let arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; - let expected: [u32; 2] = [0, 1]; + const arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + const expected: [u32; 2] = [0, 1]; - let actual = arr[..2]; // Should produce [0, 1] + const actual = arr[..2]; // Should produce [0, 1] console.assert(expected == actual); } \ No newline at end of file diff --git a/asg/tests/pass/array/spread.leo b/asg/tests/pass/array/spread.leo index 962e92c923..8bd2861aae 100644 --- a/asg/tests/pass/array/spread.leo +++ b/asg/tests/pass/array/spread.leo @@ -1,7 +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]; + const b = [1u8, 1u8]; + const c = [1u8, ...b]; console.assert(a == c); } \ No newline at end of file diff --git a/asg/tests/pass/array/tuple_3x2_value.leo b/asg/tests/pass/array/tuple_3x2_value.leo index dc9128c51e..b6659539d5 100644 --- a/asg/tests/pass/array/tuple_3x2_value.leo +++ b/asg/tests/pass/array/tuple_3x2_value.leo @@ -1,8 +1,8 @@ // Multidimensional array syntax in leo function main() { - let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline - let b: [u32; (3, 2)] = [0; (3, 2)]; // initializer + const b: [u32; (3, 2)] = [0; (3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_input_3x2.leo b/asg/tests/pass/array/type_input_3x2.leo index 40781415c1..ea60a0cc24 100644 --- a/asg/tests/pass/array/type_input_3x2.leo +++ b/asg/tests/pass/array/type_input_3x2.leo @@ -1,5 +1,5 @@ function main(a: [[u8; 2]; 3]) { - let b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_input_4x3x2.leo b/asg/tests/pass/array/type_input_4x3x2.leo index bd75514904..2d9c4cff22 100644 --- a/asg/tests/pass/array/type_input_4x3x2.leo +++ b/asg/tests/pass/array/type_input_4x3x2.leo @@ -1,5 +1,5 @@ function main(a: [[[u8; 2]; 3]; 4]) { - let b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 diff --git a/asg/tests/pass/array/type_nested_value_nested_3x2.leo b/asg/tests/pass/array/type_nested_value_nested_3x2.leo index 341b9ead9c..bcf5bae674 100644 --- a/asg/tests/pass/array/type_nested_value_nested_3x2.leo +++ b/asg/tests/pass/array/type_nested_value_nested_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer + const b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_nested_value_nested_4x3x2.leo b/asg/tests/pass/array/type_nested_value_nested_4x3x2.leo index 5ba24a381b..1691fa26c7 100644 --- a/asg/tests/pass/array/type_nested_value_nested_4x3x2.leo +++ b/asg/tests/pass/array/type_nested_value_nested_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_nested_value_tuple_3x2.leo b/asg/tests/pass/array/type_nested_value_tuple_3x2.leo index c6fac9ec64..5f14084d55 100644 --- a/asg/tests/pass/array/type_nested_value_tuple_3x2.leo +++ b/asg/tests/pass/array/type_nested_value_tuple_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer + const b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_nested_value_tuple_4x3x2.leo b/asg/tests/pass/array/type_nested_value_tuple_4x3x2.leo index 9be45de408..88a5143bd2 100644 --- a/asg/tests/pass/array/type_nested_value_tuple_4x3x2.leo +++ b/asg/tests/pass/array/type_nested_value_tuple_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_tuple_value_nested_3x2.leo b/asg/tests/pass/array/type_tuple_value_nested_3x2.leo index 4e061c4309..81195e03a1 100644 --- a/asg/tests/pass/array/type_tuple_value_nested_3x2.leo +++ b/asg/tests/pass/array/type_tuple_value_nested_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer + const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_tuple_value_nested_4x3x2.leo b/asg/tests/pass/array/type_tuple_value_nested_4x3x2.leo index d9dc698784..322a6f7601 100644 --- a/asg/tests/pass/array/type_tuple_value_nested_4x3x2.leo +++ b/asg/tests/pass/array/type_tuple_value_nested_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_tuple_value_tuple_3x2.leo b/asg/tests/pass/array/type_tuple_value_tuple_3x2.leo index b0693f7667..d451a9c1a8 100644 --- a/asg/tests/pass/array/type_tuple_value_tuple_3x2.leo +++ b/asg/tests/pass/array/type_tuple_value_tuple_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (3, 2)] = [0; (3, 2)]; // initializer + const b: [u8; (3, 2)] = [0; (3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/array/type_tuple_value_tuple_4x3x2.leo b/asg/tests/pass/array/type_tuple_value_tuple_4x3x2.leo index cdc1bc961e..1205b1dc9c 100644 --- a/asg/tests/pass/array/type_tuple_value_tuple_4x3x2.leo +++ b/asg/tests/pass/array/type_tuple_value_tuple_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/all.leo b/asg/tests/pass/boolean/all.leo index 29a3815881..64fe8a795a 100644 --- a/asg/tests/pass/boolean/all.leo +++ b/asg/tests/pass/boolean/all.leo @@ -1,8 +1,8 @@ // !(true && (false || true)) function main() { - let a = true; - let b = false || a; - let c = !(true && b); + const a = true; + const b = false || a; + const c = !(true && b); console.assert(c == false); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/false_and_false.leo b/asg/tests/pass/boolean/false_and_false.leo index 70e4b0797b..03dfabab4d 100644 --- a/asg/tests/pass/boolean/false_and_false.leo +++ b/asg/tests/pass/boolean/false_and_false.leo @@ -1,5 +1,5 @@ function main() { - let a = false && false; + const a = false && false; console.assert(a == false); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/false_or_false.leo b/asg/tests/pass/boolean/false_or_false.leo index 4ae820254e..7ea710802c 100644 --- a/asg/tests/pass/boolean/false_or_false.leo +++ b/asg/tests/pass/boolean/false_or_false.leo @@ -1,5 +1,5 @@ function main() { - let a = false || false; + const a = false || false; console.assert(a == false); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/not_mutable.leo b/asg/tests/pass/boolean/not_mutable.leo index 91a6e5ff37..c621647ff9 100644 --- a/asg/tests/pass/boolean/not_mutable.leo +++ b/asg/tests/pass/boolean/not_mutable.leo @@ -1,4 +1,4 @@ function main () { - let mut b = false; - let a = !b; + let b = false; + const a = !b; } \ No newline at end of file diff --git a/asg/tests/pass/boolean/true_and_false.leo b/asg/tests/pass/boolean/true_and_false.leo index 3c7c484603..336dde7558 100644 --- a/asg/tests/pass/boolean/true_and_false.leo +++ b/asg/tests/pass/boolean/true_and_false.leo @@ -1,5 +1,5 @@ function main() { - let a = true && false; + const a = true && false; console.assert(a == false); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/true_and_true.leo b/asg/tests/pass/boolean/true_and_true.leo index c378e50024..dae445dcf8 100644 --- a/asg/tests/pass/boolean/true_and_true.leo +++ b/asg/tests/pass/boolean/true_and_true.leo @@ -1,5 +1,5 @@ function main() { - let a = true && true; + const a = true && true; console.assert(a == true); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/true_or_false.leo b/asg/tests/pass/boolean/true_or_false.leo index d643a96aa1..216e473cdb 100644 --- a/asg/tests/pass/boolean/true_or_false.leo +++ b/asg/tests/pass/boolean/true_or_false.leo @@ -1,5 +1,5 @@ function main() { - let a = true || false; + const a = true || false; console.assert(a == true); } \ No newline at end of file diff --git a/asg/tests/pass/boolean/true_or_true.leo b/asg/tests/pass/boolean/true_or_true.leo index b8eaa91ff1..fea8628b9f 100644 --- a/asg/tests/pass/boolean/true_or_true.leo +++ b/asg/tests/pass/boolean/true_or_true.leo @@ -1,5 +1,5 @@ function main() { - let a = true || true; + const a = true || true; console.assert(a == true); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/define_circuit_inside_circuit_function.leo b/asg/tests/pass/circuits/define_circuit_inside_circuit_function.leo index 8c25c1e9d9..cedabf2185 100644 --- a/asg/tests/pass/circuits/define_circuit_inside_circuit_function.leo +++ b/asg/tests/pass/circuits/define_circuit_inside_circuit_function.leo @@ -4,10 +4,10 @@ circuit Foo { circuit Bar { function bar() { - let f = Foo { a: 0u32 }; + const f = Foo { a: 0u32 }; } } function main() { - let b = Bar::bar(); + const b = Bar::bar(); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/inline.leo b/asg/tests/pass/circuits/inline.leo index 8e214c729a..9ba06f4191 100644 --- a/asg/tests/pass/circuits/inline.leo +++ b/asg/tests/pass/circuits/inline.leo @@ -3,5 +3,5 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; } \ No newline at end of file diff --git a/asg/tests/pass/circuits/member_function.leo b/asg/tests/pass/circuits/member_function.leo index 3c9aa1aa60..4e50e97195 100644 --- a/asg/tests/pass/circuits/member_function.leo +++ b/asg/tests/pass/circuits/member_function.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let a = Foo { }; + const a = Foo { }; console.assert(a.echo(1u32) == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/member_function_nested.leo b/asg/tests/pass/circuits/member_function_nested.leo index 9e07cc9acf..e512c9df52 100644 --- a/asg/tests/pass/circuits/member_function_nested.leo +++ b/asg/tests/pass/circuits/member_function_nested.leo @@ -11,8 +11,8 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; - let b = a.add_x(1u32); + const a = Foo { x: 1u32 }; + const b = a.add_x(1u32); console.assert(b == 2u32); } diff --git a/asg/tests/pass/circuits/member_static_function.leo b/asg/tests/pass/circuits/member_static_function.leo index 4bf51190f0..9d53314f27 100644 --- a/asg/tests/pass/circuits/member_static_function.leo +++ b/asg/tests/pass/circuits/member_static_function.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let a = Foo::echo(1u32); + const a = Foo::echo(1u32); console.assert(a == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/member_variable.leo b/asg/tests/pass/circuits/member_variable.leo index 0dd35f2aec..a3f3fbe7e6 100644 --- a/asg/tests/pass/circuits/member_variable.leo +++ b/asg/tests/pass/circuits/member_variable.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; console.assert(a.x == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/member_variable_and_function.leo b/asg/tests/pass/circuits/member_variable_and_function.leo index 074feab7b8..3b90db7eaa 100644 --- a/asg/tests/pass/circuits/member_variable_and_function.leo +++ b/asg/tests/pass/circuits/member_variable_and_function.leo @@ -7,9 +7,9 @@ circuit Foo { } function main() { - let a = Foo { foo: 1 }; + const a = Foo { foo: 1 }; - let b = a.foo + Foo::bar(); + const b = a.foo + Foo::bar(); console.assert(b == 2u32); } diff --git a/asg/tests/pass/circuits/mod.rs b/asg/tests/pass/circuits/mod.rs index 811eedd2d4..ee2315b6f7 100644 --- a/asg/tests/pass/circuits/mod.rs +++ b/asg/tests/pass/circuits/mod.rs @@ -54,7 +54,7 @@ fn test_mut_member_function() { } function main() { - let mut a = Foo { }; + let a = Foo { }; console.assert(a.echo(1u32) == 1u32); }"#; diff --git a/asg/tests/pass/circuits/mut_self_variable.leo b/asg/tests/pass/circuits/mut_self_variable.leo index f5a35ec754..92bcca0050 100644 --- a/asg/tests/pass/circuits/mut_self_variable.leo +++ b/asg/tests/pass/circuits/mut_self_variable.leo @@ -8,7 +8,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/asg/tests/pass/circuits/mut_self_variable_conditional.leo b/asg/tests/pass/circuits/mut_self_variable_conditional.leo index 74345afcb4..61a5e354dc 100644 --- a/asg/tests/pass/circuits/mut_self_variable_conditional.leo +++ b/asg/tests/pass/circuits/mut_self_variable_conditional.leo @@ -1,5 +1,5 @@ function main() { - let mut f = Foo { a: 0u32 }; + let f = Foo { a: 0u32 }; f.bar(); } diff --git a/asg/tests/pass/circuits/mut_variable.leo b/asg/tests/pass/circuits/mut_variable.leo index 243d7a2cf2..151babb1cd 100644 --- a/asg/tests/pass/circuits/mut_variable.leo +++ b/asg/tests/pass/circuits/mut_variable.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/asg/tests/pass/circuits/pedersen_mock.leo b/asg/tests/pass/circuits/pedersen_mock.leo index 559ebb7614..4abef65caa 100644 --- a/asg/tests/pass/circuits/pedersen_mock.leo +++ b/asg/tests/pass/circuits/pedersen_mock.leo @@ -6,9 +6,9 @@ circuit PedersenHash { } function hash(self, bits: [bool; 512]) -> u32 { - let mut digest: u32 = 0; + let digest: u32 = 0; for i in 0..512 { - let base = bits[i] ? self.parameters[i] : 0u32; + const base = bits[i] ? self.parameters[i] : 0u32; digest += base; } return digest @@ -17,11 +17,11 @@ circuit PedersenHash { // The 'pedersen_hash' main function. function main() { - let parameters = [0u32; 512]; - let pedersen = PedersenHash::new(parameters); - let hash_input: [bool; 512] = [true; 512]; + const parameters = [0u32; 512]; + const pedersen = PedersenHash::new(parameters); + const hash_input: [bool; 512] = [true; 512]; - let res = pedersen.hash(hash_input); + const res = pedersen.hash(hash_input); console.assert(res == 0u32); } diff --git a/asg/tests/pass/circuits/self_circuit.leo b/asg/tests/pass/circuits/self_circuit.leo index 5a1d6c63be..18329433f7 100644 --- a/asg/tests/pass/circuits/self_circuit.leo +++ b/asg/tests/pass/circuits/self_circuit.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let a = Foo::new(); + const a = Foo::new(); } \ No newline at end of file diff --git a/asg/tests/pass/circuits/self_member.leo b/asg/tests/pass/circuits/self_member.leo index 1bd978433d..2b3401a228 100644 --- a/asg/tests/pass/circuits/self_member.leo +++ b/asg/tests/pass/circuits/self_member.leo @@ -7,8 +7,8 @@ circuit Foo { } function main() { - let a = Foo { f: 1u32 }; - let b = a.bar(); + const a = Foo { f: 1u32 }; + const b = a.bar(); console.assert(b == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/core/blake2s_random.leo b/asg/tests/pass/core/blake2s_random.leo index 72aef44932..c9592fcbf8 100644 --- a/asg/tests/pass/core/blake2s_random.leo +++ b/asg/tests/pass/core/blake2s_random.leo @@ -1,7 +1,7 @@ import core.unstable.blake2s.Blake2s; function main(seed: [u8; 32], message: [u8; 32], expected: [u8; 32]) { - let actual = Blake2s::hash(seed, message); + const actual = Blake2s::hash(seed, message); console.assert(expected == actual); } diff --git a/asg/tests/pass/core/unstable_blake2s.leo b/asg/tests/pass/core/unstable_blake2s.leo index ca7db13892..c430d9a837 100644 --- a/asg/tests/pass/core/unstable_blake2s.leo +++ b/asg/tests/pass/core/unstable_blake2s.leo @@ -1,10 +1,10 @@ import core.unstable.blake2s.Blake2s; function main() { - let seed: [u8; 32] = [0; 32]; - let message: [u8; 32] = [0; 32]; + const seed: [u8; 32] = [0; 32]; + const message: [u8; 32] = [0; 32]; - let result = Blake2s::hash(seed, message); + const result = Blake2s::hash(seed, message); console.log("Result: {}", result); } diff --git a/asg/tests/pass/field/ternary.leo b/asg/tests/pass/field/ternary.leo index f193ad82a3..05cb161b46 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/form_ast.rs b/asg/tests/pass/form_ast.rs index c59e055c1e..3a012d9e14 100644 --- a/asg/tests/pass/form_ast.rs +++ b/asg/tests/pass/form_ast.rs @@ -30,7 +30,7 @@ fn test_basic() { fn test_function_rename() { let program_string = r#" function iteration() -> u32 { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += 1; @@ -40,7 +40,7 @@ fn test_function_rename() { } function main() { - let total = iteration() + iteration(); + const total = iteration() + iteration(); console.assert(total == 20); } diff --git a/asg/tests/pass/function/array_input.leo b/asg/tests/pass/function/array_input.leo index a70483cae7..899c0e4af6 100644 --- a/asg/tests/pass/function/array_input.leo +++ b/asg/tests/pass/function/array_input.leo @@ -1,6 +1,6 @@ function foo(a: [u8; 1]) {} function main() { - let a: [u16; 1] = [1; 1]; + const a: [u16; 1] = [1; 1]; foo(a); } \ No newline at end of file diff --git a/asg/tests/pass/function/iteration.leo b/asg/tests/pass/function/iteration.leo index 19af4dd9cf..b1fcee6964 100644 --- a/asg/tests/pass/function/iteration.leo +++ b/asg/tests/pass/function/iteration.leo @@ -3,7 +3,7 @@ function one() -> u32 { } function main() { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += one(); diff --git a/asg/tests/pass/function/iteration_repeated.leo b/asg/tests/pass/function/iteration_repeated.leo index 3694b3594a..d76380a6b5 100644 --- a/asg/tests/pass/function/iteration_repeated.leo +++ b/asg/tests/pass/function/iteration_repeated.leo @@ -1,5 +1,5 @@ function iteration() -> u32 { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += 1; @@ -9,7 +9,7 @@ function iteration() -> u32 { } function main() { - let total = iteration() + iteration(); + const total = iteration() + iteration(); console.assert(total == 20); } \ No newline at end of file diff --git a/asg/tests/pass/function/mod.rs b/asg/tests/pass/function/mod.rs index abdbd93b7c..3ae7434608 100644 --- a/asg/tests/pass/function/mod.rs +++ b/asg/tests/pass/function/mod.rs @@ -36,7 +36,7 @@ fn test_const_args() { } function main() { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += one(i); @@ -56,8 +56,8 @@ fn test_const_args_used() { } function main() { - let mut a = 0u8; - let arr = [1u8, 2, 3]; + let a = 0u8; + const arr = [1u8, 2, 3]; for i in 0..3 { a += index(arr, i); @@ -77,8 +77,8 @@ fn test_const_args_fail() { } function main(x_value: u32) { - let mut a = 0u8; - let arr = [1u8, 2, 3]; + let a = 0u8; + const arr = [1u8, 2, 3]; a += index(arr, x_value); diff --git a/asg/tests/pass/function/multiple_returns.leo b/asg/tests/pass/function/multiple_returns.leo index ef00a4ef47..d927c51976 100644 --- a/asg/tests/pass/function/multiple_returns.leo +++ b/asg/tests/pass/function/multiple_returns.leo @@ -3,7 +3,7 @@ function tuple() -> (bool, bool) { } function main() { - let (a, b) = tuple(); + const (a, b) = tuple(); console.assert(a == true); console.assert(b == false); diff --git a/asg/tests/pass/function/repeated.leo b/asg/tests/pass/function/repeated.leo index a2d04d55f9..f83fa6098b 100644 --- a/asg/tests/pass/function/repeated.leo +++ b/asg/tests/pass/function/repeated.leo @@ -3,7 +3,7 @@ function one() -> bool { } function main() { - let a = one() && one(); + const a = one() && one(); console.assert(a == true); } \ No newline at end of file diff --git a/asg/tests/pass/function/return_array_nested_pass.leo b/asg/tests/pass/function/return_array_nested_pass.leo index dda5b4342b..bfbfc8fd29 100644 --- a/asg/tests/pass/function/return_array_nested_pass.leo +++ b/asg/tests/pass/function/return_array_nested_pass.leo @@ -7,6 +7,6 @@ function array_3x2_tuple() -> [[u8; 2]; 3] { } function main() { - let a = array_3x2_nested(); - let b = array_3x2_tuple(); + const a = array_3x2_nested(); + const b = array_3x2_tuple(); } \ No newline at end of file diff --git a/asg/tests/pass/function/return_array_tuple_pass.leo b/asg/tests/pass/function/return_array_tuple_pass.leo index a700bcabad..4199e31990 100644 --- a/asg/tests/pass/function/return_array_tuple_pass.leo +++ b/asg/tests/pass/function/return_array_tuple_pass.leo @@ -7,6 +7,6 @@ function array_3x2_tuple() -> [u8; (3, 2)] { } function main() { - let a = array_3x2_nested(); - let b = array_3x2_tuple(); + const a = array_3x2_nested(); + const b = array_3x2_tuple(); } \ No newline at end of file diff --git a/asg/tests/pass/function/return_tuple.leo b/asg/tests/pass/function/return_tuple.leo index c459740a47..a3b1bbc36a 100644 --- a/asg/tests/pass/function/return_tuple.leo +++ b/asg/tests/pass/function/return_tuple.leo @@ -1,11 +1,11 @@ // Returns a tuple of tuples. function tuples() -> ((u8, u8), u32) { - let a: (u8, u8) = (1, 2); - let b: u32 = 3; + const a: (u8, u8) = (1, 2); + const b: u32 = 3; return (a, b) } function main() { - let t = tuples(); + const t = tuples(); } \ No newline at end of file diff --git a/asg/tests/pass/function/return_tuple_conditional.leo b/asg/tests/pass/function/return_tuple_conditional.leo index c63967f548..839081b2a4 100644 --- a/asg/tests/pass/function/return_tuple_conditional.leo +++ b/asg/tests/pass/function/return_tuple_conditional.leo @@ -11,5 +11,5 @@ function tuple_conditional () -> ( } function main() { - let t = tuple_conditional(); + const t = tuple_conditional(); } \ No newline at end of file diff --git a/asg/tests/pass/function/value_unchanged.leo b/asg/tests/pass/function/value_unchanged.leo index 32dcfa62d6..936ff2ddcc 100644 --- a/asg/tests/pass/function/value_unchanged.leo +++ b/asg/tests/pass/function/value_unchanged.leo @@ -12,7 +12,7 @@ function bad_mutate(mut x: u32) { } function main() { - let a = 1u32; + const a = 1u32; bad_mutate(a); console.assert(a == 1u32); // <- value `a` is still `1u32` diff --git a/asg/tests/pass/group/both_sign_high.leo b/asg/tests/pass/group/both_sign_high.leo index a8217d6d40..4c93573e1e 100644 --- a/asg/tests/pass/group/both_sign_high.leo +++ b/asg/tests/pass/group/both_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, +)group; + const element = (+, +)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/both_sign_inferred.leo b/asg/tests/pass/group/both_sign_inferred.leo index b3b8b512c3..0bbd360ba0 100644 --- a/asg/tests/pass/group/both_sign_inferred.leo +++ b/asg/tests/pass/group/both_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, _)group; + const element = (_, _)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/both_sign_low.leo b/asg/tests/pass/group/both_sign_low.leo index 0519c6d17d..1cb4f46c55 100644 --- a/asg/tests/pass/group/both_sign_low.leo +++ b/asg/tests/pass/group/both_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, -)group; + const element = (-, -)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/one.leo b/asg/tests/pass/group/one.leo index 7be0cbbc2c..510110150b 100644 --- a/asg/tests/pass/group/one.leo +++ b/asg/tests/pass/group/one.leo @@ -1,3 +1,3 @@ function main() { - let element = 1group; + const element = 1group; } \ No newline at end of file diff --git a/asg/tests/pass/group/point.leo b/asg/tests/pass/group/point.leo index 85eeb53b7b..5e68415a0d 100644 --- a/asg/tests/pass/group/point.leo +++ b/asg/tests/pass/group/point.leo @@ -1,3 +1,3 @@ function main() { - let point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group; + const point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/point_input.leo b/asg/tests/pass/group/point_input.leo index 68d8c458a3..a3a8e63bd3 100644 --- a/asg/tests/pass/group/point_input.leo +++ b/asg/tests/pass/group/point_input.leo @@ -1,3 +1,3 @@ function main(a: group) { - let b = a; + const b = a; } \ No newline at end of file diff --git a/asg/tests/pass/group/ternary.leo b/asg/tests/pass/group/ternary.leo index fb69b74521..97fba1f5b6 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/group/x_and_y.leo b/asg/tests/pass/group/x_and_y.leo index 1b64702db1..a350a7ad6b 100644 --- a/asg/tests/pass/group/x_and_y.leo +++ b/asg/tests/pass/group/x_and_y.leo @@ -1,3 +1,3 @@ function main(element: group) { - let b = element; + const b = element; } \ No newline at end of file diff --git a/asg/tests/pass/group/x_sign_high.leo b/asg/tests/pass/group/x_sign_high.leo index 1b8d397d02..f38b54ad9a 100644 --- a/asg/tests/pass/group/x_sign_high.leo +++ b/asg/tests/pass/group/x_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, +)group; + const element = (0, +)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/x_sign_inferred.leo b/asg/tests/pass/group/x_sign_inferred.leo index 9e9622a4a4..02c5ac988b 100644 --- a/asg/tests/pass/group/x_sign_inferred.leo +++ b/asg/tests/pass/group/x_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, _)group; + const element = (0, _)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/x_sign_low.leo b/asg/tests/pass/group/x_sign_low.leo index a5058bda52..ad74d18b64 100644 --- a/asg/tests/pass/group/x_sign_low.leo +++ b/asg/tests/pass/group/x_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, -)group; + const element = (0, -)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/y_sign_high.leo b/asg/tests/pass/group/y_sign_high.leo index fe16883b39..af2a20149d 100644 --- a/asg/tests/pass/group/y_sign_high.leo +++ b/asg/tests/pass/group/y_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, 1)group; + const element = (+, 1)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/y_sign_inferred.leo b/asg/tests/pass/group/y_sign_inferred.leo index 003c373cf2..a4efa6a982 100644 --- a/asg/tests/pass/group/y_sign_inferred.leo +++ b/asg/tests/pass/group/y_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, 1)group; + const element = (_, 1)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/y_sign_low.leo b/asg/tests/pass/group/y_sign_low.leo index 9e61bfd2bb..f557ed0d35 100644 --- a/asg/tests/pass/group/y_sign_low.leo +++ b/asg/tests/pass/group/y_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, 1)group; + const element = (-, 1)group; } \ No newline at end of file diff --git a/asg/tests/pass/group/zero.leo b/asg/tests/pass/group/zero.leo index e2c0283c21..6cdd4c960e 100644 --- a/asg/tests/pass/group/zero.leo +++ b/asg/tests/pass/group/zero.leo @@ -1,3 +1,3 @@ function main() { - let element = 0group; + const element = 0group; } \ No newline at end of file diff --git a/asg/tests/pass/import/many_import.leo b/asg/tests/pass/import/many_import.leo index 5e85f19778..08ae494c4f 100644 --- a/asg/tests/pass/import/many_import.leo +++ b/asg/tests/pass/import/many_import.leo @@ -12,15 +12,15 @@ import bar.( // imports directory import import car.Car; // imports directory import function main() { - let point = Point { x: 1u32, y: 1u32 }; - let foo = foo(); + const point = Point { x: 1u32, y: 1u32 }; + const foo = foo(); - let bar = Bar { r: 1u32 }; - let baz = Baz { z: 1u32 }; - let bazzar = Bazzar { a: 1u32 }; - let bat = Bat { t: 1u32 }; + const bar = Bar { r: 1u32 }; + const baz = Baz { z: 1u32 }; + const bazzar = Bazzar { a: 1u32 }; + const bat = Bat { t: 1u32 }; - let car = Car { c: 1u32 }; + const car = Car { c: 1u32 }; console.assert(car.c == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/import/many_import_star.leo b/asg/tests/pass/import/many_import_star.leo index 5145d0d05d..575487a929 100644 --- a/asg/tests/pass/import/many_import_star.leo +++ b/asg/tests/pass/import/many_import_star.leo @@ -6,14 +6,14 @@ import bar.bat.bat.*; // imports directory import import car.*; // imports directory import function main() { - let point = Point { x: 1u32, y: 1u32 }; - let foo = foo(); + const point = Point { x: 1u32, y: 1u32 }; + const foo = foo(); - let bar = Bar { r: 1u32 }; - let bat = Bat { t: 1u32 }; - let baz = Baz { z: 1u32 }; + const bar = Bar { r: 1u32 }; + const bat = Bat { t: 1u32 }; + const baz = Baz { z: 1u32 }; - let car = Car { c: 1u32 }; + const car = Car { c: 1u32 }; console.assert(car.c == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/import/multiple.leo b/asg/tests/pass/import/multiple.leo index 5c89aaee0c..4bd181c02d 100644 --- a/asg/tests/pass/import/multiple.leo +++ b/asg/tests/pass/import/multiple.leo @@ -4,7 +4,7 @@ import test-import.( ); function main() { - let a = Point { x: 1u32, y: 0u32 }; + const a = Point { x: 1u32, y: 0u32 }; console.assert(a.x == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/import/star.leo b/asg/tests/pass/import/star.leo index 9cd817686f..69d0791627 100644 --- a/asg/tests/pass/import/star.leo +++ b/asg/tests/pass/import/star.leo @@ -1,7 +1,7 @@ import test-import.*; function main() { - let a = Point { x: 1u32, y: 0u32 }; + const a = Point { x: 1u32, y: 0u32 }; console.assert(foo() == 1u32); } \ No newline at end of file diff --git a/asg/tests/pass/input_files/program_state/access_all.leo b/asg/tests/pass/input_files/program_state/access_all.leo index 4e7cba5776..2a60f218aa 100644 --- a/asg/tests/pass/input_files/program_state/access_all.leo +++ b/asg/tests/pass/input_files/program_state/access_all.leo @@ -1,7 +1,7 @@ function main(input) { console.assert(input.state.root == [0u8; 32]); - let expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; //console.assert(input.record.owner, expected); console.assert(input.state_leaf.network_id == 0u8); diff --git a/asg/tests/pass/integers/i128/max.leo b/asg/tests/pass/integers/i128/max.leo index 46c0a32599..5ba44213e1 100644 --- a/asg/tests/pass/integers/i128/max.leo +++ b/asg/tests/pass/integers/i128/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = 170141183460469231731687303715884105727; + const a: i128 = 170141183460469231731687303715884105727; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i128/min.leo b/asg/tests/pass/integers/i128/min.leo index 5f32e5add5..19509a3fb0 100644 --- a/asg/tests/pass/integers/i128/min.leo +++ b/asg/tests/pass/integers/i128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = -170141183460469231731687303715884105728; + const a: i128 = -170141183460469231731687303715884105728; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i128/negate_zero.leo b/asg/tests/pass/integers/i128/negate_zero.leo index 9fb0c11afe..e079baf393 100644 --- a/asg/tests/pass/integers/i128/negate_zero.leo +++ b/asg/tests/pass/integers/i128/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i128; + const a = 0i128; console.assert(-a == 0i128); } \ 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 a923c428e6..3783463b22 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i16/max.leo b/asg/tests/pass/integers/i16/max.leo index 084fe4969a..2b70b3cc56 100644 --- a/asg/tests/pass/integers/i16/max.leo +++ b/asg/tests/pass/integers/i16/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = 32767; + const a: i16 = 32767; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i16/min.leo b/asg/tests/pass/integers/i16/min.leo index 3331281fcf..3d05bef95a 100644 --- a/asg/tests/pass/integers/i16/min.leo +++ b/asg/tests/pass/integers/i16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = -32768; + const a: i16 = -32768; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i16/negate_zero.leo b/asg/tests/pass/integers/i16/negate_zero.leo index 46340c3dc5..20f8a4fba7 100644 --- a/asg/tests/pass/integers/i16/negate_zero.leo +++ b/asg/tests/pass/integers/i16/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i16; + const a = 0i16; console.assert(-a == 0i16); } \ 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 4586b87bb4..d66c73cb93 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i32/max.leo b/asg/tests/pass/integers/i32/max.leo index a9c707eb7f..074c75f1a6 100644 --- a/asg/tests/pass/integers/i32/max.leo +++ b/asg/tests/pass/integers/i32/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = 2147483647; + const a: i32 = 2147483647; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i32/min.leo b/asg/tests/pass/integers/i32/min.leo index a29d591029..8436268ce6 100644 --- a/asg/tests/pass/integers/i32/min.leo +++ b/asg/tests/pass/integers/i32/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = -2147483648; + const a: i32 = -2147483648; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i32/negate_zero.leo b/asg/tests/pass/integers/i32/negate_zero.leo index 5533f575a6..a3807b1f8a 100644 --- a/asg/tests/pass/integers/i32/negate_zero.leo +++ b/asg/tests/pass/integers/i32/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i32; + const a = 0i32; console.assert(-a == 0i32); } \ 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 7927c2998b..790769d62f 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i64/max.leo b/asg/tests/pass/integers/i64/max.leo index e0d19881e6..593f91e110 100644 --- a/asg/tests/pass/integers/i64/max.leo +++ b/asg/tests/pass/integers/i64/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = 9223372036854775807; + const a: i64 = 9223372036854775807; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i64/min.leo b/asg/tests/pass/integers/i64/min.leo index d7e99a87f8..794d8fbfac 100644 --- a/asg/tests/pass/integers/i64/min.leo +++ b/asg/tests/pass/integers/i64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = -9223372036854775808; + const a: i64 = -9223372036854775808; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i64/negate_zero.leo b/asg/tests/pass/integers/i64/negate_zero.leo index 6badfe4dc7..81f09c19a3 100644 --- a/asg/tests/pass/integers/i64/negate_zero.leo +++ b/asg/tests/pass/integers/i64/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i64; + const a = 0i64; console.assert(-a == 0i64); } \ 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 1a2d03a77f..df63b3ad6a 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/i8/max.leo b/asg/tests/pass/integers/i8/max.leo index b51126da59..f20d59ddf4 100644 --- a/asg/tests/pass/integers/i8/max.leo +++ b/asg/tests/pass/integers/i8/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = 127; + const a: i8 = 127; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i8/min.leo b/asg/tests/pass/integers/i8/min.leo index d3c1bff5e4..7b6db025ea 100644 --- a/asg/tests/pass/integers/i8/min.leo +++ b/asg/tests/pass/integers/i8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = -128; + const a: i8 = -128; } \ No newline at end of file diff --git a/asg/tests/pass/integers/i8/negate_zero.leo b/asg/tests/pass/integers/i8/negate_zero.leo index 21fbbab675..cc3f4a0828 100644 --- a/asg/tests/pass/integers/i8/negate_zero.leo +++ b/asg/tests/pass/integers/i8/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i8; + const a = 0i8; console.assert(-a == 0i8); } \ 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 e1ec1943c9..0956a9cd39 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u128/max.leo b/asg/tests/pass/integers/u128/max.leo index 6da59dd058..b166ede06b 100644 --- a/asg/tests/pass/integers/u128/max.leo +++ b/asg/tests/pass/integers/u128/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 340282366920938463463374607431768211455; + const a: u128 = 340282366920938463463374607431768211455; } \ No newline at end of file diff --git a/asg/tests/pass/integers/u128/min.leo b/asg/tests/pass/integers/u128/min.leo index 044bda9e1c..41fbf1a2fe 100644 --- a/asg/tests/pass/integers/u128/min.leo +++ b/asg/tests/pass/integers/u128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 0; + const a: u128 = 0; } \ 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 22e2e67058..99a6b997e0 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u16/max.leo b/asg/tests/pass/integers/u16/max.leo index a707df9af8..56cb2af18d 100644 --- a/asg/tests/pass/integers/u16/max.leo +++ b/asg/tests/pass/integers/u16/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 65535; + const a: u16 = 65535; } \ No newline at end of file diff --git a/asg/tests/pass/integers/u16/min.leo b/asg/tests/pass/integers/u16/min.leo index ab1bd7db48..4dee94a1a4 100644 --- a/asg/tests/pass/integers/u16/min.leo +++ b/asg/tests/pass/integers/u16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 0; + const a: u16 = 0; } \ 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 11d836570d..d6131f9f4f 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u32/max.leo b/asg/tests/pass/integers/u32/max.leo index 2950164a08..4a07281b5d 100644 --- a/asg/tests/pass/integers/u32/max.leo +++ b/asg/tests/pass/integers/u32/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 4294967295; + const a: u32 = 4294967295; } \ No newline at end of file diff --git a/asg/tests/pass/integers/u32/min.leo b/asg/tests/pass/integers/u32/min.leo index 0f1c080938..8077e0ec02 100644 --- a/asg/tests/pass/integers/u32/min.leo +++ b/asg/tests/pass/integers/u32/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + const a: u32 = 0; } \ 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 3c96a7236c..f32ffc29fe 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u64/max.leo b/asg/tests/pass/integers/u64/max.leo index 985897c006..f14ac7ce64 100644 --- a/asg/tests/pass/integers/u64/max.leo +++ b/asg/tests/pass/integers/u64/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 18446744073709551615; + const a: u64 = 18446744073709551615; } \ No newline at end of file diff --git a/asg/tests/pass/integers/u64/min.leo b/asg/tests/pass/integers/u64/min.leo index aa9b72fc8a..b1da40b14c 100644 --- a/asg/tests/pass/integers/u64/min.leo +++ b/asg/tests/pass/integers/u64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 0; + const a: u64 = 0; } \ 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 4c4ddd8e0c..4427cd0466 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/integers/u8/max.leo b/asg/tests/pass/integers/u8/max.leo index 684bdfba10..03e82c9a5e 100644 --- a/asg/tests/pass/integers/u8/max.leo +++ b/asg/tests/pass/integers/u8/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 255; + const a: u8 = 255; } \ No newline at end of file diff --git a/asg/tests/pass/integers/u8/min.leo b/asg/tests/pass/integers/u8/min.leo index a88e33c5a6..1db08a07b5 100644 --- a/asg/tests/pass/integers/u8/min.leo +++ b/asg/tests/pass/integers/u8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 0; + const a: u8 = 0; } \ 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 1b436aa054..5123a511cd 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/asg/tests/pass/mutability/array_mut.leo b/asg/tests/pass/mutability/array_mut.leo index 1b86bac80f..5d4db3b68a 100644 --- a/asg/tests/pass/mutability/array_mut.leo +++ b/asg/tests/pass/mutability/array_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [1u32]; + let a = [1u32]; a[0] = 0; console.assert(a[0] == 0u32); diff --git a/asg/tests/pass/mutability/array_splice_mut.leo b/asg/tests/pass/mutability/array_splice_mut.leo index 57cc67e872..d13216600a 100644 --- a/asg/tests/pass/mutability/array_splice_mut.leo +++ b/asg/tests/pass/mutability/array_splice_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [1u32, 2u32, 3u32]; + let a = [1u32, 2u32, 3u32]; a[0u32..2u32] = [4u32, 5u32]; console.assert(a[0] == 4u32); diff --git a/asg/tests/pass/mutability/array_tuple_mut.leo b/asg/tests/pass/mutability/array_tuple_mut.leo index e0096bd7ac..ed323d46da 100644 --- a/asg/tests/pass/mutability/array_tuple_mut.leo +++ b/asg/tests/pass/mutability/array_tuple_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [(1u32, 2u32)]; + let a = [(1u32, 2u32)]; a[0u32].1 = 3u32; console.assert(a[0u32].0 == 1u32); diff --git a/asg/tests/pass/mutability/circuit_mut.leo b/asg/tests/pass/mutability/circuit_mut.leo index 27bd6109b2..f7067db11e 100644 --- a/asg/tests/pass/mutability/circuit_mut.leo +++ b/asg/tests/pass/mutability/circuit_mut.leo @@ -4,7 +4,7 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.x = 0; console.assert(a.x == 0u32); diff --git a/asg/tests/pass/mutability/circuit_variable_mut.leo b/asg/tests/pass/mutability/circuit_variable_mut.leo index 27bd6109b2..f7067db11e 100644 --- a/asg/tests/pass/mutability/circuit_variable_mut.leo +++ b/asg/tests/pass/mutability/circuit_variable_mut.leo @@ -4,7 +4,7 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.x = 0; console.assert(a.x == 0u32); diff --git a/asg/tests/pass/mutability/let_mut.leo b/asg/tests/pass/mutability/let_mut.leo index 5766d144d3..cd1060d0d2 100644 --- a/asg/tests/pass/mutability/let_mut.leo +++ b/asg/tests/pass/mutability/let_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes a variable mutable. function main() { - let mut a = 1u32; + let a = 1u32; a = 0; console.assert(a == 0u32); diff --git a/asg/tests/pass/mutability/let_mut_nested.leo b/asg/tests/pass/mutability/let_mut_nested.leo index 27121f6e48..93236ef4c6 100644 --- a/asg/tests/pass/mutability/let_mut_nested.leo +++ b/asg/tests/pass/mutability/let_mut_nested.leo @@ -1,5 +1,5 @@ function main () { - let mut x = 2u8; - let mut y = x; - let z = y / 2u8; + let x = 2u8; + let y = x; + const z = y / 2u8; } \ No newline at end of file diff --git a/asg/tests/pass/mutability/swap.leo b/asg/tests/pass/mutability/swap.leo index 0a209149ee..b2a795e826 100644 --- a/asg/tests/pass/mutability/swap.leo +++ b/asg/tests/pass/mutability/swap.leo @@ -1,17 +1,17 @@ // Swap two elements of an array. function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { - let t = a[i]; + const 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]; + let arr: [u32; 2] = [0, 1]; + const expected: [u32; 2] = [1, 0]; // Do swap. - let actual = swap(arr, 0, 1); + const actual = swap(arr, 0, 1); // Check result. for i in 0..2 { diff --git a/asg/tests/pass/statements/block.leo b/asg/tests/pass/statements/block.leo index 8650808041..ca8da645ec 100644 --- a/asg/tests/pass/statements/block.leo +++ b/asg/tests/pass/statements/block.leo @@ -1,5 +1,5 @@ function main() { - let mut x = 4u32; + let x = 4u32; { x = 5u32; diff --git a/asg/tests/pass/statements/conditional/chain.leo b/asg/tests/pass/statements/conditional/chain.leo index dbc0e1f38c..44d4e86243 100644 --- a/asg/tests/pass/statements/conditional/chain.leo +++ b/asg/tests/pass/statements/conditional/chain.leo @@ -1,5 +1,5 @@ function main(a: u32, b: u32) { - let mut c = 0u32; + let c = 0u32; if a == 1 { c = 1; diff --git a/asg/tests/pass/statements/conditional/for_loop.leo b/asg/tests/pass/statements/conditional/for_loop.leo index 2dca076858..db307f3c36 100644 --- a/asg/tests/pass/statements/conditional/for_loop.leo +++ b/asg/tests/pass/statements/conditional/for_loop.leo @@ -1,5 +1,5 @@ function main(a: bool) { - let mut b = 0u32; + let b = 0u32; if a { for i in 0..4 { @@ -7,7 +7,7 @@ function main(a: bool) { } } - let r: u32 = a ? 6 : 0; + const r: u32 = a ? 6 : 0; console.assert(r == b); } diff --git a/asg/tests/pass/statements/conditional/mutate.leo b/asg/tests/pass/statements/conditional/mutate.leo index 458d3d0d60..9bb124eefd 100644 --- a/asg/tests/pass/statements/conditional/mutate.leo +++ b/asg/tests/pass/statements/conditional/mutate.leo @@ -1,5 +1,5 @@ function main(a: u32) { - let mut b = 5u32; + let b = 5u32; if a == 1 { b = 1; diff --git a/asg/tests/pass/statements/conditional/nested.leo b/asg/tests/pass/statements/conditional/nested.leo index 3596f889d1..1849c2a339 100644 --- a/asg/tests/pass/statements/conditional/nested.leo +++ b/asg/tests/pass/statements/conditional/nested.leo @@ -1,5 +1,5 @@ function main(a: bool, b: bool, c: u32) { - let mut d = 0u32; + let d = 0u32; if a { d += 1; diff --git a/asg/tests/pass/statements/iteration_basic.leo b/asg/tests/pass/statements/iteration_basic.leo index 103c9abb9e..5d74e69a1f 100644 --- a/asg/tests/pass/statements/iteration_basic.leo +++ b/asg/tests/pass/statements/iteration_basic.leo @@ -1,5 +1,5 @@ function main() { - let mut x = 4u32; + let x = 4u32; for i in 0..3 { x -= 1; } diff --git a/asg/tests/pass/statements/ternary_basic.leo b/asg/tests/pass/statements/ternary_basic.leo index 675b681fa9..38359004a9 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 = a ? true : false; + const c = a ? true : false; - let d = c == b; + const d = c == b; } \ No newline at end of file diff --git a/asg/tests/pass/tuples/access.leo b/asg/tests/pass/tuples/access.leo index 196e9d058c..9277f4ecc5 100644 --- a/asg/tests/pass/tuples/access.leo +++ b/asg/tests/pass/tuples/access.leo @@ -1,5 +1,5 @@ function main() { - let a = (true, false); + const a = (true, false); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/asg/tests/pass/tuples/basic.leo b/asg/tests/pass/tuples/basic.leo index 37c728611c..2e777f2797 100644 --- a/asg/tests/pass/tuples/basic.leo +++ b/asg/tests/pass/tuples/basic.leo @@ -1,3 +1,3 @@ function main() { - let a = (true, false); + const a = (true, false); } \ No newline at end of file diff --git a/asg/tests/pass/tuples/function.leo b/asg/tests/pass/tuples/function.leo index b318348813..4222b858cb 100644 --- a/asg/tests/pass/tuples/function.leo +++ b/asg/tests/pass/tuples/function.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let a = foo(); + const a = foo(); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/asg/tests/pass/tuples/function_multiple.leo b/asg/tests/pass/tuples/function_multiple.leo index 39848377c6..73fbe277ae 100644 --- a/asg/tests/pass/tuples/function_multiple.leo +++ b/asg/tests/pass/tuples/function_multiple.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let (a, b) = foo(); + const (a, b) = foo(); console.assert(a == true); console.assert(b == false); diff --git a/asg/tests/pass/tuples/function_typed.leo b/asg/tests/pass/tuples/function_typed.leo index 8af2c907ca..f89e7a3273 100644 --- a/asg/tests/pass/tuples/function_typed.leo +++ b/asg/tests/pass/tuples/function_typed.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let a: (bool, bool) = foo(); + const a: (bool, bool) = foo(); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/asg/tests/pass/tuples/multiple.leo b/asg/tests/pass/tuples/multiple.leo index b7627dad2a..2cb003b0e1 100644 --- a/asg/tests/pass/tuples/multiple.leo +++ b/asg/tests/pass/tuples/multiple.leo @@ -1,5 +1,5 @@ function main() { - let (a, b) = (true, false); + const (a, b) = (true, false); console.assert(a == true); console.assert(b == false); diff --git a/asg/tests/pass/tuples/multiple_typed.leo b/asg/tests/pass/tuples/multiple_typed.leo index 29fc7ef877..bbe4a01858 100644 --- a/asg/tests/pass/tuples/multiple_typed.leo +++ b/asg/tests/pass/tuples/multiple_typed.leo @@ -1,5 +1,5 @@ function main() { - let (a, b): (bool, bool) = (true, false); + const (a, b): (bool, bool) = (true, false); console.assert(a == true); console.assert(b == false); diff --git a/asg/tests/pass/tuples/nested.leo b/asg/tests/pass/tuples/nested.leo index a9599b360c..bbdb2394a8 100644 --- a/asg/tests/pass/tuples/nested.leo +++ b/asg/tests/pass/tuples/nested.leo @@ -1,4 +1,4 @@ function main() { - let a = (true, false); - let b = (true, a); + const a = (true, false); + const b = (true, a); } \ No newline at end of file diff --git a/asg/tests/pass/tuples/nested_access.leo b/asg/tests/pass/tuples/nested_access.leo index 5edba64e24..f21fa59bba 100644 --- a/asg/tests/pass/tuples/nested_access.leo +++ b/asg/tests/pass/tuples/nested_access.leo @@ -1,6 +1,6 @@ function main() { - let a = (true, false); - let b = (true, a); + const a = (true, false); + const b = (true, a); console.assert(b.0 == true); console.assert(b.1.0 == true); diff --git a/asg/tests/pass/tuples/nested_typed.leo b/asg/tests/pass/tuples/nested_typed.leo index 2e68117a2b..44a10b2a3e 100644 --- a/asg/tests/pass/tuples/nested_typed.leo +++ b/asg/tests/pass/tuples/nested_typed.leo @@ -1,4 +1,4 @@ function main() { - let a = (true, false); - let b: (bool, (bool, bool)) = (true, a); + const a = (true, false); + const b: (bool, (bool, bool)) = (true, a); } \ No newline at end of file diff --git a/asg/tests/pass/tuples/typed.leo b/asg/tests/pass/tuples/typed.leo index 8cd2ed79db..8f623fc148 100644 --- a/asg/tests/pass/tuples/typed.leo +++ b/asg/tests/pass/tuples/typed.leo @@ -1,3 +1,3 @@ function main() { - let a: (bool, bool) = (true, false); + const a: (bool, bool) = (true, false); } \ No newline at end of file diff --git a/compiler/tests/address/console_assert_fail.leo b/compiler/tests/address/console_assert_fail.leo index 3e7a5f106d..17849256ca 100644 --- a/compiler/tests/address/console_assert_fail.leo +++ b/compiler/tests/address/console_assert_fail.leo @@ -1,6 +1,6 @@ function main() { - let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9); + const address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9); console.assert(address_1 == address_2); } \ No newline at end of file diff --git a/compiler/tests/address/console_assert_pass.leo b/compiler/tests/address/console_assert_pass.leo index 60ea4a79cd..f17d7d8c05 100644 --- a/compiler/tests/address/console_assert_pass.leo +++ b/compiler/tests/address/console_assert_pass.leo @@ -1,6 +1,6 @@ function main() { - let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); console.assert(address_1 == address_2); } \ No newline at end of file diff --git a/compiler/tests/address/empty.leo b/compiler/tests/address/empty.leo index e5c06d0def..305a77de5b 100644 --- a/compiler/tests/address/empty.leo +++ b/compiler/tests/address/empty.leo @@ -1,3 +1,3 @@ function main() { - let owner = address(); + const owner = address(); } \ No newline at end of file diff --git a/compiler/tests/address/implicit_invalid.leo b/compiler/tests/address/implicit_invalid.leo index 6f8eba5114..aadc38a6d8 100644 --- a/compiler/tests/address/implicit_invalid.leo +++ b/compiler/tests/address/implicit_invalid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; } \ No newline at end of file diff --git a/compiler/tests/address/implicit_valid.leo b/compiler/tests/address/implicit_valid.leo index df6ebf497d..75bcbaa8a1 100644 --- a/compiler/tests/address/implicit_valid.leo +++ b/compiler/tests/address/implicit_valid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; } \ No newline at end of file diff --git a/compiler/tests/address/input.leo b/compiler/tests/address/input.leo index 795deac98b..29519f0334 100644 --- a/compiler/tests/address/input.leo +++ b/compiler/tests/address/input.leo @@ -1,5 +1,5 @@ function main(owner: address) { - let sender = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const sender = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); console.assert(owner == sender); } \ No newline at end of file diff --git a/compiler/tests/address/invalid_length.leo b/compiler/tests/address/invalid_length.leo index c1b7f719be..ae1defecaf 100644 --- a/compiler/tests/address/invalid_length.leo +++ b/compiler/tests/address/invalid_length.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88); + const public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88); } \ No newline at end of file diff --git a/compiler/tests/address/invalid_prefix.leo b/compiler/tests/address/invalid_prefix.leo index 81959d2fa6..cd87e404a4 100644 --- a/compiler/tests/address/invalid_prefix.leo +++ b/compiler/tests/address/invalid_prefix.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const public_key_string = address(zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); } \ No newline at end of file diff --git a/compiler/tests/address/ternary.leo b/compiler/tests/address/ternary.leo index bdd88b9d92..dc87153d2d 100644 --- a/compiler/tests/address/ternary.leo +++ b/compiler/tests/address/ternary.leo @@ -1,8 +1,8 @@ function main(s: bool, c: address) { - let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); + const a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); - let r = s? a: b; + const r = s? a: b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/address/valid.leo b/compiler/tests/address/valid.leo index f06aefdaa6..18f1682526 100644 --- a/compiler/tests/address/valid.leo +++ b/compiler/tests/address/valid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); } \ No newline at end of file diff --git a/compiler/tests/array/input/inline_fail.leo b/compiler/tests/array/input/inline_fail.leo index 1e380be10d..72fd3be66c 100644 --- a/compiler/tests/array/input/inline_fail.leo +++ b/compiler/tests/array/input/inline_fail.leo @@ -1,3 +1,3 @@ function main() { - let a = [1u8, bool]; + const a = [1u8, bool]; } diff --git a/compiler/tests/array/multi_fail_initializer.leo b/compiler/tests/array/multi_fail_initializer.leo index 258750b327..be1ab315bd 100644 --- a/compiler/tests/array/multi_fail_initializer.leo +++ b/compiler/tests/array/multi_fail_initializer.leo @@ -1,3 +1,3 @@ function main() { - let arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions + const arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions } \ No newline at end of file diff --git a/compiler/tests/array/multi_fail_inline.leo b/compiler/tests/array/multi_fail_inline.leo index 50a06c09b2..49c9296798 100644 --- a/compiler/tests/array/multi_fail_inline.leo +++ b/compiler/tests/array/multi_fail_inline.leo @@ -1,4 +1,4 @@ function main() { - let arr: [u8; (2, 2)] = [[1u8, 1u8], + const arr: [u8; (2, 2)] = [[1u8, 1u8], [1u8]]; // incorrect dimensions } \ No newline at end of file diff --git a/compiler/tests/array/multi_initializer.leo b/compiler/tests/array/multi_initializer.leo index 7257999ddf..6133542ef0 100644 --- a/compiler/tests/array/multi_initializer.leo +++ b/compiler/tests/array/multi_initializer.leo @@ -1,7 +1,7 @@ function main() { - let a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; + const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; - let b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2]; + const b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2]; console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/multi_initializer_fail.leo b/compiler/tests/array/multi_initializer_fail.leo index 0bd76acffa..e38a8fdaee 100644 --- a/compiler/tests/array/multi_initializer_fail.leo +++ b/compiler/tests/array/multi_initializer_fail.leo @@ -1,3 +1,3 @@ function main() { - let arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions + const arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions } \ No newline at end of file diff --git a/compiler/tests/array/nested.leo b/compiler/tests/array/nested.leo index c557758b05..80fc5511bf 100644 --- a/compiler/tests/array/nested.leo +++ b/compiler/tests/array/nested.leo @@ -1,4 +1,4 @@ function main () { - let x = [false; (2, 2)]; - let y: bool = x[0][0]; + const x = [false; (2, 2)]; + const y: bool = x[0][0]; } diff --git a/compiler/tests/array/nested_3x2_value.leo b/compiler/tests/array/nested_3x2_value.leo index b69ddffb89..c5f64c997e 100644 --- a/compiler/tests/array/nested_3x2_value.leo +++ b/compiler/tests/array/nested_3x2_value.leo @@ -1,8 +1,8 @@ // Multidimensional array syntax in leo function main() { - let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline - let b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer + const b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/nested_3x2_value_fail.leo b/compiler/tests/array/nested_3x2_value_fail.leo index 35c8478cd1..a187a51991 100644 --- a/compiler/tests/array/nested_3x2_value_fail.leo +++ b/compiler/tests/array/nested_3x2_value_fail.leo @@ -1,4 +1,4 @@ // Multidimensional array syntax in leo function main() { - let a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) + const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) } diff --git a/compiler/tests/array/slice.leo b/compiler/tests/array/slice.leo index 296f5bd050..9ff83dbbb8 100644 --- a/compiler/tests/array/slice.leo +++ b/compiler/tests/array/slice.leo @@ -1,6 +1,6 @@ // `{from}..{to}` copies the elements of one array into another exclusively function main(a: [u8; 3]) { - let b = [1u8; 4]; + const b = [1u8; 4]; console.assert(a == b[0..3]); } diff --git a/compiler/tests/array/slice_lower.leo b/compiler/tests/array/slice_lower.leo index dd669830ea..0af6fbd937 100644 --- a/compiler/tests/array/slice_lower.leo +++ b/compiler/tests/array/slice_lower.leo @@ -1,8 +1,8 @@ function main() { - let arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; - let expected: [u32; 2] = [0, 1]; + const arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + const expected: [u32; 2] = [0, 1]; - let actual = arr[..2]; // Should produce [0, 1] + const actual = arr[..2]; // Should produce [0, 1] console.assert(expected == actual); } \ No newline at end of file diff --git a/compiler/tests/array/spread.leo b/compiler/tests/array/spread.leo index 962e92c923..8bd2861aae 100644 --- a/compiler/tests/array/spread.leo +++ b/compiler/tests/array/spread.leo @@ -1,7 +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]; + const b = [1u8, 1u8]; + const c = [1u8, ...b]; console.assert(a == c); } \ No newline at end of file diff --git a/compiler/tests/array/tuple_3x2_value.leo b/compiler/tests/array/tuple_3x2_value.leo index dc9128c51e..b6659539d5 100644 --- a/compiler/tests/array/tuple_3x2_value.leo +++ b/compiler/tests/array/tuple_3x2_value.leo @@ -1,8 +1,8 @@ // Multidimensional array syntax in leo function main() { - let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline - let b: [u32; (3, 2)] = [0; (3, 2)]; // initializer + const b: [u32; (3, 2)] = [0; (3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/tuple_3x2_value_fail.leo b/compiler/tests/array/tuple_3x2_value_fail.leo index 42e6f61500..78593ab696 100644 --- a/compiler/tests/array/tuple_3x2_value_fail.leo +++ b/compiler/tests/array/tuple_3x2_value_fail.leo @@ -1,4 +1,4 @@ // Multidimensional array syntax in leo function main() { - let a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) + const a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) } diff --git a/compiler/tests/array/type_fail.leo b/compiler/tests/array/type_fail.leo index 1402ceba4c..356bba976a 100644 --- a/compiler/tests/array/type_fail.leo +++ b/compiler/tests/array/type_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: [u8; -2] = [0u32; 2]; + const a: [u8; -2] = [0u32; 2]; } \ No newline at end of file diff --git a/compiler/tests/array/type_input_3x2.leo b/compiler/tests/array/type_input_3x2.leo index 40781415c1..ea60a0cc24 100644 --- a/compiler/tests/array/type_input_3x2.leo +++ b/compiler/tests/array/type_input_3x2.leo @@ -1,5 +1,5 @@ function main(a: [[u8; 2]; 3]) { - let b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_input_4x3x2.leo b/compiler/tests/array/type_input_4x3x2.leo index bd75514904..2d9c4cff22 100644 --- a/compiler/tests/array/type_input_4x3x2.leo +++ b/compiler/tests/array/type_input_4x3x2.leo @@ -1,5 +1,5 @@ function main(a: [[[u8; 2]; 3]; 4]) { - let b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 diff --git a/compiler/tests/array/type_nested_value_nested_3x2.leo b/compiler/tests/array/type_nested_value_nested_3x2.leo index 341b9ead9c..bcf5bae674 100644 --- a/compiler/tests/array/type_nested_value_nested_3x2.leo +++ b/compiler/tests/array/type_nested_value_nested_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer + const b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_nested_3x2_fail.leo b/compiler/tests/array/type_nested_value_nested_3x2_fail.leo index 4bd07f85db..56c8916fb0 100644 --- a/compiler/tests/array/type_nested_value_nested_3x2_fail.leo +++ b/compiler/tests/array/type_nested_value_nested_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) + const b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_nested_4x3x2.leo b/compiler/tests/array/type_nested_value_nested_4x3x2.leo index 5ba24a381b..1691fa26c7 100644 --- a/compiler/tests/array/type_nested_value_nested_4x3x2.leo +++ b/compiler/tests/array/type_nested_value_nested_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [[[u8; 2]; 3]; 4] = [[[0; 2]; 3]; 4]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_nested_4x3x2_fail.leo b/compiler/tests/array/type_nested_value_nested_4x3x2_fail.leo index 6479004d68..480327a91d 100644 --- a/compiler/tests/array/type_nested_value_nested_4x3x2_fail.leo +++ b/compiler/tests/array/type_nested_value_nested_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) + const b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_tuple_3x2.leo b/compiler/tests/array/type_nested_value_tuple_3x2.leo index c6fac9ec64..5f14084d55 100644 --- a/compiler/tests/array/type_nested_value_tuple_3x2.leo +++ b/compiler/tests/array/type_nested_value_tuple_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer + const b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_tuple_3x2_fail.leo b/compiler/tests/array/type_nested_value_tuple_3x2_fail.leo index ba99b070c7..3bfb559615 100644 --- a/compiler/tests/array/type_nested_value_tuple_3x2_fail.leo +++ b/compiler/tests/array/type_nested_value_tuple_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) + const b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_tuple_4x3x2.leo b/compiler/tests/array/type_nested_value_tuple_4x3x2.leo index 9be45de408..88a5143bd2 100644 --- a/compiler/tests/array/type_nested_value_tuple_4x3x2.leo +++ b/compiler/tests/array/type_nested_value_tuple_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [[[u8; 2]; 3]; 4] = [0; (4, 3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_nested_value_tuple_4x3x2_fail.leo b/compiler/tests/array/type_nested_value_tuple_4x3x2_fail.leo index 95172bf329..ce1219a37b 100644 --- a/compiler/tests/array/type_nested_value_tuple_4x3x2_fail.leo +++ b/compiler/tests/array/type_nested_value_tuple_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering) + const b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_nested_3x2.leo b/compiler/tests/array/type_tuple_value_nested_3x2.leo index 4e061c4309..81195e03a1 100644 --- a/compiler/tests/array/type_tuple_value_nested_3x2.leo +++ b/compiler/tests/array/type_tuple_value_nested_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer + const b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_nested_3x2_fail.leo b/compiler/tests/array/type_tuple_value_nested_3x2_fail.leo index 9732cf26ef..e84f025a9f 100644 --- a/compiler/tests/array/type_tuple_value_nested_3x2_fail.leo +++ b/compiler/tests/array/type_tuple_value_nested_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering) + const b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_nested_4x3x2.leo b/compiler/tests/array/type_tuple_value_nested_4x3x2.leo index d9dc698784..322a6f7601 100644 --- a/compiler/tests/array/type_tuple_value_nested_4x3x2.leo +++ b/compiler/tests/array/type_tuple_value_nested_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [u8; (4, 3, 2)] = [[[0; 2]; 3]; 4]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_nested_4x3x2_fail.leo b/compiler/tests/array/type_tuple_value_nested_4x3x2_fail.leo index b820c4d088..cbb7ccbf76 100644 --- a/compiler/tests/array/type_tuple_value_nested_4x3x2_fail.leo +++ b/compiler/tests/array/type_tuple_value_nested_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) + const b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_tuple_3x2.leo b/compiler/tests/array/type_tuple_value_tuple_3x2.leo index b0693f7667..d451a9c1a8 100644 --- a/compiler/tests/array/type_tuple_value_tuple_3x2.leo +++ b/compiler/tests/array/type_tuple_value_tuple_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (3, 2)] = [0; (3, 2)]; // initializer + const b: [u8; (3, 2)] = [0; (3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_tuple_3x2_fail.leo b/compiler/tests/array/type_tuple_value_tuple_3x2_fail.leo index 99487ccb7a..884a75db9d 100644 --- a/compiler/tests/array/type_tuple_value_tuple_3x2_fail.leo +++ b/compiler/tests/array/type_tuple_value_tuple_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering) + const b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering) } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_tuple_4x3x2.leo b/compiler/tests/array/type_tuple_value_tuple_4x3x2.leo index cdc1bc961e..1205b1dc9c 100644 --- a/compiler/tests/array/type_tuple_value_tuple_4x3x2.leo +++ b/compiler/tests/array/type_tuple_value_tuple_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const b: [u8; (4, 3, 2)] = [0; (4, 3, 2)]; // initializer console.assert(a == b); } \ No newline at end of file diff --git a/compiler/tests/array/type_tuple_value_tuple_4x3x2_fail.leo b/compiler/tests/array/type_tuple_value_tuple_4x3x2_fail.leo index 824fd90bc6..31e2a5e552 100644 --- a/compiler/tests/array/type_tuple_value_tuple_4x3x2_fail.leo +++ b/compiler/tests/array/type_tuple_value_tuple_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order) + const b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order) } \ No newline at end of file diff --git a/compiler/tests/array/variable_slice_fail.leo b/compiler/tests/array/variable_slice_fail.leo index edb04caacf..e79d64112f 100644 --- a/compiler/tests/array/variable_slice_fail.leo +++ b/compiler/tests/array/variable_slice_fail.leo @@ -1,7 +1,7 @@ function main() { - let a = [1u8; 10]; + const a = [1u8; 10]; for i in 0..10 { - let x = a[i..10]; + const x = a[i..10]; console.debug("{}", x); } } \ No newline at end of file diff --git a/compiler/tests/boolean/all.leo b/compiler/tests/boolean/all.leo index 29a3815881..64fe8a795a 100644 --- a/compiler/tests/boolean/all.leo +++ b/compiler/tests/boolean/all.leo @@ -1,8 +1,8 @@ // !(true && (false || true)) function main() { - let a = true; - let b = false || a; - let c = !(true && b); + const a = true; + const b = false || a; + const c = !(true && b); console.assert(c == false); } \ No newline at end of file diff --git a/compiler/tests/boolean/conditional_mut.leo b/compiler/tests/boolean/conditional_mut.leo index e6716cb05a..cebf82ab00 100644 --- a/compiler/tests/boolean/conditional_mut.leo +++ b/compiler/tests/boolean/conditional_mut.leo @@ -1,6 +1,6 @@ function main () { - let mut x = true; + let x = true; if x { - let y = 0u8; + const y = 0u8; } } \ No newline at end of file diff --git a/compiler/tests/boolean/false_and_false.leo b/compiler/tests/boolean/false_and_false.leo index 70e4b0797b..03dfabab4d 100644 --- a/compiler/tests/boolean/false_and_false.leo +++ b/compiler/tests/boolean/false_and_false.leo @@ -1,5 +1,5 @@ function main() { - let a = false && false; + const a = false && false; console.assert(a == false); } \ No newline at end of file diff --git a/compiler/tests/boolean/false_or_false.leo b/compiler/tests/boolean/false_or_false.leo index 4ae820254e..7ea710802c 100644 --- a/compiler/tests/boolean/false_or_false.leo +++ b/compiler/tests/boolean/false_or_false.leo @@ -1,5 +1,5 @@ function main() { - let a = false || false; + const a = false || false; console.assert(a == false); } \ No newline at end of file diff --git a/compiler/tests/boolean/not_mutable.leo b/compiler/tests/boolean/not_mutable.leo index 91a6e5ff37..c621647ff9 100644 --- a/compiler/tests/boolean/not_mutable.leo +++ b/compiler/tests/boolean/not_mutable.leo @@ -1,4 +1,4 @@ function main () { - let mut b = false; - let a = !b; + let b = false; + const a = !b; } \ No newline at end of file diff --git a/compiler/tests/boolean/true_and_false.leo b/compiler/tests/boolean/true_and_false.leo index 3c7c484603..336dde7558 100644 --- a/compiler/tests/boolean/true_and_false.leo +++ b/compiler/tests/boolean/true_and_false.leo @@ -1,5 +1,5 @@ function main() { - let a = true && false; + const a = true && false; console.assert(a == false); } \ No newline at end of file diff --git a/compiler/tests/boolean/true_and_true.leo b/compiler/tests/boolean/true_and_true.leo index c378e50024..dae445dcf8 100644 --- a/compiler/tests/boolean/true_and_true.leo +++ b/compiler/tests/boolean/true_and_true.leo @@ -1,5 +1,5 @@ function main() { - let a = true && true; + const a = true && true; console.assert(a == true); } \ No newline at end of file diff --git a/compiler/tests/boolean/true_and_u32.leo b/compiler/tests/boolean/true_and_u32.leo index e5b3a8c001..ad3ead9040 100644 --- a/compiler/tests/boolean/true_and_u32.leo +++ b/compiler/tests/boolean/true_and_u32.leo @@ -1,3 +1,3 @@ function main() { - let a = true && 1u32; + const a = true && 1u32; } \ No newline at end of file diff --git a/compiler/tests/boolean/true_or_false.leo b/compiler/tests/boolean/true_or_false.leo index d643a96aa1..216e473cdb 100644 --- a/compiler/tests/boolean/true_or_false.leo +++ b/compiler/tests/boolean/true_or_false.leo @@ -1,5 +1,5 @@ function main() { - let a = true || false; + const a = true || false; console.assert(a == true); } \ No newline at end of file diff --git a/compiler/tests/boolean/true_or_true.leo b/compiler/tests/boolean/true_or_true.leo index b8eaa91ff1..fea8628b9f 100644 --- a/compiler/tests/boolean/true_or_true.leo +++ b/compiler/tests/boolean/true_or_true.leo @@ -1,5 +1,5 @@ function main() { - let a = true || true; + const a = true || true; console.assert(a == true); } \ No newline at end of file diff --git a/compiler/tests/boolean/true_or_u32.leo b/compiler/tests/boolean/true_or_u32.leo index 500b5f7bf4..38dab727b9 100644 --- a/compiler/tests/boolean/true_or_u32.leo +++ b/compiler/tests/boolean/true_or_u32.leo @@ -1,3 +1,3 @@ function main() { - let a = true || 1u32; + const a = true || 1u32; } \ No newline at end of file diff --git a/compiler/tests/circuits/define_circuit_inside_circuit_function.leo b/compiler/tests/circuits/define_circuit_inside_circuit_function.leo index 8c25c1e9d9..cedabf2185 100644 --- a/compiler/tests/circuits/define_circuit_inside_circuit_function.leo +++ b/compiler/tests/circuits/define_circuit_inside_circuit_function.leo @@ -4,10 +4,10 @@ circuit Foo { circuit Bar { function bar() { - let f = Foo { a: 0u32 }; + const f = Foo { a: 0u32 }; } } function main() { - let b = Bar::bar(); + const b = Bar::bar(); } \ No newline at end of file diff --git a/compiler/tests/circuits/duplicate_name_context.leo b/compiler/tests/circuits/duplicate_name_context.leo index 98ff42d8f0..66640e75a2 100644 --- a/compiler/tests/circuits/duplicate_name_context.leo +++ b/compiler/tests/circuits/duplicate_name_context.leo @@ -7,7 +7,7 @@ circuit Bar { } function main () { - let Bar = 66u32; - let k1 = Bar{ b2: 30u32 }; - let k2 = Bar::add_five(55u32); + const Bar = 66u32; + const k1 = Bar{ b2: 30u32 }; + const k2 = Bar::add_five(55u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/inline.leo b/compiler/tests/circuits/inline.leo index 8e214c729a..9ba06f4191 100644 --- a/compiler/tests/circuits/inline.leo +++ b/compiler/tests/circuits/inline.leo @@ -3,5 +3,5 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; } \ No newline at end of file diff --git a/compiler/tests/circuits/inline_fail.leo b/compiler/tests/circuits/inline_fail.leo index 52792a07e0..01597005fb 100644 --- a/compiler/tests/circuits/inline_fail.leo +++ b/compiler/tests/circuits/inline_fail.leo @@ -3,5 +3,5 @@ circuit Foo { } function main() { - let a = Foo { y: 0u32 }; + const a = Foo { y: 0u32 }; } \ No newline at end of file diff --git a/compiler/tests/circuits/inline_member_fail.leo b/compiler/tests/circuits/inline_member_fail.leo index 7f0b8f7889..59f6d7992b 100644 --- a/compiler/tests/circuits/inline_member_fail.leo +++ b/compiler/tests/circuits/inline_member_fail.leo @@ -3,6 +3,6 @@ circuit Foo { } function main() { - let y: u8 = 1; - let a = Foo { y }; + const y: u8 = 1; + const a = Foo { y }; } \ No newline at end of file diff --git a/compiler/tests/circuits/inline_member_pass.leo b/compiler/tests/circuits/inline_member_pass.leo index 5541a65638..8e58e4935a 100644 --- a/compiler/tests/circuits/inline_member_pass.leo +++ b/compiler/tests/circuits/inline_member_pass.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let x: u8 = 1; - let a = Foo { x }; - let b = Foo::new(x); + const x: u8 = 1; + const a = Foo { x }; + const b = Foo::new(x); } \ No newline at end of file diff --git a/compiler/tests/circuits/inline_undefined.leo b/compiler/tests/circuits/inline_undefined.leo index af070e01e9..40c4cf722c 100644 --- a/compiler/tests/circuits/inline_undefined.leo +++ b/compiler/tests/circuits/inline_undefined.leo @@ -1,3 +1,3 @@ function main() { - let a = Foo { }; + const a = Foo { }; } \ No newline at end of file diff --git a/compiler/tests/circuits/member_function.leo b/compiler/tests/circuits/member_function.leo index e40603dffb..258b6c675e 100644 --- a/compiler/tests/circuits/member_function.leo +++ b/compiler/tests/circuits/member_function.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; console.assert(a.echo() == 1u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/member_function_fail.leo b/compiler/tests/circuits/member_function_fail.leo index 224b79cbf4..5a1c4100c5 100644 --- a/compiler/tests/circuits/member_function_fail.leo +++ b/compiler/tests/circuits/member_function_fail.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let a = Foo { }; - let err = a.echoed(1u32); + const a = Foo { }; + const err = a.echoed(1u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/member_function_invalid.leo b/compiler/tests/circuits/member_function_invalid.leo index bb834e9562..aa689eb976 100644 --- a/compiler/tests/circuits/member_function_invalid.leo +++ b/compiler/tests/circuits/member_function_invalid.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let a = Foo { }; - let err = a.echo(1u32); // echo is a static function and must be accessed using `::` + const a = Foo { }; + const err = a.echo(1u32); // echo is a static function and must be accessed using `::` } \ No newline at end of file diff --git a/compiler/tests/circuits/member_function_nested.leo b/compiler/tests/circuits/member_function_nested.leo index 9e07cc9acf..e512c9df52 100644 --- a/compiler/tests/circuits/member_function_nested.leo +++ b/compiler/tests/circuits/member_function_nested.leo @@ -11,8 +11,8 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; - let b = a.add_x(1u32); + const a = Foo { x: 1u32 }; + const b = a.add_x(1u32); console.assert(b == 2u32); } diff --git a/compiler/tests/circuits/member_static_function.leo b/compiler/tests/circuits/member_static_function.leo index 4bf51190f0..9d53314f27 100644 --- a/compiler/tests/circuits/member_static_function.leo +++ b/compiler/tests/circuits/member_static_function.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let a = Foo::echo(1u32); + const a = Foo::echo(1u32); console.assert(a == 1u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/member_static_function_invalid.leo b/compiler/tests/circuits/member_static_function_invalid.leo index 09fec386d9..7829b4b430 100644 --- a/compiler/tests/circuits/member_static_function_invalid.leo +++ b/compiler/tests/circuits/member_static_function_invalid.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::` + const err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::` } \ No newline at end of file diff --git a/compiler/tests/circuits/member_static_function_undefined.leo b/compiler/tests/circuits/member_static_function_undefined.leo index cf9f98c7b4..ece1d00963 100644 --- a/compiler/tests/circuits/member_static_function_undefined.leo +++ b/compiler/tests/circuits/member_static_function_undefined.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let err = Foo::echoed(1u32); + const err = Foo::echoed(1u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/member_variable.leo b/compiler/tests/circuits/member_variable.leo index 0dd35f2aec..a3f3fbe7e6 100644 --- a/compiler/tests/circuits/member_variable.leo +++ b/compiler/tests/circuits/member_variable.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; console.assert(a.x == 1u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/member_variable_and_function.leo b/compiler/tests/circuits/member_variable_and_function.leo index 074feab7b8..3b90db7eaa 100644 --- a/compiler/tests/circuits/member_variable_and_function.leo +++ b/compiler/tests/circuits/member_variable_and_function.leo @@ -7,9 +7,9 @@ circuit Foo { } function main() { - let a = Foo { foo: 1 }; + const a = Foo { foo: 1 }; - let b = a.foo + Foo::bar(); + const b = a.foo + Foo::bar(); console.assert(b == 2u32); } diff --git a/compiler/tests/circuits/member_variable_fail.leo b/compiler/tests/circuits/member_variable_fail.leo index 5780704ea2..fdf42068d5 100644 --- a/compiler/tests/circuits/member_variable_fail.leo +++ b/compiler/tests/circuits/member_variable_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; - let err = a.y; + const err = a.y; } \ No newline at end of file diff --git a/compiler/tests/circuits/mut_function_fail.leo b/compiler/tests/circuits/mut_function_fail.leo index 3469f97627..44583810dd 100644 --- a/compiler/tests/circuits/mut_function_fail.leo +++ b/compiler/tests/circuits/mut_function_fail.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.bar = 1u8; } \ No newline at end of file diff --git a/compiler/tests/circuits/mut_self_function_fail.leo b/compiler/tests/circuits/mut_self_function_fail.leo index 8c9b99f6ae..b81b18e743 100644 --- a/compiler/tests/circuits/mut_self_function_fail.leo +++ b/compiler/tests/circuits/mut_self_function_fail.leo @@ -9,7 +9,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.set_a(1u8); } \ No newline at end of file diff --git a/compiler/tests/circuits/mut_self_static_function_fail.leo b/compiler/tests/circuits/mut_self_static_function_fail.leo index 8c9b99f6ae..b81b18e743 100644 --- a/compiler/tests/circuits/mut_self_static_function_fail.leo +++ b/compiler/tests/circuits/mut_self_static_function_fail.leo @@ -9,7 +9,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.set_a(1u8); } \ No newline at end of file diff --git a/compiler/tests/circuits/mut_self_variable.leo b/compiler/tests/circuits/mut_self_variable.leo index f5a35ec754..dc2047d872 100644 --- a/compiler/tests/circuits/mut_self_variable.leo +++ b/compiler/tests/circuits/mut_self_variable.leo @@ -8,7 +8,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/compiler/tests/circuits/mut_self_variable_branch.leo b/compiler/tests/circuits/mut_self_variable_branch.leo index e47f9b85df..1c2f126f08 100644 --- a/compiler/tests/circuits/mut_self_variable_branch.leo +++ b/compiler/tests/circuits/mut_self_variable_branch.leo @@ -10,7 +10,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/compiler/tests/circuits/mut_self_variable_conditional.leo b/compiler/tests/circuits/mut_self_variable_conditional.leo index 74345afcb4..61a5e354dc 100644 --- a/compiler/tests/circuits/mut_self_variable_conditional.leo +++ b/compiler/tests/circuits/mut_self_variable_conditional.leo @@ -1,5 +1,5 @@ function main() { - let mut f = Foo { a: 0u32 }; + let f = Foo { a: 0u32 }; f.bar(); } diff --git a/compiler/tests/circuits/mut_self_variable_fail.leo b/compiler/tests/circuits/mut_self_variable_fail.leo index fdbb556bca..4db62a4d3e 100644 --- a/compiler/tests/circuits/mut_self_variable_fail.leo +++ b/compiler/tests/circuits/mut_self_variable_fail.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.set_a(1u8); } \ No newline at end of file diff --git a/compiler/tests/circuits/mut_static_function_fail.leo b/compiler/tests/circuits/mut_static_function_fail.leo index ed3092c656..e7db3a1df9 100644 --- a/compiler/tests/circuits/mut_static_function_fail.leo +++ b/compiler/tests/circuits/mut_static_function_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; f.bar = 1u8; } \ No newline at end of file diff --git a/compiler/tests/circuits/mut_variable.leo b/compiler/tests/circuits/mut_variable.leo index 243d7a2cf2..ddc7412038 100644 --- a/compiler/tests/circuits/mut_variable.leo +++ b/compiler/tests/circuits/mut_variable.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/compiler/tests/circuits/mut_variable_fail.leo b/compiler/tests/circuits/mut_variable_fail.leo index 4d58150c95..e116b33d5c 100644 --- a/compiler/tests/circuits/mut_variable_fail.leo +++ b/compiler/tests/circuits/mut_variable_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let f = Foo { a: 0u8 }; + const f = Foo { a: 0u8 }; f.a = 1u8; } \ No newline at end of file diff --git a/compiler/tests/circuits/pedersen_mock.leo b/compiler/tests/circuits/pedersen_mock.leo index 559ebb7614..4abef65caa 100644 --- a/compiler/tests/circuits/pedersen_mock.leo +++ b/compiler/tests/circuits/pedersen_mock.leo @@ -6,9 +6,9 @@ circuit PedersenHash { } function hash(self, bits: [bool; 512]) -> u32 { - let mut digest: u32 = 0; + let digest: u32 = 0; for i in 0..512 { - let base = bits[i] ? self.parameters[i] : 0u32; + const base = bits[i] ? self.parameters[i] : 0u32; digest += base; } return digest @@ -17,11 +17,11 @@ circuit PedersenHash { // The 'pedersen_hash' main function. function main() { - let parameters = [0u32; 512]; - let pedersen = PedersenHash::new(parameters); - let hash_input: [bool; 512] = [true; 512]; + const parameters = [0u32; 512]; + const pedersen = PedersenHash::new(parameters); + const hash_input: [bool; 512] = [true; 512]; - let res = pedersen.hash(hash_input); + const res = pedersen.hash(hash_input); console.assert(res == 0u32); } diff --git a/compiler/tests/circuits/self_circuit.leo b/compiler/tests/circuits/self_circuit.leo index 5a1d6c63be..18329433f7 100644 --- a/compiler/tests/circuits/self_circuit.leo +++ b/compiler/tests/circuits/self_circuit.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let a = Foo::new(); + const a = Foo::new(); } \ No newline at end of file diff --git a/compiler/tests/circuits/self_member.leo b/compiler/tests/circuits/self_member.leo index 1bd978433d..2b3401a228 100644 --- a/compiler/tests/circuits/self_member.leo +++ b/compiler/tests/circuits/self_member.leo @@ -7,8 +7,8 @@ circuit Foo { } function main() { - let a = Foo { f: 1u32 }; - let b = a.bar(); + const a = Foo { f: 1u32 }; + const b = a.bar(); console.assert(b == 1u32); } \ No newline at end of file diff --git a/compiler/tests/circuits/self_member_invalid.leo b/compiler/tests/circuits/self_member_invalid.leo index 2e8b14f66c..163499d619 100644 --- a/compiler/tests/circuits/self_member_invalid.leo +++ b/compiler/tests/circuits/self_member_invalid.leo @@ -7,6 +7,6 @@ circuit Foo { } function main() -> u32 { - let foo = Foo { f: 1u32 }; - let err = foo.bar(); + const foo = Foo { f: 1u32 }; + const err = foo.bar(); } \ No newline at end of file diff --git a/compiler/tests/circuits/self_member_undefined.leo b/compiler/tests/circuits/self_member_undefined.leo index 471ffb973c..05a40905d7 100644 --- a/compiler/tests/circuits/self_member_undefined.leo +++ b/compiler/tests/circuits/self_member_undefined.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let foo = Foo { }; - let err = foo.bar(); + const foo = Foo { }; + const err = foo.bar(); } \ No newline at end of file diff --git a/compiler/tests/compiler/main.leo b/compiler/tests/compiler/main.leo index f5ddfb4e7f..ed25576751 100644 --- a/compiler/tests/compiler/main.leo +++ b/compiler/tests/compiler/main.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 1 + 2; + const a: u32 = 1 + 2; } \ No newline at end of file diff --git a/compiler/tests/core/packages/unstable/blake2s/arguments_length_fail.leo b/compiler/tests/core/packages/unstable/blake2s/arguments_length_fail.leo index ccdd4c5af9..614490432d 100644 --- a/compiler/tests/core/packages/unstable/blake2s/arguments_length_fail.leo +++ b/compiler/tests/core/packages/unstable/blake2s/arguments_length_fail.leo @@ -1,9 +1,9 @@ import core.unstable.blake2s.Blake2s; function main() { - let seed: [u8; 32] = [0; 32]; + const seed: [u8; 32] = [0; 32]; - let result = Blake2s::hash(seed); // function `hash` takes 2 arguments + const result = Blake2s::hash(seed); // function `hash` takes 2 arguments console.log("Result: {}", result); } diff --git a/compiler/tests/core/packages/unstable/blake2s/arguments_type_fail.leo b/compiler/tests/core/packages/unstable/blake2s/arguments_type_fail.leo index 13c7e9735e..f80e7b0205 100644 --- a/compiler/tests/core/packages/unstable/blake2s/arguments_type_fail.leo +++ b/compiler/tests/core/packages/unstable/blake2s/arguments_type_fail.leo @@ -1,10 +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] + const seed: [u8; 32] = [0; 32]; + const message: [u16; 32] = [0; 32]; // message should be type [u8; 32] - let result = Blake2s::hash(seed, message); + const result = Blake2s::hash(seed, message); console.log("Result: {}", result); } diff --git a/compiler/tests/core/packages/unstable/blake2s/blake2s_random.leo b/compiler/tests/core/packages/unstable/blake2s/blake2s_random.leo index 72aef44932..c9592fcbf8 100644 --- a/compiler/tests/core/packages/unstable/blake2s/blake2s_random.leo +++ b/compiler/tests/core/packages/unstable/blake2s/blake2s_random.leo @@ -1,7 +1,7 @@ import core.unstable.blake2s.Blake2s; function main(seed: [u8; 32], message: [u8; 32], expected: [u8; 32]) { - let actual = Blake2s::hash(seed, message); + const actual = Blake2s::hash(seed, message); console.assert(expected == actual); } diff --git a/compiler/tests/core/unstable_blake2s.leo b/compiler/tests/core/unstable_blake2s.leo index ca7db13892..c430d9a837 100644 --- a/compiler/tests/core/unstable_blake2s.leo +++ b/compiler/tests/core/unstable_blake2s.leo @@ -1,10 +1,10 @@ import core.unstable.blake2s.Blake2s; function main() { - let seed: [u8; 32] = [0; 32]; - let message: [u8; 32] = [0; 32]; + const seed: [u8; 32] = [0; 32]; + const message: [u8; 32] = [0; 32]; - let result = Blake2s::hash(seed, message); + const result = Blake2s::hash(seed, message); console.log("Result: {}", result); } diff --git a/compiler/tests/field/field.leo b/compiler/tests/field/field.leo index 3f109881ad..5d5732e906 100644 --- a/compiler/tests/field/field.leo +++ b/compiler/tests/field/field.leo @@ -1,4 +1,4 @@ function main() { - let negOneField: field = -1field; - let oneField = 1field; + const negOneField: field = -1field; + const oneField = 1field; } \ No newline at end of file diff --git a/compiler/tests/field/ternary.leo b/compiler/tests/field/ternary.leo index f193ad82a3..05cb161b46 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/function/array_input.leo b/compiler/tests/function/array_input.leo index a70483cae7..899c0e4af6 100644 --- a/compiler/tests/function/array_input.leo +++ b/compiler/tests/function/array_input.leo @@ -1,6 +1,6 @@ function foo(a: [u8; 1]) {} function main() { - let a: [u16; 1] = [1; 1]; + const a: [u16; 1] = [1; 1]; foo(a); } \ No newline at end of file diff --git a/compiler/tests/function/array_params_direct_call.leo b/compiler/tests/function/array_params_direct_call.leo index 9305b0958d..8ded724bc4 100644 --- a/compiler/tests/function/array_params_direct_call.leo +++ b/compiler/tests/function/array_params_direct_call.leo @@ -1,7 +1,7 @@ function do_nothing(arr: [u32; 2]) {} function main() { - let arr: [u32; 2] = [0; 2]; + const arr: [u32; 2] = [0; 2]; do_nothing(arr); do_nothing([...arr]); diff --git a/compiler/tests/function/iteration.leo b/compiler/tests/function/iteration.leo index 19af4dd9cf..b1fcee6964 100644 --- a/compiler/tests/function/iteration.leo +++ b/compiler/tests/function/iteration.leo @@ -3,7 +3,7 @@ function one() -> u32 { } function main() { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += one(); diff --git a/compiler/tests/function/iteration_repeated.leo b/compiler/tests/function/iteration_repeated.leo index 3694b3594a..d76380a6b5 100644 --- a/compiler/tests/function/iteration_repeated.leo +++ b/compiler/tests/function/iteration_repeated.leo @@ -1,5 +1,5 @@ function iteration() -> u32 { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += 1; @@ -9,7 +9,7 @@ function iteration() -> u32 { } function main() { - let total = iteration() + iteration(); + const total = iteration() + iteration(); console.assert(total == 20); } \ No newline at end of file diff --git a/compiler/tests/function/multiple_returns.leo b/compiler/tests/function/multiple_returns.leo index ef00a4ef47..d927c51976 100644 --- a/compiler/tests/function/multiple_returns.leo +++ b/compiler/tests/function/multiple_returns.leo @@ -3,7 +3,7 @@ function tuple() -> (bool, bool) { } function main() { - let (a, b) = tuple(); + const (a, b) = tuple(); console.assert(a == true); console.assert(b == false); diff --git a/compiler/tests/function/multiple_returns_fail_conditional.leo b/compiler/tests/function/multiple_returns_fail_conditional.leo index 04ebb9e306..227fe5ce12 100644 --- a/compiler/tests/function/multiple_returns_fail_conditional.leo +++ b/compiler/tests/function/multiple_returns_fail_conditional.leo @@ -1,7 +1,7 @@ function main () -> u16 { if false { - let a = 1u16; - let b = a + 1u16; + const a = 1u16; + const b = a + 1u16; return b } else if false { return 0u16 diff --git a/compiler/tests/function/repeated.leo b/compiler/tests/function/repeated.leo index a2d04d55f9..f83fa6098b 100644 --- a/compiler/tests/function/repeated.leo +++ b/compiler/tests/function/repeated.leo @@ -3,7 +3,7 @@ function one() -> bool { } function main() { - let a = one() && one(); + const a = one() && one(); console.assert(a == true); } \ No newline at end of file diff --git a/compiler/tests/function/return_array_nested_fail.leo b/compiler/tests/function/return_array_nested_fail.leo index dca001d9cc..8eca684b8a 100644 --- a/compiler/tests/function/return_array_nested_fail.leo +++ b/compiler/tests/function/return_array_nested_fail.leo @@ -3,5 +3,5 @@ function array_3x2_tuple() -> [[u8; 2]; 3] { } function main() { - let b = array_3x2_tuple(); + const b = array_3x2_tuple(); } \ No newline at end of file diff --git a/compiler/tests/function/return_array_nested_pass.leo b/compiler/tests/function/return_array_nested_pass.leo index dda5b4342b..bfbfc8fd29 100644 --- a/compiler/tests/function/return_array_nested_pass.leo +++ b/compiler/tests/function/return_array_nested_pass.leo @@ -7,6 +7,6 @@ function array_3x2_tuple() -> [[u8; 2]; 3] { } function main() { - let a = array_3x2_nested(); - let b = array_3x2_tuple(); + const a = array_3x2_nested(); + const b = array_3x2_tuple(); } \ No newline at end of file diff --git a/compiler/tests/function/return_array_tuple_fail.leo b/compiler/tests/function/return_array_tuple_fail.leo index 4b7377e327..c960456ac1 100644 --- a/compiler/tests/function/return_array_tuple_fail.leo +++ b/compiler/tests/function/return_array_tuple_fail.leo @@ -3,5 +3,5 @@ function array_3x2_nested() -> [u8; (3, 2)] { } function main() { - let a = array_3x2_nested(); + const a = array_3x2_nested(); } \ No newline at end of file diff --git a/compiler/tests/function/return_array_tuple_pass.leo b/compiler/tests/function/return_array_tuple_pass.leo index a700bcabad..4199e31990 100644 --- a/compiler/tests/function/return_array_tuple_pass.leo +++ b/compiler/tests/function/return_array_tuple_pass.leo @@ -7,6 +7,6 @@ function array_3x2_tuple() -> [u8; (3, 2)] { } function main() { - let a = array_3x2_nested(); - let b = array_3x2_tuple(); + const a = array_3x2_nested(); + const b = array_3x2_tuple(); } \ No newline at end of file diff --git a/compiler/tests/function/return_tuple.leo b/compiler/tests/function/return_tuple.leo index c459740a47..a3b1bbc36a 100644 --- a/compiler/tests/function/return_tuple.leo +++ b/compiler/tests/function/return_tuple.leo @@ -1,11 +1,11 @@ // Returns a tuple of tuples. function tuples() -> ((u8, u8), u32) { - let a: (u8, u8) = (1, 2); - let b: u32 = 3; + const a: (u8, u8) = (1, 2); + const b: u32 = 3; return (a, b) } function main() { - let t = tuples(); + const t = tuples(); } \ No newline at end of file diff --git a/compiler/tests/function/return_tuple_conditional.leo b/compiler/tests/function/return_tuple_conditional.leo index c63967f548..839081b2a4 100644 --- a/compiler/tests/function/return_tuple_conditional.leo +++ b/compiler/tests/function/return_tuple_conditional.leo @@ -11,5 +11,5 @@ function tuple_conditional () -> ( } function main() { - let t = tuple_conditional(); + const t = tuple_conditional(); } \ No newline at end of file diff --git a/compiler/tests/function/scope_fail.leo b/compiler/tests/function/scope_fail.leo index 773c2479d7..6f1d390541 100644 --- a/compiler/tests/function/scope_fail.leo +++ b/compiler/tests/function/scope_fail.leo @@ -3,6 +3,6 @@ function foo() -> field { } function main() { - let myGlobal = 42field; - let err = foo(); + const myGlobal = 42field; + const err = foo(); } \ No newline at end of file diff --git a/compiler/tests/function/value_unchanged.leo b/compiler/tests/function/value_unchanged.leo index 32dcfa62d6..936ff2ddcc 100644 --- a/compiler/tests/function/value_unchanged.leo +++ b/compiler/tests/function/value_unchanged.leo @@ -12,7 +12,7 @@ function bad_mutate(mut x: u32) { } function main() { - let a = 1u32; + const a = 1u32; bad_mutate(a); console.assert(a == 1u32); // <- value `a` is still `1u32` diff --git a/compiler/tests/group/both_sign_high.leo b/compiler/tests/group/both_sign_high.leo index a8217d6d40..4c93573e1e 100644 --- a/compiler/tests/group/both_sign_high.leo +++ b/compiler/tests/group/both_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, +)group; + const element = (+, +)group; } \ No newline at end of file diff --git a/compiler/tests/group/both_sign_inferred.leo b/compiler/tests/group/both_sign_inferred.leo index b3b8b512c3..0bbd360ba0 100644 --- a/compiler/tests/group/both_sign_inferred.leo +++ b/compiler/tests/group/both_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, _)group; + const element = (_, _)group; } \ No newline at end of file diff --git a/compiler/tests/group/both_sign_low.leo b/compiler/tests/group/both_sign_low.leo index 0519c6d17d..1cb4f46c55 100644 --- a/compiler/tests/group/both_sign_low.leo +++ b/compiler/tests/group/both_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, -)group; + const element = (-, -)group; } \ No newline at end of file diff --git a/compiler/tests/group/one.leo b/compiler/tests/group/one.leo index 7be0cbbc2c..510110150b 100644 --- a/compiler/tests/group/one.leo +++ b/compiler/tests/group/one.leo @@ -1,3 +1,3 @@ function main() { - let element = 1group; + const element = 1group; } \ No newline at end of file diff --git a/compiler/tests/group/point.leo b/compiler/tests/group/point.leo index 85eeb53b7b..5e68415a0d 100644 --- a/compiler/tests/group/point.leo +++ b/compiler/tests/group/point.leo @@ -1,3 +1,3 @@ function main() { - let point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group; + const point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group; } \ No newline at end of file diff --git a/compiler/tests/group/point_input.leo b/compiler/tests/group/point_input.leo index 68d8c458a3..a3a8e63bd3 100644 --- a/compiler/tests/group/point_input.leo +++ b/compiler/tests/group/point_input.leo @@ -1,3 +1,3 @@ function main(a: group) { - let b = a; + const b = a; } \ No newline at end of file diff --git a/compiler/tests/group/positive_and_negative.leo b/compiler/tests/group/positive_and_negative.leo index fdf9b892be..5d29e36ef2 100644 --- a/compiler/tests/group/positive_and_negative.leo +++ b/compiler/tests/group/positive_and_negative.leo @@ -1,10 +1,10 @@ function main() { - let pos_element = 1group; - let neg_element = -1group; + const pos_element = 1group; + const neg_element = -1group; - let pair_x_pos = (1, _)group; - let pair_x_neg = (-1, _)group; + const pair_x_pos = (1, _)group; + const pair_x_neg = (-1, _)group; - let pair_y_pos = (_, 1)group; - let pair_y_neg = (_, -1)group; + const pair_y_pos = (_, 1)group; + const pair_y_neg = (_, -1)group; } \ No newline at end of file diff --git a/compiler/tests/group/ternary.leo b/compiler/tests/group/ternary.leo index fb69b74521..97fba1f5b6 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/group/x_and_y.leo b/compiler/tests/group/x_and_y.leo index 1b64702db1..a350a7ad6b 100644 --- a/compiler/tests/group/x_and_y.leo +++ b/compiler/tests/group/x_and_y.leo @@ -1,3 +1,3 @@ function main(element: group) { - let b = element; + const b = element; } \ No newline at end of file diff --git a/compiler/tests/group/x_sign_high.leo b/compiler/tests/group/x_sign_high.leo index 1b8d397d02..f38b54ad9a 100644 --- a/compiler/tests/group/x_sign_high.leo +++ b/compiler/tests/group/x_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, +)group; + const element = (0, +)group; } \ No newline at end of file diff --git a/compiler/tests/group/x_sign_inferred.leo b/compiler/tests/group/x_sign_inferred.leo index 9e9622a4a4..02c5ac988b 100644 --- a/compiler/tests/group/x_sign_inferred.leo +++ b/compiler/tests/group/x_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, _)group; + const element = (0, _)group; } \ No newline at end of file diff --git a/compiler/tests/group/x_sign_low.leo b/compiler/tests/group/x_sign_low.leo index a5058bda52..ad74d18b64 100644 --- a/compiler/tests/group/x_sign_low.leo +++ b/compiler/tests/group/x_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, -)group; + const element = (0, -)group; } \ No newline at end of file diff --git a/compiler/tests/group/y_sign_high.leo b/compiler/tests/group/y_sign_high.leo index fe16883b39..af2a20149d 100644 --- a/compiler/tests/group/y_sign_high.leo +++ b/compiler/tests/group/y_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, 1)group; + const element = (+, 1)group; } \ No newline at end of file diff --git a/compiler/tests/group/y_sign_inferred.leo b/compiler/tests/group/y_sign_inferred.leo index 003c373cf2..a4efa6a982 100644 --- a/compiler/tests/group/y_sign_inferred.leo +++ b/compiler/tests/group/y_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, 1)group; + const element = (_, 1)group; } \ No newline at end of file diff --git a/compiler/tests/group/y_sign_low.leo b/compiler/tests/group/y_sign_low.leo index 9e61bfd2bb..f557ed0d35 100644 --- a/compiler/tests/group/y_sign_low.leo +++ b/compiler/tests/group/y_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, 1)group; + const element = (-, 1)group; } \ No newline at end of file diff --git a/compiler/tests/group/zero.leo b/compiler/tests/group/zero.leo index e2c0283c21..6cdd4c960e 100644 --- a/compiler/tests/group/zero.leo +++ b/compiler/tests/group/zero.leo @@ -1,3 +1,3 @@ function main() { - let element = 0group; + const element = 0group; } \ No newline at end of file diff --git a/compiler/tests/import/many_import.leo b/compiler/tests/import/many_import.leo index 5e85f19778..08ae494c4f 100644 --- a/compiler/tests/import/many_import.leo +++ b/compiler/tests/import/many_import.leo @@ -12,15 +12,15 @@ import bar.( // imports directory import import car.Car; // imports directory import function main() { - let point = Point { x: 1u32, y: 1u32 }; - let foo = foo(); + const point = Point { x: 1u32, y: 1u32 }; + const foo = foo(); - let bar = Bar { r: 1u32 }; - let baz = Baz { z: 1u32 }; - let bazzar = Bazzar { a: 1u32 }; - let bat = Bat { t: 1u32 }; + const bar = Bar { r: 1u32 }; + const baz = Baz { z: 1u32 }; + const bazzar = Bazzar { a: 1u32 }; + const bat = Bat { t: 1u32 }; - let car = Car { c: 1u32 }; + const car = Car { c: 1u32 }; console.assert(car.c == 1u32); } \ No newline at end of file diff --git a/compiler/tests/import/many_import_star.leo b/compiler/tests/import/many_import_star.leo index 5145d0d05d..575487a929 100644 --- a/compiler/tests/import/many_import_star.leo +++ b/compiler/tests/import/many_import_star.leo @@ -6,14 +6,14 @@ import bar.bat.bat.*; // imports directory import import car.*; // imports directory import function main() { - let point = Point { x: 1u32, y: 1u32 }; - let foo = foo(); + const point = Point { x: 1u32, y: 1u32 }; + const foo = foo(); - let bar = Bar { r: 1u32 }; - let bat = Bat { t: 1u32 }; - let baz = Baz { z: 1u32 }; + const bar = Bar { r: 1u32 }; + const bat = Bat { t: 1u32 }; + const baz = Baz { z: 1u32 }; - let car = Car { c: 1u32 }; + const car = Car { c: 1u32 }; console.assert(car.c == 1u32); } \ No newline at end of file diff --git a/compiler/tests/import/multiple.leo b/compiler/tests/import/multiple.leo index 5c89aaee0c..4bd181c02d 100644 --- a/compiler/tests/import/multiple.leo +++ b/compiler/tests/import/multiple.leo @@ -4,7 +4,7 @@ import test-import.( ); function main() { - let a = Point { x: 1u32, y: 0u32 }; + const a = Point { x: 1u32, y: 0u32 }; console.assert(a.x == 1u32); } \ No newline at end of file diff --git a/compiler/tests/import/star.leo b/compiler/tests/import/star.leo index 9cd817686f..69d0791627 100644 --- a/compiler/tests/import/star.leo +++ b/compiler/tests/import/star.leo @@ -1,7 +1,7 @@ import test-import.*; function main() { - let a = Point { x: 1u32, y: 0u32 }; + const a = Point { x: 1u32, y: 0u32 }; console.assert(foo() == 1u32); } \ No newline at end of file diff --git a/compiler/tests/input_files/program_input/main_multi_dimension_array.leo b/compiler/tests/input_files/program_input/main_multi_dimension_array.leo index 6e523c5fe2..7c89cc1082 100644 --- a/compiler/tests/input_files/program_input/main_multi_dimension_array.leo +++ b/compiler/tests/input_files/program_input/main_multi_dimension_array.leo @@ -1,7 +1,7 @@ function main(x: [i16; (2, 2, 3)]){ console.log("x: {}", x); - let y: [i16; (2, 2, 3)] = [0i16; (2, 2, 3)]; + const y: [i16; (2, 2, 3)] = [0i16; (2, 2, 3)]; console.log("y: {}", y); console.assert(x[0][0][0] == y[0][0][0]); diff --git a/compiler/tests/input_files/program_state/access_all.leo b/compiler/tests/input_files/program_state/access_all.leo index 4e7cba5776..2a60f218aa 100644 --- a/compiler/tests/input_files/program_state/access_all.leo +++ b/compiler/tests/input_files/program_state/access_all.leo @@ -1,7 +1,7 @@ function main(input) { console.assert(input.state.root == [0u8; 32]); - let expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const expected: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; //console.assert(input.record.owner, expected); console.assert(input.state_leaf.network_id == 0u8); diff --git a/compiler/tests/integers/i128/max.leo b/compiler/tests/integers/i128/max.leo index 46c0a32599..5ba44213e1 100644 --- a/compiler/tests/integers/i128/max.leo +++ b/compiler/tests/integers/i128/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = 170141183460469231731687303715884105727; + const a: i128 = 170141183460469231731687303715884105727; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/max_fail.leo b/compiler/tests/integers/i128/max_fail.leo index 820eda8759..a9a46afd7f 100644 --- a/compiler/tests/integers/i128/max_fail.leo +++ b/compiler/tests/integers/i128/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = 170141183460469231731687303715884105728; + const a: i128 = 170141183460469231731687303715884105728; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/min.leo b/compiler/tests/integers/i128/min.leo index 5f32e5add5..19509a3fb0 100644 --- a/compiler/tests/integers/i128/min.leo +++ b/compiler/tests/integers/i128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = -170141183460469231731687303715884105728; + const a: i128 = -170141183460469231731687303715884105728; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/min_fail.leo b/compiler/tests/integers/i128/min_fail.leo index 9035444fa9..918f0e439d 100644 --- a/compiler/tests/integers/i128/min_fail.leo +++ b/compiler/tests/integers/i128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = -170141183460469231731687303715884105729; + const a: i128 = -170141183460469231731687303715884105729; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/negate_min.leo b/compiler/tests/integers/i128/negate_min.leo index cfbd308362..c9de272960 100644 --- a/compiler/tests/integers/i128/negate_min.leo +++ b/compiler/tests/integers/i128/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a: i128 = -170141183460469231731687303715884105728; - let b = -a; + const a: i128 = -170141183460469231731687303715884105728; + const b = -a; } \ No newline at end of file diff --git a/compiler/tests/integers/i128/negate_zero.leo b/compiler/tests/integers/i128/negate_zero.leo index 9fb0c11afe..e079baf393 100644 --- a/compiler/tests/integers/i128/negate_zero.leo +++ b/compiler/tests/integers/i128/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i128; + const a = 0i128; console.assert(-a == 0i128); } \ No newline at end of file diff --git a/compiler/tests/integers/i128/ternary.leo b/compiler/tests/integers/i128/ternary.leo index a923c428e6..3783463b22 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/max.leo b/compiler/tests/integers/i16/max.leo index 084fe4969a..2b70b3cc56 100644 --- a/compiler/tests/integers/i16/max.leo +++ b/compiler/tests/integers/i16/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = 32767; + const a: i16 = 32767; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/max_fail.leo b/compiler/tests/integers/i16/max_fail.leo index 8dd2b7f50a..209bcc6518 100644 --- a/compiler/tests/integers/i16/max_fail.leo +++ b/compiler/tests/integers/i16/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = 32768; + const a: i16 = 32768; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/min.leo b/compiler/tests/integers/i16/min.leo index 3331281fcf..3d05bef95a 100644 --- a/compiler/tests/integers/i16/min.leo +++ b/compiler/tests/integers/i16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = -32768; + const a: i16 = -32768; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/min_fail.leo b/compiler/tests/integers/i16/min_fail.leo index 380848381a..13d7c8b7f2 100644 --- a/compiler/tests/integers/i16/min_fail.leo +++ b/compiler/tests/integers/i16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = -32769; + const a: i16 = -32769; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/negate_min.leo b/compiler/tests/integers/i16/negate_min.leo index 2622f8d2a3..d52a356396 100644 --- a/compiler/tests/integers/i16/negate_min.leo +++ b/compiler/tests/integers/i16/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -32768i16; - let b = -a; + const a = -32768i16; + const b = -a; } \ No newline at end of file diff --git a/compiler/tests/integers/i16/negate_zero.leo b/compiler/tests/integers/i16/negate_zero.leo index 46340c3dc5..20f8a4fba7 100644 --- a/compiler/tests/integers/i16/negate_zero.leo +++ b/compiler/tests/integers/i16/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i16; + const a = 0i16; console.assert(-a == 0i16); } \ No newline at end of file diff --git a/compiler/tests/integers/i16/ternary.leo b/compiler/tests/integers/i16/ternary.leo index 4586b87bb4..d66c73cb93 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/max.leo b/compiler/tests/integers/i32/max.leo index a9c707eb7f..074c75f1a6 100644 --- a/compiler/tests/integers/i32/max.leo +++ b/compiler/tests/integers/i32/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = 2147483647; + const a: i32 = 2147483647; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/max_fail.leo b/compiler/tests/integers/i32/max_fail.leo index f3fd81815f..af2877ff5e 100644 --- a/compiler/tests/integers/i32/max_fail.leo +++ b/compiler/tests/integers/i32/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = 2147483648; + const a: i32 = 2147483648; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/min.leo b/compiler/tests/integers/i32/min.leo index a29d591029..8436268ce6 100644 --- a/compiler/tests/integers/i32/min.leo +++ b/compiler/tests/integers/i32/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = -2147483648; + const a: i32 = -2147483648; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/min_fail.leo b/compiler/tests/integers/i32/min_fail.leo index 1462d207e9..11a683b087 100644 --- a/compiler/tests/integers/i32/min_fail.leo +++ b/compiler/tests/integers/i32/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = -2147483649; + const a: i32 = -2147483649; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/negate_min.leo b/compiler/tests/integers/i32/negate_min.leo index b3c10064e1..a96455d57a 100644 --- a/compiler/tests/integers/i32/negate_min.leo +++ b/compiler/tests/integers/i32/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -2147483648i32; - let b = -a; + const a = -2147483648i32; + const b = -a; } \ No newline at end of file diff --git a/compiler/tests/integers/i32/negate_zero.leo b/compiler/tests/integers/i32/negate_zero.leo index 5533f575a6..a3807b1f8a 100644 --- a/compiler/tests/integers/i32/negate_zero.leo +++ b/compiler/tests/integers/i32/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i32; + const a = 0i32; console.assert(-a == 0i32); } \ No newline at end of file diff --git a/compiler/tests/integers/i32/ternary.leo b/compiler/tests/integers/i32/ternary.leo index 7927c2998b..790769d62f 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/max.leo b/compiler/tests/integers/i64/max.leo index e0d19881e6..593f91e110 100644 --- a/compiler/tests/integers/i64/max.leo +++ b/compiler/tests/integers/i64/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = 9223372036854775807; + const a: i64 = 9223372036854775807; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/max_fail.leo b/compiler/tests/integers/i64/max_fail.leo index 3e6603e4be..362b794a2c 100644 --- a/compiler/tests/integers/i64/max_fail.leo +++ b/compiler/tests/integers/i64/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = 9223372036854775808; + const a: i64 = 9223372036854775808; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/min.leo b/compiler/tests/integers/i64/min.leo index d7e99a87f8..794d8fbfac 100644 --- a/compiler/tests/integers/i64/min.leo +++ b/compiler/tests/integers/i64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = -9223372036854775808; + const a: i64 = -9223372036854775808; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/min_fail.leo b/compiler/tests/integers/i64/min_fail.leo index 11e43646b0..bb260ecc3f 100644 --- a/compiler/tests/integers/i64/min_fail.leo +++ b/compiler/tests/integers/i64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = -9223372036854775809; + const a: i64 = -9223372036854775809; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/negate_min.leo b/compiler/tests/integers/i64/negate_min.leo index 4dd27778d0..daf694491b 100644 --- a/compiler/tests/integers/i64/negate_min.leo +++ b/compiler/tests/integers/i64/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a: i64 = -9223372036854775808; - let b = -a; + const a: i64 = -9223372036854775808; + const b = -a; } \ No newline at end of file diff --git a/compiler/tests/integers/i64/negate_zero.leo b/compiler/tests/integers/i64/negate_zero.leo index 6badfe4dc7..81f09c19a3 100644 --- a/compiler/tests/integers/i64/negate_zero.leo +++ b/compiler/tests/integers/i64/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i64; + const a = 0i64; console.assert(-a == 0i64); } \ No newline at end of file diff --git a/compiler/tests/integers/i64/ternary.leo b/compiler/tests/integers/i64/ternary.leo index 1a2d03a77f..df63b3ad6a 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/max.leo b/compiler/tests/integers/i8/max.leo index b51126da59..f20d59ddf4 100644 --- a/compiler/tests/integers/i8/max.leo +++ b/compiler/tests/integers/i8/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = 127; + const a: i8 = 127; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/max_fail.leo b/compiler/tests/integers/i8/max_fail.leo index 4892505915..9e1956024a 100644 --- a/compiler/tests/integers/i8/max_fail.leo +++ b/compiler/tests/integers/i8/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = 128; + const a: i8 = 128; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/min.leo b/compiler/tests/integers/i8/min.leo index d3c1bff5e4..7b6db025ea 100644 --- a/compiler/tests/integers/i8/min.leo +++ b/compiler/tests/integers/i8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = -128; + const a: i8 = -128; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/min_fail.leo b/compiler/tests/integers/i8/min_fail.leo index 051468ea70..41170e9b93 100644 --- a/compiler/tests/integers/i8/min_fail.leo +++ b/compiler/tests/integers/i8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = -129; + const a: i8 = -129; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/negate_min.leo b/compiler/tests/integers/i8/negate_min.leo index 3959da615e..7f664a1b78 100644 --- a/compiler/tests/integers/i8/negate_min.leo +++ b/compiler/tests/integers/i8/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -128i8; - let b = -a; + const a = -128i8; + const b = -a; } \ No newline at end of file diff --git a/compiler/tests/integers/i8/negate_zero.leo b/compiler/tests/integers/i8/negate_zero.leo index 21fbbab675..cc3f4a0828 100644 --- a/compiler/tests/integers/i8/negate_zero.leo +++ b/compiler/tests/integers/i8/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i8; + const a = 0i8; console.assert(-a == 0i8); } \ No newline at end of file diff --git a/compiler/tests/integers/i8/ternary.leo b/compiler/tests/integers/i8/ternary.leo index e1ec1943c9..0956a9cd39 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u128/max.leo b/compiler/tests/integers/u128/max.leo index 6da59dd058..b166ede06b 100644 --- a/compiler/tests/integers/u128/max.leo +++ b/compiler/tests/integers/u128/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 340282366920938463463374607431768211455; + const a: u128 = 340282366920938463463374607431768211455; } \ No newline at end of file diff --git a/compiler/tests/integers/u128/max_fail.leo b/compiler/tests/integers/u128/max_fail.leo index 40cdf7d2bb..f51c967925 100644 --- a/compiler/tests/integers/u128/max_fail.leo +++ b/compiler/tests/integers/u128/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 340282366920938463463374607431768211456; + const a: u128 = 340282366920938463463374607431768211456; } \ No newline at end of file diff --git a/compiler/tests/integers/u128/min.leo b/compiler/tests/integers/u128/min.leo index 044bda9e1c..41fbf1a2fe 100644 --- a/compiler/tests/integers/u128/min.leo +++ b/compiler/tests/integers/u128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 0; + const a: u128 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u128/min_fail.leo b/compiler/tests/integers/u128/min_fail.leo index df2390c576..b0d17191ff 100644 --- a/compiler/tests/integers/u128/min_fail.leo +++ b/compiler/tests/integers/u128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = -1; + const a: u128 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u128/ternary.leo b/compiler/tests/integers/u128/ternary.leo index 22e2e67058..99a6b997e0 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u16/max.leo b/compiler/tests/integers/u16/max.leo index a707df9af8..56cb2af18d 100644 --- a/compiler/tests/integers/u16/max.leo +++ b/compiler/tests/integers/u16/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 65535; + const a: u16 = 65535; } \ No newline at end of file diff --git a/compiler/tests/integers/u16/max_fail.leo b/compiler/tests/integers/u16/max_fail.leo index 68ff0481e0..bb703210e3 100644 --- a/compiler/tests/integers/u16/max_fail.leo +++ b/compiler/tests/integers/u16/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 65536; + const a: u16 = 65536; } \ No newline at end of file diff --git a/compiler/tests/integers/u16/min.leo b/compiler/tests/integers/u16/min.leo index ab1bd7db48..4dee94a1a4 100644 --- a/compiler/tests/integers/u16/min.leo +++ b/compiler/tests/integers/u16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 0; + const a: u16 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u16/min_fail.leo b/compiler/tests/integers/u16/min_fail.leo index 99b7310362..0c61dd7ddf 100644 --- a/compiler/tests/integers/u16/min_fail.leo +++ b/compiler/tests/integers/u16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = -1; + const a: u16 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u16/ternary.leo b/compiler/tests/integers/u16/ternary.leo index 11d836570d..d6131f9f4f 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u32/max.leo b/compiler/tests/integers/u32/max.leo index 2950164a08..4a07281b5d 100644 --- a/compiler/tests/integers/u32/max.leo +++ b/compiler/tests/integers/u32/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 4294967295; + const a: u32 = 4294967295; } \ No newline at end of file diff --git a/compiler/tests/integers/u32/max_fail.leo b/compiler/tests/integers/u32/max_fail.leo index 96c7e01657..6b1631876e 100644 --- a/compiler/tests/integers/u32/max_fail.leo +++ b/compiler/tests/integers/u32/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 4294967296; + const a: u32 = 4294967296; } \ No newline at end of file diff --git a/compiler/tests/integers/u32/min.leo b/compiler/tests/integers/u32/min.leo index 0f1c080938..8077e0ec02 100644 --- a/compiler/tests/integers/u32/min.leo +++ b/compiler/tests/integers/u32/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + const a: u32 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u32/min_fail.leo b/compiler/tests/integers/u32/min_fail.leo index a8d41c475a..c3e3f33225 100644 --- a/compiler/tests/integers/u32/min_fail.leo +++ b/compiler/tests/integers/u32/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + const a: u32 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u32/ternary.leo b/compiler/tests/integers/u32/ternary.leo index 3c96a7236c..f32ffc29fe 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u64/max.leo b/compiler/tests/integers/u64/max.leo index 985897c006..f14ac7ce64 100644 --- a/compiler/tests/integers/u64/max.leo +++ b/compiler/tests/integers/u64/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 18446744073709551615; + const a: u64 = 18446744073709551615; } \ No newline at end of file diff --git a/compiler/tests/integers/u64/max_fail.leo b/compiler/tests/integers/u64/max_fail.leo index 0ca3f13895..d606c83585 100644 --- a/compiler/tests/integers/u64/max_fail.leo +++ b/compiler/tests/integers/u64/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 18446744073709551616; + const a: u64 = 18446744073709551616; } \ No newline at end of file diff --git a/compiler/tests/integers/u64/min.leo b/compiler/tests/integers/u64/min.leo index aa9b72fc8a..b1da40b14c 100644 --- a/compiler/tests/integers/u64/min.leo +++ b/compiler/tests/integers/u64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 0; + const a: u64 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u64/min_fail.leo b/compiler/tests/integers/u64/min_fail.leo index 81b90cc74a..e58f1897e6 100644 --- a/compiler/tests/integers/u64/min_fail.leo +++ b/compiler/tests/integers/u64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = -1; + const a: u64 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u64/ternary.leo b/compiler/tests/integers/u64/ternary.leo index 4c4ddd8e0c..4427cd0466 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/integers/u8/max.leo b/compiler/tests/integers/u8/max.leo index 684bdfba10..03e82c9a5e 100644 --- a/compiler/tests/integers/u8/max.leo +++ b/compiler/tests/integers/u8/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 255; + const a: u8 = 255; } \ No newline at end of file diff --git a/compiler/tests/integers/u8/max_fail.leo b/compiler/tests/integers/u8/max_fail.leo index f2b870096d..01bb544601 100644 --- a/compiler/tests/integers/u8/max_fail.leo +++ b/compiler/tests/integers/u8/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 256; + const a: u8 = 256; } \ No newline at end of file diff --git a/compiler/tests/integers/u8/min.leo b/compiler/tests/integers/u8/min.leo index a88e33c5a6..1db08a07b5 100644 --- a/compiler/tests/integers/u8/min.leo +++ b/compiler/tests/integers/u8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 0; + const a: u8 = 0; } \ No newline at end of file diff --git a/compiler/tests/integers/u8/min_fail.leo b/compiler/tests/integers/u8/min_fail.leo index 7b91dc6e1a..3cd8d46de7 100644 --- a/compiler/tests/integers/u8/min_fail.leo +++ b/compiler/tests/integers/u8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = -1; + const a: u8 = -1; } \ No newline at end of file diff --git a/compiler/tests/integers/u8/ternary.leo b/compiler/tests/integers/u8/ternary.leo index 1b436aa054..5123a511cd 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 = s ? a : b; + const r = s ? a : b; console.assert(r == c); } \ No newline at end of file diff --git a/compiler/tests/mutability/array.leo b/compiler/tests/mutability/array.leo index 1d51c15271..ea63baaad2 100644 --- a/compiler/tests/mutability/array.leo +++ b/compiler/tests/mutability/array.leo @@ -1,5 +1,5 @@ // Arrays are immutable by default. function main() { - let a = [1u32]; + const a = [1u32]; a[0] = 0; } \ No newline at end of file diff --git a/compiler/tests/mutability/array_mut.leo b/compiler/tests/mutability/array_mut.leo index 1b86bac80f..5d4db3b68a 100644 --- a/compiler/tests/mutability/array_mut.leo +++ b/compiler/tests/mutability/array_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [1u32]; + let a = [1u32]; a[0] = 0; console.assert(a[0] == 0u32); diff --git a/compiler/tests/mutability/array_splice_mut.leo b/compiler/tests/mutability/array_splice_mut.leo index 57cc67e872..d13216600a 100644 --- a/compiler/tests/mutability/array_splice_mut.leo +++ b/compiler/tests/mutability/array_splice_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [1u32, 2u32, 3u32]; + let a = [1u32, 2u32, 3u32]; a[0u32..2u32] = [4u32, 5u32]; console.assert(a[0] == 4u32); diff --git a/compiler/tests/mutability/array_tuple_mut.leo b/compiler/tests/mutability/array_tuple_mut.leo index e0096bd7ac..ed323d46da 100644 --- a/compiler/tests/mutability/array_tuple_mut.leo +++ b/compiler/tests/mutability/array_tuple_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [(1u32, 2u32)]; + let a = [(1u32, 2u32)]; a[0u32].1 = 3u32; console.assert(a[0u32].0 == 1u32); diff --git a/compiler/tests/mutability/circuit.leo b/compiler/tests/mutability/circuit.leo index be1c568836..508595ef16 100644 --- a/compiler/tests/mutability/circuit.leo +++ b/compiler/tests/mutability/circuit.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let a = Foo { x: 1 }; + const a = Foo { x: 1 }; a.x = 0; } \ No newline at end of file diff --git a/compiler/tests/mutability/circuit_function_mut.leo b/compiler/tests/mutability/circuit_function_mut.leo index eba1d02c0e..c1bc941c94 100644 --- a/compiler/tests/mutability/circuit_function_mut.leo +++ b/compiler/tests/mutability/circuit_function_mut.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.bar = 0; } \ No newline at end of file diff --git a/compiler/tests/mutability/circuit_mut.leo b/compiler/tests/mutability/circuit_mut.leo index 27bd6109b2..f7067db11e 100644 --- a/compiler/tests/mutability/circuit_mut.leo +++ b/compiler/tests/mutability/circuit_mut.leo @@ -4,7 +4,7 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.x = 0; console.assert(a.x == 0u32); diff --git a/compiler/tests/mutability/circuit_static_function_mut.leo b/compiler/tests/mutability/circuit_static_function_mut.leo index eba1d02c0e..c1bc941c94 100644 --- a/compiler/tests/mutability/circuit_static_function_mut.leo +++ b/compiler/tests/mutability/circuit_static_function_mut.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.bar = 0; } \ No newline at end of file diff --git a/compiler/tests/mutability/circuit_variable_mut.leo b/compiler/tests/mutability/circuit_variable_mut.leo index 27bd6109b2..f7067db11e 100644 --- a/compiler/tests/mutability/circuit_variable_mut.leo +++ b/compiler/tests/mutability/circuit_variable_mut.leo @@ -4,7 +4,7 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.x = 0; console.assert(a.x == 0u32); diff --git a/compiler/tests/mutability/const.leo b/compiler/tests/mutability/const.leo index d2a3a6ac2b..6201e7c5af 100644 --- a/compiler/tests/mutability/const.leo +++ b/compiler/tests/mutability/const.leo @@ -1,5 +1,5 @@ // Let variables are immutable by default. function main() { - let a = 1u32; + const a = 1u32; a = 0; } \ No newline at end of file diff --git a/compiler/tests/mutability/let.leo b/compiler/tests/mutability/let.leo index 477e6b35f5..105730adb7 100644 --- a/compiler/tests/mutability/let.leo +++ b/compiler/tests/mutability/let.leo @@ -1,5 +1,5 @@ // Variables are immutable by default. function main() { - let a = 1u32; + const a = 1u32; a = 0; } \ No newline at end of file diff --git a/compiler/tests/mutability/let_mut.leo b/compiler/tests/mutability/let_mut.leo index 5766d144d3..cd1060d0d2 100644 --- a/compiler/tests/mutability/let_mut.leo +++ b/compiler/tests/mutability/let_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes a variable mutable. function main() { - let mut a = 1u32; + let a = 1u32; a = 0; console.assert(a == 0u32); diff --git a/compiler/tests/mutability/let_mut_nested.leo b/compiler/tests/mutability/let_mut_nested.leo index 27121f6e48..93236ef4c6 100644 --- a/compiler/tests/mutability/let_mut_nested.leo +++ b/compiler/tests/mutability/let_mut_nested.leo @@ -1,5 +1,5 @@ function main () { - let mut x = 2u8; - let mut y = x; - let z = y / 2u8; + let x = 2u8; + let y = x; + const z = y / 2u8; } \ No newline at end of file diff --git a/compiler/tests/mutability/swap.leo b/compiler/tests/mutability/swap.leo index 0a209149ee..b2a795e826 100644 --- a/compiler/tests/mutability/swap.leo +++ b/compiler/tests/mutability/swap.leo @@ -1,17 +1,17 @@ // Swap two elements of an array. function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { - let t = a[i]; + const 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]; + let arr: [u32; 2] = [0, 1]; + const expected: [u32; 2] = [1, 0]; // Do swap. - let actual = swap(arr, 0, 1); + const actual = swap(arr, 0, 1); // Check result. for i in 0..2 { diff --git a/compiler/tests/statements/block.leo b/compiler/tests/statements/block.leo index 8650808041..ca8da645ec 100644 --- a/compiler/tests/statements/block.leo +++ b/compiler/tests/statements/block.leo @@ -1,5 +1,5 @@ function main() { - let mut x = 4u32; + let x = 4u32; { x = 5u32; diff --git a/compiler/tests/statements/conditional/chain.leo b/compiler/tests/statements/conditional/chain.leo index dbc0e1f38c..44d4e86243 100644 --- a/compiler/tests/statements/conditional/chain.leo +++ b/compiler/tests/statements/conditional/chain.leo @@ -1,5 +1,5 @@ function main(a: u32, b: u32) { - let mut c = 0u32; + let c = 0u32; if a == 1 { c = 1; diff --git a/compiler/tests/statements/conditional/for_loop.leo b/compiler/tests/statements/conditional/for_loop.leo index 2dca076858..db307f3c36 100644 --- a/compiler/tests/statements/conditional/for_loop.leo +++ b/compiler/tests/statements/conditional/for_loop.leo @@ -1,5 +1,5 @@ function main(a: bool) { - let mut b = 0u32; + let b = 0u32; if a { for i in 0..4 { @@ -7,7 +7,7 @@ function main(a: bool) { } } - let r: u32 = a ? 6 : 0; + const r: u32 = a ? 6 : 0; console.assert(r == b); } diff --git a/compiler/tests/statements/conditional/mutate.leo b/compiler/tests/statements/conditional/mutate.leo index 458d3d0d60..9bb124eefd 100644 --- a/compiler/tests/statements/conditional/mutate.leo +++ b/compiler/tests/statements/conditional/mutate.leo @@ -1,5 +1,5 @@ function main(a: u32) { - let mut b = 5u32; + let b = 5u32; if a == 1 { b = 1; diff --git a/compiler/tests/statements/conditional/nested.leo b/compiler/tests/statements/conditional/nested.leo index 3596f889d1..1849c2a339 100644 --- a/compiler/tests/statements/conditional/nested.leo +++ b/compiler/tests/statements/conditional/nested.leo @@ -1,5 +1,5 @@ function main(a: bool, b: bool, c: u32) { - let mut d = 0u32; + let d = 0u32; if a { d += 1; diff --git a/compiler/tests/statements/iteration_basic.leo b/compiler/tests/statements/iteration_basic.leo index 103c9abb9e..5d74e69a1f 100644 --- a/compiler/tests/statements/iteration_basic.leo +++ b/compiler/tests/statements/iteration_basic.leo @@ -1,5 +1,5 @@ function main() { - let mut x = 4u32; + let x = 4u32; for i in 0..3 { x -= 1; } diff --git a/compiler/tests/statements/ternary_basic.leo b/compiler/tests/statements/ternary_basic.leo index 675b681fa9..38359004a9 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 = a ? true : false; + const c = a ? true : false; - let d = c == b; + const d = c == b; } \ No newline at end of file diff --git a/compiler/tests/syntax/compare_mismatched_types.leo b/compiler/tests/syntax/compare_mismatched_types.leo index 8cf6327cb3..1ac81ab098 100644 --- a/compiler/tests/syntax/compare_mismatched_types.leo +++ b/compiler/tests/syntax/compare_mismatched_types.leo @@ -1,3 +1,3 @@ function main() { - let a = -5i8 > 342u32; + const a = -5i8 > 342u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/address_fail.leo b/compiler/tests/syntax/identifiers/address_fail.leo index 4eb12c7743..b39ea75df6 100644 --- a/compiler/tests/syntax/identifiers/address_fail.leo +++ b/compiler/tests/syntax/identifiers/address_fail.leo @@ -1,3 +1,3 @@ function main() { - let address = 0u32; + const address = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/console_fail.leo b/compiler/tests/syntax/identifiers/console_fail.leo index 6ee932a66b..c0229dd624 100644 --- a/compiler/tests/syntax/identifiers/console_fail.leo +++ b/compiler/tests/syntax/identifiers/console_fail.leo @@ -1,3 +1,3 @@ function main() { - let console = 0u32; + const console = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/field_fail.leo b/compiler/tests/syntax/identifiers/field_fail.leo index a1f85dc6ea..33bb3118d8 100644 --- a/compiler/tests/syntax/identifiers/field_fail.leo +++ b/compiler/tests/syntax/identifiers/field_fail.leo @@ -1,3 +1,3 @@ function main() { - let field = 0u32; + const field = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/group_fail.leo b/compiler/tests/syntax/identifiers/group_fail.leo index 322997ea50..db71c8a792 100644 --- a/compiler/tests/syntax/identifiers/group_fail.leo +++ b/compiler/tests/syntax/identifiers/group_fail.leo @@ -1,3 +1,3 @@ function main() { - let group = 0u32; + const group = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/i8_fail.leo b/compiler/tests/syntax/identifiers/i8_fail.leo index 596a9056ab..a2d868f9f5 100644 --- a/compiler/tests/syntax/identifiers/i8_fail.leo +++ b/compiler/tests/syntax/identifiers/i8_fail.leo @@ -1,3 +1,3 @@ function main() { - let i8 = 0u32; + const i8 = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/input_fail.leo b/compiler/tests/syntax/identifiers/input_fail.leo index e1b466d6d4..0053565a6f 100644 --- a/compiler/tests/syntax/identifiers/input_fail.leo +++ b/compiler/tests/syntax/identifiers/input_fail.leo @@ -1,3 +1,3 @@ function main() { - let input = 0u32; + const input = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/self_keyword_fail.leo b/compiler/tests/syntax/identifiers/self_keyword_fail.leo index 28b899ccd4..79bc4d6e96 100644 --- a/compiler/tests/syntax/identifiers/self_keyword_fail.leo +++ b/compiler/tests/syntax/identifiers/self_keyword_fail.leo @@ -1,3 +1,3 @@ function main() { - let Self = 0u32; + const Self = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/self_type_fail.leo b/compiler/tests/syntax/identifiers/self_type_fail.leo index 28b899ccd4..79bc4d6e96 100644 --- a/compiler/tests/syntax/identifiers/self_type_fail.leo +++ b/compiler/tests/syntax/identifiers/self_type_fail.leo @@ -1,3 +1,3 @@ function main() { - let Self = 0u32; + const Self = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/true_fail.leo b/compiler/tests/syntax/identifiers/true_fail.leo index 4eb12c7743..b39ea75df6 100644 --- a/compiler/tests/syntax/identifiers/true_fail.leo +++ b/compiler/tests/syntax/identifiers/true_fail.leo @@ -1,3 +1,3 @@ function main() { - let address = 0u32; + const address = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/identifiers/u8_fail.leo b/compiler/tests/syntax/identifiers/u8_fail.leo index 77687f5ff2..4a48780a29 100644 --- a/compiler/tests/syntax/identifiers/u8_fail.leo +++ b/compiler/tests/syntax/identifiers/u8_fail.leo @@ -1,3 +1,3 @@ function main() { - let u8 = 0u32; + const u8 = 0u32; } \ No newline at end of file diff --git a/compiler/tests/syntax/semicolon.leo b/compiler/tests/syntax/semicolon.leo index 68cfa7cbe0..f1deb29e37 100644 --- a/compiler/tests/syntax/semicolon.leo +++ b/compiler/tests/syntax/semicolon.leo @@ -1,3 +1,3 @@ function main() { - let a = 0 + const a = 0 } \ No newline at end of file diff --git a/compiler/tests/tuples/access.leo b/compiler/tests/tuples/access.leo index 196e9d058c..9277f4ecc5 100644 --- a/compiler/tests/tuples/access.leo +++ b/compiler/tests/tuples/access.leo @@ -1,5 +1,5 @@ function main() { - let a = (true, false); + const a = (true, false); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/compiler/tests/tuples/basic.leo b/compiler/tests/tuples/basic.leo index 37c728611c..2e777f2797 100644 --- a/compiler/tests/tuples/basic.leo +++ b/compiler/tests/tuples/basic.leo @@ -1,3 +1,3 @@ function main() { - let a = (true, false); + const a = (true, false); } \ No newline at end of file diff --git a/compiler/tests/tuples/function.leo b/compiler/tests/tuples/function.leo index b318348813..4222b858cb 100644 --- a/compiler/tests/tuples/function.leo +++ b/compiler/tests/tuples/function.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let a = foo(); + const a = foo(); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/compiler/tests/tuples/function_multiple.leo b/compiler/tests/tuples/function_multiple.leo index 39848377c6..73fbe277ae 100644 --- a/compiler/tests/tuples/function_multiple.leo +++ b/compiler/tests/tuples/function_multiple.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let (a, b) = foo(); + const (a, b) = foo(); console.assert(a == true); console.assert(b == false); diff --git a/compiler/tests/tuples/function_typed.leo b/compiler/tests/tuples/function_typed.leo index 8af2c907ca..f89e7a3273 100644 --- a/compiler/tests/tuples/function_typed.leo +++ b/compiler/tests/tuples/function_typed.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let a: (bool, bool) = foo(); + const a: (bool, bool) = foo(); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/compiler/tests/tuples/multiple.leo b/compiler/tests/tuples/multiple.leo index b7627dad2a..2cb003b0e1 100644 --- a/compiler/tests/tuples/multiple.leo +++ b/compiler/tests/tuples/multiple.leo @@ -1,5 +1,5 @@ function main() { - let (a, b) = (true, false); + const (a, b) = (true, false); console.assert(a == true); console.assert(b == false); diff --git a/compiler/tests/tuples/multiple_typed.leo b/compiler/tests/tuples/multiple_typed.leo index 29fc7ef877..bbe4a01858 100644 --- a/compiler/tests/tuples/multiple_typed.leo +++ b/compiler/tests/tuples/multiple_typed.leo @@ -1,5 +1,5 @@ function main() { - let (a, b): (bool, bool) = (true, false); + const (a, b): (bool, bool) = (true, false); console.assert(a == true); console.assert(b == false); diff --git a/compiler/tests/tuples/nested.leo b/compiler/tests/tuples/nested.leo index a9599b360c..bbdb2394a8 100644 --- a/compiler/tests/tuples/nested.leo +++ b/compiler/tests/tuples/nested.leo @@ -1,4 +1,4 @@ function main() { - let a = (true, false); - let b = (true, a); + const a = (true, false); + const b = (true, a); } \ No newline at end of file diff --git a/compiler/tests/tuples/nested_access.leo b/compiler/tests/tuples/nested_access.leo index 5edba64e24..f21fa59bba 100644 --- a/compiler/tests/tuples/nested_access.leo +++ b/compiler/tests/tuples/nested_access.leo @@ -1,6 +1,6 @@ function main() { - let a = (true, false); - let b = (true, a); + const a = (true, false); + const b = (true, a); console.assert(b.0 == true); console.assert(b.1.0 == true); diff --git a/compiler/tests/tuples/nested_typed.leo b/compiler/tests/tuples/nested_typed.leo index 2e68117a2b..44a10b2a3e 100644 --- a/compiler/tests/tuples/nested_typed.leo +++ b/compiler/tests/tuples/nested_typed.leo @@ -1,4 +1,4 @@ function main() { - let a = (true, false); - let b: (bool, (bool, bool)) = (true, a); + const a = (true, false); + const b: (bool, (bool, bool)) = (true, a); } \ No newline at end of file diff --git a/compiler/tests/tuples/typed.leo b/compiler/tests/tuples/typed.leo index 8cd2ed79db..8f623fc148 100644 --- a/compiler/tests/tuples/typed.leo +++ b/compiler/tests/tuples/typed.leo @@ -1,3 +1,3 @@ function main() { - let a: (bool, bool) = (true, false); + const a: (bool, bool) = (true, false); } \ No newline at end of file diff --git a/examples/hello-world/src/main.leo b/examples/hello-world/src/main.leo index 5cd23178f9..f78b77e855 100644 --- a/examples/hello-world/src/main.leo +++ b/examples/hello-world/src/main.leo @@ -1,5 +1,5 @@ // The 'hello-world' main function. function main(a: u32, b: u32) -> u32 { - let c: u32 = a + b; + const c: u32 = a + b; return c } diff --git a/examples/pedersen-hash/src/main.leo b/examples/pedersen-hash/src/main.leo index e0adfecaec..f1f142e731 100644 --- a/examples/pedersen-hash/src/main.leo +++ b/examples/pedersen-hash/src/main.leo @@ -7,7 +7,7 @@ circuit PedersenHash { } function hash(self, bits: [bool; 256]) -> group { - let mut digest: group = 0group; + let digest: group = 0group; for i in 0..256 { if bits[i] { digest += self.parameters[i]; @@ -19,9 +19,9 @@ circuit PedersenHash { // The 'pedersen-hash' main function. function main() -> group { - let parameters = [1group; 256]; - let pedersen = PedersenHash::new(parameters); - let hash_input: [bool; 256] = [true; 256]; + const parameters = [1group; 256]; + const pedersen = PedersenHash::new(parameters); + const hash_input: [bool; 256] = [true; 256]; return pedersen.hash(hash_input) } diff --git a/parser/benches/big_circuit.leo b/parser/benches/big_circuit.leo index 32011551c0..01d10c2daa 100644 --- a/parser/benches/big_circuit.leo +++ b/parser/benches/big_circuit.leo @@ -1,6 +1,6 @@ function main() { - let foo = Foo { x0: 0, x1: 1, x2: 2, x3: 3, x4: 4, x5: 5, x6: 6, x7: 7, x8: 8, x9: 9, x10: 10, x11: 11, x12: 12, x13: 13, x14: 14, x15: 15, x16: 16, x17: 17, x18: 18, x19: 19, x20: 20, x21: 21, x22: 22, x23: 23, x24: 24, x25: 25, x26: 26, x27: 27, x28: 28, x29: 29, x30: 30, x31: 31, x32: 32, x33: 33, x34: 34, x35: 35, x36: 36, x37: 37, x38: 38, x39: 39, x40: 40, x41: 41, x42: 42, x43: 43, x44: 44, x45: 45, x46: 46, x47: 47, x48: 48, x49: 49, x50: 50, x51: 51, x52: 52, x53: 53, x54: 54, x55: 55, x56: 56, x57: 57, x58: 58, x59: 59, x60: 60, x61: 61, x62: 62, x63: 63, x64: 64, x65: 65, x66: 66, x67: 67, x68: 68, x69: 69, x70: 70, x71: 71, x72: 72, x73: 73, x74: 74, x75: 75, x76: 76, x77: 77, x78: 78, x79: 79, x80: 80, x81: 81, x82: 82, x83: 83, x84: 84, x85: 85, x86: 86, x87: 87, x88: 88, x89: 89, x90: 90, x91: 91, x92: 92, x93: 93, x94: 94, x95: 95, x96: 96, x97: 97, x98: 98, x99: 99, x100: 100, x101: 101, x102: 102, x103: 103, x104: 104, x105: 105, x106: 106, x107: 107, x108: 108, x109: 109, x110: 110, x111: 111, x112: 112, x113: 113, x114: 114, x115: 115, x116: 116, x117: 117, x118: 118, x119: 119, x120: 120, x121: 121, x122: 122, x123: 123, x124: 124, x125: 125, x126: 126, x127: 127, x128: 128, x129: 129, x130: 130, x131: 131, x132: 132, x133: 133, x134: 134, x135: 135, x136: 136, x137: 137, x138: 138, x139: 139, x140: 140, x141: 141, x142: 142, x143: 143, x144: 144, x145: 145, x146: 146, x147: 147, x148: 148, x149: 149, x150: 150, x151: 151, x152: 152, x153: 153, x154: 154, x155: 155, x156: 156, x157: 157, x158: 158, x159: 159, x160: 160, x161: 161, x162: 162, x163: 163, x164: 164, x165: 165, x166: 166, x167: 167, x168: 168, x169: 169, x170: 170, x171: 171, x172: 172, x173: 173, x174: 174, x175: 175, x176: 176, x177: 177, x178: 178, x179: 179, x180: 180, x181: 181, x182: 182, x183: 183, x184: 184, x185: 185, x186: 186, x187: 187, x188: 188, x189: 189, x190: 190, x191: 191, x192: 192, x193: 193, x194: 194, x195: 195, x196: 196, x197: 197, x198: 198, x199: 199, x200: 200, x201: 201, x202: 202, x203: 203, x204: 204, x205: 205, x206: 206, x207: 207, x208: 208, x209: 209, x210: 210, x211: 211, x212: 212, x213: 213, x214: 214, x215: 215, x216: 216, x217: 217, x218: 218, x219: 219, x220: 220, x221: 221, x222: 222, x223: 223, x224: 224, x225: 225, x226: 226, x227: 227, x228: 228, x229: 229, x230: 230, x231: 231, x232: 232, x233: 233, x234: 234, x235: 235, x236: 236, x237: 237, x238: 238, x239: 239, x240: 240, x241: 241, x242: 242, x243: 243, x244: 244, x245: 245, x246: 246, x247: 247, x248: 248, x249: 249, x250: 250, x251: 251, x252: 252, x253: 253, x254: 254, x255: 255 }; - let bar = Foo { x0: 0, x1: 1, x2: 2, x3: 3, x4: 4, x5: 5, x6: 6, x7: 7, x8: 8, x9: 9, x10: 10, x11: 11, x12: 12, x13: 13, x14: 14, x15: 15, x16: 16, x17: 17, x18: 18, x19: 19, x20: 20, x21: 21, x22: 22, x23: 23, x24: 24, x25: 25, x26: 26, x27: 27, x28: 28, x29: 29, x30: 30, x31: 31, x32: 32, x33: 33, x34: 34, x35: 35, x36: 36, x37: 37, x38: 38, x39: 39, x40: 40, x41: 41, x42: 42, x43: 43, x44: 44, x45: 45, x46: 46, x47: 47, x48: 48, x49: 49, x50: 50, x51: 51, x52: 52, x53: 53, x54: 54, x55: 55, x56: 56, x57: 57, x58: 58, x59: 59, x60: 60, x61: 61, x62: 62, x63: 63, x64: 64, x65: 65, x66: 66, x67: 67, x68: 68, x69: 69, x70: 70, x71: 71, x72: 72, x73: 73, x74: 74, x75: 75, x76: 76, x77: 77, x78: 78, x79: 79, x80: 80, x81: 81, x82: 82, x83: 83, x84: 84, x85: 85, x86: 86, x87: 87, x88: 88, x89: 89, x90: 90, x91: 91, x92: 92, x93: 93, x94: 94, x95: 95, x96: 96, x97: 97, x98: 98, x99: 99, x100: 100, x101: 101, x102: 102, x103: 103, x104: 104, x105: 105, x106: 106, x107: 107, x108: 108, x109: 109, x110: 110, x111: 111, x112: 112, x113: 113, x114: 114, x115: 115, x116: 116, x117: 117, x118: 118, x119: 119, x120: 120, x121: 121, x122: 122, x123: 123, x124: 124, x125: 125, x126: 126, x127: 127, x128: 128, x129: 129, x130: 130, x131: 131, x132: 132, x133: 133, x134: 134, x135: 135, x136: 136, x137: 137, x138: 138, x139: 139, x140: 140, x141: 141, x142: 142, x143: 143, x144: 144, x145: 145, x146: 146, x147: 147, x148: 148, x149: 149, x150: 150, x151: 151, x152: 152, x153: 153, x154: 154, x155: 155, x156: 156, x157: 157, x158: 158, x159: 159, x160: 160, x161: 161, x162: 162, x163: 163, x164: 164, x165: 165, x166: 166, x167: 167, x168: 168, x169: 169, x170: 170, x171: 171, x172: 172, x173: 173, x174: 174, x175: 175, x176: 176, x177: 177, x178: 178, x179: 179, x180: 180, x181: 181, x182: 182, x183: 183, x184: 184, x185: 185, x186: 186, x187: 187, x188: 188, x189: 189, x190: 190, x191: 191, x192: 192, x193: 193, x194: 194, x195: 195, x196: 196, x197: 197, x198: 198, x199: 199, x200: 200, x201: 201, x202: 202, x203: 203, x204: 204, x205: 205, x206: 206, x207: 207, x208: 208, x209: 209, x210: 210, x211: 211, x212: 212, x213: 213, x214: 214, x215: 215, x216: 216, x217: 217, x218: 218, x219: 219, x220: 220, x221: 221, x222: 222, x223: 223, x224: 224, x225: 225, x226: 226, x227: 227, x228: 228, x229: 229, x230: 230, x231: 231, x232: 232, x233: 233, x234: 234, x235: 235, x236: 236, x237: 237, x238: 238, x239: 239, x240: 240, x241: 241, x242: 242, x243: 243, x244: 244, x245: 245, x246: 246, x247: 247, x248: 248, x249: 249, x250: 250, x251: 251, x252: 252, x253: 253, x254: 254, x255: 255 }; + const foo = Foo { x0: 0, x1: 1, x2: 2, x3: 3, x4: 4, x5: 5, x6: 6, x7: 7, x8: 8, x9: 9, x10: 10, x11: 11, x12: 12, x13: 13, x14: 14, x15: 15, x16: 16, x17: 17, x18: 18, x19: 19, x20: 20, x21: 21, x22: 22, x23: 23, x24: 24, x25: 25, x26: 26, x27: 27, x28: 28, x29: 29, x30: 30, x31: 31, x32: 32, x33: 33, x34: 34, x35: 35, x36: 36, x37: 37, x38: 38, x39: 39, x40: 40, x41: 41, x42: 42, x43: 43, x44: 44, x45: 45, x46: 46, x47: 47, x48: 48, x49: 49, x50: 50, x51: 51, x52: 52, x53: 53, x54: 54, x55: 55, x56: 56, x57: 57, x58: 58, x59: 59, x60: 60, x61: 61, x62: 62, x63: 63, x64: 64, x65: 65, x66: 66, x67: 67, x68: 68, x69: 69, x70: 70, x71: 71, x72: 72, x73: 73, x74: 74, x75: 75, x76: 76, x77: 77, x78: 78, x79: 79, x80: 80, x81: 81, x82: 82, x83: 83, x84: 84, x85: 85, x86: 86, x87: 87, x88: 88, x89: 89, x90: 90, x91: 91, x92: 92, x93: 93, x94: 94, x95: 95, x96: 96, x97: 97, x98: 98, x99: 99, x100: 100, x101: 101, x102: 102, x103: 103, x104: 104, x105: 105, x106: 106, x107: 107, x108: 108, x109: 109, x110: 110, x111: 111, x112: 112, x113: 113, x114: 114, x115: 115, x116: 116, x117: 117, x118: 118, x119: 119, x120: 120, x121: 121, x122: 122, x123: 123, x124: 124, x125: 125, x126: 126, x127: 127, x128: 128, x129: 129, x130: 130, x131: 131, x132: 132, x133: 133, x134: 134, x135: 135, x136: 136, x137: 137, x138: 138, x139: 139, x140: 140, x141: 141, x142: 142, x143: 143, x144: 144, x145: 145, x146: 146, x147: 147, x148: 148, x149: 149, x150: 150, x151: 151, x152: 152, x153: 153, x154: 154, x155: 155, x156: 156, x157: 157, x158: 158, x159: 159, x160: 160, x161: 161, x162: 162, x163: 163, x164: 164, x165: 165, x166: 166, x167: 167, x168: 168, x169: 169, x170: 170, x171: 171, x172: 172, x173: 173, x174: 174, x175: 175, x176: 176, x177: 177, x178: 178, x179: 179, x180: 180, x181: 181, x182: 182, x183: 183, x184: 184, x185: 185, x186: 186, x187: 187, x188: 188, x189: 189, x190: 190, x191: 191, x192: 192, x193: 193, x194: 194, x195: 195, x196: 196, x197: 197, x198: 198, x199: 199, x200: 200, x201: 201, x202: 202, x203: 203, x204: 204, x205: 205, x206: 206, x207: 207, x208: 208, x209: 209, x210: 210, x211: 211, x212: 212, x213: 213, x214: 214, x215: 215, x216: 216, x217: 217, x218: 218, x219: 219, x220: 220, x221: 221, x222: 222, x223: 223, x224: 224, x225: 225, x226: 226, x227: 227, x228: 228, x229: 229, x230: 230, x231: 231, x232: 232, x233: 233, x234: 234, x235: 235, x236: 236, x237: 237, x238: 238, x239: 239, x240: 240, x241: 241, x242: 242, x243: 243, x244: 244, x245: 245, x246: 246, x247: 247, x248: 248, x249: 249, x250: 250, x251: 251, x252: 252, x253: 253, x254: 254, x255: 255 }; + const bar = Foo { x0: 0, x1: 1, x2: 2, x3: 3, x4: 4, x5: 5, x6: 6, x7: 7, x8: 8, x9: 9, x10: 10, x11: 11, x12: 12, x13: 13, x14: 14, x15: 15, x16: 16, x17: 17, x18: 18, x19: 19, x20: 20, x21: 21, x22: 22, x23: 23, x24: 24, x25: 25, x26: 26, x27: 27, x28: 28, x29: 29, x30: 30, x31: 31, x32: 32, x33: 33, x34: 34, x35: 35, x36: 36, x37: 37, x38: 38, x39: 39, x40: 40, x41: 41, x42: 42, x43: 43, x44: 44, x45: 45, x46: 46, x47: 47, x48: 48, x49: 49, x50: 50, x51: 51, x52: 52, x53: 53, x54: 54, x55: 55, x56: 56, x57: 57, x58: 58, x59: 59, x60: 60, x61: 61, x62: 62, x63: 63, x64: 64, x65: 65, x66: 66, x67: 67, x68: 68, x69: 69, x70: 70, x71: 71, x72: 72, x73: 73, x74: 74, x75: 75, x76: 76, x77: 77, x78: 78, x79: 79, x80: 80, x81: 81, x82: 82, x83: 83, x84: 84, x85: 85, x86: 86, x87: 87, x88: 88, x89: 89, x90: 90, x91: 91, x92: 92, x93: 93, x94: 94, x95: 95, x96: 96, x97: 97, x98: 98, x99: 99, x100: 100, x101: 101, x102: 102, x103: 103, x104: 104, x105: 105, x106: 106, x107: 107, x108: 108, x109: 109, x110: 110, x111: 111, x112: 112, x113: 113, x114: 114, x115: 115, x116: 116, x117: 117, x118: 118, x119: 119, x120: 120, x121: 121, x122: 122, x123: 123, x124: 124, x125: 125, x126: 126, x127: 127, x128: 128, x129: 129, x130: 130, x131: 131, x132: 132, x133: 133, x134: 134, x135: 135, x136: 136, x137: 137, x138: 138, x139: 139, x140: 140, x141: 141, x142: 142, x143: 143, x144: 144, x145: 145, x146: 146, x147: 147, x148: 148, x149: 149, x150: 150, x151: 151, x152: 152, x153: 153, x154: 154, x155: 155, x156: 156, x157: 157, x158: 158, x159: 159, x160: 160, x161: 161, x162: 162, x163: 163, x164: 164, x165: 165, x166: 166, x167: 167, x168: 168, x169: 169, x170: 170, x171: 171, x172: 172, x173: 173, x174: 174, x175: 175, x176: 176, x177: 177, x178: 178, x179: 179, x180: 180, x181: 181, x182: 182, x183: 183, x184: 184, x185: 185, x186: 186, x187: 187, x188: 188, x189: 189, x190: 190, x191: 191, x192: 192, x193: 193, x194: 194, x195: 195, x196: 196, x197: 197, x198: 198, x199: 199, x200: 200, x201: 201, x202: 202, x203: 203, x204: 204, x205: 205, x206: 206, x207: 207, x208: 208, x209: 209, x210: 210, x211: 211, x212: 212, x213: 213, x214: 214, x215: 215, x216: 216, x217: 217, x218: 218, x219: 219, x220: 220, x221: 221, x222: 222, x223: 223, x224: 224, x225: 225, x226: 226, x227: 227, x228: 228, x229: 229, x230: 230, x231: 231, x232: 232, x233: 233, x234: 234, x235: 235, x236: 236, x237: 237, x238: 238, x239: 239, x240: 240, x241: 241, x242: 242, x243: 243, x244: 244, x245: 245, x246: 246, x247: 247, x248: 248, x249: 249, x250: 250, x251: 251, x252: 252, x253: 253, x254: 254, x255: 255 }; return foo.x0 + bar.x255 } diff --git a/parser/benches/big_if_else.leo b/parser/benches/big_if_else.leo index 6c974f12a3..db0d5f45e8 100644 --- a/parser/benches/big_if_else.leo +++ b/parser/benches/big_if_else.leo @@ -1,5 +1,5 @@ function main() { - let x: u8 = 191; + const x: u8 = 191; if x == 0 { return x diff --git a/parser/benches/big_ternary.leo b/parser/benches/big_ternary.leo index 6b16291dca..46e9cd6aed 100644 --- a/parser/benches/big_ternary.leo +++ b/parser/benches/big_ternary.leo @@ -1,5 +1,5 @@ function main() { - let x: u8 = 255; + const x: u8 = 255; return x == 0 ? x : (x == 1 ? x : (x == 2 ? x : (x == 3 ? x : (x == 4 ? x : (x == 5 ? x : (x == 6 ? x : (x == 7 ? x : (x == 8 ? x : (x == 9 ? x : (x == 10 ? x : (x == 11 ? x : (x == 12 ? x : (x == 13 ? x : (x == 14 ? x : (x == 15 ? x : (x == 16 ? x : (x == 17 ? x : (x == 18 ? x : (x == 19 ? x : (x == 20 ? x : (x == 21 ? x : (x == 22 ? x : (x == 23 ? x : (x == 24 ? x : (x == 25 ? x : (x == 26 ? x : (x == 27 ? x : (x == 28 ? x : (x == 29 ? x : (x == 30 ? x : (x == 31 ? x : (x == 32 ? x : (x == 33 ? x : (x == 34 ? x : (x == 35 ? x : (x == 36 ? x : (x == 37 ? x : (x == 38 ? x : (x == 39 ? x : (x == 40 ? x : (x == 41 ? x : (x == 42 ? x : (x == 43 ? x : (x == 44 ? x : (x == 45 ? x : (x == 46 ? x : (x == 47 ? x : (x == 48 ? x : (x == 49 ? x : (x == 50 ? x : (x == 51 ? x : (x == 52 ? x : (x == 53 ? x : (x == 54 ? x : (x == 55 ? x : (x == 56 ? x : (x == 57 ? x : (x == 58 ? x : (x == 59 ? x : (x == 60 ? x : (x == 61 ? x : (x == 62 ? x : (x == 63 ? x : (x == 64 ? x : (x == 65 ? x : (x == 66 ? x : (x == 67 ? x : (x == 68 ? x : (x == 69 ? x : (x == 70 ? x : (x == 71 ? x : (x == 72 ? x : (x == 73 ? x : (x == 74 ? x : (x == 75 ? x : (x == 76 ? x : (x == 77 ? x : (x == 78 ? x : (x == 79 ? x : (x == 80 ? x : (x == 81 ? x : (x == 82 ? x : (x == 83 ? x : (x == 84 ? x : (x == 85 ? x : (x == 86 ? x : (x == 87 ? x : (x == 88 ? x : (x == 89 ? x : (x == 90 ? x : (x == 91 ? x : (x == 92 ? x : (x == 93 ? x : (x == 94 ? x : (x == 95 ? x : (x == 96 ? x : (x == 97 ? x : (x == 98 ? x : (x == 99 ? x : (x == 100 ? x : (x == 101 ? x : (x == 102 ? x : (x == 103 ? x : (x == 104 ? x : (x == 105 ? x : (x == 106 ? x : (x == 107 ? x : (x == 108 ? x : (x == 109 ? x : (x == 110 ? x : (x == 111 ? x : (x == 112 ? x : (x == 113 ? x : (x == 114 ? x : (x == 115 ? x : (x == 116 ? x : (x == 117 ? x : (x == 118 ? x : (x == 119 ? x : (x == 120 ? x : (x == 121 ? x : (x == 122 ? x : (x == 123 ? x : (x == 124 ? x : (x == 125 ? x : (x == 126 ? x : (x == 127 ? x : (x == 128 ? x : (x == 129 ? x : (x == 130 ? x : (x == 131 ? x : (x == 132 ? x : (x == 133 ? x : (x == 134 ? x : (x == 135 ? x : (x == 136 ? x : (x == 137 ? x : (x == 138 ? x : (x == 139 ? x : (x == 140 ? x : (x == 141 ? x : (x == 142 ? x : (x == 143 ? x : (x == 144 ? x : (x == 145 ? x : (x == 146 ? x : (x == 147 ? x : (x == 148 ? x : (x == 149 ? x : (x == 150 ? x : (x == 151 ? x : (x == 152 ? x : (x == 153 ? x : (x == 154 ? x : (x == 155 ? x : (x == 156 ? x : (x == 157 ? x : (x == 158 ? x : (x == 159 ? x : (x == 160 ? x : (x == 161 ? x : (x == 162 ? x : (x == 163 ? x : (x == 164 ? x : (x == 165 ? x : (x == 166 ? x : (x == 167 ? x : (x == 168 ? x : (x == 169 ? x : (x == 170 ? x : (x == 171 ? x : (x == 172 ? x : (x == 173 ? x : (x == 174 ? x : (x == 175 ? x : (x == 176 ? x : (x == 177 ? x : (x == 178 ? x : (x == 179 ? x : (x == 180 ? x : (x == 181 ? x : (x == 182 ? x : (x == 183 ? x : (x == 184 ? x : (x == 185 ? x : (x == 186 ? x : (x == 187 ? x : (x == 188 ? x : (x == 189 ? x : (x == 190 ? x : (x == 191 ? x : (x == 192 ? x : (x == 193 ? x : (x == 194 ? x : (x == 195 ? x : (x == 196 ? x : (x == 197 ? x : (x == 198 ? x : (x == 199 ? x : (x == 200 ? x : (x == 201 ? x : (x == 202 ? x : (x == 203 ? x : (x == 204 ? x : (x == 205 ? x : (x == 206 ? x : (x == 207 ? x : (x == 208 ? x : (x == 209 ? x : (x == 210 ? x : (x == 211 ? x : (x == 212 ? x : (x == 213 ? x : (x == 214 ? x : (x == 215 ? x : (x == 216 ? x : (x == 217 ? x : (x == 218 ? x : (x == 219 ? x : (x == 220 ? x : (x == 221 ? x : (x == 222 ? x : (x == 223 ? x : (x == 224 ? x : (x == 225 ? x : (x == 226 ? x : (x == 227 ? x : (x == 228 ? x : (x == 229 ? x : (x == 230 ? x : (x == 231 ? x : (x == 232 ? x : (x == 233 ? x : (x == 234 ? x : (x == 235 ? x : (x == 236 ? x : (x == 237 ? x : (x == 238 ? x : (x == 239 ? x : (x == 240 ? x : (x == 241 ? x : (x == 242 ? x : (x == 243 ? x : (x == 244 ? x : (x == 245 ? x : (x == 246 ? x : (x == 247 ? x : (x == 248 ? x : (x == 249 ? x : (x == 250 ? x : (x == 251 ? x : (x == 252 ? x : (x == 253 ? x : (x == 254 ? x : (x == 255 ? x : 0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) } \ No newline at end of file diff --git a/parser/benches/long_array.leo b/parser/benches/long_array.leo index 282feb66d0..48094244b6 100644 --- a/parser/benches/long_array.leo +++ b/parser/benches/long_array.leo @@ -1,5 +1,5 @@ function main() { - let arr1: [u8; (32, 32)] = [ + const arr1: [u8; (32, 32)] = [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31], @@ -34,7 +34,7 @@ function main() { [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31] ]; - let arr2: [u8; (16, 32)] = [ + const arr2: [u8; (16, 32)] = [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31], diff --git a/parser/benches/long_expr.leo b/parser/benches/long_expr.leo index 8cbfb99939..31cf1e0641 100644 --- a/parser/benches/long_expr.leo +++ b/parser/benches/long_expr.leo @@ -1,9 +1,9 @@ function main() { - let a = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; - let b = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; - let c = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; - let d = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; - let e = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; + const a = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; + const b = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; + const c = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; + const d = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; + const e = 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1; return a + b + c + d + e } diff --git a/parser/benches/many_assigns.leo b/parser/benches/many_assigns.leo index 8f174abc4b..202bbf0da4 100644 --- a/parser/benches/many_assigns.leo +++ b/parser/benches/many_assigns.leo @@ -1,388 +1,388 @@ function main() { - let x0: u8 = 0; - let x1: u8 = x0; - let x2: u8 = x1; - let x3: u8 = x2; - let x4: u8 = x3; - let x5: u8 = x4; - let x6: u8 = x5; - let x7: u8 = x6; - let x8: u8 = x7; - let x9: u8 = x8; - let x10: u8 = x9; - let x11: u8 = x10; - let x12: u8 = x11; - let x13: u8 = x12; - let x14: u8 = x13; - let x15: u8 = x14; - let x16: u8 = x15; - let x17: u8 = x16; - let x18: u8 = x17; - let x19: u8 = x18; - let x20: u8 = x19; - let x21: u8 = x20; - let x22: u8 = x21; - let x23: u8 = x22; - let x24: u8 = x23; - let x25: u8 = x24; - let x26: u8 = x25; - let x27: u8 = x26; - let x28: u8 = x27; - let x29: u8 = x28; - let x30: u8 = x29; - let x31: u8 = x30; - let x32: u8 = x31; - let x33: u8 = x32; - let x34: u8 = x33; - let x35: u8 = x34; - let x36: u8 = x35; - let x37: u8 = x36; - let x38: u8 = x37; - let x39: u8 = x38; - let x40: u8 = x39; - let x41: u8 = x40; - let x42: u8 = x41; - let x43: u8 = x42; - let x44: u8 = x43; - let x45: u8 = x44; - let x46: u8 = x45; - let x47: u8 = x46; - let x48: u8 = x47; - let x49: u8 = x48; - let x50: u8 = x49; - let x51: u8 = x50; - let x52: u8 = x51; - let x53: u8 = x52; - let x54: u8 = x53; - let x55: u8 = x54; - let x56: u8 = x55; - let x57: u8 = x56; - let x58: u8 = x57; - let x59: u8 = x58; - let x60: u8 = x59; - let x61: u8 = x60; - let x62: u8 = x61; - let x63: u8 = x62; - let x64: u8 = x63; - let x65: u8 = x64; - let x66: u8 = x65; - let x67: u8 = x66; - let x68: u8 = x67; - let x69: u8 = x68; - let x70: u8 = x69; - let x71: u8 = x70; - let x72: u8 = x71; - let x73: u8 = x72; - let x74: u8 = x73; - let x75: u8 = x74; - let x76: u8 = x75; - let x77: u8 = x76; - let x78: u8 = x77; - let x79: u8 = x78; - let x80: u8 = x79; - let x81: u8 = x80; - let x82: u8 = x81; - let x83: u8 = x82; - let x84: u8 = x83; - let x85: u8 = x84; - let x86: u8 = x85; - let x87: u8 = x86; - let x88: u8 = x87; - let x89: u8 = x88; - let x90: u8 = x89; - let x91: u8 = x90; - let x92: u8 = x91; - let x93: u8 = x92; - let x94: u8 = x93; - let x95: u8 = x94; - let x96: u8 = x95; - let x97: u8 = x96; - let x98: u8 = x97; - let x99: u8 = x98; - let x100: u8 = x99; - let x101: u8 = x100; - let x102: u8 = x101; - let x103: u8 = x102; - let x104: u8 = x103; - let x105: u8 = x104; - let x106: u8 = x105; - let x107: u8 = x106; - let x108: u8 = x107; - let x109: u8 = x108; - let x110: u8 = x109; - let x111: u8 = x110; - let x112: u8 = x111; - let x113: u8 = x112; - let x114: u8 = x113; - let x115: u8 = x114; - let x116: u8 = x115; - let x117: u8 = x116; - let x118: u8 = x117; - let x119: u8 = x118; - let x120: u8 = x119; - let x121: u8 = x120; - let x122: u8 = x121; - let x123: u8 = x122; - let x124: u8 = x123; - let x125: u8 = x124; - let x126: u8 = x125; - let x127: u8 = x126; - let x128: u8 = x127; - let x129: u8 = x128; - let x130: u8 = x129; - let x131: u8 = x130; - let x132: u8 = x131; - let x133: u8 = x132; - let x134: u8 = x133; - let x135: u8 = x134; - let x136: u8 = x135; - let x137: u8 = x136; - let x138: u8 = x137; - let x139: u8 = x138; - let x140: u8 = x139; - let x141: u8 = x140; - let x142: u8 = x141; - let x143: u8 = x142; - let x144: u8 = x143; - let x145: u8 = x144; - let x146: u8 = x145; - let x147: u8 = x146; - let x148: u8 = x147; - let x149: u8 = x148; - let x150: u8 = x149; - let x151: u8 = x150; - let x152: u8 = x151; - let x153: u8 = x152; - let x154: u8 = x153; - let x155: u8 = x154; - let x156: u8 = x155; - let x157: u8 = x156; - let x158: u8 = x157; - let x159: u8 = x158; - let x160: u8 = x159; - let x161: u8 = x160; - let x162: u8 = x161; - let x163: u8 = x162; - let x164: u8 = x163; - let x165: u8 = x164; - let x166: u8 = x165; - let x167: u8 = x166; - let x168: u8 = x167; - let x169: u8 = x168; - let x170: u8 = x169; - let x171: u8 = x170; - let x172: u8 = x171; - let x173: u8 = x172; - let x174: u8 = x173; - let x175: u8 = x174; - let x176: u8 = x175; - let x177: u8 = x176; - let x178: u8 = x177; - let x179: u8 = x178; - let x180: u8 = x179; - let x181: u8 = x180; - let x182: u8 = x181; - let x183: u8 = x182; - let x184: u8 = x183; - let x185: u8 = x184; - let x186: u8 = x185; - let x187: u8 = x186; - let x188: u8 = x187; - let x189: u8 = x188; - let x190: u8 = x189; - let x191: u8 = x190; - let x192: u8 = x191; - let x193: u8 = x192; - let x194: u8 = x193; - let x195: u8 = x194; - let x196: u8 = x195; - let x197: u8 = x196; - let x198: u8 = x197; - let x199: u8 = x198; - let x200: u8 = x199; - let x201: u8 = x200; - let x202: u8 = x201; - let x203: u8 = x202; - let x204: u8 = x203; - let x205: u8 = x204; - let x206: u8 = x205; - let x207: u8 = x206; - let x208: u8 = x207; - let x209: u8 = x208; - let x210: u8 = x209; - let x211: u8 = x210; - let x212: u8 = x211; - let x213: u8 = x212; - let x214: u8 = x213; - let x215: u8 = x214; - let x216: u8 = x215; - let x217: u8 = x216; - let x218: u8 = x217; - let x219: u8 = x218; - let x220: u8 = x219; - let x221: u8 = x220; - let x222: u8 = x221; - let x223: u8 = x222; - let x224: u8 = x223; - let x225: u8 = x224; - let x226: u8 = x225; - let x227: u8 = x226; - let x228: u8 = x227; - let x229: u8 = x228; - let x230: u8 = x229; - let x231: u8 = x230; - let x232: u8 = x231; - let x233: u8 = x232; - let x234: u8 = x233; - let x235: u8 = x234; - let x236: u8 = x235; - let x237: u8 = x236; - let x238: u8 = x237; - let x239: u8 = x238; - let x240: u8 = x239; - let x241: u8 = x240; - let x242: u8 = x241; - let x243: u8 = x242; - let x244: u8 = x243; - let x245: u8 = x244; - let x246: u8 = x245; - let x247: u8 = x246; - let x248: u8 = x247; - let x249: u8 = x248; - let x250: u8 = x249; - let x251: u8 = x250; - let x252: u8 = x251; - let x253: u8 = x252; - let x254: u8 = x253; - let x255: u8 = x254; - let x256: u8 = x255; - let x257: u8 = x256; - let x258: u8 = x257; - let x259: u8 = x258; - let x260: u8 = x259; - let x261: u8 = x260; - let x262: u8 = x261; - let x263: u8 = x262; - let x264: u8 = x263; - let x265: u8 = x264; - let x266: u8 = x265; - let x267: u8 = x266; - let x268: u8 = x267; - let x269: u8 = x268; - let x270: u8 = x269; - let x271: u8 = x270; - let x272: u8 = x271; - let x273: u8 = x272; - let x274: u8 = x273; - let x275: u8 = x274; - let x276: u8 = x275; - let x277: u8 = x276; - let x278: u8 = x277; - let x279: u8 = x278; - let x280: u8 = x279; - let x281: u8 = x280; - let x282: u8 = x281; - let x283: u8 = x282; - let x284: u8 = x283; - let x285: u8 = x284; - let x286: u8 = x285; - let x287: u8 = x286; - let x288: u8 = x287; - let x289: u8 = x288; - let x290: u8 = x289; - let x291: u8 = x290; - let x292: u8 = x291; - let x293: u8 = x292; - let x294: u8 = x293; - let x295: u8 = x294; - let x296: u8 = x295; - let x297: u8 = x296; - let x298: u8 = x297; - let x299: u8 = x298; - let x300: u8 = x299; - let x301: u8 = x300; - let x302: u8 = x301; - let x303: u8 = x302; - let x304: u8 = x303; - let x305: u8 = x304; - let x306: u8 = x305; - let x307: u8 = x306; - let x308: u8 = x307; - let x309: u8 = x308; - let x310: u8 = x309; - let x311: u8 = x310; - let x312: u8 = x311; - let x313: u8 = x312; - let x314: u8 = x313; - let x315: u8 = x314; - let x316: u8 = x315; - let x317: u8 = x316; - let x318: u8 = x317; - let x319: u8 = x318; - let x320: u8 = x319; - let x321: u8 = x320; - let x322: u8 = x321; - let x323: u8 = x322; - let x324: u8 = x323; - let x325: u8 = x324; - let x326: u8 = x325; - let x327: u8 = x326; - let x328: u8 = x327; - let x329: u8 = x328; - let x330: u8 = x329; - let x331: u8 = x330; - let x332: u8 = x331; - let x333: u8 = x332; - let x334: u8 = x333; - let x335: u8 = x334; - let x336: u8 = x335; - let x337: u8 = x336; - let x338: u8 = x337; - let x339: u8 = x338; - let x340: u8 = x339; - let x341: u8 = x340; - let x342: u8 = x341; - let x343: u8 = x342; - let x344: u8 = x343; - let x345: u8 = x344; - let x346: u8 = x345; - let x347: u8 = x346; - let x348: u8 = x347; - let x349: u8 = x348; - let x350: u8 = x349; - let x351: u8 = x350; - let x352: u8 = x351; - let x353: u8 = x352; - let x354: u8 = x353; - let x355: u8 = x354; - let x356: u8 = x355; - let x357: u8 = x356; - let x358: u8 = x357; - let x359: u8 = x358; - let x360: u8 = x359; - let x361: u8 = x360; - let x362: u8 = x361; - let x363: u8 = x362; - let x364: u8 = x363; - let x365: u8 = x364; - let x366: u8 = x365; - let x367: u8 = x366; - let x368: u8 = x367; - let x369: u8 = x368; - let x370: u8 = x369; - let x371: u8 = x370; - let x372: u8 = x371; - let x373: u8 = x372; - let x374: u8 = x373; - let x375: u8 = x374; - let x376: u8 = x375; - let x377: u8 = x376; - let x378: u8 = x377; - let x379: u8 = x378; - let x380: u8 = x379; - let x381: u8 = x380; - let x382: u8 = x381; - let x383: u8 = x382; + const x0: u8 = 0; + const x1: u8 = x0; + const x2: u8 = x1; + const x3: u8 = x2; + const x4: u8 = x3; + const x5: u8 = x4; + const x6: u8 = x5; + const x7: u8 = x6; + const x8: u8 = x7; + const x9: u8 = x8; + const x10: u8 = x9; + const x11: u8 = x10; + const x12: u8 = x11; + const x13: u8 = x12; + const x14: u8 = x13; + const x15: u8 = x14; + const x16: u8 = x15; + const x17: u8 = x16; + const x18: u8 = x17; + const x19: u8 = x18; + const x20: u8 = x19; + const x21: u8 = x20; + const x22: u8 = x21; + const x23: u8 = x22; + const x24: u8 = x23; + const x25: u8 = x24; + const x26: u8 = x25; + const x27: u8 = x26; + const x28: u8 = x27; + const x29: u8 = x28; + const x30: u8 = x29; + const x31: u8 = x30; + const x32: u8 = x31; + const x33: u8 = x32; + const x34: u8 = x33; + const x35: u8 = x34; + const x36: u8 = x35; + const x37: u8 = x36; + const x38: u8 = x37; + const x39: u8 = x38; + const x40: u8 = x39; + const x41: u8 = x40; + const x42: u8 = x41; + const x43: u8 = x42; + const x44: u8 = x43; + const x45: u8 = x44; + const x46: u8 = x45; + const x47: u8 = x46; + const x48: u8 = x47; + const x49: u8 = x48; + const x50: u8 = x49; + const x51: u8 = x50; + const x52: u8 = x51; + const x53: u8 = x52; + const x54: u8 = x53; + const x55: u8 = x54; + const x56: u8 = x55; + const x57: u8 = x56; + const x58: u8 = x57; + const x59: u8 = x58; + const x60: u8 = x59; + const x61: u8 = x60; + const x62: u8 = x61; + const x63: u8 = x62; + const x64: u8 = x63; + const x65: u8 = x64; + const x66: u8 = x65; + const x67: u8 = x66; + const x68: u8 = x67; + const x69: u8 = x68; + const x70: u8 = x69; + const x71: u8 = x70; + const x72: u8 = x71; + const x73: u8 = x72; + const x74: u8 = x73; + const x75: u8 = x74; + const x76: u8 = x75; + const x77: u8 = x76; + const x78: u8 = x77; + const x79: u8 = x78; + const x80: u8 = x79; + const x81: u8 = x80; + const x82: u8 = x81; + const x83: u8 = x82; + const x84: u8 = x83; + const x85: u8 = x84; + const x86: u8 = x85; + const x87: u8 = x86; + const x88: u8 = x87; + const x89: u8 = x88; + const x90: u8 = x89; + const x91: u8 = x90; + const x92: u8 = x91; + const x93: u8 = x92; + const x94: u8 = x93; + const x95: u8 = x94; + const x96: u8 = x95; + const x97: u8 = x96; + const x98: u8 = x97; + const x99: u8 = x98; + const x100: u8 = x99; + const x101: u8 = x100; + const x102: u8 = x101; + const x103: u8 = x102; + const x104: u8 = x103; + const x105: u8 = x104; + const x106: u8 = x105; + const x107: u8 = x106; + const x108: u8 = x107; + const x109: u8 = x108; + const x110: u8 = x109; + const x111: u8 = x110; + const x112: u8 = x111; + const x113: u8 = x112; + const x114: u8 = x113; + const x115: u8 = x114; + const x116: u8 = x115; + const x117: u8 = x116; + const x118: u8 = x117; + const x119: u8 = x118; + const x120: u8 = x119; + const x121: u8 = x120; + const x122: u8 = x121; + const x123: u8 = x122; + const x124: u8 = x123; + const x125: u8 = x124; + const x126: u8 = x125; + const x127: u8 = x126; + const x128: u8 = x127; + const x129: u8 = x128; + const x130: u8 = x129; + const x131: u8 = x130; + const x132: u8 = x131; + const x133: u8 = x132; + const x134: u8 = x133; + const x135: u8 = x134; + const x136: u8 = x135; + const x137: u8 = x136; + const x138: u8 = x137; + const x139: u8 = x138; + const x140: u8 = x139; + const x141: u8 = x140; + const x142: u8 = x141; + const x143: u8 = x142; + const x144: u8 = x143; + const x145: u8 = x144; + const x146: u8 = x145; + const x147: u8 = x146; + const x148: u8 = x147; + const x149: u8 = x148; + const x150: u8 = x149; + const x151: u8 = x150; + const x152: u8 = x151; + const x153: u8 = x152; + const x154: u8 = x153; + const x155: u8 = x154; + const x156: u8 = x155; + const x157: u8 = x156; + const x158: u8 = x157; + const x159: u8 = x158; + const x160: u8 = x159; + const x161: u8 = x160; + const x162: u8 = x161; + const x163: u8 = x162; + const x164: u8 = x163; + const x165: u8 = x164; + const x166: u8 = x165; + const x167: u8 = x166; + const x168: u8 = x167; + const x169: u8 = x168; + const x170: u8 = x169; + const x171: u8 = x170; + const x172: u8 = x171; + const x173: u8 = x172; + const x174: u8 = x173; + const x175: u8 = x174; + const x176: u8 = x175; + const x177: u8 = x176; + const x178: u8 = x177; + const x179: u8 = x178; + const x180: u8 = x179; + const x181: u8 = x180; + const x182: u8 = x181; + const x183: u8 = x182; + const x184: u8 = x183; + const x185: u8 = x184; + const x186: u8 = x185; + const x187: u8 = x186; + const x188: u8 = x187; + const x189: u8 = x188; + const x190: u8 = x189; + const x191: u8 = x190; + const x192: u8 = x191; + const x193: u8 = x192; + const x194: u8 = x193; + const x195: u8 = x194; + const x196: u8 = x195; + const x197: u8 = x196; + const x198: u8 = x197; + const x199: u8 = x198; + const x200: u8 = x199; + const x201: u8 = x200; + const x202: u8 = x201; + const x203: u8 = x202; + const x204: u8 = x203; + const x205: u8 = x204; + const x206: u8 = x205; + const x207: u8 = x206; + const x208: u8 = x207; + const x209: u8 = x208; + const x210: u8 = x209; + const x211: u8 = x210; + const x212: u8 = x211; + const x213: u8 = x212; + const x214: u8 = x213; + const x215: u8 = x214; + const x216: u8 = x215; + const x217: u8 = x216; + const x218: u8 = x217; + const x219: u8 = x218; + const x220: u8 = x219; + const x221: u8 = x220; + const x222: u8 = x221; + const x223: u8 = x222; + const x224: u8 = x223; + const x225: u8 = x224; + const x226: u8 = x225; + const x227: u8 = x226; + const x228: u8 = x227; + const x229: u8 = x228; + const x230: u8 = x229; + const x231: u8 = x230; + const x232: u8 = x231; + const x233: u8 = x232; + const x234: u8 = x233; + const x235: u8 = x234; + const x236: u8 = x235; + const x237: u8 = x236; + const x238: u8 = x237; + const x239: u8 = x238; + const x240: u8 = x239; + const x241: u8 = x240; + const x242: u8 = x241; + const x243: u8 = x242; + const x244: u8 = x243; + const x245: u8 = x244; + const x246: u8 = x245; + const x247: u8 = x246; + const x248: u8 = x247; + const x249: u8 = x248; + const x250: u8 = x249; + const x251: u8 = x250; + const x252: u8 = x251; + const x253: u8 = x252; + const x254: u8 = x253; + const x255: u8 = x254; + const x256: u8 = x255; + const x257: u8 = x256; + const x258: u8 = x257; + const x259: u8 = x258; + const x260: u8 = x259; + const x261: u8 = x260; + const x262: u8 = x261; + const x263: u8 = x262; + const x264: u8 = x263; + const x265: u8 = x264; + const x266: u8 = x265; + const x267: u8 = x266; + const x268: u8 = x267; + const x269: u8 = x268; + const x270: u8 = x269; + const x271: u8 = x270; + const x272: u8 = x271; + const x273: u8 = x272; + const x274: u8 = x273; + const x275: u8 = x274; + const x276: u8 = x275; + const x277: u8 = x276; + const x278: u8 = x277; + const x279: u8 = x278; + const x280: u8 = x279; + const x281: u8 = x280; + const x282: u8 = x281; + const x283: u8 = x282; + const x284: u8 = x283; + const x285: u8 = x284; + const x286: u8 = x285; + const x287: u8 = x286; + const x288: u8 = x287; + const x289: u8 = x288; + const x290: u8 = x289; + const x291: u8 = x290; + const x292: u8 = x291; + const x293: u8 = x292; + const x294: u8 = x293; + const x295: u8 = x294; + const x296: u8 = x295; + const x297: u8 = x296; + const x298: u8 = x297; + const x299: u8 = x298; + const x300: u8 = x299; + const x301: u8 = x300; + const x302: u8 = x301; + const x303: u8 = x302; + const x304: u8 = x303; + const x305: u8 = x304; + const x306: u8 = x305; + const x307: u8 = x306; + const x308: u8 = x307; + const x309: u8 = x308; + const x310: u8 = x309; + const x311: u8 = x310; + const x312: u8 = x311; + const x313: u8 = x312; + const x314: u8 = x313; + const x315: u8 = x314; + const x316: u8 = x315; + const x317: u8 = x316; + const x318: u8 = x317; + const x319: u8 = x318; + const x320: u8 = x319; + const x321: u8 = x320; + const x322: u8 = x321; + const x323: u8 = x322; + const x324: u8 = x323; + const x325: u8 = x324; + const x326: u8 = x325; + const x327: u8 = x326; + const x328: u8 = x327; + const x329: u8 = x328; + const x330: u8 = x329; + const x331: u8 = x330; + const x332: u8 = x331; + const x333: u8 = x332; + const x334: u8 = x333; + const x335: u8 = x334; + const x336: u8 = x335; + const x337: u8 = x336; + const x338: u8 = x337; + const x339: u8 = x338; + const x340: u8 = x339; + const x341: u8 = x340; + const x342: u8 = x341; + const x343: u8 = x342; + const x344: u8 = x343; + const x345: u8 = x344; + const x346: u8 = x345; + const x347: u8 = x346; + const x348: u8 = x347; + const x349: u8 = x348; + const x350: u8 = x349; + const x351: u8 = x350; + const x352: u8 = x351; + const x353: u8 = x352; + const x354: u8 = x353; + const x355: u8 = x354; + const x356: u8 = x355; + const x357: u8 = x356; + const x358: u8 = x357; + const x359: u8 = x358; + const x360: u8 = x359; + const x361: u8 = x360; + const x362: u8 = x361; + const x363: u8 = x362; + const x364: u8 = x363; + const x365: u8 = x364; + const x366: u8 = x365; + const x367: u8 = x366; + const x368: u8 = x367; + const x369: u8 = x368; + const x370: u8 = x369; + const x371: u8 = x370; + const x372: u8 = x371; + const x373: u8 = x372; + const x374: u8 = x373; + const x375: u8 = x374; + const x376: u8 = x375; + const x377: u8 = x376; + const x378: u8 = x377; + const x379: u8 = x378; + const x380: u8 = x379; + const x381: u8 = x380; + const x382: u8 = x381; + const x383: u8 = x382; return x383 } diff --git a/parser/src/errors/deprecated.rs b/parser/src/errors/deprecated.rs index 496c3db306..b16a4f5247 100644 --- a/parser/src/errors/deprecated.rs +++ b/parser/src/errors/deprecated.rs @@ -43,8 +43,8 @@ impl LeoError for DeprecatedError { } impl DeprecatedError { - pub fn const_statement(span: &Span) -> Self { - let message = "const _ = ... is deprecated. Did you mean let?".to_string(); + pub fn let_mut_statement(span: &Span) -> Self { + let message = "let mut = ... is deprecated. `let` keyword implies mutabality by default.".to_string(); Self::new_from_span(message, span) } diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index c01190fa0b..b57215f398 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -286,15 +286,17 @@ 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); + pub fn parse_variable_name(&mut self, span: &SpannedToken) -> SyntaxResult { + if self.eat(Token::Mut).is_some() { + return Err(SyntaxError::DeprecatedError(DeprecatedError::let_mut_statement( + &span.span, + ))); + } + 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(), + span: name.span.clone(), + mutable: matches!(span.token, Token::Let), identifier: name, }) } @@ -306,13 +308,13 @@ impl ParserContext { 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()?); + variable_names.push(self.parse_variable_name(&declare)?); while self.eat(Token::Comma).is_some() { - variable_names.push(self.parse_variable_name()?); + variable_names.push(self.parse_variable_name(&declare)?); } self.expect(Token::RightParen)?; } else { - variable_names.push(self.parse_variable_name()?); + variable_names.push(self.parse_variable_name(&declare)?); } let type_ = if self.eat(Token::Colon).is_some() { @@ -329,12 +331,7 @@ impl ParserContext { 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 - } + Token::Const => Declare::Const, _ => unimplemented!(), }, variable_names, diff --git a/tests/fail/parse/address/empty.leo b/tests/fail/parse/address/empty.leo index e5c06d0def..305a77de5b 100644 --- a/tests/fail/parse/address/empty.leo +++ b/tests/fail/parse/address/empty.leo @@ -1,3 +1,3 @@ function main() { - let owner = address(); + const 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 index c1b7f719be..ae1defecaf 100644 --- a/tests/fail/parse/address/invalid_length.leo +++ b/tests/fail/parse/address/invalid_length.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j88); + const 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 index 81959d2fa6..cd87e404a4 100644 --- a/tests/fail/parse/address/invalid_prefix.leo +++ b/tests/fail/parse/address/invalid_prefix.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const public_key_string = address(zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); } \ No newline at end of file diff --git a/tests/fail/parse/array/type_fail.leo b/tests/fail/parse/array/type_fail.leo index 1402ceba4c..356bba976a 100644 --- a/tests/fail/parse/array/type_fail.leo +++ b/tests/fail/parse/array/type_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: [u8; -2] = [0u32; 2]; + const 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 index 5a1d6c63be..18329433f7 100644 --- a/tests/fail/parse/circuits/self_circuit.leo +++ b/tests/fail/parse/circuits/self_circuit.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let a = Foo::new(); + const a = Foo::new(); } \ No newline at end of file diff --git a/tests/fail/parse/syntax/address_fail.leo b/tests/fail/parse/syntax/address_fail.leo index 4eb12c7743..b39ea75df6 100644 --- a/tests/fail/parse/syntax/address_fail.leo +++ b/tests/fail/parse/syntax/address_fail.leo @@ -1,3 +1,3 @@ function main() { - let address = 0u32; + const 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 index 6ee932a66b..c0229dd624 100644 --- a/tests/fail/parse/syntax/console_fail.leo +++ b/tests/fail/parse/syntax/console_fail.leo @@ -1,3 +1,3 @@ function main() { - let console = 0u32; + const 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 index a1f85dc6ea..33bb3118d8 100644 --- a/tests/fail/parse/syntax/field_fail.leo +++ b/tests/fail/parse/syntax/field_fail.leo @@ -1,3 +1,3 @@ function main() { - let field = 0u32; + const 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 index 322997ea50..db71c8a792 100644 --- a/tests/fail/parse/syntax/group_fail.leo +++ b/tests/fail/parse/syntax/group_fail.leo @@ -1,3 +1,3 @@ function main() { - let group = 0u32; + const 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 index 596a9056ab..a2d868f9f5 100644 --- a/tests/fail/parse/syntax/i8_fail.leo +++ b/tests/fail/parse/syntax/i8_fail.leo @@ -1,3 +1,3 @@ function main() { - let i8 = 0u32; + const 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 index e1b466d6d4..0053565a6f 100644 --- a/tests/fail/parse/syntax/input_fail.leo +++ b/tests/fail/parse/syntax/input_fail.leo @@ -1,3 +1,3 @@ function main() { - let input = 0u32; + const 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 index 28b899ccd4..79bc4d6e96 100644 --- a/tests/fail/parse/syntax/self_keyword_fail.leo +++ b/tests/fail/parse/syntax/self_keyword_fail.leo @@ -1,3 +1,3 @@ function main() { - let Self = 0u32; + const 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 index 28b899ccd4..79bc4d6e96 100644 --- a/tests/fail/parse/syntax/self_type_fail.leo +++ b/tests/fail/parse/syntax/self_type_fail.leo @@ -1,3 +1,3 @@ function main() { - let Self = 0u32; + const Self = 0u32; } \ No newline at end of file diff --git a/tests/fail/parse/syntax/semicolon.leo b/tests/fail/parse/syntax/semicolon.leo index 68cfa7cbe0..f1deb29e37 100644 --- a/tests/fail/parse/syntax/semicolon.leo +++ b/tests/fail/parse/syntax/semicolon.leo @@ -1,3 +1,3 @@ function main() { - let a = 0 + const 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 index 4eb12c7743..b39ea75df6 100644 --- a/tests/fail/parse/syntax/true_fail.leo +++ b/tests/fail/parse/syntax/true_fail.leo @@ -1,3 +1,3 @@ function main() { - let address = 0u32; + const 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 index 77687f5ff2..4a48780a29 100644 --- a/tests/fail/parse/syntax/u8_fail.leo +++ b/tests/fail/parse/syntax/u8_fail.leo @@ -1,3 +1,3 @@ function main() { - let u8 = 0u32; + const 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 index 3e7a5f106d..17849256ca 100644 --- a/tests/pass/parse/address/console_assert_fail.leo +++ b/tests/pass/parse/address/console_assert_fail.leo @@ -1,6 +1,6 @@ function main() { - let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9); + const address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const 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 index 60ea4a79cd..f17d7d8c05 100644 --- a/tests/pass/parse/address/console_assert_pass.leo +++ b/tests/pass/parse/address/console_assert_pass.leo @@ -1,6 +1,6 @@ function main() { - let address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_1 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const address_2 = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); console.assert(address_1 == address_2); } \ No newline at end of file diff --git a/tests/pass/parse/address/implicit_invalid.leo b/tests/pass/parse/address/implicit_invalid.leo index 6f8eba5114..aadc38a6d8 100644 --- a/tests/pass/parse/address/implicit_invalid.leo +++ b/tests/pass/parse/address/implicit_invalid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = zleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const 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 index df6ebf497d..75bcbaa8a1 100644 --- a/tests/pass/parse/address/implicit_valid.leo +++ b/tests/pass/parse/address/implicit_valid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; + const 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 index 795deac98b..29519f0334 100644 --- a/tests/pass/parse/address/input.leo +++ b/tests/pass/parse/address/input.leo @@ -1,5 +1,5 @@ function main(owner: address) { - let sender = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const 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 index bdd88b9d92..dc87153d2d 100644 --- a/tests/pass/parse/address/ternary.leo +++ b/tests/pass/parse/address/ternary.leo @@ -1,8 +1,8 @@ function main(s: bool, c: address) { - let a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); - let b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); + const a = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const b = address(aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r); - let r = s? a: b; + const r = 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 index f06aefdaa6..18f1682526 100644 --- a/tests/pass/parse/address/valid.leo +++ b/tests/pass/parse/address/valid.leo @@ -1,3 +1,3 @@ function main() { - let public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); + const public_key_string = address(aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8); } \ No newline at end of file diff --git a/tests/pass/parse/array/multi_fail_initializer.leo b/tests/pass/parse/array/multi_fail_initializer.leo index 258750b327..be1ab315bd 100644 --- a/tests/pass/parse/array/multi_fail_initializer.leo +++ b/tests/pass/parse/array/multi_fail_initializer.leo @@ -1,3 +1,3 @@ function main() { - let arr: [u8; (2, 2)] = [[1u8; 2]; 1]; // incorrect dimensions + const 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 index 50a06c09b2..49c9296798 100644 --- a/tests/pass/parse/array/multi_fail_inline.leo +++ b/tests/pass/parse/array/multi_fail_inline.leo @@ -1,4 +1,4 @@ function main() { - let arr: [u8; (2, 2)] = [[1u8, 1u8], + const 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 index 7257999ddf..6133542ef0 100644 --- a/tests/pass/parse/array/multi_initializer.leo +++ b/tests/pass/parse/array/multi_initializer.leo @@ -1,7 +1,7 @@ function main() { - let a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; + const a: [u8; (2, 2, 2)] = [1u8; (2, 2, 2)]; - let b: [u8; (2, 2, 2)] = [[[1u8; 2]; 2]; 2]; + const 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 index 0bd76acffa..e38a8fdaee 100644 --- a/tests/pass/parse/array/multi_initializer_fail.leo +++ b/tests/pass/parse/array/multi_initializer_fail.leo @@ -1,3 +1,3 @@ function main() { - let arr: [u8; (2, 2)] = [1u8; (2, 1)]; // incorrect dimensions + const 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 index c557758b05..80fc5511bf 100644 --- a/tests/pass/parse/array/nested.leo +++ b/tests/pass/parse/array/nested.leo @@ -1,4 +1,4 @@ function main () { - let x = [false; (2, 2)]; - let y: bool = x[0][0]; + const x = [false; (2, 2)]; + const 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 index b69ddffb89..c5f64c997e 100644 --- a/tests/pass/parse/array/nested_3x2_value.leo +++ b/tests/pass/parse/array/nested_3x2_value.leo @@ -1,8 +1,8 @@ // Multidimensional array syntax in leo function main() { - let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline - let b: [u32; (3, 2)] = [[0; 2]; 3]; // initializer + const 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 index 35c8478cd1..a187a51991 100644 --- a/tests/pass/parse/array/nested_3x2_value_fail.leo +++ b/tests/pass/parse/array/nested_3x2_value_fail.leo @@ -1,4 +1,4 @@ // Multidimensional array syntax in leo function main() { - let a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) + const a: [u32; (3, 2)] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) } diff --git a/tests/pass/parse/array/slice.leo b/tests/pass/parse/array/slice.leo index 296f5bd050..9ff83dbbb8 100644 --- a/tests/pass/parse/array/slice.leo +++ b/tests/pass/parse/array/slice.leo @@ -1,6 +1,6 @@ // `{from}..{to}` copies the elements of one array into another exclusively function main(a: [u8; 3]) { - let b = [1u8; 4]; + const 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 index dd669830ea..0af6fbd937 100644 --- a/tests/pass/parse/array/slice_lower.leo +++ b/tests/pass/parse/array/slice_lower.leo @@ -1,8 +1,8 @@ function main() { - let arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; - let expected: [u32; 2] = [0, 1]; + const arr: [u32; 9] = [0, 1, 2, 3, 4, 5, 6, 7, 8]; + const expected: [u32; 2] = [0, 1]; - let actual = arr[..2]; // Should produce [0, 1] + const 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 index 962e92c923..8bd2861aae 100644 --- a/tests/pass/parse/array/spread.leo +++ b/tests/pass/parse/array/spread.leo @@ -1,7 +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]; + const b = [1u8, 1u8]; + const 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 index dc9128c51e..b6659539d5 100644 --- a/tests/pass/parse/array/tuple_3x2_value.leo +++ b/tests/pass/parse/array/tuple_3x2_value.leo @@ -1,8 +1,8 @@ // Multidimensional array syntax in leo function main() { - let a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline + const a = [[0u32, 0u32], [0u32, 0u32], [0u32, 0u32]]; // inline - let b: [u32; (3, 2)] = [0; (3, 2)]; // initializer + const 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 index 42e6f61500..78593ab696 100644 --- a/tests/pass/parse/array/tuple_3x2_value_fail.leo +++ b/tests/pass/parse/array/tuple_3x2_value_fail.leo @@ -1,4 +1,4 @@ // Multidimensional array syntax in leo function main() { - let a: [u32; (3, 2)] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) + const 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 index 40781415c1..ea60a0cc24 100644 --- a/tests/pass/parse/array/type_input_3x2.leo +++ b/tests/pass/parse/array/type_input_3x2.leo @@ -1,5 +1,5 @@ function main(a: [[u8; 2]; 3]) { - let b = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const 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 index bd75514904..2d9c4cff22 100644 --- a/tests/pass/parse/array/type_input_4x3x2.leo +++ b/tests/pass/parse/array/type_input_4x3x2.leo @@ -1,5 +1,5 @@ function main(a: [[[u8; 2]; 3]; 4]) { - let b = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 diff --git a/tests/pass/parse/array/type_nested_value_nested_3x2.leo b/tests/pass/parse/array/type_nested_value_nested_3x2.leo index 341b9ead9c..bcf5bae674 100644 --- a/tests/pass/parse/array/type_nested_value_nested_3x2.leo +++ b/tests/pass/parse/array/type_nested_value_nested_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [[u8; 2]; 3] = [[0; 2]; 3]; // initializer + const 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 index 4bd07f85db..56c8916fb0 100644 --- a/tests/pass/parse/array/type_nested_value_nested_3x2_fail.leo +++ b/tests/pass/parse/array/type_nested_value_nested_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[u8; 2]; 3] = [[0; 3]; 2]; // initializer (incorrectly reversed ordering) + const 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 index 5ba24a381b..1691fa26c7 100644 --- a/tests/pass/parse/array/type_nested_value_nested_4x3x2.leo +++ b/tests/pass/parse/array/type_nested_value_nested_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const 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 index 6479004d68..480327a91d 100644 --- a/tests/pass/parse/array/type_nested_value_nested_4x3x2_fail.leo +++ b/tests/pass/parse/array/type_nested_value_nested_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[[u8; 2]; 3]; 4] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) + const 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 index c6fac9ec64..5f14084d55 100644 --- a/tests/pass/parse/array/type_nested_value_tuple_3x2.leo +++ b/tests/pass/parse/array/type_nested_value_tuple_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [[u8; 2]; 3] = [0; (3, 2)]; // initializer + const 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 index ba99b070c7..3bfb559615 100644 --- a/tests/pass/parse/array/type_nested_value_tuple_3x2_fail.leo +++ b/tests/pass/parse/array/type_nested_value_tuple_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[u8; 2]; 3] = [0; (2, 3)]; // initializer (incorrectly reversed ordering) + const 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 index 9be45de408..88a5143bd2 100644 --- a/tests/pass/parse/array/type_nested_value_tuple_4x3x2.leo +++ b/tests/pass/parse/array/type_nested_value_tuple_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const 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 index 95172bf329..ce1219a37b 100644 --- a/tests/pass/parse/array/type_nested_value_tuple_4x3x2_fail.leo +++ b/tests/pass/parse/array/type_nested_value_tuple_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [[[u8; 2]; 3]; 4] = [0; (2, 3, 4)]; // initializer (incorrectly reversed ordering) + const 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 index 4e061c4309..81195e03a1 100644 --- a/tests/pass/parse/array/type_tuple_value_nested_3x2.leo +++ b/tests/pass/parse/array/type_tuple_value_nested_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (3, 2)] = [[0; 2]; 3]; // initializer + const 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 index 9732cf26ef..e84f025a9f 100644 --- a/tests/pass/parse/array/type_tuple_value_nested_3x2_fail.leo +++ b/tests/pass/parse/array/type_tuple_value_nested_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (2, 3)] = [[0; 2]; 3]; // initializer (incorrectly reversed ordering) + const 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 index d9dc698784..322a6f7601 100644 --- a/tests/pass/parse/array/type_tuple_value_nested_4x3x2.leo +++ b/tests/pass/parse/array/type_tuple_value_nested_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const 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 index b820c4d088..cbb7ccbf76 100644 --- a/tests/pass/parse/array/type_tuple_value_nested_4x3x2_fail.leo +++ b/tests/pass/parse/array/type_tuple_value_nested_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (4, 3, 2)] = [[[0; 4]; 3]; 2]; // initializer (incorrectly reversed ordering) + const 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 index b0693f7667..d451a9c1a8 100644 --- a/tests/pass/parse/array/type_tuple_value_tuple_3x2.leo +++ b/tests/pass/parse/array/type_tuple_value_tuple_3x2.leo @@ -1,7 +1,7 @@ function main() { - let a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline + const a = [[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]]; // inline - let b: [u8; (3, 2)] = [0; (3, 2)]; // initializer + const 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 index 99487ccb7a..884a75db9d 100644 --- a/tests/pass/parse/array/type_tuple_value_tuple_3x2_fail.leo +++ b/tests/pass/parse/array/type_tuple_value_tuple_3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (2, 3)] = [0; (3, 2)]; // initializer (incorrectly reversed ordering) + const 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 index cdc1bc961e..1205b1dc9c 100644 --- a/tests/pass/parse/array/type_tuple_value_tuple_4x3x2.leo +++ b/tests/pass/parse/array/type_tuple_value_tuple_4x3x2.leo @@ -1,10 +1,10 @@ function main() { - let a = [[[0u8, 0u8], [0u8, 0u8], [0u8, 0u8]], + const 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 + const 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 index 824fd90bc6..31e2a5e552 100644 --- a/tests/pass/parse/array/type_tuple_value_tuple_4x3x2_fail.leo +++ b/tests/pass/parse/array/type_tuple_value_tuple_4x3x2_fail.leo @@ -1,3 +1,3 @@ function main() { - let b: [u8; (4, 3, 2)] = [0; (2, 3, 4)]; // initializer (incorrectly reversed order) + const 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 index edb04caacf..e79d64112f 100644 --- a/tests/pass/parse/array/variable_slice_fail.leo +++ b/tests/pass/parse/array/variable_slice_fail.leo @@ -1,7 +1,7 @@ function main() { - let a = [1u8; 10]; + const a = [1u8; 10]; for i in 0..10 { - let x = a[i..10]; + const 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 index 29a3815881..64fe8a795a 100644 --- a/tests/pass/parse/boolean/all.leo +++ b/tests/pass/parse/boolean/all.leo @@ -1,8 +1,8 @@ // !(true && (false || true)) function main() { - let a = true; - let b = false || a; - let c = !(true && b); + const a = true; + const b = false || a; + const c = !(true && b); console.assert(c == false); } \ No newline at end of file diff --git a/tests/pass/parse/boolean/conditional_mut.leo b/tests/pass/parse/boolean/conditional_mut.leo index e6716cb05a..cebf82ab00 100644 --- a/tests/pass/parse/boolean/conditional_mut.leo +++ b/tests/pass/parse/boolean/conditional_mut.leo @@ -1,6 +1,6 @@ function main () { - let mut x = true; + let x = true; if x { - let y = 0u8; + const 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 index 70e4b0797b..03dfabab4d 100644 --- a/tests/pass/parse/boolean/false_and_false.leo +++ b/tests/pass/parse/boolean/false_and_false.leo @@ -1,5 +1,5 @@ function main() { - let a = false && false; + const 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 index 4ae820254e..7ea710802c 100644 --- a/tests/pass/parse/boolean/false_or_false.leo +++ b/tests/pass/parse/boolean/false_or_false.leo @@ -1,5 +1,5 @@ function main() { - let a = false || false; + const a = false || false; console.assert(a == false); } \ No newline at end of file diff --git a/tests/pass/parse/boolean/not_mutable.leo b/tests/pass/parse/boolean/not_mutable.leo index 91a6e5ff37..c621647ff9 100644 --- a/tests/pass/parse/boolean/not_mutable.leo +++ b/tests/pass/parse/boolean/not_mutable.leo @@ -1,4 +1,4 @@ function main () { - let mut b = false; - let a = !b; + let b = false; + const a = !b; } \ 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 index 3c7c484603..336dde7558 100644 --- a/tests/pass/parse/boolean/true_and_false.leo +++ b/tests/pass/parse/boolean/true_and_false.leo @@ -1,5 +1,5 @@ function main() { - let a = true && false; + const 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 index c378e50024..dae445dcf8 100644 --- a/tests/pass/parse/boolean/true_and_true.leo +++ b/tests/pass/parse/boolean/true_and_true.leo @@ -1,5 +1,5 @@ function main() { - let a = true && true; + const 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 index e5b3a8c001..ad3ead9040 100644 --- a/tests/pass/parse/boolean/true_and_u32.leo +++ b/tests/pass/parse/boolean/true_and_u32.leo @@ -1,3 +1,3 @@ function main() { - let a = true && 1u32; + const 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 index d643a96aa1..216e473cdb 100644 --- a/tests/pass/parse/boolean/true_or_false.leo +++ b/tests/pass/parse/boolean/true_or_false.leo @@ -1,5 +1,5 @@ function main() { - let a = true || false; + const 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 index b8eaa91ff1..fea8628b9f 100644 --- a/tests/pass/parse/boolean/true_or_true.leo +++ b/tests/pass/parse/boolean/true_or_true.leo @@ -1,5 +1,5 @@ function main() { - let a = true || true; + const 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 index 500b5f7bf4..38dab727b9 100644 --- a/tests/pass/parse/boolean/true_or_u32.leo +++ b/tests/pass/parse/boolean/true_or_u32.leo @@ -1,3 +1,3 @@ function main() { - let a = true || 1u32; + const 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 index 8c25c1e9d9..cedabf2185 100644 --- a/tests/pass/parse/circuits/define_circuit_inside_circuit_function.leo +++ b/tests/pass/parse/circuits/define_circuit_inside_circuit_function.leo @@ -4,10 +4,10 @@ circuit Foo { circuit Bar { function bar() { - let f = Foo { a: 0u32 }; + const f = Foo { a: 0u32 }; } } function main() { - let b = Bar::bar(); + const 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 index 98ff42d8f0..66640e75a2 100644 --- a/tests/pass/parse/circuits/duplicate_name_context.leo +++ b/tests/pass/parse/circuits/duplicate_name_context.leo @@ -7,7 +7,7 @@ circuit Bar { } function main () { - let Bar = 66u32; - let k1 = Bar{ b2: 30u32 }; - let k2 = Bar::add_five(55u32); + const Bar = 66u32; + const k1 = Bar{ b2: 30u32 }; + const 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 index 8e214c729a..9ba06f4191 100644 --- a/tests/pass/parse/circuits/inline.leo +++ b/tests/pass/parse/circuits/inline.leo @@ -3,5 +3,5 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const 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 index 52792a07e0..01597005fb 100644 --- a/tests/pass/parse/circuits/inline_fail.leo +++ b/tests/pass/parse/circuits/inline_fail.leo @@ -3,5 +3,5 @@ circuit Foo { } function main() { - let a = Foo { y: 0u32 }; + const 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 index 7f0b8f7889..59f6d7992b 100644 --- a/tests/pass/parse/circuits/inline_member_fail.leo +++ b/tests/pass/parse/circuits/inline_member_fail.leo @@ -3,6 +3,6 @@ circuit Foo { } function main() { - let y: u8 = 1; - let a = Foo { y }; + const y: u8 = 1; + const 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 index 5541a65638..8e58e4935a 100644 --- a/tests/pass/parse/circuits/inline_member_pass.leo +++ b/tests/pass/parse/circuits/inline_member_pass.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let x: u8 = 1; - let a = Foo { x }; - let b = Foo::new(x); + const x: u8 = 1; + const a = Foo { x }; + const 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 index af070e01e9..40c4cf722c 100644 --- a/tests/pass/parse/circuits/inline_undefined.leo +++ b/tests/pass/parse/circuits/inline_undefined.leo @@ -1,3 +1,3 @@ function main() { - let a = Foo { }; + const 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 index e40603dffb..258b6c675e 100644 --- a/tests/pass/parse/circuits/member_function.leo +++ b/tests/pass/parse/circuits/member_function.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const 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 index 224b79cbf4..5a1c4100c5 100644 --- a/tests/pass/parse/circuits/member_function_fail.leo +++ b/tests/pass/parse/circuits/member_function_fail.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let a = Foo { }; - let err = a.echoed(1u32); + const a = Foo { }; + const 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 index bb834e9562..aa689eb976 100644 --- a/tests/pass/parse/circuits/member_function_invalid.leo +++ b/tests/pass/parse/circuits/member_function_invalid.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let a = Foo { }; - let err = a.echo(1u32); // echo is a static function and must be accessed using `::` + const a = Foo { }; + const 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 index 9e07cc9acf..e512c9df52 100644 --- a/tests/pass/parse/circuits/member_function_nested.leo +++ b/tests/pass/parse/circuits/member_function_nested.leo @@ -11,8 +11,8 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; - let b = a.add_x(1u32); + const a = Foo { x: 1u32 }; + const 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 index 4bf51190f0..9d53314f27 100644 --- a/tests/pass/parse/circuits/member_static_function.leo +++ b/tests/pass/parse/circuits/member_static_function.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let a = Foo::echo(1u32); + const 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 index 09fec386d9..7829b4b430 100644 --- a/tests/pass/parse/circuits/member_static_function_invalid.leo +++ b/tests/pass/parse/circuits/member_static_function_invalid.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let err = Foo.echo(1u32); // Invalid, echo is a static function and must be accessed using `::` + const 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_undefined.leo b/tests/pass/parse/circuits/member_static_function_undefined.leo index cf9f98c7b4..ece1d00963 100644 --- a/tests/pass/parse/circuits/member_static_function_undefined.leo +++ b/tests/pass/parse/circuits/member_static_function_undefined.leo @@ -5,5 +5,5 @@ circuit Foo { } function main() { - let err = Foo::echoed(1u32); + const 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 index 0dd35f2aec..a3f3fbe7e6 100644 --- a/tests/pass/parse/circuits/member_variable.leo +++ b/tests/pass/parse/circuits/member_variable.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const 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 index 074feab7b8..3b90db7eaa 100644 --- a/tests/pass/parse/circuits/member_variable_and_function.leo +++ b/tests/pass/parse/circuits/member_variable_and_function.leo @@ -7,9 +7,9 @@ circuit Foo { } function main() { - let a = Foo { foo: 1 }; + const a = Foo { foo: 1 }; - let b = a.foo + Foo::bar(); + const 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 index 5780704ea2..fdf42068d5 100644 --- a/tests/pass/parse/circuits/member_variable_fail.leo +++ b/tests/pass/parse/circuits/member_variable_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let a = Foo { x: 1u32 }; + const a = Foo { x: 1u32 }; - let err = a.y; + const 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 index 3469f97627..1b87e2bfb1 100644 --- a/tests/pass/parse/circuits/mut_function_fail.leo +++ b/tests/pass/parse/circuits/mut_function_fail.leo @@ -5,7 +5,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let 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 index 8c9b99f6ae..58c8088ba1 100644 --- a/tests/pass/parse/circuits/mut_self_function_fail.leo +++ b/tests/pass/parse/circuits/mut_self_function_fail.leo @@ -9,7 +9,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let 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 index 8c9b99f6ae..58c8088ba1 100644 --- a/tests/pass/parse/circuits/mut_self_static_function_fail.leo +++ b/tests/pass/parse/circuits/mut_self_static_function_fail.leo @@ -9,7 +9,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let 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 index f5a35ec754..92bcca0050 100644 --- a/tests/pass/parse/circuits/mut_self_variable.leo +++ b/tests/pass/parse/circuits/mut_self_variable.leo @@ -8,7 +8,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/tests/pass/parse/circuits/mut_self_variable_branch.leo b/tests/pass/parse/circuits/mut_self_variable_branch.leo index e47f9b85df..0c5b8f40a4 100644 --- a/tests/pass/parse/circuits/mut_self_variable_branch.leo +++ b/tests/pass/parse/circuits/mut_self_variable_branch.leo @@ -10,7 +10,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/tests/pass/parse/circuits/mut_self_variable_conditional.leo b/tests/pass/parse/circuits/mut_self_variable_conditional.leo index 74345afcb4..61a5e354dc 100644 --- a/tests/pass/parse/circuits/mut_self_variable_conditional.leo +++ b/tests/pass/parse/circuits/mut_self_variable_conditional.leo @@ -1,5 +1,5 @@ function main() { - let mut f = Foo { a: 0u32 }; + let f = Foo { a: 0u32 }; f.bar(); } diff --git a/tests/pass/parse/circuits/mut_self_variable_fail.leo b/tests/pass/parse/circuits/mut_self_variable_fail.leo index fdbb556bca..4db62a4d3e 100644 --- a/tests/pass/parse/circuits/mut_self_variable_fail.leo +++ b/tests/pass/parse/circuits/mut_self_variable_fail.leo @@ -7,7 +7,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let 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 index ed3092c656..fd873bd17b 100644 --- a/tests/pass/parse/circuits/mut_static_function_fail.leo +++ b/tests/pass/parse/circuits/mut_static_function_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let 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 index 243d7a2cf2..151babb1cd 100644 --- a/tests/pass/parse/circuits/mut_variable.leo +++ b/tests/pass/parse/circuits/mut_variable.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let mut f = Foo { a: 0u8 }; + let f = Foo { a: 0u8 }; console.assert(f.a == 0u8); diff --git a/tests/pass/parse/circuits/mut_variable_fail.leo b/tests/pass/parse/circuits/mut_variable_fail.leo index 4d58150c95..7ba4193074 100644 --- a/tests/pass/parse/circuits/mut_variable_fail.leo +++ b/tests/pass/parse/circuits/mut_variable_fail.leo @@ -3,7 +3,7 @@ circuit Foo { } function main() { - let f = Foo { a: 0u8 }; + const 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 index 559ebb7614..4abef65caa 100644 --- a/tests/pass/parse/circuits/pedersen_mock.leo +++ b/tests/pass/parse/circuits/pedersen_mock.leo @@ -6,9 +6,9 @@ circuit PedersenHash { } function hash(self, bits: [bool; 512]) -> u32 { - let mut digest: u32 = 0; + let digest: u32 = 0; for i in 0..512 { - let base = bits[i] ? self.parameters[i] : 0u32; + const base = bits[i] ? self.parameters[i] : 0u32; digest += base; } return digest @@ -17,11 +17,11 @@ circuit PedersenHash { // The 'pedersen_hash' main function. function main() { - let parameters = [0u32; 512]; - let pedersen = PedersenHash::new(parameters); - let hash_input: [bool; 512] = [true; 512]; + const parameters = [0u32; 512]; + const pedersen = PedersenHash::new(parameters); + const hash_input: [bool; 512] = [true; 512]; - let res = pedersen.hash(hash_input); + const res = pedersen.hash(hash_input); console.assert(res == 0u32); } diff --git a/tests/pass/parse/circuits/self_member.leo b/tests/pass/parse/circuits/self_member.leo index 1bd978433d..2b3401a228 100644 --- a/tests/pass/parse/circuits/self_member.leo +++ b/tests/pass/parse/circuits/self_member.leo @@ -7,8 +7,8 @@ circuit Foo { } function main() { - let a = Foo { f: 1u32 }; - let b = a.bar(); + const a = Foo { f: 1u32 }; + const 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 index 2e8b14f66c..163499d619 100644 --- a/tests/pass/parse/circuits/self_member_invalid.leo +++ b/tests/pass/parse/circuits/self_member_invalid.leo @@ -7,6 +7,6 @@ circuit Foo { } function main() -> u32 { - let foo = Foo { f: 1u32 }; - let err = foo.bar(); + const foo = Foo { f: 1u32 }; + const 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 index 471ffb973c..05a40905d7 100644 --- a/tests/pass/parse/circuits/self_member_undefined.leo +++ b/tests/pass/parse/circuits/self_member_undefined.leo @@ -5,6 +5,6 @@ circuit Foo { } function main() { - let foo = Foo { }; - let err = foo.bar(); + const foo = Foo { }; + const 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 index f5ddfb4e7f..ed25576751 100644 --- a/tests/pass/parse/compiler/main.leo +++ b/tests/pass/parse/compiler/main.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 1 + 2; + const a: u32 = 1 + 2; } \ 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 index ccdd4c5af9..614490432d 100644 --- a/tests/pass/parse/core/arguments_length_fail.leo +++ b/tests/pass/parse/core/arguments_length_fail.leo @@ -1,9 +1,9 @@ import core.unstable.blake2s.Blake2s; function main() { - let seed: [u8; 32] = [0; 32]; + const seed: [u8; 32] = [0; 32]; - let result = Blake2s::hash(seed); // function `hash` takes 2 arguments + const 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 index 13c7e9735e..f80e7b0205 100644 --- a/tests/pass/parse/core/arguments_type_fail.leo +++ b/tests/pass/parse/core/arguments_type_fail.leo @@ -1,10 +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] + const seed: [u8; 32] = [0; 32]; + const message: [u16; 32] = [0; 32]; // message should be type [u8; 32] - let result = Blake2s::hash(seed, message); + const result = Blake2s::hash(seed, message); console.log("Result: {}", result); } diff --git a/tests/pass/parse/core/blake2s_random.leo b/tests/pass/parse/core/blake2s_random.leo index 72aef44932..c9592fcbf8 100644 --- a/tests/pass/parse/core/blake2s_random.leo +++ b/tests/pass/parse/core/blake2s_random.leo @@ -1,7 +1,7 @@ import core.unstable.blake2s.Blake2s; function main(seed: [u8; 32], message: [u8; 32], expected: [u8; 32]) { - let actual = Blake2s::hash(seed, message); + const actual = Blake2s::hash(seed, message); console.assert(expected == actual); } diff --git a/tests/pass/parse/core/unstable_blake2s.leo b/tests/pass/parse/core/unstable_blake2s.leo index ca7db13892..c430d9a837 100644 --- a/tests/pass/parse/core/unstable_blake2s.leo +++ b/tests/pass/parse/core/unstable_blake2s.leo @@ -1,10 +1,10 @@ import core.unstable.blake2s.Blake2s; function main() { - let seed: [u8; 32] = [0; 32]; - let message: [u8; 32] = [0; 32]; + const seed: [u8; 32] = [0; 32]; + const message: [u8; 32] = [0; 32]; - let result = Blake2s::hash(seed, message); + const result = Blake2s::hash(seed, message); console.log("Result: {}", result); } diff --git a/tests/pass/parse/field/field.leo b/tests/pass/parse/field/field.leo index 3f109881ad..5d5732e906 100644 --- a/tests/pass/parse/field/field.leo +++ b/tests/pass/parse/field/field.leo @@ -1,4 +1,4 @@ function main() { - let negOneField: field = -1field; - let oneField = 1field; + const negOneField: field = -1field; + const oneField = 1field; } \ No newline at end of file diff --git a/tests/pass/parse/field/ternary.leo b/tests/pass/parse/field/ternary.leo index f193ad82a3..05cb161b46 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 = s ? a : b; + const r = 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 index a70483cae7..899c0e4af6 100644 --- a/tests/pass/parse/function/array_input.leo +++ b/tests/pass/parse/function/array_input.leo @@ -1,6 +1,6 @@ function foo(a: [u8; 1]) {} function main() { - let a: [u16; 1] = [1; 1]; + const 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 index 9305b0958d..8ded724bc4 100644 --- a/tests/pass/parse/function/array_params_direct_call.leo +++ b/tests/pass/parse/function/array_params_direct_call.leo @@ -1,7 +1,7 @@ function do_nothing(arr: [u32; 2]) {} function main() { - let arr: [u32; 2] = [0; 2]; + const arr: [u32; 2] = [0; 2]; do_nothing(arr); do_nothing([...arr]); diff --git a/tests/pass/parse/function/iteration.leo b/tests/pass/parse/function/iteration.leo index 19af4dd9cf..b1fcee6964 100644 --- a/tests/pass/parse/function/iteration.leo +++ b/tests/pass/parse/function/iteration.leo @@ -3,7 +3,7 @@ function one() -> u32 { } function main() { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += one(); diff --git a/tests/pass/parse/function/iteration_repeated.leo b/tests/pass/parse/function/iteration_repeated.leo index 3694b3594a..d76380a6b5 100644 --- a/tests/pass/parse/function/iteration_repeated.leo +++ b/tests/pass/parse/function/iteration_repeated.leo @@ -1,5 +1,5 @@ function iteration() -> u32 { - let mut a = 0u32; + let a = 0u32; for i in 0..10 { a += 1; @@ -9,7 +9,7 @@ function iteration() -> u32 { } function main() { - let total = iteration() + iteration(); + const 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 index ef00a4ef47..d927c51976 100644 --- a/tests/pass/parse/function/multiple_returns.leo +++ b/tests/pass/parse/function/multiple_returns.leo @@ -3,7 +3,7 @@ function tuple() -> (bool, bool) { } function main() { - let (a, b) = tuple(); + const (a, b) = tuple(); console.assert(a == true); console.assert(b == false); diff --git a/tests/pass/parse/function/multiple_returns_fail_conditional.leo b/tests/pass/parse/function/multiple_returns_fail_conditional.leo index 04ebb9e306..227fe5ce12 100644 --- a/tests/pass/parse/function/multiple_returns_fail_conditional.leo +++ b/tests/pass/parse/function/multiple_returns_fail_conditional.leo @@ -1,7 +1,7 @@ function main () -> u16 { if false { - let a = 1u16; - let b = a + 1u16; + const a = 1u16; + const b = a + 1u16; return b } else if false { return 0u16 diff --git a/tests/pass/parse/function/repeated.leo b/tests/pass/parse/function/repeated.leo index a2d04d55f9..f83fa6098b 100644 --- a/tests/pass/parse/function/repeated.leo +++ b/tests/pass/parse/function/repeated.leo @@ -3,7 +3,7 @@ function one() -> bool { } function main() { - let a = one() && one(); + const a = one() && one(); console.assert(a == true); } \ 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 index dca001d9cc..8eca684b8a 100644 --- a/tests/pass/parse/function/return_array_nested_fail.leo +++ b/tests/pass/parse/function/return_array_nested_fail.leo @@ -3,5 +3,5 @@ function array_3x2_tuple() -> [[u8; 2]; 3] { } function main() { - let b = array_3x2_tuple(); + const 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 index dda5b4342b..bfbfc8fd29 100644 --- a/tests/pass/parse/function/return_array_nested_pass.leo +++ b/tests/pass/parse/function/return_array_nested_pass.leo @@ -7,6 +7,6 @@ function array_3x2_tuple() -> [[u8; 2]; 3] { } function main() { - let a = array_3x2_nested(); - let b = array_3x2_tuple(); + const a = array_3x2_nested(); + const 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 index 4b7377e327..c960456ac1 100644 --- a/tests/pass/parse/function/return_array_tuple_fail.leo +++ b/tests/pass/parse/function/return_array_tuple_fail.leo @@ -3,5 +3,5 @@ function array_3x2_nested() -> [u8; (3, 2)] { } function main() { - let a = array_3x2_nested(); + const 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 index a700bcabad..4199e31990 100644 --- a/tests/pass/parse/function/return_array_tuple_pass.leo +++ b/tests/pass/parse/function/return_array_tuple_pass.leo @@ -7,6 +7,6 @@ function array_3x2_tuple() -> [u8; (3, 2)] { } function main() { - let a = array_3x2_nested(); - let b = array_3x2_tuple(); + const a = array_3x2_nested(); + const 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 index c459740a47..a3b1bbc36a 100644 --- a/tests/pass/parse/function/return_tuple.leo +++ b/tests/pass/parse/function/return_tuple.leo @@ -1,11 +1,11 @@ // Returns a tuple of tuples. function tuples() -> ((u8, u8), u32) { - let a: (u8, u8) = (1, 2); - let b: u32 = 3; + const a: (u8, u8) = (1, 2); + const b: u32 = 3; return (a, b) } function main() { - let t = tuples(); + const 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 index c63967f548..839081b2a4 100644 --- a/tests/pass/parse/function/return_tuple_conditional.leo +++ b/tests/pass/parse/function/return_tuple_conditional.leo @@ -11,5 +11,5 @@ function tuple_conditional () -> ( } function main() { - let t = tuple_conditional(); + const 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 index 773c2479d7..6f1d390541 100644 --- a/tests/pass/parse/function/scope_fail.leo +++ b/tests/pass/parse/function/scope_fail.leo @@ -3,6 +3,6 @@ function foo() -> field { } function main() { - let myGlobal = 42field; - let err = foo(); + const myGlobal = 42field; + const err = foo(); } \ No newline at end of file diff --git a/tests/pass/parse/function/value_unchanged.leo b/tests/pass/parse/function/value_unchanged.leo index 32dcfa62d6..936ff2ddcc 100644 --- a/tests/pass/parse/function/value_unchanged.leo +++ b/tests/pass/parse/function/value_unchanged.leo @@ -12,7 +12,7 @@ function bad_mutate(mut x: u32) { } function main() { - let a = 1u32; + const a = 1u32; bad_mutate(a); console.assert(a == 1u32); // <- value `a` is still `1u32` diff --git a/tests/pass/parse/group/both_sign_high.leo b/tests/pass/parse/group/both_sign_high.leo index a8217d6d40..4c93573e1e 100644 --- a/tests/pass/parse/group/both_sign_high.leo +++ b/tests/pass/parse/group/both_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, +)group; + const 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 index b3b8b512c3..0bbd360ba0 100644 --- a/tests/pass/parse/group/both_sign_inferred.leo +++ b/tests/pass/parse/group/both_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, _)group; + const 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 index 0519c6d17d..1cb4f46c55 100644 --- a/tests/pass/parse/group/both_sign_low.leo +++ b/tests/pass/parse/group/both_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, -)group; + const element = (-, -)group; } \ No newline at end of file diff --git a/tests/pass/parse/group/one.leo b/tests/pass/parse/group/one.leo index 7be0cbbc2c..510110150b 100644 --- a/tests/pass/parse/group/one.leo +++ b/tests/pass/parse/group/one.leo @@ -1,3 +1,3 @@ function main() { - let element = 1group; + const element = 1group; } \ No newline at end of file diff --git a/tests/pass/parse/group/point.leo b/tests/pass/parse/group/point.leo index 85eeb53b7b..5e68415a0d 100644 --- a/tests/pass/parse/group/point.leo +++ b/tests/pass/parse/group/point.leo @@ -1,3 +1,3 @@ function main() { - let point = (7374112779530666882856915975292384652154477718021969292781165691637980424078, 3435195339177955418892975564890903138308061187980579490487898366607011481796)group; + const 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 index 68d8c458a3..a3a8e63bd3 100644 --- a/tests/pass/parse/group/point_input.leo +++ b/tests/pass/parse/group/point_input.leo @@ -1,3 +1,3 @@ function main(a: group) { - let b = a; + const 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 index fdf9b892be..5d29e36ef2 100644 --- a/tests/pass/parse/group/positive_and_negative.leo +++ b/tests/pass/parse/group/positive_and_negative.leo @@ -1,10 +1,10 @@ function main() { - let pos_element = 1group; - let neg_element = -1group; + const pos_element = 1group; + const neg_element = -1group; - let pair_x_pos = (1, _)group; - let pair_x_neg = (-1, _)group; + const pair_x_pos = (1, _)group; + const pair_x_neg = (-1, _)group; - let pair_y_pos = (_, 1)group; - let pair_y_neg = (_, -1)group; + const pair_y_pos = (_, 1)group; + const pair_y_neg = (_, -1)group; } \ No newline at end of file diff --git a/tests/pass/parse/group/ternary.leo b/tests/pass/parse/group/ternary.leo index fb69b74521..97fba1f5b6 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 = s ? a : b; + const r = 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 index 1b64702db1..a350a7ad6b 100644 --- a/tests/pass/parse/group/x_and_y.leo +++ b/tests/pass/parse/group/x_and_y.leo @@ -1,3 +1,3 @@ function main(element: group) { - let b = element; + const 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 index 1b8d397d02..f38b54ad9a 100644 --- a/tests/pass/parse/group/x_sign_high.leo +++ b/tests/pass/parse/group/x_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, +)group; + const 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 index 9e9622a4a4..02c5ac988b 100644 --- a/tests/pass/parse/group/x_sign_inferred.leo +++ b/tests/pass/parse/group/x_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, _)group; + const 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 index a5058bda52..ad74d18b64 100644 --- a/tests/pass/parse/group/x_sign_low.leo +++ b/tests/pass/parse/group/x_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (0, -)group; + const 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 index fe16883b39..af2a20149d 100644 --- a/tests/pass/parse/group/y_sign_high.leo +++ b/tests/pass/parse/group/y_sign_high.leo @@ -1,3 +1,3 @@ function main() { - let element = (+, 1)group; + const 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 index 003c373cf2..a4efa6a982 100644 --- a/tests/pass/parse/group/y_sign_inferred.leo +++ b/tests/pass/parse/group/y_sign_inferred.leo @@ -1,3 +1,3 @@ function main() { - let element = (_, 1)group; + const 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 index 9e61bfd2bb..f557ed0d35 100644 --- a/tests/pass/parse/group/y_sign_low.leo +++ b/tests/pass/parse/group/y_sign_low.leo @@ -1,3 +1,3 @@ function main() { - let element = (-, 1)group; + const 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 index e2c0283c21..6cdd4c960e 100644 --- a/tests/pass/parse/group/zero.leo +++ b/tests/pass/parse/group/zero.leo @@ -1,3 +1,3 @@ function main() { - let element = 0group; + const element = 0group; } \ No newline at end of file diff --git a/tests/pass/parse/import/many_import.leo b/tests/pass/parse/import/many_import.leo index 5e85f19778..08ae494c4f 100644 --- a/tests/pass/parse/import/many_import.leo +++ b/tests/pass/parse/import/many_import.leo @@ -12,15 +12,15 @@ import bar.( // imports directory import import car.Car; // imports directory import function main() { - let point = Point { x: 1u32, y: 1u32 }; - let foo = foo(); + const point = Point { x: 1u32, y: 1u32 }; + const foo = foo(); - let bar = Bar { r: 1u32 }; - let baz = Baz { z: 1u32 }; - let bazzar = Bazzar { a: 1u32 }; - let bat = Bat { t: 1u32 }; + const bar = Bar { r: 1u32 }; + const baz = Baz { z: 1u32 }; + const bazzar = Bazzar { a: 1u32 }; + const bat = Bat { t: 1u32 }; - let car = Car { c: 1u32 }; + const 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 index 5145d0d05d..575487a929 100644 --- a/tests/pass/parse/import/many_import_star.leo +++ b/tests/pass/parse/import/many_import_star.leo @@ -6,14 +6,14 @@ import bar.bat.bat.*; // imports directory import import car.*; // imports directory import function main() { - let point = Point { x: 1u32, y: 1u32 }; - let foo = foo(); + const point = Point { x: 1u32, y: 1u32 }; + const foo = foo(); - let bar = Bar { r: 1u32 }; - let bat = Bat { t: 1u32 }; - let baz = Baz { z: 1u32 }; + const bar = Bar { r: 1u32 }; + const bat = Bat { t: 1u32 }; + const baz = Baz { z: 1u32 }; - let car = Car { c: 1u32 }; + const 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 index 5c89aaee0c..4bd181c02d 100644 --- a/tests/pass/parse/import/multiple.leo +++ b/tests/pass/parse/import/multiple.leo @@ -4,7 +4,7 @@ import test-import.( ); function main() { - let a = Point { x: 1u32, y: 0u32 }; + const a = Point { x: 1u32, y: 0u32 }; console.assert(a.x == 1u32); } \ No newline at end of file diff --git a/tests/pass/parse/import/star.leo b/tests/pass/parse/import/star.leo index 9cd817686f..69d0791627 100644 --- a/tests/pass/parse/import/star.leo +++ b/tests/pass/parse/import/star.leo @@ -1,7 +1,7 @@ import test-import.*; function main() { - let a = Point { x: 1u32, y: 0u32 }; + const a = Point { x: 1u32, y: 0u32 }; console.assert(foo() == 1u32); } \ No newline at end of file diff --git a/tests/pass/parse/integers/i128/max.leo b/tests/pass/parse/integers/i128/max.leo index 46c0a32599..5ba44213e1 100644 --- a/tests/pass/parse/integers/i128/max.leo +++ b/tests/pass/parse/integers/i128/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = 170141183460469231731687303715884105727; + const 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 index 820eda8759..a9a46afd7f 100644 --- a/tests/pass/parse/integers/i128/max_fail.leo +++ b/tests/pass/parse/integers/i128/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = 170141183460469231731687303715884105728; + const 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 index 5f32e5add5..19509a3fb0 100644 --- a/tests/pass/parse/integers/i128/min.leo +++ b/tests/pass/parse/integers/i128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = -170141183460469231731687303715884105728; + const 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 index 9035444fa9..918f0e439d 100644 --- a/tests/pass/parse/integers/i128/min_fail.leo +++ b/tests/pass/parse/integers/i128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i128 = -170141183460469231731687303715884105729; + const a: i128 = -170141183460469231731687303715884105729; } \ 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 index cfbd308362..c9de272960 100644 --- a/tests/pass/parse/integers/i128/negate_min.leo +++ b/tests/pass/parse/integers/i128/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a: i128 = -170141183460469231731687303715884105728; - let b = -a; + const a: i128 = -170141183460469231731687303715884105728; + const 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 index 9fb0c11afe..e079baf393 100644 --- a/tests/pass/parse/integers/i128/negate_zero.leo +++ b/tests/pass/parse/integers/i128/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i128; + const a = 0i128; console.assert(-a == 0i128); } \ 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 a923c428e6..3783463b22 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index 084fe4969a..2b70b3cc56 100644 --- a/tests/pass/parse/integers/i16/max.leo +++ b/tests/pass/parse/integers/i16/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = 32767; + const 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 index 8dd2b7f50a..209bcc6518 100644 --- a/tests/pass/parse/integers/i16/max_fail.leo +++ b/tests/pass/parse/integers/i16/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = 32768; + const 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 index 3331281fcf..3d05bef95a 100644 --- a/tests/pass/parse/integers/i16/min.leo +++ b/tests/pass/parse/integers/i16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = -32768; + const 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 index 380848381a..13d7c8b7f2 100644 --- a/tests/pass/parse/integers/i16/min_fail.leo +++ b/tests/pass/parse/integers/i16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i16 = -32769; + const a: i16 = -32769; } \ 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 index 2622f8d2a3..d52a356396 100644 --- a/tests/pass/parse/integers/i16/negate_min.leo +++ b/tests/pass/parse/integers/i16/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -32768i16; - let b = -a; + const a = -32768i16; + const 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 index 46340c3dc5..20f8a4fba7 100644 --- a/tests/pass/parse/integers/i16/negate_zero.leo +++ b/tests/pass/parse/integers/i16/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i16; + const a = 0i16; console.assert(-a == 0i16); } \ 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 4586b87bb4..d66c73cb93 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index a9c707eb7f..074c75f1a6 100644 --- a/tests/pass/parse/integers/i32/max.leo +++ b/tests/pass/parse/integers/i32/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = 2147483647; + const 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 index f3fd81815f..af2877ff5e 100644 --- a/tests/pass/parse/integers/i32/max_fail.leo +++ b/tests/pass/parse/integers/i32/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = 2147483648; + const 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 index a29d591029..8436268ce6 100644 --- a/tests/pass/parse/integers/i32/min.leo +++ b/tests/pass/parse/integers/i32/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = -2147483648; + const 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 index 1462d207e9..11a683b087 100644 --- a/tests/pass/parse/integers/i32/min_fail.leo +++ b/tests/pass/parse/integers/i32/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i32 = -2147483649; + const a: i32 = -2147483649; } \ 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 index b3c10064e1..a96455d57a 100644 --- a/tests/pass/parse/integers/i32/negate_min.leo +++ b/tests/pass/parse/integers/i32/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -2147483648i32; - let b = -a; + const a = -2147483648i32; + const 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 index 5533f575a6..a3807b1f8a 100644 --- a/tests/pass/parse/integers/i32/negate_zero.leo +++ b/tests/pass/parse/integers/i32/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i32; + const a = 0i32; console.assert(-a == 0i32); } \ 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 7927c2998b..790769d62f 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index e0d19881e6..593f91e110 100644 --- a/tests/pass/parse/integers/i64/max.leo +++ b/tests/pass/parse/integers/i64/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = 9223372036854775807; + const 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 index 3e6603e4be..362b794a2c 100644 --- a/tests/pass/parse/integers/i64/max_fail.leo +++ b/tests/pass/parse/integers/i64/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = 9223372036854775808; + const 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 index d7e99a87f8..794d8fbfac 100644 --- a/tests/pass/parse/integers/i64/min.leo +++ b/tests/pass/parse/integers/i64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = -9223372036854775808; + const 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 index 11e43646b0..bb260ecc3f 100644 --- a/tests/pass/parse/integers/i64/min_fail.leo +++ b/tests/pass/parse/integers/i64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i64 = -9223372036854775809; + const a: i64 = -9223372036854775809; } \ 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 index 4dd27778d0..daf694491b 100644 --- a/tests/pass/parse/integers/i64/negate_min.leo +++ b/tests/pass/parse/integers/i64/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a: i64 = -9223372036854775808; - let b = -a; + const a: i64 = -9223372036854775808; + const 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 index 6badfe4dc7..81f09c19a3 100644 --- a/tests/pass/parse/integers/i64/negate_zero.leo +++ b/tests/pass/parse/integers/i64/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i64; + const a = 0i64; console.assert(-a == 0i64); } \ 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 1a2d03a77f..df63b3ad6a 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index b51126da59..f20d59ddf4 100644 --- a/tests/pass/parse/integers/i8/max.leo +++ b/tests/pass/parse/integers/i8/max.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = 127; + const 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 index 4892505915..9e1956024a 100644 --- a/tests/pass/parse/integers/i8/max_fail.leo +++ b/tests/pass/parse/integers/i8/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = 128; + const 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 index d3c1bff5e4..7b6db025ea 100644 --- a/tests/pass/parse/integers/i8/min.leo +++ b/tests/pass/parse/integers/i8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = -128; + const 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 index 051468ea70..41170e9b93 100644 --- a/tests/pass/parse/integers/i8/min_fail.leo +++ b/tests/pass/parse/integers/i8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: i8 = -129; + const a: i8 = -129; } \ 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 index 3959da615e..7f664a1b78 100644 --- a/tests/pass/parse/integers/i8/negate_min.leo +++ b/tests/pass/parse/integers/i8/negate_min.leo @@ -1,4 +1,4 @@ function main() { - let a = -128i8; - let b = -a; + const a = -128i8; + const 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 index 21fbbab675..cc3f4a0828 100644 --- a/tests/pass/parse/integers/i8/negate_zero.leo +++ b/tests/pass/parse/integers/i8/negate_zero.leo @@ -1,5 +1,5 @@ function main() { - let a = 0i8; + const a = 0i8; console.assert(-a == 0i8); } \ 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 e1ec1943c9..0956a9cd39 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index 6da59dd058..b166ede06b 100644 --- a/tests/pass/parse/integers/u128/max.leo +++ b/tests/pass/parse/integers/u128/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 340282366920938463463374607431768211455; + const 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 index 40cdf7d2bb..f51c967925 100644 --- a/tests/pass/parse/integers/u128/max_fail.leo +++ b/tests/pass/parse/integers/u128/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 340282366920938463463374607431768211456; + const 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 index 044bda9e1c..41fbf1a2fe 100644 --- a/tests/pass/parse/integers/u128/min.leo +++ b/tests/pass/parse/integers/u128/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = 0; + const 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 index df2390c576..b0d17191ff 100644 --- a/tests/pass/parse/integers/u128/min_fail.leo +++ b/tests/pass/parse/integers/u128/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u128 = -1; + const a: u128 = -1; } \ 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 22e2e67058..99a6b997e0 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index a707df9af8..56cb2af18d 100644 --- a/tests/pass/parse/integers/u16/max.leo +++ b/tests/pass/parse/integers/u16/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 65535; + const 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 index 68ff0481e0..bb703210e3 100644 --- a/tests/pass/parse/integers/u16/max_fail.leo +++ b/tests/pass/parse/integers/u16/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 65536; + const 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 index ab1bd7db48..4dee94a1a4 100644 --- a/tests/pass/parse/integers/u16/min.leo +++ b/tests/pass/parse/integers/u16/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = 0; + const 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 index 99b7310362..0c61dd7ddf 100644 --- a/tests/pass/parse/integers/u16/min_fail.leo +++ b/tests/pass/parse/integers/u16/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u16 = -1; + const a: u16 = -1; } \ 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 11d836570d..d6131f9f4f 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index 2950164a08..4a07281b5d 100644 --- a/tests/pass/parse/integers/u32/max.leo +++ b/tests/pass/parse/integers/u32/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 4294967295; + const 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 index 96c7e01657..6b1631876e 100644 --- a/tests/pass/parse/integers/u32/max_fail.leo +++ b/tests/pass/parse/integers/u32/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 4294967296; + const 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 index 0f1c080938..8077e0ec02 100644 --- a/tests/pass/parse/integers/u32/min.leo +++ b/tests/pass/parse/integers/u32/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = 0; + const 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 index a8d41c475a..c3e3f33225 100644 --- a/tests/pass/parse/integers/u32/min_fail.leo +++ b/tests/pass/parse/integers/u32/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u32 = -1; + const a: u32 = -1; } \ 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 3c96a7236c..f32ffc29fe 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index 985897c006..f14ac7ce64 100644 --- a/tests/pass/parse/integers/u64/max.leo +++ b/tests/pass/parse/integers/u64/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 18446744073709551615; + const 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 index 0ca3f13895..d606c83585 100644 --- a/tests/pass/parse/integers/u64/max_fail.leo +++ b/tests/pass/parse/integers/u64/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 18446744073709551616; + const 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 index aa9b72fc8a..b1da40b14c 100644 --- a/tests/pass/parse/integers/u64/min.leo +++ b/tests/pass/parse/integers/u64/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = 0; + const 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 index 81b90cc74a..e58f1897e6 100644 --- a/tests/pass/parse/integers/u64/min_fail.leo +++ b/tests/pass/parse/integers/u64/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u64 = -1; + const a: u64 = -1; } \ 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 4c4ddd8e0c..4427cd0466 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 = s ? a : b; + const r = s ? a : b; console.assert(r == 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 index 684bdfba10..03e82c9a5e 100644 --- a/tests/pass/parse/integers/u8/max.leo +++ b/tests/pass/parse/integers/u8/max.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 255; + const 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 index f2b870096d..01bb544601 100644 --- a/tests/pass/parse/integers/u8/max_fail.leo +++ b/tests/pass/parse/integers/u8/max_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 256; + const 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 index a88e33c5a6..1db08a07b5 100644 --- a/tests/pass/parse/integers/u8/min.leo +++ b/tests/pass/parse/integers/u8/min.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = 0; + const 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 index 7b91dc6e1a..3cd8d46de7 100644 --- a/tests/pass/parse/integers/u8/min_fail.leo +++ b/tests/pass/parse/integers/u8/min_fail.leo @@ -1,3 +1,3 @@ function main() { - let a: u8 = -1; + const a: u8 = -1; } \ 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 1b436aa054..5123a511cd 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 = s ? a : b; + const r = 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 index 1d51c15271..ea63baaad2 100644 --- a/tests/pass/parse/mutability/array.leo +++ b/tests/pass/parse/mutability/array.leo @@ -1,5 +1,5 @@ // Arrays are immutable by default. function main() { - let a = [1u32]; + const 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 index 1b86bac80f..5d4db3b68a 100644 --- a/tests/pass/parse/mutability/array_mut.leo +++ b/tests/pass/parse/mutability/array_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [1u32]; + let a = [1u32]; a[0] = 0; console.assert(a[0] == 0u32); diff --git a/tests/pass/parse/mutability/array_splice_mut.leo b/tests/pass/parse/mutability/array_splice_mut.leo index 57cc67e872..d13216600a 100644 --- a/tests/pass/parse/mutability/array_splice_mut.leo +++ b/tests/pass/parse/mutability/array_splice_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [1u32, 2u32, 3u32]; + let a = [1u32, 2u32, 3u32]; a[0u32..2u32] = [4u32, 5u32]; console.assert(a[0] == 4u32); diff --git a/tests/pass/parse/mutability/array_tuple_mut.leo b/tests/pass/parse/mutability/array_tuple_mut.leo index e0096bd7ac..ed323d46da 100644 --- a/tests/pass/parse/mutability/array_tuple_mut.leo +++ b/tests/pass/parse/mutability/array_tuple_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes an array variable mutable. function main() { - let mut a = [(1u32, 2u32)]; + let a = [(1u32, 2u32)]; a[0u32].1 = 3u32; console.assert(a[0u32].0 == 1u32); diff --git a/tests/pass/parse/mutability/circuit.leo b/tests/pass/parse/mutability/circuit.leo index be1c568836..508595ef16 100644 --- a/tests/pass/parse/mutability/circuit.leo +++ b/tests/pass/parse/mutability/circuit.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let a = Foo { x: 1 }; + const 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 index eba1d02c0e..c1bc941c94 100644 --- a/tests/pass/parse/mutability/circuit_function_mut.leo +++ b/tests/pass/parse/mutability/circuit_function_mut.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let 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 index 27bd6109b2..f7067db11e 100644 --- a/tests/pass/parse/mutability/circuit_mut.leo +++ b/tests/pass/parse/mutability/circuit_mut.leo @@ -4,7 +4,7 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.x = 0; console.assert(a.x == 0u32); diff --git a/tests/pass/parse/mutability/circuit_static_function_mut.leo b/tests/pass/parse/mutability/circuit_static_function_mut.leo index eba1d02c0e..c1bc941c94 100644 --- a/tests/pass/parse/mutability/circuit_static_function_mut.leo +++ b/tests/pass/parse/mutability/circuit_static_function_mut.leo @@ -4,6 +4,6 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let 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 index 27bd6109b2..f7067db11e 100644 --- a/tests/pass/parse/mutability/circuit_variable_mut.leo +++ b/tests/pass/parse/mutability/circuit_variable_mut.leo @@ -4,7 +4,7 @@ circuit Foo { } function main() { - let mut a = Foo { x: 1 }; + let a = Foo { x: 1 }; a.x = 0; console.assert(a.x == 0u32); diff --git a/tests/pass/parse/mutability/const.leo b/tests/pass/parse/mutability/const.leo index d2a3a6ac2b..6201e7c5af 100644 --- a/tests/pass/parse/mutability/const.leo +++ b/tests/pass/parse/mutability/const.leo @@ -1,5 +1,5 @@ // Let variables are immutable by default. function main() { - let a = 1u32; + const a = 1u32; a = 0; } \ No newline at end of file diff --git a/tests/pass/parse/mutability/let.leo b/tests/pass/parse/mutability/let.leo index 477e6b35f5..105730adb7 100644 --- a/tests/pass/parse/mutability/let.leo +++ b/tests/pass/parse/mutability/let.leo @@ -1,5 +1,5 @@ // Variables are immutable by default. function main() { - let a = 1u32; + const 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 index 5766d144d3..cd1060d0d2 100644 --- a/tests/pass/parse/mutability/let_mut.leo +++ b/tests/pass/parse/mutability/let_mut.leo @@ -1,6 +1,6 @@ // Adding the `mut` keyword makes a variable mutable. function main() { - let mut a = 1u32; + let a = 1u32; a = 0; console.assert(a == 0u32); diff --git a/tests/pass/parse/mutability/let_mut_nested.leo b/tests/pass/parse/mutability/let_mut_nested.leo index 27121f6e48..93236ef4c6 100644 --- a/tests/pass/parse/mutability/let_mut_nested.leo +++ b/tests/pass/parse/mutability/let_mut_nested.leo @@ -1,5 +1,5 @@ function main () { - let mut x = 2u8; - let mut y = x; - let z = y / 2u8; + let x = 2u8; + let y = x; + const 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 index 0a209149ee..b2a795e826 100644 --- a/tests/pass/parse/mutability/swap.leo +++ b/tests/pass/parse/mutability/swap.leo @@ -1,17 +1,17 @@ // Swap two elements of an array. function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { - let t = a[i]; + const 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]; + let arr: [u32; 2] = [0, 1]; + const expected: [u32; 2] = [1, 0]; // Do swap. - let actual = swap(arr, 0, 1); + const actual = swap(arr, 0, 1); // Check result. for i in 0..2 { diff --git a/tests/pass/parse/statements/block.leo b/tests/pass/parse/statements/block.leo index 8650808041..ca8da645ec 100644 --- a/tests/pass/parse/statements/block.leo +++ b/tests/pass/parse/statements/block.leo @@ -1,5 +1,5 @@ function main() { - let mut x = 4u32; + let x = 4u32; { x = 5u32; diff --git a/tests/pass/parse/statements/chain.leo b/tests/pass/parse/statements/chain.leo index dbc0e1f38c..44d4e86243 100644 --- a/tests/pass/parse/statements/chain.leo +++ b/tests/pass/parse/statements/chain.leo @@ -1,5 +1,5 @@ function main(a: u32, b: u32) { - let mut c = 0u32; + let c = 0u32; if a == 1 { c = 1; diff --git a/tests/pass/parse/statements/for_loop.leo b/tests/pass/parse/statements/for_loop.leo index 2dca076858..db307f3c36 100644 --- a/tests/pass/parse/statements/for_loop.leo +++ b/tests/pass/parse/statements/for_loop.leo @@ -1,5 +1,5 @@ function main(a: bool) { - let mut b = 0u32; + let b = 0u32; if a { for i in 0..4 { @@ -7,7 +7,7 @@ function main(a: bool) { } } - let r: u32 = a ? 6 : 0; + const r: u32 = 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 index 103c9abb9e..5d74e69a1f 100644 --- a/tests/pass/parse/statements/iteration_basic.leo +++ b/tests/pass/parse/statements/iteration_basic.leo @@ -1,5 +1,5 @@ function main() { - let mut x = 4u32; + let x = 4u32; for i in 0..3 { x -= 1; } diff --git a/tests/pass/parse/statements/mutate.leo b/tests/pass/parse/statements/mutate.leo index 458d3d0d60..9bb124eefd 100644 --- a/tests/pass/parse/statements/mutate.leo +++ b/tests/pass/parse/statements/mutate.leo @@ -1,5 +1,5 @@ function main(a: u32) { - let mut b = 5u32; + let b = 5u32; if a == 1 { b = 1; diff --git a/tests/pass/parse/statements/nested.leo b/tests/pass/parse/statements/nested.leo index 3596f889d1..1849c2a339 100644 --- a/tests/pass/parse/statements/nested.leo +++ b/tests/pass/parse/statements/nested.leo @@ -1,5 +1,5 @@ function main(a: bool, b: bool, c: u32) { - let mut d = 0u32; + let d = 0u32; if a { d += 1; diff --git a/tests/pass/parse/statements/ternary_basic.leo b/tests/pass/parse/statements/ternary_basic.leo index 675b681fa9..38359004a9 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 = a ? true : false; + const c = a ? true : false; - let d = c == b; + const 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 index 8cf6327cb3..1ac81ab098 100644 --- a/tests/pass/parse/syntax/compare_mismatched_types.leo +++ b/tests/pass/parse/syntax/compare_mismatched_types.leo @@ -1,3 +1,3 @@ function main() { - let a = -5i8 > 342u32; + const a = -5i8 > 342u32; } \ No newline at end of file diff --git a/tests/pass/parse/tuples/access.leo b/tests/pass/parse/tuples/access.leo index 196e9d058c..9277f4ecc5 100644 --- a/tests/pass/parse/tuples/access.leo +++ b/tests/pass/parse/tuples/access.leo @@ -1,5 +1,5 @@ function main() { - let a = (true, false); + const a = (true, false); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/tests/pass/parse/tuples/basic.leo b/tests/pass/parse/tuples/basic.leo index 37c728611c..2e777f2797 100644 --- a/tests/pass/parse/tuples/basic.leo +++ b/tests/pass/parse/tuples/basic.leo @@ -1,3 +1,3 @@ function main() { - let a = (true, false); + const 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 index b318348813..4222b858cb 100644 --- a/tests/pass/parse/tuples/function.leo +++ b/tests/pass/parse/tuples/function.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let a = foo(); + const a = foo(); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/tests/pass/parse/tuples/function_multiple.leo b/tests/pass/parse/tuples/function_multiple.leo index 39848377c6..73fbe277ae 100644 --- a/tests/pass/parse/tuples/function_multiple.leo +++ b/tests/pass/parse/tuples/function_multiple.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let (a, b) = foo(); + const (a, b) = foo(); console.assert(a == true); console.assert(b == false); diff --git a/tests/pass/parse/tuples/function_typed.leo b/tests/pass/parse/tuples/function_typed.leo index 8af2c907ca..f89e7a3273 100644 --- a/tests/pass/parse/tuples/function_typed.leo +++ b/tests/pass/parse/tuples/function_typed.leo @@ -3,7 +3,7 @@ function foo() -> (bool, bool) { } function main() { - let a: (bool, bool) = foo(); + const a: (bool, bool) = foo(); console.assert(a.0 == true); console.assert(a.1 == false); diff --git a/tests/pass/parse/tuples/multiple.leo b/tests/pass/parse/tuples/multiple.leo index b7627dad2a..2cb003b0e1 100644 --- a/tests/pass/parse/tuples/multiple.leo +++ b/tests/pass/parse/tuples/multiple.leo @@ -1,5 +1,5 @@ function main() { - let (a, b) = (true, false); + const (a, b) = (true, false); console.assert(a == true); console.assert(b == false); diff --git a/tests/pass/parse/tuples/multiple_typed.leo b/tests/pass/parse/tuples/multiple_typed.leo index 29fc7ef877..bbe4a01858 100644 --- a/tests/pass/parse/tuples/multiple_typed.leo +++ b/tests/pass/parse/tuples/multiple_typed.leo @@ -1,5 +1,5 @@ function main() { - let (a, b): (bool, bool) = (true, false); + const (a, b): (bool, bool) = (true, false); console.assert(a == true); console.assert(b == false); diff --git a/tests/pass/parse/tuples/nested.leo b/tests/pass/parse/tuples/nested.leo index a9599b360c..bbdb2394a8 100644 --- a/tests/pass/parse/tuples/nested.leo +++ b/tests/pass/parse/tuples/nested.leo @@ -1,4 +1,4 @@ function main() { - let a = (true, false); - let b = (true, a); + const a = (true, false); + const 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 index 5edba64e24..f21fa59bba 100644 --- a/tests/pass/parse/tuples/nested_access.leo +++ b/tests/pass/parse/tuples/nested_access.leo @@ -1,6 +1,6 @@ function main() { - let a = (true, false); - let b = (true, a); + const a = (true, false); + const b = (true, a); console.assert(b.0 == true); console.assert(b.1.0 == true); diff --git a/tests/pass/parse/tuples/nested_typed.leo b/tests/pass/parse/tuples/nested_typed.leo index 2e68117a2b..44a10b2a3e 100644 --- a/tests/pass/parse/tuples/nested_typed.leo +++ b/tests/pass/parse/tuples/nested_typed.leo @@ -1,4 +1,4 @@ function main() { - let a = (true, false); - let b: (bool, (bool, bool)) = (true, a); + const a = (true, false); + const 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 index 8cd2ed79db..8f623fc148 100644 --- a/tests/pass/parse/tuples/typed.leo +++ b/tests/pass/parse/tuples/typed.leo @@ -1,3 +1,3 @@ function main() { - let a: (bool, bool) = (true, false); + const a: (bool, bool) = (true, false); } \ No newline at end of file From 1d9befc0acedc1ca5b459c807c8f855144844ac5 Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 19 Mar 2021 11:30:24 -0400 Subject: [PATCH 19/40] function input mutable by default --- asg/tests/fail/mutability/function_input.leo | 4 ++-- asg/tests/pass/function/value_unchanged.leo | 2 +- asg/tests/pass/mutability/function_input_mut.leo | 4 ++-- asg/tests/pass/mutability/swap.leo | 2 +- compiler/tests/function/value_unchanged.leo | 2 +- compiler/tests/mutability/function_input.leo | 4 ++-- compiler/tests/mutability/function_input_mut.leo | 4 ++-- compiler/tests/mutability/swap.leo | 2 +- parser/src/errors/deprecated.rs | 14 ++++++++++++-- parser/src/parser/file.rs | 9 ++++++++- parser/src/parser/statement.rs | 5 +++-- tests/pass/parse/function/value_unchanged.leo | 2 +- tests/pass/parse/mutability/function_input_mut.leo | 4 ++-- tests/pass/parse/mutability/swap.leo | 2 +- 14 files changed, 39 insertions(+), 21 deletions(-) diff --git a/asg/tests/fail/mutability/function_input.leo b/asg/tests/fail/mutability/function_input.leo index 1ef3ce1f02..18d035574b 100644 --- a/asg/tests/fail/mutability/function_input.leo +++ b/asg/tests/fail/mutability/function_input.leo @@ -1,4 +1,4 @@ -// Function input are immutable by default. -function main(a: bool) { +// Const function input are immutable. +function main(const a: bool) { a = false; } \ No newline at end of file diff --git a/asg/tests/pass/function/value_unchanged.leo b/asg/tests/pass/function/value_unchanged.leo index 936ff2ddcc..e116736316 100644 --- a/asg/tests/pass/function/value_unchanged.leo +++ b/asg/tests/pass/function/value_unchanged.leo @@ -7,7 +7,7 @@ // line 11: variable `x` is set to value `0`. // line 18: program returns the value of `a`. -function bad_mutate(mut x: u32) { +function bad_mutate(x: u32) { x = 0; // <- does not change `a` } diff --git a/asg/tests/pass/mutability/function_input_mut.leo b/asg/tests/pass/mutability/function_input_mut.leo index 2df24b227c..98739d78c7 100644 --- a/asg/tests/pass/mutability/function_input_mut.leo +++ b/asg/tests/pass/mutability/function_input_mut.leo @@ -1,5 +1,5 @@ -// Adding the `mut` keyword makes a function variable mutable. -function main(mut a: bool) { +// Function input are mutable by default. +function main(a: bool) { a = true; console.assert(a == true); diff --git a/asg/tests/pass/mutability/swap.leo b/asg/tests/pass/mutability/swap.leo index b2a795e826..2d9ddb4279 100644 --- a/asg/tests/pass/mutability/swap.leo +++ b/asg/tests/pass/mutability/swap.leo @@ -1,5 +1,5 @@ // Swap two elements of an array. -function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { +function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { const t = a[i]; a[i] = a[j]; a[j] = t; diff --git a/compiler/tests/function/value_unchanged.leo b/compiler/tests/function/value_unchanged.leo index 936ff2ddcc..e116736316 100644 --- a/compiler/tests/function/value_unchanged.leo +++ b/compiler/tests/function/value_unchanged.leo @@ -7,7 +7,7 @@ // line 11: variable `x` is set to value `0`. // line 18: program returns the value of `a`. -function bad_mutate(mut x: u32) { +function bad_mutate(x: u32) { x = 0; // <- does not change `a` } diff --git a/compiler/tests/mutability/function_input.leo b/compiler/tests/mutability/function_input.leo index 1ef3ce1f02..18d035574b 100644 --- a/compiler/tests/mutability/function_input.leo +++ b/compiler/tests/mutability/function_input.leo @@ -1,4 +1,4 @@ -// Function input are immutable by default. -function main(a: bool) { +// Const function input are immutable. +function main(const a: bool) { a = false; } \ No newline at end of file diff --git a/compiler/tests/mutability/function_input_mut.leo b/compiler/tests/mutability/function_input_mut.leo index 2df24b227c..98739d78c7 100644 --- a/compiler/tests/mutability/function_input_mut.leo +++ b/compiler/tests/mutability/function_input_mut.leo @@ -1,5 +1,5 @@ -// Adding the `mut` keyword makes a function variable mutable. -function main(mut a: bool) { +// Function input are mutable by default. +function main(a: bool) { a = true; console.assert(a == true); diff --git a/compiler/tests/mutability/swap.leo b/compiler/tests/mutability/swap.leo index b2a795e826..2d9ddb4279 100644 --- a/compiler/tests/mutability/swap.leo +++ b/compiler/tests/mutability/swap.leo @@ -1,5 +1,5 @@ // Swap two elements of an array. -function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { +function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { const t = a[i]; a[i] = a[j]; a[j] = t; diff --git a/parser/src/errors/deprecated.rs b/parser/src/errors/deprecated.rs index b16a4f5247..5a03d59d3b 100644 --- a/parser/src/errors/deprecated.rs +++ b/parser/src/errors/deprecated.rs @@ -43,9 +43,19 @@ impl LeoError for DeprecatedError { } impl DeprecatedError { - pub fn let_mut_statement(span: &Span) -> Self { + pub fn mut_function_input(mut span: Span) -> Self { + let message = + "function func(mut a: u32) { ... } is deprecated. Passed variables are mutable by default.".to_string(); + span.col_start -= 1; + span.col_stop -= 1; + Self::new_from_span(message, &span) + } + + pub fn let_mut_statement(mut span: Span) -> Self { let message = "let mut = ... is deprecated. `let` keyword implies mutabality by default.".to_string(); - Self::new_from_span(message, span) + span.col_start -= 1; + span.col_stop -= 1; + Self::new_from_span(message, &span) } pub fn test_function(span: &Span) -> Self { diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 36dca63852..5b7687ab15 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -332,11 +332,18 @@ impl ParserContext { } return Ok(FunctionInput::SelfKeyword(SelfKeyword { span: name.span })); } + + if let Some(mutable) = &mutable { + return Err(SyntaxError::DeprecatedError(DeprecatedError::mut_function_input( + &mutable.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(), + mutable: const_.is_none(), type_, span: name.span.clone(), identifier: name, diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index b57215f398..ad2c954d6f 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -287,9 +287,10 @@ impl ParserContext { /// valid keywords. /// pub fn parse_variable_name(&mut self, span: &SpannedToken) -> SyntaxResult { - if self.eat(Token::Mut).is_some() { + let mutable = self.eat(Token::Mut); + if let Some(mutable) = &mutable { return Err(SyntaxError::DeprecatedError(DeprecatedError::let_mut_statement( - &span.span, + &mutable.span + &span.span, ))); } diff --git a/tests/pass/parse/function/value_unchanged.leo b/tests/pass/parse/function/value_unchanged.leo index 936ff2ddcc..e116736316 100644 --- a/tests/pass/parse/function/value_unchanged.leo +++ b/tests/pass/parse/function/value_unchanged.leo @@ -7,7 +7,7 @@ // line 11: variable `x` is set to value `0`. // line 18: program returns the value of `a`. -function bad_mutate(mut x: u32) { +function bad_mutate(x: u32) { x = 0; // <- does not change `a` } diff --git a/tests/pass/parse/mutability/function_input_mut.leo b/tests/pass/parse/mutability/function_input_mut.leo index 2df24b227c..98739d78c7 100644 --- a/tests/pass/parse/mutability/function_input_mut.leo +++ b/tests/pass/parse/mutability/function_input_mut.leo @@ -1,5 +1,5 @@ -// Adding the `mut` keyword makes a function variable mutable. -function main(mut a: bool) { +// Function input are mutable by default. +function main(a: bool) { a = true; console.assert(a == true); diff --git a/tests/pass/parse/mutability/swap.leo b/tests/pass/parse/mutability/swap.leo index b2a795e826..2d9ddb4279 100644 --- a/tests/pass/parse/mutability/swap.leo +++ b/tests/pass/parse/mutability/swap.leo @@ -1,5 +1,5 @@ // Swap two elements of an array. -function swap(mut a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { +function swap(a: [u32; 2], const i: u32, const j: u32) -> [u32; 2] { const t = a[i]; a[i] = a[j]; a[j] = t; From 2c6a34fea7270592b26205fd185882cea5787743 Mon Sep 17 00:00:00 2001 From: gluax Date: Mon, 22 Mar 2021 11:47:34 -0400 Subject: [PATCH 20/40] test that was failing coverage only existed on master --- compiler/tests/statements/iteration_variable.leo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tests/statements/iteration_variable.leo b/compiler/tests/statements/iteration_variable.leo index d3d82b2664..67bb166236 100644 --- a/compiler/tests/statements/iteration_variable.leo +++ b/compiler/tests/statements/iteration_variable.leo @@ -1,5 +1,5 @@ function main() { - let x: u32 = 5; + const x: u32 = 5; for i in 0..x { console.log("{}", i); From fe8eae981d5854cf618dbbb29d07aa637f6e25d8 Mon Sep 17 00:00:00 2001 From: gluax Date: Tue, 23 Mar 2021 11:32:36 -0400 Subject: [PATCH 21/40] const_ self as function input --- parser/src/parser/file.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index b590c35f3e..a298095a26 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -327,13 +327,13 @@ impl ParserContext { self.expect_ident()? }; if name.name == "self" { - if const_.is_some() { - //error - } if let Some(mutable) = &mutable { name.span = &mutable.span + &name.span; name.name = "mut self".to_string(); return Ok(FunctionInput::MutSelfKeyword(MutSelfKeyword { identifier: name })); + } else if let Some(const_) = &const_ { + name.span = &const_.span + &name.span; + name.name = "const self".to_string(); } return Ok(FunctionInput::SelfKeyword(SelfKeyword { identifier: name })); } @@ -347,8 +347,8 @@ impl ParserContext { self.expect(Token::Colon)?; let type_ = self.parse_type()?.0; Ok(FunctionInput::Variable(FunctionInputVariable { - const_: const_.is_some(), - mutable: const_.is_none(), + const_: const_.is_some() || (const_.is_none() && mutable.is_none()), + mutable: mutable.is_some(), type_, span: name.span.clone(), identifier: name, From 0ea4f1e0e35c0eaa06bd4382cbe3869b95801264 Mon Sep 17 00:00:00 2001 From: gluax Date: Tue, 23 Mar 2021 11:49:27 -0400 Subject: [PATCH 22/40] const_ self as function input properly --- asg/src/program/function.rs | 4 +++ ast/src/common/const_self_keyword.rs | 44 +++++++++++++++++++++++ ast/src/common/mod.rs | 3 ++ ast/src/functions/input/input_variable.rs | 23 +++++++++++- compiler/src/function/main_function.rs | 2 +- parser/src/parser/file.rs | 5 +-- 6 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 ast/src/common/const_self_keyword.rs diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index c74e15f850..76181db69d 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -37,6 +37,7 @@ use std::cell::{Cell, RefCell}; #[derive(Clone, Copy, PartialEq)] pub enum FunctionQualifier { SelfRef, + ConstSelfRef, MutSelfRef, Static, } @@ -89,6 +90,9 @@ impl<'a> Function<'a> { FunctionInput::SelfKeyword(_) => { qualifier = FunctionQualifier::SelfRef; } + FunctionInput::ConstSelfKeyword(_) => { + qualifier = FunctionQualifier::ConstSelfRef; + } FunctionInput::MutSelfKeyword(_) => { qualifier = FunctionQualifier::MutSelfRef; } diff --git a/ast/src/common/const_self_keyword.rs b/ast/src/common/const_self_keyword.rs new file mode 100644 index 0000000000..52d361ae16 --- /dev/null +++ b/ast/src/common/const_self_keyword.rs @@ -0,0 +1,44 @@ +// 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::{Identifier, Node, Span}; + +use serde::{Deserialize, Serialize}; +use std::fmt; + +/// The `self` keyword can view circuit values inside of a circuit function. +/// Circuit values cannot be modified. To modify values use the `mut self` [MutSelfKeyword]. +#[derive(Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] +#[serde(transparent)] +pub struct ConstSelfKeyword { + pub identifier: Identifier, +} + +impl fmt::Display for ConstSelfKeyword { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "const self") + } +} + +impl Node for ConstSelfKeyword { + fn span(&self) -> &Span { + &self.identifier.span + } + + fn set_span(&mut self, span: Span) { + self.identifier.span = span; + } +} diff --git a/ast/src/common/mod.rs b/ast/src/common/mod.rs index ad86f6ee2b..a5f8c8f9c4 100644 --- a/ast/src/common/mod.rs +++ b/ast/src/common/mod.rs @@ -17,6 +17,9 @@ pub mod array_dimensions; pub use array_dimensions::*; +pub mod const_self_keyword; +pub use const_self_keyword::*; + pub mod identifier; pub use identifier::*; diff --git a/ast/src/functions/input/input_variable.rs b/ast/src/functions/input/input_variable.rs index 5ec9306aeb..fda2c11ab8 100644 --- a/ast/src/functions/input/input_variable.rs +++ b/ast/src/functions/input/input_variable.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use crate::{FunctionInputVariable, InputKeyword, MutSelfKeyword, Node, SelfKeyword, Span}; +use crate::{ConstSelfKeyword, FunctionInputVariable, InputKeyword, MutSelfKeyword, Node, SelfKeyword, Span}; use serde::{Deserialize, Serialize}; use std::fmt; @@ -24,6 +24,7 @@ use std::fmt; pub enum FunctionInput { InputKeyword(InputKeyword), SelfKeyword(SelfKeyword), + ConstSelfKeyword(ConstSelfKeyword), MutSelfKeyword(MutSelfKeyword), Variable(FunctionInputVariable), } @@ -37,11 +38,26 @@ impl FunctionInput { match self { FunctionInput::InputKeyword(_) => false, FunctionInput::SelfKeyword(_) => true, + FunctionInput::ConstSelfKeyword(_) => true, FunctionInput::MutSelfKeyword(_) => true, FunctionInput::Variable(_) => false, } } + /// + /// Returns `true` if the function input is the `const self` keyword. + /// Returns `false` otherwise. + /// + pub fn is_const_self(&self) -> bool { + match self { + FunctionInput::InputKeyword(_) => false, + FunctionInput::SelfKeyword(_) => false, + FunctionInput::ConstSelfKeyword(_) => true, + FunctionInput::MutSelfKeyword(_) => false, + FunctionInput::Variable(_) => false, + } + } + /// /// Returns `true` if the function input is the `mut self` keyword. /// Returns `false` otherwise. @@ -50,6 +66,7 @@ impl FunctionInput { match self { FunctionInput::InputKeyword(_) => false, FunctionInput::SelfKeyword(_) => false, + FunctionInput::ConstSelfKeyword(_) => false, FunctionInput::MutSelfKeyword(_) => true, FunctionInput::Variable(_) => false, } @@ -59,6 +76,7 @@ impl FunctionInput { match self { FunctionInput::InputKeyword(keyword) => write!(f, "{}", keyword), FunctionInput::SelfKeyword(keyword) => write!(f, "{}", keyword), + FunctionInput::ConstSelfKeyword(keyword) => write!(f, "{}", keyword), FunctionInput::MutSelfKeyword(keyword) => write!(f, "{}", keyword), FunctionInput::Variable(function_input) => write!(f, "{}", function_input), } @@ -83,6 +101,7 @@ impl PartialEq for FunctionInput { match (self, other) { (FunctionInput::InputKeyword(_), FunctionInput::InputKeyword(_)) => true, (FunctionInput::SelfKeyword(_), FunctionInput::SelfKeyword(_)) => true, + (FunctionInput::ConstSelfKeyword(_), FunctionInput::ConstSelfKeyword(_)) => true, (FunctionInput::MutSelfKeyword(_), FunctionInput::MutSelfKeyword(_)) => true, (FunctionInput::Variable(left), FunctionInput::Variable(right)) => left.eq(right), _ => false, @@ -98,6 +117,7 @@ impl Node for FunctionInput { match self { InputKeyword(keyword) => &keyword.identifier.span, SelfKeyword(keyword) => &keyword.identifier.span, + ConstSelfKeyword(keyword) => &keyword.identifier.span, MutSelfKeyword(keyword) => &keyword.identifier.span, Variable(variable) => &variable.span, } @@ -108,6 +128,7 @@ impl Node for FunctionInput { match self { InputKeyword(keyword) => keyword.identifier.span = span, SelfKeyword(keyword) => keyword.identifier.span = span, + ConstSelfKeyword(keyword) => keyword.identifier.span = span, MutSelfKeyword(keyword) => keyword.identifier.span = span, Variable(variable) => variable.span = span, } diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 8a77d3fd21..865f7a9fba 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -49,7 +49,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { } match function.qualifier { - FunctionQualifier::SelfRef | FunctionQualifier::MutSelfRef => { + FunctionQualifier::SelfRef | FunctionQualifier::ConstSelfRef | FunctionQualifier::MutSelfRef => { unimplemented!("cannot access self variable in main function") } FunctionQualifier::Static => (), diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index a298095a26..acd48729f9 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -334,6 +334,7 @@ impl ParserContext { } else if let Some(const_) = &const_ { name.span = &const_.span + &name.span; name.name = "const self".to_string(); + return Ok(FunctionInput::ConstSelfKeyword(ConstSelfKeyword { identifier: name })); } return Ok(FunctionInput::SelfKeyword(SelfKeyword { identifier: name })); } @@ -347,8 +348,8 @@ impl ParserContext { self.expect(Token::Colon)?; let type_ = self.parse_type()?.0; Ok(FunctionInput::Variable(FunctionInputVariable { - const_: const_.is_some() || (const_.is_none() && mutable.is_none()), - mutable: mutable.is_some(), + const_: const_.is_some(), + mutable: const_.is_none(), type_, span: name.span.clone(), identifier: name, From 341a5290e3c6e87d650bd4dde99301e2bf16a276 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Wed, 24 Mar 2021 20:36:22 -0400 Subject: [PATCH 23/40] Delete HEAD --- HEAD | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 HEAD diff --git a/HEAD b/HEAD deleted file mode 100644 index e69de29bb2..0000000000 From afc42bcecdcb1449bed4f3c0911e2188b96dcebd Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Thu, 25 Mar 2021 11:31:08 -0400 Subject: [PATCH 24/40] perdeshen-hash Forgot to save after resolving merge conflict. --- examples/pedersen-hash/src/main.leo | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/pedersen-hash/src/main.leo b/examples/pedersen-hash/src/main.leo index 5f5a650006..84670cd6c2 100644 --- a/examples/pedersen-hash/src/main.leo +++ b/examples/pedersen-hash/src/main.leo @@ -19,11 +19,7 @@ circuit PedersenHash { // The 'pedersen-hash' main function. function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group { -<<<<<<< HEAD const pedersen = PedersenHash::new(parameters); -======= - let pedersen = PedersenHash::new(parameters); ->>>>>>> 9b61d0fa152f435e3e165090455c85eedeb9b770 return pedersen.hash(hash_input) } From 696825eb6a7e777d2fbfac0a829570148407fd86 Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 25 Mar 2021 13:48:47 -0400 Subject: [PATCH 25/40] asked for refactors started, this will fail tests --- asg/src/expression/array_access.rs | 3 - asg/src/expression/array_init.rs | 8 +- asg/src/expression/array_inline.rs | 6 +- asg/src/expression/array_range_access.rs | 17 +- asg/src/expression/binary.rs | 15 +- asg/src/expression/call.rs | 6 +- asg/src/expression/cast.rs | 5 +- asg/src/expression/circuit_access.rs | 4 +- asg/src/expression/circuit_init.rs | 4 +- asg/src/expression/constant.rs | 1 - asg/src/expression/mod.rs | 60 ++- asg/src/expression/ternary.rs | 10 +- asg/src/expression/tuple_access.rs | 8 +- asg/src/expression/tuple_init.rs | 2 - asg/src/expression/unary.rs | 3 +- asg/src/expression/variable_ref.rs | 1 - asg/src/node.rs | 1 - asg/src/program/circuit.rs | 6 +- asg/src/program/function.rs | 18 +- asg/src/program/mod.rs | 4 +- asg/src/scope.rs | 28 +- asg/src/statement/assign.rs | 8 +- asg/src/statement/block.rs | 8 +- asg/src/statement/conditional.rs | 7 +- asg/src/statement/console.rs | 17 +- asg/src/statement/definition.rs | 5 +- asg/src/statement/expression.rs | 3 +- asg/src/statement/iteration.rs | 6 +- asg/src/statement/mod.rs | 40 +- asg/src/statement/return_.rs | 2 - ast/src/lib.rs | 3 +- ast/src/reducer/canonicalization.rs | 146 ++++--- ast/src/reducer/reconstructing_director.rs | 407 ++++++++----------- ast/src/reducer/reconstructing_reducer.rs | 94 +++-- compiler/src/compiler.rs | 5 +- compiler/src/function/input/input_keyword.rs | 2 +- compiler/src/function/input/input_section.rs | 3 +- compiler/src/function/main_function.rs | 2 +- compiler/src/option.rs | 2 + compiler/src/output/output_bytes.rs | 4 +- 40 files changed, 418 insertions(+), 556 deletions(-) diff --git a/asg/src/expression/array_access.rs b/asg/src/expression/array_access.rs index 34dccbe70e..3bbbd7909d 100644 --- a/asg/src/expression/array_access.rs +++ b/asg/src/expression/array_access.rs @@ -83,13 +83,11 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<' scope: &'a Scope<'a>, value: &leo_ast::ArrayAccessExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let array = <&Expression<'a>>::from_ast( scope, &*value.array, Some(PartialType::Array(expected_type.map(Box::new), None)), - circuit_name, )?; match array.get_type() { Some(Type::Array(..)) => (), @@ -106,7 +104,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayAccessExpression> for ArrayAccessExpression<' scope, &*value.index, Some(PartialType::Integer(None, Some(IntegerType::U32))), - circuit_name, )?; if !index.is_consty() { diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index 68fe927c5a..0444e23be1 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -68,7 +68,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::ArrayInitExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let (mut expected_item, expected_len) = match expected_type { Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims), @@ -128,12 +127,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInitExpression> for ArrayInitExpression<'a> { } } } - let mut element = Some(<&'a Expression<'a>>::from_ast( - scope, - &*value.element, - expected_item, - circuit_name, - )?); + let mut element = Some(<&'a Expression<'a>>::from_ast(scope, &*value.element, expected_item)?); let mut output = None; for dimension in dimensions.iter().rev().copied() { diff --git a/asg/src/expression/array_inline.rs b/asg/src/expression/array_inline.rs index cb9805887c..79f78386fa 100644 --- a/asg/src/expression/array_inline.rs +++ b/asg/src/expression/array_inline.rs @@ -101,7 +101,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' scope: &'a Scope<'a>, value: &leo_ast::ArrayInlineExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let (mut expected_item, expected_len) = match expected_type { Some(PartialType::Array(item, dims)) => (item.map(|x| *x), dims), @@ -121,7 +120,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' for expr in value.elements.iter() { expected_item = match expr { SpreadOrExpression::Expression(e) => { - match <&Expression<'a>>::from_ast(scope, e, expected_item.clone(), circuit_name) { + match <&Expression<'a>>::from_ast(scope, e, expected_item.clone()) { Ok(expr) => expr.get_type().map(Type::partial), Err(_) => continue, } @@ -145,7 +144,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' .iter() .map(|e| match e { SpreadOrExpression::Expression(e) => { - let expr = <&Expression<'a>>::from_ast(scope, e, expected_item.clone(), circuit_name)?; + let expr = <&Expression<'a>>::from_ast(scope, e, expected_item.clone())?; if expected_item.is_none() { expected_item = expr.get_type().map(Type::partial); } @@ -157,7 +156,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayInlineExpression> for ArrayInlineExpression<' scope, e, Some(PartialType::Array(expected_item.clone().map(Box::new), None)), - circuit_name, )?; match expr.get_type() { diff --git a/asg/src/expression/array_range_access.rs b/asg/src/expression/array_range_access.rs index 97b7965efe..f070116aa0 100644 --- a/asg/src/expression/array_range_access.rs +++ b/asg/src/expression/array_range_access.rs @@ -112,7 +112,6 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx scope: &'a Scope<'a>, value: &leo_ast::ArrayRangeAccessExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let expected_array = match expected_type { Some(PartialType::Array(element, _len)) => Some(PartialType::Array(element, None)), @@ -125,7 +124,7 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx )); } }; - let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array, circuit_name)?; + let array = <&Expression<'a>>::from_ast(scope, &*value.array, expected_array)?; let array_type = array.get_type(); match array_type { Some(Type::Array(_, _)) => (), @@ -141,24 +140,14 @@ impl<'a> FromAst<'a, leo_ast::ArrayRangeAccessExpression> for ArrayRangeAccessEx .left .as_deref() .map(|left| { - <&Expression<'a>>::from_ast( - scope, - left, - Some(PartialType::Integer(None, Some(IntegerType::U32))), - circuit_name, - ) + <&Expression<'a>>::from_ast(scope, left, Some(PartialType::Integer(None, Some(IntegerType::U32)))) }) .transpose()?; let right = value .right .as_deref() .map(|right| { - <&Expression<'a>>::from_ast( - scope, - right, - Some(PartialType::Integer(None, Some(IntegerType::U32))), - circuit_name, - ) + <&Expression<'a>>::from_ast(scope, right, Some(PartialType::Integer(None, Some(IntegerType::U32)))) }) .transpose()?; diff --git a/asg/src/expression/binary.rs b/asg/src/expression/binary.rs index 532a2e8f4b..9322b1d587 100644 --- a/asg/src/expression/binary.rs +++ b/asg/src/expression/binary.rs @@ -116,7 +116,6 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::BinaryExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let class = value.op.class(); let expected_type = match class { @@ -146,18 +145,16 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { }; // left - let (left, right) = match <&Expression<'a>>::from_ast(scope, &*value.left, expected_type.clone(), circuit_name) - { + let (left, right) = match <&Expression<'a>>::from_ast(scope, &*value.left, expected_type.clone()) { Ok(left) => { if let Some(left_type) = left.get_type() { - let right = - <&Expression<'a>>::from_ast(scope, &*value.right, Some(left_type.partial()), circuit_name)?; + let right = <&Expression<'a>>::from_ast(scope, &*value.right, Some(left_type.partial()))?; (left, right) } else { - let right = <&Expression<'a>>::from_ast(scope, &*value.right, expected_type, circuit_name)?; + let right = <&Expression<'a>>::from_ast(scope, &*value.right, expected_type)?; if let Some(right_type) = right.get_type() { ( - <&Expression<'a>>::from_ast(scope, &*value.left, Some(right_type.partial()), circuit_name)?, + <&Expression<'a>>::from_ast(scope, &*value.left, Some(right_type.partial()))?, right, ) } else { @@ -166,10 +163,10 @@ impl<'a> FromAst<'a, leo_ast::BinaryExpression> for BinaryExpression<'a> { } } Err(e) => { - let right = <&Expression<'a>>::from_ast(scope, &*value.right, expected_type, circuit_name)?; + let right = <&Expression<'a>>::from_ast(scope, &*value.right, expected_type)?; if let Some(right_type) = right.get_type() { ( - <&Expression<'a>>::from_ast(scope, &*value.left, Some(right_type.partial()), circuit_name)?, + <&Expression<'a>>::from_ast(scope, &*value.left, Some(right_type.partial()))?, right, ) } else { diff --git a/asg/src/expression/call.rs b/asg/src/expression/call.rs index 7cc7e26068..8c91f86da5 100644 --- a/asg/src/expression/call.rs +++ b/asg/src/expression/call.rs @@ -89,7 +89,6 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::CallExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let (target, function) = match &*value.function { leo_ast::Expression::Identifier(name) => ( @@ -103,7 +102,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { name, span, }) => { - let target = <&Expression<'a>>::from_ast(scope, &**ast_circuit, None, circuit_name)?; + let target = <&Expression<'a>>::from_ast(scope, &**ast_circuit, None)?; let circuit = match target.get_type() { Some(Type::Circuit(circuit)) => circuit, type_ => { @@ -205,8 +204,7 @@ impl<'a> FromAst<'a, leo_ast::CallExpression> for CallExpression<'a> { .zip(function.arguments.iter()) .map(|(expr, (_, argument))| { let argument = argument.get().borrow(); - let converted = - <&Expression<'a>>::from_ast(scope, expr, Some(argument.type_.clone().partial()), circuit_name)?; + 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())); } diff --git a/asg/src/expression/cast.rs b/asg/src/expression/cast.rs index 1aca152460..e7060492d4 100644 --- a/asg/src/expression/cast.rs +++ b/asg/src/expression/cast.rs @@ -75,9 +75,8 @@ impl<'a> FromAst<'a, leo_ast::CastExpression> for CastExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::CastExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { - let target_type = scope.resolve_ast_type(&value.target_type, circuit_name)?; + 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( @@ -88,7 +87,7 @@ impl<'a> FromAst<'a, leo_ast::CastExpression> for CastExpression<'a> { } } - let inner = <&Expression<'a>>::from_ast(scope, &*value.inner, None, circuit_name)?; + let inner = <&Expression<'a>>::from_ast(scope, &*value.inner, None)?; Ok(CastExpression { parent: Cell::new(None), diff --git a/asg/src/expression/circuit_access.rs b/asg/src/expression/circuit_access.rs index b44145f085..739579cabd 100644 --- a/asg/src/expression/circuit_access.rs +++ b/asg/src/expression/circuit_access.rs @@ -97,9 +97,8 @@ impl<'a> FromAst<'a, leo_ast::CircuitMemberAccessExpression> for CircuitAccessEx scope: &'a Scope<'a>, value: &leo_ast::CircuitMemberAccessExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { - let target = <&'a Expression<'a>>::from_ast(scope, &*value.circuit, None, circuit_name)?; + let target = <&'a Expression<'a>>::from_ast(scope, &*value.circuit, None)?; let circuit = match target.get_type() { Some(Type::Circuit(circuit)) => circuit, x => { @@ -171,7 +170,6 @@ impl<'a> FromAst<'a, leo_ast::CircuitStaticFunctionAccessExpression> for Circuit scope: &Scope<'a>, value: &leo_ast::CircuitStaticFunctionAccessExpression, expected_type: Option, - _circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let circuit = match &*value.circuit { leo_ast::Expression::Identifier(name) => scope diff --git a/asg/src/expression/circuit_init.rs b/asg/src/expression/circuit_init.rs index 4318fb3349..8c26379072 100644 --- a/asg/src/expression/circuit_init.rs +++ b/asg/src/expression/circuit_init.rs @@ -84,7 +84,6 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' scope: &'a Scope<'a>, value: &leo_ast::CircuitInitExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let circuit = scope .resolve_circuit(&value.name.name) @@ -127,13 +126,12 @@ impl<'a> FromAst<'a, leo_ast::CircuitInitExpression> for CircuitInitExpression<' }; if let Some((identifier, receiver)) = members.get(&name) { let received = if let Some(receiver) = *receiver { - <&Expression<'a>>::from_ast(scope, receiver, Some(type_.partial()), circuit_name)? + <&Expression<'a>>::from_ast(scope, receiver, Some(type_.partial()))? } else { <&Expression<'a>>::from_ast( scope, &leo_ast::Expression::Identifier((*identifier).clone()), Some(type_.partial()), - circuit_name, )? }; values.push(((*identifier).clone(), Cell::new(received))); diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index 148ea09af2..ae2a1fdd13 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -77,7 +77,6 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { _scope: &'a Scope<'a>, value: &leo_ast::ValueExpression, expected_type: Option>, - _circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { use leo_ast::ValueExpression::*; Ok(match value { diff --git a/asg/src/expression/mod.rs b/asg/src/expression/mod.rs index 752eb2b610..bbd40e8298 100644 --- a/asg/src/expression/mod.rs +++ b/asg/src/expression/mod.rs @@ -284,70 +284,62 @@ impl<'a> FromAst<'a, leo_ast::Expression> for &'a Expression<'a> { scope: &'a Scope<'a>, value: &leo_ast::Expression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { use leo_ast::Expression::*; let expression = match value { - Identifier(identifier) => Self::from_ast(scope, identifier, expected_type, circuit_name)?, - Value(value) => scope.context.alloc_expression( - Constant::from_ast(scope, value, expected_type, circuit_name).map(Expression::Constant)?, - ), - Binary(binary) => scope.context.alloc_expression( - BinaryExpression::from_ast(scope, binary, expected_type, circuit_name).map(Expression::Binary)?, - ), - Unary(unary) => scope.context.alloc_expression( - UnaryExpression::from_ast(scope, unary, expected_type, circuit_name).map(Expression::Unary)?, - ), + Identifier(identifier) => Self::from_ast(scope, identifier, expected_type)?, + Value(value) => scope + .context + .alloc_expression(Constant::from_ast(scope, value, expected_type).map(Expression::Constant)?), + Binary(binary) => scope + .context + .alloc_expression(BinaryExpression::from_ast(scope, binary, expected_type).map(Expression::Binary)?), + Unary(unary) => scope + .context + .alloc_expression(UnaryExpression::from_ast(scope, unary, expected_type).map(Expression::Unary)?), Ternary(conditional) => scope.context.alloc_expression( - TernaryExpression::from_ast(scope, conditional, expected_type, circuit_name) - .map(Expression::Ternary)?, - ), - Cast(cast) => scope.context.alloc_expression( - CastExpression::from_ast(scope, cast, expected_type, circuit_name).map(Expression::Cast)?, + TernaryExpression::from_ast(scope, conditional, expected_type).map(Expression::Ternary)?, ), + Cast(cast) => scope + .context + .alloc_expression(CastExpression::from_ast(scope, cast, expected_type).map(Expression::Cast)?), ArrayInline(array_inline) => scope.context.alloc_expression( - ArrayInlineExpression::from_ast(scope, array_inline, expected_type, circuit_name) - .map(Expression::ArrayInline)?, + ArrayInlineExpression::from_ast(scope, array_inline, expected_type).map(Expression::ArrayInline)?, ), ArrayInit(array_init) => scope.context.alloc_expression( - ArrayInitExpression::from_ast(scope, array_init, expected_type, circuit_name) - .map(Expression::ArrayInit)?, + ArrayInitExpression::from_ast(scope, array_init, expected_type).map(Expression::ArrayInit)?, ), ArrayAccess(array_access) => scope.context.alloc_expression( - ArrayAccessExpression::from_ast(scope, array_access, expected_type, circuit_name) - .map(Expression::ArrayAccess)?, + ArrayAccessExpression::from_ast(scope, array_access, expected_type).map(Expression::ArrayAccess)?, ), ArrayRangeAccess(array_range_access) => scope.context.alloc_expression( - ArrayRangeAccessExpression::from_ast(scope, array_range_access, expected_type, circuit_name) + ArrayRangeAccessExpression::from_ast(scope, array_range_access, expected_type) .map(Expression::ArrayRangeAccess)?, ), TupleInit(tuple_init) => scope.context.alloc_expression( - TupleInitExpression::from_ast(scope, tuple_init, expected_type, circuit_name) - .map(Expression::TupleInit)?, + TupleInitExpression::from_ast(scope, tuple_init, expected_type).map(Expression::TupleInit)?, ), TupleAccess(tuple_access) => scope.context.alloc_expression( - TupleAccessExpression::from_ast(scope, tuple_access, expected_type, circuit_name) - .map(Expression::TupleAccess)?, + TupleAccessExpression::from_ast(scope, tuple_access, expected_type).map(Expression::TupleAccess)?, ), CircuitInit(circuit_init) => scope.context.alloc_expression( - CircuitInitExpression::from_ast(scope, circuit_init, expected_type, circuit_name) - .map(Expression::CircuitInit)?, + CircuitInitExpression::from_ast(scope, circuit_init, expected_type).map(Expression::CircuitInit)?, ), CircuitMemberAccess(circuit_member) => scope.context.alloc_expression( - CircuitAccessExpression::from_ast(scope, circuit_member, expected_type, circuit_name) + CircuitAccessExpression::from_ast(scope, circuit_member, expected_type) .map(Expression::CircuitAccess)?, ), CircuitStaticFunctionAccess(circuit_member) => scope.context.alloc_expression( - CircuitAccessExpression::from_ast(scope, circuit_member, expected_type, circuit_name) + CircuitAccessExpression::from_ast(scope, circuit_member, expected_type) .map(Expression::CircuitAccess)?, ), - Call(call) => scope.context.alloc_expression( - CallExpression::from_ast(scope, call, expected_type, circuit_name).map(Expression::Call)?, - ), + Call(call) => scope + .context + .alloc_expression(CallExpression::from_ast(scope, call, expected_type).map(Expression::Call)?), }; expression.enforce_parents(&expression); Ok(expression) diff --git a/asg/src/expression/ternary.rs b/asg/src/expression/ternary.rs index c05ee8c845..93d1a7df0f 100644 --- a/asg/src/expression/ternary.rs +++ b/asg/src/expression/ternary.rs @@ -78,7 +78,6 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::TernaryExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { Ok(TernaryExpression { parent: Cell::new(None), @@ -87,20 +86,13 @@ impl<'a> FromAst<'a, leo_ast::TernaryExpression> for TernaryExpression<'a> { scope, &*value.condition, Some(Type::Boolean.partial()), - circuit_name, )?), if_true: Cell::new(<&Expression<'a>>::from_ast( scope, &*value.if_true, expected_type.clone(), - circuit_name, - )?), - if_false: Cell::new(<&Expression<'a>>::from_ast( - scope, - &*value.if_false, - expected_type, - circuit_name, )?), + if_false: Cell::new(<&Expression<'a>>::from_ast(scope, &*value.if_false, expected_type)?), }) } } diff --git a/asg/src/expression/tuple_access.rs b/asg/src/expression/tuple_access.rs index 84839534ee..4886ff4aa6 100644 --- a/asg/src/expression/tuple_access.rs +++ b/asg/src/expression/tuple_access.rs @@ -74,7 +74,6 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<' scope: &'a Scope<'a>, value: &leo_ast::TupleAccessExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let index = value .index @@ -85,12 +84,7 @@ impl<'a> FromAst<'a, leo_ast::TupleAccessExpression> for TupleAccessExpression<' let mut expected_tuple = vec![None; index + 1]; expected_tuple[index] = expected_type; - let tuple = <&Expression<'a>>::from_ast( - scope, - &*value.tuple, - Some(PartialType::Tuple(expected_tuple)), - circuit_name, - )?; + let tuple = <&Expression<'a>>::from_ast(scope, &*value.tuple, Some(PartialType::Tuple(expected_tuple)))?; let tuple_type = tuple.get_type(); if let Some(Type::Tuple(_items)) = tuple_type { } else { diff --git a/asg/src/expression/tuple_init.rs b/asg/src/expression/tuple_init.rs index 493b4073a1..195b4fe4af 100644 --- a/asg/src/expression/tuple_init.rs +++ b/asg/src/expression/tuple_init.rs @@ -80,7 +80,6 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::TupleInitExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let tuple_types = match expected_type { Some(PartialType::Tuple(sub_types)) => Some(sub_types), @@ -113,7 +112,6 @@ impl<'a> FromAst<'a, leo_ast::TupleInitExpression> for TupleInitExpression<'a> { scope, e, tuple_types.as_ref().map(|x| x.get(i)).flatten().cloned().flatten(), - circuit_name, ) .map(Cell::new) }) diff --git a/asg/src/expression/unary.rs b/asg/src/expression/unary.rs index 9ff6c0ebad..4ccc7662a6 100644 --- a/asg/src/expression/unary.rs +++ b/asg/src/expression/unary.rs @@ -89,7 +89,6 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { scope: &'a Scope<'a>, value: &leo_ast::UnaryExpression, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, AsgConvertError> { let expected_type = match value.op { UnaryOperation::Not => match expected_type.map(|x| x.full()).flatten() { @@ -127,7 +126,7 @@ impl<'a> FromAst<'a, leo_ast::UnaryExpression> for UnaryExpression<'a> { } }, }; - let expr = <&Expression<'a>>::from_ast(scope, &*value.inner, expected_type.map(Into::into), circuit_name)?; + 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 diff --git a/asg/src/expression/variable_ref.rs b/asg/src/expression/variable_ref.rs index 8d489332a9..6a5476b40a 100644 --- a/asg/src/expression/variable_ref.rs +++ b/asg/src/expression/variable_ref.rs @@ -135,7 +135,6 @@ impl<'a> FromAst<'a, leo_ast::Identifier> for &'a Expression<'a> { scope: &'a Scope<'a>, value: &leo_ast::Identifier, expected_type: Option>, - _circuit_name: Option<&leo_ast::Identifier>, ) -> Result<&'a Expression<'a>, AsgConvertError> { let variable = if value.name == "input" { if let Some(function) = scope.resolve_current_function() { diff --git a/asg/src/node.rs b/asg/src/node.rs index c3d3d33025..58b4b7709e 100644 --- a/asg/src/node.rs +++ b/asg/src/node.rs @@ -39,7 +39,6 @@ pub(super) trait FromAst<'a, T: leo_ast::Node + 'static>: Sized { scope: &'a Scope<'a>, value: &T, expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result; } diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index abead4b2c6..deb4821e3e 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -79,7 +79,7 @@ impl<'a> Circuit<'a> { } members.insert( name.name.clone(), - CircuitMember::Variable(new_scope.resolve_ast_type(type_, Some(&value.circuit_name))?), + CircuitMember::Variable(new_scope.resolve_ast_type(type_)?), ); } leo_ast::CircuitMember::CircuitFunction(function) => { @@ -90,7 +90,7 @@ impl<'a> Circuit<'a> { &function.identifier.span, )); } - let asg_function = Function::init(new_scope, function, Some(&value.circuit_name))?; + 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)); @@ -117,7 +117,7 @@ impl<'a> Circuit<'a> { CircuitMember::Function(f) => f, _ => unimplemented!(), }; - Function::fill_from_ast(asg_function, function, Some(&value.circuit_name))?; + Function::fill_from_ast(asg_function, function)?; } } } diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index 008b391829..942337e5f9 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -68,15 +68,11 @@ impl<'a> PartialEq for Function<'a> { impl<'a> Eq for Function<'a> {} impl<'a> Function<'a> { - pub(crate) fn init( - scope: &'a Scope<'a>, - value: &leo_ast::Function, - circuit_name: Option<&leo_ast::Identifier>, - ) -> Result<&'a Function<'a>, AsgConvertError> { + pub(crate) fn init(scope: &'a Scope<'a>, value: &leo_ast::Function) -> Result<&'a Function<'a>, AsgConvertError> { let output: Type<'a> = value .output .as_ref() - .map(|t| scope.resolve_ast_type(t, circuit_name)) + .map(|t| scope.resolve_ast_type(t)) .transpose()? .unwrap_or_else(|| Type::Tuple(vec![])); let mut qualifier = FunctionQualifier::Static; @@ -106,7 +102,7 @@ impl<'a> Function<'a> { let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable { id: scope.context.get_id(), name: identifier.clone(), - type_: scope.resolve_ast_type(&type_, circuit_name)?, + type_: scope.resolve_ast_type(&type_)?, mutable: *mutable, const_: *const_, declaration: crate::VariableDeclaration::Parameter, @@ -139,11 +135,7 @@ impl<'a> Function<'a> { Ok(function) } - pub(super) fn fill_from_ast( - self: &'a Function<'a>, - value: &leo_ast::Function, - circuit_name: Option<&leo_ast::Identifier>, - ) -> Result<(), AsgConvertError> { + pub(super) fn fill_from_ast(self: &'a Function<'a>, value: &leo_ast::Function) -> Result<(), AsgConvertError> { if self.qualifier != FunctionQualifier::Static { let circuit = self.circuit.get(); let self_variable = self.scope.context.alloc_variable(RefCell::new(crate::InnerVariable { @@ -165,7 +157,7 @@ impl<'a> Function<'a> { self.scope.variables.borrow_mut().insert(name.clone(), argument.get()); } - let main_block = BlockStatement::from_ast(self.scope, &value.block, None, circuit_name)?; + let main_block = BlockStatement::from_ast(self.scope, &value.block, None)?; let mut director = MonoidalDirector::new(ReturnPathReducer::new()); if !director.reduce_block(&main_block).0 && !self.output.is_unit() { return Err(AsgConvertError::function_missing_return( diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 4dacd266b6..71d83cb1a5 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -245,7 +245,7 @@ impl<'a> Program<'a> { for (name, function) in program.functions.iter() { assert_eq!(name.name, function.identifier.name); - let function = Function::init(scope, function, None)?; + let function = Function::init(scope, function)?; scope.functions.borrow_mut().insert(name.name.clone(), function); } @@ -256,7 +256,7 @@ impl<'a> Program<'a> { assert_eq!(name.name, function.identifier.name); let asg_function = *scope.functions.borrow().get(&name.name).unwrap(); - asg_function.fill_from_ast(function, None)?; + asg_function.fill_from_ast(function)?; functions.insert(name.name.clone(), asg_function); } diff --git a/asg/src/scope.rs b/asg/src/scope.rs index f085cff4b4..3471ae6094 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -169,11 +169,7 @@ impl<'a> Scope<'a> { /// /// Returns the type returned by the current scope. /// - pub fn resolve_ast_type( - &self, - type_: &leo_ast::Type, - circuit_name: Option<&leo_ast::Identifier>, - ) -> Result, AsgConvertError> { + pub fn resolve_ast_type(&self, type_: &leo_ast::Type) -> Result, AsgConvertError> { use leo_ast::Type::*; Ok(match type_ { Address => Type::Address, @@ -182,7 +178,7 @@ impl<'a> Scope<'a> { Group => Type::Group, IntegerType(int_type) => Type::Integer(int_type.clone()), Array(sub_type, dimensions) => { - let mut item = Box::new(self.resolve_ast_type(&*sub_type, circuit_name)?); + let mut item = Box::new(self.resolve_ast_type(&*sub_type)?); for dimension in dimensions.0.iter().rev() { let dimension = dimension .value @@ -195,7 +191,7 @@ impl<'a> Scope<'a> { Tuple(sub_types) => Type::Tuple( sub_types .iter() - .map(|x| self.resolve_ast_type(x, circuit_name)) + .map(|x| self.resolve_ast_type(x)) .collect::, AsgConvertError>>()?, ), SelfType => Type::Circuit( @@ -203,15 +199,15 @@ impl<'a> Scope<'a> { .ok_or_else(AsgConvertError::reference_self_outside_circuit)?, ), Circuit(name) => { - match circuit_name { - Some(cname) if name.name == cname.name => { - return Ok(Type::Circuit( - self.resolve_circuit_self() - .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, - )); - } - _ => {} - } + // match current_circuit_name { + // Some(cname) if name.name == cname.name => { + // return Ok(Type::Circuit( + // self.resolve_circuit_self() + // .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, + // )); + // } + // _ => {} + // } Type::Circuit( self.resolve_circuit(&name.name) diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index 7978414e80..110105a2bf 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -66,7 +66,6 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::AssignStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { let (name, span) = (&statement.assignee.identifier.name, &statement.assignee.identifier.span); @@ -105,7 +104,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { .as_ref() .map( |left: &leo_ast::Expression| -> Result<&'a Expression<'a>, AsgConvertError> { - <&Expression<'a>>::from_ast(scope, left, index_type.clone(), circuit_name) + <&Expression<'a>>::from_ast(scope, left, index_type.clone()) }, ) .transpose()?; @@ -113,7 +112,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { .as_ref() .map( |right: &leo_ast::Expression| -> Result<&'a Expression<'a>, AsgConvertError> { - <&Expression<'a>>::from_ast(scope, right, index_type, circuit_name) + <&Expression<'a>>::from_ast(scope, right, index_type) }, ) .transpose()?; @@ -167,7 +166,6 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { scope, index, Some(PartialType::Integer(None, Some(IntegerType::U32))), - circuit_name, )?)) } AstAssigneeAccess::Tuple(index, _) => { @@ -217,7 +215,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { } }); } - let value = <&Expression<'a>>::from_ast(scope, &statement.value, target_type, circuit_name)?; + let value = <&Expression<'a>>::from_ast(scope, &statement.value, target_type)?; let statement = scope.context.alloc_statement(Statement::Assign(AssignStatement { parent: Cell::new(None), diff --git a/asg/src/statement/block.rs b/asg/src/statement/block.rs index 0051ffc842..9a64fcdfb9 100644 --- a/asg/src/statement/block.rs +++ b/asg/src/statement/block.rs @@ -37,18 +37,12 @@ impl<'a> FromAst<'a, leo_ast::Block> for BlockStatement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::Block, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { let new_scope = scope.make_subscope(); let mut output = vec![]; for item in statement.statements.iter() { - output.push(Cell::new(<&'a Statement<'a>>::from_ast( - &new_scope, - item, - None, - circuit_name, - )?)); + output.push(Cell::new(<&'a Statement<'a>>::from_ast(&new_scope, item, None)?)); } Ok(BlockStatement { parent: Cell::new(None), diff --git a/asg/src/statement/conditional.rs b/asg/src/statement/conditional.rs index b61e1ee95e..b468ce9d3c 100644 --- a/asg/src/statement/conditional.rs +++ b/asg/src/statement/conditional.rs @@ -38,21 +38,18 @@ impl<'a> FromAst<'a, leo_ast::ConditionalStatement> for ConditionalStatement<'a> scope: &'a Scope<'a>, statement: &leo_ast::ConditionalStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { - let condition = - <&Expression<'a>>::from_ast(scope, &statement.condition, Some(Type::Boolean.into()), circuit_name)?; + let condition = <&Expression<'a>>::from_ast(scope, &statement.condition, Some(Type::Boolean.into()))?; let result = scope.context.alloc_statement(Statement::Block(BlockStatement::from_ast( scope, &statement.block, None, - circuit_name, )?)); let next = statement .next .as_deref() .map(|next| -> Result<&'a Statement<'a>, AsgConvertError> { - <&'a Statement<'a>>::from_ast(scope, next, None, circuit_name) + <&'a Statement<'a>>::from_ast(scope, next, None) }) .transpose()?; diff --git a/asg/src/statement/console.rs b/asg/src/statement/console.rs index 1edbd13e28..5820abb579 100644 --- a/asg/src/statement/console.rs +++ b/asg/src/statement/console.rs @@ -53,7 +53,6 @@ impl<'a> FromAst<'a, leo_ast::FormattedString> for FormattedString<'a> { scope: &'a Scope<'a>, value: &leo_ast::FormattedString, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { let expected_param_len = value .parts @@ -70,12 +69,7 @@ impl<'a> FromAst<'a, leo_ast::FormattedString> for FormattedString<'a> { } let mut parameters = vec![]; for parameter in value.parameters.iter() { - parameters.push(Cell::new(<&Expression<'a>>::from_ast( - scope, - parameter, - None, - circuit_name, - )?)); + parameters.push(Cell::new(<&Expression<'a>>::from_ast(scope, parameter, None)?)); } Ok(FormattedString { parts: value.parts.clone(), @@ -100,23 +94,22 @@ impl<'a> FromAst<'a, leo_ast::ConsoleStatement> for ConsoleStatement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::ConsoleStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { Ok(ConsoleStatement { parent: Cell::new(None), span: Some(statement.span.clone()), function: match &statement.function { AstConsoleFunction::Assert(expression) => ConsoleFunction::Assert(Cell::new( - <&Expression<'a>>::from_ast(scope, expression, Some(Type::Boolean.into()), circuit_name)?, + <&Expression<'a>>::from_ast(scope, expression, Some(Type::Boolean.into()))?, )), AstConsoleFunction::Debug(formatted_string) => { - ConsoleFunction::Debug(FormattedString::from_ast(scope, formatted_string, None, circuit_name)?) + ConsoleFunction::Debug(FormattedString::from_ast(scope, formatted_string, None)?) } AstConsoleFunction::Error(formatted_string) => { - ConsoleFunction::Error(FormattedString::from_ast(scope, formatted_string, None, circuit_name)?) + ConsoleFunction::Error(FormattedString::from_ast(scope, formatted_string, None)?) } AstConsoleFunction::Log(formatted_string) => { - ConsoleFunction::Log(FormattedString::from_ast(scope, formatted_string, None, circuit_name)?) + ConsoleFunction::Log(FormattedString::from_ast(scope, formatted_string, None)?) } }, }) diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index cd38a0fb9f..fb9b7be2ee 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -50,15 +50,14 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::DefinitionStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { let type_ = statement .type_ .as_ref() - .map(|x| scope.resolve_ast_type(&x, circuit_name)) + .map(|x| scope.resolve_ast_type(&x)) .transpose()?; - let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into), circuit_name)?; + let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?; let type_ = type_.or_else(|| value.get_type()); diff --git a/asg/src/statement/expression.rs b/asg/src/statement/expression.rs index 9a9a475ef3..f00c55c488 100644 --- a/asg/src/statement/expression.rs +++ b/asg/src/statement/expression.rs @@ -36,9 +36,8 @@ impl<'a> FromAst<'a, leo_ast::ExpressionStatement> for ExpressionStatement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::ExpressionStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { - let expression = <&Expression<'a>>::from_ast(scope, &statement.expression, None, circuit_name)?; + let expression = <&Expression<'a>>::from_ast(scope, &statement.expression, None)?; Ok(ExpressionStatement { parent: Cell::new(None), diff --git a/asg/src/statement/iteration.rs b/asg/src/statement/iteration.rs index 2cb2656049..d5908d24da 100644 --- a/asg/src/statement/iteration.rs +++ b/asg/src/statement/iteration.rs @@ -53,11 +53,10 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::IterationStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { let expected_index_type = Some(PartialType::Integer(None, Some(IntegerType::U32))); - let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone(), circuit_name)?; - let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type, circuit_name)?; + let start = <&Expression<'a>>::from_ast(scope, &statement.start, expected_index_type.clone())?; + let stop = <&Expression<'a>>::from_ast(scope, &statement.stop, expected_index_type)?; // Return an error if start or stop is not constant. if !start.is_consty() { @@ -101,7 +100,6 @@ impl<'a> FromAst<'a, leo_ast::IterationStatement> for &'a Statement<'a> { scope, &statement.block, None, - circuit_name, )?)), ), })); diff --git a/asg/src/statement/mod.rs b/asg/src/statement/mod.rs index 1b732e15b1..c564eac4b8 100644 --- a/asg/src/statement/mod.rs +++ b/asg/src/statement/mod.rs @@ -79,55 +79,35 @@ impl<'a> FromAst<'a, leo_ast::Statement> for &'a Statement<'a> { scope: &'a Scope<'a>, value: &leo_ast::Statement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result<&'a Statement<'a>, AsgConvertError> { use leo_ast::Statement::*; Ok(match value { Return(statement) => scope .context - .alloc_statement(Statement::Return(ReturnStatement::from_ast( - scope, - statement, - None, - circuit_name, - )?)), - Definition(statement) => Self::from_ast(scope, statement, None, circuit_name)?, - Assign(statement) => Self::from_ast(scope, statement, None, circuit_name)?, + .alloc_statement(Statement::Return(ReturnStatement::from_ast(scope, statement, None)?)), + Definition(statement) => Self::from_ast(scope, statement, None)?, + Assign(statement) => Self::from_ast(scope, statement, None)?, Conditional(statement) => { scope .context .alloc_statement(Statement::Conditional(ConditionalStatement::from_ast( - scope, - statement, - None, - circuit_name, + scope, statement, None, )?)) } - Iteration(statement) => Self::from_ast(scope, statement, None, circuit_name)?, + Iteration(statement) => Self::from_ast(scope, statement, None)?, Console(statement) => scope .context - .alloc_statement(Statement::Console(ConsoleStatement::from_ast( - scope, - statement, - None, - circuit_name, - )?)), + .alloc_statement(Statement::Console(ConsoleStatement::from_ast(scope, statement, None)?)), Expression(statement) => { scope .context .alloc_statement(Statement::Expression(ExpressionStatement::from_ast( - scope, - statement, - None, - circuit_name, + scope, statement, None, )?)) } - Block(statement) => scope.context.alloc_statement(Statement::Block(BlockStatement::from_ast( - scope, - statement, - None, - circuit_name, - )?)), + Block(statement) => scope + .context + .alloc_statement(Statement::Block(BlockStatement::from_ast(scope, statement, None)?)), }) } } diff --git a/asg/src/statement/return_.rs b/asg/src/statement/return_.rs index fc0912421e..fb6b640390 100644 --- a/asg/src/statement/return_.rs +++ b/asg/src/statement/return_.rs @@ -35,7 +35,6 @@ impl<'a> FromAst<'a, leo_ast::ReturnStatement> for ReturnStatement<'a> { scope: &'a Scope<'a>, statement: &leo_ast::ReturnStatement, _expected_type: Option>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result { let return_type: Option = scope .resolve_current_function() @@ -48,7 +47,6 @@ impl<'a> FromAst<'a, leo_ast::ReturnStatement> for ReturnStatement<'a> { scope, &statement.expression, return_type.map(Into::into), - circuit_name, )?), }) } diff --git a/ast/src/lib.rs b/ast/src/lib.rs index 65bbc74f95..c50b3021bc 100644 --- a/ast/src/lib.rs +++ b/ast/src/lib.rs @@ -82,8 +82,9 @@ impl Ast { Self { ast: program } } + /// Mutates the program ast by preforming canonicalization on it. pub fn canonicalize(&mut self) -> Result<(), CanonicalizeError> { - self.ast = ReconstructingDirector::new(Canonicalizer).reduce_program(self.as_repr())?; + self.ast = ReconstructingDirector::new(Canonicalizer::default()).reduce_program(self.as_repr())?; Ok(()) } diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 06178ecfea..caf98e237e 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -16,17 +16,30 @@ use crate::*; -pub struct Canonicalizer; +/// Replace Self when it is in a enclosing circuit type. +/// Error when Self is outside an enclosing circuit type. +/// Tuple array types and expressions expand to nested arrays. +/// Tuple array types and expressions error if a size of 0 is given.anyhow +/// Compound operators become simple assignments. +/// Functions missing output type return a empty tuple. +pub struct Canonicalizer { + // If we are in a circuit keep track of the circuit name. + circuit_name: Option, +} impl Canonicalizer { - fn is_self_type(&self, type_option: Option<&Type>) -> bool { + pub fn default() -> Self { + Self { circuit_name: None } + } + + fn is_self_type(&mut self, type_option: Option<&Type>) -> bool { matches!(type_option, Some(Type::SelfType)) } - fn canonicalize_expression(&self, expression: &Expression, circuit_name: &Identifier) -> Expression { + fn canonicalize_expression(&mut self, expression: &Expression) -> Expression { match expression { Expression::Unary(unary) => { - let inner = Box::new(self.canonicalize_expression(&unary.inner, circuit_name)); + let inner = Box::new(self.canonicalize_expression(&unary.inner)); return Expression::Unary(UnaryExpression { inner, @@ -35,8 +48,8 @@ impl Canonicalizer { }); } Expression::Binary(binary) => { - let left = Box::new(self.canonicalize_expression(&binary.left, circuit_name)); - let right = Box::new(self.canonicalize_expression(&binary.right, circuit_name)); + let left = Box::new(self.canonicalize_expression(&binary.left)); + let right = Box::new(self.canonicalize_expression(&binary.right)); return Expression::Binary(BinaryExpression { left, @@ -46,9 +59,9 @@ impl Canonicalizer { }); } Expression::Ternary(ternary) => { - let condition = Box::new(self.canonicalize_expression(&ternary.condition, circuit_name)); - let if_true = Box::new(self.canonicalize_expression(&ternary.if_true, circuit_name)); - let if_false = Box::new(self.canonicalize_expression(&ternary.if_false, circuit_name)); + let condition = Box::new(self.canonicalize_expression(&ternary.condition)); + let if_true = Box::new(self.canonicalize_expression(&ternary.if_true)); + let if_false = Box::new(self.canonicalize_expression(&ternary.if_false)); return Expression::Ternary(TernaryExpression { condition, @@ -59,11 +72,11 @@ impl Canonicalizer { } Expression::Cast(cast) => { - let inner = Box::new(self.canonicalize_expression(&cast.inner, circuit_name)); + let inner = Box::new(self.canonicalize_expression(&cast.inner)); let mut target_type = cast.target_type.clone(); if matches!(target_type, Type::SelfType) { - target_type = Type::Circuit(circuit_name.clone()); + target_type = Type::Circuit(self.circuit_name.as_ref().unwrap().clone()); } return Expression::Cast(CastExpression { @@ -79,10 +92,10 @@ impl Canonicalizer { .iter() .map(|element| match element { SpreadOrExpression::Expression(expression) => { - SpreadOrExpression::Expression(self.canonicalize_expression(expression, circuit_name)) + SpreadOrExpression::Expression(self.canonicalize_expression(expression)) } SpreadOrExpression::Spread(expression) => { - SpreadOrExpression::Spread(self.canonicalize_expression(expression, circuit_name)) + SpreadOrExpression::Spread(self.canonicalize_expression(expression)) } }) .collect(); @@ -94,7 +107,7 @@ impl Canonicalizer { } Expression::ArrayInit(array_init) => { - let element = Box::new(self.canonicalize_expression(&array_init.element, circuit_name)); + let element = Box::new(self.canonicalize_expression(&array_init.element)); return Expression::ArrayInit(ArrayInitExpression { dimensions: array_init.dimensions.clone(), @@ -104,8 +117,8 @@ impl Canonicalizer { } Expression::ArrayAccess(array_access) => { - let array = Box::new(self.canonicalize_expression(&array_access.array, circuit_name)); - let index = Box::new(self.canonicalize_expression(&array_access.index, circuit_name)); + let array = Box::new(self.canonicalize_expression(&array_access.array)); + let index = Box::new(self.canonicalize_expression(&array_access.index)); return Expression::ArrayAccess(ArrayAccessExpression { array, @@ -115,15 +128,15 @@ impl Canonicalizer { } Expression::ArrayRangeAccess(array_range_access) => { - let array = Box::new(self.canonicalize_expression(&array_range_access.array, circuit_name)); + let array = Box::new(self.canonicalize_expression(&array_range_access.array)); let left = array_range_access .left .as_ref() - .map(|left| Box::new(self.canonicalize_expression(left, circuit_name))); + .map(|left| Box::new(self.canonicalize_expression(left))); let right = array_range_access .right .as_ref() - .map(|right| Box::new(self.canonicalize_expression(right, circuit_name))); + .map(|right| Box::new(self.canonicalize_expression(right))); return Expression::ArrayRangeAccess(ArrayRangeAccessExpression { array, @@ -137,7 +150,7 @@ impl Canonicalizer { let elements = tuple_init .elements .iter() - .map(|element| self.canonicalize_expression(element, circuit_name)) + .map(|element| self.canonicalize_expression(element)) .collect(); return Expression::TupleInit(TupleInitExpression { @@ -147,7 +160,7 @@ impl Canonicalizer { } Expression::TupleAccess(tuple_access) => { - let tuple = Box::new(self.canonicalize_expression(&tuple_access.tuple, circuit_name)); + let tuple = Box::new(self.canonicalize_expression(&tuple_access.tuple)); return Expression::TupleAccess(TupleAccessExpression { tuple, @@ -159,7 +172,7 @@ impl Canonicalizer { Expression::CircuitInit(circuit_init) => { let mut name = circuit_init.name.clone(); if name.name == *"Self" { - name = circuit_name.clone(); + name = self.circuit_name.as_ref().unwrap().clone(); } return Expression::CircuitInit(CircuitInitExpression { @@ -170,21 +183,21 @@ impl Canonicalizer { } Expression::CircuitMemberAccess(circuit_member_access) => { return Expression::CircuitMemberAccess(CircuitMemberAccessExpression { - circuit: Box::new(self.canonicalize_expression(&circuit_member_access.circuit, circuit_name)), + circuit: Box::new(self.canonicalize_expression(&circuit_member_access.circuit)), name: circuit_member_access.name.clone(), span: circuit_member_access.span.clone(), }); } Expression::CircuitStaticFunctionAccess(circuit_static_func_access) => { return Expression::CircuitStaticFunctionAccess(CircuitStaticFunctionAccessExpression { - circuit: Box::new(self.canonicalize_expression(&circuit_static_func_access.circuit, circuit_name)), + circuit: Box::new(self.canonicalize_expression(&circuit_static_func_access.circuit)), name: circuit_static_func_access.name.clone(), span: circuit_static_func_access.span.clone(), }); } Expression::Call(call) => { return Expression::Call(CallExpression { - function: Box::new(self.canonicalize_expression(&call.function, circuit_name)), + function: Box::new(self.canonicalize_expression(&call.function)), arguments: call.arguments.clone(), span: call.span.clone(), }); @@ -195,32 +208,30 @@ impl Canonicalizer { expression.clone() } - fn canonicalize_assignee_access(&self, access: &AssigneeAccess, circuit_name: &Identifier) -> AssigneeAccess { + fn canonicalize_assignee_access(&mut self, access: &AssigneeAccess) -> AssigneeAccess { match access { AssigneeAccess::ArrayRange(left, right) => { let left = match left.as_ref() { - Some(left) => Some(self.canonicalize_expression(left, circuit_name)), + Some(left) => Some(self.canonicalize_expression(left)), None => None, }; let right = match right.as_ref() { - Some(right) => Some(self.canonicalize_expression(right, circuit_name)), + Some(right) => Some(self.canonicalize_expression(right)), None => None, }; AssigneeAccess::ArrayRange(left, right) } - AssigneeAccess::ArrayIndex(index) => { - AssigneeAccess::ArrayIndex(self.canonicalize_expression(&index, circuit_name)) - } + AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(&index)), _ => access.clone(), } } - fn canonicalize_assignee(&self, assignee: &Assignee, circuit_name: &Identifier) -> Assignee { + fn canonicalize_assignee(&mut self, assignee: &Assignee) -> Assignee { let accesses = assignee .accesses .iter() - .map(|access| self.canonicalize_assignee_access(access, circuit_name)) + .map(|access| self.canonicalize_assignee_access(access)) .collect(); Assignee { @@ -230,11 +241,11 @@ impl Canonicalizer { } } - fn canonicalize_block(&self, block: &Block, circuit_name: &Identifier) -> Block { + fn canonicalize_block(&mut self, block: &Block) -> Block { let statements = block .statements .iter() - .map(|block_statement| self.canonicalize_statement(&block_statement, circuit_name)) + .map(|block_statement| self.canonicalize_statement(&block_statement)) .collect(); Block { @@ -243,21 +254,21 @@ impl Canonicalizer { } } - fn canonicalize_statement(&self, statement: &Statement, circuit_name: &Identifier) -> Statement { + fn canonicalize_statement(&mut self, statement: &Statement) -> Statement { match statement { Statement::Return(return_statement) => { - let expression = self.canonicalize_expression(&return_statement.expression, circuit_name); + let expression = self.canonicalize_expression(&return_statement.expression); Statement::Return(ReturnStatement { expression, span: return_statement.span.clone(), }) } Statement::Definition(definition) => { - let value = self.canonicalize_expression(&definition.value, circuit_name); + let value = self.canonicalize_expression(&definition.value); let mut type_ = definition.type_.clone(); if self.is_self_type(type_.as_ref()) { - type_ = Some(Type::Circuit(circuit_name.clone())); + type_ = Some(Type::Circuit(self.circuit_name.as_ref().unwrap().clone())); } Statement::Definition(DefinitionStatement { @@ -269,8 +280,8 @@ impl Canonicalizer { }) } Statement::Assign(assign) => { - let assignee = self.canonicalize_assignee(&assign.assignee, circuit_name); - let value = self.canonicalize_expression(&assign.value, circuit_name); + let assignee = self.canonicalize_assignee(&assign.assignee); + let value = self.canonicalize_expression(&assign.value); Statement::Assign(AssignStatement { assignee, @@ -280,10 +291,10 @@ impl Canonicalizer { }) } Statement::Conditional(conditional) => { - let condition = self.canonicalize_expression(&conditional.condition, circuit_name); - let block = self.canonicalize_block(&conditional.block, circuit_name); + let condition = self.canonicalize_expression(&conditional.condition); + let block = self.canonicalize_block(&conditional.block); let next = match conditional.next.as_ref() { - Some(condition) => Some(Box::new(self.canonicalize_statement(condition, circuit_name))), + Some(condition) => Some(Box::new(self.canonicalize_statement(condition))), None => None, }; @@ -295,9 +306,9 @@ impl Canonicalizer { }) } Statement::Iteration(iteration) => { - let start = self.canonicalize_expression(&iteration.start, circuit_name); - let stop = self.canonicalize_expression(&iteration.stop, circuit_name); - let block = self.canonicalize_block(&iteration.block, circuit_name); + let start = self.canonicalize_expression(&iteration.start); + let stop = self.canonicalize_expression(&iteration.stop); + let block = self.canonicalize_block(&iteration.block); Statement::Iteration(IterationStatement { variable: iteration.variable.clone(), @@ -310,13 +321,13 @@ impl Canonicalizer { Statement::Console(console_function_call) => { let function = match &console_function_call.function { ConsoleFunction::Assert(expression) => { - ConsoleFunction::Assert(self.canonicalize_expression(expression, circuit_name)) + ConsoleFunction::Assert(self.canonicalize_expression(expression)) } ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { let parameters = format .parameters .iter() - .map(|parameter| self.canonicalize_expression(parameter, circuit_name)) + .map(|parameter| self.canonicalize_expression(parameter)) .collect(); let formatted = FormattedString { @@ -340,23 +351,23 @@ impl Canonicalizer { }) } Statement::Expression(expression) => Statement::Expression(ExpressionStatement { - expression: self.canonicalize_expression(&expression.expression, circuit_name), + expression: self.canonicalize_expression(&expression.expression), span: expression.span.clone(), }), - Statement::Block(block) => Statement::Block(self.canonicalize_block(block, circuit_name)), + Statement::Block(block) => Statement::Block(self.canonicalize_block(block)), } } - fn canonicalize_circuit_member(&self, circuit_member: &CircuitMember, circuit_name: &Identifier) -> CircuitMember { + fn canonicalize_circuit_member(&mut self, circuit_member: &CircuitMember) -> CircuitMember { match circuit_member { CircuitMember::CircuitVariable(_, _) => {} CircuitMember::CircuitFunction(function) => { let input = function.input.clone(); let mut output = function.output.clone(); - let block = self.canonicalize_block(&function.block, circuit_name); + let block = self.canonicalize_block(&function.block); if self.is_self_type(output.as_ref()) { - output = Some(Type::Circuit(circuit_name.clone())); + output = Some(Type::Circuit(self.circuit_name.as_ref().unwrap().clone())); } return CircuitMember::CircuitFunction(Function { @@ -375,7 +386,13 @@ impl Canonicalizer { } impl ReconstructingReducer for Canonicalizer { - fn reduce_type(&self, _type_: &Type, new: Type, in_circuit: bool, span: &Span) -> Result { + fn reduce_type( + &mut self, + _type_: &Type, + new: Type, + in_circuit: bool, + span: &Span, + ) -> Result { match new { Type::Array(type_, mut dimensions) => { if dimensions.is_zero() { @@ -402,7 +419,7 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_array_init( - &self, + &mut self, array_init: &ArrayInitExpression, element: Expression, _in_circuit: bool, @@ -451,7 +468,7 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_assign( - &self, + &mut self, assign: &AssignStatement, assignee: Assignee, value: Expression, @@ -499,7 +516,7 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_function( - &self, + &mut self, function: &Function, identifier: Identifier, annotations: Vec, @@ -524,17 +541,20 @@ impl ReconstructingReducer for Canonicalizer { } fn reduce_circuit( - &self, + &mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec, ) -> Result { - Ok(Circuit { - circuit_name: circuit_name.clone(), + self.circuit_name = Some(circuit_name.clone()); + let circ = Circuit { + circuit_name, members: members .iter() - .map(|member| self.canonicalize_circuit_member(member, &circuit_name)) + .map(|member| self.canonicalize_circuit_member(member)) .collect(), - }) + }; + self.circuit_name = None; + Ok(circ) } } diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 06aa1f4501..302811fff3 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -22,22 +22,24 @@ use indexmap::IndexMap; pub struct ReconstructingDirector { reducer: R, + in_circuit: bool, } impl ReconstructingDirector { pub fn new(reducer: R) -> Self { - Self { reducer } + Self { + reducer, + in_circuit: false, + } } - pub fn reduce_type(&self, type_: &Type, in_circuit: bool, span: &Span) -> Result { + pub fn reduce_type(&mut self, type_: &Type, span: &Span) -> Result { let new = match type_ { - Type::Array(type_, dimensions) => { - Type::Array(Box::new(self.reduce_type(type_, in_circuit, span)?), dimensions.clone()) - } + Type::Array(type_, dimensions) => Type::Array(Box::new(self.reduce_type(type_, span)?), dimensions.clone()), Type::Tuple(types) => { let mut reduced_types = vec![]; for type_ in types.iter() { - reduced_types.push(self.reduce_type(type_, in_circuit, span)?); + reduced_types.push(self.reduce_type(type_, span)?); } Type::Tuple(reduced_types) @@ -46,70 +48,54 @@ impl ReconstructingDirector { _ => type_.clone(), }; - self.reducer.reduce_type(type_, new, in_circuit, span) + self.reducer.reduce_type(type_, new, self.in_circuit, span) } // Expressions - pub fn reduce_expression( - &self, - expression: &Expression, - in_circuit: bool, - ) -> Result { + pub fn reduce_expression(&mut self, expression: &Expression) -> Result { let new = match expression { Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?), Expression::Value(value) => Expression::Value(self.reduce_value(&value)?), - Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary, in_circuit)?), - Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary, in_circuit)?), - Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary, in_circuit)?), - Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast, in_circuit)?), + Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary)?), + Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary)?), + Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary)?), + Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast)?), - Expression::ArrayInline(array_inline) => { - Expression::ArrayInline(self.reduce_array_inline(&array_inline, in_circuit)?) - } - Expression::ArrayInit(array_init) => { - Expression::ArrayInit(self.reduce_array_init(&array_init, in_circuit)?) - } - Expression::ArrayAccess(array_access) => { - Expression::ArrayAccess(self.reduce_array_access(&array_access, in_circuit)?) - } + Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(&array_inline)?), + Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(&array_init)?), + Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(&array_access)?), Expression::ArrayRangeAccess(array_range_access) => { - Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access, in_circuit)?) + Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access)?) } - Expression::TupleInit(tuple_init) => { - Expression::TupleInit(self.reduce_tuple_init(&tuple_init, in_circuit)?) - } - Expression::TupleAccess(tuple_access) => { - Expression::TupleAccess(self.reduce_tuple_access(&tuple_access, in_circuit)?) - } + Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(&tuple_init)?), + Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(&tuple_access)?), - Expression::CircuitInit(circuit_init) => { - Expression::CircuitInit(self.reduce_circuit_init(&circuit_init, in_circuit)?) - } + Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(&circuit_init)?), Expression::CircuitMemberAccess(circuit_member_access) => { - Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access, in_circuit)?) + Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access)?) } Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => { Expression::CircuitStaticFunctionAccess( - self.reduce_circuit_static_fn_access(&circuit_static_fn_access, in_circuit)?, + self.reduce_circuit_static_fn_access(&circuit_static_fn_access)?, ) } - Expression::Call(call) => Expression::Call(self.reduce_call(&call, in_circuit)?), + Expression::Call(call) => Expression::Call(self.reduce_call(&call)?), }; - self.reducer.reduce_expression(expression, new, in_circuit) + self.reducer.reduce_expression(expression, new, self.in_circuit) } - pub fn reduce_identifier(&self, identifier: &Identifier) -> Result { + pub fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { self.reducer.reduce_identifier(identifier) } - pub fn reduce_group_tuple(&self, group_tuple: &GroupTuple) -> Result { + pub fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { self.reducer.reduce_group_tuple(group_tuple) } - pub fn reduce_group_value(&self, group_value: &GroupValue) -> Result { + pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { let new = match group_value { GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?), _ => group_value.clone(), @@ -118,7 +104,7 @@ impl ReconstructingDirector { self.reducer.reduce_group_value(group_value, new) } - pub fn reduce_value(&self, value: &ValueExpression) -> Result { + pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { let new = match value { ValueExpression::Group(group_value) => { ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?)) @@ -129,243 +115,212 @@ impl ReconstructingDirector { self.reducer.reduce_value(value, new) } - pub fn reduce_binary( - &self, - binary: &BinaryExpression, - in_circuit: bool, - ) -> Result { - let left = self.reduce_expression(&binary.left, in_circuit)?; - let right = self.reduce_expression(&binary.right, in_circuit)?; + pub fn reduce_binary(&mut self, binary: &BinaryExpression) -> Result { + let left = self.reduce_expression(&binary.left)?; + let right = self.reduce_expression(&binary.right)?; self.reducer - .reduce_binary(binary, left, right, binary.op.clone(), in_circuit) + .reduce_binary(binary, left, right, binary.op.clone(), self.in_circuit) } - pub fn reduce_unary( - &self, - unary: &UnaryExpression, - in_circuit: bool, - ) -> Result { - let inner = self.reduce_expression(&unary.inner, in_circuit)?; - - self.reducer.reduce_unary(unary, inner, unary.op.clone(), in_circuit) - } - - pub fn reduce_ternary( - &self, - ternary: &TernaryExpression, - in_circuit: bool, - ) -> Result { - let condition = self.reduce_expression(&ternary.condition, in_circuit)?; - let if_true = self.reduce_expression(&ternary.if_true, in_circuit)?; - let if_false = self.reduce_expression(&ternary.if_false, in_circuit)?; + pub fn reduce_unary(&mut self, unary: &UnaryExpression) -> Result { + let inner = self.reduce_expression(&unary.inner)?; self.reducer - .reduce_ternary(ternary, condition, if_true, if_false, in_circuit) + .reduce_unary(unary, inner, unary.op.clone(), self.in_circuit) } - pub fn reduce_cast(&self, cast: &CastExpression, in_circuit: bool) -> Result { - let inner = self.reduce_expression(&cast.inner, in_circuit)?; - let target_type = self.reduce_type(&cast.target_type, in_circuit, &cast.span)?; + pub fn reduce_ternary(&mut self, ternary: &TernaryExpression) -> Result { + let condition = self.reduce_expression(&ternary.condition)?; + let if_true = self.reduce_expression(&ternary.if_true)?; + let if_false = self.reduce_expression(&ternary.if_false)?; - self.reducer.reduce_cast(cast, inner, target_type, in_circuit) + self.reducer + .reduce_ternary(ternary, condition, if_true, if_false, self.in_circuit) + } + + pub fn reduce_cast(&mut self, cast: &CastExpression) -> Result { + let inner = self.reduce_expression(&cast.inner)?; + let target_type = self.reduce_type(&cast.target_type, &cast.span)?; + + self.reducer.reduce_cast(cast, inner, target_type, self.in_circuit) } pub fn reduce_array_inline( - &self, + &mut self, array_inline: &ArrayInlineExpression, - in_circuit: bool, ) -> Result { let mut elements = vec![]; for element in array_inline.elements.iter() { let reduced_element = match element { SpreadOrExpression::Expression(expression) => { - SpreadOrExpression::Expression(self.reduce_expression(expression, in_circuit)?) + SpreadOrExpression::Expression(self.reduce_expression(expression)?) } SpreadOrExpression::Spread(expression) => { - SpreadOrExpression::Spread(self.reduce_expression(expression, in_circuit)?) + SpreadOrExpression::Spread(self.reduce_expression(expression)?) } }; elements.push(reduced_element); } - self.reducer.reduce_array_inline(array_inline, elements, in_circuit) + self.reducer + .reduce_array_inline(array_inline, elements, self.in_circuit) } pub fn reduce_array_init( - &self, + &mut self, array_init: &ArrayInitExpression, - in_circuit: bool, ) -> Result { - let element = self.reduce_expression(&array_init.element, in_circuit)?; + let element = self.reduce_expression(&array_init.element)?; - self.reducer.reduce_array_init(array_init, element, in_circuit) + self.reducer.reduce_array_init(array_init, element, self.in_circuit) } pub fn reduce_array_access( - &self, + &mut self, array_access: &ArrayAccessExpression, - in_circuit: bool, ) -> Result { - let array = self.reduce_expression(&array_access.array, in_circuit)?; - let index = self.reduce_expression(&array_access.index, in_circuit)?; + let array = self.reduce_expression(&array_access.array)?; + let index = self.reduce_expression(&array_access.index)?; - self.reducer.reduce_array_access(array_access, array, index, in_circuit) + self.reducer + .reduce_array_access(array_access, array, index, self.in_circuit) } pub fn reduce_array_range_access( - &self, + &mut self, array_range_access: &ArrayRangeAccessExpression, - in_circuit: bool, ) -> Result { - let array = self.reduce_expression(&array_range_access.array, in_circuit)?; + let array = self.reduce_expression(&array_range_access.array)?; let left = match array_range_access.left.as_ref() { - Some(left) => Some(self.reduce_expression(left, in_circuit)?), + Some(left) => Some(self.reduce_expression(left)?), None => None, }; let right = match array_range_access.right.as_ref() { - Some(right) => Some(self.reduce_expression(right, in_circuit)?), + Some(right) => Some(self.reduce_expression(right)?), None => None, }; self.reducer - .reduce_array_range_access(array_range_access, array, left, right, in_circuit) + .reduce_array_range_access(array_range_access, array, left, right, self.in_circuit) } pub fn reduce_tuple_init( - &self, + &mut self, tuple_init: &TupleInitExpression, - in_circuit: bool, ) -> Result { let mut elements = vec![]; for element in tuple_init.elements.iter() { - elements.push(self.reduce_expression(element, in_circuit)?); + elements.push(self.reduce_expression(element)?); } - self.reducer.reduce_tuple_init(tuple_init, elements, in_circuit) + self.reducer.reduce_tuple_init(tuple_init, elements, self.in_circuit) } pub fn reduce_tuple_access( - &self, + &mut self, tuple_access: &TupleAccessExpression, - in_circuit: bool, ) -> Result { - let tuple = self.reduce_expression(&tuple_access.tuple, in_circuit)?; + let tuple = self.reduce_expression(&tuple_access.tuple)?; - self.reducer.reduce_tuple_access(tuple_access, tuple, in_circuit) + self.reducer.reduce_tuple_access(tuple_access, tuple, self.in_circuit) } pub fn reduce_circuit_implied_variable_definition( - &self, + &mut self, variable: &CircuitImpliedVariableDefinition, - in_circuit: bool, ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; let expression = match variable.expression.as_ref() { - Some(expr) => Some(self.reduce_expression(expr, in_circuit)?), + Some(expr) => Some(self.reduce_expression(expr)?), None => None, }; self.reducer - .reduce_circuit_implied_variable_definition(variable, identifier, expression, in_circuit) + .reduce_circuit_implied_variable_definition(variable, identifier, expression, self.in_circuit) } pub fn reduce_circuit_init( - &self, + &mut self, circuit_init: &CircuitInitExpression, - in_circuit: bool, ) -> Result { let name = self.reduce_identifier(&circuit_init.name)?; let mut members = vec![]; for member in circuit_init.members.iter() { - members.push(self.reduce_circuit_implied_variable_definition(member, in_circuit)?); + members.push(self.reduce_circuit_implied_variable_definition(member)?); } self.reducer - .reduce_circuit_init(circuit_init, name, members, in_circuit) + .reduce_circuit_init(circuit_init, name, members, self.in_circuit) } pub fn reduce_circuit_member_access( - &self, + &mut self, circuit_member_access: &CircuitMemberAccessExpression, - in_circuit: bool, ) -> Result { - let circuit = self.reduce_expression(&circuit_member_access.circuit, in_circuit)?; + let circuit = self.reduce_expression(&circuit_member_access.circuit)?; let name = self.reduce_identifier(&circuit_member_access.name)?; self.reducer - .reduce_circuit_member_access(circuit_member_access, circuit, name, in_circuit) + .reduce_circuit_member_access(circuit_member_access, circuit, name, self.in_circuit) } pub fn reduce_circuit_static_fn_access( - &self, + &mut self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, - in_circuit: bool, ) -> Result { - let circuit = self.reduce_expression(&circuit_static_fn_access.circuit, in_circuit)?; + let circuit = self.reduce_expression(&circuit_static_fn_access.circuit)?; let name = self.reduce_identifier(&circuit_static_fn_access.name)?; self.reducer - .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name, in_circuit) + .reduce_circuit_static_fn_access(circuit_static_fn_access, circuit, name, self.in_circuit) } - pub fn reduce_call(&self, call: &CallExpression, in_circuit: bool) -> Result { - let function = self.reduce_expression(&call.function, in_circuit)?; + pub fn reduce_call(&mut self, call: &CallExpression) -> Result { + let function = self.reduce_expression(&call.function)?; let mut arguments = vec![]; for argument in call.arguments.iter() { - arguments.push(self.reduce_expression(argument, in_circuit)?); + arguments.push(self.reduce_expression(argument)?); } - self.reducer.reduce_call(call, function, arguments, in_circuit) + self.reducer.reduce_call(call, function, arguments, self.in_circuit) } // Statements - pub fn reduce_statement(&self, statement: &Statement, in_circuit: bool) -> Result { + pub fn reduce_statement(&mut self, statement: &Statement) -> Result { let new = match statement { - Statement::Return(return_statement) => { - Statement::Return(self.reduce_return(&return_statement, in_circuit)?) - } - Statement::Definition(definition) => { - Statement::Definition(self.reduce_definition(&definition, in_circuit)?) - } - Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign, in_circuit)?), - Statement::Conditional(conditional) => { - Statement::Conditional(self.reduce_conditional(&conditional, in_circuit)?) - } - Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration, in_circuit)?), - Statement::Console(console) => Statement::Console(self.reduce_console(&console, in_circuit)?), - Statement::Expression(expression) => { - Statement::Expression(self.reduce_expression_statement(&expression, in_circuit)?) - } - Statement::Block(block) => Statement::Block(self.reduce_block(&block, in_circuit)?), + Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)?), + Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)?), + Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)?), + Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(&conditional)?), + Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration)?), + Statement::Console(console) => Statement::Console(self.reduce_console(&console)?), + Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)?), + Statement::Block(block) => Statement::Block(self.reduce_block(&block)?), }; - self.reducer.reduce_statement(statement, new, in_circuit) + self.reducer.reduce_statement(statement, new, self.in_circuit) } - pub fn reduce_return( - &self, - return_statement: &ReturnStatement, - in_circuit: bool, - ) -> Result { - let expression = self.reduce_expression(&return_statement.expression, in_circuit)?; + pub fn reduce_return(&mut self, return_statement: &ReturnStatement) -> Result { + let expression = self.reduce_expression(&return_statement.expression)?; - self.reducer.reduce_return(return_statement, expression, in_circuit) + self.reducer + .reduce_return(return_statement, expression, self.in_circuit) } - pub fn reduce_variable_name(&self, variable_name: &VariableName) -> Result { + pub fn reduce_variable_name(&mut self, variable_name: &VariableName) -> Result { let identifier = self.reduce_identifier(&variable_name.identifier)?; self.reducer.reduce_variable_name(variable_name, identifier) } pub fn reduce_definition( - &self, + &mut self, definition: &DefinitionStatement, - in_circuit: bool, ) -> Result { let mut variable_names = vec![]; for variable_name in definition.variable_names.iter() { @@ -373,109 +328,95 @@ impl ReconstructingDirector { } let type_ = match definition.type_.as_ref() { - Some(inner) => Some(self.reduce_type(inner, in_circuit, &definition.span)?), + Some(inner) => Some(self.reduce_type(inner, &definition.span)?), None => None, }; - let value = self.reduce_expression(&definition.value, in_circuit)?; + let value = self.reduce_expression(&definition.value)?; self.reducer - .reduce_definition(definition, variable_names, type_, value, in_circuit) + .reduce_definition(definition, variable_names, type_, value, self.in_circuit) } - pub fn reduce_assignee_access( - &self, - access: &AssigneeAccess, - in_circuit: bool, - ) -> Result { + pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> Result { let new = match access { AssigneeAccess::ArrayRange(left, right) => { let left = match left.as_ref() { - Some(left) => Some(self.reduce_expression(left, in_circuit)?), + Some(left) => Some(self.reduce_expression(left)?), None => None, }; let right = match right.as_ref() { - Some(right) => Some(self.reduce_expression(right, in_circuit)?), + Some(right) => Some(self.reduce_expression(right)?), None => None, }; AssigneeAccess::ArrayRange(left, right) } - AssigneeAccess::ArrayIndex(index) => { - AssigneeAccess::ArrayIndex(self.reduce_expression(&index, in_circuit)?) - } + AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(&index)?), AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)?), _ => access.clone(), }; - self.reducer.reduce_assignee_access(access, new, in_circuit) + self.reducer.reduce_assignee_access(access, new, self.in_circuit) } - pub fn reduce_assignee(&self, assignee: &Assignee, in_circuit: bool) -> Result { + pub fn reduce_assignee(&mut self, assignee: &Assignee) -> Result { let identifier = self.reduce_identifier(&assignee.identifier)?; let mut accesses = vec![]; for access in assignee.accesses.iter() { - accesses.push(self.reduce_assignee_access(access, in_circuit)?); + accesses.push(self.reduce_assignee_access(access)?); } - self.reducer.reduce_assignee(assignee, identifier, accesses, in_circuit) + self.reducer + .reduce_assignee(assignee, identifier, accesses, self.in_circuit) } - pub fn reduce_assign( - &self, - assign: &AssignStatement, - in_circuit: bool, - ) -> Result { - let assignee = self.reduce_assignee(&assign.assignee, in_circuit)?; - let value = self.reduce_expression(&assign.value, in_circuit)?; + pub fn reduce_assign(&mut self, assign: &AssignStatement) -> Result { + let assignee = self.reduce_assignee(&assign.assignee)?; + let value = self.reduce_expression(&assign.value)?; - self.reducer.reduce_assign(assign, assignee, value, in_circuit) + self.reducer.reduce_assign(assign, assignee, value, self.in_circuit) } pub fn reduce_conditional( - &self, + &mut self, conditional: &ConditionalStatement, - in_circuit: bool, ) -> Result { - let condition = self.reduce_expression(&conditional.condition, in_circuit)?; - let block = self.reduce_block(&conditional.block, in_circuit)?; + let condition = self.reduce_expression(&conditional.condition)?; + let block = self.reduce_block(&conditional.block)?; let next = match conditional.next.as_ref() { - Some(condition) => Some(self.reduce_statement(condition, in_circuit)?), + Some(condition) => Some(self.reduce_statement(condition)?), None => None, }; self.reducer - .reduce_conditional(conditional, condition, block, next, in_circuit) + .reduce_conditional(conditional, condition, block, next, self.in_circuit) } pub fn reduce_iteration( - &self, + &mut self, iteration: &IterationStatement, - in_circuit: bool, ) -> Result { let variable = self.reduce_identifier(&iteration.variable)?; - let start = self.reduce_expression(&iteration.start, in_circuit)?; - let stop = self.reduce_expression(&iteration.stop, in_circuit)?; - let block = self.reduce_block(&iteration.block, in_circuit)?; + let start = self.reduce_expression(&iteration.start)?; + let stop = self.reduce_expression(&iteration.stop)?; + let block = self.reduce_block(&iteration.block)?; self.reducer - .reduce_iteration(iteration, variable, start, stop, block, in_circuit) + .reduce_iteration(iteration, variable, start, stop, block, self.in_circuit) } pub fn reduce_console( - &self, + &mut self, console_function_call: &ConsoleStatement, - in_circuit: bool, ) -> Result { let function = match &console_function_call.function { - ConsoleFunction::Assert(expression) => { - ConsoleFunction::Assert(self.reduce_expression(expression, in_circuit)?) - } + ConsoleFunction::Assert(expression) => ConsoleFunction::Assert(self.reduce_expression(expression)?), ConsoleFunction::Debug(format) | ConsoleFunction::Error(format) | ConsoleFunction::Log(format) => { let mut parameters = vec![]; for parameter in format.parameters.iter() { - parameters.push(self.reduce_expression(parameter, in_circuit)?); + parameters.push(self.reduce_expression(parameter)?); } let formatted = FormattedString { @@ -493,33 +434,33 @@ impl ReconstructingDirector { } }; - self.reducer.reduce_console(console_function_call, function, in_circuit) + self.reducer + .reduce_console(console_function_call, function, self.in_circuit) } pub fn reduce_expression_statement( - &self, + &mut self, expression: &ExpressionStatement, - in_circuit: bool, ) -> Result { - let inner_expression = self.reduce_expression(&expression.expression, in_circuit)?; + let inner_expression = self.reduce_expression(&expression.expression)?; self.reducer - .reduce_expression_statement(expression, inner_expression, in_circuit) + .reduce_expression_statement(expression, inner_expression, self.in_circuit) } - pub fn reduce_block(&self, block: &Block, in_circuit: bool) -> Result { + pub fn reduce_block(&mut self, block: &Block) -> Result { let mut statements = vec![]; for statement in block.statements.iter() { - statements.push(self.reduce_statement(statement, in_circuit)?); + statements.push(self.reduce_statement(statement)?); } - self.reducer.reduce_block(block, statements, in_circuit) + self.reducer.reduce_block(block, statements, self.in_circuit) } // Program - pub fn reduce_program(&self, program: &Program) -> Result { + pub fn reduce_program(&mut self, program: &Program) -> Result { let mut inputs = vec![]; for input in program.expected_input.iter() { - inputs.push(self.reduce_function_input(input, false)?); + inputs.push(self.reduce_function_input(input)?); } let mut imports = vec![]; @@ -534,10 +475,7 @@ impl ReconstructingDirector { let mut functions = IndexMap::new(); for (identifier, function) in program.functions.iter() { - functions.insert( - self.reduce_identifier(identifier)?, - self.reduce_function(function, false)?, - ); + functions.insert(self.reduce_identifier(identifier)?, self.reduce_function(function)?); } self.reducer @@ -545,34 +483,29 @@ impl ReconstructingDirector { } pub fn reduce_function_input_variable( - &self, + &mut self, variable: &FunctionInputVariable, - in_circuit: bool, ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; - let type_ = self.reduce_type(&variable.type_, in_circuit, &variable.span)?; + let type_ = self.reduce_type(&variable.type_, &variable.span)?; self.reducer - .reduce_function_input_variable(variable, identifier, type_, in_circuit) + .reduce_function_input_variable(variable, identifier, type_, self.in_circuit) } - pub fn reduce_function_input( - &self, - input: &FunctionInput, - in_circuit: bool, - ) -> Result { + pub fn reduce_function_input(&mut self, input: &FunctionInput) -> Result { let new = match input { FunctionInput::Variable(function_input_variable) => { - FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable, in_circuit)?) + FunctionInput::Variable(self.reduce_function_input_variable(function_input_variable)?) } _ => input.clone(), }; - self.reducer.reduce_function_input(input, new, in_circuit) + self.reducer.reduce_function_input(input, new, self.in_circuit) } pub fn reduce_package_or_packages( - &self, + &mut self, package_or_packages: &PackageOrPackages, ) -> Result { let new = match package_or_packages { @@ -591,27 +524,32 @@ impl ReconstructingDirector { self.reducer.reduce_package_or_packages(package_or_packages, new) } - pub fn reduce_import(&self, import: &ImportStatement) -> Result { + pub fn reduce_import(&mut self, import: &ImportStatement) -> Result { let package_or_packages = self.reduce_package_or_packages(&import.package_or_packages)?; self.reducer.reduce_import(import, package_or_packages) } - pub fn reduce_circuit_member(&self, circuit_member: &CircuitMember) -> Result { + pub fn reduce_circuit_member( + &mut self, + circuit_member: &CircuitMember, + ) -> Result { + self.in_circuit = !self.in_circuit; let new = match circuit_member { CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable( self.reduce_identifier(&identifier)?, - self.reduce_type(&type_, true, &identifier.span)?, + self.reduce_type(&type_, &identifier.span)?, ), CircuitMember::CircuitFunction(function) => { - CircuitMember::CircuitFunction(self.reduce_function(&function, true)?) + CircuitMember::CircuitFunction(self.reduce_function(&function)?) } }; + self.in_circuit = !self.in_circuit; self.reducer.reduce_circuit_member(circuit_member, new) } - pub fn reduce_circuit(&self, circuit: &Circuit) -> Result { + pub fn reduce_circuit(&mut self, circuit: &Circuit) -> Result { let circuit_name = self.reduce_identifier(&circuit.circuit_name)?; let mut members = vec![]; @@ -622,13 +560,13 @@ impl ReconstructingDirector { self.reducer.reduce_circuit(circuit, circuit_name, members) } - fn reduce_annotation(&self, annotation: &Annotation) -> Result { + fn reduce_annotation(&mut self, annotation: &Annotation) -> Result { let name = self.reduce_identifier(&annotation.name)?; self.reducer.reduce_annotation(annotation, name) } - pub fn reduce_function(&self, function: &Function, in_circuit: bool) -> Result { + pub fn reduce_function(&mut self, function: &Function) -> Result { let identifier = self.reduce_identifier(&function.identifier)?; let mut annotations = vec![]; @@ -638,17 +576,24 @@ impl ReconstructingDirector { let mut inputs = vec![]; for input in function.input.iter() { - inputs.push(self.reduce_function_input(input, in_circuit)?); + inputs.push(self.reduce_function_input(input)?); } let output = match function.output.as_ref() { - Some(type_) => Some(self.reduce_type(type_, in_circuit, &function.span)?), + Some(type_) => Some(self.reduce_type(type_, &function.span)?), None => None, }; - let block = self.reduce_block(&function.block, in_circuit)?; + let block = self.reduce_block(&function.block)?; - self.reducer - .reduce_function(function, identifier, annotations, inputs, output, block, in_circuit) + self.reducer.reduce_function( + function, + identifier, + annotations, + inputs, + output, + block, + self.in_circuit, + ) } } diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 784d2c917c..872d14d52e 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -21,7 +21,7 @@ use indexmap::IndexMap; #[allow(clippy::redundant_closure)] pub trait ReconstructingReducer { fn reduce_type( - &self, + &mut self, _type_: &Type, new: Type, _in_circuit: bool, @@ -32,7 +32,7 @@ pub trait ReconstructingReducer { // Expressions fn reduce_expression( - &self, + &mut self, _expression: &Expression, new: Expression, _in_circuit: bool, @@ -40,14 +40,14 @@ pub trait ReconstructingReducer { Ok(new) } - fn reduce_identifier(&self, identifier: &Identifier) -> Result { + fn reduce_identifier(&mut self, identifier: &Identifier) -> Result { Ok(Identifier { name: identifier.name.clone(), span: identifier.span.clone(), }) } - fn reduce_group_tuple(&self, group_tuple: &GroupTuple) -> Result { + fn reduce_group_tuple(&mut self, group_tuple: &GroupTuple) -> Result { Ok(GroupTuple { x: group_tuple.x.clone(), y: group_tuple.y.clone(), @@ -55,12 +55,16 @@ pub trait ReconstructingReducer { }) } - fn reduce_group_value(&self, _group_value: &GroupValue, new: GroupValue) -> Result { + fn reduce_group_value( + &mut self, + _group_value: &GroupValue, + new: GroupValue, + ) -> Result { Ok(new) } fn reduce_value( - &self, + &mut self, _value: &ValueExpression, new: ValueExpression, ) -> Result { @@ -68,7 +72,7 @@ pub trait ReconstructingReducer { } fn reduce_binary( - &self, + &mut self, binary: &BinaryExpression, left: Expression, right: Expression, @@ -84,7 +88,7 @@ pub trait ReconstructingReducer { } fn reduce_unary( - &self, + &mut self, unary: &UnaryExpression, inner: Expression, op: UnaryOperation, @@ -98,7 +102,7 @@ pub trait ReconstructingReducer { } fn reduce_ternary( - &self, + &mut self, ternary: &TernaryExpression, condition: Expression, if_true: Expression, @@ -114,7 +118,7 @@ pub trait ReconstructingReducer { } fn reduce_cast( - &self, + &mut self, cast: &CastExpression, inner: Expression, target_type: Type, @@ -128,7 +132,7 @@ pub trait ReconstructingReducer { } fn reduce_array_inline( - &self, + &mut self, array_inline: &ArrayInlineExpression, elements: Vec, _in_circuit: bool, @@ -140,7 +144,7 @@ pub trait ReconstructingReducer { } fn reduce_array_init( - &self, + &mut self, array_init: &ArrayInitExpression, element: Expression, _in_circuit: bool, @@ -153,7 +157,7 @@ pub trait ReconstructingReducer { } fn reduce_array_access( - &self, + &mut self, array_access: &ArrayAccessExpression, array: Expression, index: Expression, @@ -167,7 +171,7 @@ pub trait ReconstructingReducer { } fn reduce_array_range_access( - &self, + &mut self, array_rage_access: &ArrayRangeAccessExpression, array: Expression, left: Option, @@ -183,7 +187,7 @@ pub trait ReconstructingReducer { } fn reduce_tuple_init( - &self, + &mut self, tuple_init: &TupleInitExpression, elements: Vec, _in_circuit: bool, @@ -195,7 +199,7 @@ pub trait ReconstructingReducer { } fn reduce_tuple_access( - &self, + &mut self, tuple_access: &TupleAccessExpression, tuple: Expression, _in_circuit: bool, @@ -208,7 +212,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_implied_variable_definition( - &self, + &mut self, _variable: &CircuitImpliedVariableDefinition, identifier: Identifier, expression: Option, @@ -218,7 +222,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_init( - &self, + &mut self, circuit_init: &CircuitInitExpression, name: Identifier, members: Vec, @@ -232,7 +236,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_member_access( - &self, + &mut self, circuit_member_access: &CircuitMemberAccessExpression, circuit: Expression, name: Identifier, @@ -246,7 +250,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_static_fn_access( - &self, + &mut self, circuit_static_fn_access: &CircuitStaticFunctionAccessExpression, circuit: Expression, name: Identifier, @@ -260,7 +264,7 @@ pub trait ReconstructingReducer { } fn reduce_call( - &self, + &mut self, call: &CallExpression, function: Expression, arguments: Vec, @@ -275,7 +279,7 @@ pub trait ReconstructingReducer { // Statements fn reduce_statement( - &self, + &mut self, _statement: &Statement, new: Statement, _in_circuit: bool, @@ -284,7 +288,7 @@ pub trait ReconstructingReducer { } fn reduce_return( - &self, + &mut self, return_statement: &ReturnStatement, expression: Expression, _in_circuit: bool, @@ -296,7 +300,7 @@ pub trait ReconstructingReducer { } fn reduce_variable_name( - &self, + &mut self, variable_name: &VariableName, identifier: Identifier, ) -> Result { @@ -308,7 +312,7 @@ pub trait ReconstructingReducer { } fn reduce_definition( - &self, + &mut self, definition: &DefinitionStatement, variable_names: Vec, type_: Option, @@ -325,7 +329,7 @@ pub trait ReconstructingReducer { } fn reduce_assignee_access( - &self, + &mut self, _access: &AssigneeAccess, new: AssigneeAccess, _in_circuit: bool, @@ -334,7 +338,7 @@ pub trait ReconstructingReducer { } fn reduce_assignee( - &self, + &mut self, assignee: &Assignee, identifier: Identifier, accesses: Vec, @@ -348,7 +352,7 @@ pub trait ReconstructingReducer { } fn reduce_assign( - &self, + &mut self, assign: &AssignStatement, assignee: Assignee, value: Expression, @@ -363,7 +367,7 @@ pub trait ReconstructingReducer { } fn reduce_conditional( - &self, + &mut self, conditional: &ConditionalStatement, condition: Expression, block: Block, @@ -379,7 +383,7 @@ pub trait ReconstructingReducer { } fn reduce_iteration( - &self, + &mut self, iteration: &IterationStatement, variable: Identifier, start: Expression, @@ -397,7 +401,7 @@ pub trait ReconstructingReducer { } fn reduce_console( - &self, + &mut self, console: &ConsoleStatement, function: ConsoleFunction, _in_circuit: bool, @@ -409,7 +413,7 @@ pub trait ReconstructingReducer { } fn reduce_expression_statement( - &self, + &mut self, expression_statement: &ExpressionStatement, expression: Expression, _in_circuit: bool, @@ -421,7 +425,7 @@ pub trait ReconstructingReducer { } fn reduce_block( - &self, + &mut self, block: &Block, statements: Vec, _in_circuit: bool, @@ -434,7 +438,7 @@ pub trait ReconstructingReducer { // Program fn reduce_program( - &self, + &mut self, program: &Program, expected_input: Vec, imports: Vec, @@ -451,7 +455,7 @@ pub trait ReconstructingReducer { } fn reduce_function_input_variable( - &self, + &mut self, variable: &FunctionInputVariable, identifier: Identifier, type_: Type, @@ -467,7 +471,7 @@ pub trait ReconstructingReducer { } fn reduce_function_input( - &self, + &mut self, _input: &FunctionInput, new: FunctionInput, _in_circuit: bool, @@ -476,7 +480,7 @@ pub trait ReconstructingReducer { } fn reduce_package_or_packages( - &self, + &mut self, _package_or_packages: &PackageOrPackages, new: PackageOrPackages, ) -> Result { @@ -484,7 +488,7 @@ pub trait ReconstructingReducer { } fn reduce_import( - &self, + &mut self, import: &ImportStatement, package_or_packages: PackageOrPackages, ) -> Result { @@ -495,7 +499,7 @@ pub trait ReconstructingReducer { } fn reduce_circuit_member( - &self, + &mut self, _circuit_member: &CircuitMember, new: CircuitMember, ) -> Result { @@ -503,15 +507,19 @@ pub trait ReconstructingReducer { } fn reduce_circuit( - &self, + &mut self, _circuit: &Circuit, circuit_name: Identifier, members: Vec, ) -> Result { - Ok(Circuit { circuit_name, members }) + Ok(Circuit { members, circuit_name }) } - fn reduce_annotation(&self, annotation: &Annotation, name: Identifier) -> Result { + fn reduce_annotation( + &mut self, + annotation: &Annotation, + name: Identifier, + ) -> Result { Ok(Annotation { span: annotation.span.clone(), name, @@ -521,7 +529,7 @@ pub trait ReconstructingReducer { #[allow(clippy::too_many_arguments)] fn reduce_function( - &self, + &mut self, function: &Function, identifier: Identifier, annotations: Vec, diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index df395f6259..42863ab92f 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -264,7 +264,10 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { ); let mut ast = parse_ast(self.main_file_path.to_str().unwrap_or_default(), program_string)?; - ast.canonicalize()?; + // Preform compiler optimization via canonicalizing AST if its enabled. + if self.options.canonicalization_enabled { + ast.canonicalize()?; + } // Store the main program file. self.program = ast.into_repr(); diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index 676528b749..63bd2767b4 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -78,7 +78,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }; let member_name = name.clone(); - let member_value = self.allocate_input_section(cs, name, sub_circuit, values, None)?; + let member_value = self.allocate_input_section(cs, name, sub_circuit, values)?; let member = ConstrainedCircuitMember(member_name, member_value); diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index 81124367d5..e188b82f3b 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -30,7 +30,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { identifier: Identifier, expected_type: &'a Circuit<'a>, section: IndexMap>, - circuit_name: Option<&leo_ast::Identifier>, ) -> Result, FunctionError> { let mut members = Vec::with_capacity(section.len()); @@ -41,7 +40,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { Some(CircuitMember::Variable(inner)) => inner, _ => continue, // present, but unused }; - let declared_type = self.asg.scope.resolve_ast_type(¶meter.type_, circuit_name)?; + let declared_type = self.asg.scope.resolve_ast_type(¶meter.type_)?; if !expected_type.is_assignable_from(&declared_type) { return Err(AsgConvertError::unexpected_type( &expected_type.to_string(), diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 6ad67d5992..3505e28f24 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -123,7 +123,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, None, &span)?; + let output_bytes = OutputBytes::new_from_constrained_value(&self.asg, registers, result_value, &span)?; Ok(output_bytes) } diff --git a/compiler/src/option.rs b/compiler/src/option.rs index 8e87d4654c..be5f8964e5 100644 --- a/compiler/src/option.rs +++ b/compiler/src/option.rs @@ -19,6 +19,7 @@ /// #[derive(Clone)] pub struct CompilerOptions { + pub canonicalization_enabled: bool, pub constant_folding_enabled: bool, pub dead_code_elimination_enabled: bool, } @@ -29,6 +30,7 @@ impl Default for CompilerOptions { /// fn default() -> Self { CompilerOptions { + canonicalization_enabled: true, constant_folding_enabled: true, dead_code_elimination_enabled: true, } diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index 2a6b66c568..9060f2e40c 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>, - circuit_name: Option<&leo_ast::Identifier>, + span: &Span, ) -> Result { let return_values = match value { @@ -68,7 +68,7 @@ impl OutputBytes { let name = parameter.variable.name; // Check register type == return value type. - let register_type = program.scope.resolve_ast_type(¶meter.type_, circuit_name)?; + let register_type = program.scope.resolve_ast_type(¶meter.type_)?; let return_value_type = value.to_type(span)?; if !register_type.is_assignable_from(&return_value_type) { From 99db18167a1fac272ec656c99c41df149bc0cdd0 Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 25 Mar 2021 14:15:30 -0400 Subject: [PATCH 26/40] second header pass for circuit members --- asg/src/program/circuit.rs | 15 ++++++++++++++- asg/src/program/mod.rs | 10 +++++++++- asg/src/scope.rs | 24 ++++++++---------------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index deb4821e3e..f787e79e5a 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -53,7 +53,7 @@ impl<'a> Node for Circuit<'a> { } impl<'a> Circuit<'a> { - pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> Result<&'a Circuit<'a>, AsgConvertError> { + pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> &'a Circuit<'a> { let new_scope = scope.make_subscope(); let circuit = scope.context.alloc_circuit(Circuit { @@ -66,6 +66,19 @@ impl<'a> Circuit<'a> { }); new_scope.circuit_self.replace(Some(circuit)); + circuit + } + + pub(super) fn init_member( + scope: &'a Scope<'a>, + value: &leo_ast::Circuit, + ) -> Result<&'a Circuit<'a>, AsgConvertError> { + let new_scope = scope.make_subscope(); + let circuits = scope.circuits.borrow(); + + let circuit = circuits.get(&value.circuit_name.name).unwrap(); + new_scope.circuit_self.replace(Some(circuit)); + let mut members = circuit.members.borrow_mut(); for member in value.members.iter() { match member { diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index 71d83cb1a5..c28cda246b 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -238,7 +238,15 @@ impl<'a> Program<'a> { // Prepare header-like scope entries. for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); - let asg_circuit = Circuit::init(scope, circuit)?; + let asg_circuit = Circuit::init(scope, circuit); + + scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit); + } + + // Second pass for circuit members. + for (name, circuit) in program.circuits.iter() { + assert_eq!(name.name, circuit.circuit_name.name); + let asg_circuit = Circuit::init_member(scope, circuit)?; scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit); } diff --git a/asg/src/scope.rs b/asg/src/scope.rs index 3471ae6094..2a8ac9d093 100644 --- a/asg/src/scope.rs +++ b/asg/src/scope.rs @@ -194,26 +194,18 @@ impl<'a> Scope<'a> { .map(|x| self.resolve_ast_type(x)) .collect::, AsgConvertError>>()?, ), + Circuit(name) if name.name == "Self" => Type::Circuit( + self.resolve_circuit_self() + .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, + ), SelfType => Type::Circuit( self.resolve_circuit_self() .ok_or_else(AsgConvertError::reference_self_outside_circuit)?, ), - Circuit(name) => { - // match current_circuit_name { - // Some(cname) if name.name == cname.name => { - // return Ok(Type::Circuit( - // self.resolve_circuit_self() - // .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, - // )); - // } - // _ => {} - // } - - Type::Circuit( - self.resolve_circuit(&name.name) - .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, - ) - } + Circuit(name) => Type::Circuit( + self.resolve_circuit(&name.name) + .ok_or_else(|| AsgConvertError::unresolved_circuit(&name.name, &name.span))?, + ), }) } } From 793cbb9f27d8bd2154b45f7445b8e504f1d39eb6 Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 25 Mar 2021 14:30:06 -0400 Subject: [PATCH 27/40] add test for const self, no clippy issues locally --- .../tests/circuits/const_self_variable_fail.leo | 13 +++++++++++++ compiler/tests/circuits/mod.rs | 9 +++++++++ examples/pedersen-hash/src/main.leo | 4 ---- 3 files changed, 22 insertions(+), 4 deletions(-) create mode 100644 compiler/tests/circuits/const_self_variable_fail.leo diff --git a/compiler/tests/circuits/const_self_variable_fail.leo b/compiler/tests/circuits/const_self_variable_fail.leo new file mode 100644 index 0000000000..fca9620946 --- /dev/null +++ b/compiler/tests/circuits/const_self_variable_fail.leo @@ -0,0 +1,13 @@ +circuit Foo { + a: u8, + + function set_a(const self, new: u8) { + self.a = new; + } +} + +function main() { + let f = Foo { a: 0u8 }; + + f.set_a(1u8); +} \ No newline at end of file diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs index 3fe4b54955..77d8801e4b 100644 --- a/compiler/tests/circuits/mod.rs +++ b/compiler/tests/circuits/mod.rs @@ -132,6 +132,15 @@ fn test_member_static_function_undefined() { expect_asg_error(error) } +// Constant +#[test] +fn test_const_self_variable_fail() { + let program_string = include_str!("const_self_variable_fail.leo"); + let error = parse_program(program_string).err().unwrap(); + + expect_asg_error(error); +} + // Mutability #[test] diff --git a/examples/pedersen-hash/src/main.leo b/examples/pedersen-hash/src/main.leo index 5f5a650006..84670cd6c2 100644 --- a/examples/pedersen-hash/src/main.leo +++ b/examples/pedersen-hash/src/main.leo @@ -19,11 +19,7 @@ circuit PedersenHash { // The 'pedersen-hash' main function. function main(hash_input: [bool; 256], const parameters: [group; 256]) -> group { -<<<<<<< HEAD const pedersen = PedersenHash::new(parameters); -======= - let pedersen = PedersenHash::new(parameters); ->>>>>>> 9b61d0fa152f435e3e165090455c85eedeb9b770 return pedersen.hash(hash_input) } From cf603dbc738930cc60d5a389e9fb21202dc6947b Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 25 Mar 2021 14:51:43 -0400 Subject: [PATCH 28/40] no circular reference --- asg/src/program/circuit.rs | 60 ++++++++++++++++++++------------------ asg/src/program/mod.rs | 2 +- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/asg/src/program/circuit.rs b/asg/src/program/circuit.rs index f787e79e5a..6ca447234e 100644 --- a/asg/src/program/circuit.rs +++ b/asg/src/program/circuit.rs @@ -53,7 +53,7 @@ impl<'a> Node for Circuit<'a> { } impl<'a> Circuit<'a> { - pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> &'a Circuit<'a> { + pub(super) fn init(scope: &'a Scope<'a>, value: &leo_ast::Circuit) -> Result<&'a Circuit<'a>, AsgConvertError> { let new_scope = scope.make_subscope(); let circuit = scope.context.alloc_circuit(Circuit { @@ -66,7 +66,24 @@ impl<'a> Circuit<'a> { }); new_scope.circuit_self.replace(Some(circuit)); - circuit + let mut members = circuit.members.borrow_mut(); + for member in value.members.iter() { + if let leo_ast::CircuitMember::CircuitVariable(name, type_) = member { + if members.contains_key(&name.name) { + return Err(AsgConvertError::redefined_circuit_member( + &value.circuit_name.name, + &name.name, + &name.span, + )); + } + members.insert( + name.name.clone(), + CircuitMember::Variable(new_scope.resolve_ast_type(type_)?), + ); + } + } + + Ok(circuit) } pub(super) fn init_member( @@ -81,35 +98,20 @@ impl<'a> Circuit<'a> { let mut members = circuit.members.borrow_mut(); for member in value.members.iter() { - match member { - leo_ast::CircuitMember::CircuitVariable(name, type_) => { - if members.contains_key(&name.name) { - return Err(AsgConvertError::redefined_circuit_member( - &value.circuit_name.name, - &name.name, - &name.span, - )); - } - members.insert( - name.name.clone(), - CircuitMember::Variable(new_scope.resolve_ast_type(type_)?), - ); + if let leo_ast::CircuitMember::CircuitFunction(function) = member { + if members.contains_key(&function.identifier.name) { + return Err(AsgConvertError::redefined_circuit_member( + &value.circuit_name.name, + &function.identifier.name, + &function.identifier.span, + )); } - leo_ast::CircuitMember::CircuitFunction(function) => { - if members.contains_key(&function.identifier.name) { - return Err(AsgConvertError::redefined_circuit_member( - &value.circuit_name.name, - &function.identifier.name, - &function.identifier.span, - )); - } - 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)); + 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/mod.rs b/asg/src/program/mod.rs index c28cda246b..56f93c1d40 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -238,7 +238,7 @@ impl<'a> Program<'a> { // Prepare header-like scope entries. for (name, circuit) in program.circuits.iter() { assert_eq!(name.name, circuit.circuit_name.name); - let asg_circuit = Circuit::init(scope, circuit); + let asg_circuit = Circuit::init(scope, circuit)?; scope.circuits.borrow_mut().insert(name.name.clone(), asg_circuit); } From c78ab699b812777e99aa527450b43ea440211b4b Mon Sep 17 00:00:00 2001 From: gluax Date: Thu, 25 Mar 2021 16:52:43 -0400 Subject: [PATCH 29/40] another test --- compiler/tests/circuits/const_self_variable.leo | 13 +++++++++++++ compiler/tests/circuits/mod.rs | 8 ++++++++ 2 files changed, 21 insertions(+) create mode 100644 compiler/tests/circuits/const_self_variable.leo diff --git a/compiler/tests/circuits/const_self_variable.leo b/compiler/tests/circuits/const_self_variable.leo new file mode 100644 index 0000000000..ebcc3076ae --- /dev/null +++ b/compiler/tests/circuits/const_self_variable.leo @@ -0,0 +1,13 @@ +circuit Foo { + a: u8, + + function use_a(const self) -> u8 { + return self.a + 1 + } +} + +function main() { + let f = Foo { a: 0u8 }; + + console.assert(1u8 == f.use_a()); +} \ No newline at end of file diff --git a/compiler/tests/circuits/mod.rs b/compiler/tests/circuits/mod.rs index 77d8801e4b..9395853529 100644 --- a/compiler/tests/circuits/mod.rs +++ b/compiler/tests/circuits/mod.rs @@ -133,6 +133,14 @@ fn test_member_static_function_undefined() { } // Constant +#[test] +fn test_const_self_variable() { + let program_string = include_str!("const_self_variable.leo"); + let program = parse_program(program_string).unwrap(); + + assert_satisfied(program); +} + #[test] fn test_const_self_variable_fail() { let program_string = include_str!("const_self_variable_fail.leo"); From 1e69d1c68ec00f3ddcd4e3d7454daef9b6de3aa4 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 14:03:22 -0700 Subject: [PATCH 30/40] allow clippy::upper_case_acroynms for imported pest structs --- Cargo.lock | 4 ++-- input/src/ast.rs | 2 +- input/src/common/eoi.rs | 1 + input/src/lib.rs | 1 - 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 39b270a271..4ec3ace7a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2828,9 +2828,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", diff --git a/input/src/ast.rs b/input/src/ast.rs index cfb3deef07..1a5ec0d99e 100644 --- a/input/src/ast.rs +++ b/input/src/ast.rs @@ -13,10 +13,10 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +#![allow(clippy::upper_case_acronyms)] //! Abstract syntax tree (ast) representation from leo-input.pest. use pest::{error::Error, iterators::Pairs, Parser, Span}; - #[derive(Parser)] #[grammar = "leo-input.pest"] pub struct LanguageParser; diff --git a/input/src/common/eoi.rs b/input/src/common/eoi.rs index 738cd6e0c2..3eda4b51e9 100644 --- a/input/src/common/eoi.rs +++ b/input/src/common/eoi.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +#![allow(clippy::upper_case_acronyms)] use crate::ast::Rule; diff --git a/input/src/lib.rs b/input/src/lib.rs index e2537eeeb1..c8f709b229 100644 --- a/input/src/lib.rs +++ b/input/src/lib.rs @@ -13,7 +13,6 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . - #[macro_use] extern crate pest_derive; #[macro_use] From 8bc2140b1ecce22438239f8746d3c1b6231e8211 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 14:48:48 -0700 Subject: [PATCH 31/40] cargo clippy --examples --all --- ast/src/reducer/canonicalization.rs | 18 ++---- ast/src/reducer/reconstructing_director.rs | 64 +++++++++++----------- ast/src/reducer/reconstructing_reducer.rs | 2 +- parser/src/parser/expression.rs | 4 +- parser/src/tokenizer/lexer.rs | 4 +- 5 files changed, 43 insertions(+), 49 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index caf98e237e..e9be54f691 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -211,14 +211,8 @@ impl Canonicalizer { fn canonicalize_assignee_access(&mut self, access: &AssigneeAccess) -> AssigneeAccess { match access { AssigneeAccess::ArrayRange(left, right) => { - let left = match left.as_ref() { - Some(left) => Some(self.canonicalize_expression(left)), - None => None, - }; - let right = match right.as_ref() { - Some(right) => Some(self.canonicalize_expression(right)), - None => None, - }; + let left = left.as_ref().map(|left| self.canonicalize_expression(left)); + let right = right.as_ref().map(|right| self.canonicalize_expression(right)); AssigneeAccess::ArrayRange(left, right) } @@ -293,10 +287,10 @@ impl Canonicalizer { Statement::Conditional(conditional) => { let condition = self.canonicalize_expression(&conditional.condition); let block = self.canonicalize_block(&conditional.block); - let next = match conditional.next.as_ref() { - Some(condition) => Some(Box::new(self.canonicalize_statement(condition))), - None => None, - }; + let next = conditional + .next + .as_ref() + .map(|condition| Box::new(self.canonicalize_statement(condition))); Statement::Conditional(ConditionalStatement { condition, diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index 302811fff3..016d8d18db 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -193,14 +193,16 @@ impl ReconstructingDirector { array_range_access: &ArrayRangeAccessExpression, ) -> Result { let array = self.reduce_expression(&array_range_access.array)?; - let left = match array_range_access.left.as_ref() { - Some(left) => Some(self.reduce_expression(left)?), - None => None, - }; - let right = match array_range_access.right.as_ref() { - Some(right) => Some(self.reduce_expression(right)?), - None => None, - }; + let left = array_range_access + .left + .as_ref() + .map(|left| self.reduce_expression(left)) + .transpose()?; + let right = array_range_access + .right + .as_ref() + .map(|right| self.reduce_expression(right)) + .transpose()?; self.reducer .reduce_array_range_access(array_range_access, array, left, right, self.in_circuit) @@ -232,10 +234,11 @@ impl ReconstructingDirector { variable: &CircuitImpliedVariableDefinition, ) -> Result { let identifier = self.reduce_identifier(&variable.identifier)?; - let expression = match variable.expression.as_ref() { - Some(expr) => Some(self.reduce_expression(expr)?), - None => None, - }; + let expression = variable + .expression + .as_ref() + .map(|expr| self.reduce_expression(expr)) + .transpose()?; self.reducer .reduce_circuit_implied_variable_definition(variable, identifier, expression, self.in_circuit) @@ -327,10 +330,11 @@ impl ReconstructingDirector { variable_names.push(self.reduce_variable_name(variable_name)?); } - let type_ = match definition.type_.as_ref() { - Some(inner) => Some(self.reduce_type(inner, &definition.span)?), - None => None, - }; + let type_ = definition + .type_ + .as_ref() + .map(|type_| self.reduce_type(type_, &definition.span)) + .transpose()?; let value = self.reduce_expression(&definition.value)?; @@ -341,14 +345,8 @@ impl ReconstructingDirector { pub fn reduce_assignee_access(&mut self, access: &AssigneeAccess) -> Result { let new = match access { AssigneeAccess::ArrayRange(left, right) => { - let left = match left.as_ref() { - Some(left) => Some(self.reduce_expression(left)?), - None => None, - }; - let right = match right.as_ref() { - Some(right) => Some(self.reduce_expression(right)?), - None => None, - }; + let left = left.as_ref().map(|left| self.reduce_expression(left)).transpose()?; + let right = right.as_ref().map(|right| self.reduce_expression(right)).transpose()?; AssigneeAccess::ArrayRange(left, right) } @@ -385,10 +383,11 @@ impl ReconstructingDirector { ) -> Result { let condition = self.reduce_expression(&conditional.condition)?; let block = self.reduce_block(&conditional.block)?; - let next = match conditional.next.as_ref() { - Some(condition) => Some(self.reduce_statement(condition)?), - None => None, - }; + let next = conditional + .next + .as_ref() + .map(|condition| self.reduce_statement(condition)) + .transpose()?; self.reducer .reduce_conditional(conditional, condition, block, next, self.in_circuit) @@ -579,10 +578,11 @@ impl ReconstructingDirector { inputs.push(self.reduce_function_input(input)?); } - let output = match function.output.as_ref() { - Some(type_) => Some(self.reduce_type(type_, &function.span)?), - None => None, - }; + let output = function + .output + .as_ref() + .map(|type_| self.reduce_type(type_, &function.span)) + .transpose()?; let block = self.reduce_block(&function.block)?; diff --git a/ast/src/reducer/reconstructing_reducer.rs b/ast/src/reducer/reconstructing_reducer.rs index 872d14d52e..a06e350481 100644 --- a/ast/src/reducer/reconstructing_reducer.rs +++ b/ast/src/reducer/reconstructing_reducer.rs @@ -512,7 +512,7 @@ pub trait ReconstructingReducer { circuit_name: Identifier, members: Vec, ) -> Result { - Ok(Circuit { members, circuit_name }) + Ok(Circuit { circuit_name, members }) } fn reduce_annotation( diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index f8dbac1f0e..09756acce9 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -309,8 +309,8 @@ impl ParserContext { /// 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()?); + let mut exprs = vec![self.parse_cast_expression()?]; + while self.eat(Token::Exp).is_some() { exprs.push(self.parse_cast_expression()?); } diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 8236e85362..41f2a31634 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -212,7 +212,7 @@ impl Token { let (input, comment) = if let Some(eol) = eol { (&input[(eol + 1)..], &input[..eol]) } else { - (&input[input.len()..input.len()], &input[..]) + (&input[input.len()..input.len()], input) }; return ( input, @@ -226,7 +226,7 @@ impl Token { let (input, comment) = if let Some(eol) = eol { (&input[(eol + 4)..], &input[..eol + 4]) } else { - (&input[input.len()..input.len()], &input[..]) + (&input[input.len()..input.len()], input) }; return ( input, From f4f66194e56b9d834221420b7517ab87fcc9f3df Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 14:52:28 -0700 Subject: [PATCH 32/40] allow clippy::upper_case_acronyms for README --- package/src/root/readme.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/package/src/root/readme.rs b/package/src/root/readme.rs index 468f5e58b9..ad4d6190f2 100644 --- a/package/src/root/readme.rs +++ b/package/src/root/readme.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +#![allow(clippy::upper_case_acronyms)] //! The `README.md` file. From 0addc8008058d047725bad0b3ed7c1c6f4f8023c Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 15:15:36 -0700 Subject: [PATCH 33/40] clippy vec_init_then_push --- parser/src/parser/statement.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index c01190fa0b..2d8c4111fe 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -139,7 +139,9 @@ impl ParserContext { /// pub fn parse_block(&mut self) -> SyntaxResult { let start = self.expect(Token::LeftCurly)?; - let mut statements = vec![]; + + #[allow(clippy::vec_init_then_push)] + let mut statements = Vec::new(); loop { match self.eat(Token::RightCurly) { None => { From b5f80c925ca3e0c281d7fdad4792bbc852a29d60 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 15:19:39 -0700 Subject: [PATCH 34/40] clippy vec_init_then_push more --- parser/src/parser/expression.rs | 10 +++++----- parser/src/parser/file.rs | 16 ++++++++-------- parser/src/parser/statement.rs | 7 +++---- parser/src/parser/type_.rs | 4 ++-- parser/src/test.rs | 8 ++++---- parser/src/tokenizer/lexer.rs | 2 +- parser/src/tokenizer/mod.rs | 2 +- 7 files changed, 24 insertions(+), 25 deletions(-) diff --git a/parser/src/parser/expression.rs b/parser/src/parser/expression.rs index 09756acce9..b11d8bafce 100644 --- a/parser/src/parser/expression.rs +++ b/parser/src/parser/expression.rs @@ -353,7 +353,7 @@ impl ParserContext { /// Otherwise, tries to parse the next token using [`parse_access_expression`]. /// pub fn parse_unary_expression(&mut self) -> SyntaxResult { - let mut ops = vec![]; + let mut ops = Vec::new(); while let Some(token) = self.eat_any(&[Token::Not, Token::Minus, Token::BitNot]) { ops.push(token); } @@ -455,7 +455,7 @@ impl ParserContext { } } Token::LeftParen => { - let mut arguments = vec![]; + let mut arguments = Vec::new(); let end_span; loop { let end = self.eat(Token::RightParen); @@ -509,7 +509,7 @@ impl ParserContext { /// pub fn parse_circuit_init(&mut self, identifier: Identifier) -> SyntaxResult { self.expect(Token::LeftCurly)?; - let mut members = vec![]; + let mut members = Vec::new(); let end_span; loop { if let Some(end) = self.eat(Token::RightCurly) { @@ -603,7 +603,7 @@ impl ParserContext { }, ))))); } - let mut args = vec![]; + let mut args = Vec::new(); let end_span; loop { let end = self.eat(Token::RightParen); @@ -630,7 +630,7 @@ impl ParserContext { Token::LeftSquare => { if let Some(end) = self.eat(Token::RightSquare) { return Ok(Expression::ArrayInline(ArrayInlineExpression { - elements: vec![], + elements: Vec::new(), span: span + end.span, })); } diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index f61f228976..3d9b6d15b9 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -23,7 +23,7 @@ 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 imports = Vec::new(); let mut circuits = IndexMap::new(); let mut functions = IndexMap::new(); // let mut tests = IndexMap::new(); @@ -70,7 +70,7 @@ impl ParserContext { } Ok(Program { name: String::new(), - expected_input: vec![], + expected_input: Vec::new(), imports, circuits, functions, @@ -90,7 +90,7 @@ impl ParserContext { } let end_span; let arguments = if self.eat(Token::LeftParen).is_some() { - let mut args = vec![]; + let mut args = Vec::new(); loop { if let Some(end) = self.eat(Token::RightParen) { end_span = end.span; @@ -112,7 +112,7 @@ impl ParserContext { args } else { end_span = name.span.clone(); - vec![] + Vec::new() }; Ok(Annotation { name, @@ -126,7 +126,7 @@ impl ParserContext { /// expressions within an import statement. /// pub fn parse_package_accesses(&mut self) -> SyntaxResult> { - let mut out = vec![]; + let mut out = Vec::new(); self.expect(Token::LeftParen)?; while self.eat(Token::RightParen).is_none() { let access = self.parse_package_access()?; @@ -293,7 +293,7 @@ impl ParserContext { self.expect(Token::Circuit)?; let name = self.expect_ident()?; self.expect(Token::LeftCurly)?; - let mut members = vec![]; + let mut members = Vec::new(); while self.eat(Token::RightCurly).is_none() { let member = self.parse_circuit_member()?; members.push(member); @@ -353,14 +353,14 @@ impl ParserContext { /// and function definition. /// pub fn parse_function(&mut self) -> SyntaxResult<(Identifier, Function)> { - let mut annotations = vec![]; + let mut annotations = Vec::new(); 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![]; + let mut inputs = Vec::new(); while self.eat(Token::RightParen).is_none() { let input = self.parse_function_input()?; inputs.push(input); diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index 2d8c4111fe..cc82e03e9d 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -72,7 +72,7 @@ impl ParserContext { /// pub fn construct_assignee(expr: Expression) -> SyntaxResult { let expr_span = expr.span().clone(); - let mut accesses = vec![]; + let mut accesses = Vec::new(); let identifier = Self::construct_assignee_access(expr, &mut accesses)?; Ok(Assignee { @@ -140,7 +140,6 @@ impl ParserContext { pub fn parse_block(&mut self) -> SyntaxResult { let start = self.expect(Token::LeftCurly)?; - #[allow(clippy::vec_init_then_push)] let mut statements = Vec::new(); loop { match self.eat(Token::RightCurly) { @@ -232,7 +231,7 @@ impl ParserContext { } SpannedToken { token, span } => return Err(SyntaxError::unexpected_str(&token, "formatted string", &span)), }; - let mut parameters = vec![]; + let mut parameters = Vec::new(); while self.eat(Token::Comma).is_some() { let param = self.parse_expression()?; parameters.push(param); @@ -306,7 +305,7 @@ impl ParserContext { /// pub fn parse_definition_statement(&mut self) -> SyntaxResult { let declare = self.expect_oneof(&[Token::Let, Token::Const])?; - let mut variable_names = vec![]; + let mut variable_names = Vec::new(); if self.eat(Token::LeftParen).is_some() { variable_names.push(self.parse_variable_name()?); while self.eat(Token::Comma).is_some() { diff --git a/parser/src/parser/type_.rs b/parser/src/parser/type_.rs index cac76bbd3c..5a3eae2ec1 100644 --- a/parser/src/parser/type_.rs +++ b/parser/src/parser/type_.rs @@ -61,7 +61,7 @@ impl ParserContext { ArrayDimensions(vec![int]) } else { self.expect(Token::LeftParen)?; - let mut dimensions = vec![]; + let mut dimensions = Vec::new(); loop { if let Some((int, _)) = self.eat_int() { dimensions.push(int); @@ -89,7 +89,7 @@ impl ParserContext { let span = ident.span.clone(); (Type::Circuit(ident), span) } else if let Some(token) = self.eat(Token::LeftParen) { - let mut types = vec![]; + let mut types = Vec::new(); let end_span; loop { if let Some(end) = self.eat(Token::RightParen) { diff --git a/parser/src/test.rs b/parser/src/test.rs index ad123ca63d..8b71f584a6 100644 --- a/parser/src/test.rs +++ b/parser/src/test.rs @@ -43,8 +43,8 @@ pub fn find_tests>(path: T, out: &mut Vec<(String, String)>) { #[test] pub fn parser_pass_tests() { let mut pass = 0; - let mut fail = vec![]; - let mut tests = vec![]; + let mut fail = Vec::new(); + let mut tests = Vec::new(); let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); test_dir.push("../tests/pass/parse/"); find_tests(&test_dir, &mut tests); @@ -76,8 +76,8 @@ pub fn parser_pass_tests() { #[test] pub fn parser_fail_tests() { let mut pass = 0; - let mut fail = vec![]; - let mut tests = vec![]; + let mut fail = Vec::new(); + let mut tests = Vec::new(); let mut test_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); test_dir.push("../tests/fail/parse/"); find_tests(&test_dir, &mut tests); diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index 41f2a31634..76639f8365 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -106,7 +106,7 @@ impl Token { let mut i = 1; let mut in_escape = false; let mut start = 1usize; - let mut segments = vec![]; + let mut segments = Vec::new(); while i < input.len() { if !in_escape { if input[i] == b'"' { diff --git a/parser/src/tokenizer/mod.rs b/parser/src/tokenizer/mod.rs index 7cfe52175f..6e307c7001 100644 --- a/parser/src/tokenizer/mod.rs +++ b/parser/src/tokenizer/mod.rs @@ -34,7 +34,7 @@ use std::rc::Rc; pub(crate) fn tokenize(path: &str, source: &str) -> Result, TokenError> { let path = Rc::new(path.to_string()); let mut input = source.as_bytes(); - let mut tokens = vec![]; + let mut tokens = Vec::new(); let mut index = 0usize; let mut line_no = 1usize; let mut line_start = 0usize; From 539642c94362750e83beecdc60fff24602a08bc0 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 15:27:19 -0700 Subject: [PATCH 35/40] clippy vec_init_then_push allow --- parser/src/parser/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/parser/src/parser/mod.rs b/parser/src/parser/mod.rs index 0801bf4cf4..8816f95c0a 100644 --- a/parser/src/parser/mod.rs +++ b/parser/src/parser/mod.rs @@ -19,6 +19,7 @@ //! This module contains the [`parse()`] method which calls the underlying [`tokenize()`] //! method to create a new program ast. +#[allow(clippy::vec_init_then_push)] mod context; use context::*; From a66c1633c1a0b96677a762c5a70796b0a4f2749c Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 15:32:58 -0700 Subject: [PATCH 36/40] clippy vec_init_then_push allow in parser module --- parser/src/lib.rs | 2 ++ parser/src/parser/mod.rs | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/parser/src/lib.rs b/parser/src/lib.rs index de440802b4..2e32c5ab4f 100644 --- a/parser/src/lib.rs +++ b/parser/src/lib.rs @@ -19,6 +19,8 @@ //! This module contains the [`parse_ast()`] method which calls the underlying [`parse()`] //! method to create a new program ast. +#![allow(clippy::vec_init_then_push)] + #[macro_use] extern crate thiserror; diff --git a/parser/src/parser/mod.rs b/parser/src/parser/mod.rs index 8816f95c0a..0801bf4cf4 100644 --- a/parser/src/parser/mod.rs +++ b/parser/src/parser/mod.rs @@ -19,7 +19,6 @@ //! This module contains the [`parse()`] method which calls the underlying [`tokenize()`] //! method to create a new program ast. -#[allow(clippy::vec_init_then_push)] mod context; use context::*; From 93908c6e7770d94ccf3c9cbd832d7f017b062ee0 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 15:38:33 -0700 Subject: [PATCH 37/40] clippy upper case acroynm READMEERROR --- package/src/errors/root/readme.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/package/src/errors/root/readme.rs b/package/src/errors/root/readme.rs index 7e9203fdc6..c123ddd826 100644 --- a/package/src/errors/root/readme.rs +++ b/package/src/errors/root/readme.rs @@ -16,6 +16,7 @@ use std::io; +#[allow(clippy::upper_case_acronyms)] #[derive(Debug, Error)] pub enum READMEError { #[error("{}: {}", _0, _1)] From ef8517b8ce6f925208b23ec7df16425a43e475d9 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 15:51:46 -0700 Subject: [PATCH 38/40] allow clippy warns --- asg/src/lib.rs | 3 +++ compiler/src/function/input/input_keyword.rs | 1 + imports/src/lib.rs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/asg/src/lib.rs b/asg/src/lib.rs index 31ad3a485b..0c74b6f3cd 100644 --- a/asg/src/lib.rs +++ b/asg/src/lib.rs @@ -22,6 +22,9 @@ //! A new [`Asg`] type can be created from an [`Ast`]. //! Converting to an [`Asg`] provides greater type safety by canonicalizing and checking program types. +#![allow(clippy::from_over_into)] +#![allow(clippy::result_unit_err)] + #[macro_use] extern crate thiserror; diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index 63bd2767b4..9db1bcbd6c 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -27,6 +27,7 @@ pub const STATE_VARIABLE_NAME: &str = "state"; pub const STATE_LEAF_VARIABLE_NAME: &str = "state_leaf"; impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { + #[allow(clippy::vec_init_then_push)] pub fn allocate_input_keyword>( &mut self, cs: &mut CS, diff --git a/imports/src/lib.rs b/imports/src/lib.rs index 9a9feb531c..3cda1b33de 100644 --- a/imports/src/lib.rs +++ b/imports/src/lib.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . +#![allow(clippy::from_over_into)] + #[macro_use] extern crate thiserror; From 28bca20b97b565cbeea79615a66824f9d5278cb3 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 16:03:32 -0700 Subject: [PATCH 39/40] pray to the clippy gods (allow upper case acronyms in state module) --- compiler/src/lib.rs | 1 + state/src/lib.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index ec6814c431..6b36c3d356 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -19,6 +19,7 @@ //! The [`Compiler`] type compiles Leo programs into R1CS circuits. #![allow(clippy::module_inception)] +#![allow(clippy::upper_case_acronyms)] #[macro_use] extern crate thiserror; diff --git a/state/src/lib.rs b/state/src/lib.rs index 91b4f3b3e2..65bd11e5d5 100644 --- a/state/src/lib.rs +++ b/state/src/lib.rs @@ -15,6 +15,7 @@ // along with the Leo library. If not, see . #![allow(clippy::module_inception)] +#![allow(clippy::upper_case_acronyms)] #[macro_use] extern crate thiserror; From dcc2844a508a41ee4b027fb3c9a18acf8b76c3c2 Mon Sep 17 00:00:00 2001 From: collin Date: Thu, 25 Mar 2021 22:52:58 -0700 Subject: [PATCH 40/40] fix canonicalization test --- compiler/tests/canonicalization/compound_assignment.leo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tests/canonicalization/compound_assignment.leo b/compiler/tests/canonicalization/compound_assignment.leo index f17d8762ff..95c810a7d5 100644 --- a/compiler/tests/canonicalization/compound_assignment.leo +++ b/compiler/tests/canonicalization/compound_assignment.leo @@ -1,4 +1,4 @@ function main() { - let mut x = 10u32; + let x = 10u32; x += 20; } \ No newline at end of file