Skip to content

Commit 42d559f

Browse files
committed
Merge remote-tracking branch 'upstream/main'
2 parents 9477928 + a5f4a85 commit 42d559f

File tree

26 files changed

+2374
-2260
lines changed

26 files changed

+2374
-2260
lines changed

document/core/appendix/index-types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Category Constructor
1717
:ref:`Packed type <syntax-packtype>` |I8| :math:`\hex{78}` (-8 as |Bs7|)
1818
:ref:`Packed type <syntax-packtype>` |I16| :math:`\hex{77}` (-9 as |Bs7|)
1919
(reserved) :math:`\hex{78}` .. :math:`\hex{75}`
20-
:ref:`Heap type <syntax-heaptype>` |NOEXN| :math:`\hex{74}` (-14 as |Bs7|)
20+
:ref:`Heap type <syntax-heaptype>` |NOEXN| :math:`\hex{74}` (-12 as |Bs7|)
2121
:ref:`Heap type <syntax-heaptype>` |NOFUNC| :math:`\hex{73}` (-13 as |Bs7|)
2222
:ref:`Heap type <syntax-heaptype>` |NOEXTERN| :math:`\hex{72}` (-14 as |Bs7|)
2323
:ref:`Heap type <syntax-heaptype>` |NONE| :math:`\hex{71}` (-15 as |Bs7|)

document/core/binary/instructions.rst

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ Control Instructions
5454
.. _binary-br:
5555
.. _binary-br_if:
5656
.. _binary-br_table:
57+
.. _binary-br_on_null:
58+
.. _binary-br_on_non_null:
59+
.. _binary-br_on_cast:
60+
.. _binary-br_on_cast_fail:
5761
.. _binary-return:
5862
.. _binary-call:
5963
.. _binary-call_ref:
@@ -65,8 +69,10 @@ Control Instructions
6569
.. _binary-throw_ref:
6670
.. _binary-try_table:
6771
.. _binary-catch:
72+
.. _binary-castop:
6873

69-
$${grammar: Bblocktype {Binstr/block Binstr/control} Bcatch}
74+
$${grammar: Bblocktype {Binstr/block Binstr/control} Bcatch Bcastop}
75+
$${syntax-ignore: castop}
7076

7177
.. note::
7278
The ${:ELSE} opcode ${:0x05} in the encoding of an ${:IF} instruction can be omitted if the following instruction sequence is empty.
@@ -140,10 +146,6 @@ $${grammar: Bmemarg Binstr/memory}
140146
.. index:: reference instruction
141147
pair: binary format; instruction
142148
.. _binary-instr-ref:
143-
.. _binary-br_on_null:
144-
.. _binary-br_on_non_null:
145-
.. _binary-br_on_cast:
146-
.. _binary-br_on_cast_fail:
147149

148150
Reference Instructions
149151
~~~~~~~~~~~~~~~~~~~~~~
@@ -154,6 +156,24 @@ Generic :ref:`reference instructions <syntax-instr-ref>` are represented by sing
154156
.. _binary-ref.func:
155157
.. _binary-ref.is_null:
156158
.. _binary-ref.as_non_null:
159+
.. _binary-ref.test:
160+
.. _binary-ref.cast:
161+
162+
$${grammar: {Binstr/ref}}
163+
164+
165+
.. index:: aggregate instruction
166+
pair: binary format; instruction
167+
.. _binary-instr-aggr:
168+
169+
Aggregate Instructions
170+
~~~~~~~~~~~~~~~~~~~~~~
171+
172+
:ref:`Aggregate instructions <syntax-instr-aggr>` all use a prefix.
173+
174+
.. _binary-ref.i31:
175+
.. _binary-i31.get_s:
176+
.. _binary-i31.get_u:
157177
.. _binary-struct.new:
158178
.. _binary-struct.new_default:
159179
.. _binary-struct.get:
@@ -174,17 +194,10 @@ Generic :ref:`reference instructions <syntax-instr-ref>` are represented by sing
174194
.. _binary-array.copy:
175195
.. _binary-array.init_data:
176196
.. _binary-array.init_elem:
177-
.. _binary-ref.i31:
178-
.. _binary-i31.get_s:
179-
.. _binary-i31.get_u:
180-
.. _binary-ref.test:
181-
.. _binary-ref.cast:
182197
.. _binary-any.convert_extern:
183198
.. _binary-extern.convert_any:
184-
.. _binary-castop:
185199

