Skip to content

Commit 99b2ff7

Browse files
committed
begin aux function specs
1 parent d391d96 commit 99b2ff7

3 files changed

Lines changed: 103 additions & 42 deletions

File tree

document/core/exec/relaxed.rst

Lines changed: 65 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,41 @@
66
Relaxed Memory Model
77
--------------------
88

9-
.. todo:: intro, cite [#cite-oopsla2019]_
10-
.. todo:: link this section with operational semantics
9+
The execution of a WebAssembly program gives rise to a :ref:`trace <relaxed-trace>` of events. WebAssembly's relaxed memory model constrains the observable behaviours of the program's execution by defining a :ref:`consistency <relaxed-consistent>` condition on the trace of events.
10+
11+
.. note::
12+
A relaxed memory model is necessary to describe the behaviour of programs exhibiting *shared memory concurrency*.
13+
WebAssembly's relaxed memory model is heavily based on those of C/C++11 and JavaScript.
14+
The relaxed memory model decribed here is derived from the following article: [#cite-oopsla2019]_.
15+
16+
17+
.. _relaxed-aux:
18+
19+
Preliminary Definitions
20+
~~~~~~~~~~~~~~~~~~~~~~~
21+
22+
.. math::
23+
\begin{array}{lcl}
24+
\timeevt \ldots & = & \ldots \\
25+
\\
26+
\readingact \ldots & = & \ldots \\
27+
\ordact \ldots & = & \ldots \\
28+
\overlapact \ldots & = & \ldots \\
29+
\\
30+
\readact \ldots & = & \ldots \\
31+
\\
32+
\writingact \ldots & = & \ldots \\
33+
\\
34+
\writeact \ldots & = & \ldots \\
35+
\offsetact \ldots & = & \ldots \\
36+
\\
37+
\syncact \ldots & = & \ldots \\
38+
\rangeact \ldots & = & \ldots \\
39+
\\
40+
\tearfreeact \ldots & = & \ldots \\
41+
\end{array}
42+
43+
.. todo:: need to refactor len+data in actions
1144

1245

1346
.. _relaxed-trace:
@@ -21,7 +54,7 @@ A trace is a coinductive set of :ref:`events <syntax-evt>`. A trace is considere
2154

2255
.. math::
2356
\frac{
24-
\config \stepto^{\evt} \config' \qquad \vdash \config' : \X{tr} \qquad \F{time}(\evt) \notin \F{time}(\X{tr})
57+
\config \stepto^{\evt} \config' \qquad \vdash \config' : \X{tr} \qquad \timeevt(\evt) \notin \timeevt^\ast(\X{tr})
2558
}{
2659
\vdash \config : \evt~\X{tr}
2760
}
@@ -40,97 +73,97 @@ Consistency
4073

4174
.. math::
4275
\frac{
43-
\forall r, \, \vdash_r \X{tr} \consistentwith
76+
\forall \loc, \, \vdash_{\loc} \X{tr} \consistentwith
4477
}{
4578
\vdash \X{tr} \consistent
4679
}
4780
4881
.. math::
4982
\frac{
5083
\begin{array}[b]{@{}l@{}}
51-
\forall \evt_R \in \F{reading}_r(\X{tr}), \exists \evt_W^\ast,
52-
\X{tr} \vdash_r \evt_R \readseachfrom \evt_W^\ast \\
84+
\forall \evt_R \in \readingact_{\loc}(\X{tr}), \exists \evt_W^\ast,
85+
\X{tr} \vdash_{\loc} \evt_R \readseachfrom \evt_W^\ast \\
5386
\forall \evt_I, \evt \in \X{tr}, \,
54-
\F{ord}_r(\evt_I) = \INIT \wedge
87+
\ordact_{\loc}(\evt_I) = \INIT \wedge
5588
\evt_I \neq \evt \wedge
56-
\F{overlap}_r(\evt_I, \evt) \Rightarrow \evt_I \prechb \evt
89+
\overlapact(\evt_I, \evt) \Rightarrow \evt_I \prechb \evt
5790
\end{array}
5891
}{
59-
\vdash_r \X{tr} \consistentwith
92+
\vdash_{\loc} \X{tr} \consistentwith
6093
}
6194
6295
.. math::
6396
\frac{
6497
\begin{array}[b]{@{}c@{}}
65-
\left|\evt_W^\ast\right| = |\F{read}_r(\evt_R)| \\
98+
\left|\evt_W^\ast\right| = |\readact_{\loc}(\evt_R)| \\
6699
\forall i < |\evt_W^\ast|,
67-
\X{tr} \vdash_r^i \evt_R \readsfrom \left(\evt_W^\ast[i]\right)
100+
\X{tr} \vdash_{\loc}^i \evt_R \readsfrom \left(\evt_W^\ast[i]\right)
68101
\\
69-
\vdash_r \evt_R \notear \evt_W^\ast
102+
\vdash_{\loc} \evt_R \notear \evt_W^\ast
70103
\end{array}
71104
}{
72-
\X{tr} \vdash_r \evt_R \readseachfrom \evt_W^\ast
105+
\X{tr} \vdash_{\loc} \evt_R \readseachfrom \evt_W^\ast
73106
}
74107
75108
.. math::
76109
\frac{
77110
\begin{array}[b]{@{}l@{}}
78111
\evt_R \neq \evt_W \\
79-
\evt_W \in \F{writing}_r(\X{tr})
112+
\evt_W \in \writingact_{\loc}(\X{tr})
80113
\end{array}
81114
\qquad
82115
\begin{array}[b]{@{}r@{}}
83-
\X{tr} \vdash_r^{i,k} \evt_R \valueconsistent \evt_W \\
84-
\X{tr} \vdash_r^k \evt_R \hbconsistent \evt_W
116+
\X{tr} \vdash_{\loc}^{i,k} \evt_R \valueconsistent \evt_W \\
117+
\X{tr} \vdash_{\loc}^k \evt_R \hbconsistent \evt_W
85118
\end{array}
86119
\qquad
87-
\X{tr} \vdash_r \evt_R \sclastvisible \evt^\ast_W
120+
\X{tr} \vdash_{\loc} \evt_R \sclastvisible \evt^\ast_W
88121
}{
89-
\X{tr} \vdash_r^i \evt_R \readsfrom \evt_W
122+
\X{tr} \vdash_{\loc}^i \evt_R \readsfrom \evt_W
90123
}
91124
92125
.. math::
93126
\frac{
94127
\begin{array}[b]{@{}r@{~}c@{~}l@{}}
95-
\F{read}_r(\evt_R)[i] &=& \F{write}_r(\evt_W)[j] \\
96-
k = \F{offset}_r(\evt_R) + i &=& \F{offset}_r(\evt_W) + j
128+
\readact_{\loc}(\evt_R)[i] &=& \writeact_{\loc}(\evt_W)[j] \\
129+
k = \offsetact_{\loc}(\evt_R) + i &=& \offsetact_{\loc}(\evt_W) + j
97130
\end{array}
98131
}{
99-
\X{tr} \vdash_r^{i,k} \evt_R \valueconsistent \evt_W
132+
\X{tr} \vdash_{\loc}^{i,k} \evt_R \valueconsistent \evt_W
100133
}
101134
102135
.. math::
103136
\frac{
104137
\begin{array}[b]{@{}c}
105138
\neg (\evt_R \prechb \evt_W) \\
106-
\F{sync}_r(\evt_W, \evt_R) \Rightarrow \evt_W \prechb \evt_R
139+
\syncact_{\loc}(\evt_W, \evt_R) \Rightarrow \evt_W \prechb \evt_R
107140
\end{array}
108141
\qquad
109142
\begin{array}[b]{@{}l@{}}
110-
\forall \evt'_W \in \F{writing}_r(\X{tr}),\\
111-
\quad \evt_W \prechb \evt'_W \prechb \evt_R \Rightarrow k \notin \F{range}_r(\evt'_W)
143+
\forall \evt'_W \in \writingact_{\loc}(\X{tr}),\\
144+
\quad \evt_W \prechb \evt'_W \prechb \evt_R \Rightarrow k \notin \rangeact_{\loc}(\evt'_W)
112145
\end{array}
113146
}{
114-
\X{tr} \vdash_r^k \evt_R \hbconsistent \evt_W
147+
\X{tr} \vdash_{\loc}^k \evt_R \hbconsistent \evt_W
115148
}
116149
117150
.. math::
118151
\frac{
119152
\begin{array}[b]{@{}l@{\qquad}l@{}}
120-
\forall \evt'_W \in \F{writing}_r(\X{tr}), \evt_W \prechb \evt_R \Rightarrow \\
121-
\quad \evt_W \prectot \evt'_W \prectot \evt_R \wedge \F{sync}_r(\evt_W, \evt_R) \Rightarrow \neg \F{sync}_r(\evt'_W, \evt_R) \\
122-
\quad \evt_W \prechb \evt'_W \prectot \evt_R \Rightarrow \neg\F{sync}_r(\evt'_W, \evt_R) \\
123-
\quad \evt_W \prectot \evt'_W \prechb \evt_R \Rightarrow \neg\F{sync}_r(\evt_W, \evt'_W)
153+
\forall \evt'_W \in \writingact_{\loc}(\X{tr}), \evt_W \prechb \evt_R \Rightarrow \\
154+
\quad \evt_W \prectot \evt'_W \prectot \evt_R \wedge \syncact_{\loc}(\evt_W, \evt_R) \Rightarrow \neg \syncact_{\loc}(\evt'_W, \evt_R) \\
155+
\quad \evt_W \prechb \evt'_W \prectot \evt_R \Rightarrow \neg\syncact_{\loc}(\evt'_W, \evt_R) \\
156+
\quad \evt_W \prectot \evt'_W \prechb \evt_R \Rightarrow \neg\syncact_{\loc}(\evt_W, \evt'_W)
124157
\end{array}
125158
}{
126-
\X{tr} \vdash_r \evt_R \sclastvisible \evt_W
159+
\X{tr} \vdash_{\loc} \evt_R \sclastvisible \evt_W
127160
}
128161
129162
.. math::
130163
\frac{
131-
\F{tearfree}_r(\evt_R) \Rightarrow |\{\evt_W \in \evt_W^\ast ~|~ \F{same}_r(\evt_R, \evt_W) \wedge \F{tearfree}_r(\evt_W)\}| \leq 1
164+
\tearfreeact_{\loc}(\evt_R) \Rightarrow |\{\evt_W \in \evt_W^\ast ~|~ \F{same}_r(\evt_R, \evt_W) \wedge \tearfreeact_{\loc}(\evt_W)\}| \leq 1
132165
}{
133-
\vdash_r \evt_R \notear \evt_W^\ast
166+
\vdash_{\loc} \evt_R \notear \evt_W^\ast
134167
}
135168
136169

document/core/exec/runtime.rst

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ even where this identity is not observable from within WebAssembly code itself
193193
.. index:: ! time stamp, ! happens-before, thread, event
194194
.. _syntax-time:
195195
.. _relaxed-prechb:
196+
.. _relaxed-prectot:
196197

197198
Time Stamps
198199
~~~~~~~~~~~
@@ -208,8 +209,12 @@ the semantics uses a notion of abstract *time stamps*.
208209
209210
Each time stamp denotes a discrete point in time, and is drawn from an infinite set.
210211
The shape of time stamps is not specified or observable.
211-
However, time stamps form a partially ordered set:
212-
a time stamp :math:`\time_1` *happens before* :math:`\time_2`, written :math:`\time_1 \prechb \time_2`, if it is known to have occurred earlier in time.
212+
213+
Time stamps are associated with a total order -- if a time stamp :math:`\time_1` is *totally ordered before* time stamp :math:`\time_2`, this is written as :math:`\time_1 \prectot \time_2`.
214+
215+
Time stamps are also associated with a *happens before* partial order -- if a time stamp :math:`\time_1` *happens before* :math:`\time_2`, this is written as :math:`\time_1 \prechb \time_2`.
216+
217+
During the execution of WebAssembly code, time stamped :ref:`events <syntax-evt>` may be emitted which are related by one or both of these orderings, thus constraining the code's observable behaviours according to WebAssembly's :ref:`relaxed memory model <relaxed>`.
213218

214219
.. note:
215220
@@ -218,9 +223,6 @@ a time stamp :math:`\time_1` *happens before* :math:`\time_2`, written :math:`\t
218223
219224
The ordering is partial because some events have an unspecified relative order -- in particular, when they occur in separate threads without intervening synchronisation.
220225
221-
.. _relaxed-prectot:
222-
.. todo:: define prectot here as well?
223-
224226
225227
.. _notation-attime:
226228

@@ -729,8 +731,8 @@ Its form and meaning is outside the scope of this specification.
729731
An :ref:`embedder <embedder>` may define a custom set of host actions and respective ordering constraints to model other forms of interactions that are not expressible within WebAssembly, but whose ordering relative to WebAssembly events is relevant for the combined semantics.
730732

731733

732-
Convention
733-
..........
734+
Conventions
735+
...........
734736

735737
* The actions :math:`\ARD_{\ord}` and :math:`\AWR_{\ord}` are abbreviated to just :math:`\ARD` and :math:`\AWR` when :math:`\ord` is :math:`\UNORD`.
736738

@@ -745,6 +747,15 @@ The following auxiliary definition is used to classify whether an access will *t
745747
746748
747749
.. todo:: better description of tearing
750+
751+
Relations between time stamps are lifted to relations between events.
752+
753+
.. math::
754+
\begin{array}{lclclcl}
755+
\act_1^\ast~\AT~\time_1 & \prectot & \act_2^\ast~\AT~\time_2 &=& \time_1 & \prectot & \time_2 \\
756+
\act_1^\ast~\AT~\time_1 & \prechb & \act_2^\ast~\AT~\time_2 &=& \time_1 & \prechb & \time_2 \\
757+
\end{array}
758+
748759
.. todo:: define notational shorthands over actions and events (or better put that in relaxed.rst?)
749760

750761

document/core/util/macros.def

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,24 @@
11131113
.. Events, meta functions
11141114
.. |tearing| mathdef:: \xref{exec/runtime}{syntax-ord}{\F{tearing}}
11151115

1116+
.. |timeevt| mathdef:: \xref{exec/runtime}{relaxed-aux}{\F{time}}
1117+
1118+
.. |readingact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{reading}}
1119+
.. |ordact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{ord}}
1120+
.. |overlapact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{overlap}}
1121+
1122+
.. |readact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{read}}
1123+
1124+
.. |writingact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{writing}}
1125+
1126+
.. |writeact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{write}}
1127+
.. |offsetact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{offset}}
1128+
1129+
.. |syncact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{sync}}
1130+
.. |rangeact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{range}}
1131+
1132+
.. |tearfreeact| mathdef:: \xref{exec/relaxed}{relaxed-aux}{\F{tearfree}}
1133+
11161134

11171135
.. Relaxed Memory Model Judgements
11181136

@@ -1125,9 +1143,8 @@
11251143
.. |hbconsistent| mathdef:: \xref{exec/relaxed}{relaxed-consistent}{\mathrel{\mbox{hb-consistent}}}
11261144
.. |valueconsistent| mathdef:: \xref{exec/relaxed}{relaxed-consistent}{\mathrel{\mbox{value-consistent}}}
11271145

1128-
.. |prechb| mathdef:: \xref{exec/relaxed}{relaxed-prechb}{\mathrel{\prec_{\K{hb}}}}
1129-
.. |prectot| mathdef:: \xref{exec/relaxed}{relaxed-prectot}{\mathrel{\prec_{\K{tot}}}}
1130-
1146+
.. |prechb| mathdef:: \xref{exec/runtime}{relaxed-prechb}{\mathrel{\prec_{\K{hb}}}}
1147+
.. |prectot| mathdef:: \xref{exec/runtime}{relaxed-prectot}{\mathrel{\prec_{\K{tot}}}}
11311148

11321149

11331150
.. Stack, terminals

0 commit comments

Comments
 (0)