Debian Codegraph @

tests/cli/component-model/adapt.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots %
2
3 (component
4 (import "log" (func $log (param "msg" string)))
5 (core module $libc
6 (memory (export "memory") 1)
7 (func (export "canonical_abi_realloc") (param i32 i32 i32 i32) (result i32)
8 unreachable)
9 )
10
11 (core module $my_module
12 (import "env" "log-utf8" (func $log_utf8 (param i32 i32)))
13 (import "env" "log-utf16" (func $log_utf16 (param i32 i32)))
14 (import "env" "log-compact-utf16" (func $log_compact_utf16 (param i32 i32)))
15
16 (func (export "log-utf8") (param i32 i32)
17 local.get 0
18 local.get 1
19 call $log_utf8
20 )
21 (func (export "log-utf16") (param i32 i32)
22 local.get 0
23 local.get 1
24 call $log_utf16
25 )
26 (func (export "log-compact-utf16") (param i32 i32)
27 local.get 0
28 local.get 1
29 call $log_compact_utf16
30 )
31 )
32
33 (core instance $libc (instantiate $libc))
34
35 (alias core export $libc "canonical_abi_realloc" (core func $realloc))
36 (alias core export $libc "memory" (core memory $memory))
37 (core func $log_lower_utf8 (canon lower (func $log) string-encoding=utf8 (memory $memory) (realloc $realloc)))
38 (core func $log_lower_utf16 (canon lower (func $log) string-encoding=utf16 (memory $memory) (realloc $realloc)))
39 (core func $log_lower_compact_utf16 (canon lower (func $log) string-encoding=latin1+utf16 (memory $memory) (realloc $realloc)))
40
41 (core instance $my_instance (instantiate $my_module
42 (with "libc" (instance $libc))
43 (with "env" (instance
44 (export "log-utf8" (func $log_lower_utf8))
45 (export "log-utf16" (func $log_lower_utf16))
46 (export "log-compact-utf16" (func $log_lower_compact_utf16))
47 ))
48 ))
49
50 (func (export "log1") (param "msg" string)
51 (canon lift
52 (core func $my_instance "log-utf8")
53 string-encoding=utf8
54 (memory $memory)
55 (realloc $realloc)
56 )
57 )
58 (func (export "log2") (param "msg" string)
59 (canon lift
60 (core func $my_instance "log-utf16")
61 string-encoding=utf16
62 (memory $memory)
63 (realloc $realloc)
64 )
65 )
66 (func (export "log3") (param "msg" string)
67 (canon lift
68 (core func $my_instance "log-compact-utf16")
69 string-encoding=latin1+utf16
70 (memory $memory)
71 (realloc $realloc)
72 )
73 )
74 )
75
76 (assert_invalid
77 (component
78 (import "i" (func $f))
79 (core func (canon lower (func $f) string-encoding=utf8 string-encoding=utf16))
80 )
81 "canonical encoding option `utf8` conflicts with option `utf16`")
82
83 (assert_invalid
84 (component
85 (import "i" (func $f))
86 (core func (canon lower (func $f) string-encoding=utf8 string-encoding=latin1+utf16))
87 )
88 "canonical encoding option `utf8` conflicts with option `latin1-utf16`")
89
90 (assert_invalid
91 (component
92 (import "i" (func $f))
93 (core func (canon lower (func $f) string-encoding=utf16 string-encoding=latin1+utf16))
94 )
95 "canonical encoding option `utf16` conflicts with option `latin1-utf16`")
96
97 (assert_invalid
98 (component
99 (import "i" (func $f))
100 (core func (canon lower (func $f) (memory 0)))
101 )
102 "memory index out of bounds")
103
104 (assert_invalid
105 (component
106 (import "i" (func $f))
107 (core module $m (memory (export "memory") 1))
108 (core instance $i (instantiate $m))
109 (core func (canon lower (func $f) (memory $i "memory") (memory $i "memory")))
110 )
111 "`memory` is specified more than once")
112
113 (assert_invalid
114 (component
115 (core module $m
116 (func (export "f") (param i32 i32))
117 )
118 (core instance $i (instantiate $m))
119 (func (param "p1" (list u8)) (canon lift (core func $i "f")))
120 )
121 "canonical option `memory` is required")
122
123 (assert_invalid
124 (component
125 (core module $m
126 (memory (export "m") 1)
127 (func (export "f") (param i32 i32))
128 )
129 (core instance $i (instantiate $m))
130 (func (param "p1" (list u8))
131 (canon lift (core func $i "f")
132 (memory $i "m")
133 )
134 )
135 )
136 "canonical option `realloc` is required")
137
138 (assert_invalid
139 (component
140 (core module $m
141 (memory (export "m") 1)
142 (func (export "f") (param i32 i32))
143 (func (export "r") (param i32 i32 i32 i32) (result i32))
144 )
145 (core instance $i (instantiate $m))
146 (func (param "p1" (list u8))
147 (canon lift (core func $i "f")
148 (memory $i "m")
149 (realloc (func $i "r"))
150 (realloc (func $i "r"))
151 )
152 )
153 )
154 "canonical option `realloc` is specified more than once")
155
156 (assert_invalid
157 (component
158 (core module $m
159 (memory (export "m") 1)
160 (func (export "f") (param i32 i32))
161 (func (export "r"))
162 )
163 (core instance $i (instantiate $m))
164 (func (param "p1" (list u8))
165 (canon lift (core func $i "f")
166 (memory $i "m")
167 (realloc (func $i "r"))
168 )
169 )
170 )
171 "canonical option `realloc` uses a core function with an incorrect signature")
172
173 (assert_invalid
174 (component
175 (core module $m
176 (memory (export "m") 1)
177 (func (export "f") (result i32))
178 (func (export "r") (param i32 i32 i32 i32) (result i32))
179 (func (export "p"))
180 )
181 (core instance $i (instantiate $m))
182 (func (result string)
183 (canon lift (core func $i "f")
184 (memory $i "m")
185 (realloc (func $i "r"))
186 (post-return (func $i "p"))
187 )
188 )
189 )
190 "canonical option `post-return` uses a core function with an incorrect signature")
191
192 (assert_invalid
193 (component
194 (core module $m
195 (memory (export "m") 1)
196 (func (export "f") (result i32))
197 (func (export "r") (param i32 i32 i32 i32) (result i32))
198 (func (export "p") (param i32))
199 )
200 (core instance $i (instantiate $m))
201 (func (result string)
202 (canon lift (core func $i "f")
203 (memory $i "m")
204 (realloc (func $i "r"))
205 (post-return (func $i "p"))
206 (post-return (func $i "p"))
207 )
208 )
209 )
210 "canonical option `post-return` is specified more than once")
211
212 (assert_invalid
213 (component
214 (import "i" (func $f (param "p1" string)))
215 (core module $m
216 (memory (export "m") 1)
217 (func (export "f") (result i32))
218 (func (export "r") (param i32 i32 i32 i32) (result i32))
219 (func (export "p") (param i32))
220 )
221 (core instance $i (instantiate $m))
222 (core func
223 (canon lower (func $f)
224 (memory $i "m")
225 (realloc (func $i "r"))
226 (post-return (func $i "p"))
227 )
228 )
229 )
230 "canonical option `post-return` cannot be specified for lowerings")
231
232 (component
233 (core module $m
234 (memory (export "m") 1)
235 (func (export "f") (result i32) unreachable)
236 (func (export "r") (param i32 i32 i32 i32) (result i32) unreachable)
237 (func (export "p") (param i32))
238 )
239 (core instance $i (instantiate $m))
240 (func (result string)
241 (canon lift (core func $i "f")
242 (memory $i "m")
243 (realloc (func $i "r"))
244 (post-return (func $i "p"))
245 )
246 )
247 )
248
249 (assert_malformed
250 (component quote
251 "(core module $m (func (export \"\")))"
252 "(core instance $i (instantiate $m))"
253 "(core func (canon lower (func $i \"\")))"
254 )
255 "unknown instance: failed to find name `$i`")
256
257 (assert_invalid
258 (component
259 (core module $m (func (export "foo") (param i32)))
260 (core instance $i (instantiate $m))
261 (func (export "foo") (canon lift (core func $i "foo")))
262 )
263 "lowered parameter types `[]` do not match parameter types `[I32]`")
264
265 (assert_invalid
266 (component
267 (core module $m (func (export "foo") (result i32)))
268 (core instance $i (instantiate $m))
269 (func (export "foo") (canon lift (core func $i "foo")))
270 )
271 "lowered result types `[]` do not match result types `[I32]`")
272
273 (assert_invalid
274 (component
275 (type $f string)
276 (core module $m (func (export "foo")))
277 (core instance $i (instantiate $m))
278 (func (export "foo") (type $f) (canon lift (core func $i "foo")))
279 )
280 "not a function type")
281
282 (assert_malformed
283 (component quote
284 "(import \"a\" (func $f))"
285 "(func (export \"foo\") (canon lift (core func $f)))"
286 )
287 "unknown core func: failed to find name `$f`")