diff options
author | Simon Marlow <marlowsd@gmail.com> | 2018-09-28 14:27:22 +0200 |
---|---|---|
committer | Krzysztof Gogolewski <krz.gogolewski@gmail.com> | 2018-09-28 14:27:22 +0200 |
commit | df67f95b2fc1c8b7200d98643e76c5feab4ed876 (patch) | |
tree | d383d3b324b4351b23afbf8e4202d6999585c042 /testsuite/tests/rts/KeepCafsMain.hs | |
parent | c89297ee41f218a92870563d881548754c3d89e4 (diff) | |
download | haskell-df67f95b2fc1c8b7200d98643e76c5feab4ed876.tar.gz |
Add -fkeep-cafs
Summary:
I noticed while playing around with
https://github.com/fbsamples/ghc-hotswap/ that the main binary needs to
have a custom main function to set `config.keep_cafs = true` when
initialising the runtime. This is pretty annoying, it means an extra
C file with some cryptic incantations in it, and a `-no-hs-main` flag.
So I've replaced this with a link-time flag to GHC, `-fkeep-cafs` that
does the same thing.
Test Plan:
New unit test that tests for the RTS's GC'd CAFs assertion, and also
the -keep-cafs flag.
Reviewers: bgamari, osa1, erikd, noamz
Reviewed By: osa1
Subscribers: rwbarton, carter
Differential Revision: https://phabricator.haskell.org/D5183
Diffstat (limited to 'testsuite/tests/rts/KeepCafsMain.hs')
-rw-r--r-- | testsuite/tests/rts/KeepCafsMain.hs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/testsuite/tests/rts/KeepCafsMain.hs b/testsuite/tests/rts/KeepCafsMain.hs new file mode 100644 index 0000000000..2f6ad5a4f9 --- /dev/null +++ b/testsuite/tests/rts/KeepCafsMain.hs @@ -0,0 +1,25 @@ +module Main (main) where + +import Foreign +import GHCi.ObjLink +import System.Mem +import System.Exit + +foreign import ccall "dynamic" + callGetX :: FunPtr (IO Int) -> IO Int + +main :: IO () +main = do + initObjLinker DontRetainCAFs + let + loadAndCall obj = do + loadObj obj + resolveObjs + r <- lookupSymbol "getX" + case r of + Nothing -> die "cannot find getX" + Just ptr -> callGetX (castPtrToFunPtr ptr) >>= print + unloadObj obj + performGC + loadAndCall "KeepCafs1.o" + loadAndCall "KeepCafs2.o" |