From 248696f06b21dc7bafaaa6ff784303d189149783 Mon Sep 17 00:00:00 2001 From: Changlin Li Date: Wed, 17 Jul 2024 14:51:56 -0700 Subject: [PATCH] Minimal fix for issue #2241 This fixes https://github.com/elm/compiler/issues/2241 Preliminary testing seems to indicate this isn't as bad of a slowdown as it may seem. For more details see https://github.com/Zokka-Dev/zokka-compiler/pull/20 This is meant as a reference PR for other people working on the Elm compiler. --- compiler/src/Type/Unify.hs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/compiler/src/Type/Unify.hs b/compiler/src/Type/Unify.hs index 837d930e0..2a56a9e34 100644 --- a/compiler/src/Type/Unify.hs +++ b/compiler/src/Type/Unify.hs @@ -166,15 +166,20 @@ fresh (Context _ (Descriptor _ rank1 _ _) _ (Descriptor _ rank2 _ _)) content = guardedUnify :: Variable -> Variable -> Unify () guardedUnify left right = Unify $ \vars ok err -> - do equivalent <- UF.equivalent left right - if equivalent - then ok vars () + do occursLeft <- Occurs.occurs left + occursRight <- Occurs.occurs right + if occursLeft || occursRight + then err vars () else - do leftDesc <- UF.get left - rightDesc <- UF.get right - case actuallyUnify (Context left leftDesc right rightDesc) of - Unify k -> - k vars ok err + equivalent <- UF.equivalent left right + if equivalent + then ok vars () + else + do leftDesc <- UF.get left + rightDesc <- UF.get right + case actuallyUnify (Context left leftDesc right rightDesc) of + Unify k -> + k vars ok err subUnify :: Variable -> Variable -> Unify ()