touch# primitive

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

touch# primitive

Daniel Cartwright
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?

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: touch# primitive

Ben Lippmeier-2

On 19 Sep 2018, at 1:07 am, Daniel Cartwright <[hidden email]> wrote:

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?

It’s used to place a dependency on a computed value, to prevent the GHC simplifier from moving the binding that computes it around. This is sometimes helpful when writing array fusion systems.

I mentioned it briefly in 

Cheers,
Ben.


_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: touch# primitive

Ben Gamari-2
In reply to this post by Daniel Cartwright
Daniel Cartwright <[hidden email]> 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

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs

signature.asc (497 bytes) Download Attachment