Skip to content

Crash & hang with non-moving GC & FFI on GHC 9.6.3

Summary

I've recently started switching from GHC 8 to GHC 9, and with the inclusion of GHC 9.6.3 in Stackage Nightly, I was able to rule out everything else and pin down a new crash.

Steps to reproduce

In Windows 10 x64, with Stack set up with the resolver nightly-2023-10-01, this 100% reliably has fatal problems on my system.

In a new, empty folder, create t.hs:

module Main(main) where
  import Data.Int

  type INT     = Int32
  type WINBOOL = Int32

  foreign import capi safe "winuser.h SetCursorPos" c_SetCursorPos :: INT -> INT -> IO WINBOOL

  main :: IO ()
  main = do
    putStrLn "Mark 1"
    c <- getChar
    if c == 'x' then do
      _ <- c_SetCursorPos 0 0
      pure ()
    else
      pure ()
    putStrLn "Mark 2"

And h.bat (assuming stack is in your path):

@rd /s/q _temp 2>nul
@del *.exe 2>nul

@md _temp 2>nul

@stack ghc -- -threaded -XCApiFFI -tmpdir _temp -odir _temp -hidir _temp t.hs
@ren t.exe t-works-normally.exe

@stack ghc -- -threaded -with-rtsopts --nonmoving-gc -XCApiFFI -tmpdir _temp -odir _temp -hidir _temp t.hs
@ren t.exe t-crashes-immediately.exe

@stack ghc -- -with-rtsopts --nonmoving-gc -XCApiFFI -tmpdir _temp -odir _temp -hidir _temp t.hs
@ren t.exe t-hangs-after-pressing-return.exe

@exit /b

Expected behavior

All three .exe files should run, first display Mark 1, then after pressing return display Mark 2.

Actual behavior

t-works-normally.exe works as intended.

t-crashes-immediately.exe segfaults immediately (before getChar is evaluated)

t-hangs-after-pressing-return.exe mostly works, but never terminates after Mark 2.

Environment

  • GHC version used: 9.6.3 (Stackage Nightly 2023-10-01)

Optional:

  • Operating System: Windows 10 x64
  • System Architecture: -
Edited by Hai / @BestYeen
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information