diff options
| author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2021-02-02 15:31:45 +0100 |
|---|---|---|
| committer | Andreas Klebinger <klebinger.andreas@gmx.at> | 2021-02-04 13:44:49 +0100 |
| commit | aaf26d0d0ce4449dffa5ac24836c636075252e9c (patch) | |
| tree | 39d22a76bf21bcc96cbaacc0f903a750e5ae02e8 /ghc | |
| parent | 34a8a0e4cf188a30d2b4b65909f24185c80d071e (diff) | |
| download | haskell-wip/andreask/runRW_fix.tar.gz | |
Make unsafeDupablePerformIO have a lazy demandwip/andreask/runRW_fix
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
Diffstat (limited to 'ghc')
0 files changed, 0 insertions, 0 deletions
