Newtype data constructors get a compulsory unfolding
authorsimonpj@microsoft.com <unknown>
Wed, 17 May 2006 15:50:09 +0000 (15:50 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 17 May 2006 15:50:09 +0000 (15:50 +0000)
With this change, newtype data constructors get a "compulsory" unfolding,
which means that they *must* be inlined, and no top-level definition of
the constructor is provided at all.  Since these constructors are no-ops,
I'm not sure why this wasn't the case all along.

compiler/basicTypes/DataCon.lhs
compiler/basicTypes/MkId.lhs

index 805ef73..8b1ed9e 100644 (file)
@@ -452,9 +452,11 @@ dataConWorkId dc = case dcIds dc of
                        NewDC _ -> pprPanic "dataConWorkId" (ppr dc)
 
 dataConWrapId_maybe :: DataCon -> Maybe Id
+-- Returns Nothing if there is no wrapper for an algebraic data con
+--                and also for a newtype (whose constructor is inlined compulsorily)
 dataConWrapId_maybe dc = case dcIds dc of
                                AlgDC mb_wrap _ -> mb_wrap
-                               NewDC wrap      -> Just wrap
+                               NewDC wrap      -> Nothing
 
 dataConWrapId :: DataCon -> Id
 -- Returns an Id which looks like the Haskell-source constructor
index 09540cc..0c84685 100644 (file)
@@ -252,7 +252,7 @@ mkDataConIds wrap_name wkr_name data_con
                           isSingleton orig_arg_tys )
                   -- No existentials on a newtype, but it can have a context
                   -- e.g.      newtype Eq a => T a = MkT (...)
-                  mkTopUnfolding $ Note InlineMe $
+                  mkCompulsoryUnfolding $ 
                   mkLams tyvars $ Lam id_arg1 $ 
                   mkNewTypeBody tycon result_ty (Var id_arg1)