Skip to content

Commit 3a53a9d

Browse files
committed
Remove LookupSpecialMethodNode.ignoreDescriptorException
1 parent 05c84e3 commit 3a53a9d

File tree

11 files changed

+83
-82
lines changed

11 files changed

+83
-82
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,7 @@ private static int length(SequenceStorage storage, GetInternalObjectArrayNode ge
11171117

11181118
private static Object getSlotsFromDict(Object type, LookupSpecialMethodNode.Dynamic lookupGetAttribute, CallBinaryMethodNode callGetAttr,
11191119
GetClassNode getClassNode, HashingStorageLibrary lib) {
1120-
Object getAttr = lookupGetAttribute.execute(null, getClassNode.execute(type), __GETATTRIBUTE__, type, false);
1120+
Object getAttr = lookupGetAttribute.execute(null, getClassNode.execute(type), __GETATTRIBUTE__, type);
11211121
Object dict = callGetAttr.executeObject(getAttr, type, __DICT__);
11221122
if (dict != PNone.NO_VALUE) {
11231123
if (dict instanceof PMappingproxy) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyFloatAsDoubleNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ static double doObject(VirtualFrame frame, Object object,
117117
@Cached WarningsModuleBuiltins.WarnNode warnNode,
118118
@Cached PRaiseNode raiseNode) {
119119
Object type = getClassNode.execute(object);
120-
Object floatDescr = lookup.execute(frame, type, __FLOAT__, object, false);
120+
Object floatDescr = lookup.execute(frame, type, __FLOAT__, object);
121121
if (floatDescr != PNone.NO_VALUE) {
122122
Object result = call.executeObject(frame, floatDescr, object);
123123
Object resultType = resultClassNode.execute(result);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyLongAsLongAndOverflowNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ long doObject(VirtualFrame frame, Object object,
112112
@Cached PRaiseNode raiseNode,
113113
@Cached PyLongAsLongAndOverflowNode recursive) throws OverflowException {
114114
Object type = getClassNode.execute(object);
115-
Object indexDescr = lookupIndex.execute(frame, type, __INDEX__, object, false);
115+
Object indexDescr = lookupIndex.execute(frame, type, __INDEX__, object);
116116
Object result = null;
117117
if (indexDescr != PNone.NO_VALUE) {
118118
result = call.executeObject(frame, indexDescr, object);
119119
checkResult(frame, object, result, resultClassNode, resultSubtype, resultIsInt, raiseNode, warnNode, __INDEX__);
120120
}
121-
Object intDescr = lookupInt.execute(frame, type, __INT__, object, false);
121+
Object intDescr = lookupInt.execute(frame, type, __INT__, object);
122122
if (intDescr != PNone.NO_VALUE) {
123123
result = call.executeObject(frame, intDescr, object);
124124
checkResult(frame, object, result, resultClassNode, resultSubtype, resultIsInt, raiseNode, warnNode, __INT__);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/lib/PyNumberFloatNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static double doObject(VirtualFrame frame, Object object,
110110
@Cached WarningsModuleBuiltins.WarnNode warnNode,
111111
@Cached PRaiseNode raiseNode,
112112
@Cached PyFloatFromString fromString) {
113-
Object floatDescr = lookup.execute(frame, getClassNode.execute(object), __FLOAT__, object, false);
113+
Object floatDescr = lookup.execute(frame, getClassNode.execute(object), __FLOAT__, object);
114114
if (floatDescr != PNone.NO_VALUE) {
115115
Object result = call.executeObject(frame, floatDescr, object);
116116
Object resultType = resultClassNode.execute(result);

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

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
6262
import com.oracle.graal.python.nodes.object.GetClassNode;
6363
import com.oracle.graal.python.runtime.PythonOptions;
64+
import com.oracle.graal.python.runtime.exception.PException;
6465
import com.oracle.graal.python.util.Supplier;
6566
import com.oracle.truffle.api.CompilerDirectives;
6667
import com.oracle.truffle.api.dsl.Cached;
@@ -174,7 +175,7 @@ public static LookupAndCallBinaryNode create(String name, String rname, Supplier
174175
}
175176

176177
protected Object getMethod(Object receiver, String methodName) {
177-
return LookupSpecialMethodNode.Dynamic.getUncached().execute(null, GetClassNode.getUncached().execute(receiver), methodName, receiver, ignoreDescriptorException);
178+
return LookupSpecialMethodNode.Dynamic.getUncached().execute(null, GetClassNode.getUncached().execute(receiver), methodName, receiver);
178179
}
179180

180181
protected boolean isReversible() {
@@ -217,7 +218,17 @@ private CallBinaryMethodNode ensureReverseDispatch() {
217218

218219
private UnexpectedResultException handleLeftURE(VirtualFrame frame, Object left, Object right, UnexpectedResultException e) throws UnexpectedResultException {
219220
if (isReversible() && e.getResult() == PNotImplemented.NOT_IMPLEMENTED) {
220-
throw new UnexpectedResultException(ensureReverseDispatch().executeObject(frame, getMethod(right, rname), right, left));
221+
Object method;
222+
try {
223+
method = getMethod(right, rname);
224+
} catch (PException e1) {
225+
if (ignoreDescriptorException) {
226+
throw e;
227+
} else {
228+
throw e1;
229+
}
230+
}
231+
throw new UnexpectedResultException(ensureReverseDispatch().executeObject(frame, method, right, left));
221232
} else {
222233
throw e;
223234
}
@@ -392,21 +403,30 @@ Object callObjectGeneric(VirtualFrame frame, Object left, Object right,
392403
@SuppressWarnings("unused") @Cached("left.getClass()") Class<?> cachedLeftClass,
393404
@SuppressWarnings("unused") @Cached("right.getClass()") Class<?> cachedRightClass,
394405
@Cached GetClassNode getClassNode,
395-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr) {
406+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr) {
396407
return doCallObject(frame, left, right, getClassNode, getattr);
397408
}
398409

399410
@Specialization(guards = "!isReversible()", replaces = "callObjectGeneric")
400411
@Megamorphic
401412
Object callObjectMegamorphic(VirtualFrame frame, Object left, Object right,
402413
@Cached GetClassNode getClassNode,
403-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr) {
414+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr) {
404415
return doCallObject(frame, left, right, getClassNode, getattr);
405416
}
406417

407418
private Object doCallObject(VirtualFrame frame, Object left, Object right, GetClassNode getClassNode, LookupSpecialMethodSlotNode getattr) {
408419
Object leftClass = getClassNode.execute(left);
409-
Object leftCallable = getattr.execute(frame, leftClass, left);
420+
Object leftCallable;
421+
try {
422+
leftCallable = getattr.execute(frame, leftClass, left);
423+
} catch (PException e) {
424+
if (ignoreDescriptorException) {
425+
leftCallable = PNone.NO_VALUE;
426+
} else {
427+
throw e;
428+
}
429+
}
410430
if (leftCallable == PNone.NO_VALUE) {
411431
if (handlerFactory != null) {
412432
return runErrorHandler(frame, left, right);
@@ -421,8 +441,8 @@ private Object doCallObject(VirtualFrame frame, Object left, Object right, GetCl
421441
Object callObjectGenericR(VirtualFrame frame, Object left, Object right,
422442
@SuppressWarnings("unused") @Cached("left.getClass()") Class<?> cachedLeftClass,
423443
@SuppressWarnings("unused") @Cached("right.getClass()") Class<?> cachedRightClass,
424-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
425-
@Cached("create(rname, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
444+
@Cached("create(name)") LookupSpecialMethodNode getattr,
445+
@Cached("create(rname)") LookupSpecialMethodNode getattrR,
426446
@Cached GetClassNode getLeftClassNode,
427447
@Cached GetClassNode getRightClassNode,
428448
@Cached TypeNodes.IsSameTypeNode isSameTypeNode,
@@ -441,8 +461,8 @@ Object callObjectGenericR(VirtualFrame frame, Object left, Object right,
441461
@Specialization(guards = "isReversible()", replaces = "callObjectGenericR")
442462
@Megamorphic
443463
Object callObjectRMegamorphic(VirtualFrame frame, Object left, Object right,
444-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
445-
@Cached("create(rname, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
464+
@Cached("create(name)") LookupSpecialMethodNode getattr,
465+
@Cached("create(rname)") LookupSpecialMethodNode getattrR,
446466
@Cached GetClassNode getLeftClassNode,
447467
@Cached GetClassNode getRightClassNode,
448468
@Cached TypeNodes.IsSameTypeNode isSameTypeNode,
@@ -474,9 +494,27 @@ private Object doCallObjectR(VirtualFrame frame, Object left, Object right, Look
474494

475495
Object result = PNotImplemented.NOT_IMPLEMENTED;
476496
Object leftClass = getLeftClassNode.execute(left);
477-
Object leftCallable = getattr.execute(frame, leftClass, left);
497+
Object leftCallable;
498+
try {
499+
leftCallable = getattr.execute(frame, leftClass, left);
500+
} catch (PException e) {
501+
if (ignoreDescriptorException) {
502+
leftCallable = PNone.NO_VALUE;
503+
} else {
504+
throw e;
505+
}
506+
}
478507
Object rightClass = getRightClassNode.execute(right);
479-
Object rightCallable = getattrR.execute(frame, rightClass, right);
508+
Object rightCallable;
509+
try {
510+
rightCallable = getattrR.execute(frame, rightClass, right);
511+
} catch (PException e) {
512+
if (ignoreDescriptorException) {
513+
rightCallable = PNone.NO_VALUE;
514+
} else {
515+
throw e;
516+
}
517+
}
480518

481519
if (!alwaysCheckReverse && leftCallable == rightCallable) {
482520
rightCallable = PNone.NO_VALUE;

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

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
6868

6969
protected final String name;
7070
private final boolean isReversible;
71-
protected final boolean ignoreDescriptorException;
7271
@Child private CallTernaryMethodNode dispatchNode = CallTernaryMethodNode.create();
7372
@Child private CallTernaryMethodNode reverseDispatchNode;
7473
@Child private CallTernaryMethodNode thirdDispatchNode;
@@ -82,18 +81,17 @@ public abstract static class NotImplementedHandler extends PNodeWithContext {
8281
public abstract Object execute(VirtualFrame frame, Object arg1, int arg2, Object arg3);
8382

8483
public static LookupAndCallTernaryNode create(String name) {
85-
return LookupAndCallTernaryNodeGen.create(name, false, null, false);
84+
return LookupAndCallTernaryNodeGen.create(name, false, null);
8685
}
8786

8887
public static LookupAndCallTernaryNode createReversible(String name, Supplier<NotImplementedHandler> handlerFactory) {
89-
return LookupAndCallTernaryNodeGen.create(name, true, handlerFactory, false);
88+
return LookupAndCallTernaryNodeGen.create(name, true, handlerFactory);
9089
}
9190

92-
LookupAndCallTernaryNode(String name, boolean isReversible, Supplier<NotImplementedHandler> handlerFactory, boolean ignoreDescriptorException) {
91+
LookupAndCallTernaryNode(String name, boolean isReversible, Supplier<NotImplementedHandler> handlerFactory) {
9392
this.name = name;
9493
this.isReversible = isReversible;
9594
this.handlerFactory = handlerFactory;
96-
this.ignoreDescriptorException = ignoreDescriptorException;
9795
}
9896

9997
protected boolean isReversible() {
@@ -104,7 +102,7 @@ protected boolean isReversible() {
104102
Object callObject(VirtualFrame frame, Object arg1, int arg2, Object arg3,
105103
@SuppressWarnings("unused") @Cached("arg1.getClass()") Class<?> cachedArg1Class,
106104
@Cached GetClassNode getClassNode,
107-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr) {
105+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr) {
108106
Object klass = getClassNode.execute(arg1);
109107
return dispatchNode.execute(frame, getattr.execute(frame, klass, arg1), arg1, arg2, arg3);
110108
}
@@ -113,7 +111,7 @@ Object callObject(VirtualFrame frame, Object arg1, int arg2, Object arg3,
113111
Object callObject(VirtualFrame frame, Object arg1, Object arg2, Object arg3,
114112
@SuppressWarnings("unused") @Cached("arg1.getClass()") Class<?> cachedArg1Class,
115113
@Cached GetClassNode getClassNode,
116-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr) {
114+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr) {
117115
Object klass = getClassNode.execute(arg1);
118116
return dispatchNode.execute(frame, getattr.execute(frame, klass, arg1), arg1, arg2, arg3);
119117
}
@@ -122,7 +120,7 @@ Object callObject(VirtualFrame frame, Object arg1, Object arg2, Object arg3,
122120
@Megamorphic
123121
Object callObjectMegamorphic(VirtualFrame frame, Object arg1, Object arg2, Object arg3,
124122
@Cached GetClassNode getClassNode,
125-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr) {
123+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr) {
126124
Object klass = getClassNode.execute(arg1);
127125
return dispatchNode.execute(frame, getattr.execute(frame, klass, arg1), arg1, arg2, arg3);
128126
}
@@ -140,7 +138,7 @@ private LookupSpecialMethodNode ensureGetAttrZ() {
140138
// this also serves as a branch profile
141139
if (getThirdAttrNode == null) {
142140
CompilerDirectives.transferToInterpreterAndInvalidate();
143-
getThirdAttrNode = insert(LookupSpecialMethodNode.create(name, ignoreDescriptorException));
141+
getThirdAttrNode = insert(LookupSpecialMethodNode.create(name));
144142
}
145143
return getThirdAttrNode;
146144
}
@@ -165,8 +163,8 @@ private GetClassNode ensureThirdGetClass() {
165163
@Specialization(guards = {"isReversible()", "v.getClass() == cachedVClass"}, limit = "getCallSiteInlineCacheMaxDepth()")
166164
Object callObjectR(VirtualFrame frame, Object v, Object w, Object z,
167165
@SuppressWarnings("unused") @Cached("v.getClass()") Class<?> cachedVClass,
168-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
169-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
166+
@Cached("create(name)") LookupSpecialMethodNode getattr,
167+
@Cached("create(name)") LookupSpecialMethodNode getattrR,
170168
@Cached GetClassNode getClass,
171169
@Cached GetClassNode getClassR,
172170
@Cached IsSubtypeNode isSubtype,
@@ -178,8 +176,8 @@ Object callObjectR(VirtualFrame frame, Object v, Object w, Object z,
178176
@Specialization(guards = "isReversible()", replaces = "callObjectR")
179177
@Megamorphic
180178
Object callObjectRMegamorphic(VirtualFrame frame, Object v, Object w, Object z,
181-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattr,
182-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodNode getattrR,
179+
@Cached("create(name)") LookupSpecialMethodNode getattr,
180+
@Cached("create(name)") LookupSpecialMethodNode getattrR,
183181
@Cached GetClassNode getClass,
184182
@Cached GetClassNode getClassR,
185183
@Cached IsSubtypeNode isSubtype,

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public abstract static class NoAttributeHandler extends PNodeWithContext {
6767
}
6868

6969
protected final String name;
70-
protected final boolean ignoreDescriptorException;
7170
protected final Supplier<NoAttributeHandler> handlerFactory;
7271
@Child private NoAttributeHandler handler;
7372

@@ -102,17 +101,16 @@ public abstract static class NoAttributeHandler extends PNodeWithContext {
102101
public abstract Object executeObject(VirtualFrame frame, double receiver);
103102

104103
public static LookupAndCallUnaryNode create(String name) {
105-
return LookupAndCallUnaryNodeGen.create(name, null, false);
104+
return LookupAndCallUnaryNodeGen.create(name, null);
106105
}
107106

108107
public static LookupAndCallUnaryNode create(String name, Supplier<NoAttributeHandler> handlerFactory) {
109-
return LookupAndCallUnaryNodeGen.create(name, handlerFactory, false);
108+
return LookupAndCallUnaryNodeGen.create(name, handlerFactory);
110109
}
111110

112-
LookupAndCallUnaryNode(String name, Supplier<NoAttributeHandler> handlerFactory, boolean ignoreDescriptorException) {
111+
LookupAndCallUnaryNode(String name, Supplier<NoAttributeHandler> handlerFactory) {
113112
this.name = name;
114113
this.handlerFactory = handlerFactory;
115-
this.ignoreDescriptorException = ignoreDescriptorException;
116114
}
117115

118116
public String getMethodName() {
@@ -219,7 +217,7 @@ static Object callObject(VirtualFrame frame, PNone receiver,
219217
Object callObjectGeneric(VirtualFrame frame, Object receiver,
220218
@SuppressWarnings("unused") @Cached("receiver.getClass()") Class<?> cachedClass,
221219
@Cached GetClassNode getClassNode,
222-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr,
220+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr,
223221
@Cached CallUnaryMethodNode dispatchNode) {
224222
return doCallObject(frame, receiver, getClassNode, getattr, dispatchNode);
225223
}
@@ -228,7 +226,7 @@ Object callObjectGeneric(VirtualFrame frame, Object receiver,
228226
@Megamorphic
229227
Object callObjectMegamorphic(VirtualFrame frame, Object receiver,
230228
@Cached GetClassNode getClassNode,
231-
@Cached("create(name, ignoreDescriptorException)") LookupSpecialMethodSlotNode getattr,
229+
@Cached("create(name)") LookupSpecialMethodSlotNode getattr,
232230
@Cached CallUnaryMethodNode dispatchNode) {
233231
return doCallObject(frame, receiver, getClassNode, getattr, dispatchNode);
234232
}
@@ -264,7 +262,7 @@ static Object doObject(Object receiver, String name,
264262
@Cached LookupSpecialMethodNode.Dynamic getattr,
265263
@Cached CallUnaryMethodNode dispatchNode,
266264
@Cached ConditionProfile profile) {
267-
Object attr = getattr.execute(null, getClassNode.execute(receiver), name, receiver, false);
265+
Object attr = getattr.execute(null, getClassNode.execute(receiver), name, receiver);
268266
if (profile.profile(attr != PNone.NO_VALUE)) {
269267
// NOTE: it's safe to pass a 'null' frame since this node can only be used via a
270268
// global state context manager

0 commit comments

Comments
 (0)