UnkindPartition / tasty

Modern and extensible testing framework for Haskell
637 stars 108 forks source link

ConsoleReporter.hs: fix unbound implicit variable with -XApplicativeDo #405

Closed ConnorBaker closed 6 months ago

ConnorBaker commented 6 months ago

Fixes the following compilation error I had seen on GHC 9.8 when building with -XApplicativeDo:

Test/Tasty/Ingredients/ConsoleReporter.hs:576:13: error: [GHC-91416]
    • Unbound implicit parameter (?colors::Bool)
        arising from a use of ‘printStatistics’
    • In a stmt of a 'do' block: _ <- printStatistics stats time
      In the expression:
        do stats <- computeStatistics smap
           printStatistics stats time
           return $ statFailures stats == 0
      In a stmt of a 'do' block:
        return $ \ time
                   -> do stats <- computeStatistics smap
                         printStatistics stats time
                         ....
    |
576 |             printStatistics stats time
    |             ^^^^^^^^^^^^^^^
Bodigrim commented 6 months ago

Fixes the following compilation error I had seen on GHC 9.8 when building with -XApplicativeDo

Could you possibly elaborate and provide instructions how to reproduce the error please? cabal build all -w ghc-9.8 seems to succeed without a hitch.

I assume this has something to do with https://gitlab.haskell.org/ghc/ghc/-/issues/20630, but I don't know why to enable -XApplicativeDo in tasty.

ConnorBaker commented 6 months ago

Could you possibly elaborate and provide instructions how to reproduce the error please? cabal build all -w ghc-9.8 seems to succeed without a hitch.

I ran cabal build lib:tasty --ghc-option="-XApplicativeDo" from the root of the repository.

Output ```console Build profile: -w ghc-9.8.1 -O1 In order, the following will be built (use -v for more details): - ansi-terminal-1.0.2 (lib) (requires build) - prettyprinter-ansi-terminal-1.1.3 (lib) (requires build) - optparse-applicative-0.18.1.0 (lib) (requires build) - tasty-1.5 (lib) (first run) Starting ansi-terminal-1.0.2 (lib) Building ansi-terminal-1.0.2 (lib) Installing ansi-terminal-1.0.2 (lib) Completed ansi-terminal-1.0.2 (lib) Starting prettyprinter-ansi-terminal-1.1.3 (lib) Building prettyprinter-ansi-terminal-1.1.3 (lib) Installing prettyprinter-ansi-terminal-1.1.3 (lib) Completed prettyprinter-ansi-terminal-1.1.3 (lib) Starting optparse-applicative-0.18.1.0 (lib) Building optparse-applicative-0.18.1.0 (lib) Installing optparse-applicative-0.18.1.0 (lib) Completed optparse-applicative-0.18.1.0 (lib) Configuring library for tasty-1.5.. Preprocessing library for tasty-1.5.. Building library for tasty-1.5.. [ 1 of 25] Compiling Control.Concurrent.Async ( Control/Concurrent/Async.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Control/Concurrent/Async.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Control/Concurrent/Async.dyn_o ) [ 2 of 25] Compiling Test.Tasty.Options ( Test/Tasty/Options.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Options.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Options.dyn_o ) [ 3 of 25] Compiling Test.Tasty.Parallel ( Test/Tasty/Parallel.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Parallel.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Parallel.dyn_o ) [ 4 of 25] Compiling Test.Tasty.Patterns.Expr ( Test/Tasty/Patterns/Expr.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Expr.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Expr.dyn_o ) [ 5 of 25] Compiling Test.Tasty.Patterns.Types ( Test/Tasty/Patterns/Types.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Types.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Types.dyn_o ) [ 6 of 25] Compiling Test.Tasty.Patterns.Printer ( Test/Tasty/Patterns/Printer.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Printer.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Printer.dyn_o ) [ 7 of 25] Compiling Test.Tasty.Patterns.Parser ( Test/Tasty/Patterns/Parser.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Parser.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Parser.dyn_o ) [ 8 of 25] Compiling Test.Tasty.Patterns.Eval ( Test/Tasty/Patterns/Eval.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Eval.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns/Eval.dyn_o ) [ 9 of 25] Compiling Test.Tasty.Patterns ( Test/Tasty/Patterns.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Patterns.dyn_o ) [10 of 25] Compiling Test.Tasty.Options.Core ( Test/Tasty/Options/Core.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Options/Core.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Options/Core.dyn_o ) [11 of 25] Compiling Test.Tasty.Providers.ConsoleFormat ( Test/Tasty/Providers/ConsoleFormat.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Providers/ConsoleFormat.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Providers/ConsoleFormat.dyn_o ) [12 of 25] Compiling Test.Tasty.Core ( Test/Tasty/Core.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Core.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Core.dyn_o ) [13 of 25] Compiling Test.Tasty.Providers ( Test/Tasty/Providers.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Providers.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Providers.dyn_o ) [14 of 25] Compiling Test.Tasty.Runners.Reducers ( Test/Tasty/Runners/Reducers.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Runners/Reducers.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Runners/Reducers.dyn_o ) [15 of 25] Compiling Test.Tasty.Runners.Utils ( Test/Tasty/Runners/Utils.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Runners/Utils.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Runners/Utils.dyn_o ) [16 of 25] Compiling Test.Tasty.Run ( Test/Tasty/Run.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Run.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Run.dyn_o ) [17 of 25] Compiling Test.Tasty.Ingredients ( Test/Tasty/Ingredients.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients.dyn_o ) [18 of 25] Compiling Test.Tasty.Options.Env ( Test/Tasty/Options/Env.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Options/Env.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Options/Env.dyn_o ) [19 of 25] Compiling Test.Tasty.Ingredients.ListTests ( Test/Tasty/Ingredients/ListTests.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients/ListTests.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients/ListTests.dyn_o ) [20 of 25] Compiling Test.Tasty.Ingredients.IncludingOptions ( Test/Tasty/Ingredients/IncludingOptions.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients/IncludingOptions.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients/IncludingOptions.dyn_o ) [21 of 25] Compiling Test.Tasty.Ingredients.ConsoleReporter ( Test/Tasty/Ingredients/ConsoleReporter.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients/ConsoleReporter.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/Ingredients/ConsoleReporter.dyn_o ) Test/Tasty/Ingredients/ConsoleReporter.hs:576:13: error: [GHC-91416] • Unbound implicit parameter (?colors::Bool) arising from a use of ‘printStatistics’ • In a stmt of a 'do' block: _ <- printStatistics stats time In the expression: do stats <- computeStatistics smap printStatistics stats time return $ statFailures stats == 0 In a stmt of a 'do' block: return $ \ time -> do stats <- computeStatistics smap printStatistics stats time .... | 576 | printStatistics stats time | ^^^^^^^^^^^^^^^ [23 of 25] Compiling Test.Tasty.CmdLine ( Test/Tasty/CmdLine.hs, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/CmdLine.o, /Users/connorbaker/Packages/ghc_hyperopt/GHC-HyperOpt/deps/tasty/dist-newstyle/build/aarch64-osx/ghc-9.8.1/tasty-1.5/build/Test/Tasty/CmdLine.dyn_o ) Error: cabal: Failed to build tasty-1.5. ```

