diff options
author | Edward Z. Yang <ezyang@cs.stanford.edu> | 2016-06-24 11:03:47 -0700 |
---|---|---|
committer | Edward Z. Yang <ezyang@cs.stanford.edu> | 2016-06-30 10:43:28 -0700 |
commit | b8b3e30a6eedf9f213b8a718573c4827cfa230ba (patch) | |
tree | cc8f8394fbf92afa12a5aa0bcc0e664d4f841efb /compiler/iface/IfaceSyn.hs | |
parent | 480e0661fb45395610d6b4a7c586a580d30d8df4 (diff) | |
download | haskell-b8b3e30a6eedf9f213b8a718573c4827cfa230ba.tar.gz |
Axe RecFlag on TyCons.
Summary:
This commit removes the information about whether or not
a TyCon is "recursive", as well as the code responsible
for calculating this information.
The original trigger for this change was complexity regarding
how we computed the RecFlag for hs-boot files. The problem
is that in order to determine if a TyCon is recursive or
not, we need to determine if it was defined in an hs-boot
file (if so, we conservatively assume that it is recursive.)
It turns that doing this is quite tricky. The "obvious"
strategy is to typecheck the hi-boot file (since we are
eventually going to need the typechecked types to check
if we properly implemented the hi-boot file) and just extract
the names of all defined TyCons from the ModDetails, but
this actually does not work well if Names from the hi-boot
file are being knot-tied via if_rec_types: the "extraction"
process will force thunks, which will force the typechecking
process earlier than we have actually defined the types
locally.
Rather than work around all this trickiness (it certainly
can be worked around, either by making interface loading
MORE lazy, or just reading of the set of defined TyCons
directly from the ModIface), we instead opted to excise
the source of the problem, the RecFlag.
For one, it is not clear if the RecFlag even makes sense,
in the presence of higher-orderness:
data T f a = MkT (f a)
T doesn't look recursive, but if we instantiate f with T,
then it very well is! It was all very shaky.
So we just don't bother anymore. This has two user-visible
implications:
1. is_too_recursive now assumes that all TyCons are
recursive and will bail out in a way that is still mysterious
to me if there are too many TyCons.
2. checkRecTc, which is used when stripping newtypes to
get to representation, also assumes all TyCons are
recursive, and will stop running if we hit the limit.
The biggest risk for this patch is that we specialize less
than we used to; however, the codeGen tests still seem to
be passing.
Signed-off-by: Edward Z. Yang <ezyang@cs.stanford.edu>
Reviewers: simonpj, austin, bgamari
Subscribers: goldfire, thomie
Differential Revision: https://phabricator.haskell.org/D2360
Diffstat (limited to 'compiler/iface/IfaceSyn.hs')
-rw-r--r-- | compiler/iface/IfaceSyn.hs | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/compiler/iface/IfaceSyn.hs b/compiler/iface/IfaceSyn.hs index 283da53e87..689452f859 100644 --- a/compiler/iface/IfaceSyn.hs +++ b/compiler/iface/IfaceSyn.hs @@ -101,7 +101,6 @@ data IfaceDecl ifRoles :: [Role], -- Roles ifCtxt :: IfaceContext, -- The "stupid theta" ifCons :: IfaceConDecls, -- Includes new/data/data family info - ifRec :: RecFlag, -- Recursive or not? ifGadtSyntax :: Bool, -- True <=> declared using -- GADT syntax ifParent :: IfaceTyConParent -- The axiom, for a newtype, @@ -130,9 +129,7 @@ data IfaceDecl ifFDs :: [FunDep FastString], -- Functional dependencies ifATs :: [IfaceAT], -- Associated type families ifSigs :: [IfaceClassOp], -- Method signatures - ifMinDef :: BooleanFormula IfLclName, -- Minimal complete definition - ifRec :: RecFlag -- Is newtype/datatype associated - -- with the class recursive? + ifMinDef :: BooleanFormula IfLclName -- Minimal complete definition } | IfaceAxiom { ifName :: IfaceTopBndr, -- Axiom name @@ -625,7 +622,7 @@ pprIfaceDecl :: ShowSub -> IfaceDecl -> SDoc pprIfaceDecl ss (IfaceData { ifName = tycon, ifCType = ctype, ifCtxt = context, ifRoles = roles, ifCons = condecls, - ifParent = parent, ifRec = isrec, + ifParent = parent, ifGadtSyntax = gadt, ifBinders = binders }) @@ -671,10 +668,10 @@ pprIfaceDecl ss (IfaceData { ifName = tycon, ifCType = ctype, IfDataTyCon{} -> text "data" IfNewTyCon{} -> text "newtype" - pp_extra = vcat [pprCType ctype, pprRec isrec] + pp_extra = vcat [pprCType ctype] -pprIfaceDecl ss (IfaceClass { ifATs = ats, ifSigs = sigs, ifRec = isrec +pprIfaceDecl ss (IfaceClass { ifATs = ats, ifSigs = sigs , ifCtxt = context, ifName = clas , ifRoles = roles , ifFDs = fds, ifMinDef = minDef @@ -682,14 +679,13 @@ pprIfaceDecl ss (IfaceClass { ifATs = ats, ifSigs = sigs, ifRec = isrec = vcat [ pprRoles (== Nominal) (pprPrefixIfDeclBndr ss clas) binders roles , text "class" <+> pprIfaceDeclHead context ss clas binders Nothing <+> pprFundeps fds <+> pp_where - , nest 2 (vcat [ vcat asocs, vcat dsigs, pprec + , nest 2 (vcat [ vcat asocs, vcat dsigs , ppShowAllSubs ss (pprMinDef minDef)])] where pp_where = ppShowRhs ss $ ppUnless (null sigs && null ats) (text "where") asocs = ppr_trim $ map maybeShowAssoc ats dsigs = ppr_trim $ map maybeShowSig sigs - pprec = ppShowIface ss (pprRec isrec) maybeShowAssoc :: IfaceAT -> Maybe SDoc maybeShowAssoc asc@(IfaceAT d _) @@ -805,10 +801,6 @@ pprRoles suppress_if tyCon bndrs roles in ppUnless (all suppress_if roles || null froles) $ text "type role" <+> tyCon <+> hsep (map ppr froles) -pprRec :: RecFlag -> SDoc -pprRec NonRecursive = Outputable.empty -pprRec Recursive = text "RecFlag: Recursive" - pprInfixIfDeclBndr, pprPrefixIfDeclBndr :: ShowSub -> OccName -> SDoc pprInfixIfDeclBndr (ShowSub { ss_ppr_bndr = ppr_bndr }) occ = pprInfixVar (isSymOcc occ) (ppr_bndr occ) @@ -1453,7 +1445,7 @@ instance Binary IfaceDecl where put_ bh details put_ bh idinfo - put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8 a9 a10) = do + put_ bh (IfaceData a1 a2 a3 a4 a5 a6 a7 a8 a9) = do putByte bh 2 put_ bh (occNameFS a1) put_ bh a2 @@ -1464,7 +1456,6 @@ instance Binary IfaceDecl where put_ bh a7 put_ bh a8 put_ bh a9 - put_ bh a10 put_ bh (IfaceSynonym a1 a2 a3 a4 a5) = do putByte bh 3 @@ -1483,7 +1474,7 @@ instance Binary IfaceDecl where put_ bh a5 put_ bh a6 - put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7 a8 a9) = do + put_ bh (IfaceClass a1 a2 a3 a4 a5 a6 a7 a8) = do putByte bh 5 put_ bh a1 put_ bh (occNameFS a2) @@ -1493,7 +1484,6 @@ instance Binary IfaceDecl where put_ bh a6 put_ bh a7 put_ bh a8 - put_ bh a9 put_ bh (IfaceAxiom a1 a2 a3 a4) = do putByte bh 6 @@ -1535,9 +1525,8 @@ instance Binary IfaceDecl where a7 <- get bh a8 <- get bh a9 <- get bh - a10 <- get bh occ <- return $! mkTcOccFS a1 - return (IfaceData occ a2 a3 a4 a5 a6 a7 a8 a9 a10) + return (IfaceData occ a2 a3 a4 a5 a6 a7 a8 a9) 3 -> do a1 <- get bh a2 <- get bh a3 <- get bh @@ -1561,9 +1550,8 @@ instance Binary IfaceDecl where a6 <- get bh a7 <- get bh a8 <- get bh - a9 <- get bh occ <- return $! mkClsOccFS a2 - return (IfaceClass a1 occ a3 a4 a5 a6 a7 a8 a9) + return (IfaceClass a1 occ a3 a4 a5 a6 a7 a8) 6 -> do a1 <- get bh a2 <- get bh a3 <- get bh |