[commit: ghc] master: Adjust AltCon Ord instance to match Core linter requirements. (e14945c)

git at git.haskell.org git at git.haskell.org
Wed Nov 15 20:06:07 UTC 2017


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

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

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

commit e14945ce046a000f1542818cd5cb6007cf2e2422
Author: klebinger.andreas at gmx.at <klebinger.andreas at gmx.at>
Date:   Wed Nov 15 11:42:48 2017 -0500

    Adjust AltCon Ord instance to match Core linter requirements.
    
    When sorting by the Ord instance put DEFAULT before other constructors.
    
    This is in line with what the core linter requests allowing the use of
    the instance for putting alternatives in the correct order.
    This implements #14464.
    
    Reviewers: bgamari, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: simonpj, rwbarton, thomie
    
    GHC Trac Issues: #14464
    
    Differential Revision: https://phabricator.haskell.org/D4198


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

e14945ce046a000f1542818cd5cb6007cf2e2422
 compiler/coreSyn/CoreSyn.hs | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/compiler/coreSyn/CoreSyn.hs b/compiler/coreSyn/CoreSyn.hs
index c931bf1..1462aef 100644
--- a/compiler/coreSyn/CoreSyn.hs
+++ b/compiler/coreSyn/CoreSyn.hs
@@ -313,16 +313,17 @@ data AltCon
 -- This instance is a bit shady. It can only be used to compare AltCons for
 -- a single type constructor. Fortunately, it seems quite unlikely that we'll
 -- ever need to compare AltCons for different type constructors.
+-- The instance adheres to the order described in [CoreSyn case invariants]
 instance Ord AltCon where
   compare (DataAlt con1) (DataAlt con2) =
     ASSERT( dataConTyCon con1 == dataConTyCon con2 )
     compare (dataConTag con1) (dataConTag con2)
-  compare (DataAlt _) _ = LT
-  compare _ (DataAlt _) = GT
+  compare (DataAlt _) _ = GT
+  compare _ (DataAlt _) = LT
   compare (LitAlt l1) (LitAlt l2) = compare l1 l2
-  compare (LitAlt _) DEFAULT = LT
+  compare (LitAlt _) DEFAULT = GT
   compare DEFAULT DEFAULT = EQ
-  compare DEFAULT _ = GT
+  compare DEFAULT _ = LT
 
 -- | Binding, used for top level bindings in a module and local bindings in a @let at .
 



More information about the ghc-commits mailing list