Eliminate voided branches only after resolving their bodies' specializations

This commit is contained in:
Ayaz Hafiz 2022-09-20 08:34:42 -05:00
parent 884843205d
commit 2f7020aa31
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 93 additions and 7 deletions

View file

@ -1962,3 +1962,41 @@ fn unreachable_void_constructor() {
"#
)
}
#[mono_test]
fn unreachable_branch_is_eliminated_but_produces_lambda_specializations() {
indoc!(
r#"
app "test" provides [main] to "./platform"
provideThunk = \x ->
when x is
Ok _ ->
t1 = \{} -> "t1"
t1
# During specialization of `main` we specialize this function,
# which leads to elimination of this branch, because it is unreachable
# (it can only match the uninhabited type `Err []`).
#
# However, naive elimination of this branch would mean we don't traverse
# the branch body. If we don't do so, we will fail to see and specialize `t2`,
# which is problematic - while `t2` won't ever be reached in this specialization,
# it is still part of the lambda set, and `thunk {}` (in main) will match over
# it before calling.
#
# So, this test verifies that we eliminate this branch, but still specialize
# everything we need.
Err _ ->
t2 = \{} -> "t2"
t2
main =
x : Result Str []
x = Ok "abc"
thunk = provideThunk x
thunk {}
"#
)
}