Unify erased lambda sets

This commit is contained in:
Ayaz Hafiz 2023-06-22 20:40:53 -05:00
parent 1d6f0d3d3f
commit 15ae7489a8
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58

View file

@ -1862,6 +1862,28 @@ fn unify_unspecialized_lambdas<M: MetaCollector>(
))
}
fn is_erased_lambda(subs: &Subs, lambda_set: UnionLambdas) -> bool {
let labels = lambda_set.labels();
if labels.start == Subs::LAMBDA_NAME_ERASED.start
&& labels.len() == Subs::LAMBDA_NAME_ERASED.len()
{
return true;
}
#[cfg(debug_assertions)]
{
let content_has_erased = lambda_set
.iter_all()
.any(|(lambda, _)| subs[lambda] == Symbol::ERASED_LAMBDA);
assert!(
!content_has_erased,
"lambda set contains erased lambda, but it is not marked as erased!"
);
}
false
}
#[must_use]
fn unify_lambda_set_help<M: MetaCollector>(
env: &mut Env,
@ -1898,6 +1920,20 @@ fn unify_lambda_set_help<M: MetaCollector>(
"Recursion var is present, but it doesn't have a recursive content!"
);
// Fast path: if either set is the erased lambda, they are both erased.
if is_erased_lambda(env.subs, solved1) || is_erased_lambda(env.subs, solved2) {
return merge(
env,
ctx,
Content::LambdaSet(LambdaSet {
solved: UnionLabels::from_slices(Subs::LAMBDA_NAME_ERASED, SubsSlice::empty()),
recursion_var: OptVariable::NONE,
unspecialized: SubsSlice::empty(),
ambient_function: ambient_function_var,
}),
);
}
let (
mut whole_outcome,
SeparatedUnionLambdas {