Skip to content

Commit 7714472

Browse files
committed
Apply suggestions from code review and email communication.
In particular: - Switched to handler ::= (tagaddr? instr*)* | labelidx exn ::= tagaddr val* instr ::= … | handler_n{handler} instr* end | caught_n{exn} instr* end removing DELEGATEadm - Changed prose to just push and pop handlers and exceptions, in the runtime, in the execution steps of the instructions, in the formal overview, and partly in appendix/properties. Not done: - Did not change the notation and prose for CAUGHTadm in appendix/properties.rst, this will be done in PR WebAssembly#244.
1 parent fbb0c95 commit 7714472

File tree

5 files changed

+161
-169
lines changed

5 files changed

+161
-169
lines changed

document/core/appendix/properties.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -606,65 +606,65 @@ To that end, all previous typing judgements :math:`C \vdash \X{prop}` are genera
606606
}
607607
608608
609-
.. index:: catch, throw context
609+
.. index:: handler, throw context
610610

611-
:math:`\CATCHadm\{\tagaddr^?~\instr_1^\ast\}^\ast~\instr_2^\ast~\END`
612-
.....................................................................
611+
:math:`\HANDLERadm_n\{(\tagaddr^?~\instr_1^\ast)^\ast\}~\instr_2^\ast~\END`
612+
...........................................................................
613613

614614
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`[t_2^\ast]` prepended to the |CLABELS| vector.
615615

616616
* Under context :math:`C'`,
617-
the instruction sequence :math:`\instr_2^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^\ast]`.
617+
the instruction sequence :math:`\instr_2^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^n]`.
618618

619-
* Let :math:`C''` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`(\LCATCH~[t_2^\ast])` prepended to the |CLABELS| vector.
619+
* Let :math:`C''` be the same :ref:`context <context>` as :math:`C`, but with the :ref:`label type <syntax-labeltype>` :math:`(\LCATCH~[t_2^n])` prepended to the |CLABELS| vector.
620620

621621
* Under context :math:`C''`,
622622
for every :math:`\tagaddr^?` and associated instruction sequence :math:`\instr_1^\ast`:
623623

624-
* If :math:`\tagaddr^? = \epsilon`, then :math:`\instr_1^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^\ast]`.
624+
* If :math:`\tagaddr^? = \epsilon`, then :math:`\instr_1^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[] \to [t_2^n]`.
625625

626626
* Else:
627627

628628
* The :ref:`external tag value <syntax-externval>` :math:`\EVTAG~\tagaddr` must be :ref:`valid <valid-externval-tag>` with some :ref:`external tag type <syntax-externtype>` :math:`\ETTAG~[t_1^\ast] \to []`.
629629

630-
* The instruction sequence :math:`\instr_1^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_1^\ast] \to [t_2^\ast]`.
630+
* The instruction sequence :math:`\instr_1^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[t_1^\ast] \to [t_2^n]`.
631631

632-
* Then the compound instruction is valid under context :math:`C'` with type :math:`[] \to [t_2^\ast]`.
632+
* Then the compound instruction is valid under context :math:`C'` with type :math:`[] \to [t_2^n]`.
633633

634634
.. math::
635635
\frac{
636636
\begin{array}{@{}c@{}}
637637
((S \vdashexternval \EVTAG~\tagaddr : \ETTAG~[t_1^\ast]\to[])^? \\
638-
~~S; C,\CLABELS\,(\LCATCH~[t_2^\ast]) \vdashinstrseq \instr_1^\ast : [(t_1^\ast)^?] \to [t_2^\ast])^\ast \\
639-
S; C,\CLABELS\,[t_2^\ast] \vdashinstrseq \instr_2^\ast : [] \to [t_2^\ast] \\
638+
~~S; C,\CLABELS\,(\LCATCH~[t_2^n]) \vdashinstrseq \instr_1^\ast : [(t_1^\ast)^?] \to [t_2^n])^\ast \\
639+
S; C,\CLABELS\,[t_2^n] \vdashinstrseq \instr_2^\ast : [] \to [t_2^n] \\
640640
\end{array}
641641
}{
642-
S; C,\CLABELS\,[t_2^\ast] \vdashadmininstr \CATCHadm\{\tagaddr^?~{\instr_1}^\ast\}^\ast~\instr_2^\ast~\END : [] \to [t_2^\ast]
642+
S; C,\CLABELS\,[t_2^n] \vdashadmininstr \HANDLERadm_n\{(\tagaddr^?~{\instr_1}^\ast)^\ast\}~\instr_2^\ast~\END : [] \to [t_2^n]
643643
}
644644
645645
646-
.. index:: delegate, throw context
647-
.. _valid-delegate-admin:
646+
.. index:: handler, throw context
647+
.. _valid-handleradm:
648648

649-
:math:`\DELEGATEadm\{l\}~\instr^\ast~\END`
650-
..........................................
649+
:math:`\HANDLERadm_n\{l\}~\instr^\ast~\END`
650+
...........................................
651651

652652
* The label :math:`C.\CLABELS[l]` must be defined in the context.
653653

654654
* Let :math:`C'` be the same :ref:`context <context>` as :math:`C`, but with the label :math:`[t^\ast]` prepended to the |CLABELS| vector.
655655

656656
* Under context :math:`C'`,
657-
the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[]\to[t^\ast]`.
657+
the instruction sequence :math:`\instr^\ast` must be :ref:`valid <valid-instr-seq>` with type :math:`[]\to[t^n]`.
658658

659-
* Then the compound instruction is valid under context :math:`C'` with type :math:`[] \to [t^\ast]`.
659+
* Then the compound instruction is valid under context :math:`C'` with type :math:`[] \to [t^n]`.
660660

661661
.. math::
662662
\frac{
663-
S; C,\CLABELS\,[t^\ast] \vdashinstrseq \instr^\ast : [] \to [t^\ast]
663+
S; C,\CLABELS\,[t^n] \vdashinstrseq \instr^\ast : [] \to [t^n]
664664
\qquad
665665
C.\CLABELS[l] = [t_0^\ast]
666666
}{
667-
S; C,\CLABELS\,[t^\ast] \vdashadmininstr \DELEGATEadm\{l\}~\instr^\ast~\END : [] \to [t^\ast]
667+
S; C,\CLABELS\,[t^n] \vdashadmininstr \HANDLERadm_n\{l\}~\instr^\ast~\END : [] \to [t^n]
668668
}
669669
670670

document/core/exec/instructions.rst

Lines changed: 60 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -2643,26 +2643,26 @@ Control Instructions
26432643

26442644
b. Let :math:`a_i` be the tag address :math:`F.\AMODULE.\MITAGS[x_i]`.
26452645

2646-
c. Let :math:`H_i` be the handler clause :math:`\{a_i~\instr_{2i}^\ast\}`.
2646+
c. Let :math:`H_i` be the handler :math:`(a_i~\instr_{2i}^\ast)`.
26472647

26482648
8. If there is a catch all clause :math:`(\CATCHALL~\instr_3^\ast)`, then:
26492649

2650-
a. Let :math:`H'^?` be the handler clause :math:`\{\epsilon~\instr_3^\ast\}`.
2650+
a. Let :math:`H'^?` be the handler :math:`(\epsilon~\instr_3^\ast)`.
26512651

26522652
9. Else:
26532653

2654-
a. Let :math:`H'^?` be the empty handler clause :math:`\epsilon`.
2654+
a. Let :math:`H'^?` be the empty handler :math:`\epsilon`.
26552655

2656-
10. Let :math:`H^\ast` be the :ref:`catching exception handler <syntax-handler>` containing the concatenation of the handler clauses :math:`H_i` and :math:`H'^?`.
2656+
10. Let :math:`H^\ast` be the concatenation of :math:`H_i` and :math:`H'^?`.
26572657

2658-
11. :ref:`Enter <exec-handler-enter>` the block :math:`\val^m~\instr_1^\ast` with label :math:`L` and exception handler :math:`H`.
2658+
11. :ref:`Enter <exec-handler-enter>` the block :math:`\val^m~\instr_1^\ast` with label :math:`L` and exception handler :math:`H^\ast`.
26592659

