From 5ebea328fb80aaac34ce116c5741ec40094b8c49 Mon Sep 17 00:00:00 2001 From: gluax Date: Sat, 26 Jun 2021 00:00:09 -0700 Subject: [PATCH 1/4] const_value for array_init, and canonicalization fixes --- asg/src/expression/array_init.rs | 4 +- ast/src/reducer/canonicalization.rs | 36 +- .../canonicalization/compound_assignment.json | 1268 +++++++++-------- .../canonicalization/compound_assignment.leo | 4 + .../string_transformation.json | 445 +++++- .../string_transformation.leo | 2 + tests/compiler/array/ternary_in_array.leo | 10 + .../compiler/array/ternary_in_array.leo.out | 18 + .../compiler/mutability/array_dyn_mut.leo.out | 10 +- 9 files changed, 1146 insertions(+), 651 deletions(-) create mode 100644 tests/compiler/array/ternary_in_array.leo create mode 100644 tests/expectations/compiler/compiler/array/ternary_in_array.leo.out diff --git a/asg/src/expression/array_init.rs b/asg/src/expression/array_init.rs index 92fdd6ba72..09264dc60c 100644 --- a/asg/src/expression/array_init.rs +++ b/asg/src/expression/array_init.rs @@ -54,8 +54,8 @@ impl<'a> ExpressionNode<'a> for ArrayInitExpression<'a> { } fn const_value(&self) -> Option { - // not implemented due to performance concerns - None + let element = self.element.get().const_value()?; + Some(ConstValue::Array(vec![element; self.len])) } fn is_consty(&self) -> bool { diff --git a/ast/src/reducer/canonicalization.rs b/ast/src/reducer/canonicalization.rs index 7abbc72232..dca6f29aa8 100644 --- a/ast/src/reducer/canonicalization.rs +++ b/ast/src/reducer/canonicalization.rs @@ -593,19 +593,13 @@ impl ReconstructingReducer for Canonicalizer { value: Expression, ) -> Result { match value { - Expression::Binary(binary_expr) if assign.operation == AssignOperation::Assign => Ok(AssignStatement { - operation: AssignOperation::Assign, - assignee, - value: Expression::Binary(binary_expr), - span: assign.span.clone(), - }), - Expression::Binary(binary_expr) if assign.operation != AssignOperation::Assign => { + value if assign.operation != AssignOperation::Assign => { let left = self.canonicalize_accesses( Expression::Identifier(assignee.identifier.clone()), &assignee.accesses, &assign.span, )?; - let right = Box::new(Expression::Binary(binary_expr)); + let right = Box::new(value); let op = self.compound_operation_converstion(&assign.operation)?; let new_value = Expression::Binary(BinaryExpression { @@ -622,36 +616,12 @@ impl ReconstructingReducer for Canonicalizer { span: assign.span.clone(), }) } - Expression::Value(value_expr) if assign.operation != AssignOperation::Assign => { - let left = self.canonicalize_accesses( - Expression::Identifier(assignee.identifier.clone()), - &assignee.accesses, - &assign.span, - )?; - let right = Box::new(Expression::Value(value_expr)); - let op = self.compound_operation_converstion(&assign.operation)?; - - let new_value = Expression::Binary(BinaryExpression { - left, - right, - op, - span: assign.span.clone(), - }); - - Ok(AssignStatement { - operation: AssignOperation::Assign, - assignee, - value: new_value, - span: assign.span.clone(), - }) - } - Expression::ArrayInline(_) => Ok(AssignStatement { + value => Ok(AssignStatement { operation: AssignOperation::Assign, assignee, value, span: assign.span.clone(), }), - _ => Ok(assign.clone()), } } diff --git a/compiler/tests/canonicalization/compound_assignment.json b/compiler/tests/canonicalization/compound_assignment.json index 49ba0bdf78..562b29d0fd 100644 --- a/compiler/tests/canonicalization/compound_assignment.json +++ b/compiler/tests/canonicalization/compound_assignment.json @@ -2,14 +2,13 @@ "name": "", "expected_input": [], "imports": [], - "global_consts": {}, "circuits": { "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Foo {\\\"}\"}": { "circuit_name": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Foo {\\\"}\"}", "members": [ { "CircuitVariable": [ - "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" f: u8,\\\"}\"}", + "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":2,\\\"line_stop\\\":2,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" f: u8;\\\"}\"}", { "IntegerType": "U8" } @@ -17,7 +16,7 @@ }, { "CircuitVariable": [ - "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: (u8, u8),\\\"}\"}", + "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":3,\\\"line_stop\\\":3,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y: (u8, u8);\\\"}\"}", { "Tuple": [ { @@ -161,7 +160,7 @@ "col_start": 12, "col_stop": 16, "path": "", - "content": " return 1u16" + "content": " return 1u16;" } ] } @@ -172,7 +171,7 @@ "col_start": 5, "col_stop": 16, "path": "", - "content": " return 1u16" + "content": " return 1u16;" } } } @@ -199,6 +198,7 @@ ] } }, + "global_consts": {}, "functions": { "{\"name\":\"main\",\"span\":\"{\\\"line_start\\\":10,\\\"line_stop\\\":10,\\\"col_start\\\":10,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"function main() {\\\"}\"}": { "annotations": [], @@ -226,9 +226,7 @@ } } ], - "type_": { - "IntegerType": "U32" - }, + "type_": null, "value": { "Value": { "Integer": [ @@ -277,8 +275,7 @@ }, "right": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "20", { "line_start": 12, @@ -364,29 +361,152 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y = [1u8, 2u8];\\\"}\"}", + "identifier": "{\"name\":\"w\",\"span\":\"{\\\"line_start\\\":15,\\\"line_stop\\\":15,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let w = 3u32;\\\"}\"}", "span": { "line_start": 15, "line_stop": 15, "col_start": 7, "col_stop": 8, "path": "", + "content": " let w = 3u32;" + } + } + ], + "type_": null, + "value": { + "Value": { + "Integer": [ + "U32", + "3", + { + "line_start": 15, + "line_stop": 15, + "col_start": 11, + "col_stop": 15, + "path": "", + "content": " let w = 3u32;" + } + ] + } + }, + "span": { + "line_start": 15, + "line_stop": 15, + "col_start": 3, + "col_stop": 15, + "path": "", + "content": " let w = 3u32;" + } + } + }, + { + "Assign": { + "operation": "Assign", + "assignee": { + "identifier": "{\"name\":\"w\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" w += x;\\\"}\"}", + "accesses": [], + "span": { + "line_start": 16, + "line_stop": 16, + "col_start": 3, + "col_stop": 4, + "path": "", + "content": " w += x;" + } + }, + "value": { + "Binary": { + "left": { + "Identifier": "{\"name\":\"w\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" w += x;\\\"}\"}" + }, + "right": { + "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":8,\\\"col_stop\\\":9,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" w += x;\\\"}\"}" + }, + "op": "Add", + "span": { + "line_start": 16, + "line_stop": 16, + "col_start": 3, + "col_stop": 9, + "path": "", + "content": " w += x;" + } + } + }, + "span": { + "line_start": 16, + "line_stop": 16, + "col_start": 3, + "col_stop": 9, + "path": "", + "content": " w += x;" + } + } + }, + { + "Console": { + "function": { + "Assert": { + "Binary": { + "left": { + "Identifier": "{\"name\":\"w\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(w == 33u32);\\\"}\"}" + }, + "right": { + "Value": { + "Integer": [ + "U32", + "33", + { + "line_start": 17, + "line_stop": 17, + "col_start": 23, + "col_stop": 28, + "path": "", + "content": " console.assert(w == 33u32);" + } + ] + } + }, + "op": "Eq", + "span": { + "line_start": 17, + "line_stop": 17, + "col_start": 18, + "col_stop": 28, + "path": "", + "content": " console.assert(w == 33u32);" + } + } + } + }, + "span": { + "line_start": 17, + "line_stop": 17, + "col_start": 3, + "col_stop": 28, + "path": "", + "content": " console.assert(w == 33u32);" + } + } + }, + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": true, + "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let y = [1u8, 2u8];\\\"}\"}", + "span": { + "line_start": 19, + "line_stop": 19, + "col_start": 7, + "col_stop": 8, + "path": "", "content": " let y = [1u8, 2u8];" } } ], - "type_": { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "2" - } - ] - ] - }, + "type_": null, "value": { "ArrayInline": { "elements": [ @@ -397,8 +517,8 @@ "U8", "1", { - "line_start": 15, - "line_stop": 15, + "line_start": 19, + "line_stop": 19, "col_start": 12, "col_stop": 15, "path": "", @@ -415,8 +535,8 @@ "U8", "2", { - "line_start": 15, - "line_stop": 15, + "line_start": 19, + "line_stop": 19, "col_start": 17, "col_stop": 20, "path": "", @@ -428,8 +548,8 @@ } ], "span": { - "line_start": 15, - "line_stop": 15, + "line_start": 19, + "line_stop": 19, "col_start": 11, "col_stop": 21, "path": "", @@ -438,8 +558,8 @@ } }, "span": { - "line_start": 15, - "line_stop": 15, + "line_start": 19, + "line_stop": 19, "col_start": 3, "col_stop": 21, "path": "", @@ -451,17 +571,16 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}", + "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}", "accesses": [ { "ArrayIndex": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "0", { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 5, "col_stop": 6, "path": "", @@ -473,8 +592,8 @@ } ], "span": { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 7, "path": "", @@ -486,16 +605,15 @@ "left": { "ArrayAccess": { "array": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":16,\\\"line_stop\\\":16,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}" + "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" y[0] += 3u8;\\\"}\"}" }, "index": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "0", { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 5, "col_stop": 6, "path": "", @@ -505,8 +623,8 @@ } }, "span": { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 14, "path": "", @@ -520,8 +638,8 @@ "U8", "3", { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 11, "col_stop": 14, "path": "", @@ -532,8 +650,8 @@ }, "op": "Add", "span": { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 14, "path": "", @@ -542,8 +660,8 @@ } }, "span": { - "line_start": 16, - "line_stop": 16, + "line_start": 20, + "line_stop": 20, "col_start": 3, "col_stop": 14, "path": "", @@ -559,16 +677,15 @@ "left": { "ArrayAccess": { "array": { - "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":17,\\\"line_stop\\\":17,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(y[0] == 4u8);\\\"}\"}" + "Identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(y[0] == 4u8);\\\"}\"}" }, "index": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "0", { - "line_start": 17, - "line_stop": 17, + "line_start": 21, + "line_stop": 21, "col_start": 20, "col_stop": 21, "path": "", @@ -578,8 +695,8 @@ } }, "span": { - "line_start": 17, - "line_stop": 17, + "line_start": 21, + "line_stop": 21, "col_start": 18, "col_stop": 22, "path": "", @@ -593,8 +710,8 @@ "U8", "4", { - "line_start": 17, - "line_stop": 17, + "line_start": 21, + "line_stop": 21, "col_start": 26, "col_stop": 29, "path": "", @@ -605,8 +722,8 @@ }, "op": "Eq", "span": { - "line_start": 17, - "line_stop": 17, + "line_start": 21, + "line_stop": 21, "col_start": 18, "col_stop": 29, "path": "", @@ -616,8 +733,8 @@ } }, "span": { - "line_start": 17, - "line_stop": 17, + "line_start": 21, + "line_stop": 21, "col_start": 3, "col_stop": 29, "path": "", @@ -631,10 +748,10 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":19,\\\"line_stop\\\":19,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let z = (1u8, 2u8);\\\"}\"}", + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":23,\\\"line_stop\\\":23,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let z = (1u8, 2u8);\\\"}\"}", "span": { - "line_start": 19, - "line_stop": 19, + "line_start": 23, + "line_stop": 23, "col_start": 7, "col_stop": 8, "path": "", @@ -642,16 +759,7 @@ } } ], - "type_": { - "Tuple": [ - { - "IntegerType": "U8" - }, - { - "IntegerType": "U8" - } - ] - }, + "type_": null, "value": { "TupleInit": { "elements": [ @@ -661,8 +769,8 @@ "U8", "1", { - "line_start": 19, - "line_stop": 19, + "line_start": 23, + "line_stop": 23, "col_start": 12, "col_stop": 15, "path": "", @@ -677,8 +785,8 @@ "U8", "2", { - "line_start": 19, - "line_stop": 19, + "line_start": 23, + "line_stop": 23, "col_start": 17, "col_stop": 20, "path": "", @@ -689,8 +797,8 @@ } ], "span": { - "line_start": 19, - "line_stop": 19, + "line_start": 23, + "line_stop": 23, "col_start": 11, "col_stop": 21, "path": "", @@ -699,8 +807,8 @@ } }, "span": { - "line_start": 19, - "line_stop": 19, + "line_start": 23, + "line_stop": 23, "col_start": 3, "col_stop": 21, "path": "", @@ -712,7 +820,7 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}", + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}", "accesses": [ { "Tuple": [ @@ -720,8 +828,8 @@ "value": "1" }, { - "line_start": 20, - "line_stop": 20, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 6, "path": "", @@ -731,8 +839,8 @@ } ], "span": { - "line_start": 20, - "line_stop": 20, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 6, "path": "", @@ -744,14 +852,14 @@ "left": { "TupleAccess": { "tuple": { - "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":20,\\\"line_stop\\\":20,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}" + "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z.1 += 3u8;\\\"}\"}" }, "index": { "value": "1" }, "span": { - "line_start": 20, - "line_stop": 20, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 13, "path": "", @@ -765,8 +873,8 @@ "U8", "3", { - "line_start": 20, - "line_stop": 20, + "line_start": 24, + "line_stop": 24, "col_start": 10, "col_stop": 13, "path": "", @@ -777,8 +885,8 @@ }, "op": "Add", "span": { - "line_start": 20, - "line_stop": 20, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 13, "path": "", @@ -787,8 +895,8 @@ } }, "span": { - "line_start": 20, - "line_stop": 20, + "line_start": 24, + "line_stop": 24, "col_start": 3, "col_stop": 13, "path": "", @@ -804,14 +912,14 @@ "left": { "TupleAccess": { "tuple": { - "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":21,\\\"line_stop\\\":21,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(z.1 == 5u8);\\\"}\"}" + "Identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(z.1 == 5u8);\\\"}\"}" }, "index": { "value": "1" }, "span": { - "line_start": 21, - "line_stop": 21, + "line_start": 25, + "line_stop": 25, "col_start": 18, "col_stop": 21, "path": "", @@ -825,8 +933,8 @@ "U8", "5", { - "line_start": 21, - "line_stop": 21, + "line_start": 25, + "line_stop": 25, "col_start": 25, "col_stop": 28, "path": "", @@ -837,8 +945,8 @@ }, "op": "Eq", "span": { - "line_start": 21, - "line_stop": 21, + "line_start": 25, + "line_stop": 25, "col_start": 18, "col_stop": 28, "path": "", @@ -848,8 +956,8 @@ } }, "span": { - "line_start": 21, - "line_stop": 21, + "line_start": 25, + "line_stop": 25, "col_start": 3, "col_stop": 28, "path": "", @@ -863,10 +971,10 @@ "variable_names": [ { "mutable": true, - "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) };\\\"}\"}", + "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":7,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "span": { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 7, "col_stop": 10, "path": "", @@ -874,23 +982,21 @@ } } ], - "type_": { - "Circuit": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":1,\\\"line_stop\\\":1,\\\"col_start\\\":9,\\\"col_stop\\\":12,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\"circuit Foo {\\\"}\"}" - }, + "type_": null, "value": { "CircuitInit": { - "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) };\\\"}\"}", + "name": "{\"name\":\"Foo\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":13,\\\"col_stop\\\":16,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "members": [ { - "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) };\\\"}\"}", + "identifier": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":19,\\\"col_stop\\\":20,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "expression": { "Value": { "Integer": [ "U8", "6", { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 22, "col_stop": 25, "path": "", @@ -901,7 +1007,7 @@ } }, { - "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) };\\\"}\"}", + "identifier": "{\"name\":\"y\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":27,\\\"col_stop\\\":28,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let foo = Foo { f: 6u8, y: (1u8, 1u8) };\\\"}\"}", "expression": { "TupleInit": { "elements": [ @@ -911,8 +1017,8 @@ "U8", "1", { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 31, "col_stop": 34, "path": "", @@ -927,8 +1033,8 @@ "U8", "1", { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 36, "col_stop": 39, "path": "", @@ -939,8 +1045,8 @@ } ], "span": { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 30, "col_stop": 40, "path": "", @@ -951,8 +1057,8 @@ } ], "span": { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 13, "col_stop": 42, "path": "", @@ -961,8 +1067,8 @@ } }, "span": { - "line_start": 23, - "line_stop": 23, + "line_start": 27, + "line_stop": 27, "col_start": 3, "col_stop": 42, "path": "", @@ -974,15 +1080,15 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", + "identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", "accesses": [ { - "Member": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" + "Member": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" } ], "span": { - "line_start": 24, - "line_stop": 24, + "line_start": 28, + "line_stop": 28, "col_start": 3, "col_stop": 8, "path": "", @@ -994,12 +1100,12 @@ "left": { "CircuitMemberAccess": { "circuit": { - "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":24,\\\"line_stop\\\":24,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}" + "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":3,\\\"col_stop\\\":6,\\\"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;\\\"}\"}", + "name": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" foo.f += 2u8;\\\"}\"}", "span": { - "line_start": 24, - "line_stop": 24, + "line_start": 28, + "line_stop": 28, "col_start": 3, "col_stop": 15, "path": "", @@ -1013,8 +1119,8 @@ "U8", "2", { - "line_start": 24, - "line_stop": 24, + "line_start": 28, + "line_stop": 28, "col_start": 12, "col_stop": 15, "path": "", @@ -1025,8 +1131,8 @@ }, "op": "Add", "span": { - "line_start": 24, - "line_stop": 24, + "line_start": 28, + "line_stop": 28, "col_start": 3, "col_stop": 15, "path": "", @@ -1035,8 +1141,8 @@ } }, "span": { - "line_start": 24, - "line_stop": 24, + "line_start": 28, + "line_stop": 28, "col_start": 3, "col_stop": 15, "path": "", @@ -1052,12 +1158,12 @@ "left": { "CircuitMemberAccess": { "circuit": { - "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":25,\\\"line_stop\\\":25,\\\"col_start\\\":18,\\\"col_stop\\\":21,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(foo.f == 8u8);\\\"}\"}" + "Identifier": "{\"name\":\"foo\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":18,\\\"col_stop\\\":21,\\\"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);\\\"}\"}", + "name": "{\"name\":\"f\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":22,\\\"col_stop\\\":23,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(foo.f == 8u8);\\\"}\"}", "span": { - "line_start": 25, - "line_stop": 25, + "line_start": 29, + "line_stop": 29, "col_start": 18, "col_stop": 23, "path": "", @@ -1071,8 +1177,8 @@ "U8", "8", { - "line_start": 25, - "line_stop": 25, + "line_start": 29, + "line_stop": 29, "col_start": 27, "col_stop": 30, "path": "", @@ -1083,8 +1189,8 @@ }, "op": "Eq", "span": { - "line_start": 25, - "line_stop": 25, + "line_start": 29, + "line_stop": 29, "col_start": 18, "col_stop": 30, "path": "", @@ -1094,8 +1200,8 @@ } }, "span": { - "line_start": 25, - "line_stop": 25, + "line_start": 29, + "line_stop": 29, "col_start": 3, "col_stop": 30, "path": "", @@ -1109,10 +1215,10 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":27,\\\"line_stop\\\":27,\\\"col_start\\\":7,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let complex = 2u8;\\\"}\"}", + "identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":7,\\\"col_stop\\\":14,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let complex = 2u8;\\\"}\"}", "span": { - "line_start": 27, - "line_stop": 27, + "line_start": 31, + "line_stop": 31, "col_start": 7, "col_stop": 14, "path": "", @@ -1120,17 +1226,15 @@ } } ], - "type_": { - "IntegerType": "U8" - }, + "type_": null, "value": { "Value": { "Integer": [ "U8", "2", { - "line_start": 27, - "line_stop": 27, + "line_start": 31, + "line_stop": 31, "col_start": 17, "col_stop": 20, "path": "", @@ -1140,8 +1244,8 @@ } }, "span": { - "line_start": 27, - "line_stop": 27, + "line_start": 31, + "line_stop": 31, "col_start": 3, "col_stop": 20, "path": "", @@ -1153,11 +1257,11 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":3,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" complex += 22u8 - 2u8+ 1u8;\\\"}\"}", + "identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":3,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" complex += 22u8 - 2u8+ 1u8;\\\"}\"}", "accesses": [], "span": { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 3, "col_stop": 10, "path": "", @@ -1167,7 +1271,7 @@ "value": { "Binary": { "left": { - "Identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":28,\\\"line_stop\\\":28,\\\"col_start\\\":3,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" complex += 22u8 - 2u8+ 1u8;\\\"}\"}" + "Identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":3,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" complex += 22u8 - 2u8+ 1u8;\\\"}\"}" }, "right": { "Binary": { @@ -1179,8 +1283,8 @@ "U8", "22", { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 14, "col_stop": 18, "path": "", @@ -1195,8 +1299,8 @@ "U8", "2", { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 21, "col_stop": 24, "path": "", @@ -1207,8 +1311,8 @@ }, "op": "Sub", "span": { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 14, "col_stop": 24, "path": "", @@ -1222,8 +1326,8 @@ "U8", "1", { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 26, "col_stop": 29, "path": "", @@ -1234,8 +1338,8 @@ }, "op": "Add", "span": { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 14, "col_stop": 29, "path": "", @@ -1245,8 +1349,8 @@ }, "op": "Add", "span": { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 3, "col_stop": 29, "path": "", @@ -1255,8 +1359,8 @@ } }, "span": { - "line_start": 28, - "line_stop": 28, + "line_start": 32, + "line_stop": 32, "col_start": 3, "col_stop": 29, "path": "", @@ -1270,7 +1374,7 @@ "Assert": { "Binary": { "left": { - "Identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":29,\\\"line_stop\\\":29,\\\"col_start\\\":18,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(complex == 23u8);\\\"}\"}" + "Identifier": "{\"name\":\"complex\",\"span\":\"{\\\"line_start\\\":33,\\\"line_stop\\\":33,\\\"col_start\\\":18,\\\"col_stop\\\":25,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(complex == 23u8);\\\"}\"}" }, "right": { "Value": { @@ -1278,8 +1382,8 @@ "U8", "23", { - "line_start": 29, - "line_stop": 29, + "line_start": 33, + "line_stop": 33, "col_start": 29, "col_stop": 33, "path": "", @@ -1290,8 +1394,8 @@ }, "op": "Eq", "span": { - "line_start": 29, - "line_stop": 29, + "line_start": 33, + "line_stop": 33, "col_start": 18, "col_stop": 33, "path": "", @@ -1301,8 +1405,8 @@ } }, "span": { - "line_start": 29, - "line_stop": 29, + "line_start": 33, + "line_stop": 33, "col_start": 3, "col_stop": 33, "path": "", @@ -1316,10 +1420,10 @@ "variable_names": [ { "mutable": true, - "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":30,\\\"line_stop\\\":30,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let a = [[0u8; 1]; 4];\\\"}\"}", + "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let a = [[0u8; 1]; 4];\\\"}\"}", "span": { - "line_start": 30, - "line_stop": 30, + "line_start": 34, + "line_stop": 34, "col_start": 7, "col_stop": 8, "path": "", @@ -1327,27 +1431,7 @@ } } ], - "type_": { - "Array": [ - { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "1" - } - ] - ] - }, - [ - { - "value": "4" - } - ] - ] - }, + "type_": null, "value": { "ArrayInit": { "element": { @@ -1358,8 +1442,8 @@ "U8", "0", { - "line_start": 30, - "line_stop": 30, + "line_start": 34, + "line_stop": 34, "col_start": 13, "col_stop": 16, "path": "", @@ -1374,8 +1458,8 @@ } ], "span": { - "line_start": 30, - "line_stop": 30, + "line_start": 34, + "line_stop": 34, "col_start": 12, "col_stop": 20, "path": "", @@ -1389,8 +1473,8 @@ } ], "span": { - "line_start": 30, - "line_stop": 30, + "line_start": 34, + "line_stop": 34, "col_start": 11, "col_stop": 24, "path": "", @@ -1399,8 +1483,8 @@ } }, "span": { - "line_start": 30, - "line_stop": 30, + "line_start": 34, + "line_stop": 34, "col_start": 3, "col_stop": 24, "path": "", @@ -1412,17 +1496,16 @@ "Assign": { "operation": "Assign", "assignee": { - "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" a[2][0] += 1u8;\\\"}\"}", + "identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" a[2][0] += 1u8;\\\"}\"}", "accesses": [ { "ArrayIndex": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "2", { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 5, "col_stop": 6, "path": "", @@ -1435,12 +1518,11 @@ { "ArrayIndex": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "0", { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 8, "col_stop": 9, "path": "", @@ -1452,8 +1534,8 @@ } ], "span": { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 3, "col_stop": 10, "path": "", @@ -1467,16 +1549,15 @@ "array": { "ArrayAccess": { "array": { - "Identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":31,\\\"line_stop\\\":31,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" a[2][0] += 1u8;\\\"}\"}" + "Identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" a[2][0] += 1u8;\\\"}\"}" }, "index": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "2", { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 5, "col_stop": 6, "path": "", @@ -1486,8 +1567,8 @@ } }, "span": { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 3, "col_stop": 17, "path": "", @@ -1497,12 +1578,11 @@ }, "index": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "0", { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 8, "col_stop": 9, "path": "", @@ -1512,8 +1592,8 @@ } }, "span": { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 3, "col_stop": 17, "path": "", @@ -1527,8 +1607,8 @@ "U8", "1", { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 14, "col_stop": 17, "path": "", @@ -1539,8 +1619,8 @@ }, "op": "Add", "span": { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 3, "col_stop": 17, "path": "", @@ -1549,8 +1629,8 @@ } }, "span": { - "line_start": 31, - "line_stop": 31, + "line_start": 35, + "line_stop": 35, "col_start": 3, "col_stop": 17, "path": "", @@ -1558,356 +1638,6 @@ } } }, - { - "Console": { - "function": { - "Assert": { - "Binary": { - "left": { - "ArrayAccess": { - "array": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":32,\\\"line_stop\\\":32,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(a[2][0] == 1u8);\\\"}\"}" - }, - "index": { - "Value": { - "Integer": [ - "U32", - "2", - { - "line_start": 32, - "line_stop": 32, - "col_start": 20, - "col_stop": 21, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - ] - } - }, - "span": { - "line_start": 32, - "line_stop": 32, - "col_start": 18, - "col_stop": 22, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - } - }, - "index": { - "Value": { - "Integer": [ - "U32", - "0", - { - "line_start": 32, - "line_stop": 32, - "col_start": 23, - "col_stop": 24, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - ] - } - }, - "span": { - "line_start": 32, - "line_stop": 32, - "col_start": 18, - "col_stop": 25, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - } - }, - "right": { - "Value": { - "Integer": [ - "U8", - "1", - { - "line_start": 32, - "line_stop": 32, - "col_start": 29, - "col_stop": 32, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - ] - } - }, - "op": "Eq", - "span": { - "line_start": 32, - "line_stop": 32, - "col_start": 18, - "col_stop": 32, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - } - } - }, - "span": { - "line_start": 32, - "line_stop": 32, - "col_start": 3, - "col_stop": 32, - "path": "", - "content": " console.assert(a[2][0] == 1u8);" - } - } - }, - { - "Definition": { - "declaration_type": "Let", - "variable_names": [ - { - "mutable": true, - "identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":34,\\\"line_stop\\\":34,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let b = [0u8; (4, 1)];\\\"}\"}", - "span": { - "line_start": 34, - "line_stop": 34, - "col_start": 7, - "col_stop": 8, - "path": "", - "content": " let b = [0u8; (4, 1)];" - } - } - ], - "type_": { - "Array": [ - { - "Array": [ - { - "IntegerType": "U8" - }, - [ - { - "value": "1" - } - ] - ] - }, - [ - { - "value": "4" - } - ] - ] - }, - "value": { - "ArrayInit": { - "element": { - "ArrayInit": { - "element": { - "Value": { - "Integer": [ - "U8", - "0", - { - "line_start": 34, - "line_stop": 34, - "col_start": 12, - "col_stop": 15, - "path": "", - "content": " let b = [0u8; (4, 1)];" - } - ] - } - }, - "dimensions": [ - { - "value": "1" - } - ], - "span": { - "line_start": 34, - "line_stop": 34, - "col_start": 11, - "col_stop": 24, - "path": "", - "content": " let b = [0u8; (4, 1)];" - } - } - }, - "dimensions": [ - { - "value": "4" - } - ], - "span": { - "line_start": 34, - "line_stop": 34, - "col_start": 11, - "col_stop": 24, - "path": "", - "content": " let b = [0u8; (4, 1)];" - } - } - }, - "span": { - "line_start": 34, - "line_stop": 34, - "col_start": 3, - "col_stop": 24, - "path": "", - "content": " let b = [0u8; (4, 1)];" - } - } - }, - { - "Assign": { - "operation": "Assign", - "assignee": { - "identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" b[2][0] += 1u8;\\\"}\"}", - "accesses": [ - { - "ArrayIndex": { - "Value": { - "Integer": [ - "U32", - "2", - { - "line_start": 35, - "line_stop": 35, - "col_start": 5, - "col_stop": 6, - "path": "", - "content": " b[2][0] += 1u8;" - } - ] - } - } - }, - { - "ArrayIndex": { - "Value": { - "Integer": [ - "U32", - "0", - { - "line_start": 35, - "line_stop": 35, - "col_start": 8, - "col_stop": 9, - "path": "", - "content": " b[2][0] += 1u8;" - } - ] - } - } - } - ], - "span": { - "line_start": 35, - "line_stop": 35, - "col_start": 3, - "col_stop": 10, - "path": "", - "content": " b[2][0] += 1u8;" - } - }, - "value": { - "Binary": { - "left": { - "ArrayAccess": { - "array": { - "ArrayAccess": { - "array": { - "Identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":35,\\\"line_stop\\\":35,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" b[2][0] += 1u8;\\\"}\"}" - }, - "index": { - "Value": { - "Integer": [ - "U32", - "2", - { - "line_start": 35, - "line_stop": 35, - "col_start": 5, - "col_stop": 6, - "path": "", - "content": " b[2][0] += 1u8;" - } - ] - } - }, - "span": { - "line_start": 35, - "line_stop": 35, - "col_start": 3, - "col_stop": 17, - "path": "", - "content": " b[2][0] += 1u8;" - } - } - }, - "index": { - "Value": { - "Integer": [ - "U32", - "0", - { - "line_start": 35, - "line_stop": 35, - "col_start": 8, - "col_stop": 9, - "path": "", - "content": " b[2][0] += 1u8;" - } - ] - } - }, - "span": { - "line_start": 35, - "line_stop": 35, - "col_start": 3, - "col_stop": 17, - "path": "", - "content": " b[2][0] += 1u8;" - } - } - }, - "right": { - "Value": { - "Integer": [ - "U8", - "1", - { - "line_start": 35, - "line_stop": 35, - "col_start": 14, - "col_stop": 17, - "path": "", - "content": " b[2][0] += 1u8;" - } - ] - } - }, - "op": "Add", - "span": { - "line_start": 35, - "line_stop": 35, - "col_start": 3, - "col_stop": 17, - "path": "", - "content": " b[2][0] += 1u8;" - } - } - }, - "span": { - "line_start": 35, - "line_stop": 35, - "col_start": 3, - "col_stop": 17, - "path": "", - "content": " b[2][0] += 1u8;" - } - } - }, { "Console": { "function": { @@ -1922,8 +1652,7 @@ }, "index": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "2", { "line_start": 36, @@ -1948,8 +1677,7 @@ }, "index": { "Value": { - "Integer": [ - "U32", + "Implicit": [ "0", { "line_start": 36, @@ -2009,11 +1737,335 @@ "content": " console.assert(a[2][0] == 1u8);" } } + }, + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": true, + "identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":38,\\\"line_stop\\\":38,\\\"col_start\\\":7,\\\"col_stop\\\":8,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let b = [0u8; (4, 1)];\\\"}\"}", + "span": { + "line_start": 38, + "line_stop": 38, + "col_start": 7, + "col_stop": 8, + "path": "", + "content": " let b = [0u8; (4, 1)];" + } + } + ], + "type_": null, + "value": { + "ArrayInit": { + "element": { + "ArrayInit": { + "element": { + "Value": { + "Integer": [ + "U8", + "0", + { + "line_start": 38, + "line_stop": 38, + "col_start": 12, + "col_stop": 15, + "path": "", + "content": " let b = [0u8; (4, 1)];" + } + ] + } + }, + "dimensions": [ + { + "value": "1" + } + ], + "span": { + "line_start": 38, + "line_stop": 38, + "col_start": 11, + "col_stop": 24, + "path": "", + "content": " let b = [0u8; (4, 1)];" + } + } + }, + "dimensions": [ + { + "value": "4" + } + ], + "span": { + "line_start": 38, + "line_stop": 38, + "col_start": 11, + "col_stop": 24, + "path": "", + "content": " let b = [0u8; (4, 1)];" + } + } + }, + "span": { + "line_start": 38, + "line_stop": 38, + "col_start": 3, + "col_stop": 24, + "path": "", + "content": " let b = [0u8; (4, 1)];" + } + } + }, + { + "Assign": { + "operation": "Assign", + "assignee": { + "identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" b[2][0] += 1u8;\\\"}\"}", + "accesses": [ + { + "ArrayIndex": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 39, + "line_stop": 39, + "col_start": 5, + "col_stop": 6, + "path": "", + "content": " b[2][0] += 1u8;" + } + ] + } + } + }, + { + "ArrayIndex": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 39, + "line_stop": 39, + "col_start": 8, + "col_stop": 9, + "path": "", + "content": " b[2][0] += 1u8;" + } + ] + } + } + } + ], + "span": { + "line_start": 39, + "line_stop": 39, + "col_start": 3, + "col_stop": 10, + "path": "", + "content": " b[2][0] += 1u8;" + } + }, + "value": { + "Binary": { + "left": { + "ArrayAccess": { + "array": { + "ArrayAccess": { + "array": { + "Identifier": "{\"name\":\"b\",\"span\":\"{\\\"line_start\\\":39,\\\"line_stop\\\":39,\\\"col_start\\\":3,\\\"col_stop\\\":4,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" b[2][0] += 1u8;\\\"}\"}" + }, + "index": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 39, + "line_stop": 39, + "col_start": 5, + "col_stop": 6, + "path": "", + "content": " b[2][0] += 1u8;" + } + ] + } + }, + "span": { + "line_start": 39, + "line_stop": 39, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " b[2][0] += 1u8;" + } + } + }, + "index": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 39, + "line_stop": 39, + "col_start": 8, + "col_stop": 9, + "path": "", + "content": " b[2][0] += 1u8;" + } + ] + } + }, + "span": { + "line_start": 39, + "line_stop": 39, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " b[2][0] += 1u8;" + } + } + }, + "right": { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 39, + "line_stop": 39, + "col_start": 14, + "col_stop": 17, + "path": "", + "content": " b[2][0] += 1u8;" + } + ] + } + }, + "op": "Add", + "span": { + "line_start": 39, + "line_stop": 39, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " b[2][0] += 1u8;" + } + } + }, + "span": { + "line_start": 39, + "line_stop": 39, + "col_start": 3, + "col_stop": 17, + "path": "", + "content": " b[2][0] += 1u8;" + } + } + }, + { + "Console": { + "function": { + "Assert": { + "Binary": { + "left": { + "ArrayAccess": { + "array": { + "ArrayAccess": { + "array": { + "Identifier": "{\"name\":\"a\",\"span\":\"{\\\"line_start\\\":40,\\\"line_stop\\\":40,\\\"col_start\\\":18,\\\"col_stop\\\":19,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" console.assert(a[2][0] == 1u8);\\\"}\"}" + }, + "index": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 40, + "line_stop": 40, + "col_start": 20, + "col_stop": 21, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + ] + } + }, + "span": { + "line_start": 40, + "line_stop": 40, + "col_start": 18, + "col_stop": 22, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + } + }, + "index": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 40, + "line_stop": 40, + "col_start": 23, + "col_stop": 24, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + ] + } + }, + "span": { + "line_start": 40, + "line_stop": 40, + "col_start": 18, + "col_stop": 25, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + } + }, + "right": { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 40, + "line_stop": 40, + "col_start": 29, + "col_stop": 32, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + ] + } + }, + "op": "Eq", + "span": { + "line_start": 40, + "line_stop": 40, + "col_start": 18, + "col_stop": 32, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + } + } + }, + "span": { + "line_start": 40, + "line_stop": 40, + "col_start": 3, + "col_stop": 32, + "path": "", + "content": " console.assert(a[2][0] == 1u8);" + } + } } ], "span": { "line_start": 10, - "line_stop": 37, + "line_stop": 41, "col_start": 17, "col_stop": 2, "path": "", @@ -2022,12 +2074,12 @@ }, "span": { "line_start": 10, - "line_stop": 37, + "line_stop": 41, "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\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\n\n\n\n\n\n\n\n\n\n\n" } } } -} \ No newline at end of file +} diff --git a/compiler/tests/canonicalization/compound_assignment.leo b/compiler/tests/canonicalization/compound_assignment.leo index cd1e7f030a..6fe7a58b5c 100644 --- a/compiler/tests/canonicalization/compound_assignment.leo +++ b/compiler/tests/canonicalization/compound_assignment.leo @@ -12,6 +12,10 @@ function main() { x += 20; console.assert(x == 30u32); + let w = 3u32; + w += x; + console.assert(w == 33u32); + let y = [1u8, 2u8]; y[0] += 3u8; console.assert(y[0] == 4u8); diff --git a/compiler/tests/canonicalization/string_transformation.json b/compiler/tests/canonicalization/string_transformation.json index 393c07ace8..6871711bec 100644 --- a/compiler/tests/canonicalization/string_transformation.json +++ b/compiler/tests/canonicalization/string_transformation.json @@ -718,11 +718,450 @@ "content": " x = \"test1\" == \"test2\";" } } + }, + { + "Definition": { + "declaration_type": "Let", + "variable_names": [ + { + "mutable": true, + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":6,\\\"line_stop\\\":6,\\\"col_start\\\":9,\\\"col_stop\\\":10,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" let z = [1u8, 2u8, 3u8, 4u8];\\\"}\"}", + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 9, + "col_stop": 10, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + } + ], + "type_": null, + "value": { + "ArrayInline": { + "elements": [ + { + "Expression": { + "Value": { + "Integer": [ + "U8", + "1", + { + "line_start": 6, + "line_stop": 6, + "col_start": 14, + "col_stop": 17, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + ] + } + } + }, + { + "Expression": { + "Value": { + "Integer": [ + "U8", + "2", + { + "line_start": 6, + "line_stop": 6, + "col_start": 19, + "col_stop": 22, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + ] + } + } + }, + { + "Expression": { + "Value": { + "Integer": [ + "U8", + "3", + { + "line_start": 6, + "line_stop": 6, + "col_start": 24, + "col_stop": 27, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + ] + } + } + }, + { + "Expression": { + "Value": { + "Integer": [ + "U8", + "4", + { + "line_start": 6, + "line_stop": 6, + "col_start": 29, + "col_stop": 32, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + ] + } + } + } + ], + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 13, + "col_stop": 33, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + } + }, + "span": { + "line_start": 6, + "line_stop": 6, + "col_start": 5, + "col_stop": 33, + "path": "", + "content": " let z = [1u8, 2u8, 3u8, 4u8];" + } + } + }, + { + "Assign": { + "operation": "Assign", + "assignee": { + "identifier": "{\"name\":\"z\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":5,\\\"col_stop\\\":6,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z[0..\\\\\\\"test\\\\\\\" == \\\\\\\"test\\\\\\\"? 2 : 2] = x[0..2];\\\"}\"}", + "accesses": [ + { + "ArrayRange": [ + { + "Value": { + "Implicit": [ + "0", + { + "line_start": 7, + "line_stop": 7, + "col_start": 7, + "col_stop": 8, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + ] + } + }, + { + "Ternary": { + "condition": { + "Binary": { + "left": { + "ArrayInline": { + "elements": [ + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 116 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 11, + "col_stop": 12, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + }, + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 101 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 12, + "col_stop": 13, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + }, + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 115 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 13, + "col_stop": 14, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + }, + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 116 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 14, + "col_stop": 15, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + } + ], + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 10, + "col_stop": 16, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + }, + "right": { + "ArrayInline": { + "elements": [ + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 116 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 21, + "col_stop": 22, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + }, + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 101 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 22, + "col_stop": 23, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + }, + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 115 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 23, + "col_stop": 24, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + }, + { + "Expression": { + "Value": { + "Char": { + "character": { + "Scalar": 116 + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 24, + "col_stop": 25, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + } + } + ], + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 20, + "col_stop": 26, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + }, + "op": "Eq", + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 10, + "col_stop": 26, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + }, + "if_true": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 7, + "line_stop": 7, + "col_start": 28, + "col_stop": 29, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + ] + } + }, + "if_false": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 7, + "line_stop": 7, + "col_start": 32, + "col_stop": 33, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + ] + } + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 10, + "col_stop": 33, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + } + ] + } + ], + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 5, + "col_stop": 34, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + }, + "value": { + "ArrayRangeAccess": { + "array": { + "Identifier": "{\"name\":\"x\",\"span\":\"{\\\"line_start\\\":7,\\\"line_stop\\\":7,\\\"col_start\\\":37,\\\"col_stop\\\":38,\\\"path\\\":\\\"\\\",\\\"content\\\":\\\" z[0..\\\\\\\"test\\\\\\\" == \\\\\\\"test\\\\\\\"? 2 : 2] = x[0..2];\\\"}\"}" + }, + "left": { + "Value": { + "Implicit": [ + "0", + { + "line_start": 7, + "line_stop": 7, + "col_start": 39, + "col_stop": 40, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + ] + } + }, + "right": { + "Value": { + "Implicit": [ + "2", + { + "line_start": 7, + "line_stop": 7, + "col_start": 42, + "col_stop": 43, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + ] + } + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 37, + "col_stop": 44, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } + }, + "span": { + "line_start": 7, + "line_stop": 7, + "col_start": 5, + "col_stop": 44, + "path": "", + "content": " z[0..\"test\" == \"test\"? 2 : 2] = x[0..2];" + } + } } ], "span": { "line_start": 1, - "line_stop": 6, + "line_stop": 8, "col_start": 17, "col_stop": 2, "path": "", @@ -731,11 +1170,11 @@ }, "span": { "line_start": 1, - "line_stop": 6, + "line_stop": 8, "col_start": 1, "col_stop": 2, "path": "", - "content": "function main() {\n...\n}\n\n\n" + "content": "function main() {\n...\n}\n\n\n\n\n" } } } diff --git a/compiler/tests/canonicalization/string_transformation.leo b/compiler/tests/canonicalization/string_transformation.leo index 5a86ad281f..fb48ab364e 100644 --- a/compiler/tests/canonicalization/string_transformation.leo +++ b/compiler/tests/canonicalization/string_transformation.leo @@ -3,4 +3,6 @@ function main() { s[..2] = "he"; let x = false; x = "test1" == "test2"; + let z = [1u8, 2u8, 3u8, 4u8]; + z[0.."test" == "test"? 2 : 2] = x[0..2]; } diff --git a/tests/compiler/array/ternary_in_array.leo b/tests/compiler/array/ternary_in_array.leo new file mode 100644 index 0000000000..5fd2498473 --- /dev/null +++ b/tests/compiler/array/ternary_in_array.leo @@ -0,0 +1,10 @@ +/* +namespace: Compile +expectation: Pass +input_file: input/three_ones.in +*/ + +function main (a: [u8; 3]) -> bool { + let y = a[0..[0u8; 2] == [0u8; 2]? 2u8 : 2u8]; + return y == [1u8, 1]; +} \ No newline at end of file diff --git a/tests/expectations/compiler/compiler/array/ternary_in_array.leo.out b/tests/expectations/compiler/compiler/array/ternary_in_array.leo.out new file mode 100644 index 0000000000..43e8053cf8 --- /dev/null +++ b/tests/expectations/compiler/compiler/array/ternary_in_array.leo.out @@ -0,0 +1,18 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - circuit: + num_public_variables: 0 + num_private_variables: 39 + num_constraints: 39 + at: 6f3ffff33f4e513211e7a55cc9edcab3bc2d2a146c2b280981308bb69165f86f + bt: adde6ad1b603a50c986ec99b6edcc972138bb6239e58a1b88e931bc0165b2e8e + ct: 867e3f6ee1f26af954e7868633a595d319267d91afc5d7e2074fe641fabde1d6 + output: + - input_file: input/three_ones.in + output: + registers: + x: + type: bool + value: "true" diff --git a/tests/expectations/compiler/compiler/mutability/array_dyn_mut.leo.out b/tests/expectations/compiler/compiler/mutability/array_dyn_mut.leo.out index c08a5f6b50..b1d1893bf2 100644 --- a/tests/expectations/compiler/compiler/mutability/array_dyn_mut.leo.out +++ b/tests/expectations/compiler/compiler/mutability/array_dyn_mut.leo.out @@ -4,11 +4,11 @@ expectation: Pass outputs: - circuit: num_public_variables: 0 - num_private_variables: 1087 - num_constraints: 1350 - at: aae29cb6b4a71a5cf49d3de006b415b9a7818a2e23191819692e8d2ee69d8be2 - bt: 11262f31fcaa7950be43eded328287305e7cbcb73c19455808f08f38116cfdd6 - ct: 01dfba9e0754ad9890117694c9b03f4646642140aa7b6c393b2e264e701c323e + num_private_variables: 1277 + num_constraints: 1604 + at: c5d2d5bbb85d0f7ba48170fdb652aff057db6d1babf378d8a548af874e0734ff + bt: 726f3c39d11da5bc8487b8b7228a55cb7819a47a9b674d41f9c756c6927fb55a + ct: 7c4917152b59cb9caa30bad7d5119a3e36c40f7a783fdb8ff602dd5447573cc7 output: - input_file: input/index1.in output: From 15402584c0a2b780a156276eacf07a32cefc886f Mon Sep 17 00:00:00 2001 From: gluax Date: Sat, 26 Jun 2021 20:44:48 -0700 Subject: [PATCH 2/4] fix array indexing assigning --- .../statement/assign/assignee/array_index.rs | 176 +++++++++++------- compiler/src/statement/assign/assignee/mod.rs | 2 + leo/main.rs | 2 +- 3 files changed, 107 insertions(+), 73 deletions(-) diff --git a/compiler/src/statement/assign/assignee/array_index.rs b/compiler/src/statement/assign/assignee/array_index.rs index ecf6796486..50f58a6277 100644 --- a/compiler/src/statement/assign/assignee/array_index.rs +++ b/compiler/src/statement/assign/assignee/array_index.rs @@ -19,7 +19,7 @@ use std::convert::TryInto; use crate::{ - errors::{ExpressionError, StatementError}, + errors::{ExpressionError, IntegerError, StatementError}, program::ConstrainedProgram, value::ConstrainedValue, GroupType, @@ -40,85 +40,117 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { mut context: ResolverContext<'a, 'b, F, G>, index: &'a Expression<'a>, ) -> Result<(), StatementError> { - if context.input.len() != 1 { + println!("RTAAI input len {}", context.input.len()); + let input_len = context.input.len(); + if input_len == 0 { return Err(StatementError::array_assign_interior_index(&context.span)); } - let input = match context.input.remove(0) { - ConstrainedValue::Array(old) => old, - _ => return Err(StatementError::array_assign_index(&context.span)), - }; + let index_resolved = self.enforce_index(cs, index, &context.span)?; - if let Some(index) = index_resolved.to_usize() { - if index >= input.len() { - Err(StatementError::array_assign_index_bounds( - index, - input.len(), - &context.span, - )) - } else { - let target = input.get_mut(index).unwrap(); - if context.remaining_accesses.is_empty() { - self.enforce_assign_context(cs, &context, target) + match (context.input.remove(0), input_len) { + (ConstrainedValue::Array(input), 1) => { + if let Some(index) = index_resolved.to_usize() { + if index >= input.len() { + Err(StatementError::array_assign_index_bounds( + index, + input.len(), + &context.span, + )) + } else { + let target = input.get_mut(index).unwrap(); + if context.remaining_accesses.is_empty() { + self.enforce_assign_context(cs, &context, target) + } else { + context.input = vec![target]; + self.resolve_target_access(cs, context) + } + } } else { - context.input = vec![target]; - self.resolve_target_access(cs, context) + let span = index.span().cloned().unwrap_or_default(); + { + let array_len: u32 = input + .len() + .try_into() + .map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?; + self.array_bounds_check(cs, &&index_resolved, array_len, &span)?; + } + + for (i, item) in input.iter_mut().enumerate() { + let namespace_string = format!( + "evaluate dyn array assignment eq {} {}:{}", + i, span.line_start, span.col_start + ); + let eq_namespace = cs.ns(|| namespace_string); + + let index_bounded = i + .try_into() + .map_err(|_| ExpressionError::array_index_out_of_legal_bounds(&span))?; + let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); + let index_comparison = index_resolved + .evaluate_equal(eq_namespace, &Integer::new(&const_index)) + .map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), &span))?; + + let mut unique_namespace = cs.ns(|| { + format!( + "select array dyn assignment {} {}:{}", + i, span.line_start, span.col_start + ) + }); + let temp_item = { + let mut item = item.clone(); + let mut new_context = ResolverContext { + input: vec![&mut item], + span: context.span.clone(), + target_value: context.target_value.clone(), + remaining_accesses: context.remaining_accesses, + indicator: context.indicator, + operation: context.operation, + }; + if context.remaining_accesses.is_empty() { + let item = new_context.input.remove(0); + self.enforce_assign_context(&mut unique_namespace, &new_context, item)?; + } else { + self.resolve_target_access(&mut unique_namespace, new_context)?; + } + item + }; + let value = ConstrainedValue::conditionally_select( + unique_namespace, + &index_comparison, + &temp_item, + &item, + ) + .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?; + *item = value; + } + Ok(()) } } - } else { - let span = index.span().cloned().unwrap_or_default(); - { - let array_len: u32 = input - .len() - .try_into() - .map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?; - self.array_bounds_check(cs, &&index_resolved, array_len, &span)?; - } - - for (i, item) in input.iter_mut().enumerate() { - let namespace_string = format!( - "evaluate dyn array assignment eq {} {}:{}", - i, span.line_start, span.col_start - ); - let eq_namespace = cs.ns(|| namespace_string); - - let index_bounded = i - .try_into() - .map_err(|_| ExpressionError::array_index_out_of_legal_bounds(&span))?; - let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); - let index_comparison = index_resolved - .evaluate_equal(eq_namespace, &Integer::new(&const_index)) - .map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), &span))?; - - let mut unique_namespace = cs.ns(|| { - format!( - "select array dyn assignment {} {}:{}", - i, span.line_start, span.col_start - ) - }); - let temp_item = { - let mut item = item.clone(); - let mut new_context = ResolverContext { - input: vec![&mut item], - span: context.span.clone(), - target_value: context.target_value.clone(), - remaining_accesses: context.remaining_accesses, - indicator: context.indicator, - operation: context.operation, - }; - if context.remaining_accesses.is_empty() { - let item = new_context.input.remove(0); - self.enforce_assign_context(&mut unique_namespace, &new_context, item)?; - } else { - self.resolve_target_access(&mut unique_namespace, new_context)?; + (target, _) => { + // index of array range + if let Some(index) = index_resolved.to_usize() { + if index >= input_len { + return Err(StatementError::array_assign_index_bounds( + index, + input_len, + &context.span, + )); } - item - }; - let value = - ConstrainedValue::conditionally_select(unique_namespace, &index_comparison, &temp_item, &item) - .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?; - *item = value; + if context.remaining_accesses.is_empty() { + self.enforce_assign_context(cs, &context, target) + } else { + context.input = vec![target]; + self.resolve_target_access(cs, context) + } + } else { + let span = index.span().cloned().unwrap_or_default(); + + Err(StatementError::from(IntegerError::invalid_integer( + index_resolved.to_string(), + &span, + ))) + } } - Ok(()) } } } diff --git a/compiler/src/statement/assign/assignee/mod.rs b/compiler/src/statement/assign/assignee/mod.rs index ca81ccc4ab..230899eb76 100644 --- a/compiler/src/statement/assign/assignee/mod.rs +++ b/compiler/src/statement/assign/assignee/mod.rs @@ -68,8 +68,10 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { self.enforce_assign_context(cs, &context, input)?; return Ok(()); } + let access = context.remaining_accesses[context.remaining_accesses.len() - 1]; context.remaining_accesses = &context.remaining_accesses[..context.remaining_accesses.len() - 1]; + match access { AssignAccess::ArrayRange(start, stop) => { self.resolve_target_access_array_range(cs, context, start.get(), stop.get()) diff --git a/leo/main.rs b/leo/main.rs index 7d92f4f087..2629c52202 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -308,7 +308,7 @@ mod cli_tests { let path = Some(dir.path("new")); assert!(run_cmd("leo new test", &path).is_ok()); - assert!(run_cmd("leo new test", &path).is_err()); // 2nd time + assert!(run_cmd("leo new test", &path).is_err()); // 2nd time assert!(run_cmd("leo new wrong_name", &path).is_err()); } From b96cc7b08c28feb9cf6d532cfd303f9dfdb86bd6 Mon Sep 17 00:00:00 2001 From: gluax Date: Sat, 26 Jun 2021 20:46:54 -0700 Subject: [PATCH 3/4] remove debug stmt --- compiler/src/statement/assign/assignee/array_index.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/compiler/src/statement/assign/assignee/array_index.rs b/compiler/src/statement/assign/assignee/array_index.rs index 50f58a6277..68f7078d95 100644 --- a/compiler/src/statement/assign/assignee/array_index.rs +++ b/compiler/src/statement/assign/assignee/array_index.rs @@ -40,7 +40,6 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { mut context: ResolverContext<'a, 'b, F, G>, index: &'a Expression<'a>, ) -> Result<(), StatementError> { - println!("RTAAI input len {}", context.input.len()); let input_len = context.input.len(); if input_len == 0 { return Err(StatementError::array_assign_interior_index(&context.span)); From 5c3b48a25bb1f957f759e5e3a15e455f84382c59 Mon Sep 17 00:00:00 2001 From: gluax Date: Mon, 28 Jun 2021 14:10:26 -0700 Subject: [PATCH 4/4] slight rework to access to clean it up and fix other missed cases, added tests --- .../statement/assign/assignee/array_index.rs | 208 +++++++++--------- .../assign/assignee/array_range_index.rs | 2 + compiler/src/statement/assign/assignee/mod.rs | 2 + tests/compiler/array/complex_access.leo | 23 ++ tests/compiler/array/input/complex_access.in | 7 + .../compiler/array/complex_access.leo.out | 18 ++ 6 files changed, 159 insertions(+), 101 deletions(-) create mode 100644 tests/compiler/array/complex_access.leo create mode 100644 tests/compiler/array/input/complex_access.in create mode 100644 tests/expectations/compiler/compiler/array/complex_access.leo.out diff --git a/compiler/src/statement/assign/assignee/array_index.rs b/compiler/src/statement/assign/assignee/array_index.rs index 68f7078d95..36a086877c 100644 --- a/compiler/src/statement/assign/assignee/array_index.rs +++ b/compiler/src/statement/assign/assignee/array_index.rs @@ -41,115 +41,121 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { index: &'a Expression<'a>, ) -> Result<(), StatementError> { let input_len = context.input.len(); - if input_len == 0 { - return Err(StatementError::array_assign_interior_index(&context.span)); - } let index_resolved = self.enforce_index(cs, index, &context.span)?; - match (context.input.remove(0), input_len) { - (ConstrainedValue::Array(input), 1) => { - if let Some(index) = index_resolved.to_usize() { - if index >= input.len() { - Err(StatementError::array_assign_index_bounds( - index, - input.len(), - &context.span, - )) - } else { - let target = input.get_mut(index).unwrap(); - if context.remaining_accesses.is_empty() { - self.enforce_assign_context(cs, &context, target) + if !context.from_range && input_len == 1 { + match context.input.remove(0) { + ConstrainedValue::Array(input) => { + if let Some(index) = index_resolved.to_usize() { + if index >= input.len() { + Err(StatementError::array_assign_index_bounds( + index, + input.len(), + &context.span, + )) } else { - context.input = vec![target]; - self.resolve_target_access(cs, context) - } - } - } else { - let span = index.span().cloned().unwrap_or_default(); - { - let array_len: u32 = input - .len() - .try_into() - .map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?; - self.array_bounds_check(cs, &&index_resolved, array_len, &span)?; - } - - for (i, item) in input.iter_mut().enumerate() { - let namespace_string = format!( - "evaluate dyn array assignment eq {} {}:{}", - i, span.line_start, span.col_start - ); - let eq_namespace = cs.ns(|| namespace_string); - - let index_bounded = i - .try_into() - .map_err(|_| ExpressionError::array_index_out_of_legal_bounds(&span))?; - let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); - let index_comparison = index_resolved - .evaluate_equal(eq_namespace, &Integer::new(&const_index)) - .map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), &span))?; - - let mut unique_namespace = cs.ns(|| { - format!( - "select array dyn assignment {} {}:{}", - i, span.line_start, span.col_start - ) - }); - let temp_item = { - let mut item = item.clone(); - let mut new_context = ResolverContext { - input: vec![&mut item], - span: context.span.clone(), - target_value: context.target_value.clone(), - remaining_accesses: context.remaining_accesses, - indicator: context.indicator, - operation: context.operation, - }; - if context.remaining_accesses.is_empty() { - let item = new_context.input.remove(0); - self.enforce_assign_context(&mut unique_namespace, &new_context, item)?; - } else { - self.resolve_target_access(&mut unique_namespace, new_context)?; + let target = input.get_mut(index).unwrap(); + if let ConstrainedValue::Integer(int) = target { + println!("RTAAI T {}", int); } - item - }; - let value = ConstrainedValue::conditionally_select( - unique_namespace, - &index_comparison, - &temp_item, - &item, - ) - .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?; - *item = value; - } - Ok(()) - } - } - (target, _) => { - // index of array range - if let Some(index) = index_resolved.to_usize() { - if index >= input_len { - return Err(StatementError::array_assign_index_bounds( - index, - input_len, - &context.span, - )); - } - if context.remaining_accesses.is_empty() { - self.enforce_assign_context(cs, &context, target) + if context.remaining_accesses.is_empty() { + self.enforce_assign_context(cs, &context, target) + } else { + context.input = vec![target]; + self.resolve_target_access(cs, context) + } + } } else { - context.input = vec![target]; - self.resolve_target_access(cs, context) - } - } else { - let span = index.span().cloned().unwrap_or_default(); + let span = index.span().cloned().unwrap_or_default(); + { + let array_len: u32 = input + .len() + .try_into() + .map_err(|_| ExpressionError::array_length_out_of_bounds(&span))?; + self.array_bounds_check(cs, &&index_resolved, array_len, &span)?; + } - Err(StatementError::from(IntegerError::invalid_integer( - index_resolved.to_string(), - &span, - ))) + for (i, item) in input.iter_mut().enumerate() { + let namespace_string = format!( + "evaluate dyn array assignment eq {} {}:{}", + i, span.line_start, span.col_start + ); + let eq_namespace = cs.ns(|| namespace_string); + + let index_bounded = i + .try_into() + .map_err(|_| ExpressionError::array_index_out_of_legal_bounds(&span))?; + let const_index = ConstInt::U32(index_bounded).cast_to(&index_resolved.get_type()); + let index_comparison = index_resolved + .evaluate_equal(eq_namespace, &Integer::new(&const_index)) + .map_err(|_| ExpressionError::cannot_evaluate("==".to_string(), &span))?; + + let mut unique_namespace = cs.ns(|| { + format!( + "select array dyn assignment {} {}:{}", + i, span.line_start, span.col_start + ) + }); + let temp_item = { + let mut item = item.clone(); + let mut new_context = ResolverContext { + input: vec![&mut item], + span: context.span.clone(), + target_value: context.target_value.clone(), + remaining_accesses: context.remaining_accesses, + indicator: context.indicator, + operation: context.operation, + from_range: false, + }; + if context.remaining_accesses.is_empty() { + let item = new_context.input.remove(0); + self.enforce_assign_context(&mut unique_namespace, &new_context, item)?; + } else { + self.resolve_target_access(&mut unique_namespace, new_context)?; + } + item + }; + let value = ConstrainedValue::conditionally_select( + unique_namespace, + &index_comparison, + &temp_item, + &item, + ) + .map_err(|e| ExpressionError::cannot_enforce("conditional select".to_string(), e, &span))?; + *item = value; + } + Ok(()) + } } + _ => Err(StatementError::array_assign_interior_index(&context.span)), } + } else if context.from_range && input_len != 0 { + if let Some(index) = index_resolved.to_usize() { + if index >= input_len { + return Err(StatementError::array_assign_index_bounds( + index, + input_len, + &context.span, + )); + } + let target = context.input.remove(index); + + if context.remaining_accesses.is_empty() { + self.enforce_assign_context(cs, &context, target) + } else { + context.input = vec![target]; + self.resolve_target_access(cs, context) + } + } else { + let span = index.span().cloned().unwrap_or_default(); + + Err(StatementError::from(IntegerError::invalid_integer( + index_resolved.to_string(), + &span, + ))) + } + } else { + Err(StatementError::array_assign_interior_index(&context.span)) } } } diff --git a/compiler/src/statement/assign/assignee/array_range_index.rs b/compiler/src/statement/assign/assignee/array_range_index.rs index 505c7164ae..38c1f80d56 100644 --- a/compiler/src/statement/assign/assignee/array_range_index.rs +++ b/compiler/src/statement/assign/assignee/array_range_index.rs @@ -32,6 +32,8 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { start: Option<&'a Expression<'a>>, stop: Option<&'a Expression<'a>>, ) -> Result<(), StatementError> { + context.from_range = true; + let start_index = start .map(|start| self.enforce_index(cs, start, &context.span)) .transpose()? diff --git a/compiler/src/statement/assign/assignee/mod.rs b/compiler/src/statement/assign/assignee/mod.rs index 230899eb76..d6e5a67f70 100644 --- a/compiler/src/statement/assign/assignee/mod.rs +++ b/compiler/src/statement/assign/assignee/mod.rs @@ -35,6 +35,7 @@ struct ResolverContext<'a, 'b, F: PrimeField, G: GroupType> { remaining_accesses: &'b [&'b AssignAccess<'a>], indicator: &'b Boolean, operation: AssignOperation, + from_range: bool, } impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { @@ -101,6 +102,7 @@ impl<'a, F: PrimeField, G: GroupType> ConstrainedProgram<'a, F, G> { remaining_accesses: &accesses[..], indicator, operation: assignee.operation, + from_range: false, })?; *self.get_mut(variable.id).unwrap() = target; Ok(()) diff --git a/tests/compiler/array/complex_access.leo b/tests/compiler/array/complex_access.leo new file mode 100644 index 0000000000..91cece47f5 --- /dev/null +++ b/tests/compiler/array/complex_access.leo @@ -0,0 +1,23 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - input/complex_access.in +*/ + +function main (a: [u8; 8], b: [[u8; 3]; 3], c: [(u8, u32); 1]) -> bool { + a[2..6][1] = 87; + a[2..3] = [42u8]; + a[6..][0] = 43u8; + + b[0..2][0] = [1u8; 3]; + b[1..][1][1..2][0] = 126; + b[1..][0] = [42, 43, 44]; + + c[..1][0].1 = 1; + + return + a == [1u8, 2, 42, 87, 5, 6, 43, 8] + && b == [[1u8, 1, 1], [42, 43, 44], [7, 126, 9]] + && c == [(0u8, 1u32)]; +} \ No newline at end of file diff --git a/tests/compiler/array/input/complex_access.in b/tests/compiler/array/input/complex_access.in new file mode 100644 index 0000000000..911a174e73 --- /dev/null +++ b/tests/compiler/array/input/complex_access.in @@ -0,0 +1,7 @@ +[main] +a: [u8; 8] = [1u8, 2, 3, 4, 5, 6, 7, 8]; +b: [[u8; 3]; 3] = [[1u8, 2, 3], [4, 5, 6], [7, 8, 9]]; +c: [(u8, u32); 1] = [(0u8, 0u32)]; + +[registers] +out: bool = true; \ No newline at end of file diff --git a/tests/expectations/compiler/compiler/array/complex_access.leo.out b/tests/expectations/compiler/compiler/array/complex_access.leo.out new file mode 100644 index 0000000000..471ffe9965 --- /dev/null +++ b/tests/expectations/compiler/compiler/array/complex_access.leo.out @@ -0,0 +1,18 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - circuit: + num_public_variables: 0 + num_private_variables: 239 + num_constraints: 239 + at: 61be39f73914fdb4059c5d5e5776840262ab56dc414aa09106ddfee1d27ba174 + bt: 3f2d18346ecde92782f60a29649e187402d8f2059cf934b31f5606c4d4381883 + ct: db5fb9e237a13bca372ce7d3f232661fdf07c8ae7ef3d99517438a3532f59a41 + output: + - input_file: input/complex_access.in + output: + registers: + out: + type: bool + value: "true"