Overflow exception

Matthew Fluet fluet@CS.Cornell.EDU
Wed, 13 Sep 2000 14:10:05 -0400 (EDT)


> The real problem with overflow was we couldn't figure out a way to do it with
> the C backend with any efficiency.  With the native backend, there are some
> problems, but I think it's doable.  Here's my proposal for how to do it.
> 
> * Add a new primitive exception constructor (ast/prim-cons.sig).
> * Split Int_mul, Int_add, Int_sub into two primitives each, one that raises and 
>   one that doesn't.  The basis library will export the raising kind.
> * Change various passes (like simplify-types, representation,
>   remove-unused-constructors) that rely on explicit references to constructors
>   so that they know about the implicit references in these new primapps.
> * Change passes (like raise-to-jump) that rely on explicit raises so that they
>   know about the new primapp.
> * Change machine-output.sig so that each chunk now contains a special
>   "overflow" label that should be jumped to by an overflowing primapp
>   (Another possibility is to have a single overflow label for the program, but
>    I thought that might make separate assembly harder?)

Assuming that the "overflow" label code would be the generic raising
mechanism, I think one overflow label for the whole program would be fine.
There aren't any issues with exporting names.

> Here are the two ways I see to go
> 
> * Setup the handler if there are nontail calls or raising primapps in the scope
>   of the handler.
> * Figure out someway to get the direct jump information to the raising primapps
>   so that they can generate the direct jump of the generic convention as
>   appropriate.

I think the second suggestion is the better way to go.  What is the
"granularity" of the handlers?  I'm fairly sure that in any block you
either use the generic mechanism or do a direct jump.  So, giving each
machine-output.sig block an additional Label.t option could be the
"hint" for whether to jump directly to the handler or to use the generic
mechanism.  I wouldn't put the global overflow label there when there
direct jump handler; although we're only proposing this for overflow
exceptions, in the future we could consider migrating division by zero
exceptions there as well, which would need a different global label for
the generic raise.