From a3f5f5b71d6ee9c5553eefdb446a51d576d05fac Mon Sep 17 00:00:00 2001 From: weikeng Date: Wed, 28 Jul 2021 11:10:02 -0700 Subject: [PATCH 1/7] fix the missing assignment issue --- compiler/src/value/address/address.rs | 58 +++++++++++++++++++-------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/compiler/src/value/address/address.rs b/compiler/src/value/address/address.rs index f706448c4d..a9fd35a42a 100644 --- a/compiler/src/value/address/address.rs +++ b/compiler/src/value/address/address.rs @@ -85,33 +85,57 @@ impl Address { Ok(ConstrainedValue::Address(address)) } - pub(crate) fn alloc_helper Result, T: Borrow>( + pub(crate) fn alloc_helper< + F: PrimeField, + CS: ConstraintSystem, + Fn: FnOnce() -> Result, + T: Borrow, + >( + cs: CS, value_gen: Fn, ) -> Result, SynthesisError> { - let address_string = match value_gen() { - Ok(value) => { - let string_value = value.borrow().clone(); - Ok(string_value) - } - _ => Err(SynthesisError::AssignmentMissing), - }?; - - AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing) + if cs.is_in_setup_mode() { + Ok(AleoAddress::::default()) + } else { + let address_string = value_gen()?.borrow().clone(); + AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing) + } } } impl AllocGadget for Address { - fn alloc Result, T: Borrow, CS: ConstraintSystem>( - cs: CS, + fn alloc_constant Result, T: Borrow, CS: ConstraintSystem>( + _cs: CS, value_gen: Fn, ) -> Result { - let address = Self::alloc_helper(value_gen)?; + let address = { + let address_string = value_gen()?.borrow().clone(); + AleoAddress::from_str(&address_string).map_err(|_| SynthesisError::AssignmentMissing)? + }; let mut address_bytes = vec![]; address .write_le(&mut address_bytes) .map_err(|_| SynthesisError::AssignmentMissing)?; - let bytes = UInt8::alloc_vec(cs, &address_bytes[..])?; + let bytes = UInt8::constant_vec(&address_bytes[..]); + + Ok(Address { + address: Some(address), + bytes, + }) + } + + fn alloc Result, T: Borrow, CS: ConstraintSystem>( + mut cs: CS, + value_gen: Fn, + ) -> Result { + let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?; + let mut address_bytes = vec![]; + address + .write_le(&mut address_bytes) + .map_err(|_| SynthesisError::AssignmentMissing)?; + + let bytes = UInt8::alloc_vec(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?; Ok(Address { address: Some(address), @@ -120,16 +144,16 @@ impl AllocGadget for Address { } fn alloc_input Result, T: Borrow, CS: ConstraintSystem>( - cs: CS, + mut cs: CS, value_gen: Fn, ) -> Result { - let address = Self::alloc_helper(value_gen)?; + let address = Self::alloc_helper(cs.ns(|| "allocate the address"), value_gen)?; let mut address_bytes = vec![]; address .write_le(&mut address_bytes) .map_err(|_| SynthesisError::AssignmentMissing)?; - let bytes = UInt8::alloc_input_vec_le(cs, &address_bytes[..])?; + let bytes = UInt8::alloc_input_vec_le(cs.ns(|| "allocate the address bytes"), &address_bytes[..])?; Ok(Address { address: Some(address), From 6f03b9df261f8ac4bb207e0d33a4501e45213ce4 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Wed, 28 Jul 2021 16:33:14 -0700 Subject: [PATCH 2/7] [ABNF] Add a notion of lexeme. This is just for nomenclature. It does not change the language or anything. --- grammar/abnf-grammar.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/grammar/abnf-grammar.txt b/grammar/abnf-grammar.txt index 124a0f1f37..ee4dc083fa 100644 --- a/grammar/abnf-grammar.txt +++ b/grammar/abnf-grammar.txt @@ -611,6 +611,10 @@ token = keyword / annotation-name / symbol +; Tokens, comments, and whitespace are lexemes, i.e. lexical units. + +lexeme = token / comment / whitespace + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Syntactic Grammar From 70c6af11c5108c2addb8c3b0544a142f36f840ad Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Wed, 28 Jul 2021 16:33:44 -0700 Subject: [PATCH 3/7] [ABNF] Re-generated the markdown file. --- grammar/README.md | 76 +++++++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 33 deletions(-) diff --git a/grammar/README.md b/grammar/README.md index b22bd5ecf0..364002f1eb 100644 --- a/grammar/README.md +++ b/grammar/README.md @@ -511,7 +511,7 @@ rest-of-block-comment = "*" rest-of-block-comment-after-star / not-star rest-of-block-comment ``` -Go to: _[rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star](#user-content-not-star)_; +Go to: _[not-star](#user-content-not-star), [rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_; @@ -521,7 +521,7 @@ rest-of-block-comment-after-star = "/" / not-star-or-slash rest-of-block-comment ``` -Go to: _[not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment), [rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star)_; +Go to: _[rest-of-block-comment-after-star](#user-content-rest-of-block-comment-after-star), [not-star-or-slash](#user-content-not-star-or-slash), [rest-of-block-comment](#user-content-rest-of-block-comment)_; @@ -772,7 +772,7 @@ character-literal-element = not-single-quote-or-backslash / unicode-character-escape ``` -Go to: _[simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_; +Go to: _[unicode-character-escape](#user-content-unicode-character-escape), [simple-character-escape](#user-content-simple-character-escape), [not-single-quote-or-backslash](#user-content-not-single-quote-or-backslash), [ascii-character-escape](#user-content-ascii-character-escape)_; @@ -827,7 +827,7 @@ simple-character-escape = single-quote-escape / null-character-escape ``` -Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [single-quote-escape](#user-content-single-quote-escape), [backslash-escape](#user-content-backslash-escape), [line-feed-escape](#user-content-line-feed-escape), [horizontal-tab-escape](#user-content-horizontal-tab-escape), [null-character-escape](#user-content-null-character-escape), [double-quote-escape](#user-content-double-quote-escape)_; +Go to: _[horizontal-tab-escape](#user-content-horizontal-tab-escape), [backslash-escape](#user-content-backslash-escape), [null-character-escape](#user-content-null-character-escape), [line-feed-escape](#user-content-line-feed-escape), [single-quote-escape](#user-content-single-quote-escape), [double-quote-escape](#user-content-double-quote-escape), [carriage-return-escape](#user-content-carriage-return-escape)_; @@ -835,7 +835,7 @@ Go to: _[carriage-return-escape](#user-content-carriage-return-escape), [single- ascii-character-escape = %s"\x" octal-digit hexadecimal-digit ``` -Go to: _[hexadecimal-digit](#user-content-hexadecimal-digit), [octal-digit](#user-content-octal-digit)_; +Go to: _[octal-digit](#user-content-octal-digit), [hexadecimal-digit](#user-content-hexadecimal-digit)_; @@ -863,7 +863,7 @@ string-literal-element = not-double-quote-or-backslash / unicode-character-escape ``` -Go to: _[not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [unicode-character-escape](#user-content-unicode-character-escape), [ascii-character-escape](#user-content-ascii-character-escape)_; +Go to: _[not-double-quote-or-backslash](#user-content-not-double-quote-or-backslash), [simple-character-escape](#user-content-simple-character-escape), [ascii-character-escape](#user-content-ascii-character-escape), [unicode-character-escape](#user-content-unicode-character-escape)_; The ones above are all the atomic literals @@ -883,7 +883,7 @@ atomic-literal = untyped-literal / string-literal ``` -Go to: _[string-literal](#user-content-string-literal), [product-group-literal](#user-content-product-group-literal), [unsigned-literal](#user-content-unsigned-literal), [field-literal](#user-content-field-literal), [address-literal](#user-content-address-literal), [boolean-literal](#user-content-boolean-literal), [untyped-literal](#user-content-untyped-literal), [character-literal](#user-content-character-literal), [signed-literal](#user-content-signed-literal)_; +Go to: _[signed-literal](#user-content-signed-literal), [unsigned-literal](#user-content-unsigned-literal), [field-literal](#user-content-field-literal), [product-group-literal](#user-content-product-group-literal), [boolean-literal](#user-content-boolean-literal), [address-literal](#user-content-address-literal), [string-literal](#user-content-string-literal), [untyped-literal](#user-content-untyped-literal), [character-literal](#user-content-character-literal)_; After defining the (mostly) alphanumeric tokens above, @@ -927,7 +927,17 @@ token = keyword / symbol ``` -Go to: _[atomic-literal](#user-content-atomic-literal), [identifier](#user-content-identifier), [symbol](#user-content-symbol), [package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [keyword](#user-content-keyword)_; +Go to: _[atomic-literal](#user-content-atomic-literal), [package-name](#user-content-package-name), [annotation-name](#user-content-annotation-name), [symbol](#user-content-symbol), [identifier](#user-content-identifier), [keyword](#user-content-keyword)_; + + +Tokens, comments, and whitespace are lexemes, i.e. lexical units. + + +```abnf +lexeme = token / comment / whitespace +``` + +Go to: _[whitespace](#user-content-whitespace), [comment](#user-content-comment), [token](#user-content-token)_; @@ -984,7 +994,7 @@ group-type = %s"group" arithmetic-type = integer-type / field-type / group-type ``` -Go to: _[field-type](#user-content-field-type), [group-type](#user-content-group-type), [integer-type](#user-content-integer-type)_; +Go to: _[integer-type](#user-content-integer-type), [field-type](#user-content-field-type), [group-type](#user-content-group-type)_; The arithmetic types, along with the boolean, address, and character types, @@ -1050,7 +1060,7 @@ or a tuple of one or more dimensions. array-type = "[" type ";" array-dimensions "]" ``` -Go to: _[array-dimensions](#user-content-array-dimensions), [type](#user-content-type)_; +Go to: _[type](#user-content-type), [array-dimensions](#user-content-array-dimensions)_; @@ -1071,7 +1081,7 @@ i.e. types whose values contain (sub-)values aggregate-type = tuple-type / array-type / circuit-type ``` -Go to: _[tuple-type](#user-content-tuple-type), [array-type](#user-content-array-type), [circuit-type](#user-content-circuit-type)_; +Go to: _[circuit-type](#user-content-circuit-type), [tuple-type](#user-content-tuple-type), [array-type](#user-content-array-type)_; Scalar and aggregate types form all the types. @@ -1081,7 +1091,7 @@ Scalar and aggregate types form all the types. type = scalar-type / aggregate-type ``` -Go to: _[aggregate-type](#user-content-aggregate-type), [scalar-type](#user-content-scalar-type)_; +Go to: _[scalar-type](#user-content-scalar-type), [aggregate-type](#user-content-aggregate-type)_; The lexical grammar given earlier defines product group literals. @@ -1159,7 +1169,7 @@ primary-expression = identifier / circuit-expression ``` -Go to: _[tuple-expression](#user-content-tuple-expression), [literal](#user-content-literal), [expression](#user-content-expression), [circuit-expression](#user-content-circuit-expression), [identifier](#user-content-identifier), [array-expression](#user-content-array-expression)_; +Go to: _[expression](#user-content-expression), [array-expression](#user-content-array-expression), [literal](#user-content-literal), [identifier](#user-content-identifier), [circuit-expression](#user-content-circuit-expression), [tuple-expression](#user-content-tuple-expression)_; Tuple expressions construct tuples. @@ -1220,7 +1230,7 @@ Go to: _[expression](#user-content-expression), [array-dimensions](#user-content array-construction = array-inline-construction / array-repeat-construction ``` -Go to: _[array-repeat-construction](#user-content-array-repeat-construction), [array-inline-construction](#user-content-array-inline-construction)_; +Go to: _[array-inline-construction](#user-content-array-inline-construction), [array-repeat-construction](#user-content-array-repeat-construction)_; @@ -1248,7 +1258,7 @@ circuit-construction = circuit-type "{" "}" ``` -Go to: _[circuit-inline-element](#user-content-circuit-inline-element), [circuit-type](#user-content-circuit-type)_; +Go to: _[circuit-type](#user-content-circuit-type), [circuit-inline-element](#user-content-circuit-inline-element)_; @@ -1307,7 +1317,7 @@ postfix-expression = primary-expression / postfix-expression "[" [expression] ".." [expression] "]" ``` -Go to: _[circuit-type](#user-content-circuit-type), [postfix-expression](#user-content-postfix-expression), [primary-expression](#user-content-primary-expression), [identifier](#user-content-identifier), [function-arguments](#user-content-function-arguments), [natural](#user-content-natural), [expression](#user-content-expression)_; +Go to: _[natural](#user-content-natural), [identifier](#user-content-identifier), [circuit-type](#user-content-circuit-type), [primary-expression](#user-content-primary-expression), [function-arguments](#user-content-function-arguments), [postfix-expression](#user-content-postfix-expression), [expression](#user-content-expression)_; Unary operators have the highest operator precedence. @@ -1321,7 +1331,7 @@ unary-expression = postfix-expression / "-" unary-expression ``` -Go to: _[unary-expression](#user-content-unary-expression), [postfix-expression](#user-content-postfix-expression)_; +Go to: _[postfix-expression](#user-content-postfix-expression), [unary-expression](#user-content-unary-expression)_; Next in the operator precedence is exponentiation, @@ -1347,7 +1357,7 @@ multiplicative-expression = exponential-expression / multiplicative-expression "/" exponential-expression ``` -Go to: _[multiplicative-expression](#user-content-multiplicative-expression), [exponential-expression](#user-content-exponential-expression)_; +Go to: _[exponential-expression](#user-content-exponential-expression), [multiplicative-expression](#user-content-multiplicative-expression)_; Then there are addition and subtraction, both left-assocative. @@ -1359,7 +1369,7 @@ additive-expression = multiplicative-expression / additive-expression "-" multiplicative-expression ``` -Go to: _[multiplicative-expression](#user-content-multiplicative-expression), [additive-expression](#user-content-additive-expression)_; +Go to: _[additive-expression](#user-content-additive-expression), [multiplicative-expression](#user-content-multiplicative-expression)_; Next in the precedence order are ordering relations. @@ -1398,7 +1408,7 @@ conjunctive-expression = equality-expression / conjunctive-expression "&&" equality-expression ``` -Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [equality-expression](#user-content-equality-expression)_; +Go to: _[equality-expression](#user-content-equality-expression), [conjunctive-expression](#user-content-conjunctive-expression)_; Next come disjunctive expressions, left-associative. @@ -1409,7 +1419,7 @@ disjunctive-expression = conjunctive-expression / disjunctive-expression "||" conjunctive-expression ``` -Go to: _[disjunctive-expression](#user-content-disjunctive-expression), [conjunctive-expression](#user-content-conjunctive-expression)_; +Go to: _[conjunctive-expression](#user-content-conjunctive-expression), [disjunctive-expression](#user-content-disjunctive-expression)_; Finally we have conditional expressions. @@ -1422,7 +1432,7 @@ conditional-expression = disjunctive-expression ":" conditional-expression ``` -Go to: _[expression](#user-content-expression), [conditional-expression](#user-content-conditional-expression), [disjunctive-expression](#user-content-disjunctive-expression)_; +Go to: _[expression](#user-content-expression), [disjunctive-expression](#user-content-disjunctive-expression), [conditional-expression](#user-content-conditional-expression)_; Those above are all the expressions. @@ -1455,7 +1465,7 @@ statement = expression-statement / block ``` -Go to: _[assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [conditional-statement](#user-content-conditional-statement), [block](#user-content-block), [loop-statement](#user-content-loop-statement), [constant-declaration](#user-content-constant-declaration), [console-statement](#user-content-console-statement), [variable-declaration](#user-content-variable-declaration), [return-statement](#user-content-return-statement)_; +Go to: _[constant-declaration](#user-content-constant-declaration), [block](#user-content-block), [variable-declaration](#user-content-variable-declaration), [conditional-statement](#user-content-conditional-statement), [return-statement](#user-content-return-statement), [assignment-statement](#user-content-assignment-statement), [expression-statement](#user-content-expression-statement), [loop-statement](#user-content-loop-statement), [console-statement](#user-content-console-statement)_; @@ -1498,7 +1508,7 @@ variable-declaration = %s"let" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type)_; +Go to: _[type](#user-content-type), [expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers)_; @@ -1507,7 +1517,7 @@ constant-declaration = %s"const" identifier-or-identifiers [ ":" type ] "=" expression ";" ``` -Go to: _[type](#user-content-type), [expression](#user-content-expression), [identifier-or-identifiers](#user-content-identifier-or-identifiers)_; +Go to: _[identifier-or-identifiers](#user-content-identifier-or-identifiers), [type](#user-content-type), [expression](#user-content-expression)_; @@ -1530,7 +1540,7 @@ Note that blocks are required in all branches, not merely statements. branch = %s"if" expression block ``` -Go to: _[expression](#user-content-expression), [block](#user-content-block)_; +Go to: _[block](#user-content-block), [expression](#user-content-expression)_; @@ -1596,7 +1606,7 @@ console-call = assert-call / print-call ``` -Go to: _[print-call](#user-content-print-call), [assert-call](#user-content-assert-call)_; +Go to: _[assert-call](#user-content-assert-call), [print-call](#user-content-print-call)_; @@ -1638,7 +1648,7 @@ annotation = annotation-name [ "(" identifier *( "," identifier ) ")" ] ``` -Go to: _[identifier](#user-content-identifier), [annotation-name](#user-content-annotation-name)_; +Go to: _[annotation-name](#user-content-annotation-name), [identifier](#user-content-identifier)_; A function declaration defines a function. @@ -1655,7 +1665,7 @@ function-declaration = *annotation %s"function" identifier block ``` -Go to: _[type](#user-content-type), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters), [block](#user-content-block)_; +Go to: _[block](#user-content-block), [identifier](#user-content-identifier), [function-parameters](#user-content-function-parameters), [type](#user-content-type)_; @@ -1665,7 +1675,7 @@ function-parameters = self-parameter / function-inputs ``` -Go to: _[self-parameter](#user-content-self-parameter), [function-inputs](#user-content-function-inputs)_; +Go to: _[function-inputs](#user-content-function-inputs), [self-parameter](#user-content-self-parameter)_; @@ -1706,7 +1716,7 @@ member-variable-declarations = *( identifier ":" type ( "," / ";" ) ) identifier ":" type ( [ "," ] / ";" ) ``` -Go to: _[identifier](#user-content-identifier), [type](#user-content-type)_; +Go to: _[type](#user-content-type), [identifier](#user-content-identifier)_; A circuit member function declaration consists of a function declaration. @@ -1756,7 +1766,7 @@ by using an explicit package name before the package path. import-declaration = %s"import" package-name "." package-path ";" ``` -Go to: _[package-name](#user-content-package-name), [package-path](#user-content-package-path)_; +Go to: _[package-path](#user-content-package-path), [package-name](#user-content-package-name)_; @@ -1782,7 +1792,7 @@ declaration = import-declaration / constant-declaration ``` -Go to: _[circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [import-declaration](#user-content-import-declaration), [function-declaration](#user-content-function-declaration)_; +Go to: _[function-declaration](#user-content-function-declaration), [circuit-declaration](#user-content-circuit-declaration), [constant-declaration](#user-content-constant-declaration), [import-declaration](#user-content-import-declaration)_; From 39203492f84c9c2bd68de0bf631a8d6f81e54753 Mon Sep 17 00:00:00 2001 From: gluaxspeed Date: Wed, 28 Jul 2021 16:56:05 -0700 Subject: [PATCH 4/7] add tests for fixes --- tests/compiler/address/branch.leo | 15 +++++++++++++ tests/compiler/address/index.leo | 12 +++++++++++ tests/compiler/address/inputs/branch.in | 6 ++++++ tests/compiler/address/inputs/index.in | 5 +++++ .../compiler/compiler/address/branch.leo.out | 21 +++++++++++++++++++ .../compiler/compiler/address/index.leo.out | 21 +++++++++++++++++++ 6 files changed, 80 insertions(+) create mode 100644 tests/compiler/address/branch.leo create mode 100644 tests/compiler/address/index.leo create mode 100644 tests/compiler/address/inputs/branch.in create mode 100644 tests/compiler/address/inputs/index.in create mode 100644 tests/expectations/compiler/compiler/address/branch.leo.out create mode 100644 tests/expectations/compiler/compiler/address/index.leo.out diff --git a/tests/compiler/address/branch.leo b/tests/compiler/address/branch.leo new file mode 100644 index 0000000000..5b2023a43b --- /dev/null +++ b/tests/compiler/address/branch.leo @@ -0,0 +1,15 @@ +/* +namespace: Compile +expectation: Pass +input_file: inputs/branch.in +*/ + + +function main (x: address, y: bool) -> bool { + let z = aleo18cw5zdez3zhypev3tnfhmwvhre9ramwle4up947gcyy5rnmjw5yqn93wsr; + if y { + z = aleo1f2gs8g0qpumlgzpvmkw3q07y6xrwsdr0lqsu9h9fgnh8d7e44v9qhpgpkj; + } + + return z == aleo1f2gs8g0qpumlgzpvmkw3q07y6xrwsdr0lqsu9h9fgnh8d7e44v9qhpgpkj; +} \ No newline at end of file diff --git a/tests/compiler/address/index.leo b/tests/compiler/address/index.leo new file mode 100644 index 0000000000..5d7cb2b389 --- /dev/null +++ b/tests/compiler/address/index.leo @@ -0,0 +1,12 @@ +/* +namespace: Compile +expectation: Pass +input_file: inputs/index.in +*/ + +function main (x: u32) -> bool { + const y = [aleo1x0rh2cudq93fhukrsce8sgvcphddv4qs0clph64stpg0hstfds9qjvxcg6; 3]; + let z = y[x]; + + return z == y[0]; +} \ No newline at end of file diff --git a/tests/compiler/address/inputs/branch.in b/tests/compiler/address/inputs/branch.in new file mode 100644 index 0000000000..24e6b338e0 --- /dev/null +++ b/tests/compiler/address/inputs/branch.in @@ -0,0 +1,6 @@ +[main] +x: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8; +y: bool = true; + +[registers] +a: bool = false; \ No newline at end of file diff --git a/tests/compiler/address/inputs/index.in b/tests/compiler/address/inputs/index.in new file mode 100644 index 0000000000..5e701ee7a6 --- /dev/null +++ b/tests/compiler/address/inputs/index.in @@ -0,0 +1,5 @@ +[main] +x: u32 = 0; + +[registers] +a: bool = false; \ No newline at end of file diff --git a/tests/expectations/compiler/compiler/address/branch.leo.out b/tests/expectations/compiler/compiler/address/branch.leo.out new file mode 100644 index 0000000000..a4c062bc76 --- /dev/null +++ b/tests/expectations/compiler/compiler/address/branch.leo.out @@ -0,0 +1,21 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - circuit: + num_public_variables: 0 + num_private_variables: 1024 + num_constraints: 1536 + at: 5afd1d58b6826912fe5cba06b60d9a7debdbad9e922b8a78ed49f7a7ca0ac65e + bt: db77c3470cf1b3c80c2e3b1b3ddc59d9891912489bfcf39b7f67c2f314ca7f6d + ct: d0993682df5b495f4a6784882e0f007dbc378adb35007d250e2c098975f4d32e + output: + - input_file: inputs/branch.in + output: + registers: + a: + type: bool + value: "true" + initial_ast: a7748573e4731753b76889c6d4c28e9589e114860a163da87957cf20b916f733 + canonicalized_ast: a7748573e4731753b76889c6d4c28e9589e114860a163da87957cf20b916f733 + type_inferenced_ast: af3663710ad6278c3d2e28a753d62084505746cd49de11949fe5e8e390ffcc60 diff --git a/tests/expectations/compiler/compiler/address/index.leo.out b/tests/expectations/compiler/compiler/address/index.leo.out new file mode 100644 index 0000000000..b4cda33ee6 --- /dev/null +++ b/tests/expectations/compiler/compiler/address/index.leo.out @@ -0,0 +1,21 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - circuit: + num_public_variables: 0 + num_private_variables: 1694 + num_constraints: 2719 + at: f9a9bc8304df327c7b16f088b61ac518fb3a7b6457ccc35a1ab9eab4565a1981 + bt: 045eba0fdd405714f788492fd5914b053e0ece622e9a542270d8cfe85c0ee291 + ct: e8fa4a33a657c70a7cecc7e9b284157b369b7ea57879948e108daf93e778551c + output: + - input_file: inputs/index.in + output: + registers: + a: + type: bool + value: "true" + initial_ast: 8934e4c1d645f6f98fe59f48bbf687623e811c99e504e87c6989bc00af62194a + canonicalized_ast: 8934e4c1d645f6f98fe59f48bbf687623e811c99e504e87c6989bc00af62194a + type_inferenced_ast: 70af835aeaec1d5bc1c4a3186635260ff44743e0d3a7aa5ac9f2c98ec03bd23e From a9a684ef2b4541fcf6ae430c766597f9706ff069 Mon Sep 17 00:00:00 2001 From: damirka Date: Mon, 2 Aug 2021 18:25:12 +0300 Subject: [PATCH 5/7] adds self canonicalization for static calls --- ast/src/reducer/canonicalization.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index edf300ada4..76aca34838 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -276,6 +276,11 @@ impl Canonicalizer { span: call.span.clone(), }); } + Expression::Identifier(identifier) => { + if identifier.name.as_ref() == "Self" && self.circuit_name.is_some() { + return Expression::Identifier(self.circuit_name.as_ref().unwrap().clone()); + } + } _ => {} } From 34f1c00da27504ebc47c5376636fb482c03b42ec Mon Sep 17 00:00:00 2001 From: damirka Date: Mon, 2 Aug 2021 23:45:33 +0300 Subject: [PATCH 6/7] clippy & test fixes --- ast/src/reducer/canonicalization.rs | 6 +- ast/src/reducer/reconstructing_director.rs | 70 +++++++++---------- ast/src/types/type_.rs | 4 +- input/src/errors/parser.rs | 2 +- input/src/values/group_coordinate.rs | 2 +- input/src/values/value.rs | 6 +- parser/examples/parser.rs | 2 +- parser/src/parser/file.rs | 2 +- parser/src/parser/statement.rs | 2 +- parser/src/tokenizer/lexer.rs | 4 +- .../member_static_function_nested.leo.out | 4 +- 11 files changed, 50 insertions(+), 54 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 76aca34838..0e14208fc1 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -47,7 +47,7 @@ impl Canonicalizer { let mut left = Box::new(start); for access in accesses.iter() { - match self.canonicalize_assignee_access(&access) { + match self.canonicalize_assignee_access(access) { AssigneeAccess::ArrayIndex(index) => { left = Box::new(Expression::ArrayAccess(ArrayAccessExpression { array: left, @@ -295,7 +295,7 @@ impl Canonicalizer { AssigneeAccess::ArrayRange(left, right) } - AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(&index)), + AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.canonicalize_expression(index)), _ => access.clone(), } } @@ -318,7 +318,7 @@ impl Canonicalizer { let statements = block .statements .iter() - .map(|block_statement| self.canonicalize_statement(&block_statement)) + .map(|block_statement| self.canonicalize_statement(block_statement)) .collect(); Block { diff --git a/ast/src/reducer/reconstructing_director.rs b/ast/src/reducer/reconstructing_director.rs index cf5a409d06..d7710df122 100644 --- a/ast/src/reducer/reconstructing_director.rs +++ b/ast/src/reducer/reconstructing_director.rs @@ -50,34 +50,32 @@ impl ReconstructingDirector { // Expressions pub fn reduce_expression(&mut self, expression: &Expression) -> Result { let new = match expression { - Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(&identifier)?), - Expression::Value(value) => self.reduce_value(&value)?, - Expression::Binary(binary) => Expression::Binary(self.reduce_binary(&binary)?), - Expression::Unary(unary) => Expression::Unary(self.reduce_unary(&unary)?), - Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(&ternary)?), - Expression::Cast(cast) => Expression::Cast(self.reduce_cast(&cast)?), + Expression::Identifier(identifier) => Expression::Identifier(self.reduce_identifier(identifier)?), + Expression::Value(value) => self.reduce_value(value)?, + Expression::Binary(binary) => Expression::Binary(self.reduce_binary(binary)?), + Expression::Unary(unary) => Expression::Unary(self.reduce_unary(unary)?), + Expression::Ternary(ternary) => Expression::Ternary(self.reduce_ternary(ternary)?), + Expression::Cast(cast) => Expression::Cast(self.reduce_cast(cast)?), - Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(&array_inline)?), - Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(&array_init)?), - Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(&array_access)?), + Expression::ArrayInline(array_inline) => Expression::ArrayInline(self.reduce_array_inline(array_inline)?), + Expression::ArrayInit(array_init) => Expression::ArrayInit(self.reduce_array_init(array_init)?), + Expression::ArrayAccess(array_access) => Expression::ArrayAccess(self.reduce_array_access(array_access)?), Expression::ArrayRangeAccess(array_range_access) => { - Expression::ArrayRangeAccess(self.reduce_array_range_access(&array_range_access)?) + Expression::ArrayRangeAccess(self.reduce_array_range_access(array_range_access)?) } - Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(&tuple_init)?), - Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(&tuple_access)?), + Expression::TupleInit(tuple_init) => Expression::TupleInit(self.reduce_tuple_init(tuple_init)?), + Expression::TupleAccess(tuple_access) => Expression::TupleAccess(self.reduce_tuple_access(tuple_access)?), - Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(&circuit_init)?), + Expression::CircuitInit(circuit_init) => Expression::CircuitInit(self.reduce_circuit_init(circuit_init)?), Expression::CircuitMemberAccess(circuit_member_access) => { - Expression::CircuitMemberAccess(self.reduce_circuit_member_access(&circuit_member_access)?) + Expression::CircuitMemberAccess(self.reduce_circuit_member_access(circuit_member_access)?) } Expression::CircuitStaticFunctionAccess(circuit_static_fn_access) => { - Expression::CircuitStaticFunctionAccess( - self.reduce_circuit_static_fn_access(&circuit_static_fn_access)?, - ) + Expression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(circuit_static_fn_access)?) } - Expression::Call(call) => Expression::Call(self.reduce_call(&call)?), + Expression::Call(call) => Expression::Call(self.reduce_call(call)?), }; self.reducer.reduce_expression(expression, new) @@ -93,7 +91,7 @@ impl ReconstructingDirector { pub fn reduce_group_value(&mut self, group_value: &GroupValue) -> Result { let new = match group_value { - GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(&group_tuple)?), + GroupValue::Tuple(group_tuple) => GroupValue::Tuple(self.reduce_group_tuple(group_tuple)?), _ => group_value.clone(), }; @@ -107,9 +105,9 @@ impl ReconstructingDirector { pub fn reduce_value(&mut self, value: &ValueExpression) -> Result { let new = match value { ValueExpression::Group(group_value) => { - Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(&group_value)?))) + Expression::Value(ValueExpression::Group(Box::new(self.reduce_group_value(group_value)?))) } - ValueExpression::String(string, span) => self.reduce_string(string, &span)?, + ValueExpression::String(string, span) => self.reduce_string(string, span)?, _ => Expression::Value(value.clone()), }; @@ -284,14 +282,14 @@ impl ReconstructingDirector { // Statements pub fn reduce_statement(&mut self, statement: &Statement) -> Result { let new = match statement { - Statement::Return(return_statement) => Statement::Return(self.reduce_return(&return_statement)?), - Statement::Definition(definition) => Statement::Definition(self.reduce_definition(&definition)?), - Statement::Assign(assign) => Statement::Assign(self.reduce_assign(&assign)?), - Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(&conditional)?), - Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(&iteration)?), - Statement::Console(console) => Statement::Console(self.reduce_console(&console)?), - Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(&expression)?), - Statement::Block(block) => Statement::Block(self.reduce_block(&block)?), + Statement::Return(return_statement) => Statement::Return(self.reduce_return(return_statement)?), + Statement::Definition(definition) => Statement::Definition(self.reduce_definition(definition)?), + Statement::Assign(assign) => Statement::Assign(self.reduce_assign(assign)?), + Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(conditional)?), + Statement::Iteration(iteration) => Statement::Iteration(self.reduce_iteration(iteration)?), + Statement::Console(console) => Statement::Console(self.reduce_console(console)?), + Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(expression)?), + Statement::Block(block) => Statement::Block(self.reduce_block(block)?), }; self.reducer.reduce_statement(statement, new) @@ -334,8 +332,8 @@ impl ReconstructingDirector { AssigneeAccess::ArrayRange(left, right) } - AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(&index)?), - AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(&identifier)?), + AssigneeAccess::ArrayIndex(index) => AssigneeAccess::ArrayIndex(self.reduce_expression(index)?), + AssigneeAccess::Member(identifier) => AssigneeAccess::Member(self.reduce_identifier(identifier)?), _ => access.clone(), }; @@ -456,7 +454,7 @@ impl ReconstructingDirector { let mut global_consts = IndexMap::new(); for (name, definition) in program.global_consts.iter() { - global_consts.insert(name.clone(), self.reduce_definition(&definition)?); + global_consts.insert(name.clone(), self.reduce_definition(definition)?); } self.reducer @@ -513,12 +511,10 @@ impl ReconstructingDirector { pub fn reduce_circuit_member(&mut self, circuit_member: &CircuitMember) -> Result { let new = match circuit_member { CircuitMember::CircuitVariable(identifier, type_) => CircuitMember::CircuitVariable( - self.reduce_identifier(&identifier)?, - self.reduce_type(&type_, &identifier.span)?, + self.reduce_identifier(identifier)?, + self.reduce_type(type_, &identifier.span)?, ), - CircuitMember::CircuitFunction(function) => { - CircuitMember::CircuitFunction(self.reduce_function(&function)?) - } + CircuitMember::CircuitFunction(function) => CircuitMember::CircuitFunction(self.reduce_function(function)?), }; self.reducer.reduce_circuit_member(circuit_member, new) diff --git a/ast/src/types/type_.rs b/ast/src/types/type_.rs index fb4ad87522..abc29f475f 100644 --- a/ast/src/types/type_.rs +++ b/ast/src/types/type_.rs @@ -70,8 +70,8 @@ impl Type { (Type::Char, Type::Char) => true, (Type::Field, Type::Field) => true, (Type::Group, Type::Group) => true, - (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(&right), - (Type::Circuit(left), Type::Circuit(right)) => left.eq(&right), + (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), + (Type::Circuit(left), Type::Circuit(right)) => left.eq(right), (Type::SelfType, Type::SelfType) => true, (Type::Array(left_type, left_dim), Type::Array(right_type, right_dim)) => { // Convert array dimensions to owned. diff --git a/input/src/errors/parser.rs b/input/src/errors/parser.rs index 215dd7382c..cca4dc850a 100644 --- a/input/src/errors/parser.rs +++ b/input/src/errors/parser.rs @@ -191,7 +191,7 @@ impl InputParserError { expected, actual ); - Self::new_from_span(message, &span) + Self::new_from_span(message, span) } pub fn section(header: Header) -> Self { diff --git a/input/src/values/group_coordinate.rs b/input/src/values/group_coordinate.rs index 8a4882c39c..70217b85cf 100644 --- a/input/src/values/group_coordinate.rs +++ b/input/src/values/group_coordinate.rs @@ -32,7 +32,7 @@ pub enum GroupCoordinate<'ast> { impl<'ast> GroupCoordinate<'ast> { pub fn span(&self) -> &Span<'ast> { match self { - GroupCoordinate::Number(number) => &number.span(), + GroupCoordinate::Number(number) => number.span(), GroupCoordinate::SignHigh(sign_high) => &sign_high.span, GroupCoordinate::SignLow(sign_low) => &sign_low.span, GroupCoordinate::Inferred(inferred) => &inferred.span, diff --git a/input/src/values/value.rs b/input/src/values/value.rs index 0c3ccfe5e9..993d5ee04b 100644 --- a/input/src/values/value.rs +++ b/input/src/values/value.rs @@ -39,13 +39,13 @@ pub enum Value<'ast> { impl<'ast> Value<'ast> { pub fn span(&self) -> &Span<'ast> { match self { - Value::Address(value) => &value.span(), + Value::Address(value) => value.span(), Value::Boolean(value) => &value.span, Value::Char(value) => &value.span, Value::Field(value) => &value.span, Value::Group(value) => &value.span, - Value::Implicit(value) => &value.span(), - Value::Integer(value) => &value.span(), + Value::Implicit(value) => value.span(), + Value::Integer(value) => value.span(), } } } diff --git a/parser/examples/parser.rs b/parser/examples/parser.rs index bd6c8f477a..2c7788f49c 100644 --- a/parser/examples/parser.rs +++ b/parser/examples/parser.rs @@ -48,7 +48,7 @@ fn main() -> Result<(), SyntaxError> { let input_filepath = Path::new(&cli_arguments[1]); // Construct the serialized syntax tree. - let serialized_leo_tree = to_leo_tree(&input_filepath)?; + let serialized_leo_tree = to_leo_tree(input_filepath)?; println!("{}", serialized_leo_tree); // Determine the output directory. diff --git a/parser/src/parser/file.rs b/parser/src/parser/file.rs index 80abacaddb..8b15b09f39 100644 --- a/parser/src/parser/file.rs +++ b/parser/src/parser/file.rs @@ -227,7 +227,7 @@ impl ParserContext { base.name = format_tendril!("{}{}", base.name, next.name); base.span = base.span + next.span; } - x if KEYWORD_TOKENS.contains(&x) => { + x if KEYWORD_TOKENS.contains(x) => { let next = self.expect_loose_identifier()?; base.name = format_tendril!("{}{}", base.name, next.name); base.span = base.span + next.span; diff --git a/parser/src/parser/statement.rs b/parser/src/parser/statement.rs index 1b82145f43..1448dad6bc 100644 --- a/parser/src/parser/statement.rs +++ b/parser/src/parser/statement.rs @@ -281,7 +281,7 @@ impl ParserContext { "log" => ConsoleFunction::Log(self.parse_console_args()?), x => { return Err(SyntaxError::unexpected_ident( - &x, + x, &["assert", "error", "log"], &function.span, )); diff --git a/parser/src/tokenizer/lexer.rs b/parser/src/tokenizer/lexer.rs index cf9b452e9b..0b573409bb 100644 --- a/parser/src/tokenizer/lexer.rs +++ b/parser/src/tokenizer/lexer.rs @@ -101,7 +101,7 @@ impl Token { return None; } - if let Ok(ascii_number) = u8::from_str_radix(&hex_string, 16) { + if let Ok(ascii_number) = u8::from_str_radix(hex_string, 16) { // According to RFC, we allow only values less than 128. if ascii_number > 127 { return None; @@ -123,7 +123,7 @@ impl Token { return None; } - if let Ok(hex) = u32::from_str_radix(&unicode_number, 16) { + if let Ok(hex) = u32::from_str_radix(unicode_number, 16) { if let Some(character) = std::char::from_u32(hex) { // scalar return Some(Char::Scalar(character)); diff --git a/tests/expectations/compiler/compiler/circuits/member_static_function_nested.leo.out b/tests/expectations/compiler/compiler/circuits/member_static_function_nested.leo.out index 8e891e6ac9..14f7a27016 100644 --- a/tests/expectations/compiler/compiler/circuits/member_static_function_nested.leo.out +++ b/tests/expectations/compiler/compiler/circuits/member_static_function_nested.leo.out @@ -17,5 +17,5 @@ outputs: type: bool value: "true" initial_ast: 4c74b65863cddde8ce523495358ab619ec48645dcb8409658a3fb3d7a3821d6d - canonicalized_ast: b5697d5884139da5a68861213ff3c7660f694e682078e1bd350856206e0289b8 - type_inferenced_ast: ff4b8f91f014277d6bb2d8d82c31361e5a5c5a46ed87a1e61f0c2e2e8d5fd254 + canonicalized_ast: 45dc35a683e14503f8a1fc40280f05e7d096b49896f115ffa649e76b9cd80941 + type_inferenced_ast: 11af72cfc90adc12c3412e3067ad285a2279de0f4f12af5081dbe27c58b5a3bf From 82f8e8a5cab0c3cc41af1df78ec2caa112d33630 Mon Sep 17 00:00:00 2001 From: damirka Date: Tue, 3 Aug 2021 01:46:18 +0300 Subject: [PATCH 7/7] clippy fixes --- asg/src/const_value.rs | 20 ++++---- asg/src/expression/constant.rs | 6 +-- asg/src/expression/mod.rs | 2 +- asg/src/program/function.rs | 2 +- asg/src/program/mod.rs | 2 +- asg/src/reducer/monoidal_director.rs | 2 +- asg/src/statement/assign.rs | 18 ++++---- asg/src/statement/block.rs | 2 +- asg/src/statement/definition.rs | 2 +- compiler/src/compiler.rs | 8 ++-- compiler/src/constraints/constraints.rs | 2 +- compiler/src/expression/array/access.rs | 2 +- compiler/src/expression/function/function.rs | 2 +- .../src/function/input/main_function_input.rs | 2 +- compiler/src/function/main_function.rs | 2 +- compiler/src/function/result/result.rs | 4 +- compiler/src/phases/reducing_director.rs | 46 +++++++++---------- .../statement/assign/assignee/array_index.rs | 8 ++-- .../src/statement/conditional/conditional.rs | 2 +- compiler/src/value/value.rs | 2 +- imports/src/parser/parse_symbol.rs | 2 +- leo/config.rs | 4 +- leo/updater.rs | 4 +- package/src/package.rs | 36 +++++++-------- 24 files changed, 91 insertions(+), 91 deletions(-) diff --git a/asg/src/const_value.rs b/asg/src/const_value.rs index d430f0bbc4..cfe091f749 100644 --- a/asg/src/const_value.rs +++ b/asg/src/const_value.rs @@ -315,16 +315,16 @@ impl ConstInt { pub fn parse(int_type: &IntegerType, value: &str, span: &Span) -> Result { Ok(match int_type { - IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), - IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + IntegerType::I8 => ConstInt::I8(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::I16 => ConstInt::I16(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::I32 => ConstInt::I32(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::I64 => ConstInt::I64(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::I128 => ConstInt::I128(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::U8 => ConstInt::U8(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::U16 => ConstInt::U16(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::U32 => ConstInt::U32(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::U64 => ConstInt::U64(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), + IntegerType::U128 => ConstInt::U128(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), }) } } diff --git a/asg/src/expression/constant.rs b/asg/src/expression/constant.rs index 8fb638974a..ae50b01071 100644 --- a/asg/src/expression/constant.rs +++ b/asg/src/expression/constant.rs @@ -115,7 +115,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { value: ConstValue::Boolean( value .parse::() - .map_err(|_| AsgConvertError::invalid_boolean(&value, span))?, + .map_err(|_| AsgConvertError::invalid_boolean(value, span))?, ), } } @@ -151,7 +151,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { Constant { parent: Cell::new(None), span: Some(span.clone()), - value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), } } Group(value) => { @@ -188,7 +188,7 @@ impl<'a> FromAst<'a, leo_ast::ValueExpression> for Constant<'a> { Some(PartialType::Type(Type::Field)) => Constant { parent: Cell::new(None), span: Some(span.clone()), - value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(&value, span))?), + value: ConstValue::Field(value.parse().map_err(|_| AsgConvertError::invalid_int(value, span))?), }, Some(PartialType::Type(Type::Group)) => Constant { parent: Cell::new(None), diff --git a/asg/src/expression/mod.rs b/asg/src/expression/mod.rs index 4778e3b6a6..60c9d3f47c 100644 --- a/asg/src/expression/mod.rs +++ b/asg/src/expression/mod.rs @@ -341,7 +341,7 @@ impl<'a> FromAst<'a, leo_ast::Expression> for &'a Expression<'a> { .context .alloc_expression(CallExpression::from_ast(scope, call, expected_type).map(Expression::Call)?), }; - expression.enforce_parents(&expression); + expression.enforce_parents(expression); Ok(expression) } } diff --git a/asg/src/program/function.rs b/asg/src/program/function.rs index bf89b0020f..91b8a223f3 100644 --- a/asg/src/program/function.rs +++ b/asg/src/program/function.rs @@ -101,7 +101,7 @@ impl<'a> Function<'a> { let variable = scope.context.alloc_variable(RefCell::new(crate::InnerVariable { id: scope.context.get_id(), name: identifier.clone(), - type_: scope.resolve_ast_type(&type_)?, + type_: scope.resolve_ast_type(type_)?, mutable: *mutable, const_: *const_, declaration: crate::VariableDeclaration::Parameter, diff --git a/asg/src/program/mod.rs b/asg/src/program/mod.rs index d6c00ef7e3..998f5928c5 100644 --- a/asg/src/program/mod.rs +++ b/asg/src/program/mod.rs @@ -127,7 +127,7 @@ fn resolve_import_package_access( PackageAccess::Multiple(packages) => { package_segments.push(packages.name.name.to_string()); for subaccess in packages.accesses.iter() { - resolve_import_package_access(output, package_segments.clone(), &subaccess); + resolve_import_package_access(output, package_segments.clone(), subaccess); } } } diff --git a/asg/src/reducer/monoidal_director.rs b/asg/src/reducer/monoidal_director.rs index 161183a19b..858a1bb256 100644 --- a/asg/src/reducer/monoidal_director.rs +++ b/asg/src/reducer/monoidal_director.rs @@ -308,6 +308,6 @@ impl<'a, T: Monoid, R: MonoidalReducerProgram<'a, T>> MonoidalDirector<'a, T, R> let circuits = input.circuits.iter().map(|(_, c)| self.reduce_circuit(c)).collect(); self.reducer - .reduce_program(&input, imported_modules, functions, circuits) + .reduce_program(input, imported_modules, functions, circuits) } } diff --git a/asg/src/statement/assign.rs b/asg/src/statement/assign.rs index e1f44b8210..1f3357d884 100644 --- a/asg/src/statement/assign.rs +++ b/asg/src/statement/assign.rs @@ -79,12 +79,12 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { } } else { scope - .resolve_variable(&name) - .ok_or_else(|| AsgConvertError::unresolved_reference(name, &span))? + .resolve_variable(name) + .ok_or_else(|| AsgConvertError::unresolved_reference(name, span))? }; if !variable.borrow().mutable { - return Err(AsgConvertError::immutable_assignment(&name, &statement.span)); + return Err(AsgConvertError::immutable_assignment(name, &statement.span)); } let mut target_type: Option = Some(variable.borrow().type_.clone().into()); @@ -123,13 +123,13 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { ) { let left = match left { ConstValue::Int(x) => x.to_usize().ok_or_else(|| { - AsgConvertError::invalid_assign_index(&name, &x.to_string(), &statement.span) + AsgConvertError::invalid_assign_index(name, &x.to_string(), &statement.span) })?, _ => unimplemented!(), }; let right = match right { ConstValue::Int(x) => x.to_usize().ok_or_else(|| { - AsgConvertError::invalid_assign_index(&name, &x.to_string(), &statement.span) + AsgConvertError::invalid_assign_index(name, &x.to_string(), &statement.span) })?, _ => unimplemented!(), }; @@ -137,7 +137,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { target_type = Some(PartialType::Array(item.clone(), Some((right - left) as usize))) } else { return Err(AsgConvertError::invalid_backwards_assignment( - &name, + name, left, right, &statement.span, @@ -145,7 +145,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { } } } - _ => return Err(AsgConvertError::index_into_non_array(&name, &statement.span)), + _ => return Err(AsgConvertError::index_into_non_array(name, &statement.span)), } AssignAccess::ArrayRange(Cell::new(left), Cell::new(right)) @@ -153,7 +153,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { AstAssigneeAccess::ArrayIndex(index) => { target_type = match target_type.clone() { Some(PartialType::Array(item, _)) => item.map(|x| *x), - _ => return Err(AsgConvertError::index_into_non_array(&name, &statement.span)), + _ => return Err(AsgConvertError::index_into_non_array(name, &statement.span)), }; AssignAccess::ArrayIndex(Cell::new(<&Expression<'a>>::from_ast( scope, @@ -171,7 +171,7 @@ impl<'a> FromAst<'a, leo_ast::AssignStatement> for &'a Statement<'a> { .get(index) .cloned() .ok_or_else(|| AsgConvertError::tuple_index_out_of_bounds(index, &statement.span))?, - _ => return Err(AsgConvertError::index_into_non_tuple(&name, &statement.span)), + _ => return Err(AsgConvertError::index_into_non_tuple(name, &statement.span)), }; AssignAccess::Tuple(index) } diff --git a/asg/src/statement/block.rs b/asg/src/statement/block.rs index 9a64fcdfb9..2b50d0c3df 100644 --- a/asg/src/statement/block.rs +++ b/asg/src/statement/block.rs @@ -42,7 +42,7 @@ impl<'a> FromAst<'a, leo_ast::Block> for BlockStatement<'a> { let mut output = vec![]; for item in statement.statements.iter() { - output.push(Cell::new(<&'a Statement<'a>>::from_ast(&new_scope, item, None)?)); + output.push(Cell::new(<&'a Statement<'a>>::from_ast(new_scope, item, None)?)); } Ok(BlockStatement { parent: Cell::new(None), diff --git a/asg/src/statement/definition.rs b/asg/src/statement/definition.rs index f340052409..54bdf50b4f 100644 --- a/asg/src/statement/definition.rs +++ b/asg/src/statement/definition.rs @@ -70,7 +70,7 @@ impl<'a> FromAst<'a, leo_ast::DefinitionStatement> for &'a Statement<'a> { let type_ = statement .type_ .as_ref() - .map(|x| scope.resolve_ast_type(&x)) + .map(|x| scope.resolve_ast_type(x)) .transpose()?; let value = <&Expression<'a>>::from_ast(scope, &statement.value, type_.clone().map(Into::into))?; diff --git a/compiler/src/compiler.rs b/compiler/src/compiler.rs index 34e55b7a7f..5efb919e2a 100644 --- a/compiler/src/compiler.rs +++ b/compiler/src/compiler.rs @@ -181,7 +181,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { state_string: &str, state_path: &Path, ) -> Result<(), CompilerError> { - let input_syntax_tree = LeoInputParser::parse_file(&input_string).map_err(|mut e| { + let input_syntax_tree = LeoInputParser::parse_file(input_string).map_err(|mut e| { e.set_path( input_path.to_str().unwrap_or_default(), &input_string.lines().map(|x| x.to_string()).collect::>()[..], @@ -189,7 +189,7 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { e })?; - let state_syntax_tree = LeoInputParser::parse_file(&state_string).map_err(|mut e| { + let state_syntax_tree = LeoInputParser::parse_file(state_string).map_err(|mut e| { e.set_path( state_path.to_str().unwrap_or_default(), &state_string.lines().map(|x| x.to_string()).collect::>()[..], @@ -308,14 +308,14 @@ impl<'a, F: PrimeField, G: GroupType> Compiler<'a, F, G> { /// Synthesizes the circuit with program input to verify correctness. /// pub fn compile_constraints>(&self, cs: &mut CS) -> Result { - generate_constraints::(cs, &self.asg.as_ref().unwrap(), &self.program_input) + generate_constraints::(cs, self.asg.as_ref().unwrap(), &self.program_input) } /// /// Synthesizes the circuit for test functions with program input. /// pub fn compile_test_constraints(self, input_pairs: InputPairs) -> Result<(u32, u32), CompilerError> { - generate_test_constraints::(&self.asg.as_ref().unwrap(), input_pairs, &self.output_directory) + generate_test_constraints::(self.asg.as_ref().unwrap(), input_pairs, &self.output_directory) } /// diff --git a/compiler/src/constraints/constraints.rs b/compiler/src/constraints/constraints.rs index 6d256dea96..4e34b4c096 100644 --- a/compiler/src/constraints/constraints.rs +++ b/compiler/src/constraints/constraints.rs @@ -44,7 +44,7 @@ pub fn generate_constraints<'a, F: PrimeField, G: GroupType, CS: ConstraintSy match main { Some(function) => { - let result = resolved_program.enforce_main_function(cs, &function, input)?; + let result = resolved_program.enforce_main_function(cs, function, input)?; Ok(result) } _ => Err(CompilerError::NoMainFunction), diff --git a/compiler/src/expression/array/access.rs b/compiler/src/expression/array/access.rs index 11009dbd64..0fd6e7f5fb 100644 --- a/compiler/src/expression/array/access.rs +++ b/compiler/src/expression/array/access.rs @@ -94,7 +94,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .len() .try_into() .map_err(|_| ExpressionError::array_length_out_of_bounds(span))?; - self.array_bounds_check(cs, &&index_resolved, array_len, span)?; + self.array_bounds_check(cs, &index_resolved, array_len, span)?; } let mut current_value = array.pop().unwrap(); diff --git a/compiler/src/expression/function/function.rs b/compiler/src/expression/function/function.rs index e67700d7a8..58f2f0b3d4 100644 --- a/compiler/src/expression/function/function.rs +++ b/compiler/src/expression/function/function.rs @@ -44,7 +44,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { }; let return_value = self - .enforce_function(&mut cs.ns(name_unique), &function, target, arguments) + .enforce_function(&mut cs.ns(name_unique), function, target, arguments) .map_err(|error| ExpressionError::from(Box::new(error)))?; Ok(return_value) diff --git a/compiler/src/function/input/main_function_input.rs b/compiler/src/function/input/main_function_input.rs index 75379676fe..ec55db0a92 100644 --- a/compiler/src/function/input/main_function_input.rs +++ b/compiler/src/function/input/main_function_input.rs @@ -62,7 +62,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { span, )?)), Type::Array(type_, len) => self.allocate_array(cs, name, &*type_, *len, input_option, span), - Type::Tuple(types) => self.allocate_tuple(cs, &name, types, input_option, span), + Type::Tuple(types) => self.allocate_tuple(cs, name, types, input_option, span), _ => unimplemented!("main function input not implemented for type {}", type_), // Should not happen. } } diff --git a/compiler/src/function/main_function.rs b/compiler/src/function/main_function.rs index 8fe7e3a635..2e615924dc 100644 --- a/compiler/src/function/main_function.rs +++ b/compiler/src/function/main_function.rs @@ -39,7 +39,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if let Some(asg_input) = asg_input { let value = - self.allocate_input_keyword(cs, &function.name.borrow().span, &asg_input.container_circuit, input)?; + self.allocate_input_keyword(cs, &function.name.borrow().span, asg_input.container_circuit, input)?; self.store(asg_input.container.borrow().id, value); } diff --git a/compiler/src/function/result/result.rs b/compiler/src/function/result/result.rs index a0f71b896c..395cf39adb 100644 --- a/compiler/src/function/result/result.rs +++ b/compiler/src/function/result/result.rs @@ -82,7 +82,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { cs.ns(|| format!("select result {} {}:{}", i, span.line_start, span.col_start)), &indicator, &result, - &value, + value, ) .map_err(|_| StatementError::select_fail(result.to_string(), value.to_string(), span))?, ); @@ -94,7 +94,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { if expected_return.is_unit() { Ok(ConstrainedValue::Tuple(vec![])) } else { - return_value.ok_or_else(|| StatementError::no_returns(&expected_return, span)) + return_value.ok_or_else(|| StatementError::no_returns(expected_return, span)) } } } diff --git a/compiler/src/phases/reducing_director.rs b/compiler/src/phases/reducing_director.rs index 2a934909a8..6cec43764d 100644 --- a/compiler/src/phases/reducing_director.rs +++ b/compiler/src/phases/reducing_director.rs @@ -155,49 +155,49 @@ impl CombineAstAsgDirector { asg: &AsgExpression, ) -> Result { let new = match (ast, asg) { - (AstExpression::Value(value), AsgExpression::Constant(const_)) => self.reduce_value(&value, &const_)?, + (AstExpression::Value(value), AsgExpression::Constant(const_)) => self.reduce_value(value, const_)?, (AstExpression::Binary(ast), AsgExpression::Binary(asg)) => { - AstExpression::Binary(self.reduce_binary(&ast, &asg)?) + AstExpression::Binary(self.reduce_binary(ast, asg)?) } (AstExpression::Unary(ast), AsgExpression::Unary(asg)) => { - AstExpression::Unary(self.reduce_unary(&ast, &asg)?) + AstExpression::Unary(self.reduce_unary(ast, asg)?) } (AstExpression::Ternary(ast), AsgExpression::Ternary(asg)) => { - AstExpression::Ternary(self.reduce_ternary(&ast, &asg)?) + AstExpression::Ternary(self.reduce_ternary(ast, asg)?) } - (AstExpression::Cast(ast), AsgExpression::Cast(asg)) => AstExpression::Cast(self.reduce_cast(&ast, &asg)?), + (AstExpression::Cast(ast), AsgExpression::Cast(asg)) => AstExpression::Cast(self.reduce_cast(ast, asg)?), (AstExpression::ArrayInline(ast), AsgExpression::ArrayInline(asg)) => { - AstExpression::ArrayInline(self.reduce_array_inline(&ast, &asg)?) + AstExpression::ArrayInline(self.reduce_array_inline(ast, asg)?) } (AstExpression::ArrayInit(ast), AsgExpression::ArrayInit(asg)) => { - AstExpression::ArrayInit(self.reduce_array_init(&ast, &asg)?) + AstExpression::ArrayInit(self.reduce_array_init(ast, asg)?) } (AstExpression::ArrayAccess(ast), AsgExpression::ArrayAccess(asg)) => { - AstExpression::ArrayAccess(self.reduce_array_access(&ast, &asg)?) + AstExpression::ArrayAccess(self.reduce_array_access(ast, asg)?) } (AstExpression::ArrayRangeAccess(ast), AsgExpression::ArrayRangeAccess(asg)) => { - AstExpression::ArrayRangeAccess(self.reduce_array_range_access(&ast, &asg)?) + AstExpression::ArrayRangeAccess(self.reduce_array_range_access(ast, asg)?) } (AstExpression::TupleInit(ast), AsgExpression::TupleInit(asg)) => { - AstExpression::TupleInit(self.reduce_tuple_init(&ast, &asg)?) + AstExpression::TupleInit(self.reduce_tuple_init(ast, asg)?) } (AstExpression::TupleAccess(ast), AsgExpression::TupleAccess(asg)) => { - AstExpression::TupleAccess(self.reduce_tuple_access(&ast, &asg)?) + AstExpression::TupleAccess(self.reduce_tuple_access(ast, asg)?) } (AstExpression::CircuitInit(ast), AsgExpression::CircuitInit(asg)) => { - AstExpression::CircuitInit(self.reduce_circuit_init(&ast, &asg)?) + AstExpression::CircuitInit(self.reduce_circuit_init(ast, asg)?) } (AstExpression::CircuitMemberAccess(ast), AsgExpression::CircuitAccess(asg)) => { - AstExpression::CircuitMemberAccess(self.reduce_circuit_member_access(&ast, &asg)?) + AstExpression::CircuitMemberAccess(self.reduce_circuit_member_access(ast, asg)?) } (AstExpression::CircuitStaticFunctionAccess(ast), AsgExpression::CircuitAccess(asg)) => { - AstExpression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(&ast, &asg)?) + AstExpression::CircuitStaticFunctionAccess(self.reduce_circuit_static_fn_access(ast, asg)?) } - (AstExpression::Call(ast), AsgExpression::Call(asg)) => AstExpression::Call(self.reduce_call(&ast, &asg)?), + (AstExpression::Call(ast), AsgExpression::Call(asg)) => AstExpression::Call(self.reduce_call(ast, asg)?), _ => ast.clone(), }; @@ -299,7 +299,7 @@ impl CombineAstAsgDirector { ast: &AstCastExpression, asg: &AsgCastExpression, ) -> Result { - let inner = self.reduce_expression(&ast.inner, &asg.inner.get())?; + let inner = self.reduce_expression(&ast.inner, asg.inner.get())?; let target_type = self.reduce_type(&ast.target_type, &asg.target_type, &ast.span)?; self.ast_reducer.reduce_cast(ast, inner, target_type) @@ -524,7 +524,7 @@ impl CombineAstAsgDirector { AstAssignAccess::ArrayRange(left, right) } (AstAssignAccess::ArrayIndex(ast_index), AsgAssignAccess::ArrayIndex(asg_index)) => { - let index = self.reduce_expression(&ast_index, asg_index.get())?; + let index = self.reduce_expression(ast_index, asg_index.get())?; AstAssignAccess::ArrayIndex(index) } _ => ast.clone(), @@ -577,7 +577,7 @@ impl CombineAstAsgDirector { block = self.reduce_block(&ast.block, asg_block)?; } else { return Err(ReducerError::from(CombinerError::asg_statement_not_block( - &asg.span.as_ref().unwrap(), + asg.span.as_ref().unwrap(), ))); } let next = match (ast.next.as_ref(), asg.next.get()) { @@ -595,7 +595,7 @@ impl CombineAstAsgDirector { ) -> Result { let function = match (&ast.function, &asg.function) { (AstConsoleFunction::Assert(ast_expression), AsgConsoleFunction::Assert(asg_expression)) => { - AstConsoleFunction::Assert(self.reduce_expression(&ast_expression, asg_expression.get())?) + AstConsoleFunction::Assert(self.reduce_expression(ast_expression, asg_expression.get())?) } (AstConsoleFunction::Error(ast_console_args), AsgConsoleFunction::Error(asg_format)) | (AstConsoleFunction::Log(ast_console_args), AsgConsoleFunction::Log(asg_format)) => { @@ -603,7 +603,7 @@ impl CombineAstAsgDirector { for (ast_parameter, asg_parameter) in ast_console_args.parameters.iter().zip(asg_format.parameters.iter()) { - parameters.push(self.reduce_expression(&ast_parameter, asg_parameter.get())?); + parameters.push(self.reduce_expression(ast_parameter, asg_parameter.get())?); } let args = AstConsoleArgs { @@ -640,14 +640,14 @@ impl CombineAstAsgDirector { let asg_type = AsgType::Tuple(types); type_ = match &ast.type_ { - Some(ast_type) => Some(self.reduce_type(&ast_type, &asg_type, &ast.span)?), + Some(ast_type) => Some(self.reduce_type(ast_type, &asg_type, &ast.span)?), None if self.options.type_inference_enabled() => Some((&asg_type).into()), _ => None, }; } else { type_ = match &ast.type_ { Some(ast_type) => { - Some(self.reduce_type(&ast_type, &asg.variables.first().unwrap().borrow().type_, &ast.span)?) + Some(self.reduce_type(ast_type, &asg.variables.first().unwrap().borrow().type_, &ast.span)?) } None if self.options.type_inference_enabled() => { Some((&asg.variables.first().unwrap().borrow().type_).into()) @@ -683,7 +683,7 @@ impl CombineAstAsgDirector { block = self.reduce_block(&ast.block, asg_block)?; } else { return Err(ReducerError::from(CombinerError::asg_statement_not_block( - &asg.span.as_ref().unwrap(), + asg.span.as_ref().unwrap(), ))); } diff --git a/compiler/src/statement/assign/assignee/array_index.rs b/compiler/src/statement/assign/assignee/array_index.rs index 4b7fc6f3b0..4a463fe3cf 100644 --- a/compiler/src/statement/assign/assignee/array_index.rs +++ b/compiler/src/statement/assign/assignee/array_index.rs @@ -69,7 +69,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .len() .try_into() .map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?; - self.array_bounds_check(cs, &&index_resolved, array_len, &span)?; + self.array_bounds_check(cs, &index_resolved, array_len, &span)?; } for (i, item) in input.iter_mut().enumerate() { @@ -116,7 +116,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { unique_namespace, &index_comparison, &temp_item, - &item, + item, ) .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?; *item = value; @@ -153,7 +153,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { .len() .try_into() .map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?; - self.array_bounds_check(cs, &&index_resolved, array_len, &span)?; + self.array_bounds_check(cs, &index_resolved, array_len, &span)?; } for (i, item) in context.input.iter_mut().enumerate() { @@ -197,7 +197,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { item }; let value = - ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, &item) + ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, item) .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?; **item = value; } diff --git a/compiler/src/statement/conditional/conditional.rs b/compiler/src/statement/conditional/conditional.rs index 3fe7469209..79b032c0e5 100644 --- a/compiler/src/statement/conditional/conditional.rs +++ b/compiler/src/statement/conditional/conditional.rs @@ -91,7 +91,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { ); let branch_2_indicator = Boolean::and( &mut cs.ns(|| format!("branch 2 {}:{}", &span.line_start, &span.col_start)), - &outer_indicator, + outer_indicator, &inner_indicator, ) .map_err(|_| StatementError::indicator_calculation(branch_2_name, &span))?; diff --git a/compiler/src/value/value.rs b/compiler/src/value/value.rs index eb23ec9843..158879d57a 100644 --- a/compiler/src/value/value.rs +++ b/compiler/src/value/value.rs @@ -124,7 +124,7 @@ impl<'a, F: PrimeField, G: GroupType> fmt::Display for ConstrainedValue<'a, F write!(f, "({})", values) } - ConstrainedValue::CircuitExpression(ref circuit, ref members) => { + ConstrainedValue::CircuitExpression(circuit, ref members) => { write!(f, "{} {{", circuit.name.borrow())?; for (i, member) in members.iter().enumerate() { write!(f, "{}: {}", member.0, member.1)?; diff --git a/imports/src/parser/parse_symbol.rs b/imports/src/parser/parse_symbol.rs index ce1f391f60..1b8183f7b0 100644 --- a/imports/src/parser/parse_symbol.rs +++ b/imports/src/parser/parse_symbol.rs @@ -54,7 +54,7 @@ impl<'a> ImportParser<'a> { // Build the package abstract syntax tree. let program_string = &std::fs::read_to_string(&file_path).map_err(|x| ImportParserError::io_error(span, file_path_str, x))?; - let mut program = leo_parser::parse(&file_path_str, &program_string)?; + let mut program = leo_parser::parse(file_path_str, program_string)?; program.name = file_name; let mut ast = leo_ast::Ast::new(program); ast.canonicalize()?; diff --git a/leo/config.rs b/leo/config.rs index ae85bc3d2c..ccba67ef0b 100644 --- a/leo/config.rs +++ b/leo/config.rs @@ -144,10 +144,10 @@ pub fn write_token_and_username(token: &str, username: &str) -> Result<(), io::E } let mut credentials = File::create(&LEO_CREDENTIALS_PATH.to_path_buf())?; - credentials.write_all(&token.as_bytes())?; + credentials.write_all(token.as_bytes())?; let mut username_file = File::create(&LEO_USERNAME_PATH.to_path_buf())?; - username_file.write_all(&username.as_bytes())?; + username_file.write_all(username.as_bytes())?; Ok(()) } diff --git a/leo/updater.rs b/leo/updater.rs index cc5c8972da..a5e5b7668a 100644 --- a/leo/updater.rs +++ b/leo/updater.rs @@ -53,7 +53,7 @@ impl Updater { .repo_owner(Self::LEO_REPO_OWNER) .repo_name(Self::LEO_REPO_NAME) .bin_name(Self::LEO_BIN_NAME) - .current_version(&env!("CARGO_PKG_VERSION")) + .current_version(env!("CARGO_PKG_VERSION")) .show_download_progress(show_output) .no_confirm(true) .show_output(show_output) @@ -69,7 +69,7 @@ impl Updater { .repo_owner(Self::LEO_REPO_OWNER) .repo_name(Self::LEO_REPO_NAME) .bin_name(Self::LEO_BIN_NAME) - .current_version(&env!("CARGO_PKG_VERSION")) + .current_version(env!("CARGO_PKG_VERSION")) .build()?; let current_version = updater.current_version(); diff --git a/package/src/package.rs b/package/src/package.rs index 8a7fb861e7..1a6b8273de 100644 --- a/package/src/package.rs +++ b/package/src/package.rs @@ -123,14 +123,14 @@ impl Package { } // Check if the input file already exists. - let input_file = InputFile::new(&package_name); + let input_file = InputFile::new(package_name); if input_file.exists_at(path) { existing_files.push(input_file.filename()); result = false; } // Check if the state file already exists. - let state_file = StateFile::new(&package_name); + let state_file = StateFile::new(package_name); if state_file.exists_at(path) { existing_files.push(state_file.filename()); result = false; @@ -157,24 +157,24 @@ impl Package { } // Check if the manifest file exists. - if !Manifest::exists_at(&path) { + if !Manifest::exists_at(path) { return false; } // Check if the input file exists. - let input_file = InputFile::new(&package_name); - if !input_file.exists_at(&path) { + let input_file = InputFile::new(package_name); + if !input_file.exists_at(path) { return false; } // Check if the state file exists. - let state_file = StateFile::new(&package_name); - if !state_file.exists_at(&path) { + let state_file = StateFile::new(package_name); + if !state_file.exists_at(path) { return false; } // Check if the main file exists. - if !MainFile::exists_at(&path) { + if !MainFile::exists_at(path) { return false; } @@ -195,34 +195,34 @@ impl Package { // Next, initialize this directory as a Leo package. { // Create the manifest file. - Manifest::new(&package_name, author)?.write_to(&path)?; + Manifest::new(package_name, author)?.write_to(path)?; // Verify that the .gitignore file does not exist. - if !Gitignore::exists_at(&path) { + if !Gitignore::exists_at(path) { // Create the .gitignore file. - Gitignore::new().write_to(&path)?; + Gitignore::new().write_to(path)?; } // Verify that the README.md file does not exist. - if !README::exists_at(&path) { + if !README::exists_at(path) { // Create the README.md file. - README::new(package_name).write_to(&path)?; + README::new(package_name).write_to(path)?; } // Create the source directory. - SourceDirectory::create(&path)?; + SourceDirectory::create(path)?; // Create the input directory. - InputsDirectory::create(&path)?; + InputsDirectory::create(path)?; // Create the input file in the inputs directory. - InputFile::new(&package_name).write_to(&path)?; + InputFile::new(package_name).write_to(path)?; // Create the state file in the inputs directory. - StateFile::new(&package_name).write_to(&path)?; + StateFile::new(package_name).write_to(path)?; // Create the main file in the source directory. - MainFile::new(&package_name).write_to(&path)?; + MainFile::new(package_name).write_to(path)?; } // Next, verify that a valid Leo package has been initialized in this directory {