Skip to content

Commit 4498ec5

Browse files
committed
Remove LocalsStorage
1 parent 07211fe commit 4498ec5

File tree

5 files changed

+15
-425
lines changed

5 files changed

+15
-425
lines changed

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

Lines changed: 11 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
*/
4141
package com.oracle.graal.python.builtins.objects.common;
4242

43-
import com.oracle.graal.python.PythonLanguage;
4443
import com.oracle.graal.python.builtins.objects.PNone;
45-
import com.oracle.graal.python.builtins.objects.common.DynamicObjectStorage.DynamicObjectStorageSetStringKey;
4644
import com.oracle.graal.python.builtins.objects.common.EconomicMapStorage.EconomicMapSetStringKey;
4745
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.HashingStorageAddAllToOtherNodeGen;
4846
import com.oracle.graal.python.builtins.objects.common.HashingStorageNodesFactory.HashingStorageCopyNodeGen;
@@ -74,7 +72,6 @@
7472
import com.oracle.truffle.api.dsl.NeverDefault;
7573
import com.oracle.truffle.api.dsl.Specialization;
7674
import com.oracle.truffle.api.frame.Frame;
77-
import com.oracle.truffle.api.frame.FrameDescriptor;
7875
import com.oracle.truffle.api.library.CachedLibrary;
7976
import com.oracle.truffle.api.nodes.LoopNode;
8077
import com.oracle.truffle.api.nodes.Node;
@@ -131,12 +128,6 @@ static Object keywords(Frame frame, KeywordsStorage self, Object key, long keyHa
131128
@Cached KeywordsStorage.GetItemNode getNode) {
132129
return getNode.execute(frame, self, key, keyHash);
133130
}
134-
135-
@Specialization
136-
static Object locals(Frame frame, LocalsStorage self, Object key, long keyHash,
137-
@Cached LocalsStorage.GetItemNode getNode) {
138-
return getNode.execute(frame, self, key, keyHash);
139-
}
140131
}
141132

142133
@GenerateUncached
@@ -197,12 +188,6 @@ static Object keywords(Frame frame, KeywordsStorage self, Object key,
197188
@Cached KeywordsStorage.GetItemNode getNode) {
198189
return getNode.execute(frame, self, key, -1);
199190
}
200-
201-
@Specialization
202-
static Object locals(Frame frame, LocalsStorage self, Object key,
203-
@Cached LocalsStorage.GetItemNode getNode) {
204-
return getNode.execute(frame, self, key, -1);
205-
}
206191
}
207192

