cvs commit: fptools/libraries/base/System IO.hs

Simon Marlow simonmar at microsoft.com
Wed Apr 21 11:11:51 EDT 2004


On 21 April 2004 10:01, Ross Paterson wrote:

> On Tue, Apr 20, 2004 at 08:52:19AM -0700, Simon Marlow wrote:
>> simonmar    2004/04/20 08:52:19 PDT
>> 
>>   Modified files:
>>     libraries/base/System IO.hs
>>   Log:
>>   New version of fixIO which does eager blackholing.
> 
> Is that different from the version Hugs uses:
> 
> 	fixIO :: (a -> IO a) -> IO a
> 	fixIO f = do
> 	    ref <- newIORef (throw NonTermination)
> 	    result <- f (unsafePerformIO (readIORef ref))
> 	    writeIORef ref result
> 	    return result
> 
> and is unsafeInterleaveIO different from return . unsafePerformIO?

I'm glad you asked that, because Simon & I had a discussion yesterday
which shed some light on exactly this point.  The meaning of
unsafeInterleaveIO is different from return.unsafePerformIO.  Here's an
example:

    f x = do print "foo"
             r <- unsafeInterleaveIO (print "bar" >> return 3)
             r `seq` return ()

the question is, is it valid for the compiler to transform this into

    k = unsafePerformIO (print "bar" >> return 3)
    f x = do print "foo"
             r <- return k
             r `seq` return ()

we don't want this transformation to be valid.  In fact,
unsafeInterleaveIO is a "safer" version of unsafePerformIO.

In Hugs, of course you won't run into problems by defining
unsafeInterleaveIO as return.unsafePerformIO, but in GHC we would if we
also allowed it to be inlined.

Cheers,
	Simon


More information about the Cvs-libraries mailing list