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

Commit

Permalink
Update ref.null encoding after subtyping change
Browse files Browse the repository at this point in the history
Issue WebAssembly/reference-types#69 requires
that `ref.null` instructions include a reference type immediate. This
concept isn't present in the bulk-memory proposal, but the encoding is
(in element segment expressions).

This change updates the binary and text format, but not the syntax. This
is OK for now, since the only reference type allowed here is `funcref`.
  • Loading branch information
binji committed May 13, 2020
1 parent b4637e9 commit a0acf63
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion document/core/binary/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
\production{element kind} & \Belemkind &::=&
\hex{00} &\Rightarrow& \FUNCREF \\
\production{element expression} & \Belemexpr &::=&
\hex{D0}~\hex{0B} &\Rightarrow& \REFNULL~\END \\ &&|&
\hex{D0}~\hex{70}~\hex{0B} &\Rightarrow& \REFNULL~\END \\ &&|&
\hex{D2}~x{:}\Bfuncidx~\hex{0B} &\Rightarrow& (\REFFUNC~x)~\END \\
\end{array}
Expand Down
2 changes: 1 addition & 1 deletion document/core/text/modules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Element segments allow for an optional :ref:`table index <text-tableidx>` to ide
\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.null}~~\text{func}~\text{)} \\ &&|&
\text{(}~\text{ref.func}~~\Tfuncidx_I~\text{)} \\
\production{table use} & \Ttableuse_I &::=&
\text{(}~\text{table}~~x{:}\Ttableidx_I ~\text{)}
Expand Down
5 changes: 4 additions & 1 deletion interpreter/binary/decode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,10 @@ let elem_kind s =

let elem_expr s =
match u8 s with
| 0xd0 -> end_ s; ref_null
| 0xd0 ->
expect 0x70 s "funcref expected";
end_ s;
ref_null
| 0xd2 ->
let x = at var s in
end_ s;
Expand Down
2 changes: 1 addition & 1 deletion interpreter/binary/encode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ let encode m =

let elem_expr e =
match e.it with
| RefNull -> u8 0xd0; end_ ()
| RefNull -> u8 0xd0; u8 0x70; end_ ()
| RefFunc x -> u8 0xd2; var x; end_ ()

let elem_index e =
Expand Down
2 changes: 1 addition & 1 deletion interpreter/text/arrange.ml
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ let elem_index el =

let elem_expr el =
match el.it with
| RefNull -> Node ("ref.null", [])
| RefNull -> Node ("ref.null", [atom elem_kind FuncRefType])
| RefFunc x -> Node ("ref.func", [atom var x])

let segment_mode category mode =
Expand Down
2 changes: 1 addition & 1 deletion interpreter/text/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ elem_kind :
| FUNC { FuncRefType }
elem_expr :
| LPAR REF_NULL RPAR { let at = at () in fun c -> ref_null @@ at }
| LPAR REF_NULL elem_kind RPAR { let at = at () in fun c -> ref_null @@ at }
| LPAR REF_FUNC var RPAR { let at = at () in fun c -> ref_func ($3 c func) @@ at }
elem_expr_list :
Expand Down
4 changes: 2 additions & 2 deletions test/core/binary.wast
Original file line number Diff line number Diff line change
Expand Up @@ -809,10 +809,10 @@

"\05\03\01\00\00" ;; Memory section

"\09\06\01" ;; Element section with one segment
"\09\07\01" ;; Element section with one segment
"\05\70" ;; Passive, funcref
"\01" ;; 1 element
"\d0\0b" ;; ref.null, end
"\d0\70\0b" ;; ref.null, end

"\0a\04\01" ;; Code section

Expand Down
2 changes: 1 addition & 1 deletion test/core/bulk.wast
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

(module
(table 3 funcref)
(elem funcref (ref.func 0) (ref.null) (ref.func 1))
(elem funcref (ref.func 0) (ref.null func) (ref.func 1))
(func)
(func))

Expand Down
18 changes: 9 additions & 9 deletions test/core/elem.wast
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

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

(elem $p1 funcref)
(elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
(elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null func) (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) funcref (ref.func $f) (ref.null func))
(elem (table $t) (i32.const 0) func)
(elem (table $t) (i32.const 0) func $f $g)
(elem (table $t) (offset (i32.const 0)) funcref)
Expand All @@ -33,16 +33,16 @@
(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)) funcref (ref.func $f) (ref.null func))
(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) funcref (ref.func $f) (ref.null func))
(elem (i32.const 0) func $f $f)
(elem (i32.const 0) $f $f)

(elem $a1 (table $t) (i32.const 0) funcref)
(elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
(elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
(elem $a3 (table $t) (i32.const 0) func)
(elem $a4 (table $t) (i32.const 0) func $f $g)
(elem $a9 (table $t) (offset (i32.const 0)) funcref)
Expand All @@ -56,11 +56,11 @@
(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 $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
(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 $a24 (i32.const 0) funcref (ref.func $f) (ref.null func))
(elem $a25 (i32.const 0) func $f $f)
(elem $a26 (i32.const 0) $f $f)
)
Expand All @@ -69,7 +69,7 @@
(func $f)
(func $g)

(table $t funcref (elem (ref.func $f) (ref.null) (ref.func $g)))
(table $t funcref (elem (ref.func $f) (ref.null func) (ref.func $g)))
)
;; Basic use

Expand Down

0 comments on commit a0acf63

Please sign in to comment.