\begin{code}
module IfaceType (
IfaceType(..), IfaceKind, IfacePredType(..), IfaceTyCon(..),
\begin{code}
module IfaceType (
IfaceType(..), IfaceKind, IfacePredType(..), IfaceTyCon(..),
- IfaceContext, IfaceBndr(..), IfaceTvBndr, IfaceIdBndr,
+ IfaceContext, IfaceBndr(..), IfaceTvBndr, IfaceIdBndr, IfaceCoercion,
IfaceExtName(..), mkIfaceExtName, isLocalIfaceExtName,
IfaceExtName(..), mkIfaceExtName, isLocalIfaceExtName,
-- Conversion from Type -> IfaceType
toIfaceType, toIfacePred, toIfaceContext,
-- Conversion from Type -> IfaceType
toIfaceType, toIfacePred, toIfaceContext,
-import Kind ( Kind(..) )
-import TypeRep ( TyThing(..), Type(..), PredType(..), ThetaType )
+import Type ( Kind )
+import Coercion ( Coercion )
+import TypeRep ( TyThing(..), Type(..), PredType(..), ThetaType,
+ unliftedTypeKindTyConName, openTypeKindTyConName,
+ ubxTupleKindTyConName, argTypeKindTyConName,
+ liftedTypeKindTyConName, isLiftedTypeKind )
import TyCon ( TyCon, isTupleTyCon, tyConArity, tupleTyConBoxity, tyConName )
import Var ( isId, tyVarKind, idType )
import TysWiredIn ( listTyConName, parrTyConName, tupleTyCon, intTyConName, charTyConName, boolTyConName )
import OccName ( OccName, parenSymOcc, occNameFS )
import Name ( Name, getName, getOccName, nameModule, nameOccName,
wiredInNameTyThing_maybe )
import TyCon ( TyCon, isTupleTyCon, tyConArity, tupleTyConBoxity, tyConName )
import Var ( isId, tyVarKind, idType )
import TysWiredIn ( listTyConName, parrTyConName, tupleTyCon, intTyConName, charTyConName, boolTyConName )
import OccName ( OccName, parenSymOcc, occNameFS )
import Name ( Name, getName, getOccName, nameModule, nameOccName,
wiredInNameTyThing_maybe )
import BasicTypes ( IPName(..), Arity, Version, mapIPName, tupleParens, Boxity )
import Outputable
import FastString
import BasicTypes ( IPName(..), Arity, Version, mapIPName, tupleParens, Boxity )
import Outputable
import FastString
- = ExtPkg Module OccName -- From an external package; no version #
- -- Also used for wired-in things regardless
- -- of whether they are home-pkg or not
+ = ExtPkg Module OccName
+ -- From an external package; no version # Also used for
+ -- wired-in things regardless of whether they are home-pkg or
+ -- not
- | HomePkg Module OccName Version -- From another module in home package;
- -- has version #; in all other respects,
- -- HomePkg and ExtPkg are the same
+ | HomePkg ModuleName OccName Version
+ -- From another module in home package; has version #; in all
+ -- other respects, HomePkg and ExtPkg are the same. Since this
+ -- is a home package name, we use ModuleName rather than Module
ifaceExtOcc (HomePkg _ occ _) = occ
ifaceExtOcc (LocalTop occ) = occ
ifaceExtOcc (LocalTopSub occ _) = occ
ifaceExtOcc (HomePkg _ occ _) = occ
ifaceExtOcc (LocalTop occ) = occ
ifaceExtOcc (LocalTopSub occ _) = occ
type IfaceTvBndr = (FastString, IfaceKind)
-------------------------------
type IfaceTvBndr = (FastString, IfaceKind)
-------------------------------
data IfacePredType -- NewTypes are handled as ordinary TyConApps
= IfaceClassP IfaceExtName [IfaceType]
| IfaceIParam (IPName OccName) IfaceType
data IfacePredType -- NewTypes are handled as ordinary TyConApps
= IfaceClassP IfaceExtName [IfaceType]
| IfaceIParam (IPName OccName) IfaceType
| IfaceIntTc | IfaceBoolTc | IfaceCharTc
| IfaceListTc | IfacePArrTc
| IfaceTupTc Boxity Arity
| IfaceIntTc | IfaceBoolTc | IfaceCharTc
| IfaceListTc | IfacePArrTc
| IfaceTupTc Boxity Arity
ifaceTyConName :: IfaceTyCon -> Name -- Works for all except IfaceTc
ifaceTyConName IfaceIntTc = intTyConName
ifaceTyConName :: IfaceTyCon -> Name -- Works for all except IfaceTc
ifaceTyConName IfaceIntTc = intTyConName
ifaceTyConName IfaceListTc = listTyConName
ifaceTyConName IfacePArrTc = parrTyConName
ifaceTyConName (IfaceTupTc bx ar) = getName (tupleTyCon bx ar)
ifaceTyConName IfaceListTc = listTyConName
ifaceTyConName IfacePArrTc = parrTyConName
ifaceTyConName (IfaceTupTc bx ar) = getName (tupleTyCon bx ar)
+ifaceTyConName IfaceLiftedTypeKindTc = liftedTypeKindTyConName
+ifaceTyConName IfaceOpenTypeKindTc = openTypeKindTyConName
+ifaceTyConName IfaceUnliftedTypeKindTc = unliftedTypeKindTyConName
+ifaceTyConName IfaceUbxTupleKindTc = ubxTupleKindTyConName
+ifaceTyConName IfaceArgTypeKindTc = argTypeKindTyConName
-- These instances are used only when printing for the user, either when
-- debugging, or in GHCi when printing the results of a :info command
instance Outputable IfaceExtName where
-- These instances are used only when printing for the user, either when
-- debugging, or in GHCi when printing the results of a :info command
instance Outputable IfaceExtName where
- ppr (ExtPkg mod occ) = pprExt mod occ
- ppr (HomePkg mod occ vers) = pprExt mod occ <> braces (ppr vers)
+ ppr (ExtPkg mod occ) = ppr mod <> dot <> ppr occ
+ ppr (HomePkg mod occ vers) = ppr mod <> dot <> ppr occ <> braces (ppr vers)
ppr (LocalTop occ) = ppr occ -- Do we want to distinguish these
ppr (LocalTopSub occ _) = ppr occ -- from an ordinary occurrence?
ppr (LocalTop occ) = ppr occ -- Do we want to distinguish these
ppr (LocalTopSub occ _) = ppr occ -- from an ordinary occurrence?
-- No need to worry about printing unqualified becuase that was handled
-- in the transiation to IfaceSyn
-- No need to worry about printing unqualified becuase that was handled
-- in the transiation to IfaceSyn
pprIfaceIdBndr (name, ty) = hsep [ppr name, dcolon, ppr ty]
pprIfaceTvBndr :: IfaceTvBndr -> SDoc
pprIfaceIdBndr (name, ty) = hsep [ppr name, dcolon, ppr ty]
pprIfaceTvBndr :: IfaceTvBndr -> SDoc
-pprIfaceTvBndr (tv, LiftedTypeKind) = ppr tv
-pprIfaceTvBndr (tv, kind) = parens (ppr tv <> dcolon <> ppr kind)
-
+pprIfaceTvBndr (tv, IfaceTyConApp IfaceLiftedTypeKindTc [])
+ = ppr tv
+pprIfaceTvBndr (tv, kind) = parens (ppr tv <> dcolon <> ppr kind)
ppr (IfaceIParam ip ty) = hsep [ppr ip, dcolon, ppr ty]
ppr (IfaceClassP cls ts) = parenSymOcc (ifaceExtOcc cls) (ppr cls)
<+> sep (map pprParendIfaceType ts)
ppr (IfaceIParam ip ty) = hsep [ppr ip, dcolon, ppr ty]
ppr (IfaceClassP cls ts) = parenSymOcc (ifaceExtOcc cls) (ppr cls)
<+> sep (map pprParendIfaceType ts)
toIfaceIdBndr ext id = (occNameFS (getOccName id), toIfaceType ext (idType id))
toIfaceTvBndrs tyvars = map toIfaceTvBndr tyvars
toIfaceIdBndr ext id = (occNameFS (getOccName id), toIfaceType ext (idType id))
toIfaceTvBndrs tyvars = map toIfaceTvBndr tyvars
---------------------
toIfaceType :: (Name -> IfaceExtName) -> Type -> IfaceType
-- Synonyms are retained in the interface type
---------------------
toIfaceType :: (Name -> IfaceExtName) -> Type -> IfaceType
-- Synonyms are retained in the interface type
toIfaceWiredInTyCon :: (Name -> IfaceExtName) -> TyCon -> Name -> IfaceTyCon
toIfaceWiredInTyCon ext tc nm
toIfaceWiredInTyCon :: (Name -> IfaceExtName) -> TyCon -> Name -> IfaceTyCon
toIfaceWiredInTyCon ext tc nm
- | isTupleTyCon tc = IfaceTupTc (tupleTyConBoxity tc) (tyConArity tc)
- | nm == intTyConName = IfaceIntTc
- | nm == boolTyConName = IfaceBoolTc
- | nm == charTyConName = IfaceCharTc
- | nm == listTyConName = IfaceListTc
- | nm == parrTyConName = IfacePArrTc
- | otherwise = IfaceTc (ext nm)
+ | isTupleTyCon tc = IfaceTupTc (tupleTyConBoxity tc) (tyConArity tc)
+ | nm == intTyConName = IfaceIntTc
+ | nm == boolTyConName = IfaceBoolTc
+ | nm == charTyConName = IfaceCharTc
+ | nm == listTyConName = IfaceListTc
+ | nm == parrTyConName = IfacePArrTc
+ | nm == liftedTypeKindTyConName = IfaceLiftedTypeKindTc
+ | nm == unliftedTypeKindTyConName = IfaceUnliftedTypeKindTc
+ | nm == openTypeKindTyConName = IfaceOpenTypeKindTc
+ | nm == argTypeKindTyConName = IfaceArgTypeKindTc
+ | nm == ubxTupleKindTyConName = IfaceUbxTupleKindTc
+ | otherwise = IfaceTc (ext nm)
-toIfacePred ext (ClassP cls ts) = IfaceClassP (ext (getName cls)) (toIfaceTypes ext ts)
-toIfacePred ext (IParam ip t) = IfaceIParam (mapIPName getOccName ip) (toIfaceType ext t)
+toIfacePred ext (ClassP cls ts) = IfaceClassP (ext (getName cls)) (toIfaceTypes ext ts)
+toIfacePred ext (IParam ip t) = IfaceIParam (mapIPName getOccName ip) (toIfaceType ext t)
+toIfacePred ext (EqPred ty1 ty2) = IfaceEqPred (toIfaceType ext ty1) (toIfaceType ext ty2)