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] 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) } }