Skip to content

Commit 9762124

Browse files
authored
[spec] Address comments by Luke (#752)
1 parent b3de271 commit 9762124

File tree

8 files changed

+95
-47
lines changed

8 files changed

+95
-47
lines changed

document/core/intro/introduction.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ WebAssembly (abbreviated Wasm [#wasm]_) is a *safe, portable, low-level code for
55
designed for efficient execution and compact representation.
66
Its main goal is to enable high performance applications on the Web, but it does not make any Web-specific assumptions or provide Web-specific features, so it can be employed in other environments as well.
77

8-
WebAssembly is an open standard developed by a `W3C Community Group <https://www.w3.org/community/webassembly/>`_ that includes representatives of all major browser vendors.
8+
WebAssembly is an open standard developed by a `W3C Community Group <https://www.w3.org/community/webassembly/>`_.
99

1010
This document describes version |release| of the :ref:`core <scope>` WebAssembly standard.
1111
It is intended that it will be superseded by new incremental releases with additional features in the future.

document/core/syntax/conventions.rst

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

4242

4343

44+
.. _notation-epsilon:
45+
.. _notation-length:
46+
.. _notation-index:
4447
.. _notation-slice:
4548
.. _notation-replace:
4649
.. _notation-record:
50+
.. _notation-project:
4751
.. _notation-concat:
4852
.. _notation-compose:
4953

document/core/syntax/types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Result Types
4949
~~~~~~~~~~~~
5050

5151
*Result types* classify the result of :ref:`executing <exec-instr>` :ref:`instructions <syntax-instr>` or :ref:`blocks <syntax-instr-control>`,
52-
which is a sequence of values.
52+
which is a sequence of values written with brackets.
5353

5454
.. math::
5555
\begin{array}{llll}
@@ -71,7 +71,7 @@ Function Types
7171
~~~~~~~~~~~~~~
7272

7373
*Function types* classify the signature of :ref:`functions <syntax-func>`,
74-
mapping a vector of parameters to a vector of results.
74+
mapping a vector of parameters to a vector of results, written as follows.
7575

7676
.. math::
7777
\begin{array}{llll}

document/core/text/modules.rst

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,8 @@ When omitted, :math:`\T{0}` is assumed.
476476
.. math::
477477
\begin{array}{llclll}
478478
\production{element segment} & \Telem_I &::=&
479-
\text{(}~\text{elem}~~(x{:}\Ttableidx_I)^?~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~y^\ast{:}\Tvec(\Tfuncidx_I)~\text{)} \\ &&& \qquad
480-
\Rightarrow\quad \{ \ETABLE~x', \EOFFSET~e, \EINIT~y^\ast \} \\
481-
&&& \qquad\qquad\qquad (\iff x' = x^? \neq \epsilon \vee x' = 0) \\
479+
\text{(}~\text{elem}~~x{:}\Ttableidx_I~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~y^\ast{:}\Tvec(\Tfuncidx_I)~\text{)} \\ &&& \qquad
480+
\Rightarrow\quad \{ \ETABLE~x, \EOFFSET~e, \EINIT~y^\ast \} \\
482481
\end{array}
483482
484483
.. note::
@@ -498,6 +497,16 @@ As an abbreviation, a single instruction may occur in place of the offset:
498497
\text{(}~\text{offset}~~\Tinstr~\text{)}
499498
\end{array}
500499
500+
Also, the table index can be omitted, defaulting to :math:`0`.
501+
502+
.. math::
503+
\begin{array}{llclll}
504+
\production{element segment} &
505+
\text{(}~\text{elem}~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\dots~\text{)}
506+
&\equiv&
507+
\text{(}~\text{elem}~~0~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\dots~\text{)}
508+
\end{array}
509+
501510
As another abbreviation, element segments may also be specified inline with :ref:`table <text-table>` definitions; see the respective section.
502511

503512

@@ -518,9 +527,8 @@ The data is written as a :ref:`string <text-string>`, which may be split up into
518527
.. math::
519528
\begin{array}{llclll}
520529
\production{data segment} & \Tdata_I &::=&
521-
\text{(}~\text{data}~~(x{:}\Tmemidx_I)^?~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~b^\ast{:}\Tdatastring~\text{)} \\ &&& \qquad
522-
\Rightarrow\quad \{ \DMEM~x', \DOFFSET~e, \DINIT~b^\ast \} \\
523-
&&& \qquad\qquad\qquad (\iff x' = x^? \neq \epsilon \vee x' = 0) \\[1ex]
530+
\text{(}~\text{data}~~x{:}\Tmemidx_I~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~b^\ast{:}\Tdatastring~\text{)} \\ &&& \qquad
531+
\Rightarrow\quad \{ \DMEM~x', \DOFFSET~e, \DINIT~b^\ast \} \\[1ex]
524532
\production{data string} & \Tdatastring &::=&
525533
(b^\ast{:}\Tstring)^\ast \quad\Rightarrow\quad \concat((b^\ast)^\ast) \\
526534
\end{array}
@@ -542,6 +550,16 @@ As an abbreviation, a single instruction may occur in place of the offset:
542550
\text{(}~\text{offset}~~\Tinstr~\text{)}
543551
\end{array}
544552
553+
Also, the memory index can be omitted, defaulting to :math:`0`.
554+
555+
.. math::
556+
\begin{array}{llclll}
557+
\production{data segment} &
558+
\text{(}~\text{data}~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\dots~\text{)}
559+
&\equiv&
560+
\text{(}~\text{data}~~0~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\dots~\text{)}
561+
\end{array}
562+
545563
As another abbreviation, data segments may also be specified inline with :ref:`memory <text-mem>` definitions; see the respective section.
546564

547565

document/core/valid/conventions.rst

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ which collects relevant information about the surrounding :ref:`module <syntax-m
4040
* *Globals*: the list of globals declared in the current module, represented by their global type.
4141
* *Locals*: the list of locals declared in the current function (including parameters), represented by their value type.
4242
* *Labels*: the stack of labels accessible from the current position, represented by their result type.
43-
* *Return*: the return type of the current function, represented as a result type.
43+
* *Return*: the return type of the current function, represented as an optional result type that is absent when no return is allowed, as in free-standing expressions.
4444

4545
In other words, a context contains a sequence of suitable :ref:`types <syntax-type>` for each :ref:`index space <syntax-index>`,
4646
describing each defined entry in that space.
4747
Locals, labels and return type are only used for validating :ref:`instructions <syntax-instr>` in :ref:`function bodies <syntax-func>`, and are left empty elsewhere.
4848
The label stack is the only part of the context that changes as validation of an instruction sequence proceeds.
4949

50-
It is convenient to define contexts as :ref:`records <notation-record>` :math:`C` with abstract syntax:
50+
More concretely, contexts are defined as :ref:`records <notation-record>` :math:`C` with abstract syntax:
5151

5252
.. math::
5353
\begin{array}{llll}
@@ -64,22 +64,18 @@ It is convenient to define contexts as :ref:`records <notation-record>` :math:`C
6464
\end{array}
6565
\end{array}
6666
67-
.. note::
68-
The fields of a context are not defined as :ref:`vectors <syntax-vec>`,
69-
since their lengths are not bounded by the maximum vector size.
67+
.. _notation-extend:
7068

71-
In addition to field access :math:`C.\K{field}` the following notation is adopted for manipulating contexts:
69+
In addition to field access written :math:`C.\K{field}` the following notation is adopted for manipulating contexts:
7270

7371
* When spelling out a context, empty fields are omitted.
7472

7573
* :math:`C,\K{field}\,A^\ast` denotes the same context as :math:`C` but with the elements :math:`A^\ast` prepended to its :math:`\K{field}` component sequence.
7674

7775
.. note::
78-
This notation is defined to *prepend* not *append*.
79-
It is only used in situations where the original :math:`C.\K{field}` is either empty
80-
or :math:`\K{field}` is :math:`\K{labels}`.
81-
In the latter case adding to the front is desired
82-
because the :ref:`label index <syntax-labelidx>` space is indexed relatively, that is, in reverse order of addition.
76+
We use :ref:`indexing notation <notation-index>` like :math:`C.\CLABELS[i]` to look up indices in their respective :ref:`index space <syntax-index>` in the context.
77+
Context extension notation :math:`C,\K{field}\,A` is primarily used to locally extend *relative* index spaces, such as :ref:`label indices <syntax-labelidx>`.
78+
Accordingly, the notation is defined to append at the *front* of the respective sequence, introducing a new relative index :math:`0` and shifting the existing ones.
8379

8480

8581
.. _valid-notation-textual:

document/core/valid/instructions.rst

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ Memory Instructions
314314

315315
* The memory :math:`C.\CMEMS[0]` must be defined in the context.
316316

317-
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than the :ref:`width <syntax-valtype>` of :math:`t` divided by :math:`8`.
317+
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than the :ref:`bit width <syntax-valtype>` of :math:`t` divided by :math:`8`.
318318

319319
* Then the instruction is valid with type :math:`[\I32] \to [t]`.
320320

@@ -354,7 +354,7 @@ Memory Instructions
354354

355355
* The memory :math:`C.\CMEMS[0]` must be defined in the context.
356356

357-
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than the :ref:`width <syntax-valtype>` of :math:`t` divided by :math:`8`.
357+
* The alignment :math:`2^{\memarg.\ALIGN}` must not be larger than the :ref:`bit width <syntax-valtype>` of :math:`t` divided by :math:`8`.
358358

359359
* Then the instruction is valid with type :math:`[\I32~t] \to []`.
360360

@@ -483,6 +483,8 @@ Control Instructions
483483
}
484484
485485
.. note::
486+
The :ref:`notation <notation-extend>` :math:`C,\CLABELS\,[t^?]` inserts the new label type at index :math:`0`, shifting all others.
487+
486488
The fact that the nested instruction sequence :math:`\instr^\ast` must have type :math:`[] \to [t^?]` implies that it cannot access operands that have been pushed on the stack before the block was entered.
487489
This may be generalized in future versions of WebAssembly.
488490

@@ -507,6 +509,8 @@ Control Instructions
507509
}
508510
509511
.. note::
512+
The :ref:`notation <notation-extend>` :math:`C,\CLABELS\,[t^?]` inserts the new label type at index :math:`0`, shifting all others.
513+
510514
The fact that the nested instruction sequence :math:`\instr^\ast` must have type :math:`[] \to [t^?]` implies that it cannot access operands that have been pushed on the stack before the loop was entered.
511515
This may be generalized in future versions of WebAssembly.
512516

@@ -536,6 +540,8 @@ Control Instructions
536540
}
537541
538542
.. note::
543+
The :ref:`notation <notation-extend>` :math:`C,\CLABELS\,[t^?]` inserts the new label type at index :math:`0`, shifting all others.
544+
539545
The fact that the nested instruction sequence :math:`\instr^\ast` must have type :math:`[] \to [t^?]` implies that it cannot access operands that have been pushed on the stack before the conditional was entered.
540546
This may be generalized in future versions of WebAssembly.
541547

@@ -559,6 +565,8 @@ Control Instructions
559565
}
560566
561567
.. note::
568+
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
569+
562570
The |BR| instruction is :ref:`stack-polymorphic <polymorphism>`.
563571

564572

@@ -580,6 +588,9 @@ Control Instructions
580588
C \vdashinstr \BRIF~l : [t^?~\I32] \to [t^?]
581589
}
582590
591+
.. note::
592+
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label first, so that :math:`C.\CLABELS[l]` performs a relative lookup as expected.
593+
583594

584595
.. _valid-br_table:
585596

@@ -608,6 +619,8 @@ Control Instructions
608619
}
609620
610621
.. note::
622+
The :ref:`label index <syntax-labelidx>` space in the :ref:`context <context>` :math:`C` contains the most recent label first, so that :math:`C.\CLABELS[l_i]` performs a relative lookup as expected.
623+
611624
The |BRTABLE| instruction is :ref:`stack-polymorphic <polymorphism>`.
612625

