Improve the semantics of asynchronous exceptions [old version]#765
Improve the semantics of asynchronous exceptions [old version]#765mshinwell wants to merge 1 commit intooxcaml:mainfrom
Conversation
ee9fd7c to
4957807
Compare
0d395f3 to
8078a47
Compare
|
There is one particular point worth noting: this PR, when compiling to native code, currently aims to deliver async exceptions only to handlers registered using Regarding bytecode, async exns would end up being delivered to normal exception handlers, but we could still support masking. |
|
Note on backward compatibility: currently this isn't backwards-compatible, since it requires |
|
Superceded by #802 |
This PR provides a way of making explicit the places where asynchronous exceptions may be raised. This in particular stops exceptions arising from allocation points and thus matches up with the model used by Flambda 2. One consequence is that the addition of safepoints will then work correctly with Flambda 2. This supercedes #194.
The asynchronous exceptions are now nicely wrapped up as follows:
Uses of
Out_of_memorythat were asynchronous exceptions (there were some uses that were not) now terminate the program.There is currently a new function
Sys.with_async_exnsthat can be used to identify a point at which asynchronous exceptions should be emitted. There is also an experiment to implement the "bracket pattern" like in Haskell; seeSys.bracket. There is a file containing a couple of tests which will need to be much enhanced.Asynchronous exceptions are funneled via a new exception pointer in the domain state, which points at normal trap frames, forming a second exception stack. The raising of asynchronous exceptions skips over traps that weren't inserted by
with_async_exns. The second exception stack, save for the head which is in the domain state, is just held in what are effectively local variables in thecaml_start_program/caml_callbackcode (albeit written in assembler).Note that
Stack_overflowis special and can be raised directly from a signal handler.Joint work with @stedolan and @lpw25 .