208193
abstract static class SpecializedSetStringKey extends Node {
@@ -219,7 +204,7 @@ static EconomicMapStorage doEconomicMap(EconomicMapStorage s) {
219204
}
220205

221206
@Specialization
222-
static EconomicMapStorage doEmptyStorage(EmptyStorage s) {
207+
static EconomicMapStorage doEmptyStorage(@SuppressWarnings("unused") EmptyStorage s) {
223208
return EconomicMapStorage.create();
224209
}
225210

@@ -244,17 +229,9 @@ static EconomicMapStorage doDynamicObjectStorage(DynamicObjectStorage s,
244229
return result;
245230
}
246231

247-
@Specialization
248-
static EconomicMapStorage doLocals(LocalsStorage s,
249-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
250-
EconomicMapStorage result = EconomicMapStorage.create(s.lengthHint());
251-
s.addAllTo(result, specializedPutNode);
252-
return result;
253-
}
254-
255232
@Specialization
256233
static EconomicMapStorage doKeywords(KeywordsStorage s,
257-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
234+
@Cached EconomicMapSetStringKey specializedPutNode) {
258235
EconomicMapStorage result = EconomicMapStorage.create(s.length());
259236
s.addAllTo(result, specializedPutNode);
260237
return result;
@@ -264,7 +241,6 @@ static EconomicMapStorage doKeywords(KeywordsStorage s,
264241
@GenerateUncached
265242
@ImportStatic(PGuards.class)
266243
public abstract static class HashingStorageSetItemWithHash extends Node {
267-
static final int DOM_SIZE_THRESHOLD = DynamicObjectStorage.SIZE_THRESHOLD;
268244

269245
@NeverDefault
270246
public static HashingStorageSetItemWithHash create() {
@@ -298,15 +274,15 @@ static HashingStorage empty(Frame frame, @SuppressWarnings("unused") EmptyStorag
298274
}
299275

300276
@Specialization(guards = "!self.shouldTransitionOnPut()")
301-
static HashingStorage domStringKey(DynamicObjectStorage self, TruffleString key, long keyHash, Object value,
277+
static HashingStorage domStringKey(DynamicObjectStorage self, TruffleString key, @SuppressWarnings("unused") long keyHash, Object value,
302278
@Shared("invalidateMro") @Cached BranchProfile invalidateMroProfile,
303279
@Shared("dylib") @CachedLibrary(limit = "3") DynamicObjectLibrary dylib) {
304280
self.setStringKey(key, value, dylib, invalidateMroProfile);
305281
return self;
306282
}
307283

308284
@Specialization(guards = {"!self.shouldTransitionOnPut()", "isBuiltinString(inliningTarget, key, profile)"}, limit = "1")
309-
static HashingStorage domPStringKey(DynamicObjectStorage self, Object key, long keyHash, Object value,
285+
static HashingStorage domPStringKey(DynamicObjectStorage self, Object key, @SuppressWarnings("unused") long keyHash, Object value,
310286
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
311287
@SuppressWarnings("unused") @Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
312288
@Cached CastToTruffleStringNode castStr,
@@ -317,7 +293,7 @@ static HashingStorage domPStringKey(DynamicObjectStorage self, Object key, long
317293
}
318294

319295
@Specialization(guards = {"self.shouldTransitionOnPut() || !isBuiltinString(inliningTarget, key, profile)"}, limit = "1")
320-
static HashingStorage domTransition(Frame frame, DynamicObjectStorage self, Object key, long keyHash, Object value,
296+
static HashingStorage domTransition(Frame frame, DynamicObjectStorage self, Object key, @SuppressWarnings("unused") long keyHash, Object value,
321297
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
322298
@SuppressWarnings("unused") @Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
323299
@Shared("dylib") @CachedLibrary(limit = "3") DynamicObjectLibrary dylib,
@@ -328,34 +304,12 @@ static HashingStorage domTransition(Frame frame, DynamicObjectStorage self, Obje
328304
return result;
329305
}
330306

331-
@Specialization(guards = "self.lengthHint() < DOM_SIZE_THRESHOLD")
332-
HashingStorage localsStringKey(LocalsStorage self, TruffleString key, long keyHash, Object value,
333-
@Shared("invalidateMro") @Cached BranchProfile invalidateMroProfile,
334-
@Shared("dylib") @CachedLibrary(limit = "3") DynamicObjectLibrary dylib,
335-
@Cached DynamicObjectStorageSetStringKey specializedPutNode) {
336-
DynamicObjectStorage result = new DynamicObjectStorage(PythonLanguage.get(this));
337-
self.addAllTo(result, specializedPutNode);
338-
return domStringKey(result, key, keyHash, value, invalidateMroProfile, dylib);
339-
}
340-
341-
@Specialization(guards = "!isTruffleString(key) || lengthHint >= DOM_SIZE_THRESHOLD")
342-
static HashingStorage localsGenericKey(Frame frame, LocalsStorage self, Object key, long keyHash, Object value,
343-
@Bind("this") Node inliningTarget,
344-
@Bind("self.lengthHint()") int lengthHint,
345-
@Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
346-
@Shared("economicPut") @Cached ObjectHashMap.PutNode putNode,
347-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
348-
EconomicMapStorage result = EconomicMapStorage.create(lengthHint);
349-
self.addAllTo(result, specializedPutNode);
350-
return economicMap(frame, result, key, keyHash, value, inliningTarget, profile, putNode);
351-
}
352-
353307
@Specialization
354308
static HashingStorage keywords(Frame frame, KeywordsStorage self, Object key, long keyHash, Object value,
355309
@Bind("this") Node inliningTarget,
356310
@Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
357311
@Shared("economicPut") @Cached ObjectHashMap.PutNode putNode,
358-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
312+
@Cached EconomicMapSetStringKey specializedPutNode) {
359313
// TODO: do we want to try DynamicObjectStorage if the key is a string?
360314
EconomicMapStorage result = EconomicMapStorage.create(self.length());
361315
self.addAllTo(result, specializedPutNode);
@@ -371,7 +325,6 @@ static HashingStorage keywords(Frame frame, KeywordsStorage self, Object key, lo
371325
@GenerateUncached
372326
@ImportStatic(PGuards.class)
373327
public abstract static class HashingStorageSetItem extends Node {
374-
static final int DOM_SIZE_THRESHOLD = DynamicObjectStorage.SIZE_THRESHOLD;
375328

376329
@NeverDefault
377330
public static HashingStorageSetItem create() {
@@ -448,36 +401,13 @@ static HashingStorage domTransition(Frame frame, DynamicObjectStorage self, Obje
448401
return result;
449402
}
450403

451-
@Specialization(guards = "self.lengthHint() < DOM_SIZE_THRESHOLD")
452-
HashingStorage localsStringKey(LocalsStorage self, TruffleString key, Object value,
453-
@Shared("invalidateMro") @Cached BranchProfile invalidateMroProfile,
454-
@Shared("dylib") @CachedLibrary(limit = "3") DynamicObjectLibrary dylib,
455-
@Cached DynamicObjectStorageSetStringKey specializedPutNode) {
456-
DynamicObjectStorage result = new DynamicObjectStorage(PythonLanguage.get(this));
457-
self.addAllTo(result, specializedPutNode);
458-
return domStringKey(result, key, value, invalidateMroProfile, dylib);
459-
}
460-
461-
@Specialization(guards = "!isTruffleString(key) || lengthHint >= DOM_SIZE_THRESHOLD")
462-
static HashingStorage localsGenericKey(Frame frame, LocalsStorage self, Object key, Object value,
463-
@Bind("this") Node inliningTarget,
464-
@Bind("self.lengthHint()") int lengthHint,
465-
@Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
466-
@Shared("hash") @Cached PyObjectHashNode hashNode,
467-
@Shared("economicPut") @Cached ObjectHashMap.PutNode putNode,
468-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
469-
EconomicMapStorage result = EconomicMapStorage.create(lengthHint);
470-
self.addAllTo(result, specializedPutNode);
471-
return economicMap(frame, result, key, value, inliningTarget, profile, hashNode, putNode);
472-
}
473-
474404
@Specialization
475405
static HashingStorage keywords(Frame frame, KeywordsStorage self, Object key, Object value,
476406
@Bind("this") Node inliningTarget,
477407
@Shared("hash") @Cached PyObjectHashNode hashNode,
478408
@Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
479409
@Shared("economicPut") @Cached ObjectHashMap.PutNode putNode,
480-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
410+
@Cached EconomicMapSetStringKey specializedPutNode) {
481411
// TODO: do we want to try DynamicObjectStorage if the key is a string?
482412
EconomicMapStorage result = EconomicMapStorage.create(self.length());
483413
self.addAllTo(result, specializedPutNode);
@@ -560,7 +490,8 @@ static Object domPStringKey(DynamicObjectStorage self, Object key, boolean isPop
560490
}
561491

562492
@Specialization(guards = "!isBuiltinString(inliningTarget, key, profile)", limit = "1")
563-
static Object domOther(Frame frame, DynamicObjectStorage self, Object key, @SuppressWarnings("unused") boolean isPop, @SuppressWarnings("unused") PHashingCollection toUpdate,
493+
static Object domOther(Frame frame, @SuppressWarnings("unused") DynamicObjectStorage self, Object key, @SuppressWarnings("unused") boolean isPop,
494+
@SuppressWarnings("unused") PHashingCollection toUpdate,
564495
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
565496
@SuppressWarnings("unused") @Shared("isBuiltin") @Cached IsBuiltinObjectProfile profile,
566497
@Shared("hash") @Cached PyObjectHashNode hashNode) {
@@ -580,23 +511,12 @@ static Object empty(Frame frame, @SuppressWarnings("unused") EmptyStorage self,
580511
static Object keywords(Frame frame, KeywordsStorage self, Object key, boolean isPop, PHashingCollection toUpdate,
581512
@Shared("hash") @Cached PyObjectHashNode hashNode,
582513
@Shared("economicRemove") @Cached ObjectHashMap.RemoveNode removeNode,
583-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
514+
@Cached EconomicMapSetStringKey specializedPutNode) {
584515
EconomicMapStorage newStorage = EconomicMapStorage.create(self.length());
585516
self.addAllTo(newStorage, specializedPutNode);
586517
toUpdate.setDictStorage(newStorage);
587518
return economicMap(frame, newStorage, key, isPop, toUpdate, hashNode, removeNode);
588519
}
589-
590-
@Specialization
591-
static Object locals(Frame frame, LocalsStorage self, Object key, boolean isPop, PHashingCollection toUpdate,
592-
@Shared("hash") @Cached PyObjectHashNode hashNode,
593-
@Shared("economicRemove") @Cached ObjectHashMap.RemoveNode removeNode,
594-
@Shared("economicSpecPut") @Cached EconomicMapSetStringKey specializedPutNode) {
595-
EconomicMapStorage newStorage = EconomicMapStorage.create(self.lengthHint());
596-
self.addAllTo(newStorage, specializedPutNode);
597-
toUpdate.setDictStorage(newStorage);
598-
return economicMap(frame, newStorage, key, isPop, toUpdate, hashNode, removeNode);
599-
}
600520
}
601521

602522
@GenerateUncached
@@ -633,12 +553,6 @@ static int empty(EmptyStorage self) {
633553
static int keywords(KeywordsStorage self) {
634554
return self.length();
635555
}
636-
637-
@Specialization
638-
static int locals(LocalsStorage self,
639-
@Cached LocalsStorage.LengthNode lengthNode) {
640-
return lengthNode.execute(self);
641-
}
642556
}
643557

644558
@GenerateUncached
@@ -683,7 +597,7 @@ static HashingStorage economic(EconomicMapStorage map) {
683597
}
684598

685599
@Specialization
686-
static EmptyStorage empty(EmptyStorage map) {
600+
static EmptyStorage empty(@SuppressWarnings("unused") EmptyStorage map) {
687601
return EmptyStorage.INSTANCE;
688602
}
689603

@@ -697,11 +611,6 @@ static DynamicObjectStorage dom(DynamicObjectStorage dom,
697611
static HashingStorage keywords(KeywordsStorage self) {
698612
return self.copy();
699613
}
700-
701-
@Specialization
702-
static HashingStorage locals(LocalsStorage self) {
703-
return self.copy();
704-
}
705614
}
706615

707616
@ValueType
@@ -783,16 +692,6 @@ static HashingStorageIterator empty(@SuppressWarnings("unused") EmptyStorage sel
783692
static HashingStorageIterator keywords(@SuppressWarnings("unused") KeywordsStorage self) {
784693
return new HashingStorageIterator();
785694
}
786-
787-
@Specialization
788-
static HashingStorageIterator locals(LocalsStorage self,
789-
@Cached BranchProfile calculateLen) {
790-
if (self.len == -1) {
791-
calculateLen.enter();
792-
self.calculateLength();
793-
}
794-
return new HashingStorageIterator();
795-
}
796695
}
797696

798697
@GenerateUncached
@@ -832,18 +731,6 @@ static HashingStorageIterator keywords(@SuppressWarnings("unused") KeywordsStora
832731
it.index = self.length();
833732
return it;
834733
}
835-
836-
@Specialization
837-
static HashingStorageIterator locals(LocalsStorage self,
838-
@Cached BranchProfile calculateLen) {
839-
if (self.len == -1) {
840-
calculateLen.enter();
841-
self.calculateLength();
842-
}
843-
HashingStorageIterator it = new HashingStorageIterator(true);
844-
it.index = self.len;
845-
return it;
846-
}
847734
}
848735

849736
@GenerateUncached
@@ -945,38 +832,6 @@ static boolean keywords(KeywordsStorage self, HashingStorageIterator it) {
945832
static boolean keywordsReverse(@SuppressWarnings("unused") KeywordsStorage self, HashingStorageIterator it) {
946833
return --it.index >= 0;
947834
}
948-
949-
@Specialization(guards = "!it.isReverse")
950-
static boolean locals(LocalsStorage self, HashingStorageIterator it) {
951-
FrameDescriptor fd = self.frame.getFrameDescriptor();
952-
it.index++;
953-
while (it.index < fd.getNumberOfSlots()) {
954-
Object identifier = fd.getSlotName(it.index);
955-
if (identifier != null && self.getValue(it.index) != null) {
956-
// Update the code in HashingStorageIteratorKey if this assumption changes:
957-
assert identifier instanceof TruffleString;
958-
return true;
959-
}
960-
it.index++;
961-
}
962-
return false;
963-
}
964-
965-
@Specialization(guards = "it.isReverse")
966-
static boolean localsReverse(LocalsStorage self, HashingStorageIterator it) {
967-
FrameDescriptor fd = self.frame.getFrameDescriptor();
968-
it.index--;
969-
while (it.index >= 0) {
970-
Object identifier = fd.getSlotName(it.index);
971-
if (identifier != null && self.getValue(it.index) != null) {
972-
// Update the code in HashingStorageIteratorKey if this assumption changes:
973-
assert identifier instanceof TruffleString;
974-
return true;
975-
}
976-
it.index--;
977-
}
978-
return false;
979-
}
980835
}
981836

982837
@GenerateUncached
@@ -1013,11 +868,6 @@ static boolean empty(EmptyStorage self, HashingStorageIterator it) {
1013868
static Object keywords(KeywordsStorage self, HashingStorageIterator it) {
1014869
return self.keywords[it.index].getValue();
1015870
}
1016-
1017-
@Specialization
1018-
static Object locals(LocalsStorage self, HashingStorageIterator it) {
1019-
return LocalsStorage.getValue(self.frame, it.index);
1020-
}
1021871
}
1022872

1023873
@GenerateUncached
@@ -1054,11 +904,6 @@ static boolean empty(EmptyStorage self, HashingStorageIterator it) {
1054904
static Object keywords(KeywordsStorage self, HashingStorageIterator it) {
1055905
return self.keywords[it.index].getName();
1056906
}
1057-
1058-
@Specialization
1059-
static TruffleString locals(LocalsStorage self, HashingStorageIterator it) {
1060-
return (TruffleString) self.frame.getFrameDescriptor().getSlotName(it.index);
1061-
}
1062907
}
1063908

1064909
@GenerateUncached
@@ -1088,12 +933,6 @@ static long keywords(KeywordsStorage self, HashingStorageIterator it,
1088933
@Shared("hash") @Cached TruffleString.HashCodeNode hashNode) {
1089934
return PyObjectHashNode.hash(self.keywords[it.index].getName(), hashNode);
1090935
}
1091-
1092-
@Specialization
1093-
static long locals(LocalsStorage self, HashingStorageIterator it,
1094-
@Shared("hash") @Cached TruffleString.HashCodeNode hashNode) {
1095-
return PyObjectHashNode.hash((TruffleString) self.frame.getFrameDescriptor().getSlotName(it.index), hashNode);
1096-
}
1097936
}
1098937

1099938
@GenerateUncached
@@ -1415,7 +1254,6 @@ public abstract static class HashingStorageAreDisjointCallback extends HashingSt
14151254

14161255
@Specialization
14171256
static HashingStorage doGeneric(Frame frame, HashingStorage aStorage, HashingStorageIterator it, HashingStorage bStorage,
1418-
@Cached ObjectHashMap.PutNode putResultNode,
14191257
@Cached HashingStorageGetItemWithHash getFromOther,
14201258
@Cached HashingStorageIteratorKey iterKey,
14211259
@Cached HashingStorageIteratorKeyHash iterHash) {

0 commit comments

Comments
 (0)