Bad STG generation for dictionary applications
(Sorry if the title is confusing)
Example:
module Lib where
data T = C1 [T] | C2 deriving (Eq)
When I build this with -O
I get this top-level thunk for the Eq [T]
dictionary:
$dEq_rO4 :: GHC.Classes.Eq [Lib.T]
[GblId] = \u [] GHC.Classes.$fEq[] Lib.$fEqT;
I don't understand why this needs to be a thunk, and why $fEq[]
is not
inlined. I think we should be inlining $fEq[]
and generating a top-level
constructor here.
This came up while looking at changes in !1304 (merged). The Eq
methods generated in
the code above are all CAFFY just because this definition is a CAF. Transitively
this has the potential to make a lot of things CAFFY for no reason.