[commit: ghc] master: Fix #10859 by using foldr1 while deriving Eq instances (2d953a6)

git at git.haskell.org git at git.haskell.org
Mon Aug 27 13:39:49 UTC 2018


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/2d953a60489ba30433e5f2fe27c50aa9da75f802/ghc

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

commit 2d953a60489ba30433e5f2fe27c50aa9da75f802
Author: Chaitanya Koparkar <ckoparkar at gmail.com>
Date:   Mon Aug 27 14:07:08 2018 +0200

    Fix #10859 by using foldr1 while deriving Eq instances
    
    Summary:
    Previously, we were using foldl1 instead, which led to the derived
    code to be wrongly associated.
    
    Test Plan: ./validate
    
    Reviewers: RyanGlScott, nomeata, simonpj, bgamari
    
    Reviewed By: RyanGlScott, nomeata
    
    Subscribers: rwbarton, carter
    
    GHC Trac Issues: #10859
    
    Differential Revision: https://phabricator.haskell.org/D5104


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

2d953a60489ba30433e5f2fe27c50aa9da75f802
 compiler/typecheck/TcGenDeriv.hs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/compiler/typecheck/TcGenDeriv.hs b/compiler/typecheck/TcGenDeriv.hs
index e74ae32..1debddd 100644
--- a/compiler/typecheck/TcGenDeriv.hs
+++ b/compiler/typecheck/TcGenDeriv.hs
@@ -214,7 +214,9 @@ gen_Eq_binds loc tycon = do
       where
         nested_eq_expr []  [] [] = true_Expr
         nested_eq_expr tys as bs
-          = foldl1 and_Expr (zipWith3Equal "nested_eq" nested_eq tys as bs)
+          = foldr1 and_Expr (zipWith3Equal "nested_eq" nested_eq tys as bs)
+          -- Using 'foldr1' here ensures that the derived code is correctly
+          -- associated. See Trac #10859.
           where
             nested_eq ty a b = nlHsPar (eq_Expr tycon ty (nlHsVar a) (nlHsVar b))
 



More information about the ghc-commits mailing list