blob: 2feedcb397fee695f523881b2ef8c516ce23b37b (
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
|
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.
;; RUN: foreach %s %t wasm-opt --string-lowering -all -S -o - | filecheck %s
(module
(rec
;; CHECK: (type $0 (array (mut i16)))
;; CHECK: (type $1 (func))
;; CHECK: (type $2 (func (param externref externref) (result i32)))
;; CHECK: (rec
;; CHECK-NEXT: (type $3 (func (param externref i32 externref)))
;; CHECK: (type $4 (func (result externref)))
;; CHECK: (type $struct-of-array (struct (field (ref $0))))
(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 $11 (func (param externref) (result externref)))
;; CHECK: (type $12 (func (param externref) (result externref)))
;; CHECK: (type $13 (func (param externref) (result i32)))
;; CHECK: (type $14 (func (param externref externref) (result i32)))
;; CHECK: (type $15 (func (param externref (ref $0)) (result i32)))
;; CHECK: (type $16 (func (param (ref $0))))
;; CHECK: (type $17 (func (param externref externref externref externref)))
;; CHECK: (type $18 (func (param (ref null $0) i32 i32) (result (ref extern))))
;; CHECK: (type $19 (func (param i32) (result (ref extern))))
;; CHECK: (type $20 (func (param externref (ref null $0) i32) (result i32)))
;; CHECK: (type $21 (func (param externref) (result i32)))
;; CHECK: (type $22 (func (param externref i32) (result i32)))
;; CHECK: (type $23 (func (param externref i32 i32) (result (ref extern))))
;; CHECK: (import "string.const" "0" (global $string.const_exported (ref extern)))
;; CHECK: (import "colliding" "name" (func $fromCodePoint (type $1)))
(import "colliding" "name" (func $fromCodePoint))
;; CHECK: (import "wasm:js-string" "fromCharCodeArray" (func $fromCharCodeArray (type $18) (param (ref null $0) i32 i32) (result (ref extern))))
;; CHECK: (import "wasm:js-string" "fromCodePoint" (func $fromCodePoint_16 (type $19) (param i32) (result (ref extern))))
;; CHECK: (import "wasm:js-string" "intoCharCodeArray" (func $intoCharCodeArray (type $20) (param externref (ref null $0) i32) (result i32)))
;; CHECK: (import "wasm:js-string" "equals" (func $equals (type $2) (param externref externref) (result i32)))
;; CHECK: (import "wasm:js-string" "compare" (func $compare (type $2) (param externref externref) (result i32)))
;; CHECK: (import "wasm:js-string" "length" (func $length (type $21) (param externref) (result i32)))
;; CHECK: (import "wasm:js-string" "codePointAt" (func $codePointAt (type $22) (param externref i32) (result i32)))
;; CHECK: (import "wasm:js-string" "substring" (func $substring (type $23) (param externref i32 i32) (result (ref extern))))
;; CHECK: (export "export.1" (func $exported-string-returner))
;; CHECK: (export "export.2" (func $exported-string-receiver))
;; CHECK: (func $string.as (type $17) (param $a externref) (param $b externref) (param $c externref) (param $d externref)
;; CHECK-NEXT: (local.set $b
;; CHECK-NEXT: (local.get $a)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $c
;; CHECK-NEXT: (local.get $a)
;; CHECK-NEXT: )
;; CHECK-NEXT: (local.set $d
;; CHECK-NEXT: (local.get $a)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.as
(param $a stringref)
(param $b stringview_wtf8)
(param $c stringview_wtf16)
(param $d stringview_iter)
;; These operations all vanish in the lowering, as they all become extref
;; (JS strings).
(local.set $b
(string.as_wtf8
(local.get $a)
)
)
(local.set $c
(string.as_wtf16
(local.get $a)
)
)
(local.set $d
(string.as_iter
(local.get $a)
)
)
)
;; CHECK: (func $string.new.gc (type $16) (param $array16 (ref $0))
;; 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 $4) (result externref)
;; CHECK-NEXT: (call $fromCodePoint_16
;; 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.encode (type $15) (param $ref externref) (param $array16 (ref $0)) (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 $14) (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 $14) (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 stringview_wtf16) (result i32)
(stringview_wtf16.length
(local.get $ref)
)
)
;; CHECK: (func $string.get_codeunit (type $13) (param $ref externref) (result i32)
;; CHECK-NEXT: (call $codePointAt
;; CHECK-NEXT: (local.get $ref)
;; CHECK-NEXT: (i32.const 2)
;; CHECK-NEXT: )
;; CHECK-NEXT: )
(func $string.get_codeunit (param $ref stringview_wtf16) (result i32)
(stringview_wtf16.get_codeunit
(local.get $ref)
(i32.const 2)
)
)
;; CHECK: (func $string.slice (type $12) (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 stringview_wtf16) (result stringref)
(stringview_wtf16.slice
(local.get $ref)
(i32.const 2)
(i32.const 3)
)
)
;; CHECK: (func $if.string (type $11) (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 $11) (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 $4) (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 $3) (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 $1)
;; CHECK-NEXT: (local $array16 (ref $0))
;; 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 $0 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)
)
)
)
)
|