Debian Codegraph @

tests/cli/component-model/gc.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots %
2
3 (component binary
4 "\00asm" "\0d\00\01\00" ;; component header
5 "\03\07" ;; core type section, 7 bytes large
6 "\01" ;; 1 count
7 "\00\50" ;; sub type
8 "\00" ;; no supertypes
9 "\60" ;; function type
10 "\00\00" ;; no parameters, no results
11 )
12
13 ;; text equivalent of above
14 (component (core type (sub (func))))
15
16 (component binary
17 "\00asm" "\0d\00\01\00" ;; component header
18 "\03\06" ;; core type section, 6 bytes large
19 "\02" ;; 2 count
20 "\50" ;; module type
21 "\00" ;; empty
22 "\60" ;; function type
23 "\00\00" ;; no parameters, no results
24 )
25
26 ;; text equivalent of above
27 (component (core type (module)) (core type (func)))
28
29 (component binary
30 "\00asm" "\0d\00\01\00" ;; component header
31 "\03\09" ;; core type section, 9 bytes large
32 "\01" ;; 1 count
33 "\50" ;; module type
34 "\01" ;; 1 count
35 "\01" ;; core type in module
36 "\50" ;; sub type
37 "\00" ;; no supertypes
38 "\60" ;; function type
39 "\00\00" ;; no parameters, no results
40 )
41
42 ;; text equivalent of above
43 (component (core type (module (type (sub (func))))))
44
45 (assert_malformed
46 (component binary
47 "\00asm" "\0d\00\01\00" ;; component header
48 "\03\06" ;; core type section, 6 bytes large
49 "\01" ;; 1 count
50 "\50" ;; attempted sub type, but actually a module type
51 "\00" ;; attempted zero super types, but actually empty
52 "\60" ;; function type
53 "\00\00" ;; no parameters, no results
54 )
55 "unexpected data at the end of the section")
56
57 (assert_malformed
58 (component binary
59 "\00asm" "\0d\00\01\00" ;; component header
60 "\03\05" ;; core type section, 5 bytes large
61 "\01" ;; 1 count
62 "\00\60" ;; attempted function type with invalid prefix
63 "\00\00" ;; no parameters, no results
64 )
65 "invalid leading byte (0x60) for non-final sub type")
66
67
68 ;; test various shapes and properties of GC types within a component
69 (component $C
70 (core type $t1 (struct))
71 (core type $t2 (array i8))
72 (core type $t3 (func))
73 (core type (struct
74 (field $a (ref $t1))
75 (field $b (ref $t2))
76 (field $c (ref $t3))
77 ))
78 (core type $s1 (sub (struct)))
79 (core type $s2 (sub final (struct)))
80 (core type $s3 (sub $s1 (struct)))
81 (core type $f (func (result (ref $f))))
82 (core rec)
83 (core rec
84 (type $f1 (func (result (ref $f2))))
85 (type $f2 (func (result (ref $f1))))
86 )
87
88 (core type (module
89 (alias outer $C $t1 (type $t1))
90 (import "x" "x" (func (result (ref $t1))))
91
92 (type $a1 (struct (field $a (ref $t1))))
93 (type $a2 (array (ref $a1)))
94 (type $a3 (func (result (ref $a2))))
95 (type $a4 (sub (struct)))
96 (type $a5 (sub final (struct)))
97 (rec)
98 (rec
99 (type $f1 (func (result (ref $f2))))
100 (type $f2 (func (result (ref $f1))))
101 )
102 (type $f (func (result (ref $f))))
103 ))
104 )
105
106 ;; aliases don't work within core types
107 (assert_malformed
108 (component quote
109 "(core type $t1 (struct))"
110 "(core type (module (type (sub $t1 (struct)))))"
111 )
112 "unknown core type: failed to find name `$t1`")
113
114 (assert_invalid
115 (component $C
116 (core type $t1 (struct))
117 (core type (sub $t1 (struct)))
118 )
119 "sub type cannot have a final super type")
120
121 (assert_invalid
122 (component $C
123 (core type (module
124 (type $t1 (struct))
125 (type (sub $t1 (struct)))
126 ))
127 )
128 "sub type cannot have a final super type")
129
130 (component
131 (type $t (resource (rep i32)))
132 (core func (canon resource.drop $t))
133 (core module
134 (type $t1 (sub (func)))
135 (type (sub $t1 (func)))
136 )
137 )