[project @ 2001-11-26 09:20:25 by simonpj]
[ghc-hetmet.git] / ghc / compiler / prelude / TysWiredIn.lhs
index b0ebb94..18bf9a0 100644 (file)
@@ -30,24 +30,20 @@ module TysWiredIn (
        consDataCon,
        doubleDataCon,
        doubleTy,
-       isDoubleTy,
        doubleTyCon,
        falseDataCon, falseDataConId,
        floatDataCon,
        floatTy,
-       isFloatTy,
        floatTyCon,
 
        intDataCon,
        intTy,
        intTyCon,
-       isIntTy,
 
        integerTy,
        integerTyCon,
        smallIntegerDataCon,
        largeIntegerDataCon,
-       isIntegerTy,
 
        listTyCon,
 
@@ -73,18 +69,7 @@ module TysWiredIn (
        voidTy,
        wordDataCon,
        wordTy,
-       wordTyCon,
-
-       isFFIArgumentTy,     -- :: DynFlags -> Bool -> Type -> Bool
-       isFFIImportResultTy, -- :: DynFlags -> Type -> Bool
-       isFFIExportResultTy, -- :: Type -> Bool
-       isFFIExternalTy,     -- :: Type -> Bool
-        isFFIDynArgumentTy,  -- :: Type -> Bool
-       isFFIDynResultTy,    -- :: Type -> Bool
-       isFFILabelTy,        -- :: Type -> Bool
-       isAddrTy,            -- :: Type -> Bool
-       isForeignPtrTy       -- :: Type -> Bool
-
+       wordTyCon
     ) where
 
 #include "HsVersions.h"
@@ -103,21 +88,19 @@ import Name                ( Name, nameRdrName, nameUnique, nameOccName,
                          nameModule, mkWiredInName )
 import OccName         ( mkOccFS, tcName, dataName, mkWorkerOcc, mkGenOcc1, mkGenOcc2 )
 import RdrName         ( rdrNameOcc )
-import DataCon         ( DataCon, StrictnessMark(..),  mkDataCon, dataConId )
+import DataCon         ( DataCon, mkDataCon, dataConId )
 import Var             ( TyVar, tyVarKind )
 import TyCon           ( TyCon, AlgTyConFlavour(..), tyConDataCons,
-                         mkTupleTyCon, isUnLiftedTyCon, mkAlgTyCon
+                         mkTupleTyCon, mkAlgTyCon
                        )
 
-import BasicTypes      ( Arity, RecFlag(..), Boxity(..), isBoxed )
+import BasicTypes      ( Arity, RecFlag(..), Boxity(..), isBoxed, StrictnessMark(..) )
 
 import Type            ( Type, mkTyConTy, mkTyConApp, mkTyVarTys, 
                          mkArrowKinds, liftedTypeKind, unliftedTypeKind,
-                         splitTyConApp_maybe, repType,
-                         TauType, ThetaType )
+                         ThetaType )
 import Unique          ( incrUnique, mkTupleTyConUnique, mkTupleDataConUnique )
 import PrelNames
-import CmdLineOpts
 import Array
 
 alpha_tyvar      = [alphaTyVar]
@@ -154,8 +137,8 @@ genericTyCons :: [TyCon]
 genericTyCons = [ plusTyCon, crossTyCon, genUnitTyCon ]
 
 
-tuple_tycons = unitTyCon : [tupleTyCon Boxed i | i <- [2..37] ]
-unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..37] ]
+tuple_tycons = unitTyCon : [tupleTyCon Boxed   i | i <- [2..mAX_TUPLE_SIZE] ]
+unboxed_tuple_tycons     = [tupleTyCon Unboxed i | i <- [1..mAX_TUPLE_SIZE] ]
 \end{code}
 
 
@@ -201,7 +184,7 @@ mk_tc_gen_info mod tc_uniq tc_name tycon
        name1       = mkWiredInName  mod occ_name1 fn1_key
        name2       = mkWiredInName  mod occ_name2 fn2_key
 
-pcDataCon :: Name -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> DataCon
+pcDataCon :: Name -> [TyVar] -> ThetaType -> [Type] -> TyCon -> DataCon
 -- The unique is the first of two free uniques;
 -- the first is used for the datacon itself and the worker;
 -- the second is used for the wrapper.
