Deduplicate capture niches

This commit is contained in:
ayazhafiz 2022-07-02 19:04:23 -04:00
parent 91050d9989
commit 3385c708c6
No known key found for this signature in database
GPG key ID: B443F7A3030C9AED
2 changed files with 29 additions and 0 deletions

View file

@ -1009,6 +1009,11 @@ impl<'a> LambdaSet<'a> {
joined.sort_by(|(lam_and_captures1, _), (lam_and_captures2, _)| {
lam_and_captures1.cmp(lam_and_captures2)
});
// Remove duplicate lambda captures layouts unification can't see as
// duplicates, for example [[Thunk {a: Str}, Thunk [A Str]]], each of which are
// newtypes over the lambda layout `Thunk Str`.
joined.dedup_by_key(|((name, captures), _)| (*name, *captures));
let (set, set_with_variables): (std::vec::Vec<_>, std::vec::Vec<_>) =
joined.into_iter().unzip();

View file

@ -1628,3 +1628,27 @@ fn lambda_capture_niches_have_captured_function_in_closure() {
"#
)
}
#[mono_test]
fn lambda_set_niche_same_layout_different_constructor() {
indoc!(
r#"
capture : a -> ({} -> Str)
capture = \val ->
thunk =
\{} ->
when val is
_ -> ""
thunk
x : [True, False]
x = True
fun =
when x is
True -> capture {a: ""}
False -> capture (A "")
fun
"#
)
}