Skip to content

Commit 25a78b9

Browse files
authored
Merge pull request #25 from dhil/wasmfx-merge
Merge with WebAssembly/function-references and WebAssembly/gc
2 parents 4663060 + 4fb7135 commit 25a78b9

File tree

12 files changed

+335
-229
lines changed

12 files changed

+335
-229
lines changed

document/core/appendix/algorithm.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,28 @@ We further assume that :ref:`validation <valid-valtype>` and :ref:`subtyping <ma
9595
func is_struct(t : comp_type) : bool
9696
func is_array(t : comp_type) : bool
9797
98+
Finally, the following function computes the least precise supertype of a given :ref:`heap type <syntax-heaptype>` (its corresponding top type):
99+
100+
.. code-block:: pseudo
101+
102+
func top_heap_type(t : heap_type) : heap_type =
103+
switch (t)
104+
case (Any | Eq | I31 | Struct | Array | None)
105+
return Any
106+
case (Func | Nofunc)
107+
return Func
108+
case (Extern | Noextern)
109+
return Extern
110+
case (Def(dt))
111+
switch (dt.rec.types[dt.proj].body)
112+
case (Struct(_) | Array(_))
113+
return Any
114+
case (Func(_))
115+
return Func
116+
case (Bot)
117+
raise CannotOccurInSource
118+
119+
98120
Context
99121
.......
100122

@@ -312,6 +334,11 @@ Other instructions are checked in a similar manner.
312334
let rt = pop_ref()
313335
push_val(Ref(rt.heap, false))
314336
337+
case (ref.test rt)
338+
validate_ref_type(rt)
339+
pop_val(Ref(top_heap_type(rt), true))
340+
push_val(I32)
341+
315342
case (local.get x)
316343
get_local(x)
317344
push_val(locals[x])

document/core/appendix/index-instructions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat
8787
Instruction(r'\CALL~x', r'\hex{10}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-call', r'exec-call'),
8888
Instruction(r'\CALLINDIRECT~x~y', r'\hex{11}', r'[t_1^\ast~\I32] \to [t_2^\ast]', r'valid-call_indirect', r'exec-call_indirect'),
8989
Instruction(r'\RETURNCALL~x', r'\hex{12}', r'[t_1^\ast] \to [t_2^\ast]', r'valid-return_call', r'exec-return_call'),
90-
Instruction(r'\RETURNCALLINDIRECT~x', r'\hex{13}', r'[t_1^\ast~\I32] \to [t_2^\ast]', r'valid-return_call_indirect', r'exec-return_call_indirect'),
90+
Instruction(r'\RETURNCALLINDIRECT~x~y', r'\hex{13}', r'[t_1^\ast~\I32] \to [t_2^\ast]', r'valid-return_call_indirect', r'exec-return_call_indirect'),
9191
Instruction(r'\CALLREF~x', r'\hex{14}', r'[t_1^\ast~(\REF~\NULL~x)] \to [t_2^\ast]', r'valid-call_ref', r'exec-call_ref'),
9292
Instruction(r'\RETURNCALLREF~x', r'\hex{15}', r'[t_1^\ast~(\REF~\NULL~x)] \to [t_2^\ast]', r'valid-return_call_ref', r'exec-return_call_ref'),
9393
Instruction(None, r'\hex{16}'),

document/core/binary/modules.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ It decodes into a vector of :ref:`tables <syntax-table>` that represent the |MTA
223223
.. note::
224224
The encoding of a table type cannot start with byte :math:`\hex{40}`,
225225
hence decoding is unambiguous.
226-
The zero byte following it is reserved for futre extensions.
226+
The zero byte following it is reserved for future extensions.
227227

228228

229229
.. index:: ! memory section, memory, memory type

document/core/exec/instructions.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4432,22 +4432,22 @@ Control Instructions
44324432
44334433
.. _exec-return_call_indirect:
44344434

4435-
:math:`\RETURNCALLINDIRECT~x`
4436-
.............................
4435+
:math:`\RETURNCALLINDIRECT~x~y`
4436+
...............................
44374437

44384438
1. Let :math:`F` be the :ref:`current <exec-notation-textual>` :ref:`frame <syntax-frame>`.
44394439

4440-
2. Assert: due to :ref:`validation <valid-call_indirect>`, :math:`F.\AMODULE.\MITABLES[0]` exists.
4440+
2. Assert: due to :ref:`validation <valid-call_indirect>`, :math:`F.\AMODULE.\MITABLES[x]` exists.
44414441

4442-
3. Let :math:`\X{ta}` be the :ref:`table address <syntax-tableaddr>` :math:`F.\AMODULE.\MITABLES[0]`.
4442+
3. Let :math:`\X{ta}` be the :ref:`table address <syntax-tableaddr>` :math:`F.\AMODULE.\MITABLES[x]`.
44434443

44444444
4. Assert: due to :ref:`validation <valid-call_indirect>`, :math:`S.\STABLES[\X{ta}]` exists.
44454445

44464446
5. Let :math:`\X{tab}` be the :ref:`table instance <syntax-tableinst>` :math:`S.\STABLES[\X{ta}]`.
44474447

4448-
6. Assert: due to :ref:`validation <valid-call_indirect>`, :math:`F.\AMODULE.\MITYPES[x]` is defined.
4448+
6. Assert: due to :ref:`validation <valid-call_indirect>`, :math:`F.\AMODULE.\MITYPES[y]` is defined.
44494449

4450-
7. Let :math:`\X{dt}_{\F{expect}}` be the :ref:`defined type <syntax-deftype>` :math:`F.\AMODULE.\MITYPES[x]`.
4450+
7. Let :math:`\X{dt}_{\F{expect}}` be the :ref:`defined type <syntax-deftype>` :math:`F.\AMODULE.\MITYPES[y]`.
44514451

44524452
8. Assert: due to :ref:`validation <valid-call_indirect>`, a value with :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
44534453

@@ -4478,10 +4478,10 @@ Control Instructions
44784478

44794479
.. math::
44804480
\begin{array}{lcl@{\qquad}l}
4481-
\val~(\RETURNCALLINDIRECT~x) &\stepto& (\RETURNINVOKE~a)
4482-
& (\iff \val~(\CALLINDIRECT~x) \stepto (\INVOKE~a)) \\
4483-
\val~(\RETURNCALLINDIRECT~x) &\stepto& \TRAP
4484-
& (\iff \val~(\CALLINDIRECT~x) \stepto \TRAP) \\
4481+
\val~(\RETURNCALLINDIRECT~x~y) &\stepto& (\RETURNINVOKE~a)
4482+
& (\iff \val~(\CALLINDIRECT~x~y) \stepto (\INVOKE~a)) \\
4483+
\val~(\RETURNCALLINDIRECT~x~y) &\stepto& \TRAP
4484+
& (\iff \val~(\CALLINDIRECT~x~y) \stepto \TRAP) \\
44854485
\end{array}
44864486
44874487

document/core/valid/instructions.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ Reference Instructions
265265
C \vdashinstr \REFTEST~\X{rt} : [\X{rt}'] \to [\I32]
266266
}
267267
268+
.. note::
269+
The liberty to pick a supertype :math:`\X{rt}'` allows typing the instruction with the least precise super type of :math:`\X{rt}` as input, that is, the top type in the corresponding heap subtyping hierarchy.
270+
271+
268272
.. _valid-ref.cast:
269273

270274
:math:`\REFCAST~\X{rt}`
@@ -285,6 +289,9 @@ Reference Instructions
285289
C \vdashinstr \REFCAST~\X{rt} : [\X{rt}'] \to [\X{rt}]
286290
}
287291
292+
.. note::
293+
The liberty to pick a supertype :math:`\X{rt}'` allows typing the instruction with the least precise super type of :math:`\X{rt}` as input, that is, the top type in the corresponding heap subtyping hierarchy.
294+
288295

289296
.. index:: aggregate reference
290297

0 commit comments

Comments
 (0)