Skip to content

Commit

Permalink
Merge branch 'main' into spec.valid-instr
Browse files Browse the repository at this point in the history
  • Loading branch information
rossberg authored Jul 12, 2023
2 parents dd2cf49 + 6b8ccab commit 16e6620
Show file tree
Hide file tree
Showing 32 changed files with 1,418 additions and 341 deletions.
31 changes: 31 additions & 0 deletions document/core/appendix/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,34 @@ Added more precise types for references [#proposal-typedref]_.
* Extended :ref:`table definitions <syntax-table>` with optional initializer expression


.. index:: reference, reference type, heap type, field type, storage type, structure type, array type, compound type, sub type, recrusive type

Garbage Collection
~~~~~~~~~~~~~~~~~~

Added managed reference types [#proposal-gc]_.

* New forms of :ref:`heap types <syntax-heaptype>`: |ANY|, |EQT|, |I31|, |STRUCT|, |ARRAY|, |NONE|, |NOFUNC|, |NOEXTERN|

* New :ref:`reference type <syntax-reftype>` short-hands: |ANYREF|, |EQREF|, |I31REF|, |STRUCTREF|, |ARRAYREF|, |NULLREF|, |NULLFUNCREF|, |NULLEXTERNREF|

* New forms of type definitions: :ref:`structure <syntax-structtype>` and :ref:`array types <syntax-arraytype>`, :ref:`sub types <syntax-subtype>`, and :ref:`recursive types <syntax-rectype>`

* Enriched :ref:`subtyping <match>` based on explicitly declared :ref:`sub types <syntax-subtype>` and the new heap types

* New generic :ref:`reference instructions <syntax-instr-ref>`: |REFEQ|, |REFTEST|, |REFCAST|, |BRONCAST|, |BRONCASTFAIL|

* New :ref:`reference instructions <syntax-instr-ref>` for :ref:`unboxed scalars <syntax-i31>`: |I31NEW|, :math:`\I31GET\K{\_}\sx`

* New :ref:`reference instructions <syntax-instr-ref>` for :ref:`structure types <syntax-structtype>`: |STRUCTNEW|, |STRUCTNEWDEFAULT|, :math:`\STRUCTGET\K{\_}\sx^?`, |STRUCTSET|

* New :ref:`reference instructions <syntax-instr-ref>` for :ref:`array types <syntax-structtype>`: |ARRAYNEW|, |ARRAYNEWDEFAULT|, |ARRAYNEWFIXED|, |ARRAYNEWDATA|, |ARRAYNEWELEM|, :math:`\ARRAYGET\K{\_}\sx^?`, |ARRAYSET|, |ARRAYLEN|, |ARRAYFILL|, |ARRAYCOPY|, |ARRAYINITDATA|, |ARRAYINITELEM|

* New :ref:`reference instructions <syntax-instr-ref>` for converting :ref:`host types <syntax-extern>`: |EXTERNINTERNALIZE|, |EXTERNEXTERNALIZE|

* Extended set of :ref:`constant instructions <valid-const>` with |I31NEW|, |STRUCTNEW|, |STRUCTNEWDEFAULT|, |ARRAYNEW|, |ARRAYNEWDEFAULT|, |ARRAYNEWFIXED|, |EXTERNINTERNALIZE|, |EXTERNEXTERNALIZE|, and |GLOBALGET| for any previously declared immutable :ref:`global <syntax-global>`


.. [#proposal-signext]
https://github.com/WebAssembly/spec/tree/main/proposals/sign-extension-ops/
Expand All @@ -185,3 +213,6 @@ Added more precise types for references [#proposal-typedref]_.
.. [#proposal-typedref]
https://github.com/WebAssembly/spec/tree/main/proposals/function-references/
.. [#proposal-gc]
https://github.com/WebAssembly/spec/tree/main/proposals/gc/
78 changes: 78 additions & 0 deletions document/core/appendix/embedding.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ Hence, these syntactic classes can also be interpreted as types.
For numeric parameters, notation like :math:`n:\u32` is used to specify a symbolic name in addition to the respective value range.


.. _embed-bool:

Booleans
~~~~~~~~

Interface operation that are predicates return Boolean values:

.. math::
\begin{array}{llll}
\production{Boolean} & \bool &::=& \FALSE ~|~ \TRUE \\
\end{array}
.. _embed-error:

Errors
Expand Down Expand Up @@ -615,3 +628,68 @@ Globals
\F{global\_write}(S, a, v) &=& S' && (\iff S.\SGLOBALS[a].\GITYPE = \MVAR~t \wedge S' = S \with \SGLOBALS[a].\GIVALUE = v) \\
\F{global\_write}(S, a, v) &=& \ERROR && (\otherwise) \\
\end{array}
.. index:: reference, reference type
.. _embed-ref-type:

References
~~~~~~~~~~

:math:`\F{ref\_type}(\store, \reff) : \reftype`
...............................................

1. Pre-condition: the :ref:`reference <syntax-ref>` :math:`\reff` is :ref:`valid <valid-val>` under store :math:`S`.

2. Return the :ref:`reference type <syntax-reftype>` :math:`t` with which :math:`\reff` is valid.

3. Post-condition: the returned :ref:`reference type <syntax-reftype>` is :ref:`valid <valid-reftype>` under the empty :ref:`context <context>`.

.. math::
\begin{array}{lclll}
\F{ref\_type}(S, r) &=& t && (\iff S \vdashval r : t) \\
\end{array}
.. note::
In future versions of WebAssembly,
not all references may carry precise type information at run time.
In such cases, this function may return a less precise supertype.


.. index:: value type, external type, subtyping
.. _embed-match-valtype:
.. _embed-match-externtype:

Matching
~~~~~~~~

:math:`\F{match\_valtype}(\valtype_1, \valtype_2) : \bool`
..........................................................

1. Pre-condition: the :ref:`value types <syntax-valtype>` :math:`\valtype_1` and :math:`\valtype_2` are :ref:`valid <valid-valtype>` under the empty :ref:`context <context>`.

2. If :math:`\valtype_1` :ref:`matches <match-valtype>` :math:`\valtype_2`, then return :math:`\TRUE`.

3. Else, return :math:`\FALSE`.

.. math::
\begin{array}{lclll}
\F{match\_reftype}(t_1, t_2) &=& \TRUE && (\iff \vdashvaltypematch t_1 \matchesvaltype t_2) \\
\F{match\_reftype}(t_1, t_2) &=& \FALSE && (\otherwise) \\
\end{array}
:math:`\F{match\_externtype}(\externtype_1, \externtype_2) : \bool`
...................................................................

1. Pre-condition: the :ref:`extern types <syntax-externtype>` :math:`\externtype_1` and :math:`\externtype_2` are :ref:`valid <valid-externtype>` under the empty :ref:`context <context>`.

2. If :math:`\externtype_1` :ref:`matches <match-externtype>` :math:`\externtype_2`, then return :math:`\TRUE`.

3. Else, return :math:`\FALSE`.

.. math::
\begin{array}{lclll}
\F{match\_externtype}(\X{et}_1, \X{et}_2) &=& \TRUE && (\iff \vdashexterntypematch \X{et}_1 \matchesexterntype \X{et}_2) \\
\F{match\_externtype}(\X{et}_1, \X{et}_2) &=& \FALSE && (\otherwise) \\
\end{array}
4 changes: 2 additions & 2 deletions document/core/appendix/index-instructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,8 @@ def Instruction(name, opcode, type=None, validation=None, execution=None, operat
Instruction(r'\V128.\STORE\K{16\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{59}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'),
Instruction(r'\V128.\STORE\K{32\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5A}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'),
Instruction(r'\V128.\STORE\K{64\_lane}~\memarg~\laneidx', r'\hex{FD}~~\hex{5B}', r'[\I32~\V128] \to []', r'valid-store-lane', r'exec-store-lane'),
Instruction(r'\V128.\LOAD\K{32\_zero}~\memarg~\laneidx', r'\hex{FD}~~\hex{5C}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'),
Instruction(r'\V128.\LOAD\K{64\_zero}~\memarg~\laneidx', r'\hex{FD}~~\hex{5D}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'),
Instruction(r'\V128.\LOAD\K{32\_zero}~\memarg', r'\hex{FD}~~\hex{5C}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'),
Instruction(r'\V128.\LOAD\K{64\_zero}~\memarg', r'\hex{FD}~~\hex{5D}', r'[\I32] \to [\V128]', r'valid-load-zero', r'exec-load-zero'),
Instruction(r'\F32X4.\VDEMOTE\K{\_f64x2\_zero}', r'\hex{FD}~~\hex{5E}', r'[\V128] \to [\V128]', r'valid-vcvtop', r'exec-vcvtop', r'op-demote'),
Instruction(r'\F64X2.\VPROMOTE\K{\_low\_f32x4}', r'\hex{FD}~~\hex{5F}', r'[\V128] \to [\V128]', r'valid-vcvtop', r'exec-vcvtop', r'op-promote'),
Instruction(r'\I8X16.\VABS', r'\hex{FD}~~\hex{60}', r'[\V128] \to [\V128]', r'valid-vunop', r'exec-vunop', r'op-iabs'),
Expand Down
80 changes: 74 additions & 6 deletions document/core/binary/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Control Instructions
:ref:`Block types <syntax-blocktype>` are encoded in special compressed form, by either the byte :math:`\hex{40}` indicating the empty type, as a single :ref:`value type <binary-valtype>`, or as a :ref:`type index <binary-typeidx>` encoded as a positive :ref:`signed integer <binary-sint>`.

.. _binary-blocktype:
.. _binary-castflags:
.. _binary-nop:
.. _binary-unreachable:
.. _binary-block:
Expand All @@ -36,6 +37,8 @@ Control Instructions
.. _binary-br_table:
.. _binary-br_on_null:
.. _binary-br_on_non_null:
.. _binary-br_on_cast:
.. _binary-br_on_cast_fail:
.. _binary-return:
.. _binary-call:
.. _binary-call_ref:
Expand All @@ -44,11 +47,11 @@ Control Instructions
.. _binary-return_call_indirect:

.. math::
\begin{array}{llcllll}
\begin{array}{@{}llcllll}
\production{block type} & \Bblocktype &::=&
\hex{40} &\Rightarrow& \epsilon \\ &&|&
t{:}\Bvaltype &\Rightarrow& t \\ &&|&
x{:}\Bs33 &\Rightarrow& x & (\iff x \geq 0) \\
x{:}\Bs33 &\Rightarrow& x \qquad (\iff x \geq 0) \\
\production{instruction} & \Binstr &::=&
\hex{00} &\Rightarrow& \UNREACHABLE \\ &&|&
\hex{01} &\Rightarrow& \NOP \\ &&|&
Expand All @@ -58,7 +61,7 @@ Control Instructions
&\Rightarrow& \LOOP~\X{bt}~\X{in}^\ast~\END \\ &&|&
\hex{04}~~\X{bt}{:}\Bblocktype~~(\X{in}{:}\Binstr)^\ast~~\hex{0B}
&\Rightarrow& \IF~\X{bt}~\X{in}^\ast~\ELSE~\epsilon~\END \\ &&|&
\hex{04}~~\X{bt}{:}\Bblocktype~~(\X{in}_1{:}\Binstr)^\ast~~
\hex{04}~~\X{bt}{:}\Bblocktype~~(\X{in}_1{:}\Binstr)^\ast\\&&&~~
\hex{05}~~(\X{in}_2{:}\Binstr)^\ast~~\hex{0B}
&\Rightarrow& \IF~\X{bt}~\X{in}_1^\ast~\ELSE~\X{in}_2^\ast~\END \\ &&|&
\hex{0C}~~l{:}\Blabelidx &\Rightarrow& \BR~l \\ &&|&
Expand All @@ -73,7 +76,14 @@ Control Instructions
\hex{14}~~x{:}\Btypeidx &\Rightarrow& \CALLREF~x \\ &&|&
\hex{15}~~x{:}\Btypeidx &\Rightarrow& \RETURNCALLREF~x \\ &&|&
\hex{D4}~~l{:}\Blabelidx &\Rightarrow& \BRONNULL~l \\ &&|&
\hex{D6}~~l{:}\Blabelidx &\Rightarrow& \BRONNONNULL~l \\
\hex{D6}~~l{:}\Blabelidx &\Rightarrow& \BRONNONNULL~l \\ &&|&
\hex{FB}~~78{:}\Bu32~~(\NULL_1^?,\NULL_2^?){:}\Bcastflags\\&&&~~~~l{:}\Blabelidx~~\X{ht}_1{:}\Bheaptype~~\X{ht}_2{:}\Bheaptype &\Rightarrow& \BRONCAST~l~(\REF~\NULL_1^?~\X{ht}_1)~(\REF~\NULL_2^?~\X{ht}_2) \\ &&|&
\hex{FB}~~79{:}\Bu32~~(\NULL_1^?,\NULL_2^?){:}\Bcastflags\\&&&~~~~l{:}\Blabelidx~~\X{ht}_1{:}\Bheaptype~~\X{ht}_2{:}\Bheaptype &\Rightarrow& \BRONCASTFAIL~l~(\REF~\NULL_1^?~\X{ht}_1)~(\REF~\NULL_2^?~\X{ht}_2) \\
\production{cast flags} & \Bcastflags &::=&
0{:}\Bu8 &\Rightarrow& (\epsilon, \epsilon) \\ &&|&
1{:}\Bu8 &\Rightarrow& (\NULL, \epsilon) \\ &&|&
2{:}\Bu8 &\Rightarrow& (\epsilon, \NULL) \\ &&|&
3{:}\Bu8 &\Rightarrow& (\NULL, \NULL) \\
\end{array}
.. note::
Expand All @@ -90,23 +100,81 @@ Control Instructions
Reference Instructions
~~~~~~~~~~~~~~~~~~~~~~

:ref:`Reference instructions <syntax-instr-ref>` are represented by single byte codes.
Generic :ref:`reference instructions <syntax-instr-ref>` are represented by single byte codes, others use prefixes and type operands.

.. _binary-ref.null:
.. _binary-ref.func:
.. _binary-ref.is_null:
.. _binary-ref.as_non_null:
.. _binary-struct.new:
.. _binary-struct.new_default:
.. _binary-struct.get:
.. _binary-struct.get_s:
.. _binary-struct.get_u:
.. _binary-struct.set:
.. _binary-array.new:
.. _binary-array.new_default:
.. _binary-array.new_fixed:
.. _binary-array.new_elem:
.. _binary-array.new_data:
.. _binary-array.get:
.. _binary-array.get_s:
.. _binary-array.get_u:
.. _binary-array.set:
.. _binary-array.len:
.. _binary-array.fill:
.. _binary-array.copy:
.. _binary-array.init_data:
.. _binary-array.init_elem:
.. _binary-i31.new:
.. _binary-i31.get_s:
.. _binary-i31.get_u:
.. _binary-ref.test:
.. _binary-ref.cast:
.. _binary-extern.internalize:
.. _binary-extern.externalize:

.. math::
\begin{array}{llclll}
\production{instruction} & \Binstr &::=& \dots \\ &&|&
\hex{D0}~~t{:}\Bheaptype &\Rightarrow& \REFNULL~t \\ &&|&
\hex{D1} &\Rightarrow& \REFISNULL \\ &&|&
\hex{D2}~~x{:}\Bfuncidx &\Rightarrow& \REFFUNC~x \\ &&|&
\hex{D3} &\Rightarrow& \REFASNONNULL \\
\hex{D3} &\Rightarrow& \REFASNONNULL \\ &&|&
\hex{D5} &\Rightarrow& \REFEQ \\ &&|&
\hex{FB}~~1{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \STRUCTNEW~x \\ &&|&
\hex{FB}~~2{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \STRUCTNEWDEFAULT~x \\ &&|&
\hex{FB}~~3{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGET~x~i \\ &&|&
\hex{FB}~~4{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGETS~x~i \\ &&|&
\hex{FB}~~5{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTGETU~x~i \\ &&|&
\hex{FB}~~6{:}\Bu32~~x{:}\Btypeidx~~i{:}\Bu32 &\Rightarrow& \STRUCTSET~x~i \\ &&|&
\hex{FB}~~16{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYFILL~x \\ &&|&
\hex{FB}~~17{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYNEW~x \\ &&|&
\hex{FB}~~18{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYNEWDEFAULT~x \\ &&|&
\hex{FB}~~19{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGET~x \\ &&|&
\hex{FB}~~20{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGETS~x \\ &&|&
\hex{FB}~~21{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYGETU~x \\ &&|&
\hex{FB}~~22{:}\Bu32~~x{:}\Btypeidx &\Rightarrow& \ARRAYSET~x \\ &&|&
\hex{FB}~~23{:}\Bu32 &\Rightarrow& \ARRAYLEN \\ &&|&
\hex{FB}~~24{:}\Bu32~~x{:}\Btypeidx~~y{:}\Btypeidx &\Rightarrow& \ARRAYCOPY~x~y \\ &&|&
\hex{FB}~~25{:}\Bu32~~x{:}\Btypeidx~~n{:}\Bu32 &\Rightarrow& \ARRAYNEWFIXED~x~n \\ &&|&
\hex{FB}~~27{:}\Bu32~~x{:}\Btypeidx~~y{:}\Bdataidx &\Rightarrow& \ARRAYNEWDATA~x~y \\ &&|&
\hex{FB}~~28{:}\Bu32~~x{:}\Btypeidx~~y{:}\Belemidx &\Rightarrow& \ARRAYNEWELEM~x~y \\ &&|&
\hex{FB}~~32{:}\Bu32 &\Rightarrow& \I31NEW \\ &&|&
\hex{FB}~~33{:}\Bu32 &\Rightarrow& \I31GETS \\ &&|&
\hex{FB}~~34{:}\Bu32 &\Rightarrow& \I31GETU \\ &&|&
\hex{FB}~~64{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFTEST~(\REF~\X{ht}) \\ &&|&
\hex{FB}~~65{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFCAST~(\REF~\X{ht}) \\ &&|&
\hex{FB}~~72{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFTEST~(\REF~\NULL~\X{ht}) \\ &&|&
\hex{FB}~~73{:}\Bu32~~\X{ht}{:}\Bheaptype &\Rightarrow& \REFCAST~(\REF~\NULL~\X{ht}) \\ &&|&
\hex{FB}~~84{:}\Bu32~~x{:}\Btypeidx~~y{:}\Bdataidx &\Rightarrow& \ARRAYINITDATA~x~y \\ &&|&
\hex{FB}~~85{:}\Bu32~~x{:}\Btypeidx~~y{:}\Belemidx &\Rightarrow& \ARRAYINITELEM~x~y \\ &&|&
\hex{FB}~~112{:}\Bu32 &\Rightarrow& \EXTERNINTERNALIZE \\ &&|&
\hex{FB}~~113{:}\Bu32 &\Rightarrow& \EXTERNEXTERNALIZE \\
\end{array}
.. index:: parametric instruction, value type, polymorphism
pair: binary format; instruction
.. _binary-instr-parametric:
Expand Down
10 changes: 5 additions & 5 deletions document/core/binary/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Their contents consist of a :ref:`name <syntax-name>` further identifying the cu
If an implementation interprets the data of a custom section, then errors in that data, or the placement of the section, must not invalidate the module.


.. index:: ! type section, type definition
.. index:: ! type section, type definition, recursive type
pair: binary format; type section
pair: section; type
.. _binary-typedef:
Expand All @@ -137,12 +137,12 @@ Type Section
~~~~~~~~~~~~

The *type section* has the id 1.
It decodes into a vector of :ref:`function types <syntax-functype>` that represent the |MTYPES| component of a :ref:`module <syntax-module>`.
It decodes into a vector of :ref:`recursive types <syntax-rectype>` that represent the |MTYPES| component of a :ref:`module <syntax-module>`.

.. math::
\begin{array}{llclll}
\production{type section} & \Btypesec &::=&
\X{ft}^\ast{:\,}\Bsection_1(\Bvec(\Bfunctype)) &\Rightarrow& \X{ft}^\ast \\
\X{rt}^\ast{:\,}\Bsection_1(\Bvec(\Brectype)) &\Rightarrow& \X{rt}^\ast \\
\end{array}
Expand Down Expand Up @@ -525,7 +525,7 @@ Furthermore, it must be present if any :ref:`data index <syntax-dataidx>` occurs
\Bmagic \\ &&&
\Bversion \\ &&&
\Bcustomsec^\ast \\ &&&
\functype^\ast{:\,}\Btypesec \\ &&&
\rectype^\ast{:\,}\Btypesec \\ &&&
\Bcustomsec^\ast \\ &&&
\import^\ast{:\,}\Bimportsec \\ &&&
\Bcustomsec^\ast \\ &&&
Expand All @@ -551,7 +551,7 @@ Furthermore, it must be present if any :ref:`data index <syntax-dataidx>` occurs
\Bcustomsec^\ast
\quad\Rightarrow\quad \{~
\begin{array}[t]{@{}l@{}}
\MTYPES~\functype^\ast, \\
\MTYPES~\rectype^\ast, \\
\MFUNCS~\func^n, \\
\MTABLES~\table^\ast, \\
\MMEMS~\mem^\ast, \\
Expand Down
Loading

0 comments on commit 16e6620

Please sign in to comment.