Commit 85008555 authored by Simon Peyton Jones's avatar Simon Peyton Jones

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).
parent d27da536
......@@ -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
......
{-# 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
-}
......@@ -229,3 +229,4 @@ test('T11155',
run_command,
['$MAKE -s --no-print-directory T11155'])
test('T11232', normal, compile, ['-O2'])
test('T11562', normal, compile, ['-O2'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment