X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Fprelude%2FTysWiredIn.lhs;h=36894793416b0b2cc316ca3379570f6528b1d93d;hp=c23cbd4bd6c395e43cfdb5554d25d8c6a683f1d7;hb=fb6d198f498d4e325a540f28aaa6e1d1530839c3;hpb=2108ca662321c38cd07a6f76accd0dcca5ab9699 diff --git a/compiler/prelude/TysWiredIn.lhs b/compiler/prelude/TysWiredIn.lhs index c23cbd4..3689479 100644 --- a/compiler/prelude/TysWiredIn.lhs +++ b/compiler/prelude/TysWiredIn.lhs @@ -3,54 +3,58 @@ % \section[TysWiredIn]{Wired-in knowledge about {\em non-primitive} types} -This module is about types that can be defined in Haskell, but which -must be wired into the compiler nonetheless. - -This module tracks the ``state interface'' document, ``GHC prelude: -types and operations.'' - \begin{code} +-- | This module is about types that can be defined in Haskell, but which +-- must be wired into the compiler nonetheless. C.f module TysPrim module TysWiredIn ( + -- * All wired in things wiredInTyCons, + -- * Bool boolTy, boolTyCon, boolTyCon_RDR, boolTyConName, trueDataCon, trueDataConId, true_RDR, falseDataCon, falseDataConId, false_RDR, + -- * Char charTyCon, charDataCon, charTyCon_RDR, charTy, stringTy, charTyConName, - + -- * Double doubleTyCon, doubleDataCon, doubleTy, doubleTyConName, + -- * Float floatTyCon, floatDataCon, floatTy, floatTyConName, + -- * Int intTyCon, intDataCon, intTyCon_RDR, intDataCon_RDR, intTyConName, intTy, + -- * Word wordTyCon, wordDataCon, wordTyConName, wordTy, + -- * List listTyCon, nilDataCon, consDataCon, listTyCon_RDR, consDataCon_RDR, listTyConName, mkListTy, - -- tuples - mkTupleTy, + -- * Tuples + mkTupleTy, mkBoxedTupleTy, tupleTyCon, tupleCon, unitTyCon, unitDataCon, unitDataConId, pairTyCon, unboxedSingletonTyCon, unboxedSingletonDataCon, unboxedPairTyCon, unboxedPairDataCon, - - boxedTupleArr, unboxedTupleArr, + -- * Unit unitTy, - -- parallel arrays + -- * Parallel arrays mkPArrTy, parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon, parrTyCon_RDR, parrTyConName ) where +#include "HsVersions.h" + import {-# SOURCE #-} MkId( mkDataConIds ) -- friends: @@ -61,10 +65,7 @@ import TysPrim import Constants ( mAX_TUPLE_SIZE ) import Module ( Module ) import RdrName -import Name ( Name, BuiltInSyntax(..), nameUnique, nameOccName, - nameModule, mkWiredInName ) -import OccName ( mkOccNameFS, tcName, dataName, mkTupleOcc, - mkDataConWorkerOcc ) +import Name import DataCon ( DataCon, mkDataCon, dataConWorkId, dataConSourceArity ) import Var import TyCon ( TyCon, AlgTyConRhs(DataTyCon), tyConDataCons, @@ -82,7 +83,7 @@ import Coercion ( unsafeCoercionTyCon, symCoercionTyCon, import TypeRep ( mkArrowKinds, liftedTypeKind, ubxTupleKind ) import Unique ( incrUnique, mkTupleTyConUnique, mkTupleDataConUnique, mkPArrDataConUnique ) -import Array +import Data.Array import FastString import Outputable @@ -136,21 +137,21 @@ wiredInTyCons = [ unitTyCon -- Not treated like other tuples, because \begin{code} mkWiredInTyConName :: BuiltInSyntax -> Module -> FastString -> Unique -> TyCon -> Name mkWiredInTyConName built_in modu fs unique tycon - = mkWiredInName modu (mkOccNameFS tcName fs) unique + = mkWiredInName modu (mkTcOccFS fs) unique (ATyCon tycon) -- Relevant TyCon built_in mkWiredInDataConName :: BuiltInSyntax -> Module -> FastString -> Unique -> DataCon -> Name mkWiredInDataConName built_in modu fs unique datacon - = mkWiredInName modu (mkOccNameFS dataName fs) unique + = mkWiredInName modu (mkDataOccFS fs) unique (ADataCon datacon) -- Relevant DataCon built_in charTyConName, charDataConName, intTyConName, intDataConName :: Name charTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Char") charTyConKey charTyCon charDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "C#") charDataConKey charDataCon -intTyConName = mkWiredInTyConName UserSyntax gHC_BASE (fsLit "Int") intTyConKey intTyCon -intDataConName = mkWiredInDataConName UserSyntax gHC_BASE (fsLit "I#") intDataConKey intDataCon +intTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Int") intTyConKey intTyCon +intDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "I#") intDataConKey intDataCon boolTyConName, falseDataConName, trueDataConName :: Name boolTyConName = mkWiredInTyConName UserSyntax gHC_BOOL (fsLit "Bool") boolTyConKey boolTyCon @@ -163,10 +164,10 @@ nilDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit "[]") ni consDataConName = mkWiredInDataConName BuiltInSyntax gHC_TYPES (fsLit ":") consDataConKey consDataCon floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name -floatTyConName = mkWiredInTyConName UserSyntax gHC_FLOAT (fsLit "Float") floatTyConKey floatTyCon -floatDataConName = mkWiredInDataConName UserSyntax gHC_FLOAT (fsLit "F#") floatDataConKey floatDataCon -doubleTyConName = mkWiredInTyConName UserSyntax gHC_FLOAT (fsLit "Double") doubleTyConKey doubleTyCon -doubleDataConName = mkWiredInDataConName UserSyntax gHC_FLOAT (fsLit "D#") doubleDataConKey doubleDataCon +floatTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon +floatDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "F#") floatDataConKey floatDataCon +doubleTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Double") doubleTyConKey doubleTyCon +doubleDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "D#") doubleDataConKey doubleDataCon parrTyConName, parrDataConName :: Name parrTyConName = mkWiredInTyConName BuiltInSyntax gHC_PARR (fsLit "[::]") parrTyConKey parrTyCon @@ -217,7 +218,6 @@ pcTyCon is_enum is_rec name tyvars cons tyvars [] -- No stupid theta (DataTyCon cons is_enum) - [] -- No record selectors NoParentTyCon is_rec True -- All the wired-in tycons have generics @@ -244,12 +244,14 @@ pcDataConWithFixity declared_infix dc_name tyvars arg_tys tycon [] -- No existential type variables [] -- No equality spec [] -- No theta - arg_tys tycon + arg_tys (mkTyConApp tycon (mkTyVarTys tyvars)) + tycon [] -- No stupid theta (mkDataConIds bogus_wrap_name wrk_name data_con) - modu = nameModule dc_name + modu = ASSERT( isExternalName dc_name ) + nameModule dc_name wrk_occ = mkDataConWorkerOcc (nameOccName dc_name) wrk_key = incrUnique (nameUnique dc_name) wrk_name = mkWiredInName modu wrk_occ wrk_key @@ -324,6 +326,7 @@ unboxedPairDataCon :: DataCon unboxedPairDataCon = tupleCon Unboxed 2 \end{code} + %************************************************************************ %* * \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)} @@ -474,6 +477,7 @@ listTyCon = pcRecDataTyCon listTyConName alpha_tyvar [nilDataCon, consDataCon] nilDataCon :: DataCon nilDataCon = pcDataCon nilDataConName alpha_tyvar [] listTyCon + consDataCon :: DataCon consDataCon = pcDataConWithFixity True {- Declared infix -} consDataConName @@ -530,11 +534,17 @@ done by enumeration\srcloc{lib/prelude/InTup?.hs}. \end{itemize} \begin{code} -mkTupleTy :: Boxity -> Int -> [Type] -> Type -mkTupleTy boxity arity tys = mkTyConApp (tupleTyCon boxity arity) tys +mkTupleTy :: Boxity -> [Type] -> Type +-- Special case for *boxed* 1-tuples, which are represented by the type itself +mkTupleTy boxity [ty] | Boxed <- boxity = ty +mkTupleTy boxity tys = mkTyConApp (tupleTyCon boxity (length tys)) tys + +-- | Build the type of a small tuple that holds the specified type of thing +mkBoxedTupleTy :: [Type] -> Type +mkBoxedTupleTy tys = mkTupleTy Boxed tys unitTy :: Type -unitTy = mkTupleTy Boxed 0 [] +unitTy = mkTupleTy Boxed [] \end{code} %************************************************************************ @@ -546,19 +556,17 @@ unitTy = mkTupleTy Boxed 0 [] Special syntax for parallel arrays needs some wired in definitions. \begin{code} --- construct a type representing the application of the parallel array --- constructor --- +-- | 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 +-- | Represents the type constructor of parallel arrays -- --- * this must match the definition in `PrelPArr' +-- * 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'. +-- @PrelPArr@. -- parrTyCon :: TyCon parrTyCon = pcNonRecDataTyCon parrTyConName alpha_tyvar [parrDataCon] @@ -573,14 +581,13 @@ parrDataCon = pcDataCon alpha_ty] parrTyCon --- check whether a type constructor is the constructor for parallel arrays --- +-- | Check whether a type constructor is the constructor for parallel arrays isPArrTyCon :: TyCon -> Bool isPArrTyCon tc = tyConName tc == parrTyConName --- fake array constructors +-- | Fake array constructors -- --- * these constructors are never really used to represent array values; +-- * 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 @@ -604,12 +611,11 @@ mkPArrFakeCon arity = data_con tyvar = head alphaTyVars tyvarTys = replicate arity $ mkTyVarTy tyvar nameStr = mkFastString ("MkPArr" ++ show arity) - name = mkWiredInName gHC_PARR (mkOccNameFS dataName nameStr) unique + name = mkWiredInName gHC_PARR (mkDataOccFS nameStr) unique (ADataCon data_con) UserSyntax unique = mkPArrDataConUnique arity --- checks whether a data constructor is a fake constructor for parallel arrays --- +-- | Checks whether a data constructor is a fake constructor for parallel arrays isPArrFakeCon :: DataCon -> Bool isPArrFakeCon dcon = dcon == parrFakeCon (dataConSourceArity dcon) \end{code}