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

Commit 37e44c9

Browse files
authored
Update ref.null encoding after subtyping change (#149)
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`.
1 parent b4637e9 commit 37e44c9

File tree

9 files changed

+21
-18
lines changed

9 files changed

+21
-18
lines changed

document/core/binary/modules.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
343343
\production{element kind} & \Belemkind &::=&
344344
\hex{00} &\Rightarrow& \FUNCREF \\
345345
\production{element expression} & \Belemexpr &::=&
346-
\hex{D0}~\hex{0B} &\Rightarrow& \REFNULL~\END \\ &&|&
346+
\hex{D0}~\hex{70}~\hex{0B} &\Rightarrow& \REFNULL~\END \\ &&|&
347347
\hex{D2}~x{:}\Bfuncidx~\hex{0B} &\Rightarrow& (\REFFUNC~x)~\END \\
348348
\end{array}
349349

document/core/text/modules.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ Element segments allow for an optional :ref:`table index <text-tableidx>` to ide
503503
\production{element list} & \Telemlist &::=&
504504
et{:}\Telemtype~~y^\ast{:}\Tvec(\Telemexpr_I) \qquad\Rightarrow\quad ( \ETYPE~et, \EINIT~y^\ast ) \\
505505
\production{element expression} & \Telemexpr &::=&
506-
\text{(}~\text{ref.null}~\text{)} \\ &&|&
506+
\text{(}~\text{ref.null}~~\text{func}~\text{)} \\ &&|&
507507
\text{(}~\text{ref.func}~~\Tfuncidx_I~\text{)} \\
508508
\production{table use} & \Ttableuse_I &::=&
509509
\text{(}~\text{table}~~x{:}\Ttableidx_I ~\text{)}

interpreter/binary/decode.ml

+4-1
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,10 @@ let elem_kind s =
636636

637637
let elem_expr s =
638638
match u8 s with
639-
| 0xd0 -> end_ s; ref_null
639+
| 0xd0 ->
640+
expect 0x70 s "funcref expected";
641+
end_ s;
642+
ref_null
640643
| 0xd2 ->
641644
let x = at var s in
642645
end_ s;

interpreter/binary/encode.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ let encode m =
482482

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

488488
let elem_index e =

interpreter/text/arrange.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ let elem_index el =
307307

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

313313
let segment_mode category mode =

interpreter/text/parser.mly

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ elem_kind :
591591
| FUNC { FuncRefType }
592592
593593
elem_expr :
594-
| LPAR REF_NULL RPAR { let at = at () in fun c -> ref_null @@ at }
594+
| LPAR REF_NULL elem_kind RPAR { let at = at () in fun c -> ref_null @@ at }
595595
| LPAR REF_FUNC var RPAR { let at = at () in fun c -> ref_func ($3 c func) @@ at }
596596
597597
elem_expr_list :

test/core/binary.wast

+2-2
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,10 @@
809809

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

812-
"\09\06\01" ;; Element section with one segment
812+
"\09\07\01" ;; Element section with one segment
813813
"\05\70" ;; Passive, funcref
814814
"\01" ;; 1 element
815-
"\d0\0b" ;; ref.null, end
815+
"\d0\70\0b" ;; ref.null, end
816816

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

test/core/bulk.wast

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
(module
77
(table 3 funcref)
8-
(elem funcref (ref.func 0) (ref.null) (ref.func 1))
8+
(elem funcref (ref.func 0) (ref.null func) (ref.func 1))
99
(func)
1010
(func))
1111

test/core/elem.wast

+9-9
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88

99
;; Passive
1010
(elem funcref)
11-
(elem funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
11+
(elem funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
1212
(elem func)
1313
(elem func $f $f $g $g)
1414

1515
(elem $p1 funcref)
16-
(elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null) (ref.func $g))
16+
(elem $p2 funcref (ref.func $f) (ref.func $f) (ref.null func) (ref.func $g))
1717
(elem $p3 func)
1818
(elem $p4 func $f $f $g $g)
1919

2020
;; Active
2121
(elem (table $t) (i32.const 0) funcref)
22-
(elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
22+
(elem (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
2323
(elem (table $t) (i32.const 0) func)
2424
(elem (table $t) (i32.const 0) func $f $g)
2525
(elem (table $t) (offset (i32.const 0)) funcref)
@@ -33,16 +33,16 @@
3333
(elem (table $t) (offset (i32.const 0)) func)
3434
(elem (table $t) (offset (i32.const 0)) func $f $f)
3535
(elem (offset (i32.const 0)))
36-
(elem (offset (i32.const 0)) funcref (ref.func $f) (ref.null))
36+
(elem (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
3737
(elem (offset (i32.const 0)) func $f $f)
3838
(elem (offset (i32.const 0)) $f $f)
3939
(elem (i32.const 0))
40-
(elem (i32.const 0) funcref (ref.func $f) (ref.null))
40+
(elem (i32.const 0) funcref (ref.func $f) (ref.null func))
4141
(elem (i32.const 0) func $f $f)
4242
(elem (i32.const 0) $f $f)
4343

4444
(elem $a1 (table $t) (i32.const 0) funcref)
45-
(elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null))
45+
(elem $a2 (table $t) (i32.const 0) funcref (ref.func $f) (ref.null func))
4646
(elem $a3 (table $t) (i32.const 0) func)
4747
(elem $a4 (table $t) (i32.const 0) func $f $g)
4848
(elem $a9 (table $t) (offset (i32.const 0)) funcref)
@@ -56,11 +56,11 @@
5656
(elem $a17 (table $t) (offset (i32.const 0)) func)
5757
(elem $a18 (table $t) (offset (i32.const 0)) func $f $f)
5858
(elem $a19 (offset (i32.const 0)))
59-
(elem $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null))
59+
(elem $a20 (offset (i32.const 0)) funcref (ref.func $f) (ref.null func))
6060
(elem $a21 (offset (i32.const 0)) func $f $f)
6161
(elem $a22 (offset (i32.const 0)) $f $f)
6262
(elem $a23 (i32.const 0))
63-
(elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null))
63+
(elem $a24 (i32.const 0) funcref (ref.func $f) (ref.null func))
6464
(elem $a25 (i32.const 0) func $f $f)
6565
(elem $a26 (i32.const 0) $f $f)
6666
)
@@ -69,7 +69,7 @@
6969
(func $f)
7070
(func $g)
7171

72-
(table $t funcref (elem (ref.func $f) (ref.null) (ref.func $g)))
72+
(table $t funcref (elem (ref.func $f) (ref.null func) (ref.func $g)))
7373
)
7474
;; Basic use
7575

0 commit comments

Comments
 (0)