Skip to content

Commit 9c96712

Browse files
msimacektimfel
authored andcommitted
Replace usages of lookupAndCallRegularMethod
1 parent 413f2a5 commit 9c96712

19 files changed

+234
-204
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.oracle.graal.python.annotations.ArgumentClinic;
3939
import com.oracle.graal.python.builtins.Builtin;
4040
import com.oracle.graal.python.builtins.CoreFunctions;
41+
import com.oracle.graal.python.builtins.Python3Core;
4142
import com.oracle.graal.python.builtins.PythonBuiltinClassType;
4243
import com.oracle.graal.python.builtins.PythonBuiltins;
4344
import com.oracle.graal.python.builtins.objects.PNone;
@@ -54,6 +55,7 @@
5455
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5556
import com.oracle.graal.python.builtins.objects.range.PIntRange;
5657
import com.oracle.graal.python.builtins.objects.str.StringNodes;
58+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
5759
import com.oracle.graal.python.nodes.PGuards;
5860
import com.oracle.graal.python.nodes.PRaiseNode;
5961
import com.oracle.graal.python.nodes.classes.IsSubtypeNode;
@@ -65,7 +67,6 @@
6567
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
6668
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
6769
import com.oracle.graal.python.nodes.util.SplitArgsNode;
68-
import com.oracle.graal.python.builtins.Python3Core;
6970
import com.oracle.graal.python.runtime.exception.PException;
7071
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
7172
import com.oracle.graal.python.runtime.sequence.PSequence;
@@ -329,7 +330,7 @@ abstract static class ArrayReconstructorNode extends PythonClinicBuiltinNode {
329330
Object reconstructCached(VirtualFrame frame, Object arrayType, String typeCode, @SuppressWarnings("unused") int mformatCode, PBytes bytes,
330331
@Cached("mformatCode") int cachedCode,
331332
@Cached("createIdentityProfile()") ValueProfile formatProfile,
332-
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
333+
@Cached PyObjectCallMethodObjArgs callDecode,
333334
@Cached ArrayBuiltins.FromBytesNode fromBytesNode,
334335
@Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
335336
@Cached IsSubtypeNode isSubtypeNode,
@@ -338,12 +339,12 @@ Object reconstructCached(VirtualFrame frame, Object arrayType, String typeCode,
338339
if (format == null) {
339340
throw raise(ValueError, "bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)");
340341
}
341-
return doReconstruct(frame, arrayType, typeCode, cachedCode, bytes, lib, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, formatProfile.profile(format));
342+
return doReconstruct(frame, arrayType, typeCode, cachedCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, formatProfile.profile(format));
342343
}
343344

344345
@Specialization(replaces = "reconstructCached")
345346
Object reconstruct(VirtualFrame frame, Object arrayType, String typeCode, int mformatCode, PBytes bytes,
346-
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
347+
@Cached PyObjectCallMethodObjArgs callDecode,
347348
@Cached ArrayBuiltins.FromBytesNode fromBytesNode,
348349
@Cached ArrayBuiltins.FromUnicodeNode fromUnicodeNode,
349350
@Cached IsSubtypeNode isSubtypeNode,
@@ -352,10 +353,10 @@ Object reconstruct(VirtualFrame frame, Object arrayType, String typeCode, int mf
352353
if (format == null) {
353354
throw raise(ValueError, "bad typecode (must be b, B, u, h, H, i, I, l, L, q, Q, f or d)");
354355
}
355-
return doReconstruct(frame, arrayType, typeCode, mformatCode, bytes, lib, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format);
356+
return doReconstruct(frame, arrayType, typeCode, mformatCode, bytes, callDecode, fromBytesNode, fromUnicodeNode, isSubtypeNode, byteSwapNode, format);
356357
}
357358

358-
private Object doReconstruct(VirtualFrame frame, Object arrayType, String typeCode, int mformatCode, PBytes bytes, PythonObjectLibrary lib,
359+
private Object doReconstruct(VirtualFrame frame, Object arrayType, String typeCode, int mformatCode, PBytes bytes, PyObjectCallMethodObjArgs callDecode,
359360
ArrayBuiltins.FromBytesNode fromBytesNode, ArrayBuiltins.FromUnicodeNode fromUnicodeNode, IsSubtypeNode isSubtypeNode,
360361
ArrayBuiltins.ByteSwapNode byteSwapNode, BufferFormat format) {
361362
if (!isSubtypeNode.execute(frame, arrayType, PythonBuiltinClassType.PArray)) {
@@ -371,7 +372,7 @@ private Object doReconstruct(VirtualFrame frame, Object arrayType, String typeCo
371372
String newTypeCode = machineFormat.format == format ? typeCode : machineFormat.format.baseTypeCode;
372373
array = factory().createArray(arrayType, newTypeCode, machineFormat.format);
373374
if (machineFormat.unicodeEncoding != null) {
374-
Object decoded = lib.lookupAndCallRegularMethod(bytes, frame, "decode", machineFormat.unicodeEncoding);
375+
Object decoded = callDecode.execute(frame, bytes, "decode", machineFormat.unicodeEncoding);
375376
fromUnicodeNode.execute(frame, array, decoded);
376377
} else {
377378
fromBytesNode.execute(frame, array, bytes);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
5151
import com.oracle.graal.python.builtins.objects.frame.PFrame;
5252
import com.oracle.graal.python.builtins.objects.function.PKeyword;
53-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
53+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
5454
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.PythonBuiltinNode;
@@ -117,13 +117,13 @@ public Object execute(VirtualFrame frame) {
117117
@TruffleBoundary
118118
private static void handleException(PythonContext context, PException e) {
119119
PBaseException pythonException = e.getEscapedException();
120-
PythonObjectLibrary lib = PythonObjectLibrary.getUncached();
121120
if (!IsBuiltinClassProfile.profileClassSlowPath(GetClassNode.getUncached().execute(pythonException), PythonBuiltinClassType.SystemExit)) {
122-
lib.lookupAndCallRegularMethod(context.getCore().getStderr(), null, "write", "Error in atexit._run_exitfuncs:\n");
121+
PyObjectCallMethodObjArgs callWrite = PyObjectCallMethodObjArgs.getUncached();
122+
callWrite.execute(null, context.getCore().getStderr(), "write", "Error in atexit._run_exitfuncs:\n");
123123
try {
124124
ExceptionUtils.printExceptionTraceback(context, pythonException);
125125
} catch (PException pe) {
126-
lib.lookupAndCallRegularMethod(context.getCore().getStderr(), null, "write", "Failed to print traceback\n");
126+
callWrite.execute(null, context.getCore().getStderr(), "write", "Failed to print traceback\n");
127127
}
128128
}
129129
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@
195195
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
196196
import com.oracle.graal.python.lib.PyNumberFloatNode;
197197
import com.oracle.graal.python.lib.PyNumberIndexNode;
198+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
198199
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
199200
import com.oracle.graal.python.lib.PyObjectSizeNode;
200201
import com.oracle.graal.python.lib.PyObjectStrAsObjectNode;
@@ -1561,16 +1562,17 @@ abstract static class ReportAbstractClassNode extends PNodeWithContext {
15611562

15621563
@Specialization
15631564
static PException report(VirtualFrame frame, Object type,
1564-
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
1565+
@Cached PyObjectCallMethodObjArgs callSort,
1566+
@Cached PyObjectCallMethodObjArgs callJoin,
15651567
@Cached PyObjectSizeNode sizeNode,
15661568
@Cached ReadAttributeFromObjectNode readAttributeFromObjectNode,
15671569
@Cached CastToJavaStringNode cast,
15681570
@Cached ListNodes.ConstructListNode constructListNode,
15691571
@Cached PRaiseNode raiseNode) {
15701572
PList list = constructListNode.execute(frame, readAttributeFromObjectNode.execute(type, __ABSTRACTMETHODS__));
15711573
int methodCount = sizeNode.execute(frame, list);
1572-
lib.lookupAndCallRegularMethod(list, frame, "sort");
1573-
String joined = cast.execute(lib.lookupAndCallRegularMethod(", ", frame, "join", list));
1574+
callSort.execute(frame, list, "sort");
1575+
String joined = cast.execute(callJoin.execute(frame, ", ", "join", list));
15741576
throw raiseNode.raise(TypeError, "Can't instantiate abstract class %N with abstract method%s %s", type, methodCount > 1 ? "s" : "", joined);
15751577
}
15761578

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,18 @@
4747
import com.oracle.graal.python.builtins.PythonBuiltins;
4848
import com.oracle.graal.python.builtins.objects.PNone;
4949
import com.oracle.graal.python.builtins.objects.module.PythonModule;
50-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
50+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
5151
import com.oracle.graal.python.lib.PyObjectStrAsJavaStringNode;
5252
import com.oracle.graal.python.nodes.PGuards;
5353
import com.oracle.graal.python.nodes.PNodeWithRaise;
5454
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5555
import com.oracle.graal.python.runtime.PythonContext;
5656
import com.oracle.truffle.api.dsl.Cached;
57+
import com.oracle.truffle.api.dsl.Cached.Shared;
5758
import com.oracle.truffle.api.dsl.ImportStatic;
5859
import com.oracle.truffle.api.dsl.NodeFactory;
5960
import com.oracle.truffle.api.dsl.Specialization;
6061
import com.oracle.truffle.api.frame.VirtualFrame;
61-
import com.oracle.truffle.api.library.CachedLibrary;
6262

6363
@CoreFunctions(defineModule = "_codecs_truffle")
6464
public class CodecsTruffleModuleBuiltins extends PythonBuiltins {
@@ -71,22 +71,22 @@ public abstract static class LookupTextEncoding extends PNodeWithRaise {
7171
public abstract Object execute(VirtualFrame frame, String encoding, String alternateCommand);
7272

7373
@Specialization
74-
static Object lookup(VirtualFrame frame, String encoding, String alternateCommand,
75-
@CachedLibrary(limit = "1") PythonObjectLibrary lib) {
76-
PythonModule codecs = PythonContext.get(lib).getCore().lookupBuiltinModule("_codecs_truffle");
77-
return lib.lookupAndCallRegularMethod(codecs, frame, "_lookup_text_encoding", encoding, alternateCommand);
74+
Object lookup(VirtualFrame frame, String encoding, String alternateCommand,
75+
@Cached PyObjectCallMethodObjArgs callMethod) {
76+
PythonModule codecs = PythonContext.get(this).getCore().lookupBuiltinModule("_codecs_truffle");
77+
return callMethod.execute(frame, codecs, "_lookup_text_encoding", encoding, alternateCommand);
7878
}
7979
}
8080

8181
public abstract static class GetPreferredEncoding extends PNodeWithRaise {
8282
public abstract String execute(VirtualFrame frame);
8383

8484
@Specialization
85-
static String getpreferredencoding(VirtualFrame frame,
86-
@CachedLibrary(limit = "2") PythonObjectLibrary lib,
85+
String getpreferredencoding(VirtualFrame frame,
86+
@Cached PyObjectCallMethodObjArgs callMethod,
8787
@Cached PyObjectStrAsJavaStringNode strNode) {
88-
PythonModule codecs = PythonContext.get(lib).getCore().lookupBuiltinModule("_codecs_truffle");
89-
Object e = lib.lookupAndCallRegularMethod(codecs, frame, "_getpreferredencoding");
88+
PythonModule codecs = PythonContext.get(this).getCore().lookupBuiltinModule("_codecs_truffle");
89+
Object e = callMethod.execute(frame, codecs, "_getpreferredencoding");
9090
return strNode.execute(frame, e);
9191
}
9292
}
@@ -98,14 +98,14 @@ public abstract static class MakeIncrementalcodecNode extends PNodeWithRaise {
9898

9999
@Specialization
100100
static Object getIncEncoder(VirtualFrame frame, Object codecInfo, @SuppressWarnings("unused") PNone errors, String attrName,
101-
@CachedLibrary(limit = "2") PythonObjectLibrary lib) {
102-
return lib.lookupAndCallRegularMethod(codecInfo, frame, attrName);
101+
@Shared("callMethod") @Cached PyObjectCallMethodObjArgs callMethod) {
102+
return callMethod.execute(frame, codecInfo, attrName);
103103
}
104104

105105
@Specialization(guards = "!isPNone(errors)")
106106
static Object getIncEncoder(VirtualFrame frame, Object codecInfo, Object errors, String attrName,
107-
@CachedLibrary(limit = "2") PythonObjectLibrary lib) {
108-
return lib.lookupAndCallRegularMethod(codecInfo, frame, attrName, errors);
107+
@Shared("callMethod") @Cached PyObjectCallMethodObjArgs callMethod) {
108+
return callMethod.execute(frame, codecInfo, attrName, errors);
109109
}
110110
}
111111

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@
5656
import com.oracle.graal.python.builtins.objects.buffer.PythonBufferAcquireLibrary;
5757
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
5858
import com.oracle.graal.python.builtins.objects.module.PythonModule;
59-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
6059
import com.oracle.graal.python.builtins.objects.str.PString;
60+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
6161
import com.oracle.graal.python.lib.PyObjectLookupAttr;
6262
import com.oracle.graal.python.nodes.ErrorMessages;
63+
import com.oracle.graal.python.nodes.call.CallNode;
6364
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6465
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
6566
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -267,19 +268,19 @@ abstract static class GetAttrNode extends PythonBuiltinNode {
267268

268269
@CompilationFinal protected Object getAttr;
269270

270-
private Object getAttr(VirtualFrame frame, PythonModule mod, PythonObjectLibrary lib) {
271+
private Object getAttr(VirtualFrame frame, PythonModule mod) {
271272
if (getAttr == null) {
272273
CompilerDirectives.transferToInterpreterAndInvalidate();
273274
Object javaLoader = PyObjectLookupAttr.getUncached().executeStrict(frame, this, mod, JAVA_PKG_LOADER);
274-
getAttr = lib.lookupAndCallRegularMethod(javaLoader, frame, MAKE_GETATTR, JAVA);
275+
getAttr = PyObjectCallMethodObjArgs.getUncached().execute(frame, javaLoader, MAKE_GETATTR, JAVA);
275276
}
276277
return getAttr;
277278
}
278279

279280
@Specialization
280281
Object none(VirtualFrame frame, PythonModule mod, Object name,
281-
@CachedLibrary(limit = "3") PythonObjectLibrary lib) {
282-
return lib.callObject(getAttr(frame, mod, lib), frame, name);
282+
@Cached CallNode callNode) {
283+
return callNode.execute(frame, getAttr(frame, mod), name);
283284
}
284285
}
285286

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
import com.oracle.graal.python.lib.PyMemoryViewFromObject;
223223
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
224224
import com.oracle.graal.python.lib.PyNumberFloatNode;
225+
import com.oracle.graal.python.lib.PyObjectCallMethodObjArgs;
225226
import com.oracle.graal.python.lib.PySequenceCheckNode;
226227
import com.oracle.graal.python.nodes.BuiltinNames;
227228
import com.oracle.graal.python.nodes.ErrorMessages;
@@ -2797,7 +2798,7 @@ static Object doMethod(VirtualFrame frame, Object receiverObj, Object methodName
27972798
abstract static class PyObjectCallMethodNode extends PythonQuaternaryBuiltinNode {
27982799
@Specialization
27992800
static Object doGeneric(VirtualFrame frame, Object receiverObj, String methodName, Object argsObj, int singleArg,
2800-
@CachedLibrary(limit = "1") PythonObjectLibrary objectLib,
2801+
@Cached PyObjectCallMethodObjArgs callMethod,
28012802
@Cached AsPythonObjectNode asPythonObjectNode,
28022803
@Cached CastArgsNode castArgsNode,
28032804
@Cached ToNewRefNode toNewRefNode,
@@ -2813,7 +2814,7 @@ static Object doGeneric(VirtualFrame frame, Object receiverObj, String methodNam
28132814
} else {
28142815
args = castArgsNode.execute(frame, argsObj);
28152816
}
2816-
return toNewRefNode.execute(objectLib.lookupAndCallRegularMethod(receiver, frame, methodName, args));
2817+
return toNewRefNode.execute(callMethod.execute(frame, receiver, methodName, args));
28172818
} catch (PException e) {
28182819
// transformExceptionToNativeNode acts as a branch profile
28192820
transformExceptionToNativeNode.execute(frame, e);
@@ -4226,7 +4227,7 @@ int doGeneric(Object ptrObject) {
42264227
stderr.println("object repr : ");
42274228
stderr.flush();
42284229
try {
4229-
Object reprObj = PythonObjectLibrary.getUncached().lookupAndCallRegularMethod(context.getBuiltins(), null, BuiltinNames.REPR, pythonObject);
4230+
Object reprObj = PyObjectCallMethodObjArgs.getUncached().execute(null, context.getBuiltins(), BuiltinNames.REPR, pythonObject);
42304231
stderr.println(CastToJavaStringNode.getUncached().execute(reprObj));
42314232
} catch (PException | CannotCastException e) {
42324233
// errors are ignored at this point

0 commit comments

Comments
 (0)