mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
don't even create a type if we only need a variable
This commit is contained in:
parent
eccb461b01
commit
8b2c1707d4
3 changed files with 81 additions and 76 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue