[mercury-users] Exceptions in Mercury

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Nov 20 07:06:35 AEDT 2002


On 19-Nov-2002, Sander at hypernation.net <xkb at hypernation.net> wrote:
> Are there any "formal" papers on the implementation of exceptions in
> mercury?

No, currently there are not.

The exception handling interface is documented in the "exception" chapter
of the library reference manual (which is just the interface section of
the "exception" module from the Mercury standard library).
That specifies the declarative and optional semantics for exceptions.
The semantic model used for exceptions is similar to the model
for Haskell described in [1].

The implementation of exceptions is different for different back-ends.
The low-level C back-end implementation works by pushing a specially
marked stack frame when doing a "try", and unwinding the stacks to that
point when doing a "throw".  The high-level C back-end implementation
of exceptions uses setjmp/longjmp (actually for GNU C we use
__builtin_setjmp/__builtin_longjmp, which can be considerably faster).
The .NET and Java back-ends just map Mercury exceptions to the
target language's exceptions.

The trickiest issue we had to deal with was the interaction between
exceptions and mutable state / destructive update.  That has been
resolved by carefully designing the interface so that (1) for `try',
we ensure that any modifications to mutable state are not visible after
the exception has been thrown, and (2) for `try_io' and `try_store',
we deliberately leave it unspecified which state will result after
an exception is thrown.

References
[1] "A semantics for imprecise exceptions."
    Simon Peyton-Jones, Alastair Reid, Tony Hoare, Simon Marlow,
    and Fergus Henderson.
    Proceedings of the 1999 ACM SIGPLAN Conference on Programming Language
    Design and Implementation, May 1999.

[2] <http://www.cs.mu.oz.au/research/mercury/mailing-lists/mercury-users/mer
     cury-users.9911/0175.html>

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list