Debian Codegraph @

tests/cli/component-model-gc/option-types.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots % -f gc,cm-gc
2
3 ;; Basic.
4 (component
5 (type $opt (option u32))
6
7 (core type $opt (struct))
8 (core type $ty (func (param (ref $opt))))
9
10 (import "i" (instance $i
11 (export "ty" (type $opt' (eq $opt)))
12 (export "f" (func (param "x" $opt')))))
13 (core func (canon lower (func $i "f") gc (core-type $ty)))
14 )
15
16 ;; With a nullable reference.
17 (component
18 (type $opt (option u32))
19
20 (core type $opt (struct))
21 (core type $ty (func (param (ref null $opt))))
22
23 (import "i" (instance $i
24 (export "ty" (type $opt' (eq $opt)))
25 (export "f" (func (param "x" $opt')))))
26 (core func (canon lower (func $i "f") gc (core-type $ty)))
27 )
28
29 ;; With a custom rec group.
30 (component
31 (type $opt (option u32))
32
33 (core rec
34 (type $opt (struct))
35 (type $ty (func (param (ref $opt)))))
36
37 (import "i" (instance $i
38 (export "ty" (type $opt' (eq $opt)))
39 (export "f" (func (param "x" $opt')))))
40 (core func (canon lower (func $i "f") gc (core-type $ty)))
41 )
42
43 ;; With a custom subtype.
44 (component
45 (type $opt (option u32))
46
47 (core type $base (sub (struct)))
48 (core type $opt (sub $base (struct)))
49 (core type $ty (func (param (ref $opt))))
50
51 (import "i" (instance $i
52 (export "ty" (type $opt' (eq $opt)))
53 (export "f" (func (param "x" $opt')))))
54 (core func (canon lower (func $i "f") gc (core-type $ty)))
55 )
56
57 ;; Unexpected field.
58 (assert_invalid
59 (component
60 (type $opt (option u32))
61
62 (core type $opt (struct (field i32)))
63 (core type $ty (func (param (ref $opt))))
64
65 (import "i" (instance $i
66 (export "ty" (type $opt' (eq $opt)))
67 (export "f" (func (param "x" $opt')))))
68 (core func (canon lower (func $i "f") gc (core-type $ty)))
69 )
70 "expected to lower component `option` type to core `(ref null? (struct))`"
71 )
72
73 ;; Lowering into a non-struct.
74 (assert_invalid
75 (component
76 (type $opt (option u32))
77
78 (core type $ty (func (param externref)))
79
80 (import "i" (instance $i
81 (export "ty" (type $opt' (eq $opt)))
82 (export "f" (func (param "x" $opt')))))
83 (core func (canon lower (func $i "f") gc (core-type $ty)))
84 )
85 "expected to lower component `option` type to core `(ref null? (struct))`"
86 )