Skip to content

Commit 80aea4a

Browse files
authored
[spec] Use optional data instance, not data address (WebAssembly#93)
data.drop must update the store, not the frame. There may be multiple copies of the frame, so any updates will only update once. We can make sure that all copies are updated by using an indirection through data addresses and updating the store instead. See discussion in PR WebAssembly#92.
1 parent 0ee9e67 commit 80aea4a

File tree

2 files changed

+50
-30
lines changed

2 files changed

+50
-30
lines changed

document/core/exec/instructions.rst

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -704,29 +704,31 @@ Memory Instructions
704704

705705
5. Let :math:`\X{mem}` be the :ref:`memory instance <syntax-meminst>` :math:`S.\SMEMS[\X{ma}]`.
706706

707-
6. Assert: due to :ref:`validation <valid-memory.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
707+
6. Assert: due to :ref:`validation <valid-data.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
708708

709-
7. Let :math:`\X{da}^?` be the optional :ref:`data address <syntax-dataaddr>` :math:`F.\AMODULE.\MIDATAS[x]`.
709+
7. Let :math:`\X{da}` be the :ref:`data address <syntax-dataaddr>` :math:`F.\AMODULE.\MIDATAS[x]`.
710710

711-
8. If :math:`\X{da}^? = \epsilon`, then:
711+
8. Assert: due to :ref:`validation <valid-data.init>`, :math:`S.\SDATA[\X{da}]` exists.
712712

713-
a. Trap.
713+
9. Let :math:`\X{data}^?` be the optional :ref:`data instance <syntax-datainst>` :math:`S.\SDATA[\X{da}]`.
714+
715+
10. If :math:`\X{data}^? = \epsilon`, then:
714716

715-
9. Let :math:`\X{data}` be the :ref:`data instance <syntax-datainst>` :math:`S.\SDATA[\X{da}]`.
717+
a. Trap.
716718

717-
10. Assert: due to :ref:`validation <valid-memory.init>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
719+
11. Assert: due to :ref:`validation <valid-memory.init>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
718720

719-
11. Pop the value :math:`\I32.\CONST~n` from the stack.
721+
12. Pop the value :math:`\I32.\CONST~n` from the stack.
720722

721-
12. Assert: due to :ref:`validation <valid-memory.init>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
723+
13. Assert: due to :ref:`validation <valid-memory.init>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
722724

723-
13. Pop the value :math:`\I32.\CONST~s` from the stack.
725+
14. Pop the value :math:`\I32.\CONST~s` from the stack.
724726

725-
14. Assert: due to :ref:`validation <valid-memory.init>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
727+
15. Assert: due to :ref:`validation <valid-memory.init>`, a value of :ref:`value type <syntax-valtype>` |I32| is on the top of the stack.
726728

727-
15. Pop the value :math:`\I32.\CONST~d` from the stack.
729+
16. Pop the value :math:`\I32.\CONST~d` from the stack.
728730

729-
16. If :math:`n` is :math:`0`, then:
731+
17. If :math:`n` is :math:`0`, then:
730732

731733
a. If :math:`d` is larger than the length of :math:`\X{mem}.\MIDATA`, then:
732734

@@ -736,7 +738,7 @@ Memory Instructions
736738

737739
i. Trap.
738740

739-
17. Else:
741+
18. Else:
740742

741743
a. Push the value :math:`\I32.\CONST~d` to the stack.
742744

@@ -755,6 +757,7 @@ Memory Instructions
755757
h. Execute the instruction :math:`\MEMORYINIT~x`.
756758

757759
.. math::
760+
~\\[-1ex]
758761
\begin{array}{l}
759762
\begin{array}{lcl@{\qquad}l}
760763
S; F; (\I32.\CONST~d)~(\I32.\CONST~s)~(\I32.\CONST~(n+1))~(\MEMORYINIT~x) &\stepto& S; F;
@@ -765,18 +768,17 @@ Memory Instructions
765768
\end{array} \\
766769
\\ \qquad
767770
\begin{array}[t]{@{}r@{~}l@{}}
768-
(\iff & F.\AMODULE.\MIDATAS[x] \ne \epsilon \\
769-
\wedge & b = \SDATA[F.\AMODULE.\MIDATAS[x]].\DIINIT[s]) \\
771+
(\iff & s < |S.\SDATA[F.\AMODULE.\MIDATAS[x]].\DIINIT| \\
772+
\wedge & b = S.\SDATA[F.\AMODULE.\MIDATAS[x]].\DIINIT[s]) \\
770773
\end{array}
771774
\\[1ex]
772775
\begin{array}{lcl@{\qquad}l}
773776
S; F; (\I32.\CONST~d)~(\I32.\CONST~(s)~(\I32.\CONST~0)~(\MEMORYINIT~x) &\stepto& S; F; \epsilon
774777
\end{array}
775778
\\ \qquad
776779
\begin{array}[t]{@{}r@{~}l@{}}
777-
(\iff & F.\AMODULE.\MIDATAS[x] \ne \epsilon \\
778-
\wedge & d \leq |\SMEMS[F.\AMODULE.\MIMEMS[0]]| \\
779-
\wedge & s \leq |\SDATA[F.\AMODULE.\MIDATAS[x]]|) \\
780+
(\iff & d \leq |S.\SMEMS[F.\AMODULE.\MIMEMS[0]].\MIDATA| \\
781+
\wedge & s \leq |S.\SDATA[F.\AMODULE.\MIDATAS[x]].\DIINIT|) \\
780782
\end{array}
781783
\\[1ex]
782784
\begin{array}{lcl@{\qquad}l}
@@ -794,22 +796,37 @@ Memory Instructions
794796

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

797-
2. Assert: due to :ref:`validation <valid-memory.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
799+
2. Assert: due to :ref:`validation <valid-data.init>`, :math:`F.\AMODULE.\MIDATAS[x]` exists.
800+
801+
3. Let :math:`a` be the :ref:`data address <syntax-dataaddr>` :math:`F.\AMODULE.\MIDATAS[x]`.
798802

799-
3. Let :math:`a^?` be the optional :ref:`data address <syntax-dataaddr>` :math:`F.\AMODULE.\MIDATAS[x]`.
803+
4. Assert: due to :ref:`validation <valid-data.init>`, :math:`S.\SDATA[a]` exists.
800804

801-
4. If :math:`a^? = \epsilon`, then:
805+
5. Let :math:`\X{data}^?` be the optional :ref:`data instance <syntax-datainst>` :math:`S.\SDATA[a]`.
806+
807+
6. If :math:`\X{data}^? = \epsilon`, then:
802808

803809
a. Trap.
804810

805-
5. Replace :math:`F.\AMODULE.\MIDATAS[x]` with :math:`\epsilon`.
811+
7. Replace :math:`S.\SDATA[a]` with :math:`\epsilon`.
806812

807813
.. math::
814+
~\\[-1ex]
815+
\begin{array}{l}
808816
\begin{array}{lcl@{\qquad}l}
809-
F; (\DATADROP~x) &\stepto& F'; \epsilon
810-
& (\iff F' = F \with \AMODULE.\MIDATAS[x] = \epsilon) \\
811-
F; (\DATADROP~x) &\stepto& F; \TRAP
812-
& (\otherwise) \\
817+
S; F; (\DATADROP~x) &\stepto& S'; F; \epsilon
818+
\end{array}
819+
\\ \qquad
820+
\begin{array}[t]{@{}r@{~}l@{}}
821+
(\iff & S.\SDATA[F.\AMODULE.\MIDATAS[x]] \ne \epsilon \\
822+
\wedge & S' = S \with \SDATA[F.\AMODULE.\MIDATAS[x]] = \epsilon) \\
823+
\end{array}
824+
\\[1ex]
825+
\begin{array}{lcl@{\qquad}l}
826+
S; F; (\DATADROP~x) &\stepto& S; F; \TRAP
827+
\end{array}
828+
\\ \qquad
829+
(\otherwise)
813830
\end{array}
814831
815832

document/core/exec/runtime.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ Store
6262
The *store* represents all global state that can be manipulated by WebAssembly programs.
6363
It consists of the runtime representation of all *instances* of :ref:`functions <syntax-funcinst>`, :ref:`tables <syntax-tableinst>`, :ref:`memories <syntax-meminst>`, and :ref:`globals <syntax-globalinst>`, :ref:`element segments <syntax-eleminst>`, and :ref:`data segments <syntax-datainst>` that have been :ref:`allocated <alloc>` during the life time of the abstract machine. [#gc]_
6464

65+
Element and data segments can be dropped by the owning module, in which case the respective instances are replaced with :math:`\epsilon`.
66+
It is an invariant of the semantics that no element or data instance is :ref:`addressed <syntax-addr>` from anywhere else but the owning module instances.
67+
6568
Syntactically, the store is defined as a :ref:`record <notation-record>` listing the existing instances of each category:
6669

6770
.. math::
@@ -72,8 +75,8 @@ Syntactically, the store is defined as a :ref:`record <notation-record>` listing
7275
\STABLES & \tableinst^\ast, \\
7376
\SMEMS & \meminst^\ast, \\
7477
\SGLOBALS & \globalinst^\ast, \\
75-
\SELEM & \eleminst^\ast, \\
76-
\SDATA & \datainst^\ast ~\} \\
78+
\SELEM & (\eleminst^?)^\ast, \\
79+
\SDATA & (\datainst^?)^\ast ~\} \\
7780
\end{array}
7881
\end{array}
7982
@@ -170,8 +173,8 @@ and collects runtime representations of all entities that are imported, defined,
170173
\MITABLES & \tableaddr^\ast, \\
171174
\MIMEMS & \memaddr^\ast, \\
172175
\MIGLOBALS & \globaladdr^\ast, \\
173-
\MIELEMS & (\elemaddr^?)^\ast, \\
174-
\MIDATAS & (\dataaddr^?)^\ast, \\
176+
\MIELEMS & \elemaddr^\ast, \\
177+
\MIDATAS & \dataaddr^\ast, \\
175178
\MIEXPORTS & \exportinst^\ast ~\} \\
176179
\end{array}
177180
\end{array}

0 commit comments

Comments
 (0)