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/prelude/TysWiredIn.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/prelude/TysWiredIn.hs')
-rw-r--r-- | compiler/prelude/TysWiredIn.hs | 49 |
1 files changed, 24 insertions, 25 deletions
diff --git a/compiler/prelude/TysWiredIn.hs b/compiler/prelude/TysWiredIn.hs index 228c4d1103..51f5555dd3 100644 --- a/compiler/prelude/TysWiredIn.hs +++ b/compiler/prelude/TysWiredIn.hs @@ -136,7 +136,7 @@ import Class ( Class, mkClass ) import RdrName import Name import NameSet ( NameSet, mkNameSet, elemNameSet ) -import BasicTypes ( Arity, RecFlag(..), Boxity(..), +import BasicTypes ( Arity, Boxity(..), TupleSort(..) ) import ForeignCall import SrcLoc ( noSrcSpan ) @@ -446,14 +446,14 @@ parrTyCon_RDR = nameRdrName parrTyConName ************************************************************************ -} -pcNonRecDataTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon +pcNonEnumTyCon :: Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon -- Not an enumeration -pcNonRecDataTyCon = pcTyCon False NonRecursive +pcNonEnumTyCon = pcTyCon False -- This function assumes that the types it creates have all parameters at -- Representational role, and that there is no kind polymorphism. -pcTyCon :: Bool -> RecFlag -> Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon -pcTyCon is_enum is_rec name cType tyvars cons +pcTyCon :: Bool -> Name -> Maybe CType -> [TyVar] -> [DataCon] -> TyCon +pcTyCon is_enum name cType tyvars cons = mkAlgTyCon name (mkAnonTyConBinders tyvars) liftedTypeKind @@ -462,7 +462,6 @@ pcTyCon is_enum is_rec name cType tyvars cons [] -- No stupid theta (DataTyCon cons is_enum) (VanillaAlgTyCon (mkPrelTyConRepName name)) - is_rec False -- Not in GADT syntax pcDataCon :: Name -> [TyVar] -> [Type] -> TyCon -> DataCon @@ -535,15 +534,15 @@ pcSpecialDataCon dc_name arg_tys tycon rri typeNatKindCon, typeSymbolKindCon :: TyCon -- data Nat -- data Symbol -typeNatKindCon = pcTyCon False NonRecursive typeNatKindConName Nothing [] [] -typeSymbolKindCon = pcTyCon False NonRecursive typeSymbolKindConName Nothing [] [] +typeNatKindCon = pcTyCon False typeNatKindConName Nothing [] [] +typeSymbolKindCon = pcTyCon False typeSymbolKindConName Nothing [] [] typeNatKind, typeSymbolKind :: Kind typeNatKind = mkTyConTy typeNatKindCon typeSymbolKind = mkTyConTy typeSymbolKindCon constraintKindTyCon :: TyCon -constraintKindTyCon = pcTyCon False NonRecursive constraintKindTyConName +constraintKindTyCon = pcTyCon False constraintKindTyConName Nothing [] [] liftedTypeKind, constraintKind, unboxedTupleKind :: Kind @@ -826,7 +825,7 @@ heqSCSelId, coercibleSCSelId :: Id = (tycon, klass, datacon, sc_sel_id) where tycon = mkClassTyCon heqTyConName binders roles - rhs klass NonRecursive + rhs klass (mkPrelTyConRepName heqTyConName) klass = mk_class tycon sc_pred sc_sel_id datacon = pcDataCon heqDataConName tvs [sc_pred] tycon @@ -844,7 +843,7 @@ heqSCSelId, coercibleSCSelId :: Id = (tycon, klass, datacon, sc_sel_id) where tycon = mkClassTyCon coercibleTyConName binders roles - rhs klass NonRecursive + rhs klass (mkPrelTyConRepName coercibleTyConName) klass = mk_class tycon sc_pred sc_sel_id datacon = pcDataCon coercibleDataConName tvs [sc_pred] tycon @@ -890,7 +889,7 @@ unicodeStarKindTyCon = mkSynonymTyCon unicodeStarKindTyConName (tYPE ptrRepLiftedTy) runtimeRepTyCon :: TyCon -runtimeRepTyCon = pcNonRecDataTyCon runtimeRepTyConName Nothing [] +runtimeRepTyCon = pcNonEnumTyCon runtimeRepTyConName Nothing [] (vecRepDataCon : runtimeRepSimpleDataCons) vecRepDataCon :: DataCon @@ -935,7 +934,7 @@ voidRepDataConTy, intRepDataConTy, wordRepDataConTy, int64RepDataConTy, runtimeRepSimpleDataCons vecCountTyCon :: TyCon -vecCountTyCon = pcNonRecDataTyCon vecCountTyConName Nothing [] +vecCountTyCon = pcNonEnumTyCon vecCountTyConName Nothing [] vecCountDataCons -- See Note [Wiring in RuntimeRep] @@ -954,7 +953,7 @@ vec2DataConTy, vec4DataConTy, vec8DataConTy, vec16DataConTy, vec32DataConTy, vec64DataConTy] = map (mkTyConTy . promoteDataCon) vecCountDataCons vecElemTyCon :: TyCon -vecElemTyCon = pcNonRecDataTyCon vecElemTyConName Nothing [] vecElemDataCons +vecElemTyCon = pcNonEnumTyCon vecElemTyConName Nothing [] vecElemDataCons -- See Note [Wiring in RuntimeRep] vecElemDataCons :: [DataCon] @@ -992,7 +991,7 @@ charTy :: Type charTy = mkTyConTy charTyCon charTyCon :: TyCon -charTyCon = pcNonRecDataTyCon charTyConName +charTyCon = pcNonEnumTyCon charTyConName (Just (CType "" Nothing ("HsChar",fsLit "HsChar"))) [] [charDataCon] charDataCon :: DataCon @@ -1005,7 +1004,7 @@ intTy :: Type intTy = mkTyConTy intTyCon intTyCon :: TyCon -intTyCon = pcNonRecDataTyCon intTyConName +intTyCon = pcNonEnumTyCon intTyConName (Just (CType "" Nothing ("HsInt",fsLit "HsInt"))) [] [intDataCon] intDataCon :: DataCon @@ -1015,7 +1014,7 @@ wordTy :: Type wordTy = mkTyConTy wordTyCon wordTyCon :: TyCon -wordTyCon = pcNonRecDataTyCon wordTyConName +wordTyCon = pcNonEnumTyCon wordTyConName (Just (CType "" Nothing ("HsWord", fsLit "HsWord"))) [] [wordDataCon] wordDataCon :: DataCon @@ -1025,7 +1024,7 @@ word8Ty :: Type word8Ty = mkTyConTy word8TyCon word8TyCon :: TyCon -word8TyCon = pcNonRecDataTyCon word8TyConName +word8TyCon = pcNonEnumTyCon word8TyConName (Just (CType "" Nothing ("HsWord8", fsLit "HsWord8"))) [] [word8DataCon] word8DataCon :: DataCon @@ -1035,7 +1034,7 @@ floatTy :: Type floatTy = mkTyConTy floatTyCon floatTyCon :: TyCon -floatTyCon = pcNonRecDataTyCon floatTyConName +floatTyCon = pcNonEnumTyCon floatTyConName (Just (CType "" Nothing ("HsFloat", fsLit "HsFloat"))) [] [floatDataCon] floatDataCon :: DataCon @@ -1045,7 +1044,7 @@ doubleTy :: Type doubleTy = mkTyConTy doubleTyCon doubleTyCon :: TyCon -doubleTyCon = pcNonRecDataTyCon doubleTyConName +doubleTyCon = pcNonEnumTyCon doubleTyConName (Just (CType "" Nothing ("HsDouble",fsLit "HsDouble"))) [] [doubleDataCon] @@ -1106,7 +1105,7 @@ boolTy :: Type boolTy = mkTyConTy boolTyCon boolTyCon :: TyCon -boolTyCon = pcTyCon True NonRecursive boolTyConName +boolTyCon = pcTyCon True boolTyConName (Just (CType "" Nothing ("HsBool", fsLit "HsBool"))) [] [falseDataCon, trueDataCon] @@ -1119,7 +1118,7 @@ falseDataConId = dataConWorkId falseDataCon trueDataConId = dataConWorkId trueDataCon orderingTyCon :: TyCon -orderingTyCon = pcTyCon True NonRecursive orderingTyConName Nothing +orderingTyCon = pcTyCon True orderingTyConName Nothing [] [ltDataCon, eqDataCon, gtDataCon] ltDataCon, eqDataCon, gtDataCon :: DataCon @@ -1151,7 +1150,7 @@ listTyCon :: TyCon listTyCon = buildAlgTyCon listTyConName alpha_tyvar [Representational] Nothing [] (DataTyCon [nilDataCon, consDataCon] False ) - Recursive False + False (VanillaAlgTyCon $ mkPrelTyConRepName listTyConName) nilDataCon :: DataCon @@ -1168,7 +1167,7 @@ consDataCon = pcDataConWithFixity True {- Declared infix -} -- Wired-in type Maybe maybeTyCon :: TyCon -maybeTyCon = pcTyCon False NonRecursive maybeTyConName Nothing alpha_tyvar +maybeTyCon = pcTyCon False maybeTyConName Nothing alpha_tyvar [nothingDataCon, justDataCon] nothingDataCon :: DataCon @@ -1264,7 +1263,7 @@ mkPArrTy ty = mkTyConApp parrTyCon [ty] -- @PrelPArr@. -- parrTyCon :: TyCon -parrTyCon = pcNonRecDataTyCon parrTyConName Nothing alpha_tyvar [parrDataCon] +parrTyCon = pcNonEnumTyCon parrTyConName Nothing alpha_tyvar [parrDataCon] parrDataCon :: DataCon parrDataCon = pcDataCon |