Optimization options (esp. -O2) in OPTIONS_GHC pragma can cause frustrating behavior
I wrote a small main module with the following options at the top:
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.
- GHC version used:
$ ghc-stage2 --version
The Glorious Glasgow Haskell Compilation System, version 9.3.20210608