unsafeInterleaveIO: handle I/O failure a little bit more gracefully
\section[PrelUnsafe]{Module @PrelUnsafe@}
These functions have their own module because we definitely don't want
\section[PrelUnsafe]{Module @PrelUnsafe@}
These functions have their own module because we definitely don't want
+them to be inlined. The reason is that we may end up turning an action
+into a constant when it is not:
+
+ new :: IORef Int
+ new =
+ let
+ foo = unsafePerformIO getNextValue
+ in
+ newIORef foo
+
+If unsafePerformIO is inlined here, the application of getNextValue to the realWorld#
+token might be floated out, leaving us with
+
+ foo' = getNextValue realWorld#
+
+ new :: IORef Int
+ new = newIORef foo'
+
+which is not what we want.
\begin{code}
{-# OPTIONS -fno-implicit-prelude #-}
\begin{code}
{-# OPTIONS -fno-implicit-prelude #-}
unsafeInterleaveIO :: IO a -> IO a
unsafeInterleaveIO (IO m) = IO ( \ s ->
let
unsafeInterleaveIO :: IO a -> IO a
unsafeInterleaveIO (IO m) = IO ( \ s ->
let
+ res =
+ case m s of
+ IOok _ r -> r
+ IOfail _ e -> error ("unsafeInterleaveIO: I/O error: " ++ show e ++ "\n")
-{-# GENERATE_SPECS _trace a #-}
trace :: String -> a -> a
trace string expr
= unsafePerformIO (
trace :: String -> a -> a
trace string expr
= unsafePerformIO (
where
sTDERR = (``stderr'' :: Addr)
\end{code}
where
sTDERR = (``stderr'' :: Addr)
\end{code}