Re: `StablePtr` in `ST`

2019-08-22 Thread Matthew Farkas-Dyck
My colleague responded but said it was rejected from ghc-devs. Message follows:

On 21/08/2019, Jon Purdy  wrote:
> Our use case is unsafeCoercing a mutable reference to use as a key in an
> IntMap. Our reasoning is that coercing an IORef/STRef is unsuitable because
> the underlying MutVar# may move, invalidating the key (i.e., you cannot
> safely coerce back if a GC has happened between insertion and reading). (If
> that’s incorrect, do enlighten us!) This is a “very nice to have” for our
> purposes—with the understanding that it’s wicked unsafe. ;)
>
> On Tue, Aug 20, 2019, 18:09 David Feuer  wrote:
>
>> You also need to avoid inspecting the StablePtr itself, which is just a
>> number, to maintain purity. The whole thing is a bit weird. Why do you
>> want
>> this anyway?
>>
>> On Wed, Aug 21, 2019, 7:39 AM David Feuer  wrote:
>>
>>> So something like
>>>
>>> newtype StablePtr a = StablePtr (StablePtrST RealWorld a)?
>>>
>>> I suppose that could work with some discipline. You have to assume that
>>> foreign code doesn't pick its address out of a hat and so something
>>> silly,
>>> but I guess you pretty much have to assume that anyway.
>>>
>>> On Wed, Aug 21, 2019, 5:00 AM Matthew Farkas-Dyck 
>>> wrote:
>>>
 I have been doing some work where i want `StablePtr`, but also to not
 be confined to `IO`. I saw the following comment in
 "compiler/prelude/PrimOp.hs":

 Question: Why @RealWorld@ - won't any instance of @_ST@ do the job?
 [ADR]

 It has been there for 20 years. What is the answer? If it is safe i'll
 send the patch generalizing these operations.
 ___
 Glasgow-haskell-users mailing list
 glasgow-haskell-us...@haskell.org
 http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users

>>> ___
>> Glasgow-haskell-users mailing list
>> glasgow-haskell-us...@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
>>
>
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs


Re: `StablePtr` in `ST`

2019-08-20 Thread David Feuer
You also need to avoid inspecting the StablePtr itself, which is just a
number, to maintain purity. The whole thing is a bit weird. Why do you want
this anyway?

On Wed, Aug 21, 2019, 7:39 AM David Feuer  wrote:

> So something like
>
> newtype StablePtr a = StablePtr (StablePtrST RealWorld a)?
>
> I suppose that could work with some discipline. You have to assume that
> foreign code doesn't pick its address out of a hat and so something silly,
> but I guess you pretty much have to assume that anyway.
>
> On Wed, Aug 21, 2019, 5:00 AM Matthew Farkas-Dyck 
> wrote:
>
>> I have been doing some work where i want `StablePtr`, but also to not
>> be confined to `IO`. I saw the following comment in
>> "compiler/prelude/PrimOp.hs":
>>
>> Question: Why @RealWorld@ - won't any instance of @_ST@ do the job? [ADR]
>>
>> It has been there for 20 years. What is the answer? If it is safe i'll
>> send the patch generalizing these operations.
>> ___
>> Glasgow-haskell-users mailing list
>> glasgow-haskell-us...@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
>>
>
___
ghc-devs mailing list
ghc-devs@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs