Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Commit fa6ff17

Browse files
authored
Merge pull request #114 from WebAssembly/fix.538.2
More fixes and tests around element segments
2 parents 52ebaa9 + 70ddb4b commit fa6ff17

File tree

4 files changed

+351
-5
lines changed

4 files changed

+351
-5
lines changed

document/core/binary/modules.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
350350
\{ \ETYPE~\X{et}, \EINIT~((\REFFUNC~y)~\END)^\ast, \EMODE~\EDECLARATIVE \} \\ &&|&
351351
4{:}\Bu32~~e{:}\Bexpr~~\X{el}^\ast{:}\Bvec(\Bexpr)
352352
&\Rightarrow& \\&&&\quad
353-
\{ \ETYPE~(\REF~\FUNC), \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
353+
\{ \ETYPE~(\REF~\NULL~\FUNC), \EINIT~\X{el}^\ast, \EMODE~\EACTIVE~\{ \ETABLE~0, \EOFFSET~e \} \} \\ &&|&
354354
5{:}\Bu32~~\X{et}:\Breftype~~\X{el}^\ast{:}\Bvec(\Bexpr)
355355
&\Rightarrow& \\&&&\quad
356356
\{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EPASSIVE \} \\ &&|&
@@ -361,7 +361,7 @@ It decodes into a vector of :ref:`element segments <syntax-elem>` that represent
361361
&\Rightarrow& \\&&&\quad
362362
\{ \ETYPE~et, \EINIT~\X{el}^\ast, \EMODE~\EDECLARATIVE \} \\
363363
\production{element kind} & \Belemkind &::=&
364-
\hex{00} &\Rightarrow& \FUNCREF \\
364+
\hex{00} &\Rightarrow& (\REF~\FUNC) \\
365365
\end{array}
366366
367367
.. note::

interpreter/binary/decode.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ let elem s =
10431043
| 0x04l ->
10441044
let emode = at active_zero s in
10451045
let einit = vec const s in
1046-
{etype = (NoNull, FuncHT); einit; emode}
1046+
{etype = (Null, FuncHT); einit; emode}
10471047
| 0x05l ->
10481048
let emode = at passive s in
10491049
let etype = ref_type s in

interpreter/binary/encode.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ struct
898898
match emode.it with
899899
| Passive ->
900900
u32 0x01l; elem_kind etype; vec elem_index einit
901-
| Active {index; offset} when index.it = 0l && is_elem_kind etype ->
901+
| Active {index; offset} when index.it = 0l ->
902902
u32 0x00l; const offset; vec elem_index einit
903903
| Active {index; offset} ->
904904
u32 0x02l;
@@ -909,7 +909,7 @@ struct
909909
match emode.it with
910910
| Passive ->
911911
u32 0x05l; ref_type etype; vec const einit
912-
| Active {index; offset} when index.it = 0l && is_elem_kind etype ->
912+
| Active {index; offset} when index.it = 0l && etype = (Null, FuncHT) ->
913913
u32 0x04l; const offset; vec const einit
914914
| Active {index; offset} ->
915915
u32 0x06l; var index; const offset; ref_type etype; vec const einit

test/core/elem.wast

Lines changed: 346 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,352 @@
233233
)
234234

235235

236+
;; Binary format variations
237+
238+
(module
239+
(func)
240+
(table 1 funcref)
241+
(elem (i32.const 0) func 0)
242+
)
243+
(module binary
244+
"\00asm" "\01\00\00\00" ;; Magic
245+
"\01\04\01\60\00\00" ;; Type section: 1 type
246+
"\03\02\01\00" ;; Function section: 1 function
247+
"\04\04\01" ;; Table section: 1 table
248+
"\70\00\01" ;; Table 0: [1..] funcref
249+
"\09\07\01" ;; Elem section: 1 element segment
250+
"\00\41\00\0b\01\00" ;; Segment 0: (i32.const 0) func 0
251+
"\0a\04\01" ;; Code section: 1 function
252+
"\02\00\0b" ;; Function 0: empty
253+
)
254+
255+
(module
256+
(func)
257+
(table 1 funcref)
258+
(elem func 0)
259+
)
260+
(module binary
261+
"\00asm" "\01\00\00\00" ;; Magic
262+
"\01\04\01\60\00\00" ;; Type section: 1 type
263+
"\03\02\01\00" ;; Function section: 1 function
264+
"\04\04\01" ;; Table section: 1 table
265+
"\70\00\01" ;; Table 0: [1..] funcref
266+
"\09\05\01" ;; Elem section: 1 element segment
267+
"\01\00\01\00" ;; Segment 0: func 0
268+
"\0a\04\01" ;; Code section: 1 function
269+
"\02\00\0b" ;; Function 0: empty
270+
)
271+
272+
(module
273+
(func)
274+
(table 1 funcref)
275+
(elem (table 0) (i32.const 0) func 0)
276+
)
277+
(module binary
278+
"\00asm" "\01\00\00\00" ;; Magic
279+
"\01\04\01\60\00\00" ;; Type section: 1 type
280+
"\03\02\01\00" ;; Function section: 1 function
281+
"\04\04\01" ;; Table section: 1 table
282+
"\70\00\01" ;; Table 0: [1..] funcref
283+
"\09\09\01" ;; Elem section: 1 element segment
284+
"\02\00\41\00\0b\00\01\00" ;; Segment 0: (table 0) (i32.const 0) func 0
285+
"\0a\04\01" ;; Code section: 1 function
286+
"\02\00\0b" ;; Function 0: empty
287+
)
288+
289+
(module
290+
(func)
291+
(table 1 funcref)
292+
(elem declare func 0)
293+
)
294+
(module binary
295+
"\00asm" "\01\00\00\00" ;; Magic
296+
"\01\04\01\60\00\00" ;; Type section: 1 type
297+
"\03\02\01\00" ;; Function section: 1 function
298+
"\04\04\01" ;; Table section: 1 table
299+
"\70\00\01" ;; Table 0: [1..] funcref
300+
"\09\05\01" ;; Elem section: 1 element segment
301+
"\03\00\01\00" ;; Segment 0: declare func 0
302+
"\0a\04\01" ;; Code section: 1 function
303+
"\02\00\0b" ;; Function 0: empty
304+
)
305+
306+
(module
307+
(func)
308+
(table 1 funcref)
309+
(elem (i32.const 0) (;;)(ref func) (ref.func 0))
310+
)
311+
(module binary
312+
"\00asm" "\01\00\00\00" ;; Magic
313+
"\01\04\01\60\00\00" ;; Type section: 1 type
314+
"\03\02\01\00" ;; Function section: 1 function
315+
"\04\04\01" ;; Table section: 1 table
316+
"\70\00\01" ;; Table 0: [1..] funcref
317+
"\09\09\01" ;; Elem section: 1 element segment
318+
"\04\41\00\0b\01\d2\00\0b" ;; Segment 0: (i32.const 0) (ref.func 0)
319+
"\0a\04\01" ;; Code section: 1 function
320+
"\02\00\0b" ;; Function 0: empty
321+
)
322+
(module
323+
(func)
324+
(table 1 funcref)
325+
(elem (i32.const 0) funcref (ref.null func))
326+
)
327+
(module binary
328+
"\00asm" "\01\00\00\00" ;; Magic
329+
"\01\04\01\60\00\00" ;; Type section: 1 type
330+
"\03\02\01\00" ;; Function section: 1 function
331+
"\04\04\01" ;; Table section: 1 table
332+
"\70\00\01" ;; Table 0: [1..] funcref
333+
"\09\09\01" ;; Elem section: 1 element segment
334+
"\04\41\00\0b\01\d0\70\0b" ;; Segment 0: (i32.const 0) (ref.null func)
335+
"\0a\04\01" ;; Code section: 1 function
336+
"\02\00\0b" ;; Function 0: empty
337+
)
338+
339+
(module
340+
(func)
341+
(table 1 funcref)
342+
(elem (i32.const 0) funcref (ref.func 0))
343+
)
344+
(module binary
345+
"\00asm" "\01\00\00\00" ;; Magic
346+
"\01\04\01\60\00\00" ;; Type section: 1 type
347+
"\03\02\01\00" ;; Function section: 1 function
348+
"\04\04\01" ;; Table section: 1 table
349+
"\70\00\01" ;; Table 0: [1..] funcref
350+
"\09\07\01" ;; Elem section: 1 element segment
351+
"\05\70\01\d2\00\0b" ;; Segment 0: funcref (ref.func 0)
352+
"\0a\04\01" ;; Code section: 1 function
353+
"\02\00\0b" ;; Function 0: empty
354+
)
355+
(module
356+
(func)
357+
(table 1 funcref)
358+
(elem (i32.const 0) funcref (ref.null func))
359+
)
360+
(module binary
361+
"\00asm" "\01\00\00\00" ;; Magic
362+
"\01\04\01\60\00\00" ;; Type section: 1 type
363+
"\03\02\01\00" ;; Function section: 1 function
364+
"\04\04\01" ;; Table section: 1 table
365+
"\70\00\01" ;; Table 0: [1..] funcref
366+
"\09\07\01" ;; Elem section: 1 element segment
367+
"\05\70\01\d0\70\0b" ;; Segment 0: funcref (ref.null func)
368+
"\0a\04\01" ;; Code section: 1 function
369+
"\02\00\0b" ;; Function 0: empty
370+
)
371+
372+
(module
373+
(func)
374+
(table 1 funcref)
375+
(elem (table 0) (i32.const 0) funcref (ref.func 0))
376+
)
377+
(module binary
378+
"\00asm" "\01\00\00\00" ;; Magic
379+
"\01\04\01\60\00\00" ;; Type section: 1 type
380+
"\03\02\01\00" ;; Function section: 1 function
381+
"\04\04\01" ;; Table section: 1 table
382+
"\70\00\01" ;; Table 0: [1..] funcref
383+
"\09\0b\01" ;; Elem section: 1 element segment
384+
"\06\00\41\00\0b\70\01\d2\00\0b" ;; Segment 0: (table 0) (i32.const 0) funcref (ref.func 0)
385+
"\0a\04\01" ;; Code section: 1 function
386+
"\02\00\0b" ;; Function 0: empty
387+
)
388+
(module
389+
(func)
390+
(table 1 funcref)
391+
(elem (table 0) (i32.const 0) funcref (ref.null func))
392+
)
393+
(module binary
394+
"\00asm" "\01\00\00\00" ;; Magic
395+
"\01\04\01\60\00\00" ;; Type section: 1 type
396+
"\03\02\01\00" ;; Function section: 1 function
397+
"\04\04\01" ;; Table section: 1 table
398+
"\70\00\01" ;; Table 0: [1..] funcref
399+
"\09\0b\01" ;; Elem section: 1 element segment
400+
"\06\00\41\00\0b\70\01\d0\70\0b" ;; Segment 0: (table 0) (i32.const 0) funcref (ref.null func)
401+
"\0a\04\01" ;; Code section: 1 function
402+
"\02\00\0b" ;; Function 0: empty
403+
)
404+
405+
(module
406+
(func)
407+
(table 1 funcref)
408+
(elem declare funcref (ref.func 0))
409+
)
410+
(module binary
411+
"\00asm" "\01\00\00\00" ;; Magic
412+
"\01\04\01\60\00\00" ;; Type section: 1 type
413+
"\03\02\01\00" ;; Function section: 1 function
414+
"\04\04\01" ;; Table section: 1 table
415+
"\70\00\01" ;; Table 0: [1..] funcref
416+
"\09\07\01" ;; Elem section: 1 element segment
417+
"\07\70\01\d2\00\0b" ;; Segment 0: declare funcref (ref.func 0)
418+
"\0a\04\01" ;; Code section: 1 function
419+
"\02\00\0b" ;; Function 0: empty
420+
)
421+
(module
422+
(func)
423+
(table 1 funcref)
424+
(elem declare funcref (ref.null func))
425+
)
426+
(module binary
427+
"\00asm" "\01\00\00\00" ;; Magic
428+
"\01\04\01\60\00\00" ;; Type section: 1 type
429+
"\03\02\01\00" ;; Function section: 1 function
430+
"\04\04\01" ;; Table section: 1 table
431+
"\70\00\01" ;; Table 0: [1..] funcref
432+
"\09\07\01" ;; Elem section: 1 element segment
433+
"\07\70\01\d0\70\0b" ;; Segment 0: declare funcref (ref.null func)
434+
"\0a\04\01" ;; Code section: 1 function
435+
"\02\00\0b" ;; Function 0: empty
436+
)
437+
438+
439+
(module
440+
(func)
441+
(table 1 (ref func) (ref.func 0))
442+
(elem (i32.const 0) func 0)
443+
)
444+
(module binary
445+
"\00asm" "\01\00\00\00" ;; Magic
446+
"\01\04\01\60\00\00" ;; Type section: 1 type
447+
"\03\02\01\00" ;; Function section: 1 function
448+
"\04\0a\01" ;; Table section: 1 table
449+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
450+
"\09\07\01" ;; Elem section: 1 element segment
451+
"\00\41\00\0b\01\00" ;; Segment 0: (i32.const 0) func 0
452+
"\0a\04\01" ;; Code section: 1 function
453+
"\02\00\0b" ;; Function 0: empty
454+
)
455+
456+
(module
457+
(func)
458+
(table 1 (ref func) (ref.func 0))
459+
(elem func 0)
460+
)
461+
(module binary
462+
"\00asm" "\01\00\00\00" ;; Magic
463+
"\01\04\01\60\00\00" ;; Type section: 1 type
464+
"\03\02\01\00" ;; Function section: 1 function
465+
"\04\0a\01" ;; Table section: 1 table
466+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
467+
"\09\05\01" ;; Elem section: 1 element segment
468+
"\01\00\01\00" ;; Segment 0: func 0
469+
"\0a\04\01" ;; Code section: 1 function
470+
"\02\00\0b" ;; Function 0: empty
471+
)
472+
473+
(module
474+
(func)
475+
(table 1 (ref func) (ref.func 0))
476+
(elem (table 0) (i32.const 0) func 0)
477+
)
478+
(module binary
479+
"\00asm" "\01\00\00\00" ;; Magic
480+
"\01\04\01\60\00\00" ;; Type section: 1 type
481+
"\03\02\01\00" ;; Function section: 1 function
482+
"\04\0a\01" ;; Table section: 1 table
483+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
484+
"\09\09\01" ;; Elem section: 1 element segment
485+
"\02\00\41\00\0b\00\01\00" ;; Segment 0: (table 0) (i32.const 0) func 0
486+
"\0a\04\01" ;; Code section: 1 function
487+
"\02\00\0b" ;; Function 0: empty
488+
)
489+
490+
(module
491+
(func)
492+
(table 1 (ref func) (ref.func 0))
493+
(elem declare func 0)
494+
)
495+
(module binary
496+
"\00asm" "\01\00\00\00" ;; Magic
497+
"\01\04\01\60\00\00" ;; Type section: 1 type
498+
"\03\02\01\00" ;; Function section: 1 function
499+
"\04\0a\01" ;; Table section: 1 table
500+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
501+
"\09\05\01" ;; Elem section: 1 element segment
502+
"\03\00\01\00" ;; Segment 0: declare func 0
503+
"\0a\04\01" ;; Code section: 1 function
504+
"\02\00\0b" ;; Function 0: empty
505+
)
506+
507+
(assert_invalid
508+
(module
509+
(func)
510+
(table 1 (ref func) (ref.func 0))
511+
(elem (i32.const 0) funcref (ref.func 0))
512+
)
513+
"type mismatch"
514+
)
515+
(assert_invalid
516+
(module binary
517+
"\00asm" "\01\00\00\00" ;; Magic
518+
"\01\04\01\60\00\00" ;; Type section: 1 type
519+
"\03\02\01\00" ;; Function section: 1 function
520+
"\04\0a\01" ;; Table section: 1 table
521+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
522+
"\09\09\01" ;; Elem section: 1 element segment
523+
"\04\41\00\0b\01\d2\00\0b" ;; Segment 0: (i32.const 0) (ref.func 0)
524+
"\0a\04\01" ;; Code section: 1 function
525+
"\02\00\0b" ;; Function 0: empty
526+
)
527+
"type mismatch"
528+
)
529+
530+
(module
531+
(func)
532+
(table 1 (ref func) (ref.func 0))
533+
(elem (ref func) (ref.func 0))
534+
)
535+
(module binary
536+
"\00asm" "\01\00\00\00" ;; Magic
537+
"\01\04\01\60\00\00" ;; Type section: 1 type
538+
"\03\02\01\00" ;; Function section: 1 function
539+
"\04\0a\01" ;; Table section: 1 table
540+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
541+
"\09\08\01" ;; Elem section: 1 element segment
542+
"\05\64\70\01\d2\00\0b" ;; Segment 0: (ref func) (ref.func 0)
543+
"\0a\04\01" ;; Code section: 1 function
544+
"\02\00\0b" ;; Function 0: empty
545+
)
546+
547+
(module
548+
(func)
549+
(table 1 (ref func) (ref.func 0))
550+
(elem (table 0) (i32.const 0) (ref func) (ref.func 0))
551+
)
552+
(module binary
553+
"\00asm" "\01\00\00\00" ;; Magic
554+
"\01\04\01\60\00\00" ;; Type section: 1 type
555+
"\03\02\01\00" ;; Function section: 1 function
556+
"\04\0a\01" ;; Table section: 1 table
557+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
558+
"\09\0c\01" ;; Elem section: 1 element segment
559+
"\06\00\41\00\0b\64\70\01\d2\00\0b" ;; Segment 0: (table 0) (i32.const 0) (ref func) (ref.func 0)
560+
"\0a\04\01" ;; Code section: 1 function
561+
"\02\00\0b" ;; Function 0: empty
562+
)
563+
564+
(module
565+
(func)
566+
(table 1 (ref func) (ref.func 0))
567+
(elem declare (ref func) (ref.func 0))
568+
)
569+
(module binary
570+
"\00asm" "\01\00\00\00" ;; Magic
571+
"\01\04\01\60\00\00" ;; Type section: 1 type
572+
"\03\02\01\00" ;; Function section: 1 function
573+
"\04\0a\01" ;; Table section: 1 table
574+
"\40\00\64\70\00\01\d2\00\0b" ;; Table 0: [1..] (ref func) (ref.func 0)
575+
"\09\08\01" ;; Elem section: 1 element segment
576+
"\07\64\70\01\d2\00\0b" ;; Segment 0: declare (ref func) (ref.func 0)
577+
"\0a\04\01" ;; Code section: 1 function
578+
"\02\00\0b" ;; Function 0: empty
579+
)
580+
581+
236582
;; Invalid bounds for elements
237583

238584
(assert_trap

0 commit comments

Comments
 (0)