613626

@@ -616,7 +629,7 @@ Control Instructions
616629
:math:`\RETURN`
617630
...............
618631

619-
* The return type :math:`C.\CRETURN` must not be empty in the context.
632+
* The return type :math:`C.\CRETURN` must not be absent in the context.
620633

621634
* Let :math:`[t^?]` be the :ref:`result type <syntax-resulttype>` of :math:`C.\CRETURN`.
622635

@@ -632,8 +645,8 @@ Control Instructions
632645
.. note::
633646
The |RETURN| instruction is :ref:`stack-polymorphic <polymorphism>`.
634647

635-
:math:`C.\CRETURN` is empty (:math:`\epsilon`) when validating an :ref:`expression <valid-expr>` that is not a function body.
636-
This differs from it being set to the empty result type (:math:`[]`),
648+
:math:`C.\CRETURN` is absent (set to :math:`\epsilon`) when validating an :ref:`expression <valid-expr>` that is not a function body.
649+
This differs from it being set to the empty result type (:math:`[\epsilon]`),
637650
which is the case for functions not returning anything.
638651

639652

@@ -773,7 +786,7 @@ Constant Expressions
773786
\frac{
774787
(C \vdashinstrconst \instr \const)^\ast
775788
}{
776-
C \vdashexprconst \instr~\END \const
789+
C \vdashexprconst \instr^\ast~\END \const
777790
}
778791
779792
.. math::
@@ -789,4 +802,7 @@ Constant Expressions
789802
}
790803
791804
.. note::
805+
Currently, constant expressions occurring as initializers of :ref:`globals <syntax-global>` are further constrained in that contained |GETGLOBAL| instructions are only allowed to refer to *imported* globals.
806+
This is enforced in the :ref:`validation rule for modules <valid-module>` by constraining the context :math:`C` accordingly.
807+
792808
The definition of constant expression may be extended in future versions of WebAssembly.

0 commit comments

Comments
 (0)