Merge pull request #4556 from roc-lang/fix-fixpoint-fixing

Correct when fixpoint-fixed type variables can be reunified
This commit is contained in:
Ayaz 2022-11-21 17:44:06 -06:00 committed by GitHub
commit ef5d83a42d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 80 additions and 2 deletions

View file

@ -8283,4 +8283,41 @@ mod solve_expr {
"MDict v -> MDict v | v has Eq", "MDict v -> MDict v | v has Eq",
); );
} }
#[test]
fn unify_types_with_fixed_fixpoints_outside_fixing_region() {
infer_queries!(indoc!(
r#"
app "test" provides [main] to "./platform"
Input := [
FromJob Job
]
Job := [
Job (List Input)
]
job : List Input -> Job
job = \inputs ->
@Job (Job inputs)
helloWorld : Job
helloWorld =
@Job ( Job [ @Input (FromJob greeting) ] )
# ^^^^^^^^^^^^^^^^^^^^^^^^^
greeting : Job
greeting =
job []
main = (\_ -> "Which platform am I running on now?\n") helloWorld
"#
),
@r###"
@Input (FromJob greeting) : [FromJob ([Job (List [FromJob a])] as a)]
"###
print_only_under_alias: true
)
}
} }

View file

@ -2047,3 +2047,39 @@ fn issue_4077_fixed_fixpoint() {
RocStr RocStr
); );
} }
#[test]
#[cfg(any(feature = "gen-llvm", feature = "gen-wasm"))]
fn unify_types_with_fixed_fixpoints_outside_fixing_region() {
assert_evals_to!(
indoc!(
r#"
app "test" provides [main] to "./platform"
Input := [
FromJob Job (List Str),
]
Job := [
Job (List Input)
]
job : List Input -> Job
job = \inputs ->
@Job (Job inputs)
helloWorld : Job
helloWorld =
@Job ( Job [ @Input (FromJob greeting []) ] )
greeting : Job
greeting =
job []
main = (\_ -> "OKAY") helloWorld
"#
),
RocStr::from("OKAY"),
RocStr
);
}

View file

@ -2814,8 +2814,13 @@ fn unify_shared_tags_merge_new<M: MetaCollector>(
new_ext_var: Variable, new_ext_var: Variable,
recursion_var: Rec, recursion_var: Rec,
) -> Outcome<M> { ) -> Outcome<M> {
let was_fixed = env.was_fixed(ctx.first) || env.was_fixed(ctx.second); if env.was_fixed(ctx.first) && env.was_fixed(ctx.second) {
if was_fixed { // Both of the tags we're looking at were just involved in fixpoint-fixing, so their types
// should be aligned. As such, do not attempt to unify them and update the recursion
// pointer again.
debug_assert!(env
.subs
.equivalent_without_compacting(ctx.first, ctx.second));
return Default::default(); return Default::default();
} }