haskell / network-uri

URI manipulation facilities
Other
24 stars 33 forks source link

Type errors under GHC 9.0 due to the change to Code in Template Haskell. #55

Closed galenhuntington closed 3 years ago

galenhuntington commented 3 years ago

In https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3358, a bunch of types were changed involving TExp and so on. As a result, this package fails to build under GHC 9.0 due to type errors, at least in Network.URI.Static:

Network/URI/Static.hs:59:34: error:
    • Couldn't match type: Language.Haskell.TH.Syntax.Code m1 URI
                     with: Language.Haskell.TH.Syntax.Q
                             (Language.Haskell.TH.Syntax.TExp URI)
      Expected: TExpQ URI
        Actual: Language.Haskell.TH.Syntax.Code m1 URI
    • In the Template Haskell quotation [|| u ||]
      In the expression: [|| u ||]
      In an equation for ‘staticURI’:
          staticURI (parseURI -> Just u) = [|| u ||]
   |
59 | staticURI (parseURI -> Just u) = [|| u ||]
   |                                  ^^^^^^^^^

Network/URI/Static.hs:112:64: error:
    • Couldn't match type: Language.Haskell.TH.Syntax.Code m0 URI
                     with: Language.Haskell.TH.Syntax.Q
                             (Language.Haskell.TH.Syntax.TExp URI)
      Expected: TExpQ URI
        Actual: Language.Haskell.TH.Syntax.Code m0 URI
    • In the Template Haskell quotation [|| ref ||]
      In the expression: [|| ref ||]
      In an equation for ‘staticRelativeReference’:
          staticRelativeReference (parseRelativeReference -> Just ref)
            = [|| ref ||]
    |
112 | staticRelativeReference (parseRelativeReference -> Just ref) = [|| ref ||]
    |                                                                ^^^^^^^^^^^

I made an effort to fix this myself, but I don't understand TH and its panoply of types very well and didn't really get anywhere.

cartazio commented 3 years ago

you might want to try using the head hackage setup... it may have some patch set already setup so things build fine

ezrakilty commented 3 years ago

I'll try to add GHC 9 to Travis CI and see if we can reproduce it there.

galenhuntington commented 3 years ago

I can get it to type check (using template-haskell 2.17) and build by putting examineCode (from Language.Haskell.TH.Syntax) in front of all the [|| ||] expressions, but because $$( ) now expects a Code type, this package no longer works as documented:

Network.URI.Static> $$(staticURI "http://www.google.com/")

<interactive>:8:4: error:
    • Couldn't match type: Language.Haskell.TH.Syntax.Q
                             (Language.Haskell.TH.Syntax.TExp Network.URI.URI)
                     with: Language.Haskell.TH.Syntax.Code
                             Language.Haskell.TH.Syntax.Q p0
      Expected: Language.Haskell.TH.Syntax.Code
                  Language.Haskell.TH.Syntax.Q p0
        Actual: Language.Haskell.TH.Lib.Internal.TExpQ Network.URI.URI
    • In the expression: staticURI "http://www.google.com/"
      In the Template Haskell splice
        $$(staticURI "http://www.google.com/")
      In the expression: $$(staticURI "http://www.google.com/")

So it seems the solution is for staticURI and so on to have different types when used with GHC 9. That might not be pretty. Maybe type aliases and CPP.

ezrakilty commented 3 years ago

Yes, looks like a bit of a nuisance... I'm working on setting up a GHC 9 that I can experiment with.

galenhuntington commented 3 years ago

There's an as-yet-unreleased WIP compatibility package th-compat, which appears to export the needed type alias, called SpliceQ. So maybe it's best to hold off putting effort into this till that package is out.

asr commented 3 years ago

Using GHC 9.0.1-rc1 I'm getting the same errors than in the OP.

Blocking https://github.com/agda/agda/issues/4955.

ezrakilty commented 3 years ago

OK, I'll check this out again today.

ezrakilty commented 3 years ago

To test with unreleased GHC 9, do I need to build my own GHC?

asr commented 3 years ago

No. You can download a binary distribution from https://downloads.haskell.org/ghc/9.0.1-rc1/.

galenhuntington commented 3 years ago

I just posted my first effort at GHC 9 compatibility here: #58.

asr commented 3 years ago

I just found there is a patch fixing this issue without using additional libraries in https://gitlab.haskell.org/ghc/head.hackage/-/blob/master/patches/network-uri-2.6.3.0.patch.

galenhuntington commented 3 years ago

Right, but the goal of th-compat is to provide a compatibility layer that can be used without resorting to repetitive CPP.