ghc-heap-view-0.5.9: Extract the heap representation of Haskell values and thunks

Copyright(c) 2013 Joachim Breitner
LicenseBSD3
MaintainerJoachim Breitner <mail@joachim-breitner.de>
Safe HaskellNone
LanguageHaskell2010

GHC.AssertNF

Description

To avoid space leaks and unwanted evaluation behaviour, the programmer might want his data to be fully evaluated at certain positions in the code. This can be enforced, for example, by ample use of Control.DeepSeq, but this comes at a cost.

Experienced users hence use deepseq only to find out about the existence of space leaks and optimize their code to not create the thunks in the first place, until the code no longer shows better performance with deepseq.

This module provides an alternative approach: An explicit assertion about the evaluation state. If the programmer expect a certain value to be fully evaluated at a specific point of the program (e.g. before a call to writeIORef), he can state that, and as long as assertions are enabled, this statement will be checked. In the production code the assertions can be disabled, to avoid the run-time cost.

Synopsis

Documentation

assertNF :: a -> IO () Source #

The function assertNF checks whether its argument is fully evaluated and deeply evaluated. If this is not the case, a warning is printed to the standard output, giving the number of thunks found and printing the shape of the unevaluated object:

> let x = 1 + 2
> let y = (x,x)
> assertNF y
Parameter not in normal form: 2 thunks found:
let t1 = _bco
in (t1,t1)
> x
3
> assertNF y
>

assertNFNamed :: String -> a -> IO () Source #

In order to better identify the source of error messages from assertNF, this variant allows you to include a name that is printed in the output:

> assertNFNamed "y" y
y not in normal form: 2 thunks found:
let t1 = _bco
in (t1,t1)

assertNFHere :: Q Exp Source #

This function, when called as $assertNFHere in a module with -XTemplateHaskell enabled, will cause the current filename and position be included in the error message:

Parameter at Test.hs:18:1 not in normal form: 2 thunks found:
let t1 = _bco
in (t1,t1)

disableAssertNF :: IO () Source #

Invoke this function at the top of your main method to turn every call to assertNF and its variants to noops.

isNF :: a -> IO Bool Source #

A variant of assertNF that does not print anything and just returns True if the value is in normal form, or False otherwise. This function is not affected by disableAssertNF.