X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fprelude%2FTysWiredIn.lhs;h=2975922af8db9f37b47845f3f3744e809ea93859;hb=e5ad9dcc35c7a0bb9b8ebca29940cbf32c6b150a;hp=a4623c2fd2191d05c72cf696161d9b984d2f4a90;hpb=dabfa71f33eabc5a2d10959728f772aa016f1c84;p=ghc-hetmet.git diff --git a/ghc/compiler/prelude/TysWiredIn.lhs b/ghc/compiler/prelude/TysWiredIn.lhs index a4623c2..2975922 100644 --- a/ghc/compiler/prelude/TysWiredIn.lhs +++ b/ghc/compiler/prelude/TysWiredIn.lhs @@ -1,5 +1,5 @@ % -% (c) The GRASP Project, Glasgow University, 1994-1995 +% (c) The GRASP Project, Glasgow University, 1994-1998 % \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types} @@ -10,12 +10,9 @@ This module tracks the ``state interface'' document, ``GHC prelude: types and operations.'' \begin{code} -#include "HsVersions.h" - module TysWiredIn ( - addrDataCon, - addrTy, - addrTyCon, + wiredInTyCons, genericTyCons, + boolTy, boolTyCon, charDataCon, @@ -25,461 +22,324 @@ module TysWiredIn ( doubleDataCon, doubleTy, doubleTyCon, - eqDataCon, - falseDataCon, + falseDataCon, falseDataConId, floatDataCon, floatTy, floatTyCon, - getStatePairingConInfo, - gtDataCon, + intDataCon, intTy, intTyCon, + integerTy, integerTyCon, - integerDataCon, - liftDataCon, - liftTyCon, + smallIntegerDataCon, + largeIntegerDataCon, + listTyCon, - ltDataCon, - foreignObjTyCon, - mkLiftTy, + mkListTy, - mkPrimIoTy, - mkStateTransformerTy, - mkTupleTy, nilDataCon, - orderingTy, - orderingTyCon, - primIoTyCon, - ratioDataCon, - ratioTyCon, - rationalTy, - rationalTyCon, - realWorldStateTy, - return2GMPsTyCon, - returnIntAndGMPTyCon, - stTyCon, - stablePtrTyCon, - stateAndAddrPrimTyCon, - stateAndArrayPrimTyCon, - stateAndByteArrayPrimTyCon, - stateAndCharPrimTyCon, - stateAndDoublePrimTyCon, - stateAndFloatPrimTyCon, - stateAndIntPrimTyCon, - stateAndForeignObjPrimTyCon, - stateAndMutableArrayPrimTyCon, - stateAndMutableByteArrayPrimTyCon, - stateAndPtrPrimTyCon, - stateAndStablePtrPrimTyCon, - stateAndSynchVarPrimTyCon, - stateAndWordPrimTyCon, - stateDataCon, - stateTyCon, + + -- tuples + mkTupleTy, + tupleTyCon, tupleCon, + unitTyCon, unitDataCon, unitDataConId, pairTyCon, + unboxedSingletonTyCon, unboxedSingletonDataCon, + unboxedPairTyCon, unboxedPairDataCon, + + -- Generics + genUnitTyCon, genUnitDataCon, + plusTyCon, inrDataCon, inlDataCon, + crossTyCon, crossDataCon, + stringTy, - stringTyCon, - trueDataCon, + trueDataCon, trueDataConId, unitTy, - voidTy, voidTyCon, + voidTy, wordDataCon, wordTy, - wordTyCon + wordTyCon, + -- parallel arrays + mkPArrTy, + parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon ) where ---ToDo:rm ---import Pretty ---import Util ---import PprType ---import PprStyle ---import Kind +#include "HsVersions.h" -import Ubiq -import TyLoop ( mkDataCon, StrictnessMark(..) ) +import {-# SOURCE #-} MkId( mkDataConWorkId ) +import {-# SOURCE #-} Generics( mkTyConGenInfo ) -- friends: -import PrelMods +import PrelNames import TysPrim -- others: -import SpecEnv ( SpecEnv(..) ) -import Kind ( mkBoxedTypeKind, mkArrowKind ) -import Name ( mkBuiltinName ) -import SrcLoc ( mkBuiltinSrcLoc ) -import TyCon ( mkDataTyCon, mkTupleTyCon, mkSynTyCon, - NewOrData(..), TyCon +import Constants ( mAX_TUPLE_SIZE ) +import Module ( mkBasePkgModule ) +import Name ( Name, nameUnique, nameOccName, + nameModule, mkWiredInName ) +import OccName ( mkOccFS, tcName, dataName, mkDataConWorkerOcc, mkGenOcc1, mkGenOcc2 ) +import DataCon ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity ) +import Var ( TyVar, tyVarKind ) +import TyCon ( TyCon, AlgTyConFlavour(..), DataConDetails(..), tyConDataCons, + mkTupleTyCon, mkAlgTyCon, tyConName ) -import Type ( mkTyConTy, applyTyCon, mkSynTy, mkSigmaTy, - mkFunTys, maybeAppDataTyConExpandingDicts, - GenType(..), ThetaType(..), TauType(..) ) -import TyVar ( tyVarKind, alphaTyVar, betaTyVar ) -import Unique -import Util ( assoc, panic ) - -nullSpecEnv = error "TysWiredIn:nullSpecEnv = " -addOneToSpecEnv = error "TysWiredIn:addOneToSpecEnv = " -pc_gen_specs = error "TysWiredIn:pc_gen_specs " -mkSpecInfo = error "TysWiredIn:SpecInfo" - -pcDataTyCon :: Unique{-TyConKey-} -> Module -> FAST_STRING - -> [TyVar] -> [Id] -> TyCon -pcDataTyCon key mod str tyvars cons - = mkDataTyCon (mkBuiltinName key mod str) tycon_kind - tyvars [{-no context-}] cons [{-no derivings-}] - DataType - where - tycon_kind = foldr (mkArrowKind . tyVarKind) mkBoxedTypeKind tyvars - -pcDataCon :: Unique{-DataConKey-} -> Module -> FAST_STRING - -> [TyVar] -> ThetaType -> [TauType] -> TyCon -> SpecEnv -> Id -pcDataCon key mod str tyvars context arg_tys tycon specenv - = mkDataCon (mkBuiltinName key mod str) - [ NotMarkedStrict | a <- arg_tys ] - [ {- no labelled fields -} ] - tyvars context arg_tys tycon - -- specenv - -pcGenerateDataSpecs :: Type -> SpecEnv -pcGenerateDataSpecs ty - = pc_gen_specs False err err err ty - where - err = panic "PrelUtils:GenerateDataSpecs" -\end{code} -%************************************************************************ -%* * -\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)} -%* * -%************************************************************************ - -\begin{code} --- The Void type is represented as a data type with no constructors -voidTy = mkTyConTy voidTyCon - -voidTyCon = pcDataTyCon voidTyConKey pRELUDE_BUILTIN SLIT("Void") [] [] -\end{code} +import BasicTypes ( Arity, RecFlag(..), Boxity(..), isBoxed ) -\begin{code} -charTy = mkTyConTy charTyCon +import Type ( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys, + mkArrowKinds, liftedTypeKind, unliftedTypeKind, + ThetaType ) +import Unique ( incrUnique, mkTupleTyConUnique, + mkTupleDataConUnique, mkPArrDataConUnique ) +import PrelNames +import Array +import FastString -charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon] -charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv +alpha_tyvar = [alphaTyVar] +alpha_ty = [alphaTy] +alpha_beta_tyvars = [alphaTyVar, betaTyVar] \end{code} -\begin{code} -intTy = mkTyConTy intTyCon - -intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon] -intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv -\end{code} -\begin{code} -wordTy = mkTyConTy wordTyCon +%************************************************************************ +%* * +\subsection{Wired in type constructors} +%* * +%************************************************************************ -wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon] -wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv -\end{code} +If you change which things are wired in, make sure you change their +names in PrelNames, so they use wTcQual, wDataQual, etc \begin{code} -addrTy = mkTyConTy addrTyCon - -addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon] -addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon nullSpecEnv +wiredInTyCons :: [TyCon] +wiredInTyCons = data_tycons ++ tuple_tycons ++ unboxed_tuple_tycons + +data_tycons = genericTyCons ++ + [ boolTyCon + , charTyCon + , doubleTyCon + , floatTyCon + , intTyCon + , integerTyCon + , listTyCon + , parrTyCon + , wordTyCon + ] + +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] ] \end{code} -\begin{code} -floatTy = mkTyConTy floatTyCon -floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon] -floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv -\end{code} +%************************************************************************ +%* * +\subsection{mkWiredInTyCon} +%* * +%************************************************************************ \begin{code} -doubleTy = mkTyConTy doubleTyCon +pcNonRecDataTyCon = pcTyCon DataTyCon NonRecursive +pcRecDataTyCon = pcTyCon DataTyCon Recursive -doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon] -doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv +pcTyCon new_or_data is_rec name tyvars argvrcs cons + = tycon + where + tycon = mkAlgTyCon name kind + tyvars + [] -- No context + argvrcs + (DataCons cons) + [] -- No record selectors + new_or_data + is_rec + gen_info + + mod = nameModule name + kind = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind + gen_info = mk_tc_gen_info mod (nameUnique name) name tycon + +-- 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 -> [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, +-- the second is used for the "worker name" + +pcDataCon dc_name tyvars context arg_tys tycon + = data_con + where + data_con = mkDataCon dc_name + [{- No strictness -}] + [{- No labelled fields -}] + tyvars context [] [] arg_tys tycon work_id + Nothing {- No wrapper for wired-in things + (they are too simple to need one) -} + + mod = nameModule dc_name + wrk_occ = mkDataConWorkerOcc (nameOccName dc_name) + wrk_key = incrUnique (nameUnique dc_name) + wrk_name = mkWiredInName mod wrk_occ wrk_key + work_id = mkDataConWorkId wrk_name data_con \end{code} -\begin{code} -mkStateTy ty = applyTyCon stateTyCon [ty] -realWorldStateTy = mkStateTy realWorldTy -- a common use -stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alphaTyVar] [stateDataCon] -stateDataCon - = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#") - [alphaTyVar] [] [mkStatePrimTy alphaTy] stateTyCon nullSpecEnv -\end{code} - -\begin{code} -stablePtrTyCon - = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr") - [alphaTyVar] [stablePtrDataCon] - where - stablePtrDataCon - = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr") - [alphaTyVar] [] [mkStablePtrPrimTy alphaTy] stablePtrTyCon nullSpecEnv -\end{code} +%************************************************************************ +%* * +\subsection[TysWiredIn-tuples]{The tuple types} +%* * +%************************************************************************ \begin{code} -foreignObjTyCon - = pcDataTyCon foreignObjTyConKey gLASGOW_MISC SLIT("_ForeignObj") - [] [foreignObjDataCon] +tupleTyCon :: Boxity -> Arity -> TyCon +tupleTyCon boxity i | i > mAX_TUPLE_SIZE = fst (mk_tuple boxity i) -- Build one specially +tupleTyCon Boxed i = fst (boxedTupleArr ! i) +tupleTyCon Unboxed i = fst (unboxedTupleArr ! i) + +tupleCon :: Boxity -> Arity -> DataCon +tupleCon boxity i | i > mAX_TUPLE_SIZE = snd (mk_tuple boxity i) -- Build one specially +tupleCon Boxed i = snd (boxedTupleArr ! i) +tupleCon Unboxed i = snd (unboxedTupleArr ! i) + +boxedTupleArr, unboxedTupleArr :: Array Int (TyCon,DataCon) +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 - foreignObjDataCon - = pcDataCon foreignObjDataConKey gLASGOW_MISC SLIT("_ForeignObj") - [] [] [foreignObjPrimTy] foreignObjTyCon nullSpecEnv + tycon = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info + tc_name = mkWiredInName mod (mkOccFS tcName name_str) tc_uniq + tc_kind = mkArrowKinds (map tyVarKind tyvars) res_kind + res_kind | isBoxed boxity = liftedTypeKind + | otherwise = unliftedTypeKind + + tyvars | isBoxed boxity = take arity alphaTyVars + | otherwise = take arity openAlphaTyVars + + tuple_con = pcDataCon 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 + tc_uniq = mkTupleTyConUnique boxity arity + dc_uniq = mkTupleDataConUnique boxity arity + mod = mkBasePkgModule mod_name + gen_info = mk_tc_gen_info mod tc_uniq tc_name tycon + +unitTyCon = tupleTyCon Boxed 0 +unitDataCon = head (tyConDataCons unitTyCon) +unitDataConId = dataConWorkId unitDataCon + +pairTyCon = tupleTyCon Boxed 2 + +unboxedSingletonTyCon = tupleTyCon Unboxed 1 +unboxedSingletonDataCon = tupleCon Unboxed 1 + +unboxedPairTyCon = tupleTyCon Unboxed 2 +unboxedPairDataCon = tupleCon Unboxed 2 \end{code} %************************************************************************ %* * -\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types} +\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)} %* * %************************************************************************ -@Integer@ and its pals are not really primitive. @Integer@ itself, first: \begin{code} -integerTy :: GenType t u -integerTy = mkTyConTy integerTyCon - -integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon] - -integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#") - [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv +-- The Void type is represented as a data type with no constructors +-- It's a built in type (i.e. there's no way to define it in Haskell; +-- the nearest would be +-- +-- data Void = -- No constructors! +-- +-- ) It's lifted; there is only one value of this +-- type, namely "void", whose semantics is just bottom. +-- +-- Haskell 98 drops the definition of a Void type, so we just 'simulate' +-- voidTy using (). +voidTy = unitTy \end{code} -And the other pairing types: -\begin{code} -return2GMPsTyCon = pcDataTyCon return2GMPsTyConKey - pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [return2GMPsDataCon] -return2GMPsDataCon - = pcDataCon return2GMPsDataConKey pRELUDE_BUILTIN SLIT("_Return2GMPs") [] [] - [intPrimTy, intPrimTy, byteArrayPrimTy, - intPrimTy, intPrimTy, byteArrayPrimTy] return2GMPsTyCon nullSpecEnv +\begin{code} +charTy = mkTyConTy charTyCon -returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey - pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon] +charTyCon = pcNonRecDataTyCon charTyConName [] [] [charDataCon] +charDataCon = pcDataCon charDataConName [] [] [charPrimTy] charTyCon -returnIntAndGMPDataCon - = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [] - [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv +stringTy = mkListTy charTy -- convenience only \end{code} -%************************************************************************ -%* * -\subsection[TysWiredIn-state-pairing]{``State-pairing'' types} -%* * -%************************************************************************ - -These boring types pair a \tr{State#} with another primitive type. -They are not really primitive, so they are given here, not in -\tr{TysPrim.lhs}. +\begin{code} +intTy = mkTyConTy intTyCon -We fish one of these \tr{StateAnd#} things with -@getStatePairingConInfo@ (given a little way down). +intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon] +intDataCon = pcDataCon intDataConName [] [] [intPrimTy] intTyCon +\end{code} \begin{code} -stateAndPtrPrimTyCon - = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#") - [alphaTyVar, betaTyVar] [stateAndPtrPrimDataCon] -stateAndPtrPrimDataCon - = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#") - [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, betaTy] - stateAndPtrPrimTyCon nullSpecEnv - -stateAndCharPrimTyCon - = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#") - [alphaTyVar] [stateAndCharPrimDataCon] -stateAndCharPrimDataCon - = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, charPrimTy] - stateAndCharPrimTyCon nullSpecEnv - -stateAndIntPrimTyCon - = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#") - [alphaTyVar] [stateAndIntPrimDataCon] -stateAndIntPrimDataCon - = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, intPrimTy] - stateAndIntPrimTyCon nullSpecEnv - -stateAndWordPrimTyCon - = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#") - [alphaTyVar] [stateAndWordPrimDataCon] -stateAndWordPrimDataCon - = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, wordPrimTy] - stateAndWordPrimTyCon nullSpecEnv - -stateAndAddrPrimTyCon - = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#") - [alphaTyVar] [stateAndAddrPrimDataCon] -stateAndAddrPrimDataCon - = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, addrPrimTy] - stateAndAddrPrimTyCon nullSpecEnv - -stateAndStablePtrPrimTyCon - = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#") - [alphaTyVar, betaTyVar] [stateAndStablePtrPrimDataCon] -stateAndStablePtrPrimDataCon - = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#") - [alphaTyVar, betaTyVar] [] - [mkStatePrimTy alphaTy, applyTyCon stablePtrPrimTyCon [betaTy]] - stateAndStablePtrPrimTyCon nullSpecEnv - -stateAndForeignObjPrimTyCon - = pcDataTyCon stateAndForeignObjPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndForeignObj#") - [alphaTyVar] [stateAndForeignObjPrimDataCon] -stateAndForeignObjPrimDataCon - = pcDataCon stateAndForeignObjPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndForeignObj#") - [alphaTyVar] [] - [mkStatePrimTy alphaTy, applyTyCon foreignObjPrimTyCon []] - stateAndForeignObjPrimTyCon nullSpecEnv - -stateAndFloatPrimTyCon - = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#") - [alphaTyVar] [stateAndFloatPrimDataCon] -stateAndFloatPrimDataCon - = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, floatPrimTy] - stateAndFloatPrimTyCon nullSpecEnv - -stateAndDoublePrimTyCon - = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#") - [alphaTyVar] [stateAndDoublePrimDataCon] -stateAndDoublePrimDataCon - = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, doublePrimTy] - stateAndDoublePrimTyCon nullSpecEnv +wordTy = mkTyConTy wordTyCon + +wordTyCon = pcNonRecDataTyCon wordTyConName [] [] [wordDataCon] +wordDataCon = pcDataCon wordDataConName [] [] [wordPrimTy] wordTyCon \end{code} \begin{code} -stateAndArrayPrimTyCon - = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#") - [alphaTyVar, betaTyVar] [stateAndArrayPrimDataCon] -stateAndArrayPrimDataCon - = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#") - [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkArrayPrimTy betaTy] - stateAndArrayPrimTyCon nullSpecEnv - -stateAndMutableArrayPrimTyCon - = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#") - [alphaTyVar, betaTyVar] [stateAndMutableArrayPrimDataCon] -stateAndMutableArrayPrimDataCon - = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#") - [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkMutableArrayPrimTy alphaTy betaTy] - stateAndMutableArrayPrimTyCon nullSpecEnv - -stateAndByteArrayPrimTyCon - = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#") - [alphaTyVar] [stateAndByteArrayPrimDataCon] -stateAndByteArrayPrimDataCon - = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, byteArrayPrimTy] - stateAndByteArrayPrimTyCon nullSpecEnv - -stateAndMutableByteArrayPrimTyCon - = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#") - [alphaTyVar] [stateAndMutableByteArrayPrimDataCon] -stateAndMutableByteArrayPrimDataCon - = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#") - [alphaTyVar] [] [mkStatePrimTy alphaTy, applyTyCon mutableByteArrayPrimTyCon [alphaTy]] - stateAndMutableByteArrayPrimTyCon nullSpecEnv - -stateAndSynchVarPrimTyCon - = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#") - [alphaTyVar, betaTyVar] [stateAndSynchVarPrimDataCon] -stateAndSynchVarPrimDataCon - = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#") - [alphaTyVar, betaTyVar] [] [mkStatePrimTy alphaTy, mkSynchVarPrimTy alphaTy betaTy] - stateAndSynchVarPrimTyCon nullSpecEnv -\end{code} +floatTy = mkTyConTy floatTyCon -The ccall-desugaring mechanism uses this function to figure out how to -rebox the result. It's really a HACK, especially the part about -how many types to drop from \tr{tys_applied}. +floatTyCon = pcNonRecDataTyCon floatTyConName [] [] [floatDataCon] +floatDataCon = pcDataCon floatDataConName [] [] [floatPrimTy] floatTyCon +\end{code} \begin{code} -getStatePairingConInfo - :: Type -- primitive type - -> (Id, -- state pair constructor for prim type - Type) -- type of state pair - -getStatePairingConInfo prim_ty - = case (maybeAppDataTyConExpandingDicts prim_ty) of - Nothing -> panic "getStatePairingConInfo:1" - Just (prim_tycon, tys_applied, _) -> - let - (pair_con, pair_tycon, num_tys) = assoc "getStatePairingConInfo" tbl prim_tycon - pair_ty = applyTyCon pair_tycon (realWorldTy : drop num_tys tys_applied) - in - (pair_con, pair_ty) - where - tbl = [ - (charPrimTyCon, (stateAndCharPrimDataCon, stateAndCharPrimTyCon, 0)), - (intPrimTyCon, (stateAndIntPrimDataCon, stateAndIntPrimTyCon, 0)), - (wordPrimTyCon, (stateAndWordPrimDataCon, stateAndWordPrimTyCon, 0)), - (addrPrimTyCon, (stateAndAddrPrimDataCon, stateAndAddrPrimTyCon, 0)), - (stablePtrPrimTyCon, (stateAndStablePtrPrimDataCon, stateAndStablePtrPrimTyCon, 0)), - (foreignObjPrimTyCon, (stateAndForeignObjPrimDataCon, stateAndForeignObjPrimTyCon, 0)), - (floatPrimTyCon, (stateAndFloatPrimDataCon, stateAndFloatPrimTyCon, 0)), - (doublePrimTyCon, (stateAndDoublePrimDataCon, stateAndDoublePrimTyCon, 0)), - (arrayPrimTyCon, (stateAndArrayPrimDataCon, stateAndArrayPrimTyCon, 0)), - (mutableArrayPrimTyCon, (stateAndMutableArrayPrimDataCon, stateAndMutableArrayPrimTyCon, 1)), - (byteArrayPrimTyCon, (stateAndByteArrayPrimDataCon, stateAndByteArrayPrimTyCon, 0)), - (mutableByteArrayPrimTyCon, (stateAndMutableByteArrayPrimDataCon, stateAndMutableByteArrayPrimTyCon, 1)), - (synchVarPrimTyCon, (stateAndSynchVarPrimDataCon, stateAndSynchVarPrimTyCon, 1)) - -- (PtrPrimTyCon, (stateAndPtrPrimDataCon, stateAndPtrPrimTyCon, 0)), - ] +doubleTy = mkTyConTy doubleTyCon + +doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [] [doubleDataCon] +doubleDataCon = pcDataCon doubleDataConName [] [] [doublePrimTy] doubleTyCon \end{code} + %************************************************************************ %* * -\subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type} +\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types} %* * %************************************************************************ -This is really just an ordinary synonym, except it is ABSTRACT. - +@Integer@ and its pals are not really primitive. @Integer@ itself, first: \begin{code} -mkStateTransformerTy s a = mkSynTy stTyCon [s, a] - -stTyCon - = let - ty = mkFunTys [mkStateTy alphaTy] (mkTupleTy 2 [betaTy, mkStateTy alphaTy]) - in - mkSynTyCon - (mkBuiltinName stTyConKey gLASGOW_ST SLIT("_ST")) - (mkBoxedTypeKind `mkArrowKind` (mkBoxedTypeKind `mkArrowKind` mkBoxedTypeKind)) - 2 [alphaTyVar, betaTyVar] - ty -\end{code} - -%************************************************************************ -%* * -\subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types} -%* * -%************************************************************************ +integerTy :: Type +integerTy = mkTyConTy integerTyCon -@PrimIO@ and @IO@ really are just plain synonyms. +integerTyCon = pcNonRecDataTyCon integerTyConName + [] [] [smallIntegerDataCon, largeIntegerDataCon] -\begin{code} -mkPrimIoTy a = mkSynTy primIoTyCon [a] - -primIoTyCon - = let - ty = mkStateTransformerTy realWorldTy alphaTy - in --- pprTrace "primIOTyCon:" (ppCat [pprType PprDebug ty, ppr PprDebug (typeKind ty)]) $ - mkSynTyCon - (mkBuiltinName primIoTyConKey pRELUDE_PRIMIO SLIT("PrimIO")) - (mkBoxedTypeKind `mkArrowKind` mkBoxedTypeKind) - 1 [alphaTyVar] ty +smallIntegerDataCon = pcDataCon smallIntegerDataConName + [] [] [intPrimTy] integerTyCon +largeIntegerDataCon = pcDataCon largeIntegerDataConName + [] [] [intPrimTy, byteArrayPrimTy] integerTyCon \end{code} + %************************************************************************ %* * \subsection[TysWiredIn-Bool]{The @Bool@ type} @@ -531,31 +391,14 @@ primitive counterpart. \begin{code} boolTy = mkTyConTy boolTyCon -boolTyCon = pcDataTyCon boolTyConKey pRELUDE SLIT("Bool") [] [falseDataCon, trueDataCon] - -falseDataCon = pcDataCon falseDataConKey pRELUDE SLIT("False") [] [] [] boolTyCon nullSpecEnv -trueDataCon = pcDataCon trueDataConKey pRELUDE SLIT("True") [] [] [] boolTyCon nullSpecEnv -\end{code} - -%************************************************************************ -%* * -\subsection[TysWiredIn-Ordering]{The @Ordering@ type} -%* * -%************************************************************************ +boolTyCon = pcTyCon EnumTyCon NonRecursive boolTyConName + [] [] [falseDataCon, trueDataCon] -\begin{code} ---------------------------------------------- --- data Ordering = LT | EQ | GT deriving () ---------------------------------------------- +falseDataCon = pcDataCon falseDataConName [] [] [] boolTyCon +trueDataCon = pcDataCon trueDataConName [] [] [] boolTyCon -orderingTy = mkTyConTy orderingTyCon - -orderingTyCon = pcDataTyCon orderingTyConKey pRELUDE_BUILTIN SLIT("Ordering") [] - [ltDataCon, eqDataCon, gtDataCon] - -ltDataCon = pcDataCon ltDataConKey pRELUDE_BUILTIN SLIT("LT") [] [] [] orderingTyCon nullSpecEnv -eqDataCon = pcDataCon eqDataConKey pRELUDE_BUILTIN SLIT("EQ") [] [] [] orderingTyCon nullSpecEnv -gtDataCon = pcDataCon gtDataConKey pRELUDE_BUILTIN SLIT("GT") [] [] [] orderingTyCon nullSpecEnv +falseDataConId = dataConWorkId falseDataCon +trueDataConId = dataConWorkId trueDataCon \end{code} %************************************************************************ @@ -565,28 +408,24 @@ gtDataCon = pcDataCon gtDataConKey pRELUDE_BUILTIN SLIT("GT") [] [] [] ordering %************************************************************************ Special syntax, deeply wired in, but otherwise an ordinary algebraic -data type: +data types: \begin{verbatim} -data List a = Nil | a : (List a) -ToDo: data [] a = [] | a : (List a) -ToDo: data () = () - data (,,) a b c = (,,) a b c +data [] a = [] | a : (List a) +data () = () +data (,) a b = (,,) a b +... \end{verbatim} \begin{code} -mkListTy :: GenType t u -> GenType t u -mkListTy ty = applyTyCon listTyCon [ty] - -alphaListTy = mkSigmaTy [alphaTyVar] [] (applyTyCon listTyCon [alphaTy]) +mkListTy :: Type -> Type +mkListTy ty = mkTyConApp listTyCon [ty] -listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("[]") - [alphaTyVar] [nilDataCon, consDataCon] +listTyCon = pcRecDataTyCon listTyConName + alpha_tyvar [(True,False)] [nilDataCon, consDataCon] -nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("[]") [alphaTyVar] [] [] listTyCon - (pcGenerateDataSpecs alphaListTy) -consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":") - [alphaTyVar] [] [alphaTy, applyTyCon listTyCon [alphaTy]] listTyCon - (pcGenerateDataSpecs alphaListTy) +nilDataCon = pcDataCon nilDataConName alpha_tyvar [] [] listTyCon +consDataCon = pcDataCon 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) @@ -639,93 +478,136 @@ done by enumeration\srcloc{lib/prelude/InTup?.hs}. \end{itemize} \begin{code} -mkTupleTy :: Int -> [GenType t u] -> GenType t u +mkTupleTy :: Boxity -> Int -> [Type] -> Type +mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys -mkTupleTy arity tys = applyTyCon (mkTupleTyCon arity) tys - -unitTy = mkTupleTy 0 [] +unitTy = mkTupleTy Boxed 0 [] \end{code} %************************************************************************ %* * -\subsection[TysWiredIn-Ratios]{@Ratio@ and @Rational@} +\subsection[TysWiredIn-PArr]{The @[::]@ type} %* * %************************************************************************ -ToDo: make this (mostly) go away. +Special syntax for parallel arrays needs some wired in definitions. \begin{code} -rationalTy :: GenType t u - -mkRatioTy ty = applyTyCon ratioTyCon [ty] -rationalTy = mkRatioTy integerTy - -ratioTyCon = pcDataTyCon ratioTyConKey rATIO SLIT("Ratio") [alphaTyVar] [ratioDataCon] - -ratioDataCon = pcDataCon ratioDataConKey rATIO SLIT(":%") - [alphaTyVar] [{-(integralClass,alphaTy)-}] [alphaTy, alphaTy] ratioTyCon nullSpecEnv - -- context omitted to match lib/prelude/ defn of "data Ratio ..." - -rationalTyCon - = mkSynTyCon - (mkBuiltinName rationalTyConKey rATIO SLIT("Rational")) - mkBoxedTypeKind - 0 [] rationalTy -- == mkRatioTy integerTy +-- construct a type representing the application of the parallel array +-- constructor +-- +mkPArrTy :: Type -> Type +mkPArrTy ty = mkTyConApp parrTyCon [ty] + +-- 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 = tycon + where + tycon = mkAlgTyCon + parrTyConName + kind + tyvars + [] -- No context + [(True, False)] + (DataCons [parrDataCon]) -- The constructor defined in `PrelPArr' + [] -- No record selectors + DataTyCon + NonRecursive + genInfo + tyvars = alpha_tyvar + mod = nameModule parrTyConName + kind = mkArrowKinds (map tyVarKind tyvars) liftedTypeKind + genInfo = mk_tc_gen_info mod (nameUnique parrTyConName) parrTyConName tycon + +parrDataCon :: DataCon +parrDataCon = pcDataCon + parrDataConName + alpha_tyvar -- forall'ed type variables + [] -- context + [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 + +-- 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 + +-- pre-defined set of constructors +-- +parrFakeConArr :: Array Int DataCon +parrFakeConArr = array (0, mAX_TUPLE_SIZE) [(i, mkPArrFakeCon i) + | i <- [0..mAX_TUPLE_SIZE]] + +-- build a fake parallel array constructor for the given arity +-- +mkPArrFakeCon :: Int -> DataCon +mkPArrFakeCon arity = pcDataCon name [tyvar] [] tyvarTys parrTyCon + where + tyvar = head alphaTyVars + tyvarTys = replicate arity $ mkTyVarTy tyvar + nameStr = mkFastString ("MkPArr" ++ show arity) + name = mkWiredInName mod (mkOccFS dataName nameStr) uniq + uniq = mkPArrDataConUnique arity + mod = mkBasePkgModule pREL_PARR_Name + +-- checks whether a data constructor is a fake constructor for parallel arrays +-- +isPArrFakeCon :: DataCon -> Bool +isPArrFakeCon dcon = dcon == parrFakeCon (dataConSourceArity dcon) \end{code} %************************************************************************ -%* * -\subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing} -%* * +%* * +\subsection{Wired In Type Constructors for Representation Types} +%* * %************************************************************************ -Again, deeply turgid: \tr{data _Lift a = _Lift a}. - -\begin{code} -mkLiftTy ty = applyTyCon liftTyCon [ty] - -{- -mkLiftTy ty - = mkSigmaTy tvs theta (applyTyCon liftTyCon [tau]) - where - (tvs, theta, tau) = splitSigmaTy ty - -isLiftTy ty - = case (maybeAppDataTyConExpandingDicts tau) of - Just (tycon, tys, _) -> tycon == liftTyCon - Nothing -> False - where - (tvs, theta, tau) = splitSigmaTy ty --} - +The following code defines the wired in datatypes cross, plus, unit +and c_of needed for the generic methods. -alphaLiftTy = mkSigmaTy [alphaTyVar] [] (applyTyCon liftTyCon [alphaTy]) +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. -liftTyCon - = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alphaTyVar] [liftDataCon] +\begin{code} +crossTyCon :: TyCon +crossTyCon = pcNonRecDataTyCon crossTyConName alpha_beta_tyvars [] [crossDataCon] -liftDataCon - = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift") - [alphaTyVar] [] [alphaTy] liftTyCon - ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv` - (mkSpecInfo [Just realWorldStatePrimTy] 0 bottom)) - where - bottom = panic "liftDataCon:State# _RealWorld" -\end{code} +crossDataCon :: DataCon +crossDataCon = pcDataCon crossDataConName alpha_beta_tyvars [] [alphaTy, betaTy] crossTyCon +plusTyCon :: TyCon +plusTyCon = pcNonRecDataTyCon plusTyConName alpha_beta_tyvars [] [inlDataCon, inrDataCon] -%************************************************************************ -%* * -\subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)} -%* * -%************************************************************************ +inlDataCon, inrDataCon :: DataCon +inlDataCon = pcDataCon inlDataConName alpha_beta_tyvars [] [alphaTy] plusTyCon +inrDataCon = pcDataCon inrDataConName alpha_beta_tyvars [] [betaTy] plusTyCon -\begin{code} -stringTy = mkListTy charTy +genUnitTyCon :: TyCon -- The "1" type constructor for generics +genUnitTyCon = pcNonRecDataTyCon genUnitTyConName [] [] [genUnitDataCon] -stringTyCon - = mkSynTyCon - (mkBuiltinName stringTyConKey pRELUDE SLIT("String")) - mkBoxedTypeKind - 0 [] stringTy +genUnitDataCon :: DataCon +genUnitDataCon = pcDataCon genUnitDataConName [] [] [] genUnitTyCon \end{code}