haskell-servant / servant

Main repository for the servant libraries — DSL for describing, serving, querying, mocking, documenting web applications and more!
https://docs.servant.dev/
1.8k stars 407 forks source link

GHC 9.6 has less ticks #1672

Closed ysangkok closed 1 year ago

ysangkok commented 1 year ago

Setting allow-newer and running the doctests reveals that this new version of GHC (or is it doctest?) prefers not to have ticks. That makes sense because unticked promoted constructors are now encouraged. But I am not sure how the tests can be made compatible such that they work for both old and new GHCs.

DOCTEST="cabal repl --with-ghc=doctest --ghc-options=-w"                    
        (cd servant && eval $DOCTEST)
        (cd servant-client && eval $DOCTEST)
        (cd servant-client-core && eval $DOCTEST)
        (cd servant-http-streams && eval $DOCTEST)
        (cd servant-docs && eval $DOCTEST)
        (cd servant-foreign && eval $DOCTEST)
        (cd servant-server && eval $DOCTEST)
        (cd servant-machines && eval $DOCTEST)
        (cd servant-conduit && eval $DOCTEST)
        (cd servant-pipes && eval $DOCTEST)
Build profile: -w ghc-9.6.1 -O0
[...]
src/Servant/API/TypeLevel.hs:221: failure in expression `ok (Proxy :: Proxy (Elem String '[Int, Bool]))'
expected: ...
          ... [Char]...'[Int, Bool...
          ...
 but got: 
          <interactive>:597:1: error: [GHC-64725]
                                       ^
              • [Char] expected in list [Int, Bool]
              • In the expression: ok (Proxy :: Proxy (Elem String '[Int, Bool]))
                In an equation for ‘it’:
                    it = ok (Proxy :: Proxy (Elem String '[Int, Bool]))

src/Servant/API/Modifiers.hs:39: failure in expression `:kind! FoldRequired '[Required, Description "something"]'
expected: FoldRequired '[Required, Description "something"] :: Bool
          = 'True
 but got: FoldRequired '[Required, Description "something"] :: Bool
          = True
            ^

