[commit: ghc] wip/T9732: Apply compulsory unfoldings during desugaring. See Note [Unfolding while desugaring] for the rationale. (7ca6589)

git at git.haskell.org git at git.haskell.org
Wed Nov 12 11:07:01 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/T9732
Link       : http://ghc.haskell.org/trac/ghc/changeset/7ca65890bf532b268f6e26212c6909d42d55af81/ghc

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

commit 7ca65890bf532b268f6e26212c6909d42d55af81
Author: Dr. ERDI Gergo <gergo at erdi.hu>
Date:   Wed Nov 12 18:18:09 2014 +0800

    Apply compulsory unfoldings during desugaring.
    See Note [Unfolding while desugaring] for the rationale.


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

7ca65890bf532b268f6e26212c6909d42d55af81
 compiler/deSugar/DsExpr.lhs | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/compiler/deSugar/DsExpr.lhs b/compiler/deSugar/DsExpr.lhs
index 6844f48..10d20d3 100644
--- a/compiler/deSugar/DsExpr.lhs
+++ b/compiler/deSugar/DsExpr.lhs
@@ -191,7 +191,11 @@ dsLExpr (L loc e) = putSrcSpanDs loc $ dsExpr e
 dsExpr :: HsExpr Id -> DsM CoreExpr
 dsExpr (HsPar e)              = dsLExpr e
 dsExpr (ExprWithTySigOut e _) = dsLExpr e
-dsExpr (HsVar var)            = return (varToCoreExpr var)   -- See Note [Desugaring vars]
+dsExpr (HsVar var)            -- See Note [Unfolding while desugaring]
+  | isCompulsoryUnfolding unfolding = return $ unfoldingTemplate unfolding
+  | otherwise = return (varToCoreExpr var)   -- See Note [Desugaring vars]
+  where
+    unfolding = idUnfolding var
 dsExpr (HsIPVar _)            = panic "dsExpr: HsIPVar"
 dsExpr (HsLit lit)            = dsLit lit
 dsExpr (HsOverLit lit)        = dsOverLit lit
@@ -220,6 +224,19 @@ dsExpr (HsApp fun arg)
 dsExpr (HsUnboundVar _) = panic "dsExpr: HsUnboundVar"
 \end{code}
 
+Note [Unfolding while desugaring]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Variables with compulsory unfolding must be substituted at desugaring
+time. This is needed to preserve the let/app invariant in cases where
+the unfolding changes whether wrapping in a case is needed.
+Suppose we have a call like this:
+    I# x
+where 'x' has an unfolding like this:
+    f void#
+In this case, 'mkCoreAppDs' needs to see 'f void#', not 'x', to be
+able to do the right thing.
+
+
 Note [Desugaring vars]
 ~~~~~~~~~~~~~~~~~~~~~~
 In one situation we can get a *coercion* variable in a HsVar, namely



More information about the ghc-commits mailing list