I assume this has something to do with https://gitlab.haskell.org/ghc/ghc/-/issues/20630, but I don't know why to enable -XApplicativeDo in tasty.

You're right, it does seem to be an instance of that issue!

As for the why of doing this -- I don't really have one. I'm building a project locally which I've split into many packages and I've taken the simple approach of using a cabal.project to enable aggressive optimizations for all of them with the following:

cabal.project ```cabal package * ghc-options: -Wall -O2 -XApplicativeDo -foptimal-applicative-do -- Test/Tasty/Ingredients/ConsoleReporter.hs:576:13: error: [GHC-91416] -- • Unbound implicit parameter (?colors::Bool) -- arising from a use of ‘printStatistics’ -- • In a stmt of a 'do' block: _ <- printStatistics stats time -- In the expression: -- do stats <- computeStatistics smap -- printStatistics stats time -- return $ statFailures stats == 0 -- In a stmt of a 'do' block: -- return $ \ time -- -> do stats <- computeStatistics smap -- printStatistics stats time -- .... -- | -- 576 | printStatistics stats time -- | ^^^^^^^^^^^^^^^ package tasty ghc-options: -XNoApplicativeDo -fno-optimal-applicative-do -- src/Hedgehog/Internal/Runner.hs:349:64: error: [GHC-83865] -- • Couldn't match type ‘Result’ with ‘Progress’ -- Expected: Progress -> Report Progress -- Actual: Result -> Report Result -- • In the second argument of ‘(.)’, namely ‘mkReport’ -- In the second argument of ‘skipToShrink’, namely -- ‘(updateUI . mkReport)’ -- In the second argument of ‘(<$>)’, namely -- ‘skipToShrink shrinkPath (updateUI . mkReport) node’ -- | -- 349 | mkReport <$> skipToShrink shrinkPath (updateUI . mkReport) node -- | ^^^^^^^^ package hedgehog ghc-options: -XNoApplicativeDo -fno-optimal-applicative-do ```

Per 6.2.4.2. Things to watch out for

Your code should just work as before when ApplicativeDo is enabled, provided you use conventional Applicative instances.

I thought it was reasonable to do so for all packages, not just my local packages because it shouldn't break anything.

I submitted this PR because I thought tasty shouldn't fail to compile when ApplicativeDo is enabled.

You're right that this looks like a bug in GHC itself. As such, I'll close this PR.

ConnorBaker commented 6 months ago

Unrelated, but any idea if it would be appropriate to amend https://gitlab.haskell.org/ghc/ghc/-/blob/master/docs/users_guide/exts/applicative_do.rst to mention https://gitlab.haskell.org/ghc/ghc/-/issues/20630?

Bodigrim commented 6 months ago

Unrelated, but any idea if it would be appropriate to amend https://gitlab.haskell.org/ghc/ghc/-/blob/master/docs/users_guide/exts/applicative_do.rst to mention https://gitlab.haskell.org/ghc/ghc/-/issues/20630?

I think it's a good idea, yes.

Bodigrim commented 6 months ago

FWIW I seriously doubt that enabling -XApplicativeDo has any measurable effect on performance for libraries, which were not specifically designed to use {-# LANGUAGE ApplicativeDo #-}.