Garbage collection

Simon Peyton Jones simonpj at
Wed Nov 19 13:06:42 UTC 2014

I'm reluctant to invest much effort in a hack, when we know we are going to create an SPT anyway.  Let's just go for it!  Even if there are no TypeReps in it yet.

Actually, I think that each entry in the SPT should have just two fields: something like
    Key, Value

where "Key" is whatever we use as the "stable name" for the static value: a string, or something like that.

The "Value" is a full Haskell value, just a pointer into the heap (these are the new GC roots).  The value has type Dynamic, or something very like it:

  data Dynamic where
     MkDyn :: TTypeRep a -> a -> Dynamic

Maybe the library Dynamic isn't quite what we need; e.g we may want to include the Key too:

   data SptEntry where
     SPT :: String -> TTypeRep a -> a -> SptEntry

But regardless, the SPT itself is a simple key/value table, and all the interesting structure in in the Values in Haskell-land.

Now all we need is
- To build top-level bindings for the SPT Entries.
  These bindings are presumably created by the desugarer,
  as it desugars uses of 'static'

- To collect them in an SPT
  This is presumably done in a similar way to the mkModuleInit stuff
  in StgCmm.codeGen


| -----Original Message-----
| From: 0xbadcode at [mailto:0xbadcode at] On Behalf Of
| Mathieu Boespflug
| Sent: 18 November 2014 18:03
| To: Simon Peyton Jones
| Cc: Facundo Domínguez; ghc-devs at; Mathieu Boespflug
| Subject: Re: Garbage collection
| On 18 November 2014 16:59, Simon Peyton Jones <simonpj at>
| wrote:
| > Isn't it this simple: the Static Pointer Table must be a source of
| roots for the garbage collector.  Of course!  An item in the SPT may be
| looked up at any time.
| As Facundo says, the existence of the SPT would solve everything. But
| we haven't quite figured out how to create a simple SPT yet, so were
| wondering whether there is an existing generic mechanism to register
| new GC roots.
| I guess there is no better solution but to just create an SPT, even if
| we don't yet have TypeRep's to put in it.
| With an SPT, and under the assumption of everyone sharing the same
| binary in the distributed system, there will be no need to hold on to
| *all* CAF's - just the ones that are known to have a StaticPointer
| created for them at compile time.

More information about the ghc-devs mailing list