How does ExitCode work? - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

Georgi Lyubenov // googleson78

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?

TheMatten

It seems to delegate ExitCode s to foreign shutdownHaskellAndExit

TheMatten

Which passes int through RTS to

void
stg_exit(int n)
{
  if (exitFn)
    (*exitFn)(n);
  exit(n);
}
TheMatten

So nothing fancy really - it passes code to RTS through FFI

Georgi Lyubenov // googleson78

but how does a users program hook into this, i.e. how does a user's main get to runIO (or something similar)?

Georgi Lyubenov // googleson78

is there some magic place where all this is documented :(

Georgi Lyubenov // googleson78

so I guess the rts is semi-attached to base

Georgi Lyubenov // googleson78

relies on having a function named in a particular way during compilation

TheMatten

Are you working on something related to this? :slight_smile:

Georgi Lyubenov // googleson78

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)

Georgi Lyubenov // googleson78

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

TheMatten

Well, GHC already depends on base anyway, at least because of bunch of functions/datatypes used e.g. in desugaring