Skip to content

Program develops space leak with -fprof-auto

This program seems to use constant memory when compiled with only -prof, but it uses increasing amounts of memory when compiled with -prof and -fprof-auto. I observed the behavior with GHC 8.0.1, 7.10.3, 7.8.4, 7.6.3, and 7.4.2, but not 7.0.4 (with -auto-all).

import System.Environment

main :: IO ()
main = do
  n <- (read . head) `fmap` getArgs
  case f [0..(n::Int)] 0 of
    (xs, s) -> print xs >> print s

f :: [Int] -> Int -> ([Int], Int)
f [] s = ([], s)
f (x:xs) s =
  let (xs', s') = f xs (x + s)
  in (x + s : xs', s')
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.0.1

$ ghc Main.hs -prof
[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main ...

$ /run/current-system/sw/bin/time ./Main 5000000 > /dev/null
2.80user 0.01system 0:02.82elapsed 100%CPU (0avgtext+0avgdata 6028maxresident)k
0inputs+0outputs (0major+661minor)pagefaults 0swaps
$ ghc Main.hs -prof -fprof-auto
[1 of 1] Compiling Main             ( Main.hs, Main.o )
Linking Main ...

$ /run/current-system/sw/bin/time ./Main 5000000 > /dev/null
4.03user 0.35system 0:04.38elapsed 100%CPU (0avgtext+0avgdata 1574348maxresident)k
0inputs+0outputs (0major+392857minor)pagefaults 0swaps

[[Image(no-fprof-auto.png)]] [[Image(fprof-auto.png)]]

Trac metadata
Trac field Value
Version 7.4.2
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Profiling
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information