Commit a4124cf4 authored by simonpj's avatar simonpj
Browse files

[project @ 2005-01-27 15:51:11 by simonpj]

Add a rule for dataToTag (tagToEnum x)
parent 2cf37ff9
...@@ -20,7 +20,7 @@ module PrelRules ( primOpRules, builtinRules ) where ...@@ -20,7 +20,7 @@ module PrelRules ( primOpRules, builtinRules ) where
#include "HsVersions.h" #include "HsVersions.h"
import CoreSyn import CoreSyn
import Id ( mkWildId ) import Id ( mkWildId, isPrimOpId_maybe )
import Literal ( Literal(..), mkMachInt, mkMachWord import Literal ( Literal(..), mkMachInt, mkMachWord
, literalType , literalType
, word2IntLit, int2WordLit , word2IntLit, int2WordLit
...@@ -381,12 +381,15 @@ For dataToTag#, we can reduce if either ...@@ -381,12 +381,15 @@ For dataToTag#, we can reduce if either
(b) the argument is a variable whose unfolding is a known constructor (b) the argument is a variable whose unfolding is a known constructor
\begin{code} \begin{code}
dataToTagRule [_, val_arg] dataToTagRule [ty1, Var tag_to_enum `App` ty2 `App` tag]
= case exprIsConApp_maybe val_arg of | Just TagToEnumOp <- isPrimOpId_maybe tag_to_enum
Just (dc,_) -> ASSERT( not (isNewTyCon (dataConTyCon dc)) ) , ty1 `coreEqType` ty2
Just (mkIntVal (toInteger (dataConTag dc - fIRST_TAG))) = Just tag -- dataToTag (tagToEnum x) ==> x
other -> Nothing dataToTagRule [_, val_arg]
| Just (dc,_) <- exprIsConApp_maybe val_arg
= ASSERT( not (isNewTyCon (dataConTyCon dc)) )
Just (mkIntVal (toInteger (dataConTag dc - fIRST_TAG)))
dataToTagRule other = Nothing dataToTagRule other = Nothing
\end{code} \end{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment