[project @ 2001-12-07 15:49:41 by sof]
[ghc-hetmet.git] / ghc / compiler / ilxGen / IlxGen.lhs
index b081318..ffccf5e 100644 (file)
@@ -1,5 +1,5 @@
 %
-\section{Generate COM+ extended assembler}
+\section{Generate .NET extended IL}
 
 \begin{code}
 module IlxGen( ilxGen ) where
@@ -8,8 +8,7 @@ module IlxGen( ilxGen ) where
 
 import Char    ( ord, chr )
 import StgSyn
-import Id      ( idType, idName, isDeadBinder, idArityInfo )
-import IdInfo   ( arityLowerBound )
+import Id      ( idType, idName, isDeadBinder, idArity )
 import Var     ( Var, Id, TyVar, isId, isTyVar, tyVarKind, tyVarName )
 import VarEnv
 import VarSet   ( isEmptyVarSet )
@@ -54,6 +53,8 @@ import TysPrim  ( foreignObjPrimTyCon, weakPrimTyCon, byteArrayPrimTyCon, mutabl
 -- One day this will be configured by the command line.
 import CmdLineOpts     ( opt_InPackage, opt_SimplDoEtaReduction )
 
+import Util            ( lengthIs, equalLength )
+
 \end{code}
 
 
@@ -68,7 +69,8 @@ import CmdLineOpts    ( opt_InPackage, opt_SimplDoEtaReduction )
 ilxGen :: Module -> [TyCon] -> [(StgBinding,[Id])] -> SDoc
        -- The TyCons should include those arising from classes
 ilxGen mod tycons binds_w_srts
-  =  vcat [ text ".assembly extern 'mscorlib' {}",
+  =  vcat [ text ".module '" <> (ppr (moduleName mod)) <> hscOptionQual <> text "o'",
+           text ".assembly extern 'mscorlib' {}",
            vcat (map (ilxImportPackage topenv) (uniqSetToList import_packages)),
             vcat (map (ilxImportModule topenv) (uniqSetToList import_modules)),
             vcat (map (ilxImportTyCon topenv) (uniqSetToList import_tycons)),
@@ -771,7 +773,7 @@ ilxFunAppAfterPush env fun args tail_call
       case lookupIlxBindEnv env fun of
          Just (_, StgRhsClosure  _ _ _ Updatable _ _)   -> Nothing 
          Just (place, StgRhsClosure  _ _ fvs _ args _)  -> Just (place,fun,args,fvs)
-         _ -> Nothing -- trace (show fun ++ " --> " ++ show (arityLowerBound (idArityInfo fun)))
+         _ -> Nothing -- trace (show fun ++ " --> " ++ show (idArity fun))
 
 type KnownClosure = Maybe (  IlxEnv    -- Of the binding site of the function
                           , Id         -- The function
@@ -855,7 +857,7 @@ ilxFunAppArgs env num_sofar funty args tail_call known_clo
        = ([],[],env,args,funty)
     get_term_args n max args env funty
       | (case known_clo of
-           Just (_,_,needed,_) -> (length needed == n)
+           Just (_,_,needed,_) -> needed `lengthIs` n
            Nothing -> False)
        -- Stop if we have the optimal number for a direct call
        = ([],[],env,args,funty)
@@ -897,7 +899,7 @@ ilxFunAppArgs env num_sofar funty args tail_call known_clo
     -- the "callfunc" case.
     basic_call_instr =
       case known_clo of
-        Just (known_env,fun,needed,fvs) | (length needed == length now_args) && 
+        Just (known_env,fun,needed,fvs) | (equalLength needed now_args) && 
                                           all (\x -> elemIlxTyEnv x env) free_ilx_tvs -> 
            vcat [text "callclo class",
                  nameReference env (idName fun) <+> singleQuotes (ilxEnvQualifyByModule env (ppr fun)),
@@ -966,7 +968,7 @@ ilxRhs env rec (bndr, StgRhsClosure _ _ fvs upd args rhs)
   where
     pushFv id = if elem id rec then text "ldnull" else pushId env id
     (free_ilx_tvs, free_non_ilx_tvs,free_vs) = categorizeVars fvs
-    clotext = pprIlxBoxedTyConApp env (ilxEnvQualifyByModule env (ppr bndr)) (map mkTyVarTy free_ilx_tvs)
+    clotext = pprIlxNamedTyConApp env (ilxEnvQualifyByModule env (ppr bndr)) (map mkTyVarTy free_ilx_tvs)
 
 ilxFixupRec env rec (bndr, _) | isVoidIlxRepId bndr = ilxComment (text "no recursive fixup for void-rep-id")
 
@@ -982,7 +984,7 @@ ilxFixupRec env rec (bndr, StgRhsClosure _ _ fvs upd args rhs)
                           text "stclofld" <+> clotext <> text "," <+> pprId recid] 
                 else text "//no fixup needed for" <+> pprId recid
     (free_ilx_tvs, free_non_ilx_tvs,free_vs) = categorizeVars fvs
-    clotext = pprIlxBoxedTyConApp env (ilxEnvQualifyByModule env (ppr bndr)) (map mkTyVarTy free_ilx_tvs)
+    clotext = pprIlxNamedTyConApp env (ilxEnvQualifyByModule env (ppr bndr)) (map mkTyVarTy free_ilx_tvs)
 
 
 
@@ -1044,7 +1046,7 @@ ilxTopBind mod env pairs       =
 ilxTopRhs mod env (bndr, StgRhsClosure _ _ fvs upd args rhs)
   = vcat [vcat (map (pushId env) free_vs),
          (if null free_non_ilx_tvs then empty else (ilxComment (text "ignored some higher order type arguments in application - code will be non verifiable...."))),
-         text "newclo" <+> pprIlxBoxedTyConApp env (ilxEnvQualifyByModule env (ppr bndr)) (map mkTyVarTy free_ilx_tvs),
+         text "newclo" <+> pprIlxNamedTyConApp env (ilxEnvQualifyByModule env (ppr bndr)) (map mkTyVarTy free_ilx_tvs),
          text "stsfld"  <+> pprFieldRef env (mod,bndTy,bndr)
     ]
   where
@@ -1227,17 +1229,28 @@ ilxTypeR env (NoteTy _ ty)
 
 pprIlxFunTy dom ran = parens (hsep [text "func",parens dom,text "-->", ran])
 
-ilxTyConApp env tc args =
-   case lookupUFM tyPrimConTable (getUnique tc) of
+ilxTyConApp env tcon args =
+   case lookupUFM tyPrimConTable (getUnique tcon) of
        Just f  -> f args env
         Nothing -> 
-            (if isUnboxedTupleTyCon tc then pprIlxUnBoxedTyConApp else pprIlxBoxedTyConApp)
-              env ((nameReference env (getName tc)) <> (ppr tc)) args
+            (if isUnboxedTupleTyCon tcon then pprIlxUnboxedTupleTyConApp else pprIlxBoxedTyConApp)
+              env tcon args
 
-pprIlxUnBoxedTyConApp env tcdoc args = text "value class" <+> tcdoc <> pprTypeArgs ilxTypeL env args
-pprIlxBoxedTyConApp env tcdoc args = text "class" <+> tcdoc <> pprTypeArgs ilxTypeR env args
+pprIlxTyCon env tcon = nameReference env (getName tcon) <> ppr tcon
+pprIlxUnboxedTupleTyConApp env tcon args 
+  = text "/* unboxed */ value class" <+> pprIlxTyCon env tcon' <> pprTypeArgs ilxTypeL env non_void
+  where 
+   non_void = filter (not . isVoidIlxRepType) args
+   tcon' = dataConTyCon (tupleCon Unboxed (length non_void)) 
+pprIlxBoxedTyConApp env tcon args 
+  = pprIlxNamedTyConApp env (pprIlxTyCon env tcon) args
+pprIlxNamedTyConApp env tcon_text args 
+  = text "class" <+> tcon_text <> pprTypeArgs ilxTypeR env args
 
 -- Returns e.g: <Int32, Bool>
+-- Void-sized type arguments are _always_ eliminated, everywhere.
+-- If the type constructor is an unboxed tuple type then it should already have
+-- been adjusted to be the correct constructor.
 pprTypeArgs f env tys = pprTypeArgs_aux f env (filter (not . isVoidIlxRepType) tys)
 
 pprTypeArgs_aux f env []  = empty
@@ -1607,8 +1620,14 @@ splitTyArgs1 (StgTypeArg ty : args) = (ty:tys, args')
 splitTyArgs1 args                  = ([], args)
 
 ilxConRef env data_con
-    = pprId data_con <> pprValArgTys ilxTypeL env' (map deepIlxRepType (filter (not . isVoidIlxRepType) arg_tys))
+ | isUnboxedTupleCon data_con
+    = let data_con' = tupleCon Unboxed (length non_void_args)in 
+      pprId data_con' <> arg_text
+ | otherwise 
+    = pprId data_con <> arg_text
   where
+    arg_text = pprValArgTys ilxTypeL env' (map deepIlxRepType non_void_args)
+    non_void_args = filter (not . isVoidIlxRepType) arg_tys
     (tyvars, tau_ty) = splitForAllTys (dataConRepType data_con)
     (arg_tys, _)     = splitFunTys tau_ty
     env'            = formalIlxEnv env tyvars
@@ -1668,8 +1687,8 @@ ilxTypeL2 ty env = ilxTypeL env ty
 ilxTypeR2 :: Type -> IlxTyFrag
 ilxTypeR2 ty env = ilxTypeR env ty
 
-ilxMethA = ilxType "!!0"
-ilxMethB = ilxType "!!1"
+ilxMethTyVarA = ilxType "!!0"
+ilxMethTyVarB = ilxType "!!1"
 prelGHCReference :: IlxTyFrag
 prelGHCReference env =
    if ilxEnvModule env == mkHomeModule (mkModuleName "PrelGHC") then empty
@@ -1709,9 +1728,12 @@ repBCO = ilxTypeSeq [ilxType "class ",prelGHCReference,ilxType "PrelGHC_BCOzh"]
 ilxTyPair l r = ilxTyParams [l,r]
 ilxTyTriple l m r = ilxTyParams [l,m,r]
 ilxTyQuad l m1 m2 r = ilxTyParams [l,m1,m2,r]
-ilxUnboxedPairRep l r = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z1H",ilxTyPair l r]
-ilxUnboxedTripleRep l m r = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z2H",ilxTyTriple l m r]
-ilxUnboxedQuadRep l m1 m2 r = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z3H",ilxTyQuad l m1 m2 r]
+ilxUnboxedEmptyRep = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z1H"]
+ilxUnboxedPairRep l r = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z2H",ilxTyPair l r]
+ilxUnboxedTripleRep l m r = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z3H",ilxTyTriple l m r]
+ilxUnboxedQuadRep l m1 m2 r = ilxTypeSeq [ilxType "value class",prelGHCReference,ilxType "PrelGHC_Z4H",ilxTyQuad l m1 m2 r]
+
+ilxTyIO b = ilxTypeSeq [ilxType "(func ( /* unit skipped */ ) --> ", b, ilxType ")"]
 
 ilxTyParams :: [IlxTyFrag] -> IlxTyFrag
 ilxTyParams [] env = empty
@@ -1786,12 +1808,12 @@ ilxPrimOpTable op
        IntLtOp     -> simp_op ilxClt
        IntLeOp     -> simp_op ilxCle
 
-        IntToInt8Op  -> simp_op  (ilxOp"conv.i1")
-        IntToInt16Op  -> simp_op (ilxOp "conv.i2")
-        IntToInt32Op  -> simp_op (ilxOp "conv.i4")
-        WordToWord8Op  -> simp_op (ilxOp "conv.u1")
-        WordToWord16Op  -> simp_op (ilxOp "conv.u2")
-        WordToWord32Op  -> simp_op (ilxOp "conv.u4")
+        Narrow8IntOp   -> simp_op  (ilxOp"conv.i1")
+        Narrow16IntOp  -> simp_op (ilxOp "conv.i2")
+        Narrow32IntOp  -> simp_op (ilxOp "conv.i4")
+        Narrow8WordOp  -> simp_op (ilxOp "conv.u1")
+        Narrow16WordOp -> simp_op (ilxOp "conv.u2")
+        Narrow32WordOp -> simp_op (ilxOp "conv.u4")
 
        WordGtOp     -> simp_op ilxCgtUn
        WordGeOp     -> simp_op ilxCgeUn
@@ -1829,6 +1851,13 @@ ilxPrimOpTable op
        IntNegOp    -> simp_op (ilxOp "neg")
        IntRemOp    -> simp_op (ilxOp "rem")
 
+    -- Addr# ops:
+        AddrAddOp  -> simp_op (ilxOp "add")
+       AddrSubOp  -> simp_op (ilxOp "sub")
+       AddrRemOp  -> simp_op (ilxOp "rem")
+       Int2AddrOp -> warn_op "int2Addr" (simp_op (ilxOp "/* PrimOp int2Addr */ "))
+       Addr2IntOp -> warn_op "addr2Int" (simp_op (ilxOp "/* PrimOp addr2Int */ "))
+
     -- Word#-related ops:
        WordAddOp    -> simp_op (ilxOp "add")
        WordSubOp    -> simp_op (ilxOp "sub")
@@ -1836,8 +1865,6 @@ ilxPrimOpTable op
        WordQuotOp   -> simp_op (ilxOp "div")
        WordRemOp    -> simp_op (ilxOp "rem")
 
-       Addr2IntOp  -> simp_op (ilxOp "conv.i4") -- Addresses are very dodgy for ILX.  They are used for both C-strings and 
-       Int2AddrOp  -> simp_op (ilxOp "conv.i")  -- the FFI.  This needs more work.
        ISllOp      -> simp_op (ilxOp "shl")
        ISraOp      -> simp_op (ilxOp "shr")
        ISrlOp      -> simp_op (ilxOp "shr.un")
@@ -1931,9 +1958,9 @@ ilxPrimOpTable op
        Integer2WordOp     -> simp_op (ilxCallSuppMeth repWord "Integer2WordOp" [] [repInt, repByteArray])
        Int2IntegerOp      -> simp_op (ilxCallSuppMeth repInteger "Int2IntegerOp" [] [repInt])
        Word2IntegerOp     -> simp_op (ilxCallSuppMeth repInteger "Word2IntegerOp" [] [repWord])
-       IntegerToInt64Op   -> simp_op (ilxCallSuppMeth repInt64 "IntegerToInt64Op" [] [repInt,repByteArray])
+--     IntegerToInt64Op   -> simp_op (ilxCallSuppMeth repInt64 "IntegerToInt64Op" [] [repInt,repByteArray])
        Int64ToIntegerOp   -> simp_op (ilxCallSuppMeth repInteger "Int64ToIntegerOp" [] [repInt64])
-       IntegerToWord64Op  -> simp_op (ilxCallSuppMeth repWord64 "IntegerToWord64Op" [] [repInt,repByteArray])
+--     IntegerToWord64Op  -> simp_op (ilxCallSuppMeth repWord64 "IntegerToWord64Op" [] [repInt,repByteArray])
        Word64ToIntegerOp  -> simp_op (ilxCallSuppMeth repInteger "Word64ToIntegerOp" [] [repWord64])
 
 
@@ -2069,6 +2096,7 @@ ilxPrimOpTable op
                   {-    Addr# -> Int# -> Char# -> State# s -> State# s -} 
 
             {- should be monadic??? -}
+       NewPinnedByteArrayOp_Char -> warn_op "newPinnedByteArray" (simp_op (ilxOp "newarr [mscorlib]System.Byte "))
        NewByteArrayOp_Char      -> simp_op (ilxOp "newarr [mscorlib]System.Byte")
 --     NewByteArrayOp_Int       -> simp_op (ilxOp "newarr [mscorlib]System.Int32")
 --     NewByteArrayOp_Word      -> simp_op (ilxOp "newarr [mscorlib]System.UInt32")
@@ -2079,6 +2107,7 @@ ilxPrimOpTable op
 --      NewByteArrayOp_Int64     -> simp_op (ilxOp "newarr [mscorlib]System.Int64")  TODO: there is no unique for this one -}
 --      NewByteArrayOp_Word64    -> simp_op (ilxOp "newarr  [mscorlib]System.UInt64") -}
                   {- Int# -> State# s -> (# State# s, MutByteArr# s #) -}
+       ByteArrayContents_Char   -> warn_op "byteArrayContents" (simp_op ilxAddrOfByteArrOp)
 
        UnsafeFreezeByteArrayOp ->   ty1_op (\ty1  -> ilxOp "nop ")
                   {- MutByteArr# s -> State# s -> (# State# s, ByteArr# #) -}
@@ -2099,7 +2128,7 @@ ilxPrimOpTable op
        WriteMutVarOp -> ty2_op (\ty1 ty2 -> ilxOpSeq [ilxOp "stfld !0" , repMutVar ty1 ty2 , ilxOp "::contents"])
                  {- MutVar# s a -> a -> State# s -> State# s -}
 
-       NewArrayOp -> ty2_op (\ty1 ty2 -> ilxCallSuppMeth (ilxType "!!0[]") "newArray" [ty1] [repInt,ilxMethA])
+       NewArrayOp -> ty2_op (\ty1 ty2 -> ilxCallSuppMeth (ilxType "!!0[]") "newArray" [ty1] [repInt,ilxMethTyVarA])
                  {- Int# -> a -> State# s -> (# State# s, MutArr# s a #) -}
        IndexArrayOp -> ty1_op (\ty1 -> ilxOp "ldelem.ref")
                  {- Array# a -> Int# -> (# a #) -}
@@ -2118,7 +2147,8 @@ ilxPrimOpTable op
 
        RaiseOp -> ty2_op (\ty1 ty2 -> ilxOp "throw")
        CatchOp -> ty2_op (\ty1 ty2 -> 
-               ilxCallSuppMeth ilxMethA "'catch'" [ty1,ty2] [ilxOp "thunk<(func ( /* unit skipped */ ) --> !!0)>", ilxOp "thunk<(func (!!1) --> (func ( /* unit skipped */ ) --> !!0))>"])
+               ilxCallSuppMeth ilxMethTyVarA "'catch'" [ty1,ty2] [ilxLift (ilxTyIO (ilxType "!!0")), 
+                                                              ilxOp "thunk<(func (!!1) --> (func ( /* unit skipped */ ) --> !!0))>"])
                            {-        (State# RealWorld -> (# State# RealWorld, a #) )
                                   -> (b -> State# RealWorld -> (# State# RealWorld, a #) ) 
                                   -> State# RealWorld
@@ -2126,14 +2156,14 @@ ilxPrimOpTable op
                             -} 
 
        BlockAsyncExceptionsOp -> ty1_op (\ty1 -> 
-               ilxCallSuppMeth ilxMethA "blockAsyncExceptions" [ty1] [ilxOp "thunk<(func ( /* unit skipped */ ) --> !!0)>"])
+               ilxCallSuppMeth ilxMethTyVarA "blockAsyncExceptions" [ty1] [ilxLift (ilxTyIO (ilxType "!!0"))])
 
                 {-     (State# RealWorld -> (# State# RealWorld, a #))
                     -> (State# RealWorld -> (# State# RealWorld, a #))
                 -}
 
        UnblockAsyncExceptionsOp -> ty1_op (\ty1 -> 
-               ilxCallSuppMeth ilxMethA "unblockAsyncExceptions" [ty1] [ilxOp "thunk<(func ( /* unit skipped */ ) --> !!0)>"])
+               ilxCallSuppMeth ilxMethTyVarA "unblockAsyncExceptions" [ty1] [ilxLift (ilxTyIO (ilxType "!!0"))])
 
                 {-
                    State# RealWorld -> (# State# RealWorld, a #))
@@ -2145,42 +2175,42 @@ ilxPrimOpTable op
                  {- State# s -> (# State# s, MVar# s a #) -}
 
        TakeMVarOp -> ty2_op (\sty ty -> 
-               ilxCallSuppMeth ilxMethA "takeMVar" [ty] [repMVar ilxMethA])
+               ilxCallSuppMeth ilxMethTyVarA "takeMVar" [ty] [repMVar ilxMethTyVarA])
                   {-  MVar# s a -> State# s -> (# State# s, a #) -}
 
        -- These aren't yet right
         TryTakeMVarOp -> ty2_op (\sty ty -> 
-               ilxCallSuppMeth (ilxUnboxedPairRep repInt ilxMethA) "tryTakeMVar" [ty] [repMVar ilxMethA])
+               ilxCallSuppMeth (ilxUnboxedPairRep repInt ilxMethTyVarA) "tryTakeMVar" [ty] [repMVar ilxMethTyVarA])
                   {-  MVar# s a -> State# s -> (# State# s, a #) -}
 
        TryPutMVarOp -> ty2_op (\sty ty -> 
-               ilxCallSuppMeth repInt "tryPutMVar" [ty] [repMVar ilxMethA,ilxMethA])
+               ilxCallSuppMeth repInt "tryPutMVar" [ty] [repMVar ilxMethTyVarA,ilxMethTyVarA])
                   {-  MVar# s a -> State# s -> (# State# s, a #) -}
 
        PutMVarOp -> ty2_op (\sty ty -> 
-               ilxCallSuppMeth (ilxOp "void") "putMVar" [ty] [repMVar ilxMethA, ilxMethA])
+               ilxCallSuppMeth (ilxOp "void") "putMVar" [ty] [repMVar ilxMethTyVarA, ilxMethTyVarA])
                    {- MVar# s a -> a -> State# s -> State# s -}
 
        SameMVarOp -> ty2_op (\sty ty -> ilxCeq)
                    {- MVar# s a -> MVar# s a -> Bool -}
 
 --     TakeMaybeMVarOp -> ty2_op (\sty ty -> 
---             (ilxCallSuppMeth (ilxUnboxedPairRep repInt ilxMethA) "tryTakeMVar" [ty] [repMVar ilxMethA]))
+--             (ilxCallSuppMeth (ilxUnboxedPairRep repInt ilxMethTyVarA) "tryTakeMVar" [ty] [repMVar ilxMethTyVarA]))
 --              {- MVar# s a -> State# s -> (# State# s, Int#, a #) -}
 
        IsEmptyMVarOp -> ty2_op (\sty ty -> 
-               ilxCallSuppMeth repInt "isEmptyMVar" [ty] [repMVar ilxMethA])
+               ilxCallSuppMeth repInt "isEmptyMVar" [ty] [repMVar ilxMethTyVarA])
                {- MVar# s a -> State# s -> (# State# s, Int# #) -}
 
        TouchOp -> warn_op "touch" (ty1_op (\ty1 -> ilxOp "pop /* PrimOp touch */ "))
 
                {- a -> Int# -}
        DataToTagOp -> ty1_op (\ty1 -> 
-               ilxCallSuppMeth repInt "dataToTag" [ty1] [ilxMethA])
+               ilxCallSuppMeth repInt "dataToTag" [ty1] [ilxMethTyVarA])
                {- a -> Int# -}
 
        TagToEnumOp -> ty1_op (\ty1 -> 
-               ilxCallSuppMeth ilxMethA "tagToEnum" [ty1] [repInt])
+               ilxCallSuppMeth ilxMethTyVarA "tagToEnum" [ty1] [repInt])
                {- Int# -> a -}
 
        MakeStablePtrOp -> ty1_op (\ty1 -> ilxOpSeq [ilxOp "box", ty1, ilxOp "newobj void", repStablePtr {- ty1 -}, ilxOp "::.ctor(class [mscorlib]System.Object)"])
@@ -2199,11 +2229,12 @@ ilxPrimOpTable op
        EqStablePtrOp -> ty1_op (\ty1 -> ilxOp "ceq")
                  {-  StablePtr# a -> StablePtr# a -> Int# -}
 
-       MkWeakOp -> ty3_op (\ty1 ty2 ty3 ->  ilxCall (ilxMethodRef (repWeak ilxMethB) classWeak "bake" [ilxLift ty1,ilxLift ty2,ty3] [ilxMethA, ilxMethB, ilxLift (ilxOp "!!2")]))
+            -- The 3rd argument to MkWeakOp is always a IO Monad action, i.e. passed as () --> ()
+       MkWeakOp -> ty3_op (\ty1 ty2 ty3 ->  ilxCall (ilxMethodRef (repWeak ilxMethTyVarB) classWeak "bake" [ilxLift ty1,ilxLift ty2] [ilxMethTyVarA, ilxMethTyVarB, ilxLift (ilxTyIO ilxUnboxedEmptyRep)]))
                  {- o -> b -> c -> State# RealWorld -> (# State# RealWorld, Weak# b #) -}
 
-       DeRefWeakOp -> ty1_op (\ty1 ->  ilxCall (ilxMethodRef (ilxUnboxedPairRep repInt ilxMethA) classWeak "deref" [ty1] [repWeak ilxMethA]))
-       FinalizeWeakOp -> ty1_op (\ty1 ->  ilxCall (ilxMethodRef (ilxUnboxedPairRep repInt (ilxOp "thunk<(func ( /* unit skipped */ ) --> class '()')>")) classWeak "finalizer" [ty1] [repWeak ilxMethA]))
+       DeRefWeakOp -> ty1_op (\ty1 ->  ilxCall (ilxMethodRef (ilxUnboxedPairRep repInt ilxMethTyVarA) classWeak "deref" [ty1] [repWeak ilxMethTyVarA]))
+       FinalizeWeakOp -> ty1_op (\ty1 ->  ilxCall (ilxMethodRef (ilxUnboxedPairRep repInt (ilxTyIO ilxUnboxedEmptyRep)) classWeak "finalizer" [ty1] [repWeak ilxMethTyVarA]))
                    {-    Weak# a -> State# RealWorld -> (# State# RealWorld, Int#, 
        State# RealWorld -> (# State# RealWorld, Unit #)) #) -}
 
@@ -2213,7 +2244,12 @@ ilxPrimOpTable op
        YieldOp -> simp_op (ilxOpSeq [ilxOp "call class [mscorlib]System.Threading.Thread class [mscorlib]System.Threading.Thread::get_CurrentThread() 
                                 call instance void class [mscorlib]System.Threading.Thread::Suspend()"])
        MyThreadIdOp -> simp_op (ilxOpSeq [ilxOp "call default  class [mscorlib]System.Threading.Thread class [mscorlib]System.Threading.Thread::get_CurrentThread() "])
-       KillThreadOp -> ty1_op (\ty -> ilxOpSeq [ilxOp "box", ty, ilxOp "call instance void class [mscorlib]System.Threading.Thread::Abort(class [mscorlib]System.Object) "])
+       -- This pushes a THUNK across as the exception value.
+        -- This is the correct Haskell semantics...  TODO: we should probably
+        -- push across an HaskellThreadAbortException object that wraps this
+        -- thunk, but which is still actually an exception of
+        -- an appropriate type.
+        KillThreadOp -> ty1_op (\ty -> ilxOpSeq [ilxOp "call instance void class [mscorlib]System.Threading.Thread::Abort(class [mscorlib]System.Object) "])
               {-   ThreadId# -> a -> State# RealWorld -> State# RealWorld -}
 
        ForkOp -> warn_op "ForkOp" (simp_op (ilxOp "/* ForkOp skipped... */ newobj void [mscorlib]System.Object::.ctor() throw"))
@@ -2231,7 +2267,7 @@ ilxPrimOpTable op
        ParGlobalOp -> warn_op "ParGlobalOp" (simp_op (ilxOp " /* ParGlobalOp skipped... */ newobj void [mscorlib]System.Object::.ctor() throw"))
        SeqOp -> warn_op "SeqOp" (simp_op (ilxOp " newobj void [mscorlib]System.Object::.ctor() throw "))
        AddrToHValueOp -> warn_op "AddrToHValueOp" (simp_op (ilxOp "newobj void [mscorlib]System.Object::.ctor() throw"))
-       ReallyUnsafePtrEqualityOp -> simp_op (ilxOp "ceq")
+--     ReallyUnsafePtrEqualityOp -> simp_op (ilxOp "ceq")
 
         MkApUpd0_Op ->  warn_op "MkApUpd0_Op" (simp_op (ilxOp " newobj void [mscorlib]System.Object::.ctor() throw"))
         NewBCOOp ->  warn_op "NewBCOOp" (simp_op (ilxOp " newobj void [mscorlib]System.Object::.ctor() throw"))