summaryrefslogtreecommitdiff
path: root/compiler/iface
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/iface')
-rw-r--r--compiler/iface/BuildTyCl.hs42
-rw-r--r--compiler/iface/IfaceSyn.hs101
-rw-r--r--compiler/iface/MkIface.hs10
-rw-r--r--compiler/iface/TcIface.hs89
4 files changed, 130 insertions, 112 deletions
diff --git a/compiler/iface/BuildTyCl.hs b/compiler/iface/BuildTyCl.hs
index 11873077ce..6085b0cc3c 100644
--- a/compiler/iface/BuildTyCl.hs
+++ b/compiler/iface/BuildTyCl.hs
@@ -14,7 +14,7 @@ module BuildTyCl (
TcMethInfo, buildClass,
distinctAbstractTyConRhs, totallyAbstractTyConRhs,
mkNewTyConRhs, mkDataTyConRhs,
- newImplicitBinder
+ newImplicitBinder, newTyConRepName
) where
#include "HsVersions.h"
@@ -22,6 +22,7 @@ module BuildTyCl (
import IfaceEnv
import FamInstEnv( FamInstEnvs )
import TysWiredIn( isCTupleTyConName )
+import PrelNames( tyConRepModOcc )
import DataCon
import PatSyn
import Var
@@ -36,6 +37,7 @@ import Id
import Coercion
import TcType
+import SrcLoc( noSrcSpan )
import DynFlags
import TcRnMonad
import UniqSupply
@@ -49,7 +51,8 @@ buildSynonymTyCon :: Name -> [TyVar] -> [Role]
-> TyCon
buildSynonymTyCon tc_name tvs roles rhs rhs_kind
= mkSynonymTyCon tc_name kind tvs roles rhs
- where kind = mkPiKinds tvs rhs_kind
+ where
+ kind = mkPiKinds tvs rhs_kind
buildFamilyTyCon :: Name -- ^ Type family name
@@ -57,7 +60,7 @@ buildFamilyTyCon :: Name -- ^ Type family name
-> Maybe Name -- ^ Result variable name
-> FamTyConFlav -- ^ Open, closed or in a boot file?
-> Kind -- ^ Kind of the RHS
- -> TyConParent -- ^ Parent, if exists
+ -> Maybe Class -- ^ Parent, if exists
-> Injectivity -- ^ Injectivity annotation
-- See [Injectivity annotation] in HsDecls
-> TyCon
@@ -132,7 +135,9 @@ mkNewTyConRhs tycon_name tycon con
------------------------------------------------------
buildDataCon :: FamInstEnvs
- -> Name -> Bool
+ -> Name
+ -> Bool -- Declared infix
+ -> Promoted TyConRepName -- Promotable
-> [HsSrcBang]
-> Maybe [HsImplBang]
-- See Note [Bangs on imported data constructors] in MkId
@@ -148,7 +153,7 @@ buildDataCon :: FamInstEnvs
-- a) makes the worker Id
-- b) makes the wrapper Id if necessary, including
-- allocating its unique (hence monadic)
-buildDataCon fam_envs src_name declared_infix src_bangs impl_bangs field_lbls
+buildDataCon fam_envs src_name declared_infix prom_info src_bangs impl_bangs field_lbls
univ_tvs ex_tvs eq_spec ctxt arg_tys res_ty rep_tycon
= do { wrap_name <- newImplicitBinder src_name mkDataConWrapperOcc
; work_name <- newImplicitBinder src_name mkDataConWorkerOcc
@@ -156,11 +161,12 @@ buildDataCon fam_envs src_name declared_infix src_bangs impl_bangs field_lbls
-- code, which (for Haskell source anyway) will be in the DataName name
-- space, and puts it into the VarName name space
+ ; traceIf (text "buildDataCon 1" <+> ppr src_name)
; us <- newUniqueSupply
; dflags <- getDynFlags
; let
stupid_ctxt = mkDataConStupidTheta rep_tycon arg_tys univ_tvs
- data_con = mkDataCon src_name declared_infix
+ data_con = mkDataCon src_name declared_infix prom_info
src_bangs field_lbls
univ_tvs ex_tvs eq_spec ctxt
arg_tys res_ty rep_tycon
@@ -169,6 +175,7 @@ buildDataCon fam_envs src_name declared_infix src_bangs impl_bangs field_lbls
dc_rep = initUs_ us (mkDataConRep dflags fam_envs wrap_name
impl_bangs data_con)
+ ; traceIf (text "buildDataCon 2" <+> ppr src_name)
; return data_con }
@@ -227,7 +234,8 @@ type TcMethInfo = (Name, DefMethSpec, Type)
-- A temporary intermediate, to communicate between
-- tcClassSigs and buildClass.
-buildClass :: Name -> [TyVar] -> [Role] -> ThetaType
+buildClass :: Name -- Name of the class/tycon (they have the same Name)
+ -> [TyVar] -> [Role] -> ThetaType
-> [FunDep TyVar] -- Functional dependencies
-> [ClassATItem] -- Associated types
-> [TcMethInfo] -- Method info
@@ -240,10 +248,7 @@ buildClass tycon_name tvs roles sc_theta fds at_items sig_stuff mindef tc_isrec
do { traceIf (text "buildClass")
; datacon_name <- newImplicitBinder tycon_name mkClassDataConOcc
- -- The class name is the 'parent' for this datacon, not its tycon,
- -- because one should import the class to get the binding for
- -- the datacon
-
+ ; tc_rep_name <- newTyConRepName tycon_name
; op_items <- mapM (mk_op_item rec_clas) sig_stuff
-- Build the selector id and default method id
@@ -282,6 +287,7 @@ buildClass tycon_name tvs roles sc_theta fds at_items sig_stuff mindef tc_isrec
; dict_con <- buildDataCon (panic "buildClass: FamInstEnvs")
datacon_name
False -- Not declared infix
+ NotPromoted -- Class tycons are not promoted
(map (const no_bang) args)
(Just (map (const HsLazy) args))
[{- No fields -}]
@@ -300,9 +306,8 @@ buildClass tycon_name tvs roles sc_theta fds at_items sig_stuff mindef tc_isrec
else return (mkDataTyConRhs [dict_con])
; let { clas_kind = mkPiKinds tvs constraintKind
-
- ; tycon = mkClassTyCon tycon_name clas_kind tvs roles
- rhs rec_clas tc_isrec
+ ; tycon = mkClassTyCon tycon_name clas_kind tvs roles
+ rhs rec_clas tc_isrec tc_rep_name
-- A class can be recursive, and in the case of newtypes
-- this matters. For example
-- class C a where { op :: C b => a -> b -> Int }
@@ -366,3 +371,12 @@ newImplicitBinder base_name mk_sys_occ
where
occ = mk_sys_occ (nameOccName base_name)
loc = nameSrcSpan base_name
+
+-- | Make the 'TyConRepName' for this 'TyCon'
+newTyConRepName :: Name -> TcRnIf gbl lcl TyConRepName
+newTyConRepName tc_name
+ | Just mod <- nameModule_maybe tc_name
+ , (mod, occ) <- tyConRepModOcc mod (nameOccName tc_name)
+ = newGlobalBinder mod occ noSrcSpan
+ | otherwise
+ = newImplicitBinder tc_name mkTyConRepUserOcc
diff --git a/compiler/iface/IfaceSyn.hs b/compiler/iface/IfaceSyn.hs
index 8bf744f0c7..3911786594 100644
--- a/compiler/iface/IfaceSyn.hs
+++ b/compiler/iface/IfaceSyn.hs
@@ -165,7 +165,8 @@ data IfaceTyConParent
IfaceTcArgs
data IfaceFamTyConFlav
- = IfaceOpenSynFamilyTyCon
+ = IfaceDataFamilyTyCon -- Data family
+ | IfaceOpenSynFamilyTyCon
| IfaceClosedSynFamilyTyCon (Maybe (IfExtName, [IfaceAxBranch]))
-- ^ Name of associated axiom and branches for pretty printing purposes,
-- or 'Nothing' for an empty closed family without an axiom
@@ -192,7 +193,6 @@ data IfaceAxBranch = IfaceAxBranch { ifaxbTyVars :: [IfaceTvBndr]
data IfaceConDecls
= IfAbstractTyCon Bool -- c.f TyCon.AbstractTyCon
- | IfDataFamTyCon -- Data family
| IfDataTyCon [IfaceConDecl] Bool [FieldLabelString] -- Data type decls
| IfNewTyCon IfaceConDecl Bool [FieldLabelString] -- Newtype decls
@@ -343,14 +343,12 @@ See [http://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/RecompilationAvoid
visibleIfConDecls :: IfaceConDecls -> [IfaceConDecl]
visibleIfConDecls (IfAbstractTyCon {}) = []
-visibleIfConDecls IfDataFamTyCon = []
visibleIfConDecls (IfDataTyCon cs _ _) = cs
visibleIfConDecls (IfNewTyCon c _ _) = [c]
ifaceConDeclFields :: IfaceConDecls -> [FieldLbl OccName]
ifaceConDeclFields x = case x of
IfAbstractTyCon {} -> []
- IfDataFamTyCon {} -> []
IfDataTyCon cons is_over labels -> map (help cons is_over) labels
IfNewTyCon con is_over labels -> map (help [con] is_over) labels
where
@@ -368,35 +366,15 @@ ifaceDeclImplicitBndrs :: IfaceDecl -> [OccName]
-- TyThing.getOccName should define a bijection between the two lists.
-- This invariant is used in LoadIface.loadDecl (see note [Tricky iface loop])
-- The order of the list does not matter.
-ifaceDeclImplicitBndrs IfaceData {ifCons = IfAbstractTyCon {}} = []
-
--- Newtype
-ifaceDeclImplicitBndrs (IfaceData {ifName = tc_occ,
- ifCons = IfNewTyCon (IfCon { ifConOcc = con_occ }) _ _})
- = -- implicit newtype coercion
- (mkNewTyCoOcc tc_occ) : -- JPM: newtype coercions shouldn't be implicit
- -- data constructor and worker (newtypes don't have a wrapper)
- [con_occ, mkDataConWorkerOcc con_occ]
-
-
-ifaceDeclImplicitBndrs (IfaceData {ifName = _tc_occ,
- ifCons = IfDataTyCon cons _ _ })
- = -- for each data constructor in order,
- -- data constructor, worker, and (possibly) wrapper
- concatMap dc_occs cons
- where
- dc_occs con_decl
- | has_wrapper = [con_occ, work_occ, wrap_occ]
- | otherwise = [con_occ, work_occ]
- where
- con_occ = ifConOcc con_decl -- DataCon namespace
- wrap_occ = mkDataConWrapperOcc con_occ -- Id namespace
- work_occ = mkDataConWorkerOcc con_occ -- Id namespace
- has_wrapper = ifConWrapper con_decl -- This is the reason for
- -- having the ifConWrapper field!
-
-ifaceDeclImplicitBndrs (IfaceClass {ifCtxt = sc_ctxt, ifName = cls_tc_occ,
- ifSigs = sigs, ifATs = ats })
+
+ifaceDeclImplicitBndrs (IfaceData {ifName = tc_occ, ifCons = cons })
+ = case cons of
+ IfAbstractTyCon {} -> []
+ IfNewTyCon cd _ _ -> mkNewTyCoOcc tc_occ : ifaceConDeclImplicitBndrs cd
+ IfDataTyCon cds _ _ -> concatMap ifaceConDeclImplicitBndrs cds
+
+ifaceDeclImplicitBndrs (IfaceClass { ifCtxt = sc_ctxt, ifName = cls_tc_occ
+ , ifSigs = sigs, ifATs = ats })
= -- (possibly) newtype coercion
co_occs ++
-- data constructor (DataCon namespace)
@@ -420,6 +398,14 @@ ifaceDeclImplicitBndrs (IfaceClass {ifCtxt = sc_ctxt, ifName = cls_tc_occ,
ifaceDeclImplicitBndrs _ = []
+ifaceConDeclImplicitBndrs :: IfaceConDecl -> [OccName]
+ifaceConDeclImplicitBndrs (IfCon { ifConWrapper = has_wrapper, ifConOcc = con_occ })
+ = [con_occ, work_occ] ++ wrap_occs
+ where
+ work_occ = mkDataConWorkerOcc con_occ -- Id namespace
+ wrap_occs | has_wrapper = [mkDataConWrapperOcc con_occ] -- Id namespace
+ | otherwise = []
+
-- -----------------------------------------------------------------------------
-- The fingerprints of an IfaceDecl
@@ -685,7 +671,6 @@ pprIfaceDecl ss (IfaceData { ifName = tycon, ifCType = ctype,
pp_nd = case condecls of
IfAbstractTyCon d -> ptext (sLit "abstract") <> ppShowIface ss (parens (ppr d))
- IfDataFamTyCon -> ptext (sLit "data family")
IfDataTyCon{} -> ptext (sLit "data")
IfNewTyCon{} -> ptext (sLit "newtype")
@@ -694,6 +679,7 @@ pprIfaceDecl ss (IfaceData { ifName = tycon, ifCType = ctype,
pp_prom | is_prom = ptext (sLit "Promotable")
| otherwise = Outputable.empty
+
pprIfaceDecl ss (IfaceClass { ifATs = ats, ifSigs = sigs, ifRec = isrec
, ifCtxt = context, ifName = clas
, ifTyVars = tyvars, ifRoles = roles
@@ -738,7 +724,12 @@ pprIfaceDecl ss (IfaceSynonym { ifName = tc
pprIfaceDecl ss (IfaceFamily { ifName = tycon, ifTyVars = tyvars
, ifFamFlav = rhs, ifFamKind = kind
, ifResVar = res_var, ifFamInj = inj })
- = vcat [ hang (text "type family" <+> pprIfaceDeclHead [] ss tycon tyvars)
+ | IfaceDataFamilyTyCon <- rhs
+ = ptext (sLit "data family") <+> pprIfaceDeclHead [] ss tycon tyvars
+
+ | otherwise
+ = vcat [ hang (ptext (sLit "type family")
+ <+> pprIfaceDeclHead [] ss tycon tyvars)
2 (pp_inj res_var inj <+> ppShowRhs ss (pp_rhs rhs))
, ppShowRhs ss (nest 2 (pp_branches rhs)) ]
where
@@ -752,11 +743,13 @@ pprIfaceDecl ss (IfaceFamily { ifName = tycon, ifTyVars = tyvars
[] -> empty
tvs -> hsep [text "|", ppr res, text "->", interppSP (map fst tvs)]
+ pp_rhs IfaceDataFamilyTyCon
+ = ppShowIface ss (ptext (sLit "data"))
pp_rhs IfaceOpenSynFamilyTyCon
= ppShowIface ss (ptext (sLit "open"))
pp_rhs IfaceAbstractClosedSynFamilyTyCon
= ppShowIface ss (ptext (sLit "closed, abstract"))
- pp_rhs (IfaceClosedSynFamilyTyCon _)
+ pp_rhs (IfaceClosedSynFamilyTyCon {})
= ptext (sLit "where")
pp_rhs IfaceBuiltInSynFamTyCon
= ppShowIface ss (ptext (sLit "built-in"))
@@ -1170,12 +1163,13 @@ freeNamesIfIdDetails _ = emptyNameSet
-- All other changes are handled via the version info on the tycon
freeNamesIfFamFlav :: IfaceFamTyConFlav -> NameSet
-freeNamesIfFamFlav IfaceOpenSynFamilyTyCon = emptyNameSet
+freeNamesIfFamFlav IfaceOpenSynFamilyTyCon = emptyNameSet
+freeNamesIfFamFlav IfaceDataFamilyTyCon = emptyNameSet
freeNamesIfFamFlav (IfaceClosedSynFamilyTyCon (Just (ax, br)))
= unitNameSet ax &&& fnList freeNamesIfAxBranch br
freeNamesIfFamFlav (IfaceClosedSynFamilyTyCon Nothing) = emptyNameSet
-freeNamesIfFamFlav IfaceAbstractClosedSynFamilyTyCon = emptyNameSet
-freeNamesIfFamFlav IfaceBuiltInSynFamTyCon = emptyNameSet
+freeNamesIfFamFlav IfaceAbstractClosedSynFamilyTyCon = emptyNameSet
+freeNamesIfFamFlav IfaceBuiltInSynFamTyCon = emptyNameSet
freeNamesIfContext :: IfaceContext -> NameSet
freeNamesIfContext = fnList freeNamesIfType
@@ -1526,18 +1520,22 @@ instance Binary IfaceDecl where
_ -> panic (unwords ["Unknown IfaceDecl tag:", show h])
instance Binary IfaceFamTyConFlav where
- put_ bh IfaceOpenSynFamilyTyCon = putByte bh 0
- put_ bh (IfaceClosedSynFamilyTyCon mb) = putByte bh 1 >> put_ bh mb
- put_ bh IfaceAbstractClosedSynFamilyTyCon = putByte bh 2
+ put_ bh IfaceDataFamilyTyCon = putByte bh 0
+ put_ bh IfaceOpenSynFamilyTyCon = putByte bh 1
+ put_ bh (IfaceClosedSynFamilyTyCon mb) = putByte bh 2 >> put_ bh mb
+ put_ bh IfaceAbstractClosedSynFamilyTyCon = putByte bh 3
put_ _ IfaceBuiltInSynFamTyCon
= pprPanic "Cannot serialize IfaceBuiltInSynFamTyCon, used for pretty-printing only" Outputable.empty
get bh = do { h <- getByte bh
; case h of
- 0 -> return IfaceOpenSynFamilyTyCon
- 1 -> do { mb <- get bh
+ 0 -> return IfaceDataFamilyTyCon
+ 1 -> return IfaceOpenSynFamilyTyCon
+ 2 -> do { mb <- get bh
; return (IfaceClosedSynFamilyTyCon mb) }
- _ -> return IfaceAbstractClosedSynFamilyTyCon }
+ 3 -> return IfaceAbstractClosedSynFamilyTyCon
+ _ -> pprPanic "Binary.get(IfaceFamTyConFlav): Invalid tag"
+ (ppr (fromIntegral h :: Int)) }
instance Binary IfaceClassOp where
put_ bh (IfaceClassOp n def ty) = do
@@ -1576,17 +1574,16 @@ instance Binary IfaceAxBranch where
return (IfaceAxBranch a1 a2 a3 a4 a5)
instance Binary IfaceConDecls where
- put_ bh (IfAbstractTyCon d) = putByte bh 0 >> put_ bh d
- put_ bh IfDataFamTyCon = putByte bh 1
- put_ bh (IfDataTyCon cs b fs) = putByte bh 2 >> put_ bh cs >> put_ bh b >> put_ bh fs
- put_ bh (IfNewTyCon c b fs) = putByte bh 3 >> put_ bh c >> put_ bh b >> put_ bh fs
+ put_ bh (IfAbstractTyCon d) = putByte bh 0 >> put_ bh d
+ put_ bh (IfDataTyCon cs b fs) = putByte bh 1 >> put_ bh cs >> put_ bh b >> put_ bh fs
+ put_ bh (IfNewTyCon c b fs) = putByte bh 2 >> put_ bh c >> put_ bh b >> put_ bh fs
get bh = do
h <- getByte bh
case h of
0 -> liftM IfAbstractTyCon $ get bh
- 1 -> return IfDataFamTyCon
- 2 -> liftM3 IfDataTyCon (get bh) (get bh) (get bh)
- _ -> liftM3 IfNewTyCon (get bh) (get bh) (get bh)
+ 1 -> liftM3 IfDataTyCon (get bh) (get bh) (get bh)
+ 2 -> liftM3 IfNewTyCon (get bh) (get bh) (get bh)
+ _ -> error "Binary(IfaceConDecls).get: Invalid IfaceConDecls"
instance Binary IfaceConDecl where
put_ bh (IfCon a1 a2 a3 a4 a5 a6 a7 a8 a9 a10) = do
diff --git a/compiler/iface/MkIface.hs b/compiler/iface/MkIface.hs
index df96f6a4af..b7bdc38ae5 100644
--- a/compiler/iface/MkIface.hs
+++ b/compiler/iface/MkIface.hs
@@ -1611,7 +1611,7 @@ tyConToIfaceDecl env tycon
ifCons = ifaceConDecls (algTyConRhs tycon) (algTcFields tycon),
ifRec = boolToRecFlag (isRecursiveTyCon tycon),
ifGadtSyntax = isGadtSyntaxTyCon tycon,
- ifPromotable = isJust (promotableTyCon_maybe tycon),
+ ifPromotable = isPromotableTyCon tycon,
ifParent = parent })
| otherwise -- FunTyCon, PrimTyCon, promoted TyCon/DataCon
@@ -1649,16 +1649,14 @@ tyConToIfaceDecl env tycon
axn = coAxiomName ax
to_if_fam_flav (ClosedSynFamilyTyCon Nothing)
= IfaceClosedSynFamilyTyCon Nothing
- to_if_fam_flav AbstractClosedSynFamilyTyCon
- = IfaceAbstractClosedSynFamilyTyCon
+ to_if_fam_flav AbstractClosedSynFamilyTyCon = IfaceAbstractClosedSynFamilyTyCon
+ to_if_fam_flav (DataFamilyTyCon {}) = IfaceDataFamilyTyCon
+ to_if_fam_flav (BuiltInSynFamTyCon {}) = IfaceBuiltInSynFamTyCon
- to_if_fam_flav (BuiltInSynFamTyCon {})
- = IfaceBuiltInSynFamTyCon
ifaceConDecls (NewTyCon { data_con = con }) flds = IfNewTyCon (ifaceConDecl con) (ifaceOverloaded flds) (ifaceFields flds)
ifaceConDecls (DataTyCon { data_cons = cons }) flds = IfDataTyCon (map ifaceConDecl cons) (ifaceOverloaded flds) (ifaceFields flds)
- ifaceConDecls (DataFamilyTyCon {}) _ = IfDataFamTyCon
ifaceConDecls (TupleTyCon { data_con = con }) _ = IfDataTyCon [ifaceConDecl con] False []
ifaceConDecls (AbstractTyCon distinct) _ = IfAbstractTyCon distinct
-- The AbstractTyCon case happens when a TyCon has been trimmed
diff --git a/compiler/iface/TcIface.hs b/compiler/iface/TcIface.hs
index 1328b3c002..80de36e82d 100644
--- a/compiler/iface/TcIface.hs
+++ b/compiler/iface/TcIface.hs
@@ -297,13 +297,13 @@ What this means is that the implicitTyThings MUST NOT DEPEND on any of
the forkM stuff.
-}
-tcIfaceDecl :: Bool -- True <=> discard IdInfo on IfaceId bindings
+tcIfaceDecl :: Bool -- ^ True <=> discard IdInfo on IfaceId bindings
-> IfaceDecl
-> IfL TyThing
-tcIfaceDecl = tc_iface_decl NoParentTyCon
+tcIfaceDecl = tc_iface_decl Nothing
-tc_iface_decl :: TyConParent -- For nested declarations
- -> Bool -- True <=> discard IdInfo on IfaceId bindings
+tc_iface_decl :: Maybe Class -- ^ For associated type/data family declarations
+ -> Bool -- ^ True <=> discard IdInfo on IfaceId bindings
-> IfaceDecl
-> IfL TyThing
tc_iface_decl _ ignore_prags (IfaceId {ifName = occ_name, ifType = iface_type,
@@ -314,7 +314,7 @@ tc_iface_decl _ ignore_prags (IfaceId {ifName = occ_name, ifType = iface_type,
; info <- tcIdInfo ignore_prags name ty info
; return (AnId (mkGlobalId details name ty info)) }
-tc_iface_decl parent _ (IfaceData {ifName = occ_name,
+tc_iface_decl _ _ (IfaceData {ifName = occ_name,
ifCType = cType,
ifTyVars = tv_bndrs,
ifRoles = roles,
@@ -326,22 +326,23 @@ tc_iface_decl parent _ (IfaceData {ifName = occ_name,
{ tc_name <- lookupIfaceTop occ_name
; tycon <- fixM $ \ tycon -> do
{ stupid_theta <- tcIfaceCtxt ctxt
- ; parent' <- tc_parent mb_parent
- ; cons <- tcIfaceDataCons tc_name tycon tyvars rdr_cons
+ ; parent' <- tc_parent tc_name mb_parent
+ ; cons <- tcIfaceDataCons tc_name tycon tyvars rdr_cons is_prom
; return (buildAlgTyCon tc_name tyvars roles cType stupid_theta
cons is_rec is_prom gadt_syn parent') }
; traceIf (text "tcIfaceDecl4" <+> ppr tycon)
; return (ATyCon tycon) }
where
- tc_parent :: IfaceTyConParent -> IfL TyConParent
- tc_parent IfNoParent = return parent
- tc_parent (IfDataInstance ax_name _ arg_tys)
- = ASSERT( isNoParent parent )
- do { ax <- tcIfaceCoAxiom ax_name
+ tc_parent :: Name -> IfaceTyConParent -> IfL AlgTyConFlav
+ tc_parent tc_name IfNoParent
+ = do { tc_rep_name <- newTyConRepName tc_name
+ ; return (VanillaAlgTyCon tc_rep_name) }
+ tc_parent _ (IfDataInstance ax_name _ arg_tys)
+ = do { ax <- tcIfaceCoAxiom ax_name
; let fam_tc = coAxiomTyCon ax
ax_unbr = toUnbranchedAxiom ax
; lhs_tys <- tcIfaceTcArgs arg_tys
- ; return (FamInstTyCon ax_unbr fam_tc lhs_tys) }
+ ; return (DataFamInstTyCon ax_unbr fam_tc lhs_tys) }
tc_iface_decl _ _ (IfaceSynonym {ifName = occ_name, ifTyVars = tv_bndrs,
ifRoles = roles,
@@ -365,20 +366,25 @@ tc_iface_decl parent _ (IfaceFamily {ifName = occ_name, ifTyVars = tv_bndrs,
{ tc_name <- lookupIfaceTop occ_name
; rhs_kind <- tcIfaceKind kind -- Note [Synonym kind loop]
; rhs <- forkM (mk_doc tc_name) $
- tc_fam_flav fam_flav
+ tc_fam_flav tc_name fam_flav
; res_name <- traverse (newIfaceName . mkTyVarOccFS) res
; let tycon = buildFamilyTyCon tc_name tyvars res_name rhs rhs_kind
parent inj
; return (ATyCon tycon) }
where
mk_doc n = ptext (sLit "Type synonym") <+> ppr n
- tc_fam_flav IfaceOpenSynFamilyTyCon = return OpenSynFamilyTyCon
- tc_fam_flav (IfaceClosedSynFamilyTyCon mb_ax_name_branches)
+
+ tc_fam_flav :: Name -> IfaceFamTyConFlav -> IfL FamTyConFlav
+ tc_fam_flav tc_name IfaceDataFamilyTyCon
+ = do { tc_rep_name <- newTyConRepName tc_name
+ ; return (DataFamilyTyCon tc_rep_name) }
+ tc_fam_flav _ IfaceOpenSynFamilyTyCon= return OpenSynFamilyTyCon
+ tc_fam_flav _ (IfaceClosedSynFamilyTyCon mb_ax_name_branches)
= do { ax <- traverse (tcIfaceCoAxiom . fst) mb_ax_name_branches
; return (ClosedSynFamilyTyCon ax) }
- tc_fam_flav IfaceAbstractClosedSynFamilyTyCon
+ tc_fam_flav _ IfaceAbstractClosedSynFamilyTyCon
= return AbstractClosedSynFamilyTyCon
- tc_fam_flav IfaceBuiltInSynFamTyCon
+ tc_fam_flav _ IfaceBuiltInSynFamTyCon
= pprPanic "tc_iface_decl"
(text "IfaceBuiltInSynFamTyCon in interface file")
@@ -422,7 +428,7 @@ tc_iface_decl _parent ignore_prags
; return (op_name, dm, op_ty) }
tc_at cls (IfaceAT tc_decl if_def)
- = do ATyCon tc <- tc_iface_decl (AssocFamilyTyCon cls) ignore_prags tc_decl
+ = do ATyCon tc <- tc_iface_decl (Just cls) ignore_prags tc_decl
mb_def <- case if_def of
Nothing -> return Nothing
Just def -> forkM (mk_at_doc tc) $
@@ -506,11 +512,10 @@ tc_ax_branch prev_branches
, cab_incomps = map (prev_branches !!) incomps }
; return (prev_branches ++ [br]) }
-tcIfaceDataCons :: Name -> TyCon -> [TyVar] -> IfaceConDecls -> IfL AlgTyConRhs
-tcIfaceDataCons tycon_name tycon tc_tyvars if_cons
+tcIfaceDataCons :: Name -> TyCon -> [TyVar] -> IfaceConDecls -> Bool -> IfL AlgTyConRhs
+tcIfaceDataCons tycon_name tycon tc_tyvars if_cons is_prom
= case if_cons of
IfAbstractTyCon dis -> return (AbstractTyCon dis)
- IfDataFamTyCon -> return DataFamilyTyCon
IfDataTyCon cons _ _ -> do { field_lbls <- mapM (traverse lookupIfaceTop) (ifaceConDeclFields if_cons)
; data_cons <- mapM (tc_con_decl field_lbls) cons
; return (mkDataTyConRhs data_cons) }
@@ -528,14 +533,14 @@ tcIfaceDataCons tycon_name tycon tc_tyvars if_cons
-- parent TyCon, and are alrady in scope
bindIfaceTyVars ex_tvs $ \ ex_tyvars -> do
{ traceIf (text "Start interface-file tc_con_decl" <+> ppr occ)
- ; name <- lookupIfaceTop occ
+ ; dc_name <- lookupIfaceTop occ
-- Read the context and argument types, but lazily for two reasons
-- (a) to avoid looking tugging on a recursive use of
-- the type itself, which is knot-tied
-- (b) to avoid faulting in the component types unless
-- they are really needed
- ; ~(eq_spec, theta, arg_tys, stricts) <- forkM (mk_doc name) $
+ ; ~(eq_spec, theta, arg_tys, stricts) <- forkM (mk_doc dc_name) $
do { eq_spec <- tcIfaceEqSpec spec
; theta <- tcIfaceCtxt ctxt
; arg_tys <- mapM tcIfaceType args
@@ -555,20 +560,24 @@ tcIfaceDataCons tycon_name tycon tc_tyvars if_cons
; let orig_res_ty = mkFamilyTyConApp tycon
(substTyVars (mkTopTvSubst eq_spec) tc_tyvars)
- ; con <- buildDataCon (pprPanic "tcIfaceDataCons: FamInstEnvs" (ppr name))
- name is_infix
- (map src_strict if_src_stricts)
- (Just stricts)
- -- Pass the HsImplBangs (i.e. final
- -- decisions) to buildDataCon; it'll use
- -- these to guide the construction of a
- -- worker.
- -- See Note [Bangs on imported data constructors] in MkId
- lbl_names
- tc_tyvars ex_tyvars
- eq_spec theta
- arg_tys orig_res_ty tycon
- ; traceIf (text "Done interface-file tc_con_decl" <+> ppr name)
+ ; prom_info <- if is_prom then do { n <- newTyConRepName dc_name
+ ; return (Promoted n) }
+ else return NotPromoted
+
+ ; con <- buildDataCon (pprPanic "tcIfaceDataCons: FamInstEnvs" (ppr dc_name))
+ dc_name is_infix prom_info
+ (map src_strict if_src_stricts)
+ (Just stricts)
+ -- Pass the HsImplBangs (i.e. final
+ -- decisions) to buildDataCon; it'll use
+ -- these to guide the construction of a
+ -- worker.
+ -- See Note [Bangs on imported data constructors] in MkId
+ lbl_names
+ tc_tyvars ex_tyvars
+ eq_spec theta
+ arg_tys orig_res_ty tycon
+ ; traceIf (text "Done interface-file tc_con_decl" <+> ppr dc_name)
; return con }
mk_doc con_name = ptext (sLit "Constructor") <+> ppr con_name
@@ -889,7 +898,7 @@ tcIfaceTupleTy sort info args
-> return (mkTyConApp base_tc args')
IfacePromotedTyCon
- | Just tc <- promotableTyCon_maybe base_tc
+ | Promoted tc <- promotableTyCon_maybe base_tc
-> return (mkTyConApp tc args')
| otherwise
-> panic "tcIfaceTupleTy" (ppr base_tc)
@@ -1366,7 +1375,7 @@ tcIfaceTyCon (IfaceTyCon name info)
-- Same Name as its underlying TyCon
where
promote_tc tc
- | Just prom_tc <- promotableTyCon_maybe tc = prom_tc
+ | Promoted prom_tc <- promotableTyCon_maybe tc = prom_tc
| isSuperKind (tyConKind tc) = tc
| otherwise = pprPanic "tcIfaceTyCon" (ppr name $$ ppr tc)