touch# primitive

Ben Gamari ben at smart-cactus.org
Wed Sep 19 14:00:02 UTC 2018


Daniel Cartwright <chessai1996 at gmail.com> 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).

Cheers,

- Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 487 bytes
Desc: not available
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20180919/12eda53e/attachment.sig>


More information about the ghc-devs mailing list