summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/ion/recover-rest.js
blob: 11bfde7ff4e3a4c8b2c645cf4093c41275377e5f (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
// Prevent GC from cancelling/discarding Ion compilations.
gczeal(0);

// This function is used to force a bailout when it is inlined, and to recover
// the frame which is inlining this function.
var resumeHere = function (i) { if (i >= 99) bailout(); };

// This function is used to cause an invalidation after having removed a branch
// after DCE. This is made to check if we correctly recover an array
// allocation.
var uceFault = function (i) {
  if (i > 98)
    uceFault = function (i) { return true; };
  return false;
};

function empty() {}

var globalArgs;
function escape(args) { globalArgs = args; }

// Check rest array length.
function length(i, ...rest) {
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function lengthBail(i, ...rest) {
  resumeHere(i);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

// Check rest array content.
function content(...rest) {
  assertEq(rest[0], rest[1]);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function contentBail(...rest) {
  resumeHere(rest[0]);
  assertEq(rest[0], rest[1]);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function contentExtraFormals(i, ...rest) {
  assertEq(rest[0], i);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}
function contentExtraFormalsBail(i, ...rest) {
  resumeHere(i);
  assertEq(rest[0], i);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

// No scalar replacement when the rest array is modified.
function setLength(i, ...rest) {
  rest.length = 0;
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function setLengthBail(i, ...rest) {
  resumeHere(i);
  rest.length = 0;
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function setContent(i, ...rest) {
  rest[0] = "bad";
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function setContentBail(i, ...rest) {
  resumeHere(i);
  rest[0] = "bad";
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function deleteContent(i, ...rest) {
  delete rest[0];
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function deleteContentBail(i, ...rest) {
  resumeHere(i);
  delete rest[0];
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

// No scalar replacement when the rest array escapes.
function escapes(i, ...rest) {
  escape(rest);
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function escapesBail(i, ...rest) {
  resumeHere(i);
  escape(rest);
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

// Check rest array with Function.prototype.apply.
function apply(...rest) {
  empty.apply(null, rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function applyBail(...rest) {
  resumeHere(rest[0]);
  empty.apply(null, rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function applyExtraFormals(i, ...rest) {
  empty.apply(null, rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function applyExtraFormalsBail(i, ...rest) {
  resumeHere(i);
  empty.apply(null, rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

// Check rest array with spread.
function spread(...rest) {
  empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function spreadBail(...rest) {
  resumeHere(rest[0]);
  empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function spreadExtraFormals(i, ...rest) {
  empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function spreadExtraFormalsBail(i, ...rest) {
  resumeHere(i);
  empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

// Extra args currently not supported.
function spreadExtraArgs(...rest) {
  empty(0, ...rest);
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function spreadExtraArgsBail(...rest) {
  resumeHere(rest[0]);
  empty(0, ...rest);
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

// Check rest array with new spread.
function newSpread(...rest) {
  new empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function newSpreadBail(...rest) {
  resumeHere(rest[0]);
  new empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function newSpreadExtraFormals(i, ...rest) {
  new empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function newSpreadExtraFormalsBail(i, ...rest) {
  resumeHere(i);
  new empty(...rest);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

// Extra args currently not supported.
function newSpreadExtraArgs(...rest) {
  new empty(0, ...rest);
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

function newSpreadExtraArgsBail(...rest) {
  resumeHere(rest[0]);
  new empty(0, ...rest);
  assertRecoveredOnBailout(rest, false);
  return rest.length;
}

// The arguments object isn't mapped.
function setArgs(i, ...rest) {
  arguments[1] = "fail";
  assertEq(rest[0], i);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

function setArgsBail(i, ...rest) {
  resumeHere(i);
  arguments[1] = "fail";
  assertEq(rest[0], i);
  assertRecoveredOnBailout(rest, true);
  return rest.length;
}

// Check that we correctly allocate the array after taking the recover path.
var uceFault_recoverLength = eval(`(${uceFault})`.replace('uceFault', 'uceFault_recoverLength'));
function recoverLength(i, ...rest) {
  if (uceFault_recoverLength(i) || uceFault_recoverLength(i)) {
    return rest.length;
  }
  assertRecoveredOnBailout(rest, true);
  return 0;
}

var uceFault_recoverContent = eval(`(${uceFault})`.replace('uceFault', 'uceFault_recoverContent'));
function recoverContent(i, ...rest) {
  if (uceFault_recoverContent(i) || uceFault_recoverContent(i)) {
    return rest[0];
  }
  assertRecoveredOnBailout(rest, true);
  return 0;
}

var uceFault_recoverApply = eval(`(${uceFault})`.replace('uceFault', 'uceFault_recoverApply'));
function recoverApply(i, ...rest) {
  if (uceFault_recoverApply(i) || uceFault_recoverApply(i)) {
    return empty.apply(null, rest);
  }
  assertRecoveredOnBailout(rest, true);
  return 0;
}

var uceFault_recoverSpread = eval(`(${uceFault})`.replace('uceFault', 'uceFault_recoverSpread'));
function recoverSpread(i, ...rest) {
  if (uceFault_recoverSpread(i) || uceFault_recoverSpread(i)) {
    return empty(...rest);
  }
  assertRecoveredOnBailout(rest, true);
  return 0;
}

var uceFault_recoverNewSpread = eval(`(${uceFault})`.replace('uceFault', 'uceFault_recoverNewSpread'));
function recoverNewSpread(i, ...rest) {
  if (uceFault_recoverNewSpread(i) || uceFault_recoverNewSpread(i)) {
    return new empty(...rest);
  }
  assertRecoveredOnBailout(rest, true);
  return 0;
}

var uceFault_recoverSetArgs = eval(`(${uceFault})`.replace('uceFault', 'uceFault_recoverSetArgs'));
function recoverSetArgs(i, ...rest) {
  arguments[1] = "fail";
  if (uceFault_recoverSetArgs(i) || uceFault_recoverSetArgs(i)) {
    // Ensure arguments[1] isn't mapped to rest[0].
    assertEq(rest[0], "ok");
    return 0;
  }
  assertRecoveredOnBailout(rest, true);
  return 0;
}

// Prevent compilation of the top-level
eval(`(${resumeHere})`);

for (let i = 0; i < 100; i++) {
  length(i);
  lengthBail(i);
  content(i, i);
  contentBail(i, i);
  contentExtraFormals(i, i);
  contentExtraFormalsBail(i, i);
  setLength(i);
  setLengthBail(i);
  setContent(i, i);
  setContentBail(i, i);
  deleteContent(i, i);
  deleteContentBail(i, i);
  escapes(i);
  escapesBail(i);
  apply(i);
  applyBail(i);
  applyExtraFormals(i);
  applyExtraFormalsBail(i);
  spread(i);
  spreadBail(i);
  spreadExtraFormals(i);
  spreadExtraFormalsBail(i);
  spreadExtraArgs(i);
  spreadExtraArgsBail(i);
  newSpread(i);
  newSpreadBail(i);
  newSpreadExtraFormals(i);
  newSpreadExtraFormalsBail(i);
  newSpreadExtraArgs(i);
  newSpreadExtraArgsBail(i);
  setArgs(i, i);
  setArgsBail(i, i);

  recoverLength(i);
  recoverContent(i);
  recoverApply(i);
  recoverSpread(i);
  recoverNewSpread(i);
  recoverSetArgs(i, "ok");
}