From 0cf7a247cc9d23ad70fb30787d55d056b5aa075f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:22:53 +0200 Subject: [PATCH 01/46] clippy: fix needless_return Signed-off-by: ljedrz --- compiler/src/expression/arithmetic/div.rs | 4 ++-- compiler/src/expression/arithmetic/mul.rs | 4 ++-- compiler/src/expression/function/core_circuit.rs | 2 +- compiler/src/value/address/address.rs | 2 +- compiler/src/value/group/targets/edwards_bls12.rs | 4 ++-- compiler/src/value/value.rs | 6 +++--- package/src/package.rs | 4 ++-- typed/src/types/type_.rs | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 274b1ff674..0a6cecc69c 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -46,10 +46,10 @@ pub fn enforce_div, CS: ConstraintSystem< enforce_div(cs, val_1, val_2, span) } (val_1, val_2) => { - return Err(ExpressionError::incompatible_types( + Err(ExpressionError::incompatible_types( format!("{} / {}", val_1, val_2,), span, - )); + )) } } } diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index d1f962ccfa..555563d21d 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -46,10 +46,10 @@ pub fn enforce_mul, CS: ConstraintSystem< enforce_mul(cs, val_1, val_2, span) } (val_1, val_2) => { - return Err(ExpressionError::incompatible_types( + Err(ExpressionError::incompatible_types( format!("{} * {}", val_1, val_2), span, - )); + )) } } } diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 6dbabbc5e7..1f18a9b0f6 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -72,6 +72,6 @@ impl> ConstrainedProgram { } } - return Ok(return_value); + Ok(return_value) } } diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index 98e1dd34e9..614e5adae4 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -153,7 +153,7 @@ impl AllocGadget for Address { impl EvaluateEqGadget for Address { fn evaluate_equal>(&self, mut cs: CS, other: &Self) -> Result { if self.is_constant() && other.is_constant() { - return Ok(Boolean::Constant(self.eq(other))); + Ok(Boolean::Constant(self.eq(other))) } else { let mut result = Boolean::constant(true); diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 263d8d57cd..1555ca6e99 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -143,13 +143,13 @@ impl EdwardsGroupType { pub fn edwards_affine_from_single(number: String, span: Span) -> Result { if number.eq("0") { - return Ok(EdwardsAffine::zero()); + Ok(EdwardsAffine::zero()) } else { let one = edwards_affine_one(); let number_value = Fp256::from_str(&number).map_err(|_| GroupError::n_group(number, span))?; let result: EdwardsAffine = one.mul(&number_value); - return Ok(result); + Ok(result) } } diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 48a5139580..daf251eefb 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -213,7 +213,7 @@ impl> ConstrainedValue { Ok((outer_scope, function.clone())) } ConstrainedValue::Import(import_scope, function) => function.extract_function(import_scope, span), - value => return Err(ExpressionError::undefined_function(value.to_string(), span)), + value => Err(ExpressionError::undefined_function(value.to_string(), span)), } } @@ -221,7 +221,7 @@ impl> ConstrainedValue { match self { ConstrainedValue::CircuitDefinition(circuit) => Ok(circuit), ConstrainedValue::Import(_import_scope, circuit) => circuit.extract_circuit(span), - value => return Err(ExpressionError::undefined_circuit(value.to_string(), span)), + value => Err(ExpressionError::undefined_circuit(value.to_string(), span)), } } @@ -413,7 +413,7 @@ impl> ConditionalEqGadget for Constrai } Ok(()) } - (_, _) => return Err(SynthesisError::Unsatisfiable), + (_, _) => Err(SynthesisError::Unsatisfiable), } } diff --git a/package/src/package.rs b/package/src/package.rs index d5b1b7609f..f8dd21bbcb 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -86,7 +86,7 @@ impl Package { tracing::error!("File(s) {:?} already exist", existing_files); } - return result; + result } /// Returns `true` if a package is initialized at the given path @@ -120,7 +120,7 @@ impl Package { } } - return true; + true } /// Creates a package at the given path diff --git a/typed/src/types/type_.rs b/typed/src/types/type_.rs index 6f017f7ed4..8754232526 100644 --- a/typed/src/types/type_.rs +++ b/typed/src/types/type_.rs @@ -111,7 +111,7 @@ fn expand_array_type(type_: &Type, dimensions: &Vec) -> (Type, Vec let mut expanded_dimensions = dimensions.clone(); expanded_dimensions.append(&mut nested_dimensions.clone()); - return expand_array_type(nested_type, &expanded_dimensions); + expand_array_type(nested_type, &expanded_dimensions) } else { // Array type is fully expanded (type_.clone(), dimensions.clone()) From 4f46dd2982bce516c6279abbf35967bc0aa5896d Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:34:06 +0200 Subject: [PATCH 02/46] clippy: allow module_inception Signed-off-by: ljedrz --- ast/src/access/mod.rs | 2 ++ ast/src/annotations/mod.rs | 2 ++ ast/src/functions/input/mod.rs | 2 ++ compiler/src/lib.rs | 2 ++ state/src/lib.rs | 2 ++ typed/src/input/mod.rs | 2 ++ typed/src/input/program_input/mod.rs | 2 ++ typed/src/input/program_state/mod.rs | 2 ++ typed/src/input/program_state/private_state/mod.rs | 2 ++ typed/src/input/program_state/public_state/mod.rs | 2 ++ 10 files changed, 20 insertions(+) diff --git a/ast/src/access/mod.rs b/ast/src/access/mod.rs index 8d3e86d7d2..d896bd2ebe 100644 --- a/ast/src/access/mod.rs +++ b/ast/src/access/mod.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::module_inception)] + pub mod access; pub use access::*; diff --git a/ast/src/annotations/mod.rs b/ast/src/annotations/mod.rs index 0303b71e48..8825f1954f 100644 --- a/ast/src/annotations/mod.rs +++ b/ast/src/annotations/mod.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::module_inception)] + pub mod annotations; pub use annotations::*; diff --git a/ast/src/functions/input/mod.rs b/ast/src/functions/input/mod.rs index 8e0a1776a4..90c793d89d 100644 --- a/ast/src/functions/input/mod.rs +++ b/ast/src/functions/input/mod.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::module_inception)] + pub mod function_input; pub use function_input::*; diff --git a/compiler/src/lib.rs b/compiler/src/lib.rs index a6a4f801ca..9e93ead53e 100644 --- a/compiler/src/lib.rs +++ b/compiler/src/lib.rs @@ -16,6 +16,8 @@ //! Module containing structs and types that make up a Leo program. +#![allow(clippy::module_inception)] + #[macro_use] extern crate thiserror; diff --git a/state/src/lib.rs b/state/src/lib.rs index 639457e0f3..d2badc4385 100644 --- a/state/src/lib.rs +++ b/state/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::module_inception)] + #[macro_use] extern crate thiserror; diff --git a/typed/src/input/mod.rs b/typed/src/input/mod.rs index 8dee75b92b..5036517f71 100644 --- a/typed/src/input/mod.rs +++ b/typed/src/input/mod.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::module_inception)] + #[macro_use] pub mod macros; pub use macros::*; diff --git a/typed/src/input/program_input/mod.rs b/typed/src/input/program_input/mod.rs index ee0af204ed..1959fad7b9 100644 --- a/typed/src/input/program_input/mod.rs +++ b/typed/src/input/program_input/mod.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::module_inception)] + pub mod main_input; pub use main_input::*; diff --git a/typed/src/input/program_state/mod.rs b/typed/src/input/program_state/mod.rs index a1f50fd915..7af5d1b318 100644 --- a/typed/src/input/program_state/mod.rs +++ b/typed/src/input/program_state/mod.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::module_inception)] + pub mod private_state; pub use private_state::*; diff --git a/typed/src/input/program_state/private_state/mod.rs b/typed/src/input/program_state/private_state/mod.rs index 39b3a4b8f3..f9cad1e98b 100644 --- a/typed/src/input/program_state/private_state/mod.rs +++ b/typed/src/input/program_state/private_state/mod.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::module_inception)] + pub mod private_state; pub use private_state::*; diff --git a/typed/src/input/program_state/public_state/mod.rs b/typed/src/input/program_state/public_state/mod.rs index 125d1ff5ac..4c03f2c37b 100644 --- a/typed/src/input/program_state/public_state/mod.rs +++ b/typed/src/input/program_state/public_state/mod.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::module_inception)] + pub mod public_state; pub use public_state::*; From b8e22e0c96e9b7c739042aa7a8221780b9769a12 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:34:52 +0200 Subject: [PATCH 03/46] clippy: fix write_with_newline Signed-off-by: ljedrz --- ast/src/statements/conditional_statement.rs | 6 +++--- typed/src/circuits/circuit.rs | 4 ++-- typed/src/statements/conditional_nested_or_end_statement.rs | 4 ++-- typed/src/statements/conditional_statement.rs | 4 ++-- typed/src/statements/statement.rs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/ast/src/statements/conditional_statement.rs b/ast/src/statements/conditional_statement.rs index e11cab8a1c..6cfd97d97e 100644 --- a/ast/src/statements/conditional_statement.rs +++ b/ast/src/statements/conditional_statement.rs @@ -39,11 +39,11 @@ pub struct ConditionalStatement<'ast> { impl<'ast> fmt::Display for ConditionalStatement<'ast> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "if ({}) {{\n", self.condition)?; - write!(f, "\t{:#?}\n", self.statements)?; + writeln!(f, "if ({}) {{", self.condition)?; + writeln!(f, "\t{:#?}", self.statements)?; self.next .as_ref() .map(|n_or_e| write!(f, "}} {}", n_or_e)) - .unwrap_or(write!(f, "}}")) + .unwrap_or_else(|| write!(f, "}}")) } } diff --git a/typed/src/circuits/circuit.rs b/typed/src/circuits/circuit.rs index ef29f140d1..a93463a4cf 100644 --- a/typed/src/circuits/circuit.rs +++ b/typed/src/circuits/circuit.rs @@ -41,9 +41,9 @@ impl<'ast> From> for Circuit { impl Circuit { fn format(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "circuit {} {{ \n", self.circuit_name)?; + writeln!(f, "circuit {} {{ ", self.circuit_name)?; for field in self.members.iter() { - write!(f, " {}\n", field)?; + writeln!(f, " {}", field)?; } write!(f, "}}") } diff --git a/typed/src/statements/conditional_nested_or_end_statement.rs b/typed/src/statements/conditional_nested_or_end_statement.rs index 151ec816ac..cad2aeb84e 100644 --- a/typed/src/statements/conditional_nested_or_end_statement.rs +++ b/typed/src/statements/conditional_nested_or_end_statement.rs @@ -47,9 +47,9 @@ impl fmt::Display for ConditionalNestedOrEndStatement { match *self { ConditionalNestedOrEndStatement::Nested(ref nested) => write!(f, "else {}", nested), ConditionalNestedOrEndStatement::End(ref statements) => { - write!(f, "else {{\n")?; + writeln!(f, "else {{")?; for statement in statements.iter() { - write!(f, "\t\t{}\n", statement)?; + writeln!(f, "\t\t{}", statement)?; } write!(f, "\t}}") } diff --git a/typed/src/statements/conditional_statement.rs b/typed/src/statements/conditional_statement.rs index 019e22f5ed..0923736fb2 100644 --- a/typed/src/statements/conditional_statement.rs +++ b/typed/src/statements/conditional_statement.rs @@ -46,9 +46,9 @@ impl<'ast> From> for ConditionalStatement { impl fmt::Display for ConditionalStatement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "if ({}) {{\n", self.condition)?; + writeln!(f, "if ({}) {{", self.condition)?; for statement in self.statements.iter() { - write!(f, "\t\t{}\n", statement)?; + writeln!(f, "\t\t{}", statement)?; } match self.next.clone() { Some(n_or_e) => write!(f, "\t}} {}", n_or_e), diff --git a/typed/src/statements/statement.rs b/typed/src/statements/statement.rs index b56defbc27..d91880bea6 100644 --- a/typed/src/statements/statement.rs +++ b/typed/src/statements/statement.rs @@ -204,9 +204,9 @@ impl fmt::Display for Statement { Statement::Assign(ref variable, ref statement, ref _span) => write!(f, "{} = {};", variable, statement), Statement::Conditional(ref statement, ref _span) => write!(f, "{}", statement), Statement::Iteration(ref var, ref start, ref stop, ref list, ref _span) => { - write!(f, "for {} in {}..{} {{\n", var, start, stop)?; + writeln!(f, "for {} in {}..{} {{", var, start, stop)?; for l in list { - write!(f, "\t\t{}\n", l)?; + writeln!(f, "\t\t{}", l)?; } write!(f, "\t}}") } From b4ae089d29f786f8a967824be55a8de3c16a31b1 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:35:18 +0200 Subject: [PATCH 04/46] clippy: fix double_must_use Signed-off-by: ljedrz --- gadgets/src/arithmetic/add.rs | 1 - gadgets/src/arithmetic/div.rs | 1 - gadgets/src/arithmetic/mul.rs | 1 - gadgets/src/arithmetic/neg.rs | 1 - gadgets/src/arithmetic/pow.rs | 1 - gadgets/src/arithmetic/sub.rs | 1 - gadgets/src/bits/rca.rs | 1 - 7 files changed, 7 deletions(-) diff --git a/gadgets/src/arithmetic/add.rs b/gadgets/src/arithmetic/add.rs index 28adc4d650..2702e4d5f5 100644 --- a/gadgets/src/arithmetic/add.rs +++ b/gadgets/src/arithmetic/add.rs @@ -30,7 +30,6 @@ where { type ErrorType; - #[must_use] fn add>(&self, cs: CS, other: &Self) -> Result; } diff --git a/gadgets/src/arithmetic/div.rs b/gadgets/src/arithmetic/div.rs index 505701c71e..18328f6e38 100644 --- a/gadgets/src/arithmetic/div.rs +++ b/gadgets/src/arithmetic/div.rs @@ -23,6 +23,5 @@ where { type ErrorType; - #[must_use] fn div>(&self, cs: CS, other: &Self) -> Result; } diff --git a/gadgets/src/arithmetic/mul.rs b/gadgets/src/arithmetic/mul.rs index 80c53d7392..0cb7068232 100644 --- a/gadgets/src/arithmetic/mul.rs +++ b/gadgets/src/arithmetic/mul.rs @@ -23,6 +23,5 @@ where { type ErrorType; - #[must_use] fn mul>(&self, cs: CS, other: &Self) -> Result; } diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index 4ac569ce96..1fd0575cfa 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -29,7 +29,6 @@ where { type ErrorType; - #[must_use] fn neg>(&self, cs: CS) -> Result; } diff --git a/gadgets/src/arithmetic/pow.rs b/gadgets/src/arithmetic/pow.rs index 58d56a451c..a6b5d6f572 100644 --- a/gadgets/src/arithmetic/pow.rs +++ b/gadgets/src/arithmetic/pow.rs @@ -23,6 +23,5 @@ where { type ErrorType; - #[must_use] fn pow>(&self, cs: CS, other: &Self) -> Result; } diff --git a/gadgets/src/arithmetic/sub.rs b/gadgets/src/arithmetic/sub.rs index 3709e0df4f..53174a26e2 100644 --- a/gadgets/src/arithmetic/sub.rs +++ b/gadgets/src/arithmetic/sub.rs @@ -23,6 +23,5 @@ where { type ErrorType; - #[must_use] fn sub>(&self, cs: CS, other: &Self) -> Result; } diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index 785b0962c2..d5df6124a2 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -27,7 +27,6 @@ pub trait RippleCarryAdder where Self: std::marker::Sized, { - #[must_use] fn add_bits>(&self, cs: CS, other: &Self) -> Result, SynthesisError>; } From c21b5ad2f30ced874749f561f3a9cbd87a843fbe Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:36:12 +0200 Subject: [PATCH 05/46] clippy: fix useless_format Signed-off-by: ljedrz --- compiler/src/errors/console.rs | 2 +- compiler/src/errors/expression.rs | 2 +- compiler/src/errors/import.rs | 2 +- compiler/src/errors/output_bytes.rs | 2 +- compiler/src/errors/statement.rs | 6 +++--- compiler/src/errors/value/address.rs | 2 +- compiler/src/errors/value/group.rs | 4 ++-- compiler/src/errors/value/integer.rs | 7 ++++--- compiler/src/errors/value/value.rs | 2 +- .../src/expression/conditional/conditional.rs | 2 +- compiler/src/expression/logical/and.rs | 2 +- compiler/src/expression/logical/or.rs | 2 +- compiler/src/expression/relational/eq.rs | 2 +- compiler/src/expression/relational/ge.rs | 2 +- compiler/src/expression/relational/gt.rs | 2 +- compiler/src/expression/relational/le.rs | 2 +- compiler/src/expression/relational/lt.rs | 2 +- .../src/statement/conditional/conditional.rs | 2 +- compiler/src/value/field/field_type.rs | 16 ++++++++-------- .../src/value/group/targets/edwards_bls12.rs | 12 ++++++------ compiler/src/value/integer/integer.rs | 12 ++++++------ compiler/src/value/value.rs | 6 +++--- core/src/errors/core_package.rs | 2 +- core/src/errors/core_package_list.rs | 2 +- gadgets/src/arithmetic/neg.rs | 2 +- gadgets/src/bits/adder.rs | 10 +++++----- package/src/root/gitignore.rs | 5 +---- typed/src/common/range_or_expression.rs | 4 ++-- 28 files changed, 58 insertions(+), 60 deletions(-) diff --git a/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index 95117d8243..d977c25103 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -50,7 +50,7 @@ impl ConsoleError { } pub fn assertion_depends_on_input(span: Span) -> Self { - let message = format!("console.assert() failed to evaluate. This error is caused by empty input file values"); + let message = "console.assert() failed to evaluate. This error is caused by empty input file values".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/expression.rs b/compiler/src/errors/expression.rs index 65b8c69bd5..605d6aa666 100644 --- a/compiler/src/errors/expression.rs +++ b/compiler/src/errors/expression.rs @@ -146,7 +146,7 @@ impl ExpressionError { } pub fn self_keyword(span: Span) -> Self { - let message = format!("cannot call keyword `Self` outside of a circuit function"); + let message = "cannot call keyword `Self` outside of a circuit function".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/import.rs b/compiler/src/errors/import.rs index 42c43e8420..956a329019 100644 --- a/compiler/src/errors/import.rs +++ b/compiler/src/errors/import.rs @@ -48,7 +48,7 @@ impl ImportError { } pub fn convert_os_string(span: Span) -> Self { - let message = format!("failed to convert file string name, maybe an illegal character?"); + let message = "failed to convert file string name, maybe an illegal character?".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/output_bytes.rs b/compiler/src/errors/output_bytes.rs index 37400bb236..97183fff6f 100644 --- a/compiler/src/errors/output_bytes.rs +++ b/compiler/src/errors/output_bytes.rs @@ -36,7 +36,7 @@ impl OutputBytesError { } pub fn not_enough_registers(span: Span) -> Self { - let message = format!("number of input registers must be greater than or equal to output registers"); + let message = "number of input registers must be greater than or equal to output registers".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/statement.rs b/compiler/src/errors/statement.rs index 2c4f483b97..b5f3002722 100644 --- a/compiler/src/errors/statement.rs +++ b/compiler/src/errors/statement.rs @@ -67,13 +67,13 @@ impl StatementError { } pub fn array_assign_index(span: Span) -> Self { - let message = format!("Cannot assign single index to array of values"); + let message = "Cannot assign single index to array of values".to_string(); Self::new_from_span(message, span) } pub fn array_assign_range(span: Span) -> Self { - let message = format!("Cannot assign range of array values to single value"); + let message = "Cannot assign range of array values to single value".to_string(); Self::new_from_span(message, span) } @@ -145,7 +145,7 @@ impl StatementError { } pub fn tuple_assign_index(span: Span) -> Self { - let message = format!("Cannot assign single index to tuple of values"); + let message = "Cannot assign single index to tuple of values".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/address.rs b/compiler/src/errors/value/address.rs index 29eeec73c2..ea8b2424e6 100644 --- a/compiler/src/errors/value/address.rs +++ b/compiler/src/errors/value/address.rs @@ -64,7 +64,7 @@ impl AddressError { } pub fn missing_address(span: Span) -> Self { - let message = format!("expected address input not found"); + let message = "expected address input not found".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/group.rs b/compiler/src/errors/value/group.rs index c8af1a7e18..6082c251c3 100644 --- a/compiler/src/errors/value/group.rs +++ b/compiler/src/errors/value/group.rs @@ -88,13 +88,13 @@ impl GroupError { } pub fn x_recover(span: Span) -> Self { - let message = format!("could not recover group element from x coordinate"); + let message = "could not recover group element from x coordinate".to_string(); Self::new_from_span(message, span) } pub fn y_recover(span: Span) -> Self { - let message = format!("could not recover group element from y coordinate"); + let message = "could not recover group element from y coordinate".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index 16d570c375..663d20fb86 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -68,7 +68,7 @@ impl IntegerError { } pub fn negate_operation(span: Span) -> Self { - let message = format!("integer negation can only be enforced on signed integers"); + let message = "integer negation can only be enforced on signed integers".to_string(); Self::new_from_span(message, span) } @@ -83,9 +83,10 @@ impl IntegerError { } pub fn invalid_index(span: Span) -> Self { - let message = format!( + let message = "index must be a constant value unsigned integer. allocated indices produce a circuit of unknown size" - ); + .to_string() + ; Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/value.rs b/compiler/src/errors/value/value.rs index 6893c53359..ee08a75293 100644 --- a/compiler/src/errors/value/value.rs +++ b/compiler/src/errors/value/value.rs @@ -63,7 +63,7 @@ impl ValueError { } pub fn implicit_group(span: Span) -> Self { - let message = format!("group coordinates should be in (x, y)group format"); + let message = "group coordinates should be in (x, y)group format".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index 28dde01676..530bbe628b 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -74,6 +74,6 @@ impl> ConstrainedProgram { }); ConstrainedValue::conditionally_select(unique_namespace, &conditional_value, &first_value, &second_value) - .map_err(|e| ExpressionError::cannot_enforce(format!("conditional select"), e, span)) + .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, span)) } } diff --git a/compiler/src/expression/logical/and.rs b/compiler/src/expression/logical/and.rs index 0f3a03004c..579600fbc5 100644 --- a/compiler/src/expression/logical/and.rs +++ b/compiler/src/expression/logical/and.rs @@ -35,7 +35,7 @@ pub fn enforce_and, CS: ConstraintSystem< if let (ConstrainedValue::Boolean(left_bool), ConstrainedValue::Boolean(right_bool)) = (left, right) { let name_unique = format!("{} {}:{}", name, span.line, span.start); let result = Boolean::and(cs.ns(|| name_unique), &left_bool, &right_bool) - .map_err(|e| BooleanError::cannot_enforce(format!("&&"), e, span))?; + .map_err(|e| BooleanError::cannot_enforce("&&".to_string(), e, span))?; return Ok(ConstrainedValue::Boolean(result)); } diff --git a/compiler/src/expression/logical/or.rs b/compiler/src/expression/logical/or.rs index 0492530ef4..ce425d47f9 100644 --- a/compiler/src/expression/logical/or.rs +++ b/compiler/src/expression/logical/or.rs @@ -35,7 +35,7 @@ pub fn enforce_or, CS: ConstraintSystem, CS: ConstraintSystem< } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("=="), span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/ge.rs b/compiler/src/expression/relational/ge.rs index fd9dc43e04..00212cd157 100644 --- a/compiler/src/expression/relational/ge.rs +++ b/compiler/src/expression/relational/ge.rs @@ -52,7 +52,7 @@ pub fn evaluate_ge, CS: ConstraintSystem< } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">="), span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">=".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/gt.rs b/compiler/src/expression/relational/gt.rs index 57228d39e2..ce733b49b7 100644 --- a/compiler/src/expression/relational/gt.rs +++ b/compiler/src/expression/relational/gt.rs @@ -52,7 +52,7 @@ pub fn evaluate_gt, CS: ConstraintSystem< } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!(">"), span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(">".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/le.rs b/compiler/src/expression/relational/le.rs index 5eca4c7656..6afb209367 100644 --- a/compiler/src/expression/relational/le.rs +++ b/compiler/src/expression/relational/le.rs @@ -52,7 +52,7 @@ pub fn evaluate_le, CS: ConstraintSystem< } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<="), span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<=".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/expression/relational/lt.rs b/compiler/src/expression/relational/lt.rs index 41b954117e..ef7a7c76f9 100644 --- a/compiler/src/expression/relational/lt.rs +++ b/compiler/src/expression/relational/lt.rs @@ -52,7 +52,7 @@ pub fn evaluate_lt, CS: ConstraintSystem< } }; - let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate(format!("<"), span))?; + let boolean = constraint_result.map_err(|_| ExpressionError::cannot_evaluate("<".to_string(), span))?; Ok(ConstrainedValue::Boolean(boolean)) } diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 4a0129fe48..260f7213b4 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -28,7 +28,7 @@ fn indicator_to_string(indicator: &Boolean) -> String { indicator .get_value() .map(|b| b.to_string()) - .unwrap_or(format!("[input]")) + .unwrap_or("[input]".to_string()) } impl> ConstrainedProgram { diff --git a/compiler/src/value/field/field_type.rs b/compiler/src/value/field/field_type.rs index a1f3baac1e..95e97145e5 100644 --- a/compiler/src/value/field/field_type.rs +++ b/compiler/src/value/field/field_type.rs @@ -79,7 +79,7 @@ impl FieldType { (FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => { let result = self_value .add(cs, other_value) - .map_err(|e| FieldError::binary_operation(format!("+"), e, span))?; + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?; Ok(FieldType::Allocated(result)) } @@ -88,7 +88,7 @@ impl FieldType { | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated( allocated_value .add_constant(cs, constant_value) - .map_err(|e| FieldError::binary_operation(format!("+"), e, span))?, + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?, )), } } @@ -102,7 +102,7 @@ impl FieldType { (FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => { let result = self_value .sub(cs, other_value) - .map_err(|e| FieldError::binary_operation(format!("-"), e, span))?; + .map_err(|e| FieldError::binary_operation("-".to_string(), e, span))?; Ok(FieldType::Allocated(result)) } @@ -111,7 +111,7 @@ impl FieldType { | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated( allocated_value .sub_constant(cs, constant_value) - .map_err(|e| FieldError::binary_operation(format!("+"), e, span))?, + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span))?, )), } } @@ -125,7 +125,7 @@ impl FieldType { (FieldType::Allocated(self_value), FieldType::Allocated(other_value)) => { let result = self_value .mul(cs, other_value) - .map_err(|e| FieldError::binary_operation(format!("*"), e, span))?; + .map_err(|e| FieldError::binary_operation("*".to_string(), e, span))?; Ok(FieldType::Allocated(result)) } @@ -134,7 +134,7 @@ impl FieldType { | (FieldType::Allocated(allocated_value), FieldType::Constant(constant_value)) => Ok(FieldType::Allocated( allocated_value .mul_by_constant(cs, constant_value) - .map_err(|e| FieldError::binary_operation(format!("*"), e, span))?, + .map_err(|e| FieldError::binary_operation("*".to_string(), e, span))?, )), } } @@ -144,14 +144,14 @@ impl FieldType { FieldType::Constant(constant) => { let constant_inverse = constant .inverse() - .ok_or(FieldError::no_inverse(constant.to_string(), span.clone()))?; + .ok_or_else(|| FieldError::no_inverse(constant.to_string(), span.clone()))?; FieldType::Constant(constant_inverse) } FieldType::Allocated(allocated) => { let allocated_inverse = allocated .inverse(&mut cs) - .map_err(|e| FieldError::binary_operation(format!("+"), e, span.clone()))?; + .map_err(|e| FieldError::binary_operation("+".to_string(), e, span.clone()))?; FieldType::Allocated(allocated_inverse) } diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 1555ca6e99..3bf59c5380 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -88,7 +88,7 @@ impl GroupType for EdwardsGroupType { cs, other_value, ) - .map_err(|e| GroupError::binary_operation(format!("+"), e, span))?; + .map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?; Ok(EdwardsGroupType::Allocated(result)) } @@ -98,7 +98,7 @@ impl GroupType for EdwardsGroupType { Ok(EdwardsGroupType::Allocated( allocated_value .add_constant(cs, constant_value) - .map_err(|e| GroupError::binary_operation(format!("+"), e, span))?, + .map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?, )) } } @@ -116,7 +116,7 @@ impl GroupType for EdwardsGroupType { cs, other_value, ) - .map_err(|e| GroupError::binary_operation(format!("-"), e, span))?; + .map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?; Ok(EdwardsGroupType::Allocated(result)) } @@ -126,7 +126,7 @@ impl GroupType for EdwardsGroupType { Ok(EdwardsGroupType::Allocated( allocated_value .sub_constant(cs, constant_value) - .map_err(|e| GroupError::binary_operation(format!("-"), e, span))?, + .map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?, )) } } @@ -294,10 +294,10 @@ impl EdwardsGroupType { let x_value = allocated.x.get_value(); let y_value = allocated.y.get_value(); - let x_allocated = FpGadget::alloc(cs.ns(|| format!("x")), || { + let x_allocated = FpGadget::alloc(cs.ns(|| "x"), || { x_value.ok_or(SynthesisError::AssignmentMissing) })?; - let y_allocated = FpGadget::alloc(cs.ns(|| format!("y")), || { + let y_allocated = FpGadget::alloc(cs.ns(|| "y"), || { y_value.ok_or(SynthesisError::AssignmentMissing) })?; diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index 40b1a6634b..c93fe097b2 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -157,7 +157,7 @@ impl Integer { let unsigned_integer = self; let value_option: Option = match_unsigned_integer!(unsigned_integer => unsigned_integer.get_value()); - let value = value_option.ok_or(IntegerError::invalid_index(span.clone()))?; + let value = value_option.ok_or_else(|| IntegerError::invalid_index(span.clone()))?; let value_usize = value .parse::() .map_err(|_| IntegerError::invalid_integer(value, span))?; @@ -395,7 +395,7 @@ impl Integer { let result = match_integers_span!((a, b), s => a.add(cs.ns(|| unique_namespace), &b)); - result.ok_or(IntegerError::binary_operation(format!("+"), span)) + result.ok_or_else(|| IntegerError::binary_operation("+".to_string(), span)) } pub fn sub>( @@ -412,7 +412,7 @@ impl Integer { let result = match_integers_span!((a, b), s => a.sub(cs.ns(|| unique_namespace), &b)); - result.ok_or(IntegerError::binary_operation(format!("-"), span)) + result.ok_or_else(|| IntegerError::binary_operation("-".to_string(), span)) } pub fn mul>( @@ -429,7 +429,7 @@ impl Integer { let result = match_integers_span!((a, b), s => a.mul(cs.ns(|| unique_namespace), &b)); - result.ok_or(IntegerError::binary_operation(format!("*"), span)) + result.ok_or_else(|| IntegerError::binary_operation("*".to_string(), span)) } pub fn div>( @@ -446,7 +446,7 @@ impl Integer { let result = match_integers_span!((a, b), s => a.div(cs.ns(|| unique_namespace), &b)); - result.ok_or(IntegerError::binary_operation(format!("÷"), span)) + result.ok_or_else(|| IntegerError::binary_operation("÷".to_string(), span)) } pub fn pow>( @@ -463,7 +463,7 @@ impl Integer { let result = match_integers_span!((a, b), s => a.pow(cs.ns(|| unique_namespace), &b)); - result.ok_or(IntegerError::binary_operation(format!("**"), span)) + result.ok_or_else(|| IntegerError::binary_operation("**".to_string(), span)) } } diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index daf251eefb..d51c1752dd 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -239,7 +239,7 @@ impl> ConstrainedValue { } ConstrainedValue::Boolean(boolean) => { let option = boolean.get_value(); - let name = option.map(|b| b.to_string()).unwrap_or(format!("[allocated]")); + let name = option.map(|b| b.to_string()).unwrap_or("[allocated]".to_string()); *boolean = allocate_bool(&mut cs, name, option, span)?; } @@ -256,7 +256,7 @@ impl> ConstrainedValue { ConstrainedValue::Integer(integer) => { let integer_type = integer.get_type(); let option = integer.get_value(); - let name = option.clone().unwrap_or(format!("[allocated]")); + let name = option.clone().unwrap_or("[allocated]".to_string()); *integer = Integer::allocate_type(&mut cs, integer_type, name, option, span)?; } @@ -328,7 +328,7 @@ impl> fmt::Display for ConstrainedValue write!(f, "{:?}", value), ConstrainedValue::Group(ref value) => write!(f, "{:?}", value), diff --git a/core/src/errors/core_package.rs b/core/src/errors/core_package.rs index 133b4aec65..30425d61d9 100644 --- a/core/src/errors/core_package.rs +++ b/core/src/errors/core_package.rs @@ -35,7 +35,7 @@ impl CorePackageError { } pub fn core_package_star(span: Span) -> Self { - let message = format!("Cannot import star from leo-core"); + let message = "Cannot import star from leo-core".to_string(); Self::new_from_span(message, span) } diff --git a/core/src/errors/core_package_list.rs b/core/src/errors/core_package_list.rs index b31ae0bdc7..4cf97980cf 100644 --- a/core/src/errors/core_package_list.rs +++ b/core/src/errors/core_package_list.rs @@ -48,7 +48,7 @@ impl CorePackageListError { } pub fn core_package_star(span: Span) -> Self { - let message = format!("Cannot import star from leo-core"); + let message = "Cannot import star from leo-core".to_string(); Self::new_from_span(message, span) } diff --git a/gadgets/src/arithmetic/neg.rs b/gadgets/src/arithmetic/neg.rs index 1fd0575cfa..ba199c8eda 100644 --- a/gadgets/src/arithmetic/neg.rs +++ b/gadgets/src/arithmetic/neg.rs @@ -43,7 +43,7 @@ impl Neg for Vec { let mut one = vec![Boolean::constant(true)]; one.append(&mut vec![Boolean::Constant(false); self.len() - 1]); - let mut bits = flipped.add_bits(cs.ns(|| format!("add one")), &one)?; + let mut bits = flipped.add_bits(cs.ns(|| "add one"), &one)?; let _carry = bits.pop(); // we already accounted for overflow above Ok(bits) diff --git a/gadgets/src/bits/adder.rs b/gadgets/src/bits/adder.rs index 91a2524f2e..f12549abb9 100644 --- a/gadgets/src/bits/adder.rs +++ b/gadgets/src/bits/adder.rs @@ -44,12 +44,12 @@ impl<'a, F: Field> FullAdder<'a, F> for Boolean { b: &'a Self, carry: &'a Self, ) -> Result<(Self, Self), SynthesisError> { - let a_x_b = Boolean::xor(cs.ns(|| format!("a XOR b")), a, b)?; - let sum = Boolean::xor(cs.ns(|| format!("adder sum")), &a_x_b, carry)?; + let a_x_b = Boolean::xor(cs.ns(|| "a XOR b"), a, b)?; + let sum = Boolean::xor(cs.ns(|| "adder sum"), &a_x_b, carry)?; - let c1 = Boolean::and(cs.ns(|| format!("a AND b")), a, b)?; - let c2 = Boolean::and(cs.ns(|| format!("carry AND (a XOR b)")), carry, &a_x_b)?; - let carry = Boolean::or(cs.ns(|| format!("c1 OR c2")), &c1, &c2)?; + let c1 = Boolean::and(cs.ns(|| "a AND b"), a, b)?; + let c2 = Boolean::and(cs.ns(|| "carry AND (a XOR b)"), carry, &a_x_b)?; + let carry = Boolean::or(cs.ns(|| "c1 OR c2"), &c1, &c2)?; Ok((sum, carry)) } diff --git a/package/src/root/gitignore.rs b/package/src/root/gitignore.rs index 306dd5220a..c8f03703d7 100644 --- a/package/src/root/gitignore.rs +++ b/package/src/root/gitignore.rs @@ -50,9 +50,6 @@ impl Gitignore { } fn template(&self) -> String { - format!( - r#"outputs/ -"#, - ) + "outputs/\n".to_string() } } diff --git a/typed/src/common/range_or_expression.rs b/typed/src/common/range_or_expression.rs index 3f3d8b998f..5c0998b431 100644 --- a/typed/src/common/range_or_expression.rs +++ b/typed/src/common/range_or_expression.rs @@ -45,8 +45,8 @@ impl fmt::Display for RangeOrExpression { RangeOrExpression::Range(ref from, ref to) => write!( f, "{}..{}", - from.as_ref().map(|e| format!("{}", e)).unwrap_or("".to_string()), - to.as_ref().map(|e| format!("{}", e)).unwrap_or("".to_string()) + from.as_ref().map(|e| e.to_string()).unwrap_or("".to_string()), + to.as_ref().map(|e| e.to_string()).unwrap_or("".to_string()) ), RangeOrExpression::Expression(ref e) => write!(f, "{}", e), } From 80bb3033fd2930d7fa47e92d81871b0125546fa5 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:37:10 +0200 Subject: [PATCH 06/46] clippy: fix single_char_pattern Signed-off-by: ljedrz --- compiler/src/console/format.rs | 4 ++-- compiler/src/expression/circuit/circuit.rs | 2 +- leo/commands/add.rs | 2 +- package/src/inputs/pairs.rs | 4 ++-- package/src/root/manifest.rs | 4 ++-- package/src/root/zip.rs | 26 +++++++++++----------- package/src/source/directory.rs | 2 +- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index a379e4cbb4..0d088a93df 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -43,10 +43,10 @@ impl> ConstrainedProgram { // Trim starting double quote `"` let mut string = formatted.string.as_str(); - string = string.trim_start_matches("\""); + string = string.trim_start_matches('\"'); // Trim everything after the ending double quote `"` - let parts: Vec<&str> = string.split("\"").collect(); + let parts: Vec<&str> = string.split('\"').collect(); string = parts[0]; // Insert the parameter for each container `{}` diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index 8963e7ca22..8e359b890c 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -40,7 +40,7 @@ impl> ConstrainedProgram { span: Span, ) -> Result, ExpressionError> { // Circuit definitions are located at the minimum file scope - let scopes: Vec<&str> = file_scope.split("_").collect(); + let scopes: Vec<&str> = file_scope.split('_').collect(); let mut program_identifier = new_scope(scopes[0].to_string(), identifier.to_string()); if identifier.is_self() { diff --git a/leo/commands/add.rs b/leo/commands/add.rs index f379ec2840..abf67dffd3 100644 --- a/leo/commands/add.rs +++ b/leo/commands/add.rs @@ -167,7 +167,7 @@ impl CLI for AddCommand { let mut file_path = path.clone(); file_path.push(file_name); - if file_name.ends_with("/") { + if file_name.ends_with('/') { create_dir_all(file_path)?; } else { if let Some(parent_directory) = path.parent() { diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index c00c8ea908..375bf8fdcc 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -56,7 +56,7 @@ impl TryFrom<&PathBuf> for InputPairs { .to_str() .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?; - if file_extension == INPUT_FILE_EXTENSION.trim_start_matches(".") { + if file_extension == INPUT_FILE_EXTENSION.trim_start_matches('.') { let input_file = InputFile::new(file_name).read_from(&file)?.0; if pairs.contains_key(file_name) { @@ -69,7 +69,7 @@ impl TryFrom<&PathBuf> for InputPairs { }; pairs.insert(file_name.to_owned(), pair); } - } else if file_extension == STATE_FILE_EXTENSION.trim_start_matches(".") { + } else if file_extension == STATE_FILE_EXTENSION.trim_start_matches('.') { let state_file = StateFile::new(file_name).read_from(&file)?.0; if pairs.contains_key(file_name) { diff --git a/package/src/root/manifest.rs b/package/src/root/manifest.rs index 485516c06d..de3976ded9 100644 --- a/package/src/root/manifest.rs +++ b/package/src/root/manifest.rs @@ -139,7 +139,7 @@ impl TryFrom<&PathBuf> for Manifest { // Determine if the old remote format is being used if line.starts_with("remote") { let remote = line - .split("=") // Split the line as 'remote' = '"{author}/{package_name}"' + .split('=') // Split the line as 'remote' = '"{author}/{package_name}"' .collect::>()[1]; // Fetch just '"{author}/{package_name}"' old_remote_format = Some(remote); @@ -182,7 +182,7 @@ impl TryFrom<&PathBuf> for Manifest { if !new_remote_format_exists { // Fetch the author from the old remote. let remote_author = old_remote - .split("/") // Split the old remote as '"{author}' and '{package_name}"' + .split('/') // Split the old remote as '"{author}' and '{package_name}"' .collect::>()[0] // Fetch just the '"{author}' .replace(&['\"', ' '][..], ""); // Remove the quotes from the author string diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index 7277fb3dd6..203f4eb022 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -150,23 +150,23 @@ impl ZipFile { /// Check if the file path should be included in the package zip file. fn is_included(path: &Path) -> bool { // excluded directories: `input`, `output`, `imports` - if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches("/")) - | path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches("/")) - | path.ends_with(IMPORTS_DIRECTORY_NAME.trim_end_matches("/")) + if path.ends_with(INPUTS_DIRECTORY_NAME.trim_end_matches('/')) + | path.ends_with(OUTPUTS_DIRECTORY_NAME.trim_end_matches('/')) + | path.ends_with(IMPORTS_DIRECTORY_NAME.trim_end_matches('/')) { return false; } // excluded extensions: `.in`, `.bytes`, `lpk`, `lvk`, `.proof`, `.sum`, `.zip`, `.bytes` if let Some(true) = path.extension().map(|ext| { - ext.eq(INPUT_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(ZIP_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(PROVING_KEY_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(VERIFICATION_KEY_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(PROOF_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(CHECKSUM_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(ZIP_FILE_EXTENSION.trim_start_matches(".")) - | ext.eq(CIRCUIT_FILE_EXTENSION.trim_start_matches(".")) + ext.eq(INPUT_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(ZIP_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(PROVING_KEY_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(VERIFICATION_KEY_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(PROOF_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(CHECKSUM_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(ZIP_FILE_EXTENSION.trim_start_matches('.')) + | ext.eq(CIRCUIT_FILE_EXTENSION.trim_start_matches('.')) }) { return false; } @@ -177,12 +177,12 @@ fn is_included(path: &Path) -> bool { } // Only allow additional files in the `src/` directory - if !path.starts_with(SOURCE_DIRECTORY_NAME.trim_end_matches("/")) { + if !path.starts_with(SOURCE_DIRECTORY_NAME.trim_end_matches('/')) { return false; } // Allow the `.leo` files in the `src/` directory path.extension() - .map(|ext| ext.eq(SOURCE_FILE_EXTENSION.trim_start_matches("."))) + .map(|ext| ext.eq(SOURCE_FILE_EXTENSION.trim_start_matches('.'))) .unwrap_or(false) } diff --git a/package/src/source/directory.rs b/package/src/source/directory.rs index 083a1bc935..1081ad3ee8 100644 --- a/package/src/source/directory.rs +++ b/package/src/source/directory.rs @@ -61,7 +61,7 @@ impl SourceDirectory { let file_extension = file_path .extension() .ok_or_else(|| SourceDirectoryError::GettingFileExtension(file_path.as_os_str().to_owned()))?; - if file_extension != SOURCE_FILE_EXTENSION.trim_start_matches(".") { + if file_extension != SOURCE_FILE_EXTENSION.trim_start_matches('.') { return Err(SourceDirectoryError::InvalidFileExtension( file_path.as_os_str().to_owned(), file_extension.to_owned(), From ffef5089f74ca9b288f98271b1f7c870140afd1e Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:38:29 +0200 Subject: [PATCH 07/46] clippy: fix new_without_default Signed-off-by: ljedrz --- compiler/src/import/parser/import_parser.rs | 7 ++----- compiler/src/program/program.rs | 12 +++++++++--- package/src/inputs/pairs.rs | 3 ++- package/src/root/gitignore.rs | 4 ++-- typed/src/input/input.rs | 10 ++++++++-- typed/src/input/macros.rs | 7 ++----- typed/src/input/program_input/main_input.rs | 4 ++-- typed/src/input/program_input/program_input.rs | 7 ++----- .../program_state/private_state/private_state.rs | 7 ++----- typed/src/input/program_state/program_state.rs | 7 ++----- .../input/program_state/public_state/public_state.rs | 4 ++-- 11 files changed, 35 insertions(+), 37 deletions(-) diff --git a/compiler/src/import/parser/import_parser.rs b/compiler/src/import/parser/import_parser.rs index c870f8670f..5bf3386498 100644 --- a/compiler/src/import/parser/import_parser.rs +++ b/compiler/src/import/parser/import_parser.rs @@ -21,7 +21,7 @@ use std::{collections::HashMap, env::current_dir}; /// Parses all relevant import files for a program. /// Stores compiled program structs. -#[derive(Clone)] +#[derive(Clone, Default)] pub struct ImportParser { imports: HashMap, core_packages: Vec, @@ -29,10 +29,7 @@ pub struct ImportParser { impl ImportParser { pub fn new() -> Self { - Self { - imports: HashMap::new(), - core_packages: vec![], - } + Self::default() } pub(crate) fn insert_import(&mut self, file_name: String, program: Program) { diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index cc9ca62f7b..24981cc59f 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -27,6 +27,14 @@ pub struct ConstrainedProgram> { pub identifiers: HashMap>, } +impl> Default for ConstrainedProgram { + fn default() -> Self { + Self { + identifiers: HashMap::new(), + } + } +} + pub fn new_scope(outer: String, inner: String) -> String { format!("{}_{}", outer, inner) } @@ -37,9 +45,7 @@ pub fn is_in_scope(current_scope: &String, desired_scope: &String) -> bool { impl> ConstrainedProgram { pub fn new() -> Self { - Self { - identifiers: HashMap::new(), - } + Self::default() } pub(crate) fn store(&mut self, name: String, value: ConstrainedValue) { diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index 375bf8fdcc..b2165fe5dd 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -21,6 +21,7 @@ use crate::{ use std::{collections::HashMap, convert::TryFrom, path::PathBuf}; +#[derive(Default)] pub struct InputPairs { /// Maps file names to input file pairs pub pairs: HashMap, @@ -33,7 +34,7 @@ pub struct InputPair { impl InputPairs { pub fn new() -> Self { - Self { pairs: HashMap::new() } + Self::default() } } diff --git a/package/src/root/gitignore.rs b/package/src/root/gitignore.rs index c8f03703d7..c7dddc9161 100644 --- a/package/src/root/gitignore.rs +++ b/package/src/root/gitignore.rs @@ -23,12 +23,12 @@ use std::{fs::File, io::Write, path::PathBuf}; pub static GITIGNORE_FILENAME: &str = ".gitignore"; -#[derive(Deserialize)] +#[derive(Deserialize, Default)] pub struct Gitignore; impl Gitignore { pub fn new() -> Self { - Self + Self::default() } pub fn exists_at(path: &PathBuf) -> bool { diff --git a/typed/src/input/input.rs b/typed/src/input/input.rs index 0ed2bdbf1c..823e8b6896 100644 --- a/typed/src/input/input.rs +++ b/typed/src/input/input.rs @@ -27,14 +27,20 @@ pub struct Input { program_state: ProgramState, } -impl Input { - pub fn new() -> Self { +impl Default for Input { + fn default() -> Self { Self { name: "default".to_owned(), program_input: ProgramInput::new(), program_state: ProgramState::new(), } } +} + +impl Input { + pub fn new() -> Self { + Self::default() + } /// Returns an empty version of this struct with `None` values. /// Called during constraint synthesis to provide private input variables. diff --git a/typed/src/input/macros.rs b/typed/src/input/macros.rs index 565236ad30..16276d4e1d 100644 --- a/typed/src/input/macros.rs +++ b/typed/src/input/macros.rs @@ -19,7 +19,7 @@ macro_rules! input_section_impl { ($($name: ident), *) => ($( /// An input section declared in an input file with `[$name]` - #[derive(Clone, PartialEq, Eq)] + #[derive(Clone, PartialEq, Eq, Default)] pub struct $name { is_present: bool, values: HashMap>, @@ -27,10 +27,7 @@ macro_rules! input_section_impl { impl $name { pub fn new() -> Self { - Self { - is_present: false, - values: HashMap::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_input/main_input.rs b/typed/src/input/program_input/main_input.rs index 61f7a3fc67..90c2b1a940 100644 --- a/typed/src/input/program_input/main_input.rs +++ b/typed/src/input/program_input/main_input.rs @@ -18,14 +18,14 @@ use crate::InputValue; use leo_input::{definitions::Definition, InputParserError}; use std::collections::HashMap; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct MainInput { input: HashMap>, } impl MainInput { pub fn new() -> Self { - Self { input: HashMap::new() } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_input/program_input.rs b/typed/src/input/program_input/program_input.rs index ba823d784c..94418ba949 100644 --- a/typed/src/input/program_input/program_input.rs +++ b/typed/src/input/program_input/program_input.rs @@ -20,7 +20,7 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramInput { pub main: MainInput, registers: Registers, @@ -28,10 +28,7 @@ pub struct ProgramInput { impl ProgramInput { pub fn new() -> Self { - Self { - main: MainInput::new(), - registers: Registers::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_state/private_state/private_state.rs b/typed/src/input/program_state/private_state/private_state.rs index 28ad9070ff..489a6ff74e 100644 --- a/typed/src/input/program_state/private_state/private_state.rs +++ b/typed/src/input/program_state/private_state/private_state.rs @@ -20,7 +20,7 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct PrivateState { record: Record, state_leaf: StateLeaf, @@ -28,10 +28,7 @@ pub struct PrivateState { impl PrivateState { pub fn new() -> Self { - Self { - record: Record::new(), - state_leaf: StateLeaf::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_state/program_state.rs b/typed/src/input/program_state/program_state.rs index 8e1fbf1309..35284c700e 100644 --- a/typed/src/input/program_state/program_state.rs +++ b/typed/src/input/program_state/program_state.rs @@ -20,7 +20,7 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct ProgramState { public: PublicState, private: PrivateState, @@ -28,10 +28,7 @@ pub struct ProgramState { impl ProgramState { pub fn new() -> Self { - Self { - public: PublicState::new(), - private: PrivateState::new(), - } + Self::default() } /// Returns an empty version of this struct with `None` values. diff --git a/typed/src/input/program_state/public_state/public_state.rs b/typed/src/input/program_state/public_state/public_state.rs index 403eb48c89..3730c4bea3 100644 --- a/typed/src/input/program_state/public_state/public_state.rs +++ b/typed/src/input/program_state/public_state/public_state.rs @@ -20,14 +20,14 @@ use leo_input::{ InputParserError, }; -#[derive(Clone, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq, Default)] pub struct PublicState { state: State, } impl PublicState { pub fn new() -> Self { - Self { state: State::new() } + Self::default() } /// Returns an empty version of this struct with `None` values. From 7c15eabd5e784961f48f04829f4d52da52a00eec Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:39:36 +0200 Subject: [PATCH 08/46] clippy: fix or_fun_call Signed-off-by: ljedrz --- compiler/src/import/store/import.rs | 2 +- compiler/src/import/store/symbol.rs | 2 +- compiler/src/statement/conditional/conditional.rs | 2 +- compiler/src/value/group/targets/edwards_bls12.rs | 4 ++-- compiler/src/value/integer/integer.rs | 2 +- compiler/src/value/value.rs | 6 +++--- core/src/types/core_package.rs | 2 +- core/src/types/value.rs | 2 +- package/src/inputs/pairs.rs | 4 ++-- typed/src/common/range_or_expression.rs | 4 ++-- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/src/import/store/import.rs b/compiler/src/import/store/import.rs index a9aec1f1c7..9188c566c8 100644 --- a/compiler/src/import/store/import.rs +++ b/compiler/src/import/store/import.rs @@ -45,7 +45,7 @@ impl> ConstrainedProgram { // Find imported program let program = imported_programs .get_import(&package) - .ok_or(ImportError::unknown_package(import.package.name.clone()))?; + .ok_or_else(|| ImportError::unknown_package(import.package.name.clone()))?; // Parse imported program self.store_definitions(program.clone(), imported_programs)?; diff --git a/compiler/src/import/store/symbol.rs b/compiler/src/import/store/symbol.rs index f640f05e0c..b98dc6be0f 100644 --- a/compiler/src/import/store/symbol.rs +++ b/compiler/src/import/store/symbol.rs @@ -80,7 +80,7 @@ impl> ConstrainedProgram { }; // take the alias if it is present - let id = symbol.alias.clone().unwrap_or(symbol.symbol.clone()); + let id = symbol.alias.clone().unwrap_or_else(|| symbol.symbol.clone()); let name = new_scope(scope, id.to_string()); // store imported circuit under imported name diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 260f7213b4..3a19f2737a 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -28,7 +28,7 @@ fn indicator_to_string(indicator: &Boolean) -> String { indicator .get_value() .map(|b| b.to_string()) - .unwrap_or("[input]".to_string()) + .unwrap_or_else(|| "[input]".to_string()) } impl> ConstrainedProgram { diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 3bf59c5380..5b29441c7f 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -201,7 +201,7 @@ impl EdwardsGroupType { let x = Fq::from_str(&x_string).map_err(|_| GroupError::x_invalid(x_string, x_span))?; match greatest { // Sign provided - Some(greatest) => EdwardsAffine::from_x_coordinate(x, greatest).ok_or(GroupError::x_recover(element_span)), + Some(greatest) => EdwardsAffine::from_x_coordinate(x, greatest).ok_or_else(|| GroupError::x_recover(element_span)), // Sign inferred None => { // Attempt to recover with a sign_low bit. @@ -230,7 +230,7 @@ impl EdwardsGroupType { match greatest { // Sign provided - Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or(GroupError::y_recover(element_span)), + Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or_else(|| GroupError::y_recover(element_span)), // Sign inferred None => { // Attempt to recover with a sign_low bit. diff --git a/compiler/src/value/integer/integer.rs b/compiler/src/value/integer/integer.rs index c93fe097b2..ef47e00cc5 100644 --- a/compiler/src/value/integer/integer.rs +++ b/compiler/src/value/integer/integer.rs @@ -378,7 +378,7 @@ impl Integer { let result = match_signed_integer!(a, s => a.neg(cs.ns(|| unique_namespace))); - result.ok_or(IntegerError::negate_operation(span)) + result.ok_or_else(|| IntegerError::negate_operation(span)) } pub fn add>( diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index d51c1752dd..3664c7fa8f 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -239,7 +239,7 @@ impl> ConstrainedValue { } ConstrainedValue::Boolean(boolean) => { let option = boolean.get_value(); - let name = option.map(|b| b.to_string()).unwrap_or("[allocated]".to_string()); + let name = option.map(|b| b.to_string()).unwrap_or_else(|| "[allocated]".to_string()); *boolean = allocate_bool(&mut cs, name, option, span)?; } @@ -256,7 +256,7 @@ impl> ConstrainedValue { ConstrainedValue::Integer(integer) => { let integer_type = integer.get_type(); let option = integer.get_value(); - let name = option.clone().unwrap_or("[allocated]".to_string()); + let name = option.clone().unwrap_or_else(|| "[allocated]".to_string()); *integer = Integer::allocate_type(&mut cs, integer_type, name, option, span)?; } @@ -328,7 +328,7 @@ impl> fmt::Display for ConstrainedValue write!(f, "{:?}", value), ConstrainedValue::Group(ref value) => write!(f, "{:?}", value), diff --git a/core/src/types/core_package.rs b/core/src/types/core_package.rs index 339a048cc9..bc7a01e477 100644 --- a/core/src/types/core_package.rs +++ b/core/src/types/core_package.rs @@ -71,7 +71,7 @@ impl CorePackage { let span = circuit.span.clone(); // take the alias if it is present - let id = circuit.alias.clone().unwrap_or(circuit.symbol.clone()); + let id = circuit.alias.clone().unwrap_or_else(|| circuit.symbol.clone()); let name = id.name.clone(); let circuit = if self.unstable { diff --git a/core/src/types/value.rs b/core/src/types/value.rs index 1a511e3ec0..e08d584769 100644 --- a/core/src/types/value.rs +++ b/core/src/types/value.rs @@ -71,7 +71,7 @@ impl fmt::Display for Value { } }; - let string = string_option.unwrap_or("[input]".to_owned()); + let string = string_option.unwrap_or_else(|| "[input]".to_owned()); write!(f, "{}", string) } diff --git a/package/src/inputs/pairs.rs b/package/src/inputs/pairs.rs index b2165fe5dd..e2076a6764 100644 --- a/package/src/inputs/pairs.rs +++ b/package/src/inputs/pairs.rs @@ -53,9 +53,9 @@ impl TryFrom<&PathBuf> for InputPairs { let file_name = file .file_stem() - .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))? + .ok_or_else(|| InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))? .to_str() - .ok_or(InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?; + .ok_or_else(|| InputsDirectoryError::GettingFileName(file.as_os_str().to_owned()))?; if file_extension == INPUT_FILE_EXTENSION.trim_start_matches('.') { let input_file = InputFile::new(file_name).read_from(&file)?.0; diff --git a/typed/src/common/range_or_expression.rs b/typed/src/common/range_or_expression.rs index 5c0998b431..97c13b350d 100644 --- a/typed/src/common/range_or_expression.rs +++ b/typed/src/common/range_or_expression.rs @@ -45,8 +45,8 @@ impl fmt::Display for RangeOrExpression { RangeOrExpression::Range(ref from, ref to) => write!( f, "{}..{}", - from.as_ref().map(|e| e.to_string()).unwrap_or("".to_string()), - to.as_ref().map(|e| e.to_string()).unwrap_or("".to_string()) + from.as_ref().map(|e| e.to_string()).unwrap_or_default(), + to.as_ref().map(|e| e.to_string()).unwrap_or_default() ), RangeOrExpression::Expression(ref e) => write!(f, "{}", e), } From a4891c6f00eba755899103ce29070dd06e578c02 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:39:58 +0200 Subject: [PATCH 09/46] clippy: fix len_zero Signed-off-by: ljedrz --- compiler/src/function/result/result.rs | 2 +- leo/cli.rs | 8 ++++---- package/src/package.rs | 2 +- package/src/root/zip.rs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 81fc947f04..3f4a7d9b5b 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -37,7 +37,7 @@ impl> ConstrainedProgram { span: Span, ) -> Result<(), StatementError> { // if there are no results, continue - if results.len() == 0 { + if results.is_empty() { return Ok(()); } diff --git a/leo/cli.rs b/leo/cli.rs index 5393d0cc66..aedf6257d9 100644 --- a/leo/cli.rs +++ b/leo/cli.rs @@ -35,7 +35,7 @@ pub trait CLI { .iter() .map(|a| { let mut args = Arg::with_name(a.0).help(a.1).required(a.3).index(a.4); - if a.2.len() > 0 { + if !a.2.is_empty() { args = args.possible_values(a.2); } args @@ -47,7 +47,7 @@ pub trait CLI { .collect::>>(); let options = &Self::OPTIONS .iter() - .map(|a| match a.2.len() > 0 { + .map(|a| match !a.2.is_empty() { true => Arg::from_usage(a.0) .conflicts_with_all(a.1) .possible_values(a.2) @@ -64,7 +64,7 @@ pub trait CLI { &s.2.iter() .map(|a| { let mut args = Arg::with_name(a.0).help(a.1).required(a.3).index(a.4); - if a.2.len() > 0 { + if !a.2.is_empty() { args = args.possible_values(a.2); } args @@ -78,7 +78,7 @@ pub trait CLI { ) .args( &s.4.iter() - .map(|a| match a.2.len() > 0 { + .map(|a| match !a.2.is_empty() { true => Arg::from_usage(a.0) .conflicts_with_all(a.1) .possible_values(a.2) diff --git a/package/src/package.rs b/package/src/package.rs index f8dd21bbcb..6cae3f1b20 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -82,7 +82,7 @@ impl Package { } } - if existing_files.len() > 0 { + if !existing_files.is_empty() { tracing::error!("File(s) {:?} already exist", existing_files); } diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index 203f4eb022..ba0bbc0210 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -108,7 +108,7 @@ impl ZipFile { f.read_to_end(&mut buffer)?; zip.write_all(&*buffer)?; buffer.clear(); - } else if name.as_os_str().len() != 0 { + } else if !name.as_os_str().is_empty() { // Only if not root Avoids path spec / warning // and mapname conversion failed error on unzip tracing::info!("Adding directory {:?} as {:?}", path, name); From a872db5ca63825dfb7df364784cb0591e379c729 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:40:18 +0200 Subject: [PATCH 10/46] clippy: fix useless_conversion Signed-off-by: ljedrz --- compiler/src/import/parser/parse_package.rs | 3 --- package/src/package.rs | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/compiler/src/import/parser/parse_package.rs b/compiler/src/import/parser/parse_package.rs index 3247cb5c29..960bd24d65 100644 --- a/compiler/src/import/parser/parse_package.rs +++ b/compiler/src/import/parser/parse_package.rs @@ -70,14 +70,12 @@ impl ImportParser { let entries = fs::read_dir(path) .map_err(|error| ImportError::directory_error(error, package_name.span.clone(), error_path.clone()))? - .into_iter() .collect::, std::io::Error>>() .map_err(|error| ImportError::directory_error(error, package_name.span.clone(), error_path.clone()))?; let matched_source_entry = entries.into_iter().find(|entry| { entry .file_name() - .to_os_string() .into_string() .unwrap() .trim_end_matches(SOURCE_FILE_EXTENSION) @@ -90,7 +88,6 @@ impl ImportParser { } else if imports_directory.exists() { let entries = fs::read_dir(imports_directory) .map_err(|error| ImportError::directory_error(error, package_name.span.clone(), error_path.clone()))? - .into_iter() .collect::, std::io::Error>>() .map_err(|error| ImportError::directory_error(error, package_name.span.clone(), error_path.clone()))?; diff --git a/package/src/package.rs b/package/src/package.rs index 6cae3f1b20..7cac214539 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -129,7 +129,7 @@ impl Package { { if !Self::can_initialize(package_name, is_lib, path) { return Err( - PackageError::FailedToInitialize(package_name.to_owned(), path.as_os_str().to_owned()).into(), + PackageError::FailedToInitialize(package_name.to_owned(), path.as_os_str().to_owned()), ); } } @@ -175,7 +175,7 @@ impl Package { { if !Self::is_initialized(package_name, is_lib, path) { return Err( - PackageError::FailedToInitialize(package_name.to_owned(), path.as_os_str().to_owned()).into(), + PackageError::FailedToInitialize(package_name.to_owned(), path.as_os_str().to_owned()), ); } } From 919c1dcada06d55fd63c84137cc76385aa558c95 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:43:20 +0200 Subject: [PATCH 11/46] clippy: fix single_match Signed-off-by: ljedrz --- ast/src/errors/parser.rs | 21 +++++++++------------ input/src/errors/parser.rs | 21 +++++++++------------ leo/commands/update.rs | 13 +++++-------- 3 files changed, 23 insertions(+), 32 deletions(-) diff --git a/ast/src/errors/parser.rs b/ast/src/errors/parser.rs index 8c8888535d..ca1b860528 100644 --- a/ast/src/errors/parser.rs +++ b/ast/src/errors/parser.rs @@ -39,20 +39,17 @@ pub enum ParserError { impl ParserError { pub fn set_path(&mut self, path: PathBuf) { - match self { - ParserError::SyntaxError(error) => { - let new_error: Error = match error { - SyntaxError::Error(error) => { - let new_error = error.clone(); - new_error.with_path(path.to_str().unwrap()) - } - }; + if let ParserError::SyntaxError(error) = self { + let new_error: Error = match error { + SyntaxError::Error(error) => { + let new_error = error.clone(); + new_error.with_path(path.to_str().unwrap()) + } + }; - tracing::error!("{}", new_error); + tracing::error!("{}", new_error); - *error = SyntaxError::Error(new_error); - } - _ => {} + *error = SyntaxError::Error(new_error); } } } diff --git a/input/src/errors/parser.rs b/input/src/errors/parser.rs index b062564471..6cdd999f2d 100644 --- a/input/src/errors/parser.rs +++ b/input/src/errors/parser.rs @@ -53,20 +53,17 @@ pub enum InputParserError { impl InputParserError { pub fn set_path(&mut self, path: PathBuf) { - match self { - InputParserError::SyntaxError(error) => { - let new_error: Error = match error { - InputSyntaxError::Error(error) => { - let new_error = error.clone(); - new_error.with_path(path.to_str().unwrap()) - } - }; + if let InputParserError::SyntaxError(error) = self { + let new_error: Error = match error { + InputSyntaxError::Error(error) => { + let new_error = error.clone(); + new_error.with_path(path.to_str().unwrap()) + } + }; - tracing::error!("{}", new_error); + tracing::error!("{}", new_error); - *error = InputSyntaxError::Error(new_error); - } - _ => {} + *error = InputSyntaxError::Error(new_error); } } diff --git a/leo/commands/update.rs b/leo/commands/update.rs index 2290e57e60..ba895e5053 100644 --- a/leo/commands/update.rs +++ b/leo/commands/update.rs @@ -52,14 +52,11 @@ impl CLI for UpdateCommand { ]; fn parse(arguments: &clap::ArgMatches) -> Result { - match arguments.subcommand() { - ("automatic", Some(arguments)) => { - // Run the `automatic` subcommand - let options = UpdateAutomatic::parse(arguments)?; - let _output = UpdateAutomatic::output(options)?; - return Ok(None); - } - _ => {} + if let ("automatic", Some(arguments)) = arguments.subcommand() { + // Run the `automatic` subcommand + let options = UpdateAutomatic::parse(arguments)?; + let _output = UpdateAutomatic::output(options)?; + return Ok(None); }; let show_all_versions = arguments.is_present("list"); From 266e6247e42a602dbafe8ffa859b75e3484017cd Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:49:38 +0200 Subject: [PATCH 12/46] clippy: fix assign_op_pattern Signed-off-by: ljedrz --- gadgets/src/signed_integer/arithmetic/add.rs | 4 ++-- gadgets/src/signed_integer/arithmetic/div.rs | 4 ++-- gadgets/src/signed_integer/arithmetic/mul.rs | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index 4f25997ffd..cc352a1bea 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -87,7 +87,7 @@ macro_rules! add_int_impl { all_constants = false; // Add the coeff * bit_gadget - lc = lc + (coeff, bit.get_variable()); + lc += (coeff, bit.get_variable()); } Boolean::Not(ref bit) => { all_constants = false; @@ -97,7 +97,7 @@ macro_rules! add_int_impl { } Boolean::Constant(bit) => { if bit { - lc = lc + (coeff, CS::one()); + lc += (coeff, CS::one()); } } } diff --git a/gadgets/src/signed_integer/arithmetic/div.rs b/gadgets/src/signed_integer/arithmetic/div.rs index 80cbddeba6..774eae8bc0 100644 --- a/gadgets/src/signed_integer/arithmetic/div.rs +++ b/gadgets/src/signed_integer/arithmetic/div.rs @@ -206,13 +206,13 @@ macro_rules! div_int_impl { &r )?; - index = index - 1; + index -= 1; let mut q_new = q.clone(); q_new.bits[index] = true_bit.clone(); q_new.value = Some(q_new.value.unwrap() + bit_value); - bit_value = (bit_value >> 1); + bit_value >>= 1; q = Self::conditionally_select( &mut cs.ns(|| format!("set_bit_or_same_{}", i)), diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index a5abcbf6cc..7bb3feaee9 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -146,7 +146,7 @@ macro_rules! mul_int_impl { all_constants = false; // Add the coeff * bit_gadget - lc = lc + (coeff, bit.get_variable()); + lc += (coeff, bit.get_variable()); } Boolean::Not(ref bit) => { all_constants = false; @@ -156,7 +156,7 @@ macro_rules! mul_int_impl { } Boolean::Constant(bit) => { if bit { - lc = lc + (coeff, CS::one()); + lc += (coeff, CS::one()); } } } From 98990721cfeaae4faad26b9870634e7f3c08f036 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:53:29 +0200 Subject: [PATCH 13/46] clippy: fix redundant_static_lifetimes Signed-off-by: ljedrz --- compiler/src/expression/circuit/access.rs | 2 +- typed/src/errors/error.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 7ad1eb5653..b7e270cfaa 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -29,7 +29,7 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; -static SELF_KEYWORD: &'static str = "self"; +static SELF_KEYWORD: &str = "self"; impl> ConstrainedProgram { pub fn enforce_circuit_access>( diff --git a/typed/src/errors/error.rs b/typed/src/errors/error.rs index 31b575b9af..7e8f8c6aaa 100644 --- a/typed/src/errors/error.rs +++ b/typed/src/errors/error.rs @@ -18,7 +18,7 @@ use crate::Span; use std::{fmt, path::PathBuf}; -pub const INDENT: &'static str = " "; +pub const INDENT: &str = " "; /// Formatted compiler error type /// --> file.leo 2:8 From 812d8ae915c7ed05ad26be0ca962ea07de5a1f6e Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:54:04 +0200 Subject: [PATCH 14/46] clippy: fix single_component_path_imports Signed-off-by: ljedrz --- typed/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/typed/src/lib.rs b/typed/src/lib.rs index 5a02f4f98f..12fb1699f5 100644 --- a/typed/src/lib.rs +++ b/typed/src/lib.rs @@ -58,8 +58,6 @@ pub use self::types::*; use leo_ast::LeoAst; -use serde_json; - #[derive(Debug, Eq, PartialEq)] pub struct LeoTypedAst { typed_ast: Program, From fae079057de3bad857ef07c836f1091abd6f8a21 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:59:04 +0200 Subject: [PATCH 15/46] clippy: fix derive_hash_xor_eq Signed-off-by: ljedrz --- typed/src/common/identifier.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/typed/src/common/identifier.rs b/typed/src/common/identifier.rs index c10474e62c..8577528363 100644 --- a/typed/src/common/identifier.rs +++ b/typed/src/common/identifier.rs @@ -32,14 +32,14 @@ use serde::{ Serialize, Serializer, }; -use std::{collections::BTreeMap, fmt}; +use std::{collections::BTreeMap, fmt, hash::{Hash, Hasher}}; /// An identifier in the constrained program. /// /// Attention - When adding or removing fields from this struct, /// please remember to update it's Serialize and Deserialize implementation /// to reflect the new struct instantiation. -#[derive(Clone, Hash)] +#[derive(Clone)] pub struct Identifier { pub name: String, pub span: Span, @@ -161,6 +161,12 @@ impl PartialEq for Identifier { impl Eq for Identifier {} +impl Hash for Identifier { + fn hash(&self, state: &mut H) { + self.name.hash(state); + } +} + impl Serialize for Identifier { fn serialize(&self, serializer: S) -> Result { // Converts an element that implements Serialize into a string. From 27c3d7b71b79be53b16c6200909b7b6abc628022 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 17:06:48 +0200 Subject: [PATCH 16/46] clippy: fix manual_swap Signed-off-by: ljedrz --- typed/src/errors/error.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/typed/src/errors/error.rs b/typed/src/errors/error.rs index 7e8f8c6aaa..67552ee2d6 100644 --- a/typed/src/errors/error.rs +++ b/typed/src/errors/error.rs @@ -95,9 +95,7 @@ impl Error { fn underline(mut start: usize, mut end: usize) -> String { if start > end { - let tmp = start; - start = end; - end = tmp; + std::mem::swap(&mut start, &mut end) } let mut underline = String::new(); From 93369aed339f9d7a6ac70890d416daf81a2be405 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 09:30:16 +0200 Subject: [PATCH 17/46] clippy: fix ptr_arg Signed-off-by: ljedrz --- compiler/src/import/parser/import_parser.rs | 2 +- compiler/src/program/program.rs | 6 +++--- leo/synthesizer/serialized_circuit.rs | 8 ++++---- typed/src/input/program_input/main_input.rs | 2 +- typed/src/types/type_.rs | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/compiler/src/import/parser/import_parser.rs b/compiler/src/import/parser/import_parser.rs index 5bf3386498..8ab7f0f3d8 100644 --- a/compiler/src/import/parser/import_parser.rs +++ b/compiler/src/import/parser/import_parser.rs @@ -41,7 +41,7 @@ impl ImportParser { let _res = self.core_packages.push(package.clone()); } - pub fn get_import(&self, file_name: &String) -> Option<&Program> { + pub fn get_import(&self, file_name: &str) -> Option<&Program> { self.imports.get(file_name) } diff --git a/compiler/src/program/program.rs b/compiler/src/program/program.rs index 24981cc59f..8e87702ab8 100644 --- a/compiler/src/program/program.rs +++ b/compiler/src/program/program.rs @@ -39,7 +39,7 @@ pub fn new_scope(outer: String, inner: String) -> String { format!("{}_{}", outer, inner) } -pub fn is_in_scope(current_scope: &String, desired_scope: &String) -> bool { +pub fn is_in_scope(current_scope: &str, desired_scope: &str) -> bool { current_scope.ends_with(desired_scope) } @@ -52,11 +52,11 @@ impl> ConstrainedProgram { self.identifiers.insert(name, value); } - pub(crate) fn get(&self, name: &String) -> Option<&ConstrainedValue> { + pub(crate) fn get(&self, name: &str) -> Option<&ConstrainedValue> { self.identifiers.get(name) } - pub(crate) fn get_mut(&mut self, name: &String) -> Option<&mut ConstrainedValue> { + pub(crate) fn get_mut(&mut self, name: &str) -> Option<&mut ConstrainedValue> { self.identifiers.get_mut(name) } } diff --git a/leo/synthesizer/serialized_circuit.rs b/leo/synthesizer/serialized_circuit.rs index ae1293d191..96dd62849e 100644 --- a/leo/synthesizer/serialized_circuit.rs +++ b/leo/synthesizer/serialized_circuit.rs @@ -57,7 +57,7 @@ impl From> for SerializedCircuit { let num_constraints = synthesizer.num_constraints(); // Serialize assignments - fn get_serialized_assignments(assignments: &Vec) -> Vec { + fn get_serialized_assignments(assignments: &[E::Fr]) -> Vec { let mut serialized = vec![]; for assignment in assignments { @@ -74,7 +74,7 @@ impl From> for SerializedCircuit { // Serialize constraints fn get_serialized_constraints( - constraints: &Vec<(E::Fr, Index)>, + constraints: &[(E::Fr, Index)], ) -> Vec<(SerializedField, SerializedIndex)> { let mut serialized = vec![]; @@ -128,7 +128,7 @@ impl TryFrom for CircuitSynthesizer { fn try_from(serialized: SerializedCircuit) -> Result, Self::Error> { // Deserialize assignments fn get_deserialized_assignments( - assignments: &Vec, + assignments: &[SerializedField], ) -> Result::Fr>, FieldError> { let mut deserialized = vec![]; @@ -146,7 +146,7 @@ impl TryFrom for CircuitSynthesizer { // Deserialize constraints fn get_deserialized_constraints( - constraints: &Vec<(SerializedField, SerializedIndex)>, + constraints: &[(SerializedField, SerializedIndex)], ) -> Result::Fr, Index)>, FieldError> { let mut deserialized = vec![]; diff --git a/typed/src/input/program_input/main_input.rs b/typed/src/input/program_input/main_input.rs index 90c2b1a940..6071305eec 100644 --- a/typed/src/input/program_input/main_input.rs +++ b/typed/src/input/program_input/main_input.rs @@ -61,7 +61,7 @@ impl MainInput { } /// Returns an `Option` of the main function input at `name` - pub fn get(&self, name: &String) -> Option> { + pub fn get(&self, name: &str) -> Option> { self.input.get(name).map(|input| input.clone()) } } diff --git a/typed/src/types/type_.rs b/typed/src/types/type_.rs index 8754232526..42b4eda439 100644 --- a/typed/src/types/type_.rs +++ b/typed/src/types/type_.rs @@ -78,7 +78,7 @@ impl Type { type_1_expanded.eq(&type_2_expanded) && dimensions_1_expanded.eq(&dimensions_2_expanded) } - pub fn outer_dimension(&self, dimensions: &Vec) -> Self { + pub fn outer_dimension(&self, dimensions: &[usize]) -> Self { let type_ = self.clone(); if dimensions.len() > 1 { @@ -91,7 +91,7 @@ impl Type { type_ } - pub fn inner_dimension(&self, dimensions: &Vec) -> Self { + pub fn inner_dimension(&self, dimensions: &[usize]) -> Self { let type_ = self.clone(); if dimensions.len() > 1 { @@ -105,16 +105,16 @@ impl Type { } } -fn expand_array_type(type_: &Type, dimensions: &Vec) -> (Type, Vec) { +fn expand_array_type(type_: &Type, dimensions: &[usize]) -> (Type, Vec) { if let Type::Array(nested_type, nested_dimensions) = type_ { // Expand nested array type - let mut expanded_dimensions = dimensions.clone(); + let mut expanded_dimensions = dimensions.to_vec(); expanded_dimensions.append(&mut nested_dimensions.clone()); expand_array_type(nested_type, &expanded_dimensions) } else { // Array type is fully expanded - (type_.clone(), dimensions.clone()) + (type_.clone(), dimensions.to_vec()) } } From 1fc9b902ddd546d2a5452f84c35eed01df33734b Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 09:33:31 +0200 Subject: [PATCH 18/46] clippy: fix redundant_clone & clone_on_copy Signed-off-by: ljedrz --- compiler/src/console/assert.rs | 2 +- compiler/src/console/format.rs | 2 +- compiler/src/expression/array/access.rs | 2 +- compiler/src/expression/array/array.rs | 4 +- compiler/src/expression/array/index.rs | 6 +-- compiler/src/expression/binary/binary.rs | 4 +- compiler/src/expression/circuit/access.rs | 8 ++-- compiler/src/expression/circuit/circuit.rs | 4 +- .../src/expression/circuit/static_access.rs | 10 ++-- .../src/expression/conditional/conditional.rs | 4 +- compiler/src/expression/expression.rs | 48 +++++++++---------- compiler/src/expression/function/function.rs | 4 +- .../src/expression/identifier/identifier.rs | 4 +- compiler/src/expression/tuple/access.rs | 6 +-- compiler/src/function/function.rs | 2 +- compiler/src/import/parser/parse_symbol.rs | 7 ++- compiler/src/import/store/import.rs | 2 +- compiler/src/import/store/symbol.rs | 4 +- compiler/src/statement/assign/array.rs | 6 +-- compiler/src/statement/assign/assign.rs | 2 +- .../src/statement/assign/circuit_variable.rs | 2 +- compiler/src/statement/branch/branch.rs | 2 +- .../src/statement/definition/definition.rs | 8 ++-- compiler/src/statement/return_/return_.rs | 4 +- .../src/value/group/targets/edwards_bls12.rs | 4 +- compiler/src/value/value.rs | 8 ++-- core/src/packages/unstable/blake2s.rs | 2 +- gadgets/src/bits/sign_extend.rs | 2 +- leo/commands/build.rs | 4 +- leo/commands/deploy.rs | 2 +- leo/commands/lint.rs | 2 +- leo/commands/setup.rs | 2 +- leo/commands/test.rs | 8 ++-- leo/config.rs | 2 +- leo/synthesizer/serialized_index.rs | 4 +- 35 files changed, 93 insertions(+), 94 deletions(-) diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index e105ea878a..00d69332a5 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -53,7 +53,7 @@ impl> ConstrainedProgram { // Unwrap assertion value and handle errors let result_option = match assert_expression { ConstrainedValue::Boolean(boolean) => boolean.get_value(), - _ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span.clone())), + _ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span)), }; let result_bool = result_option.ok_or(ConsoleError::assertion_depends_on_input(span.clone()))?; diff --git a/compiler/src/console/format.rs b/compiler/src/console/format.rs index 0d088a93df..576dad5bcd 100644 --- a/compiler/src/console/format.rs +++ b/compiler/src/console/format.rs @@ -37,7 +37,7 @@ impl> ConstrainedProgram { return Err(ConsoleError::length( formatted.containers.len(), formatted.parameters.len(), - formatted.span.clone(), + formatted.span, )); } diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index bf2287f165..9dd5dc72c0 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -57,7 +57,7 @@ impl> ConstrainedProgram { }; let to_resolved = match to { Some(to_index) => { - self.enforce_index(cs, file_scope.clone(), function_scope.clone(), to_index, span.clone())? + self.enforce_index(cs, file_scope, function_scope, to_index, span)? } None => array.len(), // Array slice ends at array length }; diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 8c06345902..22a15003dd 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -47,12 +47,12 @@ impl> ConstrainedProgram { match type_ { Type::Array(ref type_, ref dimensions) => { let number = match dimensions.first() { - Some(number) => number.clone(), + Some(number) => *number, None => return Err(ExpressionError::unexpected_array(type_.to_string(), span)), }; expected_dimensions.push(number); - expected_type = Some(type_.outer_dimension(dimensions).clone()); + expected_type = Some(type_.outer_dimension(dimensions)); } ref type_ => { return Err(ExpressionError::unexpected_array(type_.to_string(), span)); diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index 4f7a638cbe..8aca8cb9b9 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -36,13 +36,13 @@ impl> ConstrainedProgram { let expected_type = Some(Type::IntegerType(IntegerType::U32)); match self.enforce_operand( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, index, span.clone(), )? { - ConstrainedValue::Integer(number) => Ok(number.to_usize(span.clone())?), + ConstrainedValue::Integer(number) => Ok(number.to_usize(span)?), value => Err(ExpressionError::invalid_index(value.to_string(), span)), } } diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index b3109a3d94..bc76fd3956 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -45,8 +45,8 @@ impl> ConstrainedProgram { )?; let mut resolved_right = self.enforce_operand( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type.clone(), right, span.clone(), diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index b7e270cfaa..62388a3f51 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -45,11 +45,11 @@ impl> ConstrainedProgram { // access a circuit member using the `self` keyword if let Expression::Identifier(ref identifier) = *circuit_identifier { if identifier.is_self() { - let self_file_scope = new_scope(file_scope.clone(), identifier.name.to_string()); + let self_file_scope = new_scope(file_scope, identifier.name.to_string()); let self_function_scope = new_scope(self_file_scope.clone(), identifier.name.to_string()); let member_value = - self.evaluate_identifier(self_file_scope, self_function_scope, None, circuit_member.clone())?; + self.evaluate_identifier(self_file_scope, self_function_scope, None, circuit_member)?; return Ok(member_value); } @@ -58,9 +58,9 @@ impl> ConstrainedProgram { let (circuit_name, members) = match self.enforce_operand( cs, file_scope.clone(), - function_scope.clone(), + function_scope, expected_type, - *circuit_identifier.clone(), + *circuit_identifier, span.clone(), )? { ConstrainedValue::CircuitExpression(name, members) => (name, members), diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index 8e359b890c..a8698a736b 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -55,7 +55,7 @@ impl> ConstrainedProgram { let circuit_identifier = circuit.circuit_name.clone(); let mut resolved_members = vec![]; - for member in circuit.members.clone().into_iter() { + for member in circuit.members.into_iter() { match member { CircuitMember::CircuitVariable(is_mutable, identifier, type_) => { let matched_variable = members @@ -98,7 +98,7 @@ impl> ConstrainedProgram { } Ok(ConstrainedValue::CircuitExpression( - circuit_identifier.clone(), + circuit_identifier, resolved_members, )) } diff --git a/compiler/src/expression/circuit/static_access.rs b/compiler/src/expression/circuit/static_access.rs index 9fee2254e6..e9928c9764 100644 --- a/compiler/src/expression/circuit/static_access.rs +++ b/compiler/src/expression/circuit/static_access.rs @@ -36,23 +36,23 @@ impl> ConstrainedProgram { span: Span, ) -> Result, ExpressionError> { // Get defined circuit - let circuit = match *circuit_identifier.clone() { + let circuit = match *circuit_identifier { Expression::Identifier(identifier) => { // Use the "Self" keyword to access a static circuit function if identifier.is_self() { let circuit = self .get(&file_scope) - .ok_or(ExpressionError::self_keyword(identifier.span.clone()))?; + .ok_or(ExpressionError::self_keyword(identifier.span))?; circuit.to_owned() } else { - self.evaluate_identifier(file_scope.clone(), function_scope.clone(), expected_type, identifier)? + self.evaluate_identifier(file_scope, function_scope, expected_type, identifier)? } } expression => self.enforce_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, expression, )?, diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index 530bbe628b..18900d3a50 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -59,8 +59,8 @@ impl> ConstrainedProgram { let second_value = self.enforce_operand( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, second, span.clone(), diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 3304c2725d..3692968bc3 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -70,8 +70,8 @@ impl> ConstrainedProgram { Expression::Add(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -83,8 +83,8 @@ impl> ConstrainedProgram { Expression::Sub(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -96,8 +96,8 @@ impl> ConstrainedProgram { Expression::Mul(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -109,8 +109,8 @@ impl> ConstrainedProgram { Expression::Div(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -122,8 +122,8 @@ impl> ConstrainedProgram { Expression::Pow(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -141,8 +141,8 @@ impl> ConstrainedProgram { Expression::Or(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -154,8 +154,8 @@ impl> ConstrainedProgram { Expression::And(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *left, *right, @@ -167,8 +167,8 @@ impl> ConstrainedProgram { Expression::Eq(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, None, *left, *right, @@ -180,8 +180,8 @@ impl> ConstrainedProgram { Expression::Ge(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, None, *left, *right, @@ -193,8 +193,8 @@ impl> ConstrainedProgram { Expression::Gt(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, None, *left, *right, @@ -206,8 +206,8 @@ impl> ConstrainedProgram { Expression::Le(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, None, *left, *right, @@ -219,8 +219,8 @@ impl> ConstrainedProgram { Expression::Lt(left, right, span) => { let (resolved_left, resolved_right) = self.enforce_binary_expression( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, None, *left, *right, diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index 458f552e0b..ad189704d2 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -35,7 +35,7 @@ impl> ConstrainedProgram { arguments: Vec, span: Span, ) -> Result, ExpressionError> { - let (declared_circuit_reference, function_value) = match *function.clone() { + let (declared_circuit_reference, function_value) = match *function { Expression::CircuitMemberAccess(circuit_identifier, circuit_member, span) => { // Call a circuit function that can mutate self. @@ -62,7 +62,7 @@ impl> ConstrainedProgram { ), }; - let (outer_scope, function_call) = function_value.extract_function(file_scope.clone(), span.clone())?; + let (outer_scope, function_call) = function_value.extract_function(file_scope, span.clone())?; let name_unique = format!( "function call {} {}:{}", diff --git a/compiler/src/expression/identifier/identifier.rs b/compiler/src/expression/identifier/identifier.rs index c8b1188794..8022bb569a 100644 --- a/compiler/src/expression/identifier/identifier.rs +++ b/compiler/src/expression/identifier/identifier.rs @@ -37,7 +37,7 @@ impl> ConstrainedProgram { unresolved_identifier: Identifier, ) -> Result, ExpressionError> { // Evaluate the identifier name in the current function scope - let variable_name = new_scope(function_scope.clone(), unresolved_identifier.to_string()); + let variable_name = new_scope(function_scope, unresolved_identifier.to_string()); let identifier_name = new_scope(file_scope, unresolved_identifier.to_string()); let mut result_value = if let Some(value) = self.get(&variable_name) { @@ -58,7 +58,7 @@ impl> ConstrainedProgram { return Err(ExpressionError::undefined_identifier(unresolved_identifier)); }; - result_value.resolve_type(expected_type, unresolved_identifier.span.clone())?; + result_value.resolve_type(expected_type, unresolved_identifier.span)?; Ok(result_value) } diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 5eab26013b..41e832282b 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -37,14 +37,14 @@ impl> ConstrainedProgram { ) -> Result, ExpressionError> { let tuple = match self.enforce_operand( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, expected_type, *tuple, span.clone(), )? { ConstrainedValue::Tuple(tuple) => tuple, - value => return Err(ExpressionError::undefined_array(value.to_string(), span.clone())), + value => return Err(ExpressionError::undefined_array(value.to_string(), span)), }; if index > tuple.len() - 1 { diff --git a/compiler/src/function/function.rs b/compiler/src/function/function.rs index 80b58f9bbb..aa1b67c42c 100644 --- a/compiler/src/function/function.rs +++ b/compiler/src/function/function.rs @@ -55,7 +55,7 @@ impl> ConstrainedProgram { check_arguments_length(function.input.len(), input.len(), function.span.clone())?; // Store input values as new variables in resolved program - for (input_model, input_expression) in function.input.clone().iter().zip(input.into_iter()) { + for (input_model, input_expression) in function.input.iter().zip(input.into_iter()) { let (name, value) = match input_model { InputVariable::InputKeyword(identifier) => { let input_value = self.enforce_function_input( diff --git a/compiler/src/import/parser/parse_symbol.rs b/compiler/src/import/parser/parse_symbol.rs index 0d8f869b4f..cc68184dde 100644 --- a/compiler/src/import/parser/parse_symbol.rs +++ b/compiler/src/import/parser/parse_symbol.rs @@ -30,11 +30,10 @@ fn parse_import_file(entry: &DirEntry, span: &Span) -> Result> ConstrainedProgram { .find(|package| import.package.eq(package)); if let Some(package) = core_dependency { - self.store_core_package(scope.clone(), package.clone())?; + self.store_core_package(scope, package.clone())?; return Ok(()); } diff --git a/compiler/src/import/store/symbol.rs b/compiler/src/import/store/symbol.rs index b98dc6be0f..bde98a52da 100644 --- a/compiler/src/import/store/symbol.rs +++ b/compiler/src/import/store/symbol.rs @@ -59,7 +59,7 @@ impl> ConstrainedProgram { let value = match matched_circuit { Some((_circuit_name, circuit)) => ConstrainedValue::Import( - program_name.clone(), + program_name, Box::new(ConstrainedValue::CircuitDefinition(circuit.clone())), ), None => { @@ -71,7 +71,7 @@ impl> ConstrainedProgram { match matched_function { Some((_function_name, function)) => ConstrainedValue::Import( - program_name.clone(), + program_name, Box::new(ConstrainedValue::Function(None, function.clone())), ), None => return Err(ImportError::unknown_symbol(symbol.to_owned(), program_name)), diff --git a/compiler/src/statement/assign/array.rs b/compiler/src/statement/assign/array.rs index 0e5e3f0542..2157840203 100644 --- a/compiler/src/statement/assign/array.rs +++ b/compiler/src/statement/assign/array.rs @@ -44,7 +44,7 @@ impl> ConstrainedProgram { // Resolve index so we know if we are assigning to a single value or a range of values match range_or_expression { RangeOrExpression::Expression(index) => { - let index = self.enforce_index(cs, file_scope.clone(), function_scope.clone(), index, span.clone())?; + let index = self.enforce_index(cs, file_scope, function_scope, index, span.clone())?; // Modify the single value of the array in place match self.get_mutable_assignee(name, span.clone())? { @@ -77,8 +77,8 @@ impl> ConstrainedProgram { let to_index_option = match to { Some(integer) => Some(self.enforce_index( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, integer, span.clone(), )?), diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index dcd7da37bb..2915136b88 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -57,7 +57,7 @@ impl> ConstrainedProgram { match assignee { Assignee::Identifier(_identifier) => { let condition = indicator.unwrap_or(Boolean::Constant(true)); - let old_value = self.get_mutable_assignee(variable_name.clone(), span.clone())?; + let old_value = self.get_mutable_assignee(variable_name, span.clone())?; new_value.resolve_type(Some(old_value.to_type(span.clone())?), span.clone())?; diff --git a/compiler/src/statement/assign/circuit_variable.rs b/compiler/src/statement/assign/circuit_variable.rs index 53e3dde9f2..2d80f71165 100644 --- a/compiler/src/statement/assign/circuit_variable.rs +++ b/compiler/src/statement/assign/circuit_variable.rs @@ -81,7 +81,7 @@ impl> ConstrainedProgram { member.1 = selected_value.to_owned(); - Ok(selected_value.to_owned()) + Ok(selected_value) } _ => { // Throw an error if we try to mutate an immutable circuit variable diff --git a/compiler/src/statement/branch/branch.rs b/compiler/src/statement/branch/branch.rs index 1df2bbce4a..abbadee733 100644 --- a/compiler/src/statement/branch/branch.rs +++ b/compiler/src/statement/branch/branch.rs @@ -41,7 +41,7 @@ impl> ConstrainedProgram { cs, file_scope.clone(), function_scope.clone(), - indicator.clone(), + indicator, statement.clone(), return_type.clone(), "".to_owned(), diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 76da259ba2..36e16ad055 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -56,7 +56,7 @@ impl> ConstrainedProgram { ) -> Result>, StatementError> { let types = match type_ { Some(Type::Tuple(types)) => types, - Some(type_) => return Err(StatementError::tuple_type(type_.to_string(), span.clone())), + Some(type_) => return Err(StatementError::tuple_type(type_.to_string(), span)), None => vec![], }; @@ -157,7 +157,7 @@ impl> ConstrainedProgram { let variable = variables.names[0].clone(); let expression = self.enforce_expression( cs, - file_scope.clone(), + file_scope, function_scope.clone(), variables.type_, expressions[0].clone(), @@ -181,14 +181,14 @@ impl> ConstrainedProgram { let values = match self.enforce_expression( cs, - file_scope.clone(), + file_scope, function_scope.clone(), variables.type_.clone(), expressions[0].clone(), )? { // ConstrainedValue::Return(values) => values, ConstrainedValue::Tuple(values) => values, - value => return Err(StatementError::multiple_definition(value.to_string(), span.clone())), + value => return Err(StatementError::multiple_definition(value.to_string(), span)), }; self.enforce_multiple_definition(cs, function_scope, is_constant, variables, values, span) diff --git a/compiler/src/statement/return_/return_.rs b/compiler/src/statement/return_/return_.rs index 686c22af35..ddd11904f6 100644 --- a/compiler/src/statement/return_/return_.rs +++ b/compiler/src/statement/return_/return_.rs @@ -56,8 +56,8 @@ impl> ConstrainedProgram { let result = self.enforce_operand( cs, - file_scope.clone(), - function_scope.clone(), + file_scope, + function_scope, return_type.clone(), expression, span.clone(), diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 5b29441c7f..9f8a9e8843 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -205,7 +205,7 @@ impl EdwardsGroupType { // Sign inferred None => { // Attempt to recover with a sign_low bit. - if let Some(element) = EdwardsAffine::from_x_coordinate(x.clone(), false) { + if let Some(element) = EdwardsAffine::from_x_coordinate(x, false) { return Ok(element); } @@ -234,7 +234,7 @@ impl EdwardsGroupType { // Sign inferred None => { // Attempt to recover with a sign_low bit. - if let Some(element) = EdwardsAffine::from_y_coordinate(y.clone(), false) { + if let Some(element) = EdwardsAffine::from_y_coordinate(y, false) { return Ok(element); } diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 3664c7fa8f..e662663067 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -110,7 +110,7 @@ impl> ConstrainedValue { // Data type wrappers ConstrainedValue::Array(array) => { - let array_type = array[0].to_type(span.clone())?; + let array_type = array[0].to_type(span)?; let mut dimensions = vec![array.len()]; // Nested array type @@ -205,12 +205,12 @@ impl> ConstrainedValue { // If this is a circuit function, evaluate inside the circuit scope if let Some(identifier) = circuit_identifier { // avoid creating recursive scope - if !is_in_scope(&scope, &identifier.name.to_string()) { - outer_scope = new_scope(scope, identifier.name.to_string()); + if !is_in_scope(&scope, &identifier.name) { + outer_scope = new_scope(scope, identifier.name); } } - Ok((outer_scope, function.clone())) + Ok((outer_scope, function)) } ConstrainedValue::Import(import_scope, function) => function.extract_function(import_scope, span), value => Err(ExpressionError::undefined_function(value.to_string(), span)), diff --git a/core/src/packages/unstable/blake2s.rs b/core/src/packages/unstable/blake2s.rs index 4c2a6f7426..f0d7779c17 100644 --- a/core/src/packages/unstable/blake2s.rs +++ b/core/src/packages/unstable/blake2s.rs @@ -104,7 +104,7 @@ impl CoreCircuit for Blake2sCircuit { ), span.clone(), )], - span: span.clone(), + span, }, )], } diff --git a/gadgets/src/bits/sign_extend.rs b/gadgets/src/bits/sign_extend.rs index 7c44047bce..af0e5c2892 100644 --- a/gadgets/src/bits/sign_extend.rs +++ b/gadgets/src/bits/sign_extend.rs @@ -30,7 +30,7 @@ impl SignExtend for Boolean { fn sign_extend(bits: &[Boolean], length: usize) -> Vec { let msb = bits.last().expect("empty bit list"); let bits_needed = length - bits.len(); - let mut extension = vec![msb.clone(); bits_needed]; + let mut extension = vec![*msb; bits_needed]; let mut result = Vec::from(bits); result.append(&mut extension); diff --git a/leo/commands/build.rs b/leo/commands/build.rs index 95c1f0e5ed..4838b2f29e 100644 --- a/leo/commands/build.rs +++ b/leo/commands/build.rs @@ -93,7 +93,7 @@ impl CLI for BuildCommand { // Compile the library file but do not output let _program = Compiler::::parse_program_without_input( package_name.clone(), - lib_file_path.clone(), + lib_file_path, output_directory.clone(), )?; tracing::info!("Complete"); @@ -121,7 +121,7 @@ impl CLI for BuildCommand { // Load the program at `main_file_path` let program = Compiler::::parse_program_with_input( package_name.clone(), - main_file_path.clone(), + main_file_path, output_directory, &input_string, input_path, diff --git a/leo/commands/deploy.rs b/leo/commands/deploy.rs index a04b8d9c33..46cfb53825 100644 --- a/leo/commands/deploy.rs +++ b/leo/commands/deploy.rs @@ -65,7 +65,7 @@ impl CLI for DeployCommand { Ok(()) } None => { - let mut main_file_path = path.clone(); + let mut main_file_path = path; main_file_path.push(SOURCE_DIRECTORY_NAME); main_file_path.push(MAIN_FILENAME); diff --git a/leo/commands/lint.rs b/leo/commands/lint.rs index 4487f79b9f..6f3092b848 100644 --- a/leo/commands/lint.rs +++ b/leo/commands/lint.rs @@ -65,7 +65,7 @@ impl CLI for LintCommand { Ok(()) } None => { - let mut main_file_path = path.clone(); + let mut main_file_path = path; main_file_path.push(SOURCE_DIRECTORY_NAME); main_file_path.push(MAIN_FILENAME); diff --git a/leo/commands/setup.rs b/leo/commands/setup.rs index 5ee406cdcc..2d61fcd3f3 100644 --- a/leo/commands/setup.rs +++ b/leo/commands/setup.rs @@ -146,7 +146,7 @@ impl CLI for SetupCommand { Ok((program, proving_key, prepared_verifying_key)) } None => { - let mut main_file_path = path.clone(); + let mut main_file_path = path; main_file_path.push(SOURCE_DIRECTORY_NAME); main_file_path.push(MAIN_FILENAME); diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 33468bb076..56d944d733 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -60,7 +60,7 @@ impl CLI for TestCommand { let package_name = manifest.get_package_name(); // Sanitize the package path to the root directory - let mut package_path = path.clone(); + let mut package_path = path; if package_path.is_file() { package_path.pop(); } @@ -93,8 +93,8 @@ impl CLI for TestCommand { // Parse the current main program file let program = Compiler::::parse_program_without_input( - package_name.clone(), - file_path.clone(), + package_name, + file_path, output_directory, )?; @@ -102,7 +102,7 @@ impl CLI for TestCommand { let pairs = InputPairs::try_from(&package_path)?; // Run tests - let temporary_program = program.clone(); + let temporary_program = program; let (passed, failed) = temporary_program.compile_test_constraints(pairs)?; // Drop "Test" context for console logging diff --git a/leo/config.rs b/leo/config.rs index a1db95587e..4a0d2a76d6 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -131,7 +131,7 @@ pub fn write_token(token: &str) -> Result<(), io::Error> { let config_dir = LEO_CONFIG_DIRECTORY.clone(); // Create Leo config directory if it not exists - if !Path::new(&config_dir.to_path_buf()).exists() { + if !Path::new(&config_dir).exists() { create_dir_all(&config_dir)?; } diff --git a/leo/synthesizer/serialized_index.rs b/leo/synthesizer/serialized_index.rs index 88138c3e5b..88246be695 100644 --- a/leo/synthesizer/serialized_index.rs +++ b/leo/synthesizer/serialized_index.rs @@ -36,8 +36,8 @@ impl From for SerializedIndex { impl From<&SerializedIndex> for Index { fn from(serialized_index: &SerializedIndex) -> Self { match serialized_index { - SerializedIndex::Input(idx) => Index::Input(idx.clone()), - SerializedIndex::Aux(idx) => Index::Aux(idx.clone()), + SerializedIndex::Input(idx) => Index::Input(*idx), + SerializedIndex::Aux(idx) => Index::Aux(*idx), } } } From c4cdaed923244be3ffae4c702fc9caa7c3c6f5ac Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 09:34:30 +0200 Subject: [PATCH 19/46] clippy: allow too_many_arguments Signed-off-by: ljedrz --- compiler/src/expression/array/access.rs | 1 + compiler/src/expression/binary/binary.rs | 1 + compiler/src/expression/circuit/access.rs | 1 + compiler/src/expression/circuit/static_access.rs | 1 + compiler/src/expression/conditional/conditional.rs | 1 + compiler/src/expression/function/core_circuit.rs | 1 + compiler/src/expression/function/function.rs | 1 + compiler/src/expression/tuple/access.rs | 1 + compiler/src/statement/assign/array.rs | 1 + compiler/src/statement/assign/assign.rs | 1 + compiler/src/statement/conditional/conditional.rs | 1 + compiler/src/statement/definition/definition.rs | 2 ++ compiler/src/statement/iteration/iteration.rs | 1 + compiler/src/statement/statement.rs | 1 + 14 files changed, 15 insertions(+) diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 9dd5dc72c0..cdfd0c44d8 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -25,6 +25,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_array_access>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index bc76fd3956..2ccf90d2d2 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -25,6 +25,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_binary_expression>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/circuit/access.rs b/compiler/src/expression/circuit/access.rs index 62388a3f51..785053bfdb 100644 --- a/compiler/src/expression/circuit/access.rs +++ b/compiler/src/expression/circuit/access.rs @@ -32,6 +32,7 @@ use snarkos_models::{ static SELF_KEYWORD: &str = "self"; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_circuit_access>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/circuit/static_access.rs b/compiler/src/expression/circuit/static_access.rs index e9928c9764..1c4e7735a6 100644 --- a/compiler/src/expression/circuit/static_access.rs +++ b/compiler/src/expression/circuit/static_access.rs @@ -25,6 +25,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_circuit_static_access>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index 18900d3a50..d181866a3a 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -26,6 +26,7 @@ use snarkos_models::{ impl> ConstrainedProgram { /// Enforce ternary conditional expression + #[allow(clippy::too_many_arguments)] pub fn enforce_conditional_expression>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 1f18a9b0f6..c190cdec49 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -25,6 +25,7 @@ use snarkos_models::{ impl> ConstrainedProgram { /// Call a default core circuit function with arguments + #[allow(clippy::too_many_arguments)] pub fn enforce_core_circuit_call_expression>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index ad189704d2..395bccce1a 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -25,6 +25,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_function_call_expression>( &mut self, cs: &mut CS, diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index 41e832282b..a2e5756e8e 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -25,6 +25,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_tuple_access>( &mut self, cs: &mut CS, diff --git a/compiler/src/statement/assign/array.rs b/compiler/src/statement/assign/array.rs index 2157840203..dfd7c81b11 100644 --- a/compiler/src/statement/assign/array.rs +++ b/compiler/src/statement/assign/array.rs @@ -28,6 +28,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn assign_array>( &mut self, cs: &mut CS, diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 2915136b88..57f77e8d35 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -35,6 +35,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_assign_statement>( &mut self, cs: &mut CS, diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 3a19f2737a..cdb85fd4c6 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -36,6 +36,7 @@ impl> ConstrainedProgram { /// Due to R1CS constraints, we must evaluate every branch to properly construct the circuit. /// At program execution, we will pass an `indicator` bit down to all child statements within each branch. /// The `indicator` bit will select that branch while keeping the constraint system satisfied. + #[allow(clippy::too_many_arguments)] pub fn enforce_conditional_statement>( &mut self, cs: &mut CS, diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 36e16ad055..941001aa13 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -86,6 +86,7 @@ impl> ConstrainedProgram { Ok(values) } + #[allow(clippy::too_many_arguments)] fn enforce_tuple_definition>( &mut self, cs: &mut CS, @@ -135,6 +136,7 @@ impl> ConstrainedProgram { Ok(()) } + #[allow(clippy::too_many_arguments)] pub fn enforce_definition_statement>( &mut self, cs: &mut CS, diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index fde92b2dcc..0a3f01ee75 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -35,6 +35,7 @@ use snarkos_models::{ }; impl> ConstrainedProgram { + #[allow(clippy::too_many_arguments)] pub fn enforce_iteration_statement>( &mut self, cs: &mut CS, diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 69392933df..df5939b68d 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -30,6 +30,7 @@ impl> ConstrainedProgram { /// Each evaluated statement may execute of one or more statements that may return early. /// To indicate which of these return values to take we conditionally select the value according /// to the `indicator` bit that evaluates to true. + #[allow(clippy::too_many_arguments)] pub fn enforce_statement>( &mut self, cs: &mut CS, From ba9fc922295204bac44469a65d168fcad3932e2f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 09:51:54 +0200 Subject: [PATCH 20/46] clippy: fix large_enum_variant Signed-off-by: ljedrz --- compiler/src/statement/assign/assign.rs | 2 +- compiler/src/statement/statement.rs | 6 ++-- .../src/value/group/targets/edwards_bls12.rs | 24 +++++++-------- typed/src/common/assignee.rs | 4 +-- typed/src/statements/statement.rs | 30 +++++++++---------- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/compiler/src/statement/assign/assign.rs b/compiler/src/statement/assign/assign.rs index 57f77e8d35..444a9a7c9b 100644 --- a/compiler/src/statement/assign/assign.rs +++ b/compiler/src/statement/assign/assign.rs @@ -77,7 +77,7 @@ impl> ConstrainedProgram { function_scope, indicator, variable_name, - range_or_expression, + *range_or_expression, new_value, span, ), diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index df5939b68d..35e293a310 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -71,7 +71,7 @@ impl> ConstrainedProgram { declared_circuit_reference, indicator, variable, - expression, + *expression, span, )?; } @@ -95,8 +95,8 @@ impl> ConstrainedProgram { function_scope, indicator, index, - start, - stop, + *start, + *stop, statements, return_type, span, diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 9f8a9e8843..1fef04ced4 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -48,7 +48,7 @@ use std::{ #[derive(Clone, Debug)] pub enum EdwardsGroupType { Constant(EdwardsAffine), - Allocated(EdwardsBlsGadget), + Allocated(Box), } impl GroupType for EdwardsGroupType { @@ -60,7 +60,7 @@ impl GroupType for EdwardsGroupType { fn to_allocated>(&self, mut cs: CS, span: Span) -> Result { self.allocated(cs.ns(|| format!("allocate affine point {}:{}", span.line, span.start))) - .map(|result| EdwardsGroupType::Allocated(result)) + .map(|ebg| EdwardsGroupType::Allocated(Box::new(ebg))) .map_err(|error| GroupError::synthesis_error(error, span)) } @@ -71,7 +71,7 @@ impl GroupType for EdwardsGroupType { let result = , Fq>>::negate(group, cs) .map_err(|e| GroupError::negate_operation(e, span))?; - Ok(EdwardsGroupType::Allocated(result)) + Ok(EdwardsGroupType::Allocated(Box::new(result))) } } } @@ -90,16 +90,16 @@ impl GroupType for EdwardsGroupType { ) .map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?; - Ok(EdwardsGroupType::Allocated(result)) + Ok(EdwardsGroupType::Allocated(Box::new(result))) } (EdwardsGroupType::Constant(constant_value), EdwardsGroupType::Allocated(allocated_value)) | (EdwardsGroupType::Allocated(allocated_value), EdwardsGroupType::Constant(constant_value)) => { - Ok(EdwardsGroupType::Allocated( + Ok(EdwardsGroupType::Allocated(Box::new( allocated_value .add_constant(cs, constant_value) .map_err(|e| GroupError::binary_operation("+".to_string(), e, span))?, - )) + ))) } } } @@ -118,16 +118,16 @@ impl GroupType for EdwardsGroupType { ) .map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?; - Ok(EdwardsGroupType::Allocated(result)) + Ok(EdwardsGroupType::Allocated(Box::new(result))) } (EdwardsGroupType::Constant(constant_value), EdwardsGroupType::Allocated(allocated_value)) | (EdwardsGroupType::Allocated(allocated_value), EdwardsGroupType::Constant(constant_value)) => { - Ok(EdwardsGroupType::Allocated( + Ok(EdwardsGroupType::Allocated(Box::new( allocated_value .sub_constant(cs, constant_value) .map_err(|e| GroupError::binary_operation("-".to_string(), e, span))?, - )) + ))) } } } @@ -316,7 +316,7 @@ impl AllocGadget for EdwardsGroupType { Self::alloc_helper(value_gen) })?; - Ok(EdwardsGroupType::Allocated(value)) + Ok(EdwardsGroupType::Allocated(Box::new(value))) } fn alloc_input Result, T: Borrow, CS: ConstraintSystem>( @@ -327,7 +327,7 @@ impl AllocGadget for EdwardsGroupType { Self::alloc_helper(value_gen) })?; - Ok(EdwardsGroupType::Allocated(value)) + Ok(EdwardsGroupType::Allocated(Box::new(value))) } } @@ -454,7 +454,7 @@ impl CondSelectGadget for EdwardsGroupType { let second_gadget = second.allocated(cs.ns(|| "second"))?; let result = EdwardsBlsGadget::conditionally_select(cs, cond, &first_gadget, &second_gadget)?; - Ok(EdwardsGroupType::Allocated(result)) + Ok(EdwardsGroupType::Allocated(Box::new(result))) } } diff --git a/typed/src/common/assignee.rs b/typed/src/common/assignee.rs index afa7f1c460..c430b99d0c 100644 --- a/typed/src/common/assignee.rs +++ b/typed/src/common/assignee.rs @@ -27,7 +27,7 @@ use std::fmt; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum Assignee { Identifier(Identifier), - Array(Box, RangeOrExpression), + Array(Box, Box), Tuple(Box, usize), CircuitField(Box, Identifier), // (circuit name, circuit field name) } @@ -54,7 +54,7 @@ impl<'ast> From> for Assignee { .into_iter() .fold(variable, |acc, access| match access { AstAssigneeAccess::Array(array) => { - Assignee::Array(Box::new(acc), RangeOrExpression::from(array.expression)) + Assignee::Array(Box::new(acc), Box::new(RangeOrExpression::from(array.expression))) } AstAssigneeAccess::Tuple(tuple) => { Assignee::Tuple(Box::new(acc), Expression::get_count_from_ast(tuple.number)) diff --git a/typed/src/statements/statement.rs b/typed/src/statements/statement.rs index d91880bea6..edbaaf64d8 100644 --- a/typed/src/statements/statement.rs +++ b/typed/src/statements/statement.rs @@ -36,9 +36,9 @@ use std::fmt; pub enum Statement { Return(Expression, Span), Definition(Declare, Variables, Vec, Span), - Assign(Assignee, Expression, Span), + Assign(Assignee, Box, Span), Conditional(ConditionalStatement, Span), - Iteration(Identifier, Expression, Expression, Vec, Span), + Iteration(Identifier, Box, Box, Vec, Span), Console(ConsoleFunctionCall), Expression(Expression, Span), } @@ -78,7 +78,7 @@ impl<'ast> From> for Statement { match statement.assign { AssignOperation::Assign(ref _assign) => Statement::Assign( Assignee::from(statement.assignee), - Expression::from(statement.expression), + Box::new(Expression::from(statement.expression)), Span::from(statement.span), ), operation_assign => { @@ -88,47 +88,47 @@ impl<'ast> From> for Statement { match operation_assign { AssignOperation::AddAssign(ref _assign) => Statement::Assign( Assignee::from(statement.assignee), - Expression::Add( + Box::new(Expression::Add( Box::new(converted), Box::new(Expression::from(statement.expression)), Span::from(statement.span.clone()), - ), + )), Span::from(statement.span), ), AssignOperation::SubAssign(ref _assign) => Statement::Assign( Assignee::from(statement.assignee), - Expression::Sub( + Box::new(Expression::Sub( Box::new(converted), Box::new(Expression::from(statement.expression)), Span::from(statement.span.clone()), - ), + )), Span::from(statement.span), ), AssignOperation::MulAssign(ref _assign) => Statement::Assign( Assignee::from(statement.assignee), - Expression::Mul( + Box::new(Expression::Mul( Box::new(converted), Box::new(Expression::from(statement.expression)), Span::from(statement.span.clone()), - ), + )), Span::from(statement.span), ), AssignOperation::DivAssign(ref _assign) => Statement::Assign( Assignee::from(statement.assignee), - Expression::Div( + Box::new(Expression::Div( Box::new(converted), Box::new(Expression::from(statement.expression)), Span::from(statement.span.clone()), - ), + )), Span::from(statement.span), ), AssignOperation::PowAssign(ref _assign) => Statement::Assign( Assignee::from(statement.assignee), - Expression::Pow( + Box::new(Expression::Pow( Box::new(converted), Box::new(Expression::from(statement.expression)), Span::from(statement.span.clone()), - ), + )), Span::from(statement.span), ), AssignOperation::Assign(ref _assign) => unimplemented!("cannot assign twice to assign statement"), @@ -142,8 +142,8 @@ impl<'ast> From> for Statement { fn from(statement: ForStatement<'ast>) -> Self { Statement::Iteration( Identifier::from(statement.index), - Expression::from(statement.start), - Expression::from(statement.stop), + Box::new(Expression::from(statement.start)), + Box::new(Expression::from(statement.stop)), statement .statements .into_iter() From 70b87d331f7b09dabe1e807c8edf244d0aa0b050 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 09:56:09 +0200 Subject: [PATCH 21/46] fix: replace deprecated functions Signed-off-by: ljedrz --- package/src/root/zip.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/src/root/zip.rs b/package/src/root/zip.rs index ba0bbc0210..dae0725bd8 100644 --- a/package/src/root/zip.rs +++ b/package/src/root/zip.rs @@ -102,7 +102,7 @@ impl ZipFile { // Write file or directory if path.is_file() { tracing::info!("Adding file {:?} as {:?}", path, name); - zip.start_file_from_path(name, options)?; + zip.start_file(name.to_string_lossy(), options)?; let mut f = File::open(path)?; f.read_to_end(&mut buffer)?; @@ -112,7 +112,7 @@ impl ZipFile { // Only if not root Avoids path spec / warning // and mapname conversion failed error on unzip tracing::info!("Adding directory {:?} as {:?}", path, name); - zip.add_directory_from_path(name, options)?; + zip.add_directory(name.to_string_lossy(), options)?; } } From f016b972fb7c20968842208540911271abb4b1ae Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 10:01:44 +0200 Subject: [PATCH 22/46] clippy: fix vec_box Signed-off-by: ljedrz --- compiler/src/expression/array/array.rs | 4 ++-- typed/src/expression.rs | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index 22a15003dd..ed4283e8ee 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -37,7 +37,7 @@ impl> ConstrainedProgram { file_scope: String, function_scope: String, mut expected_type: Option, - array: Vec>, + array: Vec, span: Span, ) -> Result, ExpressionError> { // Check explicit array type dimension if given @@ -62,7 +62,7 @@ impl> ConstrainedProgram { let mut result = vec![]; for element in array.into_iter() { - match *element { + match element { SpreadOrExpression::Spread(spread) => match spread { Expression::Identifier(identifier) => { let array_name = new_scope(function_scope.clone(), identifier.to_string()); diff --git a/typed/src/expression.rs b/typed/src/expression.rs index 5fc2543c1a..6037d9d1ad 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -92,7 +92,7 @@ pub enum Expression { // Arrays // (array_elements, span) - Array(Vec>, Span), + Array(Vec, Span), // (array_name, range, span) ArrayAccess(Box, Box, Span), @@ -506,7 +506,7 @@ impl<'ast> From> for Expression { array .expressions .into_iter() - .map(|s_or_e| Box::new(SpreadOrExpression::from(s_or_e))) + .map(|s_or_e| SpreadOrExpression::from(s_or_e)) .collect(), Span::from(array.span), ) @@ -516,7 +516,7 @@ impl<'ast> From> for Expression { impl<'ast> From> for Expression { fn from(array: ArrayInitializerExpression<'ast>) -> Self { let dimensions = Expression::get_array_dimensions(array.dimensions); - let expression = Box::new(SpreadOrExpression::from(*array.expression)); + let expression = SpreadOrExpression::from(*array.expression); let mut elements = vec![]; @@ -527,10 +527,10 @@ impl<'ast> From> for Expression { if i == 0 { elements = vec![expression.clone(); dimension]; } else { - let element = Box::new(SpreadOrExpression::Expression(Expression::Array( + let element = SpreadOrExpression::Expression(Expression::Array( elements, Span::from(array.span.clone()), - ))); + )); elements = vec![element; dimension]; } From e9b9c1f72fb21b78e22b201c33e2c3e0ebe6f797 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 10:04:19 +0200 Subject: [PATCH 23/46] fix: allow a piece of own deprecated code Signed-off-by: ljedrz --- compiler/src/compiler.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 62b36d2dce..946cfbed19 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -135,6 +135,7 @@ impl> Compiler { } /// Parses the Leo program file, constructs a syntax tree, and generates a program. + #[allow(deprecated)] pub(crate) fn parse_program(&mut self) -> Result<(), CompilerError> { // Use the parser to construct the abstract syntax tree. let program_string = LeoAst::load_file(&self.main_file_path)?; From bdfb6f5fb5abcd9413e7551f2f2edbbb1a7a0d10 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Mon, 5 Oct 2020 16:58:35 +0200 Subject: [PATCH 24/46] clippy: fix redundant_closure Signed-off-by: ljedrz --- compiler/src/console/assert.rs | 2 +- compiler/src/expression/circuit/static_access.rs | 2 +- compiler/src/expression/function/core_circuit.rs | 2 +- compiler/src/function/main_function.rs | 2 +- compiler/src/import/parser/import_parser.rs | 2 +- compiler/src/value/value.rs | 4 ++-- core/src/packages/unstable/blake2s.rs | 2 +- typed/src/circuits/circuit.rs | 2 +- typed/src/common/range_or_expression.rs | 4 ++-- typed/src/common/variables.rs | 4 ++-- typed/src/console/formatted_string.rs | 4 ++-- typed/src/expression.rs | 12 ++++++------ typed/src/functions/function.rs | 6 +++--- typed/src/imports/import_symbol.rs | 2 +- typed/src/imports/package_access.rs | 2 +- .../input/program_state/public_state/public_state.rs | 1 + .../conditional_nested_or_end_statement.rs | 2 +- typed/src/statements/conditional_statement.rs | 2 +- typed/src/statements/statement.rs | 2 +- typed/src/types/type_.rs | 4 ++-- 20 files changed, 32 insertions(+), 31 deletions(-) diff --git a/compiler/src/console/assert.rs b/compiler/src/console/assert.rs index 00d69332a5..3822212dfe 100644 --- a/compiler/src/console/assert.rs +++ b/compiler/src/console/assert.rs @@ -55,7 +55,7 @@ impl> ConstrainedProgram { ConstrainedValue::Boolean(boolean) => boolean.get_value(), _ => return Err(ConsoleError::assertion_must_be_boolean(expression_string, span)), }; - let result_bool = result_option.ok_or(ConsoleError::assertion_depends_on_input(span.clone()))?; + let result_bool = result_option.ok_or_else(|| ConsoleError::assertion_depends_on_input(span.clone()))?; if !result_bool { return Err(ConsoleError::assertion_failed(expression_string, span)); diff --git a/compiler/src/expression/circuit/static_access.rs b/compiler/src/expression/circuit/static_access.rs index 1c4e7735a6..ba65626e56 100644 --- a/compiler/src/expression/circuit/static_access.rs +++ b/compiler/src/expression/circuit/static_access.rs @@ -43,7 +43,7 @@ impl> ConstrainedProgram { if identifier.is_self() { let circuit = self .get(&file_scope) - .ok_or(ExpressionError::self_keyword(identifier.span))?; + .ok_or_else(|| ExpressionError::self_keyword(identifier.span))?; circuit.to_owned() } else { diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index c190cdec49..4d8d4cd101 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -52,7 +52,7 @@ impl> ConstrainedProgram { // Convert the core function returns into constrained values let returns = res .into_iter() - .map(|value| ConstrainedValue::from(value)) + .map(ConstrainedValue::from) .collect::>(); let return_value = if returns.len() == 1 { diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 950d1cdc7d..c39ce3f9e1 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -54,7 +54,7 @@ impl> ConstrainedProgram { let name = input_model.identifier.name.clone(); let input_option = input .get(&name) - .ok_or(FunctionError::input_not_found(name.clone(), function.span.clone()))?; + .ok_or_else(|| FunctionError::input_not_found(name.clone(), function.span.clone()))?; let input_value = self.allocate_main_function_input( cs, input_model.type_, diff --git a/compiler/src/import/parser/import_parser.rs b/compiler/src/import/parser/import_parser.rs index 8ab7f0f3d8..7d5bbfce20 100644 --- a/compiler/src/import/parser/import_parser.rs +++ b/compiler/src/import/parser/import_parser.rs @@ -53,7 +53,7 @@ impl ImportParser { let mut imports = Self::new(); // Find all imports relative to current directory - let path = current_dir().map_err(|error| ImportError::current_directory_error(error))?; + let path = current_dir().map_err(ImportError::current_directory_error)?; // Parse each imported file program diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index e662663067..6800d5a943 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -548,13 +548,13 @@ impl> From for ConstrainedValue ConstrainedValue::Array( array .into_iter() - .map(|element| ConstrainedValue::from(element)) + .map(ConstrainedValue::from) .collect(), ), Value::Tuple(tuple) => ConstrainedValue::Tuple( tuple .into_iter() - .map(|element| ConstrainedValue::from(element)) + .map(ConstrainedValue::from) .collect(), ), } diff --git a/core/src/packages/unstable/blake2s.rs b/core/src/packages/unstable/blake2s.rs index f0d7779c17..6cff207e52 100644 --- a/core/src/packages/unstable/blake2s.rs +++ b/core/src/packages/unstable/blake2s.rs @@ -141,7 +141,7 @@ impl CoreCircuit for Blake2sCircuit { .to_bytes(cs) .map_err(|e| CoreCircuitError::cannot_enforce("Vec ToBytes".to_owned(), e, span.clone()))?; - let return_value = bytes.into_iter().map(|byte| Value::U8(byte)).collect(); + let return_value = bytes.into_iter().map(Value::U8).collect(); // Return one array digest value Ok(vec![Value::Array(return_value)]) diff --git a/typed/src/circuits/circuit.rs b/typed/src/circuits/circuit.rs index a93463a4cf..79864ee334 100644 --- a/typed/src/circuits/circuit.rs +++ b/typed/src/circuits/circuit.rs @@ -32,7 +32,7 @@ impl<'ast> From> for Circuit { let members = circuit .members .into_iter() - .map(|member| CircuitMember::from(member)) + .map(CircuitMember::from) .collect(); Self { circuit_name, members } diff --git a/typed/src/common/range_or_expression.rs b/typed/src/common/range_or_expression.rs index 97c13b350d..43b0b67661 100644 --- a/typed/src/common/range_or_expression.rs +++ b/typed/src/common/range_or_expression.rs @@ -31,8 +31,8 @@ impl<'ast> From> for RangeOrExpression { fn from(range_or_expression: AstRangeOrExpression<'ast>) -> Self { match range_or_expression { AstRangeOrExpression::Range(range) => RangeOrExpression::Range( - range.from.map(|expression| Expression::from(expression)), - range.to.map(|expression| Expression::from(expression)), + range.from.map(Expression::from), + range.to.map(Expression::from), ), AstRangeOrExpression::Expression(expression) => RangeOrExpression::Expression(Expression::from(expression)), } diff --git a/typed/src/common/variables.rs b/typed/src/common/variables.rs index 2f9d877358..21ae2643b5 100644 --- a/typed/src/common/variables.rs +++ b/typed/src/common/variables.rs @@ -32,10 +32,10 @@ impl<'ast> From> for Variables { let names = variables .names .into_iter() - .map(|x| VariableName::from(x)) + .map(VariableName::from) .collect::>(); - let type_ = variables.type_.map(|type_| Type::from(type_)); + let type_ = variables.type_.map(Type::from); Self { names, type_ } } diff --git a/typed/src/console/formatted_string.rs b/typed/src/console/formatted_string.rs index 86d08492ce..2d6b9b4c23 100644 --- a/typed/src/console/formatted_string.rs +++ b/typed/src/console/formatted_string.rs @@ -35,12 +35,12 @@ impl<'ast> From> for FormattedString { let containers = formatted .containers .into_iter() - .map(|container| FormattedContainer::from(container)) + .map(FormattedContainer::from) .collect(); let parameters = formatted .parameters .into_iter() - .map(|parameter| FormattedParameter::from(parameter)) + .map(FormattedParameter::from) .collect(); Self { diff --git a/typed/src/expression.rs b/typed/src/expression.rs index 6037d9d1ad..a4ed6f1ac4 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -170,7 +170,7 @@ impl<'ast> Expression { InputArrayDimensions::Multiple(multiple) => multiple .numbers .into_iter() - .map(|number| Self::get_count_from_input_ast(number)) + .map(Self::get_count_from_input_ast) .collect(), } } @@ -188,7 +188,7 @@ impl<'ast> Expression { ArrayDimensions::Multiple(multiple) => multiple .numbers .into_iter() - .map(|number| Self::get_count_from_ast(number)) + .map(Self::get_count_from_ast) .collect(), } } @@ -301,7 +301,7 @@ impl<'ast> From> for Expression { let members = expression .members .into_iter() - .map(|member| CircuitVariableDefinition::from(member)) + .map(CircuitVariableDefinition::from) .collect::>(); Expression::Circuit(circuit_name, members, Span::from(expression.span)) @@ -343,7 +343,7 @@ impl<'ast> From> for Expression { .expressions .expressions .into_iter() - .map(|expression| Expression::from(expression)) + .map(Expression::from) .collect(), span, ) @@ -506,7 +506,7 @@ impl<'ast> From> for Expression { array .expressions .into_iter() - .map(|s_or_e| SpreadOrExpression::from(s_or_e)) + .map(SpreadOrExpression::from) .collect(), Span::from(array.span), ) @@ -543,7 +543,7 @@ impl<'ast> From> for Expression { impl<'ast> From> for Expression { fn from(tuple: TupleExpression<'ast>) -> Self { Expression::Tuple( - tuple.expressions.into_iter().map(|e| Expression::from(e)).collect(), + tuple.expressions.into_iter().map(Expression::from).collect(), Span::from(tuple.span), ) } diff --git a/typed/src/functions/function.rs b/typed/src/functions/function.rs index 4f52da175d..8821d077f5 100644 --- a/typed/src/functions/function.rs +++ b/typed/src/functions/function.rs @@ -35,13 +35,13 @@ impl<'ast> From> for Function { let parameters = function .parameters .into_iter() - .map(|parameter| InputVariable::from(parameter)) + .map(InputVariable::from) .collect(); - let returns = function.returns.map(|type_| Type::from(type_)); + let returns = function.returns.map(Type::from); let statements = function .statements .into_iter() - .map(|statement| Statement::from(statement)) + .map(Statement::from) .collect(); Function { diff --git a/typed/src/imports/import_symbol.rs b/typed/src/imports/import_symbol.rs index efaf600807..7c1e129927 100644 --- a/typed/src/imports/import_symbol.rs +++ b/typed/src/imports/import_symbol.rs @@ -31,7 +31,7 @@ impl<'ast> From> for ImportSymbol { fn from(symbol: AstImportSymbol<'ast>) -> Self { ImportSymbol { symbol: Identifier::from(symbol.value), - alias: symbol.alias.map(|alias| Identifier::from(alias)), + alias: symbol.alias.map(Identifier::from), span: Span::from(symbol.span), } } diff --git a/typed/src/imports/package_access.rs b/typed/src/imports/package_access.rs index 437319f541..27608905ad 100644 --- a/typed/src/imports/package_access.rs +++ b/typed/src/imports/package_access.rs @@ -35,7 +35,7 @@ impl<'ast> From> for PackageAccess { AstPackageAccess::SubPackage(package) => PackageAccess::SubPackage(Box::new(Package::from(*package))), AstPackageAccess::Symbol(symbol) => PackageAccess::Symbol(ImportSymbol::from(symbol)), AstPackageAccess::Multiple(accesses) => { - PackageAccess::Multiple(accesses.into_iter().map(|access| PackageAccess::from(access)).collect()) + PackageAccess::Multiple(accesses.into_iter().map(PackageAccess::from).collect()) } } } diff --git a/typed/src/input/program_state/public_state/public_state.rs b/typed/src/input/program_state/public_state/public_state.rs index 3730c4bea3..1d359c1d78 100644 --- a/typed/src/input/program_state/public_state/public_state.rs +++ b/typed/src/input/program_state/public_state/public_state.rs @@ -25,6 +25,7 @@ pub struct PublicState { state: State, } +#[allow(clippy::len_without_is_empty)] impl PublicState { pub fn new() -> Self { Self::default() diff --git a/typed/src/statements/conditional_nested_or_end_statement.rs b/typed/src/statements/conditional_nested_or_end_statement.rs index cad2aeb84e..db609e7429 100644 --- a/typed/src/statements/conditional_nested_or_end_statement.rs +++ b/typed/src/statements/conditional_nested_or_end_statement.rs @@ -35,7 +35,7 @@ impl<'ast> From> for ConditionalNestedO AstConditionalNestedOrEndStatement::End(statements) => ConditionalNestedOrEndStatement::End( statements .into_iter() - .map(|statement| Statement::from(statement)) + .map(Statement::from) .collect(), ), } diff --git a/typed/src/statements/conditional_statement.rs b/typed/src/statements/conditional_statement.rs index 0923736fb2..e608f982bb 100644 --- a/typed/src/statements/conditional_statement.rs +++ b/typed/src/statements/conditional_statement.rs @@ -34,7 +34,7 @@ impl<'ast> From> for ConditionalStatement { statements: statement .statements .into_iter() - .map(|statement| Statement::from(statement)) + .map(Statement::from) .collect(), next: statement .next diff --git a/typed/src/statements/statement.rs b/typed/src/statements/statement.rs index edbaaf64d8..2149497e82 100644 --- a/typed/src/statements/statement.rs +++ b/typed/src/statements/statement.rs @@ -147,7 +147,7 @@ impl<'ast> From> for Statement { statement .statements .into_iter() - .map(|statement| Statement::from(statement)) + .map(Statement::from) .collect(), Span::from(statement.span), ) diff --git a/typed/src/types/type_.rs b/typed/src/types/type_.rs index 42b4eda439..117407706d 100644 --- a/typed/src/types/type_.rs +++ b/typed/src/types/type_.rs @@ -143,7 +143,7 @@ impl<'ast> From> for Type { impl<'ast> From> for Type { fn from(tuple_type: TupleType<'ast>) -> Self { - let types = tuple_type.types.into_iter().map(|type_| Type::from(type_)).collect(); + let types = tuple_type.types.into_iter().map(Type::from).collect(); Type::Tuple(types) } @@ -192,7 +192,7 @@ impl<'ast> From> for Type { impl<'ast> From> for Type { fn from(tuple_type: InputTupleType<'ast>) -> Self { - let types = tuple_type.types_.into_iter().map(|type_| Type::from(type_)).collect(); + let types = tuple_type.types_.into_iter().map(Type::from).collect(); Type::Tuple(types) } From ea3542b30e389309ac09e525ce76c5a64a856f56 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 10:43:39 +0200 Subject: [PATCH 25/46] clippy: allow len_without_is_empty Signed-off-by: ljedrz --- typed/src/input/input.rs | 1 + typed/src/input/program_input/main_input.rs | 1 + typed/src/input/program_input/program_input.rs | 1 + typed/src/input/program_state/private_state/private_state.rs | 1 + typed/src/input/program_state/program_state.rs | 1 + 5 files changed, 5 insertions(+) diff --git a/typed/src/input/input.rs b/typed/src/input/input.rs index 823e8b6896..6ad61f539a 100644 --- a/typed/src/input/input.rs +++ b/typed/src/input/input.rs @@ -37,6 +37,7 @@ impl Default for Input { } } +#[allow(clippy::len_without_is_empty)] impl Input { pub fn new() -> Self { Self::default() diff --git a/typed/src/input/program_input/main_input.rs b/typed/src/input/program_input/main_input.rs index 6071305eec..b7ca4c4a14 100644 --- a/typed/src/input/program_input/main_input.rs +++ b/typed/src/input/program_input/main_input.rs @@ -23,6 +23,7 @@ pub struct MainInput { input: HashMap>, } +#[allow(clippy::len_without_is_empty)] impl MainInput { pub fn new() -> Self { Self::default() diff --git a/typed/src/input/program_input/program_input.rs b/typed/src/input/program_input/program_input.rs index 94418ba949..4a01b9c36a 100644 --- a/typed/src/input/program_input/program_input.rs +++ b/typed/src/input/program_input/program_input.rs @@ -26,6 +26,7 @@ pub struct ProgramInput { registers: Registers, } +#[allow(clippy::len_without_is_empty)] impl ProgramInput { pub fn new() -> Self { Self::default() diff --git a/typed/src/input/program_state/private_state/private_state.rs b/typed/src/input/program_state/private_state/private_state.rs index 489a6ff74e..ff8ae2fc66 100644 --- a/typed/src/input/program_state/private_state/private_state.rs +++ b/typed/src/input/program_state/private_state/private_state.rs @@ -26,6 +26,7 @@ pub struct PrivateState { state_leaf: StateLeaf, } +#[allow(clippy::len_without_is_empty)] impl PrivateState { pub fn new() -> Self { Self::default() diff --git a/typed/src/input/program_state/program_state.rs b/typed/src/input/program_state/program_state.rs index 35284c700e..3c92e5a930 100644 --- a/typed/src/input/program_state/program_state.rs +++ b/typed/src/input/program_state/program_state.rs @@ -26,6 +26,7 @@ pub struct ProgramState { private: PrivateState, } +#[allow(clippy::len_without_is_empty)] impl ProgramState { pub fn new() -> Self { Self::default() From e6e6e9c2348ea3e2a653783fbaf70537124e4175 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 10:49:36 +0200 Subject: [PATCH 26/46] clippy: allow some instances of ptr_arg Signed-off-by: ljedrz --- typed/src/input/input.rs | 1 + typed/src/input/program_input/program_input.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/typed/src/input/input.rs b/typed/src/input/input.rs index 6ad61f539a..1252ef86e4 100644 --- a/typed/src/input/input.rs +++ b/typed/src/input/input.rs @@ -95,6 +95,7 @@ impl Input { } /// Returns the main function input value with the given `name` + #[allow(clippy::ptr_arg)] pub fn get(&self, name: &String) -> Option> { self.program_input.get(name) } diff --git a/typed/src/input/program_input/program_input.rs b/typed/src/input/program_input/program_input.rs index 4a01b9c36a..92f08b63d5 100644 --- a/typed/src/input/program_input/program_input.rs +++ b/typed/src/input/program_input/program_input.rs @@ -65,6 +65,7 @@ impl ProgramInput { } /// Returns the main function input value with the given `name` + #[allow(clippy::ptr_arg)] pub fn get(&self, name: &String) -> Option> { self.main.get(name) } From c4aa913c68696753833e4d5ac2fad1050bb2ee60 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 10:51:14 +0200 Subject: [PATCH 27/46] clippy: fix map_clone Signed-off-by: ljedrz --- typed/src/input/program_input/main_input.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typed/src/input/program_input/main_input.rs b/typed/src/input/program_input/main_input.rs index b7ca4c4a14..26f77c7400 100644 --- a/typed/src/input/program_input/main_input.rs +++ b/typed/src/input/program_input/main_input.rs @@ -63,6 +63,6 @@ impl MainInput { /// Returns an `Option` of the main function input at `name` pub fn get(&self, name: &str) -> Option> { - self.input.get(name).map(|input| input.clone()) + self.input.get(name).cloned() } } From 00e3885b3d73c619e15edf9ac755b260d611e618 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 10:55:19 +0200 Subject: [PATCH 28/46] clippy: fix match_single_binding Signed-off-by: ljedrz --- core/src/types/core_package.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/core/src/types/core_package.rs b/core/src/types/core_package.rs index bc7a01e477..fa9a4e7a00 100644 --- a/core/src/types/core_package.rs +++ b/core/src/types/core_package.rs @@ -87,9 +87,7 @@ impl CorePackage { } } else { // match core circuit - match circuit_name { - name => return Err(CorePackageError::undefined_core_circuit(name.to_string(), span)), - } + return Err(CorePackageError::undefined_core_circuit(circuit_name.to_string(), span)); }; circuit_structs.push(name, circuit) From b4bb39872bd9ddf02ca2bee06bdeaf35e7517829 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 11:01:27 +0200 Subject: [PATCH 29/46] clippy: fix unused_unit Signed-off-by: ljedrz --- compiler/src/definition/definition.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/definition/definition.rs b/compiler/src/definition/definition.rs index 0b76ec2b3e..7ac5918f30 100644 --- a/compiler/src/definition/definition.rs +++ b/compiler/src/definition/definition.rs @@ -32,7 +32,7 @@ impl> ConstrainedProgram { mutable: bool, identifier: Identifier, mut value: ConstrainedValue, - ) -> () { + ) { // Store with given mutability if mutable { value = ConstrainedValue::Mutable(Box::new(value)); From 1a3d1fb2b8f6da125b048ad0cb44e67fafd54c7a Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 11:07:21 +0200 Subject: [PATCH 30/46] clippy: fix collapsible_if Signed-off-by: ljedrz --- compiler/src/expression/array/array.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/compiler/src/expression/array/array.rs b/compiler/src/expression/array/array.rs index ed4283e8ee..578c005bf4 100644 --- a/compiler/src/expression/array/array.rs +++ b/compiler/src/expression/array/array.rs @@ -89,14 +89,12 @@ impl> ConstrainedProgram { } // Check expected_dimensions if given - if !expected_dimensions.is_empty() { - if expected_dimensions[expected_dimensions.len() - 1] != result.len() { - return Err(ExpressionError::invalid_length( - expected_dimensions[expected_dimensions.len() - 1], - result.len(), - span, - )); - } + if !expected_dimensions.is_empty() && expected_dimensions[expected_dimensions.len() - 1] != result.len() { + return Err(ExpressionError::invalid_length( + expected_dimensions[expected_dimensions.len() - 1], + result.len(), + span, + )); } Ok(ConstrainedValue::Array(result)) From 8c099ab8c8f88a04ab40fd43de6b57c056424e77 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 11:55:01 +0200 Subject: [PATCH 31/46] clippy: fix into_iter_on_ref Signed-off-by: ljedrz --- compiler/src/statement/assign/circuit_variable.rs | 2 +- compiler/src/value/value.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/compiler/src/statement/assign/circuit_variable.rs b/compiler/src/statement/assign/circuit_variable.rs index 2d80f71165..908dd0f50c 100644 --- a/compiler/src/statement/assign/circuit_variable.rs +++ b/compiler/src/statement/assign/circuit_variable.rs @@ -43,7 +43,7 @@ impl> ConstrainedProgram { match self.get_mutable_assignee(circuit_name, span.clone())? { ConstrainedValue::CircuitExpression(_variable, members) => { // Modify the circuit variable in place - let matched_variable = members.into_iter().find(|member| member.0 == variable_name); + let matched_variable = members.iter_mut().find(|member| member.0 == variable_name); match matched_variable { Some(member) => match &member.1 { diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 6800d5a943..e6301244e1 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -402,13 +402,13 @@ impl> ConditionalEqGadget for Constrai num_1.conditional_enforce_equal(cs, num_2, condition) } (ConstrainedValue::Array(arr_1), ConstrainedValue::Array(arr_2)) => { - for (i, (left, right)) in arr_1.into_iter().zip(arr_2.into_iter()).enumerate() { + for (i, (left, right)) in arr_1.iter().zip(arr_2.iter()).enumerate() { left.conditional_enforce_equal(cs.ns(|| format!("array[{}]", i)), right, condition)?; } Ok(()) } (ConstrainedValue::Tuple(tuple_1), ConstrainedValue::Tuple(tuple_2)) => { - for (i, (left, right)) in tuple_1.into_iter().zip(tuple_2.into_iter()).enumerate() { + for (i, (left, right)) in tuple_1.iter().zip(tuple_2.iter()).enumerate() { left.conditional_enforce_equal(cs.ns(|| format!("tuple index {}", i)), right, condition)?; } Ok(()) @@ -448,7 +448,7 @@ impl> CondSelectGadget for Constrained (ConstrainedValue::Array(arr_1), ConstrainedValue::Array(arr_2)) => { let mut array = vec![]; - for (i, (first, second)) in arr_1.into_iter().zip(arr_2.into_iter()).enumerate() { + for (i, (first, second)) in arr_1.iter().zip(arr_2.iter()).enumerate() { array.push(Self::conditionally_select( cs.ns(|| format!("array[{}]", i)), cond, @@ -462,7 +462,7 @@ impl> CondSelectGadget for Constrained (ConstrainedValue::Tuple(tuple_1), ConstrainedValue::Array(tuple_2)) => { let mut array = vec![]; - for (i, (first, second)) in tuple_1.into_iter().zip(tuple_2.into_iter()).enumerate() { + for (i, (first, second)) in tuple_1.iter().zip(tuple_2.iter()).enumerate() { array.push(Self::conditionally_select( cs.ns(|| format!("tuple index {}", i)), cond, @@ -484,7 +484,7 @@ impl> CondSelectGadget for Constrained ) => { let mut members = vec![]; - for (i, (first, second)) in members_1.into_iter().zip(members_2.into_iter()).enumerate() { + for (i, (first, second)) in members_1.iter().zip(members_2.iter()).enumerate() { members.push(ConstrainedCircuitMember::conditionally_select( cs.ns(|| format!("circuit member[{}]", i)), cond, From fc4e2ee4ab8766af1f3ecddb13c3352f3affa692 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 12:25:32 +0200 Subject: [PATCH 32/46] clippy: fix type_complexity Signed-off-by: ljedrz --- compiler/src/expression/binary/binary.rs | 4 +++- compiler/src/statement/branch/branch.rs | 4 ++-- compiler/src/statement/conditional/conditional.rs | 7 +++++-- compiler/src/statement/iteration/iteration.rs | 5 +++-- compiler/src/statement/statement.rs | 5 ++++- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/compiler/src/expression/binary/binary.rs b/compiler/src/expression/binary/binary.rs index 2ccf90d2d2..02b54f53d3 100644 --- a/compiler/src/expression/binary/binary.rs +++ b/compiler/src/expression/binary/binary.rs @@ -24,6 +24,8 @@ use snarkos_models::{ gadgets::r1cs::ConstraintSystem, }; +type ConstrainedValuePair = (ConstrainedValue, ConstrainedValue); + impl> ConstrainedProgram { #[allow(clippy::too_many_arguments)] pub fn enforce_binary_expression>( @@ -35,7 +37,7 @@ impl> ConstrainedProgram { left: Expression, right: Expression, span: Span, - ) -> Result<(ConstrainedValue, ConstrainedValue), ExpressionError> { + ) -> Result, ExpressionError> { let mut resolved_left = self.enforce_operand( cs, file_scope.clone(), diff --git a/compiler/src/statement/branch/branch.rs b/compiler/src/statement/branch/branch.rs index abbadee733..bd7cd35858 100644 --- a/compiler/src/statement/branch/branch.rs +++ b/compiler/src/statement/branch/branch.rs @@ -16,7 +16,7 @@ //! Enforces a branch of a conditional or iteration statement in a compiled Leo program. -use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::{program::ConstrainedProgram, GroupType, IndicatorAndConstrainedValue, StatementResult}; use leo_typed::{Statement, Type}; use snarkos_models::{ @@ -33,7 +33,7 @@ impl> ConstrainedProgram { indicator: Option, statements: Vec, return_type: Option, - ) -> Result, ConstrainedValue)>, StatementError> { + ) -> StatementResult>> { let mut results = vec![]; // Evaluate statements. Only allow a single return argument to be returned. for statement in statements.iter() { diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index cdb85fd4c6..c70a6990aa 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -16,7 +16,10 @@ //! Methods to enforce constraints on statements in a compiled Leo program. -use crate::{errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType}; +use crate::{ + errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType, + IndicatorAndConstrainedValue, StatementResult +}; use leo_typed::{ConditionalNestedOrEndStatement, ConditionalStatement, Span, Type}; use snarkos_models::{ @@ -46,7 +49,7 @@ impl> ConstrainedProgram { statement: ConditionalStatement, return_type: Option, span: Span, - ) -> Result, ConstrainedValue)>, StatementError> { + ) -> StatementResult>> { let statement_string = statement.to_string(); // Inherit the indicator from a previous conditional statement or assume that we are the outer parent diff --git a/compiler/src/statement/iteration/iteration.rs b/compiler/src/statement/iteration/iteration.rs index 0a3f01ee75..7503f7571c 100644 --- a/compiler/src/statement/iteration/iteration.rs +++ b/compiler/src/statement/iteration/iteration.rs @@ -17,12 +17,13 @@ //! Enforces an iteration statement in a compiled Leo program. use crate::{ - errors::StatementError, new_scope, program::ConstrainedProgram, value::ConstrainedValue, GroupType, + IndicatorAndConstrainedValue, Integer, + StatementResult, }; use leo_typed::{Expression, Identifier, Span, Statement, Type}; @@ -48,7 +49,7 @@ impl> ConstrainedProgram { statements: Vec, return_type: Option, span: Span, - ) -> Result, ConstrainedValue)>, StatementError> { + ) -> StatementResult>> { let mut results = vec![]; let from = self.enforce_index(cs, file_scope.clone(), function_scope.clone(), start, span.clone())?; diff --git a/compiler/src/statement/statement.rs b/compiler/src/statement/statement.rs index 35e293a310..f3e66035aa 100644 --- a/compiler/src/statement/statement.rs +++ b/compiler/src/statement/statement.rs @@ -24,6 +24,9 @@ use snarkos_models::{ gadgets::{r1cs::ConstraintSystem, utilities::boolean::Boolean}, }; +pub type StatementResult = Result; +pub type IndicatorAndConstrainedValue = (Option, ConstrainedValue); + impl> ConstrainedProgram { /// Enforce a program statement. /// Returns a Vector of (indicator, value) tuples. @@ -40,7 +43,7 @@ impl> ConstrainedProgram { statement: Statement, return_type: Option, declared_circuit_reference: String, - ) -> Result, ConstrainedValue)>, StatementError> { + ) -> StatementResult>> { let mut results = vec![]; match statement { From 4d8a91418f935b43f64f972e95b0e8a39721ad42 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 12:27:45 +0200 Subject: [PATCH 33/46] clippy: fix unnecessary_unwrap Signed-off-by: ljedrz --- compiler/src/expression/tuple/tuple.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/compiler/src/expression/tuple/tuple.rs b/compiler/src/expression/tuple/tuple.rs index caed61a360..8d397ff2f5 100644 --- a/compiler/src/expression/tuple/tuple.rs +++ b/compiler/src/expression/tuple/tuple.rs @@ -38,19 +38,18 @@ impl> ConstrainedProgram { // Check explicit tuple type dimension if given let mut expected_types = vec![]; - if expected_type.is_some() { - match expected_type.unwrap() { - Type::Tuple(ref types) => { - expected_types = types.clone(); - } - ref type_ => { - return Err(ExpressionError::unexpected_tuple( - type_.to_string(), - format!("{:?}", tuple), - span, - )); - } + match expected_type { + Some(Type::Tuple(ref types)) => { + expected_types = types.clone(); } + Some(ref type_) => { + return Err(ExpressionError::unexpected_tuple( + type_.to_string(), + format!("{:?}", tuple), + span, + )); + } + None => {} } let mut result = vec![]; From 08afb0e604314c5ce7967b2240a57841eb06a19e Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 12:30:11 +0200 Subject: [PATCH 34/46] clippy: fix redundant_pattern_matching Signed-off-by: ljedrz --- compiler/src/function/result/result.rs | 2 +- leo/config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index 3f4a7d9b5b..29ace00aed 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -44,7 +44,7 @@ impl> ConstrainedProgram { // If all indicators are none, then there are no branch conditions in the function. // We simply return the last result. - if let None = results.iter().find(|(indicator, _res)| indicator.is_some()) { + if results.iter().all(|(indicator, _res)| indicator.is_none()) { let result = &results[results.len() - 1].1; *return_value = result.clone(); diff --git a/leo/config.rs b/leo/config.rs index 4a0d2a76d6..8f24b359e1 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -91,7 +91,7 @@ impl Config { let toml_string = match fs::read_to_string(&config_path) { Ok(mut toml) => { // If the config is using an incorrect format, rewrite it. - if let Err(_) = toml::from_str::(&toml) { + if toml::from_str::(&toml).is_err() { let default_config_string = toml::to_string(&Config::default())?; fs::write(&config_path, default_config_string.clone())?; toml = default_config_string; From fe016dc16845aee6366ee960cba43ce25cd58f2f Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 12:34:03 +0200 Subject: [PATCH 35/46] clippy: fix needless_range_loop Signed-off-by: ljedrz --- compiler/src/statement/definition/definition.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 941001aa13..137d9f7662 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -63,8 +63,8 @@ impl> ConstrainedProgram { let implicit_types = types.is_empty(); let mut expected_types = vec![]; - for i in 0..expressions.len() { - let expected_type = if implicit_types { None } else { Some(types[i].clone()) }; + for ty in types.iter().take(expressions.len()) { + let expected_type = if implicit_types { None } else { Some(ty.clone()) }; expected_types.push(expected_type); } From c09b7eb3b1efc3a5993c608019621ba1c9bb6fad Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 12:35:42 +0200 Subject: [PATCH 36/46] clippy: fix if_same_then_else Signed-off-by: ljedrz --- compiler/src/statement/return_/return_.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/compiler/src/statement/return_/return_.rs b/compiler/src/statement/return_/return_.rs index ddd11904f6..56217532b2 100644 --- a/compiler/src/statement/return_/return_.rs +++ b/compiler/src/statement/return_/return_.rs @@ -28,9 +28,7 @@ fn check_return_type(expected: Option, actual: Type, span: Span) -> Result match expected { Some(expected) => { if expected.ne(&actual) { - if expected.is_self() && actual.is_circuit() { - return Ok(()); - } else if expected.match_array_types(&actual) { + if (expected.is_self() && actual.is_circuit()) || expected.match_array_types(&actual) { return Ok(()); } else { return Err(StatementError::arguments_type(&expected, &actual, span)); From 87f7d748a8760c46cabdcb7cf0b30b5617d0a077 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 12:45:13 +0200 Subject: [PATCH 37/46] clippy: fix unit_arg Signed-off-by: ljedrz --- leo/commands/watch.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/leo/commands/watch.rs b/leo/commands/watch.rs index 1bf0570078..b761f8aa47 100644 --- a/leo/commands/watch.rs +++ b/leo/commands/watch.rs @@ -57,8 +57,7 @@ impl CLI for WatchCommand { match rx.recv() { // See changes on the write event Ok(DebouncedEvent::Write(_write)) => { - let options = (); - match BuildCommand::output(options) { + match BuildCommand::output(()) { Ok(_output) => { tracing::info!("Built successfully"); } From 300666827e9b4536094fca95a465c6707c9f211c Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 13:07:30 +0200 Subject: [PATCH 38/46] fmt: run cargo +nightly fmt on the changes Signed-off-by: ljedrz --- compiler/src/errors/console.rs | 3 +- compiler/src/errors/value/integer.rs | 3 +- compiler/src/expression/arithmetic/div.rs | 10 ++-- compiler/src/expression/arithmetic/mul.rs | 10 ++-- compiler/src/expression/array/access.rs | 4 +- compiler/src/expression/array/index.rs | 9 +-- .../src/expression/circuit/static_access.rs | 8 +-- .../src/expression/conditional/conditional.rs | 9 +-- compiler/src/expression/expression.rs | 55 ++++--------------- .../src/expression/function/core_circuit.rs | 5 +- compiler/src/expression/tuple/access.rs | 9 +-- compiler/src/statement/assign/array.rs | 8 +-- .../src/statement/conditional/conditional.rs | 8 ++- .../src/value/group/targets/edwards_bls12.rs | 16 +++--- compiler/src/value/value.rs | 18 ++---- leo/commands/test.rs | 7 +-- package/src/package.rs | 14 +++-- typed/src/circuits/circuit.rs | 6 +- typed/src/common/identifier.rs | 6 +- typed/src/common/range_or_expression.rs | 7 +-- typed/src/common/variables.rs | 6 +- typed/src/console/formatted_string.rs | 12 +--- typed/src/expression.rs | 18 ++---- typed/src/functions/function.rs | 12 +--- .../conditional_nested_or_end_statement.rs | 9 +-- typed/src/statements/conditional_statement.rs | 6 +- typed/src/statements/statement.rs | 6 +- 27 files changed, 80 insertions(+), 204 deletions(-) diff --git a/compiler/src/errors/console.rs b/compiler/src/errors/console.rs index d977c25103..4079aa872e 100644 --- a/compiler/src/errors/console.rs +++ b/compiler/src/errors/console.rs @@ -50,7 +50,8 @@ impl ConsoleError { } pub fn assertion_depends_on_input(span: Span) -> Self { - let message = "console.assert() failed to evaluate. This error is caused by empty input file values".to_string(); + let message = + "console.assert() failed to evaluate. This error is caused by empty input file values".to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/errors/value/integer.rs b/compiler/src/errors/value/integer.rs index 663d20fb86..91c307bbec 100644 --- a/compiler/src/errors/value/integer.rs +++ b/compiler/src/errors/value/integer.rs @@ -85,8 +85,7 @@ impl IntegerError { pub fn invalid_index(span: Span) -> Self { let message = "index must be a constant value unsigned integer. allocated indices produce a circuit of unknown size" - .to_string() - ; + .to_string(); Self::new_from_span(message, span) } diff --git a/compiler/src/expression/arithmetic/div.rs b/compiler/src/expression/arithmetic/div.rs index 0a6cecc69c..829846f22e 100644 --- a/compiler/src/expression/arithmetic/div.rs +++ b/compiler/src/expression/arithmetic/div.rs @@ -45,11 +45,9 @@ pub fn enforce_div, CS: ConstraintSystem< let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; enforce_div(cs, val_1, val_2, span) } - (val_1, val_2) => { - Err(ExpressionError::incompatible_types( - format!("{} / {}", val_1, val_2,), - span, - )) - } + (val_1, val_2) => Err(ExpressionError::incompatible_types( + format!("{} / {}", val_1, val_2,), + span, + )), } } diff --git a/compiler/src/expression/arithmetic/mul.rs b/compiler/src/expression/arithmetic/mul.rs index 555563d21d..5ac8981d1d 100644 --- a/compiler/src/expression/arithmetic/mul.rs +++ b/compiler/src/expression/arithmetic/mul.rs @@ -45,11 +45,9 @@ pub fn enforce_mul, CS: ConstraintSystem< let val_2 = ConstrainedValue::from_other(string, &val_1, span.clone())?; enforce_mul(cs, val_1, val_2, span) } - (val_1, val_2) => { - Err(ExpressionError::incompatible_types( - format!("{} * {}", val_1, val_2), - span, - )) - } + (val_1, val_2) => Err(ExpressionError::incompatible_types( + format!("{} * {}", val_1, val_2), + span, + )), } } diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index cdfd0c44d8..15ea723f20 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -57,9 +57,7 @@ impl> ConstrainedProgram { None => 0usize, // Array slice starts at index 0 }; let to_resolved = match to { - Some(to_index) => { - self.enforce_index(cs, file_scope, function_scope, to_index, span)? - } + Some(to_index) => self.enforce_index(cs, file_scope, function_scope, to_index, span)?, None => array.len(), // Array slice ends at array length }; Ok(ConstrainedValue::Array(array[from_resolved..to_resolved].to_owned())) diff --git a/compiler/src/expression/array/index.rs b/compiler/src/expression/array/index.rs index 8aca8cb9b9..3f0a9ee436 100644 --- a/compiler/src/expression/array/index.rs +++ b/compiler/src/expression/array/index.rs @@ -34,14 +34,7 @@ impl> ConstrainedProgram { span: Span, ) -> Result { let expected_type = Some(Type::IntegerType(IntegerType::U32)); - match self.enforce_operand( - cs, - file_scope, - function_scope, - expected_type, - index, - span.clone(), - )? { + match self.enforce_operand(cs, file_scope, function_scope, expected_type, index, span.clone())? { ConstrainedValue::Integer(number) => Ok(number.to_usize(span)?), value => Err(ExpressionError::invalid_index(value.to_string(), span)), } diff --git a/compiler/src/expression/circuit/static_access.rs b/compiler/src/expression/circuit/static_access.rs index ba65626e56..88cfcf30d8 100644 --- a/compiler/src/expression/circuit/static_access.rs +++ b/compiler/src/expression/circuit/static_access.rs @@ -50,13 +50,7 @@ impl> ConstrainedProgram { self.evaluate_identifier(file_scope, function_scope, expected_type, identifier)? } } - expression => self.enforce_expression( - cs, - file_scope, - function_scope, - expected_type, - expression, - )?, + expression => self.enforce_expression(cs, file_scope, function_scope, expected_type, expression)?, } .extract_circuit(span.clone())?; diff --git a/compiler/src/expression/conditional/conditional.rs b/compiler/src/expression/conditional/conditional.rs index d181866a3a..6cb30660bf 100644 --- a/compiler/src/expression/conditional/conditional.rs +++ b/compiler/src/expression/conditional/conditional.rs @@ -58,14 +58,7 @@ impl> ConstrainedProgram { span.clone(), )?; - let second_value = self.enforce_operand( - cs, - file_scope, - function_scope, - expected_type, - second, - span.clone(), - )?; + let second_value = self.enforce_operand(cs, file_scope, function_scope, expected_type, second, span.clone())?; let unique_namespace = cs.ns(|| { format!( diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 3692968bc3..e0c108a7fe 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -165,67 +165,32 @@ impl> ConstrainedProgram { Ok(enforce_and(cs, resolved_left, resolved_right, span)?) } Expression::Eq(left, right, span) => { - let (resolved_left, resolved_right) = self.enforce_binary_expression( - cs, - file_scope, - function_scope, - None, - *left, - *right, - span.clone(), - )?; + let (resolved_left, resolved_right) = + self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?; Ok(evaluate_eq(cs, resolved_left, resolved_right, span)?) } Expression::Ge(left, right, span) => { - let (resolved_left, resolved_right) = self.enforce_binary_expression( - cs, - file_scope, - function_scope, - None, - *left, - *right, - span.clone(), - )?; + let (resolved_left, resolved_right) = + self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?; Ok(evaluate_ge(cs, resolved_left, resolved_right, span)?) } Expression::Gt(left, right, span) => { - let (resolved_left, resolved_right) = self.enforce_binary_expression( - cs, - file_scope, - function_scope, - None, - *left, - *right, - span.clone(), - )?; + let (resolved_left, resolved_right) = + self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?; Ok(evaluate_gt(cs, resolved_left, resolved_right, span)?) } Expression::Le(left, right, span) => { - let (resolved_left, resolved_right) = self.enforce_binary_expression( - cs, - file_scope, - function_scope, - None, - *left, - *right, - span.clone(), - )?; + let (resolved_left, resolved_right) = + self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?; Ok(evaluate_le(cs, resolved_left, resolved_right, span)?) } Expression::Lt(left, right, span) => { - let (resolved_left, resolved_right) = self.enforce_binary_expression( - cs, - file_scope, - function_scope, - None, - *left, - *right, - span.clone(), - )?; + let (resolved_left, resolved_right) = + self.enforce_binary_expression(cs, file_scope, function_scope, None, *left, *right, span.clone())?; Ok(evaluate_lt(cs, resolved_left, resolved_right, span)?) } diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 4d8d4cd101..6ebb292391 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -50,10 +50,7 @@ impl> ConstrainedProgram { let res = call_core_circuit(cs, core_circuit, argument_values, span.clone())?; // Convert the core function returns into constrained values - let returns = res - .into_iter() - .map(ConstrainedValue::from) - .collect::>(); + let returns = res.into_iter().map(ConstrainedValue::from).collect::>(); let return_value = if returns.len() == 1 { // The function has a single return diff --git a/compiler/src/expression/tuple/access.rs b/compiler/src/expression/tuple/access.rs index a2e5756e8e..afd3cf9483 100644 --- a/compiler/src/expression/tuple/access.rs +++ b/compiler/src/expression/tuple/access.rs @@ -36,14 +36,7 @@ impl> ConstrainedProgram { index: usize, span: Span, ) -> Result, ExpressionError> { - let tuple = match self.enforce_operand( - cs, - file_scope, - function_scope, - expected_type, - *tuple, - span.clone(), - )? { + let tuple = match self.enforce_operand(cs, file_scope, function_scope, expected_type, *tuple, span.clone())? { ConstrainedValue::Tuple(tuple) => tuple, value => return Err(ExpressionError::undefined_array(value.to_string(), span)), }; diff --git a/compiler/src/statement/assign/array.rs b/compiler/src/statement/assign/array.rs index dfd7c81b11..94d3f88668 100644 --- a/compiler/src/statement/assign/array.rs +++ b/compiler/src/statement/assign/array.rs @@ -76,13 +76,7 @@ impl> ConstrainedProgram { None => 0usize, }; let to_index_option = match to { - Some(integer) => Some(self.enforce_index( - cs, - file_scope, - function_scope, - integer, - span.clone(), - )?), + Some(integer) => Some(self.enforce_index(cs, file_scope, function_scope, integer, span.clone())?), None => None, }; diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index c70a6990aa..cf3d7dbf5f 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -17,8 +17,12 @@ //! Methods to enforce constraints on statements in a compiled Leo program. use crate::{ - errors::StatementError, program::ConstrainedProgram, value::ConstrainedValue, GroupType, - IndicatorAndConstrainedValue, StatementResult + errors::StatementError, + program::ConstrainedProgram, + value::ConstrainedValue, + GroupType, + IndicatorAndConstrainedValue, + StatementResult, }; use leo_typed::{ConditionalNestedOrEndStatement, ConditionalStatement, Span, Type}; diff --git a/compiler/src/value/group/targets/edwards_bls12.rs b/compiler/src/value/group/targets/edwards_bls12.rs index 1fef04ced4..2e45baf4d1 100644 --- a/compiler/src/value/group/targets/edwards_bls12.rs +++ b/compiler/src/value/group/targets/edwards_bls12.rs @@ -201,7 +201,9 @@ impl EdwardsGroupType { let x = Fq::from_str(&x_string).map_err(|_| GroupError::x_invalid(x_string, x_span))?; match greatest { // Sign provided - Some(greatest) => EdwardsAffine::from_x_coordinate(x, greatest).ok_or_else(|| GroupError::x_recover(element_span)), + Some(greatest) => { + EdwardsAffine::from_x_coordinate(x, greatest).ok_or_else(|| GroupError::x_recover(element_span)) + } // Sign inferred None => { // Attempt to recover with a sign_low bit. @@ -230,7 +232,9 @@ impl EdwardsGroupType { match greatest { // Sign provided - Some(greatest) => EdwardsAffine::from_y_coordinate(y, greatest).ok_or_else(|| GroupError::y_recover(element_span)), + Some(greatest) => { + EdwardsAffine::from_y_coordinate(y, greatest).ok_or_else(|| GroupError::y_recover(element_span)) + } // Sign inferred None => { // Attempt to recover with a sign_low bit. @@ -294,12 +298,8 @@ impl EdwardsGroupType { let x_value = allocated.x.get_value(); let y_value = allocated.y.get_value(); - let x_allocated = FpGadget::alloc(cs.ns(|| "x"), || { - x_value.ok_or(SynthesisError::AssignmentMissing) - })?; - let y_allocated = FpGadget::alloc(cs.ns(|| "y"), || { - y_value.ok_or(SynthesisError::AssignmentMissing) - })?; + let x_allocated = FpGadget::alloc(cs.ns(|| "x"), || x_value.ok_or(SynthesisError::AssignmentMissing))?; + let y_allocated = FpGadget::alloc(cs.ns(|| "y"), || y_value.ok_or(SynthesisError::AssignmentMissing))?; Ok(EdwardsBlsGadget::new(x_allocated, y_allocated)) } diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index e6301244e1..8951b63e11 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -239,7 +239,9 @@ impl> ConstrainedValue { } ConstrainedValue::Boolean(boolean) => { let option = boolean.get_value(); - let name = option.map(|b| b.to_string()).unwrap_or_else(|| "[allocated]".to_string()); + let name = option + .map(|b| b.to_string()) + .unwrap_or_else(|| "[allocated]".to_string()); *boolean = allocate_bool(&mut cs, name, option, span)?; } @@ -545,18 +547,8 @@ impl> From for ConstrainedValue ConstrainedValue::Integer(Integer::I64(i64)), Value::I128(i128) => ConstrainedValue::Integer(Integer::I128(i128)), - Value::Array(array) => ConstrainedValue::Array( - array - .into_iter() - .map(ConstrainedValue::from) - .collect(), - ), - Value::Tuple(tuple) => ConstrainedValue::Tuple( - tuple - .into_iter() - .map(ConstrainedValue::from) - .collect(), - ), + Value::Array(array) => ConstrainedValue::Array(array.into_iter().map(ConstrainedValue::from).collect()), + Value::Tuple(tuple) => ConstrainedValue::Tuple(tuple.into_iter().map(ConstrainedValue::from).collect()), } } } diff --git a/leo/commands/test.rs b/leo/commands/test.rs index 56d944d733..3a5108b65c 100644 --- a/leo/commands/test.rs +++ b/leo/commands/test.rs @@ -92,11 +92,8 @@ impl CLI for TestCommand { let start = Instant::now(); // Parse the current main program file - let program = Compiler::::parse_program_without_input( - package_name, - file_path, - output_directory, - )?; + let program = + Compiler::::parse_program_without_input(package_name, file_path, output_directory)?; // Parse all inputs as input pairs let pairs = InputPairs::try_from(&package_path)?; diff --git a/package/src/package.rs b/package/src/package.rs index 7cac214539..1eef499f12 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -128,9 +128,10 @@ impl Package { // First, verify that this directory is not already initialized as a Leo package. { if !Self::can_initialize(package_name, is_lib, path) { - return Err( - PackageError::FailedToInitialize(package_name.to_owned(), path.as_os_str().to_owned()), - ); + return Err(PackageError::FailedToInitialize( + package_name.to_owned(), + path.as_os_str().to_owned(), + )); } } // Next, initialize this directory as a Leo package. @@ -174,9 +175,10 @@ impl Package { // Next, verify that a valid Leo package has been initialized in this directory { if !Self::is_initialized(package_name, is_lib, path) { - return Err( - PackageError::FailedToInitialize(package_name.to_owned(), path.as_os_str().to_owned()), - ); + return Err(PackageError::FailedToInitialize( + package_name.to_owned(), + path.as_os_str().to_owned(), + )); } } diff --git a/typed/src/circuits/circuit.rs b/typed/src/circuits/circuit.rs index 79864ee334..cc5c6216af 100644 --- a/typed/src/circuits/circuit.rs +++ b/typed/src/circuits/circuit.rs @@ -29,11 +29,7 @@ pub struct Circuit { impl<'ast> From> for Circuit { fn from(circuit: AstCircuit<'ast>) -> Self { let circuit_name = Identifier::from(circuit.identifier); - let members = circuit - .members - .into_iter() - .map(CircuitMember::from) - .collect(); + let members = circuit.members.into_iter().map(CircuitMember::from).collect(); Self { circuit_name, members } } diff --git a/typed/src/common/identifier.rs b/typed/src/common/identifier.rs index 8577528363..15a2abd83b 100644 --- a/typed/src/common/identifier.rs +++ b/typed/src/common/identifier.rs @@ -32,7 +32,11 @@ use serde::{ Serialize, Serializer, }; -use std::{collections::BTreeMap, fmt, hash::{Hash, Hasher}}; +use std::{ + collections::BTreeMap, + fmt, + hash::{Hash, Hasher}, +}; /// An identifier in the constrained program. /// diff --git a/typed/src/common/range_or_expression.rs b/typed/src/common/range_or_expression.rs index 43b0b67661..60f1f97acd 100644 --- a/typed/src/common/range_or_expression.rs +++ b/typed/src/common/range_or_expression.rs @@ -30,10 +30,9 @@ pub enum RangeOrExpression { impl<'ast> From> for RangeOrExpression { fn from(range_or_expression: AstRangeOrExpression<'ast>) -> Self { match range_or_expression { - AstRangeOrExpression::Range(range) => RangeOrExpression::Range( - range.from.map(Expression::from), - range.to.map(Expression::from), - ), + AstRangeOrExpression::Range(range) => { + RangeOrExpression::Range(range.from.map(Expression::from), range.to.map(Expression::from)) + } AstRangeOrExpression::Expression(expression) => RangeOrExpression::Expression(Expression::from(expression)), } } diff --git a/typed/src/common/variables.rs b/typed/src/common/variables.rs index 21ae2643b5..b096545296 100644 --- a/typed/src/common/variables.rs +++ b/typed/src/common/variables.rs @@ -29,11 +29,7 @@ pub struct Variables { impl<'ast> From> for Variables { fn from(variables: AstVariables<'ast>) -> Self { - let names = variables - .names - .into_iter() - .map(VariableName::from) - .collect::>(); + let names = variables.names.into_iter().map(VariableName::from).collect::>(); let type_ = variables.type_.map(Type::from); diff --git a/typed/src/console/formatted_string.rs b/typed/src/console/formatted_string.rs index 2d6b9b4c23..b3d41fe20f 100644 --- a/typed/src/console/formatted_string.rs +++ b/typed/src/console/formatted_string.rs @@ -32,16 +32,8 @@ impl<'ast> From> for FormattedString { fn from(formatted: AstFormattedString<'ast>) -> Self { let string = formatted.string; let span = Span::from(formatted.span); - let containers = formatted - .containers - .into_iter() - .map(FormattedContainer::from) - .collect(); - let parameters = formatted - .parameters - .into_iter() - .map(FormattedParameter::from) - .collect(); + let containers = formatted.containers.into_iter().map(FormattedContainer::from).collect(); + let parameters = formatted.parameters.into_iter().map(FormattedParameter::from).collect(); Self { string, diff --git a/typed/src/expression.rs b/typed/src/expression.rs index a4ed6f1ac4..bf2d6deeb1 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -185,11 +185,7 @@ impl<'ast> Expression { pub(crate) fn get_array_dimensions(dimensions: ArrayDimensions<'ast>) -> Vec { match dimensions { ArrayDimensions::Single(single) => vec![Self::get_count_from_ast(single.number)], - ArrayDimensions::Multiple(multiple) => multiple - .numbers - .into_iter() - .map(Self::get_count_from_ast) - .collect(), + ArrayDimensions::Multiple(multiple) => multiple.numbers.into_iter().map(Self::get_count_from_ast).collect(), } } } @@ -503,11 +499,7 @@ impl<'ast> From> for Expression { impl<'ast> From> for Expression { fn from(array: ArrayInlineExpression<'ast>) -> Self { Expression::Array( - array - .expressions - .into_iter() - .map(SpreadOrExpression::from) - .collect(), + array.expressions.into_iter().map(SpreadOrExpression::from).collect(), Span::from(array.span), ) } @@ -527,10 +519,8 @@ impl<'ast> From> for Expression { if i == 0 { elements = vec![expression.clone(); dimension]; } else { - let element = SpreadOrExpression::Expression(Expression::Array( - elements, - Span::from(array.span.clone()), - )); + let element = + SpreadOrExpression::Expression(Expression::Array(elements, Span::from(array.span.clone()))); elements = vec![element; dimension]; } diff --git a/typed/src/functions/function.rs b/typed/src/functions/function.rs index 8821d077f5..b68526cbe6 100644 --- a/typed/src/functions/function.rs +++ b/typed/src/functions/function.rs @@ -32,17 +32,9 @@ pub struct Function { impl<'ast> From> for Function { fn from(function: AstFunction<'ast>) -> Self { let function_name = Identifier::from(function.identifier); - let parameters = function - .parameters - .into_iter() - .map(InputVariable::from) - .collect(); + let parameters = function.parameters.into_iter().map(InputVariable::from).collect(); let returns = function.returns.map(Type::from); - let statements = function - .statements - .into_iter() - .map(Statement::from) - .collect(); + let statements = function.statements.into_iter().map(Statement::from).collect(); Function { identifier: function_name, diff --git a/typed/src/statements/conditional_nested_or_end_statement.rs b/typed/src/statements/conditional_nested_or_end_statement.rs index db609e7429..5dbe8b1c5d 100644 --- a/typed/src/statements/conditional_nested_or_end_statement.rs +++ b/typed/src/statements/conditional_nested_or_end_statement.rs @@ -32,12 +32,9 @@ impl<'ast> From> for ConditionalNestedO AstConditionalNestedOrEndStatement::Nested(nested) => { ConditionalNestedOrEndStatement::Nested(Box::new(ConditionalStatement::from(*nested))) } - AstConditionalNestedOrEndStatement::End(statements) => ConditionalNestedOrEndStatement::End( - statements - .into_iter() - .map(Statement::from) - .collect(), - ), + AstConditionalNestedOrEndStatement::End(statements) => { + ConditionalNestedOrEndStatement::End(statements.into_iter().map(Statement::from).collect()) + } } } } diff --git a/typed/src/statements/conditional_statement.rs b/typed/src/statements/conditional_statement.rs index e608f982bb..90983251e6 100644 --- a/typed/src/statements/conditional_statement.rs +++ b/typed/src/statements/conditional_statement.rs @@ -31,11 +31,7 @@ impl<'ast> From> for ConditionalStatement { fn from(statement: AstConditionalStatement<'ast>) -> Self { ConditionalStatement { condition: Expression::from(statement.condition), - statements: statement - .statements - .into_iter() - .map(Statement::from) - .collect(), + statements: statement.statements.into_iter().map(Statement::from).collect(), next: statement .next .map(|n_or_e| Some(ConditionalNestedOrEndStatement::from(n_or_e))) diff --git a/typed/src/statements/statement.rs b/typed/src/statements/statement.rs index 2149497e82..c7ce04476e 100644 --- a/typed/src/statements/statement.rs +++ b/typed/src/statements/statement.rs @@ -144,11 +144,7 @@ impl<'ast> From> for Statement { Identifier::from(statement.index), Box::new(Expression::from(statement.start)), Box::new(Expression::from(statement.stop)), - statement - .statements - .into_iter() - .map(Statement::from) - .collect(), + statement.statements.into_iter().map(Statement::from).collect(), Span::from(statement.span), ) } From bbcafd16de2e6539687fcc36f0e5213d1aa2b0e3 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 13:37:51 +0200 Subject: [PATCH 39/46] clippy: fix match_ref_parts Signed-off-by: ljedrz --- gadgets/tests/signed_integer/i128.rs | 16 ++++++++-------- gadgets/tests/signed_integer/i16.rs | 16 ++++++++-------- gadgets/tests/signed_integer/i32.rs | 16 ++++++++-------- gadgets/tests/signed_integer/i64.rs | 16 ++++++++-------- gadgets/tests/signed_integer/i8.rs | 16 ++++++++-------- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/gadgets/tests/signed_integer/i128.rs b/gadgets/tests/signed_integer/i128.rs index 4ab475567f..42711ecb26 100644 --- a/gadgets/tests/signed_integer/i128.rs +++ b/gadgets/tests/signed_integer/i128.rs @@ -34,10 +34,10 @@ fn check_all_constant_bits(expected: i128, actual: Int128) { let mask = 1 << i as i128; let result = expected & mask; - match b { - &Boolean::Is(_) => panic!(), - &Boolean::Not(_) => panic!(), - &Boolean::Constant(b) => { + match *b { + Boolean::Is(_) => panic!(), + Boolean::Not(_) => panic!(), + Boolean::Constant(b) => { let bit = result == mask; assert_eq!(b, bit); } @@ -51,16 +51,16 @@ fn check_all_allocated_bits(expected: i128, actual: Int128) { let mask = 1 << i as i128; let result = expected & mask; - match b { - &Boolean::Is(ref b) => { + match *b { + Boolean::Is(ref b) => { let bit = result == mask; assert_eq!(b.get_value().unwrap(), bit); } - &Boolean::Not(ref b) => { + Boolean::Not(ref b) => { let bit = result == mask; assert_eq!(!b.get_value().unwrap(), bit); } - &Boolean::Constant(_) => unreachable!(), + Boolean::Constant(_) => unreachable!(), } } } diff --git a/gadgets/tests/signed_integer/i16.rs b/gadgets/tests/signed_integer/i16.rs index f628c2aae8..c03e553e75 100644 --- a/gadgets/tests/signed_integer/i16.rs +++ b/gadgets/tests/signed_integer/i16.rs @@ -34,10 +34,10 @@ fn check_all_constant_bits(expected: i16, actual: Int16) { let mask = 1 << i as i16; let result = expected & mask; - match b { - &Boolean::Is(_) => panic!(), - &Boolean::Not(_) => panic!(), - &Boolean::Constant(b) => { + match *b { + Boolean::Is(_) => panic!(), + Boolean::Not(_) => panic!(), + Boolean::Constant(b) => { let bit = result == mask; assert_eq!(b, bit); } @@ -51,16 +51,16 @@ fn check_all_allocated_bits(expected: i16, actual: Int16) { let mask = 1 << i as i16; let result = expected & mask; - match b { - &Boolean::Is(ref b) => { + match *b { + Boolean::Is(ref b) => { let bit = result == mask; assert_eq!(b.get_value().unwrap(), bit); } - &Boolean::Not(ref b) => { + Boolean::Not(ref b) => { let bit = result == mask; assert_eq!(!b.get_value().unwrap(), bit); } - &Boolean::Constant(_) => unreachable!(), + Boolean::Constant(_) => unreachable!(), } } } diff --git a/gadgets/tests/signed_integer/i32.rs b/gadgets/tests/signed_integer/i32.rs index ec5570009e..167ec9e675 100644 --- a/gadgets/tests/signed_integer/i32.rs +++ b/gadgets/tests/signed_integer/i32.rs @@ -34,10 +34,10 @@ fn check_all_constant_bits(expected: i32, actual: Int32) { let mask = 1 << i as i32; let result = expected & mask; - match b { - &Boolean::Is(_) => panic!(), - &Boolean::Not(_) => panic!(), - &Boolean::Constant(b) => { + match *b { + Boolean::Is(_) => panic!(), + Boolean::Not(_) => panic!(), + Boolean::Constant(b) => { let bit = result == mask; assert_eq!(b, bit); } @@ -51,16 +51,16 @@ fn check_all_allocated_bits(expected: i32, actual: Int32) { let mask = 1 << i as i32; let result = expected & mask; - match b { - &Boolean::Is(ref b) => { + match *b { + Boolean::Is(ref b) => { let bit = result == mask; assert_eq!(b.get_value().unwrap(), bit); } - &Boolean::Not(ref b) => { + Boolean::Not(ref b) => { let bit = result == mask; assert_eq!(!b.get_value().unwrap(), bit); } - &Boolean::Constant(_) => unreachable!(), + Boolean::Constant(_) => unreachable!(), } } } diff --git a/gadgets/tests/signed_integer/i64.rs b/gadgets/tests/signed_integer/i64.rs index 8ce9141a01..86f370e780 100644 --- a/gadgets/tests/signed_integer/i64.rs +++ b/gadgets/tests/signed_integer/i64.rs @@ -34,10 +34,10 @@ fn check_all_constant_bits(expected: i64, actual: Int64) { let mask = 1 << i as i64; let result = expected & mask; - match b { - &Boolean::Is(_) => panic!(), - &Boolean::Not(_) => panic!(), - &Boolean::Constant(b) => { + match *b { + Boolean::Is(_) => panic!(), + Boolean::Not(_) => panic!(), + Boolean::Constant(b) => { let bit = result == mask; assert_eq!(b, bit); } @@ -51,16 +51,16 @@ fn check_all_allocated_bits(expected: i64, actual: Int64) { let mask = 1 << i as i64; let result = expected & mask; - match b { - &Boolean::Is(ref b) => { + match *b { + Boolean::Is(ref b) => { let bit = result == mask; assert_eq!(b.get_value().unwrap(), bit); } - &Boolean::Not(ref b) => { + Boolean::Not(ref b) => { let bit = result == mask; assert_eq!(!b.get_value().unwrap(), bit); } - &Boolean::Constant(_) => unreachable!(), + Boolean::Constant(_) => unreachable!(), } } } diff --git a/gadgets/tests/signed_integer/i8.rs b/gadgets/tests/signed_integer/i8.rs index 1d8af1b154..4f6ba035d8 100644 --- a/gadgets/tests/signed_integer/i8.rs +++ b/gadgets/tests/signed_integer/i8.rs @@ -34,10 +34,10 @@ fn check_all_constant_bits(expected: i8, actual: Int8) { let mask = 1 << i as i8; let result = expected & mask; - match b { - &Boolean::Is(_) => panic!(), - &Boolean::Not(_) => panic!(), - &Boolean::Constant(b) => { + match *b { + Boolean::Is(_) => panic!(), + Boolean::Not(_) => panic!(), + Boolean::Constant(b) => { let bit = result == mask; assert_eq!(b, bit); } @@ -51,16 +51,16 @@ fn check_all_allocated_bits(expected: i8, actual: Int8) { let mask = 1 << i as i8; let result = expected & mask; - match b { - &Boolean::Is(ref b) => { + match *b { + Boolean::Is(ref b) => { let bit = result == mask; assert_eq!(b.get_value().unwrap(), bit); } - &Boolean::Not(ref b) => { + Boolean::Not(ref b) => { let bit = result == mask; assert_eq!(!b.get_value().unwrap(), bit); } - &Boolean::Constant(_) => unreachable!(), + Boolean::Constant(_) => unreachable!(), } } } From 98baae93c1ff79c75c036cf762870be5d84b32ae Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 14:22:38 +0200 Subject: [PATCH 40/46] clippy: assorted fixes to tests and benches Signed-off-by: ljedrz --- ast/benches/ast.rs | 2 +- compiler/tests/address/mod.rs | 4 ++-- compiler/tests/boolean/mod.rs | 2 +- compiler/tests/mod.rs | 3 +++ package/tests/manifest/manifest.rs | 2 +- package/tests/mod.rs | 4 +++- state/tests/test_verify_local_data_commitment.rs | 12 ++++++------ typed/benches/typed_ast.rs | 4 ++-- typed/tests/serialization/json.rs | 4 +--- 9 files changed, 20 insertions(+), 17 deletions(-) diff --git a/ast/benches/ast.rs b/ast/benches/ast.rs index 5d4cc3f436..3d48721638 100644 --- a/ast/benches/ast.rs +++ b/ast/benches/ast.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{errors::ParserError, files::File, LeoAst}; +use leo_ast::LeoAst; use criterion::{black_box, criterion_group, criterion_main, Criterion}; use std::path::{Path, PathBuf}; diff --git a/compiler/tests/address/mod.rs b/compiler/tests/address/mod.rs index 96615fd29c..c3c2167cd4 100644 --- a/compiler/tests/address/mod.rs +++ b/compiler/tests/address/mod.rs @@ -17,8 +17,8 @@ use crate::{assert_satisfied, expect_compiler_error, generate_main_input, parse_program}; use leo_typed::InputValue; -static TEST_ADDRESS_1: &'static str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8"; -static TEST_ADDRESS_2: &'static str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r"; +static TEST_ADDRESS_1: &str = "aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8"; +static TEST_ADDRESS_2: &str = "aleo18qgam03qe483tdrcc3fkqwpp38ehff4a2xma6lu7hams6lfpgcpq3dq05r"; #[test] fn test_valid() { diff --git a/compiler/tests/boolean/mod.rs b/compiler/tests/boolean/mod.rs index 72ca91f215..c51bacf790 100644 --- a/compiler/tests/boolean/mod.rs +++ b/compiler/tests/boolean/mod.rs @@ -43,7 +43,7 @@ fn fail_boolean_statement(program: EdwardsTestCompiler) { CompilerError::FunctionError(FunctionError::StatementError(StatementError::ExpressionError( ExpressionError::BooleanError(BooleanError::Error(_)), ))) => {} - _ => panic!("Expected boolean error, got {}"), + e => panic!("Expected boolean error, got {}", e), } } diff --git a/compiler/tests/mod.rs b/compiler/tests/mod.rs index 015c2e272a..ce477cbd73 100644 --- a/compiler/tests/mod.rs +++ b/compiler/tests/mod.rs @@ -14,6 +14,9 @@ // You should have received a copy of the GNU General Public License // 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; diff --git a/package/tests/manifest/manifest.rs b/package/tests/manifest/manifest.rs index afce5bfa0a..c0f4fdc51e 100644 --- a/package/tests/manifest/manifest.rs +++ b/package/tests/manifest/manifest.rs @@ -44,7 +44,7 @@ const NEW_PROJECT_FORMAT: &str = "[project]"; /// Create a manifest file with outdated formatting. fn create_outdated_manifest_file(path: PathBuf) -> PathBuf { - let mut path = path.to_owned(); + let mut path = path; if path.is_dir() { path.push(PathBuf::from(MANIFEST_FILENAME)); } diff --git a/package/tests/mod.rs b/package/tests/mod.rs index 0fe5d2f794..27a23865ae 100644 --- a/package/tests/mod.rs +++ b/package/tests/mod.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::module_inception)] + pub mod initialize; pub mod manifest; @@ -59,7 +61,7 @@ pub(crate) fn test_dir() -> PathBuf { let id = NEXT_ID.fetch_add(1, Ordering::Relaxed); TEST_ID.with(|n| *n.borrow_mut() = Some(id)); - let path: PathBuf = TEST_DIR.join(&format!("t{}", id)).into(); + let path: PathBuf = TEST_DIR.join(&format!("t{}", id)); if path.exists() { if let Err(e) = fs::remove_dir_all(&path) { diff --git a/state/tests/test_verify_local_data_commitment.rs b/state/tests/test_verify_local_data_commitment.rs index 7291ade042..89b8db06a3 100644 --- a/state/tests/test_verify_local_data_commitment.rs +++ b/state/tests/test_verify_local_data_commitment.rs @@ -111,8 +111,8 @@ fn test_generate_values_from_dpc() { .unwrap(); // Set the input records for our transaction to be the initial dummy records. - let old_records = vec![old_record.clone(); NUM_INPUT_RECORDS]; - let old_account_private_keys = vec![dummy_account.private_key.clone(); NUM_INPUT_RECORDS]; + let old_records = vec![old_record; NUM_INPUT_RECORDS]; + let old_account_private_keys = vec![dummy_account.private_key; NUM_INPUT_RECORDS]; // Construct new records. @@ -128,12 +128,12 @@ fn test_generate_values_from_dpc() { // Set the new record's program to be the "always-accept" program. - let new_record_owners = vec![new_account.address.clone(); NUM_OUTPUT_RECORDS]; + let new_record_owners = vec![new_account.address; NUM_OUTPUT_RECORDS]; let new_is_dummy_flags = vec![false; NUM_OUTPUT_RECORDS]; let new_values = vec![10; NUM_OUTPUT_RECORDS]; let new_payloads = vec![RecordPayload::default(); NUM_OUTPUT_RECORDS]; let new_birth_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; - let new_death_program_ids = vec![noop_program_id.clone(); NUM_OUTPUT_RECORDS]; + let new_death_program_ids = vec![noop_program_id; NUM_OUTPUT_RECORDS]; let memo = [0u8; 32]; let context = >::execute_offline( @@ -158,13 +158,13 @@ fn test_generate_values_from_dpc() { let root = local_data.local_data_merkle_tree.root(); - let serial_number = local_data.old_serial_numbers[0].clone(); + let serial_number = local_data.old_serial_numbers[0]; let serial_number_bytes = to_bytes![serial_number].unwrap(); let memorandum = local_data.memorandum; let network_id = local_data.network_id; let input_bytes = to_bytes![serial_number, record.commitment(), memorandum, network_id].unwrap(); - let leaf_randomness = local_data.local_data_commitment_randomizers[0].clone(); + let leaf_randomness = local_data.local_data_commitment_randomizers[0]; let old_record_leaf = ::commit( &system_parameters.local_data_commitment, diff --git a/typed/benches/typed_ast.rs b/typed/benches/typed_ast.rs index a38aa47238..38d0f70500 100644 --- a/typed/benches/typed_ast.rs +++ b/typed/benches/typed_ast.rs @@ -14,11 +14,11 @@ // You should have received a copy of the GNU General Public License // along with the Leo library. If not, see . -use leo_ast::{errors::ParserError, files::File, LeoAst}; +use leo_ast::LeoAst; use leo_typed::LeoTypedAst; use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use std::path::{Path, PathBuf}; +use std::path::Path; fn leo_typed_ast<'ast>(ast: &LeoAst<'ast>) { let typed_ast = LeoTypedAst::new("leo_typed_tree", &ast); diff --git a/typed/tests/serialization/json.rs b/typed/tests/serialization/json.rs index 772e857a7a..eb1d43a2aa 100644 --- a/typed/tests/serialization/json.rs +++ b/typed/tests/serialization/json.rs @@ -27,9 +27,7 @@ fn to_typed_ast(program_filepath: &PathBuf) -> LeoTypedAst { let ast = LeoAst::new(&program_filepath, &program_string).unwrap(); // Parse the abstract syntax tree and constructs a typed syntax tree. - let typed_ast = LeoTypedAst::new("leo_typed_tree", &ast); - - typed_ast + LeoTypedAst::new("leo_typed_tree", &ast) } #[test] From e1e22a23103041ab1fb919918e94bf6e85a9870e Mon Sep 17 00:00:00 2001 From: ljedrz Date: Tue, 6 Oct 2020 17:04:52 +0200 Subject: [PATCH 41/46] perf: vector pre-allocation and associated tweaks Signed-off-by: ljedrz --- compiler/src/expression/circuit/circuit.rs | 2 +- .../src/expression/function/core_circuit.rs | 2 +- compiler/src/expression/tuple/tuple.rs | 2 +- compiler/src/function/input/input_keyword.rs | 4 +-- compiler/src/function/input/input_section.rs | 2 +- compiler/src/function/main_function.rs | 2 +- compiler/src/output/output_bytes.rs | 3 +- compiler/src/statement/branch/branch.rs | 6 ++-- .../src/statement/definition/definition.rs | 4 +-- compiler/src/value/value.rs | 8 +++--- core/src/packages/unstable/blake2s.rs | 2 +- gadgets/src/bits/rca.rs | 2 +- gadgets/src/signed_integer/arithmetic/add.rs | 2 +- gadgets/src/signed_integer/arithmetic/mul.rs | 4 +-- leo/synthesizer/serialized_circuit.rs | 28 +++++++------------ state/src/utilities/input_value.rs | 4 +-- typed/src/input/input_value.rs | 4 +-- typed/src/types/type_.rs | 6 ++-- 18 files changed, 38 insertions(+), 49 deletions(-) diff --git a/compiler/src/expression/circuit/circuit.rs b/compiler/src/expression/circuit/circuit.rs index a8698a736b..6f70ea5943 100644 --- a/compiler/src/expression/circuit/circuit.rs +++ b/compiler/src/expression/circuit/circuit.rs @@ -53,7 +53,7 @@ impl> ConstrainedProgram { }; let circuit_identifier = circuit.circuit_name.clone(); - let mut resolved_members = vec![]; + let mut resolved_members = Vec::with_capacity(circuit.members.len()); for member in circuit.members.into_iter() { match member { diff --git a/compiler/src/expression/function/core_circuit.rs b/compiler/src/expression/function/core_circuit.rs index 6ebb292391..a6eea1fc4e 100644 --- a/compiler/src/expression/function/core_circuit.rs +++ b/compiler/src/expression/function/core_circuit.rs @@ -37,7 +37,7 @@ impl> ConstrainedProgram { span: Span, ) -> Result, ExpressionError> { // Get the value of each core function argument - let mut argument_values = vec![]; + let mut argument_values = Vec::with_capacity(arguments.len()); for argument in arguments.into_iter() { let argument_value = self.enforce_expression(cs, file_scope.clone(), function_scope.clone(), None, argument)?; diff --git a/compiler/src/expression/tuple/tuple.rs b/compiler/src/expression/tuple/tuple.rs index 8d397ff2f5..632024ed5d 100644 --- a/compiler/src/expression/tuple/tuple.rs +++ b/compiler/src/expression/tuple/tuple.rs @@ -52,7 +52,7 @@ impl> ConstrainedProgram { None => {} } - let mut result = vec![]; + let mut result = Vec::with_capacity(tuple.len()); for (i, expression) in tuple.into_iter().enumerate() { let type_ = if expected_types.is_empty() { None diff --git a/compiler/src/function/input/input_keyword.rs b/compiler/src/function/input/input_keyword.rs index 3dac6509f9..10025484bd 100644 --- a/compiler/src/function/input/input_keyword.rs +++ b/compiler/src/function/input/input_keyword.rs @@ -62,14 +62,14 @@ impl> ConstrainedProgram { // Allocate each input variable as a circuit expression - let mut sections = vec![]; + let mut sections = Vec::with_capacity(4); sections.push((registers_name, registers_values)); sections.push((record_name, record_values)); sections.push((state_name, state_values)); sections.push((state_leaf_name, state_leaf_values)); - let mut members = vec![]; + let mut members = Vec::with_capacity(sections.len()); for (name, values) in sections { let member_name = name.clone(); diff --git a/compiler/src/function/input/input_section.rs b/compiler/src/function/input/input_section.rs index ab0d849ce0..2ef7e8c42c 100644 --- a/compiler/src/function/input/input_section.rs +++ b/compiler/src/function/input/input_section.rs @@ -30,7 +30,7 @@ impl> ConstrainedProgram { identifier: Identifier, section: HashMap>, ) -> Result, FunctionError> { - let mut members = vec![]; + let mut members = Vec::with_capacity(section.len()); // Allocate each section definition as a circuit member value diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index c39ce3f9e1..2756b7213d 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -42,7 +42,7 @@ impl> ConstrainedProgram { let registers = input.get_registers(); // Iterate over main function input variables and allocate new values - let mut input_variables = vec![]; + let mut input_variables = Vec::with_capacity(function.input.len()); for input_model in function.input.clone().into_iter() { let (identifier, value) = match input_model { InputVariable::InputKeyword(identifier) => { diff --git a/compiler/src/output/output_bytes.rs b/compiler/src/output/output_bytes.rs index 04a5723442..a451c2fc4d 100644 --- a/compiler/src/output/output_bytes.rs +++ b/compiler/src/output/output_bytes.rs @@ -71,8 +71,7 @@ impl OutputBytes { string.push_str(&format); } - let mut bytes: Vec = vec![]; - bytes.extend_from_slice(string.as_bytes()); + let bytes = string.into_bytes(); Ok(Self(bytes)) } diff --git a/compiler/src/statement/branch/branch.rs b/compiler/src/statement/branch/branch.rs index bd7cd35858..200a926b34 100644 --- a/compiler/src/statement/branch/branch.rs +++ b/compiler/src/statement/branch/branch.rs @@ -34,15 +34,15 @@ impl> ConstrainedProgram { statements: Vec, return_type: Option, ) -> StatementResult>> { - let mut results = vec![]; + let mut results = Vec::with_capacity(statements.len()); // Evaluate statements. Only allow a single return argument to be returned. - for statement in statements.iter() { + for statement in statements.into_iter() { let mut value = self.enforce_statement( cs, file_scope.clone(), function_scope.clone(), indicator, - statement.clone(), + statement, return_type.clone(), "".to_owned(), )?; diff --git a/compiler/src/statement/definition/definition.rs b/compiler/src/statement/definition/definition.rs index 137d9f7662..b41420f057 100644 --- a/compiler/src/statement/definition/definition.rs +++ b/compiler/src/statement/definition/definition.rs @@ -61,7 +61,7 @@ impl> ConstrainedProgram { }; let implicit_types = types.is_empty(); - let mut expected_types = vec![]; + let mut expected_types = Vec::with_capacity(expressions.len()); for ty in types.iter().take(expressions.len()) { let expected_type = if implicit_types { None } else { Some(ty.clone()) }; @@ -69,7 +69,7 @@ impl> ConstrainedProgram { expected_types.push(expected_type); } - let mut values = vec![]; + let mut values = Vec::with_capacity(expressions.len()); for (expression, expected_type) in expressions.into_iter().zip(expected_types.into_iter()) { let value = self.enforce_expression( diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index 8951b63e11..15ac98a508 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -122,7 +122,7 @@ impl> ConstrainedValue { Type::Array(Box::new(array_type), dimensions) } ConstrainedValue::Tuple(tuple) => { - let mut types = vec![]; + let mut types = Vec::with_capacity(tuple.len()); for value in tuple { let type_ = value.to_type(span.clone())?; @@ -448,7 +448,7 @@ impl> CondSelectGadget for Constrained ConstrainedValue::Integer(Integer::conditionally_select(cs, cond, num_1, num_2)?) } (ConstrainedValue::Array(arr_1), ConstrainedValue::Array(arr_2)) => { - let mut array = vec![]; + let mut array = Vec::with_capacity(arr_1.len()); for (i, (first, second)) in arr_1.iter().zip(arr_2.iter()).enumerate() { array.push(Self::conditionally_select( @@ -462,7 +462,7 @@ impl> CondSelectGadget for Constrained ConstrainedValue::Array(array) } (ConstrainedValue::Tuple(tuple_1), ConstrainedValue::Array(tuple_2)) => { - let mut array = vec![]; + let mut array = Vec::with_capacity(tuple_1.len()); for (i, (first, second)) in tuple_1.iter().zip(tuple_2.iter()).enumerate() { array.push(Self::conditionally_select( @@ -484,7 +484,7 @@ impl> CondSelectGadget for Constrained ConstrainedValue::CircuitExpression(identifier, members_1), ConstrainedValue::CircuitExpression(_identifier, members_2), ) => { - let mut members = vec![]; + let mut members = Vec::with_capacity(members_1.len()); for (i, (first, second)) in members_1.iter().zip(members_2.iter()).enumerate() { members.push(ConstrainedCircuitMember::conditionally_select( diff --git a/core/src/packages/unstable/blake2s.rs b/core/src/packages/unstable/blake2s.rs index 6cff207e52..5031f32161 100644 --- a/core/src/packages/unstable/blake2s.rs +++ b/core/src/packages/unstable/blake2s.rs @@ -158,7 +158,7 @@ fn check_array_bytes(value: Value, size: usize, span: Span) -> Result return Err(CoreCircuitError::array_length(size, array_value.len(), span)); } - let mut array_bytes = vec![]; + let mut array_bytes = Vec::with_capacity(array_value.len()); for value in array_value { let byte = match value { diff --git a/gadgets/src/bits/rca.rs b/gadgets/src/bits/rca.rs index d5df6124a2..8b51197dd9 100644 --- a/gadgets/src/bits/rca.rs +++ b/gadgets/src/bits/rca.rs @@ -33,7 +33,7 @@ where // Generic impl impl RippleCarryAdder for Vec { fn add_bits>(&self, mut cs: CS, other: &Self) -> Result, SynthesisError> { - let mut result = vec![]; + let mut result = Vec::with_capacity(self.len() + 1); let mut carry = Boolean::constant(false); for (i, (a, b)) in self.iter().zip(other.iter()).enumerate() { let (sum, next) = Boolean::add(cs.ns(|| format!("rpc {}", i)), a, b, &carry)?; diff --git a/gadgets/src/signed_integer/arithmetic/add.rs b/gadgets/src/signed_integer/arithmetic/add.rs index cc352a1bea..b4d4e8671c 100644 --- a/gadgets/src/signed_integer/arithmetic/add.rs +++ b/gadgets/src/signed_integer/arithmetic/add.rs @@ -117,7 +117,7 @@ macro_rules! add_int_impl { } // Storage area for the resulting bits - let mut result_bits = vec![]; + let mut result_bits = Vec::with_capacity(max_bits); // Allocate each bit_gadget of the result let mut coeff = F::one(); diff --git a/gadgets/src/signed_integer/arithmetic/mul.rs b/gadgets/src/signed_integer/arithmetic/mul.rs index 7bb3feaee9..2d4a8c4d12 100644 --- a/gadgets/src/signed_integer/arithmetic/mul.rs +++ b/gadgets/src/signed_integer/arithmetic/mul.rs @@ -84,7 +84,7 @@ macro_rules! mul_int_impl { a_shifted.truncate(size); // conditionally add - let mut to_add = vec![]; + let mut to_add = Vec::with_capacity(a_shifted.len()); for (j, a_bit) in a_shifted.iter().enumerate() { let selected_bit = Boolean::conditionally_select( &mut cs.ns(|| format!("select product bit {} {}", i, j)), @@ -175,7 +175,7 @@ macro_rules! mul_int_impl { } // Storage area for the resulting bits - let mut result_bits = vec![]; + let mut result_bits = Vec::with_capacity(max_bits); // Allocate each bit_gadget of the result let mut coeff = F::one(); diff --git a/leo/synthesizer/serialized_circuit.rs b/leo/synthesizer/serialized_circuit.rs index 96dd62849e..182cda2e4b 100644 --- a/leo/synthesizer/serialized_circuit.rs +++ b/leo/synthesizer/serialized_circuit.rs @@ -58,15 +58,7 @@ impl From> for SerializedCircuit { // Serialize assignments fn get_serialized_assignments(assignments: &[E::Fr]) -> Vec { - let mut serialized = vec![]; - - for assignment in assignments { - let field = SerializedField::from(assignment); - - serialized.push(field); - } - - serialized + assignments.iter().map(SerializedField::from).collect() } let input_assignment = get_serialized_assignments::(&synthesizer.input_assignment); @@ -76,7 +68,7 @@ impl From> for SerializedCircuit { fn get_serialized_constraints( constraints: &[(E::Fr, Index)], ) -> Vec<(SerializedField, SerializedIndex)> { - let mut serialized = vec![]; + let mut serialized = Vec::with_capacity(constraints.len()); for &(ref coeff, index) in constraints { let field = SerializedField::from(coeff); @@ -88,9 +80,9 @@ impl From> for SerializedCircuit { serialized } - let mut at = vec![]; - let mut bt = vec![]; - let mut ct = vec![]; + let mut at = Vec::with_capacity(num_constraints); + let mut bt = Vec::with_capacity(num_constraints); + let mut ct = Vec::with_capacity(num_constraints); for i in 0..num_constraints { // Serialize at[i] @@ -130,7 +122,7 @@ impl TryFrom for CircuitSynthesizer { fn get_deserialized_assignments( assignments: &[SerializedField], ) -> Result::Fr>, FieldError> { - let mut deserialized = vec![]; + let mut deserialized = Vec::with_capacity(assignments.len()); for serialized_assignment in assignments { let field = ::Fr::try_from(serialized_assignment)?; @@ -148,7 +140,7 @@ impl TryFrom for CircuitSynthesizer { fn get_deserialized_constraints( constraints: &[(SerializedField, SerializedIndex)], ) -> Result::Fr, Index)>, FieldError> { - let mut deserialized = vec![]; + let mut deserialized = Vec::with_capacity(constraints.len()); for &(ref serialized_coeff, ref serialized_index) in constraints { let field = ::Fr::try_from(serialized_coeff)?; @@ -160,9 +152,9 @@ impl TryFrom for CircuitSynthesizer { Ok(deserialized) } - let mut at = vec![]; - let mut bt = vec![]; - let mut ct = vec![]; + let mut at = Vec::with_capacity(serialized.num_constraints); + let mut bt = Vec::with_capacity(serialized.num_constraints); + let mut ct = Vec::with_capacity(serialized.num_constraints); for i in 0..serialized.num_constraints { // Deserialize at[i] diff --git a/state/src/utilities/input_value.rs b/state/src/utilities/input_value.rs index c734a47824..9e1cc9421b 100644 --- a/state/src/utilities/input_value.rs +++ b/state/src/utilities/input_value.rs @@ -49,7 +49,7 @@ pub fn input_to_u8_vec(input: InputValue) -> Result, InputValueError> { value => return Err(InputValueError::ExpectedBytes(value.to_string())), }; - let mut result_vec = vec![]; + let mut result_vec = Vec::with_capacity(input_array.len()); for input in input_array { let integer_string = input_to_integer_string(input)?; @@ -67,7 +67,7 @@ pub fn input_to_nested_u8_vec(input: InputValue) -> Result>, InputVa value => return Err(InputValueError::ExpectedBytes(value.to_string())), }; - let mut result_vec = vec![]; + let mut result_vec = Vec::with_capacity(inner_arrays.len()); for input_array in inner_arrays { let array = input_to_u8_vec(input_array)?; diff --git a/typed/src/input/input_value.rs b/typed/src/input/input_value.rs index 14fa81209e..03ab13e7f9 100644 --- a/typed/src/input/input_value.rs +++ b/typed/src/input/input_value.rs @@ -123,7 +123,7 @@ impl InputValue { Type::Array(array_type) }; - let mut elements = vec![]; + let mut elements = Vec::with_capacity(inline.expressions.len()); for expression in inline.expressions.into_iter() { let element = InputValue::from_expression(inner_array_type.clone(), expression)?; @@ -229,7 +229,7 @@ impl InputValue { )); } - let mut values = vec![]; + let mut values = Vec::with_capacity(tuple_type.types_.len()); for (type_, value) in tuple_type.types_.into_iter().zip(tuple.expressions.into_iter()) { let value = InputValue::from_expression(type_, value)?; diff --git a/typed/src/types/type_.rs b/typed/src/types/type_.rs index 117407706d..2dab59356d 100644 --- a/typed/src/types/type_.rs +++ b/typed/src/types/type_.rs @@ -82,8 +82,7 @@ impl Type { let type_ = self.clone(); if dimensions.len() > 1 { - let mut next = vec![]; - next.extend_from_slice(&dimensions[1..]); + let next = dimensions[1..].to_vec(); return Type::Array(Box::new(type_), next); } @@ -95,8 +94,7 @@ impl Type { let type_ = self.clone(); if dimensions.len() > 1 { - let mut next = vec![]; - next.extend_from_slice(&dimensions[..dimensions.len() - 1]); + let next = dimensions[..dimensions.len() - 1].to_vec(); return Type::Array(Box::new(type_), next); } From 39cd98d2c0eb409e62fda97edc0237d6c3705ac6 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 7 Oct 2020 13:38:11 +0200 Subject: [PATCH 42/46] bench: extend the LeoTypedAst benchmarks Signed-off-by: ljedrz --- typed/benches/big_circuit.leo | 265 ++++++++++++++++++++++ typed/benches/big_if_else.leo | 389 +++++++++++++++++++++++++++++++++ typed/benches/big_ternary.leo | 5 + typed/benches/long_array.leo | 57 +++++ typed/benches/long_expr.leo | 9 + typed/benches/main.leo | 3 - typed/benches/many_assigns.leo | 388 ++++++++++++++++++++++++++++++++ typed/benches/many_foos.leo | 196 +++++++++++++++++ typed/benches/typed_ast.rs | 81 ++++++- 9 files changed, 1379 insertions(+), 14 deletions(-) create mode 100644 typed/benches/big_circuit.leo create mode 100644 typed/benches/big_if_else.leo create mode 100644 typed/benches/big_ternary.leo create mode 100644 typed/benches/long_array.leo create mode 100644 typed/benches/long_expr.leo delete mode 100644 typed/benches/main.leo create mode 100644 typed/benches/many_assigns.leo create mode 100644 typed/benches/many_foos.leo diff --git a/typed/benches/big_circuit.leo b/typed/benches/big_circuit.leo new file mode 100644 index 0000000000..32011551c0 --- /dev/null +++ b/typed/benches/big_circuit.leo @@ -0,0 +1,265 @@ +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 }; + + return foo.x0 + bar.x255 +} + +circuit Foo { + x0: u8, + x1: u8, + x2: u8, + x3: u8, + x4: u8, + x5: u8, + x6: u8, + x7: u8, + x8: u8, + x9: u8, + x10: u8, + x11: u8, + x12: u8, + x13: u8, + x14: u8, + x15: u8, + x16: u8, + x17: u8, + x18: u8, + x19: u8, + x20: u8, + x21: u8, + x22: u8, + x23: u8, + x24: u8, + x25: u8, + x26: u8, + x27: u8, + x28: u8, + x29: u8, + x30: u8, + x31: u8, + x32: u8, + x33: u8, + x34: u8, + x35: u8, + x36: u8, + x37: u8, + x38: u8, + x39: u8, + x40: u8, + x41: u8, + x42: u8, + x43: u8, + x44: u8, + x45: u8, + x46: u8, + x47: u8, + x48: u8, + x49: u8, + x50: u8, + x51: u8, + x52: u8, + x53: u8, + x54: u8, + x55: u8, + x56: u8, + x57: u8, + x58: u8, + x59: u8, + x60: u8, + x61: u8, + x62: u8, + x63: u8, + x64: u8, + x65: u8, + x66: u8, + x67: u8, + x68: u8, + x69: u8, + x70: u8, + x71: u8, + x72: u8, + x73: u8, + x74: u8, + x75: u8, + x76: u8, + x77: u8, + x78: u8, + x79: u8, + x80: u8, + x81: u8, + x82: u8, + x83: u8, + x84: u8, + x85: u8, + x86: u8, + x87: u8, + x88: u8, + x89: u8, + x90: u8, + x91: u8, + x92: u8, + x93: u8, + x94: u8, + x95: u8, + x96: u8, + x97: u8, + x98: u8, + x99: u8, + x100: u8, + x101: u8, + x102: u8, + x103: u8, + x104: u8, + x105: u8, + x106: u8, + x107: u8, + x108: u8, + x109: u8, + x110: u8, + x111: u8, + x112: u8, + x113: u8, + x114: u8, + x115: u8, + x116: u8, + x117: u8, + x118: u8, + x119: u8, + x120: u8, + x121: u8, + x122: u8, + x123: u8, + x124: u8, + x125: u8, + x126: u8, + x127: u8, + x128: u8, + x129: u8, + x130: u8, + x131: u8, + x132: u8, + x133: u8, + x134: u8, + x135: u8, + x136: u8, + x137: u8, + x138: u8, + x139: u8, + x140: u8, + x141: u8, + x142: u8, + x143: u8, + x144: u8, + x145: u8, + x146: u8, + x147: u8, + x148: u8, + x149: u8, + x150: u8, + x151: u8, + x152: u8, + x153: u8, + x154: u8, + x155: u8, + x156: u8, + x157: u8, + x158: u8, + x159: u8, + x160: u8, + x161: u8, + x162: u8, + x163: u8, + x164: u8, + x165: u8, + x166: u8, + x167: u8, + x168: u8, + x169: u8, + x170: u8, + x171: u8, + x172: u8, + x173: u8, + x174: u8, + x175: u8, + x176: u8, + x177: u8, + x178: u8, + x179: u8, + x180: u8, + x181: u8, + x182: u8, + x183: u8, + x184: u8, + x185: u8, + x186: u8, + x187: u8, + x188: u8, + x189: u8, + x190: u8, + x191: u8, + x192: u8, + x193: u8, + x194: u8, + x195: u8, + x196: u8, + x197: u8, + x198: u8, + x199: u8, + x200: u8, + x201: u8, + x202: u8, + x203: u8, + x204: u8, + x205: u8, + x206: u8, + x207: u8, + x208: u8, + x209: u8, + x210: u8, + x211: u8, + x212: u8, + x213: u8, + x214: u8, + x215: u8, + x216: u8, + x217: u8, + x218: u8, + x219: u8, + x220: u8, + x221: u8, + x222: u8, + x223: u8, + x224: u8, + x225: u8, + x226: u8, + x227: u8, + x228: u8, + x229: u8, + x230: u8, + x231: u8, + x232: u8, + x233: u8, + x234: u8, + x235: u8, + x236: u8, + x237: u8, + x238: u8, + x239: u8, + x240: u8, + x241: u8, + x242: u8, + x243: u8, + x244: u8, + x245: u8, + x246: u8, + x247: u8, + x248: u8, + x249: u8, + x250: u8, + x251: u8, + x252: u8, + x253: u8, + x254: u8, + x255: u8 +} \ No newline at end of file diff --git a/typed/benches/big_if_else.leo b/typed/benches/big_if_else.leo new file mode 100644 index 0000000000..6c974f12a3 --- /dev/null +++ b/typed/benches/big_if_else.leo @@ -0,0 +1,389 @@ +function main() { + let x: u8 = 191; + + if x == 0 { + return x + } else if x == 1 { + return x - 1 + } else if x == 2 { + return x - 2 + } else if x == 3 { + return x - 3 + } else if x == 4 { + return x - 4 + } else if x == 5 { + return x - 5 + } else if x == 6 { + return x - 6 + } else if x == 7 { + return x - 7 + } else if x == 8 { + return x - 8 + } else if x == 9 { + return x - 9 + } else if x == 10 { + return x - 10 + } else if x == 11 { + return x - 11 + } else if x == 12 { + return x - 12 + } else if x == 13 { + return x - 13 + } else if x == 14 { + return x - 14 + } else if x == 15 { + return x - 15 + } else if x == 16 { + return x - 16 + } else if x == 17 { + return x - 17 + } else if x == 18 { + return x - 18 + } else if x == 19 { + return x - 19 + } else if x == 20 { + return x - 20 + } else if x == 21 { + return x - 21 + } else if x == 22 { + return x - 22 + } else if x == 23 { + return x - 23 + } else if x == 24 { + return x - 24 + } else if x == 25 { + return x - 25 + } else if x == 26 { + return x - 26 + } else if x == 27 { + return x - 27 + } else if x == 28 { + return x - 28 + } else if x == 29 { + return x - 29 + } else if x == 30 { + return x - 30 + } else if x == 31 { + return x - 31 + } else if x == 32 { + return x - 32 + } else if x == 33 { + return x - 33 + } else if x == 34 { + return x - 34 + } else if x == 35 { + return x - 35 + } else if x == 36 { + return x - 36 + } else if x == 37 { + return x - 37 + } else if x == 38 { + return x - 38 + } else if x == 39 { + return x - 39 + } else if x == 40 { + return x - 40 + } else if x == 41 { + return x - 41 + } else if x == 42 { + return x - 42 + } else if x == 43 { + return x - 43 + } else if x == 44 { + return x - 44 + } else if x == 45 { + return x - 45 + } else if x == 46 { + return x - 46 + } else if x == 47 { + return x - 47 + } else if x == 48 { + return x - 48 + } else if x == 49 { + return x - 49 + } else if x == 50 { + return x - 50 + } else if x == 51 { + return x - 51 + } else if x == 52 { + return x - 52 + } else if x == 53 { + return x - 53 + } else if x == 54 { + return x - 54 + } else if x == 55 { + return x - 55 + } else if x == 56 { + return x - 56 + } else if x == 57 { + return x - 57 + } else if x == 58 { + return x - 58 + } else if x == 59 { + return x - 59 + } else if x == 60 { + return x - 60 + } else if x == 61 { + return x - 61 + } else if x == 62 { + return x - 62 + } else if x == 63 { + return x - 63 + } else if x == 64 { + return x - 64 + } else if x == 65 { + return x - 65 + } else if x == 66 { + return x - 66 + } else if x == 67 { + return x - 67 + } else if x == 68 { + return x - 68 + } else if x == 69 { + return x - 69 + } else if x == 70 { + return x - 70 + } else if x == 71 { + return x - 71 + } else if x == 72 { + return x - 72 + } else if x == 73 { + return x - 73 + } else if x == 74 { + return x - 74 + } else if x == 75 { + return x - 75 + } else if x == 76 { + return x - 76 + } else if x == 77 { + return x - 77 + } else if x == 78 { + return x - 78 + } else if x == 79 { + return x - 79 + } else if x == 80 { + return x - 80 + } else if x == 81 { + return x - 81 + } else if x == 82 { + return x - 82 + } else if x == 83 { + return x - 83 + } else if x == 84 { + return x - 84 + } else if x == 85 { + return x - 85 + } else if x == 86 { + return x - 86 + } else if x == 87 { + return x - 87 + } else if x == 88 { + return x - 88 + } else if x == 89 { + return x - 89 + } else if x == 90 { + return x - 90 + } else if x == 91 { + return x - 91 + } else if x == 92 { + return x - 92 + } else if x == 93 { + return x - 93 + } else if x == 94 { + return x - 94 + } else if x == 95 { + return x - 95 + } else if x == 96 { + return x - 96 + } else if x == 97 { + return x - 97 + } else if x == 98 { + return x - 98 + } else if x == 99 { + return x - 99 + } else if x == 100 { + return x - 100 + } else if x == 101 { + return x - 101 + } else if x == 102 { + return x - 102 + } else if x == 103 { + return x - 103 + } else if x == 104 { + return x - 104 + } else if x == 105 { + return x - 105 + } else if x == 106 { + return x - 106 + } else if x == 107 { + return x - 107 + } else if x == 108 { + return x - 108 + } else if x == 109 { + return x - 109 + } else if x == 110 { + return x - 110 + } else if x == 111 { + return x - 111 + } else if x == 112 { + return x - 112 + } else if x == 113 { + return x - 113 + } else if x == 114 { + return x - 114 + } else if x == 115 { + return x - 115 + } else if x == 116 { + return x - 116 + } else if x == 117 { + return x - 117 + } else if x == 118 { + return x - 118 + } else if x == 119 { + return x - 119 + } else if x == 120 { + return x - 120 + } else if x == 121 { + return x - 121 + } else if x == 122 { + return x - 122 + } else if x == 123 { + return x - 123 + } else if x == 124 { + return x - 124 + } else if x == 125 { + return x - 125 + } else if x == 126 { + return x - 126 + } else if x == 127 { + return x - 127 + } else if x == 128 { + return x - 128 + } else if x == 129 { + return x - 129 + } else if x == 130 { + return x - 130 + } else if x == 131 { + return x - 131 + } else if x == 132 { + return x - 132 + } else if x == 133 { + return x - 133 + } else if x == 134 { + return x - 134 + } else if x == 135 { + return x - 135 + } else if x == 136 { + return x - 136 + } else if x == 137 { + return x - 137 + } else if x == 138 { + return x - 138 + } else if x == 139 { + return x - 139 + } else if x == 140 { + return x - 140 + } else if x == 141 { + return x - 141 + } else if x == 142 { + return x - 142 + } else if x == 143 { + return x - 143 + } else if x == 144 { + return x - 144 + } else if x == 145 { + return x - 145 + } else if x == 146 { + return x - 146 + } else if x == 147 { + return x - 147 + } else if x == 148 { + return x - 148 + } else if x == 149 { + return x - 149 + } else if x == 150 { + return x - 150 + } else if x == 151 { + return x - 151 + } else if x == 152 { + return x - 152 + } else if x == 153 { + return x - 153 + } else if x == 154 { + return x - 154 + } else if x == 155 { + return x - 155 + } else if x == 156 { + return x - 156 + } else if x == 157 { + return x - 157 + } else if x == 158 { + return x - 158 + } else if x == 159 { + return x - 159 + } else if x == 160 { + return x - 160 + } else if x == 161 { + return x - 161 + } else if x == 162 { + return x - 162 + } else if x == 163 { + return x - 163 + } else if x == 164 { + return x - 164 + } else if x == 165 { + return x - 165 + } else if x == 166 { + return x - 166 + } else if x == 167 { + return x - 167 + } else if x == 168 { + return x - 168 + } else if x == 169 { + return x - 169 + } else if x == 170 { + return x - 170 + } else if x == 171 { + return x - 171 + } else if x == 172 { + return x - 172 + } else if x == 173 { + return x - 173 + } else if x == 174 { + return x - 174 + } else if x == 175 { + return x - 175 + } else if x == 176 { + return x - 176 + } else if x == 177 { + return x - 177 + } else if x == 178 { + return x - 178 + } else if x == 179 { + return x - 179 + } else if x == 180 { + return x - 180 + } else if x == 181 { + return x - 181 + } else if x == 182 { + return x - 182 + } else if x == 183 { + return x - 183 + } else if x == 184 { + return x - 184 + } else if x == 185 { + return x - 185 + } else if x == 186 { + return x - 186 + } else if x == 187 { + return x - 187 + } else if x == 188 { + return x - 188 + } else if x == 189 { + return x - 189 + } else if x == 190 { + return x - 190 + } else if x == 191 { + return x - 191 + } +} \ No newline at end of file diff --git a/typed/benches/big_ternary.leo b/typed/benches/big_ternary.leo new file mode 100644 index 0000000000..34d8669aaf --- /dev/null +++ b/typed/benches/big_ternary.leo @@ -0,0 +1,5 @@ +function main() { + let x: u8 = 255; + + return if x == 0 ? x : (if x == 1 ? x : (if x == 2 ? x : (if x == 3 ? x : (if x == 4 ? x : (if x == 5 ? x : (if x == 6 ? x : (if x == 7 ? x : (if x == 8 ? x : (if x == 9 ? x : (if x == 10 ? x : (if x == 11 ? x : (if x == 12 ? x : (if x == 13 ? x : (if x == 14 ? x : (if x == 15 ? x : (if x == 16 ? x : (if x == 17 ? x : (if x == 18 ? x : (if x == 19 ? x : (if x == 20 ? x : (if x == 21 ? x : (if x == 22 ? x : (if x == 23 ? x : (if x == 24 ? x : (if x == 25 ? x : (if x == 26 ? x : (if x == 27 ? x : (if x == 28 ? x : (if x == 29 ? x : (if x == 30 ? x : (if x == 31 ? x : (if x == 32 ? x : (if x == 33 ? x : (if x == 34 ? x : (if x == 35 ? x : (if x == 36 ? x : (if x == 37 ? x : (if x == 38 ? x : (if x == 39 ? x : (if x == 40 ? x : (if x == 41 ? x : (if x == 42 ? x : (if x == 43 ? x : (if x == 44 ? x : (if x == 45 ? x : (if x == 46 ? x : (if x == 47 ? x : (if x == 48 ? x : (if x == 49 ? x : (if x == 50 ? x : (if x == 51 ? x : (if x == 52 ? x : (if x == 53 ? x : (if x == 54 ? x : (if x == 55 ? x : (if x == 56 ? x : (if x == 57 ? x : (if x == 58 ? x : (if x == 59 ? x : (if x == 60 ? x : (if x == 61 ? x : (if x == 62 ? x : (if x == 63 ? x : (if x == 64 ? x : (if x == 65 ? x : (if x == 66 ? x : (if x == 67 ? x : (if x == 68 ? x : (if x == 69 ? x : (if x == 70 ? x : (if x == 71 ? x : (if x == 72 ? x : (if x == 73 ? x : (if x == 74 ? x : (if x == 75 ? x : (if x == 76 ? x : (if x == 77 ? x : (if x == 78 ? x : (if x == 79 ? x : (if x == 80 ? x : (if x == 81 ? x : (if x == 82 ? x : (if x == 83 ? x : (if x == 84 ? x : (if x == 85 ? x : (if x == 86 ? x : (if x == 87 ? x : (if x == 88 ? x : (if x == 89 ? x : (if x == 90 ? x : (if x == 91 ? x : (if x == 92 ? x : (if x == 93 ? x : (if x == 94 ? x : (if x == 95 ? x : (if x == 96 ? x : (if x == 97 ? x : (if x == 98 ? x : (if x == 99 ? x : (if x == 100 ? x : (if x == 101 ? x : (if x == 102 ? x : (if x == 103 ? x : (if x == 104 ? x : (if x == 105 ? x : (if x == 106 ? x : (if x == 107 ? x : (if x == 108 ? x : (if x == 109 ? x : (if x == 110 ? x : (if x == 111 ? x : (if x == 112 ? x : (if x == 113 ? x : (if x == 114 ? x : (if x == 115 ? x : (if x == 116 ? x : (if x == 117 ? x : (if x == 118 ? x : (if x == 119 ? x : (if x == 120 ? x : (if x == 121 ? x : (if x == 122 ? x : (if x == 123 ? x : (if x == 124 ? x : (if x == 125 ? x : (if x == 126 ? x : (if x == 127 ? x : (if x == 128 ? x : (if x == 129 ? x : (if x == 130 ? x : (if x == 131 ? x : (if x == 132 ? x : (if x == 133 ? x : (if x == 134 ? x : (if x == 135 ? x : (if x == 136 ? x : (if x == 137 ? x : (if x == 138 ? x : (if x == 139 ? x : (if x == 140 ? x : (if x == 141 ? x : (if x == 142 ? x : (if x == 143 ? x : (if x == 144 ? x : (if x == 145 ? x : (if x == 146 ? x : (if x == 147 ? x : (if x == 148 ? x : (if x == 149 ? x : (if x == 150 ? x : (if x == 151 ? x : (if x == 152 ? x : (if x == 153 ? x : (if x == 154 ? x : (if x == 155 ? x : (if x == 156 ? x : (if x == 157 ? x : (if x == 158 ? x : (if x == 159 ? x : (if x == 160 ? x : (if x == 161 ? x : (if x == 162 ? x : (if x == 163 ? x : (if x == 164 ? x : (if x == 165 ? x : (if x == 166 ? x : (if x == 167 ? x : (if x == 168 ? x : (if x == 169 ? x : (if x == 170 ? x : (if x == 171 ? x : (if x == 172 ? x : (if x == 173 ? x : (if x == 174 ? x : (if x == 175 ? x : (if x == 176 ? x : (if x == 177 ? x : (if x == 178 ? x : (if x == 179 ? x : (if x == 180 ? x : (if x == 181 ? x : (if x == 182 ? x : (if x == 183 ? x : (if x == 184 ? x : (if x == 185 ? x : (if x == 186 ? x : (if x == 187 ? x : (if x == 188 ? x : (if x == 189 ? x : (if x == 190 ? x : (if x == 191 ? x : (if x == 192 ? x : (if x == 193 ? x : (if x == 194 ? x : (if x == 195 ? x : (if x == 196 ? x : (if x == 197 ? x : (if x == 198 ? x : (if x == 199 ? x : (if x == 200 ? x : (if x == 201 ? x : (if x == 202 ? x : (if x == 203 ? x : (if x == 204 ? x : (if x == 205 ? x : (if x == 206 ? x : (if x == 207 ? x : (if x == 208 ? x : (if x == 209 ? x : (if x == 210 ? x : (if x == 211 ? x : (if x == 212 ? x : (if x == 213 ? x : (if x == 214 ? x : (if x == 215 ? x : (if x == 216 ? x : (if x == 217 ? x : (if x == 218 ? x : (if x == 219 ? x : (if x == 220 ? x : (if x == 221 ? x : (if x == 222 ? x : (if x == 223 ? x : (if x == 224 ? x : (if x == 225 ? x : (if x == 226 ? x : (if x == 227 ? x : (if x == 228 ? x : (if x == 229 ? x : (if x == 230 ? x : (if x == 231 ? x : (if x == 232 ? x : (if x == 233 ? x : (if x == 234 ? x : (if x == 235 ? x : (if x == 236 ? x : (if x == 237 ? x : (if x == 238 ? x : (if x == 239 ? x : (if x == 240 ? x : (if x == 241 ? x : (if x == 242 ? x : (if x == 243 ? x : (if x == 244 ? x : (if x == 245 ? x : (if x == 246 ? x : (if x == 247 ? x : (if x == 248 ? x : (if x == 249 ? x : (if x == 250 ? x : (if x == 251 ? x : (if x == 252 ? x : (if x == 253 ? x : (if x == 254 ? x : (if x == 255 ? x : 0))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) +} \ No newline at end of file diff --git a/typed/benches/long_array.leo b/typed/benches/long_array.leo new file mode 100644 index 0000000000..282feb66d0 --- /dev/null +++ b/typed/benches/long_array.leo @@ -0,0 +1,57 @@ +function main() { + let 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], + [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], + [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], + [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], + [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], + [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], + [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], + [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], + [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], + [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], + [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] + ]; + + let 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], + [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], + [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], + [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], + [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], + [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] + ]; + + return arr1[31][31] + arr2[15][31] +} diff --git a/typed/benches/long_expr.leo b/typed/benches/long_expr.leo new file mode 100644 index 0000000000..8cbfb99939 --- /dev/null +++ b/typed/benches/long_expr.leo @@ -0,0 +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; + + return a + b + c + d + e +} diff --git a/typed/benches/main.leo b/typed/benches/main.leo deleted file mode 100644 index ef22115243..0000000000 --- a/typed/benches/main.leo +++ /dev/null @@ -1,3 +0,0 @@ -function main() { - return 1 + 1 -} diff --git a/typed/benches/many_assigns.leo b/typed/benches/many_assigns.leo new file mode 100644 index 0000000000..8f174abc4b --- /dev/null +++ b/typed/benches/many_assigns.leo @@ -0,0 +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; + + return x383 +} diff --git a/typed/benches/many_foos.leo b/typed/benches/many_foos.leo new file mode 100644 index 0000000000..099f04857d --- /dev/null +++ b/typed/benches/many_foos.leo @@ -0,0 +1,196 @@ +function main() { + return x191(0u32) +} + +function x0(val: u8) -> u8 { return val } +function x1(val: u8) -> u8 { return x0(val) } +function x2(val: u8) -> u8 { return x1(val) } +function x3(val: u8) -> u8 { return x2(val) } +function x4(val: u8) -> u8 { return x3(val) } +function x5(val: u8) -> u8 { return x4(val) } +function x6(val: u8) -> u8 { return x5(val) } +function x7(val: u8) -> u8 { return x6(val) } +function x8(val: u8) -> u8 { return x7(val) } +function x9(val: u8) -> u8 { return x8(val) } +function x10(val: u8) -> u8 { return x9(val) } +function x11(val: u8) -> u8 { return x10(val) } +function x12(val: u8) -> u8 { return x11(val) } +function x13(val: u8) -> u8 { return x12(val) } +function x14(val: u8) -> u8 { return x13(val) } +function x15(val: u8) -> u8 { return x14(val) } +function x16(val: u8) -> u8 { return x15(val) } +function x17(val: u8) -> u8 { return x16(val) } +function x18(val: u8) -> u8 { return x17(val) } +function x19(val: u8) -> u8 { return x18(val) } +function x20(val: u8) -> u8 { return x19(val) } +function x21(val: u8) -> u8 { return x20(val) } +function x22(val: u8) -> u8 { return x21(val) } +function x23(val: u8) -> u8 { return x22(val) } +function x24(val: u8) -> u8 { return x23(val) } +function x25(val: u8) -> u8 { return x24(val) } +function x26(val: u8) -> u8 { return x25(val) } +function x27(val: u8) -> u8 { return x26(val) } +function x28(val: u8) -> u8 { return x27(val) } +function x29(val: u8) -> u8 { return x28(val) } +function x30(val: u8) -> u8 { return x29(val) } +function x31(val: u8) -> u8 { return x30(val) } +function x32(val: u8) -> u8 { return x31(val) } +function x33(val: u8) -> u8 { return x32(val) } +function x34(val: u8) -> u8 { return x33(val) } +function x35(val: u8) -> u8 { return x34(val) } +function x36(val: u8) -> u8 { return x35(val) } +function x37(val: u8) -> u8 { return x36(val) } +function x38(val: u8) -> u8 { return x37(val) } +function x39(val: u8) -> u8 { return x38(val) } +function x40(val: u8) -> u8 { return x39(val) } +function x41(val: u8) -> u8 { return x40(val) } +function x42(val: u8) -> u8 { return x41(val) } +function x43(val: u8) -> u8 { return x42(val) } +function x44(val: u8) -> u8 { return x43(val) } +function x45(val: u8) -> u8 { return x44(val) } +function x46(val: u8) -> u8 { return x45(val) } +function x47(val: u8) -> u8 { return x46(val) } +function x48(val: u8) -> u8 { return x47(val) } +function x49(val: u8) -> u8 { return x48(val) } +function x50(val: u8) -> u8 { return x49(val) } +function x51(val: u8) -> u8 { return x50(val) } +function x52(val: u8) -> u8 { return x51(val) } +function x53(val: u8) -> u8 { return x52(val) } +function x54(val: u8) -> u8 { return x53(val) } +function x55(val: u8) -> u8 { return x54(val) } +function x56(val: u8) -> u8 { return x55(val) } +function x57(val: u8) -> u8 { return x56(val) } +function x58(val: u8) -> u8 { return x57(val) } +function x59(val: u8) -> u8 { return x58(val) } +function x60(val: u8) -> u8 { return x59(val) } +function x61(val: u8) -> u8 { return x60(val) } +function x62(val: u8) -> u8 { return x61(val) } +function x63(val: u8) -> u8 { return x62(val) } +function x64(val: u8) -> u8 { return x63(val) } +function x65(val: u8) -> u8 { return x64(val) } +function x66(val: u8) -> u8 { return x65(val) } +function x67(val: u8) -> u8 { return x66(val) } +function x68(val: u8) -> u8 { return x67(val) } +function x69(val: u8) -> u8 { return x68(val) } +function x70(val: u8) -> u8 { return x69(val) } +function x71(val: u8) -> u8 { return x70(val) } +function x72(val: u8) -> u8 { return x71(val) } +function x73(val: u8) -> u8 { return x72(val) } +function x74(val: u8) -> u8 { return x73(val) } +function x75(val: u8) -> u8 { return x74(val) } +function x76(val: u8) -> u8 { return x75(val) } +function x77(val: u8) -> u8 { return x76(val) } +function x78(val: u8) -> u8 { return x77(val) } +function x79(val: u8) -> u8 { return x78(val) } +function x80(val: u8) -> u8 { return x79(val) } +function x81(val: u8) -> u8 { return x80(val) } +function x82(val: u8) -> u8 { return x81(val) } +function x83(val: u8) -> u8 { return x82(val) } +function x84(val: u8) -> u8 { return x83(val) } +function x85(val: u8) -> u8 { return x84(val) } +function x86(val: u8) -> u8 { return x85(val) } +function x87(val: u8) -> u8 { return x86(val) } +function x88(val: u8) -> u8 { return x87(val) } +function x89(val: u8) -> u8 { return x88(val) } +function x90(val: u8) -> u8 { return x89(val) } +function x91(val: u8) -> u8 { return x90(val) } +function x92(val: u8) -> u8 { return x91(val) } +function x93(val: u8) -> u8 { return x92(val) } +function x94(val: u8) -> u8 { return x93(val) } +function x95(val: u8) -> u8 { return x94(val) } +function x96(val: u8) -> u8 { return x95(val) } +function x97(val: u8) -> u8 { return x96(val) } +function x98(val: u8) -> u8 { return x97(val) } +function x99(val: u8) -> u8 { return x98(val) } +function x100(val: u8) -> u8 { return x99(val) } +function x101(val: u8) -> u8 { return x100(val) } +function x102(val: u8) -> u8 { return x101(val) } +function x103(val: u8) -> u8 { return x102(val) } +function x104(val: u8) -> u8 { return x103(val) } +function x105(val: u8) -> u8 { return x104(val) } +function x106(val: u8) -> u8 { return x105(val) } +function x107(val: u8) -> u8 { return x106(val) } +function x108(val: u8) -> u8 { return x107(val) } +function x109(val: u8) -> u8 { return x108(val) } +function x110(val: u8) -> u8 { return x109(val) } +function x111(val: u8) -> u8 { return x110(val) } +function x112(val: u8) -> u8 { return x111(val) } +function x113(val: u8) -> u8 { return x112(val) } +function x114(val: u8) -> u8 { return x113(val) } +function x115(val: u8) -> u8 { return x114(val) } +function x116(val: u8) -> u8 { return x115(val) } +function x117(val: u8) -> u8 { return x116(val) } +function x118(val: u8) -> u8 { return x117(val) } +function x119(val: u8) -> u8 { return x118(val) } +function x120(val: u8) -> u8 { return x119(val) } +function x121(val: u8) -> u8 { return x120(val) } +function x122(val: u8) -> u8 { return x121(val) } +function x123(val: u8) -> u8 { return x122(val) } +function x124(val: u8) -> u8 { return x123(val) } +function x125(val: u8) -> u8 { return x124(val) } +function x126(val: u8) -> u8 { return x125(val) } +function x127(val: u8) -> u8 { return x126(val) } +function x128(val: u8) -> u8 { return x127(val) } +function x129(val: u8) -> u8 { return x128(val) } +function x130(val: u8) -> u8 { return x129(val) } +function x131(val: u8) -> u8 { return x130(val) } +function x132(val: u8) -> u8 { return x131(val) } +function x133(val: u8) -> u8 { return x132(val) } +function x134(val: u8) -> u8 { return x133(val) } +function x135(val: u8) -> u8 { return x134(val) } +function x136(val: u8) -> u8 { return x135(val) } +function x137(val: u8) -> u8 { return x136(val) } +function x138(val: u8) -> u8 { return x137(val) } +function x139(val: u8) -> u8 { return x138(val) } +function x140(val: u8) -> u8 { return x139(val) } +function x141(val: u8) -> u8 { return x140(val) } +function x142(val: u8) -> u8 { return x141(val) } +function x143(val: u8) -> u8 { return x142(val) } +function x144(val: u8) -> u8 { return x143(val) } +function x145(val: u8) -> u8 { return x144(val) } +function x146(val: u8) -> u8 { return x145(val) } +function x147(val: u8) -> u8 { return x146(val) } +function x148(val: u8) -> u8 { return x147(val) } +function x149(val: u8) -> u8 { return x148(val) } +function x150(val: u8) -> u8 { return x149(val) } +function x151(val: u8) -> u8 { return x150(val) } +function x152(val: u8) -> u8 { return x151(val) } +function x153(val: u8) -> u8 { return x152(val) } +function x154(val: u8) -> u8 { return x153(val) } +function x155(val: u8) -> u8 { return x154(val) } +function x156(val: u8) -> u8 { return x155(val) } +function x157(val: u8) -> u8 { return x156(val) } +function x158(val: u8) -> u8 { return x157(val) } +function x159(val: u8) -> u8 { return x158(val) } +function x160(val: u8) -> u8 { return x159(val) } +function x161(val: u8) -> u8 { return x160(val) } +function x162(val: u8) -> u8 { return x161(val) } +function x163(val: u8) -> u8 { return x162(val) } +function x164(val: u8) -> u8 { return x163(val) } +function x165(val: u8) -> u8 { return x164(val) } +function x166(val: u8) -> u8 { return x165(val) } +function x167(val: u8) -> u8 { return x166(val) } +function x168(val: u8) -> u8 { return x167(val) } +function x169(val: u8) -> u8 { return x168(val) } +function x170(val: u8) -> u8 { return x169(val) } +function x171(val: u8) -> u8 { return x170(val) } +function x172(val: u8) -> u8 { return x171(val) } +function x173(val: u8) -> u8 { return x172(val) } +function x174(val: u8) -> u8 { return x173(val) } +function x175(val: u8) -> u8 { return x174(val) } +function x176(val: u8) -> u8 { return x175(val) } +function x177(val: u8) -> u8 { return x176(val) } +function x178(val: u8) -> u8 { return x177(val) } +function x179(val: u8) -> u8 { return x178(val) } +function x180(val: u8) -> u8 { return x179(val) } +function x181(val: u8) -> u8 { return x180(val) } +function x182(val: u8) -> u8 { return x181(val) } +function x183(val: u8) -> u8 { return x182(val) } +function x184(val: u8) -> u8 { return x183(val) } +function x185(val: u8) -> u8 { return x184(val) } +function x186(val: u8) -> u8 { return x185(val) } +function x187(val: u8) -> u8 { return x186(val) } +function x188(val: u8) -> u8 { return x187(val) } +function x189(val: u8) -> u8 { return x188(val) } +function x190(val: u8) -> u8 { return x189(val) } +function x191(val: u8) -> u8 { return x190(val) } diff --git a/typed/benches/typed_ast.rs b/typed/benches/typed_ast.rs index a38aa47238..06d5053be9 100644 --- a/typed/benches/typed_ast.rs +++ b/typed/benches/typed_ast.rs @@ -17,22 +17,81 @@ use leo_ast::{errors::ParserError, files::File, LeoAst}; use leo_typed::LeoTypedAst; -use criterion::{black_box, criterion_group, criterion_main, Criterion}; -use std::path::{Path, PathBuf}; +use criterion::{criterion_group, criterion_main, Criterion}; +use std::{ + path::{Path, PathBuf}, + time::Duration, +}; -fn leo_typed_ast<'ast>(ast: &LeoAst<'ast>) { - let typed_ast = LeoTypedAst::new("leo_typed_tree", &ast); - black_box(typed_ast); +fn leo_typed_ast<'ast>(ast: &LeoAst<'ast>) -> LeoTypedAst { + LeoTypedAst::new("leo_typed_tree", &ast) } -fn criterion_benchmark(c: &mut Criterion) { - let filepath = Path::new("./main.leo").to_path_buf(); - // let program_string = &LeoAst::load_file(&filepath).unwrap(); - let program_string = include_str!("./main.leo"); +fn bench_big_if_else(c: &mut Criterion) { + let filepath = Path::new("./big_if_else.leo").to_path_buf(); + let program_string = include_str!("./big_if_else.leo"); let ast = LeoAst::new(&filepath, program_string).unwrap(); - c.bench_function("LeoTypedAst::new", |b| b.iter(|| leo_typed_ast(black_box(&ast)))); + c.bench_function("LeoTypedAst::big_if_else", |b| b.iter(|| leo_typed_ast(&ast))); } -criterion_group!(benches, criterion_benchmark); +fn bench_big_ternary(c: &mut Criterion) { + let filepath = Path::new("./big_ternary.leo").to_path_buf(); + let program_string = include_str!("./big_ternary.leo"); + let ast = LeoAst::new(&filepath, program_string).unwrap(); + + c.bench_function("LeoTypedAst::big_ternary", |b| b.iter(|| leo_typed_ast(&ast))); +} + +fn bench_big_circuit(c: &mut Criterion) { + let filepath = Path::new("./big_circuit.leo").to_path_buf(); + let program_string = include_str!("./big_circuit.leo"); + let ast = LeoAst::new(&filepath, program_string).unwrap(); + + c.bench_function("LeoTypedAst::big_circuit", |b| b.iter(|| leo_typed_ast(&ast))); +} + +fn bench_long_expr(c: &mut Criterion) { + let filepath = Path::new("./long_expr.leo").to_path_buf(); + let program_string = include_str!("./long_expr.leo"); + let ast = LeoAst::new(&filepath, program_string).unwrap(); + + c.bench_function("LeoTypedAst::long_expr", |b| b.iter(|| leo_typed_ast(&ast))); +} + +fn bench_long_array(c: &mut Criterion) { + let filepath = Path::new("./long_array.leo").to_path_buf(); + let program_string = include_str!("./long_array.leo"); + let ast = LeoAst::new(&filepath, program_string).unwrap(); + + c.bench_function("LeoTypedAst::long_array", |b| b.iter(|| leo_typed_ast(&ast))); +} + +fn bench_many_foos(c: &mut Criterion) { + let filepath = Path::new("./many_foos.leo").to_path_buf(); + let program_string = include_str!("./many_foos.leo"); + let ast = LeoAst::new(&filepath, program_string).unwrap(); + + c.bench_function("LeoTypedAst::many_foos", |b| b.iter(|| leo_typed_ast(&ast))); +} + +fn bench_many_assigns(c: &mut Criterion) { + let filepath = Path::new("./many_assigns.leo").to_path_buf(); + let program_string = include_str!("./many_assigns.leo"); + let ast = LeoAst::new(&filepath, program_string).unwrap(); + + c.bench_function("LeoTypedAst::many_assigns", |b| b.iter(|| leo_typed_ast(&ast))); +} + +criterion_group!( + name = benches; + config = Criterion::default().sample_size(200).measurement_time(Duration::from_secs(10)).nresamples(200_000); + targets = bench_big_circuit, + bench_long_expr, + bench_big_if_else, + bench_big_ternary, + bench_long_array, + bench_many_assigns, + bench_many_foos, +); criterion_main!(benches); From c8299743b8c2eadad79838aef3bd7f2f80a0a981 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Wed, 7 Oct 2020 12:20:49 +0200 Subject: [PATCH 43/46] perf: reduce Expression size from 244B to 152B Signed-off-by: ljedrz --- compiler/src/expression/expression.rs | 2 +- typed/src/expression.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/expression/expression.rs b/compiler/src/expression/expression.rs index 3304c2725d..d79416fd4d 100644 --- a/compiler/src/expression/expression.rs +++ b/compiler/src/expression/expression.rs @@ -54,7 +54,7 @@ impl> ConstrainedProgram { Expression::Address(address, span) => Ok(ConstrainedValue::Address(Address::constant(address, span)?)), Expression::Boolean(boolean, span) => Ok(ConstrainedValue::Boolean(new_bool_constant(boolean, span)?)), Expression::Field(field, span) => Ok(ConstrainedValue::Field(FieldType::constant(field, span)?)), - Expression::Group(group_element) => Ok(ConstrainedValue::Group(G::constant(group_element)?)), + Expression::Group(group_element) => Ok(ConstrainedValue::Group(G::constant(*group_element)?)), Expression::Implicit(value, span) => Ok(enforce_number_implicit(expected_type, value, span)?), Expression::Integer(type_, integer, span) => { Ok(ConstrainedValue::Integer(Integer::new_constant(&type_, integer, span)?)) diff --git a/typed/src/expression.rs b/typed/src/expression.rs index 5fc2543c1a..cb6132bd8b 100644 --- a/typed/src/expression.rs +++ b/typed/src/expression.rs @@ -64,7 +64,7 @@ pub enum Expression { Address(String, Span), Boolean(String, Span), Field(String, Span), - Group(GroupValue), + Group(Box), Implicit(String, Span), Integer(IntegerType, String, Span), @@ -597,7 +597,7 @@ impl<'ast> From> for Expression { impl<'ast> From> for Expression { fn from(ast_group: AstGroupValue<'ast>) -> Self { - Expression::Group(GroupValue::from(ast_group)) + Expression::Group(Box::new(GroupValue::from(ast_group))) } } From a3fc39db92b3b7d53188c043656baaebe2529c35 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 8 Oct 2020 12:51:45 +0200 Subject: [PATCH 44/46] perf: hand-written Hash and PartialEq implementations for Span Signed-off-by: ljedrz --- typed/src/common/span.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/typed/src/common/span.rs b/typed/src/common/span.rs index b5af258eb2..5867b7bb8d 100644 --- a/typed/src/common/span.rs +++ b/typed/src/common/span.rs @@ -16,8 +16,9 @@ use pest::Span as AstSpan; use serde::{Deserialize, Serialize}; +use std::hash::{Hash, Hasher}; -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Debug, Serialize, Deserialize)] pub struct Span { /// text of input string pub text: String, @@ -29,6 +30,22 @@ pub struct Span { pub end: usize, } +impl PartialEq for Span { + fn eq(&self, other: &Self) -> bool { + self.line == other.line && self.start == other.start && self.end == other.end + } +} + +impl Eq for Span {} + +impl Hash for Span { + fn hash(&self, state: &mut H) { + self.line.hash(state); + self.start.hash(state); + self.end.hash(state); + } +} + impl<'ast> From> for Span { fn from(span: AstSpan<'ast>) -> Self { let mut text = " ".to_string(); From 0d01520ea52b2a9ed7fc79891dc17214d43e6b61 Mon Sep 17 00:00:00 2001 From: ljedrz Date: Thu, 8 Oct 2020 13:27:33 +0200 Subject: [PATCH 45/46] perf: hand-written PartialEq implementation for Function Signed-off-by: ljedrz --- typed/src/functions/function.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/typed/src/functions/function.rs b/typed/src/functions/function.rs index 4f52da175d..429ce5a62e 100644 --- a/typed/src/functions/function.rs +++ b/typed/src/functions/function.rs @@ -20,7 +20,7 @@ use leo_ast::functions::Function as AstFunction; use serde::{Deserialize, Serialize}; use std::fmt; -#[derive(Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Serialize, Deserialize)] pub struct Function { pub identifier: Identifier, pub input: Vec, @@ -29,6 +29,14 @@ pub struct Function { pub span: Span, } +impl PartialEq for Function { + fn eq(&self, other: &Self) -> bool { + self.identifier == other.identifier + } +} + +impl Eq for Function {} + impl<'ast> From> for Function { fn from(function: AstFunction<'ast>) -> Self { let function_name = Identifier::from(function.identifier); From d6b266f8bf4c580044df4a5785ab69b21d94d284 Mon Sep 17 00:00:00 2001 From: howardwu Date: Tue, 20 Oct 2020 18:19:12 -0700 Subject: [PATCH 46/46] Remove need for ssh key in CI --- .github/workflows/ci.yml | 24 ------------------------ .github/workflows/release-tests.yml | 16 ---------------- 2 files changed, 40 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6749f22c9f..8d12928e66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,14 +15,6 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Load snarkOS - run: | - mkdir ~/.ssh - echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval $(ssh-agent -s) - ssh-add -k ~/.ssh/id_rsa - - name: Install Rust uses: actions-rs/toolchain@v1 with: @@ -53,14 +45,6 @@ jobs: - name: Checkout uses: actions/checkout@v2 - - name: Load snarkOS - run: | - mkdir ~/.ssh - echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval $(ssh-agent -s) - ssh-add -k ~/.ssh/id_rsa - - name: Install Rust (${{ matrix.rust }}) uses: actions-rs/toolchain@v1 with: @@ -131,14 +115,6 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Load snarkOS - run: | - mkdir ~/.ssh - echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval $(ssh-agent -s) - ssh-add -k ~/.ssh/id_rsa - - name: Install Rust uses: actions-rs/toolchain@v1 with: diff --git a/.github/workflows/release-tests.yml b/.github/workflows/release-tests.yml index f97ee3384e..cec684f7da 100644 --- a/.github/workflows/release-tests.yml +++ b/.github/workflows/release-tests.yml @@ -15,14 +15,6 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Load snarkOS - run: | - mkdir ~/.ssh - echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval $(ssh-agent -s) - ssh-add -k ~/.ssh/id_rsa - - name: Install Rust uses: actions-rs/toolchain@v1 with: @@ -54,14 +46,6 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Load snarkOS - run: | - mkdir ~/.ssh - echo "${{ secrets.SNARKOS_DEPLOY_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - eval $(ssh-agent -s) - ssh-add -k ~/.ssh/id_rsa - - name: Install Rust uses: actions-rs/toolchain@v1 with: