minor cleanup to recursive alias creation

This commit is contained in:
Folkert 2022-04-24 13:43:04 +02:00
parent 912d9db293
commit dbae805071
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C

View file

@ -2055,7 +2055,7 @@ fn make_tag_union_of_alias_recursive<'a>(
alias: &mut Alias, alias: &mut Alias,
others: Vec<Symbol>, others: Vec<Symbol>,
var_store: &mut VarStore, var_store: &mut VarStore,
can_report_error: &mut bool, can_report_cyclic_error: &mut bool,
) -> Result<(), ()> { ) -> Result<(), ()> {
let alias_args = alias let alias_args = alias
.type_variables .type_variables
@ -2070,7 +2070,7 @@ fn make_tag_union_of_alias_recursive<'a>(
others, others,
&mut alias.typ, &mut alias.typ,
var_store, var_store,
can_report_error, can_report_cyclic_error,
); );
match made_recursive { match made_recursive {
@ -2119,22 +2119,25 @@ fn make_tag_union_recursive_help<'a>(
others: Vec<Symbol>, others: Vec<Symbol>,
typ: &mut Type, typ: &mut Type,
var_store: &mut VarStore, var_store: &mut VarStore,
can_report_error: &mut bool, can_report_cyclic_error: &mut bool,
) -> MakeTagUnionRecursive { ) -> MakeTagUnionRecursive {
use MakeTagUnionRecursive::*; use MakeTagUnionRecursive::*;
let Loc { let (symbol, args) = recursive_alias.value;
value: (symbol, args), let alias_region = recursive_alias.region;
region: alias_region,
} = recursive_alias;
let vars = args.iter().map(|(_, t)| t.clone()).collect::<Vec<_>>();
match typ { match typ {
Type::TagUnion(tags, ext) => { Type::TagUnion(tags, ext) => {
let recursion_variable = var_store.fresh(); let recursion_variable = var_store.fresh();
let type_arguments = args.iter().map(|(_, t)| t.clone()).collect::<Vec<_>>();
let mut pending_typ = let mut pending_typ =
Type::RecursiveTagUnion(recursion_variable, tags.to_vec(), ext.clone()); Type::RecursiveTagUnion(recursion_variable, tags.to_vec(), ext.clone());
let substitution_result = let substitution_result = pending_typ.substitute_alias(
pending_typ.substitute_alias(symbol, &vars, &Type::Variable(recursion_variable)); symbol,
&type_arguments,
&Type::Variable(recursion_variable),
);
match substitution_result { match substitution_result {
Ok(()) => { Ok(()) => {
// We can substitute the alias presence for the variable exactly. // We can substitute the alias presence for the variable exactly.
@ -2160,18 +2163,22 @@ fn make_tag_union_recursive_help<'a>(
actual, actual,
type_arguments, type_arguments,
.. ..
} => make_tag_union_recursive_help( } => {
// try to make `actual` recursive
make_tag_union_recursive_help(
env, env,
Loc::at_zero((symbol, type_arguments)), Loc::at_zero((symbol, type_arguments)),
region, region,
others, others,
actual, actual,
var_store, var_store,
can_report_error, can_report_cyclic_error,
), )
}
_ => { _ => {
mark_cyclic_alias(env, typ, symbol, region, others, *can_report_error); // take care to report a cyclic alias only once (not once for each alias in the cycle)
*can_report_error = false; mark_cyclic_alias(env, typ, symbol, region, others, *can_report_cyclic_error);
*can_report_cyclic_error = false;
Cyclic Cyclic
} }