Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling documentation seems to swallow ghc-options passed #10782

Open
Swordlash opened this issue Feb 6, 2025 · 7 comments · May be fixed by #10783
Open

Enabling documentation seems to swallow ghc-options passed #10782

Swordlash opened this issue Feb 6, 2025 · 7 comments · May be fixed by #10783
Labels
re: ghc-options Concerning passing options to GHC regression in 3.14 type: bug

Comments

@Swordlash
Copy link

Describe the bug

Pretty much what is in the title. Enabling documentation seems to swallow additional ghc-options being passed (either on command line or in cabal.project).

To Reproduce
Steps to reproduce the behavior:

cabal-test.cabal:

cabal-version:      3.0
version:            0.1.0
name:               cabal-test
build-type:         Simple

executable cabal-test
    main-is:          Main.hs
    build-depends:    base
    hs-source-dirs:   app
    default-language: Haskell2010

in the app/Main.hs:

module Main where

import Data.List -- note: redundant import
 
main :: IO ()
main = putStrLn "Hello, Haskell!"

Run

$ cabal run  --ghc-options="-Wall -Werror" --enable-documentation

Expected behavior
The build should fail with unused import. Instead, not even a warning is printed.

System information

  • Operating system: Linux Ubuntu 22.04 x86_64
  • cabal: 3.14.1.1
  • ghc: 9.6.6 (tested with 9.8.4 as well)
@chreekat
Copy link
Collaborator

chreekat commented Feb 7, 2025

I can't reproduce with Cabal 3.12.1.0,

but I do note that cabal run won't recompile if I add --ghc-options after it's already compiled once.

After a clean, the expected error shows up.

[b@kuusi:~/tmp/cabal-10782]$ cabal clean

[b@kuusi:~/tmp/cabal-10782]$ cabal run
Warning: The package list for 'hackage.haskell.org' is 15 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
 - cabal-test-0.1.0 (exe:cabal-test) (first run)
Configuring executable 'cabal-test' for cabal-test-0.1.0...
Preprocessing executable 'cabal-test' for cabal-test-0.1.0...
Building executable 'cabal-test' for cabal-test-0.1.0...
[1 of 1] Compiling Main             ( app/Main.hs, /home/b/tmp/cabal-10782/dist-newstyle/build/x86_64-linux/ghc-9.6.6/cabal-test-0.1.0/x/cabal-test/build/cabal-test/cabal-test-tmp/Main.o )
[2 of 2] Linking /home/b/tmp/cabal-10782/dist-newstyle/build/x86_64-linux/ghc-9.6.6/cabal-test-0.1.0/x/cabal-test/build/cabal-test/cabal-test
Hello, Haskell!

[b@kuusi:~/tmp/cabal-10782]$ cabal run --ghc-options="-Wall -Werror" --enable-documentation
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
 - cabal-test-0.1.0 (exe:cabal-test) (configuration changed)
Configuring executable 'cabal-test' for cabal-test-0.1.0...
Preprocessing executable 'cabal-test' for cabal-test-0.1.0...
Building executable 'cabal-test' for cabal-test-0.1.0...
Hello, Haskell!

[b@kuusi:~/tmp/cabal-10782]$ cabal clean

[b@kuusi:~/tmp/cabal-10782]$ cabal run --ghc-options="-Wall -Werror" --enable-documentation
Warning: The package list for 'hackage.haskell.org' is 15 days old.
Run 'cabal update' to get the latest list of available packages.
Resolving dependencies...
Build profile: -w ghc-9.6.6 -O1
In order, the following will be built (use -v for more details):
 - cabal-test-0.1.0 (exe:cabal-test) (first run)
Configuring executable 'cabal-test' for cabal-test-0.1.0...
Preprocessing executable 'cabal-test' for cabal-test-0.1.0...
Building executable 'cabal-test' for cabal-test-0.1.0...
[1 of 1] Compiling Main             ( app/Main.hs, /home/b/tmp/cabal-10782/dist-newstyle/build/x86_64-linux/ghc-9.6.6/cabal-test-0.1.0/x/cabal-test/build/cabal-test/cabal-test-tmp/Main.o )

