[commit: ghc] master: Always do eta-reduction (8500855)

git at git.haskell.org git at git.haskell.org
Thu Feb 11 10:38:46 UTC 2016


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/850085555a1103810d57f0d9835f4d525fd8ec00/ghc

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

commit 850085555a1103810d57f0d9835f4d525fd8ec00
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Feb 11 10:38:33 2016 +0000

    Always do eta-reduction
    
    See Note [Eta-reduction in -O0] in DynFlags.
    
    Bottom line: doing eta reduction unconditionally is benign, and
    removes an ASSERT failure (Trac #11562).


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

850085555a1103810d57f0d9835f4d525fd8ec00
 compiler/main/DynFlags.hs                          | 17 ++++++++++-
 testsuite/tests/simplCore/should_compile/T11562.hs | 35 ++++++++++++++++++++++
 testsuite/tests/simplCore/should_compile/all.T     |  1 +
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs
index 3cd72bf..5425b89 100644
--- a/compiler/main/DynFlags.hs
+++ b/compiler/main/DynFlags.hs
@@ -3457,6 +3457,7 @@ impliedXFlags
 optLevelFlags :: [([Int], GeneralFlag)]
 optLevelFlags -- see Note [Documenting optimisation flags]
   = [ ([0,1,2], Opt_DoLambdaEtaExpansion)
+    , ([0,1,2], Opt_DoEtaReduction)       -- See Note [Eta-reduction in -O0]
     , ([0,1,2], Opt_DmdTxDictSel)
     , ([0,1,2], Opt_LlvmTBAA)
     , ([0,1,2], Opt_VectorisationAvoidance)
@@ -3473,7 +3474,6 @@ optLevelFlags -- see Note [Documenting optimisation flags]
     , ([1,2],   Opt_CmmElimCommonBlocks)
     , ([1,2],   Opt_CmmSink)
     , ([1,2],   Opt_CSE)
-    , ([1,2],   Opt_DoEtaReduction)
     , ([1,2],   Opt_EnableRewriteRules)  -- Off for -O0; see Note [Scoping for Builtin rules]
                                          --              in PrelRules
     , ([1,2],   Opt_FloatIn)
@@ -3495,6 +3495,21 @@ optLevelFlags -- see Note [Documenting optimisation flags]
 --   Static Argument Transformation needs investigation. See #9374
     ]
 
+{- Note [Eta-reduction in -O0]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Trac #11562 showed an example which tripped an ASSERT in CoreToStg; a
+function was marked as MayHaveCafRefs when in fact it obviously
+didn't.  Reason was:
+ * Eta reduction wasn't happening in the simplifier, but it was
+   happening in CorePrep, on
+        $fBla = MkDict (/\a. K a)
+ * Result: rhsIsStatic told TidyPgm that $fBla might have CAF refs
+   but the eta-reduced version (MkDict K) obviously doesn't
+Simple solution: just let the simplifier do eta-reduction even in -O0.
+After all, CorePrep does it unconditionally!  Not a big deal, but
+removes an assertion failure. -}
+
+
 -- -----------------------------------------------------------------------------
 -- Standard sets of warning options
 
diff --git a/testsuite/tests/simplCore/should_compile/T11562.hs b/testsuite/tests/simplCore/should_compile/T11562.hs
new file mode 100644
index 0000000..873e1af
--- /dev/null
+++ b/testsuite/tests/simplCore/should_compile/T11562.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE ConstraintKinds #-}
+{-# LANGUAGE Rank2Types #-}
+{-# LANGUAGE PolyKinds #-}
+{-# LANGUAGE GADTs #-}
+{-# LANGUAGE NoImplicitPrelude #-}
+
+-- Trac #11562 reported an ASSERT error
+-- It only showed up /without/ -O, and obviously
+-- with a compiler built with -DDEBUG
+
+module T11562 where
+import qualified GHC.Types as C (Constraint)
+
+class Category (cat :: k -> k -> *) where
+  id :: cat a a
+  (.) :: cat b c -> cat a b -> cat a c
+
+data Dict :: C.Constraint -> * where
+  Dict :: a => Dict a
+
+newtype C2D a b = Sub (a => Dict b)
+
+instance Category C2D where
+  id  = Sub Dict
+  f . g = Sub (sub (sub Dict f) g)
+
+sub :: a => (b => r) -> (C2D a b) -> r
+sub r (Sub Dict) = r
+
+{-
+$ inplace/bin/ghc-stage2 -fforce-recomp -c C.hs -O0
+
+WARNING: file compiler/stgSyn/CoreToStg.hs, line 250
+  $fCategoryConstraint:- True False
+-}
diff --git a/testsuite/tests/simplCore/should_compile/all.T b/testsuite/tests/simplCore/should_compile/all.T
index 2ea15f6..803e344 100644
--- a/testsuite/tests/simplCore/should_compile/all.T
+++ b/testsuite/tests/simplCore/should_compile/all.T
@@ -229,3 +229,4 @@ test('T11155',
      run_command,
      ['$MAKE -s --no-print-directory T11155'])
 test('T11232', normal, compile, ['-O2'])
+test('T11562', normal, compile, ['-O2'])



More information about the ghc-commits mailing list