From b7ffad2a80db06fa106c7ae6e9090ad117b5bc3c Mon Sep 17 00:00:00 2001
From: simonmar <unknown>
Date: Tue, 27 Jul 1999 11:12:05 +0000
Subject: [PATCH] [project @ 1999-07-27 11:12:05 by simonmar] add
 unofficial/undocumented function:

    mkWeakIORef :: IORef a -> IO () -> IO (Weak (IORef a))

for weak pointers to IORefs.  This avoids some of the problems with
inlining disturbing the semantics of mkWeak by making the weak key
point to the primitive MutVar instead of the box.
---
 ghc/lib/exts/IOExts.lhs | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/ghc/lib/exts/IOExts.lhs b/ghc/lib/exts/IOExts.lhs
index 04f539d43a38..b973fa6fa0f9 100644
--- a/ghc/lib/exts/IOExts.lhs
+++ b/ghc/lib/exts/IOExts.lhs
@@ -23,6 +23,8 @@ module IOExts
         , readIORef
         , writeIORef
 
+	, mkWeakIORef
+
 	, IOArray	-- instance of: Eq
 	, newIOArray
 	, boundsIOArray
@@ -71,6 +73,7 @@ import PrelHandle ( openFileEx, IOModeEx(..),
 		  )
 import PrelST
 import PrelArr
+import PrelWeak
 import PrelGHC
 import PrelHandle
 import PrelErr
@@ -109,6 +112,10 @@ newIORef v = stToIO (newVar v) >>= \ var -> return (IORef var)
 readIORef  (IORef var) = stToIO (readVar var)
 writeIORef (IORef var) v = stToIO (writeVar var v)
 #endif
+
+mkWeakIORef :: IORef a -> IO () -> IO (Weak (IORef a))
+mkWeakIORef r@(IORef (MutableVar r#)) f = IO $ \s ->
+  case mkWeak# r# r f s of (# s1, w #) -> (# s1, Weak w #)
 \end{code}
 
 \begin{code}
-- 
GitLab