new recvar design

This commit is contained in:
Folkert 2020-10-26 16:16:01 +01:00
parent 1001a17649
commit 5fbcfe18d3
7 changed files with 69 additions and 28 deletions

View file

@ -140,7 +140,9 @@ fn unify_context(subs: &mut Subs, pool: &mut Pool, ctx: Context) -> Outcome {
}
match &ctx.first_desc.content {
FlexVar(opt_name) => unify_flex(subs, &ctx, opt_name, &ctx.second_desc.content),
RecursionVar(opt_name) => unify_recursion(subs, &ctx, opt_name, &ctx.second_desc.content),
RecursionVar { opt_name, .. } => {
unify_recursion(subs, &ctx, opt_name, &ctx.second_desc.content)
}
RigidVar(name) => unify_rigid(subs, &ctx, name, &ctx.second_desc.content),
Structure(flat_type) => {
unify_structure(subs, pool, &ctx, flat_type, &ctx.second_desc.content)
@ -169,7 +171,7 @@ fn unify_alias(
// Alias wins
merge(subs, &ctx, Alias(symbol, args.to_owned(), real_var))
}
RecursionVar(_) | RigidVar(_) => unify_pool(subs, pool, real_var, ctx.second),
RecursionVar { .. } | RigidVar(_) => unify_pool(subs, pool, real_var, ctx.second),
Alias(other_symbol, other_args, other_real_var) => {
if symbol == *other_symbol {
if args.len() == other_args.len() {
@ -214,7 +216,7 @@ fn unify_structure(
// Type mismatch! Rigid can only unify with flex.
mismatch!("trying to unify {:?} with rigid var {:?}", &flat_type, name)
}
RecursionVar(_) => {
RecursionVar { .. } => {
// keep recursion var around
merge(subs, ctx, other.clone())
}
@ -922,7 +924,7 @@ fn unify_rigid(subs: &mut Subs, ctx: &Context, name: &Lowercase, other: &Content
// If the other is flex, rigid wins!
merge(subs, ctx, RigidVar(name.clone()))
}
RigidVar(_) | RecursionVar(_) | Structure(_) | Alias(_, _, _) => {
RigidVar(_) | RecursionVar { .. } | Structure(_) | Alias(_, _, _) => {
// Type mismatch! Rigid can only unify with flex, even if the
// rigid names are the same.
mismatch!("Rigid with {:?}", &other)
@ -947,7 +949,7 @@ fn unify_flex(
merge(subs, ctx, FlexVar(opt_name.clone()))
}
FlexVar(Some(_)) | RigidVar(_) | RecursionVar(_) | Structure(_) | Alias(_, _, _) => {
FlexVar(Some(_)) | RigidVar(_) | RecursionVar { .. } | Structure(_) | Alias(_, _, _) => {
// TODO special-case boolean here
// In all other cases, if left is flex, defer to right.
// (This includes using right's name if both are flex and named.)
@ -966,7 +968,7 @@ fn unify_recursion(
other: &Content,
) -> Outcome {
match other {
RecursionVar(None) => {
RecursionVar { opt_name: None, .. } => {
// If both are flex, and only left has a name, keep the name around.
merge(subs, ctx, FlexVar(opt_name.clone()))
}
@ -976,7 +978,7 @@ fn unify_recursion(
merge(subs, ctx, FlexVar(opt_name.clone()))
}
FlexVar(_) | RigidVar(_) | RecursionVar(_) | Alias(_, _, _) => {
FlexVar(_) | RigidVar(_) | RecursionVar { .. } | Alias(_, _, _) => {
// TODO special-case boolean here
// In all other cases, if left is flex, defer to right.
// (This includes using right's name if both are flex and named.)