extract tags from the ext variable

turns out this is always needed. I also removed the explicit check for an empty tag union: there could still be tags in the ext even if the union itself seems empty.
seems weird to optimize for the empty case because it'll be very rare in practice
This commit is contained in:
Folkert 2020-03-06 13:23:53 +01:00
parent e6e9676b70
commit 12a819e762

View File

@ -359,10 +359,7 @@ fn write_flat_type(
// Sort the fields so they always end up in the same order.
let mut sorted_fields = Vec::with_capacity(fields.len());
for (label, field_var) in fields {
sorted_fields.push((label, field_var));
}
sorted_fields.extend(fields);
sorted_fields.sort_by(|(a, _), (b, _)| a.cmp(b));
let mut any_written_yet = false;
@ -397,9 +394,6 @@ fn write_flat_type(
}
}
TagUnion(tags, ext_var) => {
if tags.is_empty() {
buf.push_str(EMPTY_TAG_UNION)
} else {
let interns = &env.interns;
let home = env.home;
@ -412,6 +406,10 @@ fn write_flat_type(
sorted_fields.push((label.clone(), vars));
}
// If the `ext` contains tags, merge them into the list of tags.
// this can occur when inferring mutually recursive tags
let ext_content = chase_ext_tag_union(subs, ext_var, &mut sorted_fields);
sorted_fields.sort_by(|(a, _), (b, _)| {
a.clone()
.into_string(interns, home)
@ -436,13 +434,8 @@ fn write_flat_type(
}
buf.push_str(" ]");
}
match subs.get(ext_var).content {
Content::Structure(EmptyTagUnion) => {
// This is a closed record. We're done!
}
content => {
if let Some(content) = ext_content {
// This is an open tag union, so print the variable
// right after the ']'
//
@ -451,12 +444,8 @@ fn write_flat_type(
write_content(env, content, subs, buf, parens)
}
}
}
RecursiveTagUnion(rec_var, tags, ext_var) => {
if tags.is_empty() {
buf.push_str(EMPTY_TAG_UNION)
} else {
let interns = &env.interns;
let home = env.home;
@ -501,7 +490,6 @@ fn write_flat_type(
// or the "r" at the end of `{ x: Int }r`
write_content(env, content, subs, buf, parens)
}
}
buf.push_str(" as ");
write_content(env, subs.get(rec_var).content, subs, buf, parens)