[commit: ghc] ghc-7.8: Fix Trac #9371. (683d13a)

git at git.haskell.org git at git.haskell.org
Mon Dec 15 15:03:54 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.8
Link       : http://ghc.haskell.org/trac/ghc/changeset/683d13aa16d4bb6b3ad758998b7f5b0dece1dee7/ghc

>---------------------------------------------------------------

commit 683d13aa16d4bb6b3ad758998b7f5b0dece1dee7
Author: Richard Eisenberg <eir at cis.upenn.edu>
Date:   Sun Aug 3 18:40:30 2014 -0400

    Fix Trac #9371.
    
    This was very simple: lists of different lengths are
    *maybe* apart, not *surely* apart.
    
    (cherry picked from commit f29bdfbcedda6cb33ab05d884c151f2b31f4e4e0)


>---------------------------------------------------------------

683d13aa16d4bb6b3ad758998b7f5b0dece1dee7
 compiler/types/Unify.lhs | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/compiler/types/Unify.lhs b/compiler/types/Unify.lhs
index f2b45e8..2acbb24 100644
--- a/compiler/types/Unify.lhs
+++ b/compiler/types/Unify.lhs
@@ -415,6 +415,26 @@ substituted, we can't properly unify the types. But, that skolem variable
 may later be instantiated with a unifyable type. So, we return maybeApart
 in these cases.
 
+Note [Lists of different lengths are MaybeApart]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+It is unusual to call tcUnifyTys or tcUnifyTysFG with lists of different
+lengths. The place where we know this can happen is from compatibleBranches in
+FamInstEnv, when checking data family instances. Data family instances may be
+eta-reduced; see Note [Eta reduction for data family axioms] in TcInstDcls.
+
+We wish to say that
+
+  D :: * -> * -> *
+  axDF1 :: D Int ~ DFInst1
+  axDF2 :: D Int Bool ~ DFInst2
+
+overlap. If we conclude that lists of different lengths are SurelyApart, then
+it will look like these do *not* overlap, causing disaster. See Trac #9371.
+
+In usages of tcUnifyTys outside of family instances, we always use tcUnifyTys,
+which can't tell the difference between MaybeApart and SurelyApart, so those
+usages won't notice this design choice.
+
 \begin{code}
 tcUnifyTy :: Type -> Type       -- All tyvars are bindable
 	  -> Maybe TvSubst	-- A regular one-shot (idempotent) substitution
@@ -590,7 +610,7 @@ unifyList subst orig_xs orig_ys
     go subst []     []     = return subst
     go subst (x:xs) (y:ys) = do { subst' <- unify subst x y
 				; go subst' xs ys }
-    go _ _ _ = surelyApart
+    go subst _ _ = maybeApart subst  -- See Note [Lists of different lengths are MaybeApart]
 
 ---------------------------------
 uVar :: TvSubstEnv	-- An existing substitution to extend



More information about the ghc-commits mailing list