Skip to content

Commit 888cce9

Browse files
authored
Restrict init from stack-polymorphism (WebAssembly#75)
1 parent 62c3b5a commit 888cce9

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

document/core/appendix/algorithm.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ The initialization stack and the initialization status of locals is manipulated
185185
.. code-block:: pseudo
186186
187187
func get_local(idx : u32) =
188-
error_if(not (locals_init[idx] || ctrls[0].unreachable))
188+
error_if(not locals_init[idx])
189189
190190
func set_local(idx : u32) =
191191
if (not locals_init[idx])
@@ -196,7 +196,7 @@ The initialization stack and the initialization status of locals is manipulated
196196
while (inits.size() > height)
197197
locals_init[inits.pop()] := false
198198
199-
Getting a local verifies that it is either known to be initialized, or that that the operation is unreachable in the current stack frame.
199+
Getting a local verifies that it is known to be initialized.
200200
When a local is set that was not set already,
201201
then its initialization status is updated and the change is recorded in the initialization stack.
202202
Thus, the initialization status of all locals can be reset to a previous state by denoting a specific height in the initialization stack.

document/core/valid/instructions.rst

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Two degrees of polymorphism can be distinguished:
3030
That is the case for all :ref:`parametric instructions <valid-instr-parametric>` like |DROP| and |SELECT|.
3131

3232
* *stack-polymorphic*:
33-
the entire (or most of the) :ref:`instruction type <syntax-instrtype>` :math:`[t_1^\ast] \to_{x^\ast} [t_2^\ast]` of the instruction is unconstrained.
33+
the entire (or most of the) :ref:`instruction type <syntax-instrtype>` :math:`[t_1^\ast] \to [t_2^\ast]` of the instruction is unconstrained.
3434
That is the case for all :ref:`control instructions <valid-instr-control>` that perform an *unconditional control transfer*, such as |UNREACHABLE|, |BR|, |BRTABLE|, and |RETURN|.
3535

3636
In both cases, the unconstrained types or type sequences can be chosen arbitrarily, as long as they meet the constraints imposed for the surrounding parts of the program.
@@ -49,7 +49,7 @@ In both cases, the unconstrained types or type sequences can be chosen arbitrari
4949
are valid, with :math:`t` in the typing of |SELECT| being instantiated to |I32| or |F64|, respectively.
5050

5151
The |UNREACHABLE| instruction is stack-polymorphic,
52-
and hence valid with type :math:`[t_1^\ast] \to_{x^\ast} [t_2^\ast]` for any possible sequences of value types :math:`t_1^\ast` and :math:`t_2^\ast` and sequence of locals :math:`x^\ast`.
52+
and hence valid with type :math:`[t_1^\ast] \to [t_2^\ast]` for any possible sequences of value types :math:`t_1^\ast` and :math:`t_2^\ast`.
5353
Consequently,
5454

5555
.. math::
@@ -1257,13 +1257,13 @@ Control Instructions
12571257
:math:`\UNREACHABLE`
12581258
....................
12591259

1260-
* The instruction is valid with any :ref:`valid <valid-instrtype>` type :math:`[t_1^\ast] \to_{x^\ast} [t_2^\ast]`.
1260+
* The instruction is valid with any :ref:`valid <valid-instrtype>` type of the form :math:`[t_1^\ast] \to [t_2^\ast]`.
12611261

12621262
.. math::
12631263
\frac{
1264-
C \vdashinstrtype [t_1^\ast] \to_{x^\ast} [t_2^\ast] \ok
1264+
C \vdashinstrtype [t_1^\ast] \to [t_2^\ast] \ok
12651265
}{
1266-
C \vdashinstr \UNREACHABLE : [t_1^\ast] \to_{x^\ast} [t_2^\ast]
1266+
C \vdashinstr \UNREACHABLE : [t_1^\ast] \to [t_2^\ast]
12671267
}
12681268
12691269
.. note::
@@ -1365,15 +1365,15 @@ Control Instructions
13651365

13661366
* Let :math:`[t^\ast]` be the :ref:`result type <syntax-resulttype>` :math:`C.\CLABELS[l]`.
13671367

1368-
* Then the instruction is valid with type :math:`[t_1^\ast~t^\ast] \to_{x^\ast} [t_2^\ast]`, for any :ref:`valid <valid-instrtype>` type :math:`[t_1^\ast] \to_{x^\ast} [t_2^\ast]`.
1368+
* Then the instruction is valid with any :ref:`valid <valid-instrtype>` type of the form :math:`[t_1^\ast~t^\ast] \to [t_2^\ast]`.
13691369

13701370
.. math::
13711371
\frac{
13721372
C.\CLABELS[l] = [t^\ast]
13731373
\qquad
1374-
C \vdashinstrtype [t_1^\ast] \to_{x^\ast} [t_2^\ast] \ok
1374+
C \vdashinstrtype [t_1^\ast~t^\ast] \to [t_2^\ast] \ok
13751375
}{
1376-
C \vdashinstr \BR~l : [t_1^\ast~t^\ast] \to_{x^\ast} [t_2^\ast]
1376+
C \vdashinstr \BR~l : [t_1^\ast~t^\ast] \to [t_2^\ast]
13771377
}
13781378
13791379
.. note::
@@ -1422,17 +1422,17 @@ Control Instructions
14221422
* For all :math:`l_i` in :math:`l^\ast`,
14231423
the result type :math:`[t^\ast]` :ref:`matches <match-resulttype>` :math:`C.\CLABELS[l_i]`.
14241424

1425-
* Then the instruction is valid with type :math:`[t_1^\ast~t^\ast~\I32] \to_{x^\ast} [t_2^\ast]`, for any :ref:`valid <valid-instrtype>` type :math:`[t_1^\ast] \to_{x^\ast} [t_2^\ast]`.
1425+
* Then the instruction is valid with any :ref:`valid <valid-instrtype>` type of the form :math:`[t_1^\ast~t^\ast~\I32] \to [t_2^\ast]`.
14261426

14271427
.. math::
14281428
\frac{
14291429
(C \vdashresulttypematch [t^\ast] \matchesresulttype C.\CLABELS[l])^\ast
14301430
\qquad
14311431
C \vdashresulttypematch [t^\ast] \matchesresulttype C.\CLABELS[l_N]
14321432
\qquad
1433-
C \vdashinstrtype [t_1^\ast] \to_{x^\ast} [t_2^\ast] \ok
1433+
C \vdashinstrtype [t_1^\ast~t^\ast~\I32] \to [t_2^\ast] \ok
14341434
}{
1435-
C \vdashinstr \BRTABLE~l^\ast~l_N : [t_1^\ast~t^\ast~\I32] \to_{x^\ast} [t_2^\ast]
1435+
C \vdashinstr \BRTABLE~l^\ast~l_N : [t_1^\ast~t^\ast~\I32] \to [t_2^\ast]
14361436
}
14371437
14381438
.. note::
@@ -1500,15 +1500,15 @@ Control Instructions
15001500

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

1503-
* Then the instruction is valid with type :math:`[t_1^\ast~t^\ast] \to_{x^\ast} [t_2^\ast]`, for any :ref:`valid <valid-instrtype>` type :math:`[t_1^\ast] \to_{x^\ast} [t_2^\ast]`.
1503+
* Then the instruction is valid with any :ref:`valid <valid-instrtype>` type of the form :math:`[t_1^\ast] \to [t_2^\ast]`.
15041504

15051505
.. math::
15061506
\frac{
15071507
C.\CRETURN = [t^\ast]
15081508
\qquad
1509-
C \vdashinstrtype [t_1^\ast] \to_{x^\ast} [t_2^\ast] \ok
1509+
C \vdashinstrtype [t_1^\ast~t^\ast] \to [t_2^\ast] \ok
15101510
}{
1511-
C \vdashinstr \RETURN : [t_1^\ast~t^\ast] \to_{x^\ast} [t_2^\ast]
1511+
C \vdashinstr \RETURN : [t_1^\ast~t^\ast] \to [t_2^\ast]
15121512
}
15131513
15141514
.. note::

0 commit comments

Comments
 (0)