#include "HsVersions.h"
import CoreSyn
-import Id ( mkWildId, isPrimOpId_maybe, idUnfolding )
+import Id ( mkWildId, idUnfolding )
import Literal ( Literal(..), mkMachInt, mkMachWord
, literalType
, word2IntLit, int2WordLit
, float2IntLit, int2FloatLit, double2IntLit, int2DoubleLit
, float2DoubleLit, double2FloatLit
)
-import PrimOp ( PrimOp(..), primOpOcc )
+import PrimOp ( PrimOp(..), primOpOcc, tagToEnumKey )
import TysWiredIn ( boolTy, trueDataConId, falseDataConId )
import TyCon ( tyConDataCons_maybe, isEnumerationTyCon, isNewTyCon )
import DataCon ( dataConTag, dataConTyCon, dataConWorkId, fIRST_TAG )
import FastString
import StaticFlags ( opt_SimplExcessPrecision )
-import DATA_BITS ( Bits(..) )
+import Data.Bits ( Bits(..) )
#if __GLASGOW_HASKELL__ >= 500
-import DATA_WORD ( Word )
+import Data.Word ( Word )
#else
-import DATA_WORD ( Word64 )
+import Data.Word ( Word64 )
#endif
\end{code}
+Note [Constant folding]
+~~~~~~~~~~~~~~~~~~~~~~~
+primOpRules generates the rewrite rules for each primop
+These rules do what is often called "constant folding"
+E.g. the rules for +# might say
+ 4 +# 5 = 9
+Well, of course you'd need a lot of rules if you did it
+like that, so we use a BuiltinRule instead, so that we
+can match in any two literal values. So the rule is really
+more like
+ (Lit 4) +# (Lit y) = Lit (x+#y)
+where the (+#) on the rhs is done at compile time
+
+That is why these rules are built in here. Other rules
+which don't need to be built in are in GHC.Base. For
+example:
+ x +# 0 = x
+
+
\begin{code}
primOpRules :: PrimOp -> Name -> [CoreRule]
primOpRules op op_name = primop_rule op
\begin{code}
dataToTagRule [Type ty1, Var tag_to_enum `App` Type ty2 `App` tag]
- | Just TagToEnumOp <- isPrimOpId_maybe tag_to_enum
+ | tag_to_enum `hasKey` tagToEnumKey
, ty1 `coreEqType` ty2
= Just tag -- dataToTag (tagToEnum x) ==> x