Skip to content

Commit 6868658

Browse files
msimacektimfel
authored andcommitted
Remove remaining usages of POL.lookupAttribute
1 parent aa0cbaa commit 6868658

File tree

7 files changed

+70
-69
lines changed

7 files changed

+70
-69
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/dict/DictBuiltins.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
7171
import com.oracle.graal.python.builtins.objects.type.SpecialMethodSlot;
7272
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
73+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
7374
import com.oracle.graal.python.nodes.ErrorMessages;
7475
import com.oracle.graal.python.nodes.PGuards;
7576
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -592,10 +593,10 @@ private HashingStorage addAll(PDict self, PDict other, HashingStorageLibrary lib
592593
return newStorage;
593594
}
594595

595-
@Specialization(guards = {"args.length == 1", "!isDict(args)", "hasKeysAttr(args, frame, libArg)"})
596+
@Specialization(guards = {"args.length == 1", "!isDict(args)", "hasKeysAttr(frame, args, lookupKeys)"}, limit = "1")
596597
public static Object updateMapping(VirtualFrame frame, PDict self, Object[] args, PKeyword[] kwargs,
597-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary libArg,
598-
@CachedLibrary(limit = "3") HashingStorageLibrary lib,
598+
@SuppressWarnings("unused") @Shared("lookupKeys") @Cached PyObjectLookupAttr lookupKeys,
599+
@Shared("hlib") @CachedLibrary(limit = "3") HashingStorageLibrary lib,
599600
@Shared("keysLib") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary keysLib,
600601
@Cached("create(KEYS)") LookupAndCallUnaryNode callKeysNode,
601602
@Cached("create(__GETITEM__)") LookupAndCallBinaryNode callGetItemNode,
@@ -607,10 +608,10 @@ public static Object updateMapping(VirtualFrame frame, PDict self, Object[] args
607608
return PNone.NONE;
608609
}
609610

610-
@Specialization(guards = {"args.length == 1", "!isDict(args)", "!hasKeysAttr(args, frame, libArg)"})
611+
@Specialization(guards = {"args.length == 1", "!isDict(args)", "!hasKeysAttr(frame, args, lookupKeys)"}, limit = "1")
611612
public static Object updateSequence(VirtualFrame frame, PDict self, Object[] args, PKeyword[] kwargs,
612-
@SuppressWarnings("unused") @CachedLibrary(limit = "1") PythonObjectLibrary libArg,
613-
@CachedLibrary(limit = "3") HashingStorageLibrary lib,
613+
@SuppressWarnings("unused") @Shared("lookupKeys") @Cached PyObjectLookupAttr lookupKeys,
614+
@Shared("hlib") @CachedLibrary(limit = "3") HashingStorageLibrary lib,
614615
@Shared("keysLib") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary keysLib,
615616
@Cached PRaiseNode raise,
616617
@Cached GetNextNode nextNode,
@@ -658,8 +659,8 @@ protected static boolean isSelf(PDict self, Object[] args) {
658659
return isDict(args) && args[0] == self;
659660
}
660661

661-
protected static boolean hasKeysAttr(Object[] args, VirtualFrame frame, PythonObjectLibrary lib) {
662-
return lib.lookupAttribute(args[0], frame, KEYS) != PNone.NO_VALUE;
662+
protected static boolean hasKeysAttr(VirtualFrame frame, Object[] args, PyObjectLookupAttr lookupKeys) {
663+
return lookupKeys.execute(frame, args[0], KEYS) != NO_VALUE;
663664
}
664665

665666
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -343,41 +343,43 @@ protected static boolean isSelfModuleOrNull(PBuiltinMethod method) {
343343
}
344344

345345
@Specialization(guards = "isSelfModuleOrNull(method)")
346-
static Object doSelfIsModule(VirtualFrame frame, PMethod method, @SuppressWarnings("unused") Object obj,
346+
Object doSelfIsModule(VirtualFrame frame, PMethod method, @SuppressWarnings("unused") Object obj,
347347
@Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
348-
@Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
349-
return getName(frame, method.getFunction(), toJavaStringNode, pol);
348+
@Shared("lookupName") @Cached PyObjectLookupAttr lookupName) {
349+
return getName(frame, method.getFunction(), toJavaStringNode, lookupName);
350350
}
351351

352352
@Specialization(guards = "isSelfModuleOrNull(method)")
353-
static Object doSelfIsModule(VirtualFrame frame, PBuiltinMethod method, @SuppressWarnings("unused") Object obj,
353+
Object doSelfIsModule(VirtualFrame frame, PBuiltinMethod method, @SuppressWarnings("unused") Object obj,
354354
@Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
355-
@Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
356-
return getName(frame, method.getFunction(), toJavaStringNode, pol);
355+
@Shared("lookupName") @Cached PyObjectLookupAttr lookupName) {
356+
return getName(frame, method.getFunction(), toJavaStringNode, lookupName);
357357
}
358358

359359
@Specialization(guards = "!isSelfModuleOrNull(method)")
360360
Object doSelfIsObjet(VirtualFrame frame, PMethod method, @SuppressWarnings("unused") Object obj,
361361
@Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
362-
@Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
362+
@Shared("lookupGetattr") @Cached PyObjectLookupAttr lookupGetattr,
363+
@Shared("lookupName") @Cached PyObjectLookupAttr lookupName) {
363364
PythonModule builtins = getCore().getBuiltins();
364-
Object getattr = pol.lookupAttributeStrict(builtins, frame, GETATTR);
365-
PTuple args = factory().createTuple(new Object[]{method.getSelf(), getName(frame, method.getFunction(), toJavaStringNode, pol)});
365+
Object getattr = lookupGetattr.executeStrict(frame, this, builtins, GETATTR);
366+
PTuple args = factory().createTuple(new Object[]{method.getSelf(), getName(frame, method.getFunction(), toJavaStringNode, lookupName)});
366367
return factory().createTuple(new Object[]{getattr, args});
367368
}
368369

369370
@Specialization(guards = "!isSelfModuleOrNull(method)")
370-
Object doSelfIsObjet(VirtualFrame frame, PBuiltinMethod method, @SuppressWarnings("unused") Object obj,
371+
Object doSelfIsObject(VirtualFrame frame, PBuiltinMethod method, @SuppressWarnings("unused") Object obj,
371372
@Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
372-
@Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
373+
@Shared("lookupGetattr") @Cached PyObjectLookupAttr lookupGetattr,
374+
@Shared("lookupName") @Cached PyObjectLookupAttr lookupName) {
373375
PythonModule builtins = getCore().getBuiltins();
374-
Object getattr = pol.lookupAttributeStrict(builtins, frame, GETATTR);
375-
PTuple args = factory().createTuple(new Object[]{method.getSelf(), getName(frame, method.getFunction(), toJavaStringNode, pol)});
376+
Object getattr = lookupGetattr.executeStrict(frame, this, builtins, GETATTR);
377+
PTuple args = factory().createTuple(new Object[]{method.getSelf(), getName(frame, method.getFunction(), toJavaStringNode, lookupName)});
376378
return factory().createTuple(new Object[]{getattr, args});
377379
}
378380

379-
private static String getName(VirtualFrame frame, Object func, CastToJavaStringNode toJavaStringNode, PythonObjectLibrary pol) {
380-
return toJavaStringNode.execute(pol.lookupAttribute(func, frame, __NAME__));
381+
private String getName(VirtualFrame frame, Object func, CastToJavaStringNode toJavaStringNode, PyObjectLookupAttr lookup) {
382+
return toJavaStringNode.execute(lookup.executeStrict(frame, this, func, __NAME__));
381383
}
382384
}
383385
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/DecoratedMethodBuiltins.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
import com.oracle.graal.python.builtins.PythonBuiltins;
5555
import com.oracle.graal.python.builtins.objects.PNone;
5656
import com.oracle.graal.python.builtins.objects.dict.PDict;
57-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5857
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
58+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
5959
import com.oracle.graal.python.nodes.ErrorMessages;
6060
import com.oracle.graal.python.nodes.PGuards;
6161
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
@@ -69,7 +69,6 @@
6969
import com.oracle.truffle.api.dsl.NodeFactory;
7070
import com.oracle.truffle.api.dsl.Specialization;
7171
import com.oracle.truffle.api.frame.VirtualFrame;
72-
import com.oracle.truffle.api.library.CachedLibrary;
7372
import com.oracle.truffle.api.profiles.ConditionProfile;
7473

7574
@CoreFunctions(extendClasses = {PythonBuiltinClassType.PStaticmethod, PythonBuiltinClassType.PClassmethod})
@@ -127,10 +126,10 @@ protected Object setDict(@SuppressWarnings("unused") PDecoratedMethod self, Obje
127126
abstract static class IsAbstractMethodNode extends PythonUnaryBuiltinNode {
128127
@Specialization
129128
static boolean isAbstract(VirtualFrame frame, PDecoratedMethod self,
130-
@CachedLibrary(limit = "3") PythonObjectLibrary lib,
129+
@Cached PyObjectLookupAttr lookup,
131130
@Cached PyObjectIsTrueNode isTrue,
132131
@Cached ConditionProfile hasAttrProfile) {
133-
Object result = lib.lookupAttribute(self.getCallable(), frame, __ISABSTRACTMETHOD__);
132+
Object result = lookup.execute(frame, self.getCallable(), __ISABSTRACTMETHOD__);
134133
if (hasAttrProfile.profile(result != PNone.NO_VALUE)) {
135134
return isTrue.execute(frame, result);
136135
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/MethodBuiltins.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@
4747
import com.oracle.graal.python.builtins.objects.PNone;
4848
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4949
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
50-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
50+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
51+
import com.oracle.graal.python.lib.PyObjectReprAsJavaStringNode;
5152
import com.oracle.graal.python.nodes.ErrorMessages;
5253
import com.oracle.graal.python.nodes.PGuards;
5354
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetDefaultsNode;
5455
import com.oracle.graal.python.nodes.builtins.FunctionNodes.GetKeywordDefaultsNode;
5556
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
56-
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
5757
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
5858
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
5959
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
@@ -70,7 +70,6 @@
7070
import com.oracle.truffle.api.dsl.NodeFactory;
7171
import com.oracle.truffle.api.dsl.Specialization;
7272
import com.oracle.truffle.api.frame.VirtualFrame;
73-
import com.oracle.truffle.api.library.CachedLibrary;
7473

7574
@CoreFunctions(extendClasses = PythonBuiltinClassType.PMethod)
7675
public class MethodBuiltins extends PythonBuiltins {
@@ -144,22 +143,22 @@ Object getattribute(Object self, @SuppressWarnings("unused") Object key) {
144143
abstract static class ReprNode extends PythonUnaryBuiltinNode {
145144
@Specialization
146145
static Object reprMethod(VirtualFrame frame, PMethod method,
147-
@Cached("create(__REPR__)") LookupAndCallUnaryNode callReprNode,
146+
@Cached PyObjectReprAsJavaStringNode repr,
148147
@Cached CastToJavaStringNode toJavaStringNode,
149-
@CachedLibrary(limit = "1") PythonObjectLibrary pol) {
148+
@Cached PyObjectLookupAttr lookup) {
150149
Object self = method.getSelf();
151150
Object func = method.getFunction();
152151
String defname = "?";
153152

154-
Object funcName = pol.lookupAttribute(func, frame, __QUALNAME__);
153+
Object funcName = lookup.execute(frame, func, __QUALNAME__);
155154
if (funcName == PNone.NO_VALUE) {
156-
funcName = pol.lookupAttribute(func, frame, __NAME__);
155+
funcName = lookup.execute(frame, func, __NAME__);
157156
}
158157

159158
try {
160-
return PythonUtils.format("<bound method %s of %s>", toJavaStringNode.execute(funcName), callReprNode.executeObject(frame, self));
159+
return PythonUtils.format("<bound method %s of %s>", toJavaStringNode.execute(funcName), repr.execute(frame, self));
161160
} catch (CannotCastException e) {
162-
return PythonUtils.format("<bound method %s of %s>", defname, callReprNode.executeObject(frame, self));
161+
return PythonUtils.format("<bound method %s of %s>", defname, repr.execute(frame, self));
163162
}
164163
}
165164
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/module/ModuleBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
import com.oracle.graal.python.builtins.objects.dict.PDict;
6969
import com.oracle.graal.python.builtins.objects.module.ModuleBuiltinsClinicProviders.ModuleNodeClinicProviderGen;
7070
import com.oracle.graal.python.builtins.objects.object.ObjectBuiltins;
71-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
71+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
7272
import com.oracle.graal.python.nodes.ErrorMessages;
7373
import com.oracle.graal.python.nodes.PNodeWithRaise;
7474
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
@@ -153,9 +153,9 @@ Object dir(VirtualFrame frame, PythonModule self,
153153
@Cached ListNodes.ConstructListNode constructListNode,
154154
@Cached CallNode callNode,
155155
@Cached GetDictIfExistsNode getDict,
156-
@CachedLibrary(limit = "1") HashingStorageLibrary hashLib,
157-
@CachedLibrary(limit = "1") PythonObjectLibrary pol) {
158-
Object dict = pol.lookupAttribute(self, frame, __DICT__);
156+
@Cached PyObjectLookupAttr lookup,
157+
@CachedLibrary(limit = "1") HashingStorageLibrary hashLib) {
158+
Object dict = lookup.execute(frame, self, __DICT__);
159159
if (isDict(dict, isDictProfile)) {
160160
HashingStorage dictStorage = ((PHashingCollection) dict).getDictStorage();
161161
Object dirFunc = hashLib.getItem(dictStorage, __DIR__);

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -866,24 +866,22 @@ public Object varArgExecute(VirtualFrame frame, Object self, Object[] arguments,
866866
public abstract static class SizeOfNode extends PythonUnaryBuiltinNode {
867867
@Specialization
868868
@SuppressWarnings("unused")
869-
static Object doit(VirtualFrame frame, Object obj,
869+
Object doit(VirtualFrame frame, Object obj,
870870
@Cached GetClassNode getClassNode,
871871
@Cached PyLongAsLongNode asLongNode,
872872
@Cached PyObjectSizeNode sizeNode,
873-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
873+
@Cached PyObjectLookupAttr lookup) {
874874
Object cls = getClassNode.execute(obj);
875875
long size = 0;
876-
Object itemsize = pol.lookupAttribute(obj, frame, __ITEMSIZE__);
876+
Object itemsize = lookup.execute(frame, obj, __ITEMSIZE__);
877877
if (itemsize != PNone.NO_VALUE) {
878-
Object clsItemsize = pol.lookupAttribute(cls, frame, __ITEMSIZE__);
879-
Object objLen = pol.lookupAttribute(obj, frame, __LEN__);
880-
if (clsItemsize == PNone.NO_VALUE || objLen == PNone.NO_VALUE) {
881-
size = 0;
882-
} else {
878+
Object clsItemsize = lookup.execute(frame, cls, __ITEMSIZE__);
879+
Object objLen = lookup.execute(frame, obj, __LEN__);
880+
if (clsItemsize != PNone.NO_VALUE && objLen != PNone.NO_VALUE) {
883881
size = asLongNode.execute(frame, clsItemsize) * sizeNode.execute(frame, obj);
884882
}
885883
}
886-
size += asLongNode.execute(frame, pol.lookupAttributeStrict(cls, frame, __BASICSIZE__));
884+
size += asLongNode.execute(frame, lookup.executeStrict(frame, this, cls, __BASICSIZE__));
887885
return size;
888886
}
889887
}

0 commit comments

Comments
 (0)