summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
Diffstat (limited to 'compiler')
-rw-r--r--compiler/simplCore/SimplUtils.hs6
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/simplCore/SimplUtils.hs b/compiler/simplCore/SimplUtils.hs
index 47c5be6d8e..3b48924ed1 100644
--- a/compiler/simplCore/SimplUtils.hs
+++ b/compiler/simplCore/SimplUtils.hs
@@ -64,6 +64,7 @@ import PrelRules
import Literal
import Control.Monad ( when )
+import Data.List ( sortBy )
{-
************************************************************************
@@ -1926,7 +1927,7 @@ mkCase1 dflags scrut bndr alts_ty alts = mkCase2 dflags scrut bndr alts_ty alts
mkCase2 dflags scrut bndr alts_ty alts
| gopt Opt_CaseFolding dflags
, Just (scrut',f) <- caseRules dflags scrut
- = mkCase3 dflags scrut' bndr alts_ty (map (mapAlt f) alts)
+ = mkCase3 dflags scrut' bndr alts_ty (new_alts f)
| otherwise
= mkCase3 dflags scrut bndr alts_ty alts
where
@@ -1946,6 +1947,9 @@ mkCase2 dflags scrut bndr alts_ty alts
| isDeadBinder bndr = rhs
| otherwise = Let (NonRec bndr l) rhs
+ -- We need to re-sort the alternatives to preserve the #case_invariants#
+ new_alts f = sortBy cmpAlt (map (mapAlt f) alts)
+
mapAlt f alt@(c,bs,e) = case c of
DEFAULT -> (c, bs, wrap_rhs scrut e)
LitAlt l