Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modified the throw context example with concrete types but not concrete values. #219

Merged
Merged
25 changes: 13 additions & 12 deletions document/core/exec/runtime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -732,31 +732,32 @@ Throw contexts allow matching the program context around a throw instruction up
.. note::
For example, catching a simple :ref:`throw <exec-throw>` in a :ref:`try block <exec-try-catch>` would be as follows.
ioannad marked this conversation as resolved.
Show resolved Hide resolved

Assume that :math:`\expand_F(bt) = [t1^n] \to [t2^m]`, for some :math:`n > m` such that :math:`t1^n[(n-m):n] = t2^m`,
and that the tag address `a` of :math:`x` corresponds to the tag type :math:`[t2^m] \to []`.
Assume that :math:`\expand_F(bt) = [\I32~\F32~\I64] \to [\F32~\I64]`,
and that the tag address `a` of :math:`x` corresponds to the tag type :math:`[\F32~\I64] \to []`.
ioannad marked this conversation as resolved.
Show resolved Hide resolved
Let :math:`val_{i32}`, :math:`val_{f32}`, and :math:`val_{i64}` be values of type |I32|, |F32|, and |I64| respectively.

.. math::
\begin{array}{ll}
& \hspace{-5ex} S;~F;~\val^n~(\TRY~\X{bt}~(\THROW~x)~\CATCH~x~\RETURN~\END) \\
\stepto & S;~F;~\LABEL_m\{\} (\CATCHadm\{a~\RETURN\}~\val^n~(\THROW~x)~\END)~\END \\
& \hspace{-5ex} F;~val_{i32}~val_{f32}~val_{i64}~(\TRY~\X{bt}~(\THROW~x)~\CATCH~x~\END) \\
\stepto & F;~\LABEL_2\{\} (\CATCHadm\{a~\epsilon\}~val_{i32}~val_{f32}~val_{i64}~(\THROW~x)~\END)~\END \\
\end{array}

We denote :math:`\val^n = \val^{n-m} \val^m`.
:ref:`Handling the thrown exception <exec-throwadm>` with tag address :math:`a` in the throw context
:math:`T=[val^{n-m}\_]`, with the exception handler :math:`H=\CATCHadm\{a~\RETURN\}` gives:
:math:`T=[val_{i32}\_]`, with the exception handler :math:`H=\CATCHadm\{a~\epsilon\}` gives:

.. math::
\begin{array}{lll}
\stepto & S;~F;~\LABEL_m\{\}~(\CAUGHTadm\{a~\val^m\}~\val^m~\RETURN~\END)~\END & \hspace{9ex}\ \\
\stepto & \val^m & \\
\stepto & F;~\LABEL_2\{\}~(\CAUGHTadm\{a~val_{f32}~val_{i64}\}~val_{f32}~val_{i64}~\END)~\END & \hspace{9ex}\ \\
\stepto & F;~\LABEL_2\{\}~val_{f32}~val_{i64}~\END & \hspace{9ex}\ \\
\stepto & val_{f32}~val_{i64} & \\
\end{array}



ioannad marked this conversation as resolved.
Show resolved Hide resolved
When a throw of the form :math:`val^m (\THROWadm~a)` occurs, we search for the maximal surrounding throw context :math:`T`,
which means we pop any other values, labels, frames, and |CAUGHTadm| instructions surrounding the throw :math:`val^m (\THROWadm~a)`,
When a throw of the form :math:`\val^m (\THROWadm~a)` occurs, we search for the maximal surrounding throw context :math:`T`,
ioannad marked this conversation as resolved.
Show resolved Hide resolved
which means we pop any other values, labels, frames, and |CAUGHTadm| instructions surrounding the throw :math:`\val^m (\THROWadm~a)`,
until we find an exception handler (corresponding to a try block) that :ref:`handles the exception <syntax-handler>`.
We then append the values :math:`val^m:[t^m]` to the tag address :math:`a` into a new |CAUGHTadm| instruction which we push on the stack.
We then append the values :math:`\val^m:[t^m]` to the tag address :math:`a` into a new |CAUGHTadm| instruction which we push on the stack.

In other words, when a throw occurs, normal execution halts and exceptional execution begins, until the throw
is the continuation (i.e., in the place of a :math:`\_`) of a throw context in a catching try block.
Copy link
Member

Choose a reason for hiding this comment

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

Not strictly related to this PR, but I'm not sure if I understand this sentence.

  • What does a hole represent? (I know this is a basic question, but "block context" says it is "the next step of computation is taking place".. Is that also the case here? Which next step are we talking about?)
  • This sentence sounds like we have two separate moments of "exception execution begins" and "(until) the throw is the continuation". I thought the exception execution begins when the throw is executed... Are they two different things?

Copy link
Member

Choose a reason for hiding this comment

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

By the way this is a general question, so please don't consider this question as a blocker for landing this PR.

Copy link
Collaborator Author

@ioannad ioannad Sep 15, 2022

Choose a reason for hiding this comment

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

This sentence sounds like we have two separate moments of "exception execution begins" and "(until) the throw is the continuation". I thought the exception execution begins when the throw is executed... Are they two different things?

@aheejin this is exactly what I meant, so by "exceptional execution" I meant the execution of the throw, so the popping of values and labels until the first catching try block is reached. I was only trying to describe the execution of a throw instruction, but I see now I overcomplicated it, making it seem as if there are more than one execution steps during "exceptional execution".

About the hole, I think of the hole as the position of the stack pointer of the Wasm stack machine, but I see how mentioning the hole here can be confusing as well. Thank you for pointing this out!

Rephrasing these two lines to:

In other words, a thrown exception is caught when it's the continuation of a throw context in a catching try block, i.e., it's inside a catching try block, which is the innermost with respect to the throw.

Is it clearer like this?

Copy link
Member

Choose a reason for hiding this comment

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

when it's the continuation of a throw context in a catching try block,

What's 'it' here? It looks to be "a thrown exception" looking at the first part of the sentence, but I'm not sure what it means that an exception is a continuation of a throw context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By "the thrown exception" I meant the instruction that throws the exception, i.e., val* (throw a).

I guess it's better to call it "the exception throw" instead, reformulating.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(done)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is now entirely removed, after this discussion.

Expand Down Expand Up @@ -804,7 +805,7 @@ Finally, the following definition of *evaluation context* and associated structu
\begin{array}{llll}
\production{(evaluation contexts)} & E &::=&
[\_] ~|~
\val^\ast~E~\instr^\ast ~|~
val^\ast~E~\instr^\ast ~|~
ioannad marked this conversation as resolved.
Show resolved Hide resolved
\LABEL_n\{\instr^\ast\}~E~\END \\
\end{array}

Expand Down