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

Commit 045e74b

Browse files
committed
Merging the entire reference types repository
- Import reference types repo: https://github.com/WebAssembly/reference-types/tree/5bc46bbd387b51f52ee0088e76ff401ece0c8e4a - Update README
1 parent 4d3526b commit 045e74b

File tree

190 files changed

+27724
-5776
lines changed

Some content is hidden

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

190 files changed

+27724
-5776
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "document/core/util/katex"]
22
path = document/core/util/katex
3-
url = https://github.com/KaTeX/KaTeX/
3+
url = https://github.com/KaTeX/KaTeX.git

.travis.yml

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
language: c++
21
language: python
32
python:
4-
- "2.7"
3+
- "3.7"
4+
dist: bionic
55

6-
sudo: on
7-
8-
before_install:
9-
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
10-
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
11-
- sudo apt-get update -qq
6+
addons:
7+
apt:
8+
sources:
9+
- sourceline: 'deb https://dl.yarnpkg.com/debian/ stable main'
10+
key_url: 'https://dl.yarnpkg.com/debian/pubkey.gpg'
11+
packages:
12+
- ocaml
13+
- ocamlbuild
14+
- texlive-full
15+
- yarn
1216

1317
install:
14-
- ./interpreter/meta/travis/install-ocaml.sh
15-
- sudo pip install sphinx==1.7.9
16-
- sudo apt-get install texlive-full yarn
18+
- pip install Sphinx==2.4.4
1719
- git clone https://github.com/tabatkins/bikeshed.git
1820
- pip install --editable $PWD/bikeshed
1921
- bikeshed update
@@ -26,5 +28,5 @@ os: linux
2628

2729
env:
2830
global:
29-
- ENCRYPTION_LABEL: "5d9ec396f41d"
31+
- ENCRYPTION_LABEL: "5d9ec396f41d" # does EH spec repo need own key?
3032
- COMMIT_AUTHOR_EMAIL: "[email protected]"

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/Makefile

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@ STATICDIR = _static
1010
DOWNLOADDIR = _download
1111
NAME = WebAssembly
1212

13-
# Hack until we have moved to more recent Sphinx.
14-
OLDMATHJAX = https://cdn.mathjax.org/mathjax/latest/MathJax.js
15-
NEWMATHJAX = https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js
16-
1713
# Internal variables.
1814
PAPEROPT_a4 = -D latex_paper_size=a4
1915
PAPEROPT_letter = -D latex_paper_size=letter
20-
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
16+
ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(SPHINXOPTS) .
2117
# the i18n builder cannot share the environment and doctrees with the others
2218
I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) .
2319

@@ -111,16 +107,10 @@ html:
111107
do \
112108
sed s:BASEDIR:.:g <$$file >$$file.out; \
113109
mv -f $$file.out $$file; \
114-
sed s~$(OLDMATHJAX)~$(NEWMATHJAX)~g <$$file >$$file.out; \
115-
mv -f $$file.out $$file; \
116110
done
117111
for file in `ls $(BUILDDIR)/html/*/*.html`; \
118112
do \
119113
sed s:BASEDIR:..:g <$$file >$$file.out; \
120-
sed 's;<body; <script type="text/javascript">MathJax.Hub.Config({TeX: {MAXBUFFER: 30*1024}})</script><body;' \
121-
<$$file.out >$$file; \
122-
rm -f $$file.out; \
123-
sed s~$(OLDMATHJAX)~$(NEWMATHJAX)~g <$$file >$$file.out; \
124114
mv -f $$file.out $$file; \
125115
done
126116
@echo

document/core/appendix/algorithm.rst

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,45 +22,38 @@ Data Structures
2222
~~~~~~~~~~~~~~~
2323

2424
Types are representable as an enumeration.
25-
A simple subtyping check can be defined on these types.
2625

2726
.. code-block:: pseudo
2827
29-
type val_type = I32 | I64 | F32 | F64 | Anyref | Funcref | Nullref | Bot
28+
type val_type = I32 | I64 | F32 | F64 | Funcref | Externref
3029
3130
func is_num(t : val_type) : bool =
32-
return t = I32 || t = I64 || t = F32 || t = F64 || t = Bot
31+
return t = I32 || t = I64 || t = F32 || t = F64
3332
3433
func is_ref(t : val_type) : bool =
35-
return t = Anyref || t = Funcref || t = Nullref || t = Bot
36-
37-
func matches(t1 : val_type, t2 : val_type) : bool =
38-
return t1 = t2 || t1 = Bot ||
39-
(t1 = Nullref && is_ref(t2)) || (is_ref(t1) && t2 = Anyref)
34+
return t = Funcref || t = Externref
4035
4136
The algorithm uses two separate stacks: the *value stack* and the *control stack*.
4237
The former tracks the :ref:`types <syntax-valtype>` of operand values on the :ref:`stack <stack>`,
4338
the latter surrounding :ref:`structured control instructions <syntax-instr-control>` and their associated :ref:`blocks <syntax-instr-control>`.
4439

