| Copyright | (C) 2026 Edward Kmett |
|---|---|
| License | UPL-1.0 AND BSD-3-Clause |
| Maintainer | Edward Kmett <ekmett@gmail.com> |
| Stability | experimental |
| Portability | MagicHash, UnboxedTuples; GHC 9.14.1 finalizer ABI |
| Safe Haskell | Unsafe |
| Language | Haskell2010 |
THC.Internal.Weak
Contents
Description
Adapt a raw IO action to GHC's original automatic finalizer entry point. Raw state transformers are unsafe; the runtime owns their guest execution.
Automatic finalizer execution
runWeakFinalizer :: (State# RealWorld -> (# State# RealWorld, a #)) -> IO () Source #
Run an original State# RealWorld -> (# State# RealWorld, a #) action
through GHC's automatic finalizer policy, discarding its lifted result
without evaluating it. Each invocation runs the action once; the action
remains reusable. This does not claim or retire a weak registration.
GHC labels the executing thread, reports action exceptions to its current finalizer exception handler, and ignores exceptions thrown by that handler. The handler is read when an exception occurs, not when this action is built. Callers must supply a genuine IO state transformer and retain its owning runtime context throughout execution; state tokens must not be fabricated.