[commit: ghc] wip/T10858: Export thenComp in GHC.Base as a monomorphic function (98d1fd0)

git at git.haskell.org git at git.haskell.org
Tue Sep 8 21:35:56 UTC 2015


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

On branch  : wip/T10858
Link       : http://ghc.haskell.org/trac/ghc/changeset/98d1fd01b43071b474faf3d6b0be455efde9b6a8/ghc

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

commit 98d1fd01b43071b474faf3d6b0be455efde9b6a8
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Tue Sep 8 23:36:42 2015 +0200

    Export thenComp in GHC.Base as a monomorphic function
    
    to avoid generating calls to the overloaded (<>) in generated Ord
    instances.


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

98d1fd01b43071b474faf3d6b0be455efde9b6a8
 compiler/prelude/PrelNames.hs    |  4 ++--
 compiler/typecheck/TcGenDeriv.hs |  2 +-
 libraries/base/GHC/Base.hs       | 12 ++++++++----
 3 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/compiler/prelude/PrelNames.hs b/compiler/prelude/PrelNames.hs
index f4a0529..597ef17 100644
--- a/compiler/prelude/PrelNames.hs
+++ b/compiler/prelude/PrelNames.hs
@@ -725,7 +725,7 @@ notAssocDataCon_RDR   = dataQual_RDR gHC_GENERICS (fsLit "NotAssociative")
 
 
 fmap_RDR, pure_RDR, ap_RDR, foldable_foldr_RDR, foldMap_RDR,
-    traverse_RDR, mempty_RDR, mappend_RDR, mappend_diamond_RDR :: RdrName
+    traverse_RDR, mempty_RDR, mappend_RDR, thenCmp_RDR :: RdrName
 fmap_RDR                = varQual_RDR gHC_BASE (fsLit "fmap")
 pure_RDR                = nameRdrName pureAName
 ap_RDR                  = nameRdrName apAName
@@ -734,7 +734,7 @@ foldMap_RDR             = varQual_RDR dATA_FOLDABLE       (fsLit "foldMap")
 traverse_RDR            = varQual_RDR dATA_TRAVERSABLE    (fsLit "traverse")
 mempty_RDR              = varQual_RDR gHC_BASE            (fsLit "mempty")
 mappend_RDR             = varQual_RDR gHC_BASE            (fsLit "mappend")
-mappend_diamond_RDR     = varQual_RDR dATA_MONOID         (fsLit "<>")
+thenCmp_RDR             = varQual_RDR gHC_BASE            (fsLit "thenCmp")
 
 ----------------------
 varQual_RDR, tcQual_RDR, clsQual_RDR, dataQual_RDR
diff --git a/compiler/typecheck/TcGenDeriv.hs b/compiler/typecheck/TcGenDeriv.hs
index e281a00..5e694a9 100644
--- a/compiler/typecheck/TcGenDeriv.hs
+++ b/compiler/typecheck/TcGenDeriv.hs
@@ -375,7 +375,7 @@ gtResult OrdGT      = true_Expr
 combineResult :: OrdOp -> RdrName
 -- Knowing a1 ? b2 and a2 ? b2?,
 -- how do we combine that to obtain (a1,a2) ? (b1,b2)
-combineResult OrdCompare = mappend_diamond_RDR
+combineResult OrdCompare = thenCmp_RDR
 combineResult OrdLT      = or_RDR
 combineResult OrdLE      = and_RDR
 combineResult OrdGE      = and_RDR
diff --git a/libraries/base/GHC/Base.hs b/libraries/base/GHC/Base.hs
index 9bd6124..5d48d52 100644
--- a/libraries/base/GHC/Base.hs
+++ b/libraries/base/GHC/Base.hs
@@ -287,10 +287,14 @@ instance (Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) =>
 
 -- lexicographical ordering
 instance Monoid Ordering where
-        mempty         = EQ
-        LT `mappend` _ = LT
-        EQ `mappend` y = y
-        GT `mappend` _ = GT
+        mempty  = EQ
+        mappend = thenCmp
+
+-- The monomorphic version is used by the autogenerated Ord instances
+thenCmp :: Ordering -> Ordering -> Ordering
+LT `thenCmp` _ = LT
+EQ `thenCmp` y = y
+GT `thenCmp` _ = GT
 
 -- | Lift a semigroup into 'Maybe' forming a 'Monoid' according to
 -- <http://en.wikipedia.org/wiki/Monoid>: \"Any semigroup @S@ may be



More information about the ghc-commits mailing list