From d52a9a6bbab0626fddecda6716afb8d18ae10338 Mon Sep 17 00:00:00 2001 From: sof Date: Sat, 5 Jul 1997 03:16:22 +0000 Subject: [PATCH] [project @ 1997-07-05 03:16:22 by sof] new module --- ghc/lib/ghc/UnsafeST.lhs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 ghc/lib/ghc/UnsafeST.lhs diff --git a/ghc/lib/ghc/UnsafeST.lhs b/ghc/lib/ghc/UnsafeST.lhs new file mode 100644 index 0000000..f4aa268 --- /dev/null +++ b/ghc/lib/ghc/UnsafeST.lhs @@ -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} + -- 1.7.10.4