Commit 8924224e authored by Ömer Sinan Ağacan's avatar Ömer Sinan Ağacan Committed by Marge Bot

Make small INLINE functions behave properly

Simon writes:

Currently we check for a type arg rather than isTyCoArg.   This in turn
makes INLINE things look bigger than they should be, and stops them
being inlined into boring contexts when they perfectly well could be.
E.g.

    f x = g <refl> x
    {-# INLINE g #-}

    ... (map (f x) xs) ...

The context is boring, so don't inline unconditionally.  But f's RHS is
no bigger than its call, provided you realise that the coercion argument
is ultimately cost-free.

This happens in practice for $WHRefl. It's not a big deal: at most it
means we have an extra function call overhead.  But it's untidy, and
actually worse than what happens without an INLINE pragma.

Fixes #17182

This makes 0.0% change in nofib binary sizes.
parent 0956c194
......@@ -441,10 +441,10 @@ inlineBoringOk e
go :: Int -> CoreExpr -> Bool
go credit (Lam x e) | isId x = go (credit+1) e
| otherwise = go credit e
go credit (App f (Type {})) = go credit f
go credit (App f a) | credit > 0
go credit (App f a) | isTyCoArg a = go credit f
| credit > 0
, exprIsTrivial a = go (credit-1) f
go credit (Tick _ e) = go credit e -- dubious
go credit (Tick _ e) = go credit e -- dubious
go credit (Cast e _) = go credit e
go _ (Var {}) = boringCxtOk
go _ _ = boringCxtNotOk
......
......@@ -10,7 +10,7 @@ T2431.$WRefl [InlPrag=INLINE[0]] :: forall a. a :~: a
Str=m,
Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
WorkFree=True, Expandable=True,
Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=False)
Guidance=ALWAYS_IF(arity=0,unsat_ok=True,boring_ok=True)
Tmpl= \ (@ a) -> T2431.Refl @ a @ a @~ (<a>_N :: a GHC.Prim.~# a)}]
T2431.$WRefl
= \ (@ a) -> T2431.Refl @ a @ a @~ (<a>_N :: a GHC.Prim.~# a)
......@@ -110,3 +110,6 @@ T2431.$tc'Refl
$tc'Refl2
1#
$krep3
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