summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2012-04-22 16:24:07 +0100
committerSimon Peyton Jones <simonpj@microsoft.com>2012-04-22 16:24:07 +0100
commitbf6f7085c62370081d4fe421202ec31c9e51bcb4 (patch)
treeb5c4ef7d8a0a4ba82e36c4a7c50b4505e0fe3c10
parent24746fe78024a1edab843bc710c79c55998ab134 (diff)
downloadhaskell-bf6f7085c62370081d4fe421202ec31c9e51bcb4.tar.gz
Empty data types should not be "trimmed" by TidyPgm
That in turn means that you can derive Show etc in other modules, fixing Trac #6031
-rw-r--r--compiler/main/TidyPgm.lhs26
1 files changed, 17 insertions, 9 deletions
diff --git a/compiler/main/TidyPgm.lhs b/compiler/main/TidyPgm.lhs
index 01de9af4ee..15f68d3dcd 100644
--- a/compiler/main/TidyPgm.lhs
+++ b/compiler/main/TidyPgm.lhs
@@ -504,21 +504,29 @@ mustExposeTyCon no_trim_types exports tc
| isEnumerationTyCon tc -- For an enumeration, exposing the constructors
= True -- won't lead to the need for further exposure
- -- (This includes data types with no constructors.)
| isFamilyTyCon tc -- Open type family
= True
- | otherwise -- Newtype, datatype
- = any exported_con (tyConDataCons tc)
- -- Expose rep if any datacon or field is exported
+ -- Below here we just have data/newtype decls or family instances
- || (isNewTyCon tc && isFFITy (snd (newTyConRhs tc)))
- -- Expose the rep for newtypes if the rep is an FFI type.
- -- For a very annoying reason. 'Foreign import' is meant to
- -- be able to look through newtypes transparently, but it
- -- can only do that if it can "see" the newtype representation
+ | null data_cons -- Ditto if there are no data constructors
+ = True -- (NB: empty data types do not count as enumerations
+ -- see Note [Enumeration types] in TyCon
+
+ | any exported_con data_cons -- Expose rep if any datacon or field is exported
+ = True
+
+ | isNewTyCon tc && isFFITy (snd (newTyConRhs tc))
+ = True -- Expose the rep for newtypes if the rep is an FFI type.
+ -- For a very annoying reason. 'Foreign import' is meant to
+ -- be able to look through newtypes transparently, but it
+ -- can only do that if it can "see" the newtype representation
+
+ | otherwise
+ = False
where
+ data_cons = tyConDataCons tc
exported_con con = any (`elemNameSet` exports)
(dataConName con : dataConFieldLabels con)