Skip to content
This repository was archived by the owner on Nov 3, 2021. It is now read-only.
Merged

Text #119

Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions document/core/text/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ A :ref:`start function <syntax-start>` is defined in terms of its index.
.. _text-elem:
.. _text-elemlist:
.. _text-elemexpr:
.. _text-tableuse:

Element Segments
~~~~~~~~~~~~~~~~
Expand All @@ -497,13 +498,16 @@ Element segments allow for an optional :ref:`table index <text-tableidx>` to ide
\production{element segment} & \Telem_I &::=&
\text{(}~\text{elem}~~\Tid^?~~(et, y^\ast){:}\Telemlist~\text{)} \\ &&& \qquad
\Rightarrow\quad \{ \ETYPE~et, \EINIT~y^\ast, \EMODE~\EPASSIVE \} \\ &&|&
\text{(}~\text{elem}~~\Tid^?~~\text{(}~\text{table}~~x{:}\Ttableidx_I ~\text{)}~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~(et, y^\ast){:}\Telemlist~\text{)} \\ &&& \qquad
\text{(}~\text{elem}~~\Tid^?~~x{:}\Ttableuse_I~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~(et, y^\ast){:}\Telemlist~\text{)} \\ &&& \qquad
\Rightarrow\quad \{ \ETYPE~et, \EINIT~y^\ast, \EMODE~\EACTIVE~\{ \ETABLE~x, \EOFFSET~e \} \} \\
\production{element list} & \Telemlist &::=&
et{:}\Telemtype~~y^\ast{:}\Tvec(\Telemexpr_I) \qquad\Rightarrow\quad ( \ETYPE~et, \EINIT~y^\ast ) \\ &&|&
\production{element expression} & \Telemexpr &::=&
\text{(}~\text{ref.null}~\text{)} \\ &&|&
\text{(}~\text{ref.func}~~\Tfuncidx_I~\text{)} \\
\production{table use} & \Ttableuse_I &::=&
\text{(}~\text{table}~~x{:}\Ttableidx_I ~\text{)}
\quad\Rightarrow\quad x \\
\end{array}

