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/14] 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/14] 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/14] 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/14] 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/14] [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/14] 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/14] 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 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 08/14] 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 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 09/14] 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 10/14] 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 11/14] 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 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 12/14] 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 13/14] 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 14/14] 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,