mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
equal_types_with_storage takes type index
This commit is contained in:
parent
cca5f53e98
commit
c53e08f63c
2 changed files with 28 additions and 18 deletions
|
@ -281,14 +281,12 @@ impl Constraints {
|
||||||
|
|
||||||
pub fn equal_types_with_storage(
|
pub fn equal_types_with_storage(
|
||||||
&mut self,
|
&mut self,
|
||||||
typ: Type,
|
type_index: TypeOrVar,
|
||||||
expected: Expected<Type>,
|
expected_index: ExpectedTypeIndex,
|
||||||
category: Category,
|
category: Category,
|
||||||
region: Region,
|
region: Region,
|
||||||
storage_var: Variable,
|
storage_var: Variable,
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
let type_index = self.push_type(typ);
|
|
||||||
let expected_index = Index::push_new(&mut self.expectations, expected.map(Cell::new));
|
|
||||||
let category_index = Self::push_category(self, category);
|
let category_index = Self::push_category(self, category);
|
||||||
|
|
||||||
let equal = Constraint::Eq(Eq(type_index, expected_index, category_index, region));
|
let equal = Constraint::Eq(Eq(type_index, expected_index, category_index, region));
|
||||||
|
|
|
@ -151,6 +151,10 @@ fn constrain_untyped_closure(
|
||||||
);
|
);
|
||||||
|
|
||||||
let pattern_state_constraints = constraints.and_constraint(pattern_state.constraints);
|
let pattern_state_constraints = constraints.and_constraint(pattern_state.constraints);
|
||||||
|
|
||||||
|
let function_type = constraints.push_type(function_type);
|
||||||
|
let expected = constraints.push_expected_type(expected);
|
||||||
|
|
||||||
let cons = [
|
let cons = [
|
||||||
constraints.let_constraint(
|
constraints.let_constraint(
|
||||||
[],
|
[],
|
||||||
|
@ -211,7 +215,9 @@ pub fn constrain_expr(
|
||||||
rec_constraints.push(field_con);
|
rec_constraints.push(field_con);
|
||||||
}
|
}
|
||||||
|
|
||||||
let record_type = Type::Record(field_types, TypeExtension::Closed);
|
let record_type =
|
||||||
|
constraints.push_type(Type::Record(field_types, TypeExtension::Closed));
|
||||||
|
let expected = constraints.push_expected_type(expected);
|
||||||
|
|
||||||
let record_con = constraints.equal_types_with_storage(
|
let record_con = constraints.equal_types_with_storage(
|
||||||
record_type,
|
record_type,
|
||||||
|
@ -1113,12 +1119,15 @@ pub fn constrain_expr(
|
||||||
types.push(Type::Variable(*var));
|
types.push(Type::Variable(*var));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let tag_union_type = constraints.push_type(Type::TagUnion(
|
||||||
|
vec![(name.clone(), types)],
|
||||||
|
TypeExtension::from_type(Type::Variable(*ext_var)),
|
||||||
|
));
|
||||||
|
let expected = constraints.push_expected_type(expected);
|
||||||
|
|
||||||
let union_con = constraints.equal_types_with_storage(
|
let union_con = constraints.equal_types_with_storage(
|
||||||
Type::TagUnion(
|
tag_union_type,
|
||||||
vec![(name.clone(), types)],
|
expected,
|
||||||
TypeExtension::from_type(Type::Variable(*ext_var)),
|
|
||||||
),
|
|
||||||
expected.clone(),
|
|
||||||
Category::TagApply {
|
Category::TagApply {
|
||||||
tag_name: name.clone(),
|
tag_name: name.clone(),
|
||||||
args_count: arguments.len(),
|
args_count: arguments.len(),
|
||||||
|
@ -1139,13 +1148,15 @@ pub fn constrain_expr(
|
||||||
name,
|
name,
|
||||||
closure_name,
|
closure_name,
|
||||||
} => {
|
} => {
|
||||||
|
let function_or_tag_union = constraints.push_type(Type::FunctionOrTagUnion(
|
||||||
|
name.clone(),
|
||||||
|
*closure_name,
|
||||||
|
TypeExtension::from_type(Type::Variable(*ext_var)),
|
||||||
|
));
|
||||||
|
let expected = constraints.push_expected_type(expected);
|
||||||
let union_con = constraints.equal_types_with_storage(
|
let union_con = constraints.equal_types_with_storage(
|
||||||
Type::FunctionOrTagUnion(
|
function_or_tag_union,
|
||||||
name.clone(),
|
expected,
|
||||||
*closure_name,
|
|
||||||
TypeExtension::from_type(Type::Variable(*ext_var)),
|
|
||||||
),
|
|
||||||
expected.clone(),
|
|
||||||
Category::TagApply {
|
Category::TagApply {
|
||||||
tag_name: name.clone(),
|
tag_name: name.clone(),
|
||||||
args_count: 0,
|
args_count: 0,
|
||||||
|
@ -1167,7 +1178,7 @@ pub fn constrain_expr(
|
||||||
let (arg_var, arg_loc_expr) = &**argument;
|
let (arg_var, arg_loc_expr) = &**argument;
|
||||||
let arg_type = Type::Variable(*arg_var);
|
let arg_type = Type::Variable(*arg_var);
|
||||||
|
|
||||||
let opaque_type = Type::Alias {
|
let opaque_type = constraints.push_type(Type::Alias {
|
||||||
symbol: *name,
|
symbol: *name,
|
||||||
type_arguments: type_arguments
|
type_arguments: type_arguments
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -1179,7 +1190,7 @@ pub fn constrain_expr(
|
||||||
lambda_set_variables: lambda_set_variables.clone(),
|
lambda_set_variables: lambda_set_variables.clone(),
|
||||||
actual: Box::new(arg_type.clone()),
|
actual: Box::new(arg_type.clone()),
|
||||||
kind: AliasKind::Opaque,
|
kind: AliasKind::Opaque,
|
||||||
};
|
});
|
||||||
|
|
||||||
// Constrain the argument
|
// Constrain the argument
|
||||||
let arg_con = constrain_expr(
|
let arg_con = constrain_expr(
|
||||||
|
@ -1192,6 +1203,7 @@ pub fn constrain_expr(
|
||||||
|
|
||||||
// Link the entire wrapped opaque type (with the now-constrained argument) to the
|
// Link the entire wrapped opaque type (with the now-constrained argument) to the
|
||||||
// expected type
|
// expected type
|
||||||
|
let expected = constraints.push_expected_type(expected);
|
||||||
let opaque_con = constraints.equal_types_with_storage(
|
let opaque_con = constraints.equal_types_with_storage(
|
||||||
opaque_type,
|
opaque_type,
|
||||||
expected,
|
expected,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue