Skip to content

Commit fca41a2

Browse files
committed
Remove deprecated PHashingCollection.size()
1 parent 6b7cbc0 commit fca41a2

File tree

9 files changed

+75
-60
lines changed

9 files changed

+75
-60
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/PHashingCollection.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ public PHashingCollection(Object cls, Shape instanceShape) {
5555

5656
public abstract void setDictStorage(HashingStorage newStorage);
5757

58-
@SuppressWarnings("deprecation")
59-
@Override
60-
public abstract int size();
61-
6258
public HashingStorageIterable<Object> items() {
6359
return HashingStorageLibrary.getUncached().values(getDictStorage());
6460
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
2929
import static com.oracle.graal.python.nodes.SpecialMethodNames.__ITER__;
3030
import static com.oracle.graal.python.nodes.SpecialMethodNames.__LEN__;
31+
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REVERSED__;
3132

3233
import java.util.List;
3334

@@ -41,7 +42,6 @@
4142
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
4243
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
4344
import com.oracle.graal.python.builtins.objects.dict.PDictView.PDictValuesView;
44-
import static com.oracle.graal.python.nodes.SpecialMethodNames.__REVERSED__;
4545
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
4646
import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
4747
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
@@ -65,9 +65,12 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
6565
@Builtin(name = __LEN__, minNumOfPositionalArgs = 1)
6666
@GenerateNodeFactory
6767
public abstract static class LenNode extends PythonBuiltinNode {
68-
@Specialization
69-
Object run(PDictView self) {
70-
return self.getWrappedDict().size();
68+
@Specialization(limit = "1")
69+
static Object run(VirtualFrame frame, PDictView self,
70+
@Cached ConditionProfile hasFrameProfile,
71+
@Cached HashingCollectionNodes.GetDictStorageNode getStorage,
72+
@CachedLibrary("getStorage.execute(self.getWrappedDict())") HashingStorageLibrary lib) {
73+
return lib.lengthWithFrame(getStorage.execute(self.getWrappedDict()), hasFrameProfile, frame);
7174
}
7275
}
7376

@@ -101,7 +104,7 @@ Object doPDictValuesView(PDictValuesView self,
101104
@GenerateNodeFactory
102105
public abstract static class EqNode extends PythonBuiltinNode {
103106
@Specialization(limit = "1")
104-
boolean doItemsView(VirtualFrame frame, PDictValuesView self, PDictValuesView other,
107+
static boolean doItemsView(VirtualFrame frame, PDictValuesView self, PDictValuesView other,
105108
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
106109
@Cached HashingCollectionNodes.GetDictStorageNode getStore,
107110
@CachedLibrary("getStore.execute(self.getWrappedDict())") HashingStorageLibrary libSelf,
@@ -119,7 +122,7 @@ boolean doItemsView(VirtualFrame frame, PDictValuesView self, PDictValuesView ot
119122

120123
@Fallback
121124
@SuppressWarnings("unused")
122-
PNotImplemented doGeneric(Object self, Object other) {
125+
static PNotImplemented doGeneric(Object self, Object other) {
123126
return PNotImplemented.NOT_IMPLEMENTED;
124127
}
125128
}

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

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
3434
import com.oracle.graal.python.builtins.objects.common.KeywordsStorage;
3535
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
36+
import com.oracle.graal.python.builtins.objects.function.PArguments;
3637
import com.oracle.graal.python.builtins.objects.function.PKeyword;
3738
import com.oracle.truffle.api.CompilerAsserts;
39+
import com.oracle.truffle.api.library.CachedLibrary;
40+
import com.oracle.truffle.api.library.ExportMessage;
3841
import com.oracle.truffle.api.object.Shape;
3942

4043
public final class PDict extends PHashingCollection {
4144

42-
private HashingStorage dictStorage;
45+
protected HashingStorage dictStorage;
4346

4447
public PDict() {
4548
this(PythonBuiltinClassType.PDict, PythonBuiltinClassType.PDict.getInstanceShape());
@@ -94,14 +97,21 @@ public HashingStorage getDictStorage() {
9497
return dictStorage;
9598
}
9699

100+
@ExportMessage(limit = "1")
101+
public int lengthWithState(PArguments.ThreadState state,
102+
@CachedLibrary("this.dictStorage") HashingStorageLibrary lib) {
103+
return lib.lengthWithState(dictStorage, state);
104+
}
105+
106+
@ExportMessage(limit = "1")
107+
public int length(
108+
@CachedLibrary("this.dictStorage") HashingStorageLibrary lib) {
109+
return lib.length(dictStorage);
110+
}
111+
97112
@Override
98113
public String toString() {
99114
CompilerAsserts.neverPartOfCompilation();
100115
return "PDict<" + dictStorage.getClass().getSimpleName() + ">";
101116
}
102-
103-
@Override
104-
public int size() {
105-
return HashingStorageLibrary.getUncached().length(dictStorage);
106-
}
107117
}

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

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public Object next(VirtualFrame frame, PSequenceIterator self,
235235
@GenerateNodeFactory
236236
public abstract static class IterNode extends PythonUnaryBuiltinNode {
237237
@Specialization
238-
public Object __iter__(Object self) {
238+
public static Object __iter__(Object self) {
239239
return self;
240240
}
241241
}
@@ -245,17 +245,17 @@ public Object __iter__(Object self) {
245245
public abstract static class LengthHintNode extends PythonUnaryBuiltinNode {
246246

247247
@Specialization(guards = "self.isExhausted()")
248-
public int exhausted(@SuppressWarnings("unused") PBuiltinIterator self) {
248+
public static int exhausted(@SuppressWarnings("unused") PBuiltinIterator self) {
249249
return 0;
250250
}
251251

252252
@Specialization
253-
public int lengthHint(PArrayIterator self) {
253+
public static int lengthHint(PArrayIterator self) {
254254
return self.array.len() - self.getIndex();
255255
}
256256

257257
@Specialization(guards = "!self.isExhausted()", limit = "2")
258-
public int lengthHint(@SuppressWarnings({"unused"}) VirtualFrame frame, PDictView.PBaseDictIterator<?> self,
258+
public static int lengthHint(@SuppressWarnings({"unused"}) VirtualFrame frame, PDictView.PBaseDictIterator<?> self,
259259
@CachedLibrary("self.getHashingStorage()") HashingStorageLibrary hlib,
260260
@Cached ConditionProfile profile) {
261261
if (profile.profile(self.checkSizeChanged(hlib))) {
@@ -265,60 +265,62 @@ public int lengthHint(@SuppressWarnings({"unused"}) VirtualFrame frame, PDictVie
265265
}
266266

267267
@Specialization(guards = "!self.isExhausted()")
268-
public int lengthHint(PIntegerSequenceIterator self) {
268+
public static int lengthHint(PIntegerSequenceIterator self) {
269269
int len = self.sequence.length() - self.getIndex();
270270
return len < 0 ? 0 : len;
271271
}
272272

273273
@Specialization(guards = "!self.isExhausted()")
274-
public int lengthHint(PIntRangeIterator self) {
274+
public static int lengthHint(PIntRangeIterator self) {
275275
return self.getLength();
276276
}
277277

278278
@Specialization(guards = "!self.isExhausted()", limit = "1")
279-
public int lengthHint(PBigRangeIterator self,
279+
public static int lengthHint(PBigRangeIterator self,
280280
@CachedLibrary("self.getLen()") PythonObjectLibrary lib) {
281281
return lib.asSize(self.getLen());
282282
}
283283

284284
@Specialization(guards = "!self.isExhausted()")
285-
public int lengthHint(PDoubleSequenceIterator self) {
285+
public static int lengthHint(PDoubleSequenceIterator self) {
286286
int len = self.sequence.length() - self.getIndex();
287287
return len < 0 ? 0 : len;
288288
}
289289

290290
@Specialization(guards = "!self.isExhausted()")
291-
public int lengthHint(PLongSequenceIterator self) {
291+
public static int lengthHint(PLongSequenceIterator self) {
292292
int len = self.sequence.length() - self.getIndex();
293293
return len < 0 ? 0 : len;
294294
}
295295

296-
@Specialization(guards = "!self.isExhausted()")
297-
public int lengthHint(PBaseSetIterator self,
296+
@Specialization(guards = "!self.isExhausted()", limit = "1")
297+
public static int lengthHint(PBaseSetIterator self,
298+
@CachedLibrary("self.getSet().getDictStorage()") HashingStorageLibrary hlib,
298299
@Cached ConditionProfile profile) {
299300
int size = self.getSize();
300-
if (profile.profile(self.getSet().size() != size)) {
301+
final int lenSet = hlib.length(self.getSet().getDictStorage());
302+
if (profile.profile(lenSet != size)) {
301303
return 0;
302304
}
303305
int len = size - self.getIndex();
304306
return len < 0 ? 0 : len;
305307
}
306308

307309
@Specialization(guards = "!self.isExhausted()")
308-
public int lengthHint(PStringIterator self) {
310+
public static int lengthHint(PStringIterator self) {
309311
int len = self.value.length() - self.getIndex();
310312
return len < 0 ? 0 : len;
311313
}
312314

313315
@Specialization(guards = {"!self.isExhausted()", "self.isPSequence()"})
314-
public int lengthHint(PSequenceIterator self,
316+
public static int lengthHint(PSequenceIterator self,
315317
@Cached SequenceNodes.LenNode lenNode) {
316318
int len = lenNode.execute(self.getPSequence()) - self.getIndex();
317319
return len < 0 ? 0 : len;
318320
}
319321

320322
@Specialization(guards = {"!self.isExhausted()", "!self.isPSequence()"}, limit = "getCallSiteInlineCacheMaxDepth()")
321-
public int lengthHint(VirtualFrame frame, PSequenceIterator self,
323+
public static int lengthHint(VirtualFrame frame, PSequenceIterator self,
322324
@CachedLibrary("self.getObject()") PythonObjectLibrary lib) {
323325
int len = lib.lengthWithFrame(self.getObject(), frame) - self.getIndex();
324326
return len < 0 ? 0 : len;
@@ -459,7 +461,7 @@ private PTuple reduceInternal(VirtualFrame frame, Object arg, Object state, Pyth
459461
public abstract static class SetStateNode extends PythonBinaryBuiltinNode {
460462
@Specialization
461463
@CompilerDirectives.TruffleBoundary
462-
public Object reduce(PBigRangeIterator self, Object index,
464+
public static Object reduce(PBigRangeIterator self, Object index,
463465
@Cached CastToJavaBigIntegerNode castToJavaBigIntegerNode) {
464466
BigInteger idx = castToJavaBigIntegerNode.execute(index);
465467
if (idx.compareTo(BigInteger.ZERO) < 0) {
@@ -470,7 +472,7 @@ public Object reduce(PBigRangeIterator self, Object index,
470472
}
471473

472474
@Specialization(limit = "getCallSiteInlineCacheMaxDepth()")
473-
public Object reduce(PBuiltinIterator self, Object index,
475+
public static Object reduce(PBuiltinIterator self, Object index,
474476
@CachedLibrary(value = "index") PythonObjectLibrary pol) {
475477
int idx = pol.asSize(index);
476478
if (idx < 0) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/mappingproxy/PMappingproxy.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
package com.oracle.graal.python.builtins.objects.mappingproxy;
4242

4343
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
44-
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
4544
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
4645
import com.oracle.truffle.api.CompilerDirectives;
4746
import com.oracle.truffle.api.object.Shape;
@@ -64,9 +63,4 @@ public void setDictStorage(HashingStorage newStorage) {
6463
CompilerDirectives.transferToInterpreter();
6564
throw new IllegalStateException();
6665
}
67-
68-
@Override
69-
public int size() {
70-
return HashingStorageLibrary.getUncached().length(dictStorage);
71-
}
7266
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/BaseSetBuiltins.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,13 @@ protected abstract static class BaseLessThanNode extends PythonBinaryBuiltinNode
377377

378378
@Specialization
379379
static boolean isLessThan(VirtualFrame frame, PBaseSet self, PBaseSet other,
380-
@Cached("createBinaryProfile()") ConditionProfile sizeProfile,
380+
@CachedLibrary(limit = "2") HashingStorageLibrary hlib,
381+
@Cached ConditionProfile hasFrameProfile,
382+
@Cached ConditionProfile sizeProfile,
381383
@Cached BaseLessEqualNode lessEqualNode) {
382-
if (sizeProfile.profile(self.size() >= other.size())) {
384+
final int len1 = hlib.lengthWithFrame(self.getDictStorage(), hasFrameProfile, frame);
385+
final int len2 = hlib.lengthWithFrame(other.getDictStorage(), hasFrameProfile, frame);
386+
if (sizeProfile.profile(len1 >= len2)) {
383387
return false;
384388
}
385389
return (Boolean) lessEqualNode.execute(frame, self, other);
@@ -403,9 +407,13 @@ protected abstract static class BaseGreaterThanNode extends PythonBinaryBuiltinN
403407

404408
@Specialization
405409
static boolean isGreaterThan(VirtualFrame frame, PBaseSet self, PBaseSet other,
406-
@Cached("createBinaryProfile()") ConditionProfile sizeProfile,
410+
@CachedLibrary(limit = "2") HashingStorageLibrary hlib,
411+
@Cached ConditionProfile hasFrameProfile,
412+
@Cached ConditionProfile sizeProfile,
407413
@Cached BaseGreaterEqualNode greaterEqualNode) {
408-
if (sizeProfile.profile(self.size() <= other.size())) {
414+
final int len1 = hlib.lengthWithFrame(self.getDictStorage(), hasFrameProfile, frame);
415+
final int len2 = hlib.lengthWithFrame(other.getDictStorage(), hasFrameProfile, frame);
416+
if (sizeProfile.profile(len1 <= len2)) {
409417
return false;
410418
}
411419
return (Boolean) greaterEqualNode.execute(frame, self, other);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/set/PBaseSet.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,14 @@
2929
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
3030
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
3131
import com.oracle.graal.python.builtins.objects.common.PHashingCollection;
32+
import com.oracle.graal.python.builtins.objects.function.PArguments;
33+
import com.oracle.truffle.api.library.CachedLibrary;
34+
import com.oracle.truffle.api.library.ExportMessage;
3235
import com.oracle.truffle.api.object.Shape;
3336

3437
public abstract class PBaseSet extends PHashingCollection {
3538

36-
private HashingStorage set;
39+
protected HashingStorage set;
3740

3841
public PBaseSet(Object clazz, Shape instanceShape) {
3942
super(clazz, instanceShape);
@@ -45,15 +48,6 @@ public PBaseSet(Object clazz, Shape instanceShape, HashingStorage set) {
4548
this.set = set;
4649
}
4750

48-
public final boolean contains(Object key) {
49-
return HashingStorageLibrary.getUncached().hasKey(set, key);
50-
}
51-
52-
@Override
53-
public int size() {
54-
return HashingStorageLibrary.getUncached().length(set);
55-
}
56-
5751
@Override
5852
public final HashingStorage getDictStorage() {
5953
return set;
@@ -63,4 +57,16 @@ public final HashingStorage getDictStorage() {
6357
public void setDictStorage(HashingStorage storage) {
6458
set = storage;
6559
}
60+
61+
@ExportMessage(limit = "1")
62+
public int lengthWithState(PArguments.ThreadState state,
63+
@CachedLibrary("this.set") HashingStorageLibrary lib) {
64+
return lib.lengthWithState(set, state);
65+
}
66+
67+
@ExportMessage(limit = "1")
68+
public int length(
69+
@CachedLibrary("this.set") HashingStorageLibrary lib) {
70+
return lib.length(set);
71+
}
6672
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/PGuards.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,6 @@ public static boolean emptyArguments(PNone none) {
257257
return none == PNone.NO_VALUE;
258258
}
259259

260-
public static boolean emptyArguments(Object arg) {
261-
return arg instanceof PFrozenSet && ((PFrozenSet) arg).size() == 0;
262-
}
263-
264260
@SuppressWarnings("unused")
265261
public static boolean isForJSON(Object obj, String id, Object defaultValue) {
266262
return id.equals("for_json");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/argument/keywords/ExecuteKeywordStarargsNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public abstract class ExecuteKeywordStarargsNode extends PNodeWithContext {
7676
public abstract PKeyword[] execute(VirtualFrame frame);
7777

7878
@Specialization
79-
PKeyword[] doIt(Object starargs,
79+
static PKeyword[] doIt(Object starargs,
8080
@Cached ExpandKeywordStarargsNode expandKeywordStarargsNode) {
8181
return expandKeywordStarargsNode.executeWith(starargs);
8282
}
@@ -104,8 +104,8 @@ static PKeyword[] doEmptyStorage(@SuppressWarnings("unused") PDict starargs) {
104104

105105
@Specialization(guards = {"len(lib, starargs) == cachedLen", "cachedLen < 32"}, limit = "getVariableArgumentInlineCacheLimit()")
106106
static PKeyword[] doDictCached(PDict starargs,
107-
@Cached("starargs.size()") int cachedLen,
108107
@SuppressWarnings("unused") @CachedLibrary("starargs.getDictStorage()") HashingStorageLibrary lib,
108+
@Cached("len(lib, starargs)") int cachedLen,
109109
@Cached PRaiseNode raise,
110110
@Cached BranchProfile errorProfile) {
111111
try {
@@ -132,7 +132,7 @@ static PKeyword[] doDict(PDict starargs,
132132
@CachedLibrary("starargs.getDictStorage()") HashingStorageLibrary lib,
133133
@Cached PRaiseNode raise,
134134
@Cached BranchProfile errorProfile) {
135-
return doDictCached(starargs, lib.length(starargs.getDictStorage()), lib, raise, errorProfile);
135+
return doDictCached(starargs, lib, len(lib, starargs), raise, errorProfile);
136136
}
137137

138138
@Specialization(guards = "!isDict(object)")

0 commit comments

Comments
 (0)