How can I help SpecConstr in GHC?
Asked Answered
R

2

12

I'm using GHC 7.4.1 to try to compile a program that uses Repa. But partway through compilation, I'm running out of memory. With ghc -v, I can see that it's getting stuck in the SpecConstr phase.

SpecConstr is one of GHC's Core-to-Core transformations. Simon Peyton Jones has a nice description here, and there's some code here, but it's pretty slow-going for me since I'm not very familiar with the inner workings of GHC.

I'd like to be able to help the compiler along somehow - is there a way to tell where it's getting stuck? Alternatively, is there a way to limit memory usage in this phase until I can recompile on a bigger machine?

Thanks, Chad

Rosinweed answered 13/4, 2012 at 18:2 Comment(3)
On a whim, I removed a computeUnboxedS, and now it compiles just fine. Still no idea why, though.Rosinweed
if you post your code, we might be able to tell you why. Sight unseen, I'm going to guess you bogoned the teutonic matrix, and the jeffries tubes were hyper-ventilated.Supinate
Thanks, unfortunately I can't post the whole thing, and it's not clear how to distill to a minimal case. I had hoped there might be a general procedure for tracking what part of SpecConstr is causing the blowup. Maybe heap profiling GHC itself, or something like that.Rosinweed
O
5

You can try compiling with the flags -fspec-constr-threshold=n and -fspec-constr-count=n. More details are in the GHC docs. With 7.4.1, the defaults are n=200 for the threshold and n=3 for the count.

Without seeing code, though, it's possible you're running into this bug. In which case you may need to entirely disable the specconstr pass if the above options aren't sufficient.

Ochrea answered 13/4, 2012 at 21:54 Comment(1)
Nice, thank yoU! I don't see any references to the flags you mention, but somehow I had tried -fno-specialise but overlooked -fspec-constr entirely.Rosinweed
A
4

In addition to John L's answer, ensure you compile with the flag -fno-liberate-case. The liberate case transform tends to cause code-blowup, which then makes SpecConstr's job harder.

Antagonism answered 15/4, 2012 at 12:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.