mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Remove _inner migration helper
This commit is contained in:
parent
d84e98751e
commit
4f40d83b80
1 changed files with 32 additions and 75 deletions
|
@ -103,7 +103,7 @@ fn constrain_untyped_closure(
|
||||||
constraints: &mut Constraints,
|
constraints: &mut Constraints,
|
||||||
env: &mut Env,
|
env: &mut Env,
|
||||||
region: Region,
|
region: Region,
|
||||||
expected: Expected<TypeOrVar>,
|
expected: ExpectedTypeIndex,
|
||||||
|
|
||||||
fn_var: Variable,
|
fn_var: Variable,
|
||||||
closure_var: Variable,
|
closure_var: Variable,
|
||||||
|
@ -152,7 +152,6 @@ 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 function_type = constraints.push_type(function_type);
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
|
|
||||||
let cons = [
|
let cons = [
|
||||||
constraints.let_constraint(
|
constraints.let_constraint(
|
||||||
|
@ -181,29 +180,13 @@ pub fn constrain_expr(
|
||||||
region: Region,
|
region: Region,
|
||||||
expr: &Expr,
|
expr: &Expr,
|
||||||
expected: ExpectedTypeIndex,
|
expected: ExpectedTypeIndex,
|
||||||
) -> Constraint {
|
|
||||||
let expected = constraints.expectations[expected.index()].clone();
|
|
||||||
constrain_expr_inner(constraints, env, region, expr, expected)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn constrain_expr_inner(
|
|
||||||
constraints: &mut Constraints,
|
|
||||||
env: &mut Env,
|
|
||||||
region: Region,
|
|
||||||
expr: &Expr,
|
|
||||||
expected: Expected<TypeOrVar>,
|
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
match expr {
|
match expr {
|
||||||
&Int(var, precision, _, _, bound) => {
|
&Int(var, precision, _, _, bound) => {
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
int_literal(constraints, var, precision, expected, region, bound)
|
int_literal(constraints, var, precision, expected, region, bound)
|
||||||
}
|
}
|
||||||
&Num(var, _, _, bound) => {
|
&Num(var, _, _, bound) => num_literal(constraints, var, expected, region, bound),
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
num_literal(constraints, var, expected, region, bound)
|
|
||||||
}
|
|
||||||
&Float(var, precision, _, _, bound) => {
|
&Float(var, precision, _, _, bound) => {
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
float_literal(constraints, var, precision, expected, region, bound)
|
float_literal(constraints, var, precision, expected, region, bound)
|
||||||
}
|
}
|
||||||
EmptyRecord => constrain_empty_record(constraints, region, expected),
|
EmptyRecord => constrain_empty_record(constraints, region, expected),
|
||||||
|
@ -232,7 +215,6 @@ fn constrain_expr_inner(
|
||||||
|
|
||||||
let record_type =
|
let record_type =
|
||||||
constraints.push_type(Type::Record(field_types, TypeExtension::Closed));
|
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,
|
||||||
|
@ -286,7 +268,7 @@ fn constrain_expr_inner(
|
||||||
Category::Record,
|
Category::Record,
|
||||||
region,
|
region,
|
||||||
);
|
);
|
||||||
let expected_record = constraints.push_expected_type(expected);
|
let expected_record = expected;
|
||||||
let record_con =
|
let record_con =
|
||||||
constraints.equal_types_var(*record_var, expected_record, Category::Record, region);
|
constraints.equal_types_var(*record_var, expected_record, Category::Record, region);
|
||||||
|
|
||||||
|
@ -317,33 +299,24 @@ fn constrain_expr_inner(
|
||||||
}
|
}
|
||||||
Str(_) => {
|
Str(_) => {
|
||||||
let str_index = constraints.push_type(str_type());
|
let str_index = constraints.push_type(str_type());
|
||||||
let expected_index = constraints.push_expected_type(expected);
|
let expected_index = expected;
|
||||||
constraints.equal_types(str_index, expected_index, Category::Str, region)
|
constraints.equal_types(str_index, expected_index, Category::Str, region)
|
||||||
}
|
}
|
||||||
SingleQuote(num_var, precision_var, _, bound) => {
|
SingleQuote(num_var, precision_var, _, bound) => single_quote_literal(
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
single_quote_literal(
|
|
||||||
constraints,
|
constraints,
|
||||||
*num_var,
|
*num_var,
|
||||||
*precision_var,
|
*precision_var,
|
||||||
expected,
|
expected,
|
||||||
region,
|
region,
|
||||||
*bound,
|
*bound,
|
||||||
)
|
),
|
||||||
}
|
|
||||||
List {
|
List {
|
||||||
elem_var,
|
elem_var,
|
||||||
loc_elems,
|
loc_elems,
|
||||||
} => {
|
} => {
|
||||||
if loc_elems.is_empty() {
|
if loc_elems.is_empty() {
|
||||||
let elem_type_index = constraints.push_type(empty_list_type(*elem_var));
|
let elem_type_index = constraints.push_type(empty_list_type(*elem_var));
|
||||||
let expected_index = constraints.push_expected_type(expected);
|
let eq = constraints.equal_types(elem_type_index, expected, Category::List, region);
|
||||||
let eq = constraints.equal_types(
|
|
||||||
elem_type_index,
|
|
||||||
expected_index,
|
|
||||||
Category::List,
|
|
||||||
region,
|
|
||||||
);
|
|
||||||
constraints.exists(vec![*elem_var], eq)
|
constraints.exists(vec![*elem_var], eq)
|
||||||
} else {
|
} else {
|
||||||
let list_elem_type = Type::Variable(*elem_var);
|
let list_elem_type = Type::Variable(*elem_var);
|
||||||
|
@ -370,10 +343,9 @@ fn constrain_expr_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
let elem_type_index = constraints.push_type(list_type(list_elem_type));
|
let elem_type_index = constraints.push_type(list_type(list_elem_type));
|
||||||
let expected_index = constraints.push_expected_type(expected);
|
|
||||||
list_constraints.push(constraints.equal_types(
|
list_constraints.push(constraints.equal_types(
|
||||||
elem_type_index,
|
elem_type_index,
|
||||||
expected_index,
|
expected,
|
||||||
Category::List,
|
Category::List,
|
||||||
region,
|
region,
|
||||||
));
|
));
|
||||||
|
@ -452,7 +424,7 @@ fn constrain_expr_inner(
|
||||||
let expected_fn_type =
|
let expected_fn_type =
|
||||||
constraints.push_expected_type(ForReason(fn_reason, expected_fn_index, region));
|
constraints.push_expected_type(ForReason(fn_reason, expected_fn_index, region));
|
||||||
|
|
||||||
let expected_final_type = constraints.push_expected_type(expected);
|
let expected_final_type = expected;
|
||||||
|
|
||||||
let category = Category::CallResult(opt_symbol, *called_via);
|
let category = Category::CallResult(opt_symbol, *called_via);
|
||||||
|
|
||||||
|
@ -468,6 +440,8 @@ fn constrain_expr_inner(
|
||||||
}
|
}
|
||||||
Var(symbol, variable) => {
|
Var(symbol, variable) => {
|
||||||
// Save the expectation in the variable, then lookup the symbol's type in the environment
|
// Save the expectation in the variable, then lookup the symbol's type in the environment
|
||||||
|
// TODO don't rewrap expectation
|
||||||
|
let expected = constraints.expectations[expected.index()].clone();
|
||||||
let expected_type = *expected.get_type_ref();
|
let expected_type = *expected.get_type_ref();
|
||||||
let store_expected = constraints.store(expected_type, *variable, file!(), line!());
|
let store_expected = constraints.store(expected_type, *variable, file!(), line!());
|
||||||
|
|
||||||
|
@ -481,6 +455,8 @@ fn constrain_expr_inner(
|
||||||
&AbilityMember(symbol, specialization_id, specialization_var) => {
|
&AbilityMember(symbol, specialization_id, specialization_var) => {
|
||||||
// Save the expectation in the `specialization_var` so we know what to specialize, then
|
// Save the expectation in the `specialization_var` so we know what to specialize, then
|
||||||
// lookup the member in the environment.
|
// lookup the member in the environment.
|
||||||
|
// TODO don't rewrap expectation
|
||||||
|
let expected = constraints.expectations[expected.index()].clone();
|
||||||
let expected_type = *expected.get_type_ref();
|
let expected_type = *expected.get_type_ref();
|
||||||
let store_expected =
|
let store_expected =
|
||||||
constraints.store(expected_type, specialization_var, file!(), line!());
|
constraints.store(expected_type, specialization_var, file!(), line!());
|
||||||
|
@ -550,7 +526,6 @@ fn constrain_expr_inner(
|
||||||
expected_bool,
|
expected_bool,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
let continuation_con = constrain_expr(
|
let continuation_con = constrain_expr(
|
||||||
constraints,
|
constraints,
|
||||||
env,
|
env,
|
||||||
|
@ -606,7 +581,6 @@ fn constrain_expr_inner(
|
||||||
expected_bool,
|
expected_bool,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
let continuation_con = constrain_expr(
|
let continuation_con = constrain_expr(
|
||||||
constraints,
|
constraints,
|
||||||
env,
|
env,
|
||||||
|
@ -668,6 +642,7 @@ fn constrain_expr_inner(
|
||||||
|
|
||||||
branch_cons.push(cond_var_is_bool_con);
|
branch_cons.push(cond_var_is_bool_con);
|
||||||
|
|
||||||
|
let expected = constraints.expectations[expected.index()].clone();
|
||||||
match expected {
|
match expected {
|
||||||
FromAnnotation(name, arity, ann_source, tipe) => {
|
FromAnnotation(name, arity, ann_source, tipe) => {
|
||||||
let num_branches = branches.len() + 1;
|
let num_branches = branches.len() + 1;
|
||||||
|
@ -891,7 +866,7 @@ fn constrain_expr_inner(
|
||||||
when_branch,
|
when_branch,
|
||||||
expected_pattern,
|
expected_pattern,
|
||||||
branch_expr_reason(
|
branch_expr_reason(
|
||||||
&expected,
|
&constraints.expectations[expected.index()],
|
||||||
HumanIndex::zero_based(index),
|
HumanIndex::zero_based(index),
|
||||||
when_branch.value.region,
|
when_branch.value.region,
|
||||||
),
|
),
|
||||||
|
@ -979,8 +954,6 @@ fn constrain_expr_inner(
|
||||||
body_constraints,
|
body_constraints,
|
||||||
);
|
);
|
||||||
|
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
|
|
||||||
let result_con =
|
let result_con =
|
||||||
constraints.equal_types_var(body_var, expected, Category::When, region);
|
constraints.equal_types_var(body_var, expected, Category::When, region);
|
||||||
|
|
||||||
|
@ -1023,7 +996,6 @@ fn constrain_expr_inner(
|
||||||
let expected_record = constraints.push_expected_type(NoExpectation(record_type));
|
let expected_record = constraints.push_expected_type(NoExpectation(record_type));
|
||||||
let constraint =
|
let constraint =
|
||||||
constrain_expr(constraints, env, region, &loc_expr.value, expected_record);
|
constrain_expr(constraints, env, region, &loc_expr.value, expected_record);
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
|
|
||||||
let eq = constraints.equal_types_var(field_var, expected, category, region);
|
let eq = constraints.equal_types_var(field_var, expected, category, region);
|
||||||
constraints.exists_many(
|
constraints.exists_many(
|
||||||
|
@ -1081,15 +1053,7 @@ fn constrain_expr_inner(
|
||||||
category.clone(),
|
category.clone(),
|
||||||
region,
|
region,
|
||||||
),
|
),
|
||||||
{
|
constraints.equal_types(function_type_index, expected, category.clone(), region),
|
||||||
let expected_index = constraints.push_expected_type(expected);
|
|
||||||
constraints.equal_types(
|
|
||||||
function_type_index,
|
|
||||||
expected_index,
|
|
||||||
category.clone(),
|
|
||||||
region,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
let store_fn_var_index = constraints.push_type(Variable(*function_var));
|
let store_fn_var_index = constraints.push_type(Variable(*function_var));
|
||||||
let store_fn_var_expected =
|
let store_fn_var_expected =
|
||||||
|
@ -1110,7 +1074,6 @@ fn constrain_expr_inner(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
LetRec(defs, loc_ret, cycle_mark) => {
|
LetRec(defs, loc_ret, cycle_mark) => {
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
let body_con =
|
let body_con =
|
||||||
constrain_expr(constraints, env, loc_ret.region, &loc_ret.value, expected);
|
constrain_expr(constraints, env, loc_ret.region, &loc_ret.value, expected);
|
||||||
|
|
||||||
|
@ -1128,7 +1091,6 @@ fn constrain_expr_inner(
|
||||||
loc_ret = new_loc_ret;
|
loc_ret = new_loc_ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
let mut body_con =
|
let mut body_con =
|
||||||
constrain_expr(constraints, env, loc_ret.region, &loc_ret.value, expected);
|
constrain_expr(constraints, env, loc_ret.region, &loc_ret.value, expected);
|
||||||
|
|
||||||
|
@ -1170,7 +1132,6 @@ fn constrain_expr_inner(
|
||||||
vec![(name.clone(), types)],
|
vec![(name.clone(), types)],
|
||||||
TypeExtension::from_type(Type::Variable(*ext_var)),
|
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(
|
||||||
tag_union_type,
|
tag_union_type,
|
||||||
|
@ -1200,7 +1161,6 @@ fn constrain_expr_inner(
|
||||||
*closure_name,
|
*closure_name,
|
||||||
TypeExtension::from_type(Type::Variable(*ext_var)),
|
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(
|
||||||
function_or_tag_union,
|
function_or_tag_union,
|
||||||
expected,
|
expected,
|
||||||
|
@ -1254,7 +1214,6 @@ fn constrain_expr_inner(
|
||||||
|
|
||||||
// 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,
|
||||||
|
@ -1362,8 +1321,6 @@ fn constrain_expr_inner(
|
||||||
constraints.push_expected_type(NoExpectation(fn_type))
|
constraints.push_expected_type(NoExpectation(fn_type))
|
||||||
};
|
};
|
||||||
|
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
|
|
||||||
let cons = [
|
let cons = [
|
||||||
opaque_con,
|
opaque_con,
|
||||||
link_type_variables_con,
|
link_type_variables_con,
|
||||||
|
@ -1432,7 +1389,6 @@ fn constrain_expr_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
let category = Category::LowLevelOpResult(*op);
|
let category = Category::LowLevelOpResult(*op);
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
|
|
||||||
// Deviation: elm uses an additional And here
|
// Deviation: elm uses an additional And here
|
||||||
let eq = constraints.equal_types_var(*ret_var, expected, category, region);
|
let eq = constraints.equal_types_var(*ret_var, expected, category, region);
|
||||||
|
@ -1475,7 +1431,6 @@ fn constrain_expr_inner(
|
||||||
}
|
}
|
||||||
|
|
||||||
let category = Category::ForeignCall;
|
let category = Category::ForeignCall;
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
|
|
||||||
// Deviation: elm uses an additional And here
|
// Deviation: elm uses an additional And here
|
||||||
let eq = constraints.equal_types_var(*ret_var, expected, category, region);
|
let eq = constraints.equal_types_var(*ret_var, expected, category, region);
|
||||||
|
@ -1484,7 +1439,6 @@ fn constrain_expr_inner(
|
||||||
}
|
}
|
||||||
TypedHole(var) => {
|
TypedHole(var) => {
|
||||||
// store the expected type for this position
|
// store the expected type for this position
|
||||||
let expected = constraints.push_expected_type(expected);
|
|
||||||
constraints.equal_types_var(
|
constraints.equal_types_var(
|
||||||
*var,
|
*var,
|
||||||
expected,
|
expected,
|
||||||
|
@ -1498,6 +1452,8 @@ fn constrain_expr_inner(
|
||||||
// Instead, trivially equate the expected type to itself. This will never yield
|
// Instead, trivially equate the expected type to itself. This will never yield
|
||||||
// unification errors but it will catch errors in type translation, including ability
|
// unification errors but it will catch errors in type translation, including ability
|
||||||
// obligations.
|
// obligations.
|
||||||
|
// TODO: simpl
|
||||||
|
let expected = constraints.expectations[expected.index()].clone();
|
||||||
let trivial_type = *expected.get_type_ref();
|
let trivial_type = *expected.get_type_ref();
|
||||||
let expected = constraints.push_expected_type(expected);
|
let expected = constraints.push_expected_type(expected);
|
||||||
constraints.equal_types(trivial_type, expected, Category::Unknown, region)
|
constraints.equal_types(trivial_type, expected, Category::Unknown, region)
|
||||||
|
@ -1587,14 +1543,14 @@ fn constrain_function_def(
|
||||||
def_pattern_state
|
def_pattern_state
|
||||||
};
|
};
|
||||||
|
|
||||||
let annotation_expected = FromAnnotation(
|
let annotation_expected = constraints.push_expected_type(FromAnnotation(
|
||||||
loc_pattern,
|
loc_pattern,
|
||||||
arity,
|
arity,
|
||||||
AnnotationSource::TypedBody {
|
AnnotationSource::TypedBody {
|
||||||
region: annotation.region,
|
region: annotation.region,
|
||||||
},
|
},
|
||||||
signature_index,
|
signature_index,
|
||||||
);
|
));
|
||||||
|
|
||||||
let ret_constraint = constrain_untyped_closure(
|
let ret_constraint = constrain_untyped_closure(
|
||||||
constraints,
|
constraints,
|
||||||
|
@ -1778,11 +1734,12 @@ fn constrain_function_def(
|
||||||
None => {
|
None => {
|
||||||
let expr_type = constraints.push_type(Variable(expr_var));
|
let expr_type = constraints.push_type(Variable(expr_var));
|
||||||
|
|
||||||
|
let expected_expr = constraints.push_expected_type(NoExpectation(expr_type));
|
||||||
let expr_con = constrain_untyped_closure(
|
let expr_con = constrain_untyped_closure(
|
||||||
constraints,
|
constraints,
|
||||||
env,
|
env,
|
||||||
loc_function_def.region,
|
loc_function_def.region,
|
||||||
NoExpectation(expr_type),
|
expected_expr,
|
||||||
expr_var,
|
expr_var,
|
||||||
function_def.closure_type,
|
function_def.closure_type,
|
||||||
function_def.return_type,
|
function_def.return_type,
|
||||||
|
@ -2169,11 +2126,10 @@ fn constrain_field(
|
||||||
fn constrain_empty_record(
|
fn constrain_empty_record(
|
||||||
constraints: &mut Constraints,
|
constraints: &mut Constraints,
|
||||||
region: Region,
|
region: Region,
|
||||||
expected: Expected<TypeOrVar>,
|
expected: ExpectedTypeIndex,
|
||||||
) -> Constraint {
|
) -> Constraint {
|
||||||
let record_type_index = constraints.push_type(Type::EmptyRec);
|
let record_type_index = constraints.push_type(Type::EmptyRec);
|
||||||
let expected_index = constraints.push_expected_type(expected);
|
constraints.equal_types(record_type_index, expected, Category::Record, region)
|
||||||
constraints.equal_types(record_type_index, expected_index, Category::Record, region)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constrain top-level module declarations
|
/// Constrain top-level module declarations
|
||||||
|
@ -3120,11 +3076,12 @@ fn constraint_recursive_function(
|
||||||
None => {
|
None => {
|
||||||
let expr_type_index = constraints.push_type(Type::Variable(expr_var));
|
let expr_type_index = constraints.push_type(Type::Variable(expr_var));
|
||||||
|
|
||||||
|
let expected_expr = constraints.push_expected_type(NoExpectation(expr_type_index));
|
||||||
let expr_con = constrain_untyped_closure(
|
let expr_con = constrain_untyped_closure(
|
||||||
constraints,
|
constraints,
|
||||||
env,
|
env,
|
||||||
loc_function_def.region,
|
loc_function_def.region,
|
||||||
NoExpectation(expr_type_index),
|
expected_expr,
|
||||||
expr_var,
|
expr_var,
|
||||||
function_def.closure_type,
|
function_def.closure_type,
|
||||||
function_def.return_type,
|
function_def.return_type,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue