Skip to content

Commit 22218b6

Browse files
committed
Ignore descriptor exceptions in binary comparisons
1 parent 65d11bf commit 22218b6

File tree

6 files changed

+34
-30
lines changed

6 files changed

+34
-30
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallBinaryNode.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
7373
protected final String name;
7474
protected final String rname;
7575
protected final Supplier<NotImplementedHandler> handlerFactory;
76+
protected final boolean ignoreDescriptorException;
7677
private final boolean alwaysCheckReverse;
7778

7879
@Child private CallBinaryMethodNode dispatchNode;
@@ -103,36 +104,37 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
103104

104105
public abstract Object executeObject(VirtualFrame frame, Object arg, Object arg2);
105106

106-
LookupAndCallBinaryNode(String name, String rname, Supplier<NotImplementedHandler> handlerFactory, boolean alwaysCheckReverse) {
107+
LookupAndCallBinaryNode(String name, String rname, Supplier<NotImplementedHandler> handlerFactory, boolean alwaysCheckReverse, boolean ignoreDescriptorException) {
107108
this.name = name;
108109
this.rname = rname;
109110
this.handlerFactory = handlerFactory;
110111
this.alwaysCheckReverse = alwaysCheckReverse;
112+
this.ignoreDescriptorException = ignoreDescriptorException;
111113
}
112114

113115
public static LookupAndCallBinaryNode create(String name) {
114-
return LookupAndCallBinaryNodeGen.create(name, null, null, false);
116+
return LookupAndCallBinaryNodeGen.create(name, null, null, false, false);
115117
}
116118

117119
public static LookupAndCallBinaryNode createReversible(String name, String reverseName, Supplier<NotImplementedHandler> handlerFactory) {
118120
assert name.startsWith("__") && reverseName.startsWith("__r");
119-
return LookupAndCallBinaryNodeGen.create(name, reverseName, handlerFactory, false);
121+
return LookupAndCallBinaryNodeGen.create(name, reverseName, handlerFactory, false, false);
120122
}
121123

122124
public static LookupAndCallBinaryNode create(String name, String rname) {
123-
return LookupAndCallBinaryNodeGen.create(name, rname, null, false);
125+
return LookupAndCallBinaryNodeGen.create(name, rname, null, false, false);
124126
}
125127

126-
public static LookupAndCallBinaryNode create(String name, String rname, boolean alwaysCheckReverse) {
127-
return LookupAndCallBinaryNodeGen.create(name, rname, null, alwaysCheckReverse);
128+
public static LookupAndCallBinaryNode create(String name, String rname, boolean alwaysCheckReverse, boolean ignoreDescriptorException) {
129+
return LookupAndCallBinaryNodeGen.create(name, rname, null, alwaysCheckReverse, ignoreDescriptorException);
128130
}
129131

130132
public static LookupAndCallBinaryNode create(String name, String rname, Supplier<NotImplementedHandler> handlerFactory) {
131-
return LookupAndCallBinaryNodeGen.create(name, rname, handlerFactory, false);
133+
return LookupAndCallBinaryNodeGen.create(name, rname, handlerFactory, false, false);
132134
}
133135

134136
protected Object getMethod(Object receiver, String methodName) {
135-
return LookupSpecialMethodNode.Dynamic.getUncached().execute(GetClassNode.getUncached().execute(receiver), methodName, receiver, true);
137+
return LookupSpecialMethodNode.Dynamic.getUncached().execute(GetClassNode.getUncached().execute(receiver), methodName, receiver, ignoreDescriptorException);
136138
}
137139

138140
protected boolean isReversible() {
@@ -285,7 +287,7 @@ protected static boolean isReflectedObject(Object left, Object right, PythonObje
285287
Object callObject(VirtualFrame frame, Object left, Object right,
286288
@SuppressWarnings("unused") @CachedLibrary("left") PythonObjectLibrary libLeft,
287289
@SuppressWarnings("unused") @CachedLibrary("right") PythonObjectLibrary libRight,
288-
@Cached("create(name)") LookupSpecialMethodNode getattr) {
290+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr) {
289291
Object leftCallable = getattr.execute(frame, libLeft.getLazyPythonClass(left), left);
290292
if (leftCallable == PNone.NO_VALUE) {
291293
if (handlerFactory != null) {
@@ -299,8 +301,8 @@ Object callObject(VirtualFrame frame, Object left, Object right,
299301

300302
@Specialization(guards = {"isReversible()", "!isReflectedObject(left, right, libLeft, libRight)"}, limit = "2")
301303
Object callObject(VirtualFrame frame, Object left, Object right,
302-
@Cached("create(name)") LookupSpecialMethodNode getattr,
303-
@Cached("create(rname)") LookupSpecialMethodNode getattrR,
304+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
305+
@Cached("create(rname, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
304306
@CachedLibrary("left") PythonObjectLibrary libLeft,
305307
@CachedLibrary("right") PythonObjectLibrary libRight,
306308
@Cached("create()") TypeNodes.IsSameTypeNode isSameTypeNode,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallTernaryNode.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
6666

6767
protected final String name;
6868
private final boolean isReversible;
69+
protected final boolean ignoreDescriptorException;
6970
@Child private CallTernaryMethodNode dispatchNode = CallTernaryMethodNode.create();
7071
@Child private CallTernaryMethodNode reverseDispatchNode;
7172
@Child private CallTernaryMethodNode thirdDispatchNode;
@@ -79,19 +80,20 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
7980
public abstract Object execute(VirtualFrame frame, Object arg1, int arg2, Object arg3);
8081

8182
public static LookupAndCallTernaryNode create(String name) {
82-
return LookupAndCallTernaryNodeGen.create(name, false, null);
83+
return LookupAndCallTernaryNodeGen.create(name, false, null, false);
8384
}
8485

8586
public static LookupAndCallTernaryNode createReversible(
8687
String name, Supplier<NotImplementedHandler> handlerFactory) {
87-
return LookupAndCallTernaryNodeGen.create(name, true, handlerFactory);
88+
return LookupAndCallTernaryNodeGen.create(name, true, handlerFactory, false);
8889
}
8990

9091
LookupAndCallTernaryNode(
91-
String name, boolean isReversible, Supplier<NotImplementedHandler> handlerFactory) {
92+
String name, boolean isReversible, Supplier<NotImplementedHandler> handlerFactory, boolean ignoreDescriptorException) {
9293
this.name = name;
9394
this.isReversible = isReversible;
9495
this.handlerFactory = handlerFactory;
96+
this.ignoreDescriptorException = ignoreDescriptorException;
9597
}
9698

9799
protected boolean isReversible() {
@@ -133,7 +135,7 @@ private LookupSpecialMethodNode ensureGetAttrZ() {
133135
// this also serves as a branch profile
134136
if (getThirdAttrNode == null) {
135137
CompilerDirectives.transferToInterpreterAndInvalidate();
136-
getThirdAttrNode = insert(LookupSpecialMethodNode.create(name));
138+
getThirdAttrNode = insert(LookupSpecialMethodNode.create(name, ignoreDescriptorException));
137139
}
138140
return getThirdAttrNode;
139141
}
@@ -161,8 +163,8 @@ Object callObject(
161163
Object v,
162164
Object w,
163165
Object z,
164-
@Cached("create(name)") LookupSpecialMethodNode getattr,
165-
@Cached("create(name)") LookupSpecialMethodNode getattrR,
166+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
167+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
166168
@Cached("create()") GetClassNode getClass,
167169
@Cached("create()") GetClassNode getClassR,
168170
@Cached("create()") IsSubtypeNode isSubtype,

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallUnaryNode.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public abstract static class NoAttributeHandler extends PNodeWithContext {
6565
}
6666

6767
protected final String name;
68+
protected final boolean ignoreDescriptorException;
6869
protected final Supplier<NoAttributeHandler> handlerFactory;
6970
@Child private NoAttributeHandler handler;
7071

@@ -93,16 +94,17 @@ public abstract static class NoAttributeHandler extends PNodeWithContext {
9394
public abstract Object executeObject(VirtualFrame frame, Object receiver);
9495

9596
public static LookupAndCallUnaryNode create(String name) {
96-
return LookupAndCallUnaryNodeGen.create(name, null);
97+
return LookupAndCallUnaryNodeGen.create(name, null, false);
9798
}
9899

99100
public static LookupAndCallUnaryNode create(String name, Supplier<NoAttributeHandler> handlerFactory) {
100-
return LookupAndCallUnaryNodeGen.create(name, handlerFactory);
101+
return LookupAndCallUnaryNodeGen.create(name, handlerFactory, false);
101102
}
102103

103-
LookupAndCallUnaryNode(String name, Supplier<NoAttributeHandler> handlerFactory) {
104+
LookupAndCallUnaryNode(String name, Supplier<NoAttributeHandler> handlerFactory, boolean ignoreDescriptorException) {
104105
this.name = name;
105106
this.handlerFactory = handlerFactory;
107+
this.ignoreDescriptorException = ignoreDescriptorException;
106108
}
107109

108110
public String getMethodName() {
@@ -208,7 +210,7 @@ Object callObject(VirtualFrame frame, PNone receiver,
208210
@Specialization(limit = "3")
209211
Object callObject(VirtualFrame frame, Object receiver,
210212
@CachedLibrary("receiver") PythonObjectLibrary lib,
211-
@Cached("create(name)") LookupSpecialMethodNode getattr,
213+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
212214
@Cached("create()") CallUnaryMethodNode dispatchNode) {
213215
Object attr = getattr.execute(frame, lib.getLazyPythonClass(receiver), receiver);
214216
if (attr == PNone.NO_VALUE) {
@@ -236,7 +238,7 @@ static Object doObject(Object receiver, String name,
236238
@Cached LookupSpecialMethodNode.Dynamic getattr,
237239
@Cached CallUnaryMethodNode dispatchNode,
238240
@Cached("createBinaryProfile()") ConditionProfile profile) {
239-
Object attr = getattr.execute(lib.getLazyPythonClass(receiver), name, receiver, true);
241+
Object attr = getattr.execute(lib.getLazyPythonClass(receiver), name, receiver, false);
240242
if (profile.profile(attr != PNone.NO_VALUE)) {
241243
// NOTE: it's safe to pass a 'null' frame since this node can only be used via a
242244
// global state context manager

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupAndCallVarargsNode.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,24 @@
5050

5151
public abstract class LookupAndCallVarargsNode extends Node {
5252
protected final String name;
53+
protected final boolean ignoreDescriptorException;
5354
@Child private CallVarargsMethodNode dispatchNode = CallVarargsMethodNode.create();
5455

5556
public abstract Object execute(VirtualFrame frame, Object callable, Object[] arguments);
5657

5758
public static LookupAndCallVarargsNode create(String name) {
58-
return LookupAndCallVarargsNodeGen.create(name);
59+
return LookupAndCallVarargsNodeGen.create(name, false);
5960
}
6061

61-
LookupAndCallVarargsNode(String name) {
62+
LookupAndCallVarargsNode(String name, boolean ignoreDescriptorException) {
6263
this.name = name;
64+
this.ignoreDescriptorException = ignoreDescriptorException;
6365
}
6466

6567
@Specialization(limit = "3")
6668
Object callObject(VirtualFrame frame, Object callable, Object[] arguments,
6769
@CachedLibrary("callable") PythonObjectLibrary plib,
68-
@Cached("create(name)") LookupSpecialMethodNode getattr) {
70+
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr) {
6971
return dispatchNode.execute(frame, getattr.execute(frame, plib.getLazyPythonClass(callable), callable), arguments, PKeyword.EMPTY_KEYWORDS);
7072
}
7173
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/call/special/LookupSpecialMethodNode.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ public static LookupSpecialMethodNode create(String name, boolean ignoreDescript
8484
return LookupSpecialMethodNodeGen.create(name, ignoreDescriptorException);
8585
}
8686

87-
public static LookupSpecialMethodNode create(String name) {
88-
return LookupSpecialMethodNodeGen.create(name, true);
89-
}
90-
9187
public static class BoundDescriptor {
9288
public final Object descriptor;
9389

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/expression/BinaryComparisonNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public abstract class BinaryComparisonNode extends BinaryOpNode {
5757
this.magicReverseMethod = magicReverseMethod;
5858
this.operation = operation;
5959
// see cpython://Objects/object.c#do_richcompare - CPython always calls the reverse method
60-
this.callNode = LookupAndCallBinaryNode.create(magicMethod, magicReverseMethod, true);
60+
this.callNode = LookupAndCallBinaryNode.create(magicMethod, magicReverseMethod, true, true);
6161
}
6262

6363
public static BinaryComparisonNode create(String magicMethod, String magicReverseMethod, String operation, ExpressionNode left, ExpressionNode right) {

0 commit comments

Comments
 (0)