don't even create a type if we only need a variable

This commit is contained in:
Folkert 2022-03-13 02:12:45 +01:00
parent eccb461b01
commit 8b2c1707d4
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
3 changed files with 81 additions and 76 deletions

View file

@ -124,13 +124,7 @@ impl Constraints {
match typ {
Type::EmptyRec => EitherIndex::from_left(Self::EMPTY_RECORD),
Type::EmptyTagUnion => EitherIndex::from_left(Self::EMPTY_TAG_UNION),
Type::Variable(var) => {
// that's right, we use the variable's integer value as the index
// that way, we don't need to push anything onto a vector
let index: Index<Variable> = Index::new(var.index());
EitherIndex::from_right(index)
}
Type::Variable(var) => Self::push_type_variable(var),
other => {
let index: Index<Type> = Index::push_new(&mut self.types, other);
EitherIndex::from_left(index)
@ -138,6 +132,15 @@ impl Constraints {
}
}
#[inline(always)]
const fn push_type_variable(var: Variable) -> EitherIndex<Type, Variable> {
// that's right, we use the variable's integer value as the index
// that way, we don't need to push anything onto a vector
let index: Index<Variable> = Index::new(var.index());
EitherIndex::from_right(index)
}
#[inline(always)]
pub fn push_expected_type(&mut self, expected: Expected<Type>) -> Index<Expected<Type>> {
Index::push_new(&mut self.expectations, expected)
@ -197,6 +200,21 @@ impl Constraints {
Constraint::Eq(type_index, expected_index, category_index, region)
}
#[inline(always)]
pub fn equal_types_var(
&mut self,
var: Variable,
expected: Expected<Type>,
category: Category,
region: Region,
) -> Constraint {
let type_index = Self::push_type_variable(var);
let expected_index = Index::push_new(&mut self.expectations, expected);
let category_index = Self::push_category(self, category);
Constraint::Eq(type_index, expected_index, category_index, region)
}
pub fn equal_pattern_types(
&mut self,
typ: Type,