Skip to content

Commit ac34d9d

Browse files
committed
remove Get/SetDictStorageNode
1 parent 62d88a1 commit ac34d9d

24 files changed

+206
-411
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,7 +2290,6 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
22902290
@Cached WriteAttributeToObjectNode writeItemSize,
22912291
@Cached GetBestBaseClassNode getBestBaseNode,
22922292
@Cached IsIdentifierNode isIdentifier,
2293-
@Cached HashingCollectionNodes.SetDictStorageNode setStorage,
22942293
@Cached HashingStorage.InitNode initNode) {
22952294
// Determine the proper metatype to deal with this
22962295
String name = castStr.execute(wName);
@@ -2307,7 +2306,7 @@ Object typeNew(VirtualFrame frame, Object cls, Object wName, PTuple bases, PDict
23072306

23082307
try {
23092308
PDict namespace = factory().createDict();
2310-
setStorage.execute(namespace, initNode.execute(frame, namespaceOrig, PKeyword.EMPTY_KEYWORDS));
2309+
namespace.setDictStorage(initNode.execute(frame, namespaceOrig, PKeyword.EMPTY_KEYWORDS));
23112310
PythonClass newType = typeMetaclass(frame, name, bases, namespace, metaclass, lib, hashingStoragelib, getDictAttrNode, getWeakRefAttrNode, getBestBaseNode, getItemSize, writeItemSize,
23122311
isIdentifier);
23132312

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

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
import com.oracle.graal.python.builtins.objects.code.CodeNodes.CreateCodeNode;
5252
import com.oracle.graal.python.builtins.objects.code.PCode;
5353
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage;
54-
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes.GetDictStorageNode;
5554
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
5655
import com.oracle.graal.python.builtins.objects.common.HashingStorage.DictEntry;
5756
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
@@ -402,10 +401,9 @@ void handlePList(VirtualFrame frame, PList l, int version, DataOutputStream buff
402401
@Specialization(limit = "1")
403402
void handlePDict(VirtualFrame frame, PDict d, int version, DataOutputStream buffer,
404403
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
405-
@Cached GetDictStorageNode getStore,
406-
@CachedLibrary("getStore.execute(d)") HashingStorageLibrary lib) {
404+
@CachedLibrary("d.getDictStorage()") HashingStorageLibrary lib) {
407405
writeByte(TYPE_DICT, version, buffer);
408-
HashingStorage dictStorage = getStore.execute(d);
406+
HashingStorage dictStorage = d.getDictStorage();
409407
int len = lib.lengthWithFrame(dictStorage, hasFrame, frame);
410408
writeInt(len, version, buffer);
411409
for (DictEntry entry : lib.entries(dictStorage)) {
@@ -434,11 +432,10 @@ private static String getSourceCode(PCode c) {
434432
@Specialization(limit = "1")
435433
void handlePSet(VirtualFrame frame, PSet s, int version, DataOutputStream buffer,
436434
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
437-
@Cached GetDictStorageNode getStore,
438-
@CachedLibrary("getStore.execute(s)") HashingStorageLibrary lib) {
435+
@CachedLibrary("s.getDictStorage()") HashingStorageLibrary lib) {
439436
writeByte(TYPE_SET, version, buffer);
440437
int len;
441-
HashingStorage dictStorage = getStore.execute(s);
438+
HashingStorage dictStorage = s.getDictStorage();
442439
if (hasFrame.profile(frame != null)) {
443440
len = lib.lengthWithState(dictStorage, PArguments.getThreadState(frame));
444441
} else {
@@ -453,11 +450,10 @@ void handlePSet(VirtualFrame frame, PSet s, int version, DataOutputStream buffer
453450
@Specialization(limit = "1")
454451
void handlePForzenSet(VirtualFrame frame, PFrozenSet s, int version, DataOutputStream buffer,
455452
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
456-
@Cached GetDictStorageNode getStore,
457-
@CachedLibrary("getStore.execute(s)") HashingStorageLibrary lib) {
453+
@CachedLibrary("s.getDictStorage()") HashingStorageLibrary lib) {
458454
writeByte(TYPE_FROZENSET, version, buffer);
459455
int len;
460-
HashingStorage dictStorage = getStore.execute(s);
456+
HashingStorage dictStorage = s.getDictStorage();
461457
if (hasFrame.profile(frame != null)) {
462458
len = lib.lengthWithState(dictStorage, PArguments.getThreadState(frame));
463459
} else {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/DynamicObjectNativeWrapper.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@
102102
import com.oracle.graal.python.builtins.objects.cext.capi.PyDateTimeMRNode.DateTimeMode;
103103
import com.oracle.graal.python.builtins.objects.cext.capi.UnicodeObjectNodes.UnicodeAsWideCharNode;
104104
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage;
105-
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodes;
106105
import com.oracle.graal.python.builtins.objects.common.HashingStorage;
107106
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary;
108107
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
@@ -976,9 +975,8 @@ static Object doDQualname(PythonObject object, @SuppressWarnings("unused") Pytho
976975

977976
@Specialization(guards = "eq(SET_USED, key)", limit = "1")
978977
static long doSetUsed(PSet object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key,
979-
@Cached HashingCollectionNodes.GetDictStorageNode getStorageNode,
980-
@CachedLibrary("getStorageNode.execute(object)") HashingStorageLibrary lib) {
981-
return lib.length(getStorageNode.execute(object));
978+
@CachedLibrary("object.getDictStorage()") HashingStorageLibrary lib) {
979+
return lib.length(object.getDictStorage());
982980
}
983981

984982
@Specialization(guards = "eq(MMAP_DATA, key)")
@@ -1208,11 +1206,10 @@ static EachSubclassAdd getUncached() {
12081206
static void doTpSubclasses(PythonClass object, @SuppressWarnings("unused") PythonNativeWrapper nativeWrapper, @SuppressWarnings("unused") String key, PythonObjectNativeWrapper value,
12091207
@Cached GetSubclassesNode getSubclassesNode,
12101208
@Cached EachSubclassAdd eachNode,
1211-
@Cached HashingCollectionNodes.GetDictStorageNode getStorage,
12121209
@CachedLibrary("value") PythonNativeWrapperLibrary lib,
12131210
@CachedLibrary(limit = "1") HashingStorageLibrary hashLib) {
12141211
PDict dict = (PDict) lib.getDelegate(value);
1215-
HashingStorage storage = getStorage.execute(dict);
1212+
HashingStorage storage = dict.getDictStorage();
12161213
Set<PythonAbstractClass> subclasses = getSubclassesNode.execute(object);
12171214
hashLib.forEach(storage, eachNode, new SubclassAddState(storage, hashLib, subclasses));
12181215
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,6 @@ static Object doGeneric(ParserState state, Object kwds, Object kwdnames, boolean
10441044
@Shared("lenNode") @Cached SequenceNodes.LenNode lenNode,
10451045
@Shared("getSequenceStorageNode") @Cached GetSequenceStorageNode getSequenceStorageNode,
10461046
@Shared("getItemNode") @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode,
1047-
@Cached HashingCollectionNodes.GetDictStorageNode getDictStorageNode,
10481047
@CachedLibrary(limit = "1") InteropLibrary kwdnamesLib,
10491048
@CachedLibrary(limit = "1") HashingStorageLibrary lib,
10501049
@Cached PCallCExtFunction callCStringToString,
@@ -1066,7 +1065,7 @@ static Object doGeneric(ParserState state, Object kwds, Object kwdnames, boolean
10661065
if (kwdname instanceof String) {
10671066
// the cast to PDict is safe because either it is null or a PDict (ensured by
10681067
// the guards)
1069-
out = lib.getItem(getDictStorageNode.execute((PDict) kwds), kwdname);
1068+
out = lib.getItem(((PDict) kwds).getDictStorage(), kwdname);
10701069
}
10711070
}
10721071
if (out == null && !state.restOptional) {

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

Lines changed: 17 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,11 @@
4343
import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
4444

4545
import com.oracle.graal.python.builtins.objects.PNone;
46-
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.GetDictStorageNodeGen;
4746
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.LenNodeGen;
48-
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.SetDictStorageNodeGen;
4947
import com.oracle.graal.python.builtins.objects.common.HashingCollectionNodesFactory.SetItemNodeGen;
50-
import com.oracle.graal.python.builtins.objects.dict.PDict;
5148
import com.oracle.graal.python.builtins.objects.dict.PDictView;
5249
import com.oracle.graal.python.builtins.objects.function.PArguments;
5350
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
54-
import com.oracle.graal.python.builtins.objects.set.PBaseSet;
5551
import com.oracle.graal.python.builtins.objects.str.PString;
5652
import com.oracle.graal.python.nodes.ErrorMessages;
5753
import com.oracle.graal.python.nodes.PGuards;
@@ -81,9 +77,8 @@ public abstract static class LenNode extends PNodeWithContext {
8177

8278
@Specialization(limit = "4")
8379
static int getLen(PHashingCollection c,
84-
@Cached GetDictStorageNode getStorage,
85-
@CachedLibrary("getStorage.execute(c)") HashingStorageLibrary lib) {
86-
return lib.length(getStorage.execute(c));
80+
@CachedLibrary("c.getDictStorage()") HashingStorageLibrary lib) {
81+
return lib.length(c.getDictStorage());
8782
}
8883

8984
public static LenNode create() {
@@ -98,69 +93,17 @@ public abstract static class SetItemNode extends PNodeWithContext {
9893
@Specialization(limit = "4")
9994
static void doSetItem(VirtualFrame frame, PHashingCollection c, Object key, Object value,
10095
@Cached("createBinaryProfile()") ConditionProfile hasFrame,
101-
@Cached GetDictStorageNode getStorage,
102-
@Cached SetDictStorageNode setStorage,
10396
@CachedLibrary("c.getDictStorage()") HashingStorageLibrary lib) {
104-
HashingStorage storage = getStorage.execute(c);
97+
HashingStorage storage = c.getDictStorage();
10598
storage = lib.setItemWithFrame(storage, key, value, hasFrame, frame);
106-
setStorage.execute(c, storage);
99+
c.setDictStorage(storage);
107100
}
108101

109102
public static SetItemNode create() {
110103
return SetItemNodeGen.create();
111104
}
112105
}
113106

114-
@ImportStatic({PGuards.class})
115-
@GenerateUncached
116-
public abstract static class GetDictStorageNode extends PNodeWithContext {
117-
118-
public abstract HashingStorage execute(PHashingCollection c);
119-
120-
@Specialization
121-
static HashingStorage get(PBaseSet c) {
122-
return c.getDictStorage();
123-
}
124-
125-
@Specialization
126-
static HashingStorage get(PDict c) {
127-
return c.getDictStorage();
128-
}
129-
130-
public static GetDictStorageNode create() {
131-
return GetDictStorageNodeGen.create();
132-
}
133-
134-
public static GetDictStorageNode getUncached() {
135-
return GetDictStorageNodeGen.getUncached();
136-
}
137-
}
138-
139-
@ImportStatic({PGuards.class})
140-
@GenerateUncached
141-
public abstract static class SetDictStorageNode extends PNodeWithContext {
142-
143-
public abstract void execute(PHashingCollection c, HashingStorage storage);
144-
145-
@Specialization
146-
static void set(PBaseSet c, HashingStorage storage) {
147-
c.setDictStorage(storage);
148-
}
149-
150-
@Specialization
151-
static void set(PDict c, HashingStorage storage) {
152-
c.setDictStorage(storage);
153-
}
154-
155-
public static SetDictStorageNode create() {
156-
return SetDictStorageNodeGen.create();
157-
}
158-
159-
public static SetDictStorageNode getUncached() {
160-
return SetDictStorageNodeGen.getUncached();
161-
}
162-
}
163-
164107
@ImportStatic({PGuards.class})
165108
public abstract static class SetValueHashingStorageNode extends PNodeWithContext {
166109
public abstract void execute(VirtualFrame frame, HashingStorage iterator, Object value);
@@ -205,34 +148,30 @@ public final HashingStorage doNoValue(VirtualFrame frame, Object iterator) {
205148

206149
@Specialization(guards = "isNoValue(value)", limit = "1")
207150
static HashingStorage doHashingCollectionNoValue(@SuppressWarnings("unused") VirtualFrame frame, PHashingCollection other, @SuppressWarnings("unused") Object value,
208-
@Cached.Shared("getStorage") @Cached GetDictStorageNode getStorage,
209-
@CachedLibrary("getStorage.execute(other)") HashingStorageLibrary lib) {
210-
return lib.copy(getStorage.execute(other));
151+
@CachedLibrary("other.getDictStorage()") HashingStorageLibrary lib) {
152+
return lib.copy(other.getDictStorage());
211153
}
212154

213155
@Specialization(guards = "isNoValue(value)", limit = "1")
214156
static HashingStorage doPDictKeyViewNoValue(@SuppressWarnings("unused") VirtualFrame frame, PDictView.PDictKeysView other, Object value,
215-
@Cached.Shared("getStorage") @Cached GetDictStorageNode getStorage,
216-
@CachedLibrary("getStorage.execute(other.getWrappedDict())") HashingStorageLibrary lib) {
217-
return doHashingCollectionNoValue(frame, other.getWrappedDict(), value, getStorage, lib);
157+
@CachedLibrary("other.getWrappedDict().getDictStorage()") HashingStorageLibrary lib) {
158+
return doHashingCollectionNoValue(frame, other.getWrappedDict(), value, lib);
218159
}
219160

220161
@Specialization(guards = "!isNoValue(value)", limit = "1")
221162
static HashingStorage doHashingCollection(@SuppressWarnings("unused") VirtualFrame frame, PHashingCollection other, Object value,
222-
@Cached.Shared("getStorage") @Cached GetDictStorageNode getStorage,
223163
@Cached SetValueHashingStorageNode setValue,
224-
@CachedLibrary("getStorage.execute(other)") HashingStorageLibrary lib) {
225-
HashingStorage storage = lib.copy(getStorage.execute(other));
164+
@CachedLibrary("other.getDictStorage()") HashingStorageLibrary lib) {
165+
HashingStorage storage = lib.copy(other.getDictStorage());
226166
setValue.execute(frame, storage, value);
227167
return storage;
228168
}
229169

230170
@Specialization(guards = "!isNoValue(value)", limit = "1")
231171
static HashingStorage doPDictView(@SuppressWarnings("unused") VirtualFrame frame, PDictView.PDictKeysView other, Object value,
232-
@Cached.Shared("getStorage") @Cached GetDictStorageNode getStorage,
233172
@Cached SetValueHashingStorageNode setValue,
234-
@CachedLibrary("getStorage.execute(other.getWrappedDict())") HashingStorageLibrary lib) {
235-
return doHashingCollection(frame, other.getWrappedDict(), value, getStorage, setValue, lib);
173+
@CachedLibrary("other.getWrappedDict().getDictStorage()") HashingStorageLibrary lib) {
174+
return doHashingCollection(frame, other.getWrappedDict(), value, setValue, lib);
236175
}
237176

238177
@Specialization
@@ -293,19 +232,17 @@ public abstract static class GetHashingStorageNode extends PNodeWithContext {
293232
public abstract HashingStorage execute(VirtualFrame frame, Object iterator);
294233

295234
@Specialization
296-
static HashingStorage doHashingCollection(@SuppressWarnings("unused") VirtualFrame frame, PHashingCollection other,
297-
@Cached GetDictStorageNode getStorage) {
298-
return getStorage.execute(other);
235+
static HashingStorage doHashingCollection(PHashingCollection other) {
236+
return other.getDictStorage();
299237
}
300238

301239
@Specialization
302-
static HashingStorage doPDictView(@SuppressWarnings("unused") VirtualFrame frame, PDictView.PDictKeysView other,
303-
@Cached GetDictStorageNode getStorage) {
304-
return getStorage.execute(other.getWrappedDict());
240+
static HashingStorage doPDictView(PDictView.PDictKeysView other) {
241+
return other.getWrappedDict().getDictStorage();
305242
}
306243

307244
@Specialization(guards = {"!isPHashingCollection(other)", "!isDictKeysView(other)"})
308-
static HashingStorage doGeneric(@SuppressWarnings("unused") VirtualFrame frame, Object other,
245+
static HashingStorage doGeneric(VirtualFrame frame, Object other,
309246
@Cached GetClonedHashingStorageNode getHashingStorageNode) {
310247
return getHashingStorageNode.doNoValue(frame, other);
311248
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,20 +168,18 @@ protected boolean hasKeysAttribute(Object o) {
168168
@Specialization(guards = {"isEmpty(kwargs)", "!hasIterAttrButNotBuiltin(dictLike, dictLib)"}, limit = "1")
169169
HashingStorage doPDict(PHashingCollection dictLike, @SuppressWarnings("unused") PKeyword[] kwargs,
170170
@SuppressWarnings("unused") @CachedLibrary("dictLike") PythonObjectLibrary dictLib,
171-
@CachedLibrary(limit = "3") HashingStorageLibrary lib,
172-
@Cached HashingCollectionNodes.GetDictStorageNode getDictStorageNode) {
173-
return lib.copy(getDictStorageNode.execute(dictLike));
171+
@CachedLibrary(limit = "3") HashingStorageLibrary lib) {
172+
return lib.copy(dictLike.getDictStorage());
174173
}
175174

176175
@Specialization(guards = {"!isEmpty(kwargs)", "!hasIterAttrButNotBuiltin(iterable, iterLib)"}, limit = "1")
177176
HashingStorage doPDictKwargs(VirtualFrame frame, PHashingCollection iterable, PKeyword[] kwargs,
178177
@CachedContext(PythonLanguage.class) PythonContext context,
179178
@SuppressWarnings("unused") @CachedLibrary("iterable") PythonObjectLibrary iterLib,
180-
@CachedLibrary(limit = "2") HashingStorageLibrary lib,
181-
@Cached("create()") HashingCollectionNodes.GetDictStorageNode getDictStorageNode) {
179+
@CachedLibrary(limit = "2") HashingStorageLibrary lib) {
182180
Object state = IndirectCallContext.enter(frame, context, this);
183181
try {
184-
HashingStorage iterableDictStorage = getDictStorageNode.execute(iterable);
182+
HashingStorage iterableDictStorage = iterable.getDictStorage();
185183
HashingStorage dictStorage = lib.copy(iterableDictStorage);
186184
return lib.addAllToOther(new KeywordsStorage(kwargs), dictStorage);
187185
} finally {

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,26 @@
4343
import com.oracle.graal.python.builtins.objects.common.HashingStorage.DictEntry;
4444
import com.oracle.graal.python.builtins.objects.common.HashingStorageLibrary.HashingStorageIterable;
4545
import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject;
46+
import com.oracle.graal.python.builtins.objects.set.PFrozenSet;
4647
import com.oracle.truffle.api.object.Shape;
4748

4849
public abstract class PHashingCollection extends PythonBuiltinObject {
4950

50-
public PHashingCollection(Object cls, Shape instanceShape) {
51+
protected HashingStorage storage;
52+
53+
public PHashingCollection(Object cls, Shape instanceShape, HashingStorage storage) {
5154
super(cls, instanceShape);
55+
this.storage = storage;
5256
}
5357

54-
public abstract HashingStorage getDictStorage();
58+
public final HashingStorage getDictStorage() {
59+
return storage;
60+
}
5561

56-
public abstract void setDictStorage(HashingStorage newStorage);
62+
public final void setDictStorage(HashingStorage storage) {
63+
assert storage == this.storage || !(this instanceof PFrozenSet) : "frozenSet is unmodifiable";
64+
this.storage = storage;
65+
}
5766

5867
public HashingStorageIterable<Object> items() {
5968
return HashingStorageLibrary.getUncached().values(getDictStorage());

0 commit comments

Comments
 (0)