4540
.. code-block:: pseudo
4641
47-
type val_stack = stack(val_type)
42+
type val_stack = stack(val_type | Unknown)
4843
4944
type ctrl_stack = stack(ctrl_frame)
5045
type ctrl_frame = {
51-
label_types : list(val_type)
46+
opcode : opcode
47+
start_types : list(val_type)
5248
end_types : list(val_type)
5349
height : nat
5450
unreachable : bool
5551
}
5652
57-
For each value, the value stack records its :ref:`value type <syntax-valtype>`.
53+
For each value, the value stack records its :ref:`value type <syntax-valtype>`, or :code:`Unknown` when the type is not known.
5854

59-
For each entered block, the control stack records a *control frame* with the type of the associated :ref:`label <syntax-label>` (used to type-check branches), the result type of the block (used to check its result), the height of the operand stack at the start of the block (used to check that operands do not underflow the current block), and a flag recording whether the remainder of the block is unreachable (used to handle :ref:`stack-polymorphic <polymorphism>` typing after branches).
6055

61-
.. note::
62-
In the presentation of this algorithm, multiple values are supported for the :ref:`result types <syntax-resulttype>` classifying blocks and labels.
63-
With the current version of WebAssembly, the :code:`list` could be simplified to an optional value.
56+
For each entered block, the control stack records a *control frame* with the originating opcode, the types on the top of the operand stack at the start and end of the block (used to check its result as well as branches), the height of the operand stack at the start of the block (used to check that operands do not underflow the current block), and a flag recording whether the remainder of the block is unreachable (used to handle :ref:`stack-polymorphic <polymorphism>` typing after branches).
6457

6558
For the purpose of presenting the algorithm, the operand and control stacks are simply maintained as global variables:
6659

@@ -73,17 +66,19 @@ However, these variables are not manipulated directly by the main checking funct
7366

7467
.. code-block:: pseudo
7568
76-
func push_val(type : val_type) =
69+
func push_val(type : val_type | Unknown) =
7770
vals.push(type)
7871
79-
func pop_val() : val_type =
80-
if (vals.size() = ctrls[0].height && ctrls[0].unreachable) return Bot
72+
func pop_val() : val_type | Unknown =
73+
if (vals.size() = ctrls[0].height && ctrls[0].unreachable) return Unknown
8174
error_if(vals.size() = ctrls[0].height)
8275
return vals.pop()
8376
84-
func pop_val(expect : val_type) : val_type =
77+
func pop_val(expect : val_type | Unknown) : val_type | Unknown =
8578
let actual = pop_val()
86-
error_if(not matches(actual, expect))
79+
if (actual = Unknown) return expect
80+
if (expect = Unknown) return actual
81+
error_if(actual =/= expect)
8782
return actual
8883
8984
func push_vals(types : list(val_type)) = foreach (t in types) push_val(t)
@@ -97,10 +92,10 @@ Pushing an operand value simply pushes the respective type to the value stack.
9792
Popping an operand value checks that the value stack does not underflow the current block and then removes one type.
9893
But first, a special case is handled where the block contains no known values, but has been marked as unreachable.
9994
That can occur after an unconditional branch, when the stack is typed :ref:`polymorphically <polymorphism>`.
100-
In that case, the :code:`Bot` type is returned, because that is a *principal* choice trivially satisfying all use constraints.
95+
In that case, an unknown type is returned.
10196

10297
A second function for popping an operand value takes an expected type, which the actual operand type is checked against.
103-
The types may differ by subtyping, including the case where the actual type is :code:`Bot`, and thereby matches unconditionally.
98+
The types may differ in case one of them is Unknown.
10499
The function returns the actual type popped from the stack.
105100

106101
Finally, there are accumulative functions for pushing or popping multiple operand types.
@@ -114,17 +109,21 @@ The control stack is likewise manipulated through auxiliary functions:
114109

115110
.. code-block:: pseudo
116111
117-
func push_ctrl(label : list(val_type), out : list(val_type)) =
118-
 let frame = ctrl_frame(label, out, vals.size(), false)
112+
func push_ctrl(opcode : opcode, in : list(val_type), out : list(val_type)) =
113+
 let frame = ctrl_frame(opcode, in, out, vals.size(), false)
119114
  ctrls.push(frame)
115+
push_vals(in)
120116
121-
func pop_ctrl() : list(val_type) =
117+
func pop_ctrl() : ctrl_frame =
122118
 error_if(ctrls.is_empty())
123119
 let frame = ctrls[0]
124120
  pop_vals(frame.end_types)
125121
  error_if(vals.size() =/= frame.height)
126122
ctrls.pop()
127-
  return frame.end_types
123+
  return frame
124+
125+
func label_types(frame : ctrl_frame) : list(val_types) =
126+
return (if frame.opcode == loop then frame.start_types else frame.end_types)
128127
129128
func unreachable() =
130129
  vals.resize(ctrls[0].height)
