Skip to content

Commit

Permalink
chore: replace Type::TypeVariable, Type::PolymorphicInteger, and … (
Browse files Browse the repository at this point in the history
#2065)

* chore: replace `Type::TypeVariable`, `Type::PolymorphicInteger`, and all other type variables with one kind

* update comments
  • Loading branch information
kek kek kek authored Jul 27, 2023
1 parent bb28223 commit 6932503
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 87 deletions.
3 changes: 1 addition & 2 deletions crates/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -777,8 +777,7 @@ impl<'a> Resolver<'a> {
| Type::String(_)
| Type::Unit
| Type::Error
| Type::TypeVariable(_)
| Type::PolymorphicInteger(_, _)
| Type::TypeVariable(_, _)
| Type::Constant(_)
| Type::NamedGeneric(_, _)
| Type::Forall(_, _) => (),
Expand Down
27 changes: 12 additions & 15 deletions crates/noirc_frontend/src/hir/type_check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
types::Type,
},
node_interner::{ExprId, FuncId},
CompTime, Shared, TypeBinding, UnaryOp,
CompTime, Shared, TypeBinding, TypeVariableKind, UnaryOp,
};

use super::{errors::TypeCheckError, TypeChecker};
Expand Down Expand Up @@ -185,7 +185,10 @@ impl<'interner> TypeChecker<'interner> {
};
let fresh_id = self.interner.next_type_variable_id();
let type_variable = Shared::new(TypeBinding::Unbound(fresh_id));
let expected_type = Type::PolymorphicInteger(expected_comptime, type_variable);
let expected_type = Type::TypeVariable(
type_variable,
TypeVariableKind::IntegerOrField(expected_comptime),
);

self.unify(&start_range_type, &expected_type, range_span, || {
TypeCheckError::TypeCannotBeUsed {
Expand Down Expand Up @@ -343,8 +346,8 @@ impl<'interner> TypeChecker<'interner> {
let is_comp_time = match from.follow_bindings() {
Type::Integer(is_comp_time, ..) => is_comp_time,
Type::FieldElement(is_comp_time) => is_comp_time,
Type::PolymorphicInteger(is_comp_time, _) => is_comp_time,
Type::TypeVariable(_) => {
Type::TypeVariable(_, TypeVariableKind::IntegerOrField(is_comp_time)) => is_comp_time,
Type::TypeVariable(_, _) => {
self.errors.push(TypeCheckError::TypeAnnotationsNeeded { span });
return Type::Error;
}
Expand Down Expand Up @@ -616,12 +619,9 @@ impl<'interner> TypeChecker<'interner> {
// Avoid reporting errors multiple times
(Error, _) | (_, Error) => Ok(Bool(CompTime::Yes(None))),

// Matches on PolymorphicInteger and TypeVariable must be first to follow any type
// Matches on TypeVariable must be first to follow any type
// bindings.
(var @ PolymorphicInteger(_, int), other)
| (other, var @ PolymorphicInteger(_, int))
| (var @ TypeVariable(int), other)
| (other, var @ TypeVariable(int)) => {
(var @ TypeVariable(int, _), other) | (other, var @ TypeVariable(int, _)) => {
if let TypeBinding::Bound(binding) = &*int.borrow() {
return self.comparator_operand_type_rules(other, binding, op, span);
}
Expand Down Expand Up @@ -798,7 +798,7 @@ impl<'interner> TypeChecker<'interner> {
// Could do a single unification for the entire function type, but matching beforehand
// lets us issue a more precise error on the individual argument that fails to type check.
match function {
Type::TypeVariable(binding) => {
Type::TypeVariable(binding, TypeVariableKind::Normal) => {
if let TypeBinding::Bound(typ) = &*binding.borrow() {
return self.bind_function_type(typ.clone(), args, span);
}
Expand Down Expand Up @@ -860,12 +860,9 @@ impl<'interner> TypeChecker<'interner> {
// An error type on either side will always return an error
(Error, _) | (_, Error) => Ok(Error),

// Matches on PolymorphicInteger and TypeVariable must be first so that we follow any type
// Matches on TypeVariable must be first so that we follow any type
// bindings.
(var @ PolymorphicInteger(_, int), other)
| (other, var @ PolymorphicInteger(_, int))
| (var @ TypeVariable(int), other)
| (other, var @ TypeVariable(int)) => {
(var @ TypeVariable(int, _), other) | (other, var @ TypeVariable(int, _)) => {
if let TypeBinding::Bound(binding) = &*int.borrow() {
return self.infix_operand_type_rules(binding, op, other, span);
}
Expand Down
Loading

0 comments on commit 6932503

Please sign in to comment.