26602660
.. math::
26612661
~\\[-1ex]
26622662
\begin{array}{l}
26632663
F; \val^m~(\TRY~\X{bt}~\instr_1^\ast~(\CATCH~x~\instr_2^\ast)^\ast~(\CATCHALL~\instr_3^\ast)^?~\END
26642664
\quad \stepto \\
2665-
\qquad F; \LABEL_n\{\epsilon\}~(\CATCHadm\{a_x~\instr_2^\ast\}^\ast\{\epsilon~\instr_3\ast\}^?~\val^m~\instr_1^\ast~\END)~\END \\
2665+
\qquad F; \LABEL_n\{\epsilon\}~(\HANDLERadm_n\{(a_x~\instr_2^\ast)^\ast~(\epsilon~\instr_3^\ast)^?\}~\val^m~\instr_1^\ast~\END)~\END \\
26662666
(\iff \expand_F(\X{bt}) = [t_1^m] \to [t_2^n] \land (F.\AMODULE.\MITAGS[x]=a_x)^\ast)
26672667
\end{array}
26682668
@@ -2678,21 +2678,19 @@ Control Instructions
26782678

26792679
3. Let :math:`L` be the label whose arity is :math:`n` and whose continuation is the end of the |TRY| instruction.
26802680

2681-
4. Let :math:`H` be the :ref:`delegating exception handler <syntax-handler>` :math:`\DELEGATEadm\{l\}`, targeting the :math:`l`-th surrounding block.
2681+
4. Let :math:`H` be the :ref:`exception handler <syntax-handler>` :math:`l`, targeting the :math:`l`-th surrounding block.
26822682

26832683
5. Assert: due to :ref:`validation <valid-try-delegate>`, there are at least :math:`m` values on the top of the stack.
26842684

26852685
6. Pop the values :math:`\val^m` from the stack.
26862686

2687-
7. :ref:`Enter <exec-instr-seq-enter>` the block :math:`H~(\val^n~\instr^\ast)~\END` with label :math:`L`.
2688-
2689-
8. :ref:`Install <exec-handler-enter>` the exception handler `H` containing :math:`\val^m~\instr^\ast`.
2687+
7. :ref:`Enter <exec-handler-enter>` the block :math:`\val^m~\instr^\ast` with label :math:`L` and exception handler `H`.
26902688

26912689
.. math::
26922690
~\\[-1ex]
26932691
\begin{array}{lcl}
26942692
F; \val^m~(\TRY~\X{bt}~\instr^\ast~\DELEGATE~l) &\stepto&
2695-
F; \LABEL_n\{\epsilon\}~(\DELEGATEadm\{l\}~\val^m~\instr^\ast~\END)~\END \\
2693+
F; \LABEL_n\{\epsilon\}~(\HANDLERadm_n\{l\}~\val^m~\instr^\ast~\END)~\END \\
26962694
&& (\iff \expand_F(\X{bt}) = [t_1^m] \to [t_2^n])
26972695
\end{array}
26982696
@@ -2728,8 +2726,8 @@ Control Instructions
27282726
.. math::
27292727
~\\[-1ex]
27302728
\begin{array}{lclr@{\qquad}}
2731-
\CAUGHTadm\{a~\val^n\}~\XB^l[\RETHROW~l]~\END &\stepto&
2732-
\CAUGHTadm\{a~\val^n\}~\XB^l[\val^n~(\THROWadm~a)]~\END \\
2729+
\CAUGHTadm_n\{a~\val^n\}~\XB^l[\RETHROW~l]~\END &\stepto&
2730+
\CAUGHTadm_n\{a~\val^n\}~\XB^l[\val^n~(\THROWadm~a)]~\END \\
27332731
\end{array}
27342732
27352733
@@ -3053,8 +3051,7 @@ When the end of a :ref:`try <syntax-try>` instruction is reached without a jump,
30533051
.. math::
30543052
~\\[-1ex]
30553053
\begin{array}{lcl@{\qquad}l}
3056-
\CATCHadm\{a^?~\instr^\ast\}^\ast~\val^m~\END &\stepto& \val^m \\
3057-
\DELEGATEadm\{l\}~\val^m~\END &\stepto& \val^m
3054+
\HANDLERadm_m\{\handler\}~\val^m~\END &\stepto& \val^m \\
30583055
\end{array}
30593056
30603057
@@ -3067,7 +3064,7 @@ When a throw occurs, then values, labels, active catch clauses,
30673064
and call frames are popped if necessary, until an appropriate exception handler is found
30683065
on the top of the stack.
30693066

3070-
1. Assert: due to :ref:`validation <valid-throw>`,, :math:`S.\STAGS[a]` exists.
3067+
1. Assert: due to :ref:`validation <valid-throw>`, :math:`S.\STAGS[a]` exists.
30713068

30723069
2. Let :math:`[t^n] \to []` be the :ref:`tag type <syntax-tagtype>` :math:`S.\STAGS[a].\TAGITYPE`.
30733070

@@ -3079,126 +3076,112 @@ on the top of the stack.
30793076

30803077
a. Pop the top element from the stack.
30813078

3082-
6. Assert: The stack is now either empty, or there is an exception handler on the top of the stack.
3079+
6. Assert: the stack is now either empty, or there is an exception handler on the top of the stack.
30833080

30843081
7. If the stack is empty, then:
30853082

3086-
a. Return the uncaught exception :math:`\val^n~(\THROWadm~a)` as a result.
3087-
3088-
8. Else:
3083+
a. Return the uncaught exception :math:`\val^n~(\THROWadm~a)` as a :ref:`result <syntax-result>`.
30893084

3090-
a. Assert: there is an :ref:`exception handler <syntax-handler>` :math:`H` on the top of the stack.
3085+
8. Else assert: there is an :ref:`exception handler <syntax-handler>` :math:`H` on the top of the stack.
30913086

30923087
9. Pop the exception handler :math:`H` from the stack.
30933088

3094-
10. Assert: :math:`H` is either of the a catching or a delegating :ref:`exception handler <syntax-handler>`.
3095-
3096-
11. If :math:`H` is a catching exception handler, let :math:`\{a^?~\instr^\ast\}^k` be its clauses. Then:
3097-
3098-
a. If :math:`k = 0`, then:
3099-
3100-
i. Put the values :math:`\val^n` back onto the stack.
3101-
3102-
ii. :ref:`Throw <exec-throwadm>` an exception with tag address :math:`a`.
3103-
3104-
b. Else :math:`H`'s clauses are of the form :math:`\{a_1^?~\instr^\ast\}\{a'^?~\instr'^\ast\}^\ast`.
3089+
10. If :math:`H` is list of handlers, then:
31053090

3106-
c. If :math:`a_1^? = \epsilon`, then:
3091+
a. While :math:`H` is not empty, do:
31073092

3108-
i. :ref:`Enter <exec-caughtadm-enter>` :math:`\instr^\ast` with catch clause holding the caught exception :math:`\{a~\val^n\}`.
3093+
i. Let :math:`(a_1^?~\instr^\ast)` be the first handler in :math:`H`.
31093094

3110-
d. Else if :math:`a_1^? = a`, then:
3095+
ii. If :math:`a_1^? = \epsilon`, then:
31113096

3112-
i. :ref:`Enter <exec-caughtadm-enter>` :math:`\val^n~\instr^\ast` with catch clause holding the caught exception :math:`\{a~\val^n\}`.
3097+
* :ref:`Enter <exec-caughtadm-enter>` the block :math:`\instr^\ast` with caught exception :math:`a~\val^n`.
31133098

3114-
e. Else:
3099+
iii. Else if :math:`a_1^? = a`, then:
31153100

3116-
i. Let :math:`H'` be the catching exception handler with clauses :math:`\{a'^?~\instr'^\ast\}^\ast`.
3101+
* :ref:`Enter <exec-caughtadm-enter>` the block :math:`\val^n~\instr^\ast` with caught exception :math:`a~\val^n`.
31173102

3118-
ii. Repeat step 11 for :math:`H'`.
3103+
iv. Else, pop the first handler from :math:`H`.
31193104

3120-
12. Else:
3105+
b. Else, the exception was not caught by :math:`H`:
31213106

3122-
a. Assert: :math:`H` is a delegating exception handler.
3107+
i. Put the values :math:`\val^n` back onto the stack.
31233108

3124-
13. Let :math:`l` be the label index of :math:`H`.
3109+
ii. :ref:`Throw <exec-throwadm>` an exception with tag address :math:`a`.
31253110

3126-
14. Assert: due to :ref:`validation <valid-delegate-admin>`, the stack contains at least :math:`l` labels.
3111+
11. Else :math:`H` is a label index :math:`l`.
31273112

3128-
15. Let :math:`L` be the :math:`l`-th label appearing on the stack, starting from the top and counting from zero.
3113+
a. Assert: due to :ref:`validation <valid-handleradm>`, the stack contains at least :math:`l` labels.
31293114

3130-
15. Repeat :math:`l` times:
3115+
b. Repeat :math:`l` times:
31313116

3132-
a. While the top of the stack is not a label, do:
3117+
i. While the top of the stack is not a label, do:
31333118

3134-
i. Pop the top element from the stack.
3119+
* Pop the top element from the stack.
31353120

3136-
b. Assert: due to :ref:`validation <valid-delegate-admin>`, the top of the stack now is a label.
3121+
c. Assert: due to :ref:`validation <valid-handleradm>`, the top of the stack now is a label.
31373122

3138-
c. Pop the label from the stack.
3123+
d. Pop the label from the stack.
31393124

3140-
16. Push the values :math:`\val^n` onto the stack.
3125+
e. Push the values :math:`\val^n` onto the stack.
31413126

3142-
17. :ref:`Throw <exec-throwadm>` an exception with tag address :math:`a`.
3127+
f. :ref:`Throw <exec-throwadm>` an exception with tag address :math:`a`.
31433128

31443129
.. math::
31453130
\begin{array}{rcl}
3146-
\CATCHadm~\XT[\val^n~(\THROWadm~a)]~\END &\stepto&
3147-
\XT[\val^n~(\THROWadm~a)] \\
3148-
\CATCHadm\{a_1^?~\instr^\ast\}\{a'^?~\instr'^\ast\}^\ast~\XT[\val^n~(\THROWadm~a)]~\END &\stepto&
3149-
\CATCHadm\{a'^?~\instr'^\ast\}^\ast~\XT[\val^n~(\THROWadm~a)]~\END \\
3131+
\HANDLERadm_n\{\}~\XT[(\THROWadm~a)]~\END &\stepto&
3132+
\XT[(\THROWadm~a)] \\
3133+
\HANDLERadm_n\{(a_1^?~\instr^\ast)~(a'^?~\instr'^\ast)^\ast\}~\XT[(\THROWadm~a)]~\END &\stepto&
3134+
\HANDLERadm_n\{(a'^?~\instr'^\ast)^\ast~\XT[(\THROWadm~a)]~\END \\
31503135
&& (\iff a_1^? \neq \epsilon \land a_1^? \neq a) \\
3151-
S;~\CATCHadm\{a_1^?~\instr^\ast\}\{a'^?~\instr'^\ast\}^\ast~\XT[\val^n~(\THROWadm~a)]~\END &\stepto&
3152-
S;~\CAUGHTadm\{a~\val^n\}~(\val^n)^?~\instr^\ast~\END \\
3136+
S;~\HANDLERadm_n\{(a_1^?~\instr^\ast)~(a'^?~\instr'^\ast)^\ast\}~\XT[\val^n~(\THROWadm~a)]~\END &\stepto&
3137+
S;~\CAUGHTadm_n\{a~\val^n\}~(\val^n)^?~\instr^\ast~\END \\
31533138
&& (\iff~(a_1^? = \epsilon \lor a_1^? = a)~\land\\
31543139
&& \ S.\STAGS[a].\TAGITYPE = [t^n]\to[]) \\
3155-
\LABEL_n\{\}~\XB^l[\DELEGATEadm\{l\}~\XT[\val^n~(\THROWadm~a)]~\END]~\END &\stepto&
3156-
\XT[\val^n~(\THROWadm~a)] \\
3140+
\LABEL_n\{\}~\XB^l[\HANDLERadm_n\{l\}~\XT[(\THROWadm~a)]~\END]~\END &\stepto&
3141+
\XT[(\THROWadm~a)] \\
31573142
\end{array}
31583143
31593144
.. note::
3160-
The reduction step entering a catch clause |CAUGHTadm| is the only one that does not preserve the throw context.
3161-
3162-
.. todo::
3163-
Explain why or what's the meaning of apparently preserving the throw context in the other rules.
3145+
The rules are formulated in this way to allow looking up the exception values in the throw context,
3146+
only when a thrown exception is caught.
31643147

31653148

31663149
.. _exec-caughtadm-enter:
31673150

3168-
Entering :math:`\instr^\ast` with catch clause holding a caught exception :math:`\{a~\val^n\}`
3169-
..............................................................................................
3151+
Entering :math:`\instr^\ast` with caught exception :math:`\{\exn\}`
3152+
...................................................................
31703153

3171-
1. Push :math:`\CAUGHTadm\{a~\val^n\}` onto the stack.
3154+
1. Push the caught exception |exn| onto the stack.
31723155

31733156
2. Jump to the start of the instruction sequence :math:`\instr^\ast`.
31743157

31753158

3176-
.. _exec-caughtadm:
3159+
.. _exec-caughtadm-exit:
31773160

3178-
Exiting a catch clause
3179-
......................
3161+
Exiting a block with a caught exception
3162+
.......................................
31803163

3181-
When the |END| of a catch clause is reached without a jump, exception, or trap, then the following steps are performed.
3164+
When the |END| of a block with a caught exception is reached without a jump, thrown exception, or trap, then the following steps are performed.
31823165

3183-
1. Let :math:`\val^\ast` be the values on the top of the stack.
3166+
1. Let :math:`\val^m` be the values on the top of the stack.
31843167

3185-
2. Pop the values :math:`\val^\ast` from the stack.
3168+
2. Pop the values :math:`\val^m` from the stack.
31863169

3187-
3. Assert: due to :ref:`validation <valid-instr-seq>`, a caught exception :math:`\{a~\val_0^\ast\}` is now on the top of the stack.
3170+
3. Assert: due to :ref:`validation <valid-caughtadm>`, a caught exception is now on the top of the stack.
31883171

31893172
4. Pop the caught exception from the stack.
31903173

3191-
5. Push :math:`\val^\ast` back to the stack.
3174+
5. Push :math:`\val^m` back to the stack.
31923175

3193-
6. Jump to the position after the |END| of the administrative instruction associated with the catch clause.
3176+
6. Jump to the position after the |END| of the administrative instruction associated with the caught exception.
31943177

31953178
.. math::
31963179
\begin{array}{rcl}
3197-
\CAUGHTadm\{a~\val_0^\ast\}~\val^\ast~\END &\stepto& \val^\ast
3180+
\CAUGHTadm_n\{\exn\}~\val^m~\END &\stepto& \val^m
31983181
\end{array}
31993182
32003183
.. note::
3201-
An exception can only be rethrown from the scope of the |CAUGHTadm| administrative instruction holding it, i.e., from the scope of the |CATCH| or |CATCHALL| block of a :ref:`try-catch <syntax-try-catch>` instruction that caught it. Upon exit from a |CAUGHTadm|, the exception it holds is discarded.
3184+
A caught exception can only be rethrown from the scope of the administrative instruction associated with it, i.e., from the scope of the |CATCH| or |CATCHALL| block of a :ref:`try-catch <syntax-try-catch>` instruction that caught it. Upon exit from that block, the caught exception is discarded.
32023185

32033186

32043187
.. index:: ! call, function, function instance, label, frame

0 commit comments

Comments
 (0)