@@ -317,13 +300,9 @@ intTy = mkTyConTy intTyCon
 
 intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon]
 intDataCon = pcDataCon intDataConName [] [] [intPrimTy] intTyCon
-
-isIntTy :: Type -> Bool
-isIntTy = isTyCon intTyConKey
 \end{code}
 
 \begin{code}
-
 wordTy = mkTyConTy wordTyCon
 
 wordTyCon = pcNonRecDataTyCon wordTyConName [] [] [wordDataCon]
@@ -335,9 +314,6 @@ addrTy = mkTyConTy addrTyCon
 
 addrTyCon = pcNonRecDataTyCon addrTyConName [] [] [addrDataCon]
 addrDataCon = pcDataCon addrDataConName [] [] [addrPrimTy] addrTyCon
-
-isAddrTy :: Type -> Bool
-isAddrTy = isTyCon addrTyConKey
 \end{code}
 
 \begin{code}
@@ -359,17 +335,11 @@ floatTy   = mkTyConTy floatTyCon
 
 floatTyCon   = pcNonRecDataTyCon floatTyConName   [] [] [floatDataCon]
 floatDataCon = pcDataCon         floatDataConName [] [] [floatPrimTy] floatTyCon
-
-isFloatTy :: Type -> Bool
-isFloatTy = isTyCon floatTyConKey
 \end{code}
 
 \begin{code}
 doubleTy = mkTyConTy doubleTyCon
 
-isDoubleTy :: Type -> Bool
-isDoubleTy = isTyCon doubleTyConKey
-
 doubleTyCon   = pcNonRecDataTyCon doubleTyConName     [] [] [doubleDataCon]
 doubleDataCon = pcDataCon        doubleDataConName [] [] [doublePrimTy] doubleTyCon
 \end{code}
@@ -392,9 +362,6 @@ foreignObjTyCon
     foreignObjDataCon
       = pcDataCon foreignObjDataConName
            [] [] [foreignObjPrimTy] foreignObjTyCon
-
-isForeignObjTy :: Type -> Bool
-isForeignObjTy = isTyCon foreignObjTyConKey
 \end{code}
 
 \begin{code}
@@ -405,9 +372,6 @@ foreignPtrTyCon
     foreignPtrDataCon
       = pcDataCon foreignPtrDataConName
            alpha_tyvar [] [foreignObjPrimTy] foreignPtrTyCon
-
-isForeignPtrTy :: Type -> Bool
-isForeignPtrTy = isTyCon foreignPtrTyConKey
 \end{code}
 
 %************************************************************************
@@ -428,129 +392,6 @@ smallIntegerDataCon = pcDataCon smallIntegerDataConName
                [] [] [intPrimTy] integerTyCon
 largeIntegerDataCon = pcDataCon largeIntegerDataConName
                [] [] [intPrimTy, byteArrayPrimTy] integerTyCon
