touch# primitive

Ben Gamari ben at
Wed Sep 19 14:00:02 UTC 2018

Daniel Cartwright <chessai1996 at> writes:

> in GHC.Prim, there is a primitive 'touch#'. It seems that it is used to
> keep pointers alive, and takes something of any runtime representation, and
> a State# RealWorld, but there's really no documentation on it, so my idea
> of what it does is just a guess. Can anyone explain what exactly it does?

Technically I think touch# is only useful when applied to something with
pointer runtime representation. However, you otherwise have nailed it.
Note, however, that touch# isn't entirely water-tight since the
simplifier can (at least as of GHC 8.2) transform your program in ways
that break the liveness guarantee provided by touch#; see #14346 for an
example. We have proposed a new primop, with#, to fix this (see #14375).


- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <>

More information about the ghc-devs mailing list