Print

Print


Norm writes:

> ...
> For this idiom to have become practical, compilers would have had to recognize
> that,for exceptions declared and handled locally,  a raise statement can be
> translated into a branch rather than a call on a run-time stack-unwinding
> routine.

This does not seem like a particularly hard transformation, but
I don't think many compilers bother doing it.  Interestingly, the
same kind of "look ahead" which is necessary to handle labels
correctly could be used to effectively convert local exception
handlers into a labeled sequence of statements.  You would have
to be careful that no use were made of the exception occurrence
either explicitly via a "when E: blah =>" or implicitly via "raise;".

> ... (In Ada 95, we have to worry about finalization for any inner blocks
> we are exiting.  Even in Ada 83 we would have to wait for termination of all
> tasks dependent on inner blocks we are exiting, so a compiler would have to
> make sure there could be no such tasks before turning the run-time call into a
> branch to the handler.)

Actually, this same work has to be done if you had used a goto which
exited an inner block, so this doesn't represent a reason to suppress
the transformation.

The biggest issue would be that, without general consensus that
all decent Ada 95 compilers should perform this transformation,
you could have code whose performance varied by an order of magnitude
from compiler to compiler.

> ...
> -- Norman

-Tuck