Skip to content

Another approach to keepAlive#

Ben Gamari requested to merge wip/keepAlive-optionH into master

This is implements Option H for fixing #17760 (closed) as described in the wiki page. Specifically, we add a family of functions supplanting most uses of the existing touch# primitive:

keepAliveUnlifted#
        :: forall (arg :: TYPE 'UnliftedRep) r.
           arg
        -> (State# RealWorld -> (# State# RealWorld, r #))
        -> State# RealWorld
        -> (# State# RealWorld, r #)

keepAliveLifted#
        :: forall (arg :: TYPE 'LiftedRep) r.
           arg
        -> (State# RealWorld -> (# State# RealWorld, r #))
        -> State# RealWorld
        -> (# State# RealWorld, r #)

These are implemented in GHC.Magic as standard Haskell bindings with phased inlinings which interact with simplifier logic to disable the case-of-bottom transformation during phase 0. This ensures that touch# occurrences are not dropped while allowing the simplifier to unbox freely.

Fixes #17760 (closed). Fixes #17746. Fixes #14375 (closed).

Edited by Ben Gamari

Merge request reports