Consolidate IsOpen solve

This commit is contained in:
Ayaz Hafiz 2022-04-25 14:10:32 -04:00
parent 07e69c7860
commit 19233e08c2
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -1105,32 +1105,7 @@ fn solve(
let actual = let actual =
either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index); either_type_index_to_var(constraints, subs, rank, pools, aliases, *type_index);
let mut stack = vec![actual]; open_tag_union(subs, actual);
while let Some(var) = stack.pop() {
use {Content::*, FlatType::*};
let mut desc = subs.get(var);
if let Structure(TagUnion(tags, ext)) = desc.content {
if let Structure(EmptyTagUnion) = subs.get_content_without_compacting(ext) {
let new_ext = subs.fresh_unnamed_flex_var();
subs.set_rank(new_ext, desc.rank);
let new_union = Structure(TagUnion(tags, new_ext));
desc.content = new_union;
subs.set(var, desc);
}
// Also open up all nested tag unions.
let all_vars = tags.variables().into_iter();
stack.extend(all_vars.flat_map(|slice| subs[slice]).map(|var| subs[var]));
}
// Today, an "open" constraint doesn't affect any types
// other than tag unions. Recursive tag unions are constructed
// at a later time (during occurs checks after tag unions are
// resolved), so that's not handled here either.
// NB: Handle record types here if we add presence constraints
// to their type inference as well.
}
state state
} }