Commit 5eeefe4c authored by Simon Peyton Jones's avatar Simon Peyton Jones Committed by Marge Bot
Browse files

Improve the very simple optimiser slightly

There was a missing case in the very simple optimiser,
CoreOpt.simpleOptExpr, which led to Trac #13208 comment:2.

In particular, in simple_app, if we find a Let, we should
just float it outwards. Otherwise we leave behind some
easy-to-reduce beta-redexes.
parent e86606f2
......@@ -308,6 +308,16 @@ simple_app env (Tick t e) as
| t `tickishScopesLike` SoftScope
= mkTick t $ simple_app env e as
-- (let x = e in b) a1 .. an => let x = e in (b a1 .. an)
-- The let might appear there as a result of inlining
-- e.g. let f = let x = e in b
-- in f a1 a2
-- (Trac #13208)
simple_app env (Let bind body) as
= case simple_opt_bind env bind of
(env', Nothing) -> simple_app env' body as
(env', Just bind) -> Let bind (simple_app env' body as)
simple_app env e as
= finish_app env (simple_opt_expr env e) as
......@@ -2,6 +2,12 @@ TOP=../../..
include $(TOP)/mk/
include $(TOP)/mk/
# Should show that function f has been optimised by
# the simple CoreOpt optimiser run by the desugarer
$(RM) -f T13028.hi T13208.o
'$(TEST_HC)' $(TEST_HC_OPTS) -c T13208.hs -ddump-ds -dsuppress-uniques | grep True
$(RM) -f T5252.hi T5252.o
$(RM) -f T5252a.hi T5252a.o
module T13208 where
f x = let g = \x -> x in g True
f = \ (@ p) _ [Occ=Dead] -> GHC.Types.True
......@@ -106,3 +106,4 @@ test('T14547', normal, compile, ['-Wincomplete-patterns'])
test('T14773a', normal, compile, ['-Wincomplete-patterns'])
test('T14773b', normal, compile, ['-Wincomplete-patterns'])
test('T14815', [], makefile_test, ['T14815'])
test('T13208', [], makefile_test, ['T13208'])
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