mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 23:04:49 +00:00
feat(unify): clean up with @folkertdev
This commit is contained in:
parent
6aaa12079d
commit
f8a6cd6a74
1 changed files with 13 additions and 27 deletions
|
@ -1,4 +1,6 @@
|
||||||
use roc_collections::all::{get_shared, relative_complement, union, MutMap, SendSet};
|
use roc_collections::all::{
|
||||||
|
default_hasher, get_shared, relative_complement, union, MutMap, SendSet,
|
||||||
|
};
|
||||||
use roc_module::ident::{Lowercase, TagName};
|
use roc_module::ident::{Lowercase, TagName};
|
||||||
use roc_module::symbol::Symbol;
|
use roc_module::symbol::Symbol;
|
||||||
use roc_types::boolean_algebra::Bool;
|
use roc_types::boolean_algebra::Bool;
|
||||||
|
@ -1070,17 +1072,12 @@ fn unify_flat_type(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(TagUnion(tags, ext), Func(args, closure, ret)) if tags.len() == 1 => {
|
(TagUnion(tags, ext), Func(args, closure, ret)) if tags.len() == 1 => {
|
||||||
let (tag, payload) = tags.iter().next().unwrap();
|
let (tag_name, payload) = tags.iter().next().unwrap();
|
||||||
|
|
||||||
if payload.is_empty() {
|
if payload.is_empty() {
|
||||||
let mut new_payload = vec![];
|
let mut new_tags = MutMap::with_capacity_and_hasher(1, default_hasher());
|
||||||
let mut new_tags = MutMap::default();
|
|
||||||
|
|
||||||
for arg in args {
|
new_tags.insert(tag_name.clone(), args.clone());
|
||||||
new_payload.push(*arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
new_tags.insert(tag.clone(), new_payload);
|
|
||||||
|
|
||||||
let content = Structure(TagUnion(new_tags, *ext));
|
let content = Structure(TagUnion(new_tags, *ext));
|
||||||
|
|
||||||
|
@ -1088,16 +1085,12 @@ fn unify_flat_type(
|
||||||
|
|
||||||
let problems = unify_pool(subs, pool, new_tag_union_var, *ret);
|
let problems = unify_pool(subs, pool, new_tag_union_var, *ret);
|
||||||
|
|
||||||
dbg!(problems.clone());
|
|
||||||
|
|
||||||
if problems.is_empty() {
|
if problems.is_empty() {
|
||||||
let desc = subs.get(ctx.second);
|
let desc = subs.get(ctx.second);
|
||||||
subs.union(ctx.first, ctx.second, desc);
|
subs.union(ctx.first, ctx.second, desc);
|
||||||
|
|
||||||
vec![]
|
|
||||||
} else {
|
|
||||||
problems
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
problems
|
||||||
} else {
|
} else {
|
||||||
mismatch!(
|
mismatch!(
|
||||||
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}",
|
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}",
|
||||||
|
@ -1107,17 +1100,12 @@ fn unify_flat_type(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Func(args, closure, ret), TagUnion(tags, ext)) if tags.len() == 1 => {
|
(Func(args, closure, ret), TagUnion(tags, ext)) if tags.len() == 1 => {
|
||||||
let (tag, payload) = tags.iter().next().unwrap();
|
let (tag_name, payload) = tags.iter().next().unwrap();
|
||||||
|
|
||||||
if payload.is_empty() {
|
if payload.is_empty() {
|
||||||
let mut new_payload = vec![];
|
let mut new_tags = MutMap::with_capacity_and_hasher(1, default_hasher());
|
||||||
let mut new_tags = MutMap::default();
|
|
||||||
|
|
||||||
for arg in args {
|
new_tags.insert(tag_name.clone(), args.clone());
|
||||||
new_payload.push(*arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
new_tags.insert(tag.clone(), new_payload);
|
|
||||||
|
|
||||||
let content = Structure(TagUnion(new_tags, *ext));
|
let content = Structure(TagUnion(new_tags, *ext));
|
||||||
|
|
||||||
|
@ -1128,11 +1116,9 @@ fn unify_flat_type(
|
||||||
if problems.is_empty() {
|
if problems.is_empty() {
|
||||||
let desc = subs.get(ctx.first);
|
let desc = subs.get(ctx.first);
|
||||||
subs.union(ctx.first, ctx.second, desc);
|
subs.union(ctx.first, ctx.second, desc);
|
||||||
|
|
||||||
vec![]
|
|
||||||
} else {
|
|
||||||
problems
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
problems
|
||||||
} else {
|
} else {
|
||||||
mismatch!(
|
mismatch!(
|
||||||
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}",
|
"Trying to unify two flat types that are incompatible: {:?} ~ {:?}",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue