Opened 6 years ago

Closed 6 years ago

#5352 closed bug (fixed)

Very slow (nonterminating?) compilation if libraries compiled with -fexpose-all-unfoldings

Reported by: batterseapower Owned by: simonpj
Priority: normal Milestone:
Component: Compiler Version: 7.0.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


I built the libraries with -fexpose-all-unfoldings. The stage 1 compiler then failed to terminate within ~20 minutes on InstalledPackageInfo.hs and PackageDescription.hs. The memory usage of the compiler did not grow appreciably (at all?) during this time, which makes me suspect that the problem is a loop rather than the extra unfoldings leading to code bloat (somehow).

An example of an offending invocation is:

"inplace/bin/ghc-stage1"   -H64m -O -fasm    -package-name Cabal-1.11.2 -hide-all-packages -i -ilibraries/Cabal/cabal/. -ilibraries/Cabal/cabal/dist-install/build -ilibraries/Cabal/cabal/dist-install/build/autogen -Ilibraries/Cabal/cabal/dist-install/build -Ilibraries/Cabal/cabal/dist-install/build/autogen -Ilibraries/Cabal/cabal/.    -optP-include -optPlibraries/Cabal/cabal/dist-install/build/autogen/cabal_macros.h -package array- -package base- -package containers- -package directory- -package filepath- -package old-time- -package pretty- -package process- -package unix-  -fwarn-tabs -Wall -fno-ignore-asserts -XHaskell98 -XCPP -O -dcore-lint -fexpose-all-unfoldings -no-user-package-conf -rtsopts     -odir libraries/Cabal/cabal/dist-install/build -hidir libraries/Cabal/cabal/dist-install/build -stubdir libraries/Cabal/cabal/dist-install/build -hisuf hi -osuf  o -hcsuf hc -c libraries/Cabal/cabal/./Distribution/InstalledPackageInfo.hs -o libraries/Cabal/cabal/dist-install/build/Distribution/InstalledPackageInfo.o

The workaround is to build these two files with -O0.

Change History (5)

comment:1 Changed 6 years ago by batterseapower

This problem also manifests in these files as well:

  • libraries/Cabal/cabal/Distribution/Simple/Setup.hs
  • libraries/Cabal/cabal/Distribution/Simple/LocalBuildInfo.hs
  • libraries/Cabal/cabal/Distribution/Simple/GHC/IPI641.hs
  • libraries/Cabal/cabal/Distribution/Simple/GHC/IPI642.hs
  • libraries/Cabal/cabal/Distribution/Simple/PreProcess.o

This list is exhaustive. After compiling all these with -O0, the Cabal library will build OK.

comment:2 Changed 6 years ago by batterseapower

I think the problem is in the tidier because the post-float-in simplifed Core (of size 16895) is displayed fine if we do -ddump-simpl, but dumping the tidied output shows nothing, and -v never reports us getting further than Tidy.

OS X's sample tool indicates that the offending loop probably makes use of IntMap functions, particularly lookup.

It's somewhere within the TidyPgm search loop: tidying starts looping after the 5th iteration, with these new_ids:

    [Cabal-1.11.2:Distribution.InstalledPackageInfo.sourcePackageId{v rvl} [lidx[[RecSel]]]]
search []
    [$creadListPrec{v a1lk} [lid], $creadPrec{v a17F} [lid],
     $creadList{v a15u} [lid], $creadsPrec{v a13M} [lid]]
search [a_s3Xy{v} [lid]]
search [a_s2HK{v} [lid]]

comment:3 Changed 6 years ago by simonpj

Owner: set to simonpj

I'm fixing this.

comment:4 Changed 6 years ago by simonpj@…

commit 349b8bb23e16733875595b6db496080c8bebce49

Author: Simon Peyton Jones <>
Date:   Tue Aug 9 17:45:27 2011 +0100

    Make the free variable finder in TidyPgm work properly
    We were getting exponential behaviour by gathering free
    variables *both* from the unfolding *and* the RHS of
    a definition.  While unfoldings are of limited size this
    is merely inefficient.  But with -fexpose-all-unfoldings
    it becomes exponentially costly. Doh.
    Fixes Trac #5352.

 compiler/main/TidyPgm.lhs |   38 +++++++++++++++++++++++++-------------
 1 files changed, 25 insertions(+), 13 deletions(-)

comment:5 Changed 6 years ago by simonpj

Resolution: fixed
Status: newclosed

OK done. I don't quite know how add a test, so I'll just close. (Max, try it.)


Note: See TracTickets for help on using tickets.