Derived instances' DFun names are less informative than hand-written ones
This is a pretty minor buglet, but a buglet nonetheless. Take this code:
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE StandaloneDeriving #-}
module Bug where
class Cls a b
data A1
data A2
data B1
data B2
instance Cls A1 B1
instance Cls A2 B1
deriving anyclass instance Cls A1 B2
deriving anyclass instance Cls A2 B2
And inspect the Core that it produces:
$ /opt/ghc/8.8.1/bin/ghc Bug.hs -ddump-simpl -dsuppress-idinfo -fforce-recomp -dsuppress-module-prefixes
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
==================== Tidy Core ====================
Result size of Tidy Core
= {terms: 130, types: 57, coercions: 0, joins: 0/0}
-- RHS size: {terms: 1, types: 2, coercions: 0, joins: 0/0}
$fClsA1B1 :: Cls A1 B1
$fClsA1B1 = C:Cls @ A1 @ B1
-- RHS size: {terms: 1, types: 2, coercions: 0, joins: 0/0}
$fClsA2B1 :: Cls A2 B1
$fClsA2B1 = C:Cls @ A2 @ B1
-- RHS size: {terms: 1, types: 2, coercions: 0, joins: 0/0}
$fClsB20 :: Cls A1 B2
$fClsB20 = C:Cls @ A1 @ B2
-- RHS size: {terms: 1, types: 2, coercions: 0, joins: 0/0}
$fClsB2 :: Cls A2 B2
$fClsB2 = C:Cls @ A2 @ B2
Note that the instances for B1
, which are both written manually (i.e., without deriving
), have DFun
names $fClsA1B1
and $fClsA2B1
. This is nice and descriptive. On the other hand, the instances for B2
, which are implemented with deriving
, have the much less descriptive names $fClsB20
and $fClsB2
. These names alone don't make it clear which instance they refer to, unlike the DFun
names for the hand-written instances.
Patch incoming.