186-
$${grammar: {Binstr/ref Binstr/struct Binstr/array Binstr/cast Binstr/extern Binstr/i31} Bcastop}
187-
$${syntax-ignore: castop}
200+
$${grammar: {Binstr/struct Binstr/array Binstr/extern Binstr/i31}}
188201

189202

190203
.. index:: numeric instruction
@@ -384,31 +397,6 @@ $${grammar: {
384397

385398
$${grammar: {Binstr/vec-cvt}}
386399

387-
.. math::
388-
\begin{array}{llclll}
389-
\phantom{\production{instruction}} & \phantom{\Binstr} &\phantom{::=}& \phantom{\dots} && \phantom{vechaslongerinstructionnames} \\[-2ex] &&|&
390-
\hex{FD}~~256{:}\Bu32 &\Rightarrow& \I16X8.\VRELAXEDSWIZZLE \\ &&|&
391-
\hex{FD}~~257{:}\Bu32 &\Rightarrow& \I32X4.\VRELAXEDTRUNC\K{\_f32x4\_s} \\ &&|&
392-
\hex{FD}~~258{:}\Bu32 &\Rightarrow& \I32X4.\VRELAXEDTRUNC\K{\_f32x4\_u} \\ &&|&
393-
\hex{FD}~~259{:}\Bu32 &\Rightarrow& \I32X4.\VRELAXEDTRUNC\K{\_f32x4\_s\_zero} \\ &&|&
394-
\hex{FD}~~260{:}\Bu32 &\Rightarrow& \I32X4.\VRELAXEDTRUNC\K{\_f32x4\_u\_zero} \\ &&|&
395-
\hex{FD}~~261{:}\Bu32 &\Rightarrow& \F32X4.\VRELAXEDMADD \\ &&|&
396-
\hex{FD}~~262{:}\Bu32 &\Rightarrow& \F32X4.\VRELAXEDNMADD \\ &&|&
397-
\hex{FD}~~263{:}\Bu32 &\Rightarrow& \F64X2.\VRELAXEDMADD \\ &&|&
398-
\hex{FD}~~264{:}\Bu32 &\Rightarrow& \F64X2.\VRELAXEDNMADD \\ &&|&
399-
\hex{FD}~~265{:}\Bu32 &\Rightarrow& \I8X16.\VRELAXEDLANESELECT \\ &&|&
400-
\hex{FD}~~266{:}\Bu32 &\Rightarrow& \I16X8.\VRELAXEDLANESELECT \\ &&|&
401-
\hex{FD}~~267{:}\Bu32 &\Rightarrow& \I32X4.\VRELAXEDLANESELECT \\ &&|&
402-
\hex{FD}~~268{:}\Bu32 &\Rightarrow& \I64X2.\VRELAXEDLANESELECT \\ &&|&
403-
\hex{FD}~~269{:}\Bu32 &\Rightarrow& \F32X4.\VRELAXEDMIN \\ &&|&
404-
\hex{FD}~~270{:}\Bu32 &\Rightarrow& \F32X4.\VRELAXEDMAX \\ &&|&
405-
\hex{FD}~~271{:}\Bu32 &\Rightarrow& \F64X2.\VRELAXEDMIN \\ &&|&
406-
\hex{FD}~~272{:}\Bu32 &\Rightarrow& \F64X2.\VRELAXEDMAX \\ &&|&
407-
\hex{FD}~~273{:}\Bu32 &\Rightarrow& \I16X8.\VRELAXEDQ15MULR\K{\_s} \\ &&|&
408-
\hex{FD}~~274{:}\Bu32 &\Rightarrow& \I16X8.\VRELAXEDDOT\K{\_i8x16\_i7x16\_s} \\ &&|&
409-
\hex{FD}~~275{:}\Bu32 &\Rightarrow& \I16X8.\VRELAXEDDOT\K{\_i8x16\_i7x16\_add\_s} \\
410-
\end{array}
411-
412400

413401
.. index:: expression
414402
pair: binary format; expression

document/core/syntax/instructions.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ If missing, the operands must be of :ref:`numeric <syntax-numtype>` or :ref:`vec
6161
.. _syntax-br_on_non_null:
6262
.. _syntax-br_on_cast:
6363
.. _syntax-br_on_cast_fail:
64-
.. _syntax-return:
6564
.. _syntax-call:
65+
.. _syntax-call_ref:
6666
.. _syntax-call_indirect:
67-
.. _syntax-instrs:
68-
.. _syntax-instr-control:
67+
.. _syntax-return:
68+
.. _syntax-return_call:
69+
.. _syntax-return_call_ref:
70+
.. _syntax-return_call_indirect:
6971
.. _syntax-throw:
7072
.. _syntax-throw_ref:
7173
.. _syntax-try_table:
7274
.. _syntax-catch:
75+
.. _syntax-instrs:
76+
.. _syntax-instr-control:
7377
.. _exception:
7478

7579
Control Instructions
@@ -284,6 +288,7 @@ while the latter performs a downcast and :ref:`traps <trap>` if the operand's ty
284288
.. _syntax-i31.get_u:
285289
.. _syntax-any.convert_extern:
286290
.. _syntax-extern.convert_any:
291+
.. _syntax-instr-aggr:
287292
.. _syntax-instr-struct:
288293
.. _syntax-instr-array:
289294
.. _syntax-instr-i31:

document/core/text/instructions.rst

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,22 @@ Reference Instructions
201201
.. _text-ref.func:
202202
.. _text-ref.is_null:
203203
.. _text-ref.as_non_null:
204+
.. _text-ref.test:
205+
.. _text-ref.cast:
206+
207+
$${grammar: {Tplaininstr_/ref}}
208+
209+
210+
.. index:: aggregate instruction
211+
pair: text format; instruction
212+
.. _text-instr-aggr:
213+
214+
Aggregate Instructions
215+
~~~~~~~~~~~~~~~~~~~~~~
216+
217+
.. _text-ref.i31:
218+
.. _text-i31.get_s:
219+
.. _text-i31.get_u:
204220
.. _text-struct.new:
205221
.. _text-struct.new_default:
206222
.. _text-struct.get:
@@ -221,15 +237,10 @@ Reference Instructions
221237
.. _text-array.copy:
222238
.. _text-array.init_data:
223239
.. _text-array.init_elem:
224-
.. _text-ref.i31:
225-
.. _text-i31.get_s:
226-
.. _text-i31.get_u:
227-
.. _text-ref.test:
228-
.. _text-ref.cast:
229240
.. _text-any.convert_extern:
230241
.. _text-extern.convert_any:
231242

232-
$${grammar: {Tplaininstr_/ref Tplaininstr_/i31 Tplaininstr_/struct Tplaininstr_/array Tplaininstr_/extern}}
243+
$${grammar: {Tplaininstr_/i31 Tplaininstr_/struct Tplaininstr_/array Tplaininstr_/extern}}
233244

234245

235246
.. index:: numeric instruction

document/core/valid/matching.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Limits
167167

168168
$${rule-prose: Limits_sub}
169169

170-
$${rule: Limits_sub}
170+
$${rule: {Limits_sub/*}}
171171
172172

173173
.. index:: tag type

interpreter/valid/valid.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
904904
require (i < Lib.List32.length fts) e.at
905905
("unknown field " ^ I32.to_string_u i);
906906
let FieldT (mut, st) = Lib.List32.nth fts i in
907-
require (mut == Var) e.at "field is immutable";
907+
require (mut == Var) e.at "immutable field";
908908
let t = unpacked_storagetype st in
909909
[RefT (Null, UseHT (Inexact, Def (type_ c x))); t] --> [], []
910910

@@ -946,7 +946,7 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
946946

947947
| ArraySet x ->
948948
let FieldT (mut, st) = array_type c x in
949-
require (mut == Var) e.at "array is immutable";
949+
require (mut == Var) e.at "immutable array";
950950
let t = unpacked_storagetype st in
951951
[RefT (Null, UseHT (Inexact, Def (type_ c x))); NumT I32T; t] --> [], []
952952

@@ -956,19 +956,19 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
956956
| ArrayCopy (x, y) ->
957957
let FieldT (mutd, std) = array_type c x in
958958
let FieldT (_muts, sts) = array_type c y in
959-
require (mutd = Var) e.at "array is immutable";
959+
require (mutd = Var) e.at "immutable array";
960960
require (match_storagetype c.types sts std) e.at "array types do not match";
961961
[RefT (Null, UseHT (Inexact, Def (type_ c x))); NumT I32T; RefT (Null, UseHT (Inexact, Def (type_ c y))); NumT I32T; NumT I32T] --> [], []
962962

963963
| ArrayFill x ->
964964
let FieldT (mut, st) = array_type c x in
965-
require (mut = Var) e.at "array is immutable";
965+
require (mut = Var) e.at "immutable array";
966966
let t = unpacked_storagetype st in
967967
[RefT (Null, UseHT (Inexact, Def (type_ c x))); NumT I32T; t; NumT I32T] --> [], []
968968

969969
| ArrayInitData (x, y) ->
970970
let FieldT (mut, st) = array_type c x in
971-
require (mut = Var) e.at "array is immutable";
971+
require (mut = Var) e.at "immutable array";
972972
let () = data c y in
973973
let t = unpacked_storagetype st in
974974
require (is_numtype t || is_vectype t) x.at
@@ -977,7 +977,7 @@ let rec check_instr (c : context) (e : instr) (s : infer_resulttype) : infer_ins
977977

978978
| ArrayInitElem (x, y) ->
979979
let FieldT (mut, st) = array_type c x in
980-
require (mut = Var) e.at "array is immutable";
980+
require (mut = Var) e.at "immutable array";
981981
let rt = elem c y in
982982
require (match_valtype c.types (RefT rt) (unpacked_storagetype st)) x.at
983983
("type mismatch: element segment's type " ^ string_of_reftype rt ^

specification/wasm-3.0/1.3-syntax.instructions.spectec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ syntax vcvtop__(Jnn_1 X M_1, Jnn_2 X M_2) =
165165
| EXTEND half sx hint(show EXTEND#_#%#_#%)
166166
-- if $lsizenn2(Jnn_2) = $(2 * $lsizenn1(Jnn_1))
167167
syntax vcvtop__(Jnn_1 X M_1, Fnn_2 X M_2) =
168-
| CONVERT half? sx hint(show CONVERT#_#%#_#%) hint(show CONVERT#_#%)
168+
| CONVERT half? sx hint(show CONVERT#_#%) hint(show CONVERT#_#%#_#%)
169169
-- if $sizenn2(Fnn_2) = $lsizenn1(Jnn_1) = `32 /\ half? = eps
170170
\/ $sizenn2(Fnn_2) = $(2 * $lsizenn1(Jnn_1)) /\ half? = LOW
171171
syntax vcvtop__(Fnn_1 X M_1, Jnn_2 X M_2) =
172-
| TRUNC_SAT sx zero? hint(show TRUNC_SAT#_#%#_#%) hint(show TRUNC_SAT#_#%)
172+
| TRUNC_SAT sx zero? hint(show TRUNC_SAT#_#%) hint(show TRUNC_SAT#_#%#_#%)
173173
-- if $sizenn1(Fnn_1) = $lsizenn2(Jnn_2) = `32 /\ zero? = eps
174174
\/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Jnn_2)) /\ zero? = ZERO
175-
| RELAXED_TRUNC sx zero? hint(show RELAXED_TRUNC#_#%#_#%) hint(show RELAXED_TRUNC#_#%)
175+
| RELAXED_TRUNC sx zero? hint(show RELAXED_TRUNC#_#%) hint(show RELAXED_TRUNC#_#%#_#%)
176176
-- if $sizenn1(Fnn_1) = $lsizenn2(Jnn_2) = `32 /\ zero? = eps
177177
\/ $sizenn1(Fnn_1) = $(2 * $lsizenn2(Jnn_2)) /\ zero? = ZERO
178178
syntax vcvtop__(Fnn_1 X M_1, Fnn_2 X M_2) =

specification/wasm-3.0/2.2-validation.subtyping.spectec

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,15 @@ relation Tabletype_sub: context |- tabletype <: tabletype hint(name "S-table"
196196
relation Externtype_sub: context |- externtype <: externtype hint(name "S-extern") hint(macro "%externtypematch")
197197

198198

199-
rule Limits_sub:
200-
C |- `[n_1 .. m_1] <: `[n_2 .. m_2]
199+
rule Limits_sub/max:
200+
C |- `[n_1 .. m_1] <: `[n_2 .. m_2?]
201201
-- if n_1 >= n_2
202-
-- if m_1 <= m_2
202+
-- (if m_1 <= m_2)?
203+
204+
rule Limits_sub/eps:
205+
C |- `[n_1 .. eps] <: `[n_2 .. eps]
206+
-- if n_1 >= n_2
207+
203208

204209
rule Tagtype_sub:
205210
C |- deftype_1 <: deftype_2

specification/wasm-3.0/5.3-binary.instructions.spectec

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ grammar Binstr/parametric : instr =
1515

1616
;; Control instructions
1717

18+
syntax castop = (null?, null?)
19+
20+
grammar Bcastop : castop =
21+
| 0x00 => (eps, eps)
22+
| 0x01 => (NULL, eps)
23+
| 0x02 => (eps, NULL)
24+
| 0x03 => (NULL, NULL)
25+
1826
grammar Bblocktype : blocktype =
1927
| 0x40 => _RESULT eps
2028
| t:Bvaltype => _RESULT t
@@ -39,7 +47,15 @@ grammar Binstr/control : instr = ...
3947
| 0x11 y:Btypeidx x:Btableidx => CALL_INDIRECT x (_IDX y)
4048
| 0x12 x:Bfuncidx => RETURN_CALL x
4149
| 0x13 y:Btypeidx x:Btableidx => RETURN_CALL_INDIRECT x (_IDX y)
50+
| 0x14 x:Btypeidx => CALL_REF (_IDX x)
51+
| 0x15 x:Btypeidx => RETURN_CALL_REF (_IDX x)
4252
| 0x1F bt:Bblocktype c*:Blist(Bcatch) (in:Binstr)* 0x0B => TRY_TABLE bt c* in*
53+
| 0xD5 l:Blabelidx => BR_ON_NULL l
54+
| 0xD6 l:Blabelidx => BR_ON_NON_NULL l
55+
| 0xFB 24:Bu32 (null_1?, null_2?):Bcastop
56+
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST l (REF null_1? ht_1) (REF null_2? ht_2)
57+
| 0xFB 25:Bu32 (null_1?, null_2?):Bcastop
58+
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_FAIL l (REF null_1? ht_1) (REF null_2? ht_2)
4359
| ...
4460

4561
grammar Bcatch : catch =
@@ -120,22 +136,16 @@ grammar Binstr/memory : instr = ...
120136

121137
;; Reference instructions
122138

123-
syntax castop = (null?, null?)
124-
125-
grammar Bcastop : castop =
126-
| 0x00 => (eps, eps)
127-
| 0x01 => (NULL, eps)
128-
| 0x02 => (eps, NULL)
129-
| 0x03 => (NULL, NULL)
130-
131139
grammar Binstr/ref : instr = ...
132140
| 0xD0 ht:Bheaptype => REF.NULL ht
133141
| 0xD1 => REF.IS_NULL
134142
| 0xD2 x:Bfuncidx => REF.FUNC x
135143
| 0xD3 => REF.EQ
136144
| 0xD4 => REF.AS_NON_NULL
137-
| 0xD5 l:Blabelidx => BR_ON_NULL l
138-
| 0xD6 l:Blabelidx => BR_ON_NON_NULL l
145+
| 0xFB 20:Bu32 ht:Bheaptype => REF.TEST (REF ht)
146+
| 0xFB 21:Bu32 ht:Bheaptype => REF.TEST (REF NULL ht)
147+
| 0xFB 22:Bu32 ht:Bheaptype => REF.CAST (REF ht)
148+
| 0xFB 23:Bu32 ht:Bheaptype => REF.CAST (REF NULL ht)
139149
| ...
140150

141151
grammar Binstr/struct : instr = ...
@@ -164,17 +174,6 @@ grammar Binstr/array : instr = ...
164174
| 0xFB 19:Bu32 x:Btypeidx y:Belemidx => ARRAY.INIT_ELEM x y
165175
| ...
166176

167-
grammar Binstr/cast : instr = ...
168-
| 0xFB 20:Bu32 ht:Bheaptype => REF.TEST (REF ht)
169-
| 0xFB 21:Bu32 ht:Bheaptype => REF.TEST (REF NULL ht)
170-
| 0xFB 22:Bu32 ht:Bheaptype => REF.CAST (REF ht)
171-
| 0xFB 23:Bu32 ht:Bheaptype => REF.CAST (REF NULL ht)
172-
| 0xFB 24:Bu32 (null_1?, null_2?):Bcastop
173-
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST l (REF null_1? ht_1) (REF null_2? ht_2)
174-
| 0xFB 25:Bu32 (null_1?, null_2?):Bcastop
175-
l:Blabelidx ht_1:Bheaptype ht_2:Bheaptype => BR_ON_CAST_FAIL l (REF null_1? ht_1) (REF null_2? ht_2)
176-
| ...
177-
178177
grammar Binstr/extern : instr = ...
179178
| 0xFB 26:Bu32 => ANY.CONVERT_EXTERN
180179
| 0xFB 27:Bu32 => EXTERN.CONVERT_ANY
@@ -369,7 +368,7 @@ grammar Binstr/num-cvt : instr = ...
369368
| 0xB8 => CVTOP F64 I32 CONVERT U
370369
| 0xB9 => CVTOP F64 I64 CONVERT S
371370
| 0xBA => CVTOP F64 I64 CONVERT U
372-
| 0xBB => CVTOP F32 F64 PROMOTE
371+
| 0xBB => CVTOP F64 F32 PROMOTE
373372
| 0xBC => CVTOP I32 F32 REINTERPRET
374373
| 0xBD => CVTOP I64 F64 REINTERPRET
375374
| 0xBE => CVTOP F32 I32 REINTERPRET

spectec/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ ROOTDIR = ..
2323
INTERPRETERDIR = $(ROOTDIR)/interpreter
2424
CLONEDIR = src/backend-interpreter/reference-interpreter
2525
CLONERM = dune-project jslib
26+
OPAMPACKAGES = zarith menhir mdx
27+
2628

2729
.PHONY: exe
2830

29-
exe: $(CLONEDIR)
31+
packages:
32+
opam install $(OPAMPACKAGES)
33+
34+
exe: $(CLONEDIR) packages
3035
rm -f ./$(NAME)
3136
dune build $(SRCDIR)/$(EXE)
3237
ln -f $(OUTDIR)/$(EXE) ./$(NAME)

0 commit comments

Comments
 (0)