Help making exception-related primops open-kinded

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help making exception-related primops open-kinded

David Feuer
I'm pretty sure raiseIO#, catch#, maskAsyncExceptions#, and so on can
have open-kinded results. For example, we currently have

catch#
  :: (State# RealWorld -> (# State# RealWorld, a #) )
  -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
  -> State# RealWorld
  -> (# State# RealWorld, a #)

but I think we *should* be able to have

catch#
  :: (State# RealWorld -> (# State# RealWorld, o #) )
  -> (b -> State# RealWorld -> (# State# RealWorld, o #) )
  -> State# RealWorld
  -> (# State# RealWorld, o #)

This should allow us to avoid boxing things just to be able to get
them out of a `catch#` or `maskAsyncExceptions#` block. But when I
tried just changing the types in primops.txt.pp, I got a type mismatch
error that seems to suggest some sort of GHC build staging issue. How
can I work around this? See
https://gitlab.haskell.org/ghc/ghc/-/merge_requests/4192/diffs for my
attempt.
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

RE: Help making exception-related primops open-kinded

GHC - devs mailing list
You would have to be pretty careful to make them open-kinded.  You'd need to make sure that the implementation of these primops (which is quite complicated) never touches or moves that result value.  Maybe it is so, and if so it'd be useful -- but should be *prominently* document in the RTS C code that implements them.

I'm afraid I don't know what "some kind of staging issue" is.

Simon

|  -----Original Message-----
|  From: ghc-devs <[hidden email]> On Behalf Of David Feuer
|  Sent: 02 October 2020 21:43
|  To: ghc-devs <[hidden email]>
|  Subject: Help making exception-related primops open-kinded
|  
|  I'm pretty sure raiseIO#, catch#, maskAsyncExceptions#, and so on can
|  have open-kinded results. For example, we currently have
|  
|  catch#
|    :: (State# RealWorld -> (# State# RealWorld, a #) )
|    -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
|    -> State# RealWorld
|    -> (# State# RealWorld, a #)
|  
|  but I think we *should* be able to have
|  
|  catch#
|    :: (State# RealWorld -> (# State# RealWorld, o #) )
|    -> (b -> State# RealWorld -> (# State# RealWorld, o #) )
|    -> State# RealWorld
|    -> (# State# RealWorld, o #)
|  
|  This should allow us to avoid boxing things just to be able to get
|  them out of a `catch#` or `maskAsyncExceptions#` block. But when I
|  tried just changing the types in primops.txt.pp, I got a type mismatch
|  error that seems to suggest some sort of GHC build staging issue. How
|  can I work around this? See
|  https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl
|  ab.haskell.org%2Fghc%2Fghc%2F-
|  %2Fmerge_requests%2F4192%2Fdiffs&amp;data=02%7C01%7Csimonpj%40microsof
|  t.com%7C249daeec340348eae7a208d86713c76c%7C72f988bf86f141af91ab2d7cd01
|  1db47%7C1%7C0%7C637372681930831064&amp;sdata=y3czpdaLEC5TVJD3EAbiDN3cH
|  PDJfA5%2BnfQnFrU%2Bs3E%3D&amp;reserved=0 for my
|  attempt.
|  _______________________________________________
|  ghc-devs mailing list
|  [hidden email]
|  https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.
|  haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&amp;data=02%7C01%7Csimonpj%40microsoft.com%7C249daeec340348eae7a2
|  08d86713c76c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637372681930
|  831064&amp;sdata=PRcbOsfSWbmNT2GTPQjPQqU2c1Fh%2FpHezIRz7Z9pE6c%3D&amp;
|  reserved=0
_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
Reply | Threaded
Open this post in threaded view
|

Re: Help making exception-related primops open-kinded

David Feuer
The "staging" thing was my misinterpretation of an error message. That's resolved. Levity polymorphism of these primops *seems* to be a fundamental consequence of the deeply-entrenched assumption that the exceptional path is the slow path. Catching and masking operations appear (to my untrained eye) to stick some stuff on the stack and then just jump to the user-provided function as a tail call. The complicated operation is actually raiseIO#, and that one doesn't *have* a result to manipulate. Again, testing is certainly required anyway, and I can add comments.

On Mon, Oct 5, 2020, 6:28 AM Simon Peyton Jones <[hidden email]> wrote:
You would have to be pretty careful to make them open-kinded.  You'd need to make sure that the implementation of these primops (which is quite complicated) never touches or moves that result value.  Maybe it is so, and if so it'd be useful -- but should be *prominently* document in the RTS C code that implements them.

I'm afraid I don't know what "some kind of staging issue" is.

Simon

|  -----Original Message-----
|  From: ghc-devs <[hidden email]> On Behalf Of David Feuer
|  Sent: 02 October 2020 21:43
|  To: ghc-devs <[hidden email]>
|  Subject: Help making exception-related primops open-kinded

|  I'm pretty sure raiseIO#, catch#, maskAsyncExceptions#, and so on can
|  have open-kinded results. For example, we currently have

|  catch#
|    :: (State# RealWorld -> (# State# RealWorld, a #) )
|    -> (b -> State# RealWorld -> (# State# RealWorld, a #) )
|    -> State# RealWorld
|    -> (# State# RealWorld, a #)

|  but I think we *should* be able to have

|  catch#
|    :: (State# RealWorld -> (# State# RealWorld, o #) )
|    -> (b -> State# RealWorld -> (# State# RealWorld, o #) )
|    -> State# RealWorld
|    -> (# State# RealWorld, o #)

|  This should allow us to avoid boxing things just to be able to get
|  them out of a `catch#` or `maskAsyncExceptions#` block. But when I
|  tried just changing the types in primops.txt.pp, I got a type mismatch
|  error that seems to suggest some sort of GHC build staging issue. How
|  can I work around this? See
https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitl
ab.haskell.org%2Fghc%2Fghc%2F-
|  %2Fmerge_requests%2F4192%2Fdiffs&amp;data=02%7C01%7Csimonpj%40microsof
t.com%7C249daeec340348eae7a208d86713c76c%7C72f988bf86f141af91ab2d7cd01
|  1db47%7C1%7C0%7C637372681930831064&amp;sdata=y3czpdaLEC5TVJD3EAbiDN3cH
|  PDJfA5%2BnfQnFrU%2Bs3E%3D&amp;reserved=0 for my
|  attempt.
|  _______________________________________________
|  ghc-devs mailing list
[hidden email]
https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.
haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&amp;data=02%7C01%7Csimonpj%40microsoft.com%7C249daeec340348eae7a2
|  08d86713c76c%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637372681930
|  831064&amp;sdata=PRcbOsfSWbmNT2GTPQjPQqU2c1Fh%2FpHezIRz7Z9pE6c%3D&amp;
|  reserved=0

_______________________________________________
ghc-devs mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs