Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 5,357
    • Issues 5,357
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 566
    • Merge requests 566
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell CompilerGlasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #8635
Closed
Open
Issue created Dec 27, 2013 by Neil Mitchell@ndmitchellReporter

GHC optimisation flag ignored when importing a local module with derived type classes

Given Foo.hs and Bar.hs:

module Foo where
data Food = Food -- deriving Eq

{-# OPTIONS_GHC -O2 -ddump-simpl #-}
module Bar where
import Foo
bar :: Int -> Bool
bar x = x == 72

If I run:

ghc --make Bar -fforce-recomp

I get (snipped):

Bar.bar =
  \ (x_afk :: GHC.Types.Int) ->
    case x_afk of _ { GHC.Types.I# x1_alo ->
    case x1_alo of _ {
      __DEFAULT -> GHC.Types.False;
      72 -> GHC.Types.True
    }
    }

bar now looks pretty well optimised. However, if I uncomment the deriving Eq I get:

Bar.bar1 = GHC.Types.I# 72
Bar.bar2 = GHC.Classes.== @ GHC.Types.Int GHC.Classes.$fEqInt
Bar.bar = \ (x_amD :: GHC.Types.Int) -> Bar.bar2 x_amD Bar.bar1

Now bar looks like terrible code, using dictionaries, boxing etc. It seems adding deriving in the imported and unused module makes it ignore the optimisation level.

Edited Mar 10, 2019 by Ben Gamari
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking