blob: 1fd470ff8229ad9695bed07d405d3da5d12ccab8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt -all --preserve-type-order --string-lowering -S -o - | filecheck %s
(module
(rec
;; CHECK: (type $0 (func))
;; CHECK: (type $1 (array (mut i16)))
;; CHECK: (rec
;; CHECK-NEXT: (type $struct-of-string (struct (field externref) (field i32) (field anyref)))
(type $struct-of-string (struct (field stringref) (field i32) (field anyref)))
;; CHECK: (type $struct-of-array (struct (field (ref $1))))
(type $struct-of-array (struct (field (ref $array16))))
;; CHECK: (type $array16-imm (array i32))
(type $array16-imm (array i32))
;; CHECK: (type $array32 (array (mut i32)))
(type $array32 (array (mut i32)))
;; CHECK: (type $array16-open (sub (array (mut i16))))
(type $array16-open (sub (array (mut i16))))
;; CHECK: (type $array16-child (sub $array16-open (array (mut i16))))
(type $array16-child (sub $array16-open (array (mut i16))))
;; CHECK: (type $array16 (array (mut i16)))
(type $array16 (array (mut i16)))
)
;; CHECK: (type $9 (func (param (ref $1))))
;; CHECK: (type $10 (func (param externref externref) (result (ref extern))))
;; CHECK: (type $11 (func (param externref (ref $1)) (result i32)))
;; CHECK: (type $12 (func (param externref externref) (result i32)))
;; CHECK: (type $13 (func (param externref) (result i32)))
;; CHECK: (type $14 (func (param externref) (result externref)))
;; CHECK: (type $15 (func (param externref)))
;; CHECK: (type $16 (func (result externref)))
;; CHECK: (type $17 (func (param externref externref) (result i32)))
;; CHECK: (type $18 (func (param externref i32 externref)))
;; CHECK: (type $19 (func (param (ref null $1) i32 i32) (result (ref extern))))
;; CHECK: (type $20 (func (param i32) (result (ref extern))))
;; CHECK: (type $21 (func (param externref externref) (result (ref extern))))
;; CHECK: (type $22 (func (param externref (ref null $1) i32) (result i32)))
;; CHECK: (type $23 (func (param externref) (result i32)))
;; CHECK: (type $24 (func (param externref i32) (result i32)))
;; CHECK: (type $25 (func (param externref i32 i32) (result (ref extern))))
;; CHECK: (import "string.const" "0" (global $"string.const_\"exported\"" (ref extern)))
;; CHECK: (import "string.const" "1" (global $"string.const_\"value\"" (ref extern)))
;; CHECK: (import "colliding" "name" (func $fromCodePoint (type $0)))
(import "colliding" "name" (func $fromCodePoint))
;; CHECK: (import "wasm:js-string" "fromCharCodeArray" (func $fromCharCodeArray (type $19) (param (ref null $1) i32 i32) (result (ref extern))))
;; CHECK: (import "wasm:js-string" "fromCodePoint" (func $fromCodePoint_18 (type $20) (param i32) (result (ref extern))))
;; CHECK: (import "wasm:js-string" "concat" (func $concat (type $21) (param externref externref) (result (ref extern))))
;; CHECK: (import "wasm:js-string" "intoCharCodeArray" (func $intoCharCodeArray (type $22) (param externref (ref null $1) i32) (result i32)))
;; CHECK: (import "wasm:js-string" "equals" (func $equals (type $17) (param externref externref) (result i32)))
;; CHECK: (import "wasm:js-string" "compare" (func $compare (type $17) (param externref externref) (result i32)))
;; CHECK: (import "wasm:js-string" "length" (func $length (type $23) (param externref) (result i32)))
;; CHECK: (import "wasm:js-string" "charCodeAt" (func $charCodeAt (type $24) (param externref i32) (result i32)))
;; CHECK: (import "wasm:js-string" "substring" (func $substring (type $25) (param externref i32 i32) (result (ref extern))))
;; CHECK: (global $string externref (ref.null noextern))
(global $string stringref (ref.null string)) ;; Test we update global nulls.
;; CHECK: (export "export.1" (func $exported-string-returner))
;; CHECK: (export "export.2" (func $exported-string-receiver))
;; CHECK: (func $string.new.gc (type $9) (param $array16 (ref $1))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (call $fromCharCodeArray
;; CHECK-NEXT: (local.get $array16)
;; CHECK-NEXT: (i32.const 7)
;; CHECK-NEXT: (i32.const 8)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.new.gc (param $array16 (ref $array16))
(drop
(string.new_wtf16_array
(local.get $array16)
(i32.const 7)
(i32.const 8)
)
)
)
;; CHECK: (func $string.from_code_point (type $16) (result externref)
;; CHECK-NEXT: (call $fromCodePoint_18
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.from_code_point (result stringref)
(string.from_code_point
(i32.const 1)
)
)
;; CHECK: (func $string.concat (type $10) (param $0 externref) (param $1 externref) (result (ref extern))
;; CHECK-NEXT: (call $concat
;; CHECK-NEXT: (local.get $0)
;; CHECK-NEXT: (local.get $1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.concat (param stringref stringref) (result (ref string))
(string.concat
(local.get 0)
(local.get 1)
)
)
;; CHECK: (func $string.encode (type $11) (param $ref externref) (param $array16 (ref $1)) (result i32)
;; CHECK-NEXT: (call $intoCharCodeArray
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: (local.get $array16)
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.encode (param $ref stringref) (param $array16 (ref $array16)) (result i32)
(string.encode_wtf16_array
(local.get $ref)
(local.get $array16)
(i32.const 10)
)
)
;; CHECK: (func $string.eq (type $12) (param $a externref) (param $b externref) (result i32)
;; CHECK-NEXT: (call $equals
;; CHECK-NEXT: (local.get $a)
;; CHECK-NEXT: (local.get $b)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.eq (param $a stringref) (param $b stringref) (result i32)
(string.eq
(local.get $a)
(local.get $b)
)
)
;; CHECK: (func $string.compare (type $12) (param $a externref) (param $b externref) (result i32)
;; CHECK-NEXT: (call $compare
;; CHECK-NEXT: (local.get $a)
;; CHECK-NEXT: (local.get $b)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.compare (param $a stringref) (param $b stringref) (result i32)
(string.compare
(local.get $a)
(local.get $b)
)
)
;; CHECK: (func $string.length (type $13) (param $ref externref) (result i32)
;; CHECK-NEXT: (call $length
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.length (param $ref stringref) (result i32)
(string.measure_wtf16
(local.get $ref)
)
)
;; CHECK: (func $string.get_codeunit (type $13) (param $ref externref) (result i32)
;; CHECK-NEXT: (call $charCodeAt
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.get_codeunit (param $ref stringref) (result i32)
(stringview_wtf16.get_codeunit
(local.get $ref)
(i32.const 2)
)
)
;; CHECK: (func $string.slice (type $14) (param $ref externref) (result externref)
;; CHECK-NEXT: (call $substring
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: (i32.const 3)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.slice (param $ref stringref) (result stringref)
(stringview_wtf16.slice
(local.get $ref)
(i32.const 2)
(i32.const 3)
)
)
;; CHECK: (func $if.string (type $14) (param $ref externref) (result externref)
;; CHECK-NEXT: (if (result externref)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (ref.null noextern)
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $if.string (param $ref stringref) (result stringref)
(if (result stringref)
(i32.const 0)
(then
(ref.null none) ;; this will turn into noextern
)
(else
(local.get $ref)
)
)
)
;; CHECK: (func $if.string.flip (type $14) (param $ref externref) (result externref)
;; CHECK-NEXT: (if (result externref)
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (then
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: )
;; CHECK-NEXT: (else
;; CHECK-NEXT: (ref.null noextern)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $if.string.flip (param $ref stringref) (result stringref)
;; As above but with flipped arms.
(if (result stringref)
(i32.const 0)
(then
(local.get $ref)
)
(else
(ref.null none)
)
)
)
;; CHECK: (func $exported-string-returner (type $16) (result externref)
;; CHECK-NEXT: (global.get $"string.const_\"exported\"")
;; CHECK-NEXT: )
(func $exported-string-returner (export "export.1") (result stringref)
;; We should update the signature of this function even though it is public
;; (exported).
(string.const "exported")
)
;; CHECK: (func $exported-string-receiver (type $18) (param $x externref) (param $y i32) (param $z externref)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $x)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $y)
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (local.get $z)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $exported-string-receiver (export "export.2") (param $x stringref) (param $y i32) (param $z stringref)
;; We should update the signature of this function even though it is public
;; (exported).
(drop
(local.get $x)
)
(drop
(local.get $y)
)
(drop
(local.get $z)
)
)
;; CHECK: (func $use-struct-of-array (type $0)
;; CHECK-NEXT: (local $array16 (ref $1))
;; CHECK-NEXT: (local $open (ref $array16-open))
;; CHECK-NEXT: (local $child (ref $array16-child))
;; CHECK-NEXT: (local $32 (ref $array32))
;; CHECK-NEXT: (local $imm (ref $array16-imm))
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (call $fromCharCodeArray
;; CHECK-NEXT: (struct.get $struct-of-array 0
;; CHECK-NEXT: (struct.new $struct-of-array
;; CHECK-NEXT: (array.new_fixed $1 2
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: (i32.const 20)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (i32.const 0)
;; CHECK-NEXT: (i32.const 1)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $use-struct-of-array
;; The array type here should switch to the new 16-bit array type that we
;; use for the new imports, so that it is compatible with them. Without
;; that, calling the import as we do below will fail.
(local $array16 (ref $array16))
;; In comparison, the array16-open param should remain as it is: it is an
;; open type which is different then the one we care about.
(local $open (ref $array16-open))
;; Likewise a child of that open type is also ignored.
(local $child (ref $array16-child))
;; Another array size is also ignored.
(local $32 (ref $array32))
;; An immutable array is also ignored.
(local $imm (ref $array16-imm))
(drop
(string.new_wtf16_array
(struct.get $struct-of-array 0
(struct.new $struct-of-array
(array.new_fixed $array16 2
(i32.const 10)
(i32.const 20)
)
)
)
(i32.const 0)
(i32.const 1)
)
)
)
;; CHECK: (func $struct-of-string (type $0)
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (struct.new $struct-of-string
;; CHECK-NEXT: (ref.null noextern)
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (struct.new $struct-of-string
;; CHECK-NEXT: (global.get $"string.const_\"value\"")
;; CHECK-NEXT: (i32.const 10)
;; CHECK-NEXT: (ref.null none)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
;; CHECK-NEXT: (drop
;; CHECK-NEXT: (struct.new_default $struct-of-string)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $struct-of-string
;; Test lowering of struct fields from stringref to externref.
(drop
(struct.new $struct-of-string
(ref.null none) ;; This null must be fixed to be ext.
(i32.const 10)
(ref.null none) ;; Nothing to do here (field remains anyref).
)
)
(drop
(struct.new $struct-of-string
(string.const "value") ;; Nothing to do besides change to a global.
(i32.const 10)
(ref.null none)
)
)
(drop
(struct.new_default $struct-of-string) ;; Nothing to do here.
)
)
;; CHECK: (func $call-param-null (type $15) (param $str externref)
;; CHECK-NEXT: (call $call-param-null
;; CHECK-NEXT: (ref.null noextern)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $call-param-null (param $str stringref)
;; After the lowering this null must be an ext.
(call $call-param-null
(ref.null string)
)
)
)
|