summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-02-17 14:01:41 +0000
committerSimon Peyton Jones <simonpj@microsoft.com>2012-02-17 14:01:41 +0000
commit4c29dcb6ed80f5397b7b52c2e70341f7ccf344dc (patch)
treea9b54ad74c11b19912f2930ebd988acd67b4c806
parent1bc80144de86ba1972fc693f5046efe46884bb10 (diff)
parent6f4a073ed837e6db9466e98ea0fd8ddd4368f637 (diff)
downloadhaskell-4c29dcb6ed80f5397b7b52c2e70341f7ccf344dc.tar.gz
Merge branch 'master' of http://darcs.haskell.org/ghc
-rw-r--r--compiler/coreSyn/CoreLint.lhs5
-rw-r--r--compiler/deSugar/DsForeign.lhs39
-rw-r--r--compiler/hsSyn/Convert.lhs16
-rw-r--r--compiler/hsSyn/HsDecls.lhs2
-rw-r--r--compiler/iface/BinIface.hs12
-rw-r--r--compiler/iface/BuildTyCl.lhs11
-rw-r--r--compiler/iface/IfaceSyn.lhs2
-rw-r--r--compiler/iface/MkIface.lhs2
-rw-r--r--compiler/iface/TcIface.lhs6
-rw-r--r--compiler/parser/Lexer.x4
-rw-r--r--compiler/parser/Parser.y.pp62
-rw-r--r--compiler/parser/RdrHsSyn.lhs11
-rw-r--r--compiler/prelude/ForeignCall.lhs13
-rw-r--r--compiler/prelude/TysWiredIn.lhs34
-rw-r--r--compiler/rename/RnSource.lhs12
-rw-r--r--compiler/typecheck/TcGenGenerics.lhs2
-rw-r--r--compiler/typecheck/TcInstDcls.lhs5
-rw-r--r--compiler/typecheck/TcTyClsDecls.lhs13
-rw-r--r--compiler/types/TyCon.lhs764
-rw-r--r--compiler/vectorise/Vectorise/Generic/PData.hs1
-rw-r--r--compiler/vectorise/Vectorise/Type/Env.hs2
-rw-r--r--compiler/vectorise/Vectorise/Type/TyConDecl.hs1
-rw-r--r--ghc/GhciMonad.hs5
23 files changed, 557 insertions, 467 deletions
diff --git a/compiler/coreSyn/CoreLint.lhs b/compiler/coreSyn/CoreLint.lhs
index 47e25839fa..4a5143bcb9 100644
--- a/compiler/coreSyn/CoreLint.lhs
+++ b/compiler/coreSyn/CoreLint.lhs
@@ -7,7 +7,6 @@
A ``lint'' pass to check for Core correctness
\begin{code}
-{-# OPTIONS_GHC -fprof-auto #-}
{-# OPTIONS -fno-warn-tabs #-}
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and
@@ -15,6 +14,10 @@ A ``lint'' pass to check for Core correctness
-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
-- for details
+#if __GLASGOW_HASKELL__ >= 704
+{-# OPTIONS_GHC -fprof-auto #-}
+#endif
+
module CoreLint ( lintCoreBindings, lintUnfolding ) where
#include "HsVersions.h"
diff --git a/compiler/deSugar/DsForeign.lhs b/compiler/deSugar/DsForeign.lhs
index b613fbdcec..55b2b234e3 100644
--- a/compiler/deSugar/DsForeign.lhs
+++ b/compiler/deSugar/DsForeign.lhs
@@ -11,6 +11,8 @@ module DsForeign ( dsForeigns ) where
#include "HsVersions.h"
import TcRnMonad -- temp
+import TypeRep
+
import CoreSyn
import DsCCall
@@ -227,12 +229,12 @@ dsFCall fn_id co fcall headerFilename = do
Nothing -> io_res_ty
isVoidRes = raw_res_ty `eqType` unitTy
cResType | isVoidRes = text "void"
- | otherwise = showStgType raw_res_ty
+ | otherwise = toCType raw_res_ty
pprCconv = ccallConvAttribute CApiConv
argTypes
| null arg_tys = text "void"
| otherwise = hsep $ punctuate comma
- [ showStgType t <+> char 'a' <> int n
+ [ toCType t <+> char 'a' <> int n
| (t, n) <- zip arg_tys [1..] ]
argVals = hsep $ punctuate comma
[ char 'a' <> int n
@@ -496,7 +498,7 @@ mkFExportCBits dflags c_nm maybe_target arg_htys res_hty is_IO_res_ty cc
SDoc, -- C type
Type, -- Haskell type
CmmType)] -- the CmmType
- arg_info = [ let stg_type = showStgType ty in
+ arg_info = [ let stg_type = toCType ty in
(arg_cname n stg_type,
stg_type,
ty,
@@ -533,7 +535,7 @@ mkFExportCBits dflags c_nm maybe_target arg_htys res_hty is_IO_res_ty cc
res_hty_is_unit = res_hty `eqType` unitTy -- Look through any newtypes
cResType | res_hty_is_unit = text "void"
- | otherwise = showStgType res_hty
+ | otherwise = toCType res_hty
-- when the return type is integral and word-sized or smaller, it
-- must be assigned as type ffi_arg (#3516). To see what type
@@ -661,12 +663,35 @@ mkHObj t = text "rts_mk" <> text (showFFIType t)
unpackHObj :: Type -> SDoc
unpackHObj t = text "rts_get" <> text (showFFIType t)
-showStgType :: Type -> SDoc
-showStgType t = text "Hs" <> text (showFFIType t)
-
showFFIType :: Type -> String
showFFIType t = getOccString (getName (typeTyCon t))
+toCType :: Type -> SDoc
+toCType = f False
+ where f voidOK t
+ -- First, if we have (Ptr t) of (FunPtr t), then we need to
+ -- convert t to a C type and put a * after it. If we don't
+ -- know a type for t, then "void" is fine, though.
+ | Just (ptr, [t']) <- splitTyConApp_maybe t
+ , tyConName ptr `elem` [ptrTyConName, funPtrTyConName]
+ = f True t' <> char '*'
+ -- Otherwise, if we have a type constructor application, then
+ -- see if there is a C type associated with that constructor.
+ -- Note that we aren't looking through type synonyms or
+ -- anything, as it may be the synonym that is annotated.
+ | TyConApp tycon _ <- t
+ , Just (CType cType) <- tyConCType_maybe tycon
+ = ftext cType
+ -- If we don't know a C type for this type, then try looking
+ -- through one layer of type synonym etc.
+ | Just t' <- coreView t
+ = f voidOK t'
+ -- Otherwise we don't know the C type. If we are allowing
+ -- void then return that; otherwise something has gone wrong.
+ | voidOK = ptext (sLit "void")
+ | otherwise
+ = pprPanic "toCType" (ppr t)
+
typeTyCon :: Type -> TyCon
typeTyCon ty = case tcSplitTyConApp_maybe (repType ty) of
Just (tc,_) -> tc
diff --git a/compiler/hsSyn/Convert.lhs b/compiler/hsSyn/Convert.lhs
index 5318c5be49..0d7c960289 100644
--- a/compiler/hsSyn/Convert.lhs
+++ b/compiler/hsSyn/Convert.lhs
@@ -161,13 +161,14 @@ cvtDec (PragmaD prag)
cvtDec (TySynD tc tvs rhs)
= do { (_, tc', tvs') <- cvt_tycl_hdr [] tc tvs
; rhs' <- cvtType rhs
- ; returnL $ TyClD (TySynonym tc' tvs' Nothing rhs') }
+ ; returnL $ TyClD (TySynonym tc' Nothing tvs' Nothing rhs') }
cvtDec (DataD ctxt tc tvs constrs derivs)
= do { (ctxt', tc', tvs') <- cvt_tycl_hdr ctxt tc tvs
; cons' <- mapM cvtConstr constrs
; derivs' <- cvtDerivs derivs
- ; returnL $ TyClD (TyData { tcdND = DataType, tcdLName = tc', tcdCtxt = ctxt'
+ ; returnL $ TyClD (TyData { tcdND = DataType, tcdCType = Nothing
+ , tcdLName = tc', tcdCtxt = ctxt'
, tcdTyVars = tvs', tcdTyPats = Nothing, tcdKindSig = Nothing
, tcdCons = cons', tcdDerivs = derivs' }) }
@@ -175,7 +176,8 @@ cvtDec (NewtypeD ctxt tc tvs constr derivs)
= do { (ctxt', tc', tvs') <- cvt_tycl_hdr ctxt tc tvs
; con' <- cvtConstr constr
; derivs' <- cvtDerivs derivs
- ; returnL $ TyClD (TyData { tcdND = NewType, tcdLName = tc', tcdCtxt = ctxt'
+ ; returnL $ TyClD (TyData { tcdND = NewType, tcdCType = Nothing
+ , tcdLName = tc', tcdCtxt = ctxt'
, tcdTyVars = tvs', tcdTyPats = Nothing, tcdKindSig = Nothing
, tcdCons = [con'], tcdDerivs = derivs'}) }
@@ -214,7 +216,8 @@ cvtDec (DataInstD ctxt tc tys constrs derivs)
; cons' <- mapM cvtConstr constrs
; derivs' <- cvtDerivs derivs
; returnL $ InstD $ FamInstDecl $
- TyData { tcdND = DataType, tcdLName = tc', tcdCtxt = ctxt'
+ TyData { tcdND = DataType, tcdCType = Nothing
+ , tcdLName = tc', tcdCtxt = ctxt'
, tcdTyVars = tvs', tcdTyPats = typats', tcdKindSig = Nothing
, tcdCons = cons', tcdDerivs = derivs' } }
@@ -223,7 +226,8 @@ cvtDec (NewtypeInstD ctxt tc tys constr derivs)
; con' <- cvtConstr constr
; derivs' <- cvtDerivs derivs
; returnL $ InstD $ FamInstDecl $
- TyData { tcdND = NewType, tcdLName = tc', tcdCtxt = ctxt'
+ TyData { tcdND = NewType, tcdCType = Nothing
+ , tcdLName = tc', tcdCtxt = ctxt'
, tcdTyVars = tvs', tcdTyPats = typats', tcdKindSig = Nothing
, tcdCons = [con'], tcdDerivs = derivs' } }
@@ -231,7 +235,7 @@ cvtDec (TySynInstD tc tys rhs)
= do { (_, tc', tvs', tys') <- cvt_tyinst_hdr [] tc tys
; rhs' <- cvtType rhs
; returnL $ InstD $ FamInstDecl $
- TySynonym tc' tvs' tys' rhs' }
+ TySynonym tc' Nothing tvs' tys' rhs' }
----------------
cvt_ci_decs :: MsgDoc -> [TH.Dec]
diff --git a/compiler/hsSyn/HsDecls.lhs b/compiler/hsSyn/HsDecls.lhs
index e6d369c519..e9403104e6 100644
--- a/compiler/hsSyn/HsDecls.lhs
+++ b/compiler/hsSyn/HsDecls.lhs
@@ -465,6 +465,7 @@ data TyClDecl name
tcdCtxt :: LHsContext name, -- ^ Context
tcdLName :: Located name, -- ^ Type constructor
+ tcdCType :: Maybe CType,
tcdTyVars :: [LHsTyVarBndr name], -- ^ Type variables
tcdTyPats :: Maybe [LHsType name], -- ^ Type patterns.
-- See Note [tcdTyVars and tcdTyPats]
@@ -496,6 +497,7 @@ data TyClDecl name
}
| TySynonym { tcdLName :: Located name, -- ^ type constructor
+ tcdCType :: Maybe CType,
tcdTyVars :: [LHsTyVarBndr name], -- ^ type variables
tcdTyPats :: Maybe [LHsType name], -- ^ Type patterns
-- See Note [tcdTyVars and tcdTyPats]
diff --git a/compiler/iface/BinIface.hs b/compiler/iface/BinIface.hs
index d821c13fdc..1533bf1fec 100644
--- a/compiler/iface/BinIface.hs
+++ b/compiler/iface/BinIface.hs
@@ -1370,7 +1370,7 @@ instance Binary IfaceDecl where
put_ _ (IfaceForeign _ _) =
error "Binary.put_(IfaceDecl): IfaceForeign"
- put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7) = do
+ put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8) = do
putByte bh 2
put_ bh (occNameFS a1)
put_ bh a2
@@ -1379,13 +1379,15 @@ instance Binary IfaceDecl where
put_ bh a5
put_ bh a6
put_ bh a7
+ put_ bh a8
- put_ bh (IfaceSyn a1 a2 a3 a4) = do
+ put_ bh (IfaceSyn a1 a2 a3 a4 a5) = do
putByte bh 3
put_ bh (occNameFS a1)
put_ bh a2
put_ bh a3
put_ bh a4
+ put_ bh a5
put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7) = do
putByte bh 4
@@ -1421,14 +1423,16 @@ instance Binary IfaceDecl where
a5 <- get bh
a6 <- get bh
a7 <- get bh
+ a8 <- get bh
occ <- return $! mkOccNameFS tcName a1
- return (IfaceData occ a2 a3 a4 a5 a6 a7)
+ return (IfaceData occ a2 a3 a4 a5 a6 a7 a8)
3 -> do a1 <- get bh
a2 <- get bh
a3 <- get bh
a4 <- get bh
+ a5 <- get bh
occ <- return $! mkOccNameFS tcName a1
- return (IfaceSyn occ a2 a3 a4)
+ return (IfaceSyn occ a2 a3 a4 a5)
4 -> do a1 <- get bh
a2 <- get bh
a3 <- get bh
diff --git a/compiler/iface/BuildTyCl.lhs b/compiler/iface/BuildTyCl.lhs
index 75b8d91881..8e6f43adc7 100644
--- a/compiler/iface/BuildTyCl.lhs
+++ b/compiler/iface/BuildTyCl.lhs
@@ -29,6 +29,7 @@ import DataCon
import Var
import VarSet
import BasicTypes
+import ForeignCall
import Name
import MkId
import Class
@@ -45,17 +46,19 @@ import Outputable
\begin{code}
------------------------------------------------------
buildSynTyCon :: Name -> [TyVar]
+ -> Maybe CType
-> SynTyConRhs
-> Kind -- ^ Kind of the RHS
-> TyConParent
-> TcRnIf m n TyCon
-buildSynTyCon tc_name tvs rhs rhs_kind parent
- = return (mkSynTyCon tc_name kind tvs rhs parent)
+buildSynTyCon tc_name tvs cType rhs rhs_kind parent
+ = return (mkSynTyCon tc_name kind tvs cType rhs parent)
where kind = mkPiKinds tvs rhs_kind
------------------------------------------------------
buildAlgTyCon :: Name
-> [TyVar] -- ^ Kind variables and type variables
+ -> Maybe CType
-> ThetaType -- ^ Stupid theta
-> AlgTyConRhs
-> RecFlag
@@ -63,8 +66,8 @@ buildAlgTyCon :: Name
-> TyConParent
-> TyCon
-buildAlgTyCon tc_name ktvs stupid_theta rhs is_rec gadt_syn parent
- = mkAlgTyCon tc_name kind ktvs stupid_theta rhs parent is_rec gadt_syn
+buildAlgTyCon tc_name ktvs cType stupid_theta rhs is_rec gadt_syn parent
+ = mkAlgTyCon tc_name kind ktvs cType stupid_theta rhs parent is_rec gadt_syn
where
kind = mkPiKinds ktvs liftedTypeKind
diff --git a/compiler/iface/IfaceSyn.lhs b/compiler/iface/IfaceSyn.lhs
index fd8b361b3d..05a943fb2c 100644
--- a/compiler/iface/IfaceSyn.lhs
+++ b/compiler/iface/IfaceSyn.lhs
@@ -68,6 +68,7 @@ data IfaceDecl
ifIdInfo :: IfaceIdInfo }
| IfaceData { ifName :: OccName, -- Type constructor
+ ifCType :: Maybe CType, -- C type for CAPI FFI
ifTyVars :: [IfaceTvBndr], -- Type variables
ifCtxt :: IfaceContext, -- The "stupid theta"
ifCons :: IfaceConDecls, -- Includes new/data/data family info
@@ -79,6 +80,7 @@ data IfaceDecl
}
| IfaceSyn { ifName :: OccName, -- Type constructor
+ ifCType :: Maybe CType, -- C type for CAPI FFI
ifTyVars :: [IfaceTvBndr], -- Type variables
ifSynKind :: IfaceKind, -- Kind of the *rhs* (not of the tycon)
ifSynRhs :: Maybe IfaceType -- Just rhs for an ordinary synonyn
diff --git a/compiler/iface/MkIface.lhs b/compiler/iface/MkIface.lhs
index 9248dc3793..9290a68ad9 100644
--- a/compiler/iface/MkIface.lhs
+++ b/compiler/iface/MkIface.lhs
@@ -1432,12 +1432,14 @@ tyThingToIfaceDecl (ATyCon tycon)
| isSynTyCon tycon
= IfaceSyn { ifName = getOccName tycon,
+ ifCType = tyConCType tycon,
ifTyVars = toIfaceTvBndrs tyvars,
ifSynRhs = syn_rhs,
ifSynKind = syn_ki }
| isAlgTyCon tycon
= IfaceData { ifName = getOccName tycon,
+ ifCType = tyConCType tycon,
ifTyVars = toIfaceTvBndrs tyvars,
ifCtxt = toIfaceContext (tyConStupidTheta tycon),
ifCons = ifaceConDecls (algTyConRhs tycon),
diff --git a/compiler/iface/TcIface.lhs b/compiler/iface/TcIface.lhs
index 1263a11857..231481be70 100644
--- a/compiler/iface/TcIface.lhs
+++ b/compiler/iface/TcIface.lhs
@@ -432,6 +432,7 @@ tc_iface_decl _ ignore_prags (IfaceId {ifName = occ_name, ifType = iface_type,
; return (AnId (mkGlobalId details name ty info)) }
tc_iface_decl parent _ (IfaceData {ifName = occ_name,
+ ifCType = cType,
ifTyVars = tv_bndrs,
ifCtxt = ctxt, ifGadtSyntax = gadt_syn,
ifCons = rdr_cons,
@@ -443,7 +444,7 @@ tc_iface_decl parent _ (IfaceData {ifName = occ_name,
{ stupid_theta <- tcIfaceCtxt ctxt
; parent' <- tc_parent tyvars mb_axiom_name
; cons <- tcIfaceDataCons tc_name tycon tyvars rdr_cons
- ; return (buildAlgTyCon tc_name tyvars stupid_theta
+ ; return (buildAlgTyCon tc_name tyvars cType stupid_theta
cons is_rec gadt_syn parent') }
; traceIf (text "tcIfaceDecl4" <+> ppr tycon)
; return (ATyCon tycon) }
@@ -462,6 +463,7 @@ tc_iface_decl parent _ (IfaceData {ifName = occ_name,
; return (FamInstTyCon ax fam_tc (substTys subst fam_tys)) }
tc_iface_decl parent _ (IfaceSyn {ifName = occ_name, ifTyVars = tv_bndrs,
+ ifCType = cType,
ifSynRhs = mb_rhs_ty,
ifSynKind = kind })
= bindIfaceTyVars_AT tv_bndrs $ \ tyvars -> do
@@ -469,7 +471,7 @@ tc_iface_decl parent _ (IfaceSyn {ifName = occ_name, ifTyVars = tv_bndrs,
; rhs_kind <- tcIfaceType kind -- Note [Synonym kind loop]
; rhs <- forkM (mk_doc tc_name) $
tc_syn_rhs mb_rhs_ty
- ; tycon <- buildSynTyCon tc_name tyvars rhs rhs_kind parent
+ ; tycon <- buildSynTyCon tc_name tyvars cType rhs rhs_kind parent
; return (ATyCon tycon) }
where
mk_doc n = ptext (sLit "Type syonym") <+> ppr n
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 6e74cfbc4a..74da99a005 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -487,6 +487,7 @@ data Token
| ITvect_prag
| ITvect_scalar_prag
| ITnovect_prag
+ | ITctype
| ITdotdot -- reserved symbols
| ITcolon
@@ -2287,7 +2288,8 @@ oneWordPrags = Map.fromList([("rules", rulePrag),
("nounpack", token ITnounpack_prag),
("ann", token ITann_prag),
("vectorize", token ITvect_prag),
- ("novectorize", token ITnovect_prag)])
+ ("novectorize", token ITnovect_prag),
+ ("ctype", token ITctype)])
twoWordPrags = Map.fromList([("inline conlike", token (ITinline_prag Inline ConLike)),
("notinline conlike", token (ITinline_prag NoInline ConLike)),
diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp
index c05f2e1e6b..f29364a872 100644
--- a/compiler/parser/Parser.y.pp
+++ b/compiler/parser/Parser.y.pp
@@ -38,9 +38,7 @@ import TysWiredIn ( unitTyCon, unitDataCon, tupleTyCon, tupleCon, nilDataC
unboxedUnitTyCon, unboxedUnitDataCon,
listTyCon_RDR, parrTyCon_RDR, consDataCon_RDR, eqTyCon_RDR )
import Type ( funTyCon )
-import ForeignCall ( Safety(..), CExportSpec(..), CLabelString,
- CCallConv(..), CCallTarget(..), defaultCCallConv
- )
+import ForeignCall
import OccName ( varName, dataName, tcClsName, tvName )
import DataCon ( DataCon, dataConName )
import SrcLoc
@@ -269,6 +267,7 @@ incorrect.
'{-# VECTORISE' { L _ ITvect_prag }
'{-# VECTORISE_SCALAR' { L _ ITvect_scalar_prag }
'{-# NOVECTORISE' { L _ ITnovect_prag }
+ '{-# CTYPE' { L _ ITctype }
'#-}' { L _ ITclose_prag }
'..' { L _ ITdotdot } -- reserved symbols
@@ -610,7 +609,7 @@ cl_decl :: { LTyClDecl RdrName }
--
ty_decl :: { LTyClDecl RdrName }
-- ordinary type synonyms
- : 'type' type '=' ctypedoc
+ : 'type' capi_ctype type '=' ctypedoc
-- Note ctype, not sigtype, on the right of '='
-- We allow an explicit for-all but we don't insert one
-- in type Foo a = (b,b)
@@ -618,7 +617,7 @@ ty_decl :: { LTyClDecl RdrName }
--
-- Note the use of type for the head; this allows
-- infix type constructors to be declared
- {% mkTySynonym (comb2 $1 $4) False $2 $4 }
+ {% mkTySynonym (comb2 $1 $5) False $2 $3 $5 }
-- type family declarations
| 'type' 'family' type opt_kind_sig
@@ -627,18 +626,18 @@ ty_decl :: { LTyClDecl RdrName }
{% mkTyFamily (comb3 $1 $3 $4) TypeFamily $3 (unLoc $4) }
-- ordinary data type or newtype declaration
- | data_or_newtype tycl_hdr constrs deriving
- {% mkTyData (comb4 $1 $2 $3 $4) (unLoc $1) False $2
- Nothing (reverse (unLoc $3)) (unLoc $4) }
+ | data_or_newtype capi_ctype tycl_hdr constrs deriving
+ {% mkTyData (comb4 $1 $3 $4 $5) (unLoc $1) False $2 $3
+ Nothing (reverse (unLoc $4)) (unLoc $5) }
-- We need the location on tycl_hdr in case
-- constrs and deriving are both empty
-- ordinary GADT declaration
- | data_or_newtype tycl_hdr opt_kind_sig
+ | data_or_newtype capi_ctype tycl_hdr opt_kind_sig
gadt_constrlist
deriving
- {% mkTyData (comb4 $1 $2 $4 $5) (unLoc $1) False $2
- (unLoc $3) (unLoc $4) (unLoc $5) }
+ {% mkTyData (comb4 $1 $3 $5 $6) (unLoc $1) False $2 $3
+ (unLoc $4) (unLoc $5) (unLoc $6) }
-- We need the location on tycl_hdr in case
-- constrs and deriving are both empty
@@ -652,15 +651,15 @@ inst_decl :: { LInstDecl RdrName }
in L (comb3 $1 $2 $3) (ClsInstDecl $2 binds sigs ats) }
-- type instance declarations
- | 'type' 'instance' type '=' ctype
+ | 'type' 'instance' capi_ctype type '=' ctype
-- Note the use of type for the head; this allows
-- infix type constructors and type patterns
- {% do { L loc d <- mkTySynonym (comb2 $1 $5) True $3 $5
+ {% do { L loc d <- mkTySynonym (comb2 $1 $6) True $3 $4 $6
; return (L loc (FamInstDecl d)) } }
-- data/newtype instance declaration
| data_or_newtype 'instance' tycl_hdr constrs deriving
- {% do { L loc d <- mkTyData (comb4 $1 $3 $4 $5) (unLoc $1) True $3
+ {% do { L loc d <- mkTyData (comb4 $1 $3 $4 $5) (unLoc $1) True Nothing $3
Nothing (reverse (unLoc $4)) (unLoc $5)
; return (L loc (FamInstDecl d)) } }
@@ -668,7 +667,7 @@ inst_decl :: { LInstDecl RdrName }
| data_or_newtype 'instance' tycl_hdr opt_kind_sig
gadt_constrlist
deriving
- {% do { L loc d <- mkTyData (comb4 $1 $3 $5 $6) (unLoc $1) True $3
+ {% do { L loc d <- mkTyData (comb4 $1 $3 $5 $6) (unLoc $1) True Nothing $3
(unLoc $4) (unLoc $5) (unLoc $6)
; return (L loc (FamInstDecl d)) } }
@@ -683,16 +682,19 @@ inst_decl :: { LInstDecl RdrName }
--
at_decl_cls :: { LTyClDecl RdrName }
-- type family declarations
- : 'type' type opt_kind_sig
+ : 'type' capi_ctype type opt_kind_sig
-- Note the use of type for the head; this allows
- -- infix type constructors to be declared
- {% mkTyFamily (comb3 $1 $2 $3) TypeFamily $2 (unLoc $3) }
+ -- infix type constructors to be declared.
+ -- Note that we ignore the capi_ctype for now, but
+ -- we need it in the grammar or we get loads of
+ -- extra shift/reduce conflicts and parsing goes wrong.
+ {% mkTyFamily (comb3 $1 $3 $4) TypeFamily $3 (unLoc $4) }
-- default type instance
- | 'type' type '=' ctype
+ | 'type' capi_ctype type '=' ctype
-- Note the use of type for the head; this allows
-- infix type constructors and type patterns
- {% mkTySynonym (comb2 $1 $4) True $2 $4 }
+ {% mkTySynonym (comb2 $1 $5) True $2 $3 $5 }
-- data/newtype family declaration
| 'data' type opt_kind_sig
@@ -702,22 +704,22 @@ at_decl_cls :: { LTyClDecl RdrName }
--
at_decl_inst :: { LTyClDecl RdrName }
-- type instance declarations
- : 'type' type '=' ctype
+ : 'type' capi_ctype type '=' ctype
-- Note the use of type for the head; this allows
-- infix type constructors and type patterns
- {% mkTySynonym (comb2 $1 $4) True $2 $4 }
+ {% mkTySynonym (comb2 $1 $5) True $2 $3 $5 }
-- data/newtype instance declaration
- | data_or_newtype tycl_hdr constrs deriving
- {% mkTyData (comb4 $1 $2 $3 $4) (unLoc $1) True $2
- Nothing (reverse (unLoc $3)) (unLoc $4) }
+ | data_or_newtype capi_ctype tycl_hdr constrs deriving
+ {% mkTyData (comb4 $1 $3 $4 $5) (unLoc $1) True $2 $3
+ Nothing (reverse (unLoc $4)) (unLoc $5) }
-- GADT instance declaration
- | data_or_newtype tycl_hdr opt_kind_sig
+ | data_or_newtype capi_ctype tycl_hdr opt_kind_sig
gadt_constrlist
deriving
- {% mkTyData (comb4 $1 $2 $4 $5) (unLoc $1) True $2
- (unLoc $3) (unLoc $4) (unLoc $5) }
+ {% mkTyData (comb4 $1 $3 $5 $6) (unLoc $1) True $2 $3
+ (unLoc $4) (unLoc $5) (unLoc $6) }
data_or_newtype :: { Located NewOrData }
: 'data' { L1 DataType }
@@ -738,6 +740,10 @@ tycl_hdr :: { Located (Maybe (LHsContext RdrName), LHsType RdrName) }
: context '=>' type { LL (Just $1, $3) }
| type { L1 (Nothing, $1) }
+capi_ctype :: { Maybe CType }
+capi_ctype : '{-# CTYPE' STRING '#-}' { Just (CType (getSTRING $2)) }
+ | { Nothing }
+
-----------------------------------------------------------------------------
-- Stand-alone deriving
diff --git a/compiler/parser/RdrHsSyn.lhs b/compiler/parser/RdrHsSyn.lhs
index 14778171f5..56c643d190 100644
--- a/compiler/parser/RdrHsSyn.lhs
+++ b/compiler/parser/RdrHsSyn.lhs
@@ -192,31 +192,34 @@ mkClassDecl loc (L _ (mcxt, tycl_hdr)) fds where_cls
mkTyData :: SrcSpan
-> NewOrData
-> Bool -- True <=> data family instance
+ -> Maybe CType
-> Located (Maybe (LHsContext RdrName), LHsType RdrName)
-> Maybe (LHsKind RdrName)
-> [LConDecl RdrName]
-> Maybe [LHsType RdrName]
-> P (LTyClDecl RdrName)
-mkTyData loc new_or_data is_family (L _ (mcxt, tycl_hdr)) ksig data_cons maybe_deriv
+mkTyData loc new_or_data is_family cType (L _ (mcxt, tycl_hdr)) ksig data_cons maybe_deriv
= do { (tc, tparams) <- checkTyClHdr tycl_hdr
; checkDatatypeContext mcxt
; let cxt = fromMaybe (noLoc []) mcxt
; (tyvars, typats) <- checkTParams is_family tycl_hdr tparams
- ; return (L loc (TyData { tcdND = new_or_data, tcdCtxt = cxt, tcdLName = tc,
+ ; return (L loc (TyData { tcdND = new_or_data, tcdCType = cType,
+ tcdCtxt = cxt, tcdLName = tc,
tcdTyVars = tyvars, tcdTyPats = typats,
tcdCons = data_cons,
tcdKindSig = ksig, tcdDerivs = maybe_deriv })) }
mkTySynonym :: SrcSpan
-> Bool -- True <=> type family instances
+ -> Maybe CType
-> LHsType RdrName -- LHS
-> LHsType RdrName -- RHS
-> P (LTyClDecl RdrName)
-mkTySynonym loc is_family lhs rhs
+mkTySynonym loc is_family cType lhs rhs
= do { (tc, tparams) <- checkTyClHdr lhs
; (tyvars, typats) <- checkTParams is_family lhs tparams
- ; return (L loc (TySynonym tc tyvars typats rhs)) }
+ ; return (L loc (TySynonym tc cType tyvars typats rhs)) }
mkTyFamily :: SrcSpan
-> FamilyFlavour
diff --git a/compiler/prelude/ForeignCall.lhs b/compiler/prelude/ForeignCall.lhs
index f959fb08d4..f99f134aab 100644
--- a/compiler/prelude/ForeignCall.lhs
+++ b/compiler/prelude/ForeignCall.lhs
@@ -14,6 +14,8 @@ module ForeignCall (
CCallSpec(..),
CCallTarget(..), isDynamicTarget,
CCallConv(..), defaultCCallConv, ccallConvToInt, ccallConvAttribute,
+
+ CType(..),
) where
import FastString
@@ -227,6 +229,12 @@ instance Outputable CCallSpec where
= text "__dyn_ccall" <> gc_suf <+> text "\"\""
\end{code}
+\begin{code}
+-- | A C type, used in CAPI FFI calls
+newtype CType = CType FastString
+ deriving (Data, Typeable)
+\end{code}
+
%************************************************************************
%* *
@@ -308,4 +316,9 @@ instance Binary CCallConv where
2 -> do return PrimCallConv
3 -> do return CmmCallConv
_ -> do return CApiConv
+
+instance Binary CType where
+ put_ bh (CType fs) = put_ bh fs
+ get bh = do fs <- get bh
+ return (CType fs)
\end{code}
diff --git a/compiler/prelude/TysWiredIn.lhs b/compiler/prelude/TysWiredIn.lhs
index 162a7025c0..d7cfc58765 100644
--- a/compiler/prelude/TysWiredIn.lhs
+++ b/compiler/prelude/TysWiredIn.lhs
@@ -96,6 +96,7 @@ import RdrName
import Name
import BasicTypes ( TupleSort(..), tupleSortBoxity, IPName(..),
Arity, RecFlag(..), Boxity(..), HsBang(..) )
+import ForeignCall
import Unique ( incrUnique, mkTupleTyConUnique,
mkTupleDataConUnique, mkPArrDataConUnique )
import Data.Array
@@ -229,18 +230,19 @@ eqTyCon_RDR = nameRdrName eqTyConName
%************************************************************************
\begin{code}
-pcNonRecDataTyCon :: Name -> [TyVar] -> [DataCon] -> TyCon
+pcNonRecDataTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
pcNonRecDataTyCon = pcTyCon False NonRecursive
-pcRecDataTyCon :: Name -> [TyVar] -> [DataCon] -> TyCon
+pcRecDataTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
pcRecDataTyCon = pcTyCon False Recursive
-pcTyCon :: Bool -> RecFlag -> Name -> [TyVar] -> [DataCon] -> TyCon
-pcTyCon is_enum is_rec name tyvars cons
+pcTyCon :: Bool -> RecFlag -> Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon
+pcTyCon is_enum is_rec name cType tyvars cons
= tycon
where
tycon = mkAlgTyCon name
(mkArrowKinds (map tyVarKind tyvars) liftedTypeKind)
tyvars
+ cType
[] -- No stupid theta
(DataTyCon cons is_enum)
NoParentTyCon
@@ -406,6 +408,7 @@ mkIPName ip tycon_u datacon_u dc_wrk_u co_ax_u = name_ip
tycon = mkAlgTyCon tycon_name
(liftedTypeKind `mkArrowKind` constraintKind)
[alphaTyVar]
+ Nothing
[] -- No stupid theta
(NewTyCon { data_con = datacon,
nt_rhs = mkTyVarTy alphaTyVar,
@@ -432,6 +435,7 @@ eqTyCon :: TyCon
eqTyCon = mkAlgTyCon eqTyConName
(ForAllTy kv $ mkArrowKinds [k, k] constraintKind)
[kv, a, b]
+ Nothing
[] -- No stupid theta
(DataTyCon [eqBoxDataCon] False)
NoParentTyCon
@@ -456,7 +460,8 @@ charTy :: Type
charTy = mkTyConTy charTyCon
charTyCon :: TyCon
-charTyCon = pcNonRecDataTyCon charTyConName [] [charDataCon]
+charTyCon = pcNonRecDataTyCon charTyConName (Just (CType (fsLit "HsChar")))
+ [] [charDataCon]
charDataCon :: DataCon
charDataCon = pcDataCon charDataConName [] [charPrimTy] charTyCon
@@ -468,7 +473,7 @@ stringTy = mkListTy charTy -- convenience only
integerTyCon :: TyCon
integerTyCon = case cIntegerLibraryType of
IntegerGMP ->
- pcNonRecDataTyCon integerRealTyConName []
+ pcNonRecDataTyCon integerRealTyConName Nothing []
[integerGmpSDataCon, integerGmpJDataCon]
_ ->
panic "Evaluated integerTyCon, but not using IntegerGMP"
@@ -491,7 +496,7 @@ intTy :: Type
intTy = mkTyConTy intTyCon
intTyCon :: TyCon
-intTyCon = pcNonRecDataTyCon intTyConName [] [intDataCon]
+intTyCon = pcNonRecDataTyCon intTyConName (Just (CType (fsLit "HsInt"))) [] [intDataCon]
intDataCon :: DataCon
intDataCon = pcDataCon intDataConName [] [intPrimTy] intTyCon
\end{code}
@@ -501,7 +506,7 @@ wordTy :: Type
wordTy = mkTyConTy wordTyCon
wordTyCon :: TyCon
-wordTyCon = pcNonRecDataTyCon wordTyConName [] [wordDataCon]
+wordTyCon = pcNonRecDataTyCon wordTyConName (Just (CType (fsLit "HsWord"))) [] [wordDataCon]
wordDataCon :: DataCon
wordDataCon = pcDataCon wordDataConName [] [wordPrimTy] wordTyCon
\end{code}
@@ -511,7 +516,7 @@ floatTy :: Type
floatTy = mkTyConTy floatTyCon
floatTyCon :: TyCon
-floatTyCon = pcNonRecDataTyCon floatTyConName [] [floatDataCon]
+floatTyCon = pcNonRecDataTyCon floatTyConName (Just (CType (fsLit "HsFloat"))) [] [floatDataCon]
floatDataCon :: DataCon
floatDataCon = pcDataCon floatDataConName [] [floatPrimTy] floatTyCon
\end{code}
@@ -521,7 +526,7 @@ doubleTy :: Type
doubleTy = mkTyConTy doubleTyCon
doubleTyCon :: TyCon
-doubleTyCon = pcNonRecDataTyCon doubleTyConName [] [doubleDataCon]
+doubleTyCon = pcNonRecDataTyCon doubleTyConName (Just (CType (fsLit "HsDouble"))) [] [doubleDataCon]
doubleDataCon :: DataCon
doubleDataCon = pcDataCon doubleDataConName [] [doublePrimTy] doubleTyCon
@@ -582,7 +587,8 @@ boolTy = mkTyConTy boolTyCon
boolTyCon :: TyCon
boolTyCon = pcTyCon True NonRecursive boolTyConName
- [] [falseDataCon, trueDataCon]
+ (Just (CType (fsLit "HsBool")))
+ [] [falseDataCon, trueDataCon]
falseDataCon, trueDataCon :: DataCon
falseDataCon = pcDataCon falseDataConName [] [] boolTyCon
@@ -593,7 +599,7 @@ falseDataConId = dataConWorkId falseDataCon
trueDataConId = dataConWorkId trueDataCon
orderingTyCon :: TyCon
-orderingTyCon = pcTyCon True NonRecursive orderingTyConName
+orderingTyCon = pcTyCon True NonRecursive orderingTyConName Nothing
[] [ltDataCon, eqDataCon, gtDataCon]
ltDataCon, eqDataCon, gtDataCon :: DataCon
@@ -627,7 +633,7 @@ mkListTy :: Type -> Type
mkListTy ty = mkTyConApp listTyCon [ty]
listTyCon :: TyCon
-listTyCon = pcRecDataTyCon listTyConName alpha_tyvar [nilDataCon, consDataCon]
+listTyCon = pcRecDataTyCon listTyConName Nothing alpha_tyvar [nilDataCon, consDataCon]
mkPromotedListTy :: Type -> Type
mkPromotedListTy ty = mkTyConApp promotedListTyCon [ty]
@@ -729,7 +735,7 @@ mkPArrTy ty = mkTyConApp parrTyCon [ty]
-- @PrelPArr@.
--
parrTyCon :: TyCon
-parrTyCon = pcNonRecDataTyCon parrTyConName alpha_tyvar [parrDataCon]
+parrTyCon = pcNonRecDataTyCon parrTyConName Nothing alpha_tyvar [parrDataCon]
parrDataCon :: DataCon
parrDataCon = pcDataCon
diff --git a/compiler/rename/RnSource.lhs b/compiler/rename/RnSource.lhs
index 54f95016c7..0ebda54885 100644
--- a/compiler/rename/RnSource.lhs
+++ b/compiler/rename/RnSource.lhs
@@ -799,7 +799,8 @@ rnTyClDecl mb_cls (TyFamily { tcdLName = tycon, tcdTyVars = tyvars
-- "data", "newtype", "data instance, and "newtype instance" declarations
-- both top level and (for an associated type) in an instance decl
-rnTyClDecl mb_cls tydecl@TyData {tcdND = new_or_data, tcdCtxt = context,
+rnTyClDecl mb_cls tydecl@TyData {tcdND = new_or_data, tcdCType = cType,
+ tcdCtxt = context,
tcdLName = tycon, tcdTyVars = tyvars,
tcdTyPats = typats, tcdCons = condecls,
tcdKindSig = sig, tcdDerivs = derivs}
@@ -831,7 +832,8 @@ rnTyClDecl mb_cls tydecl@TyData {tcdND = new_or_data, tcdCtxt = context,
-- No need to check for duplicate constructor decls
-- since that is done by RnNames.extendGlobalRdrEnvRn
- ; return (TyData {tcdND = new_or_data, tcdCtxt = context',
+ ; return (TyData {tcdND = new_or_data, tcdCType = cType,
+ tcdCtxt = context',
tcdLName = tycon', tcdTyVars = tyvars',
tcdTyPats = typats', tcdKindSig = sig',
tcdCons = condecls', tcdDerivs = derivs'},
@@ -849,14 +851,16 @@ rnTyClDecl mb_cls tydecl@TyData {tcdND = new_or_data, tcdCtxt = context,
; return (Just ds', extractHsTyNames_s ds') }
-- "type" and "type instance" declarations
-rnTyClDecl mb_cls tydecl@(TySynonym { tcdTyVars = tyvars, tcdLName = name,
+rnTyClDecl mb_cls tydecl@(TySynonym { tcdTyVars = tyvars, tcdCType = cType,
+ tcdLName = name,
tcdTyPats = typats, tcdSynRhs = ty})
= bindQTvs syn_doc mb_cls tyvars $ \ tyvars' -> do
{ -- Checks for distinct tyvars
name' <- lookupTcdName mb_cls tydecl
; (typats',fvs1) <- rnTyPats syn_doc name' typats
; (ty', fvs2) <- rnHsTypeFVs syn_doc ty
- ; return (TySynonym { tcdLName = name', tcdTyVars = tyvars'
+ ; return (TySynonym { tcdLName = name', tcdCType = cType
+ , tcdTyVars = tyvars'
, tcdTyPats = typats', tcdSynRhs = ty'}
, extractHsTyVarBndrNames_s tyvars' (fvs1 `plusFV` fvs2)) }
where
diff --git a/compiler/typecheck/TcGenGenerics.lhs b/compiler/typecheck/TcGenGenerics.lhs
index 1fbb7df856..9493669e55 100644
--- a/compiler/typecheck/TcGenGenerics.lhs
+++ b/compiler/typecheck/TcGenGenerics.lhs
@@ -99,7 +99,7 @@ genGenericRepExtras tc mod =
| (u,n) <- zip us [0..] ] | (us,m) <- zip uniqsS [0..] ]
mkTyCon name = ASSERT( isExternalName name )
- buildAlgTyCon name [] [] distinctAbstractTyConRhs
+ buildAlgTyCon name [] Nothing [] distinctAbstractTyConRhs
NonRecursive False NoParentTyCon
let metaDTyCon = mkTyCon d_name
diff --git a/compiler/typecheck/TcInstDcls.lhs b/compiler/typecheck/TcInstDcls.lhs
index 89a034ba18..69d729525e 100644
--- a/compiler/typecheck/TcInstDcls.lhs
+++ b/compiler/typecheck/TcInstDcls.lhs
@@ -558,7 +558,8 @@ tcFamInstDecl1 fam_tc (decl@TySynonym {})
; return (mkSynFamInst rep_tc_name t_tvs fam_tc t_typats t_rhs) }
-- "newtype instance" and "data instance"
-tcFamInstDecl1 fam_tc (decl@TyData { tcdND = new_or_data, tcdCtxt = ctxt
+tcFamInstDecl1 fam_tc (decl@TyData { tcdND = new_or_data, tcdCType = cType
+ , tcdCtxt = ctxt
, tcdTyVars = tvs, tcdTyPats = Just pats
, tcdCons = cons})
= do { -- Check that the family declaration is for the right kind
@@ -595,7 +596,7 @@ tcFamInstDecl1 fam_tc (decl@TyData { tcdND = new_or_data, tcdCtxt = ctxt
mkNewTyConRhs rep_tc_name rec_rep_tc (head data_cons)
; let fam_inst = mkDataFamInst axiom_name tvs' fam_tc pats' rep_tc
parent = FamInstTyCon (famInstAxiom fam_inst) fam_tc pats'
- rep_tc = buildAlgTyCon rep_tc_name tvs' stupid_theta tc_rhs
+ rep_tc = buildAlgTyCon rep_tc_name tvs' cType stupid_theta tc_rhs
Recursive h98_syntax parent
-- We always assume that indexed types are recursive. Why?
-- (1) Due to their open nature, we can never be sure that a
diff --git a/compiler/typecheck/TcTyClsDecls.lhs b/compiler/typecheck/TcTyClsDecls.lhs
index 8fa79e9148..7829d1bb4c 100644
--- a/compiler/typecheck/TcTyClsDecls.lhs
+++ b/compiler/typecheck/TcTyClsDecls.lhs
@@ -560,7 +560,7 @@ tcTyClDecl1 parent _calc_isrec
= tcTyClTyVars tc_name tvs $ \ tvs' kind -> do
{ traceTc "type family:" (ppr tc_name)
; checkFamFlag tc_name
- ; tycon <- buildSynTyCon tc_name tvs' SynFamilyTyCon kind parent
+ ; tycon <- buildSynTyCon tc_name tvs' Nothing SynFamilyTyCon kind parent
; return [ATyCon tycon] }
-- "data family" declaration
@@ -571,24 +571,25 @@ tcTyClDecl1 parent _calc_isrec
; checkFamFlag tc_name
; extra_tvs <- tcDataKindSig kind
; let final_tvs = tvs' ++ extra_tvs -- we may not need these
- tycon = buildAlgTyCon tc_name final_tvs []
+ tycon = buildAlgTyCon tc_name final_tvs Nothing []
DataFamilyTyCon Recursive True parent
; return [ATyCon tycon] }
-- "type" synonym declaration
tcTyClDecl1 _parent _calc_isrec
- (TySynonym {tcdLName = L _ tc_name, tcdTyVars = tvs, tcdSynRhs = rhs_ty})
+ (TySynonym {tcdLName = L _ tc_name, tcdCType = cType, tcdTyVars = tvs, tcdSynRhs = rhs_ty})
= ASSERT( isNoParent _parent )
tcTyClTyVars tc_name tvs $ \ tvs' kind -> do
{ rhs_ty' <- tcCheckHsType rhs_ty kind
- ; tycon <- buildSynTyCon tc_name tvs' (SynonymTyCon rhs_ty')
+ ; tycon <- buildSynTyCon tc_name tvs' cType (SynonymTyCon rhs_ty')
kind NoParentTyCon
; return [ATyCon tycon] }
-- "newtype" and "data"
-- NB: not used for newtype/data instances (whether associated or not)
tcTyClDecl1 _parent calc_isrec
- (TyData { tcdND = new_or_data, tcdCtxt = ctxt, tcdTyVars = tvs
+ (TyData { tcdND = new_or_data, tcdCType = cType
+ , tcdCtxt = ctxt, tcdTyVars = tvs
, tcdLName = L _ tc_name, tcdKindSig = mb_ksig, tcdCons = cons })
= ASSERT( isNoParent _parent )
let is_rec = calc_isrec tc_name
@@ -618,7 +619,7 @@ tcTyClDecl1 _parent calc_isrec
DataType -> return (mkDataTyConRhs data_cons)
NewType -> ASSERT( not (null data_cons) )
mkNewTyConRhs tc_name tycon (head data_cons)
- ; return (buildAlgTyCon tc_name final_tvs stupid_theta tc_rhs
+ ; return (buildAlgTyCon tc_name final_tvs cType stupid_theta tc_rhs
is_rec (not h98_syntax) NoParentTyCon) }
; return [ATyCon tycon] }
diff --git a/compiler/types/TyCon.lhs b/compiler/types/TyCon.lhs
index 3347eed677..18504d16cc 100644
--- a/compiler/types/TyCon.lhs
+++ b/compiler/types/TyCon.lhs
@@ -6,88 +6,82 @@
The @TyCon@ datatype
\begin{code}
-{-# OPTIONS -fno-warn-tabs #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and
--- detab the module (please do the detabbing in a separate patch). See
--- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#TabsvsSpaces
--- for details
-
module TyCon(
-- * Main TyCon data types
- TyCon, FieldLabel,
+ TyCon, FieldLabel,
- AlgTyConRhs(..), visibleDataCons,
+ AlgTyConRhs(..), visibleDataCons,
TyConParent(..), isNoParent,
- SynTyConRhs(..),
+ SynTyConRhs(..),
- -- ** Coercion axiom constructors
- CoAxiom(..),
+ -- ** Coercion axiom constructors
+ CoAxiom(..),
coAxiomName, coAxiomArity, coAxiomTyVars,
coAxiomLHS, coAxiomRHS, isImplicitCoAxiom,
-- ** Constructing TyCons
- mkAlgTyCon,
- mkClassTyCon,
+ mkAlgTyCon,
+ mkClassTyCon,
mkIParamTyCon,
- mkFunTyCon,
- mkPrimTyCon,
- mkKindTyCon,
- mkLiftedPrimTyCon,
- mkTupleTyCon,
- mkSynTyCon,
+ mkFunTyCon,
+ mkPrimTyCon,
+ mkKindTyCon,
+ mkLiftedPrimTyCon,
+ mkTupleTyCon,
+ mkSynTyCon,
mkForeignTyCon,
- mkPromotedDataTyCon,
- mkPromotedTyCon,
+ mkPromotedDataTyCon,
+ mkPromotedTyCon,
-- ** Predicates on TyCons
isAlgTyCon,
- isClassTyCon, isFamInstTyCon,
- isFunTyCon,
+ isClassTyCon, isFamInstTyCon,
+ isFunTyCon,
isPrimTyCon,
- isTupleTyCon, isUnboxedTupleTyCon, isBoxedTupleTyCon,
+ isTupleTyCon, isUnboxedTupleTyCon, isBoxedTupleTyCon,
isSynTyCon, isClosedSynTyCon,
isDecomposableTyCon,
isForeignTyCon,
isPromotedDataTyCon, isPromotedTypeTyCon,
- isInjectiveTyCon,
- isDataTyCon, isProductTyCon, isEnumerationTyCon,
+ isInjectiveTyCon,
+ isDataTyCon, isProductTyCon, isEnumerationTyCon,
isNewTyCon, isAbstractTyCon,
isFamilyTyCon, isSynFamilyTyCon, isDataFamilyTyCon,
isUnLiftedTyCon,
- isGadtSyntaxTyCon, isDistinctTyCon, isDistinctAlgRhs,
- isTyConAssoc, tyConAssoc_maybe,
- isRecursiveTyCon,
- isImplicitTyCon,
+ isGadtSyntaxTyCon, isDistinctTyCon, isDistinctAlgRhs,
+ isTyConAssoc, tyConAssoc_maybe,
+ isRecursiveTyCon,
+ isImplicitTyCon,
-- ** Extracting information out of TyCons
- tyConName,
- tyConKind,
- tyConUnique,
- tyConTyVars,
- tyConDataCons, tyConDataCons_maybe, tyConSingleDataCon_maybe,
- tyConFamilySize,
- tyConStupidTheta,
- tyConArity,
+ tyConName,
+ tyConKind,
+ tyConUnique,
+ tyConTyVars,
+ tyConCType, tyConCType_maybe,
+ tyConDataCons, tyConDataCons_maybe, tyConSingleDataCon_maybe,
+ tyConFamilySize,
+ tyConStupidTheta,
+ tyConArity,
tyConParent,
- tyConTuple_maybe, tyConClass_maybe, tyConIP_maybe,
- tyConFamInst_maybe, tyConFamInstSig_maybe, tyConFamilyCoercion_maybe,
+ tyConTuple_maybe, tyConClass_maybe, tyConIP_maybe,
+ tyConFamInst_maybe, tyConFamInstSig_maybe, tyConFamilyCoercion_maybe,
synTyConDefn, synTyConRhs, synTyConType,
tyConExtName, -- External name for foreign types
- algTyConRhs,
- newTyConRhs, newTyConEtadRhs, unwrapNewTyCon_maybe,
+ algTyConRhs,
+ newTyConRhs, newTyConEtadRhs, unwrapNewTyCon_maybe,
tupleTyConBoxity, tupleTyConSort, tupleTyConArity,
-- ** Manipulating TyCons
- tcExpandTyCon_maybe, coreExpandTyCon_maybe,
- makeTyConAbstract,
- newTyConCo, newTyConCo_maybe,
+ tcExpandTyCon_maybe, coreExpandTyCon_maybe,
+ makeTyConAbstract,
+ newTyConCo, newTyConCo_maybe,
pprPromotionQuote,
-- * Primitive representations of Types
- PrimRep(..),
- tyConPrimRep,
+ PrimRep(..),
+ tyConPrimRep,
primRepSizeW
) where
@@ -100,6 +94,7 @@ import {-# SOURCE #-} IParam ( ipTyConName )
import Var
import Class
import BasicTypes
+import ForeignCall
import Name
import PrelNames
import Maybes
@@ -112,7 +107,7 @@ import Data.Typeable (Typeable)
\end{code}
-----------------------------------------------
- Notes about type families
+ Notes about type families
-----------------------------------------------
Note [Type synonym families]
@@ -120,9 +115,9 @@ Note [Type synonym families]
* Type synonym families, also known as "type functions", map directly
onto the type functions in FC:
- type family F a :: *
- type instance F Int = Bool
- ..etc...
+ type family F a :: *
+ type instance F Int = Bool
+ ..etc...
* Reply "yes" to isSynFamilyTyCon, and isFamilyTyCon
@@ -133,15 +128,15 @@ Note [Type synonym families]
family.
* Type functions can't appear in the LHS of a type function:
- type instance F (F Int) = ... -- BAD!
+ type instance F (F Int) = ... -- BAD!
* Translation of type family decl:
- type family F a :: *
+ type family F a :: *
translates to
a SynTyCon 'F', whose SynTyConRhs is SynFamilyTyCon
* Translation of type family decl:
- type family F a :: *
+ type family F a :: *
translates to
a SynTyCon 'F', whose SynTyConRhs is SynFamilyTyCon
@@ -155,8 +150,8 @@ Note [Data type families]
See also Note [Wrappers for data instance tycons] in MkId.lhs
* Data type families are declared thus
- data family T a :: *
- data instance T Int = T1 | T2 Bool
+ data family T a :: *
+ data instance T Int = T1 | T2 Bool
Here T is the "family TyCon".
@@ -166,40 +161,40 @@ See also Note [Wrappers for data instance tycons] in MkId.lhs
* The user does not see any "equivalent types" as he did with type
synonym families. He just sees constructors with types
- T1 :: T Int
- T2 :: Bool -> T Int
+ T1 :: T Int
+ T2 :: Bool -> T Int
* Here's the FC version of the above declarations:
- data T a
- data R:TInt = T1 | T2 Bool
- axiom ax_ti : T Int ~ R:TInt
+ data T a
+ data R:TInt = T1 | T2 Bool
+ axiom ax_ti : T Int ~ R:TInt
The R:TInt is the "representation TyCons".
It has an AlgTyConParent of
- FamInstTyCon T [Int] ax_ti
+ FamInstTyCon T [Int] ax_ti
-* The data contructor T2 has a wrapper (which is what the
+* The data contructor T2 has a wrapper (which is what the
source-level "T2" invokes):
- $WT2 :: Bool -> T Int
- $WT2 b = T2 b `cast` sym ax_ti
+ $WT2 :: Bool -> T Int
+ $WT2 b = T2 b `cast` sym ax_ti
* A data instance can declare a fully-fledged GADT:
- data instance T (a,b) where
+ data instance T (a,b) where
X1 :: T (Int,Bool)
- X2 :: a -> b -> T (a,b)
+ X2 :: a -> b -> T (a,b)
Here's the FC version of the above declaration:
- data R:TPair a where
- X1 :: R:TPair Int Bool
- X2 :: a -> b -> R:TPair a b
- axiom ax_pr :: T (a,b) ~ R:TPair a b
+ data R:TPair a where
+ X1 :: R:TPair Int Bool
+ X2 :: a -> b -> R:TPair a b
+ axiom ax_pr :: T (a,b) ~ R:TPair a b
- $WX1 :: forall a b. a -> b -> T (a,b)
- $WX1 a b (x::a) (y::b) = X2 a b x y `cast` sym (ax_pr a b)
+ $WX1 :: forall a b. a -> b -> T (a,b)
+ $WX1 a b (x::a) (y::b) = X2 a b x y `cast` sym (ax_pr a b)
The R:TPair are the "representation TyCons".
We have a bit of work to do, to unpick the result types of the
@@ -208,24 +203,24 @@ See also Note [Wrappers for data instance tycons] in MkId.lhs
The representation TyCon R:TList, has an AlgTyConParent of
- FamInstTyCon T [(a,b)] ax_pr
+ FamInstTyCon T [(a,b)] ax_pr
* Notice that T is NOT translated to a FC type function; it just
becomes a "data type" with no constructors, which can be coerced inot
into R:TInt, R:TPair by the axioms. These axioms
axioms come into play when (and *only* when) you
- - use a data constructor
- - do pattern matching
+ - use a data constructor
+ - do pattern matching
Rather like newtype, in fact
As a result
- T behaves just like a data type so far as decomposition is concerned
- - (T Int) is not implicitly converted to R:TInt during type inference.
+ - (T Int) is not implicitly converted to R:TInt during type inference.
Indeed the latter type is unknown to the programmer.
- - There *is* an instance for (T Int) in the type-family instance
+ - There *is* an instance for (T Int) in the type-family instance
environment, but it is only used for overlap checking
- It's fine to have T in the LHS of a type function:
@@ -235,14 +230,14 @@ See also Note [Wrappers for data instance tycons] in MkId.lhs
should not think of a data family T as a *type function* at all, not
even an injective one! We can't allow even injective type functions
on the LHS of a type function:
- type family injective G a :: *
- type instance F (G Int) = Bool
+ type family injective G a :: *
+ type instance F (G Int) = Bool
is no good, even if G is injective, because consider
- type instance G Int = Bool
- type instance F Bool = Char
+ type instance G Int = Bool
+ type instance F Bool = Char
So a data type family is not an injective type function. It's just a
- data type with some axioms that connect it to other data types.
+ data type with some axioms that connect it to other data types.
Note [Associated families and their parent class]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -250,18 +245,18 @@ Note [Associated families and their parent class]
that they have a TyConParent of AssocFamilyTyCon, which identifies the
parent class.
-However there is an important sharing relationship between
+However there is an important sharing relationship between
* the tyConTyVars of the parent Class
* the tyConTyvars of the associated TyCon
class C a b where
data T p a
- type F a q b
+ type F a q b
Here the 'a' and 'b' are shared with the 'Class'; that is, they have
the same Unique.
-
-This is important. In an instance declaration we expect
+
+This is important. In an instance declaration we expect
* all the shared variables to be instantiated the same way
* the non-shared variables of the associated type should not
be instantiated at all
@@ -271,9 +266,9 @@ This is important. In an instance declaration we expect
type F [x] q (Tree y) = (x,y,q)
%************************************************************************
-%* *
+%* *
\subsection{The data type}
-%* *
+%* *
%************************************************************************
\begin{code}
@@ -292,78 +287,84 @@ This is important. In an instance declaration we expect
data TyCon
= -- | The function type constructor, @(->)@
FunTyCon {
- tyConUnique :: Unique,
- tyConName :: Name,
- tc_kind :: Kind,
- tyConArity :: Arity
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tc_kind :: Kind,
+ tyConArity :: Arity
}
-- | Algebraic type constructors, which are defined to be those
-- arising @data@ type and @newtype@ declarations. All these
-- constructors are lifted and boxed. See 'AlgTyConRhs' for more
-- information.
- | AlgTyCon {
- tyConUnique :: Unique,
- tyConName :: Name,
- tc_kind :: Kind,
- tyConArity :: Arity,
+ | AlgTyCon {
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tc_kind :: Kind,
+ tyConArity :: Arity,
- tyConTyVars :: [TyVar], -- ^ The kind and type variables used in the type constructor.
+ tyConTyVars :: [TyVar], -- ^ The kind and type variables used in the type constructor.
-- Invariant: length tyvars = arity
- -- Precisely, this list scopes over:
- --
- -- 1. The 'algTcStupidTheta'
- -- 2. The cached types in 'algTyConRhs.NewTyCon'
- -- 3. The family instance types if present
- --
- -- Note that it does /not/ scope over the data constructors.
-
- algTcGadtSyntax :: Bool, -- ^ Was the data type declared with GADT syntax?
- -- If so, that doesn't mean it's a true GADT;
- -- only that the "where" form was used.
+ -- Precisely, this list scopes over:
+ --
+ -- 1. The 'algTcStupidTheta'
+ -- 2. The cached types in 'algTyConRhs.NewTyCon'
+ -- 3. The family instance types if present
+ --
+ -- Note that it does /not/ scope over the data constructors.
+ tyConCType :: Maybe CType, -- The C type that should be used
+ -- for this type when using the FFI
+ -- and CAPI
+
+ algTcGadtSyntax :: Bool, -- ^ Was the data type declared with GADT syntax?
+ -- If so, that doesn't mean it's a true GADT;
+ -- only that the "where" form was used.
-- This field is used only to guide pretty-printing
- algTcStupidTheta :: [PredType], -- ^ The \"stupid theta\" for the data type
+ algTcStupidTheta :: [PredType], -- ^ The \"stupid theta\" for the data type
-- (always empty for GADTs).
- -- A \"stupid theta\" is the context to the left
- -- of an algebraic type declaration,
- -- e.g. @Eq a@ in the declaration
+ -- A \"stupid theta\" is the context to the left
+ -- of an algebraic type declaration,
+ -- e.g. @Eq a@ in the declaration
-- @data Eq a => T a ...@.
- algTcRhs :: AlgTyConRhs, -- ^ Contains information about the
+ algTcRhs :: AlgTyConRhs, -- ^ Contains information about the
-- data constructors of the algebraic type
- algTcRec :: RecFlag, -- ^ Tells us whether the data type is part
+ algTcRec :: RecFlag, -- ^ Tells us whether the data type is part
-- of a mutually-recursive group or not
-
- algTcParent :: TyConParent -- ^ Gives the class or family declaration 'TyCon'
- -- for derived 'TyCon's representing class
- -- or family instances, respectively.
+
+ algTcParent :: TyConParent -- ^ Gives the class or family declaration 'TyCon'
+ -- for derived 'TyCon's representing class
+ -- or family instances, respectively.
-- See also 'synTcParent'
}
- -- | Represents the infinite family of tuple type constructors,
+ -- | Represents the infinite family of tuple type constructors,
-- @()@, @(a,b)@, @(# a, b #)@ etc.
| TupleTyCon {
- tyConUnique :: Unique,
- tyConName :: Name,
- tc_kind :: Kind,
- tyConArity :: Arity,
- tyConTupleSort :: TupleSort,
- tyConTyVars :: [TyVar],
- dataCon :: DataCon -- ^ Corresponding tuple data constructor
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tc_kind :: Kind,
+ tyConArity :: Arity,
+ tyConTupleSort :: TupleSort,
+ tyConTyVars :: [TyVar],
+ dataCon :: DataCon -- ^ Corresponding tuple data constructor
}
-- | Represents type synonyms
| SynTyCon {
- tyConUnique :: Unique,
- tyConName :: Name,
- tc_kind :: Kind,
- tyConArity :: Arity,
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tc_kind :: Kind,
+ tyConArity :: Arity,
- tyConTyVars :: [TyVar], -- Bound tyvars
+ tyConTyVars :: [TyVar], -- Bound tyvars
+ tyConCType :: Maybe CType, -- The C type that should be used
+ -- for this type when using the FFI
+ -- and CAPI
- synTcRhs :: SynTyConRhs, -- ^ Contains information about the
+ synTcRhs :: SynTyConRhs, -- ^ Contains information about the
-- expansion of the synonym
synTcParent :: TyConParent -- ^ Gives the family declaration 'TyCon'
@@ -374,40 +375,40 @@ data TyCon
-- | Primitive types; cannot be defined in Haskell. This includes
-- the usual suspects (such as @Int#@) as well as foreign-imported
-- types and kinds
- | PrimTyCon {
- tyConUnique :: Unique,
- tyConName :: Name,
- tc_kind :: Kind,
- tyConArity :: Arity, -- SLPJ Oct06: I'm not sure what the significance
- -- of the arity of a primtycon is!
-
- primTyConRep :: PrimRep, -- ^ Many primitive tycons are unboxed, but some are
- -- boxed (represented by pointers). This 'PrimRep'
- -- holds that information.
- -- Only relevant if tc_kind = *
-
- isUnLifted :: Bool, -- ^ Most primitive tycons are unlifted
+ | PrimTyCon {
+ tyConUnique :: Unique,
+ tyConName :: Name,
+ tc_kind :: Kind,
+ tyConArity :: Arity, -- SLPJ Oct06: I'm not sure what the significance
+ -- of the arity of a primtycon is!
+
+ primTyConRep :: PrimRep, -- ^ Many primitive tycons are unboxed, but some are
+ -- boxed (represented by pointers). This 'PrimRep'
+ -- holds that information.
+ -- Only relevant if tc_kind = *
+
+ isUnLifted :: Bool, -- ^ Most primitive tycons are unlifted
-- (may not contain bottom)
- -- but foreign-imported ones may be lifted
+ -- but foreign-imported ones may be lifted
- tyConExtName :: Maybe FastString -- ^ @Just e@ for foreign-imported types,
+ tyConExtName :: Maybe FastString -- ^ @Just e@ for foreign-imported types,
-- holds the name of the imported thing
}
-- | Represents promoted data constructor.
- | PromotedDataTyCon { -- See Note [Promoted data constructors]
- tyConUnique :: Unique, -- ^ Same Unique as the data constructor
- tyConName :: Name, -- ^ Same Name as the data constructor
- tyConArity :: Arity,
- tc_kind :: Kind, -- ^ Translated type of the data constructor
+ | PromotedDataTyCon { -- See Note [Promoted data constructors]
+ tyConUnique :: Unique, -- ^ Same Unique as the data constructor
+ tyConName :: Name, -- ^ Same Name as the data constructor
+ tyConArity :: Arity,
+ tc_kind :: Kind, -- ^ Translated type of the data constructor
dataCon :: DataCon -- ^ Corresponding data constructor
}
-- | Represents promoted type constructor.
| PromotedTypeTyCon {
- tyConUnique :: Unique, -- ^ Same Unique as the type constructor
- tyConName :: Name, -- ^ Same Name as the type constructor
- tyConArity :: Arity, -- ^ n if ty_con :: * -> ... -> * n times
+ tyConUnique :: Unique, -- ^ Same Unique as the type constructor
+ tyConName :: Name, -- ^ Same Name as the type constructor
+ tyConArity :: Arity, -- ^ n if ty_con :: * -> ... -> * n times
tc_kind :: Kind, -- ^ Always TysPrim.superKind
ty_con :: TyCon -- ^ Corresponding type constructor
}
@@ -424,14 +425,14 @@ data AlgTyConRhs
-- it's represented by a pointer. Used when we export a data type
-- abstractly into an .hi file.
= AbstractTyCon
- Bool -- True <=> It's definitely a distinct data type,
- -- equal only to itself; ie not a newtype
- -- False <=> Not sure
- -- See Note [AbstractTyCon and type equality]
+ Bool -- True <=> It's definitely a distinct data type,
+ -- equal only to itself; ie not a newtype
+ -- False <=> Not sure
+ -- See Note [AbstractTyCon and type equality]
-- | Represents an open type family without a fixed right hand
-- side. Additional instances can appear at any time.
- --
+ --
-- These are introduced by either a top level declaration:
--
-- > data T a :: *
@@ -446,42 +447,42 @@ data AlgTyConRhs
-- declaration. This includes data types with no constructors at
-- all.
| DataTyCon {
- data_cons :: [DataCon],
- -- ^ The data type constructors; can be empty if the user
- -- declares the type to have no constructors
- --
- -- INVARIANT: Kept in order of increasing 'DataCon' tag
- -- (see the tag assignment in DataCon.mkDataCon)
-
- is_enum :: Bool -- ^ Cached value: is this an enumeration type?
+ data_cons :: [DataCon],
+ -- ^ The data type constructors; can be empty if the user
+ -- declares the type to have no constructors
+ --
+ -- INVARIANT: Kept in order of increasing 'DataCon' tag
+ -- (see the tag assignment in DataCon.mkDataCon)
+
+ is_enum :: Bool -- ^ Cached value: is this an enumeration type?
-- See Note [Enumeration types]
}
-- | Information about those 'TyCon's derived from a @newtype@ declaration
| NewTyCon {
- data_con :: DataCon, -- ^ The unique constructor for the @newtype@.
+ data_con :: DataCon, -- ^ The unique constructor for the @newtype@.
-- It has no existentials
- nt_rhs :: Type, -- ^ Cached value: the argument type of the constructor,
- -- which is just the representation type of the 'TyCon'
- -- (remember that @newtype@s do not exist at runtime
+ nt_rhs :: Type, -- ^ Cached value: the argument type of the constructor,
+ -- which is just the representation type of the 'TyCon'
+ -- (remember that @newtype@s do not exist at runtime
-- so need a different representation type).
- --
- -- The free 'TyVar's of this type are the 'tyConTyVars'
+ --
+ -- The free 'TyVar's of this type are the 'tyConTyVars'
-- from the corresponding 'TyCon'
- nt_etad_rhs :: ([TyVar], Type),
- -- ^ Same as the 'nt_rhs', but this time eta-reduced.
- -- Hence the list of 'TyVar's in this field may be
- -- shorter than the declared arity of the 'TyCon'.
-
- -- See Note [Newtype eta]
- nt_co :: CoAxiom -- The axiom coercion that creates the @newtype@ from
+ nt_etad_rhs :: ([TyVar], Type),
+ -- ^ Same as the 'nt_rhs', but this time eta-reduced.
+ -- Hence the list of 'TyVar's in this field may be
+ -- shorter than the declared arity of the 'TyCon'.
+
+ -- See Note [Newtype eta]
+ nt_co :: CoAxiom -- The axiom coercion that creates the @newtype@ from
-- the representation 'Type'.
-
+
-- See Note [Newtype coercions]
-- Invariant: arity = #tvs in nt_etad_rhs;
- -- See Note [Newtype eta]
+ -- See Note [Newtype eta]
-- Watch out! If any newtypes become transparent
-- again check Trac #1072.
}
@@ -497,62 +498,62 @@ TODO
-- that visibility in this sense does not correspond to visibility in
-- the context of any particular user program!
visibleDataCons :: AlgTyConRhs -> [DataCon]
-visibleDataCons (AbstractTyCon {}) = []
-visibleDataCons DataFamilyTyCon {} = []
+visibleDataCons (AbstractTyCon {}) = []
+visibleDataCons DataFamilyTyCon {} = []
visibleDataCons (DataTyCon{ data_cons = cs }) = cs
visibleDataCons (NewTyCon{ data_con = c }) = [c]
-- ^ Both type classes as well as family instances imply implicit
-- type constructors. These implicit type constructors refer to their parent
-- structure (ie, the class or family from which they derive) using a type of
--- the following form. We use 'TyConParent' for both algebraic and synonym
+-- the following form. We use 'TyConParent' for both algebraic and synonym
-- types, but the variant 'ClassTyCon' will only be used by algebraic 'TyCon's.
-data TyConParent
+data TyConParent
= -- | An ordinary type constructor has no parent.
NoParentTyCon
-- | Type constructors representing a class dictionary.
-- See Note [ATyCon for classes] in TypeRep
| ClassTyCon
- Class -- INVARIANT: the classTyCon of this Class is the current tycon
+ Class -- INVARIANT: the classTyCon of this Class is the current tycon
-- | Associated type of a implicit parameter.
| IPTyCon
(IPName Name)
- -- | An *associated* type of a class.
- | AssocFamilyTyCon
- Class -- The class in whose declaration the family is declared
- -- See Note [Associated families and their parent class]
+ -- | An *associated* type of a class.
+ | AssocFamilyTyCon
+ Class -- The class in whose declaration the family is declared
+ -- See Note [Associated families and their parent class]
-- | Type constructors representing an instance of a *data* family. Parameters:
--
-- 1) The type family in question
--
-- 2) Instance types; free variables are the 'tyConTyVars'
- -- of the current 'TyCon' (not the family one). INVARIANT:
+ -- of the current 'TyCon' (not the family one). INVARIANT:
-- the number of types matches the arity of the family 'TyCon'
--
-- 3) A 'CoTyCon' identifying the representation
-- type with the type instance family
- | FamInstTyCon -- See Note [Data type families]
+ | FamInstTyCon -- See Note [Data type families]
CoAxiom -- The coercion constructor,
-- always of kind T ty1 ty2 ~ R:T a b c
- -- where T is the family TyCon,
+ -- where T is the family TyCon,
-- and R:T is the representation TyCon (ie this one)
-- and a,b,c are the tyConTyVars of this TyCon
-- Cached fields of the CoAxiom, but adjusted to
-- use the tyConTyVars of this TyCon
- TyCon -- The family TyCon
- [Type] -- Argument types (mentions the tyConTyVars of this TyCon)
- -- Match in length the tyConTyVars of the family TyCon
+ TyCon -- The family TyCon
+ [Type] -- Argument types (mentions the tyConTyVars of this TyCon)
+ -- Match in length the tyConTyVars of the family TyCon
- -- E.g. data intance T [a] = ...
- -- gives a representation tycon:
- -- data R:TList a = ...
- -- axiom co a :: T [a] ~ R:TList a
- -- with R:TList's algTcParent = FamInstTyCon T [a] co
+ -- E.g. data intance T [a] = ...
+ -- gives a representation tycon:
+ -- data R:TList a = ...
+ -- axiom co a :: T [a] ~ R:TList a
+ -- with R:TList's algTcParent = FamInstTyCon T [a] co
instance Outputable TyConParent where
ppr NoParentTyCon = text "No parent"
@@ -578,9 +579,9 @@ isNoParent _ = False
-- | Information pertaining to the expansion of a type synonym (@type@)
data SynTyConRhs
= -- | An ordinary type synonyn.
- SynonymTyCon
- Type -- This 'Type' is the rhs, and may mention from 'tyConTyVars'.
- -- It acts as a template for the expansion when the 'TyCon'
+ SynonymTyCon
+ Type -- This 'Type' is the rhs, and may mention from 'tyConTyVars'.
+ -- It acts as a template for the expansion when the 'TyCon'
-- is applied to some types.
-- | A type synonym family e.g. @type family F x y :: * -> *@
@@ -602,17 +603,17 @@ via the PromotedDataTyCon alternative in TyCon.
* The *kind* of a promoted DataCon may be polymorphic. Example:
type of DataCon Just :: forall (a:*). a -> Maybe a
kind of (promoted) tycon Just :: forall (a:box). a -> Maybe a
- The kind is not identical to the type, because of the */box
+ The kind is not identical to the type, because of the */box
kind signature on the forall'd variable; so the tc_kind field of
- PromotedDataTyCon is not identical to the dataConUserType of the
+ PromotedDataTyCon is not identical to the dataConUserType of the
DataCon. But it's the same modulo changing the variable kinds,
- done by Kind.promoteType.
+ done by Kind.promoteType.
* Small note: We promote the *user* type of the DataCon. Eg
data T = MkT {-# UNPACK #-} !(Bool, Bool)
The promoted kind is
MkT :: (Bool,Bool) -> T
- *not*
+ *not*
MkT :: Bool -> Bool -> T
Note [Enumeration types]
@@ -643,7 +644,7 @@ example,
newtype T a = MkT (a -> a)
-the NewTyCon for T will contain nt_co = CoT where CoT t : T t ~ t -> t.
+the NewTyCon for T will contain nt_co = CoT where CoT t : T t ~ t -> t.
In the case that the right hand side is a type application
ending with the same type variables as the left hand side, we
@@ -655,54 +656,54 @@ then we would generate the arity 0 axiom CoS : S ~ []. The
primary reason we do this is to make newtype deriving cleaner.
In the paper we'd write
- axiom CoT : (forall t. T t) ~ (forall t. [t])
+ axiom CoT : (forall t. T t) ~ (forall t. [t])
and then when we used CoT at a particular type, s, we'd say
- CoT @ s
+ CoT @ s
which encodes as (TyConApp instCoercionTyCon [TyConApp CoT [], s])
Note [Newtype eta]
~~~~~~~~~~~~~~~~~~
Consider
- newtype Parser m a = MkParser (Foogle m a)
+ newtype Parser m a = MkParser (Foogle m a)
Are these two types equal (to Core)?
- Monad (Parser m)
- Monad (Foogle m)
+ Monad (Parser m)
+ Monad (Foogle m)
Well, yes. But to see that easily we eta-reduce the RHS type of
Parser, in this case to ([], Froogle), so that even unsaturated applications
-of Parser will work right. This eta reduction is done when the type
+of Parser will work right. This eta reduction is done when the type
constructor is built, and cached in NewTyCon. The cached field is
only used in coreExpandTyCon_maybe.
-
+
Here's an example that I think showed up in practice
Source code:
- newtype T a = MkT [a]
- newtype Foo m = MkFoo (forall a. m a -> Int)
+ newtype T a = MkT [a]
+ newtype Foo m = MkFoo (forall a. m a -> Int)
- w1 :: Foo []
- w1 = ...
-
- w2 :: Foo T
- w2 = MkFoo (\(MkT x) -> case w1 of MkFoo f -> f x)
+ w1 :: Foo []
+ w1 = ...
+
+ w2 :: Foo T
+ w2 = MkFoo (\(MkT x) -> case w1 of MkFoo f -> f x)
After desugaring, and discarding the data constructors for the newtypes,
we get:
- w2 :: Foo T
- w2 = w1
+ w2 :: Foo T
+ w2 = w1
And now Lint complains unless Foo T == Foo [], and that requires T==[]
This point carries over to the newtype coercion, because we need to
-say
- w2 = w1 `cast` Foo CoT
+say
+ w2 = w1 `cast` Foo CoT
-so the coercion tycon CoT must have
- kind: T ~ []
- and arity: 0
+so the coercion tycon CoT must have
+ kind: T ~ []
+ and arity: 0
%************************************************************************
-%* *
+%* *
Coercion axioms
-%* *
+%* *
%************************************************************************
\begin{code}
@@ -711,7 +712,7 @@ data CoAxiom
= CoAxiom -- Type equality axiom.
{ co_ax_unique :: Unique -- unique identifier
, co_ax_name :: Name -- name for pretty-printing
- , co_ax_tvs :: [TyVar] -- bound type variables
+ , co_ax_tvs :: [TyVar] -- bound type variables
, co_ax_lhs :: Type -- left-hand side of the equality
, co_ax_rhs :: Type -- right-hand side of the equality
, co_ax_implicit :: Bool -- True <=> the axiom is "implicit"
@@ -749,9 +750,9 @@ See also Note [Implicit TyThings] in HscTypes
%************************************************************************
-%* *
+%* *
\subsection{PrimRep}
-%* *
+%* *
%************************************************************************
A PrimRep is somewhat similar to a CgRep (see codeGen/SMRep) and a
@@ -775,11 +776,11 @@ and clearly defined purpose:
data PrimRep
= VoidRep
| PtrRep
- | IntRep -- ^ Signed, word-sized value
- | WordRep -- ^ Unsigned, word-sized value
- | Int64Rep -- ^ Signed, 64 bit value (with 32-bit words only)
- | Word64Rep -- ^ Unsigned, 64 bit value (with 32-bit words only)
- | AddrRep -- ^ A pointer, but /not/ to a Haskell value (use 'PtrRep')
+ | IntRep -- ^ Signed, word-sized value
+ | WordRep -- ^ Unsigned, word-sized value
+ | Int64Rep -- ^ Signed, 64 bit value (with 32-bit words only)
+ | Word64Rep -- ^ Unsigned, 64 bit value (with 32-bit words only)
+ | AddrRep -- ^ A pointer, but /not/ to a Haskell value (use 'PtrRep')
| FloatRep
| DoubleRep
deriving( Eq, Show )
@@ -801,9 +802,9 @@ primRepSizeW VoidRep = 0
\end{code}
%************************************************************************
-%* *
+%* *
\subsection{TyCon Construction}
-%* *
+%* *
%************************************************************************
Note: the TyCon constructors all take a Kind as one argument, even though
@@ -814,15 +815,15 @@ So we compromise, and move their Kind calculation to the call site.
\begin{code}
-- | Given the name of the function type constructor and it's kind, create the
--- corresponding 'TyCon'. It is reccomended to use 'TypeRep.funTyCon' if you want
+-- corresponding 'TyCon'. It is reccomended to use 'TypeRep.funTyCon' if you want
-- this functionality
mkFunTyCon :: Name -> Kind -> TyCon
-mkFunTyCon name kind
- = FunTyCon {
- tyConUnique = nameUnique name,
- tyConName = name,
- tc_kind = kind,
- tyConArity = 2
+mkFunTyCon name kind
+ = FunTyCon {
+ tyConUnique = nameUnique name,
+ tyConName = name,
+ tc_kind = kind,
+ tyConArity = 2
}
-- | This is the making of an algebraic 'TyCon'. Notably, you have to
@@ -831,86 +832,89 @@ mkFunTyCon name kind
-- module)
mkAlgTyCon :: Name
-> Kind -- ^ Kind of the resulting 'TyCon'
- -> [TyVar] -- ^ 'TyVar's scoped over: see 'tyConTyVars'.
+ -> [TyVar] -- ^ 'TyVar's scoped over: see 'tyConTyVars'.
-- Arity is inferred from the length of this list
+ -> Maybe CType -- ^ The C type this type corresponds to
+ -- when using the CAPI FFI
-> [PredType] -- ^ Stupid theta: see 'algTcStupidTheta'
-> AlgTyConRhs -- ^ Information about dat aconstructors
-> TyConParent
-> RecFlag -- ^ Is the 'TyCon' recursive?
-> Bool -- ^ Was the 'TyCon' declared with GADT syntax?
-> TyCon
-mkAlgTyCon name kind tyvars stupid rhs parent is_rec gadt_syn
- = AlgTyCon {
- tyConName = name,
- tyConUnique = nameUnique name,
- tc_kind = kind,
- tyConArity = length tyvars,
- tyConTyVars = tyvars,
- algTcStupidTheta = stupid,
- algTcRhs = rhs,
- algTcParent = ASSERT2( okParent name parent, ppr name $$ ppr parent ) parent,
- algTcRec = is_rec,
- algTcGadtSyntax = gadt_syn
+mkAlgTyCon name kind tyvars cType stupid rhs parent is_rec gadt_syn
+ = AlgTyCon {
+ tyConName = name,
+ tyConUnique = nameUnique name,
+ tc_kind = kind,
+ tyConArity = length tyvars,
+ tyConTyVars = tyvars,
+ tyConCType = cType,
+ algTcStupidTheta = stupid,
+ algTcRhs = rhs,
+ algTcParent = ASSERT2( okParent name parent, ppr name $$ ppr parent ) parent,
+ algTcRec = is_rec,
+ algTcGadtSyntax = gadt_syn
}
-- | Simpler specialization of 'mkAlgTyCon' for classes
mkClassTyCon :: Name -> Kind -> [TyVar] -> AlgTyConRhs -> Class -> RecFlag -> TyCon
mkClassTyCon name kind tyvars rhs clas is_rec =
- mkAlgTyCon name kind tyvars [] rhs (ClassTyCon clas) is_rec False
+ mkAlgTyCon name kind tyvars Nothing [] rhs (ClassTyCon clas) is_rec False
-- | Simpler specialization of 'mkAlgTyCon' for implicit paramaters
mkIParamTyCon :: Name -> Kind -> TyVar -> AlgTyConRhs -> RecFlag -> TyCon
mkIParamTyCon name kind tyvar rhs is_rec =
- mkAlgTyCon name kind [tyvar] [] rhs NoParentTyCon is_rec False
+ mkAlgTyCon name kind [tyvar] Nothing [] rhs NoParentTyCon is_rec False
-mkTupleTyCon :: Name
+mkTupleTyCon :: Name
-> Kind -- ^ Kind of the resulting 'TyCon'
-> Arity -- ^ Arity of the tuple
-> [TyVar] -- ^ 'TyVar's scoped over: see 'tyConTyVars'
- -> DataCon
+ -> DataCon
-> TupleSort -- ^ Whether the tuple is boxed or unboxed
-> TyCon
mkTupleTyCon name kind arity tyvars con sort
= TupleTyCon {
- tyConUnique = nameUnique name,
- tyConName = name,
- tc_kind = kind,
- tyConArity = arity,
- tyConTupleSort = sort,
- tyConTyVars = tyvars,
- dataCon = con
+ tyConUnique = nameUnique name,
+ tyConName = name,
+ tc_kind = kind,
+ tyConArity = arity,
+ tyConTupleSort = sort,
+ tyConTyVars = tyvars,
+ dataCon = con
}
-- ^ Foreign-imported (.NET) type constructors are represented
-- as primitive, but /lifted/, 'TyCons' for now. They are lifted
-- because the Haskell type @T@ representing the (foreign) .NET
-- type @T@ is actually implemented (in ILX) as a @thunk<T>@
-mkForeignTyCon :: Name
+mkForeignTyCon :: Name
-> Maybe FastString -- ^ Name of the foreign imported thing, maybe
- -> Kind
- -> Arity
+ -> Kind
+ -> Arity
-> TyCon
mkForeignTyCon name ext_name kind arity
= PrimTyCon {
- tyConName = name,
- tyConUnique = nameUnique name,
- tc_kind = kind,
- tyConArity = arity,
- primTyConRep = PtrRep, -- they all do
- isUnLifted = False,
- tyConExtName = ext_name
+ tyConName = name,
+ tyConUnique = nameUnique name,
+ tc_kind = kind,
+ tyConArity = arity,
+ primTyConRep = PtrRep, -- they all do
+ isUnLifted = False,
+ tyConExtName = ext_name
}
-- | Create an unlifted primitive 'TyCon', such as @Int#@
mkPrimTyCon :: Name -> Kind -> Arity -> PrimRep -> TyCon
mkPrimTyCon name kind arity rep
- = mkPrimTyCon' name kind arity rep True
+ = mkPrimTyCon' name kind arity rep True
-- | Kind constructors
mkKindTyCon :: Name -> Kind -> TyCon
mkKindTyCon name kind
- = mkPrimTyCon' name kind 0 VoidRep True
+ = mkPrimTyCon' name kind 0 VoidRep True
-- | Create a lifted primitive 'TyCon' such as @RealWorld@
mkLiftedPrimTyCon :: Name -> Kind -> Arity -> PrimRep -> TyCon
@@ -920,30 +924,31 @@ mkLiftedPrimTyCon name kind arity rep
mkPrimTyCon' :: Name -> Kind -> Arity -> PrimRep -> Bool -> TyCon
mkPrimTyCon' name kind arity rep is_unlifted
= PrimTyCon {
- tyConName = name,
- tyConUnique = nameUnique name,
- tc_kind = kind,
- tyConArity = arity,
- primTyConRep = rep,
- isUnLifted = is_unlifted,
- tyConExtName = Nothing
+ tyConName = name,
+ tyConUnique = nameUnique name,
+ tc_kind = kind,
+ tyConArity = arity,
+ primTyConRep = rep,
+ isUnLifted = is_unlifted,
+ tyConExtName = Nothing
}
-- | Create a type synonym 'TyCon'
-mkSynTyCon :: Name -> Kind -> [TyVar] -> SynTyConRhs -> TyConParent -> TyCon
-mkSynTyCon name kind tyvars rhs parent
- = SynTyCon {
- tyConName = name,
- tyConUnique = nameUnique name,
- tc_kind = kind,
- tyConArity = length tyvars,
- tyConTyVars = tyvars,
- synTcRhs = rhs,
+mkSynTyCon :: Name -> Kind -> [TyVar] -> Maybe CType -> SynTyConRhs -> TyConParent -> TyCon
+mkSynTyCon name kind tyvars cType rhs parent
+ = SynTyCon {
+ tyConName = name,
+ tyConUnique = nameUnique name,
+ tc_kind = kind,
+ tyConArity = length tyvars,
+ tyConTyVars = tyvars,
+ tyConCType = cType,
+ synTcRhs = rhs,
synTcParent = parent
}
-- | Create a promoted data constructor 'TyCon'
--- Somewhat dodgily, we give it the same Name
+-- Somewhat dodgily, we give it the same Name
-- as the data constructor itself
mkPromotedDataTyCon :: DataCon -> Name -> Unique -> Kind -> Arity -> TyCon
mkPromotedDataTyCon con name unique kind arity
@@ -956,7 +961,7 @@ mkPromotedDataTyCon con name unique kind arity
}
-- | Create a promoted type constructor 'TyCon'
--- Somewhat dodgily, we give it the same Name
+-- Somewhat dodgily, we give it the same Name
-- as the type constructor itself
mkPromotedTyCon :: TyCon -> Kind -> TyCon
mkPromotedTyCon tc kind
@@ -981,7 +986,7 @@ isAbstractTyCon _ = False
-- | Make an algebraic 'TyCon' abstract. Panics if the supplied 'TyCon' is not algebraic
makeTyConAbstract :: TyCon -> TyCon
-makeTyConAbstract tc@(AlgTyCon { algTcRhs = rhs })
+makeTyConAbstract tc@(AlgTyCon { algTcRhs = rhs })
= tc { algTcRhs = AbstractTyCon (isDistinctAlgRhs rhs) }
makeTyConAbstract tc = pprPanic "makeTyConAbstract" (ppr tc)
@@ -995,7 +1000,7 @@ isPrimTyCon _ = False
isUnLiftedTyCon :: TyCon -> Bool
isUnLiftedTyCon (PrimTyCon {isUnLifted = is_unlifted}) = is_unlifted
isUnLiftedTyCon (TupleTyCon {tyConTupleSort = sort}) = not (isBoxed (tupleSortBoxity sort))
-isUnLiftedTyCon _ = False
+isUnLiftedTyCon _ = False
-- | Returns @True@ if the supplied 'TyCon' resulted from either a
-- @data@ or @newtype@ declaration
@@ -1005,30 +1010,30 @@ isAlgTyCon (TupleTyCon {}) = True
isAlgTyCon _ = False
isDataTyCon :: TyCon -> Bool
--- ^ Returns @True@ for data types that are /definitely/ represented by
--- heap-allocated constructors. These are scrutinised by Core-level
+-- ^ Returns @True@ for data types that are /definitely/ represented by
+-- heap-allocated constructors. These are scrutinised by Core-level
-- @case@ expressions, and they get info tables allocated for them.
---
+--
-- Generally, the function will be true for all @data@ types and false
-- for @newtype@s, unboxed tuples and type family 'TyCon's. But it is
-- not guaranteed to return @True@ in all cases that it could.
---
+--
-- NB: for a data type family, only the /instance/ 'TyCon's
-- get an info table. The family declaration 'TyCon' does not
isDataTyCon (AlgTyCon {algTcRhs = rhs})
= case rhs of
DataFamilyTyCon {} -> False
- DataTyCon {} -> True
- NewTyCon {} -> False
- AbstractTyCon {} -> False -- We don't know, so return False
+ DataTyCon {} -> True
+ NewTyCon {} -> False
+ AbstractTyCon {} -> False -- We don't know, so return False
isDataTyCon (TupleTyCon {tyConTupleSort = sort}) = isBoxed (tupleSortBoxity sort)
isDataTyCon _ = False
--- | 'isDistinctTyCon' is true of 'TyCon's that are equal only to
+-- | 'isDistinctTyCon' is true of 'TyCon's that are equal only to
-- themselves, even via coercions (except for unsafeCoerce).
-- This excludes newtypes, type functions, type synonyms.
--- It relates directly to the FC consistency story:
--- If the axioms are consistent,
+-- It relates directly to the FC consistency story:
+-- If the axioms are consistent,
-- and co : S tys ~ T tys, and S,T are "distinct" TyCons,
-- then S=T.
-- Cf Note [Pruning dead case alternatives] in Unify
@@ -1041,7 +1046,7 @@ isDistinctTyCon (PromotedDataTyCon {}) = True
isDistinctTyCon _ = False
isDistinctAlgRhs :: AlgTyConRhs -> Bool
-isDistinctAlgRhs (DataTyCon {}) = True
+isDistinctAlgRhs (DataTyCon {}) = True
isDistinctAlgRhs (DataFamilyTyCon {}) = True
isDistinctAlgRhs (AbstractTyCon distinct) = distinct
isDistinctAlgRhs (NewTyCon {}) = False
@@ -1055,33 +1060,33 @@ isNewTyCon _ = False
-- into, and (possibly) a coercion from the representation type to the @newtype@.
-- Returns @Nothing@ if this is not possible.
unwrapNewTyCon_maybe :: TyCon -> Maybe ([TyVar], Type, CoAxiom)
-unwrapNewTyCon_maybe (AlgTyCon { tyConTyVars = tvs,
- algTcRhs = NewTyCon { nt_co = co,
- nt_rhs = rhs }})
- = Just (tvs, rhs, co)
+unwrapNewTyCon_maybe (AlgTyCon { tyConTyVars = tvs,
+ algTcRhs = NewTyCon { nt_co = co,
+ nt_rhs = rhs }})
+ = Just (tvs, rhs, co)
unwrapNewTyCon_maybe _ = Nothing
isProductTyCon :: TyCon -> Bool
-- | A /product/ 'TyCon' must both:
--
-- 1. Have /one/ constructor
---
+--
-- 2. /Not/ be existential
---
--- However other than this there are few restrictions: they may be @data@ or @newtype@
+--
+-- However other than this there are few restrictions: they may be @data@ or @newtype@
-- 'TyCon's of any boxity and may even be recursive.
isProductTyCon tc@(AlgTyCon {}) = case algTcRhs tc of
- DataTyCon{ data_cons = [data_con] }
- -> isVanillaDataCon data_con
- NewTyCon {} -> True
- _ -> False
-isProductTyCon (TupleTyCon {}) = True
+ DataTyCon{ data_cons = [data_con] }
+ -> isVanillaDataCon data_con
+ NewTyCon {} -> True
+ _ -> False
+isProductTyCon (TupleTyCon {}) = True
isProductTyCon _ = False
-- | Is this a 'TyCon' representing a type synonym (@type@)?
isSynTyCon :: TyCon -> Bool
isSynTyCon (SynTyCon {}) = True
-isSynTyCon _ = False
+isSynTyCon _ = False
-- As for newtypes, it is in some contexts important to distinguish between
-- closed synonyms and synonym families, as synonym families have no unique
@@ -1110,7 +1115,7 @@ isEnumerationTyCon _ = False
isFamilyTyCon :: TyCon -> Bool
isFamilyTyCon (SynTyCon {synTcRhs = SynFamilyTyCon {}}) = True
isFamilyTyCon (AlgTyCon {algTcRhs = DataFamilyTyCon {}}) = True
-isFamilyTyCon _ = False
+isFamilyTyCon _ = False
-- | Is this a synonym 'TyCon' that can have may have further instances appear?
isSynFamilyTyCon :: TyCon -> Bool
@@ -1130,12 +1135,12 @@ isClosedSynTyCon tycon = isSynTyCon tycon && not (isFamilyTyCon tycon)
-- T ty1 ~ T ty2 => ty1 ~ ty2
isInjectiveTyCon :: TyCon -> Bool
isInjectiveTyCon tc = not (isSynTyCon tc)
- -- Ultimately we may have injective associated types
+ -- Ultimately we may have injective associated types
-- in which case this test will become more interesting
- --
+ --
-- It'd be unusual to call isInjectiveTyCon on a regular H98
- -- type synonym, because you should probably have expanded it first
- -- But regardless, it's not injective!
+ -- type synonym, because you should probably have expanded it first
+ -- But regardless, it's not injective!
-- | Are we able to extract informationa 'TyVar' to class argument list
-- mappping from a given 'TyCon'?
@@ -1212,58 +1217,63 @@ isPromotedTypeTyCon _ = False
-- Note that:
--
-- * Associated families are implicit, as they are re-constructed from
--- the class declaration in which they reside, and
+-- the class declaration in which they reside, and
--
-- * Family instances are /not/ implicit as they represent the instance body
-- (similar to a @dfun@ does that for a class instance).
isImplicitTyCon :: TyCon -> Bool
-isImplicitTyCon tycon
+isImplicitTyCon tycon
| isTyConAssoc tycon = True
| isSynTyCon tycon = False
| isAlgTyCon tycon = isTupleTyCon tycon
| otherwise = True
- -- 'otherwise' catches: FunTyCon, PrimTyCon,
+ -- 'otherwise' catches: FunTyCon, PrimTyCon,
-- PromotedDataCon, PomotedTypeTyCon
+
+tyConCType_maybe :: TyCon -> Maybe CType
+tyConCType_maybe tc@(AlgTyCon {}) = tyConCType tc
+tyConCType_maybe tc@(SynTyCon {}) = tyConCType tc
+tyConCType_maybe _ = Nothing
\end{code}
-----------------------------------------------
--- Expand type-constructor applications
+-- Expand type-constructor applications
-----------------------------------------------
\begin{code}
-tcExpandTyCon_maybe, coreExpandTyCon_maybe
- :: TyCon
- -> [tyco] -- ^ Arguments to 'TyCon'
- -> Maybe ([(TyVar,tyco)],
- Type,
- [tyco]) -- ^ Returns a 'TyVar' substitution, the body type
+tcExpandTyCon_maybe, coreExpandTyCon_maybe
+ :: TyCon
+ -> [tyco] -- ^ Arguments to 'TyCon'
+ -> Maybe ([(TyVar,tyco)],
+ Type,
+ [tyco]) -- ^ Returns a 'TyVar' substitution, the body type
-- of the synonym (not yet substituted) and any arguments
-- remaining from the application
--- ^ Used to create the view the /typechecker/ has on 'TyCon's.
+-- ^ Used to create the view the /typechecker/ has on 'TyCon's.
-- We expand (closed) synonyms only, cf. 'coreExpandTyCon_maybe'
-tcExpandTyCon_maybe (SynTyCon {tyConTyVars = tvs,
- synTcRhs = SynonymTyCon rhs }) tys
+tcExpandTyCon_maybe (SynTyCon {tyConTyVars = tvs,
+ synTcRhs = SynonymTyCon rhs }) tys
= expand tvs rhs tys
tcExpandTyCon_maybe _ _ = Nothing
---------------
--- ^ Used to create the view /Core/ has on 'TyCon's. We expand
+-- ^ Used to create the view /Core/ has on 'TyCon's. We expand
-- not only closed synonyms like 'tcExpandTyCon_maybe',
-- but also non-recursive @newtype@s
coreExpandTyCon_maybe tycon tys = tcExpandTyCon_maybe tycon tys
----------------
-expand :: [TyVar] -> Type -- Template
- -> [a] -- Args
- -> Maybe ([(TyVar,a)], Type, [a]) -- Expansion
+expand :: [TyVar] -> Type -- Template
+ -> [a] -- Args
+ -> Maybe ([(TyVar,a)], Type, [a]) -- Expansion
expand tvs rhs tys
= case n_tvs `compare` length tys of
- LT -> Just (tvs `zip` tys, rhs, drop n_tvs tys)
- EQ -> Just (tvs `zip` tys, rhs, [])
+ LT -> Just (tvs `zip` tys, rhs, drop n_tvs tys)
+ EQ -> Just (tvs `zip` tys, rhs, [])
GT -> Nothing
where
n_tvs = length tvs
@@ -1285,17 +1295,17 @@ tyConDataCons tycon = tyConDataCons_maybe tycon `orElse` []
tyConDataCons_maybe :: TyCon -> Maybe [DataCon]
tyConDataCons_maybe (AlgTyCon {algTcRhs = DataTyCon { data_cons = cons }}) = Just cons
tyConDataCons_maybe (AlgTyCon {algTcRhs = NewTyCon { data_con = con }}) = Just [con]
-tyConDataCons_maybe (TupleTyCon {dataCon = con}) = Just [con]
+tyConDataCons_maybe (TupleTyCon {dataCon = con}) = Just [con]
tyConDataCons_maybe _ = Nothing
-- | Determine the number of value constructors a 'TyCon' has. Panics if the 'TyCon'
-- is not algebraic or a tuple
tyConFamilySize :: TyCon -> Int
-tyConFamilySize (AlgTyCon {algTcRhs = DataTyCon {data_cons = cons}}) =
+tyConFamilySize (AlgTyCon {algTcRhs = DataTyCon {data_cons = cons}}) =
length cons
tyConFamilySize (AlgTyCon {algTcRhs = NewTyCon {}}) = 1
tyConFamilySize (AlgTyCon {algTcRhs = DataFamilyTyCon {}}) = 0
-tyConFamilySize (TupleTyCon {}) = 1
+tyConFamilySize (TupleTyCon {}) = 1
tyConFamilySize other = pprPanic "tyConFamilySize:" (ppr other)
-- | Extract an 'AlgTyConRhs' with information about data constructors from an algebraic or tuple
@@ -1325,11 +1335,11 @@ newTyConEtadRhs tycon = pprPanic "newTyConEtadRhs" (ppr tycon)
-- is not a @newtype@, returns @Nothing@
newTyConCo_maybe :: TyCon -> Maybe CoAxiom
newTyConCo_maybe (AlgTyCon {algTcRhs = NewTyCon { nt_co = co }}) = Just co
-newTyConCo_maybe _ = Nothing
+newTyConCo_maybe _ = Nothing
newTyConCo :: TyCon -> CoAxiom
newTyConCo tc = case newTyConCo_maybe tc of
- Just co -> co
+ Just co -> co
Nothing -> pprPanic "newTyConCo" (ppr tc)
-- | Find the primitive representation of a 'TyCon'
@@ -1343,7 +1353,7 @@ tyConPrimRep tc = ASSERT(not (isUnboxedTupleTyCon tc)) PtrRep
-- an algebraic type declaration, e.g. @Eq a@ in the declaration @data Eq a => T a ...@
tyConStupidTheta :: TyCon -> [PredType]
tyConStupidTheta (AlgTyCon {algTcStupidTheta = stupid}) = stupid
-tyConStupidTheta (TupleTyCon {}) = []
+tyConStupidTheta (TupleTyCon {}) = []
tyConStupidTheta tycon = pprPanic "tyConStupidTheta" (ppr tycon)
\end{code}
@@ -1351,7 +1361,7 @@ tyConStupidTheta tycon = pprPanic "tyConStupidTheta" (ppr tycon)
-- | Extract the 'TyVar's bound by a type synonym and the corresponding (unsubstituted) right hand side.
-- If the given 'TyCon' is not a type synonym, panics
synTyConDefn :: TyCon -> ([TyVar], Type)
-synTyConDefn (SynTyCon {tyConTyVars = tyvars, synTcRhs = SynonymTyCon ty})
+synTyConDefn (SynTyCon {tyConTyVars = tyvars, synTcRhs = SynonymTyCon ty})
= (tyvars, ty)
synTyConDefn tycon = pprPanic "getSynTyConDefn" (ppr tycon)
@@ -1359,15 +1369,15 @@ synTyConDefn tycon = pprPanic "getSynTyConDefn" (ppr tycon)
-- if the given 'TyCon' is not a type synonym
synTyConRhs :: TyCon -> SynTyConRhs
synTyConRhs (SynTyCon {synTcRhs = rhs}) = rhs
-synTyConRhs tc = pprPanic "synTyConRhs" (ppr tc)
+synTyConRhs tc = pprPanic "synTyConRhs" (ppr tc)
-- | Find the expansion of the type synonym represented by the given 'TyCon'. The free variables of this
-- type will typically include those 'TyVar's bound by the 'TyCon'. Panics if the 'TyCon' is not that of
-- a type synonym
synTyConType :: TyCon -> Type
synTyConType tc = case synTcRhs tc of
- SynonymTyCon t -> t
- _ -> pprPanic "synTyConType" (ppr tc)
+ SynonymTyCon t -> t
+ _ -> pprPanic "synTyConType" (ppr tc)
\end{code}
\begin{code}
@@ -1376,10 +1386,10 @@ synTyConType tc = case synTcRhs tc of
-- has more than one constructor, or represents a primitive or function type constructor then
-- @Nothing@ is returned. In any other case, the function panics
tyConSingleDataCon_maybe :: TyCon -> Maybe DataCon
-tyConSingleDataCon_maybe (TupleTyCon {dataCon = c}) = Just c
+tyConSingleDataCon_maybe (TupleTyCon {dataCon = c}) = Just c
tyConSingleDataCon_maybe (AlgTyCon {algTcRhs = DataTyCon { data_cons = [c] }}) = Just c
tyConSingleDataCon_maybe (AlgTyCon {algTcRhs = NewTyCon { data_con = c }}) = Just c
-tyConSingleDataCon_maybe _ = Nothing
+tyConSingleDataCon_maybe _ = Nothing
\end{code}
\begin{code}
@@ -1432,7 +1442,7 @@ tyConFamInst_maybe tc
FamInstTyCon _ f ts -> Just (f, ts)
_ -> Nothing
--- | If this 'TyCon' is that of a family instance, return a 'TyCon' which represents
+-- | If this 'TyCon' is that of a family instance, return a 'TyCon' which represents
-- a coercion identifying the representation type with the type instance family.
-- Otherwise, return @Nothing@
tyConFamilyCoercion_maybe :: TyCon -> Maybe CoAxiom
@@ -1444,9 +1454,9 @@ tyConFamilyCoercion_maybe tc
%************************************************************************
-%* *
+%* *
\subsection[TyCon-instances]{Instance declarations for @TyCon@}
-%* *
+%* *
%************************************************************************
@TyCon@s are compared by comparing their @Unique@s.
@@ -1461,9 +1471,9 @@ instance Eq TyCon where
instance Ord TyCon where
a <= b = case (a `compare` b) of { LT -> True; EQ -> True; GT -> False }
- a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
+ a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
a >= b = case (a `compare` b) of { LT -> False; EQ -> True; GT -> True }
- a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
+ a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
compare a b = getUnique a `compare` getUnique b
instance Uniquable TyCon where
@@ -1492,13 +1502,13 @@ instance Data.Data TyCon where
instance Eq CoAxiom where
a == b = case (a `compare` b) of { EQ -> True; _ -> False }
a /= b = case (a `compare` b) of { EQ -> False; _ -> True }
-
+
instance Ord CoAxiom where
a <= b = case (a `compare` b) of { LT -> True; EQ -> True; GT -> False }
a < b = case (a `compare` b) of { LT -> True; EQ -> False; GT -> False }
a >= b = case (a `compare` b) of { LT -> False; EQ -> True; GT -> True }
a > b = case (a `compare` b) of { LT -> False; EQ -> False; GT -> True }
- compare a b = getUnique a `compare` getUnique b
+ compare a b = getUnique a `compare` getUnique b
instance Uniquable CoAxiom where
getUnique = co_ax_unique
diff --git a/compiler/vectorise/Vectorise/Generic/PData.hs b/compiler/vectorise/Vectorise/Generic/PData.hs
index 1026e95029..f860a4a900 100644
--- a/compiler/vectorise/Vectorise/Generic/PData.hs
+++ b/compiler/vectorise/Vectorise/Generic/PData.hs
@@ -47,6 +47,7 @@ buildDataFamInst name' fam_tc vect_tc rhs
pat_tys = [mkTyConApp vect_tc (mkTyVarTys tyvars)]
rep_tc = buildAlgTyCon name'
tyvars
+ Nothing
[] -- no stupid theta
rhs
rec_flag -- FIXME: is this ok?
diff --git a/compiler/vectorise/Vectorise/Type/Env.hs b/compiler/vectorise/Vectorise/Type/Env.hs
index 0051d072a4..dd4b923ca0 100644
--- a/compiler/vectorise/Vectorise/Type/Env.hs
+++ b/compiler/vectorise/Vectorise/Type/Env.hs
@@ -326,7 +326,7 @@ vectTypeEnv tycons vectTypeDecls vectClassDecls
origName = tyConName origTyCon
vectName = tyConName vectTyCon
- mkSyn canonName ty = mkSynTyCon canonName (typeKind ty) [] (SynonymTyCon ty) NoParentTyCon
+ mkSyn canonName ty = mkSynTyCon canonName (typeKind ty) [] Nothing (SynonymTyCon ty) NoParentTyCon
defDataCons
| isAbstract = return ()
diff --git a/compiler/vectorise/Vectorise/Type/TyConDecl.hs b/compiler/vectorise/Vectorise/Type/TyConDecl.hs
index 9b830446c8..9f682a86fd 100644
--- a/compiler/vectorise/Vectorise/Type/TyConDecl.hs
+++ b/compiler/vectorise/Vectorise/Type/TyConDecl.hs
@@ -96,6 +96,7 @@ vectTyConDecl tycon name'
; return $ buildAlgTyCon
name' -- new name
(tyConTyVars tycon) -- keep original type vars
+ Nothing
[] -- no stupid theta
rhs' -- new constructor defs
rec_flag -- whether recursive
diff --git a/ghc/GhciMonad.hs b/ghc/GhciMonad.hs
index f1767c3ea5..71d1e763d3 100644
--- a/ghc/GhciMonad.hs
+++ b/ghc/GhciMonad.hs
@@ -22,7 +22,6 @@ module GhciMonad (
printForUser, printForUserPartWay, prettyLocations,
initInterpBuffering, turnOffBuffering, flushInterpBuffers,
- ghciHandleGhcException,
) where
#include "HsVersions.h"
@@ -31,7 +30,6 @@ import qualified GHC
import GhcMonad hiding (liftIO)
import Outputable hiding (printForUser, printForUserPartWay)
import qualified Outputable
-import Panic hiding (showException)
import Util
import DynFlags
import HscTypes
@@ -171,9 +169,6 @@ instance Monad GHCi where
instance Functor GHCi where
fmap f m = m >>= return . f
-ghciHandleGhcException :: (GhcException -> GHCi a) -> GHCi a -> GHCi a
-ghciHandleGhcException = handleGhcException
-
getGHCiState :: GHCi GHCiState
getGHCiState = GHCi $ \r -> liftIO $ readIORef r
setGHCiState :: GHCiState -> GHCi ()