Skip to content

All fields of CgState are lazy because of getHeapUsage

Forcing the CgState currently leads to a loop because getHeapUsage uses a fixpoint in order to pass the amount of heap used whilst generating code for the body into the function which generates the body.

This leads to thunk accumulations in the other fields which are hard to get rid of because you have to be careful where you force CgState, ie, make sure you're not inside a call to getHeapUsage.

There is a note which was pointed out to me by @AndreasK (Note [cgBind rec]) which claims that in the past there used to be more of this knot-tying going on which was removed in order to make FCode "strict" but that appears not to mean "strict in the state" unless things have regressed since then. It seems that getHeapUsage has been this way since the new code generator was merged in 12 years ago.

Proposal: Find a way to refactor getHeapUsage to avoid using a fixpoint and make fields of CgState strict.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information