Fix deriving of hash ability for recursive tag unions

This commit is contained in:
Ayaz Hafiz 2022-10-05 12:01:02 -05:00
parent 02b02901bc
commit 2517695ce4
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
4 changed files with 25 additions and 8 deletions

View file

@ -140,7 +140,8 @@ impl FlatHash {
},
Content::RangedNumber(_) => Err(Underivable),
//
Content::RecursionVar { .. } => Err(Underivable),
Content::RecursionVar { structure, .. } => Self::from_var(subs, structure),
//
Content::Error => Err(Underivable),
Content::FlexVar(_)
| Content::RigidVar(_)

View file

@ -655,7 +655,7 @@ fn make_specialization_decision<P: Phase>(
})
}
}
Structure(_) | Alias(_, _, _, _) => {
Structure(_) | Alias(_, _, _, _) | RecursionVar { .. } => {
let builtin = match ability_member.try_into() {
Ok(builtin) => builtin,
Err(_) => return SpecializeDecision::Drop,
@ -691,7 +691,6 @@ fn make_specialization_decision<P: Phase>(
| RigidAbleVar(..)
| FlexVar(..)
| RigidVar(..)
| RecursionVar { .. }
| LambdaSet(..)
| RangedNumber(..) => {
internal_error!("unexpected")

View file

@ -1568,7 +1568,6 @@ mod hash {
}
#[test]
#[ignore = "TODO"]
fn hash_recursive_tag_union() {
assert_evals_to!(
&format!(
@ -1591,7 +1590,11 @@ mod hash {
),
TEST_HASHER,
),
RocList::from_slice(&[0]),
RocList::from_slice(&[
0, 0, 1, // Cons 1
0, 0, 2, // Cons 2
1, 0, // Nil
]),
RocList<u8>
)
}

View file

@ -2937,7 +2937,6 @@ fn unify_flex_able<M: MetaCollector>(
}
RigidVar(_) => mismatch!("FlexAble can never unify with non-able Rigid"),
RecursionVar { .. } => mismatch!("FlexAble with RecursionVar"),
LambdaSet(..) => mismatch!("FlexAble with LambdaSet"),
Alias(name, _args, _real_var, AliasKind::Opaque) => {
@ -2952,7 +2951,10 @@ fn unify_flex_able<M: MetaCollector>(
)
}
Structure(_) | Alias(_, _, _, AliasKind::Structural) | RangedNumber(..) => {
RecursionVar { .. }
| Structure(_)
| Alias(_, _, _, AliasKind::Structural)
| RangedNumber(..) => {
// Structural type wins.
merge_flex_able_with_concrete(
env,
@ -3035,10 +3037,22 @@ fn unify_recursion<M: MetaCollector>(
mismatch!("RecursionVar {:?} with rigid {:?}", ctx.first, &other)
}
FlexAbleVar(..) | RigidAbleVar(..) => {
RigidAbleVar(..) => {
mismatch!("RecursionVar {:?} with able var {:?}", ctx.first, &other)
}
FlexAbleVar(_, ability) => merge_flex_able_with_concrete(
env,
ctx,
ctx.second,
*ability,
RecursionVar {
structure,
opt_name: *opt_name,
},
Obligated::Adhoc(ctx.first),
),
FlexVar(_) => merge(
env,
ctx,