summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-10-23 18:16:29 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-10-31 02:54:34 -0400
commit730ef38f467d67f4f664b2b4a5f4b236864e97b2 (patch)
tree6b032c725d5d1dd1998e39829a799c3d68ff7645
parenta98593f0c7623843a787af5fb628336cb897c527 (diff)
downloadhaskell-730ef38f467d67f4f664b2b4a5f4b236864e97b2.tar.gz
Simplify constant-folding (#18032)
See #18032 for the details. * Use `Lit (LitNumber _ i)` instead of `isLitValue_maybe` which does more work but that is not needed for constant-folding * Don't export `GHC.Types.Literal.isLitValue_maybe` * Kill `GHC.Types.Literal.isLitValue` which isn't used
-rw-r--r--compiler/GHC/Core/Opt/ConstantFold.hs6
-rw-r--r--compiler/GHC/Types/Literal.hs8
2 files changed, 4 insertions, 10 deletions
diff --git a/compiler/GHC/Core/Opt/ConstantFold.hs b/compiler/GHC/Core/Opt/ConstantFold.hs
index b8c2c5d6fa..cb3b0a2a05 100644
--- a/compiler/GHC/Core/Opt/ConstantFold.hs
+++ b/compiler/GHC/Core/Opt/ConstantFold.hs
@@ -2198,7 +2198,7 @@ pattern OpVal op <- Var (isPrimOpId_maybe -> Just op) where
-- | Match a literal
pattern L :: Integer -> Arg CoreBndr
-pattern L l <- Lit (isLitValue_maybe -> Just l)
+pattern L i <- Lit (LitNumber _ i)
-- | Explicit "type-class"-like dictionary for numeric primops
data NumOps = NumOps
@@ -2256,14 +2256,14 @@ caseRules :: Platform
caseRules platform (App (App (Var f) v) (Lit l)) -- v `op` x#
| Just op <- isPrimOpId_maybe f
- , Just x <- isLitValue_maybe l
+ , LitNumber _ x <- l
, Just adjust_lit <- adjustDyadicRight op x
= Just (v, tx_lit_con platform adjust_lit
, \v -> (App (App (Var f) (Var v)) (Lit l)))
caseRules platform (App (App (Var f) (Lit l)) v) -- x# `op` v
| Just op <- isPrimOpId_maybe f
- , Just x <- isLitValue_maybe l
+ , LitNumber _ x <- l
, Just adjust_lit <- adjustDyadicLeft x op
= Just (v, tx_lit_con platform adjust_lit
, \v -> (App (App (Var f) (Lit l)) (Var v)))
diff --git a/compiler/GHC/Types/Literal.hs b/compiler/GHC/Types/Literal.hs
index b208a45751..6fea5e2fdb 100644
--- a/compiler/GHC/Types/Literal.hs
+++ b/compiler/GHC/Types/Literal.hs
@@ -36,7 +36,7 @@ module GHC.Types.Literal
, inCharRange
, isZeroLit
, litFitsInChar
- , litValue, isLitValue, isLitValue_maybe, mapLitValue
+ , litValue, mapLitValue
-- ** Coercions
, wordToIntLit, intToWordLit
@@ -71,7 +71,6 @@ import Data.ByteString (ByteString)
import Data.Int
import Data.Word
import Data.Char
-import Data.Maybe ( isJust )
import Data.Data ( Data )
import Data.Proxy
import Numeric ( fromRat )
@@ -462,11 +461,6 @@ mapLitValue _ f (LitChar c) = mkLitChar (fchar c)
mapLitValue platform f (LitNumber nt i) = wrapLitNumber platform (LitNumber nt (f i))
mapLitValue _ _ l = pprPanic "mapLitValue" (ppr l)
--- | Indicate if the `Literal` contains an 'Integer' value, e.g. 'Char',
--- 'Int', 'Word', 'LitInteger' and 'LitNatural'.
-isLitValue :: Literal -> Bool
-isLitValue = isJust . isLitValue_maybe
-
{-
Coercions
~~~~~~~~~