diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 3cd72bf04eb5f1751987147bd446ccc3436a7e12..5425b894031593b3c3255ce5c61e5ce471a69c65 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 0000000000000000000000000000000000000000..873e1afc0fb3b9ee87f961ea5d725e960ec88ef1 --- /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 2ea15f6f606d8eba979e0209bc63ee49c87356ff..803e34493efacb9ff7dd1b5379389d99924dd303 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'])