Memory leak in recursion when switching from -O1 to -O2
For example code see attachment.
When compiling with -O1 the code behaves as expected with each loop taking about the same amount of time.
At -O2 each iteration takes (nonlinear) more time than the last and leaks memory. It gets slow enough that I never bothered to let it run past 40 iterations since the slowdown seems to be exponential.
I initially hit the bug in code using a Set instead of list but turns out the issue can be reduced to an example with lists.
Removing either filter, pattern matching or changing the loop fixes the issue.
I tested it under the following conditions:
- Compiler flags: -fno-full-laziness/No flags
- Compiler versions: GHC 8.0.1 and 7.10.3e
- Operating Systems: Windows 10, Linux Mint
In every case -O1 works as expected with -O2 showing exponential slowdown with each iteration.