Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In GHC.Prim, why can pointer operations fail with an unchecked exception?

Tags:

haskell

ghc

I'm doing a literature review about the use of pointers in functional languages and I came across the following comment in the GHC.Prim documentation:

reallyUnsafePtrEquality# :: a -> a -> Int#

Returns 1# if the given pointers are equal and 0# otherwise.

Warning: this can fail with an unchecked exception.

I understand that there are a lot of ways to misuse this function but why does it throw an exception?

like image 500
simon1505475 Avatar asked Oct 20 '25 15:10

simon1505475


1 Answers

Found the answer in the GHC source code: https://github.com/ghc/ghc/blob/master/compiler/prelude/primops.txt.pp#L3199-L3233

It turns out that it cannot throw an exception but the function is marked as throwing so that GHC won't move it.

like image 141
simon1505475 Avatar answered Oct 22 '25 03:10

simon1505475



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!