Skip to content

Commit 1b99eaa

Browse files
committed
Merge remote-tracking branch 'exn/main' into wasm-3.0
2 parents 3fb483d + 24be425 commit 1b99eaa

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3308
-326
lines changed

.github/workflows/ci-spec.yml

+28-8
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
name: code-metadata-rendered
9191
path: document/metadata/code/_build/html
9292

93-
build-legacy-exceptions-spec:
93+
build-legacy-exceptions-core-spec:
9494
runs-on: ubuntu-latest
9595
steps:
9696
- name: Checkout repo
@@ -102,16 +102,31 @@ jobs:
102102
- name: Setup Sphinx
103103
run: pip install six && pip install sphinx==5.1.0
104104
- name: Build main spec
105-
run: cd document/legacy/exceptions && make main
105+
run: cd document/legacy/exceptions/core && make main
106106
- name: Upload artifact
107107
uses: actions/upload-artifact@v2
108108
with:
109-
name: legacy-exceptions-rendered
110-
path: document/legacy/exceptions/_build/html
109+
name: legacy-exceptions-core-rendered
110+
path: document/legacy/exceptions/core/_build/html
111+
112+
build-legacy-exceptions-js-api-spec:
113+
runs-on: ubuntu-latest
114+
steps:
115+
- name: Checkout repo
116+
uses: actions/checkout@v2
117+
- name: Setup Bikeshed
118+
run: pip install bikeshed && bikeshed update
119+
- name: Run Bikeshed
120+
run: bikeshed spec "document/legacy/exceptions/js-api/index.bs" "document/legacy/exceptions/js-api/index.html"
121+
- name: Upload artifact
122+
uses: actions/upload-artifact@v2
123+
with:
124+
name: legacy-exceptions-js-api-rendered
125+
path: document/legacy/exceptions/js-api/index.html
111126

112127
publish-spec:
113128
runs-on: ubuntu-latest
114-
needs: [build-core-spec, build-js-api-spec, build-web-api-spec, build-code-metadata-spec, build-legacy-exceptions-spec]
129+
needs: [build-core-spec, build-js-api-spec, build-web-api-spec, build-code-metadata-spec, build-legacy-exceptions-core-spec, build-legacy-exceptions-js-api-spec]
115130
steps:
116131
- name: Checkout repo
117132
uses: actions/checkout@v2
@@ -137,11 +152,16 @@ jobs:
137152
with:
138153
name: code-metadata-rendered
139154
path: _output/metadata/code
140-
- name: Download legacy exceptions spec artifact
155+
- name: Download legacy exceptions core spec artifact
156+
uses: actions/download-artifact@v2
157+
with:
158+
name: legacy-exceptions-core-rendered
159+
path: _output/legacy/exceptions/core
160+
- name: Download legacy exceptions JS API spec artifact
141161
uses: actions/download-artifact@v2
142162
with:
143-
name: legacy-exceptions-rendered
144-
path: _output/legacy/exceptions
163+
name: legacy-exceptions-js-api-rendered
164+
path: _output/legacy/exceptions/js-api
145165
- name: Publish to GitHub Pages
146166
if: github.ref == 'refs/heads/main'
147167
uses: peaceiris/actions-gh-pages@v3

document/core/appendix/embedding.rst

+92-7
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,19 @@ Interface operation that are predicates return Boolean values:
3939
4040
.. _embed-error:
4141

42-
Errors
43-
~~~~~~
42+
Exceptions and Errors
43+
~~~~~~~~~~~~~~~~~~~~~
44+
45+
Invoking an exported function may throw or propagate exceptions, expressed by an auxiliary syntactic class:
46+
47+
.. math::
48+
\begin{array}{llll}
49+
\production{exception} & \exception &::=& \ETHROW ~ \exnaddr \\
50+
\end{array}
4451
45-
Failure of an interface operation is indicated by an auxiliary syntactic class:
52+
The exception address :math:`exnaddr` identifies the exception thrown.
53+
54+
Failure of an interface operation is also indicated by an auxiliary syntactic class:
4655

4756
.. math::
4857
\begin{array}{llll}
@@ -56,6 +65,8 @@ In addition to the error conditions specified explicitly in this section, such a
5665
Implementations can refine it to carry suitable classifications and diagnostic messages.
5766

5867

68+
69+
5970
Pre- and Post-Conditions
6071
~~~~~~~~~~~~~~~~~~~~~~~~
6172

@@ -307,22 +318,25 @@ Functions
307318
.. index:: invocation, value, result
308319
.. _embed-func-invoke:
309320

