Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.

Commit 864f382

Browse files
authored
[spec] Simplify datacount side condition (#83)
* Add definition of free index sets * Simplify datacount side condition * Explain convention about multiple occurrences of meta variables
1 parent 8bc0aa1 commit 864f382

File tree

6 files changed

+47
-20
lines changed

6 files changed

+47
-20
lines changed

document/core/binary/conventions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ In order to distinguish symbols of the binary syntax from symbols of the abstrac
5959

6060
* Some productions are augmented by side conditions in parentheses, which restrict the applicability of the production. They provide a shorthand for a combinatorial expansion of the production into many separate cases.
6161

62+
* If the same meta variable or non-terminal symbol appears multiple times in a production (in the syntax or in an attribute), then all those occurrences must have the same instantiation.
63+
(This is a shorthand for a side condition requiring multiple different variables to be equal.)
64+
6265
.. note::
6366
For example, the :ref:`binary grammar <binary-valtype>` for :ref:`value types <syntax-valtype>` is given as follows:
6467

document/core/binary/modules.rst

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,11 @@ The preamble is followed by a sequence of :ref:`sections <binary-section>`.
476476
:ref:`Custom sections <binary-customsec>` may be inserted at any place in this sequence,
477477
while other sections must occur at most once and in the prescribed order.
478478
All sections can be empty.
479+
479480
The lengths of vectors produced by the (possibly empty) :ref:`function <binary-funcsec>` and :ref:`code <binary-codesec>` section must match up.
480-
Similarly, the data count must match the length of the :ref:`data segment <binary-datasec>` vector.
481-
The :math:`\MEMORYINIT` and :math:`\DATADROP` instructions can only be used if the data count section is present.
481+
482+
Similarly, the optional data count must match the length of the :ref:`data segment <binary-datasec>` vector.
483+
Furthermore, it must be present if any :math:`data index <syntax-dataidx>` occurs in the code section.
482484

483485
.. math::
484486
\begin{array}{llcllll}
@@ -512,7 +514,7 @@ The :math:`\MEMORYINIT` and :math:`\DATADROP` instructions can only be used if t
512514
\Bcustomsec^\ast \\ &&&
513515
\X{code}^n{:\,}\Bcodesec \\ &&&
514516
\Bcustomsec^\ast \\ &&&
515-
\data^{\X{m'}}{:\,}\Bdatasec \\ &&&
517+
\data^m{:\,}\Bdatasec \\ &&&
516518
\Bcustomsec^\ast
517519
\quad\Rightarrow\quad \{~
518520
\begin{array}[t]{@{}l@{}}
@@ -522,30 +524,19 @@ The :math:`\MEMORYINIT` and :math:`\DATADROP` instructions can only be used if t
522524
\MMEMS~\mem^\ast, \\
523525
\MGLOBALS~\global^\ast, \\
524526
\MELEM~\elem^\ast, \\
525-
\MDATA~\data^{\X{m'}}, \\
527+
\MDATA~\data^m, \\
526528
\MSTART~\start^?, \\
527529
\MIMPORTS~\import^\ast, \\
528530
\MEXPORTS~\export^\ast ~\} \\
529-
\end{array} \\ &&&
530-
(\begin{array}[t]{@{}c@{~}l@{}}
531-
\iff & m^? \neq \epsilon \\
532-
\vee & \forall (t^\ast, e) \in \X{code}^n, \MEMORYINIT \notin e \wedge \DATADROP \notin e) \\
533-
\end{array} \\
531+
\end{array} \\ &&&
532+
(\iff m^? \neq \epsilon \vee \freedataidx(\X{code}^n) = \emptyset) \\
534533
\end{array}
535534
536535
where for each :math:`t_i^\ast, e_i` in :math:`\X{code}^n`,
537536

538537
.. math::
539538
\func^n[i] = \{ \FTYPE~\typeidx^n[i], \FLOCALS~t_i^\ast, \FBODY~e_i \} ) \\
540539
541-
and where,
542-
543-
.. math::
544-
\begin{array}{lcl@{\qquad}l}
545-
\X{m'} &=& m & (\iff m^? \neq \epsilon) \\
546-
\X{m'} &=& 0 & (\otherwise)
547-
\end{array}
548-
549540
.. note::
550541
The version of the WebAssembly binary format may increase in the future
551542
if backward-incompatible changes have to be made to the format.

document/core/syntax/conventions.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ The following conventions are adopted in defining grammar rules for abstract syn
4141

4242
* Some productions are augmented with side conditions in parentheses, ":math:`(\iff \X{condition})`", that provide a shorthand for a combinatorial expansion of the production into many separate cases.
4343

44+
* If the same meta variable or non-terminal symbol appears multiple times in a production, then all those occurrences must have the same instantiation.
45+
(This is a shorthand for a side condition requiring multiple different variables to be equal.)
46+
4447

4548
.. _notation-epsilon:
4649
.. _notation-length:
@@ -82,6 +85,7 @@ Moreover, the following conventions are employed:
8285
(similarly for :math:`x^\ast`, :math:`x^+`, :math:`x^?`).
8386
This implicitly expresses a form of mapping syntactic constructions over a sequence.
8487

88+
8589
Productions of the following form are interpreted as *records* that map a fixed set of fields :math:`\K{field}_i` to "values" :math:`A_i`, respectively:
8690

8791
.. math::

document/core/syntax/modules.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,22 +81,36 @@ Each class of definition has its own *index space*, as distinguished by the foll
8181
The index space for :ref:`functions <syntax-func>`, :ref:`tables <syntax-table>`, :ref:`memories <syntax-mem>` and :ref:`globals <syntax-global>` includes respective :ref:`imports <syntax-import>` declared in the same module.
8282
The indices of these imports precede the indices of other definitions in the same index space.
8383

84-
Element indices reference :ref:`element segments <syntax-elem>`.
85-
86-
Data indices reference :ref:`data segments <syntax-data>`.
84+
Element indices reference :ref:`element segments <syntax-elem>` and data indices reference :ref:`data segments <syntax-data>`.
8785

8886
The index space for :ref:`locals <syntax-local>` is only accessible inside a :ref:`function <syntax-func>` and includes the parameters of that function, which precede the local variables.
8987

9088
Label indices reference :ref:`structured control instructions <syntax-instr-control>` inside an instruction sequence.
9189

9290

91+
.. _free-typeidx:
92+
.. _free-funcidx:
93+
.. _free-tableidx:
94+
.. _free-memidx:
95+
.. _free-globalidx:
96+
.. _free-elemidx:
97+
.. _free-dataidx:
98+
.. _free-localidx:
99+
.. _free-labelidx:
100+
.. _free-index:
101+
93102
Conventions
94103
...........
95104

96105
* The meta variable :math:`l` ranges over label indices.
97106

98107
* The meta variables :math:`x, y` range over indices in any of the other index spaces.
99108

109+
* The notation :math:`\F{idx}(A)` denotes the set of indices from index space :math:`\X{idx}` occurring free in :math:`A`.
110+
111+
.. note::
112+
For example, if :math:`\instr^\ast` is :math:`(\DATADROP~x) (\MEMORYINIT~y)`, then :math:`\freedataidx(\instr^\ast) = \{x, y\}`.
113+
100114

101115
.. index:: ! type definition, type index, function type
102116
pair: abstract syntax; type definition

document/core/text/conventions.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ In order to distinguish symbols of the textual syntax from symbols of the abstra
5454

5555
* Some productions are augmented by side conditions in parentheses, which restrict the applicability of the production. They provide a shorthand for a combinatorial expansion of the production into many separate cases.
5656

57+
* If the same meta variable or non-terminal symbol appears multiple times in a production (in the syntax or in an attribute), then all those occurrences must have the same instantiation.
58+
5759
.. _text-syntactic:
5860

5961
* A distinction is made between *lexical* and *syntactic* productions. For the latter, arbitrary :ref:`white space <text-space>` is allowed in any place where the grammar contains spaces. The productions defining :ref:`lexical syntax <text-lexical>` and the syntax of :Ref:`values <text-value>` are considered lexical, all others are syntactic.

document/core/util/macros.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,19 @@
226226
.. |labelidx| mathdef:: \xref{syntax/modules}{syntax-labelidx}{\X{labelidx}}
227227

228228

229+
.. Indices, meta functions
230+
231+
.. |freetypeidx| mathdef:: \xref{syntax/modules}{syntax-typeidx}{\F{typeidx}}
232+
.. |freefuncidx| mathdef:: \xref{syntax/modules}{syntax-funcidx}{\F{funcidx}}
233+
.. |freetableidx| mathdef:: \xref{syntax/modules}{syntax-tableidx}{\F{tableidx}}
234+
.. |freememidx| mathdef:: \xref{syntax/modules}{syntax-memidx}{\F{memidx}}
235+
.. |freeglobalidx| mathdef:: \xref{syntax/modules}{syntax-globalidx}{\F{globalidx}}
236+
.. |freeelemidx| mathdef:: \xref{syntax/modules}{syntax-elemidx}{\F{elemidx}}
237+
.. |freedataidx| mathdef:: \xref{syntax/modules}{syntax-dataidx}{\F{dataidx}}
238+
.. |freelocalidx| mathdef:: \xref{syntax/modules}{syntax-localidx}{\F{localidx}}
239+
.. |freelabelidx| mathdef:: \xref{syntax/modules}{syntax-labelidx}{\F{labelidx}}
240+
241+
229242
.. Modules, terminals
230243

231244
.. |MTYPES| mathdef:: \xref{syntax/modules}{syntax-module}{\K{types}}

0 commit comments

Comments
 (0)