diff --git a/ghc/lib/ghc/UnsafeST.lhs b/ghc/lib/ghc/UnsafeST.lhs new file mode 100644 index 0000000000000000000000000000000000000000..f4aa268f8445b3afd97473a3974f6b03cb78f961 --- /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} +