Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
GHC
GHC
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,392
    • Issues 4,392
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
    • Iterations
  • Merge Requests 374
    • Merge Requests 374
  • Requirements
    • Requirements
    • List
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Operations
    • Operations
    • Incidents
    • Environments
  • Analytics
    • Analytics
    • CI / CD
    • Code Review
    • Insights
    • Issue
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #17339

Closed
Open
Opened Oct 10, 2019 by Ryan Scott@RyanGlScottMaintainer

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.

Assignee
Assign to
8.10.1
Milestone
8.10.1 (Past due)
Assign milestone
Time tracking
None
Due date
None
Reference: ghc/ghc#17339