[commit: ghc] ghc-spj: Empty data types should not be "trimmed" by TidyPgm (bf6f708)

Simon Peyton Jones simonpj at microsoft.com
Mon Apr 23 09:47:51 CEST 2012


Repository : ssh://darcs.haskell.org//srv/darcs/ghc

On branch  : ghc-spj

http://hackage.haskell.org/trac/ghc/changeset/bf6f7085c62370081d4fe421202ec31c9e51bcb4

>---------------------------------------------------------------

commit bf6f7085c62370081d4fe421202ec31c9e51bcb4
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Sun Apr 22 16:24:07 2012 +0100

    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

>---------------------------------------------------------------

 compiler/main/TidyPgm.lhs |   26 +++++++++++++++++---------
 1 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/compiler/main/TidyPgm.lhs b/compiler/main/TidyPgm.lhs
index 01de9af..15f68d3 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)
 





More information about the Cvs-ghc mailing list