stepcut / plugins

Dynamic linking and runtime evaluation of Haskell, and C, including dependency chasing and package resolution.
GNU Lesser General Public License v2.1
52 stars 17 forks source link

Update for 9.6.2 #21

Open pillowtrucker opened 1 year ago

pillowtrucker commented 1 year ago

@drvink @Kleidukos this builds now and make, load and unsafeEval mostly work, even on a relatively complicated test:

main = do fn <- unsafeEval_ "(\\x -> (x,x::Int))" [] ["-O2","-v","-g","-threaded","-with-rtsopts=-N"] [] [] :: IO (Either [String] (Int -> (Int,Int)))
          case fn of
            Right fn -> putStrLn $ show $ fn 8
            Left err -> putStrLn $ "error top level"
          whoop <- atomically $ newTMVar 1
          whoop2 <- atomically $ newTMVar 2
          whoop3 <- atomically $ newTMVar 3
--          when (isJust fn) $ putStrLn $ show $ (fromRight fn) 7
          danger <- unsafeEval_ "(\\w -> (atomically $ takeTMVar w) >>= putStrLn . show >> threadDelay 5000000 >> (atomically $ putTMVar w 5)) :: TMVar Int -> IO ()" ["Control.Concurrent.STM","Control.Concurrent.STM.TMVar","Control.Concurrent"] ["-O2","-v","-g","-threaded","-with-rtsopts=-N"] [] [] :: IO (Either [String] (TMVar Int -> IO ()))
          case danger of
            Right fn -> do
              tid <- forkIO $ fn whoop
              return ()
            Left err -> mapM putStrLn err >> return ()
--          hmm <- atomically $ readTMVar whoop2
--          putStrLn . show $ hmm
          threadDelay 2000000
          hmm2 <- atomically $ do
            hhhh <- tryTakeTMVar whoop
            case hhhh of
              Just ok -> return ok
              Nothing -> retry
          putStrLn . show $ hmm2

I'm getting a solid full terminal of warnings such as this though:

Symbol type mismatch.
Symbol stg_ap_pppppp_fast was defined by /home/wrath/.ghcup/ghc/9.6.2/lib/ghc-9.6.2/lib/../lib/x86_64-linux-ghc-9.6.2/rts-1.0.2/libHSrts-1.0.2.a to be a code symbol.
      yet was defined by <builtin> to be a data symbol.

I was getting those even on very basic tests and thought maybe it's because I had ghc flags different in my main project than in the evaled code, but they're the same even when I tested:

main = do fn <- unsafeEval "(\\x -> (x,x::Int))" [] :: IO (Maybe (Int -> (Int,Int)))
          when (isJust fn) $ putStrLn $ show $ (fromJust fn) 7
Kleidukos commented 1 year ago

oh wow that's wonderful, thanks a lot for this work!

arjunkathuria commented 8 months ago

Hi! Ran into this one today.

Does this build with GHC 9.2 and is mostly safe to use?

pillowtrucker commented 8 months ago

the other pull request might work better for 9.2 but I don't remember when the API changes were made. I don't know enough about the GHC API and to tell whether this is still safe. The code means exactly the same as it did before. Whether that still makes sense on the ABI level is another matter. I was hoping someone who knows this better would help debug it