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

Commit d4bc208

Browse files
authored
[spec/interpreter/test] Allow nullref type externally (#66)
1 parent 303c942 commit d4bc208

File tree

16 files changed

+142
-35
lines changed

16 files changed

+142
-35
lines changed

document/core/appendix/index-types.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ Category Constructor
1515
(reserved) :math:`\hex{7B}` .. :math:`\hex{71}`
1616
:ref:`Reference type <syntax-reftype>` |FUNCREF| :math:`\hex{70}` (-16 as |Bs7|)
1717
:ref:`Reference type <syntax-reftype>` |ANYREF| :math:`\hex{6F}` (-17 as |Bs7|)
18-
(reserved) :math:`\hex{6E}` .. :math:`\hex{61}`
18+
:ref:`Reference type <syntax-reftype>` |NULLREF| :math:`\hex{6E}` (-18 as |Bs7|)
19+
(reserved) :math:`\hex{6D}` .. :math:`\hex{61}`
1920
:ref:`Function type <syntax-functype>` :math:`[\valtype^\ast] \to [\valtype^\ast]` :math:`\hex{60}` (-32 as |Bs7|)
2021
(reserved) :math:`\hex{5F}` .. :math:`\hex{41}`
2122
:ref:`Result type <syntax-resulttype>` :math:`[\epsilon]` :math:`\hex{40}` (-64 as |Bs7|)

document/core/binary/types.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,10 @@ Reference Types
4242
\begin{array}{llclll@{\qquad\qquad}l}
4343
\production{reference type} & \Breftype &::=&
4444
\hex{70} &\Rightarrow& \FUNCREF \\ &&|&
45-
\hex{6F} &\Rightarrow& \ANYREF \\
45+
\hex{6F} &\Rightarrow& \ANYREF \\ &&|&
46+
\hex{6E} &\Rightarrow& \NULLREF \\
4647
\end{array}
4748
48-
.. note::
49-
The type :math:`\NULLREF` cannot occur in a module.
50-
5149
5250
.. index:: value type, number type, reference type
5351
pair: binary format; value type

document/core/syntax/types.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ The type |FUNCREF| denotes the infinite union of all references to :ref:`functio
6363

6464
The type |NULLREF| only contains a single value: the :ref:`null <syntax-ref.null>` reference.
6565
It is a :ref:`subtype <match-reftype>` of all other reference types.
66-
By virtue of being representable in neither the :ref:`binary format <binary-reftype>` nor the :ref:`text format <text-reftype>`, the |NULLREF| type cannot be used in a program;
67-
it only occurs during :ref:`validation <valid>`.
6866

6967
.. note::
7068
Future versions of WebAssembly may include reference types that do not include null and hence are not supertypes of |NULLREF|.

document/core/text/types.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ Reference Types
3333
\begin{array}{llcll@{\qquad\qquad}l}
3434
\production{reference type} & \Treftype &::=&
3535
\text{anyref} &\Rightarrow& \ANYREF \\ &&|&
36-
\text{funcref} &\Rightarrow& \FUNCREF \\
36+
\text{funcref} &\Rightarrow& \FUNCREF \\ &&|&
37+
\text{nullref} &\Rightarrow& \NULLREF \\
3738
\end{array}
3839
3940

document/js-api/index.bs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ urlPrefix: https://webassembly.github.io/spec/core/; spec: WebAssembly; type: df
152152
url: syntax/types.html#syntax-reftype
153153
text: anyref
154154
text: funcref
155+
text: nullref
155156
text: function element; url: exec/runtime.html#syntax-funcelem
156157
text: import component; url: syntax/modules.html#imports
157158
text: external value; url: exec/runtime.html#syntax-externval
@@ -704,6 +705,7 @@ Immediately after a WebAssembly [=memory.grow=] instruction executes, perform th
704705

705706
<pre class="idl">
706707
enum TableKind {
708+
"nullref",
707709
"anyref",
708710
"anyfunc",
709711
// Note: More values may be added in future iterations,
@@ -868,6 +870,10 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
868870
1. If |s| equals "i64", return [=𝗂𝟨𝟦=].
869871
1. If |s| equals "f32", return [=𝖿𝟥𝟤=].
870872
1. If |s| equals "f64", return [=𝖿𝟨𝟦=].
873+
1. If |s| equals "anyref", return [=anyref=].
874+
1. If |s| equals "funcref", return [=funcref=].
875+
1. If |s| equals "nullref", return [=nullref=].
876+
1. Assert: This step is not reached.
871877
</div>
872878

873879
<div algorithm>
@@ -876,7 +882,7 @@ which can be simultaneously referenced by multiple {{Instance}} objects. Each
876882
1. If |valuetype| equals [=𝗂𝟨𝟦=], return [=𝗂𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0.
877883
1. If |valuetype| equals [=𝖿𝟥𝟤=], return [=𝖿𝟥𝟤.𝖼𝗈𝗇𝗌𝗍=] 0.
878884
1. If |valuetype| equals [=𝖿𝟨𝟦=], return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] 0.
879-
1. Assert: This step is not reached.
885+
1. Else, return [=ref.null=].
880886
</div>
881887

882888
<div algorithm>
@@ -1063,11 +1069,14 @@ The algorithm <dfn>ToWebAssemblyValue</dfn>(|v|, |type|, |error|) coerces a Java
10631069
1. If |type| is [=𝖿𝟨𝟦=],
10641070
1. Let |f64| be ? [=ToNumber=](|v|).
10651071
1. Return [=𝖿𝟨𝟦.𝖼𝗈𝗇𝗌𝗍=] |f64|.
1072+
1. Assert: |type| is a reference type.
10661073
1. If |type| is [=anyref=],
1067-
1. Return the result of [=allocating a host address=] for |v|.
1074+
1. Do nothing.
10681075
1. If |type| is [=funcref=],
10691076
1. If |v| is not an [=Exported function=] or null, throw |error|.
1070-
1. Return the result of [=allocating a host address=] for |v|.
1077+
1. If |type| is [=nullref=],
1078+
1. If |v| is not null, throw |error|.
1079+
1. Return the result of [=allocating a host address=] for |v|.
10711080

10721081
</div>
10731082

interpreter/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ align: align=(1|2|4|8|...)
184184
cvtop: trunc | extend | wrap | ...
185185
186186
num_type: i32 | i64 | f32 | f64
187-
ref_type: anyref | funcref
187+
ref_type: anyref | funcref | nullref
188188
val_type: num_type | ref_type
189189
block_type : ( result <val_type>* )*
190190
func_type: ( type <var> )? <param>* <result>*

interpreter/binary/decode.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ let ref_type s =
145145
match vs7 s with
146146
| -0x10 -> FuncRefType
147147
| -0x11 -> AnyRefType
148+
| -0x12 -> NullRefType
148149
| _ -> error s (pos s - 1) "invalid reference type"
149150

150151
let value_type s =

interpreter/binary/encode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ let encode m =
9999
let ref_type = function
100100
| FuncRefType -> vs7 (-0x10)
101101
| AnyRefType -> vs7 (-0x11)
102-
| NullRefType -> assert false
102+
| NullRefType -> vs7 (-0x12)
103103

104104
let value_type = function
105105
| NumType t -> num_type t

interpreter/text/lexer.mll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ rule token = parse
162162

163163
| "anyref" { ANYREF }
164164
| "funcref" { FUNCREF }
165+
| "nullref" { NULLREF }
165166
| (nxx as t) { NUM_TYPE (num_type t) }
166167
| "mut" { MUT }
167168

interpreter/text/parser.mly

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ let inline_type_explicit (c : context) x ft at =
147147

148148
%token LPAR RPAR
149149
%token NAT INT FLOAT STRING VAR
150-
%token ANYREF FUNCREF NUM_TYPE MUT
150+
%token ANYREF NULLREF FUNCREF NUM_TYPE MUT
151151
%token UNREACHABLE NOP DROP SELECT
152152
%token BLOCK END IF THEN ELSE LOOP BR BR_IF BR_TABLE
153153
%token CALL CALL_INDIRECT RETURN
@@ -209,6 +209,7 @@ string_list :
209209
ref_type :
210210
| ANYREF { AnyRefType }
211211
| FUNCREF { FuncRefType }
212+
| NULLREF { NullRefType }
212213

213214
value_type :
214215
| NUM_TYPE { NumType $1 }

0 commit comments

Comments
 (0)