Skip to content

Commit f5cf850

Browse files
msimacektimfel
authored andcommitted
Replace usages of POL.callObject
1 parent 9c96712 commit f5cf850

File tree

7 files changed

+50
-43
lines changed

7 files changed

+50
-43
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/BuiltinFunctions.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
132132
import com.oracle.graal.python.lib.PyNumberIndexNode;
133133
import com.oracle.graal.python.lib.PyObjectAsciiNode;
134+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
134135
import com.oracle.graal.python.lib.PyObjectHashNode;
135136
import com.oracle.graal.python.lib.PyObjectLookupAttr;
136137
import com.oracle.graal.python.lib.PyObjectReprAsObjectNode;
@@ -1550,31 +1551,31 @@ public abstract static class PrintNode extends PythonBuiltinNode {
15501551
@CompilationFinal private PythonModule cachedSys;
15511552

15521553
@Specialization
1553-
PNone printNoKeywords(VirtualFrame frame, Object[] values, @SuppressWarnings("unused") PNone sep, @SuppressWarnings("unused") PNone end, @SuppressWarnings("unused") PNone file,
1554-
@SuppressWarnings("unused") PNone flush,
1555-
@CachedLibrary(limit = "3") PythonObjectLibrary lib,
1556-
@Cached PyObjectStrAsObjectNode strNode) {
1554+
@SuppressWarnings("unused")
1555+
PNone printNoKeywords(VirtualFrame frame, Object[] values, PNone sep, PNone end, PNone file, PNone flush,
1556+
@Shared("callWrite") @Cached PyObjectCallMethodObjArgs callWrite,
1557+
@Shared("callFlush") @Cached PyObjectCallMethodObjArgs callFlush,
1558+
@Shared("strNode") @Cached PyObjectStrAsObjectNode strNode) {
15571559
Object stdout = getStdout();
1558-
return printAllGiven(frame, values, DEFAULT_SEPARATOR, DEFAULT_END, stdout, false, lib, strNode);
1560+
return printAllGiven(frame, values, DEFAULT_SEPARATOR, DEFAULT_END, stdout, false, callWrite, callFlush, strNode);
15591561
}
15601562

15611563
@Specialization(guards = {"!isNone(file)", "!isNoValue(file)"})
15621564
PNone printAllGiven(VirtualFrame frame, Object[] values, String sep, String end, Object file, boolean flush,
1563-
@CachedLibrary(limit = "3") PythonObjectLibrary lib,
1564-
@Cached PyObjectStrAsObjectNode strNode) {
1565+
@Shared("callWrite") @Cached PyObjectCallMethodObjArgs callWrite,
1566+
@Shared("callFlush") @Cached PyObjectCallMethodObjArgs callFlush,
1567+
@Shared("strNode") @Cached PyObjectStrAsObjectNode strNode) {
15651568
int lastValue = values.length - 1;
1566-
Object writeMethod = lib.lookupAttributeStrict(file, frame, "write");
15671569
for (int i = 0; i < lastValue; i++) {
1568-
lib.callObject(writeMethod, frame, strNode.execute(frame, values[i]));
1569-
lib.callObject(writeMethod, frame, sep);
1570+
callWrite.execute(frame, file, "write", strNode.execute(frame, values[i]));
1571+
callWrite.execute(frame, file, "write", sep);
15701572
}
15711573
if (lastValue >= 0) {
1572-
lib.callObject(writeMethod, frame, strNode.execute(frame, values[lastValue]));
1574+
callWrite.execute(frame, file, "write", strNode.execute(frame, values[lastValue]));
15731575
}
1574-
lib.callObject(writeMethod, frame, end);
1576+
callWrite.execute(frame, file, "write", end);
15751577
if (flush) {
1576-
Object flushMethod = lib.lookupAttributeStrict(file, frame, "flush");
1577-
lib.callObject(flushMethod, frame);
1578+
callFlush.execute(frame, file, "flush");
15781579
}
15791580
return PNone.NONE;
15801581
}
@@ -1585,8 +1586,9 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
15851586
@Cached CastToJavaStringNode castEnd,
15861587
@Cached("createIfTrueNode()") CoerceToBooleanNode castFlush,
15871588
@Cached PRaiseNode raiseNode,
1588-
@CachedLibrary(limit = "4") PythonObjectLibrary lib,
1589-
@Cached PyObjectStrAsObjectNode strNode) {
1589+
@Shared("callWrite") @Cached PyObjectCallMethodObjArgs callWrite,
1590+
@Shared("callFlush") @Cached PyObjectCallMethodObjArgs callFlush,
1591+
@Shared("strNode") @Cached PyObjectStrAsObjectNode strNode) {
15901592
String sep;
15911593
try {
15921594
sep = sepIn instanceof PNone ? DEFAULT_SEPARATOR : castSep.execute(sepIn);
@@ -1613,7 +1615,7 @@ PNone printGeneric(VirtualFrame frame, Object[] values, Object sepIn, Object end
16131615
} else {
16141616
flush = castFlush.executeBoolean(frame, flushIn);
16151617
}
1616-
return printAllGiven(frame, values, sep, end, file, flush, lib, strNode);
1618+
return printAllGiven(frame, values, sep, end, file, flush, callWrite, callFlush, strNode);
16171619
}
16181620

16191621
private Object getStdout() {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/FaulthandlerModuleBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
import com.oracle.graal.python.builtins.CoreFunctions;
5151
import com.oracle.graal.python.builtins.PythonBuiltins;
5252
import com.oracle.graal.python.builtins.objects.PNone;
53-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5453
import com.oracle.graal.python.lib.PyObjectLookupAttr;
54+
import com.oracle.graal.python.nodes.call.CallNode;
5555
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5656
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
5757
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
@@ -82,7 +82,7 @@ private static void dumpTraceback(Object callable, Object file) {
8282
f = PNone.NONE;
8383
}
8484
try {
85-
PythonObjectLibrary.getUncached().callObject(callable, null, PNone.NONE, PNone.NONE, f);
85+
CallNode.getUncached().execute(null, callable, PNone.NONE, PNone.NONE, f);
8686
} catch (RuntimeException e) {
8787
ExceptionUtils.printPythonLikeStackTrace(e);
8888
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PythonCextBuiltins.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,7 +2696,7 @@ abstract static class PyObjectCallFunctionObjArgsNode extends PythonBinaryBuilti
26962696
static Object doFunction(VirtualFrame frame, Object callableObj, Object vaList,
26972697
@CachedLibrary("vaList") InteropLibrary argsArrayLib,
26982698
@Shared("argLib") @CachedLibrary(limit = "2") InteropLibrary argLib,
2699-
@CachedLibrary(limit = "1") PythonObjectLibrary callableLib,
2699+
@Cached CallNode callNode,
27002700
@Cached AsPythonObjectNode asPythonObjectNode,
27012701
@Cached CExtNodes.ToJavaNode toJavaNode,
27022702
@Cached GetLLVMType getLLVMType,
@@ -2706,7 +2706,7 @@ static Object doFunction(VirtualFrame frame, Object callableObj, Object vaList,
27062706
@Cached TransformExceptionToNativeNode transformExceptionToNativeNode) {
27072707
try {
27082708
Object callable = asPythonObjectNode.execute(callableObj);
2709-
return toNewRefNode.execute(callFunction(frame, callable, vaList, argsArrayLib, argLib, callableLib, toJavaNode, getLLVMType));
2709+
return toNewRefNode.execute(callFunction(frame, callable, vaList, argsArrayLib, argLib, callNode, toJavaNode, getLLVMType));
27102710
} catch (PException e) {
27112711
// transformExceptionToNativeNode acts as a branch profile
27122712
transformExceptionToNativeNode.execute(frame, e);
@@ -2717,7 +2717,7 @@ static Object doFunction(VirtualFrame frame, Object callableObj, Object vaList,
27172717
static Object callFunction(VirtualFrame frame, Object callable, Object vaList,
27182718
InteropLibrary argsArrayLib,
27192719
InteropLibrary argLib,
2720-
PythonObjectLibrary callableLib,
2720+
CallNode callNode,
27212721
CExtNodes.ToJavaNode toJavaNode,
27222722
GetLLVMType getLLVMType) {
27232723
if (argsArrayLib.hasArrayElements(vaList)) {
@@ -2749,7 +2749,7 @@ static Object callFunction(VirtualFrame frame, Object callable, Object vaList,
27492749
if (filled < args.length) {
27502750
args = PythonUtils.arrayCopyOf(args, filled);
27512751
}
2752-
return callableLib.callObject(callable, frame, args);
2752+
return callNode.execute(frame, callable, args);
27532753
} catch (UnsupportedMessageException | OverflowException e) {
27542754
// I think we can just assume that there won't be more than
27552755
// Integer.MAX_VALUE arguments.
@@ -2767,9 +2767,9 @@ abstract static class PyObjectCallMethodObjArgsNode extends PythonTernaryBuiltin
27672767

27682768
@Specialization(limit = "1")
27692769
static Object doMethod(VirtualFrame frame, Object receiverObj, Object methodNameObj, Object vaList,
2770-
@CachedLibrary(limit = "1") PythonObjectLibrary methodLib,
27712770
@CachedLibrary("vaList") InteropLibrary argsArrayLib,
27722771
@Shared("argLib") @CachedLibrary(limit = "2") InteropLibrary argLib,
2772+
@Cached CallNode callNode,
27732773
@Cached GetAnyAttributeNode getAnyAttributeNode,
27742774
@Cached AsPythonObjectNode asPythonObjectNode,
27752775
@Cached CExtNodes.ToJavaNode toJavaNode,
@@ -2783,7 +2783,7 @@ static Object doMethod(VirtualFrame frame, Object receiverObj, Object methodName
27832783
Object receiver = asPythonObjectNode.execute(receiverObj);
27842784
Object methodName = asPythonObjectNode.execute(methodNameObj);
27852785
Object method = getAnyAttributeNode.executeObject(frame, receiver, methodName);
2786-
return toNewRefNode.execute(PyObjectCallFunctionObjArgsNode.callFunction(frame, method, vaList, argsArrayLib, argLib, methodLib, toJavaNode, getLLVMType));
2786+
return toNewRefNode.execute(PyObjectCallFunctionObjArgsNode.callFunction(frame, method, vaList, argsArrayLib, argLib, callNode, toJavaNode, getLLVMType));
27872787
} catch (PException e) {
27882788
// transformExceptionToNativeNode acts as a branch profile
27892789
transformExceptionToNativeNode.execute(frame, e);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3500,7 +3500,7 @@ private static Object getPyObject(GetVaArgsNode getVaArgsNode, Object vaList, in
35003500
@TruffleBoundary
35013501
private static Object callBuiltin(PythonContext context, String builtinName, Object object) {
35023502
Object attribute = PyObjectLookupAttr.getUncached().execute(null, context.getBuiltins(), builtinName);
3503-
return CastToJavaStringNodeGen.getUncached().execute(PythonObjectLibrary.getUncached().callObject(attribute, null, object));
3503+
return CastToJavaStringNodeGen.getUncached().execute(CallNode.getUncached().execute(null, attribute, object));
35043504
}
35053505
}
35063506

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ static Object doGeneric(GraalHPyCallBuiltinFunction receiver, Object[] arguments
18001800
@Cached HPyAsContextNode asContextNode,
18011801
@Cached HPyAsPythonObjectNode asPythonObjectNode,
18021802
@Cached ReadAttributeFromObjectNode readAttributeFromObjectNode,
1803-
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
1803+
@Cached CallNode callNode,
18041804
@Cached(value = "createToNativeNode(receiver)", uncached = "getUncachedToNativeNode(receiver)") CExtToNativeNode toNativeNode,
18051805
@Cached HPyTransformExceptionToNativeNode transformExceptionToNativeNode,
18061806
@Exclusive @Cached GilNode gil) throws ArityException {
@@ -1817,7 +1817,7 @@ static Object doGeneric(GraalHPyCallBuiltinFunction receiver, Object[] arguments
18171817
}
18181818
try {
18191819
Object builtinFunction = readAttributeFromObjectNode.execute(nativeContext.getContext().getBuiltins(), receiver.key);
1820-
return toNativeNode.execute(nativeContext, lib.callObjectWithState(builtinFunction, null, pythonArguments));
1820+
return toNativeNode.execute(nativeContext, callNode.execute(builtinFunction, pythonArguments, PKeyword.EMPTY_KEYWORDS));
18211821
} catch (PException e) {
18221822
transformExceptionToNativeNode.execute(nativeContext, e);
18231823
switch (receiver.returnType) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectBuiltins.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@
8686
import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetBaseClassNode;
8787
import com.oracle.graal.python.builtins.objects.type.TypeNodesFactory.CheckCompatibleForAssigmentNodeGen;
8888
import com.oracle.graal.python.lib.PyLongAsLongNode;
89+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
8990
import com.oracle.graal.python.lib.PyObjectSizeNode;
9091
import com.oracle.graal.python.nodes.ErrorMessages;
9192
import com.oracle.graal.python.nodes.PGuards;
9293
import com.oracle.graal.python.nodes.attributes.LookupAttributeInMRONode;
9394
import com.oracle.graal.python.nodes.attributes.LookupCallableSlotInMRONode;
9495
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
9596
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
97+
import com.oracle.graal.python.nodes.call.CallNode;
9698
import com.oracle.graal.python.nodes.call.special.CallBinaryMethodNode;
9799
import com.oracle.graal.python.nodes.call.special.CallTernaryMethodNode;
98100
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
@@ -915,15 +917,16 @@ protected ArgumentClinicProvider getArgumentClinic() {
915917
@Specialization
916918
@SuppressWarnings("unused")
917919
static Object doit(VirtualFrame frame, Object obj, int proto,
920+
@Cached PyObjectLookupAttr lookupAttr,
921+
@Cached CallNode callNode,
918922
@Cached ConditionProfile reduceProfile,
919-
@Cached ObjectNodes.CommonReduceNode commonReduceNode,
920-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
921-
Object _reduce = pol.lookupAttribute(obj, frame, __REDUCE__);
923+
@Cached ObjectNodes.CommonReduceNode commonReduceNode) {
924+
Object _reduce = lookupAttr.execute(frame, obj, __REDUCE__);
922925
if (reduceProfile.profile(_reduce != PNone.NO_VALUE)) {
923926
// Check if __reduce__ has been overridden:
924927
// "type(obj).__reduce__ is not object.__reduce__"
925928
if (!(_reduce instanceof PBuiltinMethod) || ((PBuiltinMethod) _reduce).getFunction().getBuiltinNodeFactory() != REDUCE_FACTORY) {
926-
return pol.callObject(_reduce, frame);
929+
return callNode.execute(frame, _reduce);
927930
}
928931
}
929932
return commonReduceNode.execute(frame, obj, proto);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/object/ObjectNodes.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import com.oracle.graal.python.nodes.SpecialAttributeNames;
108108
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
109109
import com.oracle.graal.python.nodes.attributes.WriteAttributeToDynamicObjectNode;
110+
import com.oracle.graal.python.nodes.call.CallNode;
110111
import com.oracle.graal.python.nodes.object.GetClassNode;
111112
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
112113
import com.oracle.graal.python.nodes.object.IsForeignObjectNode;
@@ -121,6 +122,7 @@
121122
import com.oracle.graal.python.util.PythonUtils;
122123
import com.oracle.truffle.api.Assumption;
123124
import com.oracle.truffle.api.dsl.Cached;
125+
import com.oracle.truffle.api.dsl.Cached.Shared;
124126
import com.oracle.truffle.api.dsl.GenerateUncached;
125127
import com.oracle.truffle.api.dsl.ImportStatic;
126128
import com.oracle.truffle.api.dsl.Specialization;
@@ -459,13 +461,13 @@ abstract static class GetNewArgsInternalNode extends PNodeWithState {
459461

460462
@Specialization(guards = "!isNoValue(getNewArgsExAttr)")
461463
Pair<Object, Object> doNewArgsEx(VirtualFrame frame, Object getNewArgsExAttr, @SuppressWarnings("unused") Object getNewArgsAttr,
462-
@Cached FastIsTupleSubClassNode isTupleSubClassNode,
464+
@Shared("callNode") @Cached CallNode callNode,
465+
@Shared("tupleCheck") @Cached FastIsTupleSubClassNode isTupleSubClassNode,
463466
@Cached FastIsDictSubClassNode isDictSubClassNode,
464467
@Cached SequenceStorageNodes.GetItemNode getItemNode,
465468
@Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode,
466-
@Cached PyObjectSizeNode sizeNode,
467-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
468-
Object newargs = pol.callObject(getNewArgsExAttr, frame);
469+
@Cached PyObjectSizeNode sizeNode) {
470+
Object newargs = callNode.execute(frame, getNewArgsExAttr);
469471
if (!isTupleSubClassNode.execute(frame, newargs)) {
470472
throw raise(TypeError, SHOULD_RETURN_TYPE_A_NOT_TYPE_B, __GETNEWARGS_EX__, "tuple", newargs);
471473
}
@@ -488,11 +490,11 @@ Pair<Object, Object> doNewArgsEx(VirtualFrame frame, Object getNewArgsExAttr, @S
488490
return Pair.create(args, kwargs);
489491
}
490492

491-
@Specialization(guards = "!isNoValue(getNewArgsAttr)", limit = "getCallSiteInlineCacheMaxDepth()")
493+
@Specialization(guards = "!isNoValue(getNewArgsAttr)")
492494
Pair<Object, Object> doNewArgs(VirtualFrame frame, @SuppressWarnings("unused") PNone getNewArgsExAttr, Object getNewArgsAttr,
493-
@Cached FastIsTupleSubClassNode isTupleSubClassNode,
494-
@CachedLibrary(value = "getNewArgsAttr") PythonObjectLibrary pol) {
495-
Object args = pol.callObject(getNewArgsAttr, frame);
495+
@Shared("callNode") @Cached CallNode callNode,
496+
@Shared("tupleCheck") @Cached FastIsTupleSubClassNode isTupleSubClassNode) {
497+
Object args = callNode.execute(frame, getNewArgsAttr);
496498
if (!isTupleSubClassNode.execute(frame, args)) {
497499
throw raise(TypeError, SHOULD_RETURN_TYPE_A_NOT_TYPE_B, __GETNEWARGS__, "tuple", args);
498500
}
@@ -571,10 +573,10 @@ Object dispatch(VirtualFrame frame, Object obj, boolean required, Object copyReg
571573
abstract static class GetStateInternalNode extends PNodeWithState {
572574
public abstract Object execute(VirtualFrame frame, Object obj, boolean required, Object copyReg, Object getStateAttr);
573575

574-
@Specialization(guards = "!isNoValue(getStateAttr)", limit = "getCallSiteInlineCacheMaxDepth()")
576+
@Specialization(guards = "!isNoValue(getStateAttr)")
575577
Object getState(VirtualFrame frame, @SuppressWarnings("unused") Object obj, @SuppressWarnings("unused") boolean required, @SuppressWarnings("unused") Object copyReg, Object getStateAttr,
576-
@CachedLibrary(value = "getStateAttr") PythonObjectLibrary pol) {
577-
return pol.callObject(getStateAttr, frame);
578+
@Cached CallNode callNode) {
579+
return callNode.execute(frame, getStateAttr);
578580
}
579581

580582
@Specialization

0 commit comments

Comments
 (0)