Skip to content

Use lazyness for FastString's z-encoding memoization

Daniel Gröber (dxld) requested to merge DanielG/ghc:lazy-zenc into master

Having an IORef in FastString to memoize the z-encoded version is unecessary because there is this amazing thing Haskell can do natively, it's called "lazyness" :)

We simply remove the UNPACK and strictness annotations from the constructor field corresponding to the z-encoding, making it lazy, and store the (pure) z-encoded string there.

The only complication here is 'hasZEncoding' which allows cheking if a z-encoding was computed for a given string. Since this is only used for compiler performance statistics it's not exactly performance critical though.

To implement this we use the new ghc-heap library to look at the closure underlying the z-encoded string and check if it has been evaluated or not.

Merge request reports