Skip to content

Commit 0715c86

Browse files
committed
Undecided Arrays shouldn't need to be OriginalArray to covert to GetArrayLength
https://bugs.webkit.org/show_bug.cgi?id=211914 Reviewed by Saam Barati. JSTests: * stress/undecided-arrays-should-not-need-original-array-for-length.js: Added. (findFoo): (const.nonUndecidedFrequency.1000.SubArray): (i.i.some): Source/JavaScriptCore: Also, fix a bug that arrayModesThatPassFiltering() can't handle Undecided arrays. Because we can now emit a CheckArray on Undecided AI will try to figure out what types flow out of the check. Since Undecided was unhandled by filtering, AI will assume bottom is the only possible value and the DFG/FTL will insert a breakpoint, causing a crash. * dfg/DFGArrayMode.cpp: (JSC::DFG::ArrayMode::refine const): * dfg/DFGArrayMode.h: (JSC::DFG::ArrayMode::arrayModesThatPassFiltering const): Canonical link: https://commits.webkit.org/224819@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@261725 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 0fc981e commit 0715c86

5 files changed

Lines changed: 55 additions & 1 deletion

File tree

‎JSTests/ChangeLog‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
2020-05-14 Keith Miller <keith_miller@apple.com>
2+
3+
Undecided Arrays shouldn't need to be OriginalArray to covert to GetArrayLength
4+
https://bugs.webkit.org/show_bug.cgi?id=211914
5+
6+
Reviewed by Saam Barati.
7+
8+
* stress/undecided-arrays-should-not-need-original-array-for-length.js: Added.
9+
(findFoo):
10+
(const.nonUndecidedFrequency.1000.SubArray):
11+
(i.i.some):
12+
113
2020-05-14 Keith Miller <keith_miller@apple.com>
214

315
GetArrayLength should be "blessed" during Fixup phase in the DFG
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
function findFoo(name, array, bail) {
2+
let some = array.some
3+
if (bail)
4+
return;
5+
some.call(array, function (v) {
6+
return v === name;
7+
});
8+
}
9+
noInline(findFoo);
10+
11+
class SubArray extends Array {}
12+
for (let i = 0; i < 1e5; ++i) {
13+
let array = i % 2 ? new SubArray(0) : ["foo"];
14+
findFoo("foo", array, array.length);
15+
for (let i = 0; i < 100; ++i)
16+
[].some(function (v) { });
17+
}

‎Source/JavaScriptCore/ChangeLog‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
2020-05-14 Keith Miller <keith_miller@apple.com>
2+
3+
Undecided Arrays shouldn't need to be OriginalArray to covert to GetArrayLength
4+
https://bugs.webkit.org/show_bug.cgi?id=211914
5+
6+
Reviewed by Saam Barati.
7+
8+
Also, fix a bug that arrayModesThatPassFiltering() can't handle
9+
Undecided arrays. Because we can now emit a CheckArray on
10+
Undecided AI will try to figure out what types flow out of the
11+
check. Since Undecided was unhandled by filtering, AI will assume
12+
bottom is the only possible value and the DFG/FTL will insert a
13+
breakpoint, causing a crash.
14+
15+
* dfg/DFGArrayMode.cpp:
16+
(JSC::DFG::ArrayMode::refine const):
17+
* dfg/DFGArrayMode.h:
18+
(JSC::DFG::ArrayMode::arrayModesThatPassFiltering const):
19+
120
2020-05-14 Keith Miller <keith_miller@apple.com>
221

322
GetArrayLength should be "blessed" during Fixup phase in the DFG

‎Source/JavaScriptCore/dfg/DFGArrayMode.cpp‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,16 @@ ArrayMode ArrayMode::refine(
242242
return withTypeAndConversion(Array::Double, Array::Convert);
243243
return withTypeAndConversion(Array::Contiguous, Array::Convert);
244244
case Array::Undecided: {
245+
// As long as we have a JSArray getting its length shouldn't require any sane chainness.
246+
if (canBecomeGetArrayLength(graph, node) && isJSArray())
247+
return *this;
248+
245249
// If we have an OriginalArray and the JSArray prototype chain is sane,
246250
// any indexed access always return undefined. We have a fast path for that.
247251
JSGlobalObject* globalObject = graph.globalObjectFor(node->origin.semantic);
248252
Structure* arrayPrototypeStructure = globalObject->arrayPrototype()->structure(graph.m_vm);
249253
Structure* objectPrototypeStructure = globalObject->objectPrototype()->structure(graph.m_vm);
250-
if ((node->op() == GetByVal || canBecomeGetArrayLength(graph, node))
254+
if (node->op() == GetByVal
251255
&& isJSArrayWithOriginalStructure()
252256
&& !graph.hasExitSite(node->origin.semantic, OutOfBounds)
253257
&& arrayPrototypeStructure->transitionWatchpointSetIsStillValid()

‎Source/JavaScriptCore/dfg/DFGArrayMode.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ class ArrayMode {
430430
switch (type()) {
431431
case Array::Generic:
432432
return ALL_ARRAY_MODES;
433+
case Array::Undecided:
434+
return arrayModesWithIndexingShapes(UndecidedShape);
433435
case Array::Int32:
434436
result = arrayModesWithIndexingShapes(Int32Shape);
435437
break;

0 commit comments

Comments
 (0)