app/Main.hs:3:1: error: [-Wunused-imports, Werror=unused-imports]
    The import of ‘Data.List’ is redundant
      except perhaps to import instances from ‘Data.List’
    To import instances alone, use: import Data.List()
  |
3 | import Data.List -- note: redundant import
  | ^^^^^^^^^^^^^^^^

[b@kuusi:~/tmp/cabal-10782]$

@jasagredo
Copy link
Collaborator

I agree with @chreekat. My understanding is that ghc-options passed via the CLI do not trigger a rebuild in some cases. I don't know whether this is a cabal issue or just that the invocation to GHC with these new flags decides that it doesn't need to recompile the file:

~\cc via λ 9.10.1 took 2s
➜ ghc Main.hs
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking Main.exe

~\cc via λ 9.10.1
➜ ghc -Wall -Werror Main.hs

~\cc via λ 9.10.1
➜ rm -rf Main.o Main.hi Main.exe

~\cc via λ 9.10.1
➜ ghc -Wall -Werror Main.hs
[1 of 2] Compiling Main             ( Main.hs, Main.o )
Main.hs:3:1: error: [GHC-66111] [-Wunused-imports, Werror=unused-imports]
    The import of ‘Data.List’ is redundant
      except perhaps to import instances from ‘Data.List’
    To import instances alone, use: import Data.List()
  |
3 | import Data.List -- note: redundant import
  | ^^^^^^^^^^^^^^^^

This looks like a GHC thing and not a cabal issue.

@Swordlash
Copy link
Author

As I mentioned the bug is on 3.14.1.1; I also cannot reproduce it with 3.12.1.

See mlabs-haskell/covenant#39

@jasagredo
Copy link
Collaborator

Ok, I checked the cabal verbose output and indeed you are right, I'm sorry. My first immediate guess was that the re-compilation with documentation was not complaining. If we invoke with --enable-documentation it seems we call GHC with these arguments:

Running: "C:\ghcup\bin\ghc.exe" ... "-haddock"

and if I remove --enable-documentation it uses my args defined in my global cabal config as well as the cli args:

Running: "C:\ghcup\bin\ghc.exe" ... "-optc-Wno-pragma-pack" "-optc-Wno-macro-redefined" "-optc-Wno-missing-declarations" "-optl-Wl,--allow-multiple-definition" "-optc-Wno-pragma-pack" "-optc-Wno-macro-redefined" "-optc-Wno-missing-declarations" "-optl-Wl,--allow-multiple-definition" "-Wall" "-Werror"

notice the -Wall and -Werror at the end.

So I think this is a legitimate bug.

@chreekat
Copy link
Collaborator

chreekat commented Feb 7, 2025

As I mentioned the bug is on 3.14.1.1

Indeed, sorry I was so cryptic: I meant to preclude 3.12 on the one hand (so if it's a bug on 3.14, it's probably only on 3.14), and raise a potential separate confounding issue at the same time.

Sounds like there are two bugs :)

@Mikolaj Mikolaj added regression in 3.14 re: ghc-options Concerning passing options to GHC and removed needs triage labels Feb 8, 2025
@Mikolaj
Copy link
Member

Mikolaj commented Feb 8, 2025

Yay, thank you for reproducing. This is madness.

@chreekat: is the separate issue already reported in our bug tracker? What keywords to use to search for it?

@jasagredo jasagredo linked a pull request Feb 8, 2025 that will close this issue
6 tasks
@jasagredo jasagredo linked a pull request Feb 8, 2025 that will close this issue
6 tasks
@jasagredo
Copy link
Collaborator

Fixed in #10783. However note the comment I made there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: ghc-options Concerning passing options to GHC regression in 3.14 type: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants