[commit: ghc] master: Use (&&) instead of `if` in Ix derivation (5cce095)

git at git.haskell.org git at git.haskell.org
Wed Jan 20 16:07:16 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/5cce09543db827e662539523ffff4513deb92777/ghc

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

commit 5cce09543db827e662539523ffff4513deb92777
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Tue Jan 19 16:30:26 2016 +0100

    Use (&&) instead of `if` in Ix derivation
    
    We were previously using `if` in the derivation of `Ix` instances. This
    interacts badly with RebindableSyntax as the typechecker doesn't infer
    the type of the argument we give to `tagToEnum#`.
    
    Previously we produced, `if (ch >= ah) then (ch <= bh) else False`.
    
    We now produce `(ch >= ah) && (ch <= bh)`
    
    Fixes #11396.
    
    Test Plan: Validate
    
    Reviewers: austin, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1797
    
    GHC Trac Issues: #11396


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

5cce09543db827e662539523ffff4513deb92777
 compiler/typecheck/TcGenDeriv.hs                  | 13 ++++++++-----
 testsuite/tests/deriving/should_compile/T11396.hs | 11 +++++++++++
 testsuite/tests/deriving/should_compile/all.T     |  1 +
 3 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/compiler/typecheck/TcGenDeriv.hs b/compiler/typecheck/TcGenDeriv.hs
index c4279a7..218c0a4 100644
--- a/compiler/typecheck/TcGenDeriv.hs
+++ b/compiler/typecheck/TcGenDeriv.hs
@@ -783,16 +783,19 @@ gen_Ix_binds loc tycon
            ))
         )
 
+    -- This produces something like `(ch >= ah) && (ch <= bh)`
     enum_inRange
       = mk_easy_FunBind loc inRange_RDR [nlTuplePat [a_Pat, b_Pat] Boxed, c_Pat] $
           untag_Expr tycon [(a_RDR, ah_RDR)] (
           untag_Expr tycon [(b_RDR, bh_RDR)] (
           untag_Expr tycon [(c_RDR, ch_RDR)] (
-          nlHsIf (genPrimOpApp (nlHsVar ch_RDR) geInt_RDR (nlHsVar ah_RDR)) (
-             (genPrimOpApp (nlHsVar ch_RDR) leInt_RDR (nlHsVar bh_RDR))
-          ) {-else-} (
-             false_Expr
-          ))))
+          -- This used to use `if`, which interacts badly with RebindableSyntax.
+          -- See #11396.
+          nlHsApps and_RDR
+              [ genPrimOpApp (nlHsVar ch_RDR) geInt_RDR (nlHsVar ah_RDR)
+              , genPrimOpApp (nlHsVar ch_RDR) leInt_RDR (nlHsVar bh_RDR)
+              ]
+          )))
 
     --------------------------------------------------------------
     single_con_ixes
diff --git a/testsuite/tests/deriving/should_compile/T11396.hs b/testsuite/tests/deriving/should_compile/T11396.hs
new file mode 100644
index 0000000..ecb930c
--- /dev/null
+++ b/testsuite/tests/deriving/should_compile/T11396.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE RebindableSyntax #-}
+module IfThenElseIx where
+
+import Data.Ix (Ix, )
+import Prelude
+
+ifThenElse :: Bool -> a -> a -> a
+ifThenElse True x _ = x
+ifThenElse False _ x = x
+
+data T = A | B deriving (Eq, Ord, Ix)
diff --git a/testsuite/tests/deriving/should_compile/all.T b/testsuite/tests/deriving/should_compile/all.T
index a18a257..4589a86 100644
--- a/testsuite/tests/deriving/should_compile/all.T
+++ b/testsuite/tests/deriving/should_compile/all.T
@@ -62,3 +62,4 @@ test('T11148', normal, run_command,
      ['$MAKE -s --no-print-directory T11148'])
 test('T9968', normal, compile, [''])
 test('T11416', normal, compile, [''])
+test('T11396', normal, compile, [''])



More information about the ghc-commits mailing list