Skip to content

Commit 06d5b3f

Browse files
committed
Current core formal spec for WebAssembly Exception Handling
This adds: - the informal formal core spec laid out by Andreas Rossberg: WebAssembly#87 (comment) and - the core spec outlined in the proposal overview: https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md I have aimed for this to be as complete as possible for the above "informal formal spec" and proposal overview, meaning I added prose for all the relevant parts in syntax, validation, execution, binary format, text format, and the appendix, as well as an example for throw contexts. I also updated the README.md to: - remove mention to multi-value which is now part of the main spec, and - add a build status icon for the exception-handling modified spec.
1 parent fa7165b commit 06d5b3f

27 files changed

+1121
-154
lines changed

README.md

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
1-
[![Build Status](https://travis-ci.org/WebAssembly/spec.svg?branch=master)](https://travis-ci.org/WebAssembly/spec)
1+
[![Build Status](https://travis-ci.org/WebAssembly/exception-handling.svg?branch=master)](https://travis-ci.org/WebAssembly/exception-handling)
22

3-
# Exception handling
3+
# Exception Handling Proposal for WebAssembly
44

55
This repository
66
holds a
77
[proposal](https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md) for
88
adding exception handling to WebAssembly.
99

10-
The exception handling proposal depends on the [reference-types](https://github.com/WebAssembly/reference-types) proposal
11-
and on the [multi-value](https://github.com/WebAssembly/multi-value) proposal.
10+
* See the [proposal overview](proposals/Exceptions.md) for a summary of the proposal.
1211

13-
The repository is a clone
14-
of [WebAssembly/spec](https://github.com/WebAssembly/spec), first rebased on the spec of its dependency [reference-types](https://github.com/WebAssembly/reference-types), and then merged with the other dependency [multi-value](https://github.com/WebAssembly/multi-value).
12+
The repository is now based on the [reference types proposal](proposals/reference-types/Overview.md) and includes all respective changes.
1513

16-
The remainder of the document has contents of the two README files of the dependencies: [reference-types/README.md](https://github.com/WebAssembly/reference-types/blob/master/README.md) and [multi-value/README.md](https://github.com/WebAssembly/multi-value/blob/master/README.md).
17-
18-
# Reference Types Proposal for WebAssembly
19-
20-
[![Build Status](https://travis-ci.org/WebAssembly/reference-types.svg?branch=master)](https://travis-ci.org/WebAssembly/reference-types)
21-
22-
This repository is a clone of [github.com/WebAssembly/spec/](https://github.com/WebAssembly/spec/).
23-
It is meant for discussion, prototype specification and implementation of a proposal to add support for basic reference types to WebAssembly.
24-
25-
* See the [overview](https://github.com/WebAssembly/reference-types/blob/master/proposals/reference-types/Overview.md) for a summary of the proposal.
26-
27-
* See the [modified spec](https://webassembly.github.io/reference-types/) for details.
28-
29-
# Multi-value Proposal for WebAssembly
30-
31-
[![Build Status](https://travis-ci.org/WebAssembly/multi-value.svg?branch=master)](https://travis-ci.org/WebAssembly/multi-value)
32-
33-
This repository is a clone of [github.com/WebAssembly/spec/](https://github.com/WebAssembly/spec/).
34-
It is meant for discussion, prototype specification and implementation of a proposal to add support for returning multiple values to WebAssembly.
35-
36-
* See the [overview](https://github.com/WebAssembly/multi-value/blob/master/proposals/multi-value/Overview.md) for a summary of the proposal.
37-
38-
* See the [modified spec](https://webassembly.github.io/multi-value/) for details.
39-
40-
Original `README` from upstream repository follows...
14+
Original README from upstream repository follows...
4115

4216
# spec
4317

document/core/appendix/algorithm.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ Types are representable as an enumeration.
2525

2626
.. code-block:: pseudo
2727
28-
type val_type = I32 | I64 | F32 | F64 | Funcref | Externref
28+
type val_type = I32 | I64 | F32 | F64 | Funcref | Externref | Exnref
2929
3030
func is_num(t : val_type) : bool =
3131
return t = I32 || t = I64 || t = F32 || t = F64
3232
3333
func is_ref(t : val_type) : bool =
34-
return t = Funcref || t = Externref
34+
return t = Funcref || t = Externref || t = Exnref
3535
3636
The algorithm uses two separate stacks: the *value stack* and the *control stack*.
3737
The former tracks the :ref:`types <syntax-valtype>` of operand values on the :ref:`stack <stack>`,
@@ -210,6 +210,15 @@ Other instructions are checked in a similar manner.
210210
error_if(frame.opcode =/= if)
211211
push_ctrl(else, frame.start_types, frame.end_types)
212212
213+
case (try t1*->t2*)
214+
pop_vals([t1*])
215+
push_ctrl(try, [t1*], [t2*])
216+
217+
case (catch)
218+
let frame = pop_ctrl()
219+
error_if(frame.opcode =/= try)
220+
push_ctrl(catch, [exnref], frame.end_types)
221+
213222
case (br n)
214223
     error_if(ctrls.size() < n)
215224
      pop_vals(label_types(ctrls[n]))

document/core/appendix/embedding.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ Store
7676

7777
.. math::
7878
\begin{array}{lclll}
79-
\F{store\_init}() &=& \{ \SFUNCS~\epsilon,~ \SMEMS~\epsilon,~ \STABLES~\epsilon,~ \SGLOBALS~\epsilon \} \\
79+
\F{store\_init}() &=& \{ \SFUNCS~\epsilon,~ \SMEMS~\epsilon, ~\SEVENTS~\epsilon,~ \STABLES~\epsilon,~ \SGLOBALS~\epsilon \} \\
8080
\end{array}
8181
8282
@@ -539,6 +539,28 @@ Memories
539539
\end{array}
540540
541541
542+
.. index: event, event address, store, event instance, event type, exception attribute, function type
543+
.. _embed-event:
544+
545+
Events
546+
~~~~~~
547+
548+
.. _embedd-event-alloc:
549+
550+
:math:`\F{event\_alloc}(\store, \eventtype) : (\store, \eventaddr)`
551+
...................................................................
552+
553+
1. Pre-condition: :math:`eventtype` is :ref:`valid <valid-eventtype>`.
554+
555+
2. Let :math:`\eventaddr` be the result of :ref:`allocating an event <alloc-event>` in :math:`\store` with :ref:`event type <syntax-eventtype>` :math:`\eventtype`.
556+
557+
3. Return the new store paired with :math:`\eventaddr`.
558+
559+
.. math::
560+
\begin{array}{lclll}
561+
\F{event\_alloc}(S, \X{et}) &=& (S', \X{a}) && (\iff \allocevent(S, \X{et}) = S', \X{a}) \\
562+
\end{array}
563+
542564
543565
.. index:: global, global address, store, global instance, global type, value
544566
.. _embed-global:

document/core/appendix/implementation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ An implementation may impose restrictions on the following dimensions of a modul
3636
* the number of :ref:`functions <syntax-func>` in a :ref:`module <syntax-module>`, including imports
3737
* the number of :ref:`tables <syntax-table>` in a :ref:`module <syntax-module>`, including imports
3838
* the number of :ref:`memories <syntax-mem>` in a :ref:`module <syntax-module>`, including imports
39+
* the number of :ref:`events <syntax-event>` in a :ref:`module <syntax-module>`, including imports
3940
* the number of :ref:`globals <syntax-global>` in a :ref:`module <syntax-module>`, including imports
4041
* the number of :ref:`element segments <syntax-elem>` in a :ref:`module <syntax-module>`
4142
* the number of :ref:`data segments <syntax-data>` in a :ref:`module <syntax-module>`
@@ -123,6 +124,7 @@ Restrictions on the following dimensions may be imposed during :ref:`execution <
123124
* the number of allocated :ref:`function instances <syntax-funcinst>`
124125
* the number of allocated :ref:`table instances <syntax-tableinst>`
125126
* the number of allocated :ref:`memory instances <syntax-meminst>`
127+
* the number of allocated :ref:`event instances <syntax-eventinst>`
126128
* the number of allocated :ref:`global instances <syntax-globalinst>`
127129
* the size of a :ref:`table instance <syntax-tableinst>`
128130
* the size of a :ref:`memory instance <syntax-meminst>`

document/core/appendix/index-instructions.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ Instruction Binary Opcode Type
1313
:math:`\LOOP~\X{bt}` :math:`\hex{03}` :math:`[t_1^\ast] \to [t_2^\ast]` :ref:`validation <valid-loop>` :ref:`execution <exec-loop>`
1414
:math:`\IF~\X{bt}` :math:`\hex{04}` :math:`[t_1^\ast] \to [t_2^\ast]` :ref:`validation <valid-if>` :ref:`execution <exec-if>`
1515
:math:`\ELSE` :math:`\hex{05}`
16-
(reserved) :math:`\hex{06}`
17-
(reserved) :math:`\hex{07}`
18-
(reserved) :math:`\hex{08}`
19-
(reserved) :math:`\hex{09}`
20-
(reserved) :math:`\hex{0A}`
16+
:math:`\TRY~\X{bt}` :math:`\hex{06}` :math:`[t_1^\ast] \to [t_2^\ast]` :ref:`validation <valid-try>` :ref:`execution <exec-try>`
17+
:math:`\CATCH` :math:`\hex{07}`
18+
:math:`\THROW~x` :math:`\hex{08}` :math:`[t_1^\ast~t^\ast] \to [t_2^\ast]` :ref:`validation <valid-throw>` :ref:`execution <exec-throw>`
19+
:math:`\RETHROW` :math:`\hex{09}` :math:`[t_1^\ast~\EXNREF] \to [t_2^\ast]` :ref:`validation <valid-rethrow>` :ref:`execution <exec-rethrow>`
20+
:math:`\BRONEXN~l~x` :math:`\hex{0A}` :math:`[\EXNREF] \to [\EXNREF]` :ref:`validation <valid-br_on_exn>` :ref:`execution <exec-br_on_exn>`
2121
:math:`\END` :math:`\hex{0B}`
2222
:math:`\BR~l` :math:`\hex{0C}` :math:`[t_1^\ast~t^\ast] \to [t_2^\ast]` :ref:`validation <valid-br>` :ref:`execution <exec-br>`
2323
:math:`\BRIF~l` :math:`\hex{0D}` :math:`[t^\ast~\I32] \to [t^\ast]` :ref:`validation <valid-br_if>` :ref:`execution <exec-br_if>`

document/core/appendix/index-rules.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Construct Judgement
1818
:ref:`Block type <valid-blocktype>` :math:`\vdashblocktype \blocktype \ok`
1919
:ref:`Table type <valid-tabletype>` :math:`\vdashtabletype \tabletype \ok`
2020
:ref:`Memory type <valid-memtype>` :math:`\vdashmemtype \memtype \ok`
21+
:ref:`Event type <valid-eventtype>` :math:`\vdasheventtype \eventtype \ok`
2122
:ref:`Global type <valid-globaltype>` :math:`\vdashglobaltype \globaltype \ok`
2223
:ref:`External type <valid-externtype>` :math:`\vdashexterntype \externtype \ok`
2324
:ref:`Instruction <valid-instr>` :math:`S;C \vdashinstr \instr : \functype`
@@ -26,6 +27,7 @@ Construct Judgement
2627
:ref:`Function <valid-func>` :math:`C \vdashfunc \func : \functype`
2728
:ref:`Table <valid-table>` :math:`C \vdashtable \table : \tabletype`
2829
:ref:`Memory <valid-mem>` :math:`C \vdashmem \mem : \memtype`
30+
:ref:`Event <valid-event>` :math:`C \vdashevent \event : \eventtype`
2931
:ref:`Global <valid-global>` :math:`C \vdashglobal \global : \globaltype`
3032
:ref:`Element segment <valid-elem>` :math:`C \vdashelem \elem : \reftype`
3133
:ref:`Element mode <valid-elemmode>` :math:`C \vdashelemmode \elemmode : \reftype`
@@ -54,6 +56,7 @@ Construct Judgement
5456
:ref:`Function instance <valid-funcinst>` :math:`S \vdashfuncinst \funcinst : \functype`
5557
:ref:`Table instance <valid-tableinst>` :math:`S \vdashtableinst \tableinst : \tabletype`
5658
:ref:`Memory instance <valid-meminst>` :math:`S \vdashmeminst \meminst : \memtype`
59+
:ref:`Event instance <valid-eventinst>` :math:`S \vdasheventinst \eventinst : \eventtype`
5760
:ref:`Global instance <valid-globalinst>` :math:`S \vdashglobalinst \globalinst : \globaltype`
5861
:ref:`Element instance <valid-eleminst>` :math:`S \vdasheleminst \eleminst \ok`
5962
:ref:`Data instance <valid-datainst>` :math:`S \vdashdatainst \datainst \ok`
@@ -97,6 +100,7 @@ Construct Judgement
97100
:ref:`Function instance <extend-funcinst>` :math:`\vdashfuncinstextends \funcinst_1 \extendsto \funcinst_2`
98101
:ref:`Table instance <extend-tableinst>` :math:`\vdashtableinstextends \tableinst_1 \extendsto \tableinst_2`
99102
:ref:`Memory instance <extend-meminst>` :math:`\vdashmeminstextends \meminst_1 \extendsto \meminst_2`
103+
:ref:`Event instance <extend-eventinst>` :math:`\vdasheventinstextends \eventinst_1 \extendsto \eventinst_2`
100104
:ref:`Global instance <extend-globalinst>` :math:`\vdashglobalinstextends \globalinst_1 \extendsto \globalinst_2`
101105
:ref:`Element instance <extend-eleminst>` :math:`\vdasheleminstextends \eleminst_1 \extendsto \eleminst_2`
102106
:ref:`Data instance <extend-datainst>` :math:`\vdashdatainstextends \datainst_1 \extendsto \datainst_2`

document/core/appendix/index-types.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ Category Constructor
1515
(reserved) :math:`\hex{7B}` .. :math:`\hex{71}`
1616
:ref:`Reference type <syntax-reftype>` |FUNCREF| :math:`\hex{70}` (-16 as |Bs7|)
1717
:ref:`Reference type <syntax-reftype>` |EXTERNREF| :math:`\hex{6F}` (-17 as |Bs7|)
18-
(reserved) :math:`\hex{6E}` .. :math:`\hex{61}`
18+
:ref:`Reference type <syntax-reftype>` |EXNREF| :math:`\hex{6E}` (-18 as |Bs7|)
19+
(reserved) :math:`\hex{6D}` .. :math:`\hex{61}`
1920
:ref:`Function type <syntax-functype>` :math:`[\valtype^\ast] \to [\valtype^\ast]` :math:`\hex{60}` (-32 as |Bs7|)
2021
(reserved) :math:`\hex{5F}` .. :math:`\hex{41}`
2122
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)
2223
:ref:`Table type <syntax-tabletype>` :math:`\limits~\reftype` (none)
2324
:ref:`Memory type <syntax-memtype>` :math:`\limits` (none)
25+
:ref:`Event type <syntax-eventtype>` :math:`\EXCEPTION~\functype` (none)
2426
:ref:`Global type <syntax-globaltype>` :math:`\mut~\valtype` (none)
2527
======================================== =========================================== ===============================================================================

0 commit comments

Comments
 (0)