src/Servant/API/Modifiers.hs:68: failure in expression `:kind! FoldLenient '[]'
expected: FoldLenient '[] :: Bool
          = 'False
 but got: FoldLenient '[] :: Bool
          = False
            ^

Examples: 219  Tried: 217  Errors: 0  Failures: 4
Error: cabal: repl failed for servant-0.19.1.

Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-0.19.1 (lib) (first run)
 - servant-client-core-0.19 (lib) (configuration changed)
 - servant-client-0.19 (lib) (configuration changed)
Preprocessing library for servant-0.19.1..
Building library for servant-0.19.1..
Configuring library for servant-client-core-0.19..
Preprocessing library for servant-client-core-0.19..
Building library for servant-client-core-0.19..
Configuring library for servant-client-0.19..
Preprocessing library for servant-client-0.19..
Examples: 0  Tried: 0  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-client-core-0.19 (lib) (ephemeral targets)
Preprocessing library for servant-client-core-0.19..
Examples: 11  Tried: 11  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-http-streams-0.18.4 (lib) (configuration changed)
Configuring library for servant-http-streams-0.18.4..
Preprocessing library for servant-http-streams-0.18.4..
Examples: 0  Tried: 0  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-docs-0.12 (lib) (configuration changed)
Configuring library for servant-docs-0.12..
Preprocessing library for servant-docs-0.12..
Examples: 13  Tried: 13  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-foreign-0.15.4 (lib) (configuration changed)
Configuring library for servant-foreign-0.15.4..
Preprocessing library for servant-foreign-0.15.4..
Examples: 0  Tried: 0  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-server-0.19.2 (lib) (configuration changed)
Configuring library for servant-server-0.19.2..
Preprocessing library for servant-server-0.19.2..
src/Servant/Server/Internal.hs:910: failure in expression `serve (Proxy :: Proxy (Capture "foo" Int -> Get '[JSON] Int)) (error "...")'
expected: ...
          ...No instance HasServer (a -> b).
          ...Maybe you have used '->' instead of ':>' between
          ...Capture' '[] "foo" Int
          ...and
          ...Verb 'GET 200 '[JSON] Int
          ...
 but got: 
          <interactive>:71:1: error: [GHC-64725]
              • No instance HasServer (a -> b).
                Maybe you have used '->' instead of ':>' between 
                Capture' '[] "foo" Int
                and
                Verb GET 200 '[JSON] Int
              • In the expression:
                  serve
                    (Proxy :: Proxy (Capture "foo" Int -> Get '[JSON] Int))
                    (error "...")
                In an equation for ‘it’:
                    it
                      = serve
                          (Proxy :: Proxy (Capture "foo" Int -> Get '[JSON] Int))
          ...............................................................N^
                          (error "...")

src/Servant/Server/Internal/Context.hs:30: failure in expression `:type True :. () :. EmptyContext'
expected: True :. () :. EmptyContext :: Context '[Bool, ()]
 but got: True :. () :. EmptyContext :: Context [Bool, ()]
                                                ^

src/Servant/Server/Internal/Context.hs:72: failure in expression `getContextEntry (True :. False :. EmptyContext) :: String'
expected: ...
          ...No instance for (HasContextEntry '[] [Char])
          ...
 but got: 
          <interactive>:85:1: error: [GHC-39999]
              • No instance for ‘HasContextEntry '[] [Char]’
                                ^
                  arising from a use of ‘getContextEntry’
              • In the expression:
                    getContextEntry (True :. False :. EmptyContext) :: String
                In an equation for ‘it’:
                    it = getContextEntry (True :. False :. EmptyContext) :: String

src/Servant/Server/Internal/Context.hs:107: failure in expression `:type parentContext'
expected: parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]
 but got: parentContext :: Context [Bool, NamedContext "subContext" '[Bool]]
                                   ^

Examples: 22  Tried: 20  Errors: 0  Failures: 4
Error: cabal: repl failed for servant-server-0.19.2.

Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-machines-0.15.1 (lib) (configuration changed)
Configuring library for servant-machines-0.15.1..
Preprocessing library for servant-machines-0.15.1..
Examples: 0  Tried: 0  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-conduit-0.15.1 (lib) (configuration changed)
Configuring library for servant-conduit-0.15.1..
Preprocessing library for servant-conduit-0.15.1..
Examples: 0  Tried: 0  Errors: 0  Failures: 0
Build profile: -w ghc-9.6.1 -O0
In order, the following will be built (use -v for more details):
 - servant-pipes-0.15.3 (lib) (configuration changed)
Configuring library for servant-pipes-0.15.3..
Preprocessing library for servant-pipes-0.15.3..
Examples: 0  Tried: 0  Errors: 0  Failures: 0
tchoutri commented 1 year ago

Let's simply deactivate -Wunticked-promoted-constructors for all GHC versions?

ysangkok commented 1 year ago

Let's simply deactivate -Wunticked-promoted-constructors for all GHC versions?

I don't think this works. The issue is not caused by warnings, but it is caused by types in error messages not having the tick as they previously had. To verify this, I added -Wunticked-promoted-constructors to the test-suite of servant-server, and reran the doctest. I still get the failures. I suspect I'd be another flag we'd need to set for older GHCs, one about formatting errors. And I am not sure that exists, since the change of heart on unticked promoted constructors might not have been anticipated such that it'd be available in all the GHC versions we run the doctests for.

Solutions I can think of:

voidus commented 1 year ago

We could also add -fprint-redundant-promotion-ticks to have GHC print it in the old style.

ysangkok commented 1 year ago

@voidus Thank you! I have added the flag in #1680 . I would appreciate a review if you have time.