DataCon tag value convention

Vladislav Zavialov vladislav at
Wed Feb 12 20:01:07 UTC 2020

The globally unique tag for data constructors already exists, it’s a pointer to the StgInfoTable. You can observe it using getClosureRaw from GHC.HeapView


Prelude GHC.HeapView> getClosureRaw Nothing

Here, the globally unique tag is 0x0000000107fd8e38.

Note that newtype constructors do not get their own tag because newtypes guarantee that they do not change the underlying representation of data.

I’ve discovered the existence of such a tag only recently (Alexander Vershilov pointed it out to me), so I cannot say if it’s a reliable way to identify data constructors. For example, it is definitely not stable across several runs of the same binary. However, within a single run, it seems to work.

- Vlad

> On 12 Feb 2020, at 21:57, Csaba Hruska <csaba.hruska at> wrote:
> Hello,
> In theory could GHC codegen work if every data constructor in the whole program  have a globally unique tag value instead of starting from 1 for each algebraic data type?
> Would this break any GHC design decision?
> Regards,
> Csaba
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at

More information about the ghc-devs mailing list