Skip to content

Commit 6c0beae

Browse files
authored
Remove type annotation on ref.is_null (#100)
1 parent f18a4eb commit 6c0beae

File tree

21 files changed

+36
-31
lines changed

21 files changed

+36
-31
lines changed

document/core/appendix/index-instructions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ Instruction Binary Opcode Type
221221
(reserved) :math:`\hex{CE}`
222222
(reserved) :math:`\hex{CF}`
223223
:math:`\REFNULL~t` :math:`\hex{D0}` :math:`[] \to [t]` :ref:`validation <valid-ref.null>` :ref:`execution <exec-ref.null>`
224-
:math:`\REFISNULL~t` :math:`\hex{D1}` :math:`[t] \to [\I32]` :ref:`validation <valid-ref.is_null>` :ref:`execution <exec-ref.is_null>`
224+
:math:`\REFISNULL` :math:`\hex{D1}` :math:`[t] \to [\I32]` :ref:`validation <valid-ref.is_null>` :ref:`execution <exec-ref.is_null>`
225225
:math:`\REFFUNC~x` :math:`\hex{D2}` :math:`[] \to [\FUNCREF]` :ref:`validation <valid-ref.func>` :ref:`execution <exec-ref.func>`
226226
(reserved) :math:`\hex{D3}`
227227
(reserved) :math:`\hex{D4}`

document/core/binary/instructions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Reference Instructions
9191
\begin{array}{llclll}
9292
\production{instruction} & \Binstr &::=& \dots \\ &&|&
9393
\hex{D0}~~t{:}\Breftype &\Rightarrow& \REFNULL~t \\ &&|&
94-
\hex{D1}~~t{:}\Breftype &\Rightarrow& \REFISNULL~t \\ &&|&
94+
\hex{D1} &\Rightarrow& \REFISNULL \\ &&|&
9595
\hex{D2}~~x{:}\Bfuncidx &\Rightarrow& \REFFUNC~x \\
9696
\end{array}
9797

document/core/exec/instructions.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ Reference Instructions
203203

204204
.. _exec-ref.is_null:
205205

206-
:math:`\REFISNULL~t`
207-
....................
206+
:math:`\REFISNULL`
207+
..................
208208

209209
1. Assert: due to :ref:`validation <valid-ref.is_null>`, a :ref:`reference value <syntax-ref>` is on the top of the stack.
210210

@@ -220,9 +220,9 @@ Reference Instructions
220220

221221
.. math::
222222
\begin{array}{lcl@{\qquad}l}
223-
\val~\REFISNULL~t &\stepto& \I32.\CONST~1
223+
\val~\REFISNULL &\stepto& \I32.\CONST~1
224224
& (\iff \val = \REFNULL~t) \\
225-
\val~\REFISNULL~t &\stepto& \I32.\CONST~0
225+
\val~\REFISNULL &\stepto& \I32.\CONST~0
226226
& (\otherwise) \\
227227
\end{array}
228228

document/core/syntax/instructions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ Instructions in this group are concerned with accessing :ref:`references <syntax
187187
\production{instruction} & \instr &::=&
188188
\dots \\&&|&
189189
\REFNULL~\reftype \\&&|&
190-
\REFISNULL~\reftype \\&&|&
190+
\REFISNULL \\&&|&
191191
\REFFUNC~\funcidx \\
192192
\end{array}
193193

document/core/text/instructions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Reference Instructions
159159
\begin{array}{llclll}
160160
\production{instruction} & \Tplaininstr_I &::=& \dots \\ &&|&
161161
\text{ref.null}~~t{:}\Trefedtype &\Rightarrow& \REFNULL~t \\ &&|&
162-
\text{ref.is\_null}~~t{:}\Trefedtype &\Rightarrow& \REFISNULL~t \\ &&|&
162+
\text{ref.is\_null} &\Rightarrow& \REFISNULL \\ &&|&
163163
\text{ref.func}~~x{:}\Tfuncidx &\Rightarrow& \REFFUNC~x \\ &&|&
164164
\end{array}
165165

document/core/valid/instructions.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,16 @@ Reference Instructions
182182

183183
.. _valid-ref.is_null:
184184

185-
:math:`\REFISNULL~t`
186-
....................
185+
:math:`\REFISNULL`
186+
..................
187187

188-
* The instruction is valid with type :math:`[t] \to [\I32]`.
188+
* The instruction is valid with type :math:`[t] \to [\I32]`, for any :ref:`reference type <syntax-reftype>` :math:`t`.
189189

190190
.. math::
191191
\frac{
192+
t = \reftype
192193
}{
193-
C \vdashinstr \REFISNULL~t : [t] \to [\I32]
194+
C \vdashinstr \REFISNULL : [t] \to [\I32]
194195
}
195196
196197
.. _valid-ref.func:

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ let rec instr s =
453453
| 0xcc | 0xcd | 0xce | 0xcf as b -> illegal s pos b
454454

455455
| 0xd0 -> ref_null (ref_type s)
456-
| 0xd1 -> ref_is_null (ref_type s)
456+
| 0xd1 -> ref_is_null
457457
| 0xd2 -> ref_func (at var s)
458458

459459
| 0xfc as b1 ->

interpreter/binary/encode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ let encode m =
230230
| DataDrop x -> op 0xfc; op 0x09; var x
231231

232232
| RefNull t -> op 0xd0; ref_type t
233-
| RefIsNull t -> op 0xd1; ref_type t
233+
| RefIsNull -> op 0xd1
234234
| RefFunc x -> op 0xd2; var x
235235

236236
| Const {it = I32 c; _} -> op 0x41; vs32 c

interpreter/exec/eval.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ let rec step (c : config) : config =
427427
| RefNull t, vs' ->
428428
Ref (NullRef t) :: vs', []
429429

430-
| RefIsNull _, Ref r :: vs' ->
430+
| RefIsNull, Ref r :: vs' ->
431431
(match r with
432432
| NullRef _ ->
433433
Num (I32 1l) :: vs', []

interpreter/script/js.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ let assert_return ress ts at =
287287
Test (Values.I32 I32Op.Eqz) @@ at;
288288
BrIf (0l @@ at) @@ at ]
289289
| LitResult {it = Values.Ref (Values.NullRef t); _} ->
290-
[ RefIsNull t @@ at;
290+
[ RefIsNull @@ at;
291291
Test (Values.I32 I32Op.Eqz) @@ at;
292292
BrIf (0l @@ at) @@ at ]
293293
| LitResult {it = Values.Ref (ExternRef n); _} ->

interpreter/syntax/ast.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ and instr' =
106106
| MemoryInit of var (* initialize memory range from segment *)
107107
| DataDrop of var (* drop passive data segment *)
108108
| RefNull of ref_type (* null reference *)
109-
| RefIsNull of ref_type (* null test *)
109+
| RefIsNull (* null test *)
110110
| RefFunc of var (* function reference *)
111111
| Const of num (* constant *)
112112
| Test of testop (* numeric test *)

interpreter/syntax/free.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ let list free xs = List.fold_left union empty (List.map free xs)
6262
let rec instr (e : instr) =
6363
match e.it with
6464
| Unreachable | Nop | Drop | Select _ -> empty
65-
| RefNull _ | RefIsNull _ -> empty
65+
| RefNull _ | RefIsNull -> empty
6666
| RefFunc x -> funcs (var x)
6767
| Const _ | Test _ | Compare _ | Unary _ | Binary _ | Convert _ -> empty
6868
| Block (_, es) | Loop (_, es) -> block es

interpreter/syntax/operators.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ let f32_const n = Const (F32 n.it @@ n.at)
1010
let f64_const n = Const (F64 n.it @@ n.at)
1111
let ref_func x = RefFunc x
1212
let ref_null t = RefNull t
13-
let ref_is_null t = RefIsNull t
13+
let ref_is_null = RefIsNull
1414

1515
let unreachable = Unreachable
1616
let nop = Nop

interpreter/text/arrange.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ let rec instr e =
271271
| MemoryInit x -> "memory.init " ^ var x, []
272272
| DataDrop x -> "data.drop " ^ var x, []
273273
| RefNull t -> "ref.null", [Atom (refed_type t)]
274-
| RefIsNull t -> "ref.is_null", [Atom (refed_type t)]
274+
| RefIsNull -> "ref.is_null", []
275275
| RefFunc x -> "ref.func " ^ var x, []
276276
| Const n -> constop n ^ " " ^ num n, []
277277
| Test op -> testop op, []

interpreter/text/parser.mly

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ plain_instr :
376376
| MEMORY_INIT var { fun c -> memory_init ($2 c data) }
377377
| DATA_DROP var { fun c -> data_drop ($2 c data) }
378378
| REF_NULL ref_kind { fun c -> ref_null $2 }
379-
| REF_IS_NULL ref_kind { fun c -> ref_is_null $2 }
379+
| REF_IS_NULL { fun c -> ref_is_null }
380380
| REF_FUNC var { fun c -> ref_func ($2 c func) }
381381
| CONST num { fun c -> fst (num $1 $2) }
382382
| TEST { fun c -> $1 }

interpreter/valid/valid.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,12 @@ let rec check_instr (c : context) (e : instr) (s : infer_stack_type) : op_type =
360360
| RefNull t ->
361361
[] --> [RefType t]
362362

363-
| RefIsNull t ->
364-
[RefType t] --> [NumType I32Type]
363+
| RefIsNull ->
364+
let t = peek 1 s in
365+
require (match t with None -> true | Some t -> is_ref_type t) e.at
366+
("type mismatch: instruction requires reference type" ^
367+
" but stack has " ^ string_of_infer_type t);
368+
[t] -~> [Some (NumType I32Type)]
365369

366370
| RefFunc x ->
367371
let _ft = func c x in

test/core/ref_func.wast

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
(func $ff2)
2525

2626
(func (export "is_null-f") (result i32)
27-
(ref.is_null func (ref.func $f))
27+
(ref.is_null (ref.func $f))
2828
)
2929
(func (export "is_null-g") (result i32)
30-
(ref.is_null func (ref.func $g))
30+
(ref.is_null (ref.func $g))
3131
)
3232
(func (export "is_null-v") (result i32)
33-
(ref.is_null func (global.get $v))
33+
(ref.is_null (global.get $v))
3434
)
3535

3636
(func (export "set-f") (global.set $v (ref.func $f)))

test/core/ref_is_null.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
(module
22
(func $f1 (export "funcref") (param $x funcref) (result i32)
3-
(ref.is_null func (local.get $x))
3+
(ref.is_null (local.get $x))
44
)
55
(func $f2 (export "externref") (param $x externref) (result i32)
6-
(ref.is_null extern (local.get $x))
6+
(ref.is_null (local.get $x))
77
)
88

99
(table $t1 2 funcref)

test/core/table_get.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818

1919
(func (export "is_null-funcref") (param $i i32) (result i32)
20-
(ref.is_null func (call $f3 (local.get $i)))
20+
(ref.is_null (call $f3 (local.get $i)))
2121
)
2222
)
2323

test/core/table_grow.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
(block
9191
(loop
9292
(local.set 2 (table.get $t (local.get 0)))
93-
(br_if 1 (i32.eqz (ref.is_null func (local.get 2))))
93+
(br_if 1 (i32.eqz (ref.is_null (local.get 2))))
9494
(br_if 1 (i32.ge_u (local.get 0) (local.get 1)))
9595
(local.set 0 (i32.add (local.get 0) (i32.const 1)))
9696
(br_if 0 (i32.le_u (local.get 0) (local.get 1)))

test/core/table_set.wast

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
)
2323

2424
(func (export "is_null-funcref") (param $i i32) (result i32)
25-
(ref.is_null func (call $f3 (local.get $i)))
25+
(ref.is_null (call $f3 (local.get $i)))
2626
)
2727
)
2828

0 commit comments

Comments
 (0)