Question about correctly tracing NF using ghc-heap-views

I am trying to debug some memory issues in my code using ghc-heap-views package. I have an IORef Int (within my own custom channel data type where channel size is incremented/decremented on write/read to keep track of number of elements in the channel). Is reading it back using assertNF correct usage like shown below? First line is the actual decrement. Next two lines are for debugging.

atomicModifyIORef' sz (\x -> (x-1,()))
len <- readIORef sz
assertNFNamed "readChan" len

I get output like below on debugging (compiled with -O2 option):
…not in normal form: 1 thunks found:
_sel (_bh (…,…))

It looks like it is a black hole for now, not a full evaluated value. Am I approaching this debugging right? I am not sure I am approaching this right because atomicModifyIORef’ is supposed to strict in single type like Int which is what is being decremented here.

ghc-heap-views documentation and associated blog posts are sparse on such details. So, will appreciate pointers here.

1 Like