-
-
-isIntegerTy :: Type -> Bool
-isIntegerTy = isTyCon integerTyConKey
-\end{code}
-
-
-%************************************************************************
-%*                                                                     *
-\subsection[TysWiredIn-ext-type]{External types}
-%*                                                                     *
-%************************************************************************
-
-The compiler's foreign function interface supports the passing of a
-restricted set of types as arguments and results (the restricting factor
-being the )
-
-\begin{code}
-isFFIArgumentTy :: DynFlags -> Bool -> Type -> Bool
--- Checks for valid argument type for a 'foreign import'
-isFFIArgumentTy dflags is_safe ty 
-   = checkRepTyCon (legalOutgoingTyCon dflags is_safe) ty
-
-isFFIExternalTy :: Type -> Bool
--- Types that are allowed as arguments of a 'foreign export'
-isFFIExternalTy ty = checkRepTyCon legalFEArgTyCon ty
-
-isFFIImportResultTy :: DynFlags -> Type -> Bool
-isFFIImportResultTy dflags ty 
-  = checkRepTyCon (legalFIResultTyCon dflags) ty
-
-isFFIExportResultTy :: Type -> Bool
-isFFIExportResultTy ty = checkRepTyCon legalFEResultTyCon ty
-
-isFFIDynArgumentTy :: Type -> Bool
--- The argument type of a foreign import dynamic must be Ptr, FunPtr, Addr,
--- or a newtype of either.
-isFFIDynArgumentTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == funPtrTyCon || tc == addrTyCon)
-
-isFFIDynResultTy :: Type -> Bool
--- The result type of a foreign export dynamic must be Ptr, FunPtr, Addr,
--- or a newtype of either.
-isFFIDynResultTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == funPtrTyCon || tc == addrTyCon)
-
-isFFILabelTy :: Type -> Bool
--- The type of a foreign label must be Ptr, FunPtr, Addr,
--- or a newtype of either.
-isFFILabelTy = checkRepTyCon (\tc -> tc == ptrTyCon || tc == funPtrTyCon || tc == addrTyCon)
-
-checkRepTyCon :: (TyCon -> Bool) -> Type -> Bool
-       -- look through newtypes
-checkRepTyCon check_tc ty = checkTyCon check_tc (repType ty)
-
-checkTyCon :: (TyCon -> Bool) -> Type -> Bool
-checkTyCon check_tc ty = case splitTyConApp_maybe ty of
-                               Just (tycon, _) -> check_tc tycon
-                               Nothing         -> False
-
-isTyCon :: Unique -> Type -> Bool
-isTyCon uniq ty = checkTyCon (\tc -> uniq == getUnique tc) ty
-\end{code}
-
-----------------------------------------------
-These chaps do the work; they are not exported
-----------------------------------------------
-
-\begin{code}
-legalFEArgTyCon :: TyCon -> Bool
--- It's illegal to return foreign objects and (mutable)
--- bytearrays from a _ccall_ / foreign declaration
--- (or be passed them as arguments in foreign exported functions).
-legalFEArgTyCon tc
-  | getUnique tc `elem` [ foreignObjTyConKey, foreignPtrTyConKey,
-                         byteArrayTyConKey, mutableByteArrayTyConKey ] 
-  = False
-  -- It's also illegal to make foreign exports that take unboxed
-  -- arguments.  The RTS API currently can't invoke such things.  --SDM 7/2000
-  | otherwise
-  = boxedMarshalableTyCon tc
-
-legalFIResultTyCon :: DynFlags -> TyCon -> Bool
-legalFIResultTyCon dflags tc
-  | getUnique tc `elem`
-       [ foreignObjTyConKey, foreignPtrTyConKey,
-         byteArrayTyConKey, mutableByteArrayTyConKey ]  = False
-  | tc == unitTyCon = True
-  | otherwise      = marshalableTyCon dflags tc
-
-legalFEResultTyCon :: TyCon -> Bool
-legalFEResultTyCon tc
-  | getUnique tc `elem` 
-       [ foreignObjTyConKey, foreignPtrTyConKey,
-         byteArrayTyConKey, mutableByteArrayTyConKey ]  = False
-  | tc == unitTyCon = True
-  | otherwise       = boxedMarshalableTyCon tc
-
-legalOutgoingTyCon :: DynFlags -> Bool -> TyCon -> Bool
--- Checks validity of types going from Haskell -> external world
--- The boolean is true for a 'safe' call (when we don't want to
--- pass Haskell pointers to the world)
-legalOutgoingTyCon dflags be_safe tc
-  | be_safe && getUnique tc `elem` [byteArrayTyConKey, mutableByteArrayTyConKey]
-  = False
-  | otherwise
-  = marshalableTyCon dflags tc
-
-marshalableTyCon dflags tc
-  =  (dopt Opt_GlasgowExts dflags && isUnLiftedTyCon tc)
-  || boxedMarshalableTyCon tc
-
-boxedMarshalableTyCon tc
-   = getUnique tc `elem` [ intTyConKey, int8TyConKey, int16TyConKey
-                        , int32TyConKey, int64TyConKey
-                        , wordTyConKey, word8TyConKey, word16TyConKey
-                        , word32TyConKey, word64TyConKey
-                        , floatTyConKey, doubleTyConKey
-                        , addrTyConKey, ptrTyConKey, funPtrTyConKey
-                        , charTyConKey, foreignObjTyConKey
-                        , foreignPtrTyConKey
-                        , stablePtrTyConKey
-                        , byteArrayTyConKey, mutableByteArrayTyConKey
-                        , boolTyConKey
-                        ]
 \end{code}