You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: document/core/exec/runtime.rst
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -443,6 +443,7 @@ In order to express the reduction of :ref:`traps <trap>`, :ref:`calls <syntax-ca
443
443
\dots \\ &&|&
444
444
\TRAP \\ &&|&
445
445
\INVOKE~\funcaddr \\ &&|&
446
+
\RETURNINVOKE~\funcaddr \\ &&|&
446
447
\INITELEM~\tableaddr~\u32~\funcidx^\ast \\ &&|&
447
448
\INITDATA~\memaddr~\u32~\byte^\ast \\ &&|&
448
449
\LABEL_n\{\instr^\ast\}~\instr^\ast~\END \\ &&|&
@@ -454,6 +455,7 @@ Traps are bubbled up through nested instruction sequences, ultimately reducing t
454
455
455
456
The |INVOKE| instruction represents the imminent invocation of a :ref:`function instance <syntax-funcinst>`, identified by its :ref:`address <syntax-funcaddr>`.
456
457
It unifies the handling of different forms of calls.
458
+
Analogously, |RETURNINVOKE| represents the imminent tail invocation of a function instance.
457
459
458
460
The |INITELEM| and |INITDATA| instructions perform initialization of :ref:`element <syntax-elem>` and :ref:`data <syntax-data>` segments during module :ref:`instantiation <exec-instantiation>`.
Copy file name to clipboardExpand all lines: document/core/syntax/instructions.rst
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -301,7 +301,9 @@ Instructions in this group affect the flow of control.
301
301
\BRTABLE~\vec(\labelidx)~\labelidx \\&&|&
302
302
\RETURN \\&&|&
303
303
\CALL~\funcidx \\&&|&
304
-
\CALLINDIRECT~\typeidx \\
304
+
\CALLINDIRECT~\typeidx \\&&|&
305
+
\RETURNCALL~\funcidx \\&&|&
306
+
\RETURNCALLINDIRECT~\typeidx \\
305
307
\end{array}
306
308
307
309
The |NOP| instruction does nothing.
@@ -344,9 +346,13 @@ The |CALLINDIRECT| instruction calls a function indirectly through an operand in
344
346
Since tables may contain function elements of heterogeneous type |ANYFUNC|,
345
347
the callee is dynamically checked against the :ref:`function type <syntax-functype>` indexed by the instruction's immediate, and the call aborted with a :ref:`trap <trap>` if it does not match.
346
348
349
+
The |RETURNCALL| and |RETURNCALLINDIRECT| instructions are *tail-call* variants of the previous ones.
350
+
That is, they first return from the current function before actually performing the respective call.
351
+
It is guaranteed that no sequence of nested calls using only these instructions can cause resource exhaustion due to hitting an :ref:`implementation's limit <impl-exec>` on the number of active calls.
352
+
347
353
.. note::
348
354
In the current version of WebAssembly,
349
-
|CALLINDIRECT| implicitly operates on :ref:`table <syntax-table>` :ref:`index <syntax-tableidx>` :math:`0`.
355
+
|CALLINDIRECT| and |RETURNCALLINDIRECT| implicitly operate on :ref:`table <syntax-table>` :ref:`index <syntax-tableidx>` :math:`0`.
350
356
This restriction may be lifted in future versions.
Copy file name to clipboardExpand all lines: document/core/valid/instructions.rst
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -681,6 +681,69 @@ Control Instructions
681
681
}
682
682
683
683
684
+
.. _valid-return_call:
685
+
686
+
:math:`\RETURNCALL~x`
687
+
.....................
688
+
689
+
* The return type :math:`C.\CRETURN` must not be empty in the context.
690
+
691
+
* The function :math:`C.\CFUNCS[x]` must be defined in the context.
692
+
693
+
* Let :math:`[t_1^\ast] \to [t_2^?]` be the :ref:`function type <syntax-functype>` :math:`C.\CFUNCS[x]`.
694
+
695
+
* The :ref:`result type <syntax-resulttype>` must be the same as :math:`C.\CRETURN`.
696
+
697
+
* Then the instruction is valid with type :math:`[t_3^\ast~t_1^\ast] \to [t_4^\ast]`, for any sequences of :ref:`value types <syntax-valtype>` :math:`t_3^\ast` and :math:`t_4^\ast`.
698
+
699
+
.. math::
700
+
\frac{
701
+
C.\CFUNCS[x] = [t_1^\ast] \to [t_2^?]
702
+
\qquad
703
+
C.\CRETURN = [t_2^?]
704
+
}{
705
+
C \vdashinstr\CALL~x : [t_3^\ast~t_1^\ast] \to [t_4^\ast]
706
+
}
707
+
708
+
.. note::
709
+
The |RETURNCALL| instruction is :ref:`stack-polymorphic <polymorphism>`.
710
+
711
+
712
+
.. _valid-return_call_indirect:
713
+
714
+
:math:`\RETURNCALLINDIRECT~x`
715
+
.............................
716
+
717
+
* The return type :math:`C.\CRETURN` must not be empty in the context.
718
+
719
+
* The table :math:`C.\CTABLES[0]` must be defined in the context.
720
+
721
+
* Let :math:`\limits~\elemtype` be the :ref:`table type <syntax-tabletype>` :math:`C.\CTABLES[0]`.
722
+
723
+
* The :ref:`element type <syntax-elemtype>` :math:`\elemtype` must be |ANYFUNC|.
724
+
725
+
* The type :math:`C.\CTYPES[x]` must be defined in the context.
726
+
727
+
* Let :math:`[t_1^\ast] \to [t_2^?]` be the :ref:`function type <syntax-functype>` :math:`C.\CTYPES[x]`.
728
+
729
+
* Then the instruction is valid with type :math:`[t_3^\ast~t_1^\ast~\I32] \to [t_4^\ast]`, for any sequences of :ref:`value types <syntax-valtype>` :math:`t_3^\ast` and :math:`t_4^\ast`.
730
+
731
+
732
+
.. math::
733
+
\frac{
734
+
C.\CTABLES[0] = \limits~\ANYFUNC
735
+
\qquad
736
+
C.\CTYPES[x] = [t_1^\ast] \to [t_2^?]
737
+
\qquad
738
+
C.\CRETURN = [t_2^?]
739
+
}{
740
+
C \vdashinstr\CALLINDIRECT~x : [t_3^\ast~t_1^\ast~\I32] \to [t_4^\ast]
741
+
}
742
+
743
+
.. note::
744
+
The |RETURNCALLINDIRECT| instruction is :ref:`stack-polymorphic <polymorphism>`.
0 commit comments