310-
:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \error)`
311-
........................................................................................
321+
:math:`\F{func\_invoke}(\store, \funcaddr, \val^\ast) : (\store, \val^\ast ~|~ \exception ~|~ \error)`
322+
......................................................................................................
312323

313324
1. Try :ref:`invoking <exec-invocation>` the function :math:`\funcaddr` in :math:`\store` with :ref:`values <syntax-val>` :math:`\val^\ast` as arguments:
314325

315326
a. If it succeeds with :ref:`values <syntax-val>` :math:`{\val'}^\ast` as results, then let :math:`\X{result}` be :math:`{\val'}^\ast`.
316327

317-
b. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`.
328+
b. Else if the outcome is an exception with a thrown :ref:`exception <exec-throw_ref>` :math:`\REFEXNADDR~\exnaddr` as the result, then let :math:`\X{result}` be :math:`\ETHROW~\exnaddr`
329+
330+
c. Else it has trapped, hence let :math:`\X{result}` be :math:`\ERROR`.
318331

319332
2. Return the new store paired with :math:`\X{result}`.
320333

321334
.. math::
322335
~ \\
323336
\begin{array}{lclll}
324337
\F{func\_invoke}(S, a, v^\ast) &=& (S', {v'}^\ast) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; {v'}^\ast) \\
325-
\F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \result) \\
338+
\F{func\_invoke}(S, a, v^\ast) &=& (S', \ETHROW~a') && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \XT[(\REFEXNADDR~a')~\THROWREF] \\
339+
\F{func\_invoke}(S, a, v^\ast) &=& (S', \ERROR) && (\iff \invoke(S, a, v^\ast) \stepto^\ast S'; F; \TRAP) \\
326340
\end{array}
327341
328342
.. note::
@@ -576,6 +590,77 @@ Tags
576590
\end{array}
577591
578592
593+
.. _embed-tag-type:
594+
595+
:math:`\F{tag\_type}(\store, \tagaddr) : \tagtype`
596+
..................................................
597+
598+
1. Return :math:`S.\STAGS[a].\TAGITYPE`.
599+
600+
2. Post-condition: the returned :ref:`tag type <syntax-tagtype>` is :ref:`valid <valid-tagtype>`.
601+
602+
.. math::
603+
\begin{array}{lclll}
604+
\F{tag\_type}(S, a) &=& S.\STAGS[a].\TAGITYPE \\
605+
\end{array}
606+
607+
608+
.. index:: exception, exception address, store, exception instance, exception type
609+
.. _embed-exception:
610+
611+
Exceptions
612+
~~~~~~~~~~
613+
614+
.. _embed-exn-alloc:
615+
616+
:math:`\F{exn\_alloc}(\store, \tagaddr, \val^\ast) : (\store, \exnaddr)`
617+
........................................................................
618+
619+
1. Pre-condition: :math:`\tagaddr` is an allocated :ref:`tag address <syntax-tagaddr>`.
620+
621+
2. Let :math:`\exnaddr` be the result of :ref:`allocating an exception instance <syntax-exninst>` in :math:`\store` with :ref:`tag address <syntax-tagaddr>` :math:`\tagaddr` and initialization values :math:`\val^\ast`.
622+
623+
3. Return the new store paired with :math:`\exnaddr`.
624+
625+
.. math::
626+
\begin{array}{lcll}
627+
\F{exn\_alloc}(S, \tagaddr, \val^\ast) &=& (S \compose \{\SEXNS~\exninst\}, |S.\SEXNS|) &
628+
(\iff \exninst = \{\EITAG~\tagaddr, \EIFIELDS~\val^\ast\} \\
629+
\end{array}
630+
631+
632+
.. _embed-exn-tag:
633+
634+
:math:`\F{exn\_tag}(\store, \exnaddr) : \tagaddr`
635+
.................................................
636+
637+
1. Let :math:`\exninst` be the :ref:`exception instance <syntax-exninst>` :math:`\store.\SEXNS[\exnaddr]`.
638+
639+
2. Return the :ref:`tag address <syntax-tagaddr>` :math:`\exninst.\EITAG`.
640+
641+
.. math::
642+
\begin{array}{lcll}
643+
\F{exn\_tag}(S, a) &=& \exninst.\EITAG &
644+
(\iff \exninst = S.\SEXNS[a]) \\
645+
\end{array}
646+
647+
648+
.. _embed-exn-read:
649+
650+
:math:`\F{exn\_read}(\store, \exnaddr) : \val^\ast`
651+
...................................................
652+
653+
1. Let :math:`\exninst` be the :ref:`exception instance <syntax-exninst>` :math:`\store.\SEXNS[\exnaddr]`.
654+
655+
2. Return the :ref:`values <syntax-val>` :math:`\exninst.\EIFIELDS`.
656+
657+
.. math::
658+
\begin{array}{lcll}
659+
\F{exn\_read}(S, a) &=& \exninst.\EIFIELDS &
660+
(\iff \exninst = S.\SEXNS[a]) \\
661+
\end{array}
662+
663+
579664
.. index:: global, global address, store, global instance, global type, value
580665
.. _embed-global:
581666

document/core/binary/modules.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ It decodes into a vector of :ref:`imports <syntax-import>` that represent the |M
181181
\hex{01}~~\X{tt}{:}\Btabletype &\Rightarrow& \IDTABLE~\X{tt} \\ &&|&
182182
\hex{02}~~\X{mt}{:}\Bmemtype &\Rightarrow& \IDMEM~\X{mt} \\ &&|&
183183
\hex{03}~~\X{gt}{:}\Bglobaltype &\Rightarrow& \IDGLOBAL~\X{gt} \\ &&|&
184-
\hex{04}~~\X{tt}{:}\Btag &\Rightarrow& \IDTAG~\X{tt} \\
184+
\hex{04}~~\X{tt}{:}\Btagtype &\Rightarrow& \IDTAG~\X{tt} \\
185185
\end{array}
186186
187187

document/core/exec/instructions.rst

+9-11
Original file line numberDiff line numberDiff line change
@@ -4030,27 +4030,25 @@ Control Instructions
40304030

40314031
2. Assert: due to :ref:`validation <valid-throw>`, :math:`F.\AMODULE.\MITAGS[x]` exists.
40324032

4033-
3. Let :math:`a` be the :ref:`tag address <syntax-tagaddr>` :math:`F.\AMODULE.\MITAGS[x]`.
4033+
3. Let :math:`ta` be the :ref:`tag address <syntax-tagaddr>` :math:`F.\AMODULE.\MITAGS[x]`.
40344034

4035-
4. Assert: due to :ref:`validation <valid-throw>`, :math:`S.\STAGS[a]` exists.
4035+
4. Assert: due to :ref:`validation <valid-throw>`, :math:`S.\STAGS[ta]` exists.
40364036

4037-
5. Let :math:`\X{ti}` be the :ref:`tag instance <syntax-taginst>` :math:`S.\STAGS[a]`.
4037+
5. Let :math:`\X{ti}` be the :ref:`tag instance <syntax-taginst>` :math:`S.\STAGS[ta]`.
40384038

40394039
6. Let :math:`[t^n] \toF [{t'}^\ast]` be the :ref:`tag type <syntax-tagtype>` :math:`\X{ti}.\TAGITYPE`.
40404040

40414041
7. Assert: due to :ref:`validation <valid-throw>`, there are at least :math:`n` values on the top of the stack.
40424042

40434043
8. Pop the :math:`n` values :math:`\val^n` from the stack.
40444044

4045-
9. Let :math:`\X{exn}` be the :ref:`exception instance <syntax-exninst>` :math:`\{ \EITAG~a, \EIFIELDS~\val^n \}`.
4045+
9. Let :math:`\X{ea}` be the :ref:`exception address <syntax-exnaddr>` resulting from :ref:`allocating <alloc-exception>` an exception instance with tag address :math:`ta` and initializer values :math:`\val^n`.
40464046

4047-
10. Let :math:`\X{ea}` be the length of :math:`S.\SEXNS`.
4047+
10. Let :math:`\X{exn}` be :math:`S.\SEXNS[ea]`
40484048

4049-
11. Append :math:`\X{exn}` to :math:`S.\SEXNS`.
4049+
11. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack.
40504050

4051-
12. Push the value :math:`\REFEXNADDR~\X{ea}` to the stack.
4052-
4053-
13. Execute the instruction |THROWREF|.
4051+
12. Execute the instruction |THROWREF|.
40544052

40554053
.. math::
40564054
~\\[-1ex]
@@ -4114,13 +4112,13 @@ Control Instructions
41144112

41154113
a. Let :math:`\catch_1` be the first :ref:`catch clause <syntax-catch>` in :math:`\catch^\ast` and :math:`{\catch'}^\ast` the remaining clauses.
41164114

4117-
b. If :math:`\catch_1` is of the form :math:`\CATCH~x~l` and the :ref:`exception address <syntax-exnaddr>` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
4115+
b. If :math:`\catch_1` is of the form :math:`\CATCH~x~l` and the :ref:`tag address <syntax-tagaddr>` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
41184116

41194117
i. Push the values :math:`\X{exn}.\EIFIELDS` to the stack.
41204118

41214119
ii. Execute the instruction :math:`\BR~l`.
41224120

4123-
c. Else if :math:`\catch_1` is of the form :math:`\CATCHREF~x~l` and the :ref:`exception address <syntax-exnaddr>` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
4121+
c. Else if :math:`\catch_1` is of the form :math:`\CATCHREF~x~l` and the :ref:`tag address <syntax-tagaddr>` :math:`a` equals :math:`F.\AMODULE.\MITAGS[x]`, then:
41244122

41254123
i. Push the values :math:`\X{exn}.\EIFIELDS` to the stack.
41264124

document/core/exec/modules.rst

+26
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,32 @@ are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the fo
170170
\end{array}
171171
172172
173+
.. index:: exception, exception instance, exception address, tag address
174+
.. _alloc-exception:
175+
176+
:ref:`Exceptions <syntax-exninst>`
177+
..................................
178+
179+
1. Let :math:`ta` be the :ref:`tag address <syntax-tagaddr>` associated with the exception to allocate and :math:`\EIFIELDS~\val^\ast` be the values to initialize the exception with.
180+
181+
2. Let :math:`a` be the first free :ref:`exception address <syntax-exnaddr>` in :math:`S`.
182+
183+
3. Let :math:`\exninst` be the :ref:`exception instance <syntax-exninst>` :math:`\{ \EITAG~ta, \EIFIELDS~\val^\ast \}`.
184+
185+
4. Append :math:`\exninst` to the |SEXNS| of :math:`S`.
186+
187+
5. Return :math:`a`.
188+
189+
.. math::
190+
\begin{array}{rlll}
191+
\allocexn(S, \tagaddr, \val^\ast) &=& S', \exnaddr \\[1ex]
192+
\mbox{where:} \hfill \\
193+
\exnaddr &=& |S.\SEXNS| \\
194+
\exninst &=& \{ \EITAG~\tagaddr, \EIFIELDS~\val^\ast \} \\
195+
S' &=& S \compose \{\SEXNS~\exninst\} \\
196+
\end{array}
197+
198+
173199
.. index:: global, global instance, global address, global type, value type, mutability, value
174200
.. _alloc-global:
175201

document/core/util/macros.def

+4
Original file line numberDiff line numberDiff line change
@@ -1202,6 +1202,8 @@
12021202
.. |allocdata| mathdef:: \xref{exec/modules}{alloc-data}{\F{allocdata}}
12031203
.. |allocmodule| mathdef:: \xref{exec/modules}{alloc-module}{\F{allocmodule}}
12041204

1205+
.. |allocexn| mathdef:: \xref{exec/modules}{alloc-exception}{\F{allocexn}}
1206+
12051207
.. |growtable| mathdef:: \xref{exec/modules}{grow-table}{\F{growtable}}
12061208
.. |growmem| mathdef:: \xref{exec/modules}{grow-mem}{\F{growmem}}
12071209

@@ -1627,3 +1629,5 @@
16271629

16281630
.. |error| mathdef:: \xref{appendix/embedding}{embed-error}{\X{error}}
16291631
.. |ERROR| mathdef:: \xref{appendix/embedding}{embed-error}{\K{error}}
1632+
.. |exception| mathdef:: \xref{appendix/embedding}{embed-error}{\X{exception}}
1633+
.. |ETHROW| mathdef:: \xref{appendix/embedding}{embed-error}{\K{THROW}}

document/index.html

+11-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,17 @@ <h3>Legacy Extensions</h3>
8282
<ul>
8383
<li><p><b>Legacy Exception Handling</b>: defines additional instructions for exception handling that may still be available in some engines and tools, specifically web browsers.</p>
8484
<ul>
85-
<li><a href="legacy/exceptions/">Browser version</a></li>
86-
<li><a href="legacy/exceptions/_download/WebAssembly-Legacy-Exceptions.pdf">PDF version</a></li>
85+
<li><p><b>Core specification</b></p>
86+
<ul>
87+
<li><a href="legacy/exceptions/core/">Browser version</a></li>
88+
<li><a href="legacy/exceptions/core/_download/WebAssembly-Legacy-Exceptions.pdf">PDF version</a></li>
89+
</ul>
90+
</li>
91+
<li><p><b>JavaScirpt Embedding</b></p>
92+
<ul>
93+
<li><a href="legacy/exceptions/js-api/">W3C version</a></li>
94+
</ul>
95+
</li>
8796
</ul>
8897
</li>
8998
</ul>

0 commit comments

Comments
 (0)