Skip to content

Commit 279c504

Browse files
msimacektimfel
authored andcommitted
Migrate usages of POL.lookupAttributeStrict
1 parent e3c83eb commit 279c504

File tree

7 files changed

+101
-95
lines changed

7 files changed

+101
-95
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ static boolean writable(@SuppressWarnings("unused") PythonObject self) {
172172
@Builtin(name = _CHECKCLOSED, minNumOfPositionalArgs = 1)
173173
@GenerateNodeFactory
174174
abstract static class CheckClosedNode extends PythonUnaryBuiltinNode {
175-
@Specialization(limit = "3")
175+
@Specialization
176176
Object doCheckClosed(VirtualFrame frame, PythonObject self,
177-
@CachedLibrary("self") PythonObjectLibrary selfLib,
177+
@Cached PyObjectLookupAttr lookupAttr,
178178
@Cached PyObjectIsTrueNode isTrueNode) {
179-
if (isTrueNode.execute(frame, selfLib.lookupAttributeStrict(self, frame, CLOSED))) {
179+
if (isTrueNode.execute(frame, lookupAttr.executeStrict(frame, this, self, CLOSED))) {
180180
throw raise(ValueError, ErrorMessages.IO_CLOSED);
181181
}
182182
return PNone.NONE;

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,19 +1056,19 @@ static Object finalizing(PTextIO self) {
10561056
@GenerateNodeFactory
10571057
abstract static class NameNode extends AttachedCheckPythonUnaryBuiltinNode {
10581058
@Specialization(guards = "checkAttached(self)")
1059-
static Object name(VirtualFrame frame, PTextIO self,
1060-
@CachedLibrary(limit = "2") PythonObjectLibrary libBuffer) {
1061-
return libBuffer.lookupAttributeStrict(self.getBuffer(), frame, NAME);
1059+
Object name(VirtualFrame frame, PTextIO self,
1060+
@Cached PyObjectLookupAttr lookupAttr) {
1061+
return lookupAttr.executeStrict(frame, this, self.getBuffer(), NAME);
10621062
}
10631063
}
10641064

10651065
@Builtin(name = CLOSED, minNumOfPositionalArgs = 1, isGetter = true)
10661066
@GenerateNodeFactory
10671067
abstract static class ClosedNode extends AttachedCheckPythonUnaryBuiltinNode {
10681068
@Specialization(guards = "checkAttached(self)")
1069-
static Object closed(VirtualFrame frame, PTextIO self,
1070-
@CachedLibrary(limit = "2") PythonObjectLibrary libBuffer) {
1071-
return libBuffer.lookupAttributeStrict(self.getBuffer(), frame, CLOSED);
1069+
Object closed(VirtualFrame frame, PTextIO self,
1070+
@Cached PyObjectLookupAttr lookupAttr) {
1071+
return lookupAttr.executeStrict(frame, this, self.getBuffer(), CLOSED);
10721072
}
10731073
}
10741074

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
7272
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
7373
import com.oracle.graal.python.lib.PyObjectIsTrueNode;
74+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
7475
import com.oracle.graal.python.nodes.ErrorMessages;
7576
import com.oracle.graal.python.nodes.PNodeWithRaise;
7677
import com.oracle.graal.python.nodes.PRaiseNode;
@@ -167,10 +168,10 @@ void error(@SuppressWarnings("unused") PTextIO self) {
167168

168169
@Specialization(guards = "!self.isFileIO()")
169170
void checkGeneric(VirtualFrame frame, PTextIO self,
170-
@CachedLibrary(limit = "2") PythonObjectLibrary libBuffer,
171+
@Cached PyObjectLookupAttr lookupAttr,
171172
@Cached PyObjectIsTrueNode isTrueNode,
172173
@Cached ConditionProfile isError) {
173-
Object res = libBuffer.lookupAttributeStrict(self.getBuffer(), frame, CLOSED);
174+
Object res = lookupAttr.executeStrict(frame, this, self.getBuffer(), CLOSED);
174175
if (isError.profile(isTrueNode.execute(frame, res))) {
175176
error(self);
176177
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/function/AbstractFunctionBuiltins.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@
5353
import com.oracle.graal.python.builtins.objects.method.PMethod;
5454
import com.oracle.graal.python.builtins.objects.module.PythonModule;
5555
import com.oracle.graal.python.builtins.objects.object.PythonObject;
56-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5756
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
57+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
5858
import com.oracle.graal.python.nodes.ErrorMessages;
5959
import com.oracle.graal.python.nodes.argument.CreateArgumentsNode;
6060
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
@@ -75,7 +75,6 @@
7575
import com.oracle.truffle.api.dsl.NodeFactory;
7676
import com.oracle.truffle.api.dsl.Specialization;
7777
import com.oracle.truffle.api.frame.VirtualFrame;
78-
import com.oracle.truffle.api.library.CachedLibrary;
7978
import com.oracle.truffle.api.profiles.ConditionProfile;
8079

8180
@CoreFunctions(extendClasses = {PythonBuiltinClassType.PFunction, PythonBuiltinClassType.PBuiltinFunction})
@@ -351,9 +350,9 @@ public static TextSignatureNode create() {
351350
public abstract static class ReduceNode extends PythonBuiltinNode {
352351
@Specialization
353352
Object doBuiltinFunc(VirtualFrame frame, PBuiltinFunction func, @SuppressWarnings("unused") Object obj,
354-
@CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
353+
@Cached PyObjectLookupAttr lookupAttr) {
355354
PythonModule builtins = getCore().getBuiltins();
356-
Object getattr = pol.lookupAttributeStrict(builtins, frame, GETATTR);
355+
Object getattr = lookupAttr.executeStrict(frame, this, builtins, GETATTR);
357356
PTuple args = factory().createTuple(new Object[]{func.getEnclosingType(), func.getName()});
358357
return factory().createTuple(new Object[]{getattr, args});
359358
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/iterator/IteratorBuiltins.java

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@
5252
import com.oracle.graal.python.builtins.objects.ints.PInt;
5353
import com.oracle.graal.python.builtins.objects.list.PList;
5454
import com.oracle.graal.python.builtins.objects.module.PythonModule;
55-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5655
import com.oracle.graal.python.builtins.objects.range.RangeNodes.LenOfRangeNode;
5756
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
5857
import com.oracle.graal.python.lib.PyNumberAsSizeNode;
58+
import com.oracle.graal.python.lib.PyObjectLookupAttr;
5959
import com.oracle.graal.python.lib.PyObjectSizeNode;
6060
import com.oracle.graal.python.nodes.ErrorMessages;
6161
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
@@ -359,126 +359,118 @@ public static int lengthHint(VirtualFrame frame, PSequenceIterator self,
359359
@Builtin(name = __REDUCE__, minNumOfPositionalArgs = 1)
360360
@GenerateNodeFactory
361361
public abstract static class ReduceNode extends PythonUnaryBuiltinNode {
362+
@Child PyObjectLookupAttr lookupAttrNode;
363+
362364
@Specialization
363365
public Object reduce(VirtualFrame frame, PArrayIterator self,
364-
@Cached ConditionProfile exhaustedProfile,
365-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
366+
@Cached ConditionProfile exhaustedProfile) {
366367
PythonContext context = PythonContext.get(this);
367368
if (!exhaustedProfile.profile(self.isExhausted())) {
368-
return reduceInternal(frame, self.array, self.getIndex(), context, pol);
369+
return reduceInternal(frame, self.array, self.getIndex(), context);
369370
} else {
370-
return reduceInternal(frame, factory().createEmptyTuple(), context, pol);
371+
return reduceInternal(frame, factory().createEmptyTuple(), context);
371372
}
372373
}
373374

374375
@Specialization
375376
public Object reduce(VirtualFrame frame, PBaseSetIterator self,
376-
@Cached SequenceStorageNodes.CreateStorageFromIteratorNode storageNode,
377-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
377+
@Cached SequenceStorageNodes.CreateStorageFromIteratorNode storageNode) {
378378
int index = self.index;
379379
boolean isExhausted = self.isExhausted();
380380
PList list = factory().createList(storageNode.execute(frame, self));
381381
self.setExhausted(isExhausted);
382382
self.index = index;
383-
return reduceInternal(frame, list, self.getIndex(), PythonContext.get(this), pol);
383+
return reduceInternal(frame, list, self.getIndex(), PythonContext.get(this));
384384
}
385385

386386
@Specialization
387387
public Object reduce(VirtualFrame frame, PDictView.PBaseDictIterator<?> self,
388388
@Cached SequenceStorageNodes.CreateStorageFromIteratorNode storageNode,
389389
@Cached MapNodes.GetIteratorState getState,
390-
@Cached MapNodes.SetIteratorState setState,
391-
@CachedLibrary(limit = "2") PythonObjectLibrary pol) {
390+
@Cached MapNodes.SetIteratorState setState) {
392391
int index = self.index;
393392
boolean isExhausted = self.isExhausted();
394393
int state = getState.execute(self.getIterator());
395394
PList list = factory().createList(storageNode.execute(frame, self));
396395
setState.execute(self.getIterator(), state);
397396
self.setExhausted(isExhausted);
398397
self.index = index;
399-
return reduceInternal(frame, list, PythonContext.get(this), pol);
398+
return reduceInternal(frame, list, PythonContext.get(this));
400399
}
401400

402401
@Specialization
403-
public Object reduce(VirtualFrame frame, PIntegerSequenceIterator self,
404-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
402+
public Object reduce(VirtualFrame frame, PIntegerSequenceIterator self) {
405403
PythonContext context = PythonContext.get(this);
406404
if (self.isExhausted()) {
407-
return reduceInternal(frame, factory().createList(), null, context, pol);
405+
return reduceInternal(frame, factory().createList(), null, context);
408406
}
409-
return reduceInternal(frame, self.getObject(), self.getIndex(), context, pol);
407+
return reduceInternal(frame, self.getObject(), self.getIndex(), context);
410408
}
411409

412410
@Specialization
413-
public Object reduce(VirtualFrame frame, PPrimitiveIterator self,
414-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
411+
public Object reduce(VirtualFrame frame, PPrimitiveIterator self) {
415412
PythonContext context = PythonContext.get(this);
416413
if (self.isExhausted()) {
417-
return reduceInternal(frame, factory().createList(), null, context, pol);
414+
return reduceInternal(frame, factory().createList(), null, context);
418415
}
419-
return reduceInternal(frame, self.getObject(), self.getIndex(), context, pol);
416+
return reduceInternal(frame, self.getObject(), self.getIndex(), context);
420417
}
421418

422419
@Specialization
423-
public Object reduce(VirtualFrame frame, PStringIterator self,
424-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
420+
public Object reduce(VirtualFrame frame, PStringIterator self) {
425421
PythonContext context = PythonContext.get(this);
426422
if (self.isExhausted()) {
427-
return reduceInternal(frame, "", null, context, pol);
423+
return reduceInternal(frame, "", null, context);
428424
}
429-
return reduceInternal(frame, self.value, self.getIndex(), context, pol);
425+
return reduceInternal(frame, self.value, self.getIndex(), context);
430426
}
431427

432428
@Specialization
433429
public Object reduce(VirtualFrame frame, PIntRangeIterator self,
434-
@Cached LenOfRangeNode length,
435-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
430+
@Cached LenOfRangeNode length) {
436431
int start = self.getReduceStart();
437432
int stop = self.getReduceStop();
438433
int step = self.getReduceStep();
439434
int len = length.executeInt(start, stop, step);
440-
return reduceInternal(frame, factory().createIntRange(start, stop, step, len), self.getIndex(), PythonContext.get(this), pol);
435+
return reduceInternal(frame, factory().createIntRange(start, stop, step, len), self.getIndex(), PythonContext.get(this));
441436
}
442437

443438
@Specialization
444439
public Object reduce(VirtualFrame frame, PBigRangeIterator self,
445-
@Cached LenOfRangeNode length,
446-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
440+
@Cached LenOfRangeNode length) {
447441
PInt start = self.getReduceStart();
448442
PInt stop = self.getReduceStop(factory());
449443
PInt step = self.getReduceStep();
450444
PInt len = factory().createInt(length.execute(start.getValue(), stop.getValue(), step.getValue()));
451-
return reduceInternal(frame, factory().createBigRange(start, stop, step, len), self.getLongIndex(factory()), PythonContext.get(this), pol);
445+
return reduceInternal(frame, factory().createBigRange(start, stop, step, len), self.getLongIndex(factory()), PythonContext.get(this));
452446
}
453447

454448
@Specialization(guards = "self.isPSequence()")
455-
public Object reduce(VirtualFrame frame, PSequenceIterator self,
456-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
449+
public Object reduce(VirtualFrame frame, PSequenceIterator self) {
457450
PythonContext context = PythonContext.get(this);
458451
if (self.isExhausted()) {
459-
return reduceInternal(frame, factory().createTuple(new Object[0]), null, context, pol);
452+
return reduceInternal(frame, factory().createTuple(new Object[0]), null, context);
460453
}
461-
return reduceInternal(frame, self.getPSequence(), self.getIndex(), context, pol);
454+
return reduceInternal(frame, self.getPSequence(), self.getIndex(), context);
462455
}
463456

464457
@Specialization(guards = "!self.isPSequence()")
465-
public Object reduceNonSeq(@SuppressWarnings({"unused"}) VirtualFrame frame, PSequenceIterator self,
466-
@Cached.Shared("pol") @CachedLibrary(limit = "1") PythonObjectLibrary pol) {
458+
public Object reduceNonSeq(@SuppressWarnings({"unused"}) VirtualFrame frame, PSequenceIterator self) {
467459
PythonContext context = PythonContext.get(this);
468460
if (!self.isExhausted()) {
469-
return reduceInternal(frame, self.getObject(), self.getIndex(), context, pol);
461+
return reduceInternal(frame, self.getObject(), self.getIndex(), context);
470462
} else {
471-
return reduceInternal(frame, factory().createTuple(new Object[0]), null, context, pol);
463+
return reduceInternal(frame, factory().createTuple(new Object[0]), null, context);
472464
}
473465
}
474466

475-
private PTuple reduceInternal(VirtualFrame frame, Object arg, PythonContext context, PythonObjectLibrary pol) {
476-
return reduceInternal(frame, arg, null, context, pol);
467+
private PTuple reduceInternal(VirtualFrame frame, Object arg, PythonContext context) {
468+
return reduceInternal(frame, arg, null, context);
477469
}
478470

479-
private PTuple reduceInternal(VirtualFrame frame, Object arg, Object state, PythonContext context, PythonObjectLibrary pol) {
471+
private PTuple reduceInternal(VirtualFrame frame, Object arg, Object state, PythonContext context) {
480472
PythonModule builtins = context.getCore().getBuiltins();
481-
Object iter = pol.lookupAttributeStrict(builtins, frame, ITER);
473+
Object iter = getLookupAttrNode().executeStrict(frame, this, builtins, ITER);
482474
PTuple args = factory().createTuple(new Object[]{arg});
483475
// callable, args, state (optional)
484476
if (state != null) {
@@ -487,6 +479,14 @@ private PTuple reduceInternal(VirtualFrame frame, Object arg, Object state, Pyth
487479
return factory().createTuple(new Object[]{iter, args});
488480
}
489481
}
482+
483+
private PyObjectLookupAttr getLookupAttrNode() {
484+
if (lookupAttrNode == null) {
485+
CompilerDirectives.transferToInterpreterAndInvalidate();
486+
lookupAttrNode = insert(PyObjectLookupAttr.create());
487+
}
488+
return lookupAttrNode;
489+
}
490490
}
491491

492492
@Builtin(name = __SETSTATE__, minNumOfPositionalArgs = 2)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.oracle.graal.python.builtins.objects.PythonAbstractObject;
5050
import com.oracle.graal.python.builtins.objects.function.PKeyword;
5151
import com.oracle.graal.python.builtins.objects.module.PythonModule;
52-
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
5352
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
5453
import com.oracle.graal.python.builtins.objects.type.TypeNodes;
5554
import com.oracle.graal.python.lib.PyObjectLookupAttr;
@@ -241,22 +240,22 @@ static Object getDoc(PBuiltinMethod self,
241240
@GenerateNodeFactory
242241
public abstract static class NameNode extends PythonUnaryBuiltinNode {
243242
@Specialization
244-
static Object getName(VirtualFrame frame, PBuiltinMethod method,
243+
Object getName(VirtualFrame frame, PBuiltinMethod method,
245244
@Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
246-
@Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
245+
@Shared("lookupAttr") @Cached PyObjectLookupAttr lookupAttr) {
247246
try {
248-
return toJavaStringNode.execute(pol.lookupAttributeStrict(method.getFunction(), frame, __NAME__));
247+
return toJavaStringNode.execute(lookupAttr.executeStrict(frame, this, method.getFunction(), __NAME__));
249248
} catch (CannotCastException cce) {
250249
throw CompilerDirectives.shouldNotReachHere();
251250
}
252251
}
253252

254253
@Specialization
255-
static Object getName(VirtualFrame frame, PMethod method,
254+
Object getName(VirtualFrame frame, PMethod method,
256255
@Shared("toJavaStringNode") @Cached CastToJavaStringNode toJavaStringNode,
257-
@Shared("pol") @CachedLibrary(limit = "getCallSiteInlineCacheMaxDepth()") PythonObjectLibrary pol) {
256+
@Shared("lookupAttr") @Cached PyObjectLookupAttr lookupAttr) {
258257
try {
259-
return toJavaStringNode.execute(pol.lookupAttributeStrict(method.getFunction(), frame, __NAME__));
258+
return toJavaStringNode.execute(lookupAttr.executeStrict(frame, this, method.getFunction(), __NAME__));
260259
} catch (CannotCastException cce) {
261260
throw CompilerDirectives.shouldNotReachHere();
262261
}

0 commit comments

Comments
 (0)