commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.98k stars 842 forks source link

How to remove warning "Instead of 'ghc-options: -XOverloadedStrings ..." #6589

Open diqye opened 4 months ago

diqye commented 4 months ago

package.yaml

...
ghc-options:
- -Wall
- -fno-warn-missing-signatures
- -fno-warn-type-defaults
- -fno-warn-name-shadowing
- -fno-warn-orphans
- -fno-warn-incomplete-uni-patterns
- -fno-warn-unused-top-binds
- -fno-warn-unused-imports
- -XExtendedDefaultRules
- -XOverloadedStrings
- -XFlexibleContexts
- -XConstraintKinds
- -XScopedTypeVariables
- -XTemplateHaskell
...

There are some warning as bellow when i run stack repl

~/p/runai (master|✚4) $ stack repl
Using main module:
1.  Package runai, component runai:exe:runai, with main-is file:
    /Users/diqye/projects/runai/app/Main.hs.

myai > initial-build-steps (lib)
runai> configure (lib + exe)
runai> Configuring runai-0.1.0.0...
runai> Warning: Instead of 'ghc-options: -XExtendedDefaultRules -XOverloadedStrings
runai> -XFlexibleContexts -XConstraintKinds -XScopedTypeVariables -XTemplateHaskell
runai> -XExtendedDefaultRules -XOverloadedStrings -XFlexibleContexts
runai> -XConstraintKinds -XScopedTypeVariables -XTemplateHaskell' use 'extensions:
runai> ExtendedDefaultRules OverloadedStrings FlexibleContexts ConstraintKinds
runai> ScopedTypeVariables TemplateHaskell ExtendedDefaultRules OverloadedStrings
runai> FlexibleContexts ConstraintKinds ScopedTypeVariables TemplateHaskell'
runai> initial-build-steps (lib + exe)

Except : No warning

diqye commented 4 months ago

I think this is a warning generated when Stack generates Cabel file without using 'ghc-options', and then runs cabal

mpilgrem commented 4 months ago

@diqye, I suspect that is a message from Cabal (the library). If you stack build with Cabal set to be less verbose (https://docs.haskellstack.org/en/stable/build_command/#-no-cabal-verbosity-option) does the warning disappear?

mpilgrem commented 4 months ago

@diqye, I don't know why you are getting advice from Cabal (the library) to use extensions: - it was deprecated in Cabal 1.12 and removed in Cabal (EDIT) package description format 3.0: https://cabal.readthedocs.io/en/stable/cabal-package-description-file.html#pkg-field-extensions. What version of GHC are you specifying with stack repl?

EDIT: Hpack supports default-extensions: https://github.com/sol/hpack?tab=readme-ov-file#common-fields.

diqye commented 4 months ago

@mpilgrem

~/p/runai (master|✚4) $ ls $(stack path --compiler-bin)
ghc@               ghci@              hp2ps@             hsc2hs@            runhaskell@
ghc-9.4.7*         ghci-9.4.7*        hp2ps-ghc-9.4.7*   hsc2hs-ghc-9.4.7*  runhaskell-9.4.7*
ghc-pkg@           haddock@           hpc@               runghc@
ghc-pkg-9.4.7*     haddock-ghc-9.4.7* hpc-ghc-9.4.7*     runghc-9.4.7*

I just reproduced this problem

  1. Delete cabal file (eg. runai.cabal)
  2. Run commoand stack build
~/p/runai (master|✚4) [SIGINT]$ stack build --cabal-verbose
runai> configure (lib + exe)
runai> Using Parsec parser
runai> Configuring runai-0.1.0.0...
runai> Warning: Instead of 'ghc-options: -XExtendedDefaultRules -XOverloadedStrings
runai> -XFlexibleContexts -XConstraintKinds -XScopedTypeVariables -XTemplateHaskell
runai> -XExtendedDefaultRules -XOverloadedStrings -XFlexibleContexts
runai> -XConstraintKinds -XScopedTypeVariables -XTemplateHaskell' use 'extensions:
runai> ExtendedDefaultRules OverloadedStrings FlexibleContexts ConstraintKinds
runai> ScopedTypeVariables TemplateHaskell ExtendedDefaultRules OverloadedStrings
runai> FlexibleContexts ConstraintKinds ScopedTypeVariables TemplateHaskell'

This warning will appear whether flg is added or not.

diqye commented 4 months ago

If you do not delete the cabal file, this warning will not appear.

mpilgrem commented 4 months ago

After a little experimentation, this is indeed a Cabal (the library) warning. (Stack uses Cabal to build; by default, Stack builds when you command stack repl - see https://docs.haskellstack.org/en/stable/ghci/.) The easiest way to avoid the warning is to follow Cabal's advice, except the advice is not complete (which could be characterised as an existing Cabal bug): if you use extensions: in your Cabal file, Cabal will then warn you that it is deprecated in favour of default-extensions (which field is also supported by Hpack in its package.yaml format).

Another way to avoid the warning is to set --cabal-verbosity silent - however, that will also silence all other Cabal output. With stack repl you can, in fact, command stack --cabal-verbosity silent repl because all stack build flags/options are actually (hidden) global options.