Joachim Breitner | 21 Dec 11:16 2012
Picon

ghc-heap-view now with recursive pretty-printing

Hi,

I get the impression that blogs and planet.haskell.org are the best way
to disseminate information about new tools any more. Maybe a part of the
earlier importance has been taken over by GooglePlus, but not all,
leaving both blogs and GooglePlus less useful individually?

Anyways, I’d like to tell you about a feature of ghc-heap-view that I
have blogged about¹, namely the possibility to inspect heap values
recursively in GHCi or in your programs, including thunks, the
references between them and sharing:

Prelude> :script /home/jojo/.cabal/share/ghc-heap-view-0.4.0.0/ghci
Prelude> let x = [1..10]
Prelude> x
[1,2,3,4,5,6,7,8,9,10]
Prelude> :printHeap x
_bh [S# 1,S# 2,S# 3,S# 4,S# 5,S# 6,S# 7,S# 8,S# 9,S# 10]

Note that the tools shows us that the list is a list of S# constructors,
and also that it is still hidden behind a blackhole. After running
System.Mem.performGC, this would disappear.

Prelude> let x = Just (1 + 1)
Prelude> :printHeap x
Just _bco
Prelude> x
Just 2
Prelude> System.Mem.performGC
Prelude> :printHeap x
(Continue reading)

Thomas Schilling | 25 Dec 16:58 2012

Re: ghc-heap-view now with recursive pretty-printing

On 21 December 2012 11:16, Joachim Breitner <mail <at> joachim-breitner.de> wrote:
> Prelude> :script /home/jojo/.cabal/share/ghc-heap-view-0.4.0.0/ghci
> Prelude> let x = [1..10]
> Prelude> x
> [1,2,3,4,5,6,7,8,9,10]
> Prelude> :printHeap x
> _bh [S# 1,S# 2,S# 3,S# 4,S# 5,S# 6,S# 7,S# 8,S# 9,S# 10]
>
> Note that the tools shows us that the list is a list of S# constructors,
> and also that it is still hidden behind a blackhole. After running
> System.Mem.performGC, this would disappear.

Why do you call it a "blackhole"?  I assume you mean a thunk that has
been evaluated and updated with its value.  The commonly used term for
this is "indirection".  A blackhole is used to detect when a thunk's
value depends on itself (e.g., in "let x = id x in ..." the thunk for
x may get turned into a black hole).

It's a minor thing, but I think it's a good idea to stick to existing
terminology. Otherwise, it looks like a useful tool. Eventually, we
probably want an interactive graph where we can click a node to
evaluate it (or to show/hide children nodes).

--
Push the envelope. Watch it bend.
Joachim Breitner | 25 Dec 19:09 2012
Picon

Re: ghc-heap-view now with recursive pretty-printing

Hi,

Am Dienstag, den 25.12.2012, 16:58 +0100 schrieb Thomas Schilling:
> On 21 December 2012 11:16, Joachim Breitner <mail <at> joachim-breitner.de> wrote:
> > Prelude> :script /home/jojo/.cabal/share/ghc-heap-view-0.4.0.0/ghci
> > Prelude> let x = [1..10]
> > Prelude> x
> > [1,2,3,4,5,6,7,8,9,10]
> > Prelude> :printHeap x
> > _bh [S# 1,S# 2,S# 3,S# 4,S# 5,S# 6,S# 7,S# 8,S# 9,S# 10]
> >
> > Note that the tools shows us that the list is a list of S# constructors,
> > and also that it is still hidden behind a blackhole. After running
> > System.Mem.performGC, this would disappear.
> 
> Why do you call it a "blackhole"?  I assume you mean a thunk that has
> been evaluated and updated with its value.  The commonly used term for
> this is "indirection".  A blackhole is used to detect when a thunk's
> value depends on itself (e.g., in "let x = id x in ..." the thunk for
> x may get turned into a black hole).

I don’t call it a blackhole, GHC does :-). At least it is a closure of
type BLACKHOLE
http://hackage.haskell.org/trac/ghc/browser/includes/rts/storage/ClosureTypes.h#L61

I assume this is due to lazy blackholing or something, although it still
occurs with "ghci -fno-eager-blackholing"... strange.

> It's a minor thing, but I think it's a good idea to stick to existing
> terminology. Otherwise, it looks like a useful tool.
(Continue reading)


Gmane