Debian Codegraph @

tests/cli/component-model/alias.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-values
2
3 (component
4 (import "i" (instance $i
5 (export "f1" (func))
6 (export "f2" (func (param "p1" string)))
7 ))
8 (export "run" (func $i "f1"))
9 )
10
11 (component
12 (import "i" (component $c
13 (export "f1" (func))
14 (export "f2" (func (param "p1" string)))
15 ))
16 (instance $i (instantiate $c))
17 (export "run" (func $i "f1"))
18 )
19
20 (component
21 (import "i" (core module $m
22 (export "f1" (func $f1))
23 (export "f2" (func $f2 (param i32)))
24 ))
25 (core instance $i (instantiate $m))
26
27 (core module $m2 (import "" "" (func)))
28
29 (core instance (instantiate $m2 (with "" (instance (export "" (func $i "f1"))))))
30 )
31
32 (component
33 (import "a" (core module $libc
34 (export "memory" (memory 1))
35 (export "table" (table 0 funcref))
36 (export "func" (func))
37 (export "global" (global i32))
38 (export "global mut" (global (mut i64)))
39 ))
40 (core instance $libc (instantiate $libc))
41 (alias core export $libc "memory" (core memory $mem))
42 (alias core export $libc "table" (core table $tbl))
43 (alias core export $libc "func" (core func $func))
44 (alias core export $libc "global" (core global $global))
45 (alias core export $libc "global mut" (core global $global_mut))
46
47 (import "x" (core module $needs_libc
48 (import "" "memory" (memory 1))
49 (import "" "table" (table 0 funcref))
50 (import "" "func" (func))
51 (import "" "global" (global i32))
52 (import "" "global mut" (global (mut i64)))
53 ))
54
55 (core instance (instantiate $needs_libc (with "" (instance
56 (export "memory" (memory $mem))
57 (export "table" (table $tbl))
58 (export "func" (func $func))
59 (export "global" (global $global))
60 (export "global mut" (global $global_mut))
61 ))))
62 )
63
64 (component
65 (import "a" (instance $i
66 (export "a" (func))
67 (export "b" (core module))
68 (export "c" (instance))
69 ))
70 (export "b" (func $i "a"))
71 (export "c" (core module $i "b"))
72 (export "d" (instance $i "c"))
73 )
74
75 (component
76 (import "a" (core module $libc
77 (export "memory" (memory 1))
78 (export "table" (table 0 funcref))
79 (export "func" (func))
80 (export "global" (global i32))
81 (export "global mut" (global (mut i64)))
82 ))
83
84 (import "b" (core module $needs_libc
85 (import "" "memory" (memory 1))
86 (import "" "table" (table 0 funcref))
87 (import "" "func" (func))
88 (import "" "global" (global i32))
89 (import "" "global mut" (global (mut i64)))
90 ))
91
92 (core instance $libc (instantiate $libc))
93 (core instance (instantiate $needs_libc (with "" (instance
94 (export "memory" (memory $libc "memory"))
95 (export "table" (table $libc "table"))
96 (export "func" (func $libc "func"))
97 (export "global" (global $libc "global"))
98 (export "global mut" (global $libc "global mut"))
99 ))))
100 )
101
102 (assert_invalid
103 (component
104 (import "a" (instance (export "a" (func))))
105 (export "a" (core module 0 "a"))
106 )
107 "export `a` for instance 0 is not a module")
108
109 (assert_invalid
110 (component
111 (component
112 (component (export "a"))
113 )
114 (instance (instantiate 0))
115 (export "a" (core module 0 "a"))
116 )
117 "export `a` for instance 0 is not a module")
118
119 (assert_invalid
120 (component
121 (import "a" (core module))
122 (core instance (instantiate 0))
123 (alias core export 0 "a" (core func))
124 )
125 "core instance 0 has no export named `a`")
126
127 (assert_invalid
128 (component
129 (core module)
130 (core instance (instantiate 0))
131 (alias core export 0 "a" (core func))
132 )
133 "core instance 0 has no export named `a`")
134
135 (assert_invalid
136 (component
137 (import "a" (component))
138 (instance (instantiate 0))
139 (alias export 0 "a" (func))
140 )
141 "instance 0 has no export named `a`")
142
143 (assert_invalid
144 (component
145 (import "a" (core module $a (export "" (func))))
146 (import "b" (core module $b (import "" "" (func (param i32)))))
147
148 (core instance $a (instantiate $a))
149 (core instance $b (instantiate $b (with "" (instance $a))))
150 )
151 "type mismatch")
152
153 ;; aliasing various items works
154
155 (component $PARENT
156 (type $t (func (result string)))
157 (component
158 (import "a" (func (type $t)))
159 )
160 (component
161 (alias outer $PARENT $t (type $my_type))
162 (alias outer 0 $my_type (type $my_type_again))
163 (import "a" (func (type $my_type_again)))
164 )
165 )
166
167 (component
168 (type $a (func (result string)))
169 (component
170 (type $b (func (result u32)))
171 (component
172 (type $c (func (result s32)))
173
174 (component
175 (import "a" (func $a (type $a)))
176 (import "b" (func $b (type $b)))
177 (import "c" (func $c (type $c)))
178
179 (import "d" (component $C
180 (import "a" (func (result string)))
181 (import "b" (func (result u32)))
182 (import "c" (func (result s32)))
183 ))
184
185 (instance (instantiate $C
186 (with "a" (func $a))
187 (with "b" (func $b))
188 (with "c" (func $c))
189 ))
190 )
191 )
192 )
193 )
194
195 ;; multiple projections in alias sugar
196 (component $a
197 (import "a" (instance $a
198 (export "a" (instance
199 (export "a" (instance
200 (export "a" (instance
201 (export "a" (func))
202 ))
203 ))
204 ))
205 ))
206
207 (import "b" (component $b (import "a" (func))))
208
209 (instance (instantiate $b
210 (with "a" (func $a "a" "a" "a" "a"))
211 ))
212 )
213
214 ;; alias some constructs
215 (component
216 (import "a" (instance $foo (export "v" (value s32))))
217 (export "v" (value $foo "v"))
218 )
219
220 (component
221 (import "a" (instance $foo (export "v" (component))))
222 (export "v" (component $foo "v"))
223 )
224
225 (component
226 (import "a" (instance $foo (export "v" (core module))))
227 (export "v" (core module $foo "v"))
228 )
229
230 (component $C
231 (core type $t (func))
232 (component $C2
233 (alias outer $C $t (core type $t2))
234 (component
235 (alias outer $C $t (core type))
236 (alias outer $C2 $t2 (core type))
237 )
238 )
239 )
240
241 (component $C
242 (core module $m)
243 (alias outer $C $m (core module $target))
244 (export "v" (core module $target))
245 )
246
247 (component $C
248 (component $m)
249 (alias outer $C $m (component $target))
250 (export "v" (component $target))
251 )
252
253 (assert_invalid
254 (component (alias outer 100 0 (core type)))
255 "invalid outer alias count of 100")
256
257 (assert_invalid
258 (component (alias outer 0 0 (core type)))
259 "index out of bounds")
260
261 (assert_invalid
262 (component (alias outer 100 0 (core module)))
263 "invalid outer alias count of 100")
264
265 (assert_invalid
266 (component (alias outer 0 0 (core module)))
267 "index out of bounds")
268
269 (assert_invalid
270 (component (alias outer 100 0 (component)))
271 "invalid outer alias count of 100")
272
273 (assert_invalid
274 (component (alias outer 0 0 (component)))
275 "index out of bounds")
276
277 (component
278 (import "a" (instance $i
279 (export "x" (core module))
280 ))
281 ;; inline alias injection sugar works for module references
282 (core instance (instantiate (module $i "x")))
283 )
284
285 (component
286 (import "a" (instance $i
287 (export "x" (component))
288 ))
289 ;; inline alias injection sugar works for component references
290 (instance (instantiate (component $i "x")))
291 )