From 9fe4a7281b3628c1015a01dc37c815111c4985ee Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 10 May 2022 15:20:04 -0700 Subject: [PATCH 01/26] add scalar type to parser --- compiler/parser/src/parser/expression.rs | 1 + compiler/parser/src/parser/type_.rs | 14 +++++---- compiler/parser/src/tokenizer/lexer.rs | 1 + compiler/parser/src/tokenizer/mod.rs | 3 +- compiler/parser/src/tokenizer/token.rs | 36 +++++++++++++----------- leo/span/src/symbol.rs | 1 + 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index aec8ac86cf..b75d5685c8 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -294,6 +294,7 @@ impl ParserContext<'_> { assert_no_whitespace("group")?; Expression::Value(ValueExpression::Group(Box::new(GroupValue::Single(value, full_span)))) } + // todo @collinc97 parse scalar type here. // Literal followed by other type suffix, e.g., `42u8`. Some(suffix) => { assert_no_whitespace(&suffix.to_string())?; diff --git a/compiler/parser/src/parser/type_.rs b/compiler/parser/src/parser/type_.rs index 4cc8df88a9..e2e2fb59c9 100644 --- a/compiler/parser/src/parser/type_.rs +++ b/compiler/parser/src/parser/type_.rs @@ -18,6 +18,10 @@ use super::*; use leo_errors::Result; pub(crate) const TYPE_TOKENS: &[Token] = &[ + Token::Address, + Token::Bool, + Token::Field, + Token::Group, Token::I8, Token::I16, Token::I32, @@ -28,11 +32,8 @@ pub(crate) const TYPE_TOKENS: &[Token] = &[ Token::U32, Token::U64, Token::U128, - Token::Field, - Token::Group, - Token::Address, - Token::Bool, Token::Char, + Token::Scalar, ]; impl ParserContext<'_> { @@ -59,11 +60,12 @@ impl ParserContext<'_> { let span = self.expect_any(TYPE_TOKENS)?; Ok(( match &self.prev_token.token { - Token::Field => Type::Field, - Token::Group => Type::Group, Token::Address => Type::Address, Token::Bool => Type::Boolean, + Token::Field => Type::Field, + Token::Group => Type::Group, Token::Char => Type::Char, + // todo @collin parse scalar type here. x => Type::IntegerType(Self::token_to_int_type(x).expect("invalid int type")), }, span, diff --git a/compiler/parser/src/tokenizer/lexer.rs b/compiler/parser/src/tokenizer/lexer.rs index a8d820f815..9ecf2ddb7a 100644 --- a/compiler/parser/src/tokenizer/lexer.rs +++ b/compiler/parser/src/tokenizer/lexer.rs @@ -426,6 +426,7 @@ impl Token { "mut" => Token::Mut, "public" => Token::Public, "return" => Token::Return, + "scalar" => Token::Scalar, "true" => Token::True, "type" => Token::Type, "u8" => Token::U8, diff --git a/compiler/parser/src/tokenizer/mod.rs b/compiler/parser/src/tokenizer/mod.rs index 4829268689..1e79048c1a 100644 --- a/compiler/parser/src/tokenizer/mod.rs +++ b/compiler/parser/src/tokenizer/mod.rs @@ -154,6 +154,7 @@ mod tests { let mut return + scalar string test true @@ -204,7 +205,7 @@ mod tests { assert_eq!( output, - r#"'a' '😭' "test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address bool const else false field for function group i128 i64 i32 i16 i8 if in input let mut return string test true u128 u64 u32 u16 u8 console ! != && ( ) * ** + , - -> _ . .. / : ; < <= = == > >= [ ] { { } } || ? // test + r#"'a' '😭' "test" "test{}test" "test{}" "{}test" "test{" "test}" "test{test" "test}test" "te{{}}" aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8 test_ident 12345 address bool const else false field for function group i128 i64 i32 i16 i8 if in input let mut return scalar string test true u128 u64 u32 u16 u8 console ! != && ( ) * ** + , - -> _ . .. / : ; < <= = == > >= [ ] { { } } || ? // test /* test */ // "# ); }); diff --git a/compiler/parser/src/tokenizer/token.rs b/compiler/parser/src/tokenizer/token.rs index 5a0d58aff6..bf56b37995 100644 --- a/compiler/parser/src/tokenizer/token.rs +++ b/compiler/parser/src/tokenizer/token.rs @@ -91,25 +91,26 @@ pub enum Token { Arrow, Underscore, - // Syntactic Grammr + // Syntactic Grammar // Types - U8, - U16, - U32, - U64, - U128, I8, I16, I32, I64, I128, + Address, + Bool, Field, Group, - Bool, - Address, + U8, + U16, + U32, + U64, + U128, Char, + Scalar, - // primary expresion + // primary expression Input, // Regular Keywords @@ -159,6 +160,7 @@ pub const KEYWORD_TOKENS: &[Token] = &[ Token::Mut, Token::Public, Token::Return, + Token::Scalar, Token::True, Token::Type, Token::U8, @@ -201,6 +203,7 @@ impl Token { Token::Mut => sym::Mut, Token::Public => sym::Public, Token::Return => sym::Return, + Token::Scalar => sym::scalar, Token::True => sym::True, Token::Type => sym::Type, Token::U8 => sym::u8, @@ -264,21 +267,22 @@ impl fmt::Display for Token { Arrow => write!(f, "->"), Underscore => write!(f, "_"), - U8 => write!(f, "u8"), - U16 => write!(f, "u16"), - U32 => write!(f, "u32"), - U64 => write!(f, "u64"), - U128 => write!(f, "u128"), I8 => write!(f, "i8"), I16 => write!(f, "i16"), I32 => write!(f, "i32"), I64 => write!(f, "i64"), I128 => write!(f, "i128"), + Address => write!(f, "address"), + Bool => write!(f, "bool"), Field => write!(f, "field"), Group => write!(f, "group"), - Bool => write!(f, "bool"), - Address => write!(f, "address"), + U8 => write!(f, "u8"), + U16 => write!(f, "u16"), + U32 => write!(f, "u32"), + U64 => write!(f, "u64"), + U128 => write!(f, "u128"), Char => write!(f, "char"), + Scalar => write!(f, "scalar"), Input => write!(f, "input"), diff --git a/leo/span/src/symbol.rs b/leo/span/src/symbol.rs index c9a30ed80b..2d367869d7 100644 --- a/leo/span/src/symbol.rs +++ b/leo/span/src/symbol.rs @@ -134,6 +134,7 @@ symbols! { prelude, Public, Return: "return", + scalar, Star: "*", std, Struct: "struct", From 55260ae5ad0b4866d18835c7fd6b3e018e30f845 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 10 May 2022 15:34:42 -0700 Subject: [PATCH 02/26] add scalar type to ast --- compiler/ast/src/expression/value.rs | 22 +++++++++++++++---- compiler/ast/src/types/type_.rs | 8 +++++-- compiler/parser/src/parser/expression.rs | 7 +++++- compiler/parser/src/parser/type_.rs | 2 +- .../src/type_checker/check_expressions.rs | 1 + 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/compiler/ast/src/expression/value.rs b/compiler/ast/src/expression/value.rs index 550b947c1b..c97f538c40 100644 --- a/compiler/ast/src/expression/value.rs +++ b/compiler/ast/src/expression/value.rs @@ -21,7 +21,7 @@ use crate::{Char, CharValue}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ValueExpression { // todo: deserialize values here - /// An address literal, e.g., `aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j8`. + /// An address literal, e.g., `aleo1..`. Address(String, #[serde(with = "leo_span::span_json")] Span), /// A boolean literal, either `true` or `false`. Boolean(String, #[serde(with = "leo_span::span_json")] Span), @@ -35,6 +35,9 @@ pub enum ValueExpression { Group(Box), /// An integer literal, e.g., `42`. Integer(IntegerType, String, #[serde(with = "leo_span::span_json")] Span), + /// A scalar literal, e.g. `1scalar`. + /// An unsigned number followed by the keyword `scalar`. + Scalar(String, #[serde(with = "leo_span::span_json")] Span), /// A string literal, e.g., `"foobar"`. String(Vec, #[serde(with = "leo_span::span_json")] Span), } @@ -47,8 +50,9 @@ impl fmt::Display for ValueExpression { Boolean(boolean, _) => write!(f, "{}", boolean), Char(character) => write!(f, "{}", character), Field(field, _) => write!(f, "{}", field), - Integer(type_, value, _) => write!(f, "{}{}", value, type_), Group(group) => write!(f, "{}", group), + Integer(type_, value, _) => write!(f, "{}{}", value, type_), + Scalar(scalar, _) => write!(f, "{}", scalar), String(string, _) => { for character in string.iter() { write!(f, "{}", character)?; @@ -63,7 +67,12 @@ impl Node for ValueExpression { fn span(&self) -> &Span { use ValueExpression::*; match &self { - Address(_, span) | Boolean(_, span) | Field(_, span) | Integer(_, _, span) | String(_, span) => span, + Address(_, span) + | Boolean(_, span) + | Field(_, span) + | Integer(_, _, span) + | Scalar(_, span) + | String(_, span) => span, Char(character) => &character.span, Group(group) => match &**group { GroupValue::Single(_, span) => span, @@ -75,7 +84,12 @@ impl Node for ValueExpression { fn set_span(&mut self, new_span: Span) { use ValueExpression::*; match self { - Address(_, span) | Boolean(_, span) | Field(_, span) | Integer(_, _, span) | String(_, span) => { + Address(_, span) + | Boolean(_, span) + | Field(_, span) + | Integer(_, _, span) + | Scalar(_, span) + | String(_, span) => { *span = new_span } Char(character) => character.span = new_span, diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 87e6bdb09e..1fb252e60b 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -33,6 +33,8 @@ pub enum Type { Field, /// The `group` type. Group, + /// The `scalar` type. + Scalar, /// An integer type. IntegerType(IntegerType), @@ -51,9 +53,10 @@ impl Type { match (self, other) { (Type::Address, Type::Address) => true, (Type::Boolean, Type::Boolean) => true, - (Type::Char, Type::Char) => true, (Type::Field, Type::Field) => true, (Type::Group, Type::Group) => true, + (Type::Char, Type::Char) => true, + (Type::Scalar, Type::Scalar) => true, (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), _ => false, } @@ -65,9 +68,10 @@ impl fmt::Display for Type { match *self { Type::Address => write!(f, "address"), Type::Boolean => write!(f, "bool"), - Type::Char => write!(f, "char"), Type::Field => write!(f, "field"), Type::Group => write!(f, "group"), + Type::Char => write!(f, "char"), + Type::Scalar => write!(f, "scalar"), Type::IntegerType(ref integer_type) => write!(f, "{}", integer_type), Type::Err => write!(f, "error"), } diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index b75d5685c8..bc63fe36f7 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -32,6 +32,7 @@ const INT_TYPES: &[Token] = &[ Token::U128, Token::Field, Token::Group, + Token::Scalar, ]; impl ParserContext<'_> { @@ -294,7 +295,11 @@ impl ParserContext<'_> { assert_no_whitespace("group")?; Expression::Value(ValueExpression::Group(Box::new(GroupValue::Single(value, full_span)))) } - // todo @collinc97 parse scalar type here. + // Literal followed by `scalar` e.g., `42scalar`. + Some(Token::Scalar) => { + assert_no_whitespace("scalar")?; + Expression::Value(ValueExpression::Scalar(value, full_span)) + } // Literal followed by other type suffix, e.g., `42u8`. Some(suffix) => { assert_no_whitespace(&suffix.to_string())?; diff --git a/compiler/parser/src/parser/type_.rs b/compiler/parser/src/parser/type_.rs index e2e2fb59c9..ffe698c87c 100644 --- a/compiler/parser/src/parser/type_.rs +++ b/compiler/parser/src/parser/type_.rs @@ -65,7 +65,7 @@ impl ParserContext<'_> { Token::Field => Type::Field, Token::Group => Type::Group, Token::Char => Type::Char, - // todo @collin parse scalar type here. + Token::Scalar => Type::Scalar, x => Type::IntegerType(Self::token_to_int_type(x).expect("invalid int type")), }, span, diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index bcbccba8eb..180fb88017 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -143,6 +143,7 @@ impl<'a> TypeChecker<'a> { Some(self.assert_type(Type::IntegerType(*type_), expected, value.span())) } ValueExpression::Group(_) => Some(self.assert_type(Type::Group, expected, value.span())), + ValueExpression::Scalar(_, _) => Some(self.assert_type(Type::Scalar, expected, value.span())), ValueExpression::String(_, _) => unreachable!("String types are not reachable"), }, Expression::Binary(binary) => match binary.op { From 60f6b776296fa0df73d0b496fb54f0d249bd725d Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 10 May 2022 16:26:35 -0700 Subject: [PATCH 03/26] add scalar operation type checking --- compiler/parser/src/parser/expression.rs | 4 +-- .../src/type_checker/check_expressions.rs | 20 +++++++---- compiler/passes/src/type_checker/checker.rs | 33 +++++++++++++++---- 3 files changed, 43 insertions(+), 14 deletions(-) diff --git a/compiler/parser/src/parser/expression.rs b/compiler/parser/src/parser/expression.rs index bc63fe36f7..bed7d2906e 100644 --- a/compiler/parser/src/parser/expression.rs +++ b/compiler/parser/src/parser/expression.rs @@ -153,7 +153,7 @@ impl ParserContext<'_> { /// Returns an [`Expression`] AST node if the next tokens represent a /// binary relational expression: less than, less than or equals, greater than, greater than or equals. /// - /// Otherwise, tries to parse the next token using [`parse_shift_expression`]. + /// Otherwise, tries to parse the next token using [`parse_additive_expression`]. pub fn parse_ordering_expression(&mut self) -> Result { self.parse_bin_expr( &[Token::Lt, Token::LtEq, Token::Gt, Token::GtEq], @@ -164,7 +164,7 @@ impl ParserContext<'_> { /// Returns an [`Expression`] AST node if the next tokens represent a /// binary addition or subtraction expression. /// - /// Otherwise, tries to parse the next token using [`parse_mul_div_pow_expression`]. + /// Otherwise, tries to parse the next token using [`parse_multiplicative_expression`]. pub fn parse_additive_expression(&mut self) -> Result { self.parse_bin_expr(&[Token::Add, Token::Minus], Self::parse_multiplicative_expression) } diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index 180fb88017..07d056eba6 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -154,29 +154,37 @@ impl<'a> TypeChecker<'a> { return_incorrect_type(t1, t2, expected) } - BinaryOperation::Add | BinaryOperation::Sub => { - self.assert_arith_type(expected.clone(), binary.span()); + BinaryOperation::Add => { + self.assert_field_group_scalar_int_type(expected.clone(), binary.span()); + let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); + let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); + + return_incorrect_type(t1, t2, expected) + } + BinaryOperation::Sub => { + self.assert_field_group_int_type(expected.clone(), binary.span()); let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); return_incorrect_type(t1, t2, expected) } BinaryOperation::Mul => { - self.assert_arith_type(expected.clone(), binary.span()); + self.assert_field_group_int_type(expected.clone(), binary.span()); let t1 = self.compare_expr_type(&binary.left, None, binary.left.span()); let t2 = self.compare_expr_type(&binary.right, None, binary.right.span()); + // Allow `group` * `scalar` multiplication. match (t1.as_ref(), t2.as_ref()) { - (Some(Type::Group), Some(other)) | (Some(other), Some(Type::Group)) => { - self.assert_int_type(Some(other.clone()), binary.span()); + (Some(Type::Group), Some(Type::Scalar)) + | (Some(Type::Scalar), Some(Type::Group)) => { Some(Type::Group) } _ => return_incorrect_type(t1, t2, expected), } } BinaryOperation::Div => { - self.assert_field_or_int_type(expected.clone(), binary.span()); + self.assert_field_int_type(expected.clone(), binary.span()); let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); diff --git a/compiler/passes/src/type_checker/checker.rs b/compiler/passes/src/type_checker/checker.rs index 2039a66cdd..55fe75155e 100644 --- a/compiler/passes/src/type_checker/checker.rs +++ b/compiler/passes/src/type_checker/checker.rs @@ -27,7 +27,24 @@ pub struct TypeChecker<'a> { pub(crate) negate: bool, } -const ARITHMETIC_TYPES: &[Type] = &[ +// todo @gluax: find a more scalable way to check for types +const FIELD_GROUP_SCALAR_INT: &[Type] = &[ + Type::Field, + Type::Group, + Type::Scalar, + Type::IntegerType(IntegerType::I8), + Type::IntegerType(IntegerType::I16), + Type::IntegerType(IntegerType::I32), + Type::IntegerType(IntegerType::I64), + Type::IntegerType(IntegerType::I128), + Type::IntegerType(IntegerType::U8), + Type::IntegerType(IntegerType::U16), + Type::IntegerType(IntegerType::U32), + Type::IntegerType(IntegerType::U64), + Type::IntegerType(IntegerType::U128), +]; + +const FIELD_GROUP_INT: &[Type] = &[ Type::Field, Type::Group, Type::IntegerType(IntegerType::I8), @@ -42,7 +59,7 @@ const ARITHMETIC_TYPES: &[Type] = &[ Type::IntegerType(IntegerType::U128), ]; -const FIELD_AND_INT_TYPES: &[Type] = &[ +const FIELD_INT_TYPES: &[Type] = &[ Type::Field, Type::IntegerType(IntegerType::I8), Type::IntegerType(IntegerType::I16), @@ -111,12 +128,16 @@ impl<'a> TypeChecker<'a> { type_ } - pub(crate) fn assert_arith_type(&self, type_: Option, span: &Span) -> Option { - self.assert_one_of_types(type_, ARITHMETIC_TYPES, span) + pub(crate) fn assert_field_group_scalar_int_type(&self, type_: Option, span: &Span) -> Option { + self.assert_one_of_types(type_, FIELD_GROUP_SCALAR_INT, span) } - pub(crate) fn assert_field_or_int_type(&self, type_: Option, span: &Span) -> Option { - self.assert_one_of_types(type_, FIELD_AND_INT_TYPES, span) + pub(crate) fn assert_field_group_int_type(&self, type_: Option, span: &Span) -> Option { + self.assert_one_of_types(type_, FIELD_GROUP_INT, span) + } + + pub(crate) fn assert_field_int_type(&self, type_: Option, span: &Span) -> Option { + self.assert_one_of_types(type_, FIELD_INT_TYPES, span) } pub(crate) fn assert_int_type(&self, type_: Option, span: &Span) -> Option { From 455603f0a47b4e068817af707ba361cd977d8f45 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 10 May 2022 16:35:53 -0700 Subject: [PATCH 04/26] cargo fmt --- compiler/ast/src/expression/value.rs | 4 +--- compiler/passes/src/type_checker/check_expressions.rs | 11 +++++------ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/compiler/ast/src/expression/value.rs b/compiler/ast/src/expression/value.rs index c97f538c40..1e9e148740 100644 --- a/compiler/ast/src/expression/value.rs +++ b/compiler/ast/src/expression/value.rs @@ -89,9 +89,7 @@ impl Node for ValueExpression { | Field(_, span) | Integer(_, _, span) | Scalar(_, span) - | String(_, span) => { - *span = new_span - } + | String(_, span) => *span = new_span, Char(character) => character.span = new_span, Group(group) => match &mut **group { GroupValue::Single(_, span) => *span = new_span, diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index 07d056eba6..08ed9f69d8 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -155,11 +155,11 @@ impl<'a> TypeChecker<'a> { return_incorrect_type(t1, t2, expected) } BinaryOperation::Add => { - self.assert_field_group_scalar_int_type(expected.clone(), binary.span()); - let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); - let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); + self.assert_field_group_scalar_int_type(expected.clone(), binary.span()); + let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); + let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); - return_incorrect_type(t1, t2, expected) + return_incorrect_type(t1, t2, expected) } BinaryOperation::Sub => { self.assert_field_group_int_type(expected.clone(), binary.span()); @@ -176,8 +176,7 @@ impl<'a> TypeChecker<'a> { // Allow `group` * `scalar` multiplication. match (t1.as_ref(), t2.as_ref()) { - (Some(Type::Group), Some(Type::Scalar)) - | (Some(Type::Scalar), Some(Type::Group)) => { + (Some(Type::Group), Some(Type::Scalar)) | (Some(Type::Scalar), Some(Type::Group)) => { Some(Type::Group) } _ => return_incorrect_type(t1, t2, expected), From a9564552a9427939193b2d5f5d9d140a357eb29f Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Fri, 13 May 2022 21:32:56 -0700 Subject: [PATCH 05/26] [ABNF] Add scalar type. --- docs/grammar/README.md | Bin 50354 -> 24554 bytes docs/grammar/abnf-grammar.txt | 8 +++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/grammar/README.md b/docs/grammar/README.md index b25a20102ef10fb58f8ce66d81282b09b1ad4ac6..97245ad1535ea78f70eb461c0f07edb35dbd6ef4 100644 GIT binary patch literal 24554 zcmdU1YjfPjvHi|pF~O}QB(K0FsYtS|M~aq3TUCm!66H$yN-7)N1xdt9fB~=)8OQ(q zo}K|PGY5?oX)&opuA<55(>?u~_h6n@7gu$0de)lFr(0%!cklCbe|LZ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_&GA&y< zk8V@WYO|nYZL1+@JM&pU$T!d7%BYi5ur}wVM_Z1w5!hEf)>@;|7S_fhaU_(=+4O^7 zb%$8`Yh8x^)tVX~OnNmMi!zKijvYOw*0x$bCZQ2*qZ!pbPQ@HMM<}T*BAx1gDLd;h zg09IDntm#O9=os6b2(s~m+$Bsl>;(MJi*y}x5HExIj#9a)O#wct6_{_G1Pp>Cz%=| amradoR5~^`9g7e~r4q?op3BU7oc{nv?+ Date: Sat, 14 May 2022 20:27:08 -0700 Subject: [PATCH 06/26] added scalar tests --- .gitignore | 3 +++ tests/compiler/scalar/add.leo | 10 ++++++++++ tests/compiler/scalar/cmp.leo | 16 ++++++++++++++++ tests/compiler/scalar/div.leo | 10 ++++++++++ tests/compiler/scalar/group_mul.leo | 15 +++++++++++++++ tests/compiler/scalar/inputs/scalar_group.in | 7 +++++++ tests/compiler/scalar/inputs/scalars.in | 7 +++++++ tests/compiler/scalar/mul.leo | 10 ++++++++++ tests/compiler/scalar/negate.leo | 10 ++++++++++ .../compiler/scalar/no_space_between_literal.leo | 8 ++++++++ tests/compiler/scalar/scalar.leo | 11 +++++++++++ tests/compiler/scalar/ternary.leo | 10 ++++++++++ 12 files changed, 117 insertions(+) create mode 100644 tests/compiler/scalar/add.leo create mode 100644 tests/compiler/scalar/cmp.leo create mode 100644 tests/compiler/scalar/div.leo create mode 100644 tests/compiler/scalar/group_mul.leo create mode 100644 tests/compiler/scalar/inputs/scalar_group.in create mode 100644 tests/compiler/scalar/inputs/scalars.in create mode 100644 tests/compiler/scalar/mul.leo create mode 100644 tests/compiler/scalar/negate.leo create mode 100644 tests/compiler/scalar/no_space_between_literal.leo create mode 100644 tests/compiler/scalar/scalar.leo create mode 100644 tests/compiler/scalar/ternary.leo diff --git a/.gitignore b/.gitignore index d29c5a8cce..a1484c9626 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,6 @@ sccache*/ *~ \#*\# .\#* + +# code coverage scripts +*.bat \ No newline at end of file diff --git a/tests/compiler/scalar/add.leo b/tests/compiler/scalar/add.leo new file mode 100644 index 0000000000..2fca0c0f53 --- /dev/null +++ b/tests/compiler/scalar/add.leo @@ -0,0 +1,10 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar, b: scalar, c: scalar) -> bool { + return a + b == c; +} \ No newline at end of file diff --git a/tests/compiler/scalar/cmp.leo b/tests/compiler/scalar/cmp.leo new file mode 100644 index 0000000000..0eae370af0 --- /dev/null +++ b/tests/compiler/scalar/cmp.leo @@ -0,0 +1,16 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar, b: scalar) -> bool { + let c: bool = a == b; + let d: bool = a != b; + let e: bool = a > b; + let f: bool = a < b; + let g: bool = a >= b; + let h: bool = a <= b; + return h; +} \ No newline at end of file diff --git a/tests/compiler/scalar/div.leo b/tests/compiler/scalar/div.leo new file mode 100644 index 0000000000..679abbe3da --- /dev/null +++ b/tests/compiler/scalar/div.leo @@ -0,0 +1,10 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar, b: scalar, c: scalar) -> bool { + return a / b != c; +} \ No newline at end of file diff --git a/tests/compiler/scalar/group_mul.leo b/tests/compiler/scalar/group_mul.leo new file mode 100644 index 0000000000..1b170e53f6 --- /dev/null +++ b/tests/compiler/scalar/group_mul.leo @@ -0,0 +1,15 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalar_group.in +*/ + +function main(a: scalar, b: group, c: scalar) -> bool { + let d: group = 1group * a; + let e: group = a * 1group; + let f: group = b * a; + let g: group = a * b; + + return a * g == d; +} \ No newline at end of file diff --git a/tests/compiler/scalar/inputs/scalar_group.in b/tests/compiler/scalar/inputs/scalar_group.in new file mode 100644 index 0000000000..29402e1539 --- /dev/null +++ b/tests/compiler/scalar/inputs/scalar_group.in @@ -0,0 +1,7 @@ +[main] +a: scalar = 1scalar; +b: group = 1group; +c: scalar = 2scalar; + +[registers] +r: bool = false; \ No newline at end of file diff --git a/tests/compiler/scalar/inputs/scalars.in b/tests/compiler/scalar/inputs/scalars.in new file mode 100644 index 0000000000..6aa25f85f8 --- /dev/null +++ b/tests/compiler/scalar/inputs/scalars.in @@ -0,0 +1,7 @@ +[main] +a: scalar = 1scalar; +b: scalar = 1scalar; +c: scalar = 2scalar; + +[registers] +r: bool = false; \ No newline at end of file diff --git a/tests/compiler/scalar/mul.leo b/tests/compiler/scalar/mul.leo new file mode 100644 index 0000000000..4ce11e0345 --- /dev/null +++ b/tests/compiler/scalar/mul.leo @@ -0,0 +1,10 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar, b: scalar, c: scalar) -> bool { + return a * b == c; +} \ No newline at end of file diff --git a/tests/compiler/scalar/negate.leo b/tests/compiler/scalar/negate.leo new file mode 100644 index 0000000000..b9d04811c6 --- /dev/null +++ b/tests/compiler/scalar/negate.leo @@ -0,0 +1,10 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar, b: scalar) -> bool { + return -a == -b; +} \ No newline at end of file diff --git a/tests/compiler/scalar/no_space_between_literal.leo b/tests/compiler/scalar/no_space_between_literal.leo new file mode 100644 index 0000000000..26e45dd33f --- /dev/null +++ b/tests/compiler/scalar/no_space_between_literal.leo @@ -0,0 +1,8 @@ +/* +namespace: Compile +expectation: Fail +*/ + +function main() { + const f = 1 scalar; +} \ No newline at end of file diff --git a/tests/compiler/scalar/scalar.leo b/tests/compiler/scalar/scalar.leo new file mode 100644 index 0000000000..0c4bd5d386 --- /dev/null +++ b/tests/compiler/scalar/scalar.leo @@ -0,0 +1,11 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar) -> bool { + const s: scalar = 1scalar; + return s + a == 0scalar; +} \ No newline at end of file diff --git a/tests/compiler/scalar/ternary.leo b/tests/compiler/scalar/ternary.leo new file mode 100644 index 0000000000..91f3c2cf89 --- /dev/null +++ b/tests/compiler/scalar/ternary.leo @@ -0,0 +1,10 @@ +/* +namespace: Compile +expectation: Pass +input_file: + - inputs/scalars.in +*/ + +function main(a: scalar, b: scalar, c: scalar) -> bool { + return b == 1scalar ? a == 1scalar : c == 2scalar; +} \ No newline at end of file From 38fa7a9608aeb5c94fab283211191272d41bad0d Mon Sep 17 00:00:00 2001 From: 0rphon <59403052+0rphon@users.noreply.github.com> Date: Sun, 15 May 2022 21:53:28 -0700 Subject: [PATCH 07/26] added more tests/generated expectations for the ones that pass --- tests/compiler/scalar/cmp.leo | 12 +- tests/compiler/scalar/{negate.leo => eq.leo} | 4 +- .../compiler/compiler/scalar/add.leo.out | 8 + .../compiler/compiler/scalar/div.leo.out | 8 + .../compiler/compiler/scalar/eq.leo.out | 8 + .../compiler/scalar/group_mul.leo.out | 8 + .../compiler/compiler/scalar/mul.leo.out | 8 + .../scalar/no_space_between_literal.leo.out | 5 + .../compiler/compiler/scalar/scalar.leo.out | 8 + .../compiler/compiler/scalar/ternary.leo.out | 8 + .../literal/int_parse/scalar.leo.out | 634 ++++++++++++++++++ .../expression/literal/int_parse/scalar.leo | 114 ++++ 12 files changed, 817 insertions(+), 8 deletions(-) rename tests/compiler/scalar/{negate.leo => eq.leo} (65%) create mode 100644 tests/expectations/compiler/compiler/scalar/add.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/div.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/eq.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/group_mul.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/mul.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/no_space_between_literal.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/scalar.leo.out create mode 100644 tests/expectations/compiler/compiler/scalar/ternary.leo.out create mode 100644 tests/expectations/parser/parser/expression/literal/int_parse/scalar.leo.out create mode 100644 tests/parser/expression/literal/int_parse/scalar.leo diff --git a/tests/compiler/scalar/cmp.leo b/tests/compiler/scalar/cmp.leo index 0eae370af0..8037b65178 100644 --- a/tests/compiler/scalar/cmp.leo +++ b/tests/compiler/scalar/cmp.leo @@ -6,11 +6,9 @@ input_file: */ function main(a: scalar, b: scalar) -> bool { - let c: bool = a == b; - let d: bool = a != b; - let e: bool = a > b; - let f: bool = a < b; - let g: bool = a >= b; - let h: bool = a <= b; - return h; + let c: bool = a > b; + let d: bool = a < b; + let e: bool = a >= b; + let f: bool = a <= b; + return f; } \ No newline at end of file diff --git a/tests/compiler/scalar/negate.leo b/tests/compiler/scalar/eq.leo similarity index 65% rename from tests/compiler/scalar/negate.leo rename to tests/compiler/scalar/eq.leo index b9d04811c6..5b5ea2d294 100644 --- a/tests/compiler/scalar/negate.leo +++ b/tests/compiler/scalar/eq.leo @@ -6,5 +6,7 @@ input_file: */ function main(a: scalar, b: scalar) -> bool { - return -a == -b; + let c: bool = a == b; + let d: bool = a != b; + return d; } \ No newline at end of file diff --git a/tests/expectations/compiler/compiler/scalar/add.leo.out b/tests/expectations/compiler/compiler/scalar/add.leo.out new file mode 100644 index 0000000000..ea4749a6bb --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/add.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 4f141316ffe2f84865d36d0d28d361fdaa90bacf05ff62678d32f901a235ed74 + initial_ast: fd4126b8ea19b5afd542aa1c1ad269656d3bf24297470cbdb64b675184f6e698 + symbol_table: 892d93d278cb7a474cdf2dfd4a40294a748165ebeeb47cba6dbee3f31d7fd586 diff --git a/tests/expectations/compiler/compiler/scalar/div.leo.out b/tests/expectations/compiler/compiler/scalar/div.leo.out new file mode 100644 index 0000000000..4acc34185f --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/div.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 2fdded6208cca2d992178f1ebce1ad848f09f0e7bc5b5a01ee767fafd992737f + initial_ast: c20c79fbafd514aadf1887dea23f564f5e9bbd7c26caf9408bf664a495bfd6aa + symbol_table: eef6184d8de08329af65525b860dea76d00957bbd099b98cb35cc9e22a5c568c diff --git a/tests/expectations/compiler/compiler/scalar/eq.leo.out b/tests/expectations/compiler/compiler/scalar/eq.leo.out new file mode 100644 index 0000000000..25d0c2033a --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/eq.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 33bfdc8b1c15b79c4df536c93be684108ac3f031e23b2a4359f5cdc780ebe6e9 + initial_ast: 73e323d6a21198a304ce5691a6cd8a7c1bd449fff01afad7ea83aa57c31a3554 + symbol_table: 08cd46bf33b7d8cc59bb80d5716911598c0479cd25e30e00a1b47b175d8e7c0f diff --git a/tests/expectations/compiler/compiler/scalar/group_mul.leo.out b/tests/expectations/compiler/compiler/scalar/group_mul.leo.out new file mode 100644 index 0000000000..f00a8829d7 --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/group_mul.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: cf06fc39ca04a486855a4df808362d7a950ecd6fee1bde05bc28011c33404726 + initial_ast: 504a536d2f70bff90e1e941b0c30fd95195757c69326e9d168a224c3f9590de5 + symbol_table: cb5c8eb4006c52c0092effc2219dbd03b90ab1baf39f345f838ada8a57d1158c diff --git a/tests/expectations/compiler/compiler/scalar/mul.leo.out b/tests/expectations/compiler/compiler/scalar/mul.leo.out new file mode 100644 index 0000000000..3ee9e52d74 --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/mul.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 4f141316ffe2f84865d36d0d28d361fdaa90bacf05ff62678d32f901a235ed74 + initial_ast: c2fe013362376acd540235900ae220eef966bb7a870e6bac2efdcdb66bf96aaa + symbol_table: 1c43e99020a8214e8a0a8ff037a79dc12b597c0801642f5a564e8e4b3e42b679 diff --git a/tests/expectations/compiler/compiler/scalar/no_space_between_literal.leo.out b/tests/expectations/compiler/compiler/scalar/no_space_between_literal.leo.out new file mode 100644 index 0000000000..6072996488 --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/no_space_between_literal.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370005]: expected -> -- got '{'\n --> compiler-test:3:17\n |\n 3 | function main() {\n | ^" diff --git a/tests/expectations/compiler/compiler/scalar/scalar.leo.out b/tests/expectations/compiler/compiler/scalar/scalar.leo.out new file mode 100644 index 0000000000..946fc5ea30 --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/scalar.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: f074f67a7d4028112cee3c14d6fa831ac71e0776db4f4f793df9dbfc6bd921c3 + initial_ast: d6a1be88337def873777e4296959ced20e923c27736200993a3e86992d15eb6e + symbol_table: 85a8380cbcefab3e365d6d3f7acbb54125afedb9b8ff98e4513b147ffe0ccf14 diff --git a/tests/expectations/compiler/compiler/scalar/ternary.leo.out b/tests/expectations/compiler/compiler/scalar/ternary.leo.out new file mode 100644 index 0000000000..987893707d --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/ternary.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 33bfdc8b1c15b79c4df536c93be684108ac3f031e23b2a4359f5cdc780ebe6e9 + initial_ast: 0d139bfef33401468cd0ee0591fc2fbb5ddfcc977e4006e6ae8013c73434bbf4 + symbol_table: 3044db73279e2416a04d470427a0f319f13ac1dfbe36706b238e1fa2fb068538 diff --git a/tests/expectations/parser/parser/expression/literal/int_parse/scalar.leo.out b/tests/expectations/parser/parser/expression/literal/int_parse/scalar.leo.out new file mode 100644 index 0000000000..36a69db8b5 --- /dev/null +++ b/tests/expectations/parser/parser/expression/literal/int_parse/scalar.leo.out @@ -0,0 +1,634 @@ +--- +namespace: ParseExpression +expectation: Pass +outputs: + - Value: + Scalar: + - "123" + - span: + lo: 0 + hi: 9 + - Value: + Scalar: + - "123" + - span: + lo: 0 + hi: 9 + - Value: + Scalar: + - "456" + - span: + lo: 0 + hi: 9 + - Value: + Scalar: + - "87377802873778028737780287377802873778028737780287377802873778028737780287377802" + - span: + lo: 0 + hi: 86 + - Value: + Scalar: + - "8737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802" + - span: + lo: 0 + hi: 406 + - Value: + Scalar: + - "340130024" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "158951116" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "155529659" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "642023166" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "228481736" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "469712960" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "929437719" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "721072814" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "363254789" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "906732565" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "288246391" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "724940549" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "487101620" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "261373583" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "891163927" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "743967544" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "8372586" + - span: + lo: 0 + hi: 13 + - Value: + Scalar: + - "461793278" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "806307045" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "122764546" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "356336181" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "158370903" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "774460877" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "557174131" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "492401267" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "893445620" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "957757048" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "721540649" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "390746493" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "211251725" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "938266114" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "156985870" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "703831126" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "729964155" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "988151305" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "320872435" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "719287167" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "152289486" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "740067975" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "728627816" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "385008978" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "553967635" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "71980713" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "519444716" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "116499965" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "717422268" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "18966279" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "22458638" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "857282620" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "920675898" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "762235516" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "469018377" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "199986521" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "536679358" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "591399452" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "83083158" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "599449051" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "445442318" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "585486590" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "209278800" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "873568117" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "664470940" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "465262783" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "605652874" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "376803940" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "965247040" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "598474509" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "845119918" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "648159133" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "669051032" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "800600261" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "434689764" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "520060080" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "804659385" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "537828058" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "716600292" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "387020273" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "199375617" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "680337189" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "818479931" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "893693281" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "87377802" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "84699261" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "292826090" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "569171405" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "387436237" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "150682190" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "888770419" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "824696431" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "765659803" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "270163693" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "427940240" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "504997332" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "337808338" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "907200008" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "757177889" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "696697188" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "41376051" + - span: + lo: 0 + hi: 14 + - Value: + Scalar: + - "496293518" + - span: + lo: 0 + hi: 15 + - Value: + Scalar: + - "251218820" + - span: + lo: 0 + hi: 15 diff --git a/tests/parser/expression/literal/int_parse/scalar.leo b/tests/parser/expression/literal/int_parse/scalar.leo new file mode 100644 index 0000000000..35f5e5b1fd --- /dev/null +++ b/tests/parser/expression/literal/int_parse/scalar.leo @@ -0,0 +1,114 @@ +/* +namespace: ParseExpression +expectation: Pass +*/ + +123scalar + +123scalar +456scalar + +87377802873778028737780287377802873778028737780287377802873778028737780287377802scalar + +8737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802873778028737780287377802scalar + +340130024scalar +158951116scalar +155529659scalar +642023166scalar +228481736scalar +469712960scalar +929437719scalar +721072814scalar +363254789scalar +906732565scalar +288246391scalar +724940549scalar +487101620scalar +261373583scalar +891163927scalar +743967544scalar +8372586scalar +461793278scalar +806307045scalar +122764546scalar +356336181scalar +158370903scalar +774460877scalar +557174131scalar +492401267scalar +893445620scalar +957757048scalar +721540649scalar +390746493scalar +211251725scalar +938266114scalar +156985870scalar +703831126scalar +729964155scalar +988151305scalar +320872435scalar +719287167scalar +152289486scalar +740067975scalar +728627816scalar +385008978scalar +553967635scalar +71980713scalar +519444716scalar +116499965scalar +717422268scalar +18966279scalar +22458638scalar +857282620scalar +920675898scalar +762235516scalar +469018377scalar +199986521scalar +536679358scalar +591399452scalar +83083158scalar +599449051scalar +445442318scalar +585486590scalar +209278800scalar +873568117scalar +664470940scalar +465262783scalar +605652874scalar +376803940scalar +965247040scalar +598474509scalar +845119918scalar +648159133scalar +669051032scalar +800600261scalar +434689764scalar +520060080scalar +804659385scalar +537828058scalar +716600292scalar +387020273scalar +199375617scalar +680337189scalar +818479931scalar +893693281scalar +87377802scalar +84699261scalar +292826090scalar +569171405scalar +387436237scalar +150682190scalar +888770419scalar +824696431scalar +765659803scalar +270163693scalar +427940240scalar +504997332scalar +337808338scalar +907200008scalar +757177889scalar +696697188scalar +41376051scalar +496293518scalar +251218820scalar \ No newline at end of file From 1761b805783cc844c5724a25e0a5476572a02939 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 16 May 2022 21:24:42 -0700 Subject: [PATCH 08/26] [parser] Fix to disallow including loop ending bound. This is not part of the current version of Leo (cf. ABNF grammar and Leo Reference). Adapt tests. --- compiler/parser/src/parser/statement.rs | 3 +- tests/compiler/statements/all_loops.leo | 12 +------ tests/compiler/statements/all_loops_fail.leo | 32 +++++++++++++++++++ .../compiler/statements/all_loops.leo.out | 6 ++-- .../statements/all_loops_fail.leo.out | 5 +++ 5 files changed, 42 insertions(+), 16 deletions(-) create mode 100644 tests/compiler/statements/all_loops_fail.leo create mode 100644 tests/expectations/compiler/compiler/statements/all_loops_fail.leo.out diff --git a/compiler/parser/src/parser/statement.rs b/compiler/parser/src/parser/statement.rs index b464bf21e2..ece8a0da3e 100644 --- a/compiler/parser/src/parser/statement.rs +++ b/compiler/parser/src/parser/statement.rs @@ -140,7 +140,6 @@ impl ParserContext<'_> { // Parse iteration range. let start = self.parse_expression()?; self.expect(&Token::DotDot)?; - let inclusive = self.eat(&Token::Assign); self.disallow_circuit_construction = true; let stop = self.parse_conditional_expression()?; self.disallow_circuit_construction = false; @@ -153,7 +152,7 @@ impl ParserContext<'_> { type_: type_.0, start, stop, - inclusive, + inclusive : false, block, }) } diff --git a/tests/compiler/statements/all_loops.leo b/tests/compiler/statements/all_loops.leo index df25a12a61..d11de29a0e 100644 --- a/tests/compiler/statements/all_loops.leo +++ b/tests/compiler/statements/all_loops.leo @@ -15,15 +15,5 @@ function main(k: bool) -> bool { forward = forward + x; } - let reverse_inclusive: u32 = 0u32; - for a: u32 in 10u32..=0u32 { - reverse_inclusive = reverse_inclusive + a; - } - - let forward_inclusive: u32 = 0u32; - for b: u32 in 0u32..=10u32 { - forward_inclusive = forward_inclusive + b; - } - - return (reverse == forward) && (reverse_inclusive == forward_inclusive) && k; + return (reverse == forward) && k; } \ No newline at end of file diff --git a/tests/compiler/statements/all_loops_fail.leo b/tests/compiler/statements/all_loops_fail.leo new file mode 100644 index 0000000000..6887a32143 --- /dev/null +++ b/tests/compiler/statements/all_loops_fail.leo @@ -0,0 +1,32 @@ +/* +namespace: Compile +expectation: Fail +input_file: inputs/dummy.in + +# inclusive loops are currently disallowed + +*/ + +function main(k: bool) -> bool { + let reverse: u32 = 0u32; + for i: u32 in 9u32..0u32 { + reverse = reverse + i; + } + + let forward: u32 = 0u32; + for x: u32 in 0u32..10u32 { + forward = forward + x; + } + + let reverse_inclusive: u32 = 0u32; + for a: u32 in 10u32..=0u32 { + reverse_inclusive = reverse_inclusive + a; + } + + let forward_inclusive: u32 = 0u32; + for b: u32 in 0u32..=10u32 { + forward_inclusive = forward_inclusive + b; + } + + return (reverse == forward) && (reverse_inclusive == forward_inclusive) && k; +} \ No newline at end of file diff --git a/tests/expectations/compiler/compiler/statements/all_loops.leo.out b/tests/expectations/compiler/compiler/statements/all_loops.leo.out index 2d8cb99122..31974e91f9 100644 --- a/tests/expectations/compiler/compiler/statements/all_loops.leo.out +++ b/tests/expectations/compiler/compiler/statements/all_loops.leo.out @@ -3,6 +3,6 @@ namespace: Compile expectation: Pass outputs: - output: - - initial_input_ast: bddb7d656b6cfdeadae66e437c61090a2f14112e48fe4e23ea0e39e1ce03fed0 - initial_ast: 66baa9f7e32bb00b0c047250c97ff2710a128e9db63d0a7c0459f7673147e124 - symbol_table: 3f85b29e75222f03e70b83cbc2399746f23dbbeabd857acaa486db9e8076c03c + - initial_input_ast: 7f054d619f362422dce83ca5563d462fe3206845a29de38bb3721f3cd2c69c11 + initial_ast: 6b833755871962eb67f0a281ef1edd82bf84b0c9f03154f0b7b0330c554826d4 + symbol_table: bcf9d66217a3cbfc92d16af68089c9644a316cfb072e3bfd6bd76b5ccea0fc18 diff --git a/tests/expectations/compiler/compiler/statements/all_loops_fail.leo.out b/tests/expectations/compiler/compiler/statements/all_loops_fail.leo.out new file mode 100644 index 0000000000..4c3e127148 --- /dev/null +++ b/tests/expectations/compiler/compiler/statements/all_loops_fail.leo.out @@ -0,0 +1,5 @@ +--- +namespace: Compile +expectation: Fail +outputs: + - "Error [EPAR0370009]: unexpected string: expected 'expression', got '='\n --> compiler-test:15:26\n |\n 15 | for a: u32 in 10u32..=0u32 {\n | ^" From b1baf90719f38ff4d7e775893c2412726ad903de Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 16 May 2022 21:27:29 -0700 Subject: [PATCH 09/26] [parser] Adhere to style. --- compiler/parser/src/parser/statement.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/parser/src/parser/statement.rs b/compiler/parser/src/parser/statement.rs index ece8a0da3e..fe99cbf72a 100644 --- a/compiler/parser/src/parser/statement.rs +++ b/compiler/parser/src/parser/statement.rs @@ -152,7 +152,7 @@ impl ParserContext<'_> { type_: type_.0, start, stop, - inclusive : false, + inclusive: false, block, }) } From 7f435eba48621ff2078ebde9caac27fd094e7793 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 17 May 2022 14:41:30 +0200 Subject: [PATCH 10/26] remove expression statements --- .../ast/src/passes/reconstructing_director.rs | 6 - .../ast/src/passes/reconstructing_reducer.rs | 11 -- compiler/ast/src/passes/visitor.rs | 4 - compiler/ast/src/passes/visitor_director.rs | 7 - compiler/ast/src/statements/expression.rs | 38 ------ compiler/ast/src/statements/mod.rs | 3 - compiler/ast/src/statements/statement.rs | 16 ++- compiler/parser/src/parser/statement.rs | 8 +- compiler/parser/src/test.rs | 7 +- .../src/type_checker/check_statements.rs | 6 - leo/errors/src/errors/parser/parser_errors.rs | 8 ++ .../compiler/function/undefined_fail.leo.out | 2 +- .../functions/bounded_recursion.leo.out | 126 +----------------- .../functions/infinite_recursion.leo.out | 70 +--------- .../parser/statement/conditional.leo.out | 18 +-- .../parser/statement/expression.leo.out | 37 +---- .../parser/unreachable/math_op_fail.leo.out | 7 +- .../parser/unreachable/math_op_pass.leo.out | 70 ---------- tests/parser/functions/bounded_recursion.leo | 4 +- tests/parser/functions/infinite_recursion.leo | 4 +- tests/parser/statement/conditional.leo | 3 +- tests/parser/statement/expression.leo | 4 +- tests/parser/unreachable/math_op_fail.leo | 10 ++ tests/parser/unreachable/math_op_pass.leo | 10 -- 24 files changed, 62 insertions(+), 417 deletions(-) delete mode 100644 compiler/ast/src/statements/expression.rs diff --git a/compiler/ast/src/passes/reconstructing_director.rs b/compiler/ast/src/passes/reconstructing_director.rs index 5cd29a1510..466f89b282 100644 --- a/compiler/ast/src/passes/reconstructing_director.rs +++ b/compiler/ast/src/passes/reconstructing_director.rs @@ -126,7 +126,6 @@ impl ReconstructingDirector { Statement::Conditional(conditional) => Statement::Conditional(self.reduce_conditional(conditional)?), Statement::Iteration(iteration) => Statement::Iteration(Box::new(self.reduce_iteration(iteration)?)), Statement::Console(console) => Statement::Console(self.reduce_console(console)?), - Statement::Expression(expression) => Statement::Expression(self.reduce_expression_statement(expression)?), Statement::Block(block) => Statement::Block(self.reduce_block(block)?), }; @@ -241,11 +240,6 @@ impl ReconstructingDirector { self.reducer.reduce_console(console_function_call, function) } - pub fn reduce_expression_statement(&mut self, expression: &ExpressionStatement) -> Result { - let inner_expression = self.reduce_expression(&expression.expression)?; - self.reducer.reduce_expression_statement(expression, inner_expression) - } - pub fn reduce_block(&mut self, block: &Block) -> Result { let mut statements = vec![]; for statement in block.statements.iter() { diff --git a/compiler/ast/src/passes/reconstructing_reducer.rs b/compiler/ast/src/passes/reconstructing_reducer.rs index 5284ba47b5..8b09f97477 100644 --- a/compiler/ast/src/passes/reconstructing_reducer.rs +++ b/compiler/ast/src/passes/reconstructing_reducer.rs @@ -232,17 +232,6 @@ pub trait ReconstructingReducer { }) } - fn reduce_expression_statement( - &mut self, - expression_statement: &ExpressionStatement, - expression: Expression, - ) -> Result { - Ok(ExpressionStatement { - expression, - span: expression_statement.span, - }) - } - fn reduce_block(&mut self, block: &Block, statements: Vec) -> Result { Ok(Block { statements, diff --git a/compiler/ast/src/passes/visitor.rs b/compiler/ast/src/passes/visitor.rs index e1585c7029..79c449cd3d 100644 --- a/compiler/ast/src/passes/visitor.rs +++ b/compiler/ast/src/passes/visitor.rs @@ -92,10 +92,6 @@ pub trait StatementVisitor<'a> { Default::default() } - fn visit_expression_statement(&mut self, _input: &'a ExpressionStatement) -> VisitResult { - Default::default() - } - fn visit_block(&mut self, _input: &'a Block) -> VisitResult { Default::default() } diff --git a/compiler/ast/src/passes/visitor_director.rs b/compiler/ast/src/passes/visitor_director.rs index ede3a24a75..b5866b6ae1 100644 --- a/compiler/ast/src/passes/visitor_director.rs +++ b/compiler/ast/src/passes/visitor_director.rs @@ -91,7 +91,6 @@ impl<'a, V: ExpressionVisitor<'a> + StatementVisitor<'a>> VisitorDirector<'a, V> Statement::Conditional(stmt) => self.visit_conditional(stmt), Statement::Iteration(stmt) => self.visit_iteration(stmt), Statement::Console(stmt) => self.visit_console(stmt), - Statement::Expression(stmt) => self.visit_expression_statement(stmt), Statement::Block(stmt) => self.visit_block(stmt), } } @@ -144,12 +143,6 @@ impl<'a, V: ExpressionVisitor<'a> + StatementVisitor<'a>> VisitorDirector<'a, V> } } - pub fn visit_expression_statement(&mut self, input: &'a ExpressionStatement) { - if let VisitResult::VisitChildren = self.visitor.visit_expression_statement(input) { - self.visit_expression(&input.expression); - } - } - pub fn visit_block(&mut self, input: &'a Block) { if let VisitResult::VisitChildren = self.visitor.visit_block(input) { input.statements.iter().for_each(|stmt| self.visit_statement(stmt)); diff --git a/compiler/ast/src/statements/expression.rs b/compiler/ast/src/statements/expression.rs deleted file mode 100644 index 72c3e40c16..0000000000 --- a/compiler/ast/src/statements/expression.rs +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2019-2022 Aleo Systems Inc. -// This file is part of the Leo library. - -// The Leo library is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// The Leo library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with the Leo library. If not, see . - -use crate::{Expression, Node}; -use leo_span::Span; - -use serde::{Deserialize, Serialize}; -use std::fmt; - -/// An expression statement `expr;`. -#[derive(Clone, PartialEq, Eq, Serialize, Deserialize, Debug)] -pub struct ExpressionStatement { - /// The expression to evaluate purely for its side-effects. - pub expression: Expression, - /// The span excluding the semicolon. - pub span: Span, -} - -impl fmt::Display for ExpressionStatement { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{};", self.expression) - } -} - -crate::simple_node_impl!(ExpressionStatement); diff --git a/compiler/ast/src/statements/mod.rs b/compiler/ast/src/statements/mod.rs index 7a43dcc81f..e609ec6fd9 100644 --- a/compiler/ast/src/statements/mod.rs +++ b/compiler/ast/src/statements/mod.rs @@ -29,9 +29,6 @@ pub use return_statement::*; pub mod iteration; pub use iteration::*; -pub mod expression; -pub use expression::*; - pub mod definition; pub use definition::*; diff --git a/compiler/ast/src/statements/statement.rs b/compiler/ast/src/statements/statement.rs index 01a4fad1d1..fbb1a656b5 100644 --- a/compiler/ast/src/statements/statement.rs +++ b/compiler/ast/src/statements/statement.rs @@ -36,13 +36,20 @@ pub enum Statement { Iteration(Box), /// A console logging statement. Console(ConsoleStatement), - /// An expression statement turning an expression into a statement, - /// using the expression only for its side-effects. - Expression(ExpressionStatement), /// A block statement. Block(Block), } +impl Statement { + /// Returns a dummy statement made from an empty block `{}`. + pub fn dummy(span: Span) -> Self { + Self::Block(Block { + statements: Vec::new(), + span, + }) + } +} + impl fmt::Display for Statement { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self { @@ -52,7 +59,6 @@ impl fmt::Display for Statement { Statement::Conditional(x) => x.fmt(f), Statement::Iteration(x) => x.fmt(f), Statement::Console(x) => x.fmt(f), - Statement::Expression(x) => x.fmt(f), Statement::Block(x) => x.fmt(f), } } @@ -68,7 +74,6 @@ impl Node for Statement { Conditional(n) => n.span(), Iteration(n) => n.span(), Console(n) => n.span(), - Expression(n) => n.span(), Block(n) => n.span(), } } @@ -82,7 +87,6 @@ impl Node for Statement { Conditional(n) => n.set_span(span), Iteration(n) => n.set_span(span), Console(n) => n.set_span(span), - Expression(n) => n.set_span(span), Block(n) => n.set_span(span), } } diff --git a/compiler/parser/src/parser/statement.rs b/compiler/parser/src/parser/statement.rs index b464bf21e2..a214edce0c 100644 --- a/compiler/parser/src/parser/statement.rs +++ b/compiler/parser/src/parser/statement.rs @@ -70,11 +70,11 @@ impl ParserContext<'_> { value, }))) } else { + // Error on `expr;` but recover as an empty block `{}`. self.expect(&Token::Semicolon)?; - Ok(Statement::Expression(ExpressionStatement { - span: expr.span(), - expression: expr, - })) + let span = expr.span() + self.prev_token.span; + self.emit_err(ParserError::expr_stmts_disallowed(span)); + Ok(Statement::dummy(span)) } } diff --git a/compiler/parser/src/test.rs b/compiler/parser/src/test.rs index 8336e64d4f..ccffde5bb1 100644 --- a/compiler/parser/src/test.rs +++ b/compiler/parser/src/test.rs @@ -15,7 +15,7 @@ // along with the Leo library. If not, see . use crate::{tokenizer, ParserContext, SpannedToken}; -use leo_ast::{Expression, ExpressionStatement, Statement, ValueExpression}; +use leo_ast::Statement; use leo_errors::{emitter::Handler, LeoError}; use leo_span::{ source_map::FileName, @@ -122,10 +122,7 @@ impl Namespace for ParseStatementNamespace { create_session_if_not_set_then(|s| { let tokenizer = tokenize(test, s)?; if all_are_comments(&tokenizer) { - return Ok(yaml_or_fail(Statement::Expression(ExpressionStatement { - expression: Expression::Value(ValueExpression::String(Vec::new(), Default::default())), - span: Span::default(), - }))); + return Ok(yaml_or_fail(Statement::dummy(Span::default()))); } with_handler(tokenizer, |p| p.parse_statement()).map(yaml_or_fail) }) diff --git a/compiler/passes/src/type_checker/check_statements.rs b/compiler/passes/src/type_checker/check_statements.rs index 52e9e19c15..82e6afb341 100644 --- a/compiler/passes/src/type_checker/check_statements.rs +++ b/compiler/passes/src/type_checker/check_statements.rs @@ -123,11 +123,6 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { VisitResult::VisitChildren } - fn visit_expression_statement(&mut self, input: &'a ExpressionStatement) -> VisitResult { - self.compare_expr_type(&input.expression, None, input.span()); - VisitResult::SkipChildren - } - fn visit_block(&mut self, input: &'a Block) -> VisitResult { self.symbol_table.push_variable_scope(); // have to redo the logic here so we have scoping @@ -139,7 +134,6 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { Statement::Conditional(stmt) => self.visit_conditional(stmt), Statement::Iteration(stmt) => self.visit_iteration(stmt), Statement::Console(stmt) => self.visit_console(stmt), - Statement::Expression(stmt) => self.visit_expression_statement(stmt), Statement::Block(stmt) => self.visit_block(stmt), }; }); diff --git a/leo/errors/src/errors/parser/parser_errors.rs b/leo/errors/src/errors/parser/parser_errors.rs index bd7bae6151..8a96b70312 100644 --- a/leo/errors/src/errors/parser/parser_errors.rs +++ b/leo/errors/src/errors/parser/parser_errors.rs @@ -390,4 +390,12 @@ create_messages!( msg: "Unicode bidi override code point encountered.", help: None, } + + /// Previously, expression statements were allowed, but not anymore. + @formatted + expr_stmts_disallowed { + args: (), + msg: "Expression statements are no longer supported.", + help: None, + } ); diff --git a/tests/expectations/compiler/compiler/function/undefined_fail.leo.out b/tests/expectations/compiler/compiler/function/undefined_fail.leo.out index 1d76cbecb4..9be49fd311 100644 --- a/tests/expectations/compiler/compiler/function/undefined_fail.leo.out +++ b/tests/expectations/compiler/compiler/function/undefined_fail.leo.out @@ -2,4 +2,4 @@ namespace: Compile expectation: Fail outputs: - - "Error [ETYC0372003]: Unknown function `my_function`\n --> compiler-test:4:5\n |\n 4 | my_function();\n | ^^^^^^^^^^^\nError [ETYC0372003]: Unknown function `my_function`\n --> compiler-test:4:5\n |\n 4 | my_function();\n | ^^^^^^^^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> compiler-test:4:5\n |\n 4 | my_function();\n | ^^^^^^^^^^^^^^" diff --git a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out index ae03128631..6064028db5 100644 --- a/tests/expectations/parser/parser/functions/bounded_recursion.leo.out +++ b/tests/expectations/parser/parser/functions/bounded_recursion.leo.out @@ -1,127 +1,5 @@ --- namespace: Parse -expectation: Pass +expectation: Fail outputs: - - name: "" - expected_input: [] - functions: - "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":12}\"}": - identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":12}\"}" - input: - - Variable: - identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":22,\\\"hi\\\":23}\"}" - mode: Constant - type_: - IntegerType: U32 - span: - lo: 22 - hi: 23 - output: - IntegerType: U8 - core_mapping: ~ - block: - statements: - - Conditional: - condition: - Binary: - left: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":45,\\\"hi\\\":46}\"}" - right: - Value: - Integer: - - U32 - - "5" - - span: - lo: 49 - hi: 53 - op: Lt - span: - lo: 45 - hi: 53 - block: - statements: - - Expression: - expression: - Call: - function: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":64,\\\"hi\\\":65}\"}" - arguments: - - Binary: - left: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":66,\\\"hi\\\":67}\"}" - right: - Value: - Integer: - - U32 - - "1" - - span: - lo: 68 - hi: 72 - op: Add - span: - lo: 66 - hi: 72 - span: - lo: 64 - hi: 73 - span: - lo: 64 - hi: 73 - span: - lo: 54 - hi: 80 - next: ~ - span: - lo: 42 - hi: 80 - span: - lo: 36 - hi: 82 - span: - lo: 2 - hi: 82 - "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":93,\\\"hi\\\":97}\"}": - identifier: "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":93,\\\"hi\\\":97}\"}" - input: - - Variable: - identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":98,\\\"hi\\\":99}\"}" - mode: Private - type_: Boolean - span: - lo: 98 - hi: 99 - output: Boolean - core_mapping: ~ - block: - statements: - - Expression: - expression: - Call: - function: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":121,\\\"hi\\\":122}\"}" - arguments: - - Value: - Integer: - - U32 - - "1" - - span: - lo: 123 - hi: 127 - span: - lo: 121 - hi: 128 - span: - lo: 121 - hi: 128 - - Return: - expression: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":141,\\\"hi\\\":142}\"}" - span: - lo: 134 - hi: 142 - span: - lo: 115 - hi: 145 - span: - lo: 84 - hi: 145 + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:5:9\n |\n 5 | x(y+1u32);\n | ^^^^^^^^^^\nError [EPAR0370045]: Expression statements are no longer supported.\n --> test:10:5\n |\n 10 | x(1u32);\n | ^^^^^^^^" diff --git a/tests/expectations/parser/parser/functions/infinite_recursion.leo.out b/tests/expectations/parser/parser/functions/infinite_recursion.leo.out index 9ebf08be58..4b24f07728 100644 --- a/tests/expectations/parser/parser/functions/infinite_recursion.leo.out +++ b/tests/expectations/parser/parser/functions/infinite_recursion.leo.out @@ -1,71 +1,5 @@ --- namespace: Parse -expectation: Pass +expectation: Fail outputs: - - name: "" - expected_input: [] - functions: - "{\"name\":\"inf\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":14}\"}": - identifier: "{\"name\":\"inf\",\"span\":\"{\\\"lo\\\":11,\\\"hi\\\":14}\"}" - input: [] - output: - IntegerType: U8 - core_mapping: ~ - block: - statements: - - Expression: - expression: - Call: - function: - Identifier: "{\"name\":\"inf\",\"span\":\"{\\\"lo\\\":29,\\\"hi\\\":32}\"}" - arguments: [] - span: - lo: 29 - hi: 34 - span: - lo: 29 - hi: 34 - span: - lo: 23 - hi: 37 - span: - lo: 2 - hi: 37 - "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":48,\\\"hi\\\":52}\"}": - identifier: "{\"name\":\"main\",\"span\":\"{\\\"lo\\\":48,\\\"hi\\\":52}\"}" - input: - - Variable: - identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":53,\\\"hi\\\":54}\"}" - mode: Private - type_: Boolean - span: - lo: 53 - hi: 54 - output: Boolean - core_mapping: ~ - block: - statements: - - Expression: - expression: - Call: - function: - Identifier: "{\"name\":\"inf\",\"span\":\"{\\\"lo\\\":76,\\\"hi\\\":79}\"}" - arguments: [] - span: - lo: 76 - hi: 81 - span: - lo: 76 - hi: 81 - - Return: - expression: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":94,\\\"hi\\\":95}\"}" - span: - lo: 87 - hi: 95 - span: - lo: 70 - hi: 98 - span: - lo: 39 - hi: 98 + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:4:5\n |\n 4 | inf();\n | ^^^^^^\nError [EPAR0370045]: Expression statements are no longer supported.\n --> test:8:5\n |\n 8 | inf();\n | ^^^^^^" diff --git a/tests/expectations/parser/parser/statement/conditional.leo.out b/tests/expectations/parser/parser/statement/conditional.leo.out index 43b664b90e..c0e7b68f10 100644 --- a/tests/expectations/parser/parser/statement/conditional.leo.out +++ b/tests/expectations/parser/parser/statement/conditional.leo.out @@ -125,12 +125,6 @@ outputs: hi: 6 block: statements: - - Expression: - expression: - Identifier: "{\"name\":\"expr\",\"span\":\"{\\\"lo\\\":9,\\\"hi\\\":13}\"}" - span: - lo: 9 - hi: 13 - Return: expression: Value: @@ -138,15 +132,15 @@ outputs: - U8 - "0" - span: - lo: 22 - hi: 25 + lo: 16 + hi: 19 span: - lo: 15 - hi: 25 + lo: 9 + hi: 19 span: lo: 7 - hi: 28 + hi: 22 next: ~ span: lo: 0 - hi: 28 + hi: 22 diff --git a/tests/expectations/parser/parser/statement/expression.leo.out b/tests/expectations/parser/parser/statement/expression.leo.out index d15843dd71..5405617d20 100644 --- a/tests/expectations/parser/parser/statement/expression.leo.out +++ b/tests/expectations/parser/parser/statement/expression.leo.out @@ -1,36 +1,7 @@ --- namespace: ParseStatement -expectation: Pass +expectation: Fail outputs: - - Expression: - expression: - Identifier: "{\"name\":\"expr\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":4}\"}" - span: - lo: 0 - hi: 4 - - Expression: - expression: - Binary: - left: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - right: - Identifier: "{\"name\":\"y\",\"span\":\"{\\\"lo\\\":2,\\\"hi\\\":3}\"}" - op: Add - span: - lo: 0 - hi: 3 - span: - lo: 0 - hi: 3 - - Expression: - expression: - Call: - function: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - arguments: [] - span: - lo: 0 - hi: 3 - span: - lo: 0 - hi: 3 + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | expr;\n | ^^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x+y;\n | ^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x();\n | ^^^^" diff --git a/tests/expectations/parser/parser/unreachable/math_op_fail.leo.out b/tests/expectations/parser/parser/unreachable/math_op_fail.leo.out index 43623c7643..eafce08b2d 100644 --- a/tests/expectations/parser/parser/unreachable/math_op_fail.leo.out +++ b/tests/expectations/parser/parser/unreachable/math_op_fail.leo.out @@ -40,7 +40,7 @@ outputs: - "Error [EPAR0370005]: expected : -- got '='\n --> test:1:7\n |\n 1 | let x = a true b;\n | ^" - "Error [EPAR0370005]: expected : -- got '='\n --> test:1:7\n |\n 1 | let x = a false b;\n | ^" - "Error [EPAR0370005]: expected : -- got '='\n --> test:1:7\n |\n 1 | let x = a 0 b;\n | ^" - - "did not consume all input: '=' @ 1:3-4\n'b' @ 1:4-5\n';' @ 1:5-6\n" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x;=b;\n | ^^" - "Error [EPAR0370009]: unexpected string: expected 'int or ident', got '='\n --> test:1:3\n |\n 1 | x.=b;\n | ^" - "Error [EPAR0370005]: expected ; -- got ','\n --> test:1:2\n |\n 1 | x,=b; // 43\n | ^" - "Error [EPAR0370005]: expected ; -- got '['\n --> test:1:2\n |\n 1 | x[=b;\n | ^" @@ -57,3 +57,8 @@ outputs: - "Error [EPAR0370009]: unexpected string: expected 'expression', got '='\n --> test:1:4\n |\n 1 | x<==b;\n | ^" - "Error [EPAR0370005]: expected ; -- got '..'\n --> test:1:2\n |\n 1 | x..=b;\n | ^^" - "Error [EPAR0370023]: Expected more characters to lex but found none." + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x==b;\n | ^^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x!=b;\n | ^^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x>=b;\n | ^^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x<=b;\n | ^^^^^" + - "Error [EPAR0370045]: Expression statements are no longer supported.\n --> test:1:1\n |\n 1 | x>=b;\n | ^^^^^" diff --git a/tests/expectations/parser/parser/unreachable/math_op_pass.leo.out b/tests/expectations/parser/parser/unreachable/math_op_pass.leo.out index 653e6c0ce5..5084db5caa 100644 --- a/tests/expectations/parser/parser/unreachable/math_op_pass.leo.out +++ b/tests/expectations/parser/parser/unreachable/math_op_pass.leo.out @@ -176,76 +176,6 @@ outputs: span: lo: 0 hi: 4 - - Expression: - expression: - Binary: - left: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - right: - Identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":3,\\\"hi\\\":4}\"}" - op: Eq - span: - lo: 0 - hi: 4 - span: - lo: 0 - hi: 4 - - Expression: - expression: - Binary: - left: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - right: - Identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":3,\\\"hi\\\":4}\"}" - op: Ne - span: - lo: 0 - hi: 4 - span: - lo: 0 - hi: 4 - - Expression: - expression: - Binary: - left: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - right: - Identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":3,\\\"hi\\\":4}\"}" - op: Ge - span: - lo: 0 - hi: 4 - span: - lo: 0 - hi: 4 - - Expression: - expression: - Binary: - left: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - right: - Identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":3,\\\"hi\\\":4}\"}" - op: Le - span: - lo: 0 - hi: 4 - span: - lo: 0 - hi: 4 - - Expression: - expression: - Binary: - left: - Identifier: "{\"name\":\"x\",\"span\":\"{\\\"lo\\\":0,\\\"hi\\\":1}\"}" - right: - Identifier: "{\"name\":\"b\",\"span\":\"{\\\"lo\\\":3,\\\"hi\\\":4}\"}" - op: Ge - span: - lo: 0 - hi: 4 - span: - lo: 0 - hi: 4 - Assign: operation: Assign assignee: diff --git a/tests/parser/functions/bounded_recursion.leo b/tests/parser/functions/bounded_recursion.leo index 865b1db8ca..bc3469337c 100644 --- a/tests/parser/functions/bounded_recursion.leo +++ b/tests/parser/functions/bounded_recursion.leo @@ -1,6 +1,6 @@ /* namespace: Parse -expectation: Pass +expectation: Fail */ function x(constant y: u32) -> u8 { @@ -12,4 +12,4 @@ function x(constant y: u32) -> u8 { function main(y: bool) -> bool { x(1u32); return y; -} \ No newline at end of file +} diff --git a/tests/parser/functions/infinite_recursion.leo b/tests/parser/functions/infinite_recursion.leo index a5e75c96b9..c165b847fe 100644 --- a/tests/parser/functions/infinite_recursion.leo +++ b/tests/parser/functions/infinite_recursion.leo @@ -1,6 +1,6 @@ /* namespace: Parse -expectation: Pass +expectation: Fail */ function inf() -> u8 { @@ -10,4 +10,4 @@ function inf() -> u8 { function main(y: bool) -> bool { inf(); return y; -} \ No newline at end of file +} diff --git a/tests/parser/statement/conditional.leo b/tests/parser/statement/conditional.leo index 19e74a1837..babc32c1e6 100644 --- a/tests/parser/statement/conditional.leo +++ b/tests/parser/statement/conditional.leo @@ -16,6 +16,5 @@ if (x) {} else {} if x+y {} else if x+z {} else {} if x+y { - expr; return 0u8; -} \ No newline at end of file +} diff --git a/tests/parser/statement/expression.leo b/tests/parser/statement/expression.leo index 1a5b3b1fe1..373f1ec756 100644 --- a/tests/parser/statement/expression.leo +++ b/tests/parser/statement/expression.leo @@ -1,10 +1,10 @@ /* namespace: ParseStatement -expectation: Pass +expectation: Fail */ expr; x+y; -x(); \ No newline at end of file +x(); diff --git a/tests/parser/unreachable/math_op_fail.leo b/tests/parser/unreachable/math_op_fail.leo index 729bf30abb..3e6a77f7b3 100644 --- a/tests/parser/unreachable/math_op_fail.leo +++ b/tests/parser/unreachable/math_op_fail.leo @@ -113,3 +113,13 @@ x<==b; x..=b; x&=b; + +x==b; + +x!=b; + +x>=b; + +x<=b; + +x>=b; diff --git a/tests/parser/unreachable/math_op_pass.leo b/tests/parser/unreachable/math_op_pass.leo index f85dd305e4..25abd9e802 100644 --- a/tests/parser/unreachable/math_op_pass.leo +++ b/tests/parser/unreachable/math_op_pass.leo @@ -20,16 +20,6 @@ let x: u8 = a > b; x_=b; -x==b; - -x!=b; - -x>=b; - -x<=b; - -x>=b; - xconsole=b; xconst=b; From 5ec6d873a726e430daa1c7ee11121e0fd7489ca7 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Tue, 17 May 2022 16:07:43 +0200 Subject: [PATCH 11/26] fix #1811 --- leo/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/leo/main.rs b/leo/main.rs index 676084f013..9f2455819f 100644 --- a/leo/main.rs +++ b/leo/main.rs @@ -207,7 +207,7 @@ fn set_panic_hook() { fn main() { set_panic_hook(); - handle_error(create_session_if_not_set_then(|_| run_with_args(Opt::from_args()))); + create_session_if_not_set_then(|_| handle_error(run_with_args(Opt::from_args()))); } /// Run command with custom build arguments. From 416d8d5ad921c4eec4c2512f0ff63e7324ff75b2 Mon Sep 17 00:00:00 2001 From: Collin Chin <16715212+collinc97@users.noreply.github.com> Date: Tue, 17 May 2022 11:36:04 -0400 Subject: [PATCH 12/26] fix nit --- tests/compiler/statements/all_loops_fail.leo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compiler/statements/all_loops_fail.leo b/tests/compiler/statements/all_loops_fail.leo index 6887a32143..aa8316b366 100644 --- a/tests/compiler/statements/all_loops_fail.leo +++ b/tests/compiler/statements/all_loops_fail.leo @@ -29,4 +29,4 @@ function main(k: bool) -> bool { } return (reverse == forward) && (reverse_inclusive == forward_inclusive) && k; -} \ No newline at end of file +} From 560ea590a9d71065d8a51d06b646852fd98df2d4 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Thu, 19 May 2022 20:31:05 -0700 Subject: [PATCH 13/26] [tests] Change category of the `0x` tests --- tests/parser/expression/literal/int_fail.leo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/parser/expression/literal/int_fail.leo b/tests/parser/expression/literal/int_fail.leo index b1bd6f4b43..88802af063 100644 --- a/tests/parser/expression/literal/int_fail.leo +++ b/tests/parser/expression/literal/int_fail.leo @@ -1,5 +1,5 @@ /* -namespace: Token +namespace: ParseExpression expectation: Fail */ From 09001004d4938b159175f5046dadcef6fb898468 Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Fri, 20 May 2022 21:58:51 -0700 Subject: [PATCH 14/26] [ABNF] Refine the rule for input titles. Since we only allow four kinds of input section titles, corresponding to the public/private/constant/const characterization of function inputs, it seems beneficial to put this into the grammar, where it is easily captured. Note that the previous version of the rule, which uses `identifier`, is not quite right, because, for example, `public` is not an identiifer (it is a keyword). So the rule would have to be modified anyways. --- docs/grammar/README.md | Bin 50354 -> 24201 bytes docs/grammar/abnf-grammar.txt | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/grammar/README.md b/docs/grammar/README.md index b25a20102ef10fb58f8ce66d81282b09b1ad4ac6..e7710dd5dc5d0597a60859110950a8c1955bd626 100644 GIT binary patch literal 24201 zcmdU1YjfPjvHi|pF~O}QB(K0FsYtS|M~aq3TUCm!66H$yN-7)N1xdspzyMf@jN|`) zPtRa6GY5?oX)&opuA<55(>?u~o(BeaT3=i>#pzjRHlJ>p{oTFK)BWB3eRELewK=+K zyZpR0&#U>)#_O}9H77-x8~pzwYdTY(nC>h$FMuqI<0fmab~XTuS_FL35mp4$O@9*nxzc*j! zRo-N!dAU3;i@AAG%=4j=6&9@ z_}koFb z_42!;XFKKyj)4a@);RRU2BgW&BJZ-IY+>vV2ww}0%7r=0-scG8JTKlupUljWOe-f& z3*E@dx;nLXS-*t&W1gRws_yQX7P>t;>$;2fi`neMhYvfa)pDn9PG<u$S;dIQsV0-J3r5wfixf>@@SSl+4$+FpR(iXWW%!tl!>{xm@I}IW883$FO`ck8dpI-RA!wtDAIQS6yCp zscqc4W8OrZjEaa`KR!f62mhbdP4N#%%gVINj!DOuXe01By!p^P`sTHbZy=~Fsysc( z^99Km+AaHmV}EhT>~oB`B0J5~ChwL_MM8*bMSbN&J$=QZ+KX(SlK|Uh+4grG-_c9v zThyp;dHVNd-7$Mea#HrKl!UVxX*40C4MBmzS;ZM%%qWz}q1F$(%I@FhkR zGCqp11PGn3f>tUV(ykLV+9_n+DEc~>d{>pdE4@XyE; zDZjJZv}edqF^cj`F>f8bx7LN`%k-%$Mc1`dtPTEA3?E_0i0zMtd><;qCxtW2Z1KQx zHvf4lw3FCXnD?y3`*+iOU)ta9ef3+6C(9Et`|WLpJRFK2vw0G`viZKV`LkQK`H#11 zv&~sq=M`1f)m&MK3cH3JhiNn-l$HTaAtFw$Genk2Y>>p*fk2bjhqD56v{LRp0p_^c zKQlC&&77UyFQk7AXO&{=puLyI4Auruwv)DK&N!V~%#eJh0izD=^l0`|8)8L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00ER<5QcwMiLNv=+1wp`=N3 zXY)3k$eY))CjAw3xgORE^}g*#QZAm>LqxTEa#}t;&O;nycq}cJW;%~0&4PR_WVk*Q ztFxvjRzr=(@J!AO!^*8@-8IdxV%s$wwQP?R=TY8AQ=TyO*p&yH$=ri+Uivs6ZKy8b z{hAFN$m~7*2KR}}^90MoZ7#j_E3Q8soN24sJ7SCOtT9XWXt9RGv{s|JNN=m}q2T(g z)3v;*UfLtW(u(U?Os-xWpGWM3ofBM2Sc}3co66;CXU9rD27qLGcY1vga_8MJ+q01S zzQ*iywL89AU8om-<-CqPr$*;$H>FLy^(BqU;WfDz$qi}Wo#~!P24hiNxij6*zI`Mm zZc4car!Qm)@5&$6R9;DozZBWxL=fiGPvrYTR{v7~(%?bU`Jybh0eyu9L>W+O_OKgqK0RDl$OtGDk*$DcuQMn@n-ejt6k5_{k^nR zT(RER-f_+TJ{EgGUX1?k;puo7R(BXm7)AMR^kpxI{!J0%okO`4YE;_(kqp_&GA&y< zk8V@WYO|nYZL1+@JM&pU$T!d7%BYi5ur}wVM_Z1w5!hEf)>@;|7S_fhaU_(=+4O^7 zb%$8`Yh8x^)tVX~OnNmMi!zKijvYOw*0x$bCZQ2*qZ!pbPQ@HMM<}T*BAx1gDLd;h zg09IDntm#O9=os6b2(s~m+$Bsl>;(MJi*y}x5HExIj#9a)O#wct6_{_G1Pp>Cz%=| amradoR5~^`9g7e~r4q?op3BU7oc{nv?+ Date: Mon, 23 May 2022 01:22:23 -0700 Subject: [PATCH 15/26] tgc parsing for testnet3 --- .github/workflows/acl2.yml | 67 ++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/.github/workflows/acl2.yml b/.github/workflows/acl2.yml index f027739300..8c990fb84d 100644 --- a/.github/workflows/acl2.yml +++ b/.github/workflows/acl2.yml @@ -21,7 +21,18 @@ jobs: - name: Generate asts run: | - cargo -q run -p leo-test-framework --bin tgc + # This currently has to be on testnet3 to work: + cd compiler/parser + cargo -q install --path . --example parser + # To ensure full file tests, + # just do compiler tests and remove expectation: Fail tests + cd ../../tests/compiler + find . -type f -exec grep -q 'expectation *: *Fail' {} \; -delete + find . -name '*.leo' -execdir parser {} \; > /dev/null + # Show how many there are: + echo "Counts (.leo / .json):" + find . -name '*.leo' -print | wc -l + find . -name '*.json' -print | wc -l # Pull the latest release from the leo-acl2-bin repo, and put it into the # repo/acl2 directory. After it's done, unpack the tgz file locally. @@ -29,7 +40,7 @@ jobs: run: | mkdir acl2 && cd acl2; wget $( curl -s https://api.github.com/repos/AleoHQ/leo-acl2-bin/releases/latest \ - | jq -r '.assets[0].browser_download_url' ) + | jq -r '.assets[].browser_download_url|scan("^.*leo-acl2--v.*\\.tgz$")' ) echo "Unpacking $(ls):" tar -xvzf $(ls) @@ -37,28 +48,31 @@ jobs: # Run theorem generation and checking using the prepared ASTs and the pulled and unzipped leo-acl2 tarball. - name: Run tgc over ASTs run: | - canonicalization_errors=(); - type_inference_errors=(); - num_dirs=0; - for dir in `ls tmp/tgc`; + parsing_errors=(); + num_cases=0; + # Note that PWD gets reset at the beginning of each the step + # to /home/runner/work/leo/leo + acl2dir="${PWD}"/acl2 + cd tests/compiler; + for tc in `find ${PWD} -name '*.leo' -print`; do - cd tmp/tgc/$dir; # enter the directory - num_dirs=$((num_dirs + 1)); - ./../../../acl2/tgc canonicalization initial_ast.json canonicalization_ast.json canonicalization-theorem.lisp > canonicalization_result.out || canonicalization_errors+=("$dir"); - ./../../../acl2/tgc type-inference canonicalization_ast.json type_inferenced_ast.json type-inference-theorem.lisp > type_inference_result.out || type_inference_errors+=("$dir"); - cd ../../.. + cd "${tc%/*}"; # enter the directory + leofile="${tc##*/}"; + jsonfile="${leofile%.leo}.json"; + num_cases=$((num_cases + 1)); + "$acl2dir"/tgc parsing "$leofile" "$jsonfile" parsing-theorem.lisp > parsing_result.out || parsing_errors+=("$tc"); done; echo "----------------" - echo "Ran tgc in ${num_dirs} directories." + echo "Ran tgc on ${num_cases} programs." echo "----------------" - if [ ${#canonicalization_errors[@]} -eq 0 ]; then - echo "Canonicalization - Success!" + if [ ${#parsing_errors[@]} -eq 0 ]; then + echo "Parsing - Total Success!" else - echo "Canonicalization Failures (total: ${#canonicalization_errors[@]}):" - for dir in ${canonicalization_errors[@]}; + echo "Parsing Failures (total: ${#parsing_errors[@]}):" + for tc in ${parsing_errors[@]}; do - echo $dir + echo $tc done; #echo "Attaching logs:" @@ -69,24 +83,7 @@ jobs: #done; fi - echo "----------------" - if [ ${#type_inference_errors[@]} -eq 0 ]; then - echo "Type Inference - Success!" - else - echo "Type Inference Failures (total: ${#type_inference_errors[@]}):" - for dir in ${type_inference_errors[@]}; - do - echo $dir - done; - - #echo "Attaching logs:" - #for dir in ${type_inference_errors[@]}; - #do - # cat tmp/tgc/$dir/type_inference_result.out - #done; - fi - - if [[ ${#canonicalization_errors[@]} -ne 0 || ${#type_inference_errors[@]} -ne 0 ]]; then + if [[ ${#parsing_errors[@]} -ne 0 ]]; then echo "----------------" echo "Exiting with status 1 due to at least one tgc error." exit 1 From 744b6ddafed172ba16efb6c70dbd5b5c3eea0f0b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 May 2022 10:18:33 +0000 Subject: [PATCH 16/26] Bump regex from 1.5.5 to 1.5.6 Bumps [regex](https://github.com/rust-lang/regex) from 1.5.5 to 1.5.6. - [Release notes](https://github.com/rust-lang/regex/releases) - [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/regex/compare/1.5.5...1.5.6) --- updated-dependencies: - dependency-name: regex dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84a6b0872f..24a84d2013 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2006,9 +2006,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.5.5" +version = "1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286" +checksum = "d83f127d94bdbcda4c8cc2e50f6f84f4b611f69c902699ca385a39c3a75f9ff1" dependencies = [ "aho-corasick", "memchr", @@ -2023,9 +2023,9 @@ checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" [[package]] name = "remove_dir_all" From ff46c98b9ec64e4b73de689656db04a09cedb39c Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Mon, 23 May 2022 08:22:11 -0700 Subject: [PATCH 17/26] update test framework docs --- tests/README.md | 31 +++++++------ tests/test-framework/README.md | 82 ++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 13 deletions(-) diff --git a/tests/README.md b/tests/README.md index 93aeb7f318..33a5332358 100644 --- a/tests/README.md +++ b/tests/README.md @@ -45,27 +45,32 @@ generated instead. A PR should contain changes to expectations as well as to tes Here is the list of all possible configuration options for compiler and parser tests. -#### namespace +### namespace -``` +```yaml - Mandatory: yes - Namespace: all -- Values: Compile / Parse +- Values: ... ``` -Only two values are supported: `Parse` and `Compile`. The former is meant to be a parser test, the latter -is a full compiler test. +Several values are supported, but they vary depending on the directory you are in. -Besides the `Parse` value, -there are actually additional possible values for this field: -`ParseStatement`, `ParseExpression`, and `Token`. -Each one of them allows testing Leo parser on different levels - lexer tokens or just expressions/statements. +Parser Directory namespaces: -Compiler tests always include complete Leo programs. +- `Parse` - Parses a whole Leo file checking it is parsable. +- `ParseExpression` - Parses a Leo file line by line to see if it contains a valid expression. +- `ParseStatement` - Parses a Leo file consuming multiple lines till a new line to see if it contains a valid statement. +- `Serialize` - Parses a whole Leo file testing serialization to JSON. +- `Input` - Parses a whole input file checking if it's a valid input file. +- `Token` - Parses a Leo file line by line to see if it contains valid tokens. + +Compiler Directory namespaces: + +- `Compiler` - Parses a whole Leo file and tests it end to end. ### expectation -``` +```yaml - Mandatory: yes - Namespace: all - Values: Pass / Fail @@ -77,7 +82,7 @@ you'll know that something went wrong and the test or the compiler/parser needs ### input_file (Compile) -``` +```yaml - Mandatory: no - Namespace: Compile - Values: , ... @@ -87,7 +92,7 @@ This setting allows using one or more input files for the Leo program. The program will be run with every provided input. See this example: -``` +```yaml /* namespace: Compile expectation: Pass diff --git a/tests/test-framework/README.md b/tests/test-framework/README.md index e69de29bb2..a1762a56de 100644 --- a/tests/test-framework/README.md +++ b/tests/test-framework/README.md @@ -0,0 +1,82 @@ +# Leo Test Framework + +This directory includes the code for the Leo Test Framework. + +## How it works + +You would first create a rust test file inside the folder of some part of the compiler, as the test framework tests are run by the rust test framework. + +### Namespaces + +Then you would create a `struct` that represents a `Namespace` where you have to implement the following: + +#### Parse Type + +Each `namespace` must have a function, `parse_type` that returns a `ParseType`. There are several kinds of `ParseTypes`: + +- Line - Parses the File line one by one. +- ContinuousLines - Parses lines continuously as one item until an empty line is encountered. +- Whole - Parses the whole file. + +#### Run Test + +Each `namespace` must have a function, that runs and dictates how you want the tests for that namespace to work. To make running a test possible you are given information about the test file, like its name, content, path, etc. It allows you to return any type of output to be written to an expectation file as long as it's serializable. + +### Runner + +Then you would create a `struct` that represents a `Runner` where you have to implement the following: + +#### Resolve Namespace + +Each test file only needs one runner that represents the namespace resolution to which type of test should be run with a given string. + +i.e. + +```rust +struct ParseTestRunner; + +impl Runner for ParseTestRunner { + fn resolve_namespace(&self, name: &str) -> Option> { + Some(match name { + "Parse" => Box::new(ParseNamespace), + "ParseExpression" => Box::new(ParseExpressionNamespace), + "ParseStatement" => Box::new(ParseStatementNamespace), + "Serialize" => Box::new(SerializeNamespace), + "Input" => Box::new(InputNamespace), + "Token" => Box::new(TokenNamespace), + _ => return None, + }) + } +} +``` + +### Rust test Function + +A rust test function that calls the framework over the runner, as well as the name of the directory, is the last thing necessary. + +i.e. + +```rust +#[test] +pub fn parser_tests() { + // The second argument indicates the directory where tests(.leo files) + // would be found(tests/parser). + leo_test_framework::run_tests(&ParseTestRunner, "parser"); +} + +``` + +### Clearing Expectations + +To do so you can simply remove the corresponding `.out` file in the `tests/expectations` directory. Doing so will cause the output to be regenerated. There is an easier way to mass change them as well discussed in the next section. + +### Test Framework Environment Variables + +To make several aspects of the test framework easier to work with there are several environment variables: + +- `TEST_FILTER` - runs all tests that contain the specified name. +- `CLEAR_LEO_TEST_EXPECTATIONS` - which if set clears all current expectations and regenerates them all. + +To set environment variables please look at your Shell(bash/powershell/cmd/fish/etc) specific implementation for doing so + +**NOTE**: Don't forget to clear the environment variable after running it with that setting, or set a temporary env variable if your shell supports it. From d0273719ab7a136d8e81ef3352c511fbc90525ca Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Mon, 23 May 2022 11:40:14 -0400 Subject: [PATCH 18/26] push broken type checker --- .../src/type_checker/check_expressions.rs | 4 +- compiler/passes/src/type_checker/checker.rs | 63 ++++--------------- 2 files changed, 14 insertions(+), 53 deletions(-) diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index c43239a383..1cbb18f250 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -242,10 +242,10 @@ impl<'a> TypeChecker<'a> { self.assert_type(Type::Boolean, expected.clone(), binary.span()); let t1 = self.compare_expr_type(&binary.left, None, binary.left.span()); - self.assert_int_type(t1.clone(), binary.left.span()); + self.assert_field_scalar_int_type(t1.clone(), binary.left.span()); let t2 = self.compare_expr_type(&binary.right, None, binary.right.span()); - self.assert_int_type(t2.clone(), binary.right.span()); + self.assert_field_scalar_int_type(t2.clone(), binary.right.span()); return_incorrect_type(t1, t2, expected) } diff --git a/compiler/passes/src/type_checker/checker.rs b/compiler/passes/src/type_checker/checker.rs index 378ed6b925..6d4d3e9bb8 100644 --- a/compiler/passes/src/type_checker/checker.rs +++ b/compiler/passes/src/type_checker/checker.rs @@ -27,53 +27,10 @@ pub struct TypeChecker<'a> { pub(crate) negate: bool, } -// todo @gluax: find a more scalable way to check for types -const FIELD_GROUP_SCALAR_INT: &[Type] = &[ - Type::Field, - Type::Group, - Type::Scalar, - Type::IntegerType(IntegerType::I8), - Type::IntegerType(IntegerType::I16), - Type::IntegerType(IntegerType::I32), - Type::IntegerType(IntegerType::I64), - Type::IntegerType(IntegerType::I128), - Type::IntegerType(IntegerType::U8), - Type::IntegerType(IntegerType::U16), - Type::IntegerType(IntegerType::U32), - Type::IntegerType(IntegerType::U64), - Type::IntegerType(IntegerType::U128), -]; - -const FIELD_GROUP_INT: &[Type] = &[ - Type::Field, - Type::Group, - Type::IntegerType(IntegerType::I8), - Type::IntegerType(IntegerType::I16), - Type::IntegerType(IntegerType::I32), - Type::IntegerType(IntegerType::I64), - Type::IntegerType(IntegerType::I128), - Type::IntegerType(IntegerType::U8), - Type::IntegerType(IntegerType::U16), - Type::IntegerType(IntegerType::U32), - Type::IntegerType(IntegerType::U64), - Type::IntegerType(IntegerType::U128), -]; - -const FIELD_INT_TYPES: &[Type] = &[ - Type::Field, - Type::IntegerType(IntegerType::I8), - Type::IntegerType(IntegerType::I16), - Type::IntegerType(IntegerType::I32), - Type::IntegerType(IntegerType::I64), - Type::IntegerType(IntegerType::I128), - Type::IntegerType(IntegerType::U8), - Type::IntegerType(IntegerType::U16), - Type::IntegerType(IntegerType::U32), - Type::IntegerType(IntegerType::U64), - Type::IntegerType(IntegerType::U128), -]; - -const INT_TYPES: &[Type] = &[ +const FIELD_TYPE: Type = Type::Field; +const GROUP_TYPE: Type = Type::Group; +const SCALAR_TYPE: Type = Type::Scalar; +const INT_TYPES: [Type; 10] = [ Type::IntegerType(IntegerType::I8), Type::IntegerType(IntegerType::I16), Type::IntegerType(IntegerType::I32), @@ -129,18 +86,22 @@ impl<'a> TypeChecker<'a> { } pub(crate) fn assert_field_group_scalar_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, FIELD_GROUP_SCALAR_INT, span) + self.assert_one_of_types(type_, , span) } pub(crate) fn assert_field_group_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, FIELD_GROUP_INT, span) + self.assert_one_of_types(type_, , span) + } + + pub(crate) fn assert_field_scalar_int_type(&self, type_: Option, span: Span) -> Option { + self.assert_one_of_types(type_, , span) } pub(crate) fn assert_field_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, FIELD_INT_TYPES, span) + self.assert_one_of_types(type_, span) } pub(crate) fn assert_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, INT_TYPES, span) + self.assert_one_of_types(type_, , span) } } From 848868a05ae5a7db218570794184642473da563b Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Mon, 23 May 2022 09:37:04 -0700 Subject: [PATCH 19/26] make suggested changes fix tests --- tests/README.md | 6 +++--- tests/test-framework/src/lib.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/README.md b/tests/README.md index 33a5332358..036477aa13 100644 --- a/tests/README.md +++ b/tests/README.md @@ -58,11 +58,11 @@ Several values are supported, but they vary depending on the directory you are i Parser Directory namespaces: - `Parse` - Parses a whole Leo file checking it is parsable. -- `ParseExpression` - Parses a Leo file line by line to see if it contains a valid expression. -- `ParseStatement` - Parses a Leo file consuming multiple lines till a new line to see if it contains a valid statement. +- `ParseExpression` - Parses a Leo file line by line to see if each line contains an expression. +- `ParseStatement` - Parses a Leo file consuming multiple lines till a blank line to see if it contains a valid statement. - `Serialize` - Parses a whole Leo file testing serialization to JSON. - `Input` - Parses a whole input file checking if it's a valid input file. -- `Token` - Parses a Leo file line by line to see if it contains valid tokens. +- `Token` - Parses a Leo file line by line to see if it contains zero or more valid tokens. Compiler Directory namespaces: diff --git a/tests/test-framework/src/lib.rs b/tests/test-framework/src/lib.rs index 86115089ca..feab356368 100644 --- a/tests/test-framework/src/lib.rs +++ b/tests/test-framework/src/lib.rs @@ -22,6 +22,7 @@ //! To regenerate the tests after a syntax change or failing test, delete the [`tests/expectations/`] //! directory and run the [`parser_tests()`] test in [`parser/src/test.rs`]. +#![cfg(not(doctest))] // Don't doctest the markdown. #![doc = include_str!("../README.md")] pub mod error; From eee58883a6c285f22a72ed3b80bb9acb06f70df5 Mon Sep 17 00:00:00 2001 From: gluax <16431709+gluax@users.noreply.github.com> Date: Mon, 23 May 2022 11:07:43 -0700 Subject: [PATCH 20/26] clean up and fix type set checking --- .../ast/src/passes/reconstructing_director.rs | 2 +- compiler/ast/src/types/type_.rs | 14 ++--- .../src/type_checker/check_expressions.rs | 54 ++++++++---------- .../src/type_checker/check_statements.rs | 10 ++-- compiler/passes/src/type_checker/checker.rs | 57 ++++++++++++++----- .../compiler/compiler/scalar/cmp.leo.out | 8 +++ 6 files changed, 90 insertions(+), 55 deletions(-) create mode 100644 tests/expectations/compiler/compiler/scalar/cmp.leo.out diff --git a/compiler/ast/src/passes/reconstructing_director.rs b/compiler/ast/src/passes/reconstructing_director.rs index 466f89b282..334fcb394e 100644 --- a/compiler/ast/src/passes/reconstructing_director.rs +++ b/compiler/ast/src/passes/reconstructing_director.rs @@ -34,7 +34,7 @@ impl ReconstructingDirector { } pub fn reduce_type(&mut self, type_: &Type, span: &Span) -> Result { - self.reducer.reduce_type(type_, type_.clone(), span) + self.reducer.reduce_type(type_, *type_, span) } // Expressions diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 1fb252e60b..c84a740052 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -20,7 +20,7 @@ use serde::{Deserialize, Serialize}; use std::fmt; /// Explicit type used for defining a variable or expression type -#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum Type { // Data types /// The `address` type. @@ -51,12 +51,12 @@ impl Type { /// pub fn eq_flat(&self, other: &Self) -> bool { match (self, other) { - (Type::Address, Type::Address) => true, - (Type::Boolean, Type::Boolean) => true, - (Type::Field, Type::Field) => true, - (Type::Group, Type::Group) => true, - (Type::Char, Type::Char) => true, - (Type::Scalar, Type::Scalar) => true, + (Type::Address, Type::Address) + | (Type::Boolean, Type::Boolean) + | (Type::Field, Type::Field) + | (Type::Group, Type::Group) + | (Type::Char, Type::Char) + | (Type::Scalar, Type::Scalar) => true, (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), _ => false, } diff --git a/compiler/passes/src/type_checker/check_expressions.rs b/compiler/passes/src/type_checker/check_expressions.rs index 1cbb18f250..854dc5b917 100644 --- a/compiler/passes/src/type_checker/check_expressions.rs +++ b/compiler/passes/src/type_checker/check_expressions.rs @@ -43,7 +43,7 @@ impl<'a> TypeChecker<'a> { match expr { Expression::Identifier(ident) => { if let Some(var) = self.symbol_table.lookup_variable(&ident.name) { - Some(self.assert_type(var.type_.clone(), expected, span)) + Some(self.assert_type(*var.type_, expected, span)) } else { self.handler .emit_err(TypeCheckerError::unknown_sym("variable", ident.name, span).into()); @@ -148,28 +148,28 @@ impl<'a> TypeChecker<'a> { }, Expression::Binary(binary) => match binary.op { BinaryOperation::And | BinaryOperation::Or => { - self.assert_type(Type::Boolean, expected.clone(), binary.span()); - let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); - let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); + self.assert_type(Type::Boolean, expected, binary.span()); + let t1 = self.compare_expr_type(&binary.left, expected, binary.left.span()); + let t2 = self.compare_expr_type(&binary.right, expected, binary.right.span()); return_incorrect_type(t1, t2, expected) } BinaryOperation::Add => { - self.assert_field_group_scalar_int_type(expected.clone(), binary.span()); - let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); - let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); + self.assert_field_group_scalar_int_type(expected, binary.span()); + let t1 = self.compare_expr_type(&binary.left, expected, binary.left.span()); + let t2 = self.compare_expr_type(&binary.right, expected, binary.right.span()); return_incorrect_type(t1, t2, expected) } BinaryOperation::Sub => { - self.assert_field_group_int_type(expected.clone(), binary.span()); - let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); - let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); + self.assert_field_group_int_type(expected, binary.span()); + let t1 = self.compare_expr_type(&binary.left, expected, binary.left.span()); + let t2 = self.compare_expr_type(&binary.right, expected, binary.right.span()); return_incorrect_type(t1, t2, expected) } BinaryOperation::Mul => { - self.assert_field_group_int_type(expected.clone(), binary.span()); + self.assert_field_group_int_type(expected, binary.span()); let t1 = self.compare_expr_type(&binary.left, None, binary.left.span()); let t2 = self.compare_expr_type(&binary.right, None, binary.right.span()); @@ -177,17 +177,17 @@ impl<'a> TypeChecker<'a> { // Allow `group` * `scalar` multiplication. match (t1.as_ref(), t2.as_ref()) { (Some(Type::Group), Some(other)) | (Some(other), Some(Type::Group)) => { - self.assert_type(other.clone(), Some(Type::Scalar), binary.span()); + self.assert_type(*other, Some(Type::Scalar), binary.span()); Some(Type::Group) } _ => return_incorrect_type(t1, t2, expected), } } BinaryOperation::Div => { - self.assert_field_int_type(expected.clone(), binary.span()); + self.assert_field_int_type(expected, binary.span()); - let t1 = self.compare_expr_type(&binary.left, expected.clone(), binary.left.span()); - let t2 = self.compare_expr_type(&binary.right, expected.clone(), binary.right.span()); + let t1 = self.compare_expr_type(&binary.left, expected, binary.left.span()); + let t2 = self.compare_expr_type(&binary.right, expected, binary.right.span()); return_incorrect_type(t1, t2, expected) } BinaryOperation::Pow => { @@ -198,7 +198,7 @@ impl<'a> TypeChecker<'a> { // Type A must be an int. // Type B must be a unsigned int. (Some(Type::IntegerType(_)), Some(Type::IntegerType(itype))) if !itype.is_signed() => { - self.assert_type(t1.clone().unwrap(), expected, binary.span()); + self.assert_type(t1.unwrap(), expected, binary.span()); } // Type A was an int. // But Type B was not a unsigned int. @@ -231,7 +231,7 @@ impl<'a> TypeChecker<'a> { t1 } BinaryOperation::Eq | BinaryOperation::Ne => { - self.assert_type(Type::Boolean, expected.clone(), binary.span()); + self.assert_type(Type::Boolean, expected, binary.span()); let t1 = self.compare_expr_type(&binary.left, None, binary.left.span()); let t2 = self.compare_expr_type(&binary.right, None, binary.right.span()); @@ -239,20 +239,20 @@ impl<'a> TypeChecker<'a> { return_incorrect_type(t1, t2, expected) } BinaryOperation::Lt | BinaryOperation::Gt | BinaryOperation::Le | BinaryOperation::Ge => { - self.assert_type(Type::Boolean, expected.clone(), binary.span()); + self.assert_type(Type::Boolean, expected, binary.span()); let t1 = self.compare_expr_type(&binary.left, None, binary.left.span()); - self.assert_field_scalar_int_type(t1.clone(), binary.left.span()); + self.assert_field_scalar_int_type(t1, binary.left.span()); let t2 = self.compare_expr_type(&binary.right, None, binary.right.span()); - self.assert_field_scalar_int_type(t2.clone(), binary.right.span()); + self.assert_field_scalar_int_type(t2, binary.right.span()); return_incorrect_type(t1, t2, expected) } }, Expression::Unary(unary) => match unary.op { UnaryOperation::Not => { - self.assert_type(Type::Boolean, expected.clone(), unary.span()); + self.assert_type(Type::Boolean, expected, unary.span()); self.compare_expr_type(&unary.inner, expected, unary.inner.span()) } UnaryOperation::Negate => { @@ -278,14 +278,14 @@ impl<'a> TypeChecker<'a> { }, Expression::Ternary(ternary) => { self.compare_expr_type(&ternary.condition, Some(Type::Boolean), ternary.condition.span()); - let t1 = self.compare_expr_type(&ternary.if_true, expected.clone(), ternary.if_true.span()); - let t2 = self.compare_expr_type(&ternary.if_false, expected.clone(), ternary.if_false.span()); + let t1 = self.compare_expr_type(&ternary.if_true, expected, ternary.if_true.span()); + let t2 = self.compare_expr_type(&ternary.if_false, expected, ternary.if_false.span()); return_incorrect_type(t1, t2, expected) } Expression::Call(call) => match &*call.function { Expression::Identifier(ident) => { if let Some(func) = self.symbol_table.lookup_fn(&ident.name) { - let ret = self.assert_type(func.output.clone(), expected, ident.span()); + let ret = self.assert_type(func.output, expected, ident.span()); if func.input.len() != call.arguments.len() { self.handler.emit_err( @@ -302,11 +302,7 @@ impl<'a> TypeChecker<'a> { .iter() .zip(call.arguments.iter()) .for_each(|(expected, argument)| { - self.compare_expr_type( - argument, - Some(expected.get_variable().type_.clone()), - argument.span(), - ); + self.compare_expr_type(argument, Some(expected.get_variable().type_), argument.span()); }); Some(ret) diff --git a/compiler/passes/src/type_checker/check_statements.rs b/compiler/passes/src/type_checker/check_statements.rs index 82e6afb341..e5051ee4af 100644 --- a/compiler/passes/src/type_checker/check_statements.rs +++ b/compiler/passes/src/type_checker/check_statements.rs @@ -26,7 +26,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { let parent = self.parent.unwrap(); // Would never be None. - let func_output_type = self.symbol_table.lookup_fn(&parent).map(|f| f.output.clone()); + let func_output_type = self.symbol_table.lookup_fn(&parent).map(|f| f.output); self.compare_expr_type(&input.expression, func_output_type, input.expression.span()); VisitResult::VisitChildren @@ -51,7 +51,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { self.handler.emit_err(err); } - self.compare_expr_type(&input.value, Some(input.type_.clone()), input.value.span()); + self.compare_expr_type(&input.value, Some(input.type_), input.value.span()); }); VisitResult::VisitChildren @@ -70,7 +70,7 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { _ => {} } - Some(var.type_.clone()) + Some(*var.type_) } else { self.handler.emit_err( TypeCheckerError::unknown_sym("variable", &input.assignee.identifier.name, input.assignee.span).into(), @@ -104,8 +104,8 @@ impl<'a> StatementVisitor<'a> for TypeChecker<'a> { self.handler.emit_err(err); } - self.compare_expr_type(&input.start, Some(input.type_.clone()), input.start.span()); - self.compare_expr_type(&input.stop, Some(input.type_.clone()), input.stop.span()); + self.compare_expr_type(&input.start, Some(input.type_), input.start.span()); + self.compare_expr_type(&input.stop, Some(input.type_), input.stop.span()); VisitResult::VisitChildren } diff --git a/compiler/passes/src/type_checker/checker.rs b/compiler/passes/src/type_checker/checker.rs index 6d4d3e9bb8..605a326081 100644 --- a/compiler/passes/src/type_checker/checker.rs +++ b/compiler/passes/src/type_checker/checker.rs @@ -27,9 +27,6 @@ pub struct TypeChecker<'a> { pub(crate) negate: bool, } -const FIELD_TYPE: Type = Type::Field; -const GROUP_TYPE: Type = Type::Group; -const SCALAR_TYPE: Type = Type::Scalar; const INT_TYPES: [Type; 10] = [ Type::IntegerType(IntegerType::I8), Type::IntegerType(IntegerType::I16), @@ -43,6 +40,32 @@ const INT_TYPES: [Type; 10] = [ Type::IntegerType(IntegerType::U128), ]; +const fn create_type_superset( + subset: [Type; S], + additional: [Type; A], +) -> [Type; O] { + let mut superset: [Type; O] = [Type::IntegerType(IntegerType::U8); O]; + let mut i = 0; + while i < S { + superset[i] = subset[i]; + i += 1; + } + let mut j = 0; + while j < A { + superset[i + j] = additional[j]; + j += 1; + } + superset +} + +const FIELD_INT_TYPES: [Type; 11] = create_type_superset(INT_TYPES, [Type::Field]); + +const FIELD_SCALAR_INT_TYPES: [Type; 12] = create_type_superset(FIELD_INT_TYPES, [Type::Scalar]); + +const FIELD_GROUP_INT_TYPES: [Type; 12] = create_type_superset(FIELD_INT_TYPES, [Type::Group]); + +const ALL_NUMERICAL_TYPES: [Type; 13] = create_type_superset(FIELD_GROUP_INT_TYPES, [Type::Scalar]); + impl<'a> TypeChecker<'a> { pub fn new(symbol_table: &'a mut SymbolTable<'a>, handler: &'a Handler) -> Self { Self { @@ -57,7 +80,7 @@ impl<'a> TypeChecker<'a> { if let Some(expected) = expected { if type_ != expected { self.handler - .emit_err(TypeCheckerError::type_should_be(type_.clone(), expected, span).into()); + .emit_err(TypeCheckerError::type_should_be(type_, expected, span).into()); } } @@ -65,7 +88,7 @@ impl<'a> TypeChecker<'a> { } pub(crate) fn assert_one_of_types(&self, type_: Option, expected: &[Type], span: Span) -> Option { - if let Some(type_) = type_.clone() { + if let Some(type_) = type_ { for t in expected.iter() { if &type_ == t { return Some(type_); @@ -85,23 +108,31 @@ impl<'a> TypeChecker<'a> { type_ } + pub(crate) fn _assert_arith_type(&self, type_: Option, span: Span) -> Option { + self.assert_one_of_types(type_, &FIELD_GROUP_INT_TYPES, span) + } + + pub(crate) fn _assert_field_or_int_type(&self, type_: Option, span: Span) -> Option { + self.assert_one_of_types(type_, &FIELD_INT_TYPES, span) + } + + pub(crate) fn _assert_int_type(&self, type_: Option, span: Span) -> Option { + self.assert_one_of_types(type_, &INT_TYPES, span) + } + pub(crate) fn assert_field_group_scalar_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, , span) + self.assert_one_of_types(type_, &ALL_NUMERICAL_TYPES, span) } pub(crate) fn assert_field_group_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, , span) + self.assert_one_of_types(type_, &FIELD_GROUP_INT_TYPES, span) } pub(crate) fn assert_field_scalar_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, , span) + self.assert_one_of_types(type_, &FIELD_SCALAR_INT_TYPES, span) } pub(crate) fn assert_field_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, span) - } - - pub(crate) fn assert_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, , span) + self.assert_one_of_types(type_, &FIELD_INT_TYPES, span) } } diff --git a/tests/expectations/compiler/compiler/scalar/cmp.leo.out b/tests/expectations/compiler/compiler/scalar/cmp.leo.out new file mode 100644 index 0000000000..b91a025eec --- /dev/null +++ b/tests/expectations/compiler/compiler/scalar/cmp.leo.out @@ -0,0 +1,8 @@ +--- +namespace: Compile +expectation: Pass +outputs: + - output: + - initial_input_ast: 85349bd16d49ff31c5ed3aeacf84ee6278d4d951409f8b055849eb41481e612e + initial_ast: f9d6d5d94f9aead249bf86205884b49eff222937842973864758c01757d3eafa + symbol_table: 240729bf3dd32b0ff548d132bc74bc91e42a8677f98d5fa1e388259e6a407d95 From 944c5dcdd8867c353fb7d9df098eecf9234fc40b Mon Sep 17 00:00:00 2001 From: Collin Chin <16715212+collinc97@users.noreply.github.com> Date: Tue, 24 May 2022 11:27:28 -0400 Subject: [PATCH 21/26] Update value.rs --- compiler/ast/src/expression/value.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/ast/src/expression/value.rs b/compiler/ast/src/expression/value.rs index e53e8d9c55..ea47b1cee4 100644 --- a/compiler/ast/src/expression/value.rs +++ b/compiler/ast/src/expression/value.rs @@ -21,14 +21,14 @@ use crate::{Char, CharValue}; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub enum ValueExpression { // todo: deserialize values here - /// An address literal, e.g., `aleo1..`. + /// An address literal, e.g., `aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9`. Address(String, #[serde(with = "leo_span::span_json")] Span), /// A boolean literal, either `true` or `false`. Boolean(String, #[serde(with = "leo_span::span_json")] Span), /// A char literal, e.g., `'a'`, representing a single unicode code point. Char(CharValue), /// A field literal, e.g., `42field`. - /// That is, a signed number followed by the keyword `field`. + /// A signed number followed by the keyword `field`. Field(String, #[serde(with = "leo_span::span_json")] Span), /// A group literal, either product or affine. /// For example, `42group` or `(12, 52)group`. From c62f8767659e387126c101ffbb477847c21f4e55 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 24 May 2022 12:11:55 -0400 Subject: [PATCH 22/26] type checker clean up and add docs --- compiler/passes/src/type_checker/checker.rs | 63 +++++++++------------ 1 file changed, 26 insertions(+), 37 deletions(-) diff --git a/compiler/passes/src/type_checker/checker.rs b/compiler/passes/src/type_checker/checker.rs index 605a326081..976d43d7af 100644 --- a/compiler/passes/src/type_checker/checker.rs +++ b/compiler/passes/src/type_checker/checker.rs @@ -64,9 +64,10 @@ const FIELD_SCALAR_INT_TYPES: [Type; 12] = create_type_superset(FIELD_INT_TYPES, const FIELD_GROUP_INT_TYPES: [Type; 12] = create_type_superset(FIELD_INT_TYPES, [Type::Group]); -const ALL_NUMERICAL_TYPES: [Type; 13] = create_type_superset(FIELD_GROUP_INT_TYPES, [Type::Scalar]); +const FIELD_GROUP_SCALAR_INT_TYPES: [Type; 13] = create_type_superset(FIELD_GROUP_INT_TYPES, [Type::Scalar]); impl<'a> TypeChecker<'a> { + /// Returns a new type checker given a symbol table and error handler. pub fn new(symbol_table: &'a mut SymbolTable<'a>, handler: &'a Handler) -> Self { Self { symbol_table, @@ -76,6 +77,7 @@ impl<'a> TypeChecker<'a> { } } + /// Returns the given type if it equals the expected type or the expected type is none. pub(crate) fn assert_type(&self, type_: Type, expected: Option, span: Span) -> Type { if let Some(expected) = expected { if type_ != expected { @@ -87,52 +89,39 @@ impl<'a> TypeChecker<'a> { type_ } - pub(crate) fn assert_one_of_types(&self, type_: Option, expected: &[Type], span: Span) -> Option { + /// Emits an error to the error handler if the given type is not equal to any of the expected types. + pub(crate) fn assert_one_of_types(&self, type_: Option, expected: &[Type], span: Span) { if let Some(type_) = type_ { - for t in expected.iter() { - if &type_ == t { - return Some(type_); - } + if !expected.iter().any(|t: &Type| t == &type_) { + self.handler.emit_err( + TypeCheckerError::expected_one_type_of( + expected.iter().map(|t| t.to_string() + ",").collect::(), + type_, + span, + ) + .into(), + ); } - - self.handler.emit_err( - TypeCheckerError::expected_one_type_of( - expected.iter().map(|t| t.to_string() + ",").collect::(), - type_, - span, - ) - .into(), - ); } - - type_ } - pub(crate) fn _assert_arith_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, &FIELD_GROUP_INT_TYPES, span) - } - - pub(crate) fn _assert_field_or_int_type(&self, type_: Option, span: Span) -> Option { + /// Emits an error to the handler if the given type is not a field or integer. + pub(crate) fn assert_field_int_type(&self, type_: Option, span: Span) { self.assert_one_of_types(type_, &FIELD_INT_TYPES, span) } - pub(crate) fn _assert_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, &INT_TYPES, span) - } - - pub(crate) fn assert_field_group_scalar_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, &ALL_NUMERICAL_TYPES, span) - } - - pub(crate) fn assert_field_group_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, &FIELD_GROUP_INT_TYPES, span) - } - - pub(crate) fn assert_field_scalar_int_type(&self, type_: Option, span: Span) -> Option { + /// Emits an error to the handler if the given type is not a field, scalar, or integer. + pub(crate) fn assert_field_scalar_int_type(&self, type_: Option, span: Span) { self.assert_one_of_types(type_, &FIELD_SCALAR_INT_TYPES, span) } - pub(crate) fn assert_field_int_type(&self, type_: Option, span: Span) -> Option { - self.assert_one_of_types(type_, &FIELD_INT_TYPES, span) + /// Emits an error to the handler if the given type is not a field, group, or integer. + pub(crate) fn assert_field_group_int_type(&self, type_: Option, span: Span) { + self.assert_one_of_types(type_, &FIELD_GROUP_INT_TYPES, span) + } + + /// Emits an error to the handler if the given type is not a field, group, scalar or integer. + pub(crate) fn assert_field_group_scalar_int_type(&self, type_: Option, span: Span) { + self.assert_one_of_types(type_, &FIELD_GROUP_SCALAR_INT_TYPES, span) } } From 637ab9c0b6d8d93ae1be023057acd72aa2f503dd Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 24 May 2022 12:45:11 -0400 Subject: [PATCH 23/26] update test readme --- tests/README.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/README.md b/tests/README.md index 036477aa13..5322d0f795 100644 --- a/tests/README.md +++ b/tests/README.md @@ -57,16 +57,16 @@ Several values are supported, but they vary depending on the directory you are i Parser Directory namespaces: -- `Parse` - Parses a whole Leo file checking it is parsable. -- `ParseExpression` - Parses a Leo file line by line to see if each line contains an expression. -- `ParseStatement` - Parses a Leo file consuming multiple lines till a blank line to see if it contains a valid statement. -- `Serialize` - Parses a whole Leo file testing serialization to JSON. -- `Input` - Parses a whole input file checking if it's a valid input file. -- `Token` - Parses a Leo file line by line to see if it contains zero or more valid tokens. +- `Parse` - Test a file to check that it is a valid Leo program. +- `ParseExpression` - Test a file line by line to check that each line is a valid Leo expression. +- `ParseStatement` - Test a file consuming multiple lines till a blank line to check that it contains a valid Leo statement. +- `Serialize` - Test a file to check that it can be serialized to JSON. +- `Input` - Test an input file to check that it is a valid Leo input file. +- `Token` - Test a file line by line to check that it contains zero or more valid Leo parser tokens. Compiler Directory namespaces: -- `Compiler` - Parses a whole Leo file and tests it end to end. +- `Compiler` - Test a file to check that it is a valid Leo program, and it can be compiled without errors. ### expectation From 38d701851da58199bcb03386e7bc5ae63c59666f Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 24 May 2022 12:49:38 -0400 Subject: [PATCH 24/26] clean up match --- compiler/ast/src/types/type_.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index c84a740052..0e460acbf3 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -53,10 +53,9 @@ impl Type { match (self, other) { (Type::Address, Type::Address) | (Type::Boolean, Type::Boolean) - | (Type::Field, Type::Field) - | (Type::Group, Type::Group) | (Type::Char, Type::Char) - | (Type::Scalar, Type::Scalar) => true, + | (Type::Field, Type::Field) + | (Type::Group, Type::Group) => true, (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), _ => false, } From c10e305366c5f58bd0aab235f163a5207448b132 Mon Sep 17 00:00:00 2001 From: Collin Chin <16715212+collinc97@users.noreply.github.com> Date: Tue, 24 May 2022 13:24:36 -0400 Subject: [PATCH 25/26] Update type_.rs --- compiler/ast/src/types/type_.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 0e460acbf3..3105bcbced 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -55,7 +55,8 @@ impl Type { | (Type::Boolean, Type::Boolean) | (Type::Char, Type::Char) | (Type::Field, Type::Field) - | (Type::Group, Type::Group) => true, + | (Type::Group, Type::Group) + | (Type::Scalar, Type::Scalar) => true, (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), _ => false, } From 4bc2fb10f4bb8e482ce02636e3d7534c55fe3603 Mon Sep 17 00:00:00 2001 From: collin <16715212+collinc97@users.noreply.github.com> Date: Tue, 24 May 2022 13:39:08 -0400 Subject: [PATCH 26/26] cargo fmt --- compiler/ast/src/types/type_.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ast/src/types/type_.rs b/compiler/ast/src/types/type_.rs index 3105bcbced..a4bb3b033a 100644 --- a/compiler/ast/src/types/type_.rs +++ b/compiler/ast/src/types/type_.rs @@ -55,7 +55,7 @@ impl Type { | (Type::Boolean, Type::Boolean) | (Type::Char, Type::Char) | (Type::Field, Type::Field) - | (Type::Group, Type::Group) + | (Type::Group, Type::Group) | (Type::Scalar, Type::Scalar) => true, (Type::IntegerType(left), Type::IntegerType(right)) => left.eq(right), _ => false,