Skip to content

Commit e5bb3c2

Browse files
committed
[GR-52203] Fix UnsupportedSpecializationException in richcompare nodes.
PullRequest: graalpython/3208
2 parents 2e064e5 + e48aa64 commit e5bb3c2

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ints/IntBuiltins.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
import com.oracle.graal.python.builtins.objects.ints.IntBuiltinsClinicProviders.FormatNodeClinicProviderGen;
124124
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
125125
import com.oracle.graal.python.builtins.objects.type.PythonBuiltinClass;
126+
import com.oracle.graal.python.lib.PyLongCheckNode;
126127
import com.oracle.graal.python.lib.PyNumberFloatNode;
127128
import com.oracle.graal.python.lib.PyObjectHashNode;
128129
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -2648,8 +2649,13 @@ abstract static class RichCompareNode extends PythonTernaryBuiltinNode {
26482649
@Specialization(guards = {"opCode == cachedOp.opCode"}, limit = "6")
26492650
static Object doCached(Object left, Object right, @SuppressWarnings("unused") int opCode,
26502651
@Bind("this") Node inliningTarget,
2652+
@Cached PyLongCheckNode checkLeft,
2653+
@Cached PyLongCheckNode checkRight,
26512654
@SuppressWarnings("unused") @Cached("fromOpCode(opCode)") ComparisonOp cachedOp,
26522655
@Cached RichCompareHelperNode cmpNode) {
2656+
if (!checkLeft.execute(inliningTarget, left) || !checkRight.execute(inliningTarget, right)) {
2657+
return PNotImplemented.NOT_IMPLEMENTED;
2658+
}
26532659
return cmpNode.execute(inliningTarget, left, right, cachedOp);
26542660
}
26552661
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/StringBuiltins.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
136136
import com.oracle.graal.python.lib.PyObjectGetItem;
137137
import com.oracle.graal.python.lib.PyObjectHashNode;
138+
import com.oracle.graal.python.lib.PyUnicodeCheckNode;
138139
import com.oracle.graal.python.nodes.ErrorMessages;
139140
import com.oracle.graal.python.nodes.PGuards;
140141
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -515,15 +516,25 @@ abstract static class RichCompareNode extends PythonTernaryBuiltinNode {
515516
@Specialization(guards = "isEqualityOpCode(opCode)")
516517
static Object doEqNeOp(Object left, Object right, int opCode,
517518
@Bind("this") Node inliningTarget,
519+
@Exclusive @Cached PyUnicodeCheckNode checkLeft,
520+
@Exclusive @Cached PyUnicodeCheckNode checkRight,
518521
@Cached StringEqOpHelperNode stringEqOpHelperNode) {
522+
if (!checkLeft.execute(inliningTarget, left) || !checkRight.execute(inliningTarget, right)) {
523+
return PNotImplemented.NOT_IMPLEMENTED;
524+
}
519525
return stringEqOpHelperNode.execute(inliningTarget, left, right, opCode == ComparisonOp.NE.opCode);
520526
}
521527

522528
@Specialization(guards = {"opCode == cachedOp.opCode", "!isEqualityOpCode(opCode)"}, limit = "4")
523529
static Object doRelOp(Object left, Object right, @SuppressWarnings("unused") int opCode,
524530
@Bind("this") Node inliningTarget,
531+
@Exclusive @Cached PyUnicodeCheckNode checkLeft,
532+
@Exclusive @Cached PyUnicodeCheckNode checkRight,
525533
@Cached("fromOpCode(opCode)") ComparisonOp cachedOp,
526534
@Cached StringCmpOpHelperNode stringCmpOpHelperNode) {
535+
if (!checkLeft.execute(inliningTarget, left) || !checkRight.execute(inliningTarget, right)) {
536+
return PNotImplemented.NOT_IMPLEMENTED;
537+
}
527538
return stringCmpOpHelperNode.execute(inliningTarget, left, right, cachedOp.intPredicate);
528539
}
529540
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/tuple/TupleBuiltins.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import com.oracle.truffle.api.HostCompilerDirectives.InliningCutoff;
108108
import com.oracle.truffle.api.dsl.Bind;
109109
import com.oracle.truffle.api.dsl.Cached;
110+
import com.oracle.truffle.api.dsl.Cached.Exclusive;
110111
import com.oracle.truffle.api.dsl.Cached.Shared;
111112
import com.oracle.truffle.api.dsl.Fallback;
112113
import com.oracle.truffle.api.dsl.GenerateCached;
@@ -419,21 +420,26 @@ abstract static class RichCompareNode extends PythonTernaryBuiltinNode {
419420
@Specialization(guards = {"opCode == cachedOp.opCode"}, limit = "6")
420421
static Object doPTuple(VirtualFrame frame, PTuple left, PTuple right, @SuppressWarnings("unused") int opCode,
421422
@SuppressWarnings("unused") @Cached("fromOpCode(opCode)") ComparisonOp cachedOp,
422-
@Cached("createCmpNode(cachedOp)") SequenceStorageNodes.CmpNode cmpNode) {
423+
@Exclusive @Cached("createCmpNode(cachedOp)") SequenceStorageNodes.CmpNode cmpNode) {
423424
return cmpNode.execute(frame, left.getSequenceStorage(), right.getSequenceStorage());
424425
}
425426

426-
@Specialization(guards = {"opCode == cachedOp.opCode", "checkRight.execute(inliningTarget, right)"}, limit = "6", replaces = "doPTuple")
427-
static Object doRelOp(VirtualFrame frame, Object left, Object right, @SuppressWarnings("unused") int opCode,
427+
@Specialization(guards = {"opCode == cachedOp.opCode"}, limit = "6", replaces = "doPTuple")
428+
static Object doGeneric(VirtualFrame frame, Object left, Object right, @SuppressWarnings("unused") int opCode,
428429
@Bind("this") Node inliningTarget,
429430
@SuppressWarnings("unused") @Cached("fromOpCode(opCode)") ComparisonOp cachedOp,
430-
@SuppressWarnings("unused") @Cached PyTupleCheckNode checkRight,
431+
@Cached PyTupleCheckNode checkLeft,
432+
@Cached PyTupleCheckNode checkRight,
431433
@Cached GetTupleStorage getLeft,
432434
@Cached GetTupleStorage getRight,
433-
@Cached("createCmpNode(cachedOp)") SequenceStorageNodes.CmpNode cmpNode) {
435+
@Exclusive @Cached("createCmpNode(cachedOp)") SequenceStorageNodes.CmpNode cmpNode) {
436+
if (!checkLeft.execute(inliningTarget, left) || !checkRight.execute(inliningTarget, right)) {
437+
return PNotImplemented.NOT_IMPLEMENTED;
438+
}
434439
return cmpNode.execute(frame, getLeft.execute(inliningTarget, left), getRight.execute(inliningTarget, right));
435440
}
436441

442+
@NeverDefault
437443
static SequenceStorageNodes.CmpNode createCmpNode(ComparisonOp op) {
438444
switch (op) {
439445
case LE:

0 commit comments

Comments
 (0)