Index into constraining via trait

This commit is contained in:
Ayaz Hafiz 2022-11-07 17:07:58 -06:00
parent 24b6d4a3a9
commit 51d813dae2
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 25 additions and 9 deletions

View file

@ -441,7 +441,7 @@ pub fn constrain_expr(
}
Var(symbol, variable) => {
// Save the expectation in the variable, then lookup the symbol's type in the environment
let expected_type = *constraints.expectations[expected.index()].get_type_ref();
let expected_type = *constraints[expected].get_type_ref();
let store_expected = constraints.store(expected_type, *variable, file!(), line!());
let lookup_constr = constraints.lookup(*symbol, expected, region);
@ -451,7 +451,7 @@ pub fn constrain_expr(
&AbilityMember(symbol, specialization_id, specialization_var) => {
// Save the expectation in the `specialization_var` so we know what to specialize, then
// lookup the member in the environment.
let expected_type = *constraints.expectations[expected.index()].get_type_ref();
let expected_type = *constraints[expected].get_type_ref();
let store_expected =
constraints.store(expected_type, specialization_var, file!(), line!());
@ -636,7 +636,7 @@ pub fn constrain_expr(
branch_cons.push(cond_var_is_bool_con);
let expected = constraints.expectations[expected.index()].clone();
let expected = constraints[expected].clone();
match expected {
FromAnnotation(name, arity, ann_source, tipe) => {
let num_branches = branches.len() + 1;
@ -860,7 +860,7 @@ pub fn constrain_expr(
when_branch,
expected_pattern,
branch_expr_reason(
&constraints.expectations[expected.index()],
&constraints[expected],
HumanIndex::zero_based(index),
when_branch.value.region,
),
@ -1446,7 +1446,7 @@ pub fn constrain_expr(
// Instead, trivially equate the expected type to itself. This will never yield
// unification errors but it will catch errors in type translation, including ability
// obligations.
let trivial_type = *constraints.expectations[expected.index()].get_type_ref();
let trivial_type = *constraints[expected].get_type_ref();
constraints.equal_types(trivial_type, expected, Category::Unknown, region)
}
}

View file

@ -198,7 +198,7 @@ pub fn constrain_pattern(
// A -> ""
// _ -> ""
// so, we know that "x" (in this case, a tag union) must be open.
let expected_type = *constraints.pattern_expectations[expected.index()].get_type_ref();
let expected_type = *constraints[expected].get_type_ref();
if could_be_a_tag_union(constraints, expected_type) {
state
.delayed_is_open_constraints
@ -210,7 +210,7 @@ pub fn constrain_pattern(
}
Identifier(symbol) | Shadowed(_, _, symbol) => {
let expected = &constraints.pattern_expectations[expected.index()];
let expected = &constraints[expected];
let type_index = *expected.get_type_ref();
if could_be_a_tag_union(constraints, type_index) {
@ -232,7 +232,7 @@ pub fn constrain_pattern(
ident: symbol,
specializes: _,
} => {
let expected = &constraints.pattern_expectations[expected.index()];
let expected = &constraints[expected];
let type_index = *expected.get_type_ref();
if could_be_a_tag_union(constraints, type_index) {
@ -598,7 +598,7 @@ pub fn constrain_pattern(
}
let pat_category = PatternCategory::Ctor(tag_name.clone());
let expected_type = *constraints.pattern_expectations[expected.index()].get_type_ref();
let expected_type = *constraints[expected].get_type_ref();
let whole_con = constraints.includes_tag(
expected_type,