[project @ 1997-07-05 03:16:22 by sof]
authorsof <unknown>
Sat, 5 Jul 1997 03:16:22 +0000 (03:16 +0000)
committersof <unknown>
Sat, 5 Jul 1997 03:16:22 +0000 (03:16 +0000)
new module

ghc/lib/ghc/UnsafeST.lhs [new file with mode: 0644]

diff --git a/ghc/lib/ghc/UnsafeST.lhs b/ghc/lib/ghc/UnsafeST.lhs
new file mode 100644 (file)
index 0000000..f4aa268
--- /dev/null
@@ -0,0 +1,45 @@
+%
+% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
+%
+\section[UnsafeST]{Unsafe ST operations}
+
+VERY IMPORTANT!  This module must be compiled without "-O".  If you
+compile it with "-O" then the inlinings of the unsafe ST operators are exposed.
+It turns out that exposing these inlininings can lead to unsound transformations,
+such as generating a MutVar only once rather than once each call to unsafePerformIO.
+
+\begin{code}
+{-# OPTIONS -fno-implicit-prelude -Onot #-}
+\end{code}
+
+
+\begin{code}
+module UnsafeST(
+       unsafeInterleaveST,
+       unsafePerformPrimIO,
+       unsafeInterleavePrimIO
+  )  where
+
+import STBase
+import PrelBase
+import GHC
+
+
+unsafeInterleaveST :: ST s a -> ST s a
+unsafeInterleaveST (ST m) = ST $ \ s ->
+    let
+       (r, new_s) = m s
+    in
+    (r, s)
+
+unsafePerformPrimIO    :: PrimIO a -> a
+       -- We give a fresh definition here.  There are no
+       -- magical universal types kicking around.
+unsafePerformPrimIO (ST m)
+  = case m (S# realWorld#) of
+      (r,_) -> r
+
+unsafeInterleavePrimIO :: PrimIO a -> PrimIO a
+unsafeInterleavePrimIO = unsafeInterleaveST
+\end{code}
+