[commit: ghc] ghc-8.6: Fix #10859 by using foldr1 while deriving Eq instances (bc90726)

git at git.haskell.org git at git.haskell.org
Sun Sep 16 17:10:26 UTC 2018


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

On branch  : ghc-8.6
Link       : http://ghc.haskell.org/trac/ghc/changeset/bc907262b40d09b479d100875b26f1add352523a/ghc

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

commit bc907262b40d09b479d100875b26f1add352523a
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
    
    (cherry picked from commit 2d953a60489ba30433e5f2fe27c50aa9da75f802)


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

bc907262b40d09b479d100875b26f1add352523a
 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 beaad98..bb7cd9a 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