From 2bb85f52c128d33ec0875238f05392801d76f5d9 Mon Sep 17 00:00:00 2001 From: gluax Date: Fri, 9 Apr 2021 22:52:14 -0400 Subject: [PATCH] quick fix, it's in order in this location not reversed, add tests --- ast/src/reducer/canonicalization.rs | 2 +- .../canonicalization/compound_assignment.json | 844 +++++++++++++++--- .../canonicalization/compound_assignment.leo | 12 +- 3 files changed, 711 insertions(+), 147 deletions(-) diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 6cbd7ffe94..0fe3a124b0 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -472,7 +472,7 @@ impl ReconstructingReducer for Canonicalizer { Expression::Value(value_expr) if assign.operation != AssignOperation::Assign => { let mut left = Box::new(Expression::Identifier(assignee.identifier.clone())); - for access in assignee.accesses.iter().rev() { + for access in assignee.accesses.iter() { match self.canonicalize_assignee_access(&access) { AssigneeAccess::ArrayIndex(index) => { left = Box::new(Expression::ArrayAccess(ArrayAccessExpression { diff --git a/compiler/tests/canonicalization/compound_assignment.json b/compiler/tests/canonicalization/compound_assignment.json index fa2c4825a5..54230d1560 100644 --- a/compiler/tests/canonicalization/compound_assignment.json +++ b/compiler/tests/canonicalization/compound_assignment.json @@ -13,14 +13,195 @@ "IntegerType": "U8" } ] + }, + { + "CircuitVariable": [ + "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: (u8, u8),\\\"}\"}", + { + "Tuple": [ + { + "IntegerType": "U8" + }, + { + "IntegerType": "U8" + } + ] + } + ] + }, + { + "CircuitFunction": { + "annotations": [], + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":12,\\\"col_stop\\\":13,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function z (mut self) -> u16 {\\\"}\"}", + "input": [ + { + "MutSelfKeyword": "{\"name\":\"mut self\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":15,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" function z (mut self) -> u16 {\\\"}\"}" + } + ], + "output": { + "IntegerType": "U16" + }, + "block": { + "statements": [ + { + "Assign": { + "operation": "Assign", + "assignee": { + "identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" self.y.0 += 1u8;\\\"}\"}", + "accesses": [ + { + "Member": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" self.y.0 += 1u8;\\\"}\"}" + }, + { + "Tuple": [ + { + "value": "0" + }, + { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 13, + "path": "", + "content": " self.y.0 += 1u8;" + } + ] + } + ], + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 13, + "path": "", + "content": " self.y.0 += 1u8;" + } + }, + "value": { + "Binary": { + "left": { + "TupleAccess": { + "tuple": { + "CircuitMemberAccess": { + "circuit": { + "Identifier": "{\"name\":\"self\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":5,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" self.y.0 += 1u8;\\\"}\"}" + }, + "name": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":10,\\\"col_stop\\\":11,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" self.y.0 += 1u8;\\\"}\"}", + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 20, + "path": "", + "content": " self.y.0 += 1u8;" + } + } + }, + "index": { + "value": "0" + }, + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 20, + "path": "", + "content": " self.y.0 += 1u8;" + } + } + }, + "right": { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 6, + "line_stop": 6, + "col_start": 17, + "col_stop": 20, + "path": "", + "content": " self.y.0 += 1u8;" + } + ] + } + }, + "op": "Add", + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 20, + "path": "", + "content": " self.y.0 += 1u8;" + } + } + }, + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 20, + "path": "", + "content": " self.y.0 += 1u8;" + } + } + }, + { + "Return": { + "expression": { + "Value": { + "Integer": [ + "U16", + "1", + { + "line_start": 7, + "line_stop": 7, + "col_start": 12, + "col_stop": 16, + "path": "", + "content": " return 1u16" + } + ] + } + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 5, + "col_stop": 16, + "path": "", + "content": " return 1u16" + } + } + } + ], + "span": { + "line_start": 5, + "line_stop": 8, + "col_start": 32, + "col_stop": 4, + "path": "", + "content": " function z (mut self) -> u16 {\n...\n }" + } + }, + "span": { + "line_start": 5, + "line_stop": 8, + "col_start": 3, + "col_stop": 4, + "path": "", + "content": " function z (mut self) -> u16 {\n...\n }\n" + } + } } ] } }, "functions": { - "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}": { + "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}": { "annotations": [], - "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":4,\\\"line_stop\\\":4,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}", + "identifier": "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}", "input": [], "output": { "Tuple": [] @@ -33,10 +214,10 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":5,\\\"line_stop\\\":5,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x = 10u32;\\\"}\"}", + "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let x = 10u32;\\\"}\"}", "span": { - "line_start": 5, - "line_stop": 5, + "line_start": 11, + "line_stop": 11, "col_start": 7, "col_stop": 8, "path": "", @@ -51,8 +232,8 @@ "U32", "10", { - "line_start": 5, - "line_stop": 5, + "line_start": 11, + "line_stop": 11, "col_start": 11, "col_stop": 16, "path": "", @@ -62,8 +243,8 @@ } }, "span": { - "line_start": 5, - "line_stop": 5, + "line_start": 11, + "line_stop": 11, "col_start": 3, "col_stop": 16, "path": "", @@ -75,11 +256,11 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x += 20;\\\"}\"}", + "identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x += 20;\\\"}\"}", "accesses": [], "span": { - "line_start": 6, - "line_stop": 6, + "line_start": 12, + "line_stop": 12, "col_start": 3, "col_stop": 4, "path": "", @@ -89,15 +270,15 @@ "value": { "Binary": { "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x += 20;\\\"}\"}" + "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":12,\\\"line_stop\\\":12,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" x += 20;\\\"}\"}" }, "right": { "Value": { "Implicit": [ "20", { - "line_start": 6, - "line_stop": 6, + "line_start": 12, + "line_stop": 12, "col_start": 8, "col_stop": 10, "path": "", @@ -108,8 +289,8 @@ }, "op": "Add", "span": { - "line_start": 6, - "line_stop": 6, + "line_start": 12, + "line_stop": 12, "col_start": 3, "col_stop": 10, "path": "", @@ -118,8 +299,8 @@ } }, "span": { - "line_start": 6, - "line_stop": 6, + "line_start": 12, + "line_stop": 12, "col_start": 3, "col_stop": 10, "path": "", @@ -133,7 +314,7 @@ "Assert": { "Binary": { "left": { - "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(x == 30u32);\\\"}\"}" + "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(x == 30u32);\\\"}\"}" }, "right": { "Value": { @@ -141,8 +322,8 @@ "U32", "30", { - "line_start": 7, - "line_stop": 7, + "line_start": 13, + "line_stop": 13, "col_start": 23, "col_stop": 28, "path": "", @@ -153,8 +334,8 @@ }, "op": "Eq", "span": { - "line_start": 7, - "line_stop": 7, + "line_start": 13, + "line_stop": 13, "col_start": 18, "col_stop": 28, "path": "", @@ -164,8 +345,8 @@ } }, "span": { - "line_start": 7, - "line_stop": 7, + "line_start": 13, + "line_stop": 13, "col_start": 3, "col_stop": 28, "path": "", @@ -179,10 +360,10 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":9,\\\"line_stop\\\":9,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y = [1u8, 2u8];\\\"}\"}", + "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y = [1u8, 2u8];\\\"}\"}", "span": { - "line_start": 9, - "line_stop": 9, + "line_start": 15, + "line_stop": 15, "col_start": 7, "col_stop": 8, "path": "", @@ -201,8 +382,8 @@ "U8", "1", { - "line_start": 9, - "line_stop": 9, + "line_start": 15, + "line_stop": 15, "col_start": 12, "col_stop": 15, "path": "", @@ -219,8 +400,8 @@ "U8", "2", { - "line_start": 9, - "line_stop": 9, + "line_start": 15, + "line_stop": 15, "col_start": 17, "col_stop": 20, "path": "", @@ -232,8 +413,8 @@ } ], "span": { - "line_start": 9, - "line_stop": 9, + "line_start": 15, + "line_stop": 15, "col_start": 11, "col_stop": 21, "path": "", @@ -242,8 +423,8 @@ } }, "span": { - "line_start": 9, - "line_stop": 9, + "line_start": 15, + "line_stop": 15, "col_start": 3, "col_stop": 21, "path": "", @@ -255,7 +436,7 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}", + "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}", "accesses": [ { "ArrayIndex": { @@ -263,8 +444,8 @@ "Implicit": [ "0", { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 5, "col_stop": 6, "path": "", @@ -276,8 +457,8 @@ } ], "span": { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 3, "col_stop": 7, "path": "", @@ -289,15 +470,15 @@ "left": { "ArrayAccess": { "array": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}" + "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}" }, "index": { "Value": { "Implicit": [ "0", { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 5, "col_stop": 6, "path": "", @@ -307,8 +488,8 @@ } }, "span": { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 3, "col_stop": 14, "path": "", @@ -322,8 +503,8 @@ "U8", "3", { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 11, "col_stop": 14, "path": "", @@ -334,8 +515,8 @@ }, "op": "Add", "span": { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 3, "col_stop": 14, "path": "", @@ -344,8 +525,8 @@ } }, "span": { - "line_start": 10, - "line_stop": 10, + "line_start": 16, + "line_stop": 16, "col_start": 3, "col_stop": 14, "path": "", @@ -361,15 +542,15 @@ "left": { "ArrayAccess": { "array": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":11,\\\"line_stop\\\":11,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(y[0] == 4u8);\\\"}\"}" + "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(y[0] == 4u8);\\\"}\"}" }, "index": { "Value": { "Implicit": [ "0", { - "line_start": 11, - "line_stop": 11, + "line_start": 17, + "line_stop": 17, "col_start": 20, "col_stop": 21, "path": "", @@ -379,8 +560,8 @@ } }, "span": { - "line_start": 11, - "line_stop": 11, + "line_start": 17, + "line_stop": 17, "col_start": 18, "col_stop": 22, "path": "", @@ -394,8 +575,8 @@ "U8", "4", { - "line_start": 11, - "line_stop": 11, + "line_start": 17, + "line_stop": 17, "col_start": 26, "col_stop": 29, "path": "", @@ -406,8 +587,8 @@ }, "op": "Eq", "span": { - "line_start": 11, - "line_stop": 11, + "line_start": 17, + "line_stop": 17, "col_start": 18, "col_stop": 29, "path": "", @@ -417,8 +598,8 @@ } }, "span": { - "line_start": 11, - "line_stop": 11, + "line_start": 17, + "line_stop": 17, "col_start": 3, "col_stop": 29, "path": "", @@ -432,10 +613,10 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":13,\\\"line_stop\\\":13,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let z = (1u8, 2u8);\\\"}\"}", + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let z = (1u8, 2u8);\\\"}\"}", "span": { - "line_start": 13, - "line_stop": 13, + "line_start": 19, + "line_stop": 19, "col_start": 7, "col_stop": 8, "path": "", @@ -453,8 +634,8 @@ "U8", "1", { - "line_start": 13, - "line_stop": 13, + "line_start": 19, + "line_stop": 19, "col_start": 12, "col_stop": 15, "path": "", @@ -469,8 +650,8 @@ "U8", "2", { - "line_start": 13, - "line_stop": 13, + "line_start": 19, + "line_stop": 19, "col_start": 17, "col_stop": 20, "path": "", @@ -481,8 +662,8 @@ } ], "span": { - "line_start": 13, - "line_stop": 13, + "line_start": 19, + "line_stop": 19, "col_start": 11, "col_stop": 21, "path": "", @@ -491,8 +672,8 @@ } }, "span": { - "line_start": 13, - "line_stop": 13, + "line_start": 19, + "line_stop": 19, "col_start": 3, "col_stop": 21, "path": "", @@ -504,7 +685,7 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}", + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}", "accesses": [ { "Tuple": [ @@ -512,8 +693,8 @@ "value": "1" }, { - "line_start": 14, - "line_stop": 14, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 6, "path": "", @@ -523,8 +704,8 @@ } ], "span": { - "line_start": 14, - "line_stop": 14, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 6, "path": "", @@ -536,14 +717,14 @@ "left": { "TupleAccess": { "tuple": { - "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":14,\\\"line_stop\\\":14,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}" + "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}" }, "index": { "value": "1" }, "span": { - "line_start": 14, - "line_stop": 14, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 13, "path": "", @@ -557,8 +738,8 @@ "U8", "3", { - "line_start": 14, - "line_stop": 14, + "line_start": 20, + "line_stop": 20, "col_start": 10, "col_stop": 13, "path": "", @@ -569,8 +750,8 @@ }, "op": "Add", "span": { - "line_start": 14, - "line_stop": 14, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 13, "path": "", @@ -579,8 +760,8 @@ } }, "span": { - "line_start": 14, - "line_stop": 14, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 13, "path": "", @@ -596,14 +777,14 @@ "left": { "TupleAccess": { "tuple": { - "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(z.1 == 5u8);\\\"}\"}" + "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(z.1 == 5u8);\\\"}\"}" }, "index": { "value": "1" }, "span": { - "line_start": 15, - "line_stop": 15, + "line_start": 21, + "line_stop": 21, "col_start": 18, "col_stop": 21, "path": "", @@ -617,8 +798,8 @@ "U8", "5", { - "line_start": 15, - "line_stop": 15, + "line_start": 21, + "line_stop": 21, "col_start": 25, "col_stop": 28, "path": "", @@ -629,8 +810,8 @@ }, "op": "Eq", "span": { - "line_start": 15, - "line_stop": 15, + "line_start": 21, + "line_stop": 21, "col_start": 18, "col_stop": 28, "path": "", @@ -640,8 +821,8 @@ } }, "span": { - "line_start": 15, - "line_stop": 15, + "line_start": 21, + "line_stop": 21, "col_start": 3, "col_stop": 28, "path": "", @@ -655,59 +836,108 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":7,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8 };\\\"}\"}", + "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":7,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "span": { - "line_start": 17, - "line_stop": 17, + "line_start": 23, + "line_stop": 23, "col_start": 7, "col_stop": 10, "path": "", - "content": " let foo = Foo { f: 6u8 };" + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" } } ], "type_": null, "value": { "CircuitInit": { - "name": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":13,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8 };\\\"}\"}", + "name": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":13,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "members": [ { - "identifier": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":19,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8 };\\\"}\"}", + "identifier": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":19,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "expression": { "Value": { "Integer": [ "U8", "6", { - "line_start": 17, - "line_stop": 17, + "line_start": 23, + "line_stop": 23, "col_start": 22, "col_stop": 25, "path": "", - "content": " let foo = Foo { f: 6u8 };" + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" } ] } } + }, + { + "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":27,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", + "expression": { + "TupleInit": { + "elements": [ + { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 23, + "line_stop": 23, + "col_start": 31, + "col_stop": 34, + "path": "", + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" + } + ] + } + }, + { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 23, + "line_stop": 23, + "col_start": 36, + "col_stop": 39, + "path": "", + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" + } + ] + } + } + ], + "span": { + "line_start": 23, + "line_stop": 23, + "col_start": 30, + "col_stop": 40, + "path": "", + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" + } + } + } } ], "span": { - "line_start": 17, - "line_stop": 17, + "line_start": 23, + "line_stop": 23, "col_start": 13, - "col_stop": 27, + "col_stop": 42, "path": "", - "content": " let foo = Foo { f: 6u8 };" + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" } } }, "span": { - "line_start": 17, - "line_stop": 17, + "line_start": 23, + "line_stop": 23, "col_start": 3, - "col_stop": 27, + "col_stop": 42, "path": "", - "content": " let foo = Foo { f: 6u8 };" + "content": " let foo = Foo { f: 6u8, y: (1u8, 1u8) };" } } }, @@ -715,15 +945,15 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", + "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", "accesses": [ { - "Member": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" + "Member": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" } ], "span": { - "line_start": 18, - "line_stop": 18, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 8, "path": "", @@ -735,12 +965,12 @@ "left": { "CircuitMemberAccess": { "circuit": { - "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" + "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" }, - "name": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":18,\\\"line_stop\\\":18,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", + "name": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", "span": { - "line_start": 18, - "line_stop": 18, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 15, "path": "", @@ -754,8 +984,8 @@ "U8", "2", { - "line_start": 18, - "line_stop": 18, + "line_start": 24, + "line_stop": 24, "col_start": 12, "col_stop": 15, "path": "", @@ -766,8 +996,8 @@ }, "op": "Add", "span": { - "line_start": 18, - "line_stop": 18, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 15, "path": "", @@ -776,8 +1006,8 @@ } }, "span": { - "line_start": 18, - "line_stop": 18, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 15, "path": "", @@ -793,12 +1023,12 @@ "left": { "CircuitMemberAccess": { "circuit": { - "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":18,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(foo.f == 8u8);\\\"}\"}" + "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":18,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(foo.f == 8u8);\\\"}\"}" }, - "name": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":22,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(foo.f == 8u8);\\\"}\"}", + "name": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":22,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(foo.f == 8u8);\\\"}\"}", "span": { - "line_start": 19, - "line_stop": 19, + "line_start": 25, + "line_stop": 25, "col_start": 18, "col_stop": 23, "path": "", @@ -812,8 +1042,8 @@ "U8", "8", { - "line_start": 19, - "line_stop": 19, + "line_start": 25, + "line_stop": 25, "col_start": 27, "col_stop": 30, "path": "", @@ -824,8 +1054,8 @@ }, "op": "Eq", "span": { - "line_start": 19, - "line_stop": 19, + "line_start": 25, + "line_stop": 25, "col_start": 18, "col_stop": 30, "path": "", @@ -835,32 +1065,356 @@ } }, "span": { - "line_start": 19, - "line_stop": 19, + "line_start": 25, + "line_stop": 25, "col_start": 3, "col_stop": 30, "path": "", "content": " console.assert(foo.f == 8u8);" } } + }, + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": true, + "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let a = [[0u8; 1]; 4];\\\"}\"}", + "span": { + "line_start": 27, + "line_stop": 27, + "col_start": 7, + "col_stop": 8, + "path": "", + "content": " let a = [[0u8; 1]; 4];" + } + } + ], + "type_": null, + "value": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "Value": { + "Integer": [ + "U8", + "0", + { + "line_start": 27, + "line_stop": 27, + "col_start": 13, + "col_stop": 16, + "path": "", + "content": " let a = [[0u8; 1]; 4];" + } + ] + } + }, + "dimensions": [ + { + "value": "1" + } + ], + "span": { + "line_start": 27, + "line_stop": 27, + "col_start": 12, + "col_stop": 20, + "path": "", + "content": " let a = [[0u8; 1]; 4];" + } + } + }, + "dimensions": [ + { + "value": "4" + } + ], + "span": { + "line_start": 27, + "line_stop": 27, + "col_start": 11, + "col_stop": 24, + "path": "", + "content": " let a = [[0u8; 1]; 4];" + } + } + }, + "span": { + "line_start": 27, + "line_stop": 27, + "col_start": 3, + "col_stop": 24, + "path": "", + "content": " let a = [[0u8; 1]; 4];" + } + } + }, + { + "Assign": { + "operation": "Assign", + "assignee": { + "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" a[2][0] += 1u8;\\\"}\"}", + "accesses": [ + { + "ArrayIndex": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 28, + "line_stop": 28, + "col_start": 5, + "col_stop": 6, + "path": "", + "content": " a[2][0] += 1u8;" + } + ] + } + } + }, + { + "ArrayIndex": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 28, + "line_stop": 28, + "col_start": 8, + "col_stop": 9, + "path": "", + "content": " a[2][0] += 1u8;" + } + ] + } + } + } + ], + "span": { + "line_start": 28, + "line_stop": 28, + "col_start": 3, + "col_stop": 10, + "path": "", + "content": " a[2][0] += 1u8;" + } + }, + "value": { + "Binary": { + "left": { + "ArrayAccess": { + "array": { + "ArrayAccess": { + "array": { + "Identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" a[2][0] += 1u8;\\\"}\"}" + }, + "index": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 28, + "line_stop": 28, + "col_start": 5, + "col_stop": 6, + "path": "", + "content": " a[2][0] += 1u8;" + } + ] + } + }, + "span": { + "line_start": 28, + "line_stop": 28, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " a[2][0] += 1u8;" + } + } + }, + "index": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 28, + "line_stop": 28, + "col_start": 8, + "col_stop": 9, + "path": "", + "content": " a[2][0] += 1u8;" + } + ] + } + }, + "span": { + "line_start": 28, + "line_stop": 28, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " a[2][0] += 1u8;" + } + } + }, + "right": { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 28, + "line_stop": 28, + "col_start": 14, + "col_stop": 17, + "path": "", + "content": " a[2][0] += 1u8;" + } + ] + } + }, + "op": "Add", + "span": { + "line_start": 28, + "line_stop": 28, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " a[2][0] += 1u8;" + } + } + }, + "span": { + "line_start": 28, + "line_stop": 28, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " a[2][0] += 1u8;" + } + } + }, + { + "Console": { + "function": { + "Assert": { + "Binary": { + "left": { + "ArrayAccess": { + "array": { + "ArrayAccess": { + "array": { + "Identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(a[2][0] == 3u8);\\\"}\"}" + }, + "index": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 29, + "line_stop": 29, + "col_start": 20, + "col_stop": 21, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + ] + } + }, + "span": { + "line_start": 29, + "line_stop": 29, + "col_start": 18, + "col_stop": 22, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + } + }, + "index": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 29, + "line_stop": 29, + "col_start": 23, + "col_stop": 24, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + ] + } + }, + "span": { + "line_start": 29, + "line_stop": 29, + "col_start": 18, + "col_stop": 25, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + } + }, + "right": { + "Value": { + "Integer": [ + "U8", + "3", + { + "line_start": 29, + "line_stop": 29, + "col_start": 29, + "col_stop": 32, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + ] + } + }, + "op": "Eq", + "span": { + "line_start": 29, + "line_stop": 29, + "col_start": 18, + "col_stop": 32, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + } + } + }, + "span": { + "line_start": 29, + "line_stop": 29, + "col_start": 3, + "col_stop": 32, + "path": "", + "content": " console.assert(a[2][0] == 3u8);" + } + } } ], "span": { - "line_start": 4, - "line_stop": 20, + "line_start": 10, + "line_stop": 30, "col_start": 17, "col_stop": 2, "path": "", - "content": "function main() {\n...\n} " + "content": "function main() {\n...\n}" } }, "span": { - "line_start": 4, - "line_stop": 20, + "line_start": 10, + "line_stop": 30, "col_start": 1, "col_stop": 2, "path": "", - "content": "function main() {\n...\n} \n\n\n\n\n\n\n\n\n\n\n\n\n\n" + "content": "function main() {\n...\n}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n" } } } diff --git a/compiler/tests/canonicalization/compound_assignment.leo b/compiler/tests/canonicalization/compound_assignment.leo index 346d4de3c7..f0680343fb 100644 --- a/compiler/tests/canonicalization/compound_assignment.leo +++ b/compiler/tests/canonicalization/compound_assignment.leo @@ -1,5 +1,11 @@ circuit Foo { f: u8, + y: (u8, u8), + + function z (mut self) -> u16 { + self.y.0 += 1u8; + return 1u16 + } } function main() { let x = 10u32; @@ -14,7 +20,11 @@ function main() { z.1 += 3u8; console.assert(z.1 == 5u8); - let foo = Foo { f: 6u8 }; + let foo = Foo { f: 6u8, y: (1u8, 1u8) }; foo.f += 2u8; console.assert(foo.f == 8u8); + + let a = [[0u8; 1]; 4]; + a[2][0] += 1u8; + console.assert(a[2][0] == 1u8); } \ No newline at end of file