.. note::
Expand Down Expand Up @@ -532,16 +536,15 @@ Also, the element list may be written as just a sequence of :ref:`function indic
\text{funcref}~~\Tvec(\text{(}~\text{ref.func}~~\Tfuncidx_I~\text{)})
\end{array}

Also, the table index can be omitted, defaulting to :math:`\T{0}`.
Furthermore, for backwards compatibility with earlier versions of WebAssembly, if the table index is omitted, the :math:`\text{func}` keyword can be omitted as well.
Also, a table use can be omitted, defaulting to :math:`\T{0}`.
Furthermore, for backwards compatibility with earlier versions of WebAssembly, if the table use is omitted, the :math:`\text{func}` keyword can be omitted as well.

.. math::
\begin{array}{llclll}
\production{table use} &
\epsilon &\equiv& \text{(}~\text{table}~~\text{0}~\text{)} \\
\production{element segment} &
\text{(}~\text{elem}~~\Tid^?~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\Telemlist~\text{)}
&\equiv&
\text{(}~\text{elem}~~\Tid^?~~\text{(}~\text{table}~~\text{0}~\text{)}~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\Telemlist~\text{)}
\text{(}~\text{elem}~~\Tid^?~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\Tvec(\Tfuncidx_I)~\text{)}
\text{(}~\text{elem}~~\Tid^?~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\Tvec(\Tfuncidx_I)~\text{)}
&\equiv&
\text{(}~\text{elem}~~\Tid^?~~\text{(}~\text{table}~~\text{0}~\text{)}~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\text{func}~~\Tvec(\Tfuncidx_I)~\text{)}
\end{array}
Expand All @@ -555,6 +558,7 @@ As another abbreviation, element segments may also be specified inline with :ref
single: data; segment
.. _text-datastring:
.. _text-data:
.. _test-memuse:

Data Segments
~~~~~~~~~~~~~
Expand All @@ -567,10 +571,13 @@ The data is written as a :ref:`string <text-string>`, which may be split up into
\production{data segment} & \Tdata_I &::=&
\text{(}~\text{data}~~\Tid^?~~b^\ast{:}\Tdatastring~\text{)} \\ &&& \qquad
\Rightarrow\quad \{ \DINIT~b^\ast, \DMODE~\DPASSIVE \} \\ &&|&
\text{(}~\text{data}~~\Tid^?~~\text{(}~\text{memory}~~x{:}\Tmemidx_I ~\text{)}~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~b^\ast{:}\Tdatastring~\text{)} \\ &&& \qquad
\text{(}~\text{data}~~\Tid^?~~x{:}\Tmemuse_I~~\text{(}~\text{offset}~~e{:}\Texpr_I~\text{)}~~b^\ast{:}\Tdatastring~\text{)} \\ &&& \qquad
\Rightarrow\quad \{ \DINIT~b^\ast, \DMODE~\DACTIVE~\{ \DMEM~x', \DOFFSET~e \} \} \\
\production{data string} & \Tdatastring &::=&
(b^\ast{:}\Tstring)^\ast \quad\Rightarrow\quad \concat((b^\ast)^\ast) \\
\production{memory use} & \Tmemuse_I &::=&
\text{(}~\text{memory}~~x{:}\Tmemidx_I ~\text{)}
\quad\Rightarrow\quad x \\
\end{array}

.. note::
Expand All @@ -590,14 +597,12 @@ As an abbreviation, a single instruction may occur in place of the offset of an
\text{(}~\text{offset}~~\Tinstr~\text{)}
\end{array}

Also, the memory index can be omitted, defaulting to :math:`\T{0}`.
Also, a memory use can be omitted, defaulting to :math:`\T{0}`.

.. math::
\begin{array}{llclll}
\production{data segment} &
\text{(}~\text{data}~~\Tid^?~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\dots~\text{)}
&\equiv&
\text{(}~\text{data}~~\Tid^?~~\text{(}~\text{memory}~~\text{0}~\text{)}~~\text{(}~\text{offset}~~\Texpr_I~\text{)}~~\dots~\text{)}
\production{memory use} &
\epsilon &\equiv& \text{(}~\text{memory}~~\text{0}~\text{)} \\
\end{array}

As another abbreviation, data segments may also be specified inline with :ref:`memory <text-mem>` definitions; see the respective section.
Expand Down
2 changes: 2 additions & 0 deletions document/core/util/macros.def
Original file line number Diff line number Diff line change
Expand Up @@ -700,11 +700,13 @@
.. |Telem| mathdef:: \xref{text/modules}{text-elem}{\T{elem}}
.. |Telemlist| mathdef:: \xref{text/modules}{text-elemlist}{\T{elemlist}}
.. |Telemexpr| mathdef:: \xref{text/modules}{text-elemexpr}{\X{elemexpr}}
.. |Ttableuse| mathdef:: \xref{text/modules}{text-tableuse}{\T{tableuse}}
.. |Tcode| mathdef:: \xref{text/modules}{text-code}{\T{code}}
.. |Tlocal| mathdef:: \xref{text/modules}{text-local}{\T{local}}
.. |Tlocals| mathdef:: \xref{text/modules}{text-local}{\T{locals}}
.. |Tdata| mathdef:: \xref{text/modules}{text-data}{\T{data}}
.. |Tdatastring| mathdef:: \xref{text/modules}{text-datastring}{\T{datastring}}
.. |Tmemuse| mathdef:: \xref{text/modules}{text-memuse}{\T{memuse}}
.. |Tstart| mathdef:: \xref{text/modules}{text-start}{\T{start}}


Expand Down
36 changes: 17 additions & 19 deletions interpreter/text/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,9 @@ func_body :
table_use :
| LPAR TABLE var RPAR { fun c -> $3 c }

memory_use :
| LPAR MEMORY var RPAR { fun c -> $3 c }

offset :
| LPAR OFFSET const_expr RPAR { $3 }
| expr { let at = at () in fun c -> $1 c @@ at } /* Sugar */
Expand Down Expand Up @@ -597,29 +600,29 @@ elem_list :


elem :
| LPAR ELEM bind_var_opt offset elem_var_list RPAR /* Sugar */
{ let at = at () in
fun c -> ignore ($3 c anon_elem bind_elem);
fun () ->
{ etype = FuncRefType; einit = $5 c func;
emode = Active {index = 0l @@ at; offset = $4 c} @@ at} @@ at }
| LPAR ELEM bind_var_opt elem_list RPAR
{ let at = at () in
fun c -> ignore ($3 c anon_elem bind_elem);
fun () ->
{etype = (fst $4); einit = (snd $4) c; emode = Passive @@ at} @@ at }
{ etype = (fst $4); einit = (snd $4) c; emode = Passive @@ at } @@ at }
| LPAR ELEM bind_var_opt table_use offset elem_list RPAR
{ let at = at () in
fun c -> ignore ($3 c anon_elem bind_elem);
fun () ->
{ etype = (fst $6); einit = (snd $6) c;
emode = Active {index = $4 c table; offset = $5 c} @@ at} @@ at }
emode = Active {index = $4 c table; offset = $5 c} @@ at } @@ at }
| LPAR ELEM bind_var_opt offset elem_list RPAR /* Sugar */
{ let at = at () in
fun c -> ignore ($3 c anon_elem bind_elem);
fun () ->
{ etype = (fst $5); einit = (snd $5) c;
emode = Active {index = 0l @@ at; offset = $4 c} @@ at} @@ at }
emode = Active {index = 0l @@ at; offset = $4 c} @@ at } @@ at }
| LPAR ELEM bind_var_opt offset elem_var_list RPAR /* Sugar */
{ let at = at () in
fun c -> ignore ($3 c anon_elem bind_elem);
fun () ->
{ etype = FuncRefType; einit = $5 c func;
emode = Active {index = 0l @@ at; offset = $4 c} @@ at } @@ at }

table :
| LPAR TABLE bind_var_opt table_fields RPAR
Expand Down Expand Up @@ -662,21 +665,16 @@ data :
{ let at = at () in
fun c -> ignore ($3 c anon_data bind_data);
fun () -> {dinit = $4; dmode = Passive @@ at} @@ at }
| LPAR DATA bind_var var offset string_list RPAR
| LPAR DATA bind_var_opt memory_use offset string_list RPAR
{ let at = at () in
fun c -> ignore (bind_data c $3);
fun c -> ignore ($3 c anon_data bind_data);
fun () ->
{dinit = $6; dmode = Active {index = $4 c memory; offset = $5 c} @@ at} @@ at }
| LPAR DATA var offset string_list RPAR
{ let at = at () in
fun c -> ignore (anon_data c);
fun () ->
{dinit = $5; dmode = Active {index = $3 c memory; offset = $4 c} @@ at} @@ at }
| LPAR DATA offset string_list RPAR /* Sugar */
| LPAR DATA bind_var_opt offset string_list RPAR /* Sugar */
{ let at = at () in
fun c -> ignore (anon_data c);
fun c -> ignore ($3 c anon_data bind_data);
fun () ->
{dinit = $4; dmode = Active {index = 0l @@ at; offset = $3 c} @@ at} @@ at }
{dinit = $5; dmode = Active {index = 0l @@ at; offset = $4 c} @@ at} @@ at }

memory :
| LPAR MEMORY bind_var_opt memory_fields RPAR
Expand Down
2 changes: 1 addition & 1 deletion test/core/bulk.wast
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
(module
(memory 1)
(data $p "x")
(data $a 0 (i32.const 0) "x")
(data $a (memory 0) (i32.const 0) "x")

(func (export "drop_passive") (data.drop $p))
(func (export "init_passive") (param $len i32)
Expand Down
28 changes: 20 additions & 8 deletions test/core/data.wast
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,26 @@
(data (i32.const 1) "a" "" "bcd")
(data (offset (i32.const 0)))
(data (offset (i32.const 0)) "" "a" "bc" "")
(data 0 (i32.const 0))
(data 0x0 (i32.const 1) "a" "" "bcd")
(data 0x000 (offset (i32.const 0)))
(data 0 (offset (i32.const 0)) "" "a" "bc" "")
(data $m (i32.const 0))
(data $m (i32.const 1) "a" "" "bcd")
(data $m (offset (i32.const 0)))
(data $m (offset (i32.const 0)) "" "a" "bc" "")
(data (memory 0) (i32.const 0))
(data (memory 0x0) (i32.const 1) "a" "" "bcd")
(data (memory 0x000) (offset (i32.const 0)))
(data (memory 0) (offset (i32.const 0)) "" "a" "bc" "")
(data (memory $m) (i32.const 0))
(data (memory $m) (i32.const 1) "a" "" "bcd")
(data (memory $m) (offset (i32.const 0)))
(data (memory $m) (offset (i32.const 0)) "" "a" "bc" "")
(data $d1 (i32.const 0))
(data $d2 (i32.const 1) "a" "" "bcd")
(data $d3 (offset (i32.const 0)))
(data $d4 (offset (i32.const 0)) "" "a" "bc" "")
(data $d5 (memory 0) (i32.const 0))
(data $d6 (memory 0x0) (i32.const 1) "a" "" "bcd")
(data $d7 (memory 0x000) (offset (i32.const 0)))
(data $d8 (memory 0) (offset (i32.const 0)) "" "a" "bc" "")
(data $d9 (memory $m) (i32.const 0))
(data $d10 (memory $m) (i32.const 1) "a" "" "bcd")
(data $d11 (memory $m) (offset (i32.const 0)))
(data $d12 (memory $m) (offset (i32.const 0)) "" "a" "bc" "")
Comment on lines +21 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests look exactly the same as above, although with IDs. Do you expect these additional data segments to increase coverage? Could you add a comment which describes the goals of these tests?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Note that the header comment above says "Syntax", so this module is all about testing that the parser understands all combinations of syntax.

)

;; Basic use
Expand Down
68 changes: 53 additions & 15 deletions test/core/elem.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,29 @@
(table $t 10 funcref)
(func $f)
(func $g)
(elem (table $t) (i32.const 0) func)
(elem (i32.const 0))
(elem (i32.const 0) $f $f)
(elem (offset (i32.const 0)))
(elem (offset (i32.const 0)) $f $f)

;; Passive
(elem funcref)
(elem funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
(elem func)
(elem $s func)
(elem func $f $f $g $g)
(elem $x func $f $f $g $g)

(elem $p1 funcref)
(elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
(elem $p3 func)
(elem $p4 func $f $f $g $g)

;; Active
(elem (table $t) (i32.const 0) funcref)
(elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
(elem (table $t) (i32.const 0) func)
(elem (table $t) (i32.const 0) func $f $g)
(elem (table $t) (i32.const 0) funcref)
(elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
(elem (table $t) (i32.const 0) func)
(elem (table $t) (i32.const 0) func $f $g)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't these just duplicates of the tests above?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yes, removed (here and below).

(elem (table $t) (offset (i32.const 0)) funcref)
(elem (table $t) (offset (i32.const 0)) func $f $g)
(elem (table 0) (i32.const 0) func)
(elem (table 0x0) (i32.const 0) func $f $f)
(elem (table 0x000) (offset (i32.const 0)) func)
Expand All @@ -24,15 +36,41 @@
(elem (table $t) (i32.const 0) func $f $f)
(elem (table $t) (offset (i32.const 0)) func)
(elem (table $t) (offset (i32.const 0)) func $f $f)
(elem (offset (i32.const 0)))
(elem (offset (i32.const 0)) funcref (ref.func $f) (ref.null))
(elem (offset (i32.const 0)) func $f $f)
(elem (offset (i32.const 0)) $f $f)
(elem (i32.const 0))
(elem (i32.const 0) funcref (ref.func $f) (ref.null))
(elem (i32.const 0) func $f $f)
(elem (i32.const 0) $f $f)

(elem (i32.const 3) funcref (ref.func $f) (ref.func $g) (ref.func $f))
(elem (i32.const 3) funcref (ref.func $f) (ref.null) (ref.func $f))

(elem funcref (ref.func $f) (ref.func $g) (ref.func $f))
(elem funcref (ref.func $f) (ref.func $g) (ref.null))

(elem (table $t) (i32.const 3) funcref (ref.func $f) (ref.func $g) (ref.func $f))
(elem (table $t) (i32.const 3) funcref (ref.func $f) (ref.null) (ref.func $g))
(elem $a1 (table $t) (i32.const 0) funcref)
(elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
(elem $a3 (table $t) (i32.const 0) func)
(elem $a4 (table $t) (i32.const 0) func $f $g)
(elem $a5 (table $t) (i32.const 0) funcref)
(elem $a6 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
(elem $a7 (table $t) (i32.const 0) func)
(elem $a8 (table $t) (i32.const 0) func $f $g)
(elem $a9 (table $t) (offset (i32.const 0)) funcref)
(elem $a10 (table $t) (offset (i32.const 0)) func $f $g)
(elem $a11 (table 0) (i32.const 0) func)
(elem $a12 (table 0x0) (i32.const 0) func $f $f)
(elem $a13 (table 0x000) (offset (i32.const 0)) func)
(elem $a14 (table 0) (offset (i32.const 0)) func $f $f)
(elem $a15 (table $t) (i32.const 0) func)
(elem $a16 (table $t) (i32.const 0) func $f $f)
(elem $a17 (table $t) (offset (i32.const 0)) func)
(elem $a18 (table $t) (offset (i32.const 0)) func $f $f)
(elem $a19 (offset (i32.const 0)))
(elem $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null))
(elem $a21 (offset (i32.const 0)) func $f $f)
(elem $a22 (offset (i32.const 0)) $f $f)
(elem $a23 (i32.const 0))
(elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null))
(elem $a25 (i32.const 0) func $f $f)
(elem $a26 (i32.const 0) $f $f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also here you add tests for active element segments with IDs which are the same as the tests above. What is the purpose of these tests? As far as I understand, you cannot even use active elements by ID. Can you add a comment which explains the idea behind these tests, and how they are supposed to increase coverage?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like above, this is purely a syntax test, see heading.

Active elements can be used by ids, but behave like a dropped segment, i.e., trap in most cases.

)

(module
Expand Down
4 changes: 2 additions & 2 deletions test/core/imports.wast
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@

(module
(import "spectest" "memory" (memory 1 2))
(data 0 (i32.const 10) "\10")
(data (memory 0) (i32.const 10) "\10")

(func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
)
Expand All @@ -392,7 +392,7 @@

(module
(memory (import "spectest" "memory") 1 2)
(data 0 (i32.const 10) "\10")
(data (memory 0) (i32.const 10) "\10")

(func (export "load") (param i32) (result i32) (i32.load (local.get 0)))
)
Expand Down