Merge pull request #5363 from roc-lang/i5344

Correctly include flex vars in generalization group of rec defs
This commit is contained in:
Ayaz 2023-05-02 16:44:29 -05:00 committed by GitHub
commit 4824de5192
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 1 deletions

View File

@ -3594,7 +3594,7 @@ fn constraint_recursive_function(
let expr_con = attach_resolution_constraints(constraints, env, expr_con);
let def_con = expr_con;
flex_info.vars = vec![expr_var];
flex_info.vars.push(expr_var);
flex_info.constraints.push(def_con);
flex_info.def_types.insert(
loc_symbol.value,

View File

@ -258,6 +258,7 @@ pub struct InferOptions {
pub print_can_decls: bool,
pub print_only_under_alias: bool,
pub print_ranks: bool,
pub print_variables: bool,
pub no_promote: bool,
}
@ -467,6 +468,7 @@ impl<'a> QueryCtx<'a> {
print_lambda_sets: true,
print_only_under_alias: self.options.print_only_under_alias,
print_ranks: self.options.print_ranks,
print_variables: self.options.print_variables,
ignore_polarity: true,
print_weakened_vars: true,
},

View File

@ -62,6 +62,7 @@ pub struct DebugPrint {
pub print_ranks: bool,
pub ignore_polarity: bool,
pub print_weakened_vars: bool,
pub print_variables: bool,
}
impl DebugPrint {
@ -71,6 +72,7 @@ impl DebugPrint {
print_ranks: false,
ignore_polarity: false,
print_weakened_vars: false,
print_variables: false,
};
}
@ -658,6 +660,12 @@ fn write_content<'a>(
if env.debug.print_ranks {
buf.push_str(&format!("⟨@{:?}", subs.get_rank(var).into_usize()));
}
if env.debug.print_variables {
buf.push_str(&format!(
"<{:?}>",
subs.get_root_key_without_compacting(var)
));
}
match subs.get_content_without_compacting(var) {
FlexVar(Some(name_index)) => {

View File

@ -257,6 +257,7 @@ impl<'a> TestCase<'a> {
"allow_errors" => infer_opts.allow_errors = true,
"print_only_under_alias" => infer_opts.print_only_under_alias = true,
"print_ranks" => infer_opts.print_ranks = true,
"print_variables" => infer_opts.print_variables = true,
other => return Err(format!("unknown infer option: {other:?}").into()),
}
}

View File

@ -0,0 +1,24 @@
# +opt infer:print_variables
app "test" provides [main] to "./platform"
f = \{} ->
#^{-1} <1527><116>{} -<119>[[f(1)]]-> <115>[Ok <1535>{}]<79>*
when g {} is
# ^ <1517><1535>{} -<1525>[[g(2)]]-> <71>[Ok <1535>{}]<101>*
_ -> Ok {}
g = \{} ->
#^{-1} <1517><1535>{} -<1525>[[g(2)]]-> <71>[Ok <1535>{}]<101>*
when h {} is
# ^ <1522><1535>{} -<1530>[[h(3)]]-> <93>[Ok <1535>{}]<123>*
_ -> Ok {}
h = \{} ->
#^{-1} <1522><1535>{} -<1530>[[h(3)]]-> <93>[Ok <1535>{}]<123>*
when f {} is
# ^ <1527><116>{} -<119>[[f(1)]]-> <115>[Ok <1535>{}]<79>*
_ -> Ok {}
main = f {}
# ^ <1537><132>{} -<135>[[f(1)]]-> <137>[Ok <1535>{}]<1536>w_a