@@ -137,13 +136,15 @@ Popping a frame first checks that the control stack is not empty.
137136
It then verifies that the operand stack contains the right types of values expected at the end of the exited block and pops them off the operand stack.
138137
Afterwards, it checks that the stack has shrunk back to its initial height.
139138

139+
The type of the :ref:`label <syntax-label>` associated with a control frame is either that of the stack at the start or the end of the frame, determined by the opcode that it originates from.
140+
140141
Finally, the current frame can be marked as unreachable.
141142
In that case, all existing operand types are purged from the value stack, in order to allow for the :ref:`stack-polymorphism <polymorphism>` logic in :code:`pop_val` to take effect.
142143

143144
.. note::
144145
Even with the unreachable flag set, consecutive operands are still pushed to and popped from the operand stack.
145146
That is necessary to detect invalid :ref:`examples <polymorphism>` like :math:`(\UNREACHABLE~(\I32.\CONST)~\I64.\ADD)`.
146-
However, a polymorphic stack cannot underflow, but instead generates :code:`Bot` types as needed.
147+
However, a polymorphic stack cannot underflow, but instead generates :code:`Unknown` types as needed.
147148

148149

149150
.. index:: opcode
@@ -175,8 +176,8 @@ Other instructions are checked in a similar manner.
175176
let t1 = pop_val()
176177
let t2 = pop_val()
177178
error_if(not (is_num(t1) && is_num(t2)))
178-
error_if(t1 =/= t2 && t1 =/= Bot && t2 =/= Bot)
179-
push_val(if (t1 = Bot) t2 else t1)
179+
error_if(t1 =/= t2 && t1 =/= Unknown && t2 =/= Unknown)
180+
push_val(if (t1 = Unknown) t2 else t1)
180181
181182
case (select t)
182183
pop_val(I32)
@@ -187,44 +188,45 @@ Other instructions are checked in a similar manner.
187188
   case (unreachable)
188189
      unreachable()
189190
190-
case (block t*)
191-
push_ctrl([t*], [t*])
191+
case (block t1*->t2*)
192+
pop_vals([t1*])
193+
push_ctrl(block, [t1*], [t2*])
192194
193-
case (loop t*)
194-
push_ctrl([], [t*])
195+
case (loop t1*->t2*)
196+
pop_vals([t1*])
197+
push_ctrl(loop, [t1*], [t2*])
195198
196-
case (if t*)
199+
case (if t1*->t2*)
197200
pop_val(I32)
198-
push_ctrl([t*], [t*])
201+
pop_vals([t1*])
202+
push_ctrl(if, [t1*], [t2*])
199203
200204
case (end)
201-
let results = pop_ctrl()
202-
push_vals(results)
205+
let frame = pop_ctrl()
206+
push_vals(frame.end_types)
203207
204208
case (else)
205-
let results = pop_ctrl()
206-
push_ctrl(results, results)
209+
let frame = pop_ctrl()
210+
error_if(frame.opcode =/= if)
211+
push_ctrl(else, frame.start_types, frame.end_types)
207212
208213
case (br n)
209214
     error_if(ctrls.size() < n)
210-
      pop_vals(ctrls[n].label_types)
215+
      pop_vals(label_types(ctrls[n]))
211216
      unreachable()
212217
213218
case (br_if n)
214219
     error_if(ctrls.size() < n)
215220
pop_val(I32)
216-
      pop_vals(ctrls[n].label_types)
217-
      push_vals(ctrls[n].label_types)
221+
      pop_vals(label_types(ctrls[n]))
222+
      push_vals(label_types(ctrls[n]))
218223
219224
   case (br_table n* m)
220-
pop_val(I32)
221225
      error_if(ctrls.size() < m)
222-
let arity = ctrls[m].label_types.size()
223226
      foreach (n in n*)
224-
        error_if(ctrls.size() < n)
225-
        error_if(ctrls[n].label_types.size() =/= arity)
226-
push_vals(pop_vals(ctrls[n].label_types))
227-
pop_vals(ctrls[m].label_types)
227+
        error_if(ctrls.size() < n || label_types(ctrls[n]) =/= label_types(ctrls[m]))
228+
pop_val(I32)
229+
      pop_vals(label_types(ctrls[m]))
228230
      unreachable()
229231
230232
.. note::

document/core/appendix/implementation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ An implementation may impose restrictions on the following dimensions of a modul
4343
* the number of :ref:`exports <syntax-export>` from a :ref:`module <syntax-module>`
4444
* the number of parameters in a :ref:`function type <syntax-functype>`
4545
* the number of results in a :ref:`function type <syntax-functype>`
46+
* the number of parameters in a :ref:`block type <syntax-blocktype>`
47+
* the number of results in a :ref:`block type <syntax-blocktype>`
4648
* the number of :ref:`locals <syntax-local>` in a :ref:`function <syntax-func>`
4749
* the size of a :ref:`function <syntax-func>` body
4850
* the size of a :ref:`structured control instruction <syntax-instr-control>`

0 commit comments

Comments
 (0)