X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fprelude%2FTysWiredIn.lhs;h=ceb4df550aaec8e0651aa43cb63604a130e0782f;hb=9d7da331989abcd1844e9d03b8d1e4163796fa85;hp=57695057cd446442d88049a7227caccf477cb8b3;hpb=cf158e40f528a008226e730f1e47ca6efa9ea8ad;p=ghc-hetmet.git diff --git a/ghc/compiler/prelude/TysWiredIn.lhs b/ghc/compiler/prelude/TysWiredIn.lhs index 5769505..ceb4df5 100644 --- a/ghc/compiler/prelude/TysWiredIn.lhs +++ b/ghc/compiler/prelude/TysWiredIn.lhs @@ -11,86 +11,46 @@ types and operations.'' \begin{code} module TysWiredIn ( - wiredInTyCons, genericTyCons, - - addrDataCon, - addrTy, - addrTyCon, - ptrDataCon, - ptrTy, - ptrTyCon, - funPtrDataCon, - funPtrTy, - funPtrTyCon, - boolTy, - boolTyCon, - charDataCon, - charTy, - charTyCon, - consDataCon, - doubleDataCon, - doubleTy, - isDoubleTy, - doubleTyCon, - falseDataCon, falseDataConId, - floatDataCon, - floatTy, - isFloatTy, - floatTyCon, - - intDataCon, - intTy, - intTyCon, - isIntTy, + wiredInTyCons, + + boolTy, boolTyCon, boolTyCon_RDR, boolTyConName, + trueDataCon, trueDataConId, true_RDR, + falseDataCon, falseDataConId, false_RDR, + + charTyCon, charDataCon, charTyCon_RDR, + charTy, stringTy, charTyConName, - integerTy, - integerTyCon, - smallIntegerDataCon, - largeIntegerDataCon, - isIntegerTy, + + doubleTyCon, doubleDataCon, doubleTy, doubleTyConName, + + floatTyCon, floatDataCon, floatTy, floatTyConName, - listTyCon, + intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName, + intTy, + listTyCon, nilDataCon, consDataCon, + listTyCon_RDR, consDataCon_RDR, listTyConName, mkListTy, - nilDataCon, -- tuples mkTupleTy, tupleTyCon, tupleCon, - unitTyCon, unitDataConId, pairTyCon, + unitTyCon, unitDataCon, unitDataConId, pairTyCon, unboxedSingletonTyCon, unboxedSingletonDataCon, unboxedPairTyCon, unboxedPairDataCon, - -- Generics - genUnitTyCon, genUnitDataCon, - plusTyCon, inrDataCon, inlDataCon, - crossTyCon, crossDataCon, - - stablePtrTyCon, - stringTy, - trueDataCon, trueDataConId, unitTy, 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 + -- parallel arrays + mkPArrTy, + parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon, + parrTyCon_RDR, parrTyConName ) where #include "HsVersions.h" -import {-# SOURCE #-} MkId( mkDataConId, mkDataConWrapId ) -import {-# SOURCE #-} Generics( mkTyConGenInfo ) +import {-# SOURCE #-} MkId( mkDataConIds ) -- friends: import PrelNames @@ -98,31 +58,31 @@ import TysPrim -- others: import Constants ( mAX_TUPLE_SIZE ) -import Module ( mkPrelModule ) -import Name ( Name, nameRdrName, nameUnique, nameOccName, +import Module ( Module ) +import RdrName ( nameRdrName ) +import Name ( Name, BuiltInSyntax(..), nameUnique, nameOccName, nameModule, mkWiredInName ) -import OccName ( mkOccFS, tcName, dataName, mkWorkerOcc, mkGenOcc1, mkGenOcc2 ) -import RdrName ( rdrNameOcc ) -import DataCon ( DataCon, StrictnessMark(..), mkDataCon, dataConId ) +import OccName ( mkOccNameFS, tcName, dataName, mkTupleOcc, + mkDataConWorkerOcc ) +import DataCon ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity ) import Var ( TyVar, tyVarKind ) -import TyCon ( TyCon, AlgTyConFlavour(..), tyConDataCons, - mkTupleTyCon, isUnLiftedTyCon, mkAlgTyCon - ) +import TyCon ( TyCon, AlgTyConRhs(DataTyCon), tyConDataCons, + mkTupleTyCon, mkAlgTyCon, tyConName ) -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 ) -import Unique ( incrUnique, mkTupleTyConUnique, mkTupleDataConUnique ) -import PrelNames -import CmdLineOpts +import Type ( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys, + TyThing(..) ) +import Kind ( mkArrowKinds, liftedTypeKind, ubxTupleKind ) +import Unique ( incrUnique, mkTupleTyConUnique, + mkTupleDataConUnique, mkPArrDataConUnique ) import Array +import FastString +import Outputable -alpha_tyvar = [alphaTyVar] -alpha_ty = [alphaTy] -alpha_beta_tyvars = [alphaTyVar, betaTyVar] +alpha_tyvar = [alphaTyVar] +alpha_ty = [alphaTy] \end{code} @@ -132,30 +92,71 @@ alpha_beta_tyvars = [alphaTyVar, betaTyVar] %* * %************************************************************************ +If you change which things are wired in, make sure you change their +names in PrelNames, so they use wTcQual, wDataQual, etc + \begin{code} -wiredInTyCons :: [TyCon] -wiredInTyCons = data_tycons ++ tuple_tycons ++ unboxed_tuple_tycons - -data_tycons = genericTyCons ++ - [ addrTyCon - , ptrTyCon - , funPtrTyCon - , boolTyCon +wiredInTyCons :: [TyCon] -- Excludes tuples +wiredInTyCons = [ unitTyCon -- Not treated like other tuples, because + -- it's defined in GHC.Base, and there's only + -- one of it. We put it in wiredInTyCons so + -- that it'll pre-populate the name cache, so + -- the special case in lookupOrigNameCache + -- doesn't need to look out for it + , boolTyCon , charTyCon , doubleTyCon , floatTyCon , intTyCon - , integerTyCon , listTyCon - , wordTyCon + , parrTyCon ] +\end{code} -genericTyCons :: [TyCon] -genericTyCons = [ plusTyCon, crossTyCon, genUnitTyCon ] - - -tuple_tycons = unitTyCon : [tupleTyCon Boxed i | i <- [2..mAX_TUPLE_SIZE] ] -unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..mAX_TUPLE_SIZE] ] +\begin{code} +mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name +mkWiredInTyConName built_in mod fs uniq tycon + = mkWiredInName mod (mkOccNameFS tcName fs) uniq + Nothing -- No parent object + (ATyCon tycon) -- Relevant TyCon + built_in + +mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name -> Name +mkWiredInDataConName built_in mod fs uniq datacon parent + = mkWiredInName mod (mkOccNameFS dataName fs) uniq + (Just parent) -- Name of parent TyCon + (ADataCon datacon) -- Relevant DataCon + built_in + +charTyConName = mkWiredInTyConName UserSyntax pREL_BASE FSLIT("Char") charTyConKey charTyCon +charDataConName = mkWiredInDataConName UserSyntax pREL_BASE FSLIT("C#") charDataConKey charDataCon charTyConName +intTyConName = mkWiredInTyConName UserSyntax pREL_BASE FSLIT("Int") intTyConKey intTyCon +intDataConName = mkWiredInDataConName UserSyntax pREL_BASE FSLIT("I#") intDataConKey intDataCon intTyConName + +boolTyConName = mkWiredInTyConName UserSyntax pREL_BASE FSLIT("Bool") boolTyConKey boolTyCon +falseDataConName = mkWiredInDataConName UserSyntax pREL_BASE FSLIT("False") falseDataConKey falseDataCon boolTyConName +trueDataConName = mkWiredInDataConName UserSyntax pREL_BASE FSLIT("True") trueDataConKey trueDataCon boolTyConName +listTyConName = mkWiredInTyConName BuiltInSyntax pREL_BASE FSLIT("[]") listTyConKey listTyCon +nilDataConName = mkWiredInDataConName BuiltInSyntax pREL_BASE FSLIT("[]") nilDataConKey nilDataCon listTyConName +consDataConName = mkWiredInDataConName BuiltInSyntax pREL_BASE FSLIT(":") consDataConKey consDataCon listTyConName + +floatTyConName = mkWiredInTyConName UserSyntax pREL_FLOAT FSLIT("Float") floatTyConKey floatTyCon +floatDataConName = mkWiredInDataConName UserSyntax pREL_FLOAT FSLIT("F#") floatDataConKey floatDataCon floatTyConName +doubleTyConName = mkWiredInTyConName UserSyntax pREL_FLOAT FSLIT("Double") doubleTyConKey doubleTyCon +doubleDataConName = mkWiredInDataConName UserSyntax pREL_FLOAT FSLIT("D#") doubleDataConKey doubleDataCon doubleTyConName + +parrTyConName = mkWiredInTyConName BuiltInSyntax pREL_PARR FSLIT("[::]") parrTyConKey parrTyCon +parrDataConName = mkWiredInDataConName UserSyntax pREL_PARR FSLIT("PArr") parrDataConKey parrDataCon parrTyConName + +boolTyCon_RDR = nameRdrName boolTyConName +false_RDR = nameRdrName falseDataConName +true_RDR = nameRdrName trueDataConName +intTyCon_RDR = nameRdrName intTyConName +charTyCon_RDR = nameRdrName charTyConName +intDataCon_RDR = nameRdrName intDataConName +listTyCon_RDR = nameRdrName listTyConName +consDataCon_RDR = nameRdrName consDataConName +parrTyCon_RDR = nameRdrName parrTyConName \end{code} @@ -166,64 +167,51 @@ unboxed_tuple_tycons = [tupleTyCon Unboxed i | i <- [1..mAX_TUPLE_SIZE] ] %************************************************************************ \begin{code} -pcNonRecDataTyCon = pcTyCon DataTyCon NonRecursive -pcRecDataTyCon = pcTyCon DataTyCon Recursive +pcNonRecDataTyCon = pcTyCon False NonRecursive +pcRecDataTyCon = pcTyCon False Recursive -pcTyCon new_or_data is_rec name tyvars argvrcs cons +pcTyCon is_enum is_rec name tyvars argvrcs cons = tycon where - tycon = mkAlgTyCon name kind + tycon = mkAlgTyCon name + (mkArrowKinds (map tyVarKind tyvars) liftedTypeKind) tyvars - [] -- No context argvrcs - cons - (length cons) - [] -- No record selectors - new_or_data + [] -- No stupid theta + (DataTyCon cons is_enum) + [] -- No record selectors is_rec - gen_info + True -- All the wired-in tycons have generics - mod = nameModule name - kind = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind - gen_info = mk_tc_gen_info mod (nameUnique name) name tycon +pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon +pcDataCon = pcDataConWithFixity False --- We generate names for the generic to/from Ids by incrementing --- the TyCon unique. So each Prelude tycon needs 3 slots, one --- for itself and two more for the generic Ids. -mk_tc_gen_info mod tc_uniq tc_name tycon - = mkTyConGenInfo tycon [name1, name2] - where - tc_occ_name = nameOccName tc_name - occ_name1 = mkGenOcc1 tc_occ_name - occ_name2 = mkGenOcc2 tc_occ_name - fn1_key = incrUnique tc_uniq - fn2_key = incrUnique fn1_key - name1 = mkWiredInName mod occ_name1 fn1_key - name2 = mkWiredInName mod occ_name2 fn2_key - -pcDataCon :: Name -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> DataCon +pcDataConWithFixity :: Bool -> Name -> [TyVar] -> [Type] -> TyCon -> DataCon +-- The Name should be in the DataName name space; it's the name +-- of the DataCon itself. +-- -- 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. +-- the first is used for the datacon itself, +-- the second is used for the "worker name" -pcDataCon name tyvars context arg_tys tycon +pcDataConWithFixity declared_infix dc_name tyvars arg_tys tycon = data_con where - data_con = mkDataCon name - [ NotMarkedStrict | a <- arg_tys ] - [ {- no labelled fields -} ] - tyvars context [] [] arg_tys tycon work_id wrap_id - - wrap_rdr = nameRdrName name - wrap_occ = rdrNameOcc wrap_rdr - - mod = nameModule name - wrap_id = mkDataConWrapId data_con - - work_occ = mkWorkerOcc wrap_occ - work_key = incrUnique (nameUnique name) - work_name = mkWiredInName mod work_occ work_key - work_id = mkDataConId work_name data_con + data_con = mkDataCon dc_name declared_infix True {- Vanilla -} + (map (const NotMarkedStrict) arg_tys) + [{- No labelled fields -}] + tyvars [] [] arg_tys tycon (mkTyVarTys tyvars) + (mkDataConIds bogus_wrap_name wrk_name data_con) + + + mod = nameModule dc_name + wrk_occ = mkDataConWorkerOcc (nameOccName dc_name) + wrk_key = incrUnique (nameUnique dc_name) + wrk_name = mkWiredInName mod wrk_occ wrk_key + (Just (tyConName tycon)) + (AnId (dataConWorkId data_con)) UserSyntax + bogus_wrap_name = pprPanic "Wired-in data wrapper id" (ppr dc_name) + -- Wired-in types are too simple to need wrappers \end{code} @@ -245,32 +233,35 @@ tupleCon Boxed i = snd (boxedTupleArr ! i) tupleCon Unboxed i = snd (unboxedTupleArr ! i) boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon) -boxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Boxed i) | i <- [0..mAX_TUPLE_SIZE]] -unboxedTupleArr = array (0,mAX_TUPLE_SIZE) [(i,mk_tuple Unboxed i) | i <- [0..mAX_TUPLE_SIZE]] +boxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Boxed i | i <- [0..mAX_TUPLE_SIZE]] +unboxedTupleArr = listArray (0,mAX_TUPLE_SIZE) [mk_tuple Unboxed i | i <- [0..mAX_TUPLE_SIZE]] mk_tuple :: Boxity -> Int -> (TyCon,DataCon) mk_tuple boxity arity = (tycon, tuple_con) where tycon = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info - tc_name = mkWiredInName mod (mkOccFS tcName name_str) tc_uniq + mod = mkTupleModule boxity arity + tc_name = mkWiredInName mod (mkTupleOcc tcName boxity arity) tc_uniq + Nothing (ATyCon tycon) BuiltInSyntax tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind res_kind | isBoxed boxity = liftedTypeKind - | otherwise = unliftedTypeKind + | otherwise = ubxTupleKind tyvars | isBoxed boxity = take arity alphaTyVars | otherwise = take arity openAlphaTyVars - tuple_con = pcDataCon name tyvars [] tyvar_tys tycon + tuple_con = pcDataCon dc_name tyvars tyvar_tys tycon tyvar_tys = mkTyVarTys tyvars - (mod_name, name_str) = mkTupNameStr boxity arity - name = mkWiredInName mod (mkOccFS dataName name_str) dc_uniq + dc_name = mkWiredInName mod (mkTupleOcc dataName boxity arity) dc_uniq + (Just tc_name) (ADataCon tuple_con) BuiltInSyntax tc_uniq = mkTupleTyConUnique boxity arity dc_uniq = mkTupleDataConUnique boxity arity - mod = mkPrelModule mod_name - gen_info = mk_tc_gen_info mod tc_uniq tc_name tycon + gen_info = True -- Tuples all have generics.. + -- hmm: that's a *lot* of code unitTyCon = tupleTyCon Boxed 0 -unitDataConId = dataConId (head (tyConDataCons unitTyCon)) +unitDataCon = head (tyConDataCons unitTyCon) +unitDataConId = dataConWorkId unitDataCon pairTyCon = tupleTyCon Boxed 2 @@ -307,7 +298,7 @@ voidTy = unitTy charTy = mkTyConTy charTyCon charTyCon = pcNonRecDataTyCon charTyConName [] [] [charDataCon] -charDataCon = pcDataCon charDataConName [] [] [charPrimTy] charTyCon +charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon stringTy = mkListTy charTy -- convenience only \end{code} @@ -316,241 +307,21 @@ stringTy = mkListTy charTy -- convenience only 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] -wordDataCon = pcDataCon wordDataConName [] [] [wordPrimTy] wordTyCon -\end{code} - -\begin{code} -addrTy = mkTyConTy addrTyCon - -addrTyCon = pcNonRecDataTyCon addrTyConName [] [] [addrDataCon] -addrDataCon = pcDataCon addrDataConName [] [] [addrPrimTy] addrTyCon - -isAddrTy :: Type -> Bool -isAddrTy = isTyCon addrTyConKey -\end{code} - -\begin{code} -ptrTy = mkTyConTy ptrTyCon - -ptrTyCon = pcNonRecDataTyCon ptrTyConName alpha_tyvar [(True,False)] [ptrDataCon] -ptrDataCon = pcDataCon ptrDataConName alpha_tyvar [] [addrPrimTy] ptrTyCon -\end{code} - -\begin{code} -funPtrTy = mkTyConTy funPtrTyCon - -funPtrTyCon = pcNonRecDataTyCon funPtrTyConName alpha_tyvar [(True,False)] [funPtrDataCon] -funPtrDataCon = pcDataCon funPtrDataConName alpha_tyvar [] [addrPrimTy] funPtrTyCon +intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon \end{code} \begin{code} floatTy = mkTyConTy floatTyCon floatTyCon = pcNonRecDataTyCon floatTyConName [] [] [floatDataCon] -floatDataCon = pcDataCon floatDataConName [] [] [floatPrimTy] floatTyCon - -isFloatTy :: Type -> Bool -isFloatTy = isTyCon floatTyConKey +floatDataCon = pcDataCon floatDataConName [] [floatPrimTy] floatTyCon \end{code} \begin{code} doubleTy = mkTyConTy doubleTyCon -isDoubleTy :: Type -> Bool -isDoubleTy = isTyCon doubleTyConKey - -doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [] [doubleDataCon] -doubleDataCon = pcDataCon doubleDataConName [] [] [doublePrimTy] doubleTyCon -\end{code} - -\begin{code} -stablePtrTyCon - = pcNonRecDataTyCon stablePtrTyConName - alpha_tyvar [(True,False)] [stablePtrDataCon] - where - stablePtrDataCon - = pcDataCon stablePtrDataConName - alpha_tyvar [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon -\end{code} - -\begin{code} -foreignObjTyCon - = pcNonRecDataTyCon foreignObjTyConName - [] [] [foreignObjDataCon] - where - foreignObjDataCon - = pcDataCon foreignObjDataConName - [] [] [foreignObjPrimTy] foreignObjTyCon - -isForeignObjTy :: Type -> Bool -isForeignObjTy = isTyCon foreignObjTyConKey -\end{code} - -\begin{code} -foreignPtrTyCon - = pcNonRecDataTyCon foreignPtrTyConName - alpha_tyvar [(True,False)] [foreignPtrDataCon] - where - foreignPtrDataCon - = pcDataCon foreignPtrDataConName - alpha_tyvar [] [foreignObjPrimTy] foreignPtrTyCon - -isForeignPtrTy :: Type -> Bool -isForeignPtrTy = isTyCon foreignPtrTyConKey -\end{code} - -%************************************************************************ -%* * -\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types} -%* * -%************************************************************************ - -@Integer@ and its pals are not really primitive. @Integer@ itself, first: -\begin{code} -integerTy :: Type -integerTy = mkTyConTy integerTyCon - -integerTyCon = pcNonRecDataTyCon integerTyConName - [] [] [smallIntegerDataCon, largeIntegerDataCon] - -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 - ] +doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [] [doubleDataCon] +doubleDataCon = pcDataCon doubleDataConName [] [doublePrimTy] doubleTyCon \end{code} @@ -605,14 +376,14 @@ primitive counterpart. \begin{code} boolTy = mkTyConTy boolTyCon -boolTyCon = pcTyCon EnumTyCon NonRecursive boolTyConName +boolTyCon = pcTyCon True NonRecursive boolTyConName [] [] [falseDataCon, trueDataCon] -falseDataCon = pcDataCon falseDataConName [] [] [] boolTyCon -trueDataCon = pcDataCon trueDataConName [] [] [] boolTyCon +falseDataCon = pcDataCon falseDataConName [] [] boolTyCon +trueDataCon = pcDataCon trueDataConName [] [] boolTyCon -falseDataConId = dataConId falseDataCon -trueDataConId = dataConId trueDataCon +falseDataConId = dataConWorkId falseDataCon +trueDataConId = dataConWorkId trueDataCon \end{code} %************************************************************************ @@ -637,9 +408,10 @@ mkListTy ty = mkTyConApp listTyCon [ty] listTyCon = pcRecDataTyCon listTyConName alpha_tyvar [(True,False)] [nilDataCon, consDataCon] -nilDataCon = pcDataCon nilDataConName alpha_tyvar [] [] listTyCon -consDataCon = pcDataCon consDataConName - alpha_tyvar [] [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon +nilDataCon = pcDataCon nilDataConName alpha_tyvar [] listTyCon +consDataCon = pcDataConWithFixity True {- Declared infix -} + consDataConName + alpha_tyvar [alphaTy, mkTyConApp listTyCon alpha_ty] listTyCon -- Interesting: polymorphic recursion would help here. -- We can't use (mkListTy alphaTy) in the defn of consDataCon, else mkListTy -- gets the over-specific type (Type -> Type) @@ -699,36 +471,79 @@ unitTy = mkTupleTy Boxed 0 [] \end{code} %************************************************************************ -%* * -\subsection{Wired In Type Constructors for Representation Types} -%* * +%* * +\subsection[TysWiredIn-PArr]{The @[::]@ type} +%* * %************************************************************************ -The following code defines the wired in datatypes cross, plus, unit -and c_of needed for the generic methods. - -Ok, so the basic story is that for each type constructor I need to -create 2 things - a TyCon and a DataCon and then we are basically -ok. There are going to be no arguments passed to these functions -because -well- there is nothing to pass to these functions. +Special syntax for parallel arrays needs some wired in definitions. \begin{code} -crossTyCon :: TyCon -crossTyCon = pcNonRecDataTyCon crossTyConName alpha_beta_tyvars [] [crossDataCon] - -crossDataCon :: DataCon -crossDataCon = pcDataCon crossDataConName alpha_beta_tyvars [] [alphaTy, betaTy] crossTyCon +-- construct a type representing the application of the parallel array +-- constructor +-- +mkPArrTy :: Type -> Type +mkPArrTy ty = mkTyConApp parrTyCon [ty] -plusTyCon :: TyCon -plusTyCon = pcNonRecDataTyCon plusTyConName alpha_beta_tyvars [] [inlDataCon, inrDataCon] +-- represents the type constructor of parallel arrays +-- +-- * this must match the definition in `PrelPArr' +-- +-- NB: Although the constructor is given here, it will not be accessible in +-- user code as it is not in the environment of any compiled module except +-- `PrelPArr'. +-- +parrTyCon :: TyCon +parrTyCon = pcNonRecDataTyCon parrTyConName alpha_tyvar [(True, False)] [parrDataCon] + +parrDataCon :: DataCon +parrDataCon = pcDataCon + parrDataConName + alpha_tyvar -- forall'ed type variables + [intPrimTy, -- 1st argument: Int# + mkTyConApp -- 2nd argument: Array# a + arrayPrimTyCon + alpha_ty] + parrTyCon + +-- check whether a type constructor is the constructor for parallel arrays +-- +isPArrTyCon :: TyCon -> Bool +isPArrTyCon tc = tyConName tc == parrTyConName -inlDataCon, inrDataCon :: DataCon -inlDataCon = pcDataCon inlDataConName alpha_beta_tyvars [] [alphaTy] plusTyCon -inrDataCon = pcDataCon inrDataConName alpha_beta_tyvars [] [betaTy] plusTyCon +-- fake array constructors +-- +-- * these constructors are never really used to represent array values; +-- however, they are very convenient during desugaring (and, in particular, +-- in the pattern matching compiler) to treat array pattern just like +-- yet another constructor pattern +-- +parrFakeCon :: Arity -> DataCon +parrFakeCon i | i > mAX_TUPLE_SIZE = mkPArrFakeCon i -- build one specially +parrFakeCon i = parrFakeConArr!i -genUnitTyCon :: TyCon -- The "1" type constructor for generics -genUnitTyCon = pcNonRecDataTyCon genUnitTyConName [] [] [genUnitDataCon] +-- pre-defined set of constructors +-- +parrFakeConArr :: Array Int DataCon +parrFakeConArr = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i) + | i <- [0..mAX_TUPLE_SIZE]] -genUnitDataCon :: DataCon -genUnitDataCon = pcDataCon genUnitDataConName [] [] [] genUnitTyCon +-- build a fake parallel array constructor for the given arity +-- +mkPArrFakeCon :: Int -> DataCon +mkPArrFakeCon arity = data_con + where + data_con = pcDataCon name [tyvar] tyvarTys parrTyCon + tyvar = head alphaTyVars + tyvarTys = replicate arity $ mkTyVarTy tyvar + nameStr = mkFastString ("MkPArr" ++ show arity) + name = mkWiredInName pREL_PARR (mkOccNameFS dataName nameStr) uniq + Nothing (ADataCon data_con) UserSyntax + uniq = mkPArrDataConUnique arity + +-- checks whether a data constructor is a fake constructor for parallel arrays +-- +isPArrFakeCon :: DataCon -> Bool +isPArrFakeCon dcon = dcon == parrFakeCon (dataConSourceArity dcon) \end{code} +