Commit b2fdb7de authored by Alexis King's avatar Alexis King

Flatten nested casts in the simple optimizer

Normally, we aren’t supposed to generated any nested casts, since mkCast
takes care to flatten them, but the simple optimizer didn’t use mkCast,
so they could show up after inlining. This isn’t really a problem, since
the simplifier will clean them up immediately anyway, but it can clutter
the -ddump-ds output, and it’s an extremely easy fix.

closes #18112
parent fd7ea0fe
Pipeline #18840 passed with stages
in 495 minutes and 50 seconds
......@@ -221,10 +221,13 @@ simple_opt_expr env expr
go (Coercion co) = Coercion (optCoercion (soe_dflags env) (getTCvSubst subst) co)
go (Lit lit) = Lit lit
go (Tick tickish e) = mkTick (substTickish subst tickish) (go e)
go (Cast e co) | isReflCo co' = go e
| otherwise = Cast (go e) co'
co' = optCoercion (soe_dflags env) (getTCvSubst subst) co
go (Cast e co) = case go e of
-- flatten nested casts before calling the coercion optimizer;
-- see #18112 (note that mkCast handles dropping Refl coercions)
Cast e' co' -> mkCast e' (opt_co (mkTransCo co' co))
e' -> mkCast e' (opt_co co)
opt_co = optCoercion (soe_dflags env) (getTCvSubst subst)
go (Let bind body) = case simple_opt_bind env bind NotTopLevel of
(env', Nothing) -> simple_opt_expr env' body
{-# LANGUAGE TypeFamilies #-}
module T18112 where
type family F a where
F Int = String
-- This test is really testing the simple optimizer. We expect the
-- optimized desugared output to contain no casts, since the simple
-- optimizer should fuse the two casts together after inlining y.
blah :: Bool -> String
blah x = let y :: F Int
y = show x
in y
......@@ -109,3 +109,4 @@ test('T14773b', normal, compile, ['-Wincomplete-patterns'])
test('T14815', [], makefile_test, ['T14815'])
test('T13208', [], makefile_test, ['T13208'])
test('T16615', normal, compile, ['-ddump-ds -dsuppress-uniques'])
test('T18112', [grep_errmsg('cast')], compile, ['-ddump-ds'])
......@@ -12,4 +12,4 @@ Simplifier ticks exhausted
simplifier non-termination has been judged acceptable.
To see detailed counts use -ddump-simpl-stats
Total ticks: 140084
Total ticks: 138082
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