From: simonpj@microsoft.com Date: Tue, 14 Sep 2010 11:38:50 +0000 (+0000) Subject: Comment on what an "enumeration" type is X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=13adf25f23091c8ef1a14cfb11ed9379ffbaed90 Comment on what an "enumeration" type is --- diff --git a/compiler/iface/BuildTyCl.lhs b/compiler/iface/BuildTyCl.lhs index de57feb..4319d1f 100644 --- a/compiler/iface/BuildTyCl.lhs +++ b/compiler/iface/BuildTyCl.lhs @@ -112,15 +112,9 @@ mkDataTyConRhs :: [DataCon] -> AlgTyConRhs mkDataTyConRhs cons = DataTyCon { data_cons = cons, - is_enum = -- We define datatypes with no constructors to not be - -- enumerations; this fixes trac #2578, Otherwise we - -- end up generating an empty table for - -- __closure_tbl - -- which is used by tagToEnum# to map Int# to constructors - -- in an enumeration. The empty table apparently upset - -- the linker. - not (null cons) && + is_enum = not (null cons) && all isNullarySrcDataCon cons + -- See Note [Enumeration types] in TyCon } mkNewTyConRhs :: Name -> TyCon -> DataCon -> TcRnIf m n AlgTyConRhs diff --git a/compiler/types/TyCon.lhs b/compiler/types/TyCon.lhs index e7f8507..2350973 100644 --- a/compiler/types/TyCon.lhs +++ b/compiler/types/TyCon.lhs @@ -440,7 +440,7 @@ data AlgTyConRhs -- (see the tag assignment in DataCon.mkDataCon) is_enum :: Bool -- ^ Cached value: is this an enumeration type? - -- (See 'isEnumerationTyCon') + -- See Note [Enumeration types] } -- | Information about those 'TyCon's derived from a @newtype@ declaration @@ -580,6 +580,16 @@ data CoTyConDesc | CoUnsafe \end{code} +Note [Enumeration types] +~~~~~~~~~~~~~~~~~~~~~~~~ +We define datatypes with no constructors to not be +enumerations; this fixes trac #2578, Otherwise we +end up generating an empty table for + __closure_tbl +which is used by tagToEnum# to map Int# to constructors +in an enumeration. The empty table apparently upset +the linker. + Note [Newtype coercions] ~~~~~~~~~~~~~~~~~~~~~~~~ The NewTyCon field nt_co is a a TyCon (a coercion constructor in fact) @@ -983,6 +993,7 @@ isGadtSyntaxTyCon _ = False -- | Is this an algebraic 'TyCon' which is just an enumeration of values? isEnumerationTyCon :: TyCon -> Bool +-- See Note [Enumeration types] in TyCon isEnumerationTyCon (AlgTyCon {algTcRhs = DataTyCon { is_enum = res }}) = res isEnumerationTyCon (TupleTyCon {tyConArity = arity}) = arity == 0 isEnumerationTyCon _ = False