X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fprelude%2FTysWiredIn.lhs;h=7f78ecd449fc19951d88f21606c54ddcde78aa7f;hb=0d52a0a134871d317b5f8b53a952c882ce5ae5b6;hp=b0b198cc601af1b308122ff3d7fab9841883a108;hpb=10521d8418fd3a1cf32882718b5bd28992db36fd;p=ghc-hetmet.git diff --git a/ghc/compiler/prelude/TysWiredIn.lhs b/ghc/compiler/prelude/TysWiredIn.lhs index b0b198c..7f78ecd 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,470 +10,319 @@ This module tracks the ``state interface'' document, ``GHC prelude: types and operations.'' \begin{code} -#include "HsVersions.h" - module TysWiredIn ( - addrDataCon, - addrTy, - addrTyCon, - boolTy, - boolTyCon, - charDataCon, - charTy, - charTyCon, - cmpTagTy, - cmpTagTyCon, - consDataCon, - doubleDataCon, - doubleTy, - doubleTyCon, - eqPrimDataCon, - falseDataCon, - floatDataCon, - floatTy, - floatTyCon, - getStatePairingConInfo, - gtPrimDataCon, - intDataCon, + wiredInTyCons, + + boolTy, boolTyCon, boolTyCon_RDR, boolTyConName, + trueDataCon, trueDataConId, true_RDR, + falseDataCon, falseDataConId, false_RDR, + + charTyCon, charDataCon, charTyCon_RDR, + charTy, stringTy, charTyConName, + + + doubleTyCon, doubleDataCon, doubleTy, + + floatTyCon, floatDataCon, floatTy, + + intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName, intTy, - intTyCon, - integerTy, - integerTyCon, - integerDataCon, - liftDataCon, - liftTyCon, - listTyCon, - ltPrimDataCon, - mallocPtrTyCon, - mkLiftTy, + + listTyCon, nilDataCon, consDataCon, + listTyCon_RDR, consDataCon_RDR, listTyConName, mkListTy, - mkPrimIoTy, - mkStateTransformerTy, + + -- tuples mkTupleTy, - nilDataCon, - primIoTyCon, - ratioDataCon, - ratioTyCon, - rationalTy, - rationalTyCon, - realWorldStateTy, - return2GMPsTyCon, - returnIntAndGMPTyCon, - stTyCon, - stablePtrTyCon, - stateAndAddrPrimTyCon, - stateAndArrayPrimTyCon, - stateAndByteArrayPrimTyCon, - stateAndCharPrimTyCon, - stateAndDoublePrimTyCon, - stateAndFloatPrimTyCon, - stateAndIntPrimTyCon, - stateAndMallocPtrPrimTyCon, - stateAndMutableArrayPrimTyCon, - stateAndMutableByteArrayPrimTyCon, - stateAndPtrPrimTyCon, - stateAndStablePtrPrimTyCon, - stateAndSynchVarPrimTyCon, - stateAndWordPrimTyCon, - stateDataCon, - stateTyCon, - stringTy, - stringTyCon, - trueDataCon, + tupleTyCon, tupleCon, + unitTyCon, unitDataCon, unitDataConId, pairTyCon, + unboxedSingletonTyCon, unboxedSingletonDataCon, + unboxedPairTyCon, unboxedPairDataCon, + unitTy, - wordDataCon, - wordTy, - wordTyCon + voidTy, + + -- parallel arrays + mkPArrTy, + parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon, + parrTyCon_RDR, parrTyConName ) where -import Pretty --ToDo:rm debugging only +#include "HsVersions.h" + +import {-# SOURCE #-} MkId( mkDataConIds ) -import PrelFuns -- help functions, types and things +-- friends: +import PrelNames import TysPrim -import AbsUniType ( applyTyCon, mkTupleTyCon, mkSynonymTyCon, - getUniDataTyCon_maybe, mkSigmaTy, TyCon - , pprUniType --ToDo: rm debugging only - IF_ATTACK_PRAGMAS(COMMA cmpTyCon) +-- others: +import Constants ( mAX_TUPLE_SIZE ) +import Module ( Module ) +import RdrName ( nameRdrName ) +import Name ( Name, BuiltInSyntax(..), nameUnique, nameOccName, + nameModule, mkWiredInName ) +import OccName ( mkOccFS, tcName, dataName, mkTupleOcc, mkDataConWorkerOcc ) +import DataCon ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity ) +import Var ( TyVar, tyVarKind ) +import TyCon ( TyCon, AlgTyConRhs(DataTyCon), tyConDataCons, + mkTupleTyCon, mkAlgTyCon, tyConName ) -import IdInfo -import Maybes ( Maybe(..) ) -import Unique -import Util -\end{code} -%************************************************************************ -%* * -\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)} -%* * -%************************************************************************ - -\begin{code} -charTy = UniData charTyCon [] - -charTyCon = pcDataTyCon charTyConKey pRELUDE_BUILTIN SLIT("Char") [] [charDataCon] -charDataCon = pcDataCon charDataConKey pRELUDE_BUILTIN SLIT("C#") [] [] [charPrimTy] charTyCon nullSpecEnv -\end{code} +import BasicTypes ( Arity, RecFlag(..), Boxity(..), isBoxed, StrictnessMark(..) ) -\begin{code} -intTy = UniData intTyCon [] +import Type ( Type, mkTyConTy, mkTyConApp, mkTyVarTy, mkTyVarTys, TyThing(..) ) +import Kind ( mkArrowKinds, liftedTypeKind, ubxTupleKind ) +import Unique ( incrUnique, mkTupleTyConUnique, + mkTupleDataConUnique, mkPArrDataConUnique ) +import PrelNames +import Array +import FastString +import Outputable -intTyCon = pcDataTyCon intTyConKey pRELUDE_BUILTIN SLIT("Int") [] [intDataCon] -intDataCon = pcDataCon intDataConKey pRELUDE_BUILTIN SLIT("I#") [] [] [intPrimTy] intTyCon nullSpecEnv +alpha_tyvar = [alphaTyVar] +alpha_ty = [alphaTy] \end{code} -\begin{code} -wordTy = UniData wordTyCon [] - -wordTyCon = pcDataTyCon wordTyConKey pRELUDE_BUILTIN SLIT("_Word") [] [wordDataCon] -wordDataCon = pcDataCon wordDataConKey pRELUDE_BUILTIN SLIT("W#") [] [] [wordPrimTy] wordTyCon nullSpecEnv -\end{code} -\begin{code} -addrTy = UniData addrTyCon [] +%************************************************************************ +%* * +\subsection{Wired in type constructors} +%* * +%************************************************************************ -addrTyCon = pcDataTyCon addrTyConKey pRELUDE_BUILTIN SLIT("_Addr") [] [addrDataCon] -addrDataCon = pcDataCon addrDataConKey pRELUDE_BUILTIN SLIT("A#") [] [] [addrPrimTy] addrTyCon 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} -floatTy = UniData floatTyCon [] - -floatTyCon = pcDataTyCon floatTyConKey pRELUDE_BUILTIN SLIT("Float") [] [floatDataCon] -floatDataCon = pcDataCon floatDataConKey pRELUDE_BUILTIN SLIT("F#") [] [] [floatPrimTy] floatTyCon nullSpecEnv +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 + , listTyCon + , parrTyCon + ] \end{code} \begin{code} -doubleTy = UniData doubleTyCon [] - -doubleTyCon = pcDataTyCon doubleTyConKey pRELUDE_BUILTIN SLIT("Double") [] [doubleDataCon] -doubleDataCon = pcDataCon doubleDataConKey pRELUDE_BUILTIN SLIT("D#") [] [] [doublePrimTy] doubleTyCon nullSpecEnv +mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name +mkWiredInTyConName built_in mod fs uniq tycon + = mkWiredInName mod (mkOccFS 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 (mkOccFS 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} -\begin{code} -mkStateTy ty = applyTyCon stateTyCon [ty] -realWorldStateTy = mkStateTy realWorldTy -- a common use -stateTyCon = pcDataTyCon stateTyConKey pRELUDE_BUILTIN SLIT("_State") [alpha_tv] [stateDataCon] -stateDataCon - = pcDataCon stateDataConKey pRELUDE_BUILTIN SLIT("S#") - [alpha_tv] [] [mkStatePrimTy alpha] stateTyCon nullSpecEnv -\end{code} +%************************************************************************ +%* * +\subsection{mkWiredInTyCon} +%* * +%************************************************************************ \begin{code} -{- OLD: -byteArrayTyCon - = pcDataTyCon byteArrayTyConKey pRELUDE_ARRAY SLIT("_ByteArray") - [alpha_tv] [byteArrayDataCon] - -byteArrayDataCon - = pcDataCon byteArrayDataConKey pRELUDE_ARRAY SLIT("_ByteArray") - [alpha_tv] [] - [mkTupleTy 2 [alpha, alpha], byteArrayPrimTy] - byteArrayTyCon nullSpecEnv --} -\end{code} +pcNonRecDataTyCon = pcTyCon False NonRecursive +pcRecDataTyCon = pcTyCon False Recursive -\begin{code} -{- OLD: -mutableArrayTyCon - = pcDataTyCon mutableArrayTyConKey gLASGOW_ST SLIT("_MutableArray") - [alpha_tv, beta_tv, gamma_tv] [mutableArrayDataCon] +pcTyCon is_enum is_rec name tyvars argvrcs cons + = tycon where - mutableArrayDataCon - = pcDataCon mutableArrayDataConKey gLASGOW_ST SLIT("_MutableArray") - [alpha_tv, beta_tv, gamma_tv] [] - [mkTupleTy 2 [beta, beta], applyTyCon mutableArrayPrimTyCon [alpha, gamma]] - mutableArrayTyCon nullSpecEnv --} -\end{code} - -\begin{code} -{- -mutableByteArrayTyCon - = pcDataTyCon mutableByteArrayTyConKey gLASGOW_ST SLIT("_MutableByteArray") - [alpha_tv, beta_tv] [mutableByteArrayDataCon] - -mutableByteArrayDataCon - = pcDataCon mutableByteArrayDataConKey gLASGOW_ST SLIT("_MutableByteArray") - [alpha_tv, beta_tv] [] - [mkTupleTy 2 [beta, beta], mkMutableByteArrayPrimTy alpha] - mutableByteArrayTyCon nullSpecEnv --} -\end{code} - -\begin{code} -stablePtrTyCon - = pcDataTyCon stablePtrTyConKey gLASGOW_MISC SLIT("_StablePtr") - [alpha_tv] [stablePtrDataCon] + tycon = mkAlgTyCon name + (mkArrowKinds (map tyVarKind tyvars) liftedTypeKind) + tyvars + argvrcs + (DataTyCon (Just []) cons is_enum) + [] -- No record selectors + is_rec + True -- All the wired-in tycons have generics + +pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon +pcDataCon = pcDataConWithFixity False + +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, +-- the second is used for the "worker name" + +pcDataConWithFixity declared_infix dc_name tyvars arg_tys tycon + = data_con where - stablePtrDataCon - = pcDataCon stablePtrDataConKey gLASGOW_MISC SLIT("_StablePtr") - [alpha_tv] [] [applyTyCon stablePtrPrimTyCon [alpha]] stablePtrTyCon nullSpecEnv + 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} -\begin{code} -mallocPtrTyCon - = pcDataTyCon mallocPtrTyConKey gLASGOW_MISC SLIT("_MallocPtr") - [] [mallocPtrDataCon] - where - mallocPtrDataCon - = pcDataCon mallocPtrDataConKey gLASGOW_MISC SLIT("_MallocPtr") - [] [] [applyTyCon mallocPtrPrimTyCon []] mallocPtrTyCon nullSpecEnv -\end{code} %************************************************************************ %* * -\subsection[TysWiredIn-Integer]{@Integer@ and its related ``pairing'' types} +\subsection[TysWiredIn-tuples]{The tuple types} %* * %************************************************************************ -@Integer@ and its pals are not really primitive. @Integer@ itself, first: \begin{code} -integerTy :: UniType -integerTy = UniData integerTyCon [] - -integerTyCon = pcDataTyCon integerTyConKey pRELUDE_BUILTIN SLIT("Integer") [] [integerDataCon] - -#ifndef DPH -integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#") - [] [] [intPrimTy, intPrimTy, byteArrayPrimTy] integerTyCon nullSpecEnv -#else --- DPH: For the time being we implement Integers in the same way as Ints. -integerDataCon = pcDataCon integerDataConKey pRELUDE_BUILTIN SLIT("J#") - [] [] [intPrimTy] integerTyCon nullSpecEnv -#endif {- Data Parallel Haskell -} -\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 - -returnIntAndGMPTyCon = pcDataTyCon returnIntAndGMPTyConKey - pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [returnIntAndGMPDataCon] - -returnIntAndGMPDataCon - = pcDataCon returnIntAndGMPDataConKey pRELUDE_BUILTIN SLIT("_ReturnIntAndGMP") [] [] - [intPrimTy, intPrimTy, intPrimTy, byteArrayPrimTy] returnIntAndGMPTyCon nullSpecEnv +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 + tycon = mkTupleTyCon tc_name tc_kind arity tyvars tuple_con boxity gen_info + 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 = ubxTupleKind + + tyvars | isBoxed boxity = take arity alphaTyVars + | otherwise = take arity openAlphaTyVars + + tuple_con = pcDataCon dc_name tyvars tyvar_tys tycon + tyvar_tys = mkTyVarTys tyvars + 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 + gen_info = True -- Tuples all have generics.. + -- hmm: that's a *lot* of code + +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-state-pairing]{``State-pairing'' types} +\subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)} %* * %************************************************************************ -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}. - -We fish one of these \tr{StateAnd#} things with -@getStatePairingConInfo@ (given a little way down). - -\begin{code} -stateAndPtrPrimTyCon - = pcDataTyCon stateAndPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndPtr#") - [alpha_tv, beta_tv] [stateAndPtrPrimDataCon] -stateAndPtrPrimDataCon - = pcDataCon stateAndPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndPtr#") - [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, beta] - stateAndPtrPrimTyCon nullSpecEnv - -stateAndCharPrimTyCon - = pcDataTyCon stateAndCharPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndChar#") - [alpha_tv] [stateAndCharPrimDataCon] -stateAndCharPrimDataCon - = pcDataCon stateAndCharPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndChar#") - [alpha_tv] [] [mkStatePrimTy alpha, charPrimTy] - stateAndCharPrimTyCon nullSpecEnv - -stateAndIntPrimTyCon - = pcDataTyCon stateAndIntPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndInt#") - [alpha_tv] [stateAndIntPrimDataCon] -stateAndIntPrimDataCon - = pcDataCon stateAndIntPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndInt#") - [alpha_tv] [] [mkStatePrimTy alpha, intPrimTy] - stateAndIntPrimTyCon nullSpecEnv - -stateAndWordPrimTyCon - = pcDataTyCon stateAndWordPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndWord#") - [alpha_tv] [stateAndWordPrimDataCon] -stateAndWordPrimDataCon - = pcDataCon stateAndWordPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndWord#") - [alpha_tv] [] [mkStatePrimTy alpha, wordPrimTy] - stateAndWordPrimTyCon nullSpecEnv - -stateAndAddrPrimTyCon - = pcDataTyCon stateAndAddrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndAddr#") - [alpha_tv] [stateAndAddrPrimDataCon] -stateAndAddrPrimDataCon - = pcDataCon stateAndAddrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndAddr#") - [alpha_tv] [] [mkStatePrimTy alpha, addrPrimTy] - stateAndAddrPrimTyCon nullSpecEnv - -stateAndStablePtrPrimTyCon - = pcDataTyCon stateAndStablePtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#") - [alpha_tv, beta_tv] [stateAndStablePtrPrimDataCon] -stateAndStablePtrPrimDataCon - = pcDataCon stateAndStablePtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndStablePtr#") - [alpha_tv, beta_tv] [] - [mkStatePrimTy alpha, applyTyCon stablePtrPrimTyCon [beta]] - stateAndStablePtrPrimTyCon nullSpecEnv - -stateAndMallocPtrPrimTyCon - = pcDataTyCon stateAndMallocPtrPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#") - [alpha_tv] [stateAndMallocPtrPrimDataCon] -stateAndMallocPtrPrimDataCon - = pcDataCon stateAndMallocPtrPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMallocPtr#") - [alpha_tv] [] - [mkStatePrimTy alpha, applyTyCon mallocPtrPrimTyCon []] - stateAndMallocPtrPrimTyCon nullSpecEnv - -stateAndFloatPrimTyCon - = pcDataTyCon stateAndFloatPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndFloat#") - [alpha_tv] [stateAndFloatPrimDataCon] -stateAndFloatPrimDataCon - = pcDataCon stateAndFloatPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndFloat#") - [alpha_tv] [] [mkStatePrimTy alpha, floatPrimTy] - stateAndFloatPrimTyCon nullSpecEnv - -stateAndDoublePrimTyCon - = pcDataTyCon stateAndDoublePrimTyConKey pRELUDE_BUILTIN SLIT("StateAndDouble#") - [alpha_tv] [stateAndDoublePrimDataCon] -stateAndDoublePrimDataCon - = pcDataCon stateAndDoublePrimDataConKey pRELUDE_BUILTIN SLIT("StateAndDouble#") - [alpha_tv] [] [mkStatePrimTy alpha, doublePrimTy] - stateAndDoublePrimTyCon nullSpecEnv -\end{code} - \begin{code} -stateAndArrayPrimTyCon - = pcDataTyCon stateAndArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndArray#") - [alpha_tv, beta_tv] [stateAndArrayPrimDataCon] -stateAndArrayPrimDataCon - = pcDataCon stateAndArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndArray#") - [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkArrayPrimTy beta] - stateAndArrayPrimTyCon nullSpecEnv - -stateAndMutableArrayPrimTyCon - = pcDataTyCon stateAndMutableArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#") - [alpha_tv, beta_tv] [stateAndMutableArrayPrimDataCon] -stateAndMutableArrayPrimDataCon - = pcDataCon stateAndMutableArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableArray#") - [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkMutableArrayPrimTy alpha beta] - stateAndMutableArrayPrimTyCon nullSpecEnv - -stateAndByteArrayPrimTyCon - = pcDataTyCon stateAndByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#") - [alpha_tv] [stateAndByteArrayPrimDataCon] -stateAndByteArrayPrimDataCon - = pcDataCon stateAndByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndByteArray#") - [alpha_tv] [] [mkStatePrimTy alpha, byteArrayPrimTy] - stateAndByteArrayPrimTyCon nullSpecEnv - -stateAndMutableByteArrayPrimTyCon - = pcDataTyCon stateAndMutableByteArrayPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#") - [alpha_tv] [stateAndMutableByteArrayPrimDataCon] -stateAndMutableByteArrayPrimDataCon - = pcDataCon stateAndMutableByteArrayPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndMutableByteArray#") - [alpha_tv] [] [mkStatePrimTy alpha, applyTyCon mutableByteArrayPrimTyCon [alpha]] - stateAndMutableByteArrayPrimTyCon nullSpecEnv - -stateAndSynchVarPrimTyCon - = pcDataTyCon stateAndSynchVarPrimTyConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#") - [alpha_tv, beta_tv] [stateAndSynchVarPrimDataCon] -stateAndSynchVarPrimDataCon - = pcDataCon stateAndSynchVarPrimDataConKey pRELUDE_BUILTIN SLIT("StateAndSynchVar#") - [alpha_tv, beta_tv] [] [mkStatePrimTy alpha, mkSynchVarPrimTy alpha beta] - stateAndSynchVarPrimTyCon 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} -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}. \begin{code} -getStatePairingConInfo - :: UniType -- primitive type - -> (Id, -- state pair constructor for prim type - UniType) -- type of state pair - -getStatePairingConInfo prim_ty - = case (getUniDataTyCon_maybe 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)), - (mallocPtrPrimTyCon, (stateAndMallocPtrPrimDataCon, stateAndMallocPtrPrimTyCon, 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)), - ] -\end{code} +charTy = mkTyConTy charTyCon -%************************************************************************ -%* * -\subsection[TysWiredIn-ST]{The basic @_ST@ state-transformer type} -%* * -%************************************************************************ +charTyCon = pcNonRecDataTyCon charTyConName [] [] [charDataCon] +charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon -This is really just an ordinary synonym, except it is ABSTRACT. +stringTy = mkListTy charTy -- convenience only +\end{code} \begin{code} -mkStateTransformerTy s a = applyTyCon stTyCon [s, a] - -stTyCon - = mkSynonymTyCon - stTyConKey - (mkPreludeCoreName gLASGOW_ST SLIT("_ST")) - 2 - [alpha_tv, beta_tv] - (mkStateTy alpha `UniFun` mkTupleTy 2 [beta, mkStateTy alpha]) - True -- ToDo: make... *** ABSTRACT *** +intTy = mkTyConTy intTyCon + +intTyCon = pcNonRecDataTyCon intTyConName [] [] [intDataCon] +intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon \end{code} -%************************************************************************ -%* * -\subsection[TysWiredIn-IO]{The @PrimIO@ and @IO@ monadic-I/O types} -%* * -%************************************************************************ +\begin{code} +floatTy = mkTyConTy floatTyCon -@PrimIO@ and @IO@ really are just a plain synonyms. +floatTyCon = pcNonRecDataTyCon floatTyConName [] [] [floatDataCon] +floatDataCon = pcDataCon floatDataConName [] [floatPrimTy] floatTyCon +\end{code} \begin{code} -mkPrimIoTy a = applyTyCon primIoTyCon [a] - -primIoTyCon - = mkSynonymTyCon - primIoTyConKey - (mkPreludeCoreName pRELUDE_PRIMIO SLIT("PrimIO")) - 1 - [alpha_tv] - (mkStateTransformerTy realWorldTy alpha) - True -- need not be abstract +doubleTy = mkTyConTy doubleTyCon + +doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [] [doubleDataCon] +doubleDataCon = pcDataCon doubleDataConName [] [doublePrimTy] doubleTyCon \end{code} + %************************************************************************ %* * \subsection[TysWiredIn-Bool]{The @Bool@ type} @@ -523,33 +372,16 @@ primitive counterpart. {\em END IDLE SPECULATION BY SIMON} \begin{code} -boolTy = UniData boolTyCon [] +boolTy = mkTyConTy boolTyCon -boolTyCon = pcDataTyCon boolTyConKey pRELUDE_CORE SLIT("Bool") [] [falseDataCon, trueDataCon] +boolTyCon = pcTyCon True NonRecursive boolTyConName + [] [] [falseDataCon, trueDataCon] -falseDataCon = pcDataCon falseDataConKey pRELUDE_CORE SLIT("False") [] [] [] boolTyCon nullSpecEnv -trueDataCon = pcDataCon trueDataConKey pRELUDE_CORE SLIT("True") [] [] [] boolTyCon nullSpecEnv -\end{code} +falseDataCon = pcDataCon falseDataConName [] [] boolTyCon +trueDataCon = pcDataCon trueDataConName [] [] boolTyCon -%************************************************************************ -%* * -\subsection[TysWiredIn-CMP-TAG]{The @CMP_TAG#@ type (for fast `derived' comparisons)} -%* * -%************************************************************************ - -\begin{code} ---------------------------------------------- --- data _CMP_TAG = _LT | _EQ | _GT deriving () ---------------------------------------------- - -cmpTagTy = UniData cmpTagTyCon [] - -cmpTagTyCon = pcDataTyCon cmpTagTyConKey pRELUDE_BUILTIN SLIT("_CMP_TAG") [] - [ltPrimDataCon, eqPrimDataCon, gtPrimDataCon] - -ltPrimDataCon = pcDataCon ltTagDataConKey pRELUDE_BUILTIN SLIT("_LT") [] [] [] cmpTagTyCon nullSpecEnv -eqPrimDataCon = pcDataCon eqTagDataConKey pRELUDE_BUILTIN SLIT("_EQ") [] [] [] cmpTagTyCon nullSpecEnv -gtPrimDataCon = pcDataCon gtTagDataConKey pRELUDE_BUILTIN SLIT("_GT") [] [] [] cmpTagTyCon nullSpecEnv +falseDataConId = dataConWorkId falseDataCon +trueDataConId = dataConWorkId trueDataCon \end{code} %************************************************************************ @@ -559,38 +391,28 @@ gtPrimDataCon = pcDataCon gtTagDataConKey pRELUDE_BUILTIN SLIT("_GT") [] [] [] %************************************************************************ Special syntax, deeply wired in, but otherwise an ordinary algebraic -data type: +data types: \begin{verbatim} -data List a = Nil | a : (List a) +data [] a = [] | a : (List a) +data () = () +data (,) a b = (,,) a b +... \end{verbatim} \begin{code} -mkListTy :: UniType -> UniType -mkListTy ty = UniData listTyCon [ty] - -alphaListTy = mkSigmaTy [alpha_tv] [] (mkListTy alpha) - -listTyCon = pcDataTyCon listTyConKey pRELUDE_BUILTIN SLIT("List") [alpha_tv] [nilDataCon, consDataCon] - -nilDataCon = pcDataCon nilDataConKey pRELUDE_BUILTIN SLIT("Nil") [alpha_tv] [] [] listTyCon - (pcGenerateDataSpecs alphaListTy) -consDataCon = pcDataCon consDataConKey pRELUDE_BUILTIN SLIT(":") - [alpha_tv] [] [alpha, mkListTy alpha] listTyCon - (pcGenerateDataSpecs alphaListTy) -\end{code} - -This is the @_Build@ data constructor, it does {\em not} appear inside -listTyCon. It has this type: \tr{((a -> b -> b) -> b -> b) -> [a]}. -\begin{code} -{- NOT USED: -buildDataCon - = pcDataCon buildDataConKey pRELUDE_BUILTIN "Build" - [alpha_tv] [] [ - mkSigmaTy [beta_tv] [] - ((alpha `UniFun` (beta `UniFun` beta)) - `UniFun` (beta - `UniFun` beta))] listTyCon nullSpecEnv --} +mkListTy :: Type -> Type +mkListTy ty = mkTyConApp listTyCon [ty] + +listTyCon = pcRecDataTyCon listTyConName + alpha_tyvar [(True,False)] [nilDataCon, consDataCon] + +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) \end{code} %************************************************************************ @@ -604,14 +426,12 @@ family. \begin{itemize} \item -They have a special family of type constructors, of type -@TyCon@\srcloc{uniType/TyCon.lhs}. +They have a special family of type constructors, of type @TyCon@ These contain the tycon arity, but don't require a Unique. \item They have a special family of constructors, of type -@Id@\srcloc{basicTypes/Id.lhs}. Again these contain their arity but -don't need a Unique. +@Id@. Again these contain their arity but don't need a Unique. \item There should be a magic way of generating the info tables and @@ -642,117 +462,86 @@ done by enumeration\srcloc{lib/prelude/InTup?.hs}. \end{itemize} \begin{code} -mkTupleTy :: Int -> [UniType] -> UniType +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 :: UniType - -mkRatioTy ty = UniData ratioTyCon [ty] -rationalTy = mkRatioTy integerTy - -ratioTyCon = pcDataTyCon ratioTyConKey pRELUDE_RATIO SLIT("Ratio") [alpha_tv] [ratioDataCon] - -ratioDataCon = pcDataCon ratioDataConKey pRELUDE_RATIO SLIT(":%") - [alpha_tv] [{-(integralClass,alpha)-}] [alpha, alpha] ratioTyCon nullSpecEnv - -- context omitted to match lib/prelude/ defn of "data Ratio ..." - -rationalTyCon - = mkSynonymTyCon - rationalTyConKey - (mkPreludeCoreName pRELUDE_RATIO SLIT("Rational")) - 0 -- arity - [] -- tyvars - rationalTy -- == mkRatioTy integerTy - True -- unabstract -\end{code} - -%************************************************************************ -%* * -\subsection[TysWiredIn-_Lift]{@_Lift@ type: to support array indexing} -%* * -%************************************************************************ - -Again, deeply turgid: \tr{data _Lift a = _Lift a}. - -\begin{code} -mkLiftTy ty = applyTyCon liftTyCon [ty] - -{- -mkLiftTy ty - = mkSigmaTy tvs theta (UniData liftTyCon [tau]) - where - (tvs, theta, tau) = splitType ty - -isLiftTy ty - = case getUniDataTyCon_maybe tau of - Just (tycon, tys, _) -> tycon == liftTyCon - Nothing -> False - where - (tvs, theta, tau) = splitType ty --} - - -alphaLiftTy = mkSigmaTy [alpha_tv] [] (UniData liftTyCon [alpha]) - -liftTyCon - = pcDataTyCon liftTyConKey pRELUDE_BUILTIN SLIT("_Lift") [alpha_tv] [liftDataCon] - -liftDataCon - = pcDataCon liftDataConKey pRELUDE_BUILTIN SLIT("_Lift") - [alpha_tv] [] [alpha] liftTyCon - ((pcGenerateDataSpecs alphaLiftTy) `addOneToSpecEnv` - (SpecInfo [Just realWorldStatePrimTy] 0 bottom)) +-- 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 = 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 + +-- 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 = data_con where - bottom = panic "liftDataCon:State# _RealWorld" -\end{code} - - -%************************************************************************ -%* * -\subsection[TysWiredIn-for-convenience]{Types wired in for convenience (e.g., @String@)} -%* * -%************************************************************************ - -\begin{code} -stringTy = mkListTy charTy - -stringTyCon - = mkSynonymTyCon - stringTyConKey - (mkPreludeCoreName pRELUDE_CORE SLIT("String")) - 0 - [] -- type variables - stringTy - True -- unabstract + data_con = pcDataCon name [tyvar] tyvarTys parrTyCon + tyvar = head alphaTyVars + tyvarTys = replicate arity $ mkTyVarTy tyvar + nameStr = mkFastString ("MkPArr" ++ show arity) + name = mkWiredInName pREL_PARR (mkOccFS 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} -\begin{code} -{- UNUSED: -packedStringTy = applyTyCon packedStringTyCon [] - -packedStringTyCon - = pcDataTyCon packedStringTyConKey pRELUDE_PS SLIT("_PackedString") [] - [psDataCon, cpsDataCon] - -psDataCon - = pcDataCon psDataConKey pRELUDE_PS SLIT("_PS") - [] [] [intPrimTy, byteArrayPrimTy] packedStringTyCon - -cpsDataCon - = pcDataCon cpsDataConKey pRELUDE_PS SLIT("_CPS") - [] [] [addrPrimTy] packedStringTyCon --} -\end{code}