From 307ea550bfa8fb9146f07c0dc103e53a31f4436c Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Wed, 17 May 2006 15:50:09 +0000 Subject: [PATCH] Newtype data constructors get a compulsory unfolding 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 | 4 +++- compiler/basicTypes/MkId.lhs | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/compiler/basicTypes/DataCon.lhs b/compiler/basicTypes/DataCon.lhs index 805ef73..8b1ed9e 100644 --- a/compiler/basicTypes/DataCon.lhs +++ b/compiler/basicTypes/DataCon.lhs @@ -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 diff --git a/compiler/basicTypes/MkId.lhs b/compiler/basicTypes/MkId.lhs index 09540cc..0c84685 100644 --- a/compiler/basicTypes/MkId.lhs +++ b/compiler/basicTypes/MkId.lhs @@ -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) -- 1.7.10.4