haskus / packages

Haskus packages
https://haskus.org/
24 stars 11 forks source link

build on 9.2+ #53

Closed pillowtrucker closed 7 months ago

pillowtrucker commented 7 months ago

Hello again! I've been trying to build haskus-system and its dependencies on ghc 9.8.1 and I believe I've already managed to patch most of the ghc API incompatibilities in the haskus-binary package here: https://github.com/pillowtrucker/haskus-packages/commit/176709d46ca6956ed4753e7a325018a61e39ce70 but there's still one error thrown by cabal that I just don't understand:

src/lib/Haskus/Memory/Buffer.hs:167:18: error: [GHC-18872]
    • Couldn't match a lifted type with an unlifted type
      When matching types
        a0 :: *
        (# (# #) | MutVar# RealWorld [IO ()] #) :: TYPE
                                                     (SumRep [ZeroBitRep, UnliftedRep])
      Expected: a0
        Actual: Finalizers# RealWorld
    • In the first argument of ‘mkWeak#’, namely ‘fin’
      In the expression: mkWeak# fin b (unIO $ runFinalizers fin) s
      In the expression:
        case mkWeak# fin b (unIO $ runFinalizers fin) s of
          (# s1, _wk #) -> (# s1, () #)
    |
167 |     case mkWeak# fin b (unIO $ runFinalizers fin) s of

I've tried to work around it by using compatMkWeak# from the basement package, but that seems to be an even earlier implementation of mkWeak# and it doesn't help. I'm afraid I don't really understand what has changed there any how/why

pillowtrucker commented 7 months ago

Would something like this do what was originally intended ?

addFinalizer :: Buffer -> IO () -> IO ()
addFinalizer b f = do
   let !fin = getFinalizers b
   case fin of
     Finalizers rfs -> do
       wasEmpty <- insertFinalizer fin f
     -- add the weak reference to the finalizer IORef (not to Addr#/byteArray#/...)
       when wasEmpty $ IO \s ->
         case mkWeak# (IORef (STRef rfs)) b (unIO $ runFinalizers fin) s of
           (# s1, _wk #) -> (# s1, () #)
     NoFinalizers -> error "nonsense"

The main difference seems to be that mkWeak# does not take unlifted types since 9.x, but I don't know what I'm doing here really. I've also considered changing fin into \_ -> fin, but that seems more obviously wrong than the above

pillowtrucker commented 7 months ago

As mentioned in https://github.com/haskus/haskus-system/issues/3 — I think I have at least basic functionality working under ghc 9.8.1 now. Would you like me to try to refactor the changes to this repository and to haskus-system as a real PR ? https://github.com/haskus/packages/compare/master...pillowtrucker:haskus-packages:mine

pillowtrucker commented 7 months ago

haskus-ui, haskus-maths and haskus-calculus seem to have problems with https://gitlab.haskell.org/ghc/ghc/-/issues/18806, so I'm just replacing the macro with the expansion as per https://github.com/haskus/haskus-manual/blob/master/source/eadt/basics.rst, but letting the compiler infer what the signature actually is there

hsyl20 commented 7 months ago

Hello! Thanks for the nudge :D

I've pushed some fixes: I can now build locally with 8.10, 9.0, 9.2, 9.4, 9.6, 9.8

pillowtrucker commented 7 months ago

that's great :D thank you. I will test again with the new version

pillowtrucker commented 7 months ago

works great, cheers!