Improve the semantics of asynchronous exceptions [old version] #765
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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_memory
that were asynchronous exceptions (there were some uses that were not) now terminate the program.There is currently a new function
Sys.with_async_exns
that 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_callback
code (albeit written in assembler).Note that
Stack_overflow
is special and can be raised directly from a signal handler.Joint work with @stedolan and @lpw25 .