Way to prevent a value from being garbage collected too early

Folks, I need a little help, I remember I had read some where that, there's a function to fake a use of a value, so it won't be garbage collected too early, as GHC has an optimization to forget a value as early as possible. But I can't remember the function name or even the keyword to google it out, hint me please! Best regards, Compl

You're looking for the `touch` function. I don't remember where it lives. I believe there's also a new and improved replacement whose name I don't remember. On Wed, May 13, 2020, 2:47 AM YueCompl via Haskell-Cafe < haskell-cafe@haskell.org> wrote:
Folks,
I need a little help, I remember I had read some where that, there's a function to fake a use of a value, so it won't be garbage collected too early, as GHC has an optimization to forget a value as early as possible. But I can't remember the function name or even the keyword to google it out, hint me please!
Best regards, Compl
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Thanks! I found `touch` in `Control.Monad.Primitive` , and repa even requires an array element type to implement `Elt` which mainly asking for the `touch` method. It's interesting to know there's even more improvement on it.
On 2020-05-13, at 14:52, David Feuer
wrote: You're looking for the `touch` function. I don't remember where it lives. I believe there's also a new and improved replacement whose name I don't remember.
On Wed, May 13, 2020, 2:47 AM YueCompl via Haskell-Cafe
mailto:haskell-cafe@haskell.org> wrote: Folks, I need a little help, I remember I had read some where that, there's a function to fake a use of a value, so it won't be garbage collected too early, as GHC has an optimization to forget a value as early as possible. But I can't remember the function name or even the keyword to google it out, hint me please!
Best regards, Compl
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

The primitive is `touch#` (https://www.stackage.org/haddock/lts-15.12/base-4.13.0.0/GHC-Exts.html#v:tou...) It's quite fragile (e.g. can be optimized away or moved), so we're trying to replace it with something else. See https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/with-combinator On 13/05/2020 09:03, YueCompl via Haskell-Cafe wrote:
Thanks! I found `touch` in `Control.Monad.Primitive` , and repa even requires an array element type to implement `Elt` which mainly asking for the `touch` method.
It's interesting to know there's even more improvement on it.
On 2020-05-13, at 14:52, David Feuer
mailto:david.feuer@gmail.com> wrote: You're looking for the `touch` function. I don't remember where it lives. I believe there's also a new and improved replacement whose name I don't remember.
On Wed, May 13, 2020, 2:47 AM YueCompl via Haskell-Cafe
mailto:haskell-cafe@haskell.org> wrote: Folks,
I need a little help, I remember I had read some where that, there's a function to fake a use of a value, so it won't be garbage collected too early, as GHC has an optimization to forget a value as early as possible. But I can't remember the function name or even the keyword to google it out, hint me please!
Best regards, Compl
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On Wed, 13 May 2020, Sylvain Henry wrote:
It's quite fragile (e.g. can be optimized away or moved), so we're trying to replace it with something else. See https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/with-combinator
I remember that the fragility due to optimization is quite a problem. I found that creating a StablePtr is reliable, however.

On May 13, 2020 5:00:08 AM EDT, Henning Thielemann
On Wed, 13 May 2020, Sylvain Henry wrote:
It's quite fragile (e.g. can be optimized away or moved), so we're trying to replace it with something else. See https://gitlab.haskell.org/ghc/ghc/-/wikis/proposal/with-combinator
I remember that the fragility due to optimization is quite a problem. I
found that creating a StablePtr is reliable, however. _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
Yes, but do note that the latter of significantly more expensive. Cheers, — Ben
participants (5)
-
Ben Gamari
-
David Feuer
-
Henning Thielemann
-
Sylvain Henry
-
YueCompl