[project @ 1999-11-29 17:34:14 by simonpj]
[ghc-hetmet.git] / ghc / compiler / basicTypes / Const.lhs
index 2c2fbb4..22fa7f8 100644 (file)
@@ -7,7 +7,7 @@
 module Const (
        Con(..),
        conType, conPrimRep,
-       conOkForApp, conOkForAlt, isWHNFCon, isDataCon,
+       conOkForApp, conOkForAlt, isWHNFCon, isDataCon, isBoxedDataCon,
        conIsTrivial, conIsCheap, conIsDupable, conStrictness, 
        conOkForSpeculation, hashCon,
 
@@ -31,7 +31,9 @@ import Name           ( hashName )
 import PrimOp          ( PrimOp, primOpType, primOpIsDupable, primOpTag,
                          primOpIsCheap, primOpStrictness, primOpOkForSpeculation )
 import PrimRep         ( PrimRep(..) )
-import DataCon         ( DataCon, dataConName, dataConType, dataConTyCon, isNullaryDataCon, dataConRepStrictness )
+import DataCon         ( DataCon, dataConName, dataConType, dataConTyCon, 
+                         isNullaryDataCon, dataConRepStrictness, isUnboxedTupleCon
+                       )
 import TyCon           ( isNewTyCon )
 import Type            ( Type, typePrimRep )
 import PprType         ( pprParendType )
@@ -44,6 +46,10 @@ import Util          ( thenCmp )
 import Ratio           ( numerator, denominator )
 import FastString      ( uniqueOfFS )
 import Char            ( ord )
+
+#if __GLASGOW_HASKELL__ >= 404
+import GlaExts         ( fromInt )
+#endif
 \end{code}
 
 
@@ -113,15 +119,20 @@ isWHNFCon (PrimOp _)   = False
 isDataCon (DataCon dc) = True
 isDataCon other               = False
 
+isBoxedDataCon (DataCon dc) = not (isUnboxedTupleCon dc)
+isBoxedDataCon other       = False
+
 -- conIsTrivial is true for constants we are unconditionally happy to duplicate
 -- cf CoreUtils.exprIsTrivial
 conIsTrivial (Literal lit) = not (isNoRepLit lit)
 conIsTrivial (PrimOp _)    = False
 conIsTrivial con          = True
 
--- conIsCheap is true for constants whose applications we are willing
+-- conIsCheap is true for constants whose *work* we are willing
 -- to duplicate in exchange for some modest gain.  cf CoreUtils.exprIsCheap
-conIsCheap (Literal lit) = not (isNoRepLit lit)
+conIsCheap (Literal lit) = True                -- Even no-rep lits are cheap; we don't end
+                                       -- up duplicating their work if we push them inside
+                                       -- a lambda, because we float them to the top in the end
 conIsCheap (DataCon con) = True
 conIsCheap (PrimOp op)   = primOpIsCheap op