-
Notifications
You must be signed in to change notification settings - Fork 36
Should if_except
pop the exception off the stack?
#44
Comments
Both Option 1 and 3 look find to me. And for C++ they are gonna be the same. So I guess we can make The reasons I don't like Option 0 and 2:
|
One of the things @aheejin and I were talking about was that Option 3 is really just Option 1 + |
I was assuming 1. Agreed that it is the simplest and most coherent. I don't see the need for 3, as long as we don't have that for |
This section says "The exception value is not popped when queried." It seems like this should be changed since everyone seems to prefer option 1. |
I've updated the PR to use option 1. |
Since #49 merged, I'm going to mark this as closed. |
For the behavior of
if_except
, the current proposal states:It does not explicitly state what happens to the exception object on the stack. I would interpret this to mean that the exception object remains on the stack in both the then and the else branches. Is this the behavior we want?
There are a couple of other options that I think could be reasonable choices and are worth discussing.
Option 0: Status Quo
This is the option that matches my read of the current proposal. The exception stays on the stack in both the then and else branches of
if_except
. I'm calling it Option 0 to make it easy to refer to in discussions.Having the exception available in the then branch is possibly convenient for rethrowing the exception. However, it will be buried by the exception arguments and the producer will have to pop these off before getting access to the exception, meaning it may not actually be all that useful.
Having the exception available in the else branch makes it more compact to chain multiple tests, such as:
Option 1:
if_except
Always Pops the ExceptionIn this case, the producer would have to explicitly save the exception to a local if it wants to refer to it multiple times. For example:
This seems more consistent with the rest of the Wasm instructions, which generally remove any arguments used from the stack.
The downside is that every chained
if_except
will need aget_local
, although chainedif_except
s are likely to be rare, I expect.Option 2: Pop in Then Branch, Leave in Else Branch
This feels natural to me. The
if_except
instruction attempts to unpack the exception, and if it exceeds then it consumes the exception and leaves the contents of the exception on the stack. In the else case, things are left unchanged since it failed to unpack the exception.Care will be needed to make sure the types balance on the two branches, and the one armed
if_except
case seems weird under this strategy. This option does allow chaining like Option 0 does.Option 3: Multiple Matches
The main advantage for leaving the exception on the stack is to allow chaining. Another option would be to make
if_except
act more like a case statement. For example:If we had this kind of format then it would make most since to me to always have
if_except
pop the exception, and if multiple copies are needed then locals can be used.What does everyone think? My choice would be for Option 3, with Option 2 as a second choice. Once we seem to have some consensus here, I can write up a PR to clarify which option is used.
The text was updated successfully, but these errors were encountered: