polysemy-research / polysemy

:gemini: higher-order, no-boilerplate monads
BSD 3-Clause "New" or "Revised" License
1.03k stars 73 forks source link

GHC 9.10: Pattern match has inaccessible right hand side #486

Closed locallycompact closed 2 weeks ago

locallycompact commented 8 months ago
       > src/Polysemy/Internal/Union.hs:298:1: warning: [8;;https://errors.haskell.org/messages/GHC-94210GHC-942108;;] [-Woverlapping-patterns]
       >     Pattern match has inaccessible right hand side
       >     In an equation for ‘absurdU’: absurdU (Union _ _) = ...
       >     |
       > 298 | absurdU (Union _ _) = error "Unsafe use of UnsafeMkElemOf"

https://gitlab.horizon-haskell.net/package-sets/horizon-advance/-/jobs/1417118#L185

m4dc4p commented 5 months ago

I also see errors related to TH changes:

[17 of 44] Compiling Polysemy.Internal.TH.Effect ( src/Polysemy/Internal/TH/Effect.hs, dist/build/Polysemy/Internal/TH/Effect.o, dist/build/Polysemy/Internal/TH/Effect.dyn_o )
src/Polysemy/Internal/TH/Effect.hs:140:28: error: [8;;https://errors.haskell.org/messages/GHC-83865GHC-838658;;]
    • Couldn't match type ‘Name -> Dec’ with ‘Dec’
      Expected: Fixity -> NamespaceSpecifier -> Dec
        Actual: Fixity -> NamespaceSpecifier -> Name -> Dec
    • Probable cause: ‘InfixD’ is applied to too few arguments
      In the first argument of ‘flip’, namely ‘InfixD’
      In the second argument of ‘(.)’, namely
        ‘flip InfixD (cliFunName cli)’
      In the second argument of ‘maybe’, namely
        ‘(pure . flip InfixD (cliFunName cli))’
    |
140 |   =  maybe [] (pure . flip InfixD (cliFunName cli)) (cliFunFixity cli)
    |                            ^^^^^^
m4dc4p commented 5 months ago

The fix for the error above is really simple:

diff --git a/vendor/polysemy/src/Polysemy/Internal/TH/Effect.hs b/vendor/polysemy/src/Polysemy/Internal/TH/Effect.hs
index c4df68da3..bb8051326 100644
--- a/vendor/polysemy/src/Polysemy/Internal/TH/Effect.hs
+++ b/vendor/polysemy/src/Polysemy/Internal/TH/Effect.hs
@@ -137,7 +137,11 @@ genFreer should_mk_sigs type_name = do
 -- its body on effect's data constructor.
 genSig :: ConLiftInfo -> [Dec]
 genSig cli
-  =  maybe [] (pure . flip InfixD (cliFunName cli)) (cliFunFixity cli)
+#if __GLASGOW_HASKELL__ >= 910
+  =  maybe [] (\fixity -> pure $ InfixD fixity NoNamespaceSpecifier (cliFunName cli)) (cliFunFixity cli)
+#else
+  =  maybe [] (\fixity -> pure $ InfixD fixity (cliFunName cli)) (cliFunFixity cli)
+#endif
   ++ [ SigD (cliFunName cli) $ quantifyType
        $ ForallT [] (member_cxt : cliFunCxt cli)
        $ foldArrowTs sem

I didn't look into the warning, but that will get the library compiling at least.

tek commented 5 months ago

I think that warning has always been there, hasn't it? Gotta research which GHC versions need that match.

Anyway, I added the TH fix, but I don't have 9.10 available, so someone's gotta test this.

locallycompact commented 5 months ago

You can get a 9.10.1 shell for polysemy directly from horizon by doing:

nix develop 'git
+https://gitlab.horizon-haskell.net/package-sets/horizon-advance#polysemy.env'

Run ghc-pkg list to see what it pulled.

tek commented 5 months ago

thanks. I'm getting

conflict: ghc-tcplugins-extra => ghc>=7.10 && <9.10

although I saw that there's a patch in the repo that's supposed to jailbreak this

tek commented 5 months ago

added some CPP for the warning as well

m4dc4p commented 5 months ago

I would be happy to test but I can't tell what branch or commit I should use. I don't see a linked PR ...

tek commented 5 months ago

@m4dc4p it's in master

m4dc4p commented 5 months ago

Can confirm this builds with 9.10.1!

tek commented 5 months ago

alright, uploaded a release!