From ca87faa906b60e2d5ed896fa624cb0266d6d051c Mon Sep 17 00:00:00 2001 From: Ayaz Hafiz Date: Mon, 27 Jun 2022 13:07:22 -0400 Subject: [PATCH] Allow union lambdas to have duplicates --- crates/compiler/types/src/subs.rs | 7 +++++-- crates/compiler/unify/src/unify.rs | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/compiler/types/src/subs.rs b/crates/compiler/types/src/subs.rs index eb3e9f4a98..a4b99eba78 100644 --- a/crates/compiler/types/src/subs.rs +++ b/crates/compiler/types/src/subs.rs @@ -2650,11 +2650,14 @@ impl UnionLabels where L: Label + Ord, { - pub fn is_sorted_no_duplicates(&self, subs: &Subs) -> bool { + /// Checks if the union of labels is sorted by label. + /// Duplicates *are* admitted, since this represents a lambda set, in which we may have + /// duplicate lambda captures, if those lambda captures have different representations! + pub fn is_sorted(&self, subs: &Subs) -> bool { let mut iter = self.iter_from_subs(subs).peekable(); while let Some((before, _)) = iter.next() { if let Some((after, _)) = iter.peek() { - if before >= after { + if before > after { return false; } } diff --git a/crates/compiler/unify/src/unify.rs b/crates/compiler/unify/src/unify.rs index 3929829561..fb525f2c8e 100644 --- a/crates/compiler/unify/src/unify.rs +++ b/crates/compiler/unify/src/unify.rs @@ -1506,8 +1506,8 @@ fn separate_union_lambdas( fields1: UnionLambdas, fields2: UnionLambdas, ) -> Separate { - debug_assert!(fields1.is_sorted_no_duplicates(subs)); - debug_assert!(fields2.is_sorted_no_duplicates(subs)); + debug_assert!(fields1.is_sorted(subs)); + debug_assert!(fields2.is_sorted(subs)); let it1 = fields1.iter_all().map(|(s, vars)| (subs[s], subs[vars])); let it2 = fields2.iter_all().map(|(s, vars)| (subs[s], subs[vars]));