-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs for unsafeThaw
should warn about the same things that unsafePerformIO
#139
Comments
Proposed new haddocks for
I'm currently unclear on whether |
Hrmm. This is a good start! What are the analogous docs / exposition for unsafe perform IO aren't the safety requirements more like unsafe dupable perform IO for On Monday, October 3, 2016, Francesco Mazzoli [email protected]
|
I don't think it does. If you are sure that you do no further mutation of the mutable buffer, it doesn't matter if freezing it gets inlined. |
We definitely need a more specific warning, if one is deemed necessary, because I don't think this case is particularly similar to |
Yeah. This stuff is really subtle. On Wednesday, October 5, 2016, dolio [email protected] wrote:
|
replicateM_ 5 $ do
vm <- noinline V.unsafeThaw (V.generate 1 id)
x <- VM.read vm 0
print x
VM.write vm 0 (100 + x) will produce: 0
100
200
300
400 regardless of any ghc flags that I've tried. See my comment for more info on the ghc ticket: https://gitlab.haskell.org/ghc/ghc/-/issues/12656#note_347996 If we are to improve the documentation we need to figure out the exact guidelines for users, instead of just "try sprinkle some ghc flags and see if it helps" |
I don't think so. It's GHC optimizer creating/destroying sharing which is generally safe for pure code but readily apparent once you start mutating things in place. Bug happens and disappears at whim of optimizer so it's expected that seemingly equivalent programs will have different behaviors. Here's one that does have such behavior: import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
main :: IO ()
main = foo >> foo
foo :: IO ()
foo = do
indexVector <- V.unsafeThaw $ V.generate 10 id
x <- VM.read indexVector 5
VM.write indexVector 5 (x * x)
print x
After some thinking I come to conclusion that mutating vector after All in all attempts to modify vector after |
🤣 I think we should include this sentence verbatim into haddock. |
It now explains dangers of unsafeThaw. Fixes haskell#139
It now explains dangers of unsafeThaw. Fixes #139
It now explains dangers of unsafeThaw. Fixes #139
Everything that the docs for
unsafePerformIO
say regardingNOINLINE
,-fno-cse
, and-fno-full-laziness
applies tounsafeThaw
. In fact, I think it's even easier to fall into weird behavior withunsafeThaw
-- for example this program is unsafe:(See also https://ghc.haskell.org/trac/ghc/ticket/12656#comment:9 for related woes)
The text was updated successfully, but these errors were encountered: