Some programs crash when runing REPL with --nonmoving-gc on Windows using GHC 9.8.1
Summary
To improve performance in REPL, we can turn on the --nonmoving-gc
option (see the related issue #24416).
However, on Windows, some programs will crash.
Steps to reproduce
Create a cabal project
test/
| test.cabal
\---app
Main.hs
test.cabal
cabal-version: 3.0
name: test
version: 0.1.0.0
build-type: Simple
common warnings
ghc-options: -Wall
executable test
import: warnings
main-is: Main.hs
build-depends: base ^>=4.19.0.0
, gloss >= 1.10 && <1.14
, vector == 0.13.1.0
, random >=1.1 && <1.3
, containers >= 0.5 && < 0.7
hs-source-dirs: app
default-language: Haskell2010
app/Main.hs
-- | Display "Hello World" in a window.
--
module Main where
import System.Random
import Data.Map
import Data.Vector
main :: IO ()
main = putStr "Hello World"
Type in MINGW
cabal repl test --repl-options="+RTS --nonmoving-gc -RTS"
GHCi crash
Chansey@Chansey-PC MINGW64 /e/work-pl/haskell/code/frp/yampa/test
$ cabal repl test --repl-options="+RTS --nonmoving-gc -RTS"
Build profile: -w ghc-9.8.1 -O1
In order, the following will be built (use -v for more details):
- test-0.1.0.0 (exe:test) (file app\Main.hs changed)
Preprocessing executable 'test' for test-0.1.0.0..
GHCi, version 9.8.1: https://www.haskell.org/ghc/ :? for help
[1 of 2] Compiling Main ( app\Main.hs, interpreted ) [Source file changed]
app\Main.hs:5:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘System.Random’ is redundant
except perhaps to import instances from ‘System.Random’
To import instances alone, use: import System.Random()
|
5 | import System.Random
| ^^^^^^^^^^^^^^^^^^^^
app\Main.hs:6:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Map’ is redundant
except perhaps to import instances from ‘Data.Map’
To import instances alone, use: import Data.Map()
|
6 | import Data.Map
| ^^^^^^^^^^^^^^^
app\Main.hs:7:1: warning: [GHC-66111] [-Wunused-imports]
The import of ‘Data.Vector’ is redundant
except perhaps to import instances from ‘Data.Vector’
To import instances alone, use: import Data.Vector()
|
7 | import Data.Vector
| ^^^^^^^^^^^^^^^^^^
Access violation in generated code when reading 0x10
Attempting to reconstruct a stack trace...
Frame Code address
* 0x21d490 0x13fdcae34 C:\env\haskell\ghc\ghc-9.8.1-x86_64-unknown-mingw32\bin\ghc-9.8.1.exe+0x17ae34
* 0x21d498 0x143997eee C:\env\haskell\ghc\ghc-9.8.1-x86_64-unknown-mingw32\bin\ghc-9.8.1.exe+0x3d47eee
* 0x21d4a0 0x6fef6b2d481
* 0x21d4a8 0x6fef6e5cba0
* 0x21d4b0 0x6fef6e5cc50
* 0x21d4b8 0x32
Error: cabal.exe: repl failed for exe:test from test-0.1.0.0. The build
process terminated with exit code 11
P.S. The above program might not crash on your side.
In order to reproduce, you have to add more code, such as import Graphics.Gloss
, picture
, main
.
For example:
module Main where
import Graphics.Gloss
import System.Random
import Data.Map
import Data.Vector
main :: IO ()
main
= display
(InWindow
"Hello World" -- window title
(400, 150) -- window size
(10, 10)) -- window position
white -- background color
picture -- picture to display
picture :: Picture
picture
= Translate (-170) (-20) -- shift the text to the middle of the window
$ Scale 0.5 0.5 -- display it half the original size
$ Text "Hello World" -- text to display
Expected behavior
Don't crash.
Environment
- GHC 9.8.1, cabal-install 3.10.2.1
- Windows 7/10