[project @ 2000-06-30 13:11:07 by simonpj]
[ghc-hetmet.git] / ghc / compiler / prelude / PrimOp.lhs
index b8f5521..34d49c7 100644 (file)
@@ -6,19 +6,21 @@
 \begin{code}
 module PrimOp (
        PrimOp(..), allThePrimOps,
-       tagOf_PrimOp, -- ToDo: rm
-       primOpType,
-       primOpUniq, primOpOcc,
+       primOpType, primOpSig, primOpUsg, primOpArity,
+       mkPrimOpIdName, primOpRdrName, primOpTag, primOpOcc,
 
        commutableOp,
 
-       primOpOutOfLine, primOpNeedsWrapper,
-       primOpOkForSpeculation, primOpIsCheap,
+       primOpOutOfLine, primOpNeedsWrapper, 
+       primOpOkForSpeculation, primOpIsCheap, primOpIsDupable,
        primOpHasSideEffects,
 
        getPrimOpResultInfo,  PrimOpResultInfo(..),
 
-       pprPrimOp
+       pprPrimOp,
+
+       CCall(..), CCallTarget(..), ccallMayGC, ccallIsCasm, pprCCallOp,
+       isDynamicTarget, dynamicTarget, setCCallUnique
     ) where
 
 #include "HsVersions.h"
@@ -27,19 +29,25 @@ import PrimRep              -- most of it
 import TysPrim
 import TysWiredIn
 
-import Var             ( TyVar )
+import Demand          ( Demand, wwLazy, wwPrim, wwStrict, StrictnessInfo(..) )
+import Var             ( TyVar, Id )
 import CallConv                ( CallConv, pprCallConv )
 import PprType         ( pprParendType )
-import OccName         ( OccName, pprOccName, varOcc )
-import TyCon           ( TyCon )
-import Type            ( mkForAllTys, mkForAllTy, mkFunTy, mkFunTys, 
-                         mkTyConApp, typePrimRep,
-                         splitAlgTyConApp, Type, isUnboxedTupleType, 
-                         splitAlgTyConApp_maybe
+import Name            ( Name, mkWiredInIdName )
+import RdrName         ( RdrName, mkRdrQual )
+import OccName         ( OccName, pprOccName, mkSrcVarOcc )
+import TyCon           ( TyCon, tyConArity )
+import Type            ( Type, mkForAllTys, mkForAllTy, mkFunTy, mkFunTys, mkTyVarTys,
+                         mkTyConTy, mkTyConApp, typePrimRep,mkTyVarTy,
+                         splitFunTy_maybe, splitAlgTyConApp_maybe, splitTyConApp_maybe,
+                          UsageAnn(..), mkUsgTy
                        )
 import Unique          ( Unique, mkPrimOpIdUnique )
+import BasicTypes      ( Arity, Boxity(..) )
+import CStrings                ( CLabelString, pprCLabelString )
+import PrelNames       ( pREL_GHC, pREL_GHC_Name )
 import Outputable
-import Util            ( assoc )
+import Util            ( assoc, zipWithEqual )
 import GlaExts         ( Int(..), Int#, (==#) )
 \end{code}
 
@@ -68,10 +76,13 @@ data PrimOp
     | OrdOp | ChrOp
 
     -- Int#-related ops:
-   -- IntAbsOp unused?? ADR
     | IntAddOp | IntSubOp | IntMulOp | IntQuotOp
-    | IntRemOp | IntNegOp | IntAbsOp
+    | IntRemOp | IntNegOp
     | ISllOp | ISraOp | ISrlOp -- shift {left,right} {arithmetic,logical}
+    | IntAddCOp
+    | IntSubCOp
+    | IntMulCOp
+    | IntGcdOp
 
     -- Word#-related ops:
     | WordQuotOp | WordRemOp
@@ -111,8 +122,11 @@ data PrimOp
     -- slightly weird -- to match GMP package.
     | IntegerAddOp | IntegerSubOp | IntegerMulOp | IntegerGcdOp
     | IntegerQuotRemOp | IntegerDivModOp | IntegerNegOp
+    | IntegerIntGcdOp | IntegerDivExactOp
+    | IntegerQuotOp | IntegerRemOp
 
     | IntegerCmpOp
+    | IntegerCmpIntOp
 
     | Integer2IntOp  | Integer2WordOp  
     | Int2IntegerOp  | Word2IntegerOp
@@ -122,8 +136,8 @@ data PrimOp
     | IntegerToWord64Op | Word64ToIntegerOp
     -- ?? gcd, etc?
 
-    | FloatEncodeOp  | FloatDecodeOp
-    | DoubleEncodeOp | DoubleDecodeOp
+    | FloatDecodeOp
+    | DoubleDecodeOp
 
     -- primitive ops for primitive arrays
 
@@ -138,15 +152,18 @@ data PrimOp
     | ReadByteArrayOp  PrimRep
     | WriteByteArrayOp PrimRep
     | IndexByteArrayOp PrimRep
-    | IndexOffAddrOp   PrimRep
+    | ReadOffAddrOp    PrimRep
     | WriteOffAddrOp    PrimRep
-       -- PrimRep can be one of {Char,Int,Addr,Float,Double}Kind.
+    | IndexOffAddrOp   PrimRep
+       -- PrimRep can be one of :
+       --      {Char,Int,Word,Addr,Float,Double,StablePtr,Int64,Word64}Rep.
        -- This is just a cheesy encoding of a bunch of ops.
        -- Note that ForeignObjRep is not included -- the only way of
        -- creating a ForeignObj is with a ccall or casm.
     | IndexOffForeignObjOp PrimRep
 
     | UnsafeFreezeArrayOp | UnsafeFreezeByteArrayOp
+    | UnsafeThawArrayOp
     | SizeofByteArrayOp   | SizeofMutableByteArrayOp
 
     -- Mutable variables
@@ -160,97 +177,36 @@ data PrimOp
     | TakeMVarOp 
     | PutMVarOp
     | SameMVarOp
+    | TryTakeMVarOp 
+    | IsEmptyMVarOp
 
     -- exceptions
     | CatchOp
     | RaiseOp
+    | BlockAsyncExceptionsOp
+    | UnblockAsyncExceptionsOp
 
-    | MakeForeignObjOp
+    -- foreign objects
+    | MkForeignObjOp
     | WriteForeignObjOp
 
+    -- weak pointers
     | MkWeakOp
     | DeRefWeakOp
+    | FinalizeWeakOp
+
+    -- stable names
+    | MakeStableNameOp
+    | EqStableNameOp
+    | StableNameToIntOp
 
+    -- stable pointers
     | MakeStablePtrOp
     | DeRefStablePtrOp
     | EqStablePtrOp
-\end{code}
-
-A special ``trap-door'' to use in making calls direct to C functions:
-\begin{code}
-    | CCallOp  (Either 
-                   FAST_STRING    -- Left fn => An "unboxed" ccall# to `fn'.
-                   Unique)        -- Right u => first argument (an Addr#) is the function pointer
-                                  --   (unique is used to generate a 'typedef' to cast
-                                  --    the function pointer if compiling the ccall# down to
-                                  --    .hc code - can't do this inline for tedious reasons.)
-                                   
-               Bool                -- True <=> really a "casm"
-               Bool                -- True <=> might invoke Haskell GC
-               CallConv            -- calling convention to use.
-
-    -- (... to be continued ... )
-\end{code}
-
-The ``type'' of @CCallOp foo [t1, ... tm] r@ is @t1 -> ... tm -> r@.
-(See @primOpInfo@ for details.)
-
-Note: that first arg and part of the result should be the system state
-token (which we carry around to fool over-zealous optimisers) but
-which isn't actually passed.
-
-For example, we represent
-\begin{pseudocode}
-((ccall# foo [StablePtr# a, Int] Float) sp# i#) :: (Float, IoWorld)
-\end{pseudocode}
-by
-\begin{pseudocode}
-Case
-  ( Prim
-      (CCallOp "foo" [Universe#, StablePtr# a, Int#] FloatPrimAndUniverse False)
-       -- :: Universe# -> StablePtr# a -> Int# -> FloatPrimAndUniverse
-      []
-      [w#, sp# i#]
-  )
-  (AlgAlts [ ( FloatPrimAndIoWorld,
-                [f#, w#],
-                Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
-              ) ]
-            NoDefault
-  )
-\end{pseudocode}
-
-Nota Bene: there are some people who find the empty list of types in
-the @Prim@ somewhat puzzling and would represent the above by
-\begin{pseudocode}
-Case
-  ( Prim
-      (CCallOp "foo" [alpha1, alpha2, alpha3] alpha4 False)
-       -- :: /\ alpha1, alpha2 alpha3, alpha4.
-       --       alpha1 -> alpha2 -> alpha3 -> alpha4
-      [Universe#, StablePtr# a, Int#, FloatPrimAndIoWorld]
-      [w#, sp# i#]
-  )
-  (AlgAlts [ ( FloatPrimAndIoWorld,
-                [f#, w#],
-                Con (TupleCon 2) [Float, IoWorld] [F# f#, World w#]
-              ) ]
-            NoDefault
-  )
-\end{pseudocode}
-
-But, this is a completely different way of using @CCallOp@.  The most
-major changes required if we switch to this are in @primOpInfo@, and
-the desugarer. The major difficulty is in moving the HeapRequirement
-stuff somewhere appropriate.  (The advantage is that we could simplify
-@CCallOp@ and record just the number of arguments with corresponding
-simplifications in reading pragma unfoldings, the simplifier,
-instantiation (etc) of core expressions, ... .  Maybe we should think
-about using it this way?? ADR)
-
-\begin{code}
-    -- (... continued from above ... )
 
+    -- Foreign calls
+    | CCallOp CCall
     -- Operation to test two closure addresses for equality (yes really!)
     -- BLAME ALASTAIR REID FOR THIS!  THE REST OF US ARE INNOCENT!
     | ReallyUnsafePtrEqualityOp
@@ -262,10 +218,13 @@ about using it this way?? ADR)
     -- concurrency
     | ForkOp
     | KillThreadOp
+    | YieldOp
+    | MyThreadIdOp
     | DelayOp
     | WaitReadOp
     | WaitWriteOp
 
+    -- more parallel stuff
     | ParGlobalOp      -- named global par
     | ParLocalOp       -- named local par
     | ParAtOp          -- specifies destination of local par
@@ -274,11 +233,18 @@ about using it this way?? ADR)
     | ParAtForNowOp    -- specifies initial destination of global par
     | CopyableOp       -- marks copyable code
     | NoFollowOp       -- marks non-followup expression
+
+    -- tag-related
+    | DataToTagOp
+    | TagToEnumOp
 \end{code}
 
 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)
@@ -321,207 +287,223 @@ tagOf_PrimOp IntAddOp                         = ILIT( 39)
 tagOf_PrimOp IntSubOp                        = ILIT( 40)
 tagOf_PrimOp IntMulOp                        = ILIT( 41)
 tagOf_PrimOp IntQuotOp                       = ILIT( 42)
-tagOf_PrimOp IntRemOp                        = ILIT( 43)
-tagOf_PrimOp IntNegOp                        = ILIT( 44)
-tagOf_PrimOp IntAbsOp                        = ILIT( 45)
-tagOf_PrimOp WordQuotOp                              = ILIT( 46)
-tagOf_PrimOp WordRemOp                       = ILIT( 47)
-tagOf_PrimOp AndOp                           = ILIT( 48)
-tagOf_PrimOp OrOp                            = ILIT( 49)
-tagOf_PrimOp NotOp                           = ILIT( 50)
-tagOf_PrimOp XorOp                           = ILIT( 51)
-tagOf_PrimOp SllOp                           = ILIT( 52)
-tagOf_PrimOp SrlOp                           = ILIT( 53)
-tagOf_PrimOp ISllOp                          = ILIT( 54)
-tagOf_PrimOp ISraOp                          = ILIT( 55)
-tagOf_PrimOp ISrlOp                          = ILIT( 56)
-tagOf_PrimOp Int2WordOp                              = ILIT( 57)
-tagOf_PrimOp Word2IntOp                              = ILIT( 58)
-tagOf_PrimOp Int2AddrOp                              = ILIT( 59)
-tagOf_PrimOp Addr2IntOp                              = ILIT( 60)
-
-tagOf_PrimOp FloatAddOp                              = ILIT( 61)
-tagOf_PrimOp FloatSubOp                              = ILIT( 62)
-tagOf_PrimOp FloatMulOp                              = ILIT( 63)
-tagOf_PrimOp FloatDivOp                              = ILIT( 64)
-tagOf_PrimOp FloatNegOp                              = ILIT( 65)
-tagOf_PrimOp Float2IntOp                     = ILIT( 66)
-tagOf_PrimOp Int2FloatOp                     = ILIT( 67)
-tagOf_PrimOp FloatExpOp                              = ILIT( 68)
-tagOf_PrimOp FloatLogOp                              = ILIT( 69)
-tagOf_PrimOp FloatSqrtOp                     = ILIT( 70)
-tagOf_PrimOp FloatSinOp                              = ILIT( 71)
-tagOf_PrimOp FloatCosOp                              = ILIT( 72)
-tagOf_PrimOp FloatTanOp                              = ILIT( 73)
-tagOf_PrimOp FloatAsinOp                     = ILIT( 74)
-tagOf_PrimOp FloatAcosOp                     = ILIT( 75)
-tagOf_PrimOp FloatAtanOp                     = ILIT( 76)
-tagOf_PrimOp FloatSinhOp                     = ILIT( 77)
-tagOf_PrimOp FloatCoshOp                     = ILIT( 78)
-tagOf_PrimOp FloatTanhOp                     = ILIT( 79)
-tagOf_PrimOp FloatPowerOp                    = ILIT( 80)
-
-tagOf_PrimOp DoubleAddOp                     = ILIT( 81)
-tagOf_PrimOp DoubleSubOp                     = ILIT( 82)
-tagOf_PrimOp DoubleMulOp                     = ILIT( 83)
-tagOf_PrimOp DoubleDivOp                     = ILIT( 84)
-tagOf_PrimOp DoubleNegOp                     = ILIT( 85)
-tagOf_PrimOp Double2IntOp                    = ILIT( 86)
-tagOf_PrimOp Int2DoubleOp                    = ILIT( 87)
-tagOf_PrimOp Double2FloatOp                  = ILIT( 88)
-tagOf_PrimOp Float2DoubleOp                  = ILIT( 89)
-tagOf_PrimOp DoubleExpOp                     = ILIT( 90)
-tagOf_PrimOp DoubleLogOp                     = ILIT( 91)
-tagOf_PrimOp DoubleSqrtOp                    = ILIT( 92)
-tagOf_PrimOp DoubleSinOp                     = ILIT( 93)
-tagOf_PrimOp DoubleCosOp                     = ILIT( 94)
-tagOf_PrimOp DoubleTanOp                     = ILIT( 95)
-tagOf_PrimOp DoubleAsinOp                    = ILIT( 96)
-tagOf_PrimOp DoubleAcosOp                    = ILIT( 97)
-tagOf_PrimOp DoubleAtanOp                    = ILIT( 98)
-tagOf_PrimOp DoubleSinhOp                    = ILIT( 99)
-tagOf_PrimOp DoubleCoshOp                    = ILIT(100)
-tagOf_PrimOp DoubleTanhOp                    = ILIT(101)
-tagOf_PrimOp DoublePowerOp                   = ILIT(102)
-
-tagOf_PrimOp IntegerAddOp                    = ILIT(103)
-tagOf_PrimOp IntegerSubOp                    = ILIT(104)
-tagOf_PrimOp IntegerMulOp                    = ILIT(105)
-tagOf_PrimOp IntegerGcdOp                    = ILIT(106)
-tagOf_PrimOp IntegerQuotRemOp                = ILIT(107)
-tagOf_PrimOp IntegerDivModOp                 = ILIT(108)
-tagOf_PrimOp IntegerNegOp                    = ILIT(109)
-tagOf_PrimOp IntegerCmpOp                    = ILIT(110)
-tagOf_PrimOp Integer2IntOp                   = ILIT(111)
-tagOf_PrimOp Integer2WordOp                  = ILIT(112)
-tagOf_PrimOp Int2IntegerOp                   = ILIT(113)
-tagOf_PrimOp Word2IntegerOp                  = ILIT(114)
-tagOf_PrimOp Addr2IntegerOp                  = ILIT(115)
-tagOf_PrimOp IntegerToInt64Op                = ILIT(116)
-tagOf_PrimOp Int64ToIntegerOp                = ILIT(117)
-tagOf_PrimOp IntegerToWord64Op               = ILIT(118)
-tagOf_PrimOp Word64ToIntegerOp               = ILIT(119)
-
-tagOf_PrimOp FloatEncodeOp                   = ILIT(120)
-tagOf_PrimOp FloatDecodeOp                   = ILIT(121)
-tagOf_PrimOp DoubleEncodeOp                  = ILIT(122)
-tagOf_PrimOp DoubleDecodeOp                  = ILIT(123)
-
-tagOf_PrimOp NewArrayOp                              = ILIT(124)
-tagOf_PrimOp (NewByteArrayOp CharRep)        = ILIT(125)
-tagOf_PrimOp (NewByteArrayOp IntRep)         = ILIT(126)
-tagOf_PrimOp (NewByteArrayOp WordRep)        = ILIT(127)
-tagOf_PrimOp (NewByteArrayOp AddrRep)        = ILIT(128)
-tagOf_PrimOp (NewByteArrayOp FloatRep)       = ILIT(129)
-tagOf_PrimOp (NewByteArrayOp DoubleRep)       = ILIT(130)
-tagOf_PrimOp (NewByteArrayOp StablePtrRep)    = ILIT(131)
-tagOf_PrimOp SameMutableArrayOp                      = ILIT(132)
-tagOf_PrimOp SameMutableByteArrayOp          = ILIT(133)
-tagOf_PrimOp ReadArrayOp                     = ILIT(134)
-tagOf_PrimOp WriteArrayOp                    = ILIT(135)
-tagOf_PrimOp IndexArrayOp                    = ILIT(136)
-
-tagOf_PrimOp (ReadByteArrayOp CharRep)       = ILIT(137)
-tagOf_PrimOp (ReadByteArrayOp IntRep)        = ILIT(138)
-tagOf_PrimOp (ReadByteArrayOp WordRep)       = ILIT(139)
-tagOf_PrimOp (ReadByteArrayOp AddrRep)       = ILIT(140)
-tagOf_PrimOp (ReadByteArrayOp FloatRep)       = ILIT(141)
-tagOf_PrimOp (ReadByteArrayOp DoubleRep)      = ILIT(142)
-tagOf_PrimOp (ReadByteArrayOp StablePtrRep)   = ILIT(143)
-tagOf_PrimOp (ReadByteArrayOp Int64Rep)              = ILIT(144)
-tagOf_PrimOp (ReadByteArrayOp Word64Rep)      = ILIT(145)
-
-tagOf_PrimOp (WriteByteArrayOp CharRep)       = ILIT(146)
-tagOf_PrimOp (WriteByteArrayOp IntRep)       = ILIT(147)
-tagOf_PrimOp (WriteByteArrayOp WordRep)              = ILIT(148)
-tagOf_PrimOp (WriteByteArrayOp AddrRep)       = ILIT(149)
-tagOf_PrimOp (WriteByteArrayOp FloatRep)      = ILIT(150)
-tagOf_PrimOp (WriteByteArrayOp DoubleRep)     = ILIT(151)
-tagOf_PrimOp (WriteByteArrayOp StablePtrRep)  = ILIT(152)
-tagOf_PrimOp (WriteByteArrayOp Int64Rep)      = ILIT(153)
-tagOf_PrimOp (WriteByteArrayOp Word64Rep)     = ILIT(154)
-
-tagOf_PrimOp (IndexByteArrayOp CharRep)       = ILIT(155)
-tagOf_PrimOp (IndexByteArrayOp IntRep)       = ILIT(156)
-tagOf_PrimOp (IndexByteArrayOp WordRep)              = ILIT(157)
-tagOf_PrimOp (IndexByteArrayOp AddrRep)       = ILIT(158)
-tagOf_PrimOp (IndexByteArrayOp FloatRep)      = ILIT(159)
-tagOf_PrimOp (IndexByteArrayOp DoubleRep)     = ILIT(160)
-tagOf_PrimOp (IndexByteArrayOp StablePtrRep)  = ILIT(161)
-tagOf_PrimOp (IndexByteArrayOp Int64Rep)      = ILIT(162)
-tagOf_PrimOp (IndexByteArrayOp Word64Rep)     = ILIT(163)
-
-tagOf_PrimOp (IndexOffAddrOp CharRep)        = ILIT(164)
-tagOf_PrimOp (IndexOffAddrOp IntRep)         = ILIT(165)
-tagOf_PrimOp (IndexOffAddrOp WordRep)        = ILIT(166)
-tagOf_PrimOp (IndexOffAddrOp AddrRep)        = ILIT(167)
-tagOf_PrimOp (IndexOffAddrOp FloatRep)       = ILIT(168)
-tagOf_PrimOp (IndexOffAddrOp DoubleRep)       = ILIT(169)
-tagOf_PrimOp (IndexOffAddrOp StablePtrRep)    = ILIT(170)
-tagOf_PrimOp (IndexOffAddrOp Int64Rep)       = ILIT(171)
-tagOf_PrimOp (IndexOffAddrOp Word64Rep)              = ILIT(172)
-tagOf_PrimOp (IndexOffForeignObjOp CharRep)   = ILIT(173)
-tagOf_PrimOp (IndexOffForeignObjOp IntRep)    = ILIT(174)
-tagOf_PrimOp (IndexOffForeignObjOp WordRep)   = ILIT(175)
-tagOf_PrimOp (IndexOffForeignObjOp AddrRep)   = ILIT(176)
-tagOf_PrimOp (IndexOffForeignObjOp FloatRep)  = ILIT(177)
-tagOf_PrimOp (IndexOffForeignObjOp DoubleRep) = ILIT(178)
-tagOf_PrimOp (IndexOffForeignObjOp StablePtrRep) = ILIT(179)
-tagOf_PrimOp (IndexOffForeignObjOp Int64Rep)  = ILIT(180)
-tagOf_PrimOp (IndexOffForeignObjOp Word64Rep) = ILIT(181)
-
-tagOf_PrimOp (WriteOffAddrOp CharRep)         = ILIT(182)
-tagOf_PrimOp (WriteOffAddrOp IntRep)          = ILIT(183)
-tagOf_PrimOp (WriteOffAddrOp WordRep)         = ILIT(184)
-tagOf_PrimOp (WriteOffAddrOp AddrRep)         = ILIT(185)
-tagOf_PrimOp (WriteOffAddrOp FloatRep)        = ILIT(186)
-tagOf_PrimOp (WriteOffAddrOp DoubleRep)       = ILIT(187)
-tagOf_PrimOp (WriteOffAddrOp StablePtrRep)    = ILIT(188)
-tagOf_PrimOp (WriteOffAddrOp ForeignObjRep)   = ILIT(189)
-tagOf_PrimOp (WriteOffAddrOp Int64Rep)        = ILIT(190)
-tagOf_PrimOp (WriteOffAddrOp Word64Rep)       = ILIT(191)
-
-tagOf_PrimOp UnsafeFreezeArrayOp             = ILIT(192)
-tagOf_PrimOp UnsafeFreezeByteArrayOp         = ILIT(193)
-tagOf_PrimOp SizeofByteArrayOp               = ILIT(194)
-tagOf_PrimOp SizeofMutableByteArrayOp        = ILIT(195)
-tagOf_PrimOp NewMVarOp                       = ILIT(196)
-tagOf_PrimOp TakeMVarOp                              = ILIT(197)
-tagOf_PrimOp PutMVarOp                       = ILIT(198)
-tagOf_PrimOp SameMVarOp                              = ILIT(199)
-tagOf_PrimOp MakeForeignObjOp                = ILIT(200)
-tagOf_PrimOp WriteForeignObjOp               = ILIT(201)
-tagOf_PrimOp MkWeakOp                        = ILIT(202)
-tagOf_PrimOp DeRefWeakOp                     = ILIT(203)
-tagOf_PrimOp MakeStablePtrOp                 = ILIT(204)
-tagOf_PrimOp DeRefStablePtrOp                = ILIT(205)
-tagOf_PrimOp EqStablePtrOp                   = ILIT(206)
-tagOf_PrimOp (CCallOp _ _ _ _)               = ILIT(207)
-tagOf_PrimOp ReallyUnsafePtrEqualityOp       = ILIT(208)
-tagOf_PrimOp SeqOp                           = ILIT(209)
-tagOf_PrimOp ParOp                           = ILIT(210)
-tagOf_PrimOp ForkOp                          = ILIT(211)
-tagOf_PrimOp KillThreadOp                    = ILIT(212)
-tagOf_PrimOp DelayOp                         = ILIT(213)
-tagOf_PrimOp WaitReadOp                              = ILIT(214)
-tagOf_PrimOp WaitWriteOp                     = ILIT(215)
-tagOf_PrimOp ParGlobalOp                     = ILIT(216)
-tagOf_PrimOp ParLocalOp                              = ILIT(217)
-tagOf_PrimOp ParAtOp                         = ILIT(218)
-tagOf_PrimOp ParAtAbsOp                              = ILIT(219)
-tagOf_PrimOp ParAtRelOp                              = ILIT(220)
-tagOf_PrimOp ParAtForNowOp                   = ILIT(221)
-tagOf_PrimOp CopyableOp                              = ILIT(222)
-tagOf_PrimOp NoFollowOp                              = ILIT(223)
-tagOf_PrimOp NewMutVarOp                     = ILIT(224)
-tagOf_PrimOp ReadMutVarOp                    = ILIT(225)
-tagOf_PrimOp WriteMutVarOp                   = ILIT(226)
-tagOf_PrimOp SameMutVarOp                    = ILIT(227)
-tagOf_PrimOp CatchOp                         = ILIT(228)
-tagOf_PrimOp RaiseOp                         = ILIT(229)
+tagOf_PrimOp IntGcdOp                        = ILIT( 43)
+tagOf_PrimOp IntRemOp                        = ILIT( 44)
+tagOf_PrimOp IntNegOp                        = ILIT( 45)
+tagOf_PrimOp WordQuotOp                              = ILIT( 47)
+tagOf_PrimOp WordRemOp                       = ILIT( 48)
+tagOf_PrimOp AndOp                           = ILIT( 49)
+tagOf_PrimOp OrOp                            = ILIT( 50)
+tagOf_PrimOp NotOp                           = ILIT( 51)
+tagOf_PrimOp XorOp                           = ILIT( 52)
+tagOf_PrimOp SllOp                           = ILIT( 53)
+tagOf_PrimOp SrlOp                           = ILIT( 54)
+tagOf_PrimOp ISllOp                          = ILIT( 55)
+tagOf_PrimOp ISraOp                          = ILIT( 56)
+tagOf_PrimOp ISrlOp                          = ILIT( 57)
+tagOf_PrimOp IntAddCOp                       = ILIT( 58)
+tagOf_PrimOp IntSubCOp                       = ILIT( 59)
+tagOf_PrimOp IntMulCOp                       = ILIT( 60)
+tagOf_PrimOp Int2WordOp                              = ILIT( 61)
+tagOf_PrimOp Word2IntOp                              = ILIT( 62)
+tagOf_PrimOp Int2AddrOp                              = ILIT( 63)
+tagOf_PrimOp Addr2IntOp                              = ILIT( 64)
+tagOf_PrimOp FloatAddOp                              = ILIT( 65)
+tagOf_PrimOp FloatSubOp                              = ILIT( 66)
+tagOf_PrimOp FloatMulOp                              = ILIT( 67)
+tagOf_PrimOp FloatDivOp                              = ILIT( 68)
+tagOf_PrimOp FloatNegOp                              = ILIT( 69)
+tagOf_PrimOp Float2IntOp                     = ILIT( 70)
+tagOf_PrimOp Int2FloatOp                     = ILIT( 71)
+tagOf_PrimOp FloatExpOp                              = ILIT( 72)
+tagOf_PrimOp FloatLogOp                              = ILIT( 73)
+tagOf_PrimOp FloatSqrtOp                     = ILIT( 74)
+tagOf_PrimOp FloatSinOp                              = ILIT( 75)
+tagOf_PrimOp FloatCosOp                              = ILIT( 76)
+tagOf_PrimOp FloatTanOp                              = ILIT( 77)
+tagOf_PrimOp FloatAsinOp                     = ILIT( 78)
+tagOf_PrimOp FloatAcosOp                     = ILIT( 79)
+tagOf_PrimOp FloatAtanOp                     = ILIT( 80)
+tagOf_PrimOp FloatSinhOp                     = ILIT( 81)
+tagOf_PrimOp FloatCoshOp                     = ILIT( 82)
+tagOf_PrimOp FloatTanhOp                     = ILIT( 83)
+tagOf_PrimOp FloatPowerOp                    = ILIT( 84)
+tagOf_PrimOp DoubleAddOp                     = ILIT( 85)
+tagOf_PrimOp DoubleSubOp                     = ILIT( 86)
+tagOf_PrimOp DoubleMulOp                     = ILIT( 87)
+tagOf_PrimOp DoubleDivOp                     = ILIT( 88)
+tagOf_PrimOp DoubleNegOp                     = ILIT( 89)
+tagOf_PrimOp Double2IntOp                    = ILIT( 90)
+tagOf_PrimOp Int2DoubleOp                    = ILIT( 91)
+tagOf_PrimOp Double2FloatOp                  = ILIT( 92)
+tagOf_PrimOp Float2DoubleOp                  = ILIT( 93)
+tagOf_PrimOp DoubleExpOp                     = ILIT( 94)
+tagOf_PrimOp DoubleLogOp                     = ILIT( 95)
+tagOf_PrimOp DoubleSqrtOp                    = ILIT( 96)
+tagOf_PrimOp DoubleSinOp                     = ILIT( 97)
+tagOf_PrimOp DoubleCosOp                     = ILIT( 98)
+tagOf_PrimOp DoubleTanOp                     = ILIT( 99)
+tagOf_PrimOp DoubleAsinOp                    = ILIT(100)
+tagOf_PrimOp DoubleAcosOp                    = ILIT(101)
+tagOf_PrimOp DoubleAtanOp                    = ILIT(102)
+tagOf_PrimOp DoubleSinhOp                    = ILIT(103)
+tagOf_PrimOp DoubleCoshOp                    = ILIT(104)
+tagOf_PrimOp DoubleTanhOp                    = ILIT(105)
+tagOf_PrimOp DoublePowerOp                   = ILIT(106)
+tagOf_PrimOp IntegerAddOp                    = ILIT(107)
+tagOf_PrimOp IntegerSubOp                    = ILIT(108)
+tagOf_PrimOp IntegerMulOp                    = ILIT(109)
+tagOf_PrimOp IntegerGcdOp                    = ILIT(110)
+tagOf_PrimOp IntegerIntGcdOp                 = ILIT(111)
+tagOf_PrimOp IntegerDivExactOp               = ILIT(112)
+tagOf_PrimOp IntegerQuotOp                   = ILIT(113)
+tagOf_PrimOp IntegerRemOp                    = ILIT(114)
+tagOf_PrimOp IntegerQuotRemOp                = ILIT(115)
+tagOf_PrimOp IntegerDivModOp                 = ILIT(116)
+tagOf_PrimOp IntegerNegOp                    = ILIT(117)
+tagOf_PrimOp IntegerCmpOp                    = ILIT(118)
+tagOf_PrimOp IntegerCmpIntOp                 = ILIT(119)
+tagOf_PrimOp Integer2IntOp                   = ILIT(120)
+tagOf_PrimOp Integer2WordOp                  = ILIT(121)
+tagOf_PrimOp Int2IntegerOp                   = ILIT(122)
+tagOf_PrimOp Word2IntegerOp                  = ILIT(123)
+tagOf_PrimOp Addr2IntegerOp                  = ILIT(125)
+tagOf_PrimOp IntegerToInt64Op                = ILIT(127)
+tagOf_PrimOp Int64ToIntegerOp                = ILIT(128)
+tagOf_PrimOp IntegerToWord64Op               = ILIT(129)
+tagOf_PrimOp Word64ToIntegerOp               = ILIT(130)
+tagOf_PrimOp FloatDecodeOp                   = ILIT(131)
+tagOf_PrimOp DoubleDecodeOp                  = ILIT(132)
+tagOf_PrimOp NewArrayOp                              = ILIT(133)
+tagOf_PrimOp (NewByteArrayOp CharRep)        = ILIT(134)
+tagOf_PrimOp (NewByteArrayOp IntRep)         = ILIT(135)
+tagOf_PrimOp (NewByteArrayOp WordRep)        = ILIT(136)
+tagOf_PrimOp (NewByteArrayOp AddrRep)        = ILIT(137)
+tagOf_PrimOp (NewByteArrayOp FloatRep)       = ILIT(138)
+tagOf_PrimOp (NewByteArrayOp DoubleRep)       = ILIT(139)
+tagOf_PrimOp (NewByteArrayOp StablePtrRep)    = ILIT(140)
+tagOf_PrimOp SameMutableArrayOp                      = ILIT(141)
+tagOf_PrimOp SameMutableByteArrayOp          = ILIT(142)
+tagOf_PrimOp ReadArrayOp                     = ILIT(143)
+tagOf_PrimOp WriteArrayOp                    = ILIT(144)
+tagOf_PrimOp IndexArrayOp                    = ILIT(145)
+tagOf_PrimOp (ReadByteArrayOp CharRep)       = ILIT(146)
+tagOf_PrimOp (ReadByteArrayOp IntRep)        = ILIT(147)
+tagOf_PrimOp (ReadByteArrayOp WordRep)       = ILIT(148)
+tagOf_PrimOp (ReadByteArrayOp AddrRep)       = ILIT(149)
+tagOf_PrimOp (ReadByteArrayOp FloatRep)       = ILIT(150)
+tagOf_PrimOp (ReadByteArrayOp DoubleRep)      = ILIT(151)
+tagOf_PrimOp (ReadByteArrayOp StablePtrRep)   = ILIT(152)
+tagOf_PrimOp (ReadByteArrayOp Int64Rep)              = ILIT(153)
+tagOf_PrimOp (ReadByteArrayOp Word64Rep)      = ILIT(154)
+tagOf_PrimOp (WriteByteArrayOp CharRep)       = ILIT(155)
+tagOf_PrimOp (WriteByteArrayOp IntRep)       = ILIT(156)
+tagOf_PrimOp (WriteByteArrayOp WordRep)              = ILIT(157)
+tagOf_PrimOp (WriteByteArrayOp AddrRep)       = ILIT(158)
+tagOf_PrimOp (WriteByteArrayOp FloatRep)      = ILIT(159)
+tagOf_PrimOp (WriteByteArrayOp DoubleRep)     = ILIT(160)
+tagOf_PrimOp (WriteByteArrayOp StablePtrRep)  = ILIT(161)
+tagOf_PrimOp (WriteByteArrayOp Int64Rep)      = ILIT(162)
+tagOf_PrimOp (WriteByteArrayOp Word64Rep)     = ILIT(163)
+tagOf_PrimOp (IndexByteArrayOp CharRep)       = ILIT(164)
+tagOf_PrimOp (IndexByteArrayOp IntRep)       = ILIT(165)
+tagOf_PrimOp (IndexByteArrayOp WordRep)              = ILIT(166)
+tagOf_PrimOp (IndexByteArrayOp AddrRep)       = ILIT(167)
+tagOf_PrimOp (IndexByteArrayOp FloatRep)      = ILIT(168)
+tagOf_PrimOp (IndexByteArrayOp DoubleRep)     = ILIT(169)
+tagOf_PrimOp (IndexByteArrayOp StablePtrRep)  = ILIT(170)
+tagOf_PrimOp (IndexByteArrayOp Int64Rep)      = ILIT(171)
+tagOf_PrimOp (IndexByteArrayOp Word64Rep)     = ILIT(172)
+tagOf_PrimOp (IndexOffAddrOp CharRep)        = ILIT(173)
+tagOf_PrimOp (IndexOffAddrOp IntRep)         = ILIT(174)
+tagOf_PrimOp (IndexOffAddrOp WordRep)        = ILIT(175)
+tagOf_PrimOp (IndexOffAddrOp AddrRep)        = ILIT(176)
+tagOf_PrimOp (IndexOffAddrOp FloatRep)       = ILIT(177)
+tagOf_PrimOp (IndexOffAddrOp DoubleRep)       = ILIT(178)
+tagOf_PrimOp (IndexOffAddrOp StablePtrRep)    = ILIT(179)
+tagOf_PrimOp (IndexOffAddrOp Int64Rep)       = ILIT(180)
+tagOf_PrimOp (IndexOffAddrOp Word64Rep)              = ILIT(181)
+tagOf_PrimOp (IndexOffForeignObjOp CharRep)   = ILIT(182)
+tagOf_PrimOp (IndexOffForeignObjOp IntRep)    = ILIT(183)
+tagOf_PrimOp (IndexOffForeignObjOp WordRep)   = ILIT(184)
+tagOf_PrimOp (IndexOffForeignObjOp AddrRep)   = ILIT(185)
+tagOf_PrimOp (IndexOffForeignObjOp FloatRep)  = ILIT(186)
+tagOf_PrimOp (IndexOffForeignObjOp DoubleRep) = ILIT(187)
+tagOf_PrimOp (IndexOffForeignObjOp StablePtrRep) = ILIT(188)
+tagOf_PrimOp (IndexOffForeignObjOp Int64Rep)  = ILIT(189)
+tagOf_PrimOp (IndexOffForeignObjOp Word64Rep) = ILIT(190)
+tagOf_PrimOp (ReadOffAddrOp CharRep)          = ILIT(191)
+tagOf_PrimOp (ReadOffAddrOp IntRep)           = ILIT(192)
+tagOf_PrimOp (ReadOffAddrOp WordRep)          = ILIT(193)
+tagOf_PrimOp (ReadOffAddrOp AddrRep)          = ILIT(194)
+tagOf_PrimOp (ReadOffAddrOp FloatRep)         = ILIT(195)
+tagOf_PrimOp (ReadOffAddrOp DoubleRep)        = ILIT(196)
+tagOf_PrimOp (ReadOffAddrOp StablePtrRep)     = ILIT(197)
+tagOf_PrimOp (ReadOffAddrOp ForeignObjRep)    = ILIT(198)
+tagOf_PrimOp (ReadOffAddrOp Int64Rep)         = ILIT(199)
+tagOf_PrimOp (ReadOffAddrOp Word64Rep)        = ILIT(200)
+tagOf_PrimOp (WriteOffAddrOp CharRep)         = ILIT(201)
+tagOf_PrimOp (WriteOffAddrOp IntRep)          = ILIT(202)
+tagOf_PrimOp (WriteOffAddrOp WordRep)         = ILIT(203)
+tagOf_PrimOp (WriteOffAddrOp AddrRep)         = ILIT(205)
+tagOf_PrimOp (WriteOffAddrOp FloatRep)        = ILIT(206)
+tagOf_PrimOp (WriteOffAddrOp DoubleRep)       = ILIT(207)
+tagOf_PrimOp (WriteOffAddrOp StablePtrRep)    = ILIT(208)
+tagOf_PrimOp (WriteOffAddrOp ForeignObjRep)   = ILIT(209)
+tagOf_PrimOp (WriteOffAddrOp Int64Rep)        = ILIT(210)
+tagOf_PrimOp (WriteOffAddrOp Word64Rep)       = ILIT(211)
+tagOf_PrimOp UnsafeFreezeArrayOp             = ILIT(212)
+tagOf_PrimOp UnsafeFreezeByteArrayOp         = ILIT(213)
+tagOf_PrimOp UnsafeThawArrayOp               = ILIT(214)
+tagOf_PrimOp SizeofByteArrayOp               = ILIT(215)
+tagOf_PrimOp SizeofMutableByteArrayOp        = ILIT(216)
+tagOf_PrimOp NewMVarOp                       = ILIT(217)
+tagOf_PrimOp TakeMVarOp                              = ILIT(218)
+tagOf_PrimOp PutMVarOp                       = ILIT(219)
+tagOf_PrimOp SameMVarOp                              = ILIT(220)
+tagOf_PrimOp TryTakeMVarOp                   = ILIT(221)
+tagOf_PrimOp IsEmptyMVarOp                   = ILIT(222)
+tagOf_PrimOp MkForeignObjOp                  = ILIT(223)
+tagOf_PrimOp WriteForeignObjOp               = ILIT(224)
+tagOf_PrimOp MkWeakOp                        = ILIT(225)
+tagOf_PrimOp DeRefWeakOp                     = ILIT(226)
+tagOf_PrimOp FinalizeWeakOp                  = ILIT(227)
+tagOf_PrimOp MakeStableNameOp                = ILIT(228)
+tagOf_PrimOp EqStableNameOp                  = ILIT(229)
+tagOf_PrimOp StableNameToIntOp               = ILIT(230)
+tagOf_PrimOp MakeStablePtrOp                 = ILIT(231)
+tagOf_PrimOp DeRefStablePtrOp                = ILIT(232)
+tagOf_PrimOp EqStablePtrOp                   = ILIT(234)
+tagOf_PrimOp ReallyUnsafePtrEqualityOp       = ILIT(235)
+tagOf_PrimOp SeqOp                           = ILIT(236)
+tagOf_PrimOp ParOp                           = ILIT(237)
+tagOf_PrimOp ForkOp                          = ILIT(238)
+tagOf_PrimOp KillThreadOp                    = ILIT(239)
+tagOf_PrimOp YieldOp                         = ILIT(240)
+tagOf_PrimOp MyThreadIdOp                    = ILIT(241)
+tagOf_PrimOp DelayOp                         = ILIT(242)
+tagOf_PrimOp WaitReadOp                              = ILIT(243)
+tagOf_PrimOp WaitWriteOp                     = ILIT(244)
+tagOf_PrimOp ParGlobalOp                     = ILIT(245)
+tagOf_PrimOp ParLocalOp                              = ILIT(246)
+tagOf_PrimOp ParAtOp                         = ILIT(247)
+tagOf_PrimOp ParAtAbsOp                              = ILIT(248)
+tagOf_PrimOp ParAtRelOp                              = ILIT(249)
+tagOf_PrimOp ParAtForNowOp                   = ILIT(250)
+tagOf_PrimOp CopyableOp                              = ILIT(251)
+tagOf_PrimOp NoFollowOp                              = ILIT(252)
+tagOf_PrimOp NewMutVarOp                     = ILIT(253)
+tagOf_PrimOp ReadMutVarOp                    = ILIT(254)
+tagOf_PrimOp WriteMutVarOp                   = ILIT(255)
+tagOf_PrimOp SameMutVarOp                    = ILIT(256)
+tagOf_PrimOp CatchOp                         = ILIT(257)
+tagOf_PrimOp RaiseOp                         = ILIT(258)
+tagOf_PrimOp BlockAsyncExceptionsOp          = ILIT(259)
+tagOf_PrimOp UnblockAsyncExceptionsOp        = ILIT(260)
+tagOf_PrimOp DataToTagOp                     = ILIT(261)
+tagOf_PrimOp TagToEnumOp                     = ILIT(262)
 
 tagOf_PrimOp op = pprPanic# "tagOf_PrimOp: pattern-match" (ppr op)
---panic# "tagOf_PrimOp: pattern-match"
 
 instance Eq PrimOp where
     op1 == op2 = tagOf_PrimOp op1 _EQ_ tagOf_PrimOp op2
@@ -544,7 +526,7 @@ instance Show PrimOp where
 
 An @Enum@-derived list would be better; meanwhile... (ToDo)
 \begin{code}
-allThePrimOps
+allThePrimOps          -- Except CCall, which is really a family of primops
   = [  CharGtOp,
        CharGeOp,
        CharEqOp,
@@ -588,6 +570,7 @@ allThePrimOps
        IntMulOp,
        IntQuotOp,
        IntRemOp,
+       IntGcdOp,
        IntNegOp,
        WordQuotOp,
        WordRemOp,
@@ -600,6 +583,9 @@ allThePrimOps
        ISllOp,
        ISraOp,
        ISrlOp,
+       IntAddCOp,
+       IntSubCOp,
+       IntMulCOp,
        Int2WordOp,
        Word2IntOp,
        Int2AddrOp,
@@ -651,10 +637,15 @@ allThePrimOps
        IntegerSubOp,
        IntegerMulOp,
        IntegerGcdOp,
+        IntegerIntGcdOp,
+        IntegerDivExactOp,
+        IntegerQuotOp,
+        IntegerRemOp,
        IntegerQuotRemOp,
        IntegerDivModOp,
        IntegerNegOp,
        IntegerCmpOp,
+       IntegerCmpIntOp,
        Integer2IntOp,
        Integer2WordOp,
        Int2IntegerOp,
@@ -664,9 +655,7 @@ allThePrimOps
        Int64ToIntegerOp,
        IntegerToWord64Op,
        Word64ToIntegerOp,
-       FloatEncodeOp,
        FloatDecodeOp,
-       DoubleEncodeOp,
        DoubleDecodeOp,
        NewArrayOp,
        NewByteArrayOp CharRep,
@@ -726,6 +715,16 @@ allThePrimOps
        IndexOffAddrOp StablePtrRep,
        IndexOffAddrOp Int64Rep,
        IndexOffAddrOp Word64Rep,
+       ReadOffAddrOp CharRep,
+       ReadOffAddrOp IntRep,
+       ReadOffAddrOp WordRep,
+       ReadOffAddrOp AddrRep,
+       ReadOffAddrOp FloatRep,
+       ReadOffAddrOp DoubleRep,
+       ReadOffAddrOp ForeignObjRep,
+       ReadOffAddrOp StablePtrRep,
+       ReadOffAddrOp Int64Rep,
+       ReadOffAddrOp Word64Rep,
        WriteOffAddrOp CharRep,
        WriteOffAddrOp IntRep,
        WriteOffAddrOp WordRep,
@@ -738,6 +737,7 @@ allThePrimOps
        WriteOffAddrOp Word64Rep,
        UnsafeFreezeArrayOp,
        UnsafeFreezeByteArrayOp,
+       UnsafeThawArrayOp,
        SizeofByteArrayOp,
        SizeofMutableByteArrayOp,
        NewMutVarOp,
@@ -746,14 +746,22 @@ allThePrimOps
        SameMutVarOp,
         CatchOp,
         RaiseOp,
+       BlockAsyncExceptionsOp,
+       UnblockAsyncExceptionsOp,
        NewMVarOp,
        TakeMVarOp,
        PutMVarOp,
        SameMVarOp,
-       MakeForeignObjOp,
+       TryTakeMVarOp,
+       IsEmptyMVarOp,
+       MkForeignObjOp,
        WriteForeignObjOp,
        MkWeakOp,
        DeRefWeakOp,
+       FinalizeWeakOp,
+       MakeStableNameOp,
+       EqStableNameOp,
+       StableNameToIntOp,
        MakeStablePtrOp,
        DeRefStablePtrOp,
        EqStablePtrOp,
@@ -770,9 +778,13 @@ allThePrimOps
        ParOp,
        ForkOp,
        KillThreadOp,
+       YieldOp,
+       MyThreadIdOp,
        DelayOp,
        WaitReadOp,
-       WaitWriteOp
+       WaitWriteOp,
+       DataToTagOp,
+       TagToEnumOp
     ]
 \end{code}
 
@@ -805,42 +817,94 @@ data PrimOpInfo
                [Type] 
                Type 
 
-mkDyadic str  ty = Dyadic  (varOcc str) ty
-mkMonadic str ty = Monadic (varOcc str) ty
-mkCompare str ty = Compare (varOcc str) ty
-mkGenPrimOp str tvs tys ty = GenPrimOp (varOcc str) tvs tys ty
+mkDyadic str  ty = Dyadic  (mkSrcVarOcc str) ty
+mkMonadic str ty = Monadic (mkSrcVarOcc str) ty
+mkCompare str ty = Compare (mkSrcVarOcc str) ty
+mkGenPrimOp str tvs tys ty = GenPrimOp (mkSrcVarOcc str) tvs tys ty
 \end{code}
 
 Utility bits:
 \begin{code}
-one_Integer_ty = [intPrimTy, intPrimTy, byteArrayPrimTy]
+one_Integer_ty = [intPrimTy, byteArrayPrimTy]
 two_Integer_tys
-  = [intPrimTy, intPrimTy, byteArrayPrimTy, -- first Integer pieces
-     intPrimTy, intPrimTy, byteArrayPrimTy] -- second '' pieces
+  = [intPrimTy, byteArrayPrimTy, -- first Integer pieces
+     intPrimTy, byteArrayPrimTy] -- second '' pieces
 an_Integer_and_Int_tys
-  = [intPrimTy, intPrimTy, byteArrayPrimTy, -- Integer
+  = [intPrimTy, byteArrayPrimTy, -- Integer
      intPrimTy]
 
-unboxedPair     = mkUnboxedTupleTy 2
-unboxedTriple    = mkUnboxedTupleTy 3
-unboxedQuadruple = mkUnboxedTupleTy 4
-unboxedSexTuple  = mkUnboxedTupleTy 6
+unboxedSingleton = mkTupleTy Unboxed 1
+unboxedPair     = mkTupleTy Unboxed 2
+unboxedTriple    = mkTupleTy Unboxed 3
+unboxedQuadruple = mkTupleTy Unboxed 4
+
+mkIOTy ty = mkFunTy realWorldStatePrimTy 
+                   (unboxedPair [realWorldStatePrimTy,ty])
 
 integerMonadic name = mkGenPrimOp name [] one_Integer_ty 
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+                       (unboxedPair one_Integer_ty)
 
 integerDyadic name = mkGenPrimOp name [] two_Integer_tys 
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+                       (unboxedPair one_Integer_ty)
 
 integerDyadic2Results name = mkGenPrimOp name [] two_Integer_tys 
-    (unboxedSexTuple [intPrimTy, intPrimTy, byteArrayPrimTy, 
-                     intPrimTy, intPrimTy, byteArrayPrimTy])
+    (unboxedQuadruple two_Integer_tys)
 
 integerCompare name = mkGenPrimOp name [] two_Integer_tys intPrimTy
 \end{code}
 
 %************************************************************************
 %*                                                                     *
+\subsubsection{Strictness}
+%*                                                                     *
+%************************************************************************
+
+Not all primops are strict!
+
+\begin{code}
+primOpStrictness :: Arity -> PrimOp -> StrictnessInfo
+       -- See Demand.StrictnessInfo for discussion of what the results
+       -- The arity should be the arity of the primop; that's why
+       -- this function isn't exported.
+
+primOpStrictness arity SeqOp            = StrictnessInfo [wwStrict] False
+       -- Seq is strict in its argument; see notes in ConFold.lhs
+
+primOpStrictness arity ParOp            = StrictnessInfo [wwLazy] False
+       -- Note that Par is lazy to avoid that the sparked thing
+       -- gets evaluted strictly, which it should *not* be
+
+primOpStrictness arity ForkOp          = StrictnessInfo [wwLazy, wwPrim] False
+
+primOpStrictness arity NewArrayOp       = StrictnessInfo [wwPrim, wwLazy, wwPrim] False
+primOpStrictness arity WriteArrayOp     = StrictnessInfo [wwPrim, wwPrim, wwLazy, wwPrim] False
+
+primOpStrictness arity NewMutVarOp     = StrictnessInfo [wwLazy, wwPrim] False
+primOpStrictness arity WriteMutVarOp   = StrictnessInfo [wwPrim, wwLazy, wwPrim] False
+
+primOpStrictness arity PutMVarOp       = StrictnessInfo [wwPrim, wwLazy, wwPrim] False
+
+primOpStrictness arity CatchOp                 = StrictnessInfo [wwLazy, wwLazy, wwPrim] False
+       -- Catch is actually strict in its first argument
+       -- but we don't want to tell the strictness
+       -- analyser about that!
+
+primOpStrictness arity RaiseOp                 = StrictnessInfo [wwLazy] True  -- NB: True => result is bottom
+primOpStrictness arity BlockAsyncExceptionsOp   = StrictnessInfo [wwLazy] False
+primOpStrictness arity UnblockAsyncExceptionsOp = StrictnessInfo [wwLazy] False
+
+primOpStrictness arity MkWeakOp                = StrictnessInfo [wwLazy, wwLazy, wwLazy, wwPrim] False
+primOpStrictness arity MakeStableNameOp = StrictnessInfo [wwLazy, wwPrim] False
+primOpStrictness arity MakeStablePtrOp  = StrictnessInfo [wwLazy, wwPrim] False
+
+primOpStrictness arity DataToTagOp      = StrictnessInfo [wwLazy] False
+
+       -- The rest all have primitive-typed arguments
+primOpStrictness arity other           = StrictnessInfo (replicate arity wwPrim) False
+\end{code}
+
+%************************************************************************
+%*                                                                     *
 \subsubsection[PrimOp-comparison]{PrimOpInfo basic comparison ops}
 %*                                                                     *
 %************************************************************************
@@ -917,14 +981,26 @@ primOpInfo ChrOp = mkGenPrimOp SLIT("chr#") [] [intPrimTy]  charPrimTy
 %************************************************************************
 
 \begin{code}
-primOpInfo IntAddOp  = mkDyadic SLIT("+#")      intPrimTy
-primOpInfo IntSubOp  = mkDyadic SLIT("-#") intPrimTy
-primOpInfo IntMulOp  = mkDyadic SLIT("*#") intPrimTy
-primOpInfo IntQuotOp = mkDyadic SLIT("quotInt#")        intPrimTy
-primOpInfo IntRemOp  = mkDyadic SLIT("remInt#")         intPrimTy
+primOpInfo IntAddOp  = mkDyadic SLIT("+#")         intPrimTy
+primOpInfo IntSubOp  = mkDyadic SLIT("-#")         intPrimTy
+primOpInfo IntMulOp  = mkDyadic SLIT("*#")         intPrimTy
+primOpInfo IntQuotOp = mkDyadic SLIT("quotInt#")    intPrimTy
+primOpInfo IntRemOp  = mkDyadic SLIT("remInt#")            intPrimTy
+primOpInfo IntGcdOp  = mkDyadic SLIT("gcdInt#")            intPrimTy
 
 primOpInfo IntNegOp  = mkMonadic SLIT("negateInt#") intPrimTy
-primOpInfo IntAbsOp  = mkMonadic SLIT("absInt#") intPrimTy
+
+primOpInfo IntAddCOp = 
+       mkGenPrimOp SLIT("addIntC#")  [] [intPrimTy, intPrimTy] 
+               (unboxedPair [intPrimTy, intPrimTy])
+
+primOpInfo IntSubCOp = 
+       mkGenPrimOp SLIT("subIntC#")  [] [intPrimTy, intPrimTy] 
+               (unboxedPair [intPrimTy, intPrimTy])
+
+primOpInfo IntMulCOp = 
+       mkGenPrimOp SLIT("mulIntC#")  [] [intPrimTy, intPrimTy] 
+               (unboxedPair [intPrimTy, intPrimTy])
 \end{code}
 
 %************************************************************************
@@ -978,8 +1054,7 @@ primOpInfo Addr2IntOp = mkGenPrimOp SLIT("addr2Int#") [] [addrPrimTy] intPrimTy
 %*                                                                     *
 %************************************************************************
 
-@encodeFloat#@ and @decodeFloat#@ are given w/ Integer-stuff (it's
-similar).
+@decodeFloat#@ is given w/ Integer-stuff (it's similar).
 
 \begin{code}
 primOpInfo FloatAddOp  = mkDyadic    SLIT("plusFloat#")           floatPrimTy
@@ -1012,8 +1087,7 @@ primOpInfo FloatPowerOp   = mkDyadic    SLIT("powerFloat#")   floatPrimTy
 %*                                                                     *
 %************************************************************************
 
-@encodeDouble#@ and @decodeDouble#@ are given w/ Integer-stuff (it's
-similar).
+@decodeDouble#@ is given w/ Integer-stuff (it's similar).
 
 \begin{code}
 primOpInfo DoubleAddOp = mkDyadic    SLIT("+##")   doublePrimTy
@@ -1056,8 +1130,14 @@ primOpInfo IntegerAddOp  = integerDyadic SLIT("plusInteger#")
 primOpInfo IntegerSubOp        = integerDyadic SLIT("minusInteger#")
 primOpInfo IntegerMulOp        = integerDyadic SLIT("timesInteger#")
 primOpInfo IntegerGcdOp        = integerDyadic SLIT("gcdInteger#")
+primOpInfo IntegerIntGcdOp = mkGenPrimOp SLIT("gcdIntegerInt#") [] an_Integer_and_Int_tys intPrimTy
+primOpInfo IntegerDivExactOp  = integerDyadic SLIT("divExactInteger#")
+primOpInfo IntegerQuotOp = integerDyadic SLIT("quotInteger#")
+primOpInfo IntegerRemOp  = integerDyadic SLIT("remInteger#")
 
 primOpInfo IntegerCmpOp        = integerCompare SLIT("cmpInteger#")
+primOpInfo IntegerCmpIntOp 
+  = mkGenPrimOp SLIT("cmpIntegerInt#") [] an_Integer_and_Int_tys intPrimTy
 
 primOpInfo IntegerQuotRemOp = integerDyadic2Results SLIT("quotRemInteger#")
 primOpInfo IntegerDivModOp  = integerDyadic2Results SLIT("divModInteger#")
@@ -1070,47 +1150,41 @@ primOpInfo Integer2WordOp
 
 primOpInfo Int2IntegerOp
   = mkGenPrimOp SLIT("int2Integer#") [] [intPrimTy] 
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedPair one_Integer_ty)
 
 primOpInfo Word2IntegerOp
   = mkGenPrimOp SLIT("word2Integer#") [] [wordPrimTy] 
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedPair one_Integer_ty)
 
 primOpInfo Addr2IntegerOp
   = mkGenPrimOp SLIT("addr2Integer#") [] [addrPrimTy] 
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedPair one_Integer_ty)
 
 primOpInfo IntegerToInt64Op
   = mkGenPrimOp SLIT("integerToInt64#") [] one_Integer_ty int64PrimTy
 
 primOpInfo Int64ToIntegerOp
   = mkGenPrimOp SLIT("int64ToInteger#") [] [int64PrimTy]
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedPair one_Integer_ty)
 
 primOpInfo Word64ToIntegerOp
   = mkGenPrimOp SLIT("word64ToInteger#") [] [word64PrimTy] 
-                       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedPair one_Integer_ty)
 
 primOpInfo IntegerToWord64Op
   = mkGenPrimOp SLIT("integerToWord64#") [] one_Integer_ty word64PrimTy
 \end{code}
 
-Encoding and decoding of floating-point numbers is sorta
-Integer-related.
+Decoding of floating-point numbers is sorta Integer-related.  Encoding
+is done with plain ccalls now (see PrelNumExtra.lhs).
 
 \begin{code}
-primOpInfo FloatEncodeOp
-  = mkGenPrimOp SLIT("encodeFloat#") [] an_Integer_and_Int_tys floatPrimTy
-
-primOpInfo DoubleEncodeOp
-  = mkGenPrimOp SLIT("encodeDouble#") [] an_Integer_and_Int_tys doublePrimTy
-
 primOpInfo FloatDecodeOp
   = mkGenPrimOp SLIT("decodeFloat#") [] [floatPrimTy] 
-       (unboxedQuadruple [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
 primOpInfo DoubleDecodeOp
   = mkGenPrimOp SLIT("decodeDouble#") [] [doublePrimTy] 
-       (unboxedQuadruple [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy])
+       (unboxedTriple [intPrimTy, intPrimTy, byteArrayPrimTy])
 \end{code}
 
 %************************************************************************
@@ -1119,6 +1193,11 @@ primOpInfo DoubleDecodeOp
 %*                                                                     *
 %************************************************************************
 
+\begin{verbatim}
+newArray#    :: Int# -> a -> State# s -> (# State# s, MutArr# s a #)
+newFooArray# :: Int# -> State# s -> (# State# s, MutByteArr# s #)
+\end{verbatim}
+
 \begin{code}
 primOpInfo NewArrayOp
   = let {
@@ -1142,6 +1221,11 @@ primOpInfo (NewByteArrayOp kind)
 
 ---------------------------------------------------------------------------
 
+{-
+sameMutableArray#     :: MutArr# s a -> MutArr# s a -> Bool
+sameMutableByteArray# :: MutByteArr# s -> MutByteArr# s -> Bool
+-}
+
 primOpInfo SameMutableArrayOp
   = let {
        elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
@@ -1161,6 +1245,12 @@ primOpInfo SameMutableByteArrayOp
 ---------------------------------------------------------------------------
 -- Primitive arrays of Haskell pointers:
 
+{-
+readArray#  :: MutArr# s a -> Int# -> State# s -> (# State# s, a #)
+writeArray# :: MutArr# s a -> Int# -> a -> State# s -> State# s
+indexArray# :: Array# a -> Int# -> (# a #)
+-}
+
 primOpInfo ReadArrayOp
   = let {
        elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
@@ -1182,7 +1272,7 @@ primOpInfo WriteArrayOp
 primOpInfo IndexArrayOp
   = let { elt = alphaTy; elt_tv = alphaTyVar } in
     mkGenPrimOp SLIT("indexArray#") [elt_tv] [mkArrayPrimTy elt, intPrimTy]
-       (unboxedPair [realWorldStatePrimTy, elt])
+       (unboxedSingleton [elt])
 
 ---------------------------------------------------------------------------
 -- Primitive arrays full of unboxed bytes:
@@ -1192,86 +1282,72 @@ primOpInfo (ReadByteArrayOp kind)
        s = alphaTy; s_tv = alphaTyVar
 
        op_str         = _PK_ ("read" ++ primRepString kind ++ "Array#")
-       relevant_type  = assoc "primOpInfo{ReadByteArrayOp}" tbl kind
+       (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
        state          = mkStatePrimTy s
-
-        tvs
-         | kind == StablePtrRep = [s_tv, betaTyVar]
-         | otherwise            = [s_tv]
     in
-    mkGenPrimOp op_str tvs
+    mkGenPrimOp op_str (s_tv:tvs)
        [mkMutableByteArrayPrimTy s, intPrimTy, state]
-       (unboxedPair [state, relevant_type])
-  where
-    tbl = [ (CharRep,   charPrimTy),
-           (IntRep,     intPrimTy),
-           (WordRep,    wordPrimTy),
-           (AddrRep,    addrPrimTy),
-           (FloatRep,   floatPrimTy),
-           (StablePtrRep, mkStablePtrPrimTy betaTy),
-           (DoubleRep,  doublePrimTy) ]
-
-  -- How come there's no Word byte arrays? ADR
+       (unboxedPair [state, prim_ty])
 
 primOpInfo (WriteByteArrayOp kind)
   = let
        s = alphaTy; s_tv = alphaTyVar
        op_str = _PK_ ("write" ++ primRepString kind ++ "Array#")
-       prim_ty = mkTyConApp (primRepTyCon kind) []
-
-        (the_prim_ty, tvs)
-         | kind == StablePtrRep = (mkStablePtrPrimTy betaTy, [s_tv, betaTyVar])
-         | otherwise            = (prim_ty, [s_tv])
-
+       (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
     in
-    mkGenPrimOp op_str tvs
-       [mkMutableByteArrayPrimTy s, intPrimTy, the_prim_ty, mkStatePrimTy s]
+    mkGenPrimOp op_str (s_tv:tvs)
+       [mkMutableByteArrayPrimTy s, intPrimTy, prim_ty, mkStatePrimTy s]
        (mkStatePrimTy s)
 
 primOpInfo (IndexByteArrayOp kind)
   = let
        op_str = _PK_ ("index" ++ primRepString kind ++ "Array#")
-
-        (prim_tycon_args, tvs)
-         | kind == StablePtrRep = ([alphaTy], [alphaTyVar])
-         | otherwise            = ([],[])
+        (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
     in
-    mkGenPrimOp op_str tvs [byteArrayPrimTy, intPrimTy] 
-       (mkTyConApp (primRepTyCon kind) prim_tycon_args)
+    mkGenPrimOp op_str tvs [byteArrayPrimTy, intPrimTy] prim_ty
 
 primOpInfo (IndexOffForeignObjOp kind)
   = let
        op_str = _PK_ ("index" ++ primRepString kind ++ "OffForeignObj#")
-
-        (prim_tycon_args, tvs)
-         | kind == StablePtrRep = ([alphaTy], [alphaTyVar])
-         | otherwise            = ([], [])
+        (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
     in
-    mkGenPrimOp op_str tvs [foreignObjPrimTy, intPrimTy] 
-       (mkTyConApp (primRepTyCon kind) prim_tycon_args)
+    mkGenPrimOp op_str tvs [foreignObjPrimTy, intPrimTy] prim_ty
 
 primOpInfo (IndexOffAddrOp kind)
   = let
        op_str = _PK_ ("index" ++ primRepString kind ++ "OffAddr#")
+        (tvs, prim_ty) = mkPrimTyApp alphaTyVars kind
+    in
+    mkGenPrimOp op_str tvs [addrPrimTy, intPrimTy] prim_ty
 
-        (prim_tycon_args, tvs)
-         | kind == StablePtrRep = ([alphaTy], [alphaTyVar])
-         | otherwise            = ([], [])
+primOpInfo (ReadOffAddrOp kind)
+  = let
+       s = alphaTy; s_tv = alphaTyVar
+       op_str = _PK_ ("read" ++ primRepString kind ++ "OffAddr#")
+        (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
+       state          = mkStatePrimTy s
     in
-    mkGenPrimOp op_str tvs [addrPrimTy, intPrimTy] 
-       (mkTyConApp (primRepTyCon kind) prim_tycon_args)
+    mkGenPrimOp op_str (s_tv:tvs)
+       [addrPrimTy, intPrimTy, state]
+       (unboxedPair [state, prim_ty])
 
 primOpInfo (WriteOffAddrOp kind)
   = let
        s = alphaTy; s_tv = alphaTyVar
        op_str = _PK_ ("write" ++ primRepString kind ++ "OffAddr#")
-       prim_ty = mkTyConApp (primRepTyCon kind) []
+        (tvs, prim_ty) = mkPrimTyApp betaTyVars kind
     in
-    mkGenPrimOp op_str [s_tv]
+    mkGenPrimOp op_str (s_tv:tvs)
        [addrPrimTy, intPrimTy, prim_ty, mkStatePrimTy s]
        (mkStatePrimTy s)
 
 ---------------------------------------------------------------------------
+{-
+unsafeFreezeArray#     :: MutArr# s a -> State# s -> (# State# s, Array# a #)
+unsafeFreezeByteArray# :: MutByteArr# s -> State# s -> (# State# s, ByteArray# #)
+unsafeThawArray#       :: Array# a -> State# s -> (# State# s, MutArr# s a #)
+-}
+
 primOpInfo UnsafeFreezeArrayOp
   = let {
        elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
@@ -1290,6 +1366,15 @@ primOpInfo UnsafeFreezeByteArrayOp
        [mkMutableByteArrayPrimTy s, state]
        (unboxedPair [state, byteArrayPrimTy])
 
+primOpInfo UnsafeThawArrayOp
+  = let {
+       elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar;
+       state = mkStatePrimTy s
+    } in
+    mkGenPrimOp SLIT("unsafeThawArray#") [s_tv, elt_tv]
+       [mkArrayPrimTy elt, state]
+       (unboxedPair [state, mkMutableArrayPrimTy s elt])
+
 ---------------------------------------------------------------------------
 primOpInfo SizeofByteArrayOp
   = mkGenPrimOp
@@ -1355,23 +1440,50 @@ primOpInfo SameMutVarOp
 %*                                                                     *
 %************************************************************************
 
-catch :: IO a -> (IOError -> IO a) -> IO a
-catch :: a  -> (b -> a) -> a
+catch# :: (State# RealWorld -> (# State# RealWorld, a))
+       -> (b -> State# RealWorld -> (# State# RealWorld, a)) 
+       -> State# RealWorld
+       -> (# State# RealWorld, a)
+
+throw  :: Exception -> a
+raise# :: a -> b
+
+blockAsyncExceptions#   :: IO a -> IO a
+unblockAsyncExceptions# :: IO a -> IO a
 
 \begin{code}
 primOpInfo CatchOp   
   = let
-       a = alphaTy; a_tv = alphaTyVar;
+       a = alphaTy; a_tv = alphaTyVar
        b = betaTy;  b_tv = betaTyVar;
+       io_a = mkIOTy a
     in
-    mkGenPrimOp SLIT("catch#") [a_tv, b_tv] [a, mkFunTy b a] a
+    mkGenPrimOp SLIT("catch#") [a_tv, b_tv] 
+         [io_a, mkFunTy b io_a, realWorldStatePrimTy]
+         (unboxedPair [realWorldStatePrimTy, a])
 
 primOpInfo RaiseOp
   = let
-       a = alphaTy; a_tv = alphaTyVar;
+       a = alphaTy; a_tv = alphaTyVar
        b = betaTy;  b_tv = betaTyVar;
     in
     mkGenPrimOp SLIT("raise#") [a_tv, b_tv] [a] b
+
+primOpInfo BlockAsyncExceptionsOp
+  = let
+      a = alphaTy; a_tv = alphaTyVar
+    in
+    mkGenPrimOp SLIT("blockAsyncExceptions#") [a_tv]
+       [ mkIOTy a, realWorldStatePrimTy ]
+       (unboxedPair [realWorldStatePrimTy,a])
+       
+primOpInfo UnblockAsyncExceptionsOp
+  = let
+      a = alphaTy; a_tv = alphaTyVar
+    in
+    mkGenPrimOp SLIT("unblockAsyncExceptions#") [a_tv]
+       [ mkIOTy a, realWorldStatePrimTy ]
+       (unboxedPair [realWorldStatePrimTy,a])
 \end{code}
 
 %************************************************************************
@@ -1412,6 +1524,25 @@ primOpInfo SameMVarOp
        mvar_ty = mkMVarPrimTy s elt
     in
     mkGenPrimOp SLIT("sameMVar#") [s_tv, elt_tv] [mvar_ty, mvar_ty] boolTy
+
+primOpInfo TryTakeMVarOp
+  = let
+       elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
+       state = mkStatePrimTy s
+    in
+    mkGenPrimOp SLIT("tryTakeMVar#") [s_tv, elt_tv]
+       [mkMVarPrimTy s elt, state]
+       (unboxedTriple [state, intPrimTy, elt])
+
+primOpInfo IsEmptyMVarOp
+  = let
+       elt = alphaTy; elt_tv = alphaTyVar; s = betaTy; s_tv = betaTyVar
+       state = mkStatePrimTy s
+    in
+    mkGenPrimOp SLIT("isEmptyMVar#") [s_tv, elt_tv]
+       [mkMVarPrimTy s elt, mkStatePrimTy s]
+       (unboxedPair [state, intPrimTy])
+
 \end{code}
 
 %************************************************************************
@@ -1457,11 +1588,23 @@ primOpInfo ForkOp
        [alphaTy, realWorldStatePrimTy]
        (unboxedPair [realWorldStatePrimTy, threadIdPrimTy])
 
--- killThread# :: ThreadId# -> State# RealWorld -> State# RealWorld
+-- killThread# :: ThreadId# -> exception -> State# RealWorld -> State# RealWorld
 primOpInfo KillThreadOp
-  = mkGenPrimOp SLIT("killThread#") [] 
-       [threadIdPrimTy, realWorldStatePrimTy]
+  = mkGenPrimOp SLIT("killThread#") [alphaTyVar] 
+       [threadIdPrimTy, alphaTy, realWorldStatePrimTy]
        realWorldStatePrimTy
+
+-- yield# :: State# RealWorld -> State# RealWorld
+primOpInfo YieldOp
+  = mkGenPrimOp SLIT("yield#") [] 
+       [realWorldStatePrimTy]
+       realWorldStatePrimTy
+
+-- myThreadId# :: State# RealWorld -> (# State# RealWorld, ThreadId# #)
+primOpInfo MyThreadIdOp
+  = mkGenPrimOp SLIT("myThreadId#") [] 
+       [realWorldStatePrimTy]
+       (unboxedPair [realWorldStatePrimTy, threadIdPrimTy])
 \end{code}
 
 ************************************************************************
@@ -1471,8 +1614,8 @@ primOpInfo KillThreadOp
 %************************************************************************
 
 \begin{code}
-primOpInfo MakeForeignObjOp
-  = mkGenPrimOp SLIT("makeForeignObj#") [] 
+primOpInfo MkForeignObjOp
+  = mkGenPrimOp SLIT("mkForeignObj#") [] 
        [addrPrimTy, realWorldStatePrimTy] 
        (unboxedPair [realWorldStatePrimTy, foreignObjPrimTy])
 
@@ -1502,13 +1645,13 @@ 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}
 
 The following operation dereferences a weak pointer.  The weak pointer
-may have been finalised, so the operation returns a result code which
+may have been finalized, so the operation returns a result code which
 must be inspected before looking at the dereferenced value.
 
        deRefWeak# :: Weak# v -> State# RealWorld ->
@@ -1527,41 +1670,87 @@ primOpInfo DeRefWeakOp
        (unboxedTriple [realWorldStatePrimTy, intPrimTy, alphaTy])
 \end{code}
 
+Weak pointers can be finalized early by using the finalize# operation:
+       
+       finalizeWeak# :: Weak# v -> State# RealWorld -> 
+                          (# State# RealWorld, Int#, IO () #)
+
+The Int# returned is either
+
+       0 if the weak pointer has already been finalized, or it has no
+         finalizer (the third component is then invalid).
+
+       1 if the weak pointer is still alive, with the finalizer returned
+         as the third component.
+
+\begin{code}
+primOpInfo FinalizeWeakOp
+ = mkGenPrimOp SLIT("finalizeWeak#") [alphaTyVar]
+       [mkWeakPrimTy alphaTy, realWorldStatePrimTy]
+       (unboxedTriple [realWorldStatePrimTy, intPrimTy,
+                       mkFunTy realWorldStatePrimTy 
+                         (unboxedPair [realWorldStatePrimTy,unitTy])])
+\end{code}
+
 %************************************************************************
 %*                                                                     *
-\subsubsection[PrimOp-stable-pointers]{PrimOpInfo for ``stable pointers''}
+\subsubsection[PrimOp-stable-pointers]{PrimOpInfo for stable pointers and stable names}
 %*                                                                     *
 %************************************************************************
 
-A {\em stable pointer} is an index into a table of pointers into the
-heap.  Since the garbage collector is told about stable pointers, it
-is safe to pass a stable pointer to external systems such as C
+A {\em stable name/pointer} is an index into a table of stable name
+entries.  Since the garbage collector is told about stable pointers,
+it is safe to pass a stable pointer to external systems such as C
 routines.
 
-Here's what the operations and types are supposed to be (from
-state-interface document).
-
 \begin{verbatim}
-makeStablePtr#  :: a -> State# _RealWorld -> (# State# _RealWorld, a #)
-freeStablePtr#  :: StablePtr# a -> State# _RealWorld -> State# _RealWorld
-deRefStablePtr# :: StablePtr# a -> State# _RealWorld -> (# State# _RealWorld, a #)
+makeStablePtr#  :: a -> State# RealWorld -> (# State# RealWorld, StablePtr# a #)
+freeStablePtr   :: StablePtr# a -> State# RealWorld -> State# RealWorld
+deRefStablePtr# :: StablePtr# a -> State# RealWorld -> (# State# RealWorld, a #)
 eqStablePtr#    :: StablePtr# a -> StablePtr# a -> Int#
 \end{verbatim}
 
-It may seem a bit surprising that @makeStablePtr#@ is a @PrimIO@
+It may seem a bit surprising that @makeStablePtr#@ is a @IO@
 operation since it doesn't (directly) involve IO operations.  The
 reason is that if some optimisation pass decided to duplicate calls to
 @makeStablePtr#@ and we only pass one of the stable pointers over, a
-massive space leak can result.  Putting it into the PrimIO monad
+massive space leak can result.  Putting it into the IO monad
 prevents this.  (Another reason for putting them in a monad is to
-ensure correct sequencing wrt the side-effecting @freeStablePtr#@
+ensure correct sequencing wrt the side-effecting @freeStablePtr@
 operation.)
 
+An important property of stable pointers is that if you call
+makeStablePtr# twice on the same object you get the same stable
+pointer back.
+
 Note that we can implement @freeStablePtr#@ using @_ccall_@ (and,
 besides, it's not likely to be used from Haskell) so it's not a
 primop.
 
-Question: Why @_RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
+Question: Why @RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
+
+Stable Names
+~~~~~~~~~~~~
+
+A stable name is like a stable pointer, but with three important differences:
+
+       (a) You can't deRef one to get back to the original object.
+       (b) You can convert one to an Int.
+       (c) You don't need to 'freeStableName'
+
+The existence of a stable name doesn't guarantee to keep the object it
+points to alive (unlike a stable pointer), hence (a).
+
+Invariants:
+       
+       (a) makeStableName always returns the same value for a given
+           object (same as stable pointers).
+
+       (b) if two stable names are equal, it implies that the objects
+           from which they were created were the same.
+
+       (c) stableNameToInt always returns the same Int for a given
+           stable name.
 
 \begin{code}
 primOpInfo MakeStablePtrOp
@@ -1579,6 +1768,22 @@ primOpInfo EqStablePtrOp
   = mkGenPrimOp SLIT("eqStablePtr#") [alphaTyVar, betaTyVar]
        [mkStablePtrPrimTy alphaTy, mkStablePtrPrimTy betaTy]
        intPrimTy
+
+primOpInfo MakeStableNameOp
+  = mkGenPrimOp SLIT("makeStableName#") [alphaTyVar]
+       [alphaTy, realWorldStatePrimTy]
+       (unboxedPair [realWorldStatePrimTy, 
+                       mkTyConApp stableNamePrimTyCon [alphaTy]])
+
+primOpInfo EqStableNameOp
+  = mkGenPrimOp SLIT("eqStableName#") [alphaTyVar, betaTyVar]
+       [mkStableNamePrimTy alphaTy, mkStableNamePrimTy betaTy]
+       intPrimTy
+
+primOpInfo StableNameToIntOp
+  = mkGenPrimOp SLIT("stableNameToInt#") [alphaTyVar]
+       [mkStableNamePrimTy alphaTy]
+       intPrimTy
 \end{code}
 
 %************************************************************************
@@ -1644,119 +1849,176 @@ primOpInfo ParOp      -- par# :: a -> Int#
 -- HWL: The first 4 Int# in all par... annotations denote:
 --   name, granularity info, size of result, degree of parallelism
 --      Same  structure as _seq_ i.e. returns Int#
+-- KSW: v, the second arg in parAt# and parAtForNow#, is used only to determine
+--   `the processor containing the expression v'; it is not evaluated
 
-primOpInfo ParGlobalOp -- parGlobal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
+primOpInfo ParGlobalOp -- parGlobal# :: a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
   = mkGenPrimOp SLIT("parGlobal#")     [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
 
-primOpInfo ParLocalOp  -- parLocal# :: Int# -> Int# -> Int# -> Int# -> a -> b -> b
+primOpInfo ParLocalOp  -- parLocal# :: a -> Int# -> Int# -> Int# -> Int# -> b -> Int#
   = mkGenPrimOp SLIT("parLocal#")      [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
 
-primOpInfo ParAtOp     -- parAt# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
+primOpInfo ParAtOp     -- parAt# :: a -> v -> Int# -> Int# -> Int# -> Int# -> b -> Int#
   = mkGenPrimOp SLIT("parAt#") [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
 
-primOpInfo ParAtAbsOp  -- parAtAbs# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
+primOpInfo ParAtAbsOp  -- parAtAbs# :: a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
   = mkGenPrimOp SLIT("parAtAbs#")      [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
 
-primOpInfo ParAtRelOp  -- parAtRel# :: Int# -> Int# -> Int# -> Int# -> Int# -> a -> b -> b
+primOpInfo ParAtRelOp  -- parAtRel# :: a -> Int# -> Int# -> Int# -> Int# -> Int# -> b -> Int#
   = mkGenPrimOp SLIT("parAtRel#")      [alphaTyVar,betaTyVar] [alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,betaTy] intPrimTy
 
-primOpInfo ParAtForNowOp       -- parAtForNow# :: Int# -> Int# -> Int# -> Int# -> a -> b -> c -> c
+primOpInfo ParAtForNowOp -- parAtForNow# :: a -> v -> Int# -> Int# -> Int# -> Int# -> b -> Int#
   = mkGenPrimOp SLIT("parAtForNow#")   [alphaTyVar,betaTyVar,gammaTyVar] [betaTy,alphaTy,intPrimTy,intPrimTy,intPrimTy,intPrimTy,gammaTy] intPrimTy
 
-primOpInfo CopyableOp  -- copyable# :: a -> a
+primOpInfo CopyableOp  -- copyable# :: a -> Int#
   = mkGenPrimOp SLIT("copyable#")      [alphaTyVar] [alphaTy] intPrimTy
 
-primOpInfo NoFollowOp  -- noFollow# :: a -> a
+primOpInfo NoFollowOp  -- noFollow# :: a -> Int#
   = mkGenPrimOp SLIT("noFollow#")      [alphaTyVar] [alphaTy] intPrimTy
 \end{code}
 
 %************************************************************************
 %*                                                                     *
-\subsubsection[PrimOp-IO-etc]{PrimOpInfo for C calls, and I/O-ish things}
+\subsubsection[PrimOp-tag]{PrimOpInfo for @dataToTag#@ and @tagToEnum#@}
 %*                                                                     *
 %************************************************************************
 
+These primops are pretty wierd.
+
+       dataToTag# :: a -> Int    (arg must be an evaluated data type)
+       tagToEnum# :: Int -> a    (result type must be an enumerated type)
+
+The constraints aren't currently checked by the front end, but the
+code generator will fall over if they aren't satisfied.
+
 \begin{code}
-primOpInfo (CCallOp _ _ _ _)
-     = mkGenPrimOp SLIT("ccall#") [alphaTyVar] [] alphaTy
+primOpInfo DataToTagOp
+  = mkGenPrimOp SLIT("dataToTag#") [alphaTyVar] [alphaTy] intPrimTy
+
+primOpInfo TagToEnumOp
+  = mkGenPrimOp SLIT("tagToEnum#") [alphaTyVar] [intPrimTy] alphaTy
 
-{-
-primOpInfo (CCallOp _ _ _ _ arg_tys result_ty)
-  = mkGenPrimOp SLIT("ccall#") [] arg_tys result_tycon tys_applied
-  where
-    (result_tycon, tys_applied, _) = splitAlgTyConApp result_ty
--}
 #ifdef DEBUG
-primOpInfo op = panic ("primOpInfo:"++ show (I# (tagOf_PrimOp op)))
+primOpInfo op = pprPanic "primOpInfo:" (ppr op)
 #endif
 \end{code}
 
+%************************************************************************
+%*                                                                     *
+\subsubsection[PrimOp-ool]{Which PrimOps are out-of-line}
+%*                                                                     *
+%************************************************************************
+
 Some PrimOps need to be called out-of-line because they either need to
 perform a heap check or they block.
 
 \begin{code}
 primOpOutOfLine op
   = case op of
-       TakeMVarOp              -> True
-       PutMVarOp               -> True
-       DelayOp                 -> True
-       WaitReadOp              -> True
-       WaitWriteOp             -> True
-       CatchOp                 -> True
-       RaiseOp                 -> True
-       NewArrayOp              -> True
-       NewByteArrayOp _        -> True
-       IntegerAddOp            -> True
-       IntegerSubOp            -> True
-       IntegerMulOp            -> True
-       IntegerGcdOp            -> True
-       IntegerQuotRemOp        -> True
-       IntegerDivModOp         -> True
-       Int2IntegerOp           -> True
-       Word2IntegerOp          -> True
-       Addr2IntegerOp          -> True
-       Word64ToIntegerOp       -> True
-       Int64ToIntegerOp        -> True
-       FloatDecodeOp           -> True
-       DoubleDecodeOp          -> True
-       MkWeakOp                -> True
-       DeRefWeakOp             -> True
-       MakeForeignObjOp        -> True
-       MakeStablePtrOp         -> True
-       NewMutVarOp             -> True
-       NewMVarOp               -> True
-       ForkOp                  -> True
-       KillThreadOp            -> True
-       CCallOp _ _ may_gc@True _ -> True       -- _ccall_GC_
-       _                       -> False
+       TakeMVarOp                   -> True
+       TryTakeMVarOp                -> True
+       PutMVarOp                    -> True
+       DelayOp                      -> True
+       WaitReadOp                   -> True
+       WaitWriteOp                  -> True
+       CatchOp                      -> True
+       RaiseOp                      -> True
+       BlockAsyncExceptionsOp       -> True
+       UnblockAsyncExceptionsOp     -> True
+       NewArrayOp                   -> True
+       NewByteArrayOp _             -> True
+       IntegerAddOp                 -> True
+       IntegerSubOp                 -> True
+       IntegerMulOp                 -> True
+       IntegerGcdOp                 -> True
+       IntegerDivExactOp            -> True
+       IntegerQuotOp                -> True
+       IntegerRemOp                 -> True
+       IntegerQuotRemOp             -> True
+       IntegerDivModOp              -> True
+       Int2IntegerOp                -> True
+       Word2IntegerOp               -> True
+       Addr2IntegerOp               -> True
+       Word64ToIntegerOp            -> True
+       Int64ToIntegerOp             -> True
+       FloatDecodeOp                -> True
+       DoubleDecodeOp               -> True
+       MkWeakOp                     -> True
+       FinalizeWeakOp               -> True
+       MakeStableNameOp             -> True
+       MkForeignObjOp               -> True
+       NewMutVarOp                  -> True
+       NewMVarOp                    -> True
+       ForkOp                       -> True
+       KillThreadOp                 -> True
+       YieldOp                      -> True
+
+       UnsafeThawArrayOp            -> True
+         -- UnsafeThawArrayOp doesn't perform any heap checks,
+         -- but it is of such an esoteric nature that
+         -- it is done out-of-line rather than require
+         -- the NCG to implement it.
+
+       CCallOp c_call -> ccallMayGC c_call
+
+       other -> False
 \end{code}
 
+
+primOpOkForSpeculation
+~~~~~~~~~~~~~~~~~~~~~~
 Sometimes we may choose to execute a PrimOp even though it isn't
 certain that its result will be required; ie execute them
 ``speculatively''.  The same thing as ``cheap eagerness.'' Usually
 this is OK, because PrimOps are usually cheap, but it isn't OK for
 (a)~expensive PrimOps and (b)~PrimOps which can fail.
 
+PrimOps that have side effects also should not be executed speculatively.
+
+Ok-for-speculation also means that it's ok *not* to execute the
+primop. For example
+       case op a b of
+         r -> 3
+Here the result is not used, so we can discard the primop.  Anything
+that has side effects mustn't be dicarded in this way, of course!
+
 See also @primOpIsCheap@ (below).
 
-PrimOps that have side effects also should not be executed speculatively
-or by data dependencies.
 
 \begin{code}
 primOpOkForSpeculation :: PrimOp -> Bool
+       -- See comments with CoreUtils.exprOkForSpeculation
 primOpOkForSpeculation op 
   = not (primOpCanFail op || primOpHasSideEffects op || primOpOutOfLine op)
 \end{code}
 
+
+primOpIsCheap
+~~~~~~~~~~~~~
 @primOpIsCheap@, as used in \tr{SimplUtils.lhs}.  For now (HACK
 WARNING), we just borrow some other predicates for a
 what-should-be-good-enough test.  "Cheap" means willing to call it more
 than once.  Evaluation order is unaffected.
 
 \begin{code}
+primOpIsCheap :: PrimOp -> Bool
+       -- See comments with CoreUtils.exprOkForSpeculation
 primOpIsCheap op = not (primOpHasSideEffects op || primOpOutOfLine op)
 \end{code}
 
+primOpIsDupable
+~~~~~~~~~~~~~~~
+primOpIsDupable means that the use of the primop is small enough to
+duplicate into different case branches.  See CoreUtils.exprIsDupable.
+
+\begin{code}
+primOpIsDupable :: PrimOp -> Bool
+       -- See comments with CoreUtils.exprIsDupable
+       -- We say it's dupable it isn't implemented by a C call with a wrapper
+primOpIsDupable op = not (primOpNeedsWrapper op)
+\end{code}
+
+
 \begin{code}
 primOpCanFail :: PrimOp -> Bool
 -- Int.
@@ -1788,24 +2050,43 @@ duplicated.
 \begin{code}
 primOpHasSideEffects :: PrimOp -> Bool
 
-primOpHasSideEffects TakeMVarOp        = True
-primOpHasSideEffects DelayOp           = True
-primOpHasSideEffects WaitReadOp        = True
-primOpHasSideEffects WaitWriteOp       = True
-
 primOpHasSideEffects ParOp            = True
 primOpHasSideEffects ForkOp           = True
 primOpHasSideEffects KillThreadOp      = True
+primOpHasSideEffects YieldOp          = True
 primOpHasSideEffects SeqOp            = True
 
-primOpHasSideEffects MakeForeignObjOp  = True
+primOpHasSideEffects MkForeignObjOp    = True
 primOpHasSideEffects WriteForeignObjOp = True
 primOpHasSideEffects MkWeakOp                 = True
 primOpHasSideEffects DeRefWeakOp       = True
+primOpHasSideEffects FinalizeWeakOp    = True
 primOpHasSideEffects MakeStablePtrOp   = True
+primOpHasSideEffects MakeStableNameOp  = True
 primOpHasSideEffects EqStablePtrOp     = True  -- SOF
 primOpHasSideEffects DeRefStablePtrOp  = True  -- ??? JSM & ADR
 
+-- In general, writes are considered a side effect, but 
+--     reads and variable allocations are not
+-- Why?  Because writes must not be omitted, but reads can be if their result is not used.
+-- (Sequencing of reads is maintained by data dependencies on the resulting
+-- world state.)
+primOpHasSideEffects WriteArrayOp         = True
+primOpHasSideEffects (WriteByteArrayOp _)  = True
+primOpHasSideEffects (WriteOffAddrOp _)           = True
+primOpHasSideEffects WriteMutVarOp        = True
+
+primOpHasSideEffects UnsafeFreezeArrayOp       = True
+primOpHasSideEffects UnsafeFreezeByteArrayOp   = True
+primOpHasSideEffects UnsafeThawArrayOp         = True
+
+primOpHasSideEffects TakeMVarOp        = True
+primOpHasSideEffects TryTakeMVarOp     = True
+primOpHasSideEffects PutMVarOp         = True
+primOpHasSideEffects DelayOp           = True
+primOpHasSideEffects WaitReadOp        = True
+primOpHasSideEffects WaitWriteOp       = True
+
 primOpHasSideEffects ParGlobalOp       = True
 primOpHasSideEffects ParLocalOp                = True
 primOpHasSideEffects ParAtOp           = True
@@ -1814,9 +2095,7 @@ primOpHasSideEffects ParAtRelOp           = True
 primOpHasSideEffects ParAtForNowOp     = True
 primOpHasSideEffects CopyableOp                = True  -- Possibly not.  ASP 
 primOpHasSideEffects NoFollowOp                = True  -- Possibly not.  ASP
-
--- CCall
-primOpHasSideEffects (CCallOp  _ _ _ _) = True
+primOpHasSideEffects (CCallOp _)       = True
 
 primOpHasSideEffects other = False
 \end{code}
@@ -1827,11 +2106,12 @@ any live variables that are stored in caller-saves registers.
 \begin{code}
 primOpNeedsWrapper :: PrimOp -> Bool
 
-primOpNeedsWrapper (CCallOp _ _ _ _)    = True
+primOpNeedsWrapper (CCallOp _)                 = True
 
 primOpNeedsWrapper Integer2IntOp       = True
 primOpNeedsWrapper Integer2WordOp      = True
 primOpNeedsWrapper IntegerCmpOp                = True
+primOpNeedsWrapper IntegerCmpIntOp     = True
 
 primOpNeedsWrapper FloatExpOp          = True
 primOpNeedsWrapper FloatLogOp          = True
@@ -1846,7 +2126,6 @@ primOpNeedsWrapper FloatSinhOp            = True
 primOpNeedsWrapper FloatCoshOp         = True
 primOpNeedsWrapper FloatTanhOp         = True
 primOpNeedsWrapper FloatPowerOp                = True
-primOpNeedsWrapper FloatEncodeOp       = True
 
 primOpNeedsWrapper DoubleExpOp         = True
 primOpNeedsWrapper DoubleLogOp         = True
@@ -1861,9 +2140,8 @@ primOpNeedsWrapper DoubleSinhOp           = True
 primOpNeedsWrapper DoubleCoshOp                = True
 primOpNeedsWrapper DoubleTanhOp                = True
 primOpNeedsWrapper DoublePowerOp       = True
-primOpNeedsWrapper DoubleEncodeOp      = True
 
-primOpNeedsWrapper MakeStablePtrOp     = True
+primOpNeedsWrapper MakeStableNameOp    = True
 primOpNeedsWrapper DeRefStablePtrOp    = True
 
 primOpNeedsWrapper DelayOp             = True
@@ -1874,19 +2152,15 @@ primOpNeedsWrapper other_op             = False
 \end{code}
 
 \begin{code}
-primOpOcc op
+primOpArity :: PrimOp -> Arity
+primOpArity op 
   = case (primOpInfo op) of
-      Dyadic     occ _        -> occ
-      Monadic    occ _        -> occ
-      Compare    occ _        -> occ
-      GenPrimOp  occ _ _ _     -> occ
-\end{code}
-
-\begin{code}
-primOpUniq :: PrimOp -> Unique
-primOpUniq op = mkPrimOpIdUnique (IBOX(tagOf_PrimOp op))
-
-primOpType :: PrimOp -> Type
+      Monadic occ ty                     -> 1
+      Dyadic occ ty                      -> 2
+      Compare occ ty                     -> 2
+      GenPrimOp occ tyvars arg_tys res_ty -> length arg_tys
+               
+primOpType :: PrimOp -> Type  -- you may want to use primOpSig instead
 primOpType op
   = case (primOpInfo op) of
       Dyadic occ ty ->     dyadic_fun_ty ty
@@ -1895,6 +2169,145 @@ primOpType op
 
       GenPrimOp occ tyvars arg_tys res_ty -> 
        mkForAllTys tyvars (mkFunTys arg_tys res_ty)
+
+mkPrimOpIdName :: PrimOp -> Id -> Name
+       -- Make the name for the PrimOp's Id
+       -- We have to pass in the Id itself because it's a WiredInId
+       -- and hence recursive
+mkPrimOpIdName op id
+  = mkWiredInIdName key pREL_GHC occ_name id
+  where
+    occ_name = primOpOcc op
+    key             = mkPrimOpIdUnique (primOpTag op)
+
+
+primOpRdrName :: PrimOp -> RdrName 
+primOpRdrName op = mkRdrQual pREL_GHC_Name (primOpOcc op)
+
+primOpOcc :: PrimOp -> OccName
+primOpOcc op = case (primOpInfo op) of
+                             Dyadic    occ _     -> occ
+                             Monadic   occ _     -> occ
+                             Compare   occ _     -> occ
+                             GenPrimOp occ _ _ _ -> occ
+
+-- primOpSig is like primOpType but gives the result split apart:
+-- (type variables, argument types, result type)
+-- It also gives arity, strictness info
+
+primOpSig :: PrimOp -> ([TyVar], [Type], Type, Arity, StrictnessInfo)
+primOpSig op
+  = (tyvars, arg_tys, res_ty, arity, primOpStrictness arity op)
+  where
+    arity = length arg_tys
+    (tyvars, arg_tys, res_ty)
+      = case (primOpInfo op) of
+         Monadic   occ ty -> ([],     [ty],    ty    )
+         Dyadic    occ ty -> ([],     [ty,ty], ty    )
+         Compare   occ ty -> ([],     [ty,ty], boolTy)
+         GenPrimOp occ tyvars arg_tys res_ty
+                           -> (tyvars, arg_tys, res_ty)
+
+-- primOpUsg is like primOpSig but the types it yields are the
+-- appropriate sigma (i.e., usage-annotated) types,
+-- as required by the UsageSP inference.
+
+primOpUsg :: PrimOp -> ([TyVar],[Type],Type)
+primOpUsg op
+  = case op of
+
+      -- Refer to comment by `otherwise' clause; we need consider here
+      -- *only* primops that have arguments or results containing Haskell
+      -- pointers (things that are pointed).  Unpointed values are
+      -- irrelevant to the usage analysis.  The issue is whether pointed
+      -- values may be entered or duplicated by the primop.
+
+      -- Remember that primops are *never* partially applied.
+
+      NewArrayOp           -> mangle [mkP, mkM, mkP     ] mkM
+      SameMutableArrayOp   -> mangle [mkP, mkP          ] mkM
+      ReadArrayOp          -> mangle [mkM, mkP, mkP     ] mkM
+      WriteArrayOp         -> mangle [mkM, mkP, mkM, mkP] mkR
+      IndexArrayOp         -> mangle [mkM, mkP          ] mkM
+      UnsafeFreezeArrayOp  -> mangle [mkM, mkP          ] mkM
+      UnsafeThawArrayOp    -> mangle [mkM, mkP          ] mkM
+
+      NewMutVarOp          -> mangle [mkM, mkP          ] mkM
+      ReadMutVarOp         -> mangle [mkM, mkP          ] mkM
+      WriteMutVarOp        -> mangle [mkM, mkM, mkP     ] mkR
+      SameMutVarOp         -> mangle [mkP, mkP          ] mkM
+
+      CatchOp              -> --     [mkO, mkO . (inFun mkM mkO)] mkO
+                              mangle [mkM, mkM . (inFun mkM mkM), mkP] mkM
+                              -- might use caught action multiply
+      RaiseOp              -> mangle [mkM               ] mkM
+
+      NewMVarOp            -> mangle [mkP               ] mkR
+      TakeMVarOp           -> mangle [mkM, mkP          ] mkM
+      PutMVarOp            -> mangle [mkM, mkM, mkP     ] mkR
+      SameMVarOp           -> mangle [mkP, mkP          ] mkM
+      TryTakeMVarOp        -> mangle [mkM, mkP          ] mkM
+      IsEmptyMVarOp        -> mangle [mkP, mkP          ] mkM
+
+      ForkOp               -> mangle [mkO, mkP          ] mkR
+      KillThreadOp         -> mangle [mkP, mkM, mkP     ] mkR
+
+      MkWeakOp             -> mangle [mkZ, mkM, mkM, mkP] mkM
+      DeRefWeakOp          -> mangle [mkM, mkP          ] mkM
+      FinalizeWeakOp       -> mangle [mkM, mkP          ] (mkR . (inUB [id,id,inFun mkR mkM]))
+
+      MakeStablePtrOp      -> mangle [mkM, mkP          ] mkM
+      DeRefStablePtrOp     -> mangle [mkM, mkP          ] mkM
+      EqStablePtrOp        -> mangle [mkP, mkP          ] mkR
+      MakeStableNameOp     -> mangle [mkZ, mkP          ] mkR
+      EqStableNameOp       -> mangle [mkP, mkP          ] mkR
+      StableNameToIntOp    -> mangle [mkP               ] mkR
+
+      ReallyUnsafePtrEqualityOp -> mangle [mkZ, mkZ     ] mkR
+
+      SeqOp                -> mangle [mkO               ] mkR
+      ParOp                -> mangle [mkO               ] mkR
+      ParGlobalOp          -> mangle [mkO, mkP, mkP, mkP, mkP, mkM] mkM
+      ParLocalOp           -> mangle [mkO, mkP, mkP, mkP, mkP, mkM] mkM
+      ParAtOp              -> mangle [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM
+      ParAtAbsOp           -> mangle [mkO, mkP, mkP, mkP, mkP, mkM] mkM
+      ParAtRelOp           -> mangle [mkO, mkP, mkP, mkP, mkP, mkM] mkM
+      ParAtForNowOp        -> mangle [mkO, mkZ, mkP, mkP, mkP, mkP, mkM] mkM
+      CopyableOp           -> mangle [mkZ               ] mkR
+      NoFollowOp           -> mangle [mkZ               ] mkR
+
+      CCallOp _           -> mangle [                  ] mkM
+
+      -- Things with no Haskell pointers inside: in actuality, usages are
+      -- irrelevant here (hence it doesn't matter that some of these
+      -- apparently permit duplication; since such arguments are never 
+      -- ENTERed anyway, the usage annotation they get is entirely irrelevant
+      -- except insofar as it propagates to infect other values that *are*
+      -- pointed.
+
+      otherwise            -> nomangle
+                                    
+  where mkZ          = mkUsgTy UsOnce  -- pointed argument used zero
+        mkO          = mkUsgTy UsOnce  -- pointed argument used once
+        mkM          = mkUsgTy UsMany  -- pointed argument used multiply
+        mkP          = mkUsgTy UsOnce  -- unpointed argument
+        mkR          = mkUsgTy UsMany  -- unpointed result
+  
+        (tyvars, arg_tys, res_ty, _, _) = primOpSig op
+
+        nomangle     = (tyvars, map mkP arg_tys, mkR res_ty)
+
+        mangle fs g  = (tyvars, zipWithEqual "primOpUsg" ($) fs arg_tys, g res_ty)
+
+        inFun f g ty = case splitFunTy_maybe ty of
+                         Just (a,b) -> mkFunTy (f a) (g b)
+                         Nothing    -> pprPanic "primOpUsg:inFun" (ppr op <+> ppr ty)
+
+        inUB fs ty  = case splitTyConApp_maybe ty of
+                        Just (tc,tys) -> ASSERT( tc == tupleTyCon Unboxed (length fs) )
+                                         mkTupleTy Unboxed (length fs) (zipWithEqual "primOpUsg"
+                                                                         ($) fs tys)
+                        Nothing       -> pprPanic "primOpUsg:inUB" (ppr op <+> ppr ty)
 \end{code}
 
 \begin{code}
@@ -1907,12 +2320,13 @@ data PrimOpResultInfo
 -- be out of line, or the code generator won't work.
 
 getPrimOpResultInfo :: PrimOp -> PrimOpResultInfo
-
+getPrimOpResultInfo (CCallOp _)
+  = ReturnsAlg unboxedPairTyCon
 getPrimOpResultInfo op
   = case (primOpInfo op) of
       Dyadic  _ ty              -> ReturnsPrim (typePrimRep ty)
       Monadic _ ty              -> ReturnsPrim (typePrimRep ty)
-      Compare _ ty              -> ReturnsAlg  boolTyCon
+      Compare _ ty              -> ReturnsAlg boolTyCon
       GenPrimOp _ _ _ ty        -> 
        let rep = typePrimRep ty in
        case rep of
@@ -1920,13 +2334,6 @@ getPrimOpResultInfo op
                        Nothing -> panic "getPrimOpResultInfo"
                        Just (tc,_,_) -> ReturnsAlg tc
           other -> ReturnsPrim other
-
-isCompareOp :: PrimOp -> Bool
-
-isCompareOp op
-  = case primOpInfo op of
-      Compare _ _ -> True
-      _                  -> False
 \end{code}
 
 The commutable ops are those for which we will try to move constants
@@ -1947,6 +2354,7 @@ commutableOp IntNeOp        = True
 commutableOp IntegerAddOp = True
 commutableOp IntegerMulOp = True
 commutableOp IntegerGcdOp = True
+commutableOp IntegerIntGcdOp = True
 commutableOp FloatAddOp          = True
 commutableOp FloatMulOp          = True
 commutableOp FloatEqOp   = True
@@ -1960,6 +2368,15 @@ commutableOp _             = False
 
 Utils:
 \begin{code}
+mkPrimTyApp :: [TyVar] -> PrimRep -> ([TyVar], Type)
+       -- CharRep       -->  ([],  Char#)
+       -- StablePtrRep  -->  ([a], StablePtr# a)
+mkPrimTyApp tvs kind
+  = (forall_tvs, mkTyConApp tycon (mkTyVarTys forall_tvs))
+  where
+    tycon      = primRepTyCon kind
+    forall_tvs = take (tyConArity tycon) tvs
+
 dyadic_fun_ty  ty = mkFunTys [ty, ty] ty
 monadic_fun_ty ty = mkFunTy  ty ty
 compare_fun_ty ty = mkFunTys [ty, ty] boolTy
@@ -1969,35 +2386,92 @@ Output stuff:
 \begin{code}
 pprPrimOp  :: PrimOp -> SDoc
 
-pprPrimOp (CCallOp fun is_casm may_gc cconv)
-  = let
+pprPrimOp (CCallOp c_call) = pprCCallOp c_call
+pprPrimOp other_op
+  = getPprStyle $ \ sty ->
+    if ifaceStyle sty then     -- For interfaces Print it qualified with PrelGHC.
+       ptext SLIT("PrelGHC.") <> pprOccName occ
+    else
+       pprOccName occ
+  where
+    occ = primOpOcc other_op
+\end{code}
+
+
+%************************************************************************
+%*                                                                     *
+\subsubsection{CCalls}
+%*                                                                     *
+%************************************************************************
+
+A special ``trap-door'' to use in making calls direct to C functions:
+\begin{code}
+data CCall
+  =  CCall     CCallTarget
+               Bool            -- True <=> really a "casm"
+               Bool            -- True <=> might invoke Haskell GC
+               CallConv        -- calling convention to use.
+  deriving( Eq )
+
+data CCallTarget
+  = StaticTarget  CLabelString  -- An "unboxed" ccall# to `fn'.
+  | DynamicTarget Unique       -- First argument (an Addr#) is the function pointer
+                               --   (unique is used to generate a 'typedef' to cast
+                               --    the function pointer if compiling the ccall# down to
+                               --    .hc code - can't do this inline for tedious reasons.)
+
+instance Eq CCallTarget where
+  (StaticTarget l1) == (StaticTarget l2) = l1 == l2
+  (DynamicTarget _) == (DynamicTarget _) = True        
+       -- Ignore the arbitrary unique; this is important when comparing
+       -- a dynamic ccall read from an interface file A.hi with the
+       -- one constructed from A.hs, when deciding whether the interface
+       -- has changed
+  t1 == t2 = False
+
+ccallMayGC :: CCall -> Bool
+ccallMayGC (CCall _ _ may_gc _) = may_gc
+
+ccallIsCasm :: CCall -> Bool
+ccallIsCasm (CCall _ c_asm _ _) = c_asm
+
+isDynamicTarget (DynamicTarget _) = True
+isDynamicTarget (StaticTarget _)  = False
+
+dynamicTarget :: CCallTarget
+dynamicTarget = DynamicTarget (panic "Unique in DynamicTarget not yet set")
+       -- The unique is really only to do with code generation, so it
+       -- is only set in CoreToStg; before then it's just an error message
+
+setCCallUnique :: CCall -> Unique -> CCall
+setCCallUnique (CCall (DynamicTarget _) is_asm may_gc cconv) uniq
+  = CCall (DynamicTarget uniq) is_asm may_gc cconv
+setCCallUnique ccall uniq = ccall
+\end{code}
+
+\begin{code}
+pprCCallOp (CCall fun is_casm may_gc cconv)
+  = hcat [ ifPprDebug callconv
+        , text "__", ppr_dyn
+         , text before , ppr_fun , after]
+  where
         callconv = text "{-" <> pprCallConv cconv <> text "-}"
 
        before
-         | is_casm && may_gc = "__casm_GC ``"
-         | is_casm           = "__casm ``"
-         | may_gc            = "__ccall_GC "
-         | otherwise         = "__ccall "
+         | is_casm && may_gc = "casm_GC ``"
+         | is_casm           = "casm ``"
+         | may_gc            = "ccall_GC "
+         | otherwise         = "ccall "
 
        after
          | is_casm   = text "''"
          | otherwise = empty
-
-       ppr_fun =
-        case fun of
-          Right _ -> ptext SLIT("<dynamic>")
-          Left fn -> ptext fn
-        
-    in
-    hcat [ ifPprDebug callconv
-         , text before , ppr_fun , after]
-
-pprPrimOp other_op
-  = getPprStyle $ \ sty ->
-   if ifaceStyle sty then      -- For interfaces Print it qualified with PrelGHC.
-       ptext SLIT("PrelGHC.") <> pprOccName occ
-   else
-       pprOccName occ
-  where
-    occ = primOpOcc other_op
+         
+       ppr_dyn = case fun of
+                   DynamicTarget _ -> text "dyn_"
+                   _               -> empty
+
+       ppr_fun = case fun of
+                    DynamicTarget _ -> text "\"\""
+                    StaticTarget fn -> pprCLabelString fn
 \end{code}