[project @ 1999-07-27 11:09:31 by simonmar]
[ghc-hetmet.git] / ghc / compiler / prelude / PrimOp.lhs
index ab78b8d..24bd867 100644 (file)
@@ -7,7 +7,7 @@
 module PrimOp (
        PrimOp(..), allThePrimOps,
        primOpType, primOpSig, primOpUsg,
-       mkPrimOpIdName, primOpRdrName,
+       mkPrimOpIdName, primOpRdrName, primOpTag,
 
        commutableOp,
 
@@ -35,7 +35,7 @@ import RdrName                ( RdrName, mkRdrQual )
 import OccName         ( OccName, pprOccName, mkSrcVarOcc )
 import TyCon           ( TyCon, tyConArity )
 import Type            ( Type, mkForAllTys, mkForAllTy, mkFunTy, mkFunTys, mkTyVarTys,
-                         mkTyConTy, mkTyConApp, typePrimRep,
+                         mkTyConTy, mkTyConApp, typePrimRep,mkTyVarTy,
                          splitFunTy_maybe, splitAlgTyConApp_maybe, splitTyConApp_maybe,
                           UsageAnn(..), mkUsgTy
                        )
@@ -304,6 +304,9 @@ about using it this way?? ADR)
 Used for the Ord instance
 
 \begin{code}
+primOpTag :: PrimOp -> Int
+primOpTag op = IBOX( tagOf_PrimOp op )
+
 tagOf_PrimOp CharGtOp                        = (ILIT( 1) :: FAST_INT)
 tagOf_PrimOp CharGeOp                        = ILIT(  2)
 tagOf_PrimOp CharEqOp                        = ILIT(  3)
@@ -905,8 +908,13 @@ primOpStrictness :: PrimOp -> ([Demand], Bool)
        -- the list of demands may be infinite!
        -- Use only the ones you ned.
 
-primOpStrictness SeqOp            = ([wwLazy], False)
+primOpStrictness SeqOp            = ([wwStrict], False)
+       -- Seq is strict in its argument; see notes in ConFold.lhs
+
 primOpStrictness ParOp            = ([wwLazy], False)
+       -- But Par is lazy, to avoid that the sparked thing
+       -- gets evaluted strictly, which it should *not* be
+
 primOpStrictness ForkOp                  = ([wwLazy, wwPrim], False)
 
 primOpStrictness NewArrayOp       = ([wwPrim, wwLazy, wwPrim], False)
@@ -1631,8 +1639,8 @@ In practice, you'll use the higher-level
 
 \begin{code}
 primOpInfo MkWeakOp
-  = mkGenPrimOp SLIT("mkWeak#") [alphaTyVar, betaTyVar, gammaTyVar] 
-       [alphaTy, betaTy, gammaTy, realWorldStatePrimTy]
+  = mkGenPrimOp SLIT("mkWeak#") [openAlphaTyVar, betaTyVar, gammaTyVar] 
+       [mkTyVarTy openAlphaTyVar, betaTy, gammaTy, realWorldStatePrimTy]
        (unboxedPair [realWorldStatePrimTy, mkWeakPrimTy betaTy])
 \end{code}
 
@@ -1989,8 +1997,10 @@ primOpIsDupable means that the use of the primop is small enough to
 duplicate into different case branches.  See CoreUtils.exprIsDupable.
 
 \begin{code}
-primOpIsDupable (CCallOp _ _ _ _) = False
-primOpIsDupable op               = not (primOpOutOfLine op)
+primOpIsDupable (CCallOp _ _ might_gc _) = not might_gc
+       -- If the ccall can't GC then the call is pretty cheap, and
+       -- we're happy to duplicate
+primOpIsDupable op                      = not (primOpOutOfLine op)
 \end{code}
 
 
@@ -2131,7 +2141,7 @@ mkPrimOpIdName op id
   = mkWiredInIdName key pREL_GHC occ_name id
   where
     occ_name = primOpOcc op
-    key             = mkPrimOpIdUnique (IBOX(tagOf_PrimOp op))
+    key             = mkPrimOpIdUnique (primOpTag op)
 
 
 primOpRdrName :: PrimOp -> RdrName