Skip to content
  • Andreas Klebinger's avatar
    b8d8f31e
    Make unsafeDupablePerformIO have a lazy demand · b8d8f31e
    Andreas Klebinger authored and Marge Bot's avatar Marge Bot committed
    When a user writes code like:
    
        unsafePerformIO $ do
            let x = f x
            writeIORef ref x
            return x
    
    We might expect that the write happens before we evaluate `f x`.
    Sadly this wasn't to case for reasons detailed in #19181.
    
    We fix this by avoiding the strict demand by turning:
    
        unsafeDupablePerformIO (IO m) = case runRW# m of (# _, a #) -> a
    
    into
    
        unsafeDupablePerformIO (IO m) = case runRW# m of (# _, a #) -> lazy a
    
    This makes the above code lazy in x. And ensures the side effect of the
    write happens before the evaluation of `f x`. If a user *wants* the code
    to be strict on the returned value he can simply use `return $! x`.
    
    This fixes #19181
    b8d8f31e
    Make unsafeDupablePerformIO have a lazy demand
    Andreas Klebinger authored and Marge Bot's avatar Marge Bot committed
    When a user writes code like:
    
        unsafePerformIO $ do
            let x = f x
            writeIORef ref x
            return x
    
    We might expect that the write happens before we evaluate `f x`.
    Sadly this wasn't to case for reasons detailed in #19181.
    
    We fix this by avoiding the strict demand by turning:
    
        unsafeDupablePerformIO (IO m) = case runRW# m of (# _, a #) -> a
    
    into
    
        unsafeDupablePerformIO (IO m) = case runRW# m of (# _, a #) -> lazy a
    
    This makes the above code lazy in x. And ensures the side effect of the
    write happens before the evaluation of `f x`. If a user *wants* the code
    to be strict on the returned value he can simply use `return $! x`.
    
    This fixes #19181
Loading