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
  • #20021
Closed
Open
Issue created Jun 19, 2021 by harendra@harendra

Optimization options (esp. -O2) in OPTIONS_GHC pragma can cause frustrating behavior

Summary

I wrote a small main module with the following options at the top:

{-# OPTIONS_GHC
  -O2
  -ddump-simpl
  -ddump-to-file
  -dsuppress-all
#-}

It was working well for some time. Then I introduced an import AnotherModule in this module and I did not realize that this simple change caused the -O2 option to not work. The program was not getting optimized and I was frustrated because I thought there is a performance bug issue when some code is moved to another module.

After battling for a long time with this I realized that the -O2 option is specified for this file but not for the other file which might be causing the issue. The problem occurs even if I just import the other module and do not use anything from it. The problem goes away if -O2 is specified in the imported module as well or -O2 is specified on the command line.

This is very frustrating. We should probably ban the -O2 option in OPTIONS_GHC pragma or any such option which could impact the behavior of the overall program if we specify it locally in a file. Or at least we should issue a warning even without -Wall on.

This is a usability/user experience/reliability issue.

Environment

  • GHC version used:
$ ghc-stage2 --version
The Glorious Glasgow Haskell Compilation System, version 9.3.20210608
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking