mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-03 00:24:34 +00:00
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:
parent
e6e9676b70
commit
12a819e762
1 changed files with 77 additions and 89 deletions
|
@ -359,10 +359,7 @@ fn write_flat_type(
|
||||||
// Sort the fields so they always end up in the same order.
|
// Sort the fields so they always end up in the same order.
|
||||||
let mut sorted_fields = Vec::with_capacity(fields.len());
|
let mut sorted_fields = Vec::with_capacity(fields.len());
|
||||||
|
|
||||||
for (label, field_var) in fields {
|
sorted_fields.extend(fields);
|
||||||
sorted_fields.push((label, field_var));
|
|
||||||
}
|
|
||||||
|
|
||||||
sorted_fields.sort_by(|(a, _), (b, _)| a.cmp(b));
|
sorted_fields.sort_by(|(a, _), (b, _)| a.cmp(b));
|
||||||
|
|
||||||
let mut any_written_yet = false;
|
let mut any_written_yet = false;
|
||||||
|
@ -397,9 +394,6 @@ fn write_flat_type(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TagUnion(tags, ext_var) => {
|
TagUnion(tags, ext_var) => {
|
||||||
if tags.is_empty() {
|
|
||||||
buf.push_str(EMPTY_TAG_UNION)
|
|
||||||
} else {
|
|
||||||
let interns = &env.interns;
|
let interns = &env.interns;
|
||||||
let home = env.home;
|
let home = env.home;
|
||||||
|
|
||||||
|
@ -412,6 +406,10 @@ fn write_flat_type(
|
||||||
sorted_fields.push((label.clone(), vars));
|
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, _)| {
|
sorted_fields.sort_by(|(a, _), (b, _)| {
|
||||||
a.clone()
|
a.clone()
|
||||||
.into_string(interns, home)
|
.into_string(interns, home)
|
||||||
|
@ -436,13 +434,8 @@ fn write_flat_type(
|
||||||
}
|
}
|
||||||
|
|
||||||
buf.push_str(" ]");
|
buf.push_str(" ]");
|
||||||
}
|
|
||||||
|
|
||||||
match subs.get(ext_var).content {
|
if let Some(content) = ext_content {
|
||||||
Content::Structure(EmptyTagUnion) => {
|
|
||||||
// This is a closed record. We're done!
|
|
||||||
}
|
|
||||||
content => {
|
|
||||||
// This is an open tag union, so print the variable
|
// This is an open tag union, so print the variable
|
||||||
// right after the ']'
|
// right after the ']'
|
||||||
//
|
//
|
||||||
|
@ -451,12 +444,8 @@ fn write_flat_type(
|
||||||
write_content(env, content, subs, buf, parens)
|
write_content(env, content, subs, buf, parens)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
RecursiveTagUnion(rec_var, tags, ext_var) => {
|
RecursiveTagUnion(rec_var, tags, ext_var) => {
|
||||||
if tags.is_empty() {
|
|
||||||
buf.push_str(EMPTY_TAG_UNION)
|
|
||||||
} else {
|
|
||||||
let interns = &env.interns;
|
let interns = &env.interns;
|
||||||
let home = env.home;
|
let home = env.home;
|
||||||
|
|
||||||
|
@ -501,7 +490,6 @@ fn write_flat_type(
|
||||||
// or the "r" at the end of `{ x: Int }r`
|
// or the "r" at the end of `{ x: Int }r`
|
||||||
write_content(env, content, subs, buf, parens)
|
write_content(env, content, subs, buf, parens)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
buf.push_str(" as ");
|
buf.push_str(" as ");
|
||||||
write_content(env, subs.get(rec_var).content, subs, buf, parens)
|
write_content(env, subs.get(rec_var).content, subs, buf, parens)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue