Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Add prose for reduction rule of rethrow. #225

Merged
merged 4 commits into from
Feb 15, 2023

Conversation

ioannad
Copy link
Collaborator

@ioannad ioannad commented Sep 7, 2022

Why WIP:

I'm not sure how to justify step 5 of the prose, that is how to assert that the lth label surrounding a rethrow instruction has a CAUGHTadm{a val*} next to it.

aheejin added a commit to aheejin/exception-handling that referenced this pull request Sep 13, 2022
I think this should be also updated to include handlers and `caught` to
match the `rethrow` rule in WebAssembly#225.
Copy link
Member

@aheejin aheejin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We extended labels to include an optional catch in validation:

label := catch'? resulttype

Is this not used in execution semantics? If we use this, can we this to guarantee there's a catch label on the stack, which is equivalent of having caught? I might be completely confused about different things... in which case please let me know.

aheejin added a commit that referenced this pull request Sep 15, 2022
I think this should be also updated to include handlers and `caught` to
match the `rethrow` rule in #225.
@ioannad
Copy link
Collaborator Author

ioannad commented Sep 16, 2022

We extended labels to include an optional catch in validation:

label := catch'? resulttype

Is this not used in execution semantics? If we use this, can we this to guarantee there's a catch label on the stack, which is equivalent of having caught? I might be completely confused about different things... in which case please let me know.

I don't think you are confused, my problem is that I don't know how to use it there. So by validation we know that the l'th label of the context C has the form catch [t*], but why is the l'th administrative instruction followed by an administrative instruction caught{a val*}? The only thing I have is that validation of caught requires a catch [t*] label in the context, and it's the only instruction that requires such a label, but I can't connect the last dots after that. Is it obvious and I'm just stuck? I don't know. 😅


3. Assert: due to :ref:`validation <valid-rethrow>`, :math:`L` is a catch label, i.e., a label of the form :math:`(\LCATCH~[t^\ast])`.

4. Repeat :math:`l+1` times:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest doing it only l times in the loop, so that you haven't skipped over the caught clause already.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the loop entirely, trying to avoid popping and pushing back the entire block context.


c. Pop the label from the stack.

5. Assert: due to **TODO**, the last two instructions popped are a |CAUGHTadm| instruction and the :math:`l+1`-th label, in that order.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use typing of rethrow as a proxy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a little more?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the loop as mentioned in the previous comment, and replaced the assertion with:

3. Assert: due to :ref:`validation <valid-rethrow>`, :math:`L` is a catch label, i.e., a label of the form :math:`(\LCATCH~[t^\ast])`, which is a label followed by a caught exception in an active catch clause.

Is that formulation ok @rossberg ?


6. Let :math:`\CAUGHTadm\{a~\val^\ast\}` be the instruction after the label :math:`L`.

7. Put all the popped values back on the stack, except the last instruction, the |RETHROW|.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems really odd. As commented elsewhere, I think we should avoid this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you think can we avoid this? Can we use a concept of shadow stack or something, so we don't really pop the values in 4-a-i above but just scan through it?

Should we do this looping thing in 4-a-i after all? All other branch-like instructions do it so there must be a reason, but can't we just say, because of validation, we can assert Lth is a catch label with type [t*]->[] and L-1th is a caught instruction because of try-catch execution rule, and just refer to the vals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, I just pushed an attempt to avoid all this pushing a popping. WDYT?


8. Push the values :math:`\val^\ast` onto the stack.

8. :ref:`Throw <exec-throwadm>` an exception with :ref:`tag address <syntax-tagaddr>` :math:`a`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you somehow need to jump to the right point first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the right point? Shouldn't we throw the exception in the original location?


6. Let :math:`\CAUGHTadm\{a~\val^\ast\}` be the instruction after the label :math:`L`.

7. Put all the popped values back on the stack, except the last instruction, the |RETHROW|.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you think can we avoid this? Can we use a concept of shadow stack or something, so we don't really pop the values in 4-a-i above but just scan through it?

Should we do this looping thing in 4-a-i after all? All other branch-like instructions do it so there must be a reason, but can't we just say, because of validation, we can assert Lth is a catch label with type [t*]->[] and L-1th is a caught instruction because of try-catch execution rule, and just refer to the vals?


c. Pop the label from the stack.

5. Assert: due to **TODO**, the last two instructions popped are a |CAUGHTadm| instruction and the :math:`l+1`-th label, in that order.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate a little more?

@ioannad ioannad changed the title WIP: Add prose for reduction rule of rethrow. Add prose for reduction rule of rethrow. Dec 9, 2022
ioannad and others added 4 commits February 9, 2023 16:39
Why WIP:
--------
I'm not sure how to justify step 5 of the prose, that is
how to assert that the lth label surrounding a rethrow instruction
has a CAUGHTadm{a val*} next to it.

- Also slightly changed notation to match the [formal overview document](https://github.com/WebAssembly/exception-handling/blob/main/proposals/exception-handling/Exceptions-formal-overview.md).
I no longer consider this PR a WIP.
@ioannad ioannad force-pushed the spec-prose-exec-rethrow branch from 1edf74d to a3ec6f5 Compare February 9, 2023 15:40
@ioannad
Copy link
Collaborator Author

ioannad commented Feb 9, 2023

The force push was to rebase to the current exception-handling/main, to make sure all checks pass before merging.

@rossberg
Copy link
Member

rossberg commented Feb 9, 2023

The force push was to rebase to the current exception-handling/main, to make sure all checks pass before merging.

FWIW, instead of rebase you can simply merge main into this branch, which has the same effect but keeps log and PR intact.

@ioannad
Copy link
Collaborator Author

ioannad commented Feb 15, 2023

@rossberg sorry about that, it was careless, because the PR is approved.

@ioannad ioannad merged commit 3177fbc into WebAssembly:main Feb 15, 2023
@ioannad ioannad deleted the spec-prose-exec-rethrow branch February 15, 2023 10:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants