Add a rule for dataToTag (tagToEnum x)
#include "HsVersions.h"
import CoreSyn
#include "HsVersions.h"
import CoreSyn
+import Id ( mkWildId, isPrimOpId_maybe )
import Literal ( Literal(..), mkMachInt, mkMachWord
, literalType
, word2IntLit, int2WordLit
import Literal ( Literal(..), mkMachInt, mkMachWord
, literalType
, word2IntLit, int2WordLit
(b) the argument is a variable whose unfolding is a known constructor
\begin{code}
(b) the argument is a variable whose unfolding is a known constructor
\begin{code}
-dataToTagRule [_, val_arg]
- = case exprIsConApp_maybe val_arg of
- Just (dc,_) -> ASSERT( not (isNewTyCon (dataConTyCon dc)) )
- Just (mkIntVal (toInteger (dataConTag dc - fIRST_TAG)))
+dataToTagRule [ty1, Var tag_to_enum `App` ty2 `App` tag]
+ | Just TagToEnumOp <- isPrimOpId_maybe tag_to_enum
+ , ty1 `coreEqType` ty2
+ = Just tag -- dataToTag (tagToEnum x) ==> x
+dataToTagRule [_, val_arg]
+ | Just (dc,_) <- exprIsConApp_maybe val_arg
+ = ASSERT( not (isNewTyCon (dataConTyCon dc)) )
+ Just (mkIntVal (toInteger (dataConTag dc - fIRST_TAG)))
dataToTagRule other = Nothing
\end{code}
dataToTagRule other = Nothing
\end{code}