Is anyone familiar with how the values stored in ExitCode get to the RTS (i.e. actually make the program exit with the given number). As far as I can tell ExitCode is used as an everyday normal-looking exception (which are defined entirely in "library code", by using the raise#/catch# primitives), without any direct link to the RTS. What am I missing?
nope (un??)fortunately, a colleague of mine made a claim that the rts depends on the base library (by detecting ExitCode manually in the rts or something)
and it was also standalone interesting, because in the continuations proposal there was also the claim There's really nothing special about the SomeException type as far as I know, and in principle an alternate base would be perfectly free to use a different one
Is anyone familiar with how the values stored in
ExitCode
get to the RTS (i.e. actually make the program exit with the given number). As far as I can tellExitCode
is used as an everyday normal-looking exception (which are defined entirely in "library code", by using theraise#
/catch#
primitives), without any direct link to the RTS. What am I missing?This module seems to be relevant: https://gitlab.haskell.org/ghc/ghc/-/blob/a1f34d37b47826e86343e368a5c00f1a4b1f2bce/libraries/base/GHC/TopHandler.hs
It seems to delegate
ExitCode
s to foreignshutdownHaskellAndExit
Which passes int through RTS to
So nothing fancy really - it passes code to RTS through FFI
but how does a users program hook into this, i.e. how does a user's
main
get torunIO
(or something similar)?is there some magic place where all this is documented :(
Found this: https://gitlab.haskell.org/ghc/ghc/-/blob/a1f34d37b47826e86343e368a5c00f1a4b1f2bce/rts/RtsAPI.c#L478
https://gitlab.haskell.org/ghc/ghc/-/blob/a1f34d37b47826e86343e368a5c00f1a4b1f2bce/rts/Schedule.c#L2175
so I guess the rts is semi-attached to
base
relies on having a function named in a particular way during compilation
thanks!
Are you working on something related to this? :slight_smile:
nope (un??)fortunately, a colleague of mine made a claim that the rts depends on the
base
library (by detectingExitCode
manually in the rts or something)and I was highly doubtful
and it was also standalone interesting, because in the continuations proposal there was also the claim
There's really nothing special about the SomeException type as far as I know, and in principle an alternate base would be perfectly free to use a different one
Well, GHC already depends on
base
anyway, at least because of bunch of functions/datatypes used e.g. in desugaring