Skip to content

Commit cd8bba6

Browse files
authored
Update embedding and execution specs for memory64 (WebAssembly#74)
* Convert table and memory instance storage to sequences Vectors in the spec are syntactically limited to a maximum size of 2^32. This is incompatible with memory64, so the storage has been changed to use sequences instead of vectors. The execution semantics are unaffected. * Update memory/table validation/execution/embedding to u64 Memory and table operations in the embedding section have been updated to use u64 instead of u32, reflecting the changes to `limits`. Various operations in the execution section were also updated to reflect `idxtype`'s inclusion in `memtype` and `tabletype`, as well as the supporting validation rules.
1 parent c61da44 commit cd8bba6

File tree

4 files changed

+45
-51
lines changed

4 files changed

+45
-51
lines changed

document/core/appendix/embedding.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Tables
383383
384384
.. _embed-table-read:
385385

386-
:math:`\F{table\_read}(\store, \tableaddr, i:\u32) : \reff ~|~ \error`
386+
:math:`\F{table\_read}(\store, \tableaddr, i:\u64) : \reff ~|~ \error`
387387
......................................................................
388388

389389
1. Let :math:`\X{ti}` be the :ref:`table instance <syntax-tableinst>` :math:`\store.\STABLES[\tableaddr]`.
@@ -401,7 +401,7 @@ Tables
401401
402402
.. _embed-table-write:
403403

404-
:math:`\F{table\_write}(\store, \tableaddr, i:\u32, \reff) : \store ~|~ \error`
404+
:math:`\F{table\_write}(\store, \tableaddr, i:\u64, \reff) : \store ~|~ \error`
405405
...............................................................................
406406

407407
1. Let :math:`\X{ti}` be the :ref:`table instance <syntax-tableinst>` :math:`\store.\STABLES[\tableaddr]`.
@@ -421,7 +421,7 @@ Tables
421421
422422
.. _embed-table-size:
423423

424-
:math:`\F{table\_size}(\store, \tableaddr) : \u32`
424+
:math:`\F{table\_size}(\store, \tableaddr) : \u64`
425425
..................................................
426426

427427
1. Return the length of :math:`\store.\STABLES[\tableaddr].\TIELEM`.
@@ -437,7 +437,7 @@ Tables
437437
438438
.. _embed-table-grow:
439439

440-
:math:`\F{table\_grow}(\store, \tableaddr, n:\u32, \reff) : \store ~|~ \error`
440+
:math:`\F{table\_grow}(\store, \tableaddr, n:\u64, \reff) : \store ~|~ \error`
441441
..............................................................................
442442

443443
1. Try :ref:`growing <grow-table>` the :ref:`table instance <syntax-tableinst>` :math:`\store.\STABLES[\tableaddr]` by :math:`n` elements with initialization value :math:`\reff`:
@@ -495,7 +495,7 @@ Memories
495495
496496
.. _embed-mem-read:
497497

498-
:math:`\F{mem\_read}(\store, \memaddr, i:\u32) : \byte ~|~ \error`
498+
:math:`\F{mem\_read}(\store, \memaddr, i:\u64) : \byte ~|~ \error`
499499
..................................................................
500500

501501
1. Let :math:`\X{mi}` be the :ref:`memory instance <syntax-meminst>` :math:`\store.\SMEMS[\memaddr]`.
@@ -513,12 +513,12 @@ Memories
513513
514514
.. _embed-mem-write:
515515

516-
:math:`\F{mem\_write}(\store, \memaddr, i:\u32, \byte) : \store ~|~ \error`
516+
:math:`\F{mem\_write}(\store, \memaddr, i:\u64, \byte) : \store ~|~ \error`
517517
...........................................................................
518518

519519
1. Let :math:`\X{mi}` be the :ref:`memory instance <syntax-meminst>` :math:`\store.\SMEMS[\memaddr]`.
520520

521-
2. If :math:`\u32` is larger than or equal to the length of :math:`\X{mi}.\MIDATA`, then return :math:`\ERROR`.
521+
2. If :math:`i` is larger than or equal to the length of :math:`\X{mi}.\MIDATA`, then return :math:`\ERROR`.
522522

523523
3. Replace :math:`\X{mi}.\MIDATA[i]` with :math:`\byte`.
524524

@@ -533,7 +533,7 @@ Memories
533533
534534
.. _embed-mem-size:
535535

536-
:math:`\F{mem\_size}(\store, \memaddr) : \u32`
536+
:math:`\F{mem\_size}(\store, \memaddr) : \u64`
537537
..............................................
538538

539539
1. Return the length of :math:`\store.\SMEMS[\memaddr].\MIDATA` divided by the :ref:`page size <page-size>`.
@@ -549,7 +549,7 @@ Memories
549549
550550
.. _embed-mem-grow:
551551

552-
:math:`\F{mem\_grow}(\store, \memaddr, n:\u32) : \store ~|~ \error`
552+
:math:`\F{mem\_grow}(\store, \memaddr, n:\u64) : \store ~|~ \error`
553553
...................................................................
554554

555555
1. Try :ref:`growing <grow-mem>` the :ref:`memory instance <syntax-meminst>` :math:`\store.\SMEMS[\memaddr]` by :math:`n` :ref:`pages <page-size>`:

document/core/exec/modules.rst

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the fo
9494

9595
1. Let :math:`\tabletype` be the :ref:`table type <syntax-tabletype>` of the table to allocate and :math:`\reff` the initialization value.
9696

97-
2. Let :math:`(\{\LMIN~n, \LMAX~m^?\}~\reftype)` be the structure of :ref:`table type <syntax-tabletype>` :math:`\tabletype`.
97+
2. Let :math:`(\idxtype~\{\LMIN~n, \LMAX~m^?\}~\reftype)` be the structure of :ref:`table type <syntax-tabletype>` :math:`\tabletype`.
9898

9999
3. Let :math:`a` be the first free :ref:`table address <syntax-tableaddr>` in :math:`S`.
100100

101-
4. Let :math:`\tableinst` be the :ref:`table instance <syntax-tableinst>` :math:`\{ \TITYPE~\tabletype', \TIELEM~\reff^n \}` with :math:`n` elements set to :math:`\reff`.
101+
4. Let :math:`\tableinst` be the :ref:`table instance <syntax-tableinst>` :math:`\{ \TITYPE~\tabletype, \TIELEM~\reff^n \}` with :math:`n` elements set to :math:`\reff`.
102102

103103
5. Append :math:`\tableinst` to the |STABLES| of :math:`S`.
104104

@@ -108,7 +108,7 @@ are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the fo
108108
\begin{array}{rlll}
109109
\alloctable(S, \tabletype, \reff) &=& S', \tableaddr \\[1ex]
110110
\mbox{where:} \hfill \\
111-
\tabletype &=& \{\LMIN~n, \LMAX~m^?\}~\reftype \\
111+
\tabletype &=& \idxtype~\{\LMIN~n, \LMAX~m^?\}~\reftype \\
112112
\tableaddr &=& |S.\STABLES| \\
113113
\tableinst &=& \{ \TITYPE~\tabletype, \TIELEM~\reff^n \} \\
114114
S' &=& S \compose \{\STABLES~\tableinst\} \\
@@ -123,7 +123,7 @@ are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the fo
123123

124124
1. Let :math:`\memtype` be the :ref:`memory type <syntax-memtype>` of the memory to allocate.
125125

126-
2. Let :math:`\{\LMIN~n, \LMAX~m^?\}` be the structure of :ref:`memory type <syntax-memtype>` :math:`\memtype`.
126+
2. Let :math:`(\idxtype~\{\LMIN~n, \LMAX~m^?\})` be the structure of :ref:`memory type <syntax-memtype>` :math:`\memtype`.
127127

128128
3. Let :math:`a` be the first free :ref:`memory address <syntax-memaddr>` in :math:`S`.
129129

@@ -137,7 +137,7 @@ are *allocated* in a :ref:`store <syntax-store>` :math:`S`, as defined by the fo
137137
\begin{array}{rlll}
138138
\allocmem(S, \memtype) &=& S', \memaddr \\[1ex]
139139
\mbox{where:} \hfill \\
140-
\memtype &=& \{\LMIN~n, \LMAX~m^?\} \\
140+
\memtype &=& \idxtype~\{\LMIN~n, \LMAX~m^?\} \\
141141
\memaddr &=& |S.\SMEMS| \\
142142
\meminst &=& \{ \MITYPE~\memtype, \MIDATA~(\hex{00})^{n \cdot 64\,\F{Ki}} \} \\
143143
S' &=& S \compose \{\SMEMS~\meminst\} \\
@@ -284,28 +284,25 @@ Growing :ref:`tables <syntax-tableinst>`
284284

285285
2. Let :math:`\X{len}` be :math:`n` added to the length of :math:`\tableinst.\TIELEM`.
286286

287-
3. If :math:`\X{len}` is larger than or equal to :math:`2^{32}`, then fail.
287+
3. Let :math:`(\idxtype~\limits~\reftype)` be the structure of :ref:`table type <syntax-tabletype>` :math:`\tableinst.\TITYPE`.
288288

289-
4. Let :math:`\limits~t` be the structure of :ref:`table type <syntax-tabletype>` :math:`\tableinst.\TITYPE`.
289+
4. Let :math:`\limits'` be :math:`\limits` with :math:`\LMIN` updated to :math:`\X{len}`.
290290

291-
5. Let :math:`\limits'` be :math:`\limits` with :math:`\LMIN` updated to :math:`\X{len}`.
292-
293-
6. If :math:`\limits'` is not :ref:`valid <valid-limits>`, then fail.
291+
5. If the :ref:`table type <syntax-tabletype>` :math:`(\idxtype~\limits'~\reftype)` is not :ref:`valid <valid-tabletype>`, then fail.
294292

295-
7. Append :math:`\reff^n` to :math:`\tableinst.\TIELEM`.
293+
6. Append :math:`\reff^n` to :math:`\tableinst.\TIELEM`.
296294

297-
8. Set :math:`\tableinst.\TITYPE` to the :ref:`table type <syntax-tabletype>` :math:`\limits'~t`.
295+
7. Set :math:`\tableinst.\TITYPE` to the :ref:`table type <syntax-tabletype>` :math:`(\idxtype~\limits'~\reftype)`.
298296

299297
.. math::
300298
\begin{array}{rllll}
301-
\growtable(\tableinst, n, \reff) &=& \tableinst \with \TITYPE = \limits'~t \with \TIELEM = \tableinst.\TIELEM~\reff^n \\
299+
\growtable(\tableinst, n, \reff) &=& \tableinst \with \TITYPE = \idxtype~\limits'~\reftype \with \TIELEM = \tableinst.\TIELEM~\reff^n \\
302300
&& (
303301
\begin{array}[t]{@{}r@{~}l@{}}
304302
\iff & \X{len} = n + |\tableinst.\TIELEM| \\
305-
\wedge & \X{len} < 2^{32} \\
306-
\wedge & \limits~t = \tableinst.\TITYPE \\
303+
\wedge & \idxtype~\limits~\reftype = \tableinst.\TITYPE \\
307304
\wedge & \limits' = \limits \with \LMIN = \X{len} \\
308-
\wedge & \vdashlimits \limits' \ok) \\
305+
\wedge & \vdashtabletype \idxtype~\limits'~\reftype \ok) \\
309306
\end{array} \\
310307
\end{array}
311308
@@ -322,28 +319,25 @@ Growing :ref:`memories <syntax-meminst>`
322319

323320
3. Let :math:`\X{len}` be :math:`n` added to the length of :math:`\meminst.\MIDATA` divided by the :ref:`page size <page-size>` :math:`64\,\F{Ki}`.
324321

325-
4. If :math:`\X{len}` is larger than :math:`2^{16}`, then fail.
322+
4. Let :math:`(\idxtype~\limits)` be the structure of :ref:`memory type <syntax-memtype>` :math:`\meminst.\MITYPE`.
326323

327-
5. Let :math:`\limits` be the structure of :ref:`memory type <syntax-memtype>` :math:`\meminst.\MITYPE`.
328-
329-
6. Let :math:`\limits'` be :math:`\limits` with :math:`\LMIN` updated to :math:`\X{len}`.
324+
5. Let :math:`\limits'` be :math:`\limits` with :math:`\LMIN` updated to :math:`\X{len}`.
330325

331-
7. If :math:`\limits'` is not :ref:`valid <valid-limits>`, then fail.
326+
6. If the :ref:`memory type <syntax-memtype>` :math:`(\idxtype~\limits')` is not :ref:`valid <valid-memtype>`, then fail.
332327

333-
8. Append :math:`n` times :math:`64\,\F{Ki}` :ref:`bytes <syntax-byte>` with value :math:`\hex{00}` to :math:`\meminst.\MIDATA`.
328+
7. Append :math:`n` times :math:`64\,\F{Ki}` :ref:`bytes <syntax-byte>` with value :math:`\hex{00}` to :math:`\meminst.\MIDATA`.
334329

335-
9. Set :math:`\meminst.\MITYPE` to the :ref:`memory type <syntax-memtype>` :math:`\limits'`.
330+
8. Set :math:`\meminst.\MITYPE` to the :ref:`memory type <syntax-memtype>` :math:`(\idxtype~\limits')`.
336331

337332
.. math::
338333
\begin{array}{rllll}
339-
\growmem(\meminst, n) &=& \meminst \with \MITYPE = \limits' \with \MIDATA = \meminst.\MIDATA~(\hex{00})^{n \cdot 64\,\F{Ki}} \\
334+
\growmem(\meminst, n) &=& \meminst \with \MITYPE = \idxtype~\limits' \with \MIDATA = \meminst.\MIDATA~(\hex{00})^{n \cdot 64\,\F{Ki}} \\
340335
&& (
341336
\begin{array}[t]{@{}r@{~}l@{}}
342337
\iff & \X{len} = n + |\meminst.\MIDATA| / 64\,\F{Ki} \\
343-
\wedge & \X{len} \leq 2^{16} \\
344-
\wedge & \limits = \meminst.\MITYPE \\
338+
\wedge & \idxtype~\limits = \meminst.\MITYPE \\
345339
\wedge & \limits' = \limits \with \LMIN = \X{len} \\
346-
\wedge & \vdashlimits \limits' \ok) \\
340+
\wedge & \vdashmemtype \idxtype~\limits' \ok) \\
347341
\end{array} \\
348342
\end{array}
349343

document/core/exec/runtime.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,18 +356,18 @@ Table Instances
356356
~~~~~~~~~~~~~~~
357357

358358
A *table instance* is the runtime representation of a :ref:`table <syntax-table>`.
359-
It records its :ref:`type <syntax-tabletype>` and holds a vector of :ref:`reference values <syntax-ref>`.
359+
It records its :ref:`type <syntax-tabletype>` and holds a sequence of :ref:`reference values <syntax-ref>`.
360360

361361
.. math::
362362
\begin{array}{llll}
363363
\production{table instance} & \tableinst &::=&
364-
\{ \TITYPE~\tabletype, \TIELEM~\vec(\reff) \} \\
364+
\{ \TITYPE~\tabletype, \TIELEM~\reff^\ast \} \\
365365
\end{array}
366366
367367
Table elements can be mutated through :ref:`table instructions <syntax-instr-table>`, the execution of an active :ref:`element segment <syntax-elem>`, or by external means provided by the :ref:`embedder <embedder>`.
368368

369369
It is an invariant of the semantics that all table elements have a type :ref:`matching <match-reftype>` the element type of :math:`\tabletype`.
370-
It also is an invariant that the length of the element vector never exceeds the maximum size of :math:`\tabletype`, if present.
370+
It also is an invariant that the length of the element sequence never exceeds the maximum size of :math:`\tabletype`, if present.
371371

372372

373373
.. index:: ! memory instance, memory, byte, ! page size, memory type, embedder, data segment, instruction
@@ -380,15 +380,15 @@ Memory Instances
380380
~~~~~~~~~~~~~~~~
381381

382382
A *memory instance* is the runtime representation of a linear :ref:`memory <syntax-mem>`.
383-
It records its :ref:`type <syntax-memtype>` and holds a vector of :ref:`bytes <syntax-byte>`.
383+
It records its :ref:`type <syntax-memtype>` and holds a sequence of :ref:`bytes <syntax-byte>`.
384384

385385
.. math::
386386
\begin{array}{llll}
387387
\production{memory instance} & \meminst &::=&
388-
\{ \MITYPE~\memtype, \MIDATA~\vec(\byte) \} \\
388+
\{ \MITYPE~\memtype, \MIDATA~\byte^\ast \} \\
389389
\end{array}
390390
391-
The length of the vector always is a multiple of the WebAssembly *page size*, which is defined to be the constant :math:`65536` -- abbreviated :math:`64\,\F{Ki}`.
391+
The length of the sequence always is a multiple of the WebAssembly *page size*, which is defined to be the constant :math:`65536` -- abbreviated :math:`64\,\F{Ki}`.
392392

393393
The bytes can be mutated through :ref:`memory instructions <syntax-instr-memory>`, the execution of an active :ref:`data segment <syntax-data>`, or by external means provided by the :ref:`embedder <embedder>`.
394394

document/core/valid/types.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,22 +501,22 @@ Limits
501501
Table Types
502502
~~~~~~~~~~~
503503

504-
:math:`\limits~\reftype`
505-
........................
504+
:math:`\idxtype~\limits~\reftype`
505+
.................................
506506

507-
* The limits :math:`\limits` must be :ref:`valid <valid-limits>` within range :math:`2^{32}-1`.
507+
* The limits :math:`\limits` must be :ref:`valid <valid-limits>` within range :math:`2^{|\idxtype|}-1`.
508508

509509
* The reference type :math:`\reftype` must be :ref:`valid <valid-reftype>`.
510510

511511
* Then the table type is valid.
512512

513513
.. math::
514514
\frac{
515-
C \vdashlimits \limits : 2^{32} - 1
515+
C \vdashlimits \limits : 2^{|\idxtype|}-1
516516
\qquad
517517
C \vdashreftype \reftype \ok
518518
}{
519-
C \vdashtabletype \limits~\reftype \ok
519+
C \vdashtabletype \idxtype~\limits~\reftype \ok
520520
}
521521
522522
@@ -528,16 +528,16 @@ Table Types
528528
Memory Types
529529
~~~~~~~~~~~~
530530

531-
:math:`\limits`
532-
...............
531+
:math:`\idxtype~\limits`
532+
........................
533533

534-
* The limits :math:`\limits` must be :ref:`valid <valid-limits>` within range :math:`2^{16}`.
534+
* The limits :math:`\limits` must be :ref:`valid <valid-limits>` within range :math:`2^{|\idxtype|-16}`.
535535

536536
* Then the memory type is valid.
537537

538538
.. math::
539539
\frac{
540-
C \vdashlimits \limits : 2^{16}
540+
C \vdashlimits \limits : 2^{|\idxtype|-16}
541541
}{
542542
C \vdashmemtype \limits \ok
543543
}

0 commit comments

Comments
 (0)