Skip to content

Commit e6b201a

Browse files
msimacektimfel
authored andcommitted
Replace many usages of lookupAttribute with node
1 parent a7fb66b commit e6b201a

20 files changed

+148
-114
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.util.regex.Matcher;
4545
import java.util.regex.Pattern;
4646

47+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
4748
import org.graalvm.nativeimage.ImageInfo;
4849

4950
import com.oracle.graal.python.PythonLanguage;
@@ -211,7 +212,6 @@
211212
import com.oracle.graal.python.builtins.objects.module.PythonModule;
212213
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
213214
import com.oracle.graal.python.builtins.objects.object.PythonObject;
214-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
215215
import com.oracle.graal.python.builtins.objects.posix.DirEntryBuiltins;
216216
import com.oracle.graal.python.builtins.objects.posix.ScandirIteratorBuiltins;
217217
import com.oracle.graal.python.builtins.objects.property.PropertyBuiltins;
@@ -759,7 +759,7 @@ public void warn(PythonBuiltinClassType type, String format, Object... args) {
759759
*/
760760
public Object getStderr() {
761761
try {
762-
return PythonObjectLibrary.getUncached().lookupAttribute(sysModule, null, "stderr");
762+
return PyObjectLookupAttr.getUncached().execute(null, sysModule, "stderr");
763763
} catch (PException e) {
764764
try {
765765
getContext().getEnv().err().write("lost sys.stderr\n".getBytes());

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@
132132
import com.oracle.graal.python.lib.PyNumberIndexNode;
133133
import com.oracle.graal.python.lib.PyObjectAsciiNode;
134134
import com.oracle.graal.python.lib.PyObjectHashNode;
135+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
135136
import com.oracle.graal.python.lib.PyObjectReprAsObjectNode;
136137
import com.oracle.graal.python.lib.PyObjectSizeNode;
137138
import com.oracle.graal.python.lib.PyObjectStrAsJavaStringNode;
@@ -2108,10 +2109,9 @@ Object calculate(Object metatype, PTuple bases,
21082109
public abstract static class BuildClassNode extends PythonVarargsBuiltinNode {
21092110
@TruffleBoundary
21102111
private static Object buildJavaClass(Object func, String name, Object base) {
2111-
PythonObjectLibrary factory = PythonObjectLibrary.getUncached();
21122112
// uncached PythonContext get, since this code path is slow in any case
21132113
Object module = PythonContext.get(null).getCore().lookupBuiltinModule(BuiltinNames.__GRAALPYTHON__);
2114-
Object buildFunction = factory.lookupAttribute(module, null, "build_java_class");
2114+
Object buildFunction = PyObjectLookupAttr.getUncached().execute(null, module, "build_java_class");
21152115
return CallNode.getUncached().execute(buildFunction, func, name, base);
21162116
}
21172117

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import com.oracle.graal.python.builtins.PythonBuiltins;
5252
import com.oracle.graal.python.builtins.objects.PNone;
5353
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
54+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
5455
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5556
import com.oracle.graal.python.nodes.function.builtins.PythonClinicBuiltinNode;
5657
import com.oracle.graal.python.nodes.function.builtins.clinic.ArgumentClinicProvider;
@@ -112,7 +113,7 @@ private static void dump(PythonLanguage language, PythonContext context, Object
112113
Object printStackFunc;
113114
try {
114115
Object tracebackModule = AbstractImportNode.importModule("traceback");
115-
printStackFunc = PythonObjectLibrary.getUncached().lookupAttribute(tracebackModule, null, "print_stack");
116+
printStackFunc = PyObjectLookupAttr.getUncached().execute(null, tracebackModule, "print_stack");
116117
} catch (PException e) {
117118
return;
118119
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575
import com.oracle.graal.python.builtins.objects.ints.PInt;
7676
import com.oracle.graal.python.builtins.objects.module.PythonModule;
7777
import com.oracle.graal.python.builtins.objects.object.PythonObject;
78-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
7978
import com.oracle.graal.python.builtins.objects.str.PString;
79+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
8080
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode;
8181
import com.oracle.graal.python.nodes.attributes.SetAttributeNode;
8282
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -326,19 +326,19 @@ public int run(@SuppressWarnings("unused") Object noName) {
326326
@Builtin(name = "create_builtin", minNumOfPositionalArgs = 1)
327327
@GenerateNodeFactory
328328
public abstract static class CreateBuiltin extends PythonBuiltinNode {
329-
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
329+
@Specialization
330330
public Object run(VirtualFrame frame, PythonObject moduleSpec,
331331
@Cached CastToJavaStringNode toJavaStringNode,
332332
@Cached("create(__LOADER__)") SetAttributeNode setAttributeNode,
333-
@CachedLibrary(value = "moduleSpec") PythonObjectLibrary pol) {
334-
Object name = pol.lookupAttribute(moduleSpec, frame, "name");
333+
@Cached PyObjectLookupAttr lookup) {
334+
Object name = lookup.execute(frame, moduleSpec, "name");
335335
PythonModule builtinModule = getBuiltinModule(toJavaStringNode.execute(name));
336336
if (builtinModule != null) {
337337
// TODO: GR-26411 builtin modules cannot be re-initialized (see is_builtin)
338338
// We are setting the loader to the spec loader (since this is the loader that is
339339
// set during bootstrap); this, however, should be handled be the builtin module
340340
// reinitialization (if reinit is possible)
341-
Object loader = pol.lookupAttribute(moduleSpec, frame, "loader");
341+
Object loader = lookup.execute(frame, moduleSpec, "loader");
342342
if (loader != PNone.NO_VALUE) {
343343
setAttributeNode.executeVoid(frame, builtinModule, loader);
344344
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/ctypes/StgDictBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
6969
import com.oracle.graal.python.builtins.objects.type.TypeNodes.IsTypeNode;
7070
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
71+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
7172
import com.oracle.graal.python.lib.PyObjectSizeNode;
7273
import com.oracle.graal.python.lib.PySequenceCheckNode;
7374
import com.oracle.graal.python.nodes.PGuards;
@@ -113,9 +114,9 @@ protected abstract static class InitNode extends PythonBuiltinNode {
113114

114115
@Specialization
115116
Object init(VirtualFrame frame, StgDictObject self, Object[] args, PKeyword[] kwargs,
116-
@CachedLibrary(limit = "1") PythonObjectLibrary lib,
117+
@Cached PyObjectLookupAttr lookup,
117118
@Cached CallNode callNode) {
118-
Object initMethod = lib.lookupAttribute(PythonBuiltinClassType.PDict, frame, SpecialMethodNames.__INIT__);
119+
Object initMethod = lookup.execute(frame, PythonBuiltinClassType.PDict, SpecialMethodNames.__INIT__);
119120
Object[] dictArgs;
120121
if (args.length > 0) {
121122
dictArgs = new Object[args.length + 1];

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/BufferedIOMixinBuiltins.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777
import com.oracle.graal.python.builtins.Builtin;
7878
import com.oracle.graal.python.builtins.CoreFunctions;
7979
import com.oracle.graal.python.builtins.objects.PNone;
80-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
8180
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
81+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
8282
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
8383
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
8484
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
@@ -98,7 +98,6 @@
9898
import com.oracle.truffle.api.dsl.Specialization;
9999
import com.oracle.truffle.api.dsl.TypeSystemReference;
100100
import com.oracle.truffle.api.frame.VirtualFrame;
101-
import com.oracle.truffle.api.library.CachedLibrary;
102101
import com.oracle.truffle.api.profiles.ConditionProfile;
103102

104103
@CoreFunctions(extendClasses = {PBufferedReader, PBufferedWriter, PBufferedRandom})
@@ -370,15 +369,15 @@ static Object doit(VirtualFrame frame, PBuffered self,
370369
abstract static class ReprNode extends PythonUnaryBuiltinNode {
371370
@Specialization
372371
Object repr(VirtualFrame frame, PBuffered self,
373-
@CachedLibrary(limit = "2") PythonObjectLibrary libSelf,
372+
@Cached PyObjectLookupAttr lookup,
374373
@Cached TypeNodes.GetNameNode getNameNode,
375374
@Cached GetClassNode getClassNode,
376375
@Cached IsBuiltinClassProfile isValueError,
377376
@Cached("create(__REPR__)") LookupAndCallUnaryNode repr) {
378377
Object clazz = getNameNode.execute(getClassNode.execute(self));
379378
Object nameobj = PNone.NO_VALUE;
380379
try {
381-
nameobj = libSelf.lookupAttribute(self, frame, NAME);
380+
nameobj = lookup.execute(frame, self, NAME);
382381
} catch (PException e) {
383382
e.expect(ValueError, isValueError);
384383
// ignore

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IOBaseBuiltins.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
import com.oracle.graal.python.builtins.objects.object.PythonObject;
9090
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
9191
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
92+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
9293
import com.oracle.graal.python.lib.PyObjectSizeNode;
9394
import com.oracle.graal.python.nodes.ErrorMessages;
9495
import com.oracle.graal.python.nodes.PGuards;
@@ -129,10 +130,10 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
129130
@GenerateNodeFactory
130131
abstract static class ClosedNode extends PythonUnaryBuiltinNode {
131132

132-
@Specialization(limit = "1")
133+
@Specialization
133134
static boolean closed(VirtualFrame frame, PythonObject self,
134-
@CachedLibrary("self") PythonObjectLibrary lib) {
135-
return isClosed(self, frame, lib);
135+
@Cached PyObjectLookupAttr lookup) {
136+
return isClosed(self, frame, lookup);
136137
}
137138
}
138139

@@ -232,9 +233,10 @@ abstract static class CloseNode extends PythonUnaryBuiltinNode {
232233
@Specialization(limit = "3")
233234
PNone close(VirtualFrame frame, PythonObject self,
234235
@CachedLibrary("self") PythonObjectLibrary lib,
236+
@Cached PyObjectLookupAttr lookup,
235237
@Cached("create(__IOBASE_CLOSED)") SetAttributeNode setAttributeNode,
236238
@Cached BranchProfile errorProfile) {
237-
if (!isClosed(self, frame, lib)) {
239+
if (!isClosed(self, frame, lookup)) {
238240
try {
239241
lib.lookupAndCallRegularMethod(self, frame, FLUSH);
240242
} catch (PException e) {
@@ -258,11 +260,10 @@ PNone close(VirtualFrame frame, PythonObject self,
258260
@GenerateNodeFactory
259261
abstract static class FlushNode extends PythonUnaryBuiltinNode {
260262

261-
@Specialization(limit = "1")
263+
@Specialization
262264
PNone flush(VirtualFrame frame, PythonObject self,
263-
@CachedLibrary("self") PythonObjectLibrary lib,
264-
@Cached ConditionProfile closedProfile) {
265-
if (closedProfile.profile(isClosed(self, frame, lib))) {
265+
@Cached PyObjectLookupAttr lookup) {
266+
if (isClosed(self, frame, lookup)) {
266267
throw raise(ValueError, ErrorMessages.IO_CLOSED);
267268
}
268269
return PNone.NONE;
@@ -407,11 +408,12 @@ protected ArgumentClinicProvider getArgumentClinic() {
407408
@Specialization(limit = "2")
408409
PBytes readline(VirtualFrame frame, Object self, int limit,
409410
@CachedLibrary("self") PythonObjectLibrary lib,
411+
@Cached PyObjectLookupAttr lookup,
410412
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
411413
@Cached ConditionProfile hasPeek,
412414
@Cached ConditionProfile isBytes) {
413415
/* For backwards compatibility, a (slowish) readline(). */
414-
Object peek = lib.lookupAttribute(self, frame, "peek");
416+
Object peek = lookup.execute(frame, self, "peek");
415417
ByteArrayOutputStream buffer = createOutputStream();
416418
while (limit < 0 || buffer.size() < limit) {
417419
int nreadahead = 1;
@@ -505,8 +507,8 @@ Object withHint(VirtualFrame frame, Object self, int hint,
505507
* @param self the IOBase instance
506508
* @return true if the {@link IONodes#__IOBASE_CLOSED} attribute exists
507509
*/
508-
private static boolean isClosed(PythonObject self, VirtualFrame frame, PythonObjectLibrary lib) {
509-
return !PGuards.isNoValue(lib.lookupAttribute(self, frame, __IOBASE_CLOSED));
510+
private static boolean isClosed(PythonObject self, VirtualFrame frame, PyObjectLookupAttr lookup) {
511+
return !PGuards.isNoValue(lookup.execute(frame, self, __IOBASE_CLOSED));
510512
}
511513

512514
/**

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/IONodes.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.oracle.graal.python.builtins.objects.str.PString;
6060
import com.oracle.graal.python.lib.PyIndexCheckNode;
6161
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
62+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
6263
import com.oracle.graal.python.nodes.ErrorMessages;
6364
import com.oracle.graal.python.nodes.PGuards;
6465
import com.oracle.graal.python.nodes.PNodeWithRaise;
@@ -451,10 +452,10 @@ static Object write(VirtualFrame frame, Object obj, Object data,
451452
public abstract static class HasRead1 extends Node {
452453
public abstract boolean execute(VirtualFrame frame, Object obj);
453454

454-
@Specialization(limit = "1")
455+
@Specialization
455456
static boolean hasRead1(VirtualFrame frame, Object obj,
456-
@CachedLibrary("obj") PythonObjectLibrary lib) {
457-
return lib.lookupAttribute(obj, frame, READ1) != PNone.NO_VALUE;
457+
@Cached PyObjectLookupAttr lookup) {
458+
return lookup.execute(frame, obj, READ1) != PNone.NO_VALUE;
458459
}
459460
}
460461

@@ -693,40 +694,40 @@ static Object flush(VirtualFrame frame, Object obj,
693694
public abstract static class GetMode extends Node {
694695
public abstract Object execute(VirtualFrame frame, Object obj);
695696

696-
@Specialization(limit = "1")
697+
@Specialization
697698
static Object mode(VirtualFrame frame, Object obj,
698-
@CachedLibrary("obj") PythonObjectLibrary lib) {
699-
return lib.lookupAttribute(obj, frame, MODE);
699+
@Cached PyObjectLookupAttr lookup) {
700+
return lookup.execute(frame, obj, MODE);
700701
}
701702
}
702703

703704
public abstract static class GetName extends Node {
704705
public abstract Object execute(VirtualFrame frame, Object obj);
705706

706-
@Specialization(limit = "1")
707+
@Specialization
707708
static Object name(VirtualFrame frame, Object obj,
708-
@CachedLibrary("obj") PythonObjectLibrary lib) {
709-
return lib.lookupAttribute(obj, frame, NAME);
709+
@Cached PyObjectLookupAttr lookup) {
710+
return lookup.execute(frame, obj, NAME);
710711
}
711712
}
712713

713714
public abstract static class GetClosed extends Node {
714715
public abstract Object execute(VirtualFrame frame, Object obj);
715716

716-
@Specialization(limit = "1")
717+
@Specialization
717718
static Object closed(VirtualFrame frame, Object obj,
718-
@CachedLibrary("obj") PythonObjectLibrary lib) {
719-
return lib.lookupAttribute(obj, frame, CLOSED);
719+
@Cached PyObjectLookupAttr lookup) {
720+
return lookup.execute(frame, obj, CLOSED);
720721
}
721722
}
722723

723724
public abstract static class GetNewlines extends Node {
724725
public abstract Object execute(VirtualFrame frame, Object obj);
725726

726-
@Specialization(limit = "1")
727+
@Specialization
727728
static Object newlines(VirtualFrame frame, Object obj,
728-
@CachedLibrary("obj") PythonObjectLibrary lib) {
729-
return lib.lookupAttribute(obj, frame, NEWLINES);
729+
@Cached PyObjectLookupAttr lookup) {
730+
return lookup.execute(frame, obj, NEWLINES);
730731
}
731732
}
732733

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/io/TextIOWrapperBuiltins.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
123123
import com.oracle.graal.python.lib.PyNumberIndexNode;
124124
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
125+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
125126
import com.oracle.graal.python.lib.PyObjectSizeNode;
126127
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
127128
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -1148,7 +1149,7 @@ Object doit(VirtualFrame frame, PTextIO self,
11481149
abstract static class ReprNode extends InitCheckPythonUnaryBuiltinNode {
11491150
@Specialization(guards = "self.isOK()")
11501151
Object doit(VirtualFrame frame, PTextIO self,
1151-
@CachedLibrary(limit = "2") PythonObjectLibrary libSelf,
1152+
@Cached PyObjectLookupAttr lookup,
11521153
@Cached("create(__REPR__)") LookupAndCallUnaryNode repr,
11531154
@Cached IONodes.ToStringNode toString,
11541155
@Cached IsBuiltinClassProfile isValueError) {
@@ -1160,7 +1161,7 @@ Object doit(VirtualFrame frame, PTextIO self,
11601161
PythonUtils.append(sb, "<_io.TextIOWrapper");
11611162
Object nameobj = PNone.NO_VALUE;
11621163
try {
1163-
nameobj = libSelf.lookupAttributeStrict(self, frame, NAME);
1164+
nameobj = lookup.execute(frame, self, NAME);
11641165
} catch (PException e) {
11651166
e.expect(ValueError, isValueError);
11661167
/* Ignore ValueError raised if the underlying stream was detached */
@@ -1169,7 +1170,7 @@ Object doit(VirtualFrame frame, PTextIO self,
11691170
Object name = repr.executeObject(frame, nameobj);
11701171
PythonUtils.append(sb, PythonUtils.format(" name=%s", toString.execute(name)));
11711172
}
1172-
Object modeobj = libSelf.lookupAttribute(self, frame, MODE);
1173+
Object modeobj = lookup.execute(frame, self, MODE);
11731174
if (modeobj != PNone.NO_VALUE) {
11741175
PythonUtils.append(sb, PythonUtils.format(" mode='%s'", toString.execute(modeobj)));
11751176
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/json/JSONScannerBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
import com.oracle.graal.python.builtins.objects.dict.PDict;
2424
import com.oracle.graal.python.builtins.objects.exception.PBaseException;
2525
import com.oracle.graal.python.builtins.objects.floats.FloatUtils;
26-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
2726
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
2827
import com.oracle.graal.python.lib.PyFloatCheckExactNode;
2928
import com.oracle.graal.python.lib.PyLongCheckExactNode;
29+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
3030
import com.oracle.graal.python.nodes.PRaiseNode;
3131
import com.oracle.graal.python.nodes.call.CallNode;
3232
import com.oracle.graal.python.nodes.call.special.CallUnaryMethodNode;
@@ -527,7 +527,7 @@ static String scanStringUnicode(String string, int start, boolean strict, IntRef
527527
private static RuntimeException decodeError(Node raisingNode, String jsonString, int pos, String format) {
528528
CompilerAsserts.neverPartOfCompilation();
529529
Object module = AbstractImportNode.importModule("json.decoder");
530-
Object errorClass = PythonObjectLibrary.getUncached().lookupAttribute(module, null, "JSONDecodeError");
530+
Object errorClass = PyObjectLookupAttr.getUncached().execute(null, module, "JSONDecodeError");
531531
Object exception = CallNode.getUncached().execute(errorClass, format, jsonString, pos);
532532
throw PRaiseNode.raise(raisingNode, (PBaseException) exception, false);
533533
}

0 commit comments

Comments
 (0)