diff options
author | Simon Marlow <marlowsd@gmail.com> | 2018-05-02 11:01:13 +0100 |
---|---|---|
committer | Simon Marlow <marlowsd@gmail.com> | 2018-05-09 13:43:32 +0100 |
commit | 5fe6aaa3756cda654374ebfd883fa8f064ff64a4 (patch) | |
tree | 3b667e7100f20864a2133c3330543d74afa88ebf /ghc/GHCi/UI.hs | |
parent | ba6e445e1cf31957f2a327a73f9f66cfa7f24e26 (diff) | |
download | haskell-5fe6aaa3756cda654374ebfd883fa8f064ff64a4.tar.gz |
Add -fghci-leak-check to check for space leaks
Summary:
Space leaks in GHCi emerge from time to time and tend to come back again
after they get fixed. This is an attempt to limit regressions by
* adding a reliable detection for some classes of space leaks in GHCi
* turning on leak checking for all GHCi tests in the test suite, so that
we'll notice if the leak appears again.
The idea for detecting space leaks is quite simple:
* find some data that we expect to be GC'd later, make a weak pointer to it
* when we expect the data to be dead, do a `performGC` and then check
the status of the weak pointer.
It would be nice to apply this trick to lots of things in GHC,
e.g. ensuring that HsSyn is not retained after the desugarer, or
ensuring that CoreSyn from the previous simplifier pass is not retained.
Test Plan: validate
Reviewers: bgamari, simonpj, erikd, niteria
Subscribers: thomie, carter
GHC Trac Issues: #15111
Differential Revision: https://phabricator.haskell.org/D4658
Diffstat (limited to 'ghc/GHCi/UI.hs')
-rw-r--r-- | ghc/GHCi/UI.hs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ghc/GHCi/UI.hs b/ghc/GHCi/UI.hs index 349368b6d7..c97fb01033 100644 --- a/ghc/GHCi/UI.hs +++ b/ghc/GHCi/UI.hs @@ -134,6 +134,8 @@ import GHC.IO.Exception ( IOErrorType(InvalidArgument) ) import GHC.IO.Handle ( hFlushAll ) import GHC.TopHandler ( topHandler ) +import GHCi.Leak + ----------------------------------------------------------------------------- data GhciSettings = GhciSettings { @@ -1646,6 +1648,14 @@ loadModule' files = do -- require some re-working of the GHC interface, so we'll leave it -- as a ToDo for now. + hsc_env <- GHC.getSession + + -- Grab references to the currently loaded modules so that we can + -- see if they leak. + leak_indicators <- if gopt Opt_GhciLeakCheck (hsc_dflags hsc_env) + then liftIO $ getLeakIndicators hsc_env + else return (panic "no leak indicators") + -- unload first _ <- GHC.abandonAll lift discardActiveBreakPoints @@ -1653,7 +1663,10 @@ loadModule' files = do _ <- GHC.load LoadAllTargets GHC.setTargets targets - doLoadAndCollectInfo False LoadAllTargets + success <- doLoadAndCollectInfo False LoadAllTargets + when (gopt Opt_GhciLeakCheck (hsc_dflags hsc_env)) $ + liftIO $ checkLeakIndicators (hsc_dflags hsc_env) leak_indicators + return success -- | @:add@ command addModule :: [FilePath] -> InputT GHCi () |