Useful RULEs are being discarded
(Side note: This ticket is essentially the same as #18532 (closed).)
Note [Trimming auto rules]
in GHC.Core.Iface.Tidy describes how
auto-generated specialisation rules are discarded. But this discards
way more rules than I thought. Consider
f :: Num a => a -> a
f x = ...f.... -- Perhpas big
foo = f@Int...
The specialiser will specialise f
and, if the specialised version
is strict, we'll get
$w$sf :: Int# -> Int#
$w$sf x = ...$w$sf... -- Perhaps big
$sf :: Int -> Int
$sf x = case x of I# x' -> $w$sf x'
f x = ....f...;
{-# RULE "SPEC" forall d. f @Int d = $sf
foo = ....$w$sf...
Now the only thing keeping $sf
alive is that RULE, so according
to See Note [Trimming auto rules]
we'll drop the RULE. But that's
a crying shame because $sf
is small, so not much code is retained
if we keep it; and the payoff is that importing modules get to see
this jolly good RULE.
I think we should measure the effect on binary size of being less aggressive about discarding RULES.
Edited by Simon Peyton Jones