Add -fghci-leak-check to check for space leaks
ClosedPublic

Authored by simonmar on May 2 2018, 5:17 AM.

Details

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

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
simonmar created this revision.May 2 2018, 5:17 AM
simonmar requested review of this revision.May 2 2018, 6:58 AM
simonmar updated this revision to Diff 16277.May 3 2018, 4:41 AM

update test output

bgamari accepted this revision.May 3 2018, 1:19 PM

This is a neat trick.

The patch looks good to me.

docs/users_guide/ghci.rst
2028

Thanks for the documentation.

This revision is now accepted and ready to land.May 3 2018, 1:19 PM
This revision was automatically updated to reflect the committed changes.
osa1 added a subscriber: osa1.EditedMay 10 2018, 6:28 AM

It seems like this broke the build. ./validate output of 5fe6aaa375:

Unexpected failures:
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/prog010/ghci.prog010.run       ghci.prog010 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/prog012/prog012.run            prog012 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/prog001/prog001.run            prog001 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/prog002/prog002.run            prog002 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/scripts/ghci025.run            ghci025 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/scripts/ghci038.run            ghci038 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/prog003/prog003.run            prog003 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/scripts/ghci058.run            ghci058 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/scripts/T6106.run              T6106 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci/should_run/T13825-ghci.run     T13825-ghci [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci.debugger/scripts/print007.run  print007 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci.debugger/scripts/break008.run  break008 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci.debugger/scripts/break009.run  break009 [bad stdout] (ghci)
   /tmp/ghctest-h_kvl_sd/test   spaces/./ghci.debugger/scripts/break026.run  break026 [bad stdout] (ghci)

Example failure:

Actual stdout output differs from expected:
diff -uw "./ghci/scripts/ghci038.run/ghci038.stdout.normalised" "./ghci/scripts/ghci038.run/ghci038.run.stdout.normalised"
--- ./ghci/scripts/ghci038.run/ghci038.stdout.normalised        2018-05-10 14:28:37.733144714 +0300
+++ ./ghci/scripts/ghci038.run/ghci038.run.stdout.normalised    2018-05-10 14:28:37.733144714 +0300
@@ -1,3 +1,7 @@
+-fghci-leak-check: HomeModInfo for Main is still alive!
+-fghci-leak-check: ModIface is still alive!
+-fghci-leak-check: ModDetails is still alive!
+-fghci-leak-check: Linkable is still alive!
 import Prelude -- implicit
 import Prelude
 == map in scope due to explicit 'import Prelude'
*** unexpected failure for ghci038(ghci)

Sorry! Of course it broke things because I haven't committed the fix for these yet